Subversion Repositories Kolibri OS

Rev

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

  1. //===================================================//
  2. //                                                   //
  3. //                       LIB                         //
  4. //                                                   //
  5. //===================================================//
  6.  
  7. #include "../lib/gui.h"
  8. #include "../lib/obj/box_lib.h"
  9. #include "../lib/obj/proc_lib.h"
  10. #include "../lib/patterns/simple_open_dialog.h"
  11.  
  12. //===================================================//
  13. //                                                   //
  14. //                       DATA                        //
  15. //                                                   //
  16. //===================================================//
  17.  
  18. //proc_info Form;
  19. #define WIN_W 450
  20.  
  21. char default_dir[] = "/rd/1";
  22. od_filter filter2 = {0,0};
  23.  
  24. char src_path[4096];
  25. char dst_path[4096];
  26. edit_box src_box = {WIN_W-36-DOT_W,18,30,0xffffff,0x94AECE,0xFFFfff,
  27.         0xffffff,0x10000000,sizeof(src_path)-2,#src_path,0, ed_focus};
  28. edit_box dst_box = {WIN_W-36-DOT_W,18,85,0xffffff,0x94AECE,0xFFFfff,
  29.         0xffffff,0x10000000,sizeof(dst_path)-2,#dst_path,0, 0b};
  30.  
  31. enum {
  32.         BID_EXIT_PRC=1,
  33.         BID_SRC_OPEN,
  34.         BID_DST_OPEN,
  35.         BID_GO
  36. };
  37.  
  38. #ifndef COPYING
  39.         #define T_FIRST "First file:"
  40.         #define T_SECOND "Second file:"
  41.         #define T_GO  " Compare "
  42. #endif
  43.  
  44. #define READY 0
  45. int state=READY;
  46.  
  47. //===================================================//
  48. //                                                   //
  49. //                       CODE                        //
  50. //                                                   //
  51. //===================================================//
  52.  
  53. void gui()
  54. {
  55.         word btn;
  56.         load_dll(boxlib, #box_lib_init,0);
  57.         load_dll(Proc_lib,  #OpenDialog_init,0);
  58.         OpenDialog_init stdcall (#o_dialog);
  59.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  60.  
  61.         loop() switch(WaitEvent())
  62.         {
  63.                 case evMouse:
  64.                         if (READY == state) {
  65.                                 edit_box_mouse stdcall (#src_box);
  66.                                 edit_box_mouse stdcall (#dst_box);                             
  67.                         }
  68.                         break;
  69.  
  70.                 case evButton:
  71.                         btn = @GetButtonID();
  72.                         if (btn == BID_EXIT_PRC) ExitProcess();
  73.                         if (btn == BID_SRC_OPEN) EventOpenDialogFirst();
  74.                         if (btn == BID_DST_OPEN) EventOpenDialogSecond();
  75.                         if (btn == BID_GO) EventGo();
  76.                         break;
  77.          
  78.                 case evKey:
  79.                         GetKeys();
  80.                         if (key_scancode == SCAN_CODE_ESC) ExitProcess();
  81.                         if (key_scancode == SCAN_CODE_TAB) EventTabClick();
  82.                         if (key_scancode == SCAN_CODE_ENTER) EventGo();
  83.                         if (key_scancode == SCAN_CODE_INS) EventInsert();
  84.                         EAX = key_editbox;
  85.                         edit_box_key stdcall (#src_box);
  86.                         EAX = key_editbox;
  87.                         edit_box_key stdcall (#dst_box);
  88.                         break;
  89.                  
  90.                 case evReDraw:
  91.                         draw_window();
  92.                         break;
  93.         }
  94. }
  95.  
  96. void draw_window()
  97. {
  98.         system.color.get();
  99.         DefineAndDrawWindow(215, 100, WIN_W+9, 170 + skin_height, 0x34, system.color.work, #window_title,0);
  100.         //GetProcessInfo(#Form, SelfInfo);
  101.         if (READY==state) {
  102.                 DrawFileBox(#src_box, T_FIRST, BID_SRC_OPEN);
  103.                 DrawFileBox(#dst_box, T_SECOND, BID_DST_OPEN);
  104.                 DrawStandartCaptButton(dst_box.left - 2, dst_box.top + 40, BID_GO, T_GO);
  105.         }
  106.         #ifdef COPYING
  107.         if (COPYING==state) {
  108.                 pr.frame_color = system.color.work_graph;
  109.                 DrawRectangle3D(PR_LEFT-1, PR_TOP-1, PR_W+1, PR_H+1, system.color.work_dark,
  110.                         system.color.work_light);
  111.                 DrawProgress();
  112.                 DrawStandartCaptButton(-19*8+WIN_W/2-15, dst_box.top + 35, B_STOP, "        Stop       ");
  113.         }
  114.         #endif
  115. }
  116.  
  117. void UpdateEditBoxes(dword f1, f2)
  118. {
  119.         EditBox_UpdateText(#src_box, f1);
  120.         EditBox_UpdateText(#dst_box, f2);
  121.         edit_box_draw stdcall (#src_box);
  122.         edit_box_draw stdcall (#dst_box);
  123. }
  124.  
  125. //===================================================//
  126. //                                                   //
  127. //                     EVENTS                        //
  128. //                                                   //
  129. //===================================================//
  130.  
  131. #ifndef COPYING
  132. void EventGo()
  133. {
  134.         char run_param[4096];
  135.         sprintf(#run_param, "\"%s\" \"%s\"", #src_path, #dst_path);
  136.         RunProgram(I_Path, #run_param);
  137. }
  138. #endif
  139.  
  140. void EventTabClick()
  141. {
  142.         if ( src_box.flags & ed_focus ) {
  143.                 UpdateEditBoxes(0, ed_focus);
  144.         } else {
  145.                 UpdateEditBoxes(ed_focus, 0);
  146.         }
  147. }
  148.  
  149. void EventOpenDialogFirst()
  150. {
  151.         o_dialog.type = 0; //0-file, 1-save, 2-select folder
  152.         OpenDialog_start stdcall (#o_dialog);
  153.         if (o_dialog.status) {
  154.                 strcpy(#src_path, #openfile_path);
  155.                 UpdateEditBoxes(ed_focus, 0);
  156.         }
  157. }
  158.  
  159. void EventOpenDialogSecond()
  160. {
  161.         #ifdef COPYING
  162.         o_dialog.type = 1; //0-file, 1-save, 2-select folder
  163.         #endif
  164.         OpenDialog_start stdcall (#o_dialog);
  165.         if (o_dialog.status) {
  166.                 strcpy(#dst_path, #openfile_path);
  167.                 UpdateEditBoxes(0, ed_focus);
  168.         }
  169. }
  170.  
  171. void EventInsert()
  172. {
  173.         if ( src_box.flags & ed_focus ) EventOpenDialogFirst();
  174.         if ( dst_box.flags & ed_focus ) EventOpenDialogSecond();
  175. }