Code

Allow GdlDockItems to take focus, and grab focus on present. Various
[inkscape.git] / src / ui / widget / dock-item.h
1 /**
2  * \brief A custom wrapper around gdl-dock-item
3  *
4  * Author:
5  *   Gustav Broberg <broberg@kth.se>
6  *
7  * Copyright (C) 2007 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */
13 #ifndef INKSCAPE_UI_WIGET_DOCK_ITEM_H
14 #define INKSCAPE_UI_WIGET_DOCK_ITEM_H
16 #include <gtkmm/button.h>
17 #include <gtkmm/buttonbox.h>
18 #include <gtkmm/frame.h>
19 #include <gtkmm/paned.h>
20 #include <gtkmm/window.h>
22 #include "libgdl/libgdl.h"
24 namespace Inkscape {
25 namespace UI {
26 namespace Widget {
28 class Dock;
30 class DockItem {
32 public:
34     enum State { UNATTACHED, FLOATING_STATE, DOCKED_STATE };
36     enum Placement { 
37         NONE     = GDL_DOCK_NONE,
38         TOP      = GDL_DOCK_TOP,
39         BOTTOM   = GDL_DOCK_BOTTOM,
40         RIGHT    = GDL_DOCK_RIGHT,
41         LEFT     = GDL_DOCK_LEFT,
42         CENTER   = GDL_DOCK_CENTER,
43         FLOATING = GDL_DOCK_FLOATING
44     };
46     DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& long_name, 
47              const Glib::ustring& icon_name, State state);
49     ~DockItem();
51     Gtk::Widget& getWidget();
52     GtkWidget *gobj();
54     Gtk::VBox *get_vbox();
56     void get_position(int& x, int& y);
57     void get_size(int& width, int& height);
59     void resize(int width, int height);
60     void move(int x, int y);
61     void set_position(Gtk::WindowPosition);
62     void set_size_request(int width, int height);
63     void size_request(Gtk::Requisition& requisition);
64     void set_title(Glib::ustring title);
66     bool isAttached() const;
67     bool isFloating() const;
68     bool isIconified() const;
69     State getState() const;
70     State getPrevState() const;
71     Placement getPlacement() const;
73     Gtk::Window *getWindow();   //< gives the parent window, if the dock item has one (i.e. it's floating)
75     void addButton(Gtk::Button *button, int response_id);
77     void hide();
78     void show();
79     void show_all();
81     void present();
83     void grab_focus();
85     Glib::SignalProxy0<void> signal_show();
86     Glib::SignalProxy0<void> signal_hide();
87     Glib::SignalProxy1<bool, GdkEventAny *> signal_delete_event();
88     Glib::SignalProxy1<void, int> signal_response();
89     Glib::SignalProxy0<void> signal_drag_begin();
90     Glib::SignalProxy1<void, bool> signal_drag_end();
91     Glib::SignalProxy0<void> signal_realize();
93     sigc::signal<void, State, State> signal_state_changed();
95 private:
96     Dock &_dock;              //< parent dock
98     State _prev_state;        //< last known state
100     int _prev_position;
102     Gtk::Window *_window;     //< reference to floating window, if any 
103     int _x, _y;               //< last known position of window, if floating
105     bool _grab_focus_on_realize;   //< if the dock item should grab focus on the next realize
107     GtkWidget *_gdl_dock_item;
108     Glib::RefPtr<Gdk::Pixbuf> _icon_pixbuf;
110     /** Interface widgets, will be packed like 
111      * gdl_dock_item -> _frame -> _dock_item_box -> (_dock_item_action_area) 
112      */
113     Gtk::Frame _frame;
114     Gtk::VBox _dock_item_box;
115     Gtk::HButtonBox *_dock_item_action_area;
117     /** Internal signal handlers */
118     void _onHide();
119     void _onHideWindow();
120     void _onShow();
121     void _onResponse(int response_id);
122     void _onDragBegin();
123     void _onDragEnd(bool cancelled);
124     void _onRealize();
126     bool _onKeyPress(GdkEventKey *event);
127     void _onStateChanged(State prev_state, State new_state);
128     bool _onDeleteEvent(GdkEventAny *event);
130     sigc::connection _signal_key_press_event_connection;
132     /** GdlDockItem signal proxy structures */
133     static const Glib::SignalProxyInfo _signal_show_proxy;
134     static const Glib::SignalProxyInfo _signal_hide_proxy;
135     static const Glib::SignalProxyInfo _signal_delete_event_proxy;
136     static const Glib::SignalProxyInfo _signal_response_proxy;
137     static const Glib::SignalProxyInfo _signal_drag_begin_proxy;
138     static const Glib::SignalProxyInfo _signal_drag_end_proxy;
139     static const Glib::SignalProxyInfo _signal_realize_proxy;
141     static gboolean _signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, void *data);
142     static void _signal_drag_end_callback(GtkWidget* self, gboolean p0, void* data);
144     /** In order to emulate a signal_response signal like the one for Gtk::Dialog we inject a new
145      * signal into GdlDockItem. This signal will be emitted when a button in the dock item added
146      * through the addButton(..., response_id) method, is clicked. 
147      */
148     static void _signal_response_callback(GtkWidget* self, gint p0, void* data);
150     sigc::signal<void, State, State> _signal_state_changed;
152     DockItem();
153 };
155 } // namespace Widget
156 } // namespace UI
157 } // namespace Inkscape
159 #endif // INKSCAPE_UI_WIGET_DOCK_ITEM_H
161 /*
162   Local Variables:
163   mode:c++
164   c-file-style:"stroustrup"
165   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
166   indent-tabs-mode:nil
167   fill-column:99
168   End:
169 */
170 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :