aboutsummaryrefslogtreecommitdiff
path: root/src/Toolbar.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Toolbar.hh')
-rw-r--r--src/Toolbar.hh295
1 files changed, 173 insertions, 122 deletions
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index d6e19db..59b1600 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,193 @@
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.38 2003/07/10 15:52:58 fluxgen Exp $
23#define _TOOLBAR_HH_
24
25#include <X11/Xlib.h>
26
27 26
27#ifndef TOOLBAR_HH
28#define TOOLBAR_HH
28 29
29
30#include "Basemenu.hh"
31#include "LinkedList.hh"
32#include "Timer.hh" 30#include "Timer.hh"
33#include "IconBar.hh" 31#include "ToolbarTheme.hh"
32#include "EventHandler.hh"
33#include "FbWindow.hh"
34#include "ArrowButton.hh"
35#include "Observer.hh"
36#include "XLayer.hh"
37#include "XLayerItem.hh"
38#include "LayerMenu.hh"
39#include "Resource.hh"
40
41#include <memory>
42
43class BScreen;
44class Strut;
45class IconBar;
46class Shape;
47
48namespace FbTk {
49class ImageControl;
50};
34 51
52/// The toolbar.
53/// Handles iconbar, workspace name view and clock view
54class Toolbar : public FbTk::TimeoutHandler, public FbTk::EventHandler {
55public:
56
57 /// Toolbar placement on the screen
58 enum Placement{
59 // top and bottom placement
60 TOPLEFT = 1, BOTTOMLEFT, TOPCENTER,
61 BOTTOMCENTER, TOPRIGHT, BOTTOMRIGHT,
62 // left and right placement
63 LEFTCENTER, LEFTBOTTOM, LEFTTOP,
64 RIGHTCENTER, RIGHTBOTTOM, RIGHTTOP
65 };
66
67 /// Create a toolbar on the screen with specific width
68 Toolbar(BScreen &screen, FbTk::XLayer &layer, FbTk::Menu &menu, size_t width = 200);
69
70 virtual ~Toolbar();
71
72 /// add icon to iconbar
73 void addIcon(FluxboxWindow *w);
74 /// remove icon from iconbar
75 void delIcon(FluxboxWindow *w);
76 bool containsIcon(const FluxboxWindow &win) const;
77 /// remove all icons
78 void delAllIcons(bool ignore_stuck = false);
79 void enableIconBar();
80 void disableIconBar();
81 void raise();
82 void lower();
83
84 void enableUpdates();
85 void disableUpdates();
86
87 inline const FbTk::Menu &menu() const { return m_toolbarmenu; }
88 inline FbTk::Menu &menu() { return m_toolbarmenu; }
89 inline FbTk::Menu &placementMenu() { return m_placementmenu; }
90 inline const FbTk::Menu &placementMenu() const { return m_placementmenu; }
91
92 inline FbTk::Menu &layermenu() { return m_layermenu; }
93 inline const FbTk::Menu &layermenu() const { return m_layermenu; }
94
95 void moveToLayer(int layernum);
96
97 FbTk::XLayerItem &layerItem() { return m_layeritem; }
98
99 /// are we in workspacename editing?
100 inline bool isEditing() const { return m_editing; }
101 /// are we hidden?
102 inline bool isHidden() const { return m_hidden; }
103 /// do we auto hide the toolbar?
104 inline bool doAutoHide() const { return *m_rc_auto_hide; }
105 /// @return X window of the toolbar
106 inline const FbTk::FbWindow &window() const { return frame.window; }
107 inline BScreen &screen() { return m_screen; }
108 inline const BScreen &screen() const { return m_screen; }
109 inline unsigned int width() const { return frame.width; }
110 inline unsigned int height() const { return frame.height; }
111 inline unsigned int exposedHeight() const { return doAutoHide() ? frame.bevel_w : frame.height; }
112 inline int x() const { return isHidden() ? frame.x_hidden : frame.x; }
113 inline int y() const { return isHidden() ? frame.y_hidden : frame.y; }
114 inline Placement placement() const { return *m_rc_placement; }
115 /// @return pointer to iconbar if it got one, else 0
116 inline const IconBar *iconBar() const { return m_iconbar.get(); }
117 inline const ToolbarTheme &theme() const { return m_theme; }
118 inline ToolbarTheme &theme() { return m_theme; }
119 bool isVertical() const;
120
121 /**
122 @name eventhandlers
123 */
124 //@{
125 void buttonPressEvent(XButtonEvent &be);
126 void buttonReleaseEvent(XButtonEvent &be);
127 void enterNotifyEvent(XCrossingEvent &ce);
128 void leaveNotifyEvent(XCrossingEvent &ce);
129 void exposeEvent(XExposeEvent &ee);
130 void keyPressEvent(XKeyEvent &ke);
131 //@}
132
133 void redrawWindowLabel(bool redraw= false);
134 void redrawWorkspaceLabel(bool redraw= false);
135 /// enter edit mode on workspace label
136 void edit();
137 void reconfigure();
138 void setPlacement(Placement where);
139 void checkClock(bool redraw = false, bool date = false);
35 140
36// forward declaration 141 virtual void timeout();
37class Toolbar;
38 142
39class Toolbarmenu : public Basemenu { 143
40private: 144private:
41 class Placementmenu : public Basemenu { 145 void setupMenus();
42 private: 146 void clearStrut();
43 Toolbarmenu *toolbarmenu; 147 void updateStrut();
44 148
45 protected: 149 bool m_editing; ///< edit workspace label mode
46 virtual void itemSelected(int, int); 150 bool m_hidden; ///< hidden state
47 151
48 public: 152 /// Toolbar frame
49 Placementmenu(Toolbarmenu *); 153 struct Frame {
50 }; 154 Frame(FbTk::EventHandler &evh, int screen_num);
155 ~Frame();
51 156
52 Toolbar *toolbar; 157 Pixmap base, label, wlabel, clk, button, pbutton;
53 Placementmenu *placementmenu; 158 FbTk::FbWindow window, workspace_label, window_label, clock;
159 ArrowButton psbutton, nsbutton, pwbutton, nwbutton;
54 160
55 friend class Placementmenu; 161 int x, y, x_hidden, y_hidden, hour, minute, grab_x, grab_y;
56 friend class Toolbar; 162 unsigned int width, height, window_label_w, workspace_label_w, clock_w,
163 button_w, bevel_w, label_h;
164 } frame;
57 165
166 class HideHandler : public FbTk::TimeoutHandler {
167 public:
168 Toolbar *toolbar;
58 169
59protected: 170 virtual void timeout();
60 virtual void itemSelected(int, int); 171 } hide_handler;
61 virtual void internal_hide(void);
62 172
63public: 173 friend class HideHandler;
64 Toolbarmenu(Toolbar *);
65 ~Toolbarmenu(void);
66 174
67 inline Basemenu *getPlacementmenu(void) { return placementmenu; } 175 BScreen &m_screen; ///< screen connection
68 176
69 void reconfigure(void); 177 FbTk::Timer m_clock_timer; ///< timer to update clock
70}; 178 FbTk::Timer m_hide_timer; ///< timer to for auto hide toolbar
71 179 FbTk::Menu &m_toolbarmenu;
72 180 FbTk::Menu m_placementmenu;
73class Toolbar : public TimeoutHandler { 181 LayerMenu<Toolbar> m_layermenu;
74private: 182 std::auto_ptr<IconBar> m_iconbar;
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
105 friend class HideHandler;
106 friend class Toolbarmenu;
107 friend class Toolbarmenu::Placementmenu;
108
109
110public:
111 Toolbar(BScreen *);
112 virtual ~Toolbar(void);
113 void addIcon(FluxboxWindow *w);
114 void delIcon(FluxboxWindow *w);
115 183
116 inline Toolbarmenu *getMenu(void) { return toolbarmenu; } 184 std::string m_new_workspace_name; ///< temp variable in edit workspace name mode
117 //inline Window getWindowLabel(void) { return frame.window_label; } 185
118 inline const Bool &isEditing(void) const { return editing; } 186 ToolbarTheme m_theme;
119 inline const Bool &isOnTop(void) const { return on_top; } 187
120 inline const Bool &isHidden(void) const { return hidden; } 188 //!! TODO this is just temporary
121 inline const Bool &doAutoHide(void) const { return do_auto_hide; } 189 class ThemeListener: public FbTk::Observer {
122 190 public:
123 inline const Window &getWindowID(void) const { return frame.window; } 191 ThemeListener(Toolbar &tb):m_tb(tb) { }
124 192 void update(FbTk::Subject *subj) {
125 inline const unsigned int &getWidth(void) const { return frame.width; } 193 m_tb.reconfigure();
126 inline const unsigned int &getHeight(void) const { return frame.height; } 194 }
127 inline const unsigned int &getExposedHeight(void) const 195 private:
128 { return ((do_auto_hide) ? frame.bevel_w : frame.height); } 196 Toolbar &m_tb;
129 inline const int &getX(void) const 197 };
130 { return ((hidden) ? frame.x_hidden : frame.x); } 198
131 inline const int &getY(void) const 199 ThemeListener m_themelistener;
132 { return ((hidden) ? frame.y_hidden : frame.y); } 200
133 201 FbTk::XLayerItem m_layeritem;
134 void buttonPressEvent(XButtonEvent *); 202
135 void buttonReleaseEvent(XButtonEvent *); 203 Strut *m_strut; ///< created and destroyed by BScreen
136 void enterNotifyEvent(XCrossingEvent *); 204 // resources
137 void leaveNotifyEvent(XCrossingEvent *); 205 FbTk::Resource<bool> m_rc_auto_hide, m_rc_maximize_over;
138 void exposeEvent(XExposeEvent *); 206 FbTk::Resource<int> m_rc_width_percent;
139 void keyPressEvent(XKeyEvent *); 207 FbTk::Resource<Fluxbox::Layer> m_rc_layernum;
140 208 FbTk::Resource<int> m_rc_on_head;
141 void redrawWindowLabel(Bool = False); 209 FbTk::Resource<Placement> m_rc_placement;
142 void redrawWorkspaceLabel(Bool = False); 210 std::auto_ptr<Shape> m_shape;
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}; 211};
161 212
162 213
163#endif // __Toolbar_hh 214#endif // TOOLBAR_HH