Subversion Repositories Kolibri OS

Rev

Rev 7975 | 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 edit_key();
  13.         bool edit_mouse();
  14.         int find_all();
  15.         int find_next();
  16.         int find_prior();
  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. int SEARCH::find_all()
  59. {
  60.         dword haystack = textbuf.p;
  61.         int needle_len = strlen(#found_text);
  62.         found.drop();
  63.         loop() {
  64.                 if (! haystack = strstri(haystack, #found_text)) break;
  65.                 found.add(haystack - needle_len);
  66.                 haystack += needle_len;
  67.         }
  68. }
  69.  
  70. int SEARCH::find_next(int _first)
  71. {
  72.         int i;
  73.         if (!search_text[0]) return false;
  74.  
  75.         if (!streq(#found_text, #search_text)) {
  76.                 strcpy(#found_text, #search_text);
  77.                 find_all();
  78.                 draw_window();
  79.         }
  80.  
  81.         for (i=0; i<found.count; i++) {
  82.                 if (signed found.get(i) - lines.get(_first) > 0) {
  83.                         while(signed found.get(i) - lines.get(_first) > 0) _first++;
  84.                         return _first-1;
  85.                 }
  86.         }
  87.         return false;
  88. }
  89.  
  90. int SEARCH::find_prior(int _first)
  91. {
  92.         int i;
  93.         if (!search_text[0]) return false;
  94.  
  95.         if (!streq(#found_text, #search_text)) {
  96.                 strcpy(#found_text, #search_text);
  97.                 find_all();
  98.                 draw_window();
  99.         }
  100.  
  101.         for (i=0; i<found.count; i++) {
  102.                 if (signed found.get(i) - lines.get(_first) > 0) {
  103.                         while(signed lines.get(_first) - found.get(i-1) > 0) _first--;
  104.                         return _first;
  105.                 }
  106.         }
  107.         return false;
  108. }
  109.