Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. //===================================================//
  3. //                                                   //
  4. //                      MODULE                       //
  5. //                                                   //
  6. //===================================================//
  7.  
  8. #define TABS_MAX 5
  9.  
  10. TWebBrowser data[TABS_MAX+1];
  11. _history tabstory[TABS_MAX+1];
  12.  
  13. struct TAB
  14. {
  15.         int count;
  16.         signed int active;
  17.         bool add();
  18.         bool close();
  19.         void save_state();
  20.         void restore();
  21. } tab = {1,0};
  22.  
  23.  
  24. bool TAB::add()
  25. {
  26.         if (count==TABS_MAX) return false;
  27.         save_state();
  28.         count++;
  29.         active = count-1;
  30.         history = tabstory[active];
  31.         return true;
  32. }
  33.  
  34. bool TAB::close(int _tab_number)
  35. {
  36.         int i;
  37.         if (count==1) return false;
  38.         for (i=_tab_number; i<=TABS_MAX; i++) {
  39.                 data[i] = data[i+1];
  40.                 tabstory[i] = tabstory[i+1];
  41.         }
  42.         if (_tab_number<active) && (active>0) active--;
  43.         if (active==count-1) && (active>0) active--;
  44.         count--;
  45.         return true;
  46. }
  47.  
  48. void TAB::save_state()
  49. {
  50.         tabstory[active] = history;
  51.         data[active] = WB1;
  52. }
  53.  
  54. void TAB::restore(int _id)
  55. {
  56.         tab.active = _id;
  57.         WB1 = data[_id];       
  58.         history = tabstory[_id];
  59. }
  60.  
  61. //===================================================//
  62. //                                                   //
  63. //                 WebView Actions                   //
  64. //                                                   //
  65. //===================================================//
  66.  
  67. #define DEFAULT_TABW 220
  68. int tab_w = DEFAULT_TABW;
  69.  
  70. int GetTabWidth()
  71. {
  72.         if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else
  73.         return Form.cwidth - TAB_H - 2 / tab.count;
  74. }
  75.  
  76. void DrawTab(int _id)
  77. {
  78.         #define CLOSE_S 13
  79.         dword bgcol, border_bottom_color;
  80.         char header_no_version[sizeof(TWebBrowser.header)];
  81.         char name[DEFAULT_TABW/6];
  82.         int xxx = _id * tab_w;
  83.  
  84.         if (_id==tab.active) {
  85.                 tab.save_state();
  86.                 bgcol = system.color.work_light;
  87.                 border_bottom_color = system.color.work_light;
  88.         } else {
  89.                 bgcol=system.color.work;
  90.                 border_bottom_color = system.color.work_graph;
  91.         }
  92.         if (data[_id].header) {
  93.                 strncpy(#header_no_version, #data[_id].header, strlen(#data[_id].header)-sizeof(version)-2);
  94.                 strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
  95.         }
  96.         DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_dark);
  97.         DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
  98.         DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
  99.         DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
  100.         WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, system.color.work_text, #name);
  101.  
  102.         DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
  103.         DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, system.color.work_dark);
  104.         WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, system.color.work_light, "x");
  105. }
  106.  
  107. void DrawActiveTab()
  108. {
  109.         if (tab_w == GetTabWidth())     DrawTab(tab.active);
  110.         else DrawTabsBar();
  111. }
  112.  
  113. void DrawNewTabButton()
  114. {
  115.         dword btn_light = MixColors(system.color.work_button, 0xFFFfff, 220);
  116.         dword btn_dark = MixColors(system.color.work_button, 0, 180);
  117.         int xxx = tab.count * tab_w;
  118.         DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_graph);
  119.         DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, system.color.work_button);
  120.         DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
  121.         PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
  122.         DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
  123.         WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+");       
  124. }
  125.  
  126. void DrawTabsBar()
  127. {
  128.         dword i;
  129.         tab_w = GetTabWidth();
  130.         for (i=0; i<tab.count; i++) DrawTab(i);
  131.         DrawNewTabButton();
  132.         i = tab_w * i + TAB_H + 2;
  133.         DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(system.color.work_dark, system.color.work, 128));
  134.         DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, system.color.work_graph);
  135. }
  136.  
  137. void EventTabClose(int _id)
  138. {
  139.         DeleteButton(tab.count);
  140.         if (_id == tab.active) {
  141.                 tab.close(_id);
  142.                 tab.restore(tab.active);
  143.                 WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
  144.                 WB1.DrawPage();
  145.                 SetOmniboxText(history.current());
  146.         } else {
  147.                 tab.close(_id);
  148.         }
  149.         DrawTabsBar();
  150. }
  151.  
  152. void EventCloseActiveTab()
  153. {
  154.         EventTabClose(tab.active);
  155. }
  156.  
  157. void EventTabClick(int _id)
  158. {
  159.         if (_id>=tab.count) _id = 0;
  160.         if (_id==-1) _id = tab.count-1;
  161.         tab.save_state();
  162.         tab.restore(_id);
  163.         SetElementSizes();
  164.         if (!BrowserWidthChanged()) {
  165.                 DrawTabsBar();
  166.                 WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
  167.                 WB1.DrawPage();        
  168.         }
  169.         SetOmniboxText(history.current());
  170. }
  171.  
  172. void EventOpenNewTab(dword _url)
  173. {
  174.         tab.add();
  175.         OpenPage(_url);
  176.         DrawTabsBar();
  177. }
  178.  
  179. void EventActivateNextTab()
  180. {
  181.         EventTabClick(tab.active+1);
  182. }
  183.  
  184. void EventActivatePreviousTab()
  185. {
  186.         EventTabClick(tab.active-1);
  187. }
  188.  
  189.  
  190. :void DebugTabs()
  191. {
  192.         debugln("\n\n\nHISTORY==========================");
  193.         history.add("history");
  194.         history.debug();
  195.  
  196.         debugln("\n\n\nTABSTORY[0]======================");
  197.         tabstory[0].add("tabstory0");
  198.         tabstory[0].debug();
  199.  
  200.         debugln("\n\n\nTABSTORY[1]======================");
  201.         tabstory[1].add("tabstory1");
  202.         tabstory[1].debug();
  203.  
  204.         debugln("\n\n\n\n");
  205.         debugval("history.items.data_start", history.items.data_start);
  206.         debugval("tabstory[0].items.data_start", tabstory[0].items.data_start);
  207.         debugval("tabstory[1].items.data_start", tabstory[1].items.data_start);
  208.         debugln("\n\n\n\n");
  209. }
  210.