changeset 2053:416d99f6eb81

Cleanups and bugfix for closing an unselected tab * Removed the invisible widget from the tabbar * Fixed closing the first tab when not selected * Removed a workaround (not necessary anymore)
author Jorge Arellano Cid <jcid@dillo.org>
date Thu, 26 May 2011 19:21:15 -0400
parents 89af8495455f
children 68399783ccec
files src/uicmd.cc
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/uicmd.cc	Thu May 26 21:12:33 2011 +0200
+++ b/src/uicmd.cc	Thu May 26 19:21:15 2011 -0400
@@ -92,9 +92,7 @@
       CustGroupHorizontal(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(0,0,0,0,"i n v i s i b l e");
-      w->box(FL_NO_BOX);
-      resizable(0);
+      resizable(NULL);
       box(FL_FLAT_BOX);
       end();
 
@@ -106,7 +104,7 @@
    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
+   int num_tabs() { return children(); }
    void switch_tab(CustTabButton *cbtn);
    void prev_tab(void);
    void next_tab(void);
@@ -199,7 +197,6 @@
    btn->color(focus ? tabcolor_active : tabcolor_inactive);
    btn->ui(new_ui);
    add(btn);
-   btn->redraw();
    btn->callback(tab_btn_cb, this);
 
    if (focus)
@@ -216,19 +213,19 @@
 {
    CustTabButton *btn;
 
-   // remove label button
-   int idx = get_btn_idx(ui);
-   btn = (CustTabButton*)child(idx);
-   idx > 1 ? prev_tab() : next_tab();
+   // get active tab idx
+   int act_idx = get_btn_idx((UI*)Wizard->value());
+   // get to-be-removed tab idx
+   int rm_idx = get_btn_idx(ui);
+   btn = (CustTabButton*)child(rm_idx);
 
-   // WORKAROUND: with two tabs, closing the non-focused one, doesn't
-   // delete it from screen. This hide() call makes it work.  --Jcid
-   btn->hide();
-
-   remove(idx);
+   if (act_idx == rm_idx) {
+      // Active tab is being closed, switch to another one
+      rm_idx > 0 ? prev_tab() : next_tab();
+   }
+   remove(rm_idx);
    delete btn;
    rearrange();
-   redraw();
 
    Wizard->remove(ui);
    delete(ui);
@@ -242,7 +239,7 @@
 
 int CustTabs::get_btn_idx(UI *ui)
 {
-   for (int i = 1; i <= num_tabs(); ++i) {
+   for (int i = 0; i < num_tabs(); ++i) {
       CustTabButton *btn = (CustTabButton*)child(i);
       if (btn->ui() == ui)
          return i;
@@ -250,6 +247,9 @@
    return -1;
 }
 
+/*
+ * Make cbtn's tab the active one
+ */
 void CustTabs::switch_tab(CustTabButton *cbtn)
 {
    int idx;
@@ -259,7 +259,7 @@
 
    if (cbtn->ui() != old_ui) {
       // Set old tab label to normal color
-      if ((idx = get_btn_idx(old_ui)) > 0) {
+      if ((idx = get_btn_idx(old_ui)) != -1) {
          btn = (CustTabButton*)child(idx);
          btn->color(tabcolor_inactive);
          btn->redraw();
@@ -281,7 +281,7 @@
    int idx;
 
    if ((idx = get_btn_idx((UI*)Wizard->value())) != -1)
-      switch_tab( (CustTabButton*)child(idx > 1 ? idx-1 : num_tabs()) );
+      switch_tab( (CustTabButton*)child(idx > 0 ? idx-1 : num_tabs()-1) );
 }
 
 void CustTabs::next_tab()
@@ -289,7 +289,7 @@
    int idx;
 
    if ((idx = get_btn_idx((UI*)Wizard->value())) != -1)
-      switch_tab( (CustTabButton*)child(idx < num_tabs() ? idx+1 : 1) );
+      switch_tab( (CustTabButton*)child((idx+1 < num_tabs()) ? idx+1 : 0) );
 }
 
 /*
@@ -300,7 +300,7 @@
    char title[128];
    int idx = get_btn_idx(ui);
 
-   if (idx > 0) {
+   if (idx != -1) {
       // Make a label for this tab
       size_t tab_chars = 7, label_len = strlen(label);