diff options
author | jcid <devnull@localhost> | 2008-10-09 20:38:36 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-10-09 20:38:36 +0200 |
commit | 57bbebd6867c19e5a96972395051adc3f6e0248e (patch) | |
tree | 1d87223eaba24ac91c6e23f90b26fdecdd64ce70 /src | |
parent | 4fea52451363423ccb2ddb74f374f265f38b1755 (diff) |
- File menu as popup implementation.
- Working show_filemenu dillorc option.
Diffstat (limited to 'src')
-rw-r--r-- | src/menu.cc | 74 | ||||
-rw-r--r-- | src/menu.hh | 1 | ||||
-rw-r--r-- | src/prefs.c | 10 | ||||
-rw-r--r-- | src/prefs.h | 2 | ||||
-rw-r--r-- | src/ui.cc | 135 | ||||
-rw-r--r-- | src/ui.hh | 3 | ||||
-rw-r--r-- | src/uicmd.cc | 8 | ||||
-rw-r--r-- | src/uicmd.hh | 1 |
8 files changed, 148 insertions, 86 deletions
diff --git a/src/menu.cc b/src/menu.cc index 17787cb0..6856143e 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -37,6 +37,8 @@ using namespace fltk; static DilloUrl *popup_url = NULL; // Weak reference to the popup's bw static BrowserWindow *popup_bw = NULL; +// Where to place the filemenu popup +int popup_x, popup_y; // History popup direction (-1 = back, 1 = forward). static int history_direction = -1; // History popup, list of URL-indexes. @@ -75,6 +77,28 @@ void CustItem::draw() { //-------------------------------------------------------------------------- +/* + * Static function for File menu callbacks. + */ +static void filemenu_cb(Widget *wid, void *data) +{ + if (strcmp((char*)data, "nw") == 0) { + UI *ui = (UI*)popup_bw->ui; + a_UIcmd_browser_window_new(ui->w(), ui->h(), popup_bw); + } else if (strcmp((char*)data, "nt") == 0) { + a_UIcmd_open_url_nt(popup_bw, NULL, 1); + } else if (strcmp((char*)data, "of") == 0) { + a_UIcmd_open_file(popup_bw); + } else if (strcmp((char*)data, "ou") == 0) { + a_UIcmd_focus_location(popup_bw); + } else if (strcmp((char*)data, "cw") == 0) { + a_Timeout_add(0.0, a_UIcmd_close_bw, popup_bw); + } else if (strcmp((char*)data, "ed") == 0) { + a_Timeout_add(0.0, a_UIcmd_close_all_bw, NULL); + } +} + + static void Menu_copy_urlstr_cb(Widget *) { if (popup_url) @@ -244,7 +268,7 @@ static void Menu_history_cb(Widget *wid, void *data) } /* - * Manus are popped-up from this timeout callback so the events + * Menus are popped-up from this timeout callback so the events * associated with the button are gone when it pops. This way we * avoid a segfault when a new page replaces the page that issued * the popup menu. @@ -256,6 +280,17 @@ static void Menu_popup_cb(void *data) } /* + * Same as above but with coordinates. + */ +static void Menu_popup_cb2(void *data) +{ + Menu *m = (Menu *)data; + m->value(-1); + m->popup(Rectangle(popup_x,popup_y,m->w(),m->h()), m->label()); + a_Timeout_remove(); +} + +/* * Page popup menu (construction & popup) */ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, @@ -413,6 +448,43 @@ void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url, } /* + * File popup menu (construction & popup) + */ +void a_Menu_file_popup(BrowserWindow *bw, void *v_wid) +{ + UI *ui = (UI *)bw->ui; + Widget *wid = (Widget*)v_wid; + // One menu for every browser window + static PopupMenu *pm = 0; + + popup_bw = bw; + popup_x = wid->x(); + popup_y = wid->y() + wid->h() + + // WORKAROUND: ?? wid->y() doesn't count tabs ?? + (((Group*)ui->tabs())->children() > 1 ? 20 : 0); + a_Url_free(popup_url); + popup_url = NULL; + + if (!pm) { + Item *i; + pm = new PopupMenu(0,0,0,0,"File"); + pm->begin(); + i = new Item("New Window", CTRL+'n', filemenu_cb, (void*)"nw"); + i = new Item("New Tab", CTRL+'t', filemenu_cb, (void*)"nt"); + new Divider(); + i = new Item("Open File...", CTRL+'o', filemenu_cb, (void*)"of"); + i = new Item("Open URL...", CTRL+'l', filemenu_cb, (void*)"ou"); + i = new Item("Close", CTRL+'q', filemenu_cb, (void*)"cw"); + new Divider(); + i = new Item("Exit Dillo", ALT+'q', filemenu_cb, (void*)"ed"); + pm->type(PopupMenu::POPUP123); + pm->end(); + } + + a_Timeout_add(0.0, Menu_popup_cb2, (void *)pm); +} + +/* * Bugmeter popup menu (construction & popup) */ void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url) diff --git a/src/menu.hh b/src/menu.hh index 2fdcc96e..9e8a73c6 100644 --- a/src/menu.hh +++ b/src/menu.hh @@ -12,6 +12,7 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url); void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url, bool_t loaded_img, DilloUrl *link_url); +void a_Menu_file_popup(BrowserWindow *bw, void *v_wid); void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url); void a_Menu_history_popup(BrowserWindow *bw, int direction); diff --git a/src/prefs.c b/src/prefs.c index 67b99617..d761842c 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -91,7 +91,7 @@ typedef enum { DRC_TOKEN_SHOW_EXTRA_WARNINGS, DRC_TOKEN_SHOW_FORW, DRC_TOKEN_SHOW_HOME, - DRC_TOKEN_SHOW_MENUBAR, + DRC_TOKEN_SHOW_FILEMENU, DRC_TOKEN_SHOW_MSG, DRC_TOKEN_SHOW_PROGRESS_BOX, DRC_TOKEN_SHOW_RELOAD, @@ -150,9 +150,9 @@ static const SymNode_t symbols[] = { { "show_bookmarks", DRC_TOKEN_SHOW_BOOKMARKS }, { "show_clear_url", DRC_TOKEN_SHOW_CLEAR_URL }, { "show_extra_warnings", DRC_TOKEN_SHOW_EXTRA_WARNINGS }, + { "show_filemenu", DRC_TOKEN_SHOW_FILEMENU }, { "show_forw", DRC_TOKEN_SHOW_FORW }, { "show_home", DRC_TOKEN_SHOW_HOME }, - { "show_menubar", DRC_TOKEN_SHOW_MENUBAR }, { "show_msg", DRC_TOKEN_SHOW_MSG }, { "show_progress_box", DRC_TOKEN_SHOW_PROGRESS_BOX }, { "show_reload", DRC_TOKEN_SHOW_RELOAD }, @@ -302,8 +302,8 @@ static int Prefs_parse_pair(char *name, char *value) case DRC_TOKEN_SHOW_BOOKMARKS: prefs.show_bookmarks = (strcmp(value, "YES") == 0); break; - case DRC_TOKEN_SHOW_MENUBAR: - prefs.show_menubar = (strcmp(value, "YES") == 0); + case DRC_TOKEN_SHOW_FILEMENU: + prefs.show_filemenu = (strcmp(value, "YES") == 0); break; case DRC_TOKEN_SHOW_CLEAR_URL: prefs.show_clear_url = (strcmp(value, "YES") == 0); @@ -442,7 +442,7 @@ void a_Prefs_init(void) prefs.show_save=TRUE; prefs.show_stop=TRUE; prefs.show_bookmarks=TRUE; - prefs.show_menubar=TRUE; + prefs.show_filemenu=TRUE; prefs.show_clear_url=TRUE; prefs.show_url=TRUE; prefs.show_search=TRUE; diff --git a/src/prefs.h b/src/prefs.h index 275aec48..7a409631 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -45,7 +45,7 @@ struct _DilloPrefs { bool_t show_save; bool_t show_stop; bool_t show_bookmarks; - bool_t show_menubar; + bool_t show_filemenu; bool_t show_clear_url; bool_t show_url; bool_t show_search; @@ -204,8 +204,6 @@ public: static void search_cb(Widget *wid, void *data) { int k = event_key(); - if (k && k <= 7) - MSG("[Search], mouse button %d was pressed\n", k); if (k == 1) { a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(wid)); @@ -217,6 +215,17 @@ static void search_cb(Widget *wid, void *data) } /* + * Callback for the File menu button. + */ +static void filemenu_cb(Widget *wid, void *) +{ + int k = event_key(); + if (k == 1 || k == 3) { + a_UIcmd_file_popup(a_UIcmd_get_bw_by_widget(wid), wid); + } +} + +/* * Callback for the location's clear-button. */ static void clear_cb(Widget *w, void *data) @@ -224,8 +233,6 @@ static void clear_cb(Widget *w, void *data) UI *ui = (UI*)data; int k = event_key(); - if (k && k <= 7) - MSG("[Clear], mouse button %d was pressed\n", k); if (k == 1) { ui->set_location(""); ui->focus_location(); @@ -338,8 +345,6 @@ static void b1_cb(Widget *wid, void *cb_data) static void bugmeter_cb(Widget *wid, void *data) { int k = event_key(); - if (k && k <= 7) - MSG("[BugMeter], mouse button %d was pressed\n", k); if (k == 1) { a_UIcmd_view_page_bugs(a_UIcmd_get_bw_by_widget(wid)); } else if (k == 3) { @@ -470,63 +475,32 @@ PackedGroup *UI::make_progress_bars(int wide, int thin_up) } /* - * Close bw's behind a timeout to let the triggering code unwind out of the - * window before it's all torn down. - */ -static void menubar_close_bw(void *vbw) -{ - BrowserWindow *bw = (BrowserWindow *)vbw; - if (bw) - a_UIcmd_close_bw(bw); - else - a_UIcmd_close_all_bw(NULL); - a_Timeout_remove(); -} - -/* - * Static function for menubar callbacks. + * Create the "File" menu + * Static function for File menu callbacks. */ -static void menubar_cb(Widget *wid, void *data) +Widget *UI::make_filemenu_button() { - if (strcmp((char*)data, "nb") == 0) { - a_UIcmd_browser_window_new(wid->window()->w(), wid->window()->h(), - a_UIcmd_get_bw_by_widget(wid)); - } else if (strcmp((char*)data, "nt") == 0) { - a_UIcmd_open_url_nt(a_UIcmd_get_bw_by_widget(wid), NULL, 1); - } else if (strcmp((char*)data, "of") == 0) { - a_UIcmd_open_file(a_UIcmd_get_bw_by_widget(wid)); - } else if (strcmp((char*)data, "ou") == 0) { - a_UIcmd_focus_location(a_UIcmd_get_bw_by_widget(wid)); - } else if (strcmp((char*)data, "cw") == 0) { - a_Timeout_add(0.0, menubar_close_bw, a_UIcmd_get_bw_by_widget(wid)); - } else if (strcmp((char*)data, "ed") == 0) { - a_Timeout_add(0.0, menubar_close_bw, NULL); - } + HighlightButton *btn; + int w,h, padding; + + FileButton = btn = new HighlightButton(0,0,0,0,"W"); + btn->measure_label(w, h); + padding = w; + btn->copy_label(PanelSize == P_tiny ? "&F" : "&File"); + btn->measure_label(w,h); + if (PanelSize == P_large) + h = fh; + btn->resize(w+padding,h); + _MSG("UI::make_filemenu_button w=%d h=%d padding=%d\n", w, h, padding); + btn->box(PanelSize == P_large ? FLAT_BOX : THIN_UP_BOX); + btn->callback(filemenu_cb, this); + btn->tooltip("File menu"); + btn->clear_tab_to_focus(); + if (!prefs.show_filemenu && PanelSize != P_large) + btn->hide(); + return btn; } -/* - * Create the menubar ("File" menu only). - */ -void UI::make_menubar(int x, int y, int w, int h) -{ - MenuBar *mb = new MenuBar(x,y,w,h); - mb->begin(); - ItemGroup *g = new ItemGroup( "&File" ); - g->begin(); - /* FLTK2 BUG: The space prefix avoids FLTK2 taking the - * first letter as a SHORTCUT */ - new Item(" &New Window", COMMAND + 'n', menubar_cb, (void *)"nb"); - new Item(" New &Tab", COMMAND + 't', menubar_cb, (void *)"nt"); - new Divider(); - new Item(" &Open File...", COMMAND + 'o', menubar_cb, (void *)"of"); - new Item(" Open UR&L...", COMMAND + 'l', menubar_cb, (void *)"ou"); - new Item(" Close &Window", COMMAND + 'q', menubar_cb, (void *)"cw"); - new Divider(); - new Item(" E&xit Dillo", ACCELERATOR + 'q', menubar_cb, (void *)"ed"); - g->end(); - mb->box(EMBOSSED_BOX); - mb->end(); -} /* * Create the control panel @@ -566,38 +540,43 @@ Group *UI::make_panel(int ww) if (Small_Icons) xpos = 0, bw = 42, bh = 36, fh = 22, lh = 22, lbl = 1; else - xpos = 0, bw = 45, bh = 45, fh = 28, lh = 28, lbl = 1; + xpos = 0, bw = 45, bh = 45, fh = 24, lh = 28, lbl = 1; } if (PanelSize == P_tiny) { g1 = new Group(0,0,ww,bh); - g1->begin(); // Toolbar pg = make_toolbar(ww,bh); pg->box(EMBOSSED_BOX); - //pg->box(BORDER_FRAME); - w = make_location(); + g1->add(pg); + w = make_filemenu_button(); + pg->add(w); + w = make_location(); pg->add(w); pg->resizable(w); - w = make_progress_bars(0,1); + w = make_progress_bars(0,1); pg->add(w); g1->resizable(pg); - g1->end(); } else { g1 = new Group(0,0,ww,fh+lh+bh); g1->begin(); - // File menu - if (PanelSize == P_large) { - make_menubar(0,0,ww,fh); - } - - // Location - g2 = new Group(0,fh,ww,lh); - g2->begin(); - pg = make_location(); - pg->resize(ww,lh); + // File menu + if (PanelSize == P_large) { + make_filemenu_button(); + g2 = new Group(0,fh,ww,lh); + g2->begin(); + pg = make_location(); + pg->resize(ww,lh); + } else { + g2 = new PackedGroup(0,fh,ww,lh); + g2->type(PackedGroup::ALL_CHILDREN_VERTICAL); + g2->begin(); + make_filemenu_button(); + pg = make_location(); + } + g2->resizable(pg); g2->end(); @@ -801,7 +780,9 @@ int UI::handle(int event) ret = 1; } } else if (modifier == ALT) { - if (k == 'q' && event_key_state(LeftAltKey)) { + if (k == 'f') { + a_UIcmd_file_popup(a_UIcmd_get_bw_by_widget(this), FileButton); + } else if (k == 'q' && event_key_state(LeftAltKey)) { a_Timeout_add(0.0, a_UIcmd_close_all_bw, NULL); } } else { @@ -954,8 +935,6 @@ void UI::customize(int flags) { // flags argument not currently used - if ( !prefs.show_menubar ) - MSG("show_menubar preference ignored\n"); if ( !prefs.show_back ) Back->hide(); if ( !prefs.show_forw ) @@ -49,7 +49,7 @@ class UI : public fltk::Group { Group *TopGroup; Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks, - *Clear, *Search, *FullScreen, *ImageLoad, *BugMeter; + *Clear, *Search, *FullScreen, *ImageLoad, *BugMeter, *FileButton; Input *Location; PackedGroup *ProgBox; CustProgressBox *PProg, *IProg; @@ -69,6 +69,7 @@ class UI : public fltk::Group { PackedGroup *make_location(); PackedGroup *make_progress_bars(int wide, int thin_up); void make_menubar(int x, int y, int w, int h); + Widget *make_filemenu_button(); Group *make_panel(int ww); public: diff --git a/src/uicmd.cc b/src/uicmd.cc index d6a52f0f..e56605bd 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -665,6 +665,14 @@ void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img, } /* + * Pop up the file menu + */ +void a_UIcmd_file_popup(void *vbw, void *v_wid) +{ + a_Menu_file_popup((BrowserWindow*)vbw, v_wid); +} + +/* * Copy url string to paste buffer */ void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr) diff --git a/src/uicmd.hh b/src/uicmd.hh index 2dbe8726..7115cbf0 100644 --- a/src/uicmd.hh +++ b/src/uicmd.hh @@ -41,6 +41,7 @@ void a_UIcmd_page_popup(void *vbw, const DilloUrl *url, void a_UIcmd_link_popup(void *vbw, const DilloUrl *url); void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img, DilloUrl *link_url); +void a_UIcmd_file_popup(void *vbw, void *v_wid); void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr); void a_UIcmd_view_page_source(const DilloUrl *url); void a_UIcmd_view_page_bugs(void *vbw); |