Subversion Repositories Kolibri OS

Rev

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

  1. #include <kolibri.h>
  2. #include <kos_heap.h>
  3. #include <kos_file.h>
  4. #include <load_lib.h>
  5. #include <l_proc_lib.h>
  6.  
  7. using namespace Kolibri;
  8.  
  9. const char header[] = "Open Dialog";
  10. char library_path[2048];
  11.  
  12. OpenDialog_data ofd;
  13. unsigned char procinfo[1024];
  14. char plugin_path[4096], openfile_path[4096], filename_area[256];
  15. od_filter filter1 = { 8, "TXT\0\0" };
  16.  
  17. namespace Kolibri{
  18.         char CurrentDirectoryPath[2048];
  19. }
  20.  
  21. void KolibriOnPaint(void);
  22.  
  23. void __stdcall DrawWindow()
  24. {
  25.         asm{
  26.                 push ebx
  27.                 mcall SF_REDRAW,SSF_BEGIN_DRAW
  28.         }
  29.         KolibriOnPaint();
  30.         asm{
  31.                 mcall SF_REDRAW,SSF_END_DRAW
  32.                 pop ebx
  33.         }
  34. }
  35.  
  36. bool KolibriOnStart(TStartData &kos_start, TThreadData /*th*/)
  37. {
  38.         kos_start.Left = 10;
  39.         kos_start.Top = 40;
  40.         kos_start.Width = 420;
  41.         kos_start.Height = 320;
  42.         kos_start.WinData.WindowColor = 0xFFFFFF;
  43.         kos_start.WinData.WindowType = 0x33; // 0x34 - fixed, 0x33 - not fixed
  44.         kos_start.WinData.Title = header;
  45.         if(LoadLibrary("proc_lib.obj", library_path, "/sys/lib/proc_lib.obj", &import_proc_lib))
  46.         {
  47.                 ofd.procinfo = procinfo;
  48.                 ofd.com_area_name = "FFFFFFFF_open_dialog";
  49.                 ofd.com_area = 0;
  50.                 ofd.opendir_path = plugin_path;
  51.                 ofd.dir_default_path = "/rd/1";
  52.                 ofd.start_path = "/rd/1/File managers/opendial";
  53.                 ofd.draw_window = DrawWindow;
  54.                 ofd.status = 0;
  55.                 ofd.openfile_path = openfile_path;
  56.                 ofd.filename_area = filename_area;
  57.                 ofd.filter_area = &filter1;
  58.                 ofd.x_size = 420;
  59.                 ofd.x_start = 10;
  60.                 ofd.y_size = 320;
  61.                 ofd.y_start = 10;
  62.                 OpenDialog_Init(&ofd);
  63.         } else return false;
  64.         return true;
  65. }
  66.  
  67. void KolibriOnPaint(void)
  68. {
  69.         // If button have ID 1, this is close button
  70.         DrawButton(2,0xf0f0f0, 10,10,50,20);
  71.         DrawText(20,16,0,"Open");
  72.         DrawButton(3,0xf0f0f0, 70,10,50,20);
  73.         DrawText(80,16,0,"Save");
  74.         DrawButton(4,0xf0f0f0, 130,10,95,20);
  75.         DrawText(140,16,0,"Select folder");
  76.  
  77.         if(ofd.openfile_path[0]) DrawText(10,40,0,ofd.openfile_path);
  78.         if(ofd.opendir_path[0])  DrawText(10,55,0,ofd.opendir_path);
  79.         if(ofd.filename_area[0]) DrawText(10,70,0,ofd.filename_area);
  80. }
  81.  
  82. void KolibriOnButton(long id, TThreadData /*th*/)
  83. {
  84.         FileInfoBlock* file;
  85.         long int k;
  86.  
  87.         switch(id){
  88.         case 2:
  89.                 ofd.type = 0; // 0 - open
  90.                 OpenDialog_Start(&ofd);
  91.                 if(ofd.status==1){
  92.                         //... open ...
  93.                 }
  94.                 break;
  95.         case 3:
  96.                 ofd.type = 1; // 1 - save
  97.                 OpenDialog_Start(&ofd);
  98.                 if(ofd.status==1){
  99.                         //... save ...
  100.                 }
  101.                 break;
  102.         case 4:
  103.                 ofd.type = 2; // 2 - select folder
  104.                 OpenDialog_Start(&ofd);
  105.                 if(ofd.status==1){
  106.                         //...
  107.                 }
  108.                 //break;
  109.         };
  110. }
  111.