Subversion Repositories Kolibri OS

Rev

Rev 7872 | 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.         char matches[30];
  72.         strcpy(#matches, "Matches: ");
  73.         strcat(#matches, itoa(found_count));
  74.         strcat(#matches, "   ");       
  75.         WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
  76. }
  77.  
  78. bool SEARCH::draw(dword _btn_find, _btn_hide, _y)
  79. {
  80.         if (!visible) return false;
  81.         DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
  82.         DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
  83.  
  84.         search_box.top = _y + 6;
  85.         search_box.width = math.min(Form.width - 200, 250);
  86.  
  87.         DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
  88.  
  89.         edit_box_draw stdcall(#search_box);
  90.  
  91.         DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 90,
  92.                 TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, "Find next");
  93.  
  94.         draw_found();
  95.  
  96.         DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1,
  97.                 TOOLBAR_ICON_HEIGHT+1, _btn_hide);
  98.         WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
  99.         return true;
  100. }
  101.  
  102. void SEARCH::clear()
  103. {
  104.         pos.drop();
  105.         lines.drop();
  106.         visible = false;
  107.         found_text[0] = '\0';
  108.         found_count = 0;
  109. }
  110.  
  111. void SEARCH::add(dword _pos, _line)
  112. {
  113.         pos.add(itoa(_pos));
  114.         lines.add(_line);
  115. }
  116.  
  117. int SEARCH::find_next(int _cur_pos, _bg_color)
  118. {
  119.         int i;
  120.         if (!search_text[0]) return false;
  121.  
  122.                 strcpy(#found_text, #search_text);
  123.                 highlight(0xFF0000, _bg_color);
  124.                 draw_found();
  125.  
  126.         for (i=_cur_pos+1; i<pos.count; i++) {
  127.                 if (strstri(lines.get(i),#search_text)!=-1) return atoi(pos.get(i));
  128.         }
  129.         return false;
  130. }
  131.  
  132. int SEARCH::highlight(dword _color, _bg_color)
  133. {
  134.         int i;
  135.         dword col;
  136.         found_count = 0;
  137.         for (i=0; i<pos.count; i++) {
  138.                 if (strstri(lines.get(i),#search_text)==-1) {
  139.                         col=_bg_color;
  140.                 } else {
  141.                         col=_color;
  142.                         found_count++; 
  143.                 }
  144.                 //draw_bar(0, atoi(pos.get(i)), 3, list.item_h, col);
  145.         }
  146. }
  147.  
  148. :void draw_bar(dword _x, _y, _w, _h, _color)
  149. {
  150.         int i;
  151.         for (i = _y*list.w+_x*4+kfont.raw ; i<_y*list.w+_x+_w*4+kfont.raw ; i+=4)
  152.         {
  153.                 ESDWORD[i] = _color;
  154.         }
  155.         if (_h>0) draw_bar(dword _x, _y+1, _w, _h-1, _color);
  156. }