Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #define SEARCH_H 34
  3.  
  4.  
  5. struct SEARCH
  6. {
  7.         bool visible;
  8.         int found_count;
  9.         collection_int found;
  10.         void show();
  11.         void hide();
  12.         bool draw();
  13.         bool edit_key();
  14.         bool edit_mouse();
  15.         int find_all();
  16.         int find_next();
  17. } search;
  18.  
  19. char found_text[64];
  20.  
  21. char search_text[64];
  22. edit_box search_box = {250, 10, NULL, 0xffffff,
  23. 0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text};
  24.  
  25.  
  26. void SEARCH::show()
  27. {
  28.         visible = true;
  29.         search_box.flags = ed_focus;
  30.         draw_window();
  31. }
  32.  
  33. void SEARCH::hide()
  34. {
  35.         visible = false;
  36.         draw_window();
  37. }
  38.  
  39. bool SEARCH::edit_key()
  40. {
  41.         if (visible) && (search_box.flags & ed_focus) {
  42.                 EAX = key_editbox;
  43.                 edit_box_key stdcall(#search_box);
  44.                 return true;
  45.         }
  46.         return false;
  47. }
  48.  
  49. bool SEARCH::edit_mouse()
  50. {
  51.         if (visible) {
  52.                 edit_box_mouse stdcall(#search_box);
  53.                 if (search_box.flags & ed_focus) return true;
  54.         }
  55.         return false;
  56. }
  57.  
  58. bool SEARCH::draw(dword _btn_find, _btn_hide, _y)
  59. {
  60.         char matches[30];
  61.         if (!visible) return false;
  62.         DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
  63.         DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
  64.  
  65.         search_box.top = _y + 6;
  66.         search_box.width = math.min(Form.width - 200, 150);
  67.  
  68.         DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
  69.  
  70.         edit_box_draw stdcall(#search_box);
  71.  
  72.         DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 100,
  73.                 TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, T_FIND_NEXT);
  74.  
  75.         sprintf(#matches, T_MATCHES, found.count);
  76.         WriteTextWithBg(search_box.left+search_box.width+14+115,
  77.                 search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
  78.  
  79.         DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1,
  80.                 TOOLBAR_ICON_HEIGHT+1, _btn_hide);
  81.         WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
  82.         return true;
  83. }
  84.  
  85. int SEARCH::find_all()
  86. {
  87.         dword haystack = io.buffer_data;
  88.         int needle_len = strlen(#found_text);
  89.         found.drop();
  90.         loop() {
  91.                 if (! haystack = strstri(haystack, #found_text)) break;
  92.                 found.add(haystack - needle_len);
  93.                 haystack += needle_len;
  94.         }
  95. }
  96.  
  97. int SEARCH::find_next(int _cur_pos)
  98. {
  99.         int i;
  100.         dword t1, t2;
  101.         if (!search_text[0]) return false;
  102.  
  103.         if (!streq(#found_text, #search_text)) {
  104.                 strcpy(#found_text, #search_text);
  105.                 find_all();
  106.                 draw_window();
  107.         }
  108.  
  109.         for (i=0; i<found.count; i++) {
  110.                 if (signed found.get(i) - lines.get(_cur_pos) > 0) {
  111.                         t1 = found.get(i);
  112.                         while(t1 > lines.get(_cur_pos)) _cur_pos++;    
  113.                         return _cur_pos-1;
  114.                 }
  115.         }
  116.         return false;
  117. }
  118.  
  119.