Mercurial > dillo_port1.3
changeset 400:31b866fdde87
- File menu as popup implementation.
- Working show_filemenu dillorc option.
author | jcid |
---|---|
date | Thu, 09 Oct 2008 20:38:36 +0200 |
parents | 256c36a7e70f |
children | 6536af676d0b |
files | dillo2rc src/menu.cc src/menu.hh src/prefs.c src/prefs.h src/ui.cc src/ui.hh src/uicmd.cc src/uicmd.hh |
diffstat | 9 files changed, 148 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/dillo2rc Thu Oct 09 15:26:45 2008 +0200 +++ b/dillo2rc Thu Oct 09 20:38:36 2008 +0200 @@ -179,7 +179,7 @@ #show_save=YES #show_stop=YES #show_bookmarks=YES -#show_menubar=YES +#show_filemenu=YES #show_clear_url=YES #show_url=YES #show_search=YES
--- a/src/menu.cc Thu Oct 09 15:26:45 2008 +0200 +++ b/src/menu.cc Thu Oct 09 20:38:36 2008 +0200 @@ -37,6 +37,8 @@ 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 @@ //-------------------------------------------------------------------------- +/* + * 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 @@ } /* - * 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 @@ } /* + * 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 @@ } /* + * 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)
--- a/src/menu.hh Thu Oct 09 15:26:45 2008 +0200 +++ b/src/menu.hh Thu Oct 09 20:38:36 2008 +0200 @@ -12,6 +12,7 @@ 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);
--- a/src/prefs.c Thu Oct 09 15:26:45 2008 +0200 +++ b/src/prefs.c Thu Oct 09 20:38:36 2008 +0200 @@ -91,7 +91,7 @@ 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 @@ { "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 @@ 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 @@ 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;
--- a/src/prefs.h Thu Oct 09 15:26:45 2008 +0200 +++ b/src/prefs.h Thu Oct 09 20:38:36 2008 +0200 @@ -45,7 +45,7 @@ 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;
--- a/src/ui.cc Thu Oct 09 15:26:45 2008 +0200 +++ b/src/ui.cc Thu Oct 09 20:38:36 2008 +0200 @@ -204,8 +204,6 @@ 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 @@ } /* + * 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 @@ 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 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 @@ } /* - * Close bw's behind a timeout to let the triggering code unwind out of the - * window before it's all torn down. + * Create the "File" menu + * Static function for File menu callbacks. */ -static void menubar_close_bw(void *vbw) +Widget *UI::make_filemenu_button() { - BrowserWindow *bw = (BrowserWindow *)vbw; - if (bw) - a_UIcmd_close_bw(bw); - else - a_UIcmd_close_all_bw(NULL); - a_Timeout_remove(); + 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; } -/* - * Static function for menubar callbacks. - */ -static void menubar_cb(Widget *wid, void *data) -{ - 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); - } -} - -/* - * 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 @@ 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); - } + // 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(); + } - // Location - g2 = new Group(0,fh,ww,lh); - g2->begin(); - pg = make_location(); - pg->resize(ww,lh); g2->resizable(pg); g2->end(); @@ -801,7 +780,9 @@ 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 @@ { // 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 )
--- a/src/ui.hh Thu Oct 09 15:26:45 2008 +0200 +++ b/src/ui.hh Thu Oct 09 20:38:36 2008 +0200 @@ -49,7 +49,7 @@ 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 @@ 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:
--- a/src/uicmd.cc Thu Oct 09 15:26:45 2008 +0200 +++ b/src/uicmd.cc Thu Oct 09 20:38:36 2008 +0200 @@ -665,6 +665,14 @@ } /* + * 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)
--- a/src/uicmd.hh Thu Oct 09 15:26:45 2008 +0200 +++ b/src/uicmd.hh Thu Oct 09 20:38:36 2008 +0200 @@ -41,6 +41,7 @@ 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);