]> icculus.org git repositories - mikachu/openbox.git/blob - src/Toolbar.h
fixed snap to edges with toolbar hidden
[mikachu/openbox.git] / src / Toolbar.h
1 // Toolbar.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifndef   __Toolbar_hh
24 #define   __Toolbar_hh
25
26 #include <X11/Xlib.h>
27
28 #include "Basemenu.h"
29 #include "Timer.h"
30 #include "Screen.h"
31
32 // forward declaration
33 class Toolbar;
34
35 class Toolbarmenu : public Basemenu {
36 private:
37   class Placementmenu : public Basemenu {
38   private:
39     Toolbarmenu &toolbarmenu;
40
41   protected:
42     virtual void itemSelected(int, int);
43
44   public:
45     Placementmenu(Toolbarmenu &);
46   };
47
48   Toolbar &toolbar;
49   Placementmenu *placementmenu;
50
51   friend class Placementmenu;
52   friend class Toolbar;
53
54
55 protected:
56   virtual void itemSelected(int, int);
57   virtual void internal_hide(void);
58
59 public:
60   Toolbarmenu(Toolbar &);
61   ~Toolbarmenu(void);
62
63   inline Basemenu *getPlacementmenu(void) { return placementmenu; }
64
65   void reconfigure(void);
66 };
67
68
69 class Toolbar : public TimeoutHandler {
70 private:
71   Bool on_top, editing, hidden, do_auto_hide, do_hide;
72   Display *display;
73
74   struct frame {
75     unsigned long button_pixel, pbutton_pixel;
76     Pixmap base, label, wlabel, clk, button, pbutton;
77     Window window, workspace_label, window_label, clock, psbutton, nsbutton,
78       pwbutton, nwbutton;
79
80     int x, y, x_hidden, y_hidden, hour, minute, grab_x, grab_y;
81     unsigned int width, height, window_label_w, workspace_label_w, clock_w,
82       button_w, bevel_w, label_h;
83   } frame;
84
85   class HideHandler : public TimeoutHandler {
86   public:
87     Toolbar *toolbar;
88
89     virtual void timeout(void);
90   } hide_handler;
91
92   Openbox &openbox;
93   BImageControl *image_ctrl;
94   BScreen &screen;
95   BTimer *clock_timer, *hide_timer;
96   Toolbarmenu *toolbarmenu;
97
98   char *new_workspace_name;
99   size_t new_name_pos;
100
101   friend class HideHandler;
102   friend class Toolbarmenu;
103   friend class Toolbarmenu::Placementmenu;
104
105
106 public:
107   Toolbar(BScreen &);
108   virtual ~Toolbar(void);
109
110   inline Toolbarmenu *getMenu(void) { return toolbarmenu; }
111
112   inline const Bool &isEditing(void) const { return editing; }
113   inline const Bool &isOnTop(void) const { return on_top; }
114   inline const Bool &isHidden(void) const { return hidden; }
115   inline const Bool &doAutoHide(void) const { return do_auto_hide; }
116
117   inline const Window &getWindowID(void) const { return frame.window; }
118
119   inline const unsigned int &getWidth(void) const { return frame.width; }
120   inline const unsigned int &getHeight(void) const { return frame.height; }
121   inline const unsigned int getExposedHeight(void) const {
122     if (do_hide) return 0;
123     else if (do_auto_hide) return frame.bevel_w;
124     else return frame.height;
125   }
126   
127   inline const int &getX(void) const
128   { return ((hidden) ? frame.x_hidden : frame.x); }
129   //  const int getY(void) const;
130   inline const int getY(void) const { 
131     if (do_hide) return screen.size().h();
132     else if (hidden) return frame.y_hidden;
133     else return frame.y;
134   }
135
136   
137   void buttonPressEvent(XButtonEvent *);
138   void buttonReleaseEvent(XButtonEvent *);
139   void enterNotifyEvent(XCrossingEvent *);
140   void leaveNotifyEvent(XCrossingEvent *);
141   void exposeEvent(XExposeEvent *);
142   void keyPressEvent(XKeyEvent *);
143
144   void redrawWindowLabel(Bool = False);
145   void redrawWorkspaceLabel(Bool = False);
146   void redrawPrevWorkspaceButton(Bool = False, Bool = False);
147   void redrawNextWorkspaceButton(Bool = False, Bool = False);
148   void redrawPrevWindowButton(Bool = False, Bool = False);
149   void redrawNextWindowButton(Bool = False, Bool = False);
150   void edit(void);
151   void reconfigure(void);
152   void mapToolbar(void);
153   void unMapToolbar(void);
154 #ifdef    HAVE_STRFTIME
155   void checkClock(Bool = False);
156 #else //  HAVE_STRFTIME
157   void checkClock(Bool = False, Bool = False);
158 #endif // HAVE_STRFTIME
159
160   virtual void timeout(void);
161
162   enum { TopLeft = 1, BottomLeft, TopCenter,
163          BottomCenter, TopRight, BottomRight };
164 };
165
166
167 #endif // __Toolbar_hh