1 /**************************************************************************
2 ** (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
10 ** DESCRIPTION : Definition of menu classes
12 ** EXPORTED OBJECTS : class menu_container
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 13, 1998
20 ** LAST UPDATE : Mar 07, 1998
22 **************************************************************************/
24 /*****************************
26 Revision 1.1 2002-07-25 08:01:27 arjen
27 First checkin, AXE release 0.2
29 *****************************/
31 /* static const char *RCSID = "$Id: menu.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
37 ///////////////////////////////////////////////////////////////////////////
38 // NAME : menu_container
40 // MEMBERS : mode : Horizontal or Vertical
44 // DESCRIPTION : A menu_container is the parent window of menu items.
45 // The menu_container lines the menu items up next to
46 // eachother and makes them all fit together.
48 // RELATIONS : shown_by : menu_item that popped me up. The menu item
49 // which is clicked uses this to climb to
50 // the top of the menu tree and hide all submenus
52 // LAST MODIFIED : Feb 27, 1998
53 ///////////////////////////////////////////////////////////////////////////
56 class menu_item; // Forward declaration.
58 class menu_container : public window
63 enum {Horizontal, Vertical} mode;
70 * Both constructors perform the same function. Create a window
71 * with default size, set the background color and solicit
72 * StructureNotify events.
73 * Note that the size of the menu_container is eventually determined
74 * by the sizes of the menu items.
77 menu_container() : window(0, 0, 50, 100, 1)
81 Background(menu_normal);
82 SelectInput(StructureNotifyMask, 1);
85 menu_container(window &frame) : window(frame, 0, 0, 100, 15)
89 Background(menu_normal);
90 SelectInput(StructureNotifyMask, 1);
93 void RearrangeItems(unsigned &overall_width, unsigned &overall_height);
96 * The position of a sub-menu depends on the mode. Horizontal menus
97 * put submenus below the item, vertical menus put a submenu right
101 void PositionSubmenu(int &x, int &y, unsigned w, unsigned h)
103 if (mode == Horizontal)
110 * Submenu management.
113 void HideSubmenus(void);
115 void Show(menu_item *by, int x, int y);
121 ///////////////////////////////////////////////////////////////////////////
123 // BASECLASS : window
133 ///////////////////////////////////////////////////////////////////////////
136 class menu_item : public window
145 menu_container *popup;
149 menu_item(window &bar, int cc, int en = 1) : window(bar, 0, 0, 50, 15, 0)
156 SelectInput(ExposureMask, 1);
157 Background(menu_normal);
158 SelectInput(ButtonReleaseMask|EnterWindowMask|LeaveWindowMask, enabled);
161 virtual void redraw(void);
163 virtual int EV_Expose(XExposeEvent ev)
169 virtual int EV_EnterNotify(XCrossingEvent ev);
170 virtual int EV_LeaveNotify(XCrossingEvent ev);
171 virtual int EV_ButtonRelease(XButtonEvent ev);
173 void HideSubmenu(void);
174 void ShowSubmenu(int x, int y);
176 void Popup(menu_container *pop)
184 SelectInput(EnterWindowMask, e);
190 ///////////////////////////////////////////////////////////////////////////
192 // BASECLASS : menu_container
202 ///////////////////////////////////////////////////////////////////////////
205 class menu_bar : public menu_container
209 menu_bar(window &frame) : menu_container(frame)
215 virtual int ParentResized(int w, int h)
217 unsigned width, height;
219 RearrangeItems(width, height);
221 // Resize to fit the parent window
231 ///////////////////////////////////////////////////////////////////////////
233 // BASECLASS : menu_container
243 ///////////////////////////////////////////////////////////////////////////
246 class popup_menu: public menu_container
250 popup_menu() : menu_container()
252 XSetWindowAttributes attrib;
255 attrib.override_redirect = True;
256 mask = CWOverrideRedirect;
258 XChangeWindowAttributes(stddpy.Dpy(), ID(), mask, &attrib);
262 virtual int EV_ConfigureNotify(XConfigureEvent ev)
264 unsigned width, height;
266 RearrangeItems(width, height);
268 Resize(width, height);
277 ///////////////////////////////////////////////////////////////////////////
279 // BASECLASS : menu_item
288 // LAST MODIFIED : Mar 07, 1998
289 ///////////////////////////////////////////////////////////////////////////
292 class menu_label : public menu_item
298 menu_label(window &bar, char *text, int cc = 0) : menu_item(bar, cc)
301 int width = default_font.TextWidth(label) + 10;
302 int height = default_font.ascent() + default_font.descent() + 6;
303 Resize(width, height);
306 virtual void redraw(void);
310 ///////////////////////////////////////////////////////////////////////////
311 // NAME : menu_separator
312 // BASECLASS : menu_item
322 ///////////////////////////////////////////////////////////////////////////
325 class menu_separator : public menu_item
329 menu_separator(window &bar) : menu_item(bar, 0, 0)
334 virtual void redraw(void);