Subversion Repositories Kolibri OS

Rev

Rev 8190 | 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.  
  5. using namespace Kolibri;
  6.  
  7. const char header[] = "File open";
  8. unsigned char* f_data = 0;
  9.  
  10. bool KolibriOnStart(TStartData &kos_start, TThreadData /*th*/)
  11. {
  12.         kos_start.Left = 10;
  13.         kos_start.Top = 40;
  14.         kos_start.Width = 300;
  15.         kos_start.Height = 220;
  16.         kos_start.WinData.WindowColor = 0xFFFFFF;
  17.         kos_start.WinData.WindowType = 0x34; // 0x34 - fixed, 0x33 - not fixed
  18.         kos_start.WinData.Title = header;
  19.  
  20.         return true;
  21. }
  22.  
  23. void KolibriOnPaint(void)
  24. {
  25.         // If button have ID 1, this is close button
  26.         DrawButton(2,0xf0f0f0, 10,10,50,20);
  27.         DrawText(20,16,0,"1.txt");
  28.         DrawButton(3,0xf0f0f0, 70,10,50,20);
  29.         DrawText(80,16,0,"2.txt");
  30.  
  31.         if (f_data){
  32.                 long i=0, j, y=0;
  33.                 char buf[300];
  34.                 do{
  35.                         j=0;
  36.                         while(f_data[i] && f_data[i]!=13 && f_data[i]!=10){
  37.                                 buf[j]=f_data[i];
  38.                                 i++;
  39.                                 j++;
  40.                         };
  41.                         buf[j]=0;
  42.                         DrawText(10,45+9*y,0,buf);
  43.                         y++;
  44.                         while(f_data[i]==13 || f_data[i]==10) i++;
  45.                 }while(f_data[i]);
  46.         }
  47. }
  48.  
  49. void KolibriOnButton(long id, TThreadData /*th*/)
  50. {
  51.         FileInfoBlock* file;
  52.         unsigned long int k;
  53.  
  54.         switch(id){
  55.         case 2:
  56.                 file = FileOpen("1.txt");
  57.                 if (!file){
  58.                         SetWindowCaption("Error open file '1.txt'");
  59.                         break;
  60.                 }
  61.                 k = FileGetLength(file);
  62.                 if (k > 0){
  63.                         if(f_data) Free(f_data);
  64.                         f_data = (unsigned char*)Alloc(k);
  65.                         if (f_data){
  66.                                 if (FileRead(file, f_data, k) != k){
  67.                                         Free(f_data); f_data = 0;
  68.                                 }
  69.                                 else{
  70.                                         SetWindowCaption("1.txt");
  71.                                         Redraw(1);
  72.                                 }
  73.                         }
  74.                 }
  75.                 FileClose(file);
  76.                 break;
  77.         case 3:
  78.                 file = FileOpen("2.txt");
  79.                 if (!file){
  80.                         SetWindowCaption("Error open file '2.txt'");
  81.                         break;
  82.                 }
  83.                 k = FileGetLength(file);
  84.                 if (k > 0){
  85.                         if(f_data) Free(f_data);
  86.                         f_data = (unsigned char*)Alloc(k);
  87.                         if (f_data){
  88.                                 if (FileRead(file, f_data, k) != k){
  89.                                         Free(f_data); f_data = 0;
  90.                                 }
  91.                                 else{
  92.                                         SetWindowCaption("2.txt");
  93.                                         Redraw(1);
  94.                                 }
  95.                         }
  96.                 }
  97.                 FileClose(file);
  98.                 //break;
  99.         };
  100. }
  101.  
  102. bool KolibriOnClose(TThreadData /*th*/) {
  103.         if(f_data) {Free(f_data); f_data = 0;}
  104.         return true;
  105. }