Code

Allow GdlDockItems to take focus, and grab focus on present. Various
authorgustav_b <gustav_b@users.sourceforge.net>
Mon, 10 Sep 2007 21:20:06 +0000 (21:20 +0000)
committergustav_b <gustav_b@users.sourceforge.net>
Mon, 10 Sep 2007 21:20:06 +0000 (21:20 +0000)
cleanups.

src/libgdl/gdl-dock-item-grip.c
src/libgdl/gdl-dock-item.c
src/ui/dialog/floating-behavior.cpp
src/ui/widget/dock-item.cpp
src/ui/widget/dock-item.h
src/ui/widget/dock.h

index 7465aefb20cb0149df621b9a6f6274f0d828263a..d1ba2372c19b20a62744a14724e7592b3de9708e 100644 (file)
@@ -130,6 +130,7 @@ gdl_dock_item_grip_expose (GtkWidget      *widget,
     GdlDockItemGrip *grip;
     GdkRectangle     title_area;
     GdkRectangle     expose_area;
+    GtkStyle        *bg_style;
     gint             layout_width;
     gint             layout_height;
     gint             text_x;
@@ -138,13 +139,12 @@ gdl_dock_item_grip_expose (GtkWidget      *widget,
     grip = GDL_DOCK_ITEM_GRIP (widget);
     gdl_dock_item_grip_get_title_area (grip, &title_area);
 
-    /* draw darker a background */
-    gdk_draw_rectangle (GDK_DRAWABLE (widget->window),
-                        gtk_widget_get_style (widget)->dark_gc[widget->state],
-                        TRUE,
-                        1, 0,
-                        widget->allocation.width - 1,
-                        widget->allocation.height);
+    /* draw background, highlight it if the dock item has focus */
+    bg_style = (GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (grip->item)) ? 
+                gtk_widget_get_style (widget)->mid_gc[widget->state] :
+                gtk_widget_get_style (widget)->dark_gc[widget->state]);
+    gdk_draw_rectangle (GDK_DRAWABLE (widget->window), bg_style, TRUE,
+                        1, 0, widget->allocation.width - 1, widget->allocation.height);
 
     if (grip->_priv->icon_pixbuf) {
         GdkRectangle pixbuf_rect;
index d9f805ffe1b3eaafb0099488629dfc763a1fdaab..87fbb41a08474779f71ded6b803a787d499ab471 100644 (file)
@@ -355,6 +355,7 @@ static void
 gdl_dock_item_instance_init (GdlDockItem *item)
 {
     GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (item), GTK_NO_WINDOW);
+    GTK_WIDGET_SET_FLAGS (GTK_WIDGET (item), GTK_CAN_FOCUS);
 
     item->child = NULL;
     
index 79f5d08fb257fb8751c8cfeb442f3c137822fdc2..55daf772bcfba79b7cf69459501b3aed38fc2ef9 100644 (file)
@@ -37,7 +37,7 @@ FloatingBehavior::FloatingBehavior(Dialog& dialog) :
     _d->set_has_separator(false);
 
     signal_response().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::on_response));
-    _d->signal_delete_event().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::on_delete_event));
+    signal_delete_event().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::on_delete_event));
 
     sp_transientize(GTK_WIDGET(_d->gobj()));
     _dialog.retransientize_suppress = false;
index 58a0e87f451fe5ca06c48bce2cee19ecd058c4a3..d615de1ffacfc35753fd2cfd161f162deb1cb58a 100644 (file)
@@ -87,6 +87,7 @@ DockItem::DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& l
     signal_show().connect(sigc::mem_fun(*this, &Inkscape::UI::Widget::DockItem::_onShow), false);
     signal_state_changed().connect(sigc::mem_fun(*this, &Inkscape::UI::Widget::DockItem::_onStateChanged));
     signal_delete_event().connect(sigc::mem_fun(*this, &Inkscape::UI::Widget::DockItem::_onDeleteEvent));
+    signal_realize().connect(sigc::mem_fun(*this, &Inkscape::UI::Widget::DockItem::_onRealize));
 
     _dock.addItem(*this, (_prev_state == FLOATING_STATE ? FLOATING : TOP));
 
@@ -117,6 +118,74 @@ DockItem::get_vbox()
 }
 
 
+void 
+DockItem::get_position(int& x, int& y)
+{ 
+    if (getWindow()) {
+        getWindow()->get_position(x, y);
+    } else {
+        x = _x;
+        y = _y;
+    }
+}
+
+void 
+DockItem::get_size(int& width, int& height)
+{ 
+    if (_window) {
+        _window->get_size(width, height);
+    } else {
+        width = get_vbox()->get_width();
+        height = get_vbox()->get_height();
+    }
+}
+
+
+void
+DockItem::resize(int width, int height) 
+{
+    if (_window)
+        _window->resize(width, height);
+}
+
+
+void
+DockItem::move(int x, int y)
+{
+    if (_window)
+        _window->move(x, y);
+}
+
+void
+DockItem::set_position(Gtk::WindowPosition position)
+{
+    if (_window)
+        _window->set_position(position);
+}
+
+void
+DockItem::set_size_request(int width, int height)
+{
+    getWidget().set_size_request(width, height);
+}
+
+void 
+DockItem::size_request(Gtk::Requisition& requisition)
+{ 
+    getWidget().size_request(requisition);
+}
+
+void
+DockItem::set_title(Glib::ustring title)
+{
+    g_object_set (_gdl_dock_item,
+                  "long-name", title.c_str(),
+                  NULL);
+
+    gdl_dock_item_set_tablabel(GDL_DOCK_ITEM(_gdl_dock_item),
+                               gtk_label_new (title.c_str()));
+}
+
 bool
 DockItem::isAttached() const
 {
@@ -200,20 +269,13 @@ DockItem::show_all()
 void
 DockItem::present()
 {
-    // iconified
-    if (isIconified()) {
+    // iconified or unattached
+    if (isIconified() || !isAttached()) {
         show();
-        return;
-    }
-    
-    // unattached
-    if (!isAttached()) {
-        gdl_dock_item_show_item (GDL_DOCK_ITEM(_gdl_dock_item));
-        return;
-    }
+    }        
 
     // tabbed
-    if (getPlacement() == CENTER) {
+    else if (getPlacement() == CENTER) {
         int i = gtk_notebook_page_num (GTK_NOTEBOOK (_gdl_dock_item->parent),
                                        GTK_WIDGET (_gdl_dock_item));
         if (i >= 0)
@@ -221,79 +283,21 @@ DockItem::present()
         return;
     }
 
-    // we're already present, do nothing
+    // always grab focus, even if we're already present
+    grab_focus();
 }
 
 
-void 
-DockItem::get_position(int& x, int& y)
-{ 
-    if (getWindow()) {
-        getWindow()->get_position(x, y);
-    } else {
-        x = _x;
-        y = _y;
-    }
-}
-
-void 
-DockItem::get_size(int& width, int& height)
-{ 
-    if (_window) {
-        _window->get_size(width, height);
-    } else {
-        width = get_vbox()->get_width();
-        height = get_vbox()->get_height();
-    }
-}
-
-
-void
-DockItem::resize(int width, int height) 
-{
-    if (_window)
-        _window->resize(width, height);
-}
-
-
-void
-DockItem::move(int x, int y)
-{
-    if (_window)
-        _window->move(x, y);
-}
-
-void
-DockItem::set_position(Gtk::WindowPosition position)
-{
-    if (_window)
-        _window->set_position(position);
-}
-
 void
-DockItem::set_size_request(int width, int height)
+DockItem::grab_focus()
 {
-    getWidget().set_size_request(width, height);
-}
-
-void 
-DockItem::size_request(Gtk::Requisition& requisition)
-{ 
-    getWidget().size_request(requisition);
+    if (GTK_WIDGET_REALIZED (_gdl_dock_item))
+        gtk_widget_grab_focus (_gdl_dock_item);
+    else
+        _grab_focus_on_realize = true;
 }
 
 
-void
-DockItem::set_title(Glib::ustring title)
-{
-    g_object_set (_gdl_dock_item,
-                  "long-name", title.c_str(),
-                  NULL);
-
-    gdl_dock_item_set_tablabel(GDL_DOCK_ITEM(_gdl_dock_item),
-                               gtk_label_new (title.c_str()));
-}
-
 /* Signal wrappers */
 
 Glib::SignalProxy0<void>
@@ -338,6 +342,13 @@ DockItem::signal_drag_end()
                                           &_signal_drag_end_proxy);
 }
 
+Glib::SignalProxy0<void>
+DockItem::signal_realize()
+{
+    return Glib::SignalProxy0<void>(Glib::wrap(GTK_WIDGET(_gdl_dock_item)),
+                                    &_signal_realize_proxy);
+}
+
 sigc::signal<void, DockItem::State, DockItem::State>
 DockItem::signal_state_changed()
 {
@@ -387,6 +398,15 @@ DockItem::_onDragEnd(bool)
     _prev_state = state;
 }
 
+void
+DockItem::_onRealize()
+{
+    if (_grab_focus_on_realize) {
+        _grab_focus_on_realize = false;
+        grab_focus();
+    }
+}
+
 bool
 DockItem::_onKeyPress(GdkEventKey *event)
 {
@@ -477,6 +497,15 @@ DockItem::_signal_drag_end_proxy =
 };
 
 
+const Glib::SignalProxyInfo
+DockItem::_signal_realize_proxy = 
+{
+    "realize",
+    (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+    (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
 gboolean
 DockItem::_signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, void *data)
 {
index f4e403e34ecd55d607357e1b914b445dd4a60ee3..d2881c0053263709f4e064c511b6fa557b7b7961 100644 (file)
@@ -80,12 +80,15 @@ public:
 
     void present();
 
+    void grab_focus();
+
     Glib::SignalProxy0<void> signal_show();
     Glib::SignalProxy0<void> signal_hide();
     Glib::SignalProxy1<bool, GdkEventAny *> signal_delete_event();
     Glib::SignalProxy1<void, int> signal_response();
     Glib::SignalProxy0<void> signal_drag_begin();
     Glib::SignalProxy1<void, bool> signal_drag_end();
+    Glib::SignalProxy0<void> signal_realize();
 
     sigc::signal<void, State, State> signal_state_changed();
 
@@ -99,6 +102,8 @@ private:
     Gtk::Window *_window;     //< reference to floating window, if any 
     int _x, _y;               //< last known position of window, if floating
 
+    bool _grab_focus_on_realize;   //< if the dock item should grab focus on the next realize
+
     GtkWidget *_gdl_dock_item;
     Glib::RefPtr<Gdk::Pixbuf> _icon_pixbuf;
 
@@ -116,6 +121,8 @@ private:
     void _onResponse(int response_id);
     void _onDragBegin();
     void _onDragEnd(bool cancelled);
+    void _onRealize();
+
     bool _onKeyPress(GdkEventKey *event);
     void _onStateChanged(State prev_state, State new_state);
     bool _onDeleteEvent(GdkEventAny *event);
@@ -129,6 +136,7 @@ private:
     static const Glib::SignalProxyInfo _signal_response_proxy;
     static const Glib::SignalProxyInfo _signal_drag_begin_proxy;
     static const Glib::SignalProxyInfo _signal_drag_end_proxy;
+    static const Glib::SignalProxyInfo _signal_realize_proxy;
 
     static gboolean _signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, void *data);
     static void _signal_drag_end_callback(GtkWidget* self, gboolean p0, void* data);
index be0c4ef1db5ae7692a5088b632812de6795c6127..3b2cb8d772783fbd0616dc166edcd47f38043a0f 100644 (file)
@@ -68,8 +68,6 @@ protected:
     /** Internal signal handlers */
     void _onLayoutChanged();
 
-    void _onFoo();
-
     /** GdlDock signal proxy structures */
     static const Glib::SignalProxyInfo _signal_layout_changed_proxy;