changeset 1931:36cec2fa951a

Made remove_tab() work for non-focused tabs
author Jorge Arellano Cid <jcid@dillo.org>
date Wed, 09 Mar 2011 14:26:19 -0300
parents 49dda3dfbcad
children 22d9dd1fb523
files src/uicmd.cc
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/uicmd.cc	Wed Mar 09 14:25:32 2011 -0300
+++ b/src/uicmd.cc	Wed Mar 09 14:26:19 2011 -0300
@@ -93,7 +93,6 @@
       CustGroup(0,0,ww,th,lbl) {
       tab_w = 80, tab_h = th, tab_n = 0, curtab_idx = -1;
       tabcolor_active = FL_DARK_CYAN; tabcolor_inactive = 206;
-      //Fl_Box *w = new Fl_Box(tab_w,0,ww-tab_w,tab_h,"i n v i s i b l e");
       Fl_Box *w = new Fl_Box(0,0,0,0,"i n v i s i b l e");
       w->box(FL_NO_BOX);
       resizable(0);
@@ -101,13 +100,10 @@
 
       Wizard = new Fl_Wizard(0,tab_h,ww,wh-tab_h);
       Wizard->end();
-      printf("Wizard window: %p\n", Wizard->window());
-      //printf("Gui visible: %d\n", Gui->visible());
-      //printf("Gui visible_r: %d\n", Gui->visible_r());
    };
    int handle(int e);
    UI *add_new_tab(int focus);
-   void remove_tab();
+   void remove_tab(UI *ui);
    Fl_Wizard *wizard(void) { return Wizard; }
    int get_btn_idx(UI *ui);
    int num_tabs() { return (children() - 1); } // substract invisible box
@@ -127,15 +123,19 @@
    CustTabs *tabs = (CustTabs*) cb_data;
    int b = Fl::event_button();
 
-   if (b == FL_LEFT_MOUSE)
+   if (b == FL_LEFT_MOUSE) {
       tabs->switch_tab(btn);
+   } else if (b == FL_RIGHT_MOUSE) {
+      // TODO: just an example, not necessarily final
+      a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(btn->ui()));
+   }
 }
 
 int CustTabs::handle(int e)
 {
    int ret = 0;
 
-   //printf("CustTabs::handle e=%s\n", fl_eventnames[e]);
+   _MSG("CustTabs::handle e=%s\n", fl_eventnames[e]);
    if (e == FL_KEYBOARD) {
       return 0; // Receive as shortcut
    } else if (e == FL_SHORTCUT) {
@@ -151,16 +151,16 @@
          a_UIcmd_close_bw(bw);
          ret = 1;
       } else if (cmd == KEYS_LEFT_TAB) {
-         printf("CustTabs::handle KEYS_LEFT_TAB\n");
+         MSG("CustTabs::handle KEYS_LEFT_TAB\n");
          ret = 1;
       } else if (cmd == KEYS_RIGHT_TAB) {
-         printf("CustTabs::handle KEYS_RIGHT_TAB\n");
+         MSG("CustTabs::handle KEYS_RIGHT_TAB\n");
          ret = 1;
       } else if (cmd == KEYS_NEW_WINDOW) {
          a_UIcmd_browser_window_new(ui->w(),ui->h()+this->h(),0,bw);
          ret = 1;
       } else if (cmd == KEYS_FULLSCREEN) {
-         printf("CustTabs::handle KEYS_FULLSCREEN\n");
+         MSG("CustTabs::handle KEYS_FULLSCREEN\n");
          ret = 1;
       } else if (cmd == KEYS_CLOSE_ALL) {
          a_Timeout_add(0.0, a_UIcmd_close_all_bw, NULL);
@@ -216,10 +216,12 @@
    return new_ui;
 }
 
-void CustTabs::remove_tab()
+/*
+ * Remove tab by UI
+ */
+void CustTabs::remove_tab(UI *ui)
 {
    CustTabButton *btn;
-   UI *ui = (UI*)Wizard->value();
 
    // remove label button
    int idx = get_btn_idx(ui);
@@ -228,6 +230,7 @@
    remove(idx);
    delete btn;
    rearrange();
+   //TODO: redraw doesn't work sometimes
    redraw();
 
    Wizard->remove(ui);
@@ -334,8 +337,9 @@
    BrowserWindow *bw;
    for (int i = 0; i < a_Bw_num(); ++i) {
       bw = a_Bw_get(i);
-      if (((Fl_Widget*)bw->ui)->contains((Fl_Widget*)v_wid))
+      if (((UI*)bw->ui)->contains((Fl_Widget*)v_wid)) {
          return bw;
+      }
    }
    return NULL;
 }
@@ -447,7 +451,7 @@
    //TODO: sometimes this call segfaults upon exit
    delete(layout);
    if (ui->tabs()) {
-      ui->tabs()->remove_tab();
+      ui->tabs()->remove_tab(ui);
    }
    a_Bw_free(bw);
 }