changeset 372:49886f14ffe1

- Committed the no bw as window user_data() patch.
author jcid
date Wed, 01 Oct 2008 16:08:30 +0200
parents 898e6ca77d7e
children 264ae15dae64
files src/bw.c src/bw.h src/findbar.cc src/ui.cc src/ui.hh src/uicmd.cc src/uicmd.hh
diffstat 7 files changed, 60 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/bw.c	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/bw.c	Wed Oct 01 16:08:30 2008 +0200
@@ -263,12 +263,12 @@
 }
 
 /*
- * TODO: remove this Hack.
+ * Return a bw by index
  */
-BrowserWindow *a_Bw_get()
+BrowserWindow *a_Bw_get(int i)
 {
-   if (num_bws > 0)
-      return bws[0];
+   if (i >= 0 && i < num_bws)
+      return bws[i];
    return NULL;
 }
 
--- a/src/bw.h	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/bw.h	Wed Oct 01 16:08:30 2008 +0200
@@ -72,7 +72,7 @@
 void a_Bw_init(void);
 BrowserWindow *a_Bw_new();
 void a_Bw_free(BrowserWindow *bw);
-BrowserWindow *a_Bw_get();
+BrowserWindow *a_Bw_get(int i);
 int a_Bw_num();
 
 void a_Bw_add_client(BrowserWindow *bw, int Key, int Root);
--- a/src/findbar.cc	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/findbar.cc	Wed Oct 01 16:08:30 2008 +0200
@@ -55,7 +55,7 @@
    bool case_sens = fb->cb->value();
 
    if (key[0] != '\0')
-      a_UIcmd_findtext_search((BrowserWindow *) fb->window()->user_data(),
+      a_UIcmd_findtext_search(a_UIcmd_get_bw_by_widget(fb),
                               key, case_sens);
 }
 
@@ -170,7 +170,7 @@
    BrowserWindow *bw;
 
    Group::hide();
-   if ((bw = (BrowserWindow *) this->window()->user_data()))
+   if ((bw = a_UIcmd_get_bw_by_widget(this)))
       a_UIcmd_findtext_reset(bw);
    a_UIcmd_focus_main_area(bw);
 }
--- a/src/ui.cc	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/ui.cc	Wed Oct 01 16:08:30 2008 +0200
@@ -99,8 +99,8 @@
    if (e == PASTE) {
       const char* t = event_text();
       if (t && *t) {
-         a_UIcmd_set_location_text(this->window()->user_data(), t);
-         a_UIcmd_open_urlstr(this->window()->user_data(), t);
+         a_UIcmd_set_location_text(a_UIcmd_get_bw_by_widget(this), t);
+         a_UIcmd_open_urlstr(a_UIcmd_get_bw_by_widget(this), t);
          return 1;
       }
    }
