Subversion Repositories Kolibri OS

Rev

Rev 7422 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // Notes v0.7 ALPHA
  2.  
  3. #define MEMSIZE 0xDAE80
  4. #include "..\lib\kolibri.h"
  5. #include "..\lib\mem.h"
  6. #include "..\lib\strings.h"
  7. #include "..\lib\fs.h"
  8. #include "..\lib\dll.h"
  9.  
  10. #include "..\lib\obj\box_lib.h"
  11. #include "..\lib\gui.h"
  12. #include "..\lib\encoding.h"
  13. #include "..\lib\list_box.h"
  14.  
  15. //===================================================//
  16. //                                                   //
  17. //                       DATA                        //
  18. //                                                   //
  19. //===================================================//
  20.  
  21. #ifndef AUTOBUILD
  22.         #include "lang.h--"
  23. #endif
  24.  
  25. #define LANG_RUS
  26.  
  27. #ifdef LANG_RUS
  28.         ?define WINDOW_CAPTION "‡ ¬¥âª¨"
  29.         ?define DELETE_TEXT "Udoli";
  30. #else
  31.         ?define WINDOW_CAPTION "Notes and reminders"
  32.         ?define DELETE_TEXT "Delete";
  33. #endif
  34.  
  35. #define RED_LINE_X 22
  36. #define COL_RED_LINE 0xF3C9C9
  37. unsigned char edge[sizeof(file "edge.raw")]= FROM "edge.raw"; //292x6
  38. #define EDGE_H 6
  39. #define TITLE_H 24
  40. #define HEADER_HEIGHT TITLE_H+EDGE_H
  41.  
  42. #define DELETE_BTN 4;
  43.  
  44. #include "engine.h"
  45.  
  46. dword editbox_text;
  47. proc_info Form;
  48. edit_box edit_box= {0,999,0,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,MAX_LINE_CHARS-1,#editbox_text,#mouse,100000000000010b};
  49. dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
  50.  
  51. //===================================================//
  52. //                                                   //
  53. //                       CODE                        //
  54. //                                                   //
  55. //===================================================//
  56.  
  57. struct KDelete {
  58.         char width;
  59.         char active;
  60.         void Draw();
  61. } DeleteBtn;
  62.  
  63. void KDelete::Draw(dword x, y, h)
  64. {
  65.         width = strlen(DELETE_TEXT)+2*6;
  66.         x -= width+1;
  67.         DefineButton(x, y, width, h-1, DELETE_BTN, 0xFF0000);
  68.         WriteText(x+6+1, h/2-4+y, 0x80, 0xFFFfff, DELETE_TEXT);
  69. }
  70.  
  71. void main()
  72. {  
  73.         int btn;
  74.         dword cur_line_offset;
  75.         load_dll(boxlib, #box_lib_init,0);
  76.        
  77.         if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
  78.         notes.list.cur_y = -1;
  79.  
  80.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  81.  
  82.         loop() switch(WaitEvent())
  83.         {
  84.                 case evMouse:
  85.                         mouse.get();
  86.  
  87.                         if (notes.list.MouseOver(mouse.x, mouse.y)) {
  88.                         notes.list.ProcessMouse(mouse.x, mouse.y);
  89.                                 if (mouse.lkm) EventSelectItem();
  90.                                 if (mouse.pkm) EventDrawDeleteButton();
  91.                         }
  92.  
  93.                         if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<Form.width-30) EventDragWindow();
  94.  
  95.                         if (notes.list.cur_y>=0) edit_box_mouse stdcall (#edit_box);
  96.                         break;
  97.  
  98.                  case evButton:
  99.                         btn = GetButtonID();              
  100.                         if (CLOSE_BTN == btn) EventExitApp();
  101.                         if (DELETE_BTN == btn)
  102.                         {
  103.                                 notes.DeleteCurrentNode();
  104.                                 notes.DrawList();
  105.                                 DeleteBtn.active = 0;
  106.                                 break;
  107.                         }
  108.                         if (btn>=CHECKBOX_ID) //checkboxes
  109.                         {
  110.                                 notes.lines[btn-CHECKBOX_ID].state ^= 1;
  111.                                 notes.DrawList();
  112.                                 break;
  113.                         }
  114.                         break;
  115.          
  116.                 case evKey:
  117.                         GetKeys();
  118.                         if (SCAN_CODE_ESC  == key_scancode) EventExitApp();
  119.                         if (SCAN_CODE_DOWN == key_scancode) { EventActivateLine(notes.list.cur_y+1); break; }
  120.                         if (SCAN_CODE_UP   == key_scancode) { EventActivateLine(notes.list.cur_y-1); break; }
  121.                         if (notes.list.cur_y>=0) edit_box_key stdcall (#edit_box);
  122.                         break;
  123.                  
  124.                  case evReDraw:
  125.                         draw_window();
  126.    }
  127. }
  128.  
  129.  
  130. void DrawCloseButton(dword x,y,w,h)
  131. {
  132.         DrawRectangle(x,y,w,h,0xC96832);
  133.         DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
  134.         PutPixel(x+w-1, y+1, 0xE08C5E);
  135.         DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
  136.         WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
  137. }
  138.  
  139. void draw_window()
  140. {
  141.         int i;
  142.         notes.list.SetSizes(1, HEADER_HEIGHT, 270, RED_LINE_X*LINES_COUNT, RED_LINE_X);
  143.         DefineAndDrawWindow(100,100,notes.list.w+1,notes.list.h+HEADER_HEIGHT+4,0x01,0,0,0x01fffFFF);
  144.         //DefineDragableWindow(100, 100, notes.list.w+1, notes.list.h+HEADER_HEIGHT+4);
  145.         GetProcessInfo(#Form, SelfInfo);
  146.         DrawRectangle3D(0,0,Form.width,TITLE_H-1,0xBB6535, 0xCD6F3B);
  147.         DrawRectangle3D(1,1,Form.width-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
  148.         DrawBar(2,2,Form.width-3,TITLE_H-4,0xE08C5E);
  149.         WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
  150.         WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
  151.         _PutImage(1, TITLE_H, 292,EDGE_H, #edge);
  152.         PutPixel(notes.list.x+RED_LINE_X, notes.list.y-1, COL_RED_LINE);
  153.         ECX-=1; $int 0x40;
  154.         DrawCloseButton(Form.width-23,4,16,16);
  155.         DrawRectangle(0,TITLE_H,Form.width,Form.height-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
  156.         for (i=0; lists[i]!=0; i++) DrawBar(1,Form.height-i-1, Form.width-1, 1, lists[i]);
  157.         edit_box.width = notes.list.w-RED_LINE_X-8;
  158.         edit_box.left = notes.list.x+RED_LINE_X+4;
  159.  
  160.         notes.DrawList();
  161. }
  162.  
  163. void DrawEditBox_Notes()
  164. {
  165.         edit_box.pos = edit_box.offset = edit_box.shift = 0;
  166.         edit_box.size = strlen(edit_box.text);
  167.         edit_box.top = notes.list.cur_y*notes.list.item_h+4+notes.list.y;
  168.         edit_box_draw stdcall(#edit_box);      
  169. }
  170.  
  171. //===================================================//
  172. //                                                   //
  173. //                     EVENTS                        //
  174. //                                                   //
  175. //===================================================//
  176.  
  177. void EventActivateLine(int line_n)
  178. {
  179.         int old;
  180.         if (line_n<0) || (line_n>notes.list.count) return;
  181.         DeleteBtn.active = 0;
  182.         //redraw lines
  183.         notes.list.cur_y = line_n;
  184.         edit_box.text = notes.DrawLine(notes.list.cur_y, notes.list.item_h);
  185.         notes.DrawList();
  186.         DrawEditBox_Notes();
  187. }
  188.  
  189.  
  190. void EventExitApp()
  191. {
  192.         notes.SaveTxt();
  193.         ExitProcess();
  194. }
  195.  
  196. void EventDrawDeleteButton()
  197. {
  198.         notes.DrawLine(notes.list.cur_y, notes.list.item_h);
  199.         DeleteBtn.Draw(notes.list.x+notes.list.w, notes.list.cur_y*notes.list.item_h+notes.list.y, notes.list.item_h);
  200.         edit_box.top=-20;
  201.         DeleteBtn.active = 1;
  202. }
  203.  
  204. void EventSelectItem()
  205. {
  206.         int id;
  207.         id = mouse.y-notes.list.y/notes.list.item_h;
  208.         if (DeleteBtn.active) && (mouse.x>notes.list.x+notes.list.w-DeleteBtn.width) return;
  209.         if (id!=notes.list.cur_y) && (id<notes.list.count) EventActivateLine(id);
  210.         else { notes.list.cur_y=-1; notes.DrawList(); }
  211. }
  212.  
  213. stop:
  214.