diff options
Diffstat (limited to 'src/ui.cc')
-rw-r--r-- | src/ui.cc | 138 |
1 files changed, 67 insertions, 71 deletions
@@ -39,9 +39,9 @@ using namespace fltk; * (Used to avoid certain shortcuts in the location bar) */ -class NewInput : public Input { +class CustInput : public Input { public: - NewInput (int x, int y, int w, int h, const char* l=0) : + CustInput (int x, int y, int w, int h, const char* l=0) : Input(x,y,w,h,l) {}; int handle(int e); }; @@ -50,15 +50,15 @@ public: * Disable: UpKey, DownKey, PageUpKey, PageDownKey and * CTRL+{o,r,HomeKey,EndKey} */ -int NewInput::handle(int e) +int CustInput::handle(int e) { int k = event_key(); - _MSG("NewInput::handle event=%d\n", e); + _MSG("CustInput::handle event=%d\n", e); // Don't focus with arrow keys if (e == FOCUS && - (k == UpKey || k == DownKey || k == LeftKey|| k == RightKey)) { + (k == UpKey || k == DownKey || k == LeftKey || k == RightKey)) { return 0; } @@ -80,14 +80,14 @@ int NewInput::handle(int e) /* * Used to handle "paste" within the toolbar's Clear button. */ -class NewHighlightButton : public HighlightButton { +class CustHighlightButton : public HighlightButton { public: - NewHighlightButton(int x, int y, int w, int h, const char *l=0) : + CustHighlightButton(int x, int y, int w, int h, const char *l=0) : HighlightButton(x,y,w,h,l) {}; int handle(int e); }; -int NewHighlightButton::handle(int e) +int CustHighlightButton::handle(int e) { if (e == PASTE) { const char* t = event_text(); @@ -105,9 +105,9 @@ int NewHighlightButton::handle(int e) /* * Used to resize the progress boxes automatically. */ -class NewProgressBox : public InvisibleBox { +class CustProgressBox : public InvisibleBox { public: - NewProgressBox(int x, int y, int w, int h, const char *l=0) : + CustProgressBox(int x, int y, int w, int h, const char *l=0) : InvisibleBox(x,y,w,h,l) {}; void update_label(const char *lbl) { static int padding = 0; @@ -138,14 +138,6 @@ public: // /* - * Callback handler for the close window event. - */ -static void close_window_cb(Widget *wid, void *data) -{ - a_UIcmd_close_bw(data); -} - -/* * Callback for the search button. */ static void search_cb(Widget *wid, void *data) @@ -281,15 +273,15 @@ static void fullscreen_cb(Widget *wid, void *data) /* * Callback for the bug meter button. */ -static void bugmeter_cb(Widget *w, void *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(((UI*)data)->user_data()); + a_UIcmd_view_page_bugs(wid->window()->user_data()); } else if (k == 3) { - a_UIcmd_bugmeter_popup(((UI*)data)->user_data()); + a_UIcmd_bugmeter_popup(wid->window()->user_data()); } } @@ -415,14 +407,14 @@ PackedGroup *UI::make_location() Button *b; PackedGroup *pg = new PackedGroup(0,0,0,0); pg->begin(); - Clear = b = new NewHighlightButton(2,2,16,22,0); + Clear = b = new CustHighlightButton(2,2,16,22,0); ImgClear = new xpmImage(new_s_xpm); b->image(ImgClear); b->tooltip("Clear the URL box.\nMiddle-click to paste a URL."); b->callback(clear_cb, (void *)this); b->clear_tab_to_focus(); - Input *i = Location = new NewInput(0,0,0,0,0); + Input *i = Location = new CustInput(0,0,0,0,0); i->tooltip("Location"); i->color(CuteColor); i->when(WHEN_ENTER_KEY); @@ -451,12 +443,12 @@ PackedGroup *UI::make_progress_bars(int wide, int thin_up) ProgBox = new PackedGroup(0,0,0,0); ProgBox->begin(); // Images - IProg = new NewProgressBox(0,0,0,0); + IProg = new CustProgressBox(0,0,0,0); IProg->box(thin_up ? THIN_UP_BOX : EMBOSSED_BOX); IProg->labelcolor(GRAY10); IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0"); // Page - PProg = new NewProgressBox(0,0,0,0); + PProg = new CustProgressBox(0,0,0,0); PProg->box(thin_up ? THIN_UP_BOX : EMBOSSED_BOX); PProg->labelcolor(GRAY10); PProg->update_label(wide ? "Page\n0.0KB" : "0.0KB"); @@ -476,14 +468,14 @@ 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(), ui); } else if (strcmp((char*)data, "of") == 0) { - a_UIcmd_open_file(ui->user_data()); + a_UIcmd_open_file(wid->window()->user_data()); } else if (strcmp((char*)data, "ou") == 0) { if (ui->get_panelmode() == UI_HIDDEN) { ui->set_panelmode(UI_TEMPORARILY_SHOW_PANELS); } ui->focus_location(); } else if (strcmp((char*)data, "cw") == 0) { - a_UIcmd_close_bw(ui->user_data()); + a_UIcmd_close_bw(wid->window()->user_data()); } else if (strcmp((char*)data, "ed") == 0) { a_UIcmd_close_all_bw(); } @@ -609,11 +601,11 @@ Group *UI::make_panel(int ww) * User Interface constructor */ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : - Window(win_w, win_h, label) + Group(0, 0, win_w, win_h, label) { int s_h = 20; - clear_double_buffer(); + Tabs = NULL; TopGroup = new PackedGroup(0, 0, win_w, win_h); add(TopGroup); resizable(TopGroup); @@ -633,10 +625,6 @@ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : } - // Set handler for the close window event - // (the argument is set later via user_data()) - callback(close_window_cb); - // Control panel Panel = make_panel(win_w); TopGroup->add(Panel); @@ -655,7 +643,7 @@ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : MainIdx = TopGroup->find(Main); // Find text bar - findbar = new Findbar(win_w, 30, this); + findbar = new Findbar(win_w, 30); TopGroup->add(findbar); // Status Panel @@ -729,6 +717,7 @@ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : */ UI::~UI() { + _MSG("UI::~UI()\n"); delete_panel_images(); delete_status_panel_images(); delete ImgFullScreenOn; @@ -751,27 +740,22 @@ void UI::delete_status_panel_images() */ int UI::handle(int event) { - _MSG("UI::handle event=%d\n", event); + MSG("UI::handle event=%d (%d,%d)\n", event, event_x(), event_y()); + _MSG("Panel->h()=%d Main->h()=%d\n", Panel->h() , Main->h()); + int ret = 0, k = event_key(); - // We're only interested in some flags - // (not whether numlock is on for example) - unsigned modifier = event_state() & (SHIFT | CTRL | ALT | META); + // We're only interested in some flags + unsigned modifier = event_state() & (SHIFT | CTRL | ALT); - // Let FLTK pass these events to child widgets. if (event == KEY) { - if (k == UpKey || k == DownKey || k == SpaceKey || - k == LeftKey || k == RightKey) - return 0; - // Ignore Escape for main window. - if (k == EscapeKey) - ret = 1; + return 0; // Receive as shortcut } else if (event == SHORTCUT) { - // Handle these shortcuts here. + // Handle keyboard shortcuts here. if (modifier == CTRL) { if (k == 'b') { - a_UIcmd_book(user_data()); + a_UIcmd_book(this->window()->user_data()); ret = 1; } else if (k == 'f') { set_findbar_visibility(1); @@ -786,44 +770,48 @@ int UI::handle(int event) a_UIcmd_browser_window_new(w(), h(), this); ret = 1; } else if (k == 'o') { - a_UIcmd_open_file(user_data()); + a_UIcmd_open_file(this->window()->user_data()); ret = 1; } else if (k == 'q') { - a_UIcmd_close_bw(user_data()); + a_UIcmd_close_bw(this->window()->user_data()); ret = 1; } else if (k == 'r') { - a_UIcmd_reload(user_data()); + a_UIcmd_reload(this->window()->user_data()); ret = 1; } else if (k == 's') { - a_UIcmd_search_dialog(user_data()); + a_UIcmd_search_dialog(this->window()->user_data()); ret = 1; } else if (k == ' ') { panelmode_cb_i(); ret = 1; } + } else { + // Back and Forward navigation shortcuts + if (modifier == 0 && (k == BackSpaceKey || k == ',')) { + a_UIcmd_back(this->window()->user_data()); + ret = 1; + } else if ((modifier == 0 && k == '.') || + (modifier == SHIFT && k == BackSpaceKey)) { + a_UIcmd_forw(this->window()->user_data()); + ret = 1; + } } - if (event_key_state(LeftAltKey) && modifier == ALT && k == 'q') { - a_UIcmd_close_all_bw(); - ret = 1; - } - - // Back and Forward navigation shortcuts - if ((modifier == 0 && k == BackSpaceKey) || - (modifier == 0 && k == ',')) { - a_UIcmd_back(user_data()); - ret = 1; - } else if ((modifier == SHIFT && k == BackSpaceKey) || - (modifier == 0 &&k == '.')) { - a_UIcmd_forw(user_data()); - ret = 1; - } + } else if (event == FOCUS_CHANGE) { + // The "bw" for this tab is stored in the parent window. + // Update "bw" each time we switch tabs. + window()->user_data(vbw()); + ret = 0; } - if (ret == 0) { - ret = Window::handle(event); - } + if (!ret) + ret = Group::handle(event); return ret; + + // if (event_key_state(LeftAltKey) && modifier == ALT && k == 'q') { + // a_UIcmd_close_all_bw(); + // ret = 1; + // } } @@ -859,6 +847,14 @@ void UI::focus_location() } /* + * Focus Main area. + */ +void UI::focus_main() +{ + Main->take_focus(); +} + +/* * Set a new message in the status bar. */ void UI::set_status(const char *str) @@ -1075,8 +1071,8 @@ void UI::set_page_title(const char *label) char title[128]; snprintf(title, 128, "Dillo: %s", label); - this->copy_label(title); - this->redraw_label(); + this->window()->copy_label(title); + this->window()->redraw_label(); } /* |