Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include "../lib/collection.h"
  3.  
  4. #define SEARCH_H 34
  5.  
  6.  
  7. struct SEARCH
  8. {
  9.         bool visible;
  10.         int found_count;
  11.         collection lines;
  12.         collection pos;
  13.         void show();
  14.         void hide();
  15.         bool draw();
  16.         void draw_found();
  17.         int height();
  18.         bool edit_key();
  19.         bool edit_mouse();
  20.         void add();
  21.         void clear();
  22.         int find_next();
  23.         int highlight();
  24. } search;
  25.  
  26. char search_text[64];
  27. char found_text[64];
  28. edit_box search_box = {250, 10, NULL, 0xffffff,
  29. 0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text};
  30.  
  31.  
  32. void SEARCH::show()
  33. {
  34.         visible = true;
  35.         search_box.flags = ed_focus;
  36.         draw_window();
  37. }
  38.  
  39. void SEARCH::hide()
  40. {
  41.         visible = false;
  42.         draw_window();
  43. }
  44.  
  45. int SEARCH::height()
  46. {
  47.         return visible * SEARCH_H;
  48. }
  49.  
  50. bool SEARCH::edit_key()
  51. {
  52.         if (visible) && (search_box.flags & ed_focus) {
  53.                 EAX = key_editbox;
  54.                 edit_box_key stdcall(#search_box);
  55.                 return true;
  56.         }
  57.         return false;
  58. }
  59.  
  60. bool SEARCH::edit_mouse()
  61. {
  62.         if (visible) {
  63.                 edit_box_mouse stdcall(#search_box);
  64.                 if (search_box.flags & ed_focus) return true;
  65.         }
  66.         return false;
  67. }
  68.  
  69. void SEARCH::draw_found()
  70. {
  71.         strcpy(#param, "Matches: ");
  72.         strcat(#param, itoa(found_count));
  73.         strcat(#param, "   "); 
  74.         WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #param, sc.work);
  75. }
  76.  
  77. bool SEARCH::draw(dword _btn_find, _btn_hide)
  78. {
  79.         if (!visible) return false;
  80.         DrawBar(0,Form.cheight - SEARCH_H, Form.cwidth, 1, sc.work_graph);
  81.         DrawBar(0,Form.cheight - SEARCH_H+1, Form.cwidth, SEARCH_H-1, sc.work);
  82.  
  83.         search_box.top = Form.cheight - SEARCH_H + 6;
  84.         search_box.width = math.min(Form.width - 200, 250);
  85.  
  86.         DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
  87.  
  88.         edit_box_draw stdcall(#search_box);
  89.  
  90.         DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 90,
  91.                 TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, "Find next");
  92.  
  93.         draw_found();
  94.  
  95.         DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1,
  96.                 TOOLBAR_ICON_HEIGHT+1, _btn_hide);
  97.         WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
  98.         return true;
  99. }
  100.  
  101. void SEARCH::clear()
  102. {
  103.         pos.drop();
  104.         lines.drop();
  105.         visible = false;
  106.         found_text[0] = '\0';
  107.         found_count = 0;
  108. }
  109.  
  110. void SEARCH::add(dword _pos, _line)
  111. {
  112.         pos.add(itoa(_pos));
  113.         lines.add(_line);
  114. }
  115.  
  116. int SEARCH::find_next(int _cur_pos, _bg_color)
  117. {
  118.         int i;
  119.         if (!search_text[0]) return false;
  120.  
  121.                 strcpy(#found_text, #search_text);
  122.                 highlight(0xFF0000, _bg_color);
  123.                 draw_found();
  124.  
  125.         for (i=_cur_pos+1; i<pos.count; i++) {
  126.                 if (strstri(lines.get(i),#search_text)!=-1) return atoi(pos.get(i));
  127.         }
  128.         return false;
  129. }
  130.  
  131. int SEARCH::highlight(dword _color, _bg_color)
  132. {
  133.         int i;
  134.         dword col;
  135.         found_count = 0;
  136.         for (i=0; i<pos.count; i++) {
  137.                 if (strstri(lines.get(i),#search_text)==-1) {
  138.                         col=_bg_color;
  139.                 } else {
  140.                         col=_color;
  141.                         found_count++; 
  142.                 }
  143.                 draw_bar(0, atoi(pos.get(i)), 3, list.item_h, col);
  144.         }
  145. }
  146.  
  147. void draw_bar(dword _x, _y, _w, _h, _color)
  148. {
  149.         int i;
  150.         for (i = _y*list.w+_x*KFONT_BPP+kfont.raw ; i<_y*list.w+_x+_w*KFONT_BPP+kfont.raw ; i+=KFONT_BPP)
  151.         {
  152.                 ESDWORD[i] = _color;
  153.         }
  154.         if (_h>0) draw_bar(dword _x, _y+1, _w, _h-1, _color);
  155. }