Subversion Repositories Kolibri OS

Rev

Rev 7778 | Rev 7799 | 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 == TABS_MAX) return Form.cwidth / tab.count;
  73.         if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else
  74.         return Form.cwidth - TAB_H - 2 / tab.count;
  75. }
  76.  
  77. void DrawTab(int _id)
  78. {
  79.         #define CLOSE_S 13
  80.         dword bgcol, border_bottom_color;
  81.         char header_no_version[sizeof(TWebBrowser.header)];
  82.         char name[DEFAULT_TABW/6];
  83.         int xxx = _id * tab_w;
  84.  
  85.         if (_id==tab.active) {
  86.                 tab.save_state();
  87.                 bgcol = system.color.work_light;
  88.                 border_bottom_color = system.color.work_light;
  89.         } else {
  90.                 bgcol=system.color.work;
  91.                 border_bottom_color = system.color.work_graph;
  92.         }
  93.         if (data[_id].header) {
  94.                 strncpy(#header_no_version, #data[_id].header, strlen(#data[_id].header)-sizeof(version)-2);
  95.                 strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
  96.         }
  97.         DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_dark);
  98.         DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
  99.         DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
  100.         DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
  101.         WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, system.color.work_text, #name);
  102.  
  103.         DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
  104.         DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, system.color.work_dark);
  105.         WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, system.color.work_light, "x");
  106. }
  107.  
  108. void DrawActiveTab()
  109. {
  110.         if (tab_w == GetTabWidth())     DrawTab(tab.active);
  111.         else DrawTabsBar();
  112. }
  113.  
  114. int DrawNewTabButton()
  115. {
  116.         dword btn_light = MixColors(system.color.work_button, 0xFFFfff, 220);
  117.         dword btn_dark = MixColors(system.color.work_button, 0, 180);
  118.         int xxx = tab.count * tab_w;
  119.  
  120.         if (tab.count < TABS_MAX) {
  121.                 DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_graph);
  122.                 DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, system.color.work_button);
  123.                 DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
  124.                 PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
  125.                 DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
  126.                 WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+");
  127.                 return xxx + TAB_H + 2;
  128.         } else {
  129.                 return xxx;
  130.         }
  131. }
  132.  
  133. void DrawTabsBar()
  134. {
  135.         dword i;
  136.         tab_w = GetTabWidth();
  137.         for (i=0; i<tab.count; i++) DrawTab(i);
  138.         i = DrawNewTabButton();
  139.         DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(system.color.work_dark, system.color.work, 128));
  140.         DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, system.color.work_graph);
  141. }
  142.  
  143. void EventTabClose(int _id)
  144. {
  145.         DeleteButton(tab.count);
  146.         if (_id == tab.active) {
  147.                 tab.close(_id);
  148.                 tab.restore(tab.active);
  149.                 WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
  150.                 WB1.DrawPage();
  151.                 SetOmniboxText(history.current());
  152.         } else {
  153.                 tab.close(_id);
  154.         }
  155.         DrawTabsBar();
  156. }
  157.  
  158. void EventCloseActiveTab()
  159. {
  160.         EventTabClose(tab.active);
  161. }
  162.  
  163. void EventTabClick(int _id)
  164. {
  165.         if (_id>=tab.count) _id = 0;
  166.         if (_id==-1) _id = tab.count-1;
  167.         tab.save_state();
  168.         tab.restore(_id);
  169.         SetElementSizes();
  170.         if (!BrowserWidthChanged()) {
  171.                 DrawTabsBar();
  172.                 WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
  173.                 WB1.DrawPage();        
  174.         }
  175.         SetOmniboxText(history.current());
  176. }
  177.  
  178. void EventOpenNewTab(dword _url)
  179. {
  180.         tab.add();
  181.         OpenPage(_url);
  182.         DrawTabsBar();
  183. }
  184.  
  185. void EventActivateNextTab()
  186. {
  187.         EventTabClick(tab.active+1);
  188. }
  189.  
  190. void EventActivatePreviousTab()
  191. {
  192.         EventTabClick(tab.active-1);
  193. }
  194.  
  195.  
  196. :void DebugTabs()
  197. {
  198.         debugln("\n\n\nHISTORY==========================");
  199.         history.add("history");
  200.         history.debug();
  201.  
  202.         debugln("\n\n\nTABSTORY[0]======================");
  203.         tabstory[0].add("tabstory0");
  204.         tabstory[0].debug();
  205.  
  206.         debugln("\n\n\nTABSTORY[1]======================");
  207.         tabstory[1].add("tabstory1");
  208.         tabstory[1].debug();
  209.  
  210.         debugln("\n\n\n\n");
  211.         debugval("history.items.data_start", history.items.data_start);
  212.         debugval("tabstory[0].items.data_start", tabstory[0].items.data_start);
  213.         debugval("tabstory[1].items.data_start", tabstory[1].items.data_start);
  214.         debugln("\n\n\n\n");
  215. }
  216.