1 | /* $Id: menu.cpp,v 1.40 2001-11-21 11:51:37 sandervl Exp $*/
|
---|
2 | /*
|
---|
3 | * Menu functions
|
---|
4 | *
|
---|
5 | * Copyright 1993 Martin Ayotte
|
---|
6 | * Copyright 1994 Alexandre Julliard
|
---|
7 | * Copyright 1997 Morten Welinder
|
---|
8 | *
|
---|
9 | * Copyright 1999 Christoph Bratschi
|
---|
10 | *
|
---|
11 | * Corel version: 200005313
|
---|
12 | * (WINE version: 20000130)
|
---|
13 | *
|
---|
14 | * Status: ???
|
---|
15 | * Version: ???
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * Note: the style MF_MOUSESELECT is used to mark popup items that
|
---|
20 | * have been selected, i.e. their popup menu is currently displayed.
|
---|
21 | * This is probably not the meaning this style has in MS-Windows.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include <assert.h>
|
---|
25 | #include <ctype.h>
|
---|
26 | #include <stdlib.h>
|
---|
27 | #include <string.h>
|
---|
28 | #include <os2win.h>
|
---|
29 | #include <heapstring.h>
|
---|
30 | #include "controls.h"
|
---|
31 | #include "menu.h"
|
---|
32 |
|
---|
33 | #ifdef __WIN32OS2__
|
---|
34 | #include <objhandle.h>
|
---|
35 | #include "pmwindow.h"
|
---|
36 | #include "win32wmisc.h"
|
---|
37 | #include "oslibmsg.h"
|
---|
38 |
|
---|
39 | #define DBG_LOCALLOG DBG_menu
|
---|
40 | #include "dbglocal.h"
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | //DEFAULT_DEBUG_CHANNEL(menu)
|
---|
44 | //DECLARE_DEBUG_CHANNEL(winhelp)
|
---|
45 |
|
---|
46 |
|
---|
47 | /* internal popup menu window messages */
|
---|
48 |
|
---|
49 | #define MM_SETMENUHANDLE (WM_USER + 0)
|
---|
50 | #define MM_GETMENUHANDLE (WM_USER + 1)
|
---|
51 |
|
---|
52 | /* Menu item structure */
|
---|
53 | typedef struct {
|
---|
54 | /* ----------- MENUITEMINFO Stuff ----------- */
|
---|
55 | UINT fType; /* Item type. */
|
---|
56 | UINT fState; /* Item state. */
|
---|
57 | UINT wID; /* Item id. */
|
---|
58 | HMENU hSubMenu; /* Pop-up menu. */
|
---|
59 | HBITMAP hCheckBit; /* Bitmap when checked. */
|
---|
60 | HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
|
---|
61 | LPSTR text; /* Item text or bitmap handle. */
|
---|
62 | DWORD dwItemData; /* Application defined. */
|
---|
63 | DWORD dwTypeData; /* depends on fMask */
|
---|
64 | HBITMAP hbmpItem; /* bitmap in win98 style menus */
|
---|
65 | /* ----------- Wine stuff ----------- */
|
---|
66 | RECT rect; /* Item area (relative to menu window) */
|
---|
67 | UINT xTab; /* X position of text after Tab */
|
---|
68 | } MENUITEM;
|
---|
69 |
|
---|
70 | /* Popup menu structure */
|
---|
71 | typedef struct {
|
---|
72 | WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
|
---|
73 | WORD wMagic; /* Magic number */
|
---|
74 | HQUEUE hTaskQ; /* Task queue for this menu */
|
---|
75 | WORD Width; /* Width of the whole menu */
|
---|
76 | WORD Height; /* Height of the whole menu */
|
---|
77 | WORD nItems; /* Number of items in the menu */
|
---|
78 | HWND hWnd; /* Window containing the menu */
|
---|
79 | MENUITEM *items; /* Array of menu items */
|
---|
80 | UINT FocusedItem; /* Currently focused item */
|
---|
81 | HWND hwndOwner; /* window receiving the messages for ownerdraw */
|
---|
82 | BOOL bTimeToHide; /* Request hiding when receiving a second click in the top-level menu item */
|
---|
83 | /* ------------ MENUINFO members ------ */
|
---|
84 | DWORD dwStyle; /* Extended mennu style */
|
---|
85 | UINT cyMax; /* max hight of the whole menu, 0 is screen hight */
|
---|
86 | HBRUSH hbrBack; /* brush for menu background */
|
---|
87 | DWORD dwContextHelpID;
|
---|
88 | DWORD dwMenuData; /* application defined value */
|
---|
89 | HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */
|
---|
90 | } POPUPMENU, *LPPOPUPMENU;
|
---|
91 |
|
---|
92 | /* internal flags for menu tracking */
|
---|
93 |
|
---|
94 | #define TF_ENDMENU 0x0001
|
---|
95 | #define TF_SUSPENDPOPUP 0x0002
|
---|
96 | #define TF_SKIPREMOVE 0x0004
|
---|
97 |
|
---|
98 | typedef struct
|
---|
99 | {
|
---|
100 | UINT trackFlags;
|
---|
101 | HMENU hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
|
---|
102 | HMENU hTopMenu; /* initial menu */
|
---|
103 | HWND hOwnerWnd; /* where notifications are sent */
|
---|
104 | POINT pt;
|
---|
105 | } MTRACKER;
|
---|
106 |
|
---|
107 | #define MENU_MAGIC 0x554d /* 'MU' */
|
---|
108 |
|
---|
109 | #define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
|
---|
110 |
|
---|
111 | #define ITEM_PREV -1
|
---|
112 | #define ITEM_NEXT 1
|
---|
113 |
|
---|
114 | /* Internal MENU_TrackMenu() flags */
|
---|
115 | #define TPM_INTERNAL 0xF0000000
|
---|
116 | #define TPM_ENTERIDLEEX 0x80000000 /* set owner window for WM_ENTERIDLE */
|
---|
117 | #define TPM_BUTTONDOWN 0x40000000 /* menu was clicked before tracking */
|
---|
118 | #define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
|
---|
119 | #define TPM_CAPTIONSYSMENU 0x10000000
|
---|
120 |
|
---|
121 | /* popup menu shade thickness */
|
---|
122 | #define POPUP_XSHADE 4
|
---|
123 | #define POPUP_YSHADE 4
|
---|
124 |
|
---|
125 | /* Space between 2 menu bar items */
|
---|
126 | #define MENU_BAR_ITEMS_SPACE 12
|
---|
127 |
|
---|
128 | /* Minimum width of a tab character */
|
---|
129 | #define MENU_TAB_SPACE 8
|
---|
130 |
|
---|
131 | /* Height of a separator item */
|
---|
132 | #define SEPARATOR_HEIGHT 5
|
---|
133 |
|
---|
134 | /* (other menu->FocusedItem values give the position of the focused item) */
|
---|
135 | #define NO_SELECTED_ITEM 0xffff
|
---|
136 |
|
---|
137 | #define MENU_ITEM_TYPE(flags) \
|
---|
138 | ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
|
---|
139 |
|
---|
140 | #define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
|
---|
141 | #define IS_SEPARATOR_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_SEPARATOR)
|
---|
142 | #define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
|
---|
143 |
|
---|
144 | #define IS_SYSTEM_MENU(menu) \
|
---|
145 | (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
|
---|
146 |
|
---|
147 | #define IS_SYSTEM_POPUP(menu) \
|
---|
148 | ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
|
---|
149 |
|
---|
150 | #define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
|
---|
151 | MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
|
---|
152 | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
|
---|
153 | MF_POPUP | MF_SYSMENU | MF_HELP)
|
---|
154 | #define STATE_MASK (~TYPE_MASK)
|
---|
155 |
|
---|
156 | /* Dimension of the menu bitmaps */
|
---|
157 | static WORD check_bitmap_width = 0, check_bitmap_height = 0;
|
---|
158 | static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
|
---|
159 |
|
---|
160 | static HBITMAP hStdRadioCheck = 0;
|
---|
161 | static HBITMAP hStdCheck = 0;
|
---|
162 | static HBITMAP hStdMnArrow = 0;
|
---|
163 |
|
---|
164 | /* Minimze/restore/close buttons to be inserted in menubar */
|
---|
165 | static HBITMAP hBmpMinimize = 0;
|
---|
166 | static HBITMAP hBmpMinimizeD = 0;
|
---|
167 | static HBITMAP hBmpMaximize = 0;
|
---|
168 | static HBITMAP hBmpMaximizeD = 0;
|
---|
169 | static HBITMAP hBmpClose = 0;
|
---|
170 | static HBITMAP hBmpCloseD = 0;
|
---|
171 |
|
---|
172 |
|
---|
173 | static HBRUSH hShadeBrush = 0;
|
---|
174 | static HFONT hMenuFont = 0;
|
---|
175 | static HFONT hMenuFontBold = 0;
|
---|
176 |
|
---|
177 | static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
|
---|
178 |
|
---|
179 | /* Use global popup window because there's no way 2 menus can
|
---|
180 | * be tracked at the same time. */
|
---|
181 |
|
---|
182 | static HWND pTopPopupWnd = 0;
|
---|
183 | static UINT uSubPWndLevel = 0;
|
---|
184 |
|
---|
185 | /* Flag set by EndMenu() to force an exit from menu tracking */
|
---|
186 | static BOOL fEndMenu = FALSE;
|
---|
187 |
|
---|
188 | /*
|
---|
189 | The following variables and defines are used to keep track of which
|
---|
190 | menu item the mouse is currently over. (Used to implement a pause before
|
---|
191 | popup menus are displayed. )
|
---|
192 |
|
---|
193 | See: MENU_MouseMove()
|
---|
194 | MENU_TrackMenu()
|
---|
195 | */
|
---|
196 | #define SUBMENU_POPUP_TIMERID 100
|
---|
197 | #define POPUP_MENU_DELAY 500
|
---|
198 | static UINT mouseOverMenuID = -1;
|
---|
199 | static BOOL isTimerSet = FALSE;
|
---|
200 |
|
---|
201 | #ifdef __WIN32OS2__
|
---|
202 | static BOOL fDisableOdinSysMenuItems = FALSE;
|
---|
203 | #endif
|
---|
204 |
|
---|
205 | /***********************************************************************
|
---|
206 | * debug_print_menuitem
|
---|
207 | *
|
---|
208 | * Print a menuitem in readable form.
|
---|
209 | */
|
---|
210 |
|
---|
211 | #define debug_print_menuitem(pre, mp, post) \
|
---|
212 | if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
|
---|
213 |
|
---|
214 | #define MENUOUT(text) \
|
---|
215 | DPRINTF("%s%s", (count++ ? "," : ""), (text))
|
---|
216 |
|
---|
217 | #define MENUFLAG(bit,text) \
|
---|
218 | do { \
|
---|
219 | if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
|
---|
220 | } while (0)
|
---|
221 |
|
---|
222 | #if 0
|
---|
223 | static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
|
---|
224 | const char *postfix)
|
---|
225 | {
|
---|
226 | TRACE("%s ", prefix);
|
---|
227 | if (mp) {
|
---|
228 | UINT flags = mp->fType;
|
---|
229 | int typ = MENU_ITEM_TYPE(flags);
|
---|
230 | DPRINTF( "{ ID=0x%x", mp->wID);
|
---|
231 | if (flags & MF_POPUP)
|
---|
232 | DPRINTF( ", Sub=0x%x", mp->hSubMenu);
|
---|
233 | if (flags) {
|
---|
234 | int count = 0;
|
---|
235 | DPRINTF( ", Typ=");
|
---|
236 | if (typ == MFT_STRING)
|
---|
237 | /* Nothing */ ;
|
---|
238 | else if (typ == MFT_SEPARATOR)
|
---|
239 | MENUOUT("sep");
|
---|
240 | else if (typ == MFT_OWNERDRAW)
|
---|
241 | MENUOUT("own");
|
---|
242 | else if (typ == MFT_BITMAP)
|
---|
243 | MENUOUT("bit");
|
---|
244 | else
|
---|
245 | MENUOUT("???");
|
---|
246 | flags -= typ;
|
---|
247 |
|
---|
248 | MENUFLAG(MF_POPUP, "pop");
|
---|
249 | MENUFLAG(MFT_MENUBARBREAK, "barbrk");
|
---|
250 | MENUFLAG(MFT_MENUBREAK, "brk");
|
---|
251 | MENUFLAG(MFT_RADIOCHECK, "radio");
|
---|
252 | MENUFLAG(MFT_RIGHTORDER, "rorder");
|
---|
253 | MENUFLAG(MF_SYSMENU, "sys");
|
---|
254 | MENUFLAG(MFT_RIGHTJUSTIFY, "right"); /* same as MF_HELP */
|
---|
255 |
|
---|
256 | if (flags)
|
---|
257 | DPRINTF( "+0x%x", flags);
|
---|
258 | }
|
---|
259 | flags = mp->fState;
|
---|
260 | if (flags) {
|
---|
261 | int count = 0;
|
---|
262 | DPRINTF( ", State=");
|
---|
263 | MENUFLAG(MFS_GRAYED, "grey");
|
---|
264 | MENUFLAG(MFS_DEFAULT, "default");
|
---|
265 | MENUFLAG(MFS_DISABLED, "dis");
|
---|
266 | MENUFLAG(MFS_CHECKED, "check");
|
---|
267 | MENUFLAG(MFS_HILITE, "hi");
|
---|
268 | MENUFLAG(MF_USECHECKBITMAPS, "usebit");
|
---|
269 | MENUFLAG(MF_MOUSESELECT, "mouse");
|
---|
270 | if (flags)
|
---|
271 | DPRINTF( "+0x%x", flags);
|
---|
272 | }
|
---|
273 | if (mp->hCheckBit)
|
---|
274 | DPRINTF( ", Chk=0x%x", mp->hCheckBit);
|
---|
275 | if (mp->hUnCheckBit)
|
---|
276 | DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
|
---|
277 |
|
---|
278 | if (typ == MFT_STRING) {
|
---|
279 | if (mp->text)
|
---|
280 | DPRINTF( ", Text=\"%s\"", mp->text);
|
---|
281 | else
|
---|
282 | DPRINTF( ", Text=Null");
|
---|
283 | } else if (mp->text == NULL)
|
---|
284 | /* Nothing */ ;
|
---|
285 | else
|
---|
286 | DPRINTF( ", Text=%p", mp->text);
|
---|
287 | if (mp->dwItemData)
|
---|
288 | DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
|
---|
289 | DPRINTF( " }");
|
---|
290 | } else {
|
---|
291 | DPRINTF( "NULL");
|
---|
292 | }
|
---|
293 |
|
---|
294 | DPRINTF(" %s\n", postfix);
|
---|
295 | }
|
---|
296 | #endif
|
---|
297 |
|
---|
298 | #undef MENUOUT
|
---|
299 | #undef MENUFLAG
|
---|
300 |
|
---|
301 | //#define USER_HEAP_ALLOC(size) HeapAlloc(GetProcessHeap(),0,size)
|
---|
302 | //#define USER_HEAP_FREE(handle) HeapFree(GetProcessHeap(),0,(LPVOID)handle)
|
---|
303 |
|
---|
304 |
|
---|
305 | /***********************************************************************
|
---|
306 | * MENU_GetMenu
|
---|
307 | *
|
---|
308 | * Validate the given menu handle and returns the menu structure pointer.
|
---|
309 | */
|
---|
310 | POPUPMENU *MENU_GetMenu(HMENU hMenu)
|
---|
311 | {
|
---|
312 | #ifdef __WIN32OS2__
|
---|
313 | if(ObjGetHandleType(hMenu) == USEROBJ_MENU) {
|
---|
314 | POPUPMENU *menu;
|
---|
315 |
|
---|
316 | menu = (POPUPMENU *)ObjGetHandleData(hMenu, USEROBJ_MENU);
|
---|
317 | return menu;
|
---|
318 | }
|
---|
319 | return NULL;
|
---|
320 | #else
|
---|
321 | POPUPMENU *menu;
|
---|
322 | menu = (POPUPMENU*)hMenu;
|
---|
323 | if (!IS_A_MENU(menu))
|
---|
324 | {
|
---|
325 | //ERR("invalid menu handle=%x, ptr=%p, magic=%x\n", hMenu, menu, menu? menu->wMagic:0);
|
---|
326 | menu = NULL;
|
---|
327 | }
|
---|
328 | return menu;
|
---|
329 | #endif
|
---|
330 | }
|
---|
331 |
|
---|
332 | /***********************************************************************
|
---|
333 | * MENU_CopySysPopup
|
---|
334 | *
|
---|
335 | * Return the default system menu.
|
---|
336 | */
|
---|
337 | static HMENU MENU_CopySysPopup(void)
|
---|
338 | {
|
---|
339 | HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
|
---|
340 |
|
---|
341 | if( hMenu ) {
|
---|
342 | #ifdef __WIN32OS2__
|
---|
343 | POPUPMENU* menu = MENU_GetMenu(hMenu);
|
---|
344 | #else
|
---|
345 | POPUPMENU* menu = (POPUPMENU*)hMenu;
|
---|
346 | #endif
|
---|
347 | menu->wFlags |= MF_SYSMENU | MF_POPUP;
|
---|
348 | SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
|
---|
349 | #ifdef __WIN32OS2__
|
---|
350 | if(fDisableOdinSysMenuItems) {
|
---|
351 | RemoveMenu(hMenu, 9, MF_BYPOSITION);
|
---|
352 | RemoveMenu(hMenu, 9, MF_BYPOSITION);
|
---|
353 | RemoveMenu(hMenu, 9, MF_BYPOSITION);
|
---|
354 | RemoveMenu(hMenu, 9, MF_BYPOSITION);
|
---|
355 | RemoveMenu(hMenu, 9, MF_BYPOSITION);
|
---|
356 | }
|
---|
357 | #ifndef DEBUG
|
---|
358 | else {
|
---|
359 | RemoveMenu(hMenu, SC_PUTMARK, MF_BYCOMMAND);
|
---|
360 | RemoveMenu(hMenu, SC_DEBUGINT3, MF_BYCOMMAND);
|
---|
361 | RemoveMenu(hMenu, 11, MF_BYPOSITION); //separator
|
---|
362 | }
|
---|
363 | #endif
|
---|
364 | #endif
|
---|
365 | }
|
---|
366 | else {
|
---|
367 | hMenu = 0;
|
---|
368 | //ERR("Unable to load default system menu\n" );
|
---|
369 | }
|
---|
370 |
|
---|
371 | //TRACE("returning %x.\n", hMenu );
|
---|
372 |
|
---|
373 | return hMenu;
|
---|
374 | }
|
---|
375 |
|
---|
376 | /***********************************************************************
|
---|
377 | * MENU_GetTopPopupWnd()
|
---|
378 | *
|
---|
379 | * Return the locked pointer pTopPopupWnd.
|
---|
380 | */
|
---|
381 | static HWND MENU_GetTopPopupWnd()
|
---|
382 | {
|
---|
383 | return pTopPopupWnd;
|
---|
384 | }
|
---|
385 | /***********************************************************************
|
---|
386 | * MENU_ReleaseTopPopupWnd()
|
---|
387 | *
|
---|
388 | * Realease the locked pointer pTopPopupWnd.
|
---|
389 | */
|
---|
390 | static void MENU_ReleaseTopPopupWnd()
|
---|
391 | {
|
---|
392 | }
|
---|
393 | /***********************************************************************
|
---|
394 | * MENU_DestroyTopPopupWnd()
|
---|
395 | *
|
---|
396 | * Destroy the locked pointer pTopPopupWnd.
|
---|
397 | */
|
---|
398 | static void MENU_DestroyTopPopupWnd()
|
---|
399 | {
|
---|
400 | pTopPopupWnd = NULL;
|
---|
401 | }
|
---|
402 |
|
---|
403 |
|
---|
404 |
|
---|
405 | /**********************************************************************
|
---|
406 | * MENU_GetSysMenu
|
---|
407 | *
|
---|
408 | * Create a copy of the system menu. System menu in Windows is
|
---|
409 | * a special menu-bar with the single entry - system menu popup.
|
---|
410 | * This popup is presented to the outside world as a "system menu".
|
---|
411 | * However, the real system menu handle is sometimes seen in the
|
---|
412 | * WM_MENUSELECT paramemters (and Word 6 likes it this way).
|
---|
413 | */
|
---|
414 | HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
|
---|
415 | {
|
---|
416 | HMENU hMenu;
|
---|
417 |
|
---|
418 | hMenu = CreateMenu();
|
---|
419 | if (hMenu)
|
---|
420 | {
|
---|
421 | #ifdef __WIN32OS2__
|
---|
422 | POPUPMENU *menu = MENU_GetMenu(hMenu);
|
---|
423 | #else
|
---|
424 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
---|
425 | #endif
|
---|
426 | menu->wFlags = MF_SYSMENU;
|
---|
427 | menu->hWnd = hWnd;
|
---|
428 |
|
---|
429 | if (hPopupMenu == (HMENU)(-1))
|
---|
430 | hPopupMenu = MENU_CopySysPopup();
|
---|
431 | else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
|
---|
432 |
|
---|
433 | if (hPopupMenu)
|
---|
434 | {
|
---|
435 | InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
|
---|
436 |
|
---|
437 | menu->items[0].fType = MF_SYSMENU | MF_POPUP;
|
---|
438 | menu->items[0].fState = 0;
|
---|
439 | #ifdef __WIN32OS2__
|
---|
440 | menu = MENU_GetMenu(hPopupMenu);
|
---|
441 | #else
|
---|
442 | menu = (POPUPMENU*)hPopupMenu;
|
---|
443 | #endif
|
---|
444 | menu->wFlags |= MF_SYSMENU;
|
---|
445 |
|
---|
446 | //TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
|
---|
447 | return hMenu;
|
---|
448 | }
|
---|
449 | DestroyMenu( hMenu );
|
---|
450 | }
|
---|
451 | //ERR("failed to load system menu!\n");
|
---|
452 | return 0;
|
---|
453 | }
|
---|
454 |
|
---|
455 |
|
---|
456 | /***********************************************************************
|
---|
457 | * MENU_Init
|
---|
458 | *
|
---|
459 | * Menus initialisation.
|
---|
460 | */
|
---|
461 | BOOL MENU_Init()
|
---|
462 | {
|
---|
463 | HBITMAP hBitmap;
|
---|
464 | NONCLIENTMETRICSA ncm;
|
---|
465 |
|
---|
466 | static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
|
---|
467 | 0x55, 0, 0xAA, 0,
|
---|
468 | 0x55, 0, 0xAA, 0,
|
---|
469 | 0x55, 0, 0xAA, 0 };
|
---|
470 |
|
---|
471 | /* Load menu bitmaps */
|
---|
472 | hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
|
---|
473 | hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
|
---|
474 | hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
|
---|
475 | /* Load system buttons bitmaps */
|
---|
476 | hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
|
---|
477 | hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
|
---|
478 | hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
|
---|
479 | hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
|
---|
480 | hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
|
---|
481 | hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
|
---|
482 |
|
---|
483 | if (hStdCheck)
|
---|
484 | {
|
---|
485 | BITMAP bm;
|
---|
486 | GetObjectA( hStdCheck, sizeof(bm), &bm );
|
---|
487 | check_bitmap_width = bm.bmWidth;
|
---|
488 | check_bitmap_height = bm.bmHeight;
|
---|
489 | } else
|
---|
490 | return FALSE;
|
---|
491 |
|
---|
492 | /* Assume that radio checks have the same size as regular check. */
|
---|
493 | if (!hStdRadioCheck)
|
---|
494 | return FALSE;
|
---|
495 |
|
---|
496 | if (hStdMnArrow)
|
---|
497 | {
|
---|
498 | BITMAP bm;
|
---|
499 | GetObjectA( hStdMnArrow, sizeof(bm), &bm );
|
---|
500 | arrow_bitmap_width = bm.bmWidth;
|
---|
501 | arrow_bitmap_height = bm.bmHeight;
|
---|
502 | } else
|
---|
503 | return FALSE;
|
---|
504 |
|
---|
505 | if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
|
---|
506 | return FALSE;
|
---|
507 |
|
---|
508 | if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
|
---|
509 | return FALSE;
|
---|
510 |
|
---|
511 | DeleteObject( hBitmap );
|
---|
512 | if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
|
---|
513 | return FALSE;
|
---|
514 |
|
---|
515 | ncm.cbSize = sizeof (NONCLIENTMETRICSA);
|
---|
516 | if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
|
---|
517 | return FALSE;
|
---|
518 |
|
---|
519 | if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
|
---|
520 | return FALSE;
|
---|
521 |
|
---|
522 | ncm.lfMenuFont.lfWeight += 300;
|
---|
523 | if ( ncm.lfMenuFont.lfWeight > 1000)
|
---|
524 | ncm.lfMenuFont.lfWeight = 1000;
|
---|
525 |
|
---|
526 | if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
|
---|
527 | return FALSE;
|
---|
528 |
|
---|
529 | return TRUE;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /***********************************************************************
|
---|
533 | * MENU_InitSysMenuPopup
|
---|
534 | *
|
---|
535 | * Grey the appropriate items in System menu.
|
---|
536 | */
|
---|
537 | static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
|
---|
538 | {
|
---|
539 | BOOL gray;
|
---|
540 |
|
---|
541 | gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
|
---|
542 | EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
---|
543 | gray = ((style & WS_MAXIMIZE) != 0);
|
---|
544 | EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
|
---|
545 | gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
|
---|
546 | EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
---|
547 | gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
|
---|
548 | EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
---|
549 | gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
|
---|
550 | EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
|
---|
551 | gray = (clsStyle & CS_NOCLOSE) != 0;
|
---|
552 |
|
---|
553 | /* The menu item must keep its state if it's disabled */
|
---|
554 | if(gray)
|
---|
555 | EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | /******************************************************************************
|
---|
560 | *
|
---|
561 | * UINT32 MENU_GetStartOfNextColumn(
|
---|
562 | * HMENU32 hMenu )
|
---|
563 | *
|
---|
564 | *****************************************************************************/
|
---|
565 |
|
---|
566 | static UINT MENU_GetStartOfNextColumn(
|
---|
567 | HMENU hMenu )
|
---|
568 | {
|
---|
569 | #ifdef __WIN32OS2__
|
---|
570 | POPUPMENU *menu = MENU_GetMenu(hMenu);
|
---|
571 | #else
|
---|
572 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
---|
573 | #endif
|
---|
574 | UINT i = menu->FocusedItem + 1;
|
---|
575 |
|
---|
576 | if(!menu)
|
---|
577 | return NO_SELECTED_ITEM;
|
---|
578 |
|
---|
579 | if( i == NO_SELECTED_ITEM )
|
---|
580 | return i;
|
---|
581 |
|
---|
582 | for( ; i < menu->nItems; ++i ) {
|
---|
583 | if (menu->items[i].fType & MF_MENUBARBREAK)
|
---|
584 | return i;
|
---|
585 | }
|
---|
586 |
|
---|
587 | return NO_SELECTED_ITEM;
|
---|
588 | }
|
---|
589 |
|
---|
590 |
|
---|
591 | /******************************************************************************
|
---|
592 | *
|
---|
593 | * UINT32 MENU_GetStartOfPrevColumn(
|
---|
594 | * HMENU32 hMenu )
|
---|
595 | *
|
---|
596 | *****************************************************************************/
|
---|
597 |
|
---|
598 | static UINT MENU_GetStartOfPrevColumn(
|
---|
599 | HMENU hMenu )
|
---|
600 | {
|
---|
601 | #ifdef __WIN32OS2__
|
---|
602 | POPUPMENU const *menu = MENU_GetMenu(hMenu);
|
---|
603 | #else
|
---|
604 | POPUPMENU const *menu = (POPUPMENU*)hMenu;
|
---|
605 | #endif
|
---|
606 | UINT i;
|
---|
607 |
|
---|
608 | if( !menu )
|
---|
609 | return NO_SELECTED_ITEM;
|
---|
610 |
|
---|
611 | if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
|
---|
612 | return NO_SELECTED_ITEM;
|
---|
613 |
|
---|
614 | /* Find the start of the column */
|
---|
615 |
|
---|
616 | for(i = menu->FocusedItem; i != 0 &&
|
---|
617 | !(menu->items[i].fType & MF_MENUBARBREAK);
|
---|
618 | --i); /* empty */
|
---|
619 |
|
---|
620 | if(i == 0)
|
---|
621 | return NO_SELECTED_ITEM;
|
---|
622 |
|
---|
623 | for(--i; i != 0; --i) {
|
---|
624 | if (menu->items[i].fType & MF_MENUBARBREAK)
|
---|
625 | break;
|
---|
626 | }
|
---|
627 |
|
---|
628 | //TRACE("ret %d.\n", i );
|
---|
629 |
|
---|
630 | return i;
|
---|
631 | }
|
---|
632 |
|
---|
633 |
|
---|
634 |
|
---|
635 | /***********************************************************************
|
---|
636 | * MENU_FindItem
|
---|
637 | *
|
---|
638 | * Find a menu item. Return a pointer on the item, and modifies *hmenu
|
---|
639 | * in case the item was in a sub-menu.
|
---|
640 | */
|
---|
641 | static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
|
---|
642 | {
|
---|
643 | POPUPMENU *menu;
|
---|
644 | UINT i;
|
---|
645 |
|
---|
646 | if (((*hmenu)==0xffff) || (!(menu = MENU_GetMenu(*hmenu)))) return NULL;
|
---|
647 | if (!menu) return NULL;
|
---|
648 | if (wFlags & MF_BYPOSITION)
|
---|
649 | {
|
---|
650 | if (*nPos >= menu->nItems) return NULL;
|
---|
651 | return &menu->items[*nPos];
|
---|
652 | }
|
---|
653 | else
|
---|
654 | {
|
---|
655 | MENUITEM *item = menu->items;
|
---|
656 |
|
---|
657 | for (i = 0; i < menu->nItems; i++, item++)
|
---|
658 | {
|
---|
659 | if (item->wID == *nPos)
|
---|
660 | {
|
---|
661 | *nPos = i;
|
---|
662 | return item;
|
---|
663 | }
|
---|
664 | else if (item->fType & MF_POPUP)
|
---|
665 | {
|
---|
666 | HMENU hsubmenu = item->hSubMenu;
|
---|
667 | MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
|
---|
668 | if (subitem)
|
---|
669 | {
|
---|
670 | *hmenu = hsubmenu;
|
---|
671 | return subitem;
|
---|
672 | }
|
---|
673 | }
|
---|
674 | }
|
---|
675 | }
|
---|
676 | return NULL;
|
---|
677 | }
|
---|
678 |
|
---|
679 | /***********************************************************************
|
---|
680 | * MENU_FindSubMenu
|
---|
681 | *
|
---|
682 | * Find a Sub menu. Return the position of the submenu, and modifies
|
---|
683 | * *hmenu in case it is found in another sub-menu.
|
---|
684 | * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
|
---|
685 | */
|
---|
686 | UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget )
|
---|
687 | {
|
---|
688 | POPUPMENU *menu;
|
---|
689 | UINT i;
|
---|
690 | MENUITEM *item;
|
---|
691 | if (((*hmenu)==0xffff) ||
|
---|
692 | (!(menu = MENU_GetMenu(*hmenu))))
|
---|
693 | return NO_SELECTED_ITEM;
|
---|
694 | item = menu->items;
|
---|
695 | for (i = 0; i < menu->nItems; i++, item++) {
|
---|
696 | if(!(item->fType & MF_POPUP)) continue;
|
---|
697 | if (item->hSubMenu == hSubTarget) {
|
---|
698 | return i;
|
---|
699 | }
|
---|
700 | else {
|
---|
701 | HMENU hsubmenu = item->hSubMenu;
|
---|
702 | UINT pos = MENU_FindSubMenu( &hsubmenu, hSubTarget );
|
---|
703 | if (pos != NO_SELECTED_ITEM) {
|
---|
704 | *hmenu = hsubmenu;
|
---|
705 | return pos;
|
---|
706 | }
|
---|
707 | }
|
---|
708 | }
|
---|
709 | return NO_SELECTED_ITEM;
|
---|
710 | }
|
---|
711 |
|
---|
712 | /***********************************************************************
|
---|
713 | * MENU_FreeItemData
|
---|
714 | */
|
---|
715 | static void MENU_FreeItemData( MENUITEM* item )
|
---|
716 | {
|
---|
717 | /* delete text */
|
---|
718 | if (IS_STRING_ITEM(item->fType) && item->text)
|
---|
719 | HeapFree(GetProcessHeap(), 0, item->text );
|
---|
720 | }
|
---|
721 |
|
---|
722 | /***********************************************************************
|
---|
723 | * MENU_FindItemByCoords
|
---|
724 | *
|
---|
725 | * Find the item at the specified coordinates (screen coords). Does
|
---|
726 | * not work for child windows and therefore should not be called for
|
---|
727 | * an arbitrary system menu.
|
---|
728 | */
|
---|
729 | static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
|
---|
730 | POINT pt, UINT *pos )
|
---|
731 | {
|
---|
732 | MENUITEM *item;
|
---|
733 | UINT i;
|
---|
734 | RECT wrect;
|
---|
735 |
|
---|
736 | if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
|
---|
737 | pt.x -= wrect.left;pt.y -= wrect.top;
|
---|
738 | item = menu->items;
|
---|
739 | for (i = 0; i < menu->nItems; i++, item++)
|
---|
740 | {
|
---|
741 | if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
|
---|
742 | (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
|
---|
743 | {
|
---|
744 | if (pos) *pos = i;
|
---|
745 | return item;
|
---|
746 | }
|
---|
747 | }
|
---|
748 | return NULL;
|
---|
749 | }
|
---|
750 |
|
---|
751 |
|
---|
752 | /***********************************************************************
|
---|
753 | * MENU_FindItemByKey
|
---|
754 | *
|
---|
755 | * Find the menu item selected by a key press.
|
---|
756 | * Return item id, -1 if none, -2 if we should close the menu.
|
---|
757 | */
|
---|
758 | static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
|
---|
759 | UINT key, BOOL forceMenuChar )
|
---|
760 | {
|
---|
761 | //TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
|
---|
762 |
|
---|
763 | if (!IsMenu( hmenu ))
|
---|
764 | {
|
---|
765 | hmenu = GetSubMenu(getSysMenu(hwndOwner), 0);
|
---|
766 | }
|
---|
767 |
|
---|
768 | if (hmenu)
|
---|
769 | {
|
---|
770 | POPUPMENU *menu = MENU_GetMenu(hmenu);
|
---|
771 | MENUITEM *item = menu->items;
|
---|
772 | LONG menuchar;
|
---|
773 |
|
---|
774 | if( !forceMenuChar )
|
---|
775 | {
|
---|
776 | UINT i;
|
---|
777 |
|
---|
778 | key = toupper(key);
|
---|
779 | for (i = 0; i < menu->nItems; i++, item++)
|
---|
780 | {
|
---|
781 | if (item->text && (IS_STRING_ITEM(item->fType)))
|
---|
782 | {
|
---|
783 | char *p = item->text - 2;
|
---|
784 | do
|
---|
785 | {
|
---|
786 | p = strchr (p + 2, '&');
|
---|
787 | }
|
---|
788 | while (p != NULL && p [1] == '&');
|
---|
789 | if (p && (toupper(p[1]) == key)) return i;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | }
|
---|
793 | menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
|
---|
794 | MAKEWPARAM( key, menu->wFlags ), hmenu );
|
---|
795 | if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
|
---|
796 | if (HIWORD(menuchar) == 1) return (UINT)(-2);
|
---|
797 | }
|
---|
798 | return (UINT)(-1);
|
---|
799 | }
|
---|
800 | /***********************************************************************
|
---|
801 | * MENU_LoadMagicItem
|
---|
802 | *
|
---|
803 | * Load the bitmap associated with the magic menu item and its style
|
---|
804 | */
|
---|
805 |
|
---|
806 | static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
|
---|
807 | {
|
---|
808 | /*
|
---|
809 | * Magic menu item id's section
|
---|
810 | * These magic id's are used by windows to insert "standard" mdi
|
---|
811 | * buttons (minimize,restore,close) on menu. Under windows,
|
---|
812 | * these magic id's make sure the right things appear when those
|
---|
813 | * bitmap buttons are pressed/selected/released.
|
---|
814 | */
|
---|
815 |
|
---|
816 | switch(id & 0xffff)
|
---|
817 | { case HBMMENU_SYSTEM:
|
---|
818 | return (dwItemData) ?
|
---|
819 | (HBITMAP)dwItemData :
|
---|
820 | (hilite ? hBmpMinimizeD : hBmpMinimize);
|
---|
821 | case HBMMENU_MBAR_RESTORE:
|
---|
822 | return (hilite ? hBmpMaximizeD: hBmpMaximize);
|
---|
823 | case HBMMENU_MBAR_MINIMIZE:
|
---|
824 | return (hilite ? hBmpMinimizeD : hBmpMinimize);
|
---|
825 | case HBMMENU_MBAR_CLOSE:
|
---|
826 | return (hilite ? hBmpCloseD : hBmpClose);
|
---|
827 | case HBMMENU_CALLBACK:
|
---|
828 | case HBMMENU_MBAR_CLOSE_D:
|
---|
829 | case HBMMENU_MBAR_MINIMIZE_D:
|
---|
830 | case HBMMENU_POPUP_CLOSE:
|
---|
831 | case HBMMENU_POPUP_RESTORE:
|
---|
832 | case HBMMENU_POPUP_MAXIMIZE:
|
---|
833 | case HBMMENU_POPUP_MINIMIZE:
|
---|
834 | default:
|
---|
835 | //FIXME("Magic 0x%08x not implemented\n", id);
|
---|
836 | return 0;
|
---|
837 | }
|
---|
838 |
|
---|
839 | }
|
---|
840 |
|
---|
841 | /***********************************************************************
|
---|
842 | * MENU_CalcItemSize
|
---|
843 | *
|
---|
844 | * Calculate the size of the menu item and store it in lpitem->rect.
|
---|
845 | */
|
---|
846 | static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
|
---|
847 | INT orgX, INT orgY, BOOL menuBar )
|
---|
848 | {
|
---|
849 | char *p;
|
---|
850 |
|
---|
851 | //TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
|
---|
852 | //debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
|
---|
853 | // (menuBar ? " (MenuBar)" : ""));
|
---|
854 |
|
---|
855 | SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
|
---|
856 |
|
---|
857 | if (lpitem->fType & MF_OWNERDRAW)
|
---|
858 | {
|
---|
859 | MEASUREITEMSTRUCT mis;
|
---|
860 | mis.CtlType = ODT_MENU;
|
---|
861 | mis.CtlID = 0;
|
---|
862 | mis.itemID = lpitem->wID;
|
---|
863 | mis.itemData = (DWORD)lpitem->dwItemData;
|
---|
864 | mis.itemHeight = 0;
|
---|
865 | mis.itemWidth = 0;
|
---|
866 | SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
|
---|
867 | lpitem->rect.bottom += mis.itemHeight;
|
---|
868 | lpitem->rect.right += mis.itemWidth;
|
---|
869 |
|
---|
870 | //SvL: Add size of space between two menu items (fixes RealPlayer 7 menu)
|
---|
871 | if(menuBar)
|
---|
872 | {
|
---|
873 | lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
|
---|
874 | }
|
---|
875 |
|
---|
876 | //TRACE("id=%04x size=%dx%d\n",
|
---|
877 | // lpitem->wID, mis.itemWidth, mis.itemHeight);
|
---|
878 | return;
|
---|
879 | }
|
---|
880 |
|
---|
881 | if (lpitem->fType & MF_SEPARATOR)
|
---|
882 | {
|
---|
883 | lpitem->rect.bottom += SEPARATOR_HEIGHT;
|
---|
884 | return;
|
---|
885 | }
|
---|
886 |
|
---|
887 | if (!menuBar)
|
---|
888 | {
|
---|
889 | lpitem->rect.right += 2 * check_bitmap_width;
|
---|
890 | if (lpitem->fType & MF_POPUP)
|
---|
891 | lpitem->rect.right += arrow_bitmap_width;
|
---|
892 | }
|
---|
893 |
|
---|
894 | if (IS_BITMAP_ITEM(lpitem->fType))
|
---|
895 | {
|
---|
896 | BITMAP bm;
|
---|
897 | HBITMAP resBmp = 0;
|
---|
898 |
|
---|
899 | /* Check if there is a magic menu item associated with this item */
|
---|
900 | if((LOWORD((int)lpitem->text))<12)
|
---|
901 | {
|
---|
902 | resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
|
---|
903 | lpitem->dwItemData);
|
---|
904 | }
|
---|
905 | else
|
---|
906 | resBmp = (HBITMAP)lpitem->text;
|
---|
907 |
|
---|
908 | if (GetObjectA(resBmp, sizeof(bm), &bm ))
|
---|
909 | {
|
---|
910 | lpitem->rect.right += bm.bmWidth;
|
---|
911 | lpitem->rect.bottom += bm.bmHeight;
|
---|
912 |
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 |
|
---|
917 | /* it must be a text item - unless it's the system menu */
|
---|
918 | if (!(lpitem->fType & MF_SYSMENU) && IS_STRING_ITEM( lpitem->fType ))
|
---|
919 | { SIZE size;
|
---|
920 |
|
---|
921 | GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
|
---|
922 |
|
---|
923 | lpitem->rect.right += size.cx;
|
---|
924 | lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
|
---|
925 | lpitem->xTab = 0;
|
---|
926 |
|
---|
927 | if (menuBar)
|
---|
928 | {
|
---|
929 | lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
|
---|
930 | }
|
---|
931 | else if ((p = strchr( lpitem->text, '\t' )) != NULL)
|
---|
932 | {
|
---|
933 | /* Item contains a tab (only meaningful in popup menus) */
|
---|
934 | GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
|
---|
935 | lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
|
---|
936 | lpitem->rect.right += MENU_TAB_SPACE;
|
---|
937 | }
|
---|
938 | else
|
---|
939 | {
|
---|
940 | if (strchr( lpitem->text, '\b' ))
|
---|
941 | lpitem->rect.right += MENU_TAB_SPACE;
|
---|
942 | lpitem->xTab = lpitem->rect.right - check_bitmap_width
|
---|
943 | - arrow_bitmap_width;
|
---|
944 | }
|
---|
945 | }
|
---|
946 | //dprintf(("MENU_CalcItemSize %x (%d,%d)-(%d,%d)", lpitem->wID, lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom));
|
---|
947 | //TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
|
---|
948 | }
|
---|
949 |
|
---|
950 |
|
---|
951 | /***********************************************************************
|
---|
952 | * MENU_PopupMenuCalcSize
|
---|
953 | *
|
---|
954 | * Calculate the size of a popup menu.
|
---|
955 | */
|
---|
956 | static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
|
---|
957 | {
|
---|
958 | MENUITEM *lpitem;
|
---|
959 | HDC hdc;
|
---|
960 | int start, i;
|
---|
961 | int orgX, orgY, maxX, maxTab, maxTabWidth;
|
---|
962 |
|
---|
963 | lppop->Width = lppop->Height = 0;
|
---|
964 | if (lppop->nItems == 0) return;
|
---|
965 | #ifdef __WIN32OS2__
|
---|
966 | hdc = CreateCompatibleDC( 0 );
|
---|
967 | #else
|
---|
968 | hdc = GetDC( 0 );
|
---|
969 | #endif
|
---|
970 |
|
---|
971 | SelectObject( hdc, hMenuFont);
|
---|
972 |
|
---|
973 | start = 0;
|
---|
974 | maxX = 2 ;
|
---|
975 |
|
---|
976 | while (start < lppop->nItems)
|
---|
977 | {
|
---|
978 | lpitem = &lppop->items[start];
|
---|
979 | orgX = maxX;
|
---|
980 | orgY = 2;
|
---|
981 |
|
---|
982 | maxTab = maxTabWidth = 0;
|
---|
983 |
|
---|
984 | /* Parse items until column break or end of menu */
|
---|
985 | for (i = start; i < lppop->nItems; i++, lpitem++)
|
---|
986 | {
|
---|
987 | if ((i != start) &&
|
---|
988 | (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
|
---|
989 |
|
---|
990 | MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
|
---|
991 |
|
---|
992 | if (lpitem->fType & MF_MENUBARBREAK) orgX++;
|
---|
993 | maxX = MAX( maxX, lpitem->rect.right );
|
---|
994 | orgY = lpitem->rect.bottom;
|
---|
995 | if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
|
---|
996 | {
|
---|
997 | maxTab = MAX( maxTab, lpitem->xTab );
|
---|
998 | maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
|
---|
999 | }
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | /* Finish the column (set all items to the largest width found) */
|
---|
1003 | maxX = MAX( maxX, maxTab + maxTabWidth );
|
---|
1004 | for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
|
---|
1005 | {
|
---|
1006 | lpitem->rect.right = maxX;
|
---|
1007 | if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
|
---|
1008 | lpitem->xTab = maxTab;
|
---|
1009 |
|
---|
1010 | }
|
---|
1011 | lppop->Height = MAX( lppop->Height, orgY );
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | lppop->Width = maxX;
|
---|
1015 |
|
---|
1016 | /* space for 3d border */
|
---|
1017 | lppop->Height += 2;
|
---|
1018 | lppop->Width += 2;
|
---|
1019 |
|
---|
1020 | #ifdef __WIN32OS2__
|
---|
1021 | DeleteDC(hdc);
|
---|
1022 | #else
|
---|
1023 | ReleaseDC( 0, hdc );
|
---|
1024 | #endif
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 |
|
---|
1028 | /***********************************************************************
|
---|
1029 | * MENU_MenuBarCalcSize
|
---|
1030 | *
|
---|
1031 | * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
|
---|
1032 | * height is off by 1 pixel which causes lengthy window relocations when
|
---|
1033 | * active document window is maximized/restored.
|
---|
1034 | *
|
---|
1035 | * Calculate the size of the menu bar.
|
---|
1036 | */
|
---|
1037 | static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
|
---|
1038 | LPPOPUPMENU lppop, HWND hwndOwner )
|
---|
1039 | {
|
---|
1040 | MENUITEM *lpitem;
|
---|
1041 | int start, i, orgX, orgY, maxY, helpPos;
|
---|
1042 |
|
---|
1043 | if ((lprect == NULL) || (lppop == NULL)) return;
|
---|
1044 | if (lppop->nItems == 0) return;
|
---|
1045 | //TRACE("left=%d top=%d right=%d bottom=%d\n",
|
---|
1046 | // lprect->left, lprect->top, lprect->right, lprect->bottom);
|
---|
1047 | lppop->Width = lprect->right - lprect->left;
|
---|
1048 | lppop->Height = 0;
|
---|
1049 | maxY = lprect->top;
|
---|
1050 | start = 0;
|
---|
1051 | helpPos = -1;
|
---|
1052 | while (start < lppop->nItems)
|
---|
1053 | {
|
---|
1054 | lpitem = &lppop->items[start];
|
---|
1055 | orgX = lprect->left;
|
---|
1056 | orgY = maxY;
|
---|
1057 |
|
---|
1058 | /* Parse items until line break or end of menu */
|
---|
1059 | for (i = start; i < lppop->nItems; i++, lpitem++)
|
---|
1060 | {
|
---|
1061 | if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
|
---|
1062 | if ((i != start) &&
|
---|
1063 | (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
|
---|
1064 |
|
---|
1065 | //TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
|
---|
1066 | // orgX, orgY );
|
---|
1067 | //debug_print_menuitem (" item: ", lpitem, "");
|
---|
1068 | MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
|
---|
1069 |
|
---|
1070 | if (lpitem->rect.right > lprect->right)
|
---|
1071 | {
|
---|
1072 | if (i != start) break;
|
---|
1073 | else lpitem->rect.right = lprect->right;
|
---|
1074 | }
|
---|
1075 | maxY = MAX( maxY, lpitem->rect.bottom );
|
---|
1076 | orgX = lpitem->rect.right;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | /* Finish the line (set all items to the largest height found) */
|
---|
1080 | while (start < i) lppop->items[start++].rect.bottom = maxY;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | lprect->bottom = maxY;
|
---|
1084 | lppop->Height = lprect->bottom - lprect->top;
|
---|
1085 |
|
---|
1086 | /* Flush right all magic items and items between the MF_HELP and */
|
---|
1087 | /* the last item (if several lines, only move the last line) */
|
---|
1088 | lpitem = &lppop->items[lppop->nItems-1];
|
---|
1089 | orgY = lpitem->rect.top;
|
---|
1090 | orgX = lprect->right;
|
---|
1091 | for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
|
---|
1092 | {
|
---|
1093 | if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
|
---|
1094 | break; /* done */
|
---|
1095 | if (lpitem->rect.top != orgY) break; /* Other line */
|
---|
1096 | if (lpitem->rect.right >= orgX) break; /* Too far right already */
|
---|
1097 | lpitem->rect.left += orgX - lpitem->rect.right;
|
---|
1098 | lpitem->rect.right = orgX;
|
---|
1099 | orgX = lpitem->rect.left;
|
---|
1100 | }
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | /***********************************************************************
|
---|
1104 | * MENU_DrawMenuItem
|
---|
1105 | *
|
---|
1106 | * Draw a single menu item.
|
---|
1107 | */
|
---|
1108 | static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
|
---|
1109 | UINT height, BOOL menuBar, UINT odaction )
|
---|
1110 | {
|
---|
1111 | RECT rect;
|
---|
1112 |
|
---|
1113 | //debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
|
---|
1114 |
|
---|
1115 | if (lpitem->fType & MF_SYSMENU) return;
|
---|
1116 |
|
---|
1117 | if (lpitem->fType & MF_OWNERDRAW)
|
---|
1118 | {
|
---|
1119 | DRAWITEMSTRUCT dis;
|
---|
1120 |
|
---|
1121 | dis.CtlType = ODT_MENU;
|
---|
1122 | dis.CtlID = 0;
|
---|
1123 | dis.itemID = lpitem->wID;
|
---|
1124 | dis.itemData = (DWORD)lpitem->dwItemData;
|
---|
1125 | dis.itemState = 0;
|
---|
1126 | if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
|
---|
1127 | if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
|
---|
1128 | if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
|
---|
1129 | dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
|
---|
1130 | dis.hwndItem = hmenu;
|
---|
1131 | dis.hDC = hdc;
|
---|
1132 | dis.rcItem = lpitem->rect;
|
---|
1133 | //TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
|
---|
1134 | // "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
|
---|
1135 | // dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
|
---|
1136 | // dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
|
---|
1137 | // dis.rcItem.bottom);
|
---|
1138 | SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
|
---|
1139 | return;
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | //TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
|
---|
1143 | // lpitem->rect.right,lpitem->rect.bottom);
|
---|
1144 |
|
---|
1145 | if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
|
---|
1146 |
|
---|
1147 | rect = lpitem->rect;
|
---|
1148 |
|
---|
1149 | //CB: todo: does Win98 use DrawEdge for menubars?
|
---|
1150 |
|
---|
1151 | if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
|
---|
1152 | FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
|
---|
1153 | else {
|
---|
1154 | //SvL: TODO: Bug in GDI32; draws black rectangle instead of menu color
|
---|
1155 | /// for everything except the 1st menu item
|
---|
1156 | RECT dummy = rect;
|
---|
1157 |
|
---|
1158 | FillRect( hdc, &dummy, GetSysColorBrush(COLOR_HIGHLIGHT) );
|
---|
1159 | FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) ); //CB: back color switching bug?
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | SetBkMode( hdc, TRANSPARENT );
|
---|
1163 |
|
---|
1164 | /* vertical separator */
|
---|
1165 | if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
|
---|
1166 | {
|
---|
1167 | RECT rc = rect;
|
---|
1168 | rc.top = 3;
|
---|
1169 | rc.bottom = height - 3;
|
---|
1170 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | /* horizontal separator */
|
---|
1174 | if (lpitem->fType & MF_SEPARATOR)
|
---|
1175 | {
|
---|
1176 | RECT rc = rect;
|
---|
1177 | rc.left++;
|
---|
1178 | rc.right--;
|
---|
1179 | rc.top += SEPARATOR_HEIGHT / 2;
|
---|
1180 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
|
---|
1181 | return;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | /* Setup colors */
|
---|
1185 |
|
---|
1186 | if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
|
---|
1187 | {
|
---|
1188 | if (lpitem->fState & MF_GRAYED)
|
---|
1189 | SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
|
---|
1190 | #if 1 //CB: WINE's Win98 menubar -> to check
|
---|
1191 |
|
---|
1192 | else
|
---|
1193 | SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
|
---|
1194 | #else
|
---|
1195 | else
|
---|
1196 | {
|
---|
1197 | if (menuBar)
|
---|
1198 | SetTextColor(hdc,GetSysColor(COLOR_MENUTEXT));
|
---|
1199 | else
|
---|
1200 | SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
|
---|
1201 | }
|
---|
1202 | #endif
|
---|
1203 | SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
|
---|
1204 | }
|
---|
1205 | else
|
---|
1206 | {
|
---|
1207 | if (lpitem->fState & MF_GRAYED)
|
---|
1208 | SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
|
---|
1209 | else
|
---|
1210 | SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
|
---|
1211 | SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | /* helper lines for debugging */
|
---|
1215 | /* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
|
---|
1216 | SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
|
---|
1217 | MoveTo( hdc, rect.left, (rect.top + rect.bottom)/2,NULL);
|
---|
1218 | LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
|
---|
1219 | */
|
---|
1220 |
|
---|
1221 | if (!menuBar)
|
---|
1222 | {
|
---|
1223 | INT y = rect.top + rect.bottom;
|
---|
1224 |
|
---|
1225 | /* Draw the check mark
|
---|
1226 | *
|
---|
1227 | * FIXME:
|
---|
1228 | * Custom checkmark bitmaps are monochrome but not always 1bpp.
|
---|
1229 | */
|
---|
1230 |
|
---|
1231 | if (lpitem->fState & MF_CHECKED)
|
---|
1232 | {
|
---|
1233 | HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
|
---|
1234 | ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
|
---|
1235 | HDC hdcMem = CreateCompatibleDC( hdc );
|
---|
1236 |
|
---|
1237 | SelectObject( hdcMem, bm );
|
---|
1238 | BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
|
---|
1239 | check_bitmap_width, check_bitmap_height,
|
---|
1240 | hdcMem, 0, 0, (lpitem->fState & MF_HILITE) ? MERGEPAINT : SRCAND );
|
---|
1241 | DeleteDC( hdcMem );
|
---|
1242 | }
|
---|
1243 | else if (lpitem->hUnCheckBit)
|
---|
1244 | {
|
---|
1245 | HDC hdcMem = CreateCompatibleDC( hdc );
|
---|
1246 |
|
---|
1247 | SelectObject( hdcMem, lpitem->hUnCheckBit );
|
---|
1248 | BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
|
---|
1249 | check_bitmap_width, check_bitmap_height,
|
---|
1250 | hdcMem, 0, 0, (lpitem->fState & MF_HILITE) ? MERGEPAINT : SRCAND );
|
---|
1251 | DeleteDC( hdcMem );
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | /* Draw the popup-menu arrow */
|
---|
1255 | if (lpitem->fType & MF_POPUP)
|
---|
1256 | {
|
---|
1257 | HDC hdcMem = CreateCompatibleDC( hdc );
|
---|
1258 |
|
---|
1259 | SelectObject( hdcMem, hStdMnArrow );
|
---|
1260 | BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
|
---|
1261 | (y - arrow_bitmap_height) / 2,
|
---|
1262 | arrow_bitmap_width, arrow_bitmap_height,
|
---|
1263 | hdcMem, 0, 0, (lpitem->fState & MF_HILITE) ? MERGEPAINT : SRCAND );
|
---|
1264 | DeleteDC( hdcMem );
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | rect.left += check_bitmap_width;
|
---|
1268 | rect.right -= arrow_bitmap_width;
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | /* Draw the item text or bitmap */
|
---|
1272 | if (IS_BITMAP_ITEM(lpitem->fType))
|
---|
1273 | { int top;
|
---|
1274 |
|
---|
1275 | HBITMAP resBmp = 0;
|
---|
1276 |
|
---|
1277 | HDC hdcMem = CreateCompatibleDC( hdc );
|
---|
1278 |
|
---|
1279 | /*
|
---|
1280 | * Check if there is a magic menu item associated with this item
|
---|
1281 | * and load the appropriate bitmap
|
---|
1282 | */
|
---|
1283 | if((LOWORD((int)lpitem->text)) < 12)
|
---|
1284 | {
|
---|
1285 | resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
|
---|
1286 | lpitem->dwItemData);
|
---|
1287 | }
|
---|
1288 | else
|
---|
1289 | resBmp = (HBITMAP)lpitem->text;
|
---|
1290 |
|
---|
1291 | if (resBmp)
|
---|
1292 | {
|
---|
1293 | BITMAP bm;
|
---|
1294 | GetObjectA( resBmp, sizeof(bm), &bm );
|
---|
1295 |
|
---|
1296 | SelectObject(hdcMem,resBmp );
|
---|
1297 |
|
---|
1298 | /* handle fontsize > bitmap_height */
|
---|
1299 | top = ((rect.bottom-rect.top)>bm.bmHeight) ?
|
---|
1300 | rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
|
---|
1301 |
|
---|
1302 | BitBlt( hdc, rect.left, top, rect.right - rect.left,
|
---|
1303 | rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
|
---|
1304 | }
|
---|
1305 | DeleteDC( hdcMem );
|
---|
1306 |
|
---|
1307 | return;
|
---|
1308 |
|
---|
1309 | }
|
---|
1310 | /* No bitmap - process text if present */
|
---|
1311 | else if (IS_STRING_ITEM(lpitem->fType))
|
---|
1312 | {
|
---|
1313 | register int i;
|
---|
1314 | HFONT hfontOld = 0;
|
---|
1315 |
|
---|
1316 | UINT uFormat = (menuBar) ?
|
---|
1317 | DT_CENTER | DT_VCENTER | DT_SINGLELINE :
|
---|
1318 | DT_LEFT | DT_VCENTER | DT_SINGLELINE;
|
---|
1319 |
|
---|
1320 | if ( lpitem->fState & MFS_DEFAULT )
|
---|
1321 | {
|
---|
1322 | hfontOld = SelectObject( hdc, hMenuFontBold);
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | if (menuBar)
|
---|
1326 | {
|
---|
1327 | rect.left += MENU_BAR_ITEMS_SPACE / 2;
|
---|
1328 | rect.right -= MENU_BAR_ITEMS_SPACE / 2;
|
---|
1329 | i = strlen( lpitem->text );
|
---|
1330 | }
|
---|
1331 | else
|
---|
1332 | {
|
---|
1333 | for (i = 0; lpitem->text[i]; i++)
|
---|
1334 | if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
|
---|
1335 | break;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | if(lpitem->fState & MF_GRAYED)
|
---|
1339 | {
|
---|
1340 | if (!(lpitem->fState & MF_HILITE) )
|
---|
1341 | {
|
---|
1342 | ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
|
---|
1343 | SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
|
---|
1344 | DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
|
---|
1345 | --rect.left; --rect.top; --rect.right; --rect.bottom;
|
---|
1346 | }
|
---|
1347 | SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
|
---|
1351 |
|
---|
1352 | /* paint the shortcut text */
|
---|
1353 | if (lpitem->text[i]) /* There's a tab or flush-right char */
|
---|
1354 | {
|
---|
1355 | if (lpitem->text[i] == '\t')
|
---|
1356 | {
|
---|
1357 | rect.left = lpitem->xTab;
|
---|
1358 | uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
|
---|
1359 | }
|
---|
1360 | else
|
---|
1361 | {
|
---|
1362 | uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | if(lpitem->fState & MF_GRAYED)
|
---|
1366 | {
|
---|
1367 | if (!(lpitem->fState & MF_HILITE) )
|
---|
1368 | {
|
---|
1369 | ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
|
---|
1370 | SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
|
---|
1371 | DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
|
---|
1372 | --rect.left; --rect.top; --rect.right; --rect.bottom;
|
---|
1373 | }
|
---|
1374 | SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
|
---|
1375 | }
|
---|
1376 | DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | if (hfontOld)
|
---|
1380 | SelectObject (hdc, hfontOld);
|
---|
1381 | }
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 |
|
---|
1385 | /***********************************************************************
|
---|
1386 | * MENU_DrawPopupMenu
|
---|
1387 | *
|
---|
1388 | * Paint a popup menu.
|
---|
1389 | */
|
---|
1390 | static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
|
---|
1391 | {
|
---|
1392 | HBRUSH hPrevBrush = 0;
|
---|
1393 | RECT rect;
|
---|
1394 |
|
---|
1395 | //TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
|
---|
1396 |
|
---|
1397 | GetClientRect( hwnd, &rect );
|
---|
1398 |
|
---|
1399 | if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
|
---|
1400 | && (SelectObject( hdc, hMenuFont)))
|
---|
1401 | {
|
---|
1402 | HPEN hPrevPen;
|
---|
1403 |
|
---|
1404 | Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
|
---|
1405 |
|
---|
1406 | hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
|
---|
1407 | if( hPrevPen )
|
---|
1408 | {
|
---|
1409 | INT ropPrev, i;
|
---|
1410 | POPUPMENU *menu;
|
---|
1411 |
|
---|
1412 | /* draw 3-d shade */
|
---|
1413 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
|
---|
1414 |
|
---|
1415 | /* draw menu items */
|
---|
1416 |
|
---|
1417 | menu = MENU_GetMenu(hmenu);
|
---|
1418 | if (menu && menu->nItems)
|
---|
1419 | {
|
---|
1420 | MENUITEM *item;
|
---|
1421 | UINT u;
|
---|
1422 |
|
---|
1423 | for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
|
---|
1424 | MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
|
---|
1425 | menu->Height, FALSE, ODA_DRAWENTIRE );
|
---|
1426 |
|
---|
1427 | }
|
---|
1428 | } else
|
---|
1429 | {
|
---|
1430 | SelectObject( hdc, hPrevBrush );
|
---|
1431 | }
|
---|
1432 | }
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | /***********************************************************************
|
---|
1436 | * MENU_DrawMenuBar
|
---|
1437 | *
|
---|
1438 | * Paint a menu bar. Returns the height of the menu bar.
|
---|
1439 | * called from [windows/nonclient.c]
|
---|
1440 | */
|
---|
1441 | UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
|
---|
1442 | BOOL suppress_draw)
|
---|
1443 | {
|
---|
1444 | LPPOPUPMENU lppop;
|
---|
1445 | UINT i,retvalue;
|
---|
1446 | HFONT hfontOld = 0;
|
---|
1447 |
|
---|
1448 | lppop = MENU_GetMenu(GetMenu(hwnd));
|
---|
1449 | if (lppop == NULL || lprect == NULL)
|
---|
1450 | {
|
---|
1451 | retvalue = GetSystemMetrics(SM_CYMENU);
|
---|
1452 | goto END;
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 | //TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
|
---|
1456 |
|
---|
1457 | hfontOld = SelectObject( hDC, hMenuFont);
|
---|
1458 |
|
---|
1459 | if (lppop->Height == 0)
|
---|
1460 | MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
|
---|
1461 |
|
---|
1462 | lprect->bottom = lprect->top + lppop->Height;
|
---|
1463 |
|
---|
1464 | if (suppress_draw)
|
---|
1465 | {
|
---|
1466 | retvalue = lppop->Height;
|
---|
1467 | goto END;
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 | HDC memDC;
|
---|
1471 | HBITMAP memBmp,oldBmp;
|
---|
1472 | RECT r;
|
---|
1473 | HFONT oldMemFont;
|
---|
1474 |
|
---|
1475 | memDC = CreateCompatibleDC(hDC);
|
---|
1476 | r = *lprect;
|
---|
1477 | r.right -= r.left;
|
---|
1478 | r.bottom -= r.top;
|
---|
1479 | r.left = r.top = 0;
|
---|
1480 | memBmp = CreateCompatibleBitmap(hDC,r.right,r.bottom+1);
|
---|
1481 | oldBmp = SelectObject(memDC,memBmp);
|
---|
1482 | oldMemFont = SelectObject(memDC,hMenuFont);
|
---|
1483 |
|
---|
1484 | FillRect(memDC,&r,GetSysColorBrush(COLOR_MENU));
|
---|
1485 |
|
---|
1486 | SelectObject(memDC,GetSysColorPen(COLOR_3DFACE));
|
---|
1487 | MoveToEx(memDC,r.left,r.bottom,NULL);
|
---|
1488 | LineTo(memDC,r.right,r.bottom);
|
---|
1489 |
|
---|
1490 | if (lppop->nItems == 0)
|
---|
1491 | {
|
---|
1492 | retvalue = GetSystemMetrics(SM_CYMENU);
|
---|
1493 | } else
|
---|
1494 | {
|
---|
1495 | for (i = 0; i < lppop->nItems; i++)
|
---|
1496 | {
|
---|
1497 | OffsetRect(&lppop->items[i].rect,-lprect->left,-lprect->top);
|
---|
1498 | MENU_DrawMenuItem( hwnd,GetMenu(hwnd), GetWindow(hwnd,GW_OWNER),
|
---|
1499 | memDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
|
---|
1500 | OffsetRect(&lppop->items[i].rect,lprect->left,lprect->top);
|
---|
1501 | }
|
---|
1502 | retvalue = lppop->Height;
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | BitBlt(hDC,lprect->left,lprect->top,lprect->right-lprect->left,lprect->bottom-lprect->top+1,memDC,0,0,SRCCOPY);
|
---|
1506 | SelectObject(memDC,oldBmp);
|
---|
1507 | if (oldMemFont) SelectObject(memDC,oldMemFont);
|
---|
1508 | DeleteObject(memBmp);
|
---|
1509 | DeleteDC(memDC);
|
---|
1510 |
|
---|
1511 | END:
|
---|
1512 | if (hfontOld)
|
---|
1513 | SelectObject (hDC, hfontOld);
|
---|
1514 |
|
---|
1515 | return retvalue;
|
---|
1516 | }
|
---|
1517 |
|
---|
1518 | /***********************************************************************
|
---|
1519 | * MENU_PatchResidentPopup
|
---|
1520 | */
|
---|
1521 | BOOL MENU_PatchResidentPopup( HQUEUE checkQueue, HWND checkWnd )
|
---|
1522 | {
|
---|
1523 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
---|
1524 | #if 0 //CB: todo
|
---|
1525 | if( pTPWnd )
|
---|
1526 | {
|
---|
1527 | HTASK hTask = 0;
|
---|
1528 |
|
---|
1529 | //TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
|
---|
1530 | // checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
|
---|
1531 | // pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
|
---|
1532 |
|
---|
1533 | switch( checkQueue )
|
---|
1534 | {
|
---|
1535 | case 0: /* checkWnd is the new popup owner */
|
---|
1536 | if( checkWnd )
|
---|
1537 | {
|
---|
1538 | pTPWnd->owner = checkWnd;
|
---|
1539 | if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
|
---|
1540 | hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
|
---|
1541 | }
|
---|
1542 | break;
|
---|
1543 |
|
---|
1544 | case 0xFFFF: /* checkWnd is destroyed */
|
---|
1545 | if( pTPWnd->owner == checkWnd )
|
---|
1546 | pTPWnd->owner = NULL;
|
---|
1547 | MENU_ReleaseTopPopupWnd();
|
---|
1548 | return TRUE;
|
---|
1549 |
|
---|
1550 | default: /* checkQueue is exiting */
|
---|
1551 | if( pTPWnd->hmemTaskQ == checkQueue )
|
---|
1552 | {
|
---|
1553 | hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
|
---|
1554 | hTask = TASK_GetNextTask( hTask );
|
---|
1555 | }
|
---|
1556 | break;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | if( hTask )
|
---|
1560 | {
|
---|
1561 | TDB* task = (TDB*)GlobalLock( hTask );
|
---|
1562 | if( task )
|
---|
1563 | {
|
---|
1564 | pTPWnd->hInstance = task->hInstance;
|
---|
1565 | pTPWnd->hmemTaskQ = task->hQueue;
|
---|
1566 | MENU_ReleaseTopPopupWnd();
|
---|
1567 | return TRUE;
|
---|
1568 | }
|
---|
1569 | //else WARN("failed to patch resident popup.\n");
|
---|
1570 | }
|
---|
1571 | }
|
---|
1572 | #endif
|
---|
1573 | MENU_ReleaseTopPopupWnd();
|
---|
1574 | return FALSE;
|
---|
1575 | }
|
---|
1576 |
|
---|
1577 | /***********************************************************************
|
---|
1578 | * MENU_ShowPopup
|
---|
1579 | *
|
---|
1580 | * Display a popup menu.
|
---|
1581 | */
|
---|
1582 | static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
|
---|
1583 | INT x, INT y, INT xanchor, INT yanchor )
|
---|
1584 | {
|
---|
1585 | POPUPMENU *menu;
|
---|
1586 |
|
---|
1587 | //TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
|
---|
1588 | //hwndOwner, hmenu, id, x, y, xanchor, yanchor);
|
---|
1589 |
|
---|
1590 | if (!(menu = MENU_GetMenu(hmenu))) return FALSE;
|
---|
1591 | if (menu->FocusedItem != NO_SELECTED_ITEM)
|
---|
1592 | {
|
---|
1593 | menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
|
---|
1594 | menu->FocusedItem = NO_SELECTED_ITEM;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | /* store the owner for DrawItem*/
|
---|
1598 | menu->hwndOwner = hwndOwner;
|
---|
1599 |
|
---|
1600 | if(IsWindow(hwndOwner))
|
---|
1601 | {
|
---|
1602 | UINT width, height;
|
---|
1603 |
|
---|
1604 | MENU_PopupMenuCalcSize( menu, hwndOwner );
|
---|
1605 |
|
---|
1606 | /* adjust popup menu pos so that it fits within the desktop */
|
---|
1607 |
|
---|
1608 | width = menu->Width + GetSystemMetrics(SM_CXBORDER);
|
---|
1609 | height = menu->Height + GetSystemMetrics(SM_CYBORDER);
|
---|
1610 |
|
---|
1611 | if( x + width > GetSystemMetrics(SM_CXSCREEN ))
|
---|
1612 | {
|
---|
1613 | if( xanchor )
|
---|
1614 | x -= width - xanchor;
|
---|
1615 | if( x + width > GetSystemMetrics(SM_CXSCREEN))
|
---|
1616 | x = GetSystemMetrics(SM_CXSCREEN) - width;
|
---|
1617 | }
|
---|
1618 | if( x < 0 ) x = 0;
|
---|
1619 |
|
---|
1620 | if( y + height > GetSystemMetrics(SM_CYSCREEN ))
|
---|
1621 | {
|
---|
1622 | if( yanchor )
|
---|
1623 | y -= height + yanchor;
|
---|
1624 | if( y + height > GetSystemMetrics(SM_CYSCREEN ))
|
---|
1625 | y = GetSystemMetrics(SM_CYSCREEN) - height;
|
---|
1626 | }
|
---|
1627 | if( y < 0 ) y = 0;
|
---|
1628 |
|
---|
1629 | /* NOTE: In Windows, top menu popup is not owned. */
|
---|
1630 | if (!pTopPopupWnd) /* create top level popup menu window */
|
---|
1631 | {
|
---|
1632 | assert( uSubPWndLevel == 0 );
|
---|
1633 |
|
---|
1634 | pTopPopupWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
|
---|
1635 | WS_POPUP, x, y, width, height,
|
---|
1636 | hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
|
---|
1637 | (LPVOID)hmenu );
|
---|
1638 | if (!pTopPopupWnd)
|
---|
1639 | {
|
---|
1640 | DebugInt3();
|
---|
1641 | return FALSE;
|
---|
1642 | }
|
---|
1643 | menu->hWnd = pTopPopupWnd;
|
---|
1644 | MENU_ReleaseTopPopupWnd();
|
---|
1645 | }
|
---|
1646 | else
|
---|
1647 | if( uSubPWndLevel )
|
---|
1648 | {
|
---|
1649 | /* create a new window for the submenu */
|
---|
1650 |
|
---|
1651 | menu->hWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
|
---|
1652 | WS_POPUP, x, y, width, height,
|
---|
1653 | hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
|
---|
1654 | (LPVOID)hmenu );
|
---|
1655 | if( !menu->hWnd )
|
---|
1656 | {
|
---|
1657 | DebugInt3();
|
---|
1658 | return FALSE;
|
---|
1659 | }
|
---|
1660 | }
|
---|
1661 | else /* top level popup menu window already exists */
|
---|
1662 | {
|
---|
1663 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
---|
1664 | menu->hWnd = pTPWnd;
|
---|
1665 |
|
---|
1666 | MENU_PatchResidentPopup( 0, hwndOwner );
|
---|
1667 | SendMessageA( pTPWnd, MM_SETMENUHANDLE, (WPARAM)hmenu, 0L);
|
---|
1668 |
|
---|
1669 | /* adjust its size */
|
---|
1670 |
|
---|
1671 | SetWindowPos( menu->hWnd, 0, x, y, width, height,
|
---|
1672 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
|
---|
1673 | MENU_ReleaseTopPopupWnd();
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | uSubPWndLevel++; /* menu level counter */
|
---|
1677 |
|
---|
1678 | /* Display the window */
|
---|
1679 |
|
---|
1680 | SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
|
---|
1681 | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
|
---|
1682 | EnableWindow(menu->hWnd,TRUE);
|
---|
1683 | UpdateWindow( menu->hWnd );
|
---|
1684 | return TRUE;
|
---|
1685 | }
|
---|
1686 | return FALSE;
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 |
|
---|
1690 | /***********************************************************************
|
---|
1691 | * MENU_SelectItem
|
---|
1692 | */
|
---|
1693 | static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
|
---|
1694 | BOOL sendMenuSelect, HMENU topmenu )
|
---|
1695 | {
|
---|
1696 | LPPOPUPMENU lppop;
|
---|
1697 | HDC hdc;
|
---|
1698 |
|
---|
1699 | //TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
|
---|
1700 |
|
---|
1701 | lppop = MENU_GetMenu(hmenu);
|
---|
1702 | if ((!lppop) || (!lppop->nItems)) return;
|
---|
1703 |
|
---|
1704 | if (lppop->FocusedItem == wIndex) return;
|
---|
1705 | if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
|
---|
1706 | else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
---|
1707 |
|
---|
1708 | SelectObject( hdc, hMenuFont);
|
---|
1709 |
|
---|
1710 | /* Clear previous highlighted item */
|
---|
1711 | if (lppop->FocusedItem != NO_SELECTED_ITEM)
|
---|
1712 | {
|
---|
1713 | lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
|
---|
1714 | MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
|
---|
1715 | lppop->Height, !(lppop->wFlags & MF_POPUP),
|
---|
1716 | ODA_SELECT );
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | /* Highlight new item (if any) */
|
---|
1720 | lppop->FocusedItem = wIndex;
|
---|
1721 | if (lppop->FocusedItem != NO_SELECTED_ITEM)
|
---|
1722 | {
|
---|
1723 | if(!(lppop->items[wIndex].fType & MF_SEPARATOR)) {
|
---|
1724 | lppop->items[wIndex].fState |= MF_HILITE;
|
---|
1725 | MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc,
|
---|
1726 | &lppop->items[wIndex], lppop->Height,
|
---|
1727 | !(lppop->wFlags & MF_POPUP), ODA_SELECT );
|
---|
1728 | }
|
---|
1729 | if (sendMenuSelect)
|
---|
1730 | {
|
---|
1731 | MENUITEM *ip = &lppop->items[lppop->FocusedItem];
|
---|
1732 | SendMessageA( hwndOwner, WM_MENUSELECT,
|
---|
1733 | MAKELONG(ip->fType & MF_POPUP ? wIndex: ip->wID,
|
---|
1734 | ip->fType | ip->fState | MF_MOUSESELECT |
|
---|
1735 | (lppop->wFlags & MF_SYSMENU)), hmenu);
|
---|
1736 | }
|
---|
1737 | }
|
---|
1738 | else if (sendMenuSelect) {
|
---|
1739 | if(topmenu){
|
---|
1740 | int pos;
|
---|
1741 | if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){
|
---|
1742 | #ifdef __WIN32OS2__
|
---|
1743 | POPUPMENU *ptm = MENU_GetMenu(topmenu);
|
---|
1744 | #else
|
---|
1745 | POPUPMENU *ptm = (POPUPMENU*)topmenu;
|
---|
1746 | #endif
|
---|
1747 | MENUITEM *ip = &ptm->items[pos];
|
---|
1748 | SendMessageA( hwndOwner, WM_MENUSELECT, MAKELONG(pos,
|
---|
1749 | ip->fType | ip->fState | MF_MOUSESELECT |
|
---|
1750 | (ptm->wFlags & MF_SYSMENU)), topmenu);
|
---|
1751 | }
|
---|
1752 | }
|
---|
1753 | }
|
---|
1754 | ReleaseDC( lppop->hWnd, hdc );
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 |
|
---|
1758 | /***********************************************************************
|
---|
1759 | * MENU_MoveSelection
|
---|
1760 | *
|
---|
1761 | * Moves currently selected item according to the offset parameter.
|
---|
1762 | * If there is no selection then it should select the last item if
|
---|
1763 | * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
|
---|
1764 | */
|
---|
1765 | static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
|
---|
1766 | {
|
---|
1767 | INT i;
|
---|
1768 | POPUPMENU *menu;
|
---|
1769 |
|
---|
1770 | //TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
|
---|
1771 |
|
---|
1772 | menu = MENU_GetMenu(hmenu);
|
---|
1773 | if ((!menu) || (!menu->items)) return;
|
---|
1774 |
|
---|
1775 | if ( menu->FocusedItem != NO_SELECTED_ITEM )
|
---|
1776 | {
|
---|
1777 | if( menu->nItems == 1 ) return; else
|
---|
1778 | for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
|
---|
1779 | ; i += offset)
|
---|
1780 | if (!(menu->items[i].fType & MF_SEPARATOR))
|
---|
1781 | {
|
---|
1782 | MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
|
---|
1783 | return;
|
---|
1784 | }
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | for ( i = (offset > 0) ? 0 : menu->nItems - 1;
|
---|
1788 | i >= 0 && i < menu->nItems ; i += offset)
|
---|
1789 | if (!(menu->items[i].fType & MF_SEPARATOR))
|
---|
1790 | {
|
---|
1791 | MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
|
---|
1792 | return;
|
---|
1793 | }
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 |
|
---|
1797 | /**********************************************************************
|
---|
1798 | * MENU_SetItemData
|
---|
1799 | *
|
---|
1800 | * Set an item flags, id and text ptr. Called by InsertMenu() and
|
---|
1801 | * ModifyMenu().
|
---|
1802 | */
|
---|
1803 | static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
|
---|
1804 | LPCSTR str )
|
---|
1805 | {
|
---|
1806 | LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
|
---|
1807 |
|
---|
1808 | //debug_print_menuitem("MENU_SetItemData from: ", item, "");
|
---|
1809 |
|
---|
1810 |
|
---|
1811 | if (IS_STRING_ITEM(flags))
|
---|
1812 | {
|
---|
1813 | if (!str || !*str)
|
---|
1814 | {
|
---|
1815 | flags |= MF_SEPARATOR;
|
---|
1816 | item->text = NULL;
|
---|
1817 | }
|
---|
1818 | else
|
---|
1819 | {
|
---|
1820 | LPSTR text;
|
---|
1821 | /* Item beginning with a backspace is a help item */
|
---|
1822 | if (*str == '\b')
|
---|
1823 | {
|
---|
1824 | flags |= MF_HELP;
|
---|
1825 | str++;
|
---|
1826 | }
|
---|
1827 | if (!(text = HEAP_strdupA(GetProcessHeap(), 0, str ))) return FALSE;
|
---|
1828 | item->text = text;
|
---|
1829 | }
|
---|
1830 | }
|
---|
1831 | else if (IS_BITMAP_ITEM(flags))
|
---|
1832 | #ifdef __WIN32OS2__
|
---|
1833 | //SvL: Our bitmap handles are 32 bits!
|
---|
1834 | item->text = (LPSTR)str;
|
---|
1835 | #else
|
---|
1836 | item->text = (LPSTR)(HBITMAP)LOWORD(str);
|
---|
1837 | #endif
|
---|
1838 | else item->text = NULL;
|
---|
1839 |
|
---|
1840 | if (flags & MF_OWNERDRAW)
|
---|
1841 | item->dwItemData = (DWORD)str;
|
---|
1842 | else
|
---|
1843 | item->dwItemData = 0;
|
---|
1844 |
|
---|
1845 | if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
|
---|
1846 | DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
|
---|
1847 |
|
---|
1848 | if (flags & MF_POPUP)
|
---|
1849 | {
|
---|
1850 | POPUPMENU *menu = MENU_GetMenu((UINT)id);
|
---|
1851 | if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
|
---|
1852 | else
|
---|
1853 | {
|
---|
1854 | item->wID = 0;
|
---|
1855 | item->hSubMenu = 0;
|
---|
1856 | item->fType = 0;
|
---|
1857 | item->fState = 0;
|
---|
1858 | return FALSE;
|
---|
1859 | }
|
---|
1860 | }
|
---|
1861 |
|
---|
1862 | item->wID = id;
|
---|
1863 | if (flags & MF_POPUP)
|
---|
1864 | item->hSubMenu = id;
|
---|
1865 |
|
---|
1866 | if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
|
---|
1867 | flags |= MF_POPUP; /* keep popup */
|
---|
1868 |
|
---|
1869 | item->fType = flags & TYPE_MASK;
|
---|
1870 | item->fState = (flags & STATE_MASK) &
|
---|
1871 | ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
|
---|
1872 |
|
---|
1873 |
|
---|
1874 | /* Don't call SetRectEmpty here! */
|
---|
1875 |
|
---|
1876 |
|
---|
1877 | if (prevText) HeapFree(GetProcessHeap(), 0, prevText );
|
---|
1878 |
|
---|
1879 | //debug_print_menuitem("MENU_SetItemData to : ", item, "");
|
---|
1880 | return TRUE;
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 |
|
---|
1884 | /**********************************************************************
|
---|
1885 | * MENU_InsertItem
|
---|
1886 | *
|
---|
1887 | * Insert a new item into a menu.
|
---|
1888 | */
|
---|
1889 | static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
|
---|
1890 | {
|
---|
1891 | MENUITEM *newItems;
|
---|
1892 | POPUPMENU *menu;
|
---|
1893 |
|
---|
1894 | if (!(menu = MENU_GetMenu(hMenu)))
|
---|
1895 | return NULL;
|
---|
1896 |
|
---|
1897 | /* Find where to insert new item */
|
---|
1898 | if (flags & MF_BYPOSITION) {
|
---|
1899 | if (pos > menu->nItems)
|
---|
1900 | pos = menu->nItems;
|
---|
1901 | } else {
|
---|
1902 | if (!MENU_FindItem( &hMenu, &pos, flags ))
|
---|
1903 | pos = menu->nItems;
|
---|
1904 | else {
|
---|
1905 | if (!(menu = MENU_GetMenu( hMenu )))
|
---|
1906 | return NULL;
|
---|
1907 | }
|
---|
1908 | }
|
---|
1909 | /* Create new items array */
|
---|
1910 |
|
---|
1911 | newItems = (MENUITEM*)HeapAlloc(GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
|
---|
1912 | if (!newItems)
|
---|
1913 | {
|
---|
1914 | //WARN("allocation failed\n" );
|
---|
1915 | return NULL;
|
---|
1916 | }
|
---|
1917 | if (menu->nItems > 0)
|
---|
1918 | {
|
---|
1919 | /* Copy the old array into the new */
|
---|
1920 | if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
|
---|
1921 | if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
|
---|
1922 | (menu->nItems-pos)*sizeof(MENUITEM) );
|
---|
1923 | HeapFree(GetProcessHeap(), 0, menu->items );
|
---|
1924 | }
|
---|
1925 | menu->items = newItems;
|
---|
1926 | menu->nItems++;
|
---|
1927 | memset( &newItems[pos], 0, sizeof(*newItems) );
|
---|
1928 | menu->Height = 0; /* force size recalculate */
|
---|
1929 | return &newItems[pos];
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 |
|
---|
1933 | /**********************************************************************
|
---|
1934 | * MENU_ParseResource
|
---|
1935 | *
|
---|
1936 | * Parse a standard menu resource and add items to the menu.
|
---|
1937 | * Return a pointer to the end of the resource.
|
---|
1938 | */
|
---|
1939 | static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
|
---|
1940 | {
|
---|
1941 | WORD flags, id = 0;
|
---|
1942 | LPCSTR str;
|
---|
1943 |
|
---|
1944 | do
|
---|
1945 | {
|
---|
1946 | flags = GET_WORD(res);
|
---|
1947 | res += sizeof(WORD);
|
---|
1948 | if (!(flags & MF_POPUP))
|
---|
1949 | {
|
---|
1950 | id = GET_WORD(res);
|
---|
1951 | res += sizeof(WORD);
|
---|
1952 | }
|
---|
1953 | //if (!IS_STRING_ITEM(flags))
|
---|
1954 | // ERR("not a string item %04x\n", flags );
|
---|
1955 | str = res;
|
---|
1956 | if (!unicode) res += strlen(str) + 1;
|
---|
1957 | else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
|
---|
1958 | if (flags & MF_POPUP)
|
---|
1959 | {
|
---|
1960 | HMENU hSubMenu = CreatePopupMenu();
|
---|
1961 | if (!hSubMenu) return NULL;
|
---|
1962 | if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
|
---|
1963 | return NULL;
|
---|
1964 | if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
|
---|
1965 | else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
|
---|
1966 | }
|
---|
1967 | else /* Not a popup */
|
---|
1968 | {
|
---|
1969 | if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
|
---|
1970 | else AppendMenuW( hMenu, flags, id,
|
---|
1971 | *(LPCWSTR)str ? (LPCWSTR)str : NULL );
|
---|
1972 | }
|
---|
1973 | } while (!(flags & MF_END));
|
---|
1974 | return res;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 |
|
---|
1978 | /**********************************************************************
|
---|
1979 | * MENUEX_ParseResource
|
---|
1980 | *
|
---|
1981 | * Parse an extended menu resource and add items to the menu.
|
---|
1982 | * Return a pointer to the end of the resource.
|
---|
1983 | */
|
---|
1984 | static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
|
---|
1985 | {
|
---|
1986 | WORD resinfo;
|
---|
1987 | do {
|
---|
1988 | MENUITEMINFOW mii;
|
---|
1989 |
|
---|
1990 | mii.cbSize = sizeof(mii);
|
---|
1991 | mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
|
---|
1992 | mii.fType = GET_DWORD(res);
|
---|
1993 | res += sizeof(DWORD);
|
---|
1994 | mii.fState = GET_DWORD(res);
|
---|
1995 | res += sizeof(DWORD);
|
---|
1996 | mii.wID = GET_DWORD(res);
|
---|
1997 | res += sizeof(DWORD);
|
---|
1998 | resinfo = GET_WORD(res);
|
---|
1999 | res += sizeof(WORD);
|
---|
2000 | /* Align the text on a word boundary. */
|
---|
2001 | res += (~((int)res - 1)) & 1;
|
---|
2002 | mii.dwTypeData = (LPWSTR) res;
|
---|
2003 | res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
|
---|
2004 | /* Align the following fields on a dword boundary. */
|
---|
2005 | res += (~((int)res - 1)) & 3;
|
---|
2006 |
|
---|
2007 | /* FIXME: This is inefficient and cannot be optimised away by gcc. */
|
---|
2008 | {
|
---|
2009 | LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
|
---|
2010 | 0, mii.dwTypeData);
|
---|
2011 | //TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
|
---|
2012 | // mii.fType, mii.fState, mii.wID, resinfo, newstr);
|
---|
2013 | HeapFree( GetProcessHeap(), 0, newstr );
|
---|
2014 | }
|
---|
2015 |
|
---|
2016 | if (resinfo & 1) { /* Pop-up? */
|
---|
2017 | /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
|
---|
2018 | res += sizeof(DWORD);
|
---|
2019 | mii.hSubMenu = CreatePopupMenu();
|
---|
2020 | if (!mii.hSubMenu)
|
---|
2021 | return NULL;
|
---|
2022 | if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
|
---|
2023 | DestroyMenu(mii.hSubMenu);
|
---|
2024 | return NULL;
|
---|
2025 | }
|
---|
2026 | mii.fMask |= MIIM_SUBMENU;
|
---|
2027 | mii.fType |= MF_POPUP;
|
---|
2028 | }
|
---|
2029 | InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
|
---|
2030 | } while (!(resinfo & MF_END));
|
---|
2031 | return res;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 |
|
---|
2035 | /***********************************************************************
|
---|
2036 | * MENU_GetSubPopup
|
---|
2037 | *
|
---|
2038 | * Return the handle of the selected sub-popup menu (if any).
|
---|
2039 | */
|
---|
2040 | static HMENU MENU_GetSubPopup( HMENU hmenu )
|
---|
2041 | {
|
---|
2042 | POPUPMENU *menu;
|
---|
2043 | MENUITEM *item;
|
---|
2044 |
|
---|
2045 | menu = MENU_GetMenu(hmenu);
|
---|
2046 |
|
---|
2047 | if ((!menu) || (menu->FocusedItem == NO_SELECTED_ITEM)) return 0;
|
---|
2048 |
|
---|
2049 | item = &menu->items[menu->FocusedItem];
|
---|
2050 | if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
|
---|
2051 | return item->hSubMenu;
|
---|
2052 | return 0;
|
---|
2053 | }
|
---|
2054 |
|
---|
2055 |
|
---|
2056 | /***********************************************************************
|
---|
2057 | * MENU_HideSubPopups
|
---|
2058 | *
|
---|
2059 | * Hide the sub-popup menus of this menu.
|
---|
2060 | */
|
---|
2061 | static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
|
---|
2062 | BOOL sendMenuSelect )
|
---|
2063 | {
|
---|
2064 | POPUPMENU *menu = MENU_GetMenu(hmenu);
|
---|
2065 |
|
---|
2066 | //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
|
---|
2067 |
|
---|
2068 | if (menu && uSubPWndLevel)
|
---|
2069 | {
|
---|
2070 | HMENU hsubmenu;
|
---|
2071 | POPUPMENU *submenu;
|
---|
2072 | MENUITEM *item;
|
---|
2073 |
|
---|
2074 | if (menu->FocusedItem != NO_SELECTED_ITEM)
|
---|
2075 | {
|
---|
2076 | item = &menu->items[menu->FocusedItem];
|
---|
2077 | if (!(item->fType & MF_POPUP) ||
|
---|
2078 | !(item->fState & MF_MOUSESELECT)) return;
|
---|
2079 | item->fState &= ~MF_MOUSESELECT;
|
---|
2080 | hsubmenu = item->hSubMenu;
|
---|
2081 | } else return;
|
---|
2082 |
|
---|
2083 | submenu = MENU_GetMenu(hsubmenu);
|
---|
2084 | MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
|
---|
2085 | MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
|
---|
2086 |
|
---|
2087 | if (submenu->hWnd == MENU_GetTopPopupWnd() )
|
---|
2088 | {
|
---|
2089 | DestroyWindow( submenu->hWnd );
|
---|
2090 | submenu->hWnd = 0;
|
---|
2091 | // ShowWindow( submenu->hWnd, SW_HIDE );
|
---|
2092 | uSubPWndLevel = 0;
|
---|
2093 | }
|
---|
2094 | else
|
---|
2095 | {
|
---|
2096 | DestroyWindow( submenu->hWnd );
|
---|
2097 | submenu->hWnd = 0;
|
---|
2098 | }
|
---|
2099 | MENU_ReleaseTopPopupWnd();
|
---|
2100 | }
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 |
|
---|
2104 | /***********************************************************************
|
---|
2105 | * MENU_ShowSubPopup
|
---|
2106 | *
|
---|
2107 | * Display the sub-menu of the selected item of this menu.
|
---|
2108 | * Return the handle of the submenu, or hmenu if no submenu to display.
|
---|
2109 | */
|
---|
2110 | static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
|
---|
2111 | BOOL selectFirst, UINT wFlags,POINT *pt)
|
---|
2112 | {
|
---|
2113 | RECT rect;
|
---|
2114 | POPUPMENU *menu;
|
---|
2115 | MENUITEM *item;
|
---|
2116 | HDC hdc;
|
---|
2117 |
|
---|
2118 | //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
|
---|
2119 |
|
---|
2120 | if (!(menu = MENU_GetMenu(hmenu))) return hmenu;
|
---|
2121 |
|
---|
2122 | if (menu->FocusedItem == NO_SELECTED_ITEM)
|
---|
2123 | {
|
---|
2124 | return hmenu;
|
---|
2125 | }
|
---|
2126 |
|
---|
2127 | item = &menu->items[menu->FocusedItem];
|
---|
2128 | if (!(item->fType & MF_POPUP) ||
|
---|
2129 | (item->fState & (MF_GRAYED | MF_DISABLED)))
|
---|
2130 | {
|
---|
2131 | return hmenu;
|
---|
2132 | }
|
---|
2133 |
|
---|
2134 | /* message must be send before using item,
|
---|
2135 | because nearly everything may by changed by the application ! */
|
---|
2136 |
|
---|
2137 | /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
|
---|
2138 | if (!(wFlags & TPM_NONOTIFY))
|
---|
2139 | SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
|
---|
2140 | MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
|
---|
2141 |
|
---|
2142 | item = &menu->items[menu->FocusedItem];
|
---|
2143 | rect = item->rect;
|
---|
2144 |
|
---|
2145 | /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
|
---|
2146 | if (!(item->fState & MF_HILITE))
|
---|
2147 | {
|
---|
2148 | if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
|
---|
2149 | else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
---|
2150 |
|
---|
2151 | SelectObject( hdc, hMenuFont);
|
---|
2152 |
|
---|
2153 | item->fState |= MF_HILITE;
|
---|
2154 | MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
|
---|
2155 | ReleaseDC( menu->hWnd, hdc );
|
---|
2156 | }
|
---|
2157 | if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
|
---|
2158 | item->rect = rect;
|
---|
2159 |
|
---|
2160 | item->fState |= MF_MOUSESELECT;
|
---|
2161 |
|
---|
2162 | if (IS_SYSTEM_MENU(menu))
|
---|
2163 | {
|
---|
2164 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
|
---|
2165 |
|
---|
2166 | MENU_InitSysMenuPopup(item->hSubMenu,GetWindowLongA(menu->hWnd,GWL_STYLE), GetClassLongA(menu->hWnd, GCL_STYLE));
|
---|
2167 |
|
---|
2168 | if ((wFlags & TPM_CAPTIONSYSMENU) && pt)
|
---|
2169 | {
|
---|
2170 | rect.top = pt->y;
|
---|
2171 | rect.left = pt->x;
|
---|
2172 | rect.bottom = rect.right = 0;
|
---|
2173 | } else
|
---|
2174 | {
|
---|
2175 | if (win32wnd) win32wnd->GetSysPopupPos(&rect);
|
---|
2176 | rect.top = rect.bottom;
|
---|
2177 | rect.right = GetSystemMetrics(SM_CXSIZE);
|
---|
2178 | rect.bottom = GetSystemMetrics(SM_CYSIZE);
|
---|
2179 | }
|
---|
2180 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
2181 | }
|
---|
2182 | else
|
---|
2183 | {
|
---|
2184 | if (menu->wFlags & MF_POPUP)
|
---|
2185 | {
|
---|
2186 | RECT rectWindow;
|
---|
2187 |
|
---|
2188 | GetWindowRect(menu->hWnd,&rectWindow);
|
---|
2189 | rect.left = rectWindow.left + item->rect.right;
|
---|
2190 | rect.top = rectWindow.top + item->rect.top;
|
---|
2191 | rect.right = item->rect.left - item->rect.right;
|
---|
2192 | rect.bottom = item->rect.top - item->rect.bottom;
|
---|
2193 | }
|
---|
2194 | else
|
---|
2195 | {
|
---|
2196 | RECT rectWindow;
|
---|
2197 |
|
---|
2198 | GetWindowRect(menu->hWnd,&rectWindow);
|
---|
2199 | rect.left = rectWindow.left + item->rect.left;
|
---|
2200 | rect.top = rectWindow.top + item->rect.bottom;
|
---|
2201 | rect.right = item->rect.right - item->rect.left;
|
---|
2202 | rect.bottom = item->rect.bottom - item->rect.top;
|
---|
2203 | }
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
|
---|
2207 | rect.left, rect.top, rect.right, rect.bottom );
|
---|
2208 | if (selectFirst)
|
---|
2209 | MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
|
---|
2210 | return item->hSubMenu;
|
---|
2211 | }
|
---|
2212 |
|
---|
2213 | /***********************************************************************
|
---|
2214 | * MENU_PtMenu
|
---|
2215 | *
|
---|
2216 | * Walks menu chain trying to find a menu pt maps to.
|
---|
2217 | */
|
---|
2218 | static HMENU MENU_PtMenu(HMENU hMenu,POINT pt,BOOL inMenuBar)
|
---|
2219 | {
|
---|
2220 | POPUPMENU *menu = MENU_GetMenu(hMenu);
|
---|
2221 | register UINT ht = menu->FocusedItem;
|
---|
2222 |
|
---|
2223 | /* try subpopup first (if any) */
|
---|
2224 | ht = (ht != NO_SELECTED_ITEM &&
|
---|
2225 | (menu->items[ht].fType & MF_POPUP) &&
|
---|
2226 | (menu->items[ht].fState & MF_MOUSESELECT))
|
---|
2227 | ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu,pt,inMenuBar) : 0;
|
---|
2228 |
|
---|
2229 | if( !ht ) /* check the current window (avoiding WM_HITTEST) */
|
---|
2230 | {
|
---|
2231 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
|
---|
2232 | if(win32wnd==NULL) {
|
---|
2233 | //SvL: This happens in Moraff's YourJongg 2.0, return here
|
---|
2234 | //TODO: Check if this is supposed to happen at all...
|
---|
2235 | return (HMENU)0;
|
---|
2236 | }
|
---|
2237 |
|
---|
2238 | ht = win32wnd->HandleNCHitTest(pt);
|
---|
2239 | RELEASE_WNDOBJ(win32wnd);
|
---|
2240 | if( menu->wFlags & MF_POPUP )
|
---|
2241 | ht = (ht != (UINT)HTNOWHERE &&
|
---|
2242 | ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
|
---|
2243 | else
|
---|
2244 | {
|
---|
2245 | ht = ((ht == HTSYSMENU) && !inMenuBar) ? (UINT)(getSysMenu(menu->hWnd))
|
---|
2246 | : ((ht == HTMENU) && inMenuBar) ? (UINT)(GetMenu(menu->hWnd)) : 0;
|
---|
2247 | }
|
---|
2248 | }
|
---|
2249 | return (HMENU)ht;
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | /***********************************************************************
|
---|
2253 | * MENU_ExecFocusedItem
|
---|
2254 | *
|
---|
2255 | * Execute a menu item (for instance when user pressed Enter).
|
---|
2256 | * Return the wID of the executed item. Otherwise, -1 indicating
|
---|
2257 | * that no menu item wase executed;
|
---|
2258 | * Have to receive the flags for the TrackPopupMenu options to avoid
|
---|
2259 | * sending unwanted message.
|
---|
2260 | *
|
---|
2261 | */
|
---|
2262 | static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
|
---|
2263 | {
|
---|
2264 | MENUITEM *item;
|
---|
2265 | POPUPMENU *menu = MENU_GetMenu(hMenu);
|
---|
2266 |
|
---|
2267 | //TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
|
---|
2268 |
|
---|
2269 | if (!menu || !menu->nItems ||
|
---|
2270 | (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
|
---|
2271 |
|
---|
2272 | item = &menu->items[menu->FocusedItem];
|
---|
2273 |
|
---|
2274 | //TRACE("%08x %08x %08x\n",
|
---|
2275 | // hMenu, item->wID, item->hSubMenu);
|
---|
2276 |
|
---|
2277 | if (!(item->fType & MF_POPUP))
|
---|
2278 | {
|
---|
2279 | if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
|
---|
2280 | {
|
---|
2281 | /* If TPM_RETURNCMD is set you return the id, but
|
---|
2282 | do not send a message to the owner */
|
---|
2283 | if(!(wFlags & TPM_RETURNCMD))
|
---|
2284 | {
|
---|
2285 | if( menu->wFlags & MF_SYSMENU )
|
---|
2286 | PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
|
---|
2287 | MAKELPARAM(pmt->pt.x, pmt->pt.y) );
|
---|
2288 | else
|
---|
2289 | PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
|
---|
2290 | }
|
---|
2291 | return item->wID;
|
---|
2292 | }
|
---|
2293 | }
|
---|
2294 | else
|
---|
2295 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags,&pmt->pt);
|
---|
2296 |
|
---|
2297 | return -1;
|
---|
2298 | }
|
---|
2299 |
|
---|
2300 | /***********************************************************************
|
---|
2301 | * MENU_SwitchTracking
|
---|
2302 | *
|
---|
2303 | * Helper function for menu navigation routines.
|
---|
2304 | */
|
---|
2305 | static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
|
---|
2306 | {
|
---|
2307 | POPUPMENU *ptmenu = MENU_GetMenu(hPtMenu);
|
---|
2308 | POPUPMENU *topmenu = MENU_GetMenu(pmt->hTopMenu);
|
---|
2309 |
|
---|
2310 | //TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
|
---|
2311 |
|
---|
2312 | if( pmt->hTopMenu != hPtMenu &&
|
---|
2313 | !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
|
---|
2314 | {
|
---|
2315 | /* both are top level menus (system and menu-bar) */
|
---|
2316 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
---|
2317 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
|
---|
2318 | pmt->hTopMenu = hPtMenu;
|
---|
2319 | }
|
---|
2320 | else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
|
---|
2321 | MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
|
---|
2322 | }
|
---|
2323 |
|
---|
2324 |
|
---|
2325 | /***********************************************************************
|
---|
2326 | * MENU_ButtonDown
|
---|
2327 | *
|
---|
2328 | * Return TRUE if we can go on with menu tracking.
|
---|
2329 | */
|
---|
2330 | static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
|
---|
2331 | {
|
---|
2332 | //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
|
---|
2333 |
|
---|
2334 | if (hPtMenu)
|
---|
2335 | {
|
---|
2336 | UINT id = 0;
|
---|
2337 | POPUPMENU *ptmenu = MENU_GetMenu(hPtMenu);
|
---|
2338 | MENUITEM *item;
|
---|
2339 |
|
---|
2340 | if( IS_SYSTEM_MENU(ptmenu) )
|
---|
2341 | item = ptmenu->items;
|
---|
2342 | else
|
---|
2343 | item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
---|
2344 |
|
---|
2345 | if( item )
|
---|
2346 | {
|
---|
2347 | if( ptmenu->FocusedItem != id )
|
---|
2348 | MENU_SwitchTracking( pmt, hPtMenu, id );
|
---|
2349 |
|
---|
2350 | /* If the popup menu is not already "popped" */
|
---|
2351 | if(!(item->fState & MF_MOUSESELECT ))
|
---|
2352 | {
|
---|
2353 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,hPtMenu,FALSE,wFlags,&pmt->pt);
|
---|
2354 |
|
---|
2355 | #ifdef __WIN32OS2__
|
---|
2356 | if(fOS2Look)
|
---|
2357 | ptmenu->bTimeToHide = FALSE;
|
---|
2358 | #else
|
---|
2359 | /* In win31, a newly popped menu always remains opened for the next buttonup */
|
---|
2360 | if(TWEAK_WineLook == WIN31_LOOK)
|
---|
2361 | ptmenu->bTimeToHide = FALSE;
|
---|
2362 | #endif
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | return TRUE;
|
---|
2366 | }
|
---|
2367 | /* Else the click was on the menu bar, finish the tracking */
|
---|
2368 | }
|
---|
2369 | return FALSE;
|
---|
2370 | }
|
---|
2371 |
|
---|
2372 | /***********************************************************************
|
---|
2373 | * MENU_ButtonUp
|
---|
2374 | *
|
---|
2375 | * Return the value of MENU_ExecFocusedItem if
|
---|
2376 | * the selected item was not a popup. Else open the popup.
|
---|
2377 | * A -1 return value indicates that we go on with menu tracking.
|
---|
2378 | *
|
---|
2379 | */
|
---|
2380 | static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
|
---|
2381 | {
|
---|
2382 | //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
|
---|
2383 |
|
---|
2384 | if (hPtMenu)
|
---|
2385 | {
|
---|
2386 | UINT id = 0;
|
---|
2387 | POPUPMENU *ptmenu = MENU_GetMenu(hPtMenu);
|
---|
2388 | MENUITEM *item;
|
---|
2389 |
|
---|
2390 | if( IS_SYSTEM_MENU(ptmenu) )
|
---|
2391 | item = ptmenu->items;
|
---|
2392 | else
|
---|
2393 | item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
---|
2394 |
|
---|
2395 | if( item && (ptmenu->FocusedItem == id ))
|
---|
2396 | {
|
---|
2397 | if( !(item->fType & MF_POPUP) )
|
---|
2398 | return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
|
---|
2399 |
|
---|
2400 | /* If we are dealing with the top-level menu and that this */
|
---|
2401 | /* is a click on an already "poppped" item */
|
---|
2402 | /* Stop the menu tracking and close the opened submenus */
|
---|
2403 | if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
|
---|
2404 | return 0;
|
---|
2405 | }
|
---|
2406 | ptmenu->bTimeToHide = TRUE;
|
---|
2407 | }
|
---|
2408 | return -1;
|
---|
2409 | }
|
---|
2410 |
|
---|
2411 |
|
---|
2412 | /***********************************************************************
|
---|
2413 | * MENU_MouseMove
|
---|
2414 | *
|
---|
2415 | * Return TRUE if we can go on with menu tracking.
|
---|
2416 | */
|
---|
2417 | static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
|
---|
2418 | {
|
---|
2419 | UINT id = NO_SELECTED_ITEM;
|
---|
2420 | POPUPMENU *ptmenu = NULL;
|
---|
2421 |
|
---|
2422 | if( hPtMenu )
|
---|
2423 | {
|
---|
2424 | ptmenu = MENU_GetMenu(hPtMenu);
|
---|
2425 | if( IS_SYSTEM_MENU(ptmenu) )
|
---|
2426 | id = 0;
|
---|
2427 | else
|
---|
2428 | MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
---|
2429 | }
|
---|
2430 |
|
---|
2431 | if( id == NO_SELECTED_ITEM )
|
---|
2432 | {
|
---|
2433 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
---|
2434 | NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
|
---|
2435 |
|
---|
2436 | }
|
---|
2437 | else if( ptmenu->FocusedItem != id )
|
---|
2438 | {
|
---|
2439 | POPUPMENU *menu;
|
---|
2440 | MENUITEM *item;
|
---|
2441 |
|
---|
2442 | MENU_SwitchTracking( pmt, hPtMenu, id );
|
---|
2443 |
|
---|
2444 |
|
---|
2445 | /*
|
---|
2446 | Test to see if we are trying to popup a submenu or not.
|
---|
2447 | If we aren't, don't change the current menu pointer
|
---|
2448 | and return.
|
---|
2449 | */
|
---|
2450 | if (!(menu = (POPUPMENU *)MENU_GetMenu( hPtMenu )))
|
---|
2451 | {
|
---|
2452 | pmt->hCurrentMenu = hPtMenu;
|
---|
2453 | return TRUE;
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | if (!IsWindow( menu->hWnd ) ||
|
---|
2457 | (menu->FocusedItem == NO_SELECTED_ITEM))
|
---|
2458 | {
|
---|
2459 | pmt->hCurrentMenu = hPtMenu;
|
---|
2460 | return TRUE;
|
---|
2461 | }
|
---|
2462 |
|
---|
2463 | item = &menu->items[menu->FocusedItem];
|
---|
2464 | if (!(item->fType & MF_POPUP) ||
|
---|
2465 | (item->fState & (MF_GRAYED | MF_DISABLED)))
|
---|
2466 | {
|
---|
2467 | pmt->hCurrentMenu = hPtMenu;
|
---|
2468 | return TRUE;
|
---|
2469 | }
|
---|
2470 |
|
---|
2471 | /* Check to see if we are trying to popup a toplevel menu or a
|
---|
2472 | submenu. Only the submenu has a delay.
|
---|
2473 | */
|
---|
2474 | if (uSubPWndLevel)
|
---|
2475 | {
|
---|
2476 | /*
|
---|
2477 | If we made it here, we want to pop up a submenu. Before we pop it up,
|
---|
2478 | we want a slight delay. This is implemented by remembering the ID of the menu
|
---|
2479 | where the mouse is currently positioned, and setting up a timer. When the
|
---|
2480 | timer fires (handled in MENU_TrackMenu() ), if the mouse is over the same
|
---|
2481 | submenu item, we popup it up. Otherwise, we do nothing.
|
---|
2482 | */
|
---|
2483 | KillTimer (pmt->hOwnerWnd, SUBMENU_POPUP_TIMERID); /* Just in case another timer was set up and not fired yet... */
|
---|
2484 | if ( (SetTimer (pmt->hOwnerWnd, SUBMENU_POPUP_TIMERID, POPUP_MENU_DELAY, NULL)) != SUBMENU_POPUP_TIMERID)
|
---|
2485 | {
|
---|
2486 | /*
|
---|
2487 | For some reason the timer wasn't set up properly... Revert to old
|
---|
2488 | functionality.
|
---|
2489 | */
|
---|
2490 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,hPtMenu,FALSE,wFlags,&pmt->pt);
|
---|
2491 | return TRUE;
|
---|
2492 | }
|
---|
2493 | } else
|
---|
2494 | {
|
---|
2495 | /* We are trying to popup a top level menu... so no delay */
|
---|
2496 |
|
---|
2497 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags,&pmt->pt);
|
---|
2498 | return TRUE;
|
---|
2499 | }
|
---|
2500 |
|
---|
2501 | mouseOverMenuID = id;
|
---|
2502 | isTimerSet = TRUE;
|
---|
2503 | }
|
---|
2504 | return TRUE;
|
---|
2505 | }
|
---|
2506 |
|
---|
2507 |
|
---|
2508 | /***********************************************************************
|
---|
2509 | * MENU_DoNextMenu
|
---|
2510 | *
|
---|
2511 | * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
|
---|
2512 | */
|
---|
2513 | static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
|
---|
2514 | {
|
---|
2515 | POPUPMENU *menu = MENU_GetMenu(pmt->hTopMenu);
|
---|
2516 |
|
---|
2517 | if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
|
---|
2518 | (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
|
---|
2519 | {
|
---|
2520 | MDINEXTMENU next_menu;
|
---|
2521 | HMENU hNewMenu;
|
---|
2522 | HWND hNewWnd;
|
---|
2523 | UINT id = 0;
|
---|
2524 |
|
---|
2525 | next_menu.hmenuIn = (IS_SYSTEM_MENU(menu)) ? GetSubMenu(pmt->hTopMenu,0) : pmt->hTopMenu;
|
---|
2526 | next_menu.hmenuNext = 0;
|
---|
2527 | next_menu.hwndNext = 0;
|
---|
2528 |
|
---|
2529 | SendMessageW( pmt->hOwnerWnd, WM_NEXTMENU, vk, (LPARAM)&next_menu );
|
---|
2530 |
|
---|
2531 | dprintf(("%04x [%04x] -> %04x [%04x]\n",
|
---|
2532 | pmt->hCurrentMenu, pmt->hOwnerWnd, next_menu.hmenuNext, next_menu.hwndNext ));
|
---|
2533 |
|
---|
2534 | if (!next_menu.hmenuNext || !next_menu.hwndNext)
|
---|
2535 | {
|
---|
2536 | hNewWnd = pmt->hOwnerWnd;
|
---|
2537 | if( IS_SYSTEM_MENU(menu) )
|
---|
2538 | {
|
---|
2539 | /* switch to the menu bar */
|
---|
2540 |
|
---|
2541 | if( (GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_CHILD) || !GetMenu(pmt->hOwnerWnd) )
|
---|
2542 | {
|
---|
2543 | return FALSE;
|
---|
2544 | }
|
---|
2545 |
|
---|
2546 | hNewMenu = GetMenu(pmt->hOwnerWnd);
|
---|
2547 | if( vk == VK_LEFT )
|
---|
2548 | {
|
---|
2549 | menu = MENU_GetMenu(hNewMenu);
|
---|
2550 | id = menu->nItems - 1;
|
---|
2551 | }
|
---|
2552 | }
|
---|
2553 | else if( GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_SYSMENU )
|
---|
2554 | {
|
---|
2555 | /* switch to the system menu */
|
---|
2556 | hNewMenu = getSysMenu(pmt->hOwnerWnd);
|
---|
2557 | }
|
---|
2558 | else
|
---|
2559 | {
|
---|
2560 | return FALSE;
|
---|
2561 | }
|
---|
2562 | }
|
---|
2563 | else /* application returned a new menu to switch to */
|
---|
2564 | {
|
---|
2565 | hNewMenu = next_menu.hmenuNext;
|
---|
2566 | hNewWnd = next_menu.hwndNext;
|
---|
2567 |
|
---|
2568 | if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
|
---|
2569 | {
|
---|
2570 | if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_SYSMENU) &&
|
---|
2571 | GetSubMenu(getSysMenu(hNewWnd), 0) == hNewMenu )
|
---|
2572 | {
|
---|
2573 | /* get the real system menu */
|
---|
2574 | hNewMenu = getSysMenu(hNewWnd);
|
---|
2575 | }
|
---|
2576 | else if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_CHILD) || (GetMenu(hNewWnd) != hNewMenu) )
|
---|
2577 | {
|
---|
2578 | /* FIXME: Not sure what to do here, perhaps,
|
---|
2579 | * try to track hNewMenu as a popup? */
|
---|
2580 |
|
---|
2581 | //TRACE(" -- got confused.\n");
|
---|
2582 | return FALSE;
|
---|
2583 | }
|
---|
2584 | }
|
---|
2585 | else return FALSE;
|
---|
2586 | }
|
---|
2587 |
|
---|
2588 | if( hNewMenu != pmt->hTopMenu )
|
---|
2589 | {
|
---|
2590 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
|
---|
2591 | FALSE, 0 );
|
---|
2592 | if( pmt->hCurrentMenu != pmt->hTopMenu )
|
---|
2593 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
---|
2594 | }
|
---|
2595 |
|
---|
2596 | if( hNewWnd != pmt->hOwnerWnd )
|
---|
2597 | {
|
---|
2598 | ReleaseCapture();
|
---|
2599 | pmt->hOwnerWnd = hNewWnd;
|
---|
2600 | SetCapture(pmt->hOwnerWnd); //SvL: Don't know if this is good enough
|
---|
2601 | //EVENT_Capture( pmt->hOwnerWnd, HTMENU ); //CB: todo
|
---|
2602 | }
|
---|
2603 |
|
---|
2604 | pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
|
---|
2605 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
|
---|
2606 |
|
---|
2607 | return TRUE;
|
---|
2608 | }
|
---|
2609 | return FALSE;
|
---|
2610 | }
|
---|
2611 |
|
---|
2612 | /***********************************************************************
|
---|
2613 | * MENU_SuspendPopup
|
---|
2614 | *
|
---|
2615 | * The idea is not to show the popup if the next input message is
|
---|
2616 | * going to hide it anyway.
|
---|
2617 | */
|
---|
2618 | static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT uMsg )
|
---|
2619 | {
|
---|
2620 | MSG msg;
|
---|
2621 |
|
---|
2622 | msg.hwnd = pmt->hOwnerWnd;
|
---|
2623 |
|
---|
2624 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
|
---|
2625 | pmt->trackFlags |= TF_SKIPREMOVE;
|
---|
2626 |
|
---|
2627 | switch( uMsg )
|
---|
2628 | {
|
---|
2629 | case WM_KEYDOWN:
|
---|
2630 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
|
---|
2631 | if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
|
---|
2632 | {
|
---|
2633 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
|
---|
2634 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
|
---|
2635 | if( msg.message == WM_KEYDOWN &&
|
---|
2636 | (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
|
---|
2637 | {
|
---|
2638 | pmt->trackFlags |= TF_SUSPENDPOPUP;
|
---|
2639 | return TRUE;
|
---|
2640 | }
|
---|
2641 | }
|
---|
2642 | break;
|
---|
2643 | }
|
---|
2644 |
|
---|
2645 | /* failures go through this */
|
---|
2646 | pmt->trackFlags &= ~TF_SUSPENDPOPUP;
|
---|
2647 | return FALSE;
|
---|
2648 | }
|
---|
2649 |
|
---|
2650 | /***********************************************************************
|
---|
2651 | * MENU_KeyLeft
|
---|
2652 | *
|
---|
2653 | * Handle a VK_LEFT key event in a menu.
|
---|
2654 | */
|
---|
2655 | static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
|
---|
2656 | {
|
---|
2657 | POPUPMENU *menu;
|
---|
2658 | HMENU hmenutmp, hmenuprev;
|
---|
2659 | UINT prevcol;
|
---|
2660 |
|
---|
2661 | hmenuprev = hmenutmp = pmt->hTopMenu;
|
---|
2662 | menu = MENU_GetMenu(hmenutmp);
|
---|
2663 |
|
---|
2664 | /* Try to move 1 column left (if possible) */
|
---|
2665 | if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
|
---|
2666 | NO_SELECTED_ITEM ) {
|
---|
2667 |
|
---|
2668 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
---|
2669 | prevcol, TRUE, 0 );
|
---|
2670 | return;
|
---|
2671 | }
|
---|
2672 |
|
---|
2673 | /* close topmost popup */
|
---|
2674 | while (hmenutmp != pmt->hCurrentMenu)
|
---|
2675 | {
|
---|
2676 | hmenuprev = hmenutmp;
|
---|
2677 | hmenutmp = MENU_GetSubPopup( hmenuprev );
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
|
---|
2681 | pmt->hCurrentMenu = hmenuprev;
|
---|
2682 |
|
---|
2683 | if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
|
---|
2684 | {
|
---|
2685 | /* move menu bar selection if no more popups are left */
|
---|
2686 |
|
---|
2687 | if( !MENU_DoNextMenu( pmt, VK_LEFT) )
|
---|
2688 | MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
|
---|
2689 |
|
---|
2690 | if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
|
---|
2691 | {
|
---|
2692 | /* A sublevel menu was displayed - display the next one
|
---|
2693 | * unless there is another displacement coming up */
|
---|
2694 |
|
---|
2695 | if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
|
---|
2696 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
|
---|
2697 | pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
|
---|
2698 | }
|
---|
2699 | }
|
---|
2700 | }
|
---|
2701 |
|
---|
2702 |
|
---|
2703 | /***********************************************************************
|
---|
2704 | * MENU_KeyRight
|
---|
2705 | *
|
---|
2706 | * Handle a VK_RIGHT key event in a menu.
|
---|
2707 | */
|
---|
2708 | static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
|
---|
2709 | {
|
---|
2710 | HMENU hmenutmp;
|
---|
2711 | POPUPMENU *menu = MENU_GetMenu(pmt->hTopMenu);
|
---|
2712 | UINT nextcol;
|
---|
2713 |
|
---|
2714 | //TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
|
---|
2715 | // pmt->hCurrentMenu,
|
---|
2716 | // ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
|
---|
2717 | // items[0].text,
|
---|
2718 | // pmt->hTopMenu, menu->items[0].text );
|
---|
2719 |
|
---|
2720 | if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
|
---|
2721 | {
|
---|
2722 | /* If already displaying a popup, try to display sub-popup */
|
---|
2723 |
|
---|
2724 | hmenutmp = pmt->hCurrentMenu;
|
---|
2725 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags,&pmt->pt);
|
---|
2726 |
|
---|
2727 | /* if subpopup was displayed then we are done */
|
---|
2728 | if (hmenutmp != pmt->hCurrentMenu) return;
|
---|
2729 | }
|
---|
2730 |
|
---|
2731 | /* Check to see if there's another column */
|
---|
2732 | if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
|
---|
2733 | NO_SELECTED_ITEM ) {
|
---|
2734 | //TRACE("Going to %d.\n", nextcol );
|
---|
2735 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
---|
2736 | nextcol, TRUE, 0 );
|
---|
2737 | return;
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
|
---|
2741 | {
|
---|
2742 | if( pmt->hCurrentMenu != pmt->hTopMenu )
|
---|
2743 | {
|
---|
2744 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
---|
2745 | hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
|
---|
2746 | } else hmenutmp = 0;
|
---|
2747 |
|
---|
2748 | /* try to move to the next item */
|
---|
2749 | if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
|
---|
2750 | MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
|
---|
2751 |
|
---|
2752 | if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
|
---|
2753 | if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
|
---|
2754 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
|
---|
2755 | pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
|
---|
2756 | }
|
---|
2757 | }
|
---|
2758 |
|
---|
2759 | VOID MENU_DispatchMouseMsg(MSG *msg)
|
---|
2760 | {
|
---|
2761 | LONG hittest;
|
---|
2762 |
|
---|
2763 | hittest = SendMessageA(msg->hwnd,WM_NCHITTEST,0,MAKELONG(msg->pt.x,msg->pt.y));
|
---|
2764 | if (hittest != HTCLIENT)
|
---|
2765 | SendMessageA(msg->hwnd,msg->message+WM_NCMOUSEMOVE-WM_MOUSEMOVE,hittest,MAKELONG(msg->pt.x,msg->pt.y));
|
---|
2766 | else
|
---|
2767 | DispatchMessageA(msg);
|
---|
2768 | }
|
---|
2769 |
|
---|
2770 | /***********************************************************************
|
---|
2771 | * MENU_TrackMenu
|
---|
2772 | *
|
---|
2773 | * Menu tracking code.
|
---|
2774 | */
|
---|
2775 | static INT MENU_TrackMenu(HMENU hmenu,UINT wFlags,INT x,INT y,HWND hwnd,BOOL inMenuBar,const RECT *lprect)
|
---|
2776 | {
|
---|
2777 | MSG msg;
|
---|
2778 | POPUPMENU *menu;
|
---|
2779 | BOOL fRemove;
|
---|
2780 | INT executedMenuId = -1;
|
---|
2781 | MTRACKER mt;
|
---|
2782 | BOOL enterIdleSent = FALSE;
|
---|
2783 | BOOL bSysMenu;
|
---|
2784 |
|
---|
2785 | mt.trackFlags = 0;
|
---|
2786 | mt.hCurrentMenu = hmenu;
|
---|
2787 | mt.hTopMenu = hmenu;
|
---|
2788 | mt.hOwnerWnd = hwnd;
|
---|
2789 | mt.pt.x = x;
|
---|
2790 | mt.pt.y = y;
|
---|
2791 |
|
---|
2792 | //TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
|
---|
2793 | // hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
|
---|
2794 | // (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
|
---|
2795 |
|
---|
2796 | fEndMenu = FALSE;
|
---|
2797 | if (!(menu = MENU_GetMenu(hmenu))) return FALSE;
|
---|
2798 |
|
---|
2799 | bSysMenu = IS_SYSTEM_MENU(menu);
|
---|
2800 |
|
---|
2801 | if (wFlags & TPM_BUTTONDOWN)
|
---|
2802 | {
|
---|
2803 | /* Get the result in order to start the tracking or not */
|
---|
2804 | fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
|
---|
2805 | fEndMenu = !fRemove;
|
---|
2806 | }
|
---|
2807 |
|
---|
2808 | #ifdef __WIN32OS2__
|
---|
2809 | //SvL: Set keyboard & mouse event capture
|
---|
2810 | SetCapture(mt.hOwnerWnd);
|
---|
2811 | //SetCapture breaks system menu (double click), must generate double
|
---|
2812 | //clicks manually
|
---|
2813 | SetMenuDoubleClick(TRUE);
|
---|
2814 | #else
|
---|
2815 | EVENT_Capture( mt.hOwnerWnd, HTMENU );
|
---|
2816 | #endif
|
---|
2817 |
|
---|
2818 | while (!fEndMenu)
|
---|
2819 | {
|
---|
2820 | menu = MENU_GetMenu(mt.hCurrentMenu);
|
---|
2821 | msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
|
---|
2822 |
|
---|
2823 | /* we have to keep the message in the queue until it's
|
---|
2824 | * clear that menu loop is not over yet. */
|
---|
2825 | #ifdef __WIN32OS2__
|
---|
2826 | //SvL: Getting messages for only the menu delays background paints (i.e. VPBuddy logo)
|
---|
2827 | if (!GetMessageA(&msg,0,0,0)) break;
|
---|
2828 | #else
|
---|
2829 | if (!GetMessageA(&msg,msg.hwnd,0,0)) break;
|
---|
2830 | #endif
|
---|
2831 | TranslateMessage( &msg );
|
---|
2832 | mt.pt = msg.pt;
|
---|
2833 |
|
---|
2834 | if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
|
---|
2835 | enterIdleSent=FALSE;
|
---|
2836 |
|
---|
2837 | fRemove = FALSE;
|
---|
2838 | if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
|
---|
2839 | {
|
---|
2840 | /* Find a menu for this mouse event */
|
---|
2841 | POINT pt = msg.pt;
|
---|
2842 |
|
---|
2843 | hmenu = MENU_PtMenu(mt.hTopMenu,pt,inMenuBar);
|
---|
2844 |
|
---|
2845 | //CB: todo: solve conflicts with OS/2's single message queue architecture
|
---|
2846 |
|
---|
2847 | switch(msg.message)
|
---|
2848 | {
|
---|
2849 | /* no WM_NC... messages in captured state */
|
---|
2850 |
|
---|
2851 | case WM_RBUTTONDBLCLK:
|
---|
2852 | case WM_RBUTTONDOWN:
|
---|
2853 | if (!(wFlags & TPM_RIGHTBUTTON)) break;
|
---|
2854 | goto buttondown;
|
---|
2855 | case WM_LBUTTONDBLCLK:
|
---|
2856 | if (bSysMenu && (hmenu == mt.hTopMenu))
|
---|
2857 | {
|
---|
2858 | #ifdef __WIN32OS2__
|
---|
2859 | //double click on system menu -> close application
|
---|
2860 | PostMessageA(hwnd, WM_SYSCOMMAND,SC_CLOSE, msg.lParam);
|
---|
2861 | #endif
|
---|
2862 | fEndMenu = TRUE;
|
---|
2863 | break;
|
---|
2864 | }
|
---|
2865 | /* fall through */
|
---|
2866 | case WM_LBUTTONDOWN:
|
---|
2867 | /* If the message belongs to the menu, removes it from the queue */
|
---|
2868 | /* Else, end menu tracking */
|
---|
2869 |
|
---|
2870 | buttondown:
|
---|
2871 | /* Forcing mouse popup NOW - Ensure timer doesn't popup menu also */
|
---|
2872 | mouseOverMenuID = -1;
|
---|
2873 | fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
|
---|
2874 | fEndMenu = !fRemove;
|
---|
2875 | break;
|
---|
2876 |
|
---|
2877 | case WM_RBUTTONUP:
|
---|
2878 | if (!(wFlags & TPM_RIGHTBUTTON)) break;
|
---|
2879 | /* fall through */
|
---|
2880 | case WM_LBUTTONUP:
|
---|
2881 | /* Check if a menu was selected by the mouse */
|
---|
2882 | if (hmenu)
|
---|
2883 | {
|
---|
2884 | /* Forcing mouse popup NOW - Ensure timer doesn't popup menu also */
|
---|
2885 | mouseOverMenuID = -1;
|
---|
2886 | executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
|
---|
2887 |
|
---|
2888 | /* End the loop if executedMenuId is an item ID */
|
---|
2889 | /* or if the job was done (executedMenuId = 0). */
|
---|
2890 | fEndMenu = fRemove = (executedMenuId != -1);
|
---|
2891 | }
|
---|
2892 | /* No menu was selected by the mouse */
|
---|
2893 | /* if the function was called by TrackPopupMenu, continue
|
---|
2894 | with the menu tracking. If not, stop it */
|
---|
2895 | else
|
---|
2896 | fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
|
---|
2897 |
|
---|
2898 | break;
|
---|
2899 |
|
---|
2900 | case WM_MOUSEMOVE:
|
---|
2901 | /* In win95 winelook, the selected menu item must be changed every time the
|
---|
2902 | mouse moves. In Win31 winelook, the mouse button has to be held down */
|
---|
2903 | #ifdef __WIN32OS2__
|
---|
2904 | if ( !fOS2Look ||
|
---|
2905 | ( (msg.wParam & MK_LBUTTON) ||
|
---|
2906 | ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
|
---|
2907 | fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
|
---|
2908 | #else
|
---|
2909 | if ( (TWEAK_WineLook > WIN31_LOOK) ||
|
---|
2910 | ( (msg.wParam & MK_LBUTTON) ||
|
---|
2911 | ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
|
---|
2912 | fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
|
---|
2913 | #endif
|
---|
2914 |
|
---|
2915 | } /* switch(msg.message) - mouse */
|
---|
2916 | }
|
---|
2917 | else if (msg.message == WM_TIMER)
|
---|
2918 | {
|
---|
2919 | UINT id = -1;
|
---|
2920 | POPUPMENU *ptmenu = NULL;
|
---|
2921 |
|
---|
2922 | if (isTimerSet)
|
---|
2923 | {
|
---|
2924 | /*
|
---|
2925 | If we get here, an attempt was made to pop up a submenu.
|
---|
2926 | (See MENU_MouseMove() )
|
---|
2927 | */
|
---|
2928 |
|
---|
2929 | /* Get the ID of the menu item the mouse is over now. */
|
---|
2930 | if( hmenu )
|
---|
2931 | {
|
---|
2932 | ptmenu = (POPUPMENU *)MENU_GetMenu( hmenu );
|
---|
2933 | if( IS_SYSTEM_MENU(ptmenu) )
|
---|
2934 | id = 0;
|
---|
2935 | else
|
---|
2936 | MENU_FindItemByCoords( ptmenu, mt.pt, &id );
|
---|
2937 |
|
---|
2938 | /* If it is over the same item that set up the timer originally .... */
|
---|
2939 | if (mouseOverMenuID != -1 && mouseOverMenuID == id)
|
---|
2940 | {
|
---|
2941 | /* .... Pop up the menu */
|
---|
2942 | mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, hmenu, FALSE, wFlags,&mt.pt);
|
---|
2943 | }
|
---|
2944 | }
|
---|
2945 |
|
---|
2946 | /* Reset the timer so it doesn't fire again. (So we are ready for the next
|
---|
2947 | attempt to popup a submenu... ) */
|
---|
2948 | KillTimer(mt.hOwnerWnd,SUBMENU_POPUP_TIMERID);
|
---|
2949 | isTimerSet = FALSE;
|
---|
2950 | }
|
---|
2951 | }
|
---|
2952 | else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
|
---|
2953 | {
|
---|
2954 | fRemove = TRUE; /* Keyboard messages are always removed */
|
---|
2955 | switch(msg.message)
|
---|
2956 | {
|
---|
2957 | case WM_KEYDOWN:
|
---|
2958 | switch(msg.wParam)
|
---|
2959 | {
|
---|
2960 | case VK_HOME:
|
---|
2961 | case VK_END:
|
---|
2962 | MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
|
---|
2963 | NO_SELECTED_ITEM, FALSE, 0 );
|
---|
2964 | /* fall through */
|
---|
2965 | case VK_UP:
|
---|
2966 | MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
|
---|
2967 | (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
|
---|
2968 | break;
|
---|
2969 |
|
---|
2970 | case VK_DOWN: /* If on menu bar, pull-down the menu */
|
---|
2971 |
|
---|
2972 | menu = MENU_GetMenu(mt.hCurrentMenu);
|
---|
2973 | if (!(menu->wFlags & MF_POPUP))
|
---|
2974 | mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags,&mt.pt);
|
---|
2975 | else /* otherwise try to move selection */
|
---|
2976 | MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
|
---|
2977 | break;
|
---|
2978 |
|
---|
2979 | case VK_LEFT:
|
---|
2980 | MENU_KeyLeft( &mt, wFlags );
|
---|
2981 | break;
|
---|
2982 |
|
---|
2983 | case VK_RIGHT:
|
---|
2984 | MENU_KeyRight( &mt, wFlags );
|
---|
2985 | break;
|
---|
2986 |
|
---|
2987 | case VK_ESCAPE:
|
---|
2988 | fEndMenu = TRUE;
|
---|
2989 | break;
|
---|
2990 |
|
---|
2991 | case VK_F1:
|
---|
2992 | {
|
---|
2993 | HELPINFO hi;
|
---|
2994 | hi.cbSize = sizeof(HELPINFO);
|
---|
2995 | hi.iContextType = HELPINFO_MENUITEM;
|
---|
2996 | if (menu->FocusedItem == NO_SELECTED_ITEM)
|
---|
2997 | hi.iCtrlId = 0;
|
---|
2998 | else
|
---|
2999 | hi.iCtrlId = menu->items[menu->FocusedItem].wID;
|
---|
3000 | hi.hItemHandle = hmenu;
|
---|
3001 | hi.dwContextId = menu->dwContextHelpID;
|
---|
3002 | hi.MousePos = msg.pt;
|
---|
3003 | //TRACE_(winhelp)("Sending HELPINFO_MENUITEM to 0x%08x\n", hwnd);
|
---|
3004 | SendMessageA(hwnd, WM_HELP, 0, (LPARAM)&hi);
|
---|
3005 | break;
|
---|
3006 | }
|
---|
3007 |
|
---|
3008 | default:
|
---|
3009 | break;
|
---|
3010 | }
|
---|
3011 | break; /* WM_KEYDOWN */
|
---|
3012 |
|
---|
3013 | case WM_SYSKEYDOWN:
|
---|
3014 | switch(msg.wParam)
|
---|
3015 | {
|
---|
3016 | case VK_MENU:
|
---|
3017 | fEndMenu = TRUE;
|
---|
3018 | break;
|
---|
3019 |
|
---|
3020 | }
|
---|
3021 | break; /* WM_SYSKEYDOWN */
|
---|
3022 |
|
---|
3023 | case WM_CHAR:
|
---|
3024 | {
|
---|
3025 | UINT pos;
|
---|
3026 |
|
---|
3027 | if (msg.wParam == '\r' || msg.wParam == ' ')
|
---|
3028 | {
|
---|
3029 | executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
|
---|
3030 | fEndMenu = (executedMenuId != -1);
|
---|
3031 |
|
---|
3032 | break;
|
---|
3033 | }
|
---|
3034 |
|
---|
3035 | /* Hack to avoid control chars. */
|
---|
3036 | /* We will find a better way real soon... */
|
---|
3037 | if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
|
---|
3038 |
|
---|
3039 | pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
|
---|
3040 | LOWORD(msg.wParam), FALSE );
|
---|
3041 | if (pos == (UINT)-2) fEndMenu = TRUE;
|
---|
3042 | else if (pos == (UINT)-1) MessageBeep(0);
|
---|
3043 | else
|
---|
3044 | {
|
---|
3045 | MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
|
---|
3046 | TRUE, 0 );
|
---|
3047 | executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
|
---|
3048 | fEndMenu = (executedMenuId != -1);
|
---|
3049 | }
|
---|
3050 | }
|
---|
3051 | break;
|
---|
3052 | } /* switch(msg.message) - kbd */
|
---|
3053 | }
|
---|
3054 | else if (msg.message == WM_SYSCOMMAND)
|
---|
3055 | {
|
---|
3056 | /* The user clicked on the system menu/button */
|
---|
3057 | fEndMenu = TRUE;
|
---|
3058 | break;
|
---|
3059 | }
|
---|
3060 | else
|
---|
3061 | {
|
---|
3062 | DispatchMessageA( &msg );
|
---|
3063 | }
|
---|
3064 |
|
---|
3065 | if (!fEndMenu) fRemove = TRUE;
|
---|
3066 |
|
---|
3067 | /* finally remove message from the queue */
|
---|
3068 |
|
---|
3069 | if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
|
---|
3070 | PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
|
---|
3071 | else mt.trackFlags &= ~TF_SKIPREMOVE;
|
---|
3072 | }
|
---|
3073 | #ifdef __WIN32OS2__
|
---|
3074 | SetMenuDoubleClick(FALSE);
|
---|
3075 | ReleaseCapture();
|
---|
3076 | #endif
|
---|
3077 |
|
---|
3078 | menu = MENU_GetMenu(mt.hTopMenu);
|
---|
3079 |
|
---|
3080 | if( IsWindow( mt.hOwnerWnd ) )
|
---|
3081 | {
|
---|
3082 | MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
|
---|
3083 |
|
---|
3084 | MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
|
---|
3085 | #ifdef __WIN32OS2__
|
---|
3086 | if (menu && menu->wFlags & MF_POPUP)
|
---|
3087 | {
|
---|
3088 | DestroyWindow( menu->hWnd );
|
---|
3089 | menu->hWnd = 0;
|
---|
3090 | // ShowWindow( menu->hWnd, SW_HIDE );
|
---|
3091 | uSubPWndLevel = 0;
|
---|
3092 | }
|
---|
3093 | #endif
|
---|
3094 | SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
|
---|
3095 | }
|
---|
3096 |
|
---|
3097 | /* Reset the variable for hiding menu */
|
---|
3098 | menu->bTimeToHide = FALSE;
|
---|
3099 |
|
---|
3100 | /* The return value is only used by TrackPopupMenu */
|
---|
3101 | return ((executedMenuId != -1) ? executedMenuId : 0);
|
---|
3102 | }
|
---|
3103 |
|
---|
3104 | /***********************************************************************
|
---|
3105 | * MENU_InitTracking
|
---|
3106 | */
|
---|
3107 | static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
|
---|
3108 | {
|
---|
3109 | //TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
|
---|
3110 |
|
---|
3111 | HideCaret(0);
|
---|
3112 |
|
---|
3113 | /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
|
---|
3114 | if (!(wFlags & TPM_NONOTIFY))
|
---|
3115 | SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
|
---|
3116 |
|
---|
3117 | SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
|
---|
3118 |
|
---|
3119 | if (!(wFlags & TPM_NONOTIFY))
|
---|
3120 | SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
|
---|
3121 |
|
---|
3122 | return TRUE;
|
---|
3123 | }
|
---|
3124 | /***********************************************************************
|
---|
3125 | * MENU_ExitTracking
|
---|
3126 | */
|
---|
3127 | static BOOL MENU_ExitTracking(HWND hWnd)
|
---|
3128 | {
|
---|
3129 | //TRACE("hwnd=0x%04x\n", hWnd);
|
---|
3130 |
|
---|
3131 | SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
|
---|
3132 | ShowCaret(0);
|
---|
3133 | return TRUE;
|
---|
3134 | }
|
---|
3135 |
|
---|
3136 | /***********************************************************************
|
---|
3137 | * MENU_TrackMouseMenuBar
|
---|
3138 | *
|
---|
3139 | * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
|
---|
3140 | */
|
---|
3141 | void MENU_TrackMouseMenuBar( HWND hWnd, INT ht, POINT pt )
|
---|
3142 | {
|
---|
3143 | HMENU hMenu = (ht == 0) ? GetMenu(hWnd):getSysMenu(hWnd);
|
---|
3144 | UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
|
---|
3145 |
|
---|
3146 | //TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
|
---|
3147 |
|
---|
3148 | if (IsMenu(hMenu))
|
---|
3149 | {
|
---|
3150 | if (ht == HTCAPTION) wFlags |= TPM_CAPTIONSYSMENU | TPM_RIGHTBUTTON;
|
---|
3151 | if (IsIconic(hWnd)) wFlags |= TPM_BOTTOMALIGN; //CB: todo: for minimized windows
|
---|
3152 |
|
---|
3153 | MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
|
---|
3154 | MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd,ht == 0, NULL );
|
---|
3155 | MENU_ExitTracking(hWnd);
|
---|
3156 | }
|
---|
3157 | }
|
---|
3158 |
|
---|
3159 | MENUITEM *MENU_HighlightedItem=NULL;
|
---|
3160 | UINT MENU_HighlightedItemID=NO_SELECTED_ITEM;
|
---|
3161 | POPUPMENU *MENU_HighlightedMenu=NULL;
|
---|
3162 |
|
---|
3163 | void MENU_TrackMouseMenuBar_MouseMove(HWND hwnd,POINT pt,BOOL OnMenu)
|
---|
3164 | {
|
---|
3165 | HMENU hMenu = GetMenu(hwnd);
|
---|
3166 | MENUITEM *item = NULL;
|
---|
3167 | RECT rect;
|
---|
3168 | HDC hdc;
|
---|
3169 | BOOL UnHighlight = (OnMenu==TRUE)?FALSE:TRUE;
|
---|
3170 | POPUPMENU *ptmenu = NULL;
|
---|
3171 | UINT id = NO_SELECTED_ITEM;
|
---|
3172 |
|
---|
3173 | if (OnMenu == TRUE && IsMenu(hMenu)) {
|
---|
3174 |
|
---|
3175 | ptmenu=(POPUPMENU *)MENU_GetMenu( hMenu );
|
---|
3176 |
|
---|
3177 | item=MENU_FindItemByCoords( ptmenu, pt, &id );
|
---|
3178 |
|
---|
3179 | if(!item) {
|
---|
3180 | /* No item selected, perhaps we are on the blank spot? */
|
---|
3181 | UnHighlight = TRUE;
|
---|
3182 | /* Paranoid setting */
|
---|
3183 | item=NULL;
|
---|
3184 | } else if(id == MENU_HighlightedItemID) {
|
---|
3185 | /* If it's already highlighted, don't do it again */
|
---|
3186 | return;
|
---|
3187 | } else if(item->fState & MF_MOUSESELECT) {
|
---|
3188 | /* If it's dropped, we let the DrawMenuItem draw the sunken border */
|
---|
3189 | return;
|
---|
3190 | } else if(item->fType & MF_BITMAP) {
|
---|
3191 | UnHighlight = TRUE;
|
---|
3192 | /* (Required) Paranoid setting */
|
---|
3193 | item=NULL;
|
---|
3194 | } else {
|
---|
3195 | hdc = GetDCEx( ptmenu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
---|
3196 | rect = item->rect;
|
---|
3197 | DrawEdge(hdc, &rect, BDR_RAISEDINNER, BF_RECT);
|
---|
3198 | ReleaseDC( ptmenu->hWnd, hdc );
|
---|
3199 |
|
---|
3200 | UnHighlight = TRUE;
|
---|
3201 | }
|
---|
3202 | }
|
---|
3203 |
|
---|
3204 | if(UnHighlight == TRUE) {
|
---|
3205 | if(MENU_HighlightedItem) {
|
---|
3206 | if(!(MENU_HighlightedItem->fState & MF_MOUSESELECT)) {
|
---|
3207 | hdc = GetDCEx( MENU_HighlightedMenu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
---|
3208 | rect = MENU_HighlightedItem->rect;
|
---|
3209 |
|
---|
3210 | FrameRect(hdc, &rect, GetSysColorBrush(COLOR_MENU));
|
---|
3211 | ReleaseDC( MENU_HighlightedMenu->hWnd, hdc );
|
---|
3212 | }
|
---|
3213 | }
|
---|
3214 |
|
---|
3215 | /* Sets to NULL, NO_SELECTED_ITEM, NULL, unless it found a new
|
---|
3216 | item, then it will be filled in with the proper values */
|
---|
3217 | MENU_HighlightedItem = item;
|
---|
3218 | MENU_HighlightedItemID = id;
|
---|
3219 | MENU_HighlightedMenu= ptmenu;
|
---|
3220 | }
|
---|
3221 | }
|
---|
3222 |
|
---|
3223 | /***********************************************************************
|
---|
3224 | * MENU_TrackKbdMenuBar
|
---|
3225 | *
|
---|
3226 | * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
|
---|
3227 | */
|
---|
3228 | void MENU_TrackKbdMenuBar( HWND hWnd, UINT wParam, INT vkey)
|
---|
3229 | {
|
---|
3230 | UINT uItem = NO_SELECTED_ITEM;
|
---|
3231 | HMENU hTrackMenu;
|
---|
3232 | UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
|
---|
3233 |
|
---|
3234 | /* find window that has a menu */
|
---|
3235 |
|
---|
3236 | while(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD)
|
---|
3237 | if( !(hWnd = GetParent(hWnd)) ) return;
|
---|
3238 |
|
---|
3239 | /* check if we have to track a system menu */
|
---|
3240 |
|
---|
3241 | if( (GetWindowLongA(hWnd,GWL_STYLE) & (WS_CHILD | WS_MINIMIZE)) ||
|
---|
3242 | !GetMenu(hWnd) || vkey == VK_SPACE )
|
---|
3243 | {
|
---|
3244 | if( !(GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) ) return;
|
---|
3245 | hTrackMenu = getSysMenu(hWnd);
|
---|
3246 | uItem = 0;
|
---|
3247 | wParam |= HTSYSMENU; /* prevent item lookup */
|
---|
3248 | }
|
---|
3249 | else
|
---|
3250 | hTrackMenu = GetMenu(hWnd);
|
---|
3251 |
|
---|
3252 | if (IsMenu( hTrackMenu ))
|
---|
3253 | {
|
---|
3254 | MENU_InitTracking( hWnd, hTrackMenu, FALSE, wFlags );
|
---|
3255 |
|
---|
3256 | if( vkey && vkey != VK_SPACE )
|
---|
3257 | {
|
---|
3258 | uItem = MENU_FindItemByKey( hWnd, hTrackMenu,
|
---|
3259 | vkey, (wParam & HTSYSMENU) );
|
---|
3260 | if( uItem >= (UINT)(-2) )
|
---|
3261 | {
|
---|
3262 | if( uItem == (UINT)(-1) ) MessageBeep(0);
|
---|
3263 | hTrackMenu = 0;
|
---|
3264 | }
|
---|
3265 | }
|
---|
3266 |
|
---|
3267 | if( hTrackMenu )
|
---|
3268 | {
|
---|
3269 | MENU_SelectItem( hWnd, hTrackMenu, uItem, TRUE, 0 );
|
---|
3270 |
|
---|
3271 | if( uItem == NO_SELECTED_ITEM )
|
---|
3272 | MENU_MoveSelection( hWnd, hTrackMenu, ITEM_NEXT );
|
---|
3273 | else if( vkey )
|
---|
3274 | PostMessageA( hWnd, WM_KEYDOWN, VK_DOWN, 0L );
|
---|
3275 |
|
---|
3276 | MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, hWnd,TRUE, NULL );
|
---|
3277 | }
|
---|
3278 |
|
---|
3279 | MENU_ExitTracking (hWnd);
|
---|
3280 | }
|
---|
3281 | }
|
---|
3282 |
|
---|
3283 |
|
---|
3284 | /**********************************************************************
|
---|
3285 | * TrackPopupMenu (USER32.549)
|
---|
3286 | *
|
---|
3287 | * Like the win32 API, the function return the command ID only if the
|
---|
3288 | * flag TPM_RETURNCMD is on.
|
---|
3289 | *
|
---|
3290 | */
|
---|
3291 | BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
|
---|
3292 | INT nReserved, HWND hWnd, const RECT *lpRect )
|
---|
3293 | {
|
---|
3294 | BOOL ret = FALSE;
|
---|
3295 |
|
---|
3296 | if(lpRect) {
|
---|
3297 | dprintf(("USER32: TrackPopupMenu %x %x (%d,%d) %x %x (%d,%d)(%d,%d)", hMenu, wFlags, x, y, nReserved, hWnd, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom));
|
---|
3298 | }
|
---|
3299 | else dprintf(("USER32: TrackPopupMenu %x %x (%d,%d) %x %x lpRect=NULL", hMenu, wFlags, x, y, nReserved, hWnd));
|
---|
3300 |
|
---|
3301 | MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
|
---|
3302 |
|
---|
3303 | /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
|
---|
3304 | if (!(wFlags & TPM_NONOTIFY))
|
---|
3305 | SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
|
---|
3306 |
|
---|
3307 | if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
|
---|
3308 | ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd,FALSE, lpRect );
|
---|
3309 | MENU_ExitTracking(hWnd);
|
---|
3310 |
|
---|
3311 | if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
|
---|
3312 | ret = 1;
|
---|
3313 |
|
---|
3314 | return ret;
|
---|
3315 | }
|
---|
3316 |
|
---|
3317 | /**********************************************************************
|
---|
3318 | * TrackPopupMenuEx (USER32.550)
|
---|
3319 | */
|
---|
3320 | BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
|
---|
3321 | HWND hWnd, LPTPMPARAMS lpTpm )
|
---|
3322 | {
|
---|
3323 | dprintf(("USER32: TrackPopupMenuEx"));
|
---|
3324 | //FIXME("not fully implemented\n" );
|
---|
3325 | return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
|
---|
3326 | lpTpm ? &lpTpm->rcExclude : NULL );
|
---|
3327 | }
|
---|
3328 |
|
---|
3329 | /***********************************************************************
|
---|
3330 | * PopupMenuWndProc
|
---|
3331 | *
|
---|
3332 | * NOTE: Windows has totally different (and undocumented) popup wndproc.
|
---|
3333 | */
|
---|
3334 | LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
|
---|
3335 | LPARAM lParam )
|
---|
3336 | {
|
---|
3337 | LRESULT retvalue;
|
---|
3338 |
|
---|
3339 | //TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
|
---|
3340 | //hwnd, message, wParam, lParam);
|
---|
3341 |
|
---|
3342 | switch(message)
|
---|
3343 | {
|
---|
3344 | case WM_CREATE:
|
---|
3345 | {
|
---|
3346 | CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
|
---|
3347 | SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
|
---|
3348 | retvalue = 0;
|
---|
3349 | goto END;
|
---|
3350 | }
|
---|
3351 |
|
---|
3352 | case WM_MOUSEACTIVATE: /* We don't want to be activated */
|
---|
3353 | retvalue = MA_NOACTIVATE;
|
---|
3354 | goto END;
|
---|
3355 |
|
---|
3356 | case WM_PAINT:
|
---|
3357 | {
|
---|
3358 | PAINTSTRUCT ps;
|
---|
3359 | BeginPaint( hwnd, &ps );
|
---|
3360 | MENU_DrawPopupMenu( hwnd, ps.hdc,
|
---|
3361 | (HMENU)GetWindowLongA( hwnd, 0 ) );
|
---|
3362 | EndPaint( hwnd, &ps );
|
---|
3363 | retvalue = 0;
|
---|
3364 | goto END;
|
---|
3365 | }
|
---|
3366 | case WM_ERASEBKGND:
|
---|
3367 | retvalue = 1;
|
---|
3368 | goto END;
|
---|
3369 |
|
---|
3370 | case WM_DESTROY:
|
---|
3371 |
|
---|
3372 | /* zero out global pointer in case resident popup window
|
---|
3373 | * was somehow destroyed. */
|
---|
3374 |
|
---|
3375 | if(MENU_GetTopPopupWnd() )
|
---|
3376 | {
|
---|
3377 | if( hwnd == pTopPopupWnd )
|
---|
3378 | {
|
---|
3379 | //ERR("resident popup destroyed!\n");
|
---|
3380 |
|
---|
3381 | MENU_DestroyTopPopupWnd();
|
---|
3382 | uSubPWndLevel = 0;
|
---|
3383 | }
|
---|
3384 | else
|
---|
3385 | uSubPWndLevel--;
|
---|
3386 | MENU_ReleaseTopPopupWnd();
|
---|
3387 | }
|
---|
3388 | break;
|
---|
3389 |
|
---|
3390 | case WM_SHOWWINDOW:
|
---|
3391 |
|
---|
3392 | if( wParam )
|
---|
3393 | {
|
---|
3394 | //if( !(*(HMENU*)wndPtr->wExtra) )
|
---|
3395 | // ERR("no menu to display\n");
|
---|
3396 | }
|
---|
3397 | else
|
---|
3398 | SetWindowLongA(hwnd,0,0);
|
---|
3399 | break;
|
---|
3400 |
|
---|
3401 | case MM_SETMENUHANDLE:
|
---|
3402 |
|
---|
3403 | SetWindowLongA(hwnd,0,wParam);
|
---|
3404 | break;
|
---|
3405 |
|
---|
3406 | case MM_GETMENUHANDLE:
|
---|
3407 |
|
---|
3408 | retvalue = GetWindowLongA(hwnd,0);
|
---|
3409 | goto END;
|
---|
3410 |
|
---|
3411 | default:
|
---|
3412 | retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
|
---|
3413 | goto END;
|
---|
3414 | }
|
---|
3415 | retvalue = 0;
|
---|
3416 | END:
|
---|
3417 | return retvalue;
|
---|
3418 | }
|
---|
3419 |
|
---|
3420 |
|
---|
3421 | /***********************************************************************
|
---|
3422 | * MENU_GetMenuBarHeight
|
---|
3423 | *
|
---|
3424 | * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
|
---|
3425 | */
|
---|
3426 | UINT MENU_GetMenuBarHeight(HWND hwnd,UINT menubarWidth,INT orgX,INT orgY)
|
---|
3427 | {
|
---|
3428 | HDC hdc;
|
---|
3429 | RECT rectBar;
|
---|
3430 | LPPOPUPMENU lppop;
|
---|
3431 | UINT retvalue;
|
---|
3432 |
|
---|
3433 | //TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
|
---|
3434 | // hwnd, menubarWidth, orgX, orgY );
|
---|
3435 |
|
---|
3436 | if (!(lppop = MENU_GetMenu(GetMenu(hwnd))))
|
---|
3437 | {
|
---|
3438 | return 0;
|
---|
3439 | }
|
---|
3440 |
|
---|
3441 | hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
|
---|
3442 | SelectObject( hdc, hMenuFont);
|
---|
3443 | SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
|
---|
3444 | MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
|
---|
3445 | ReleaseDC( hwnd, hdc );
|
---|
3446 | retvalue = lppop->Height;
|
---|
3447 | return retvalue;
|
---|
3448 | }
|
---|
3449 |
|
---|
3450 |
|
---|
3451 | /*******************************************************************
|
---|
3452 | * ChangeMenu32A (USER32.23)
|
---|
3453 | */
|
---|
3454 | BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
|
---|
3455 | UINT id, UINT flags )
|
---|
3456 | {
|
---|
3457 | dprintf(("USER32: ChangeMenuA"));
|
---|
3458 |
|
---|
3459 | //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
|
---|
3460 | // hMenu, pos, (DWORD)data, id, flags );
|
---|
3461 | if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
|
---|
3462 | id, data );
|
---|
3463 | if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
|
---|
3464 | if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
|
---|
3465 | id, data );
|
---|
3466 | if (flags & MF_REMOVE) return RemoveMenu( hMenu,
|
---|
3467 | flags & MF_BYPOSITION ? pos : id,
|
---|
3468 | flags & ~MF_REMOVE );
|
---|
3469 | /* Default: MF_INSERT */
|
---|
3470 | return InsertMenuA( hMenu, pos, flags, id, data );
|
---|
3471 | }
|
---|
3472 |
|
---|
3473 |
|
---|
3474 | /*******************************************************************
|
---|
3475 | * ChangeMenu32W (USER32.24)
|
---|
3476 | */
|
---|
3477 | BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
|
---|
3478 | UINT id, UINT flags )
|
---|
3479 | {
|
---|
3480 | dprintf(("USER32: ChangeMenuW"));
|
---|
3481 |
|
---|
3482 | //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
|
---|
3483 | // hMenu, pos, (DWORD)data, id, flags );
|
---|
3484 | if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
|
---|
3485 | id, data );
|
---|
3486 | if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
|
---|
3487 | if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
|
---|
3488 | id, data );
|
---|
3489 | if (flags & MF_REMOVE) return RemoveMenu( hMenu,
|
---|
3490 | flags & MF_BYPOSITION ? pos : id,
|
---|
3491 | flags & ~MF_REMOVE );
|
---|
3492 | /* Default: MF_INSERT */
|
---|
3493 | return InsertMenuW( hMenu, pos, flags, id, data );
|
---|
3494 | }
|
---|
3495 |
|
---|
3496 |
|
---|
3497 | /*******************************************************************
|
---|
3498 | * CheckMenuItem (USER32.46)
|
---|
3499 | */
|
---|
3500 | DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
|
---|
3501 | {
|
---|
3502 | MENUITEM *item;
|
---|
3503 | DWORD ret;
|
---|
3504 |
|
---|
3505 | dprintf(("USER32: CheckMenuItem %x %x %x", hMenu, id, flags));
|
---|
3506 |
|
---|
3507 | //TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
|
---|
3508 | if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
|
---|
3509 | ret = item->fState & MF_CHECKED;
|
---|
3510 | if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
|
---|
3511 | else item->fState &= ~MF_CHECKED;
|
---|
3512 | return ret;
|
---|
3513 | }
|
---|
3514 |
|
---|
3515 |
|
---|
3516 | /**********************************************************************
|
---|
3517 | * EnableMenuItem32 (USER32.170)
|
---|
3518 | */
|
---|
3519 | UINT WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
|
---|
3520 | {
|
---|
3521 | UINT oldflags;
|
---|
3522 | MENUITEM *item;
|
---|
3523 | POPUPMENU *menu;
|
---|
3524 |
|
---|
3525 | dprintf(("USER32: EnableMenuItem %x %x %x", hMenu, wItemID, wFlags));
|
---|
3526 |
|
---|
3527 | //TRACE("(%04x, %04X, %04X) !\n",
|
---|
3528 | // hMenu, wItemID, wFlags);
|
---|
3529 |
|
---|
3530 | /* Get the Popupmenu to access the owner menu */
|
---|
3531 | if (!(menu = MENU_GetMenu(hMenu)))
|
---|
3532 | return (UINT)-1;
|
---|
3533 |
|
---|
3534 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
|
---|
3535 | return (UINT)-1;
|
---|
3536 |
|
---|
3537 | oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
|
---|
3538 | item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
|
---|
3539 |
|
---|
3540 | /* In win95 if the close item in the system menu change update the close button */
|
---|
3541 | if((item->wID == SC_CLOSE) && (oldflags != wFlags))
|
---|
3542 | {
|
---|
3543 | if (menu->hSysMenuOwner != 0)
|
---|
3544 | {
|
---|
3545 | POPUPMENU* parentMenu;
|
---|
3546 |
|
---|
3547 | /* Get the parent menu to access*/
|
---|
3548 | if (!(parentMenu = MENU_GetMenu(menu->hSysMenuOwner)))
|
---|
3549 | return (UINT)-1;
|
---|
3550 |
|
---|
3551 | /* Refresh the frame to reflect the change*/
|
---|
3552 | SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
|
---|
3553 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
|
---|
3554 | }
|
---|
3555 | }
|
---|
3556 |
|
---|
3557 | return oldflags;
|
---|
3558 | }
|
---|
3559 |
|
---|
3560 |
|
---|
3561 | /*******************************************************************
|
---|
3562 | * GetMenuString32A (USER32.268)
|
---|
3563 | */
|
---|
3564 | INT WINAPI GetMenuStringA(
|
---|
3565 | HMENU hMenu, /* [in] menuhandle */
|
---|
3566 | UINT wItemID, /* [in] menu item (dep. on wFlags) */
|
---|
3567 | LPSTR str, /* [out] outbuffer. If NULL, func returns entry length*/
|
---|
3568 | INT nMaxSiz, /* [in] length of buffer. if 0, func returns entry len*/
|
---|
3569 | UINT wFlags /* [in] MF_ flags */
|
---|
3570 | ) {
|
---|
3571 | MENUITEM *item;
|
---|
3572 |
|
---|
3573 | dprintf(("USER32: GetMenuStringA %x %d %d %x", hMenu, wItemID, nMaxSiz, wFlags));
|
---|
3574 |
|
---|
3575 | //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
|
---|
3576 | // hMenu, wItemID, str, nMaxSiz, wFlags );
|
---|
3577 |
|
---|
3578 | item = MENU_FindItem( &hMenu, &wItemID, wFlags );
|
---|
3579 |
|
---|
3580 | if (!str || !nMaxSiz)
|
---|
3581 | {
|
---|
3582 | if (item && IS_STRING_ITEM(item->fType))
|
---|
3583 | return strlen(item->text);
|
---|
3584 | else
|
---|
3585 | return 0;
|
---|
3586 | }
|
---|
3587 |
|
---|
3588 | str[0] = '\0';
|
---|
3589 |
|
---|
3590 | if (item)
|
---|
3591 | {
|
---|
3592 | if (!IS_STRING_ITEM(item->fType)) return 0;
|
---|
3593 | lstrcpynA( str, item->text, nMaxSiz );
|
---|
3594 | }
|
---|
3595 |
|
---|
3596 | return strlen(str);
|
---|
3597 | }
|
---|
3598 |
|
---|
3599 |
|
---|
3600 | /*******************************************************************
|
---|
3601 | * GetMenuString32W (USER32.269)
|
---|
3602 | */
|
---|
3603 | INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
|
---|
3604 | LPWSTR str, INT nMaxSiz, UINT wFlags )
|
---|
3605 | {
|
---|
3606 | MENUITEM *item;
|
---|
3607 |
|
---|
3608 | dprintf(("USER32: GetMenuStringW %x %d %x %d %d", hMenu, wItemID, str, nMaxSiz, wFlags));
|
---|
3609 |
|
---|
3610 | //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
|
---|
3611 | // hMenu, wItemID, str, nMaxSiz, wFlags );
|
---|
3612 |
|
---|
3613 | item = MENU_FindItem( &hMenu, &wItemID, wFlags );
|
---|
3614 |
|
---|
3615 | if (!str || !nMaxSiz)
|
---|
3616 | {
|
---|
3617 | if (item && IS_STRING_ITEM(item->fType))
|
---|
3618 | return strlen(item->text);
|
---|
3619 | else
|
---|
3620 | return 0;
|
---|
3621 | }
|
---|
3622 |
|
---|
3623 | str[0] = '\0';
|
---|
3624 |
|
---|
3625 | if (item)
|
---|
3626 | {
|
---|
3627 | if (!IS_STRING_ITEM(item->fType)) return 0;
|
---|
3628 | lstrcpynAtoW( str, item->text, nMaxSiz );
|
---|
3629 | }
|
---|
3630 |
|
---|
3631 | return lstrlenW(str);
|
---|
3632 | }
|
---|
3633 |
|
---|
3634 |
|
---|
3635 | /**********************************************************************
|
---|
3636 | * HiliteMenuItem32 (USER32.318)
|
---|
3637 | */
|
---|
3638 | BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
|
---|
3639 | UINT wHilite )
|
---|
3640 | {
|
---|
3641 | LPPOPUPMENU menu;
|
---|
3642 |
|
---|
3643 | dprintf(("USER32: HiliteMenuItem"));
|
---|
3644 |
|
---|
3645 | //TRACE("(%04x, %04x, %04x, %04x);\n",
|
---|
3646 | // hWnd, hMenu, wItemID, wHilite);
|
---|
3647 | if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
|
---|
3648 | if (!(menu = MENU_GetMenu(hMenu))) return FALSE;
|
---|
3649 | if (menu->FocusedItem == wItemID) return TRUE;
|
---|
3650 | MENU_HideSubPopups( hWnd, hMenu, FALSE );
|
---|
3651 | MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 );
|
---|
3652 | return TRUE;
|
---|
3653 | }
|
---|
3654 |
|
---|
3655 |
|
---|
3656 | /**********************************************************************
|
---|
3657 | * GetMenuState (USER32.267)
|
---|
3658 | */
|
---|
3659 | UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
|
---|
3660 | {
|
---|
3661 | MENUITEM *item;
|
---|
3662 |
|
---|
3663 | dprintf(("USER32: GetMenuState %d %d",wItemID,wFlags));
|
---|
3664 |
|
---|
3665 | //TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
|
---|
3666 | // hMenu, wItemID, wFlags);
|
---|
3667 |
|
---|
3668 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
|
---|
3669 |
|
---|
3670 | //debug_print_menuitem (" item: ", item, "");
|
---|
3671 | if (item->fType & MF_POPUP)
|
---|
3672 | {
|
---|
3673 | POPUPMENU *menu = MENU_GetMenu(item->hSubMenu);
|
---|
3674 | if (!menu) return -1;
|
---|
3675 | else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
|
---|
3676 | }
|
---|
3677 | else
|
---|
3678 | {
|
---|
3679 | /* We used to (from way back then) mask the result to 0xff. */
|
---|
3680 | /* I don't know why and it seems wrong as the documented */
|
---|
3681 | /* return flag MF_SEPARATOR is outside that mask. */
|
---|
3682 | return (item->fType | item->fState);
|
---|
3683 | }
|
---|
3684 | }
|
---|
3685 |
|
---|
3686 |
|
---|
3687 | /**********************************************************************
|
---|
3688 | * GetMenuItemCount32 (USER32.262)
|
---|
3689 | */
|
---|
3690 | INT WINAPI GetMenuItemCount( HMENU hMenu )
|
---|
3691 | {
|
---|
3692 | LPPOPUPMENU menu = MENU_GetMenu(hMenu);
|
---|
3693 |
|
---|
3694 | dprintf(("USER32: GetMenuItemCount %x", hMenu));
|
---|
3695 |
|
---|
3696 | if (!IS_A_MENU(menu)) return -1;
|
---|
3697 | //TRACE("(%04x) returning %d\n",
|
---|
3698 | // hMenu, menu->nItems );
|
---|
3699 | return menu->nItems;
|
---|
3700 | }
|
---|
3701 |
|
---|
3702 | /**********************************************************************
|
---|
3703 | * GetMenuItemID32 (USER32.263)
|
---|
3704 | */
|
---|
3705 | UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
|
---|
3706 | {
|
---|
3707 | MENUITEM * lpmi;
|
---|
3708 |
|
---|
3709 | dprintf(("USER32: GetMenuItemID %x %d", hMenu, nPos));
|
---|
3710 |
|
---|
3711 | if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0xFFFFFFFF;
|
---|
3712 | if (lpmi->fType & MF_POPUP) return 0xFFFFFFFF;
|
---|
3713 | return lpmi->wID;
|
---|
3714 |
|
---|
3715 | }
|
---|
3716 |
|
---|
3717 | /*******************************************************************
|
---|
3718 | * InsertMenu32A (USER32.322)
|
---|
3719 | */
|
---|
3720 | BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
|
---|
3721 | UINT id, LPCSTR str )
|
---|
3722 | {
|
---|
3723 | MENUITEM *item;
|
---|
3724 |
|
---|
3725 | if (IS_STRING_ITEM(flags) && str)
|
---|
3726 | dprintf(("USER32: InsertMenuA %x %d %x %x %s", hMenu, pos, flags, id, str));
|
---|
3727 | // TRACE("hMenu %04x, pos %d, flags %08x, "
|
---|
3728 | // "id %04x, str '%s'\n",
|
---|
3729 | // hMenu, pos, flags, id, str );
|
---|
3730 | else // TRACE("hMenu %04x, pos %d, flags %08x, "
|
---|
3731 | dprintf(("USER32: InsertMenuA %x %d %x %d %x", hMenu, pos, flags, id, str));
|
---|
3732 | // "id %04x, str %08lx (not a string)\n",
|
---|
3733 | // hMenu, pos, flags, id, (DWORD)str );
|
---|
3734 |
|
---|
3735 | if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
|
---|
3736 |
|
---|
3737 | if (!(MENU_SetItemData( item, flags, id, str )))
|
---|
3738 | {
|
---|
3739 | RemoveMenu( hMenu, pos, flags );
|
---|
3740 | return FALSE;
|
---|
3741 | }
|
---|
3742 |
|
---|
3743 | if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
|
---|
3744 | (MENU_GetMenu((HMENU)id))->wFlags |= MF_POPUP;
|
---|
3745 |
|
---|
3746 | item->hCheckBit = item->hUnCheckBit = 0;
|
---|
3747 | return TRUE;
|
---|
3748 | }
|
---|
3749 |
|
---|
3750 |
|
---|
3751 | /*******************************************************************
|
---|
3752 | * InsertMenu32W (USER32.325)
|
---|
3753 | */
|
---|
3754 | BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
|
---|
3755 | UINT id, LPCWSTR str )
|
---|
3756 | {
|
---|
3757 | BOOL ret;
|
---|
3758 |
|
---|
3759 | if (IS_STRING_ITEM(flags) && str)
|
---|
3760 | {
|
---|
3761 | LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
|
---|
3762 | ret = InsertMenuA( hMenu, pos, flags, id, newstr );
|
---|
3763 | HeapFree( GetProcessHeap(), 0, newstr );
|
---|
3764 | return ret;
|
---|
3765 | }
|
---|
3766 | else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
|
---|
3767 | }
|
---|
3768 |
|
---|
3769 |
|
---|
3770 | /*******************************************************************
|
---|
3771 | * AppendMenu32A (USER32.5)
|
---|
3772 | */
|
---|
3773 | BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
|
---|
3774 | UINT id, LPCSTR data )
|
---|
3775 | {
|
---|
3776 | dprintf(("USER32: AppendMenuA %x %x %x %x", hMenu, flags, id, data));
|
---|
3777 |
|
---|
3778 | return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
|
---|
3779 | }
|
---|
3780 |
|
---|
3781 |
|
---|
3782 | /*******************************************************************
|
---|
3783 | * AppendMenu32W (USER32.6)
|
---|
3784 | */
|
---|
3785 | BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
|
---|
3786 | UINT id, LPCWSTR data )
|
---|
3787 | {
|
---|
3788 | dprintf(("USER32: AppendMenuW %x %x %x %x", hMenu, flags, id, data));
|
---|
3789 |
|
---|
3790 | return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
|
---|
3791 | }
|
---|
3792 |
|
---|
3793 |
|
---|
3794 | /**********************************************************************
|
---|
3795 | * RemoveMenu (USER32.441)
|
---|
3796 | */
|
---|
3797 | BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
|
---|
3798 | {
|
---|
3799 | LPPOPUPMENU menu;
|
---|
3800 | MENUITEM *item;
|
---|
3801 |
|
---|
3802 | dprintf(("USER32: RemoveMenu %x %d %x", hMenu, nPos, wFlags));
|
---|
3803 |
|
---|
3804 | //TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
|
---|
3805 | if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
|
---|
3806 | if (!(menu = MENU_GetMenu(hMenu))) return FALSE;
|
---|
3807 |
|
---|
3808 | /* Remove item */
|
---|
3809 |
|
---|
3810 | MENU_FreeItemData( item );
|
---|
3811 |
|
---|
3812 | if (--menu->nItems == 0)
|
---|
3813 | {
|
---|
3814 | HeapFree(GetProcessHeap(), 0, menu->items );
|
---|
3815 | menu->items = NULL;
|
---|
3816 | }
|
---|
3817 | else
|
---|
3818 | {
|
---|
3819 | while(nPos < menu->nItems)
|
---|
3820 | {
|
---|
3821 | *item = *(item+1);
|
---|
3822 | item++;
|
---|
3823 | nPos++;
|
---|
3824 | }
|
---|
3825 | menu->items = (MENUITEM*)HeapReAlloc(GetProcessHeap(), 0, menu->items,
|
---|
3826 | menu->nItems * sizeof(MENUITEM) );
|
---|
3827 | }
|
---|
3828 | return TRUE;
|
---|
3829 | }
|
---|
3830 |
|
---|
3831 |
|
---|
3832 | /**********************************************************************
|
---|
3833 | * DeleteMenu32 (USER32.129)
|
---|
3834 | */
|
---|
3835 | BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
|
---|
3836 | {
|
---|
3837 | MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
|
---|
3838 |
|
---|
3839 | dprintf(("USER32: DeleteMenu %x %d %x", hMenu, nPos, wFlags));
|
---|
3840 |
|
---|
3841 | if (!item) return FALSE;
|
---|
3842 | if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
|
---|
3843 | /* nPos is now the position of the item */
|
---|
3844 | RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
|
---|
3845 | return TRUE;
|
---|
3846 | }
|
---|
3847 |
|
---|
3848 |
|
---|
3849 | /*******************************************************************
|
---|
3850 | * ModifyMenu32A (USER32.397)
|
---|
3851 | */
|
---|
3852 | BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
|
---|
3853 | UINT id, LPCSTR str )
|
---|
3854 | {
|
---|
3855 | MENUITEM *item;
|
---|
3856 |
|
---|
3857 |
|
---|
3858 | if (IS_STRING_ITEM(flags))
|
---|
3859 | {
|
---|
3860 | dprintf(("USER32: ModifyMenuA, %x %d %x %d %s", hMenu, pos, flags, id, str));
|
---|
3861 | //TRACE("%04x %d %04x %04x '%s'\n",
|
---|
3862 | // hMenu, pos, flags, id, str ? str : "#NULL#" );
|
---|
3863 | if (!str) return FALSE;
|
---|
3864 | }
|
---|
3865 | else
|
---|
3866 | {
|
---|
3867 | dprintf(("USER32: ModifyMenuA, %x %d %x %d %x", hMenu, pos, flags, id, str));
|
---|
3868 | //TRACE("%04x %d %04x %04x %08lx\n",
|
---|
3869 | // hMenu, pos, flags, id, (DWORD)str );
|
---|
3870 | }
|
---|
3871 |
|
---|
3872 | if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
|
---|
3873 | return MENU_SetItemData( item, flags, id, str );
|
---|
3874 | }
|
---|
3875 |
|
---|
3876 |
|
---|
3877 | /*******************************************************************
|
---|
3878 | * ModifyMenu32W (USER32.398)
|
---|
3879 | */
|
---|
3880 | BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
|
---|
3881 | UINT id, LPCWSTR str )
|
---|
3882 | {
|
---|
3883 | BOOL ret;
|
---|
3884 |
|
---|
3885 | if (IS_STRING_ITEM(flags) && str)
|
---|
3886 | {
|
---|
3887 | LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
|
---|
3888 | ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
|
---|
3889 | HeapFree( GetProcessHeap(), 0, newstr );
|
---|
3890 | return ret;
|
---|
3891 | }
|
---|
3892 | else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
|
---|
3893 | }
|
---|
3894 |
|
---|
3895 |
|
---|
3896 | /**********************************************************************
|
---|
3897 | * CreatePopupMenu32 (USER32.82)
|
---|
3898 | */
|
---|
3899 | HMENU WINAPI CreatePopupMenu(void)
|
---|
3900 | {
|
---|
3901 | HMENU hmenu;
|
---|
3902 | POPUPMENU *menu;
|
---|
3903 |
|
---|
3904 | dprintf(("USER32: CreatePopupMenu"));
|
---|
3905 |
|
---|
3906 | if (!(hmenu = CreateMenu())) return 0;
|
---|
3907 | menu = MENU_GetMenu(hmenu);
|
---|
3908 | menu->wFlags |= MF_POPUP;
|
---|
3909 | menu->bTimeToHide = FALSE;
|
---|
3910 | return hmenu;
|
---|
3911 | }
|
---|
3912 |
|
---|
3913 |
|
---|
3914 | /**********************************************************************
|
---|
3915 | * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
|
---|
3916 | */
|
---|
3917 | DWORD WINAPI GetMenuCheckMarkDimensions(void)
|
---|
3918 | {
|
---|
3919 | dprintf(("USER32: GetMenuCheckMarkDimensions"));
|
---|
3920 |
|
---|
3921 | return MAKELONG( check_bitmap_width, check_bitmap_height );
|
---|
3922 | }
|
---|
3923 |
|
---|
3924 |
|
---|
3925 | /**********************************************************************
|
---|
3926 | * SetMenuItemBitmaps32 (USER32.490)
|
---|
3927 | */
|
---|
3928 | BOOL WINAPI SetMenuItemBitmaps(HMENU hMenu, UINT nPos, UINT wFlags,
|
---|
3929 | HBITMAP hNewUnCheck, HBITMAP hNewCheck)
|
---|
3930 | {
|
---|
3931 | MENUITEM *item;
|
---|
3932 |
|
---|
3933 | dprintf(("USER32: SetMenuItemBitmaps %x %d %x %x %x", hMenu, nPos, wFlags, hNewCheck, hNewUnCheck));
|
---|
3934 |
|
---|
3935 | //TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
|
---|
3936 | // hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
|
---|
3937 | if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
|
---|
3938 |
|
---|
3939 | if (!hNewCheck && !hNewUnCheck)
|
---|
3940 | {
|
---|
3941 | item->fState &= ~MF_USECHECKBITMAPS;
|
---|
3942 | }
|
---|
3943 | else /* Install new bitmaps */
|
---|
3944 | {
|
---|
3945 | item->hCheckBit = hNewCheck;
|
---|
3946 | item->hUnCheckBit = hNewUnCheck;
|
---|
3947 | item->fState |= MF_USECHECKBITMAPS;
|
---|
3948 | }
|
---|
3949 | return TRUE;
|
---|
3950 | }
|
---|
3951 |
|
---|
3952 |
|
---|
3953 | /**********************************************************************
|
---|
3954 | * CreateMenu (USER32.81)
|
---|
3955 | */
|
---|
3956 | HMENU WINAPI CreateMenu(void)
|
---|
3957 | {
|
---|
3958 | HMENU hMenu;
|
---|
3959 | LPPOPUPMENU menu;
|
---|
3960 |
|
---|
3961 | dprintf(("USER32: CreateMenu"));
|
---|
3962 |
|
---|
3963 | #ifdef __WIN32OS2__
|
---|
3964 | if (!(menu = (LPPOPUPMENU)HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU)))) return 0;
|
---|
3965 | if(ObjAllocateHandle(&hMenu, (DWORD)menu, USEROBJ_MENU) == FALSE) return 0;
|
---|
3966 | #else
|
---|
3967 | if (!(hMenu = (HMENU)HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU)))) return 0;
|
---|
3968 | menu = (LPPOPUPMENU)hMenu;
|
---|
3969 | #endif
|
---|
3970 |
|
---|
3971 | ZeroMemory(menu, sizeof(POPUPMENU));
|
---|
3972 | menu->wMagic = MENU_MAGIC;
|
---|
3973 | menu->FocusedItem = NO_SELECTED_ITEM;
|
---|
3974 | menu->bTimeToHide = FALSE;
|
---|
3975 |
|
---|
3976 | //TRACE("return %04x\n", hMenu );
|
---|
3977 |
|
---|
3978 | return hMenu;
|
---|
3979 | }
|
---|
3980 |
|
---|
3981 |
|
---|
3982 | /**********************************************************************
|
---|
3983 | * DestroyMenu32 (USER32.134)
|
---|
3984 | */
|
---|
3985 | BOOL WINAPI DestroyMenu( HMENU hMenu )
|
---|
3986 | {
|
---|
3987 | //TRACE("(%04x)\n", hMenu);
|
---|
3988 |
|
---|
3989 | dprintf(("USER32: DestroyMenu %x", hMenu));
|
---|
3990 |
|
---|
3991 | /* Silently ignore attempts to destroy default system popup */
|
---|
3992 |
|
---|
3993 | if (hMenu && hMenu != MENU_DefSysPopup)
|
---|
3994 | {
|
---|
3995 | LPPOPUPMENU lppop = MENU_GetMenu(hMenu);
|
---|
3996 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
---|
3997 |
|
---|
3998 | if( pTPWnd && (hMenu == GetWindowLongA(pTPWnd,0)) )
|
---|
3999 | SetWindowLongA(pTPWnd,0,0);
|
---|
4000 |
|
---|
4001 | if (IS_A_MENU(lppop))
|
---|
4002 | {
|
---|
4003 | lppop->wMagic = 0; /* Mark it as destroyed */
|
---|
4004 |
|
---|
4005 | if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
|
---|
4006 | (!pTPWnd || (lppop->hWnd != pTPWnd)))
|
---|
4007 | DestroyWindow( lppop->hWnd );
|
---|
4008 |
|
---|
4009 | if (lppop->items) /* recursively destroy submenus */
|
---|
4010 | {
|
---|
4011 | int i;
|
---|
4012 | MENUITEM *item = lppop->items;
|
---|
4013 | for (i = lppop->nItems; i > 0; i--, item++)
|
---|
4014 | {
|
---|
4015 | if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
|
---|
4016 | MENU_FreeItemData( item );
|
---|
4017 | }
|
---|
4018 | HeapFree(GetProcessHeap(), 0, lppop->items );
|
---|
4019 | }
|
---|
4020 | #ifdef __WIN32OS2__
|
---|
4021 | HeapFree(GetProcessHeap(),0,(LPVOID)lppop);
|
---|
4022 | ObjFreeHandle(hMenu);
|
---|
4023 | #else
|
---|
4024 | HeapFree(GetProcessHeap(),0,(LPVOID)hMenu);
|
---|
4025 | #endif
|
---|
4026 | MENU_ReleaseTopPopupWnd();
|
---|
4027 | }
|
---|
4028 | else
|
---|
4029 | {
|
---|
4030 | MENU_ReleaseTopPopupWnd();
|
---|
4031 | return FALSE;
|
---|
4032 | }
|
---|
4033 | }
|
---|
4034 | return (hMenu != MENU_DefSysPopup);
|
---|
4035 | }
|
---|
4036 |
|
---|
4037 | /**********************************************************************
|
---|
4038 | * GetSystemMenu32 (USER32.291)
|
---|
4039 | */
|
---|
4040 | HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
|
---|
4041 | {
|
---|
4042 | HMENU retvalue = 0;
|
---|
4043 |
|
---|
4044 | dprintf(("USER32: GetSystemMenu %x %d", hWnd, bRevert));
|
---|
4045 |
|
---|
4046 | if (IsWindow(hWnd))
|
---|
4047 | {
|
---|
4048 | HMENU hSysMenu = getSysMenu(hWnd);
|
---|
4049 | if(hSysMenu)
|
---|
4050 | {
|
---|
4051 | if( bRevert )
|
---|
4052 | {
|
---|
4053 | DestroyMenu(hSysMenu);
|
---|
4054 | hSysMenu = 0;
|
---|
4055 | setSysMenu(hWnd,hSysMenu);
|
---|
4056 | }
|
---|
4057 | else
|
---|
4058 | {
|
---|
4059 | POPUPMENU *menu = MENU_GetMenu(hSysMenu);
|
---|
4060 | if(menu)
|
---|
4061 | {
|
---|
4062 | if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
|
---|
4063 | menu->items[0].hSubMenu = MENU_CopySysPopup();
|
---|
4064 | }
|
---|
4065 | else
|
---|
4066 | {
|
---|
4067 | //WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
|
---|
4068 | // wndPtr->hSysMenu, hWnd);
|
---|
4069 | hSysMenu = 0;
|
---|
4070 | setSysMenu(hWnd,hSysMenu);
|
---|
4071 | }
|
---|
4072 | }
|
---|
4073 | }
|
---|
4074 |
|
---|
4075 | if(!hSysMenu && (GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) )
|
---|
4076 | {
|
---|
4077 | hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
|
---|
4078 | setSysMenu(hWnd,hSysMenu);
|
---|
4079 | }
|
---|
4080 |
|
---|
4081 | if( hSysMenu )
|
---|
4082 | {
|
---|
4083 | POPUPMENU *menu;
|
---|
4084 | retvalue = GetSubMenu(hSysMenu, 0);
|
---|
4085 |
|
---|
4086 | /* Store the dummy sysmenu handle to facilitate the refresh */
|
---|
4087 | /* of the close button if the SC_CLOSE item change */
|
---|
4088 | menu = MENU_GetMenu(retvalue);
|
---|
4089 | if (menu)
|
---|
4090 | menu->hSysMenuOwner = hSysMenu;
|
---|
4091 | }
|
---|
4092 | }
|
---|
4093 | return retvalue;
|
---|
4094 | }
|
---|
4095 |
|
---|
4096 |
|
---|
4097 | /*******************************************************************
|
---|
4098 | * SetSystemMenu32 (USER32.508)
|
---|
4099 | */
|
---|
4100 | BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
|
---|
4101 | {
|
---|
4102 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
4103 |
|
---|
4104 | dprintf(("USER32: SetSystemMenu"));
|
---|
4105 |
|
---|
4106 | if (win32wnd)
|
---|
4107 | {
|
---|
4108 | if (win32wnd->GetSysMenu()) DestroyMenu(win32wnd->GetSysMenu());
|
---|
4109 | win32wnd->SetSysMenu(MENU_GetSysMenu( hwnd, hMenu ));
|
---|
4110 | RELEASE_WNDOBJ(win32wnd);
|
---|
4111 | return TRUE;
|
---|
4112 | }
|
---|
4113 | return FALSE;
|
---|
4114 | }
|
---|
4115 |
|
---|
4116 | /**********************************************************************
|
---|
4117 | * GetMenu32 (USER32.257)
|
---|
4118 | */
|
---|
4119 | HMENU WINAPI GetMenu( HWND hWnd )
|
---|
4120 | {
|
---|
4121 | HMENU retvalue;
|
---|
4122 |
|
---|
4123 | dprintf(("USER32: GetMenu %x %x", hWnd, GetWindowLongA( hWnd, GWL_ID )));
|
---|
4124 |
|
---|
4125 | if (GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) {
|
---|
4126 | dprintf(("WARNING: window is child; no menu"));
|
---|
4127 | return 0;
|
---|
4128 | }
|
---|
4129 | retvalue = (HMENU)GetWindowLongA( hWnd, GWL_ID );
|
---|
4130 | if(MENU_GetMenu(retvalue) != NULL) {
|
---|
4131 | return retvalue;
|
---|
4132 | }
|
---|
4133 | return 0;
|
---|
4134 | }
|
---|
4135 |
|
---|
4136 | /**********************************************************************
|
---|
4137 | * SetMenu32 (USER32.487)
|
---|
4138 | */
|
---|
4139 | BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
|
---|
4140 | {
|
---|
4141 | //TRACE("(%04x, %04x);\n", hWnd, hMenu);
|
---|
4142 |
|
---|
4143 | dprintf(("USER32: SetMenu %x %x", hWnd, hMenu));
|
---|
4144 |
|
---|
4145 | if (hMenu && !IsMenu(hMenu))
|
---|
4146 | {
|
---|
4147 | //WARN("hMenu is not a menu handle\n");
|
---|
4148 | return FALSE;
|
---|
4149 | }
|
---|
4150 |
|
---|
4151 |
|
---|
4152 | if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD))
|
---|
4153 | {
|
---|
4154 | if (GetCapture() == hWnd) ReleaseCapture();
|
---|
4155 |
|
---|
4156 | if (hMenu != 0)
|
---|
4157 | {
|
---|
4158 | LPPOPUPMENU lpmenu;
|
---|
4159 |
|
---|
4160 | if (!(lpmenu = MENU_GetMenu(hMenu)))
|
---|
4161 | {
|
---|
4162 | return FALSE;
|
---|
4163 | }
|
---|
4164 | lpmenu->hWnd = hWnd;
|
---|
4165 | lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
|
---|
4166 | lpmenu->Height = 0; /* Make sure we recalculate the size */
|
---|
4167 | }
|
---|
4168 | SetWindowLongA( hWnd, GWL_ID, hMenu );
|
---|
4169 |
|
---|
4170 | #ifdef __WIN32OS2__
|
---|
4171 | //SvL: This fixes the menu in standard mine sweeper (window isn't visible
|
---|
4172 | // when SetMenu is called)
|
---|
4173 | // if (IsWindowVisible(hWnd))
|
---|
4174 | #endif
|
---|
4175 | SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
|
---|
4176 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
|
---|
4177 | return TRUE;
|
---|
4178 | }
|
---|
4179 | return FALSE;
|
---|
4180 | }
|
---|
4181 |
|
---|
4182 |
|
---|
4183 | /**********************************************************************
|
---|
4184 | * GetSubMenu32 (USER32.288)
|
---|
4185 | */
|
---|
4186 | HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
|
---|
4187 | {
|
---|
4188 | MENUITEM * lpmi;
|
---|
4189 |
|
---|
4190 | dprintf(("USER32: GetSubMenu %x %d", hMenu, nPos));
|
---|
4191 |
|
---|
4192 | #ifdef __WIN32OS2__
|
---|
4193 | if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) {
|
---|
4194 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
4195 | return 0;
|
---|
4196 | }
|
---|
4197 | #else
|
---|
4198 | if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
|
---|
4199 | #endif
|
---|
4200 |
|
---|
4201 | if (!(lpmi->fType & MF_POPUP)) return 0;
|
---|
4202 | return lpmi->hSubMenu;
|
---|
4203 | }
|
---|
4204 |
|
---|
4205 |
|
---|
4206 | /**********************************************************************
|
---|
4207 | * DrawMenuBar (USER32.161)
|
---|
4208 | */
|
---|
4209 | BOOL WINAPI DrawMenuBar( HWND hWnd )
|
---|
4210 | {
|
---|
4211 | LPPOPUPMENU lppop;
|
---|
4212 |
|
---|
4213 | dprintf(("USER32: DrawMenuBar %x", hWnd));
|
---|
4214 |
|
---|
4215 | if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) && GetMenu(hWnd))
|
---|
4216 | {
|
---|
4217 | lppop = MENU_GetMenu(GetMenu(hWnd));
|
---|
4218 | if (lppop == NULL)
|
---|
4219 | {
|
---|
4220 | return FALSE;
|
---|
4221 | }
|
---|
4222 |
|
---|
4223 | lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
|
---|
4224 | lppop->hwndOwner = hWnd;
|
---|
4225 | SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
|
---|
4226 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
|
---|
4227 | return TRUE;
|
---|
4228 | }
|
---|
4229 | return FALSE;
|
---|
4230 | }
|
---|
4231 |
|
---|
4232 |
|
---|
4233 | /***********************************************************************
|
---|
4234 | * EndMenu (USER.187) (USER32.175)
|
---|
4235 | */
|
---|
4236 | void WINAPI EndMenu(void)
|
---|
4237 | {
|
---|
4238 | dprintf(("USER32: EndMenu not implemented!"));
|
---|
4239 | /*
|
---|
4240 | * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
|
---|
4241 | */
|
---|
4242 |
|
---|
4243 | fEndMenu = TRUE;
|
---|
4244 | }
|
---|
4245 |
|
---|
4246 |
|
---|
4247 | /*****************************************************************
|
---|
4248 | * LoadMenu32A (USER32.370)
|
---|
4249 | */
|
---|
4250 | HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
|
---|
4251 | {
|
---|
4252 | HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
|
---|
4253 |
|
---|
4254 | dprintf(("USER32: LoadMenuA %x %x", instance, name));
|
---|
4255 |
|
---|
4256 | if (!hrsrc) return 0;
|
---|
4257 | return LoadMenuIndirectA( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
|
---|
4258 | }
|
---|
4259 |
|
---|
4260 |
|
---|
4261 | /*****************************************************************
|
---|
4262 | * LoadMenu32W (USER32.373)
|
---|
4263 | */
|
---|
4264 | HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
|
---|
4265 | {
|
---|
4266 | HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
|
---|
4267 |
|
---|
4268 | dprintf(("USER32: LoadMenuW %x %x", instance, name));
|
---|
4269 |
|
---|
4270 | if (!hrsrc) return 0;
|
---|
4271 | return LoadMenuIndirectW( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
|
---|
4272 | }
|
---|
4273 |
|
---|
4274 |
|
---|
4275 | /**********************************************************************
|
---|
4276 | * LoadMenuIndirect32A (USER32.371)
|
---|
4277 | */
|
---|
4278 | HMENU WINAPI LoadMenuIndirectA(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate)
|
---|
4279 | {
|
---|
4280 | HMENU hMenu;
|
---|
4281 | WORD version, offset;
|
---|
4282 | LPCSTR p = (LPCSTR)lpMenuTemplate;
|
---|
4283 |
|
---|
4284 | dprintf(("USER32: LoadMenuIndirectA"));
|
---|
4285 |
|
---|
4286 | //TRACE("%p\n", template );
|
---|
4287 | version = GET_WORD(p);
|
---|
4288 | p += sizeof(WORD);
|
---|
4289 | switch (version)
|
---|
4290 | {
|
---|
4291 | case 0:
|
---|
4292 | offset = GET_WORD(p);
|
---|
4293 | p += sizeof(WORD) + offset;
|
---|
4294 | if (!(hMenu = CreateMenu())) return 0;
|
---|
4295 | if (!MENU_ParseResource( p, hMenu, TRUE ))
|
---|
4296 | {
|
---|
4297 | DestroyMenu( hMenu );
|
---|
4298 | return 0;
|
---|
4299 | }
|
---|
4300 | return hMenu;
|
---|
4301 | case 1:
|
---|
4302 | offset = GET_WORD(p);
|
---|
4303 | p += sizeof(WORD) + offset;
|
---|
4304 | if (!(hMenu = CreateMenu())) return 0;
|
---|
4305 | if (!MENUEX_ParseResource( p, hMenu))
|
---|
4306 | {
|
---|
4307 | DestroyMenu( hMenu );
|
---|
4308 | return 0;
|
---|
4309 | }
|
---|
4310 | return hMenu;
|
---|
4311 | default:
|
---|
4312 | //ERR("version %d not supported.\n", version);
|
---|
4313 | return 0;
|
---|
4314 | }
|
---|
4315 | }
|
---|
4316 |
|
---|
4317 |
|
---|
4318 | /**********************************************************************
|
---|
4319 | * LoadMenuIndirect32W (USER32.372)
|
---|
4320 | */
|
---|
4321 | HMENU WINAPI LoadMenuIndirectW(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate )
|
---|
4322 | {
|
---|
4323 | dprintf(("USER32: LoadMenuIndirectW"));
|
---|
4324 |
|
---|
4325 | /* FIXME: is there anything different between A and W? */
|
---|
4326 | return LoadMenuIndirectA(lpMenuTemplate);
|
---|
4327 | }
|
---|
4328 |
|
---|
4329 |
|
---|
4330 | /**********************************************************************
|
---|
4331 | * IsMenu32 (USER32.346)
|
---|
4332 | */
|
---|
4333 | BOOL WINAPI IsMenu(HMENU hmenu)
|
---|
4334 | {
|
---|
4335 | LPPOPUPMENU menu = MENU_GetMenu(hmenu);
|
---|
4336 |
|
---|
4337 | dprintf(("USER32: IsMenu"));
|
---|
4338 |
|
---|
4339 | return IS_A_MENU(menu);
|
---|
4340 | }
|
---|
4341 |
|
---|
4342 | /**********************************************************************
|
---|
4343 | * GetMenuItemInfo32_common
|
---|
4344 | */
|
---|
4345 |
|
---|
4346 | static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
|
---|
4347 | LPMENUITEMINFOA lpmii, BOOL unicode)
|
---|
4348 | {
|
---|
4349 | MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
|
---|
4350 |
|
---|
4351 | //debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
|
---|
4352 |
|
---|
4353 | if (!menu)
|
---|
4354 | return FALSE;
|
---|
4355 |
|
---|
4356 | if (lpmii->fMask & MIIM_TYPE) {
|
---|
4357 | lpmii->fType = menu->fType;
|
---|
4358 | switch (MENU_ITEM_TYPE(menu->fType)) {
|
---|
4359 | case MF_STRING:
|
---|
4360 | if (menu->text) {
|
---|
4361 | if (unicode) {
|
---|
4362 | if(lpmii->dwTypeData && lpmii->cch)
|
---|
4363 | lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
|
---|
4364 | lpmii->cch = lstrlenA(menu->text);
|
---|
4365 | } else {
|
---|
4366 | if(lpmii->dwTypeData && lpmii->cch)
|
---|
4367 | lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
|
---|
4368 | lpmii->cch = lstrlenA(menu->text);
|
---|
4369 | }
|
---|
4370 | }
|
---|
4371 | break;
|
---|
4372 | case MF_OWNERDRAW:
|
---|
4373 | case MF_BITMAP:
|
---|
4374 | lpmii->dwTypeData = menu->text;
|
---|
4375 | /* fall through */
|
---|
4376 | default:
|
---|
4377 | lpmii->cch = 0;
|
---|
4378 | }
|
---|
4379 | }
|
---|
4380 |
|
---|
4381 | if (lpmii->fMask & MIIM_STRING) {
|
---|
4382 | if (unicode) {
|
---|
4383 | lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
|
---|
4384 | lpmii->cch = lstrlenW((LPWSTR)menu->text);
|
---|
4385 | } else {
|
---|
4386 | lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
|
---|
4387 | lpmii->cch = lstrlenA(menu->text);
|
---|
4388 | }
|
---|
4389 | }
|
---|
4390 |
|
---|
4391 | if (lpmii->fMask & MIIM_FTYPE)
|
---|
4392 | lpmii->fType = menu->fType;
|
---|
4393 |
|
---|
4394 | if (lpmii->fMask & MIIM_BITMAP)
|
---|
4395 | lpmii->hbmpItem = menu->hbmpItem;
|
---|
4396 |
|
---|
4397 | if (lpmii->fMask & MIIM_STATE)
|
---|
4398 | lpmii->fState = menu->fState;
|
---|
4399 |
|
---|
4400 | if (lpmii->fMask & MIIM_ID)
|
---|
4401 | lpmii->wID = menu->wID;
|
---|
4402 |
|
---|
4403 | if (lpmii->fMask & MIIM_SUBMENU)
|
---|
4404 | lpmii->hSubMenu = menu->hSubMenu;
|
---|
4405 |
|
---|
4406 | if (lpmii->fMask & MIIM_CHECKMARKS) {
|
---|
4407 | lpmii->hbmpChecked = menu->hCheckBit;
|
---|
4408 | lpmii->hbmpUnchecked = menu->hUnCheckBit;
|
---|
4409 | }
|
---|
4410 | if (lpmii->fMask & MIIM_DATA)
|
---|
4411 | lpmii->dwItemData = menu->dwItemData;
|
---|
4412 |
|
---|
4413 | return TRUE;
|
---|
4414 | }
|
---|
4415 |
|
---|
4416 | /**********************************************************************
|
---|
4417 | * GetMenuItemInfoA (USER32.264)
|
---|
4418 | */
|
---|
4419 | BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
|
---|
4420 | LPMENUITEMINFOA lpmii)
|
---|
4421 | {
|
---|
4422 | dprintf(("USER32: GetMenuItemInfoA"));
|
---|
4423 |
|
---|
4424 | return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
|
---|
4425 | }
|
---|
4426 |
|
---|
4427 | /**********************************************************************
|
---|
4428 | * GetMenuItemInfoW (USER32.265)
|
---|
4429 | */
|
---|
4430 | BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
|
---|
4431 | LPMENUITEMINFOW lpmii)
|
---|
4432 | {
|
---|
4433 | dprintf(("USER32: GetMenuItemInfoW"));
|
---|
4434 |
|
---|
4435 | return GetMenuItemInfo_common (hmenu, item, bypos,
|
---|
4436 | (LPMENUITEMINFOA)lpmii, TRUE);
|
---|
4437 | }
|
---|
4438 |
|
---|
4439 | /**********************************************************************
|
---|
4440 | * SetMenuItemInfo32_common
|
---|
4441 | */
|
---|
4442 |
|
---|
4443 | static BOOL SetMenuItemInfo_common(MENUITEM * menu,
|
---|
4444 | const MENUITEMINFOA *lpmii,
|
---|
4445 | BOOL unicode)
|
---|
4446 | {
|
---|
4447 | if (!menu) return FALSE;
|
---|
4448 |
|
---|
4449 | if (lpmii->fMask & MIIM_TYPE ) {
|
---|
4450 | /* Get rid of old string. */
|
---|
4451 | if ( IS_STRING_ITEM(menu->fType) && menu->text) {
|
---|
4452 | HeapFree(GetProcessHeap(), 0, menu->text);
|
---|
4453 | menu->text = NULL;
|
---|
4454 | }
|
---|
4455 |
|
---|
4456 | /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
|
---|
4457 | menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
|
---|
4458 | menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
|
---|
4459 |
|
---|
4460 | menu->text = lpmii->dwTypeData;
|
---|
4461 |
|
---|
4462 | if (IS_STRING_ITEM(menu->fType) && menu->text) {
|
---|
4463 | if (unicode)
|
---|
4464 | menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
|
---|
4465 | else
|
---|
4466 | menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
|
---|
4467 | }
|
---|
4468 | }
|
---|
4469 |
|
---|
4470 | if (lpmii->fMask & MIIM_FTYPE ) {
|
---|
4471 | /* free the string when the type is changing */
|
---|
4472 | if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
|
---|
4473 | HeapFree(GetProcessHeap(), 0, menu->text);
|
---|
4474 | menu->text = NULL;
|
---|
4475 | }
|
---|
4476 | menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
|
---|
4477 | menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
|
---|
4478 | }
|
---|
4479 |
|
---|
4480 | if (lpmii->fMask & MIIM_STRING ) {
|
---|
4481 | /* free the string when used */
|
---|
4482 | if ( IS_STRING_ITEM(menu->fType) && menu->text) {
|
---|
4483 | HeapFree(GetProcessHeap(), 0, menu->text);
|
---|
4484 | if (unicode)
|
---|
4485 | menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
|
---|
4486 | else
|
---|
4487 | menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
|
---|
4488 | }
|
---|
4489 | }
|
---|
4490 |
|
---|
4491 | if (lpmii->fMask & MIIM_STATE)
|
---|
4492 | {
|
---|
4493 | /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
|
---|
4494 | menu->fState = lpmii->fState;
|
---|
4495 | }
|
---|
4496 |
|
---|
4497 | if (lpmii->fMask & MIIM_ID)
|
---|
4498 | menu->wID = lpmii->wID;
|
---|
4499 |
|
---|
4500 | if (lpmii->fMask & MIIM_SUBMENU) {
|
---|
4501 | menu->hSubMenu = lpmii->hSubMenu;
|
---|
4502 | if (menu->hSubMenu) {
|
---|
4503 | POPUPMENU *subMenu = MENU_GetMenu((UINT)menu->hSubMenu);
|
---|
4504 | if (IS_A_MENU(subMenu)) {
|
---|
4505 | subMenu->wFlags |= MF_POPUP;
|
---|
4506 | menu->fType |= MF_POPUP;
|
---|
4507 | }
|
---|
4508 | else
|
---|
4509 | /* FIXME: Return an error ? */
|
---|
4510 | menu->fType &= ~MF_POPUP;
|
---|
4511 | }
|
---|
4512 | else
|
---|
4513 | menu->fType &= ~MF_POPUP;
|
---|
4514 | }
|
---|
4515 |
|
---|
4516 | if (lpmii->fMask & MIIM_CHECKMARKS)
|
---|
4517 | {
|
---|
4518 | menu->hCheckBit = lpmii->hbmpChecked;
|
---|
4519 | menu->hUnCheckBit = lpmii->hbmpUnchecked;
|
---|
4520 | }
|
---|
4521 | if (lpmii->fMask & MIIM_DATA)
|
---|
4522 | menu->dwItemData = lpmii->dwItemData;
|
---|
4523 |
|
---|
4524 | //debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
|
---|
4525 | return TRUE;
|
---|
4526 | }
|
---|
4527 |
|
---|
4528 | /**********************************************************************
|
---|
4529 | * SetMenuItemInfo32A (USER32.491)
|
---|
4530 | */
|
---|
4531 | BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
|
---|
4532 | const MENUITEMINFOA *lpmii)
|
---|
4533 | {
|
---|
4534 | dprintf(("USER32: SetMenuItemInfoA %x %d %d %x", hmenu, item, bypos, lpmii));
|
---|
4535 |
|
---|
4536 | return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
|
---|
4537 | lpmii, FALSE);
|
---|
4538 | }
|
---|
4539 |
|
---|
4540 | /**********************************************************************
|
---|
4541 | * SetMenuItemInfo32W (USER32.492)
|
---|
4542 | */
|
---|
4543 | BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
|
---|
4544 | const MENUITEMINFOW *lpmii)
|
---|
4545 | {
|
---|
4546 | dprintf(("USER32: SetMenuItemInfoW"));
|
---|
4547 |
|
---|
4548 | return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
|
---|
4549 | (const MENUITEMINFOA*)lpmii, TRUE);
|
---|
4550 | }
|
---|
4551 |
|
---|
4552 | /**********************************************************************
|
---|
4553 | * SetMenuDefaultItem (USER32.489)
|
---|
4554 | *
|
---|
4555 | */
|
---|
4556 | BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
|
---|
4557 | {
|
---|
4558 | UINT i;
|
---|
4559 | POPUPMENU *menu;
|
---|
4560 | MENUITEM *item;
|
---|
4561 |
|
---|
4562 |
|
---|
4563 | dprintf(("USER32: SetMenuDefaultItem"));
|
---|
4564 | //TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
|
---|
4565 |
|
---|
4566 | if (!(menu = MENU_GetMenu(hmenu))) return FALSE;
|
---|
4567 |
|
---|
4568 | /* reset all default-item flags */
|
---|
4569 | item = menu->items;
|
---|
4570 | for (i = 0; i < menu->nItems; i++, item++)
|
---|
4571 | {
|
---|
4572 | item->fState &= ~MFS_DEFAULT;
|
---|
4573 | }
|
---|
4574 |
|
---|
4575 | /* no default item */
|
---|
4576 | if ( -1 == uItem)
|
---|
4577 | {
|
---|
4578 | return TRUE;
|
---|
4579 | }
|
---|
4580 |
|
---|
4581 | item = menu->items;
|
---|
4582 | if ( bypos )
|
---|
4583 | {
|
---|
4584 | if ( uItem >= menu->nItems ) return FALSE;
|
---|
4585 | item[uItem].fState |= MFS_DEFAULT;
|
---|
4586 | return TRUE;
|
---|
4587 | }
|
---|
4588 | else
|
---|
4589 | {
|
---|
4590 | for (i = 0; i < menu->nItems; i++, item++)
|
---|
4591 | {
|
---|
4592 | if (item->wID == uItem)
|
---|
4593 | {
|
---|
4594 | item->fState |= MFS_DEFAULT;
|
---|
4595 | return TRUE;
|
---|
4596 | }
|
---|
4597 | }
|
---|
4598 |
|
---|
4599 | }
|
---|
4600 | return FALSE;
|
---|
4601 | }
|
---|
4602 |
|
---|
4603 | /**********************************************************************
|
---|
4604 | * GetMenuDefaultItem (USER32.260)
|
---|
4605 | */
|
---|
4606 | UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
|
---|
4607 | {
|
---|
4608 | POPUPMENU *menu;
|
---|
4609 | MENUITEM * item;
|
---|
4610 | UINT i = 0;
|
---|
4611 |
|
---|
4612 | dprintf(("USER32: GetMenuDefaultItem"));
|
---|
4613 | //TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
|
---|
4614 |
|
---|
4615 | if (!(menu = MENU_GetMenu(hmenu))) return -1;
|
---|
4616 |
|
---|
4617 | /* find default item */
|
---|
4618 | item = menu->items;
|
---|
4619 |
|
---|
4620 | /* empty menu */
|
---|
4621 | if (! item) return -1;
|
---|
4622 |
|
---|
4623 | while ( !( item->fState & MFS_DEFAULT ) )
|
---|
4624 | {
|
---|
4625 | i++; item++;
|
---|
4626 | if (i >= menu->nItems ) return -1;
|
---|
4627 | }
|
---|
4628 |
|
---|
4629 | /* default: don't return disabled items */
|
---|
4630 | if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
|
---|
4631 |
|
---|
4632 | /* search rekursiv when needed */
|
---|
4633 | if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
|
---|
4634 | {
|
---|
4635 | UINT ret;
|
---|
4636 | ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
|
---|
4637 | if ( -1 != ret ) return ret;
|
---|
4638 |
|
---|
4639 | /* when item not found in submenu, return the popup item */
|
---|
4640 | }
|
---|
4641 | return ( bypos ) ? i : item->wID;
|
---|
4642 |
|
---|
4643 | }
|
---|
4644 |
|
---|
4645 | /**********************************************************************
|
---|
4646 | * InsertMenuItem32A (USER32.323)
|
---|
4647 | */
|
---|
4648 | BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
|
---|
4649 | const MENUITEMINFOA *lpmii)
|
---|
4650 | {
|
---|
4651 | MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
|
---|
4652 |
|
---|
4653 | dprintf(("USER32: InsertMenuItemA %x %d %d %x", hMenu, uItem, bypos, lpmii->wID));
|
---|
4654 |
|
---|
4655 | return SetMenuItemInfo_common(item, lpmii, FALSE);
|
---|
4656 | }
|
---|
4657 |
|
---|
4658 |
|
---|
4659 | /**********************************************************************
|
---|
4660 | * InsertMenuItem32W (USER32.324)
|
---|
4661 | */
|
---|
4662 | BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
|
---|
4663 | const MENUITEMINFOW *lpmii)
|
---|
4664 | {
|
---|
4665 | MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
|
---|
4666 |
|
---|
4667 | dprintf(("USER32: InsertMenuItemW"));
|
---|
4668 |
|
---|
4669 | return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
|
---|
4670 | }
|
---|
4671 |
|
---|
4672 | /**********************************************************************
|
---|
4673 | * CheckMenuRadioItem32 (USER32.47)
|
---|
4674 | */
|
---|
4675 |
|
---|
4676 | BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
|
---|
4677 | UINT first, UINT last, UINT check,
|
---|
4678 | UINT bypos)
|
---|
4679 | {
|
---|
4680 | MENUITEM *mifirst, *milast, *micheck;
|
---|
4681 | HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
|
---|
4682 |
|
---|
4683 | dprintf(("USER32: CheckMenuRadioItem"));
|
---|
4684 | //TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
|
---|
4685 | // hMenu, first, last, check, bypos);
|
---|
4686 |
|
---|
4687 | mifirst = MENU_FindItem (&mfirst, &first, bypos);
|
---|
4688 | milast = MENU_FindItem (&mlast, &last, bypos);
|
---|
4689 | micheck = MENU_FindItem (&mcheck, &check, bypos);
|
---|
4690 |
|
---|
4691 | if (mifirst == NULL || milast == NULL || micheck == NULL ||
|
---|
4692 | mifirst > milast || mfirst != mlast || mfirst != mcheck ||
|
---|
4693 | micheck > milast || micheck < mifirst)
|
---|
4694 | return FALSE;
|
---|
4695 |
|
---|
4696 | while (mifirst <= milast)
|
---|
4697 | {
|
---|
4698 | if (mifirst == micheck)
|
---|
4699 | {
|
---|
4700 | mifirst->fType |= MFT_RADIOCHECK;
|
---|
4701 | mifirst->fState |= MFS_CHECKED;
|
---|
4702 | } else {
|
---|
4703 | mifirst->fType &= ~MFT_RADIOCHECK;
|
---|
4704 | mifirst->fState &= ~MFS_CHECKED;
|
---|
4705 | }
|
---|
4706 | mifirst++;
|
---|
4707 | }
|
---|
4708 |
|
---|
4709 | return TRUE;
|
---|
4710 | }
|
---|
4711 |
|
---|
4712 | /**********************************************************************
|
---|
4713 | * GetMenuItemRect32 (USER32.266)
|
---|
4714 | *
|
---|
4715 | * ATTENTION: Here, the returned values in rect are the screen
|
---|
4716 | * coordinates of the item just like if the menu was
|
---|
4717 | * always on the upper left side of the application.
|
---|
4718 | *
|
---|
4719 | */
|
---|
4720 | BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
|
---|
4721 | LPRECT rect)
|
---|
4722 | {
|
---|
4723 | POPUPMENU *itemMenu;
|
---|
4724 | MENUITEM *item;
|
---|
4725 | HWND referenceHwnd;
|
---|
4726 |
|
---|
4727 | //TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
|
---|
4728 |
|
---|
4729 | item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
|
---|
4730 | referenceHwnd = hwnd;
|
---|
4731 |
|
---|
4732 | if(!hwnd)
|
---|
4733 | {
|
---|
4734 | itemMenu = MENU_GetMenu(hMenu);
|
---|
4735 | if (itemMenu == NULL) {
|
---|
4736 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
4737 | return FALSE;
|
---|
4738 | }
|
---|
4739 |
|
---|
4740 | if(itemMenu->hWnd == 0)
|
---|
4741 | return FALSE;
|
---|
4742 | referenceHwnd = itemMenu->hWnd;
|
---|
4743 | }
|
---|
4744 |
|
---|
4745 | if ((rect == NULL) || (item == NULL)) {
|
---|
4746 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
4747 | return FALSE;
|
---|
4748 | }
|
---|
4749 | *rect = item->rect;
|
---|
4750 |
|
---|
4751 | MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
|
---|
4752 | dprintf(("USER32: GetMenuItemRect %x %x %d (%d,%d)(%d,%d)", hwnd, hMenu, uItem, rect->left, rect->top, rect->right, rect->bottom));
|
---|
4753 |
|
---|
4754 | return TRUE;
|
---|
4755 | }
|
---|
4756 |
|
---|
4757 | /**********************************************************************
|
---|
4758 | * SetMenuInfo
|
---|
4759 | *
|
---|
4760 | * FIXME
|
---|
4761 | * MIM_APPLYTOSUBMENUS
|
---|
4762 | * actually use the items to draw the menu
|
---|
4763 | */
|
---|
4764 | BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
|
---|
4765 | {
|
---|
4766 | POPUPMENU *menu;
|
---|
4767 |
|
---|
4768 | dprintf(("USER32: SetMenuInfo"));
|
---|
4769 | //TRACE("(0x%04x %p)\n", hMenu, lpmi);
|
---|
4770 |
|
---|
4771 | if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=MENU_GetMenu(hMenu)))
|
---|
4772 | {
|
---|
4773 |
|
---|
4774 | if (lpmi->fMask & MIM_BACKGROUND)
|
---|
4775 | menu->hbrBack = lpmi->hbrBack;
|
---|
4776 |
|
---|
4777 | if (lpmi->fMask & MIM_HELPID)
|
---|
4778 | menu->dwContextHelpID = lpmi->dwContextHelpID;
|
---|
4779 |
|
---|
4780 | if (lpmi->fMask & MIM_MAXHEIGHT)
|
---|
4781 | menu->cyMax = lpmi->cyMax;
|
---|
4782 |
|
---|
4783 | if (lpmi->fMask & MIM_MENUDATA)
|
---|
4784 | menu->dwMenuData = lpmi->dwMenuData;
|
---|
4785 |
|
---|
4786 | if (lpmi->fMask & MIM_STYLE)
|
---|
4787 | menu->dwStyle = lpmi->dwStyle;
|
---|
4788 |
|
---|
4789 | return TRUE;
|
---|
4790 | }
|
---|
4791 | return FALSE;
|
---|
4792 | }
|
---|
4793 |
|
---|
4794 | /**********************************************************************
|
---|
4795 | * GetMenuInfo
|
---|
4796 | *
|
---|
4797 | * NOTES
|
---|
4798 | * win98/NT5.0
|
---|
4799 | *
|
---|
4800 | */
|
---|
4801 | BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
|
---|
4802 | { POPUPMENU *menu;
|
---|
4803 |
|
---|
4804 | dprintf(("USER32: GetMenuInfo"));
|
---|
4805 | //TRACE("(0x%04x %p)\n", hMenu, lpmi);
|
---|
4806 |
|
---|
4807 | if (lpmi && (menu = MENU_GetMenu(hMenu)))
|
---|
4808 | {
|
---|
4809 |
|
---|
4810 | if (lpmi->fMask & MIM_BACKGROUND)
|
---|
4811 | lpmi->hbrBack = menu->hbrBack;
|
---|
4812 |
|
---|
4813 | if (lpmi->fMask & MIM_HELPID)
|
---|
4814 | lpmi->dwContextHelpID = menu->dwContextHelpID;
|
---|
4815 |
|
---|
4816 | if (lpmi->fMask & MIM_MAXHEIGHT)
|
---|
4817 | lpmi->cyMax = menu->cyMax;
|
---|
4818 |
|
---|
4819 | if (lpmi->fMask & MIM_MENUDATA)
|
---|
4820 | lpmi->dwMenuData = menu->dwMenuData;
|
---|
4821 |
|
---|
4822 | if (lpmi->fMask & MIM_STYLE)
|
---|
4823 | lpmi->dwStyle = menu->dwStyle;
|
---|
4824 |
|
---|
4825 | return TRUE;
|
---|
4826 | }
|
---|
4827 | return FALSE;
|
---|
4828 | }
|
---|
4829 |
|
---|
4830 | /**********************************************************************
|
---|
4831 | * SetMenuContextHelpId (USER32.488)
|
---|
4832 | */
|
---|
4833 | BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
|
---|
4834 | {
|
---|
4835 | LPPOPUPMENU menu;
|
---|
4836 |
|
---|
4837 | dprintf(("USER32: SetMenuContextHelpId"));
|
---|
4838 | //TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
|
---|
4839 |
|
---|
4840 | menu = MENU_GetMenu(hMenu);
|
---|
4841 | if (menu)
|
---|
4842 | {
|
---|
4843 | menu->dwContextHelpID = dwContextHelpID;
|
---|
4844 | return TRUE;
|
---|
4845 | }
|
---|
4846 | return FALSE;
|
---|
4847 | }
|
---|
4848 |
|
---|
4849 | /**********************************************************************
|
---|
4850 | * GetMenuContextHelpId (USER32.488)
|
---|
4851 | */
|
---|
4852 | DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
|
---|
4853 | {
|
---|
4854 | LPPOPUPMENU menu;
|
---|
4855 |
|
---|
4856 | dprintf(("USER32: GetMenuContextHelpId"));
|
---|
4857 |
|
---|
4858 | menu = MENU_GetMenu(hMenu);
|
---|
4859 | if (menu)
|
---|
4860 | {
|
---|
4861 | return menu->dwContextHelpID;
|
---|
4862 | }
|
---|
4863 | return 0;
|
---|
4864 | }
|
---|
4865 |
|
---|
4866 | /**********************************************************************
|
---|
4867 | * MenuItemFromPoint (USER32.387)
|
---|
4868 | */
|
---|
4869 | UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
|
---|
4870 | {
|
---|
4871 | dprintf(("USER32: MenuItemFromPoint not implemented!"));
|
---|
4872 |
|
---|
4873 | return 0;
|
---|
4874 | }
|
---|
4875 |
|
---|
4876 | /**********************************************************************
|
---|
4877 | * IsMenuActive (Internal)
|
---|
4878 | */
|
---|
4879 | BOOL IsMenuActive(void)
|
---|
4880 | {
|
---|
4881 | return pTopPopupWnd && (GetWindowLongA(pTopPopupWnd,GWL_STYLE) & WS_VISIBLE);
|
---|
4882 | }
|
---|
4883 |
|
---|
4884 | BOOL POPUPMENU_Register()
|
---|
4885 | {
|
---|
4886 | WNDCLASSA wndClass;
|
---|
4887 | BOOL rc;
|
---|
4888 |
|
---|
4889 | //SvL: Don't check this now
|
---|
4890 | // if (GlobalFindAtomA(POPUPMENUCLASSNAME)) return FALSE;
|
---|
4891 |
|
---|
4892 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
4893 | wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
|
---|
4894 | wndClass.lpfnWndProc = (WNDPROC)PopupMenuWndProc;
|
---|
4895 | wndClass.cbClsExtra = 0;
|
---|
4896 | wndClass.cbWndExtra = sizeof(HMENU);
|
---|
4897 | wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
|
---|
4898 | wndClass.hbrBackground = NULL_BRUSH;
|
---|
4899 | wndClass.lpszClassName = POPUPMENUCLASSNAME;
|
---|
4900 |
|
---|
4901 | rc = RegisterClassA(&wndClass);
|
---|
4902 | MENU_Init();
|
---|
4903 |
|
---|
4904 | return rc;
|
---|
4905 | }
|
---|
4906 | //******************************************************************************
|
---|
4907 | //******************************************************************************
|
---|
4908 | BOOL POPUPMENU_Unregister()
|
---|
4909 | {
|
---|
4910 | if (GlobalFindAtomA(POPUPMENUCLASSNAME))
|
---|
4911 | return UnregisterClassA(POPUPMENUCLASSNAME,(HINSTANCE)NULL);
|
---|
4912 | else return FALSE;
|
---|
4913 | }
|
---|
4914 | //******************************************************************************
|
---|
4915 | //******************************************************************************
|
---|
4916 | #ifdef __WIN32OS2__
|
---|
4917 | void DisableOdinSysMenuItems()
|
---|
4918 | {
|
---|
4919 | fDisableOdinSysMenuItems = TRUE;
|
---|
4920 | }
|
---|
4921 | //******************************************************************************
|
---|
4922 | //******************************************************************************
|
---|
4923 | #endif
|
---|