diff options
Diffstat (limited to 'src/Toolbar.hh')
-rw-r--r-- | src/Toolbar.hh | 265 |
1 files changed, 148 insertions, 117 deletions
diff --git a/src/Toolbar.hh b/src/Toolbar.hh index d6e19db..2ff3a02 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh | |||
@@ -1,3 +1,6 @@ | |||
1 | // Toolbar.hh for Fluxbox | ||
2 | // Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
1 | // Toolbar.hh for Blackbox - an X11 Window manager | 4 | // Toolbar.hh for Blackbox - an X11 Window manager |
2 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | 5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) |
3 | // | 6 | // |
@@ -19,145 +22,173 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
21 | 24 | ||
22 | #ifndef _TOOLBAR_HH_ | 25 | // $Id: Toolbar.hh,v 1.52 2003/12/20 19:04:45 fluxgen Exp $ |
23 | #define _TOOLBAR_HH_ | ||
24 | |||
25 | #include <X11/Xlib.h> | ||
26 | 26 | ||
27 | #ifndef TOOLBAR_HH | ||
28 | #define TOOLBAR_HH | ||
27 | 29 | ||
30 | #include "ToolbarTheme.hh" | ||
31 | #include "LayerMenu.hh" | ||
32 | #include "ToolFactory.hh" | ||
33 | #include "ToolTheme.hh" | ||
28 | 34 | ||
35 | #include "FbTk/Timer.hh" | ||
36 | #include "FbTk/Resource.hh" | ||
37 | #include "FbTk/Observer.hh" | ||
38 | #include "FbTk/XLayer.hh" | ||
39 | #include "FbTk/XLayerItem.hh" | ||
40 | #include "FbTk/EventHandler.hh" | ||
41 | #include "FbTk/FbWindow.hh" | ||
29 | 42 | ||
30 | #include "Basemenu.hh" | 43 | #include <memory> |
31 | #include "LinkedList.hh" | ||
32 | #include "Timer.hh" | ||
33 | #include "IconBar.hh" | ||
34 | 44 | ||
45 | class BScreen; | ||
46 | class Strut; | ||
47 | class FbMenu; | ||
48 | class Shape; | ||
49 | class ToolbarItem; | ||
35 | 50 | ||
36 | // forward declaration | 51 | namespace FbTk { |
37 | class Toolbar; | 52 | class ImageControl; |
53 | } | ||
38 | 54 | ||
39 | class Toolbarmenu : public Basemenu { | 55 | /// The toolbar. |
56 | /// Handles iconbar, workspace name view and clock view | ||
57 | class Toolbar: public FbTk::EventHandler, public FbTk::Observer { | ||
58 | public: | ||
59 | |||
60 | /// Toolbar placement on the screen | ||
61 | enum Placement{ | ||
62 | // top and bottom placement | ||
63 | TOPLEFT = 1, BOTTOMLEFT, TOPCENTER, | ||
64 | BOTTOMCENTER, TOPRIGHT, BOTTOMRIGHT, | ||
65 | // left and right placement | ||
66 | LEFTCENTER, LEFTBOTTOM, LEFTTOP, | ||
67 | RIGHTCENTER, RIGHTBOTTOM, RIGHTTOP | ||
68 | }; | ||
69 | |||
70 | /// Create a toolbar on the screen with specific width | ||
71 | Toolbar(BScreen &screen, FbTk::XLayer &layer, size_t width = 200); | ||
72 | |||
73 | virtual ~Toolbar(); | ||
74 | |||
75 | void raise(); | ||
76 | void lower(); | ||
77 | void updateVisibleState(); | ||
78 | void toggleHidden(); | ||
79 | |||
80 | |||
81 | void moveToLayer(int layernum); | ||
82 | |||
83 | void saveOnHead(int head); | ||
84 | |||
85 | /** | ||
86 | @name eventhandlers | ||
87 | */ | ||
88 | //@{ | ||
89 | void buttonPressEvent(XButtonEvent &be); | ||
90 | void buttonReleaseEvent(XButtonEvent &be); | ||
91 | void enterNotifyEvent(XCrossingEvent &ce); | ||
92 | void leaveNotifyEvent(XCrossingEvent &ce); | ||
93 | void exposeEvent(XExposeEvent &ee); | ||
94 | void handleEvent(XEvent &event); | ||
95 | //@} | ||
96 | |||
97 | /// enter edit mode on workspace label | ||
98 | void edit(); | ||
99 | void reconfigure(); | ||
100 | void setPlacement(Placement where); | ||
101 | |||
102 | void update(FbTk::Subject *subj); | ||
103 | |||
104 | FbTk::XLayerItem &layerItem() { return m_layeritem; } | ||
105 | |||
106 | inline const FbTk::Menu &menu() const { return m_toolbarmenu; } | ||
107 | inline FbTk::Menu &menu() { return m_toolbarmenu; } | ||
108 | inline FbTk::Menu &placementMenu() { return m_placementmenu; } | ||
109 | inline const FbTk::Menu &placementMenu() const { return m_placementmenu; } | ||
110 | |||
111 | inline FbTk::Menu &layermenu() { return m_layermenu; } | ||
112 | inline const FbTk::Menu &layermenu() const { return m_layermenu; } | ||
113 | |||
114 | /// are we hidden? | ||
115 | inline bool isHidden() const { return m_hidden; } | ||
116 | /// do we auto hide the toolbar? | ||
117 | inline bool doAutoHide() const { return *m_rc_auto_hide; } | ||
118 | /// @return X window of the toolbar | ||
119 | inline const FbTk::FbWindow &window() const { return frame.window; } | ||
120 | inline BScreen &screen() { return m_screen; } | ||
121 | inline const BScreen &screen() const { return m_screen; } | ||
122 | inline unsigned int width() const { return frame.window.width(); } | ||
123 | inline unsigned int height() const { return frame.window.height(); } | ||
124 | inline unsigned int exposedHeight() const { return doAutoHide() ? frame.bevel_w : frame.height; } | ||
125 | inline int x() const { return isHidden() ? frame.x_hidden : frame.x; } | ||
126 | inline int y() const { return isHidden() ? frame.y_hidden : frame.y; } | ||
127 | inline Placement placement() const { return *m_rc_placement; } | ||
128 | /// @return pointer to iconbar if it got one, else 0 | ||
129 | inline const ToolbarTheme &theme() const { return m_theme; } | ||
130 | inline ToolbarTheme &theme() { return m_theme; } | ||
131 | bool isVertical() const; | ||
132 | |||
133 | inline int getOnHead() const { return *m_rc_on_head; } | ||
134 | |||
40 | private: | 135 | private: |
41 | class Placementmenu : public Basemenu { | 136 | void rearrangeItems(); |
42 | private: | 137 | void deleteItems(); |
43 | Toolbarmenu *toolbarmenu; | ||
44 | 138 | ||
45 | protected: | 139 | void updateIconbarGraphics(); |
46 | virtual void itemSelected(int, int); | 140 | void setupMenus(); |
141 | void clearStrut(); | ||
142 | void updateStrut(); | ||
47 | 143 | ||
48 | public: | 144 | bool m_hidden; ///< hidden state |
49 | Placementmenu(Toolbarmenu *); | ||
50 | }; | ||
51 | 145 | ||
52 | Toolbar *toolbar; | 146 | /// Toolbar frame |
53 | Placementmenu *placementmenu; | 147 | struct Frame { |
148 | Frame(FbTk::EventHandler &evh, int screen_num); | ||
149 | ~Frame(); | ||
54 | 150 | ||
55 | friend class Placementmenu; | 151 | FbTk::FbWindow window; |
56 | friend class Toolbar; | ||
57 | 152 | ||
153 | int x, y, x_hidden, y_hidden, grab_x, grab_y; | ||
154 | unsigned int width, height, bevel_w; | ||
155 | } frame; | ||
156 | // background pixmap | ||
157 | Pixmap m_window_pm; | ||
58 | 158 | ||
59 | protected: | 159 | BScreen &m_screen; ///< screen connection |
60 | virtual void itemSelected(int, int); | ||
61 | virtual void internal_hide(void); | ||
62 | 160 | ||
63 | public: | 161 | FbTk::Timer m_hide_timer; ///< timer to for auto hide toolbar |
64 | Toolbarmenu(Toolbar *); | ||
65 | ~Toolbarmenu(void); | ||
66 | 162 | ||
67 | inline Basemenu *getPlacementmenu(void) { return placementmenu; } | 163 | LayerMenu<Toolbar> m_layermenu; |
164 | FbMenu m_placementmenu, m_toolbarmenu; | ||
68 | 165 | ||
69 | void reconfigure(void); | ||
70 | }; | ||
71 | 166 | ||
167 | // themes | ||
168 | ToolbarTheme m_theme; | ||
169 | |||
170 | FbTk::XLayerItem m_layeritem; | ||
171 | typedef std::list<ToolbarItem *> ItemList; | ||
172 | ItemList m_item_list; | ||
72 | 173 | ||
73 | class Toolbar : public TimeoutHandler { | 174 | ToolFactory m_tool_factory; |
74 | private: | ||
75 | Bool on_top, editing, hidden, do_auto_hide; | ||
76 | Display *display; | ||
77 | |||
78 | struct frame { | ||
79 | unsigned long button_pixel, pbutton_pixel; | ||
80 | Pixmap base, label, wlabel, clk, button, pbutton; | ||
81 | Window window, workspace_label, window_label, clock, psbutton, nsbutton, | ||
82 | pwbutton, nwbutton; | ||
83 | |||
84 | int x, y, x_hidden, y_hidden, hour, minute, grab_x, grab_y; | ||
85 | unsigned int width, height, window_label_w, workspace_label_w, clock_w, | ||
86 | button_w, bevel_w, label_h; | ||
87 | } frame; | ||
88 | |||
89 | class HideHandler : public TimeoutHandler { | ||
90 | public: | ||
91 | Toolbar *toolbar; | ||
92 | |||
93 | virtual void timeout(void); | ||
94 | } hide_handler; | ||
95 | |||
96 | Fluxbox *fluxbox; | ||
97 | BImageControl *image_ctrl; | ||
98 | BScreen *screen; | ||
99 | BTimer *clock_timer, *hide_timer; | ||
100 | Toolbarmenu *toolbarmenu; | ||
101 | class IconBar *iconbar; | ||
102 | |||
103 | char *new_workspace_name, *new_name_pos; | ||
104 | 175 | ||
105 | friend class HideHandler; | 176 | Strut *m_strut; ///< created and destroyed by BScreen |
106 | friend class Toolbarmenu; | ||
107 | friend class Toolbarmenu::Placementmenu; | ||
108 | 177 | ||
178 | // resources | ||
179 | FbTk::Resource<bool> m_rc_auto_hide, m_rc_maximize_over, m_rc_visible; | ||
180 | FbTk::Resource<int> m_rc_width_percent; | ||
181 | FbTk::Resource<Fluxbox::Layer> m_rc_layernum; | ||
182 | FbTk::Resource<int> m_rc_on_head; | ||
183 | FbTk::Resource<Placement> m_rc_placement; | ||
184 | FbTk::Resource<int> m_rc_height; | ||
185 | FbTk::Resource<std::string> m_rc_tools; | ||
186 | std::auto_ptr<Shape> m_shape; | ||
187 | typedef std::list<std::string> StringList; | ||
188 | StringList m_tools; | ||
109 | 189 | ||
110 | public: | 190 | bool m_resize_lock; ///< to lock rearrangeItems or not |
111 | Toolbar(BScreen *); | ||
112 | virtual ~Toolbar(void); | ||
113 | void addIcon(FluxboxWindow *w); | ||
114 | void delIcon(FluxboxWindow *w); | ||
115 | |||
116 | inline Toolbarmenu *getMenu(void) { return toolbarmenu; } | ||
117 | //inline Window getWindowLabel(void) { return frame.window_label; } | ||
118 | inline const Bool &isEditing(void) const { return editing; } | ||
119 | inline const Bool &isOnTop(void) const { return on_top; } | ||
120 | inline const Bool &isHidden(void) const { return hidden; } | ||
121 | inline const Bool &doAutoHide(void) const { return do_auto_hide; } | ||
122 | |||
123 | inline const Window &getWindowID(void) const { return frame.window; } | ||
124 | |||
125 | inline const unsigned int &getWidth(void) const { return frame.width; } | ||
126 | inline const unsigned int &getHeight(void) const { return frame.height; } | ||
127 | inline const unsigned int &getExposedHeight(void) const | ||
128 | { return ((do_auto_hide) ? frame.bevel_w : frame.height); } | ||
129 | inline const int &getX(void) const | ||
130 | { return ((hidden) ? frame.x_hidden : frame.x); } | ||
131 | inline const int &getY(void) const | ||
132 | { return ((hidden) ? frame.y_hidden : frame.y); } | ||
133 | |||
134 | void buttonPressEvent(XButtonEvent *); | ||
135 | void buttonReleaseEvent(XButtonEvent *); | ||
136 | void enterNotifyEvent(XCrossingEvent *); | ||
137 | void leaveNotifyEvent(XCrossingEvent *); | ||
138 | void exposeEvent(XExposeEvent *); | ||
139 | void keyPressEvent(XKeyEvent *); | ||
140 | |||
141 | void redrawWindowLabel(Bool = False); | ||
142 | void redrawWorkspaceLabel(Bool = False); | ||
143 | void redrawPrevWorkspaceButton(Bool = False, Bool = False); | ||
144 | void redrawNextWorkspaceButton(Bool = False, Bool = False); | ||
145 | void redrawPrevWindowButton(Bool = False, Bool = False); | ||
146 | void redrawNextWindowButton(Bool = False, Bool = False); | ||
147 | void edit(void); | ||
148 | void reconfigure(void); | ||
149 | |||
150 | #ifdef HAVE_STRFTIME | ||
151 | void checkClock(Bool = False); | ||
152 | #else // HAVE_STRFTIME | ||
153 | void checkClock(Bool = False, Bool = False); | ||
154 | #endif // HAVE_STRFTIME | ||
155 | |||
156 | virtual void timeout(void); | ||
157 | |||
158 | enum { TopLeft = 1, BottomLeft, TopCenter, | ||
159 | BottomCenter, TopRight, BottomRight }; | ||
160 | }; | 191 | }; |
161 | 192 | ||
162 | 193 | ||
163 | #endif // __Toolbar_hh | 194 | #endif // TOOLBAR_HH |