1 /**************************************************************************
2 ** (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : menu.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
10 ** DESCRIPTION : Implementation of menu classes
12 ** EXPORTED OBJECTS : 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.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
38 /*=========================================================================
39 ** NAME : RearrangeItems
51 **=========================================================================
54 void menu_container::RearrangeItems(unsigned &ov_width, unsigned &ov_height)
57 unsigned width, height;
62 if (mode == Horizontal)
64 for(l = children; l; l = l->next)
66 l->child->Move(ov_width, 0);
67 l->child->Size(width, height);
69 ov_height = height > ov_height ? height : ov_height;
72 for(l = children; l; l = l->next)
74 l->child->Size(width, height);
75 l->child->Resize(width, ov_height);
78 else /* mode is Vertical */
80 for(l = children; l; l = l->next)
82 l->child->Move(0, ov_height);
83 l->child->Size(width, height);
85 ov_width = width > ov_width ? width : ov_width;
88 for(l = children; l; l = l->next)
90 l->child->Size(width, height);
91 l->child->Resize(ov_width, height);
97 /*=========================================================================
98 ** NAME : HideSubmenus
110 **=========================================================================
113 void menu_container::HideSubmenus(void)
115 //printf("HideSubmenus(0x%x)\n",this);
117 win_list *l = children;
123 mi = (menu_item *)l->child;
131 /*=========================================================================
144 **=========================================================================
147 void menu_container::Show(menu_item *by, int x, int y)
155 void menu_item::redraw(void)
159 /*=========================================================================
160 ** NAME : EV_EnterNotify
172 **=========================================================================
175 int menu_item::EV_EnterNotify(XCrossingEvent ev)
178 Background(menu_highlight);
183 GrabPointer(hand_cursor);
185 // Make sure all sibling popup menus are disappeared.
187 win_list *l = parent->children;
193 mi = (menu_item *)l->child;
200 ShowSubmenu(ev.x_root - ev.x, ev.y_root - ev.y);
205 /*=========================================================================
206 ** NAME : EV_LeaveNotify
218 **=========================================================================
221 int menu_item::EV_LeaveNotify(XCrossingEvent ev)
224 Background(menu_normal);
231 /*=========================================================================
232 ** NAME : EV_ButtonRelease
244 **=========================================================================
247 int menu_item::EV_ButtonRelease(XButtonEvent ev)
249 menu_container *contain;
253 contain = (menu_container *)parent;
254 while (contain->shown_by)
256 menu_item *mi = (menu_item *)contain->shown_by;
257 contain = (menu_container *)mi->parent;
259 //printf("contain->HideSubmenus(0x%x)\n", contain);
260 contain->HideSubmenus();
262 if (highlighted && !popup)
264 return XApp->SendCommand(command_code);
271 /*=========================================================================
272 ** NAME : HideSubmenu
284 **=========================================================================
287 void menu_item::HideSubmenu(void)
291 //printf("popup->HideSubmenus(0x%x)\n", popup);
292 popup->HideSubmenus();
298 /*=========================================================================
299 ** NAME : ShowSubmenu
311 **=========================================================================
314 void menu_item::ShowSubmenu(int x, int y)
320 menu_container *contain;
324 contain = (menu_container *)parent;
325 contain->PositionSubmenu(x, y, w, h);
327 popup->Show(this, x, y);
333 /*=========================================================================
334 ** NAME : redraw - Draw a label in a menu item
345 ** LAST MODIFIED : Mar 07, 1998
346 **=========================================================================
349 void menu_label::redraw(void)
351 XDrawString(stddpy, ID(), enabled ? menu_normal_gc : menu_dimmed_gc,
352 5, default_font.ascent() + 3, label, strlen(label));
356 /*=========================================================================
357 ** NAME : redraw -- Draw a separator in a menu item
369 **=========================================================================
372 void menu_separator::redraw(void)
377 XDrawLine(stddpy, ID(), menu_normal_gc, 0, 3, w, 3);