@@ -154,7 +154,7 @@
       MSG("[Search], mouse button %d was pressed\n", k);
 
    if (k == 1) {
-      a_UIcmd_search_dialog(wid->window()->user_data());
+      a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(wid));
    } else if (k == 2) {
       ((UI*)data)->color_change_cb_i();
    } else if (k == 3) {
@@ -203,7 +203,7 @@
     * The Back or Forward, buttons, or the first click on a rendered
     * page. BUG: this must be investigated and reported to FLTK2 team */
    if (event_key() == ReturnKey) {
-      a_UIcmd_open_urlstr(i->window()->user_data(), 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);
@@ -225,41 +225,41 @@
    switch (bn) {
    case UI_BACK:
       if (k == 1) {
-         a_UIcmd_back(wid->window()->user_data());
+         a_UIcmd_back(a_UIcmd_get_bw_by_widget(wid));
       } else if (k == 3) {
-         a_UIcmd_back_popup(wid->window()->user_data());
+         a_UIcmd_back_popup(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_FORW:
       if (k == 1) {
-         a_UIcmd_forw(wid->window()->user_data());
+         a_UIcmd_forw(a_UIcmd_get_bw_by_widget(wid));
       } else if (k == 3) {
-         a_UIcmd_forw_popup(wid->window()->user_data());
+         a_UIcmd_forw_popup(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_HOME:
       if (k == 1) {
-         a_UIcmd_home(wid->window()->user_data());
+         a_UIcmd_home(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_RELOAD:
       if (k == 1) {
-         a_UIcmd_reload(wid->window()->user_data());
+         a_UIcmd_reload(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_SAVE:
       if (k == 1) {
-         a_UIcmd_save(wid->window()->user_data());
+         a_UIcmd_save(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_STOP:
       if (k == 1) {
-         a_UIcmd_stop(wid->window()->user_data());
+         a_UIcmd_stop(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    case UI_BOOK:
       if (k == 1) {
-         a_UIcmd_book(wid->window()->user_data());
+         a_UIcmd_book(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
    default:
@@ -286,9 +286,9 @@
    if (k && k <= 7)
       MSG("[BugMeter], mouse button %d was pressed\n", k);
    if (k == 1) {
-      a_UIcmd_view_page_bugs(wid->window()->user_data());
+      a_UIcmd_view_page_bugs(a_UIcmd_get_bw_by_widget(wid));
    } else if (k == 3) {
-      a_UIcmd_bugmeter_popup(wid->window()->user_data());
+      a_UIcmd_bugmeter_popup(a_UIcmd_get_bw_by_widget(wid));
    }
 }
 
@@ -458,15 +458,15 @@
 {
    if (strcmp((char*)data, "nb") == 0) {
       a_UIcmd_browser_window_new(wid->window()->w(), wid->window()->h(),
-                                 wid->window()->user_data());
+                                 a_UIcmd_get_bw_by_widget(wid));
    } else if (strcmp((char*)data, "nt") == 0) {
-      a_UIcmd_open_url_nt(wid->window()->user_data(), NULL, 1);
+      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(wid->window()->user_data());
+      a_UIcmd_open_file(a_UIcmd_get_bw_by_widget(wid));
    } else if (strcmp((char*)data, "ou") == 0) {
-      a_UIcmd_focus_location(wid->window()->user_data());
+      a_UIcmd_focus_location(a_UIcmd_get_bw_by_widget(wid));
    } else if (strcmp((char*)data, "cw") == 0) {
-      a_UIcmd_close_bw(wid->window()->user_data());
+      a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(wid));
    } else if (strcmp((char*)data, "ed") == 0) {
       a_UIcmd_close_all_bw();
    }
@@ -756,7 +756,7 @@
       // Handle keyboard shortcuts here.
       if (modifier == CTRL) {
          if (k == 'b') {
-            a_UIcmd_book(this->window()->user_data());
+            a_UIcmd_book(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 'f') {
             set_findbar_visibility(1);
@@ -765,22 +765,22 @@
             focus_location();
             ret = 1;
          } else if (k == 'n') {
-            a_UIcmd_browser_window_new(w(), h(), this->window()->user_data());
+            a_UIcmd_browser_window_new(w(),h(),a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 'o') {
-            a_UIcmd_open_file(this->window()->user_data());
+            a_UIcmd_open_file(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 'q') {
-            a_UIcmd_close_bw(this->window()->user_data());
+            a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 'r') {
-            a_UIcmd_reload(this->window()->user_data());
+            a_UIcmd_reload(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 's') {
-            a_UIcmd_search_dialog(this->window()->user_data());
+            a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if (k == 't') {
-            a_UIcmd_open_url_nt(this->window()->user_data(), NULL, 1);
+            a_UIcmd_open_url_nt(a_UIcmd_get_bw_by_widget(this), NULL, 1);
             ret = 1;
          } else if (k == ' ') {
             panelmode_cb_i();
@@ -789,20 +789,14 @@
       } else {
          // Back and Forward navigation shortcuts
          if (modifier == 0 && (k == BackSpaceKey ||  k == ',')) {
-            a_UIcmd_back(this->window()->user_data());
+            a_UIcmd_back(a_UIcmd_get_bw_by_widget(this));
             ret = 1;
          } else if ((modifier == 0 && k == '.') ||
                     (modifier == SHIFT && k == BackSpaceKey)) {
-            a_UIcmd_forw(this->window()->user_data());
+            a_UIcmd_forw(a_UIcmd_get_bw_by_widget(this));
             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)
--- a/src/ui.hh	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/ui.hh	Wed Oct 01 16:08:30 2008 +0200
@@ -44,7 +44,6 @@
 // UI class definition -------------------------------------------------------
 //
 class UI : public fltk::Group {
-   void *Bw;
    CustTabGroup *Tabs;
    char *TabTooltip;
 
@@ -109,8 +108,6 @@
 
    CustTabGroup *tabs() { return Tabs; }
    void tabs(CustTabGroup *tabs) { Tabs = tabs; }
-   void *vbw() { return Bw; }
-   void vbw(void *v_bw) { Bw = v_bw; }
 
    // Hooks to method callbacks
    void panel_cb_i();
--- a/src/uicmd.cc	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/uicmd.cc	Wed Oct 01 16:08:30 2008 +0200
@@ -113,19 +113,27 @@
    CustTabGroup *tabs;
    int choice = 0;
 
-   if (cb_data == NULL) {
-      w->hide ();
-   } else {
-      // It is assumed that user_data() of a window contains a pointer
-      // to the current BrowserWindow.
-      tabs = BW2UI((BrowserWindow*) cb_data)->tabs();
-      if (tabs->children () > 1)
-         choice = a_Dialog_choice3 ("Window contains more than one tab.",
-            "Close all tabs", "Cancel", NULL);
-      if (choice == 0)
-         for (int i = tabs->children() - 1; i >= 0; i--)
-            a_UIcmd_close_bw(((UI*)tabs->child(i))->vbw());
+   tabs = BW2UI((BrowserWindow*) cb_data)->tabs();
+   if (tabs->children () > 1)
+      choice = a_Dialog_choice3 ("Window contains more than one tab.",
+                                 "Close all tabs", "Cancel", NULL);
+   if (choice == 0)
+      while (tabs->children())
+         a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(tabs->child(0)));
+}
+
+/*
+ * Given a UI or UI child widget, return its bw.
+ */
+BrowserWindow *a_UIcmd_get_bw_by_widget(void *v_wid)
+{
+   BrowserWindow *bw;
+   for (int i = 0; i < a_Bw_num(); ++i) {
+      bw = a_Bw_get(i);
+      if (((fltk::Widget*)bw->ui)->contains((fltk::Widget*)v_wid))
+         return bw;
    }
+   return NULL;
 }
 
 /*
@@ -150,7 +158,6 @@
    CustTabGroup *DilloTabs = new CustTabGroup(0, 0, ww, wh);
    DilloTabs->selection_color(156);
    win->add(DilloTabs);
-   win->callback(win_cb, (void*) NULL);
 
    // Create and set the UI
    UI *new_ui = new UI(0, 0, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL);
@@ -184,14 +191,13 @@
    // Now, create a new browser window structure
    new_bw = a_Bw_new();
 
-   // Store new_bw for callback data inside UI
-   new_ui->vbw(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;
 
+   win->callback(win_cb, new_bw);
+
    return new_bw;
 }
 
@@ -232,9 +238,6 @@
    // Now, create a new browser window structure
    new_bw = a_Bw_new();
 
-   // Store new_bw for callback data inside UI
-   new_ui->vbw(new_bw);
-
    // Reference the UI from the bw
    new_bw->ui = (void *)new_ui;
    // Copy the layout pointer into the bw data
@@ -279,7 +282,7 @@
       choice = a_Dialog_choice3 ("More than one open tab or Window.",
          "Close all tabs and windows", "Cancel", NULL);
    if (choice == 0)
-      while ((bw = a_Bw_get()))
+      while ((bw = a_Bw_get(0)))
          a_UIcmd_close_bw((void*)bw);
 }
 
--- a/src/uicmd.hh	Tue Sep 30 18:05:05 2008 +0200
+++ b/src/uicmd.hh	Wed Oct 01 16:08:30 2008 +0200
@@ -9,6 +9,7 @@
 
 
 BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *v_bw);
+BrowserWindow *a_UIcmd_get_bw_by_widget(void *v_wid);
 void a_UIcmd_open_urlstr(void *vbw, const char *urlstr);
 void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url);
 void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url);