2003-07-10 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / lib / user32 / windows / menu.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: menu.c,v 1.8 2003/07/10 21:04:32 chorns Exp $
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/menu.c
23 * PURPOSE: Menus
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <windows.h>
32 #include <user32.h>
33 #include <debug.h>
34
35 /* TYPES *********************************************************************/
36
37 typedef struct _MENUITEM
38 {
39 UINT Type;
40 UINT State;
41 UINT Id;
42 HMENU SubMenu;
43 HBITMAP CheckBit;
44 HBITMAP UnCheckBit;
45 LPWSTR Text;
46 DWORD ItemData;
47 DWORD TypeData;
48 HBITMAP BmpItem;
49 RECT Rect;
50 UINT XTab;
51 } MENUITEM, *PMENUITEM;
52
53 typedef struct _POPUP_MENU
54 {
55 MENUITEM* Items;
56 WORD NrItems;
57 } POPUP_MENU, *PPOPUP_MENU;
58
59 /* FUNCTIONS *****************************************************************/
60
61 static PPOPUP_MENU
62 MenuGetMenu(HMENU hMenu)
63 {
64 PPOPUP_MENU Menu;
65 Menu = (PPOPUP_MENU)hMenu;
66 return(Menu);
67 }
68
69 static MENUITEM*
70 MenuFindItem(HMENU* hMenu, UINT* nPos, UINT wFlags)
71 {
72 POPUP_MENU* Menu;
73 ULONG i;
74
75 if ((ULONG)(*hMenu) == 0xFFFF || (Menu = MenuGetMenu(*hMenu)) == NULL)
76 {
77 return(NULL);
78 }
79 if (wFlags & MF_BYPOSITION)
80 {
81 if ((*nPos) >= Menu->NrItems)
82 {
83 return(NULL);
84 }
85 return(&Menu->Items[*nPos]);
86 }
87 else
88 {
89 MENUITEM* Item = Menu->Items;
90 for (i = 0; i < Menu->NrItems; i++)
91 {
92 if (Item->Id == (*nPos))
93 {
94 *nPos = i;
95 return(Item);
96 }
97 else if (Item->Type & MF_POPUP)
98 {
99 HMENU SubMenu = Item->SubMenu;
100 MENUITEM* SubItem = MenuFindItem(&SubMenu, nPos, wFlags);
101 if (SubItem)
102 {
103 *hMenu = SubMenu;
104 return(SubItem);
105 }
106 }
107 }
108 }
109 return(NULL);
110 }
111
112
113 /*
114 * @implemented
115 */
116 WINBOOL STDCALL
117 AppendMenuA(HMENU hMenu,
118 UINT uFlags,
119 UINT_PTR uIDNewItem,
120 LPCSTR lpNewItem)
121 {
122 DPRINT("AppendMenuA(hMenu 0x%X, uFlags 0x%X, uIDNewItem %d, "
123 "lpNewItem %s\n", hMenu, uFlags, uIDNewItem, lpNewItem);
124 return(InsertMenuA(hMenu, -1, uFlags | MF_BYPOSITION, uIDNewItem,
125 lpNewItem));
126 }
127
128
129 /*
130 * @implemented
131 */
132 WINBOOL STDCALL
133 AppendMenuW(HMENU hMenu,
134 UINT uFlags,
135 UINT_PTR uIDNewItem,
136 LPCWSTR lpNewItem)
137 {
138 DPRINT("AppendMenuW(hMenu 0x%X, uFlags 0x%X, uIDNewItem %d, "
139 "lpNewItem %S\n", hMenu, uFlags, uIDNewItem, lpNewItem);
140 return(InsertMenuW(hMenu, -1, uFlags | MF_BYPOSITION, uIDNewItem,
141 lpNewItem));
142 }
143
144
145 /*
146 * @implemented
147 */
148 DWORD STDCALL
149 CheckMenuItem(HMENU hmenu,
150 UINT uIDCheckItem,
151 UINT uCheck)
152 {
153 MENUITEM* Item;
154 DWORD Ret;
155
156 DPRINT("CheckMenuItem(hmenu 0x%X, uIDCheckItem %d, uCheck %d",
157 hmenu, uIDCheckItem, uCheck);
158 if ((Item = MenuFindItem(&hmenu, &uIDCheckItem, uCheck)) == NULL)
159 {
160 return(-1);
161 }
162 Ret = Item->State & MF_CHECKED;
163 if (uCheck & MF_CHECKED)
164 {
165 Item->State |= MF_CHECKED;
166 }
167 else
168 {
169 Item->State &= ~MF_CHECKED;
170 }
171 return(Ret);
172 }
173
174
175 /*
176 * @unimplemented
177 */
178 WINBOOL
179 STDCALL
180 CheckMenuRadioItem(
181 HMENU hmenu,
182 UINT idFirst,
183 UINT idLast,
184 UINT idCheck,
185 UINT uFlags)
186 {
187 UNIMPLEMENTED;
188 return FALSE;
189 }
190
191
192 /*
193 * @unimplemented
194 */
195 HMENU
196 STDCALL
197 CreateMenu(VOID)
198 {
199 UNIMPLEMENTED;
200 return (HMENU)0;
201 }
202
203
204 /*
205 * @unimplemented
206 */
207 HMENU
208 STDCALL
209 CreatePopupMenu(VOID)
210 {
211 UNIMPLEMENTED;
212 return (HMENU)0;
213 }
214
215
216 /*
217 * @unimplemented
218 */
219 WINBOOL
220 STDCALL
221 DeleteMenu(
222 HMENU hMenu,
223 UINT uPosition,
224 UINT uFlags)
225 {
226 UNIMPLEMENTED;
227 return FALSE;
228 }
229
230
231 /*
232 * @unimplemented
233 */
234 WINBOOL
235 STDCALL
236 DestroyMenu(
237 HMENU hMenu)
238 {
239 UNIMPLEMENTED;
240 return FALSE;
241 }
242
243
244 /*
245 * @unimplemented
246 */
247 WINBOOL
248 STDCALL
249 DrawMenuBar(
250 HWND hWnd)
251 {
252 UNIMPLEMENTED;
253 return FALSE;
254 }
255
256
257 /*
258 * @unimplemented
259 */
260 WINBOOL
261 STDCALL
262 EnableMenuItem(
263 HMENU hMenu,
264 UINT uIDEnableItem,
265 UINT uEnable)
266 {
267 UNIMPLEMENTED;
268 return FALSE;
269 }
270
271
272 /*
273 * @unimplemented
274 */
275 WINBOOL
276 STDCALL
277 EndMenu(VOID)
278 {
279 UNIMPLEMENTED;
280 return FALSE;
281 }
282
283
284 /*
285 * @unimplemented
286 */
287 HMENU
288 STDCALL
289 GetMenu(
290 HWND hWnd)
291 {
292 UNIMPLEMENTED;
293 return (HMENU)0;
294 }
295
296
297 /*
298 * @unimplemented
299 */
300 WINBOOL
301 STDCALL
302 GetMenuBarInfo(
303 HWND hwnd,
304 LONG idObject,
305 LONG idItem,
306 PMENUBARINFO pmbi)
307 {
308 UNIMPLEMENTED;
309 return FALSE;
310 }
311
312
313 /*
314 * @unimplemented
315 */
316 LONG
317 STDCALL
318 GetMenuCheckMarkDimensions(VOID)
319 {
320 UNIMPLEMENTED;
321 return 0;
322 }
323
324
325 /*
326 * @unimplemented
327 */
328 UINT
329 STDCALL
330 GetMenuDefaultItem(
331 HMENU hMenu,
332 UINT fByPos,
333 UINT gmdiFlags)
334 {
335 UNIMPLEMENTED;
336 return 0;
337 }
338
339
340 /*
341 * @unimplemented
342 */
343 WINBOOL
344 STDCALL
345 GetMenuInfo(
346 HMENU hmenu,
347 LPCMENUINFO lpcmi)
348 {
349 UNIMPLEMENTED;
350 return FALSE;
351 }
352
353
354 /*
355 * @unimplemented
356 */
357 int
358 STDCALL
359 GetMenuItemCount(
360 HMENU hMenu)
361 {
362 UNIMPLEMENTED;
363 return 0;
364 }
365
366
367 /*
368 * @unimplemented
369 */
370 UINT
371 STDCALL
372 GetMenuItemID(
373 HMENU hMenu,
374 int nPos)
375 {
376 UNIMPLEMENTED;
377 return 0;
378 }
379
380
381 /*
382 * @unimplemented
383 */
384 WINBOOL
385 STDCALL
386 GetMenuItemInfoA(
387 HMENU hMenu,
388 UINT uItem,
389 WINBOOL fByPosition,
390 LPMENUITEMINFO lpmii)
391 {
392 UNIMPLEMENTED;
393 return FALSE;
394 }
395
396
397 /*
398 * @unimplemented
399 */
400 WINBOOL
401 STDCALL
402 GetMenuItemInfoW(
403 HMENU hMenu,
404 UINT uItem,
405 WINBOOL fByPosition,
406 LPMENUITEMINFO lpmii)
407 {
408 UNIMPLEMENTED;
409 return FALSE;
410 }
411
412
413 /*
414 * @unimplemented
415 */
416 WINBOOL
417 STDCALL
418 GetMenuItemRect(
419 HWND hWnd,
420 HMENU hMenu,
421 UINT uItem,
422 LPRECT lprcItem)
423 {
424 UNIMPLEMENTED;
425 return FALSE;
426 }
427
428
429 /*
430 * @unimplemented
431 */
432 UINT
433 STDCALL
434 GetMenuState(
435 HMENU hMenu,
436 UINT uId,
437 UINT uFlags)
438 {
439 UNIMPLEMENTED;
440 return 0;
441 }
442
443
444 /*
445 * @unimplemented
446 */
447 int
448 STDCALL
449 GetMenuStringA(
450 HMENU hMenu,
451 UINT uIDItem,
452 LPSTR lpString,
453 int nMaxCount,
454 UINT uFlag)
455 {
456 UNIMPLEMENTED;
457 return 0;
458 }
459
460
461 /*
462 * @unimplemented
463 */
464 int
465 STDCALL
466 GetMenuStringW(
467 HMENU hMenu,
468 UINT uIDItem,
469 LPWSTR lpString,
470 int nMaxCount,
471 UINT uFlag)
472 {
473 UNIMPLEMENTED;
474 return 0;
475 }
476
477
478 /*
479 * @unimplemented
480 */
481 HMENU
482 STDCALL
483 GetSubMenu(
484 HMENU hMenu,
485 int nPos)
486 {
487 UNIMPLEMENTED;
488 return (HMENU)0;
489 }
490
491
492 /*
493 * @unimplemented
494 */
495 WINBOOL
496 STDCALL
497 HiliteMenuItem(
498 HWND hwnd,
499 HMENU hmenu,
500 UINT uItemHilite,
501 UINT uHilite)
502 {
503 UNIMPLEMENTED;
504 return FALSE;
505 }
506
507
508 /*
509 * @unimplemented
510 */
511 WINBOOL
512 STDCALL
513 InsertMenuA(
514 HMENU hMenu,
515 UINT uPosition,
516 UINT uFlags,
517 UINT_PTR uIDNewItem,
518 LPCSTR lpNewItem)
519 {
520 UNIMPLEMENTED;
521 return FALSE;
522 }
523
524
525 /*
526 * @unimplemented
527 */
528 WINBOOL
529 STDCALL
530 InsertMenuItemA(
531 HMENU hMenu,
532 UINT uItem,
533 WINBOOL fByPosition,
534 LPCMENUITEMINFO lpmii)
535 {
536 UNIMPLEMENTED;
537 return FALSE;
538 }
539
540
541 /*
542 * @unimplemented
543 */
544 WINBOOL
545 STDCALL
546 InsertMenuItemW(
547 HMENU hMenu,
548 UINT uItem,
549 WINBOOL fByPosition,
550 LPCMENUITEMINFO lpmii)
551 {
552 UNIMPLEMENTED;
553 return FALSE;
554 }
555
556
557 /*
558 * @unimplemented
559 */
560 WINBOOL
561 STDCALL
562 InsertMenuW(
563 HMENU hMenu,
564 UINT uPosition,
565 UINT uFlags,
566 UINT_PTR uIDNewItem,
567 LPCWSTR lpNewItem)
568 {
569 UNIMPLEMENTED;
570 return FALSE;
571 }
572
573
574 /*
575 * @unimplemented
576 */
577 WINBOOL
578 STDCALL
579 IsMenu(
580 HMENU hMenu)
581 {
582 UNIMPLEMENTED;
583 return FALSE;
584 }
585
586
587 /*
588 * @unimplemented
589 */
590 HMENU
591 STDCALL
592 LoadMenuA(
593 HINSTANCE hInstance,
594 LPCSTR lpMenuName)
595 {
596 UNIMPLEMENTED;
597 return (HMENU)0;
598 }
599
600
601 /*
602 * @unimplemented
603 */
604 HMENU
605 STDCALL
606 LoadMenuIndirectA(
607 CONST MENUTEMPLATE *lpMenuTemplate)
608 {
609 UNIMPLEMENTED;
610 return (HMENU)0;
611 }
612
613
614 /*
615 * @unimplemented
616 */
617 HMENU
618 STDCALL
619 LoadMenuIndirectW(
620 CONST MENUTEMPLATE *lpMenuTemplate)
621 {
622 UNIMPLEMENTED;
623 return (HMENU)0;
624 }
625
626
627 /*
628 * @unimplemented
629 */
630 HMENU
631 STDCALL
632 LoadMenuW(
633 HINSTANCE hInstance,
634 LPCWSTR lpMenuName)
635 {
636 UNIMPLEMENTED;
637 return (HMENU)0;
638 }
639
640
641 /*
642 * @unimplemented
643 */
644 int
645 STDCALL
646 MenuItemFromPoint(
647 HWND hWnd,
648 HMENU hMenu,
649 POINT ptScreen)
650 {
651 UNIMPLEMENTED;
652 return 0;
653 }
654
655
656 /*
657 * @unimplemented
658 */
659 WINBOOL
660 STDCALL
661 ModifyMenuA(
662 HMENU hMnu,
663 UINT uPosition,
664 UINT uFlags,
665 UINT_PTR uIDNewItem,
666 LPCSTR lpNewItem)
667 {
668 UNIMPLEMENTED;
669 return FALSE;
670 }
671
672
673 /*
674 * @unimplemented
675 */
676 WINBOOL
677 STDCALL
678 ModifyMenuW(
679 HMENU hMnu,
680 UINT uPosition,
681 UINT uFlags,
682 UINT_PTR uIDNewItem,
683 LPCWSTR lpNewItem)
684 {
685 UNIMPLEMENTED;
686 return FALSE;
687 }
688
689
690 /*
691 * @unimplemented
692 */
693 WINBOOL
694 STDCALL
695 RemoveMenu(
696 HMENU hMenu,
697 UINT uPosition,
698 UINT uFlags)
699 {
700 UNIMPLEMENTED;
701 return FALSE;
702 }
703
704
705 /*
706 * @unimplemented
707 */
708 WINBOOL
709 STDCALL
710 SetMenu(
711 HWND hWnd,
712 HMENU hMenu)
713 {
714 UNIMPLEMENTED;
715 return FALSE;
716 }
717
718
719 /*
720 * @unimplemented
721 */
722 WINBOOL
723 STDCALL
724 SetMenuDefaultItem(
725 HMENU hMenu,
726 UINT uItem,
727 UINT fByPos)
728 {
729 UNIMPLEMENTED;
730 return FALSE;
731 }
732
733
734 /*
735 * @unimplemented
736 */
737 WINBOOL
738 STDCALL
739 SetMenuInfo(
740 HMENU hmenu,
741 LPCMENUINFO lpcmi)
742 {
743 UNIMPLEMENTED;
744 return FALSE;
745 }
746
747
748 /*
749 * @unimplemented
750 */
751 WINBOOL
752 STDCALL
753 SetMenuItemBitmaps(
754 HMENU hMenu,
755 UINT uPosition,
756 UINT uFlags,
757 HBITMAP hBitmapUnchecked,
758 HBITMAP hBitmapChecked)
759 {
760 UNIMPLEMENTED;
761 return FALSE;
762 }
763
764
765 /*
766 * @unimplemented
767 */
768 WINBOOL
769 STDCALL
770 SetMenuItemInfoA(
771 HMENU hMenu,
772 UINT uItem,
773 WINBOOL fByPosition,
774 LPMENUITEMINFO lpmii)
775 {
776 UNIMPLEMENTED;
777 return FALSE;
778 }
779
780
781 /*
782 * @unimplemented
783 */
784 WINBOOL
785 STDCALL
786 SetMenuItemInfoW(
787 HMENU hMenu,
788 UINT uItem,
789 WINBOOL fByPosition,
790 LPMENUITEMINFO lpmii)
791 {
792 UNIMPLEMENTED;
793 return FALSE;
794 }
795
796
797 /*
798 * @unimplemented
799 */
800 WINBOOL
801 STDCALL
802 TrackPopupMenu(
803 HMENU hMenu,
804 UINT uFlags,
805 int x,
806 int y,
807 int nReserved,
808 HWND hWnd,
809 CONST RECT *prcRect)
810 {
811 UNIMPLEMENTED;
812 return FALSE;
813 }
814
815
816 /*
817 * @unimplemented
818 */
819 WINBOOL
820 STDCALL
821 TrackPopupMenuEx(
822 HMENU hmenu,
823 UINT fuFlags,
824 int x,
825 int y,
826 HWND hwnd,
827 LPTPMPARAMS lptpm)
828 {
829 UNIMPLEMENTED;
830 return FALSE;
831 }