From: gustav_b Date: Mon, 10 Sep 2007 21:20:06 +0000 (+0000) Subject: Allow GdlDockItems to take focus, and grab focus on present. Various X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=88203f7fac722a3539389dbc0e580176f3458653;p=inkscape.git Allow GdlDockItems to take focus, and grab focus on present. Various cleanups. --- diff --git a/src/libgdl/gdl-dock-item-grip.c b/src/libgdl/gdl-dock-item-grip.c index 7465aefb2..d1ba2372c 100644 --- a/src/libgdl/gdl-dock-item-grip.c +++ b/src/libgdl/gdl-dock-item-grip.c @@ -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; diff --git a/src/libgdl/gdl-dock-item.c b/src/libgdl/gdl-dock-item.c index d9f805ffe..87fbb41a0 100644 --- a/src/libgdl/gdl-dock-item.c +++ b/src/libgdl/gdl-dock-item.c @@ -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; diff --git a/src/ui/dialog/floating-behavior.cpp b/src/ui/dialog/floating-behavior.cpp index 79f5d08fb..55daf772b 100644 --- a/src/ui/dialog/floating-behavior.cpp +++ b/src/ui/dialog/floating-behavior.cpp @@ -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; diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index 58a0e87f4..d615de1ff 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -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 @@ -338,6 +342,13 @@ DockItem::signal_drag_end() &_signal_drag_end_proxy); } +Glib::SignalProxy0 +DockItem::signal_realize() +{ + return Glib::SignalProxy0(Glib::wrap(GTK_WIDGET(_gdl_dock_item)), + &_signal_realize_proxy); +} + sigc::signal 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) { diff --git a/src/ui/widget/dock-item.h b/src/ui/widget/dock-item.h index f4e403e34..d2881c005 100644 --- a/src/ui/widget/dock-item.h +++ b/src/ui/widget/dock-item.h @@ -80,12 +80,15 @@ public: void present(); + void grab_focus(); + Glib::SignalProxy0 signal_show(); Glib::SignalProxy0 signal_hide(); Glib::SignalProxy1 signal_delete_event(); Glib::SignalProxy1 signal_response(); Glib::SignalProxy0 signal_drag_begin(); Glib::SignalProxy1 signal_drag_end(); + Glib::SignalProxy0 signal_realize(); sigc::signal 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 _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); diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index be0c4ef1d..3b2cb8d77 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -68,8 +68,6 @@ protected: /** Internal signal handlers */ void _onLayoutChanged(); - void _onFoo(); - /** GdlDock signal proxy structures */ static const Glib::SignalProxyInfo _signal_layout_changed_proxy;