diff options
author | jcid <devnull@localhost> | 2008-09-18 00:16:38 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-09-18 00:16:38 +0200 |
commit | f9da96dd24c8f8c83a88d0ed77d562aa456a33c4 (patch) | |
tree | 6a950a2728516159bde5d3d0da5c932cbbb21542 /src/uicmd.cc | |
parent | d61666920e33d15d25ac6381e4f4c64f66165493 (diff) |
- Implemented tabbed browsing.
Diffstat (limited to 'src/uicmd.cc')
-rw-r--r-- | src/uicmd.cc | 120 |
1 files changed, 91 insertions, 29 deletions
diff --git a/src/uicmd.cc b/src/uicmd.cc index ca716692..7e77096c 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -16,6 +16,7 @@ #include <stdarg.h> #include <math.h> /* for rint */ #include <fltk/Widget.h> +#include <fltk/TabGroup.h> #include "dir.h" #include "ui.hh" @@ -32,53 +33,100 @@ #include "nav.h" +// Handy macro +#define BW2UI(bw) ((UI*)(bw->ui)) + // Platform idependent part using namespace dw::core; // FLTK related using namespace dw::fltk; -typedef struct { - UI *ui; - BrowserWindow *bw; -} Uibw; /* * Local data */ -// A matching table for all open ui/bw pairs -// BUG: must be dynamic. -static Uibw uibws[32]; -static int uibws_num = 0, uibws_max = 32; - static char *save_dir = NULL; using namespace fltk; +// +// For custom handling of keyboard +// +class CustTabGroup : public fltk::TabGroup { +public: + CustTabGroup (int x, int y, int ww, int wh, const char *lbl=0) : + TabGroup(x,y,ww,wh,lbl) {}; + int handle(int e) { + // Don't focus with arrow keys + _MSG("CustTabGroup::handle %d\n", e); + int k = event_key(); + // We're only interested in some flags + unsigned modifier = event_state() & (SHIFT | CTRL | ALT); + if (e == KEY) { + if (k == UpKey || k == DownKey || k == TabKey) { + return 0; + } else if (k == LeftKey || k == RightKey) { + if (modifier == SHIFT) { + int i = value(); + if (k == LeftKey) {i = i ? i-1 : children()-1;} + else {i++; if (i >= children()) i = 0;} + if (value(i)) do_callback(); + return 1; + } + return 0; + } + } + return TabGroup::handle(e); + } +}; + /* * Create a new UI and its associated BrowserWindow data structure. * Use style from v_ui. If non-NULL it must be of type UI*. */ -BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *v_ui) +BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *vbw) { + static TabGroup *DilloTabs = NULL; + BrowserWindow *old_bw = (BrowserWindow*)vbw; + BrowserWindow *new_bw = NULL; + if (ww <= 0 || wh <= 0) { // Set default geometry from dillorc. ww = prefs.width; wh = prefs.height; } + if (!DilloTabs) { + {Window *o = new Window(ww, wh); + o->shortcut(0); // Ignore Escape + o->clear_double_buffer(); + DilloTabs = new CustTabGroup(0, 0, ww, wh); + DilloTabs->selection_color(156); + //DilloTabs->clear_tab_to_focus(); + o->add(DilloTabs); + } + wh -= 20; + } + // Create and set the UI - UI *new_ui = new UI(ww, wh, "Dillo: UI", (UI*) v_ui); + UI *new_ui = new UI(0, 20, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL); new_ui->set_status("http://www.dillo.org/"); + new_ui->tabs(DilloTabs); //new_ui->set_location("http://dillo.org/"); //new_ui->customize(12); - if (v_ui == NULL && prefs.xpos >= 0 && prefs.ypos >= 0) { + DilloTabs->add(new_ui); + DilloTabs->resizable(new_ui); + DilloTabs->window()->resizable(new_ui); + DilloTabs->window()->show(); + + if (old_bw == NULL && prefs.xpos >= 0 && prefs.ypos >= 0) { // position the first window according to preferences fltk::Rectangle r; - new_ui->borders(&r); + new_ui->window()->borders(&r); // borders() gives x and y border sizes as negative values - new_ui->position(prefs.xpos - r.x(), prefs.ypos - r.y()); + new_ui->window()->position(prefs.xpos - r.x(), prefs.ypos - r.y()); } // Now create the Dw render layout and viewport @@ -93,24 +141,16 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *v_ui) viewport->setScrollStep((int) rint(14.0 * prefs.font_factor)); // Now, create a new browser window structure - BrowserWindow *new_bw = a_Bw_new(); + new_bw = a_Bw_new(); + + // Store new_bw for callback data inside UI + new_ui->vbw(new_bw); - // Set new_bw as callback data for UI - new_ui->user_data(new_bw); // Reference the UI from the bw new_bw->ui = (void *)new_ui; // Copy the layout pointer into the bw data new_bw->render_layout = (void*)layout; - // insert the new ui/bw pair in the table - if (uibws_num < uibws_max) { - uibws[uibws_num].ui = new_ui; - uibws[uibws_num].bw = new_bw; - uibws_num++; - } - - new_ui->show(); - return new_bw; } @@ -120,12 +160,19 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *v_ui) void a_UIcmd_close_bw(void *vbw) { BrowserWindow *bw = (BrowserWindow *)vbw; - UI *ui = (UI*)bw->ui; + UI *ui = BW2UI(bw); Layout *layout = (Layout*)bw->render_layout; MSG("a_UIcmd_close_bw\n"); a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force); delete(layout); + if (ui->tabs()) { + ui->tabs()->remove(ui); + if (ui->tabs()->value() != -1) + ui->tabs()->selected_child()->take_focus(); + else + ui->tabs()->window()->hide(); + } delete(ui); a_Bw_free(bw); } @@ -562,8 +609,6 @@ void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw) // UI binding functions ------------------------------------------------------- -#define BW2UI(bw) ((UI*)(bw->ui)) - /* * Return browser window width and height */ @@ -757,3 +802,20 @@ void a_UIcmd_findtext_reset(BrowserWindow *bw) a_UIcmd_set_msg(bw, ""); } +/* + * Focus the rendered area. + */ +void a_UIcmd_focus_main_area(BrowserWindow *bw) +{ + BW2UI(bw)->focus_main(); +} + +/* + * Focus the location bar. + */ +void a_UIcmd_focus_location(void *vbw) +{ + BrowserWindow *bw = (BrowserWindow*)vbw; + BW2UI(bw)->focus_location(); +} + |