From b0357cf1928e75b4128e6d4366897fc75449a28b Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Thu, 26 May 2011 19:21:15 -0400 Subject: 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) --- src/uicmd.cc | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/uicmd.cc b/src/uicmd.cc index a28128c8..575fa082 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -92,9 +92,7 @@ public: 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 @@ public: 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 @@ UI *CustTabs::add_new_tab(UI *old_ui, int focus) 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 @@ void CustTabs::remove_tab(UI *ui) { CustTabButton *btn; - // remove label button - int idx = get_btn_idx(ui); - btn = (CustTabButton*)child(idx); - idx > 1 ? prev_tab() : next_tab(); - - // WORKAROUND: with two tabs, closing the non-focused one, doesn't - // delete it from screen. This hide() call makes it work. --Jcid - btn->hide(); + // 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); - 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 @@ void CustTabs::remove_tab(UI *ui) 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 @@ int CustTabs::get_btn_idx(UI *ui) return -1; } +/* + * Make cbtn's tab the active one + */ void CustTabs::switch_tab(CustTabButton *cbtn) { int idx; @@ -259,7 +259,7 @@ void CustTabs::switch_tab(CustTabButton *cbtn) 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 @@ void CustTabs::prev_tab() 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 @@ void CustTabs::next_tab() 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 @@ void CustTabs::set_tab_label(UI *ui, const char *label) 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); -- cgit v1.2.3 From a5e0529ddbbebe32ca3a652e53926389fbd00379 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Fri, 27 May 2011 09:47:48 -0400 Subject: Hide tabbar when (tabs == 1), show tabbar when (tabs >= 2) --- src/uicmd.cc | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/uicmd.cc b/src/uicmd.cc index 575fa082..275b059f 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -84,19 +84,20 @@ public: * Allows fine control of the tabbed interface */ class CustTabs : public CustGroupHorizontal { - int tab_w, tab_h, tab_n; + int tab_w, tab_h, ctab_h, tab_n; Fl_Wizard *Wizard; int tabcolor_inactive, tabcolor_active, curtab_idx; public: CustTabs (int ww, int wh, int th, const char *lbl=0) : CustGroupHorizontal(0,0,ww,th,lbl) { - tab_w = 80, tab_h = th, tab_n = 0, curtab_idx = -1; + tab_w = 80, tab_h = th, ctab_h = 1, tab_n = 0, curtab_idx = -1; tabcolor_active = FL_DARK_CYAN; tabcolor_inactive = 206; + resize(0,0,ww,ctab_h); resizable(NULL); box(FL_FLAT_BOX); end(); - Wizard = new Fl_Wizard(0,tab_h,ww,wh-tab_h); + Wizard = new Fl_Wizard(0,ctab_h,ww,wh-ctab_h); Wizard->end(); }; int handle(int e); @@ -182,14 +183,23 @@ UI *CustTabs::add_new_tab(UI *old_ui, int focus) { char tab_label[64]; + if (num_tabs() == 1) { + // Show tabbar + ctab_h = tab_h; + Wizard->resize(0,ctab_h,Wizard->w(),window()->h()-ctab_h); + resize(0,0,window()->w(),ctab_h); // tabbar + child(0)->show(); // first tab button + window()->init_sizes(); + } + current(0); - UI *new_ui = new UI(0,tab_h,Wizard->w(),Wizard->h(),0,old_ui); + UI *new_ui = new UI(0,ctab_h,Wizard->w(),Wizard->h(),0,old_ui); new_ui->tabs(this); Wizard->add(new_ui); new_ui->show(); snprintf(tab_label, 64,"ctab%d", ++tab_n); - CustTabButton *btn = new CustTabButton(num_tabs()*tab_w,0,tab_w,tab_h); + CustTabButton *btn = new CustTabButton(num_tabs()*tab_w,0,tab_w,ctab_h); btn->align(FL_ALIGN_INSIDE|FL_ALIGN_CLIP); btn->copy_label(tab_label); btn->clear_visible_focus(); @@ -201,6 +211,8 @@ UI *CustTabs::add_new_tab(UI *old_ui, int focus) if (focus) switch_tab(btn); + if (num_tabs() == 1) + btn->hide(); rearrange(); return new_ui; @@ -234,6 +246,15 @@ void CustTabs::remove_tab(UI *ui) window()->hide(); // TODO: free memory //delete window(); + + } else if (num_tabs() == 1) { + // hide tabbar + ctab_h = 1; + child(0)->hide(); // first tab button + resize(0,0,window()->w(),ctab_h); // tabbar + Wizard->resize(0,ctab_h,Wizard->w(),window()->h()-ctab_h); + window()->init_sizes(); + window()->redraw(); } } -- cgit v1.2.3 From 57b8dfc2cce6d65927d11fbc15667b5a410fb3de Mon Sep 17 00:00:00 2001 From: corvid Date: Fri, 27 May 2011 15:20:08 +0000 Subject: rm fltk2 workaround Haven't found any need for it with 1.3. --- dw/fltkui.cc | 11 +---------- src/ui.cc | 9 ++------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/dw/fltkui.cc b/dw/fltkui.cc index f3192c22..62928ed4 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -513,16 +513,7 @@ void FltkEntryResource::sizeRequest (core::Requisition *requisition) void FltkEntryResource::widgetCallback (Fl_Widget *widget, void *data) { - /* The (::fltk::event_key() == FL_Enter) test - * is necessary because WHEN_ENTER_KEY also includes - * other events we're not interested in. For instance pressing - * The Back or Forward, buttons, or the first click on a rendered - * page. BUG: this must be investigated and reported to FLTK2 team - */ - _MSG("when = %d\n", widget->when ()); - if ((widget->when () & FL_WHEN_ENTER_KEY_ALWAYS) && - (Fl::event_key() == FL_Enter)) - ((FltkEntryResource*)data)->emitActivate (); + ((FltkEntryResource*)data)->emitActivate (); } const char *FltkEntryResource::getText () diff --git a/src/ui.cc b/src/ui.cc index 1004bfdc..30106c21 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -320,13 +320,8 @@ static void location_cb(Fl_Widget *wid, void *data) UI *ui = (UI*)data; _MSG("location_cb()\n"); - /* This test is necessary because WHEN_ENTER_KEY also includes - * other events we're not interested in. For instance pressing - * The Back or Forward, buttons, or the first click on a rendered - * page. BUG: this must be investigated and reported to FLTK2 team */ - if (Fl::event_key() == FL_Enter) { - a_UIcmd_open_urlstr(a_UIcmd_get_bw_by_widget(i), i->value()); - } + a_UIcmd_open_urlstr(a_UIcmd_get_bw_by_widget(i), i->value()); + if (ui->get_panelmode() == UI_TEMPORARILY_SHOW_PANELS) { ui->set_panelmode(UI_HIDDEN); } -- cgit v1.2.3 From 9b72578eab16832c7bf70984fb528339a3994e32 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Fri, 27 May 2011 13:26:15 -0400 Subject: Avoid unnecessary background redraws --- src/ui.cc | 4 ++++ src/uicmd.cc | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/ui.cc b/src/ui.cc index 30106c21..6fc769c8 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -591,6 +591,7 @@ void UI::make_panel(int ww) current(0); if (PanelSize == P_tiny) { NavBar = new CustGroupHorizontal(0,0,ww,nh); + NavBar->box(FL_NO_BOX); NavBar->begin(); make_toolbar(ww,bh); make_filemenu_button(); @@ -622,6 +623,7 @@ void UI::make_panel(int ww) TopGroup->insert(*LocBar,1); } else { LocBar = new CustGroupHorizontal(0,0,ww,lh); + LocBar->box(FL_NO_BOX); LocBar->begin(); p_xpos = 0; make_filemenu_button(); @@ -635,6 +637,7 @@ void UI::make_panel(int ww) // Toolbar p_ypos = 0; NavBar = new CustGroupHorizontal(0,0,ww,bh); + NavBar->box(FL_NO_BOX); NavBar->begin(); make_toolbar(ww,bh); w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh); @@ -659,6 +662,7 @@ void UI::make_status_bar(int ww, int wh) { const int bm_w = 20; StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh); + StatusBar->box(FL_NO_BOX); // Status box StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh); diff --git a/src/uicmd.cc b/src/uicmd.cc index 275b059f..68550e41 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -98,6 +98,7 @@ public: end(); Wizard = new Fl_Wizard(0,ctab_h,ww,wh-ctab_h); + Wizard->box(FL_NO_BOX); Wizard->end(); }; int handle(int e); @@ -431,6 +432,7 @@ static BrowserWindow *UIcmd_tab_new(CustTabs *tabs, UI *old_ui, int focus) // set_render_layout() sets the proper viewport size FltkViewport *viewport = new FltkViewport (0, 0, 0, 1); + viewport->box(FL_NO_BOX); viewport->setBufferedDrawing (prefs.buffered_drawing ? true : false); layout->attachView (viewport); new_ui->set_render_layout(viewport); -- cgit v1.2.3 From 037c25162ba7a36e600f4e1366a206e4abf05020 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Fri, 27 May 2011 13:27:11 -0400 Subject: Make sources fit in 80 columns --- dw/fltkplatform.cc | 3 ++- dw/fltkui.hh | 3 ++- dw/image.cc | 6 +++--- dw/layout.hh | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index 70d9cfd2..00e1d07e 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -42,7 +42,8 @@ container::typed::HashTable (false, false); container::typed::HashTable *FltkFont::systemFonts = NULL; + FltkFont::FontFamily> *FltkFont::systemFonts = + NULL; FltkFont::FontFamily FltkFont::standardFontFamily; diff --git a/dw/fltkui.hh b/dw/fltkui.hh index 074a6166..daddfb78 100644 --- a/dw/fltkui.hh +++ b/dw/fltkui.hh @@ -402,7 +402,8 @@ private: public: Group (FltkRadioButtonResource *radioButtonResource); - inline lout::container::typed::Iterator iterator () + inline lout::container::typed::Iterator + iterator () { return list->iterator (); } diff --git a/dw/image.cc b/dw/image.cc index 23e2dc84..827cd753 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -315,8 +315,8 @@ bool Image::buttonPressImpl (core::EventButton *event) { bool ret = false; - currLink = mapList? mapList->link (mapKey, contentX(event),contentY(event)): - getStyle()->x_link; + currLink = mapList ? mapList->link(mapKey,contentX(event),contentY(event)) : + getStyle()->x_link; if (event->button == 3){ (void)layout->emitLinkPress(this, currLink, getStyle()->x_img, -1, -1, event); @@ -330,7 +330,7 @@ bool Image::buttonPressImpl (core::EventButton *event) bool Image::buttonReleaseImpl (core::EventButton *event) { - currLink = mapList ? mapList->link (mapKey, contentX(event),contentY(event)): + currLink = mapList ? mapList->link(mapKey,contentX(event),contentY(event)) : getStyle()->x_link; if (clicking) { int x = isMap ? contentX(event) : -1; diff --git a/dw/layout.hh b/dw/layout.hh index dc9bf227..0ac1ea5b 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -152,7 +152,8 @@ private: bool scrollIdleNotInterrupted; /* Anchors of the widget tree */ - lout::container::typed::HashTable *anchorsTable; + lout::container::typed::HashTable + *anchorsTable; SelectionState selectionState; FindtextState findtextState; -- cgit v1.2.3