2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
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.
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.
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.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
24 * FILE: subsys/win32k/ntuser/menu.c
25 * PROGRAMER: Thomas Weidenmueller (w3seek@users.sourceforge.net)
27 * 07/30/2003 CSH Created
29 /* INCLUDES ******************************************************************/
37 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
);
41 /* STATIC FUNCTION ***********************************************************/
49 PROSMENUITEMINFO UnsafeItemInfo
,
56 PROSMENUINFO UnsafeMenuInfo
,
59 /* INTERNAL ******************************************************************/
61 /* maximum number of menu items a menu can contain */
62 #define MAX_MENU_ITEMS (0x4000)
63 #define MAX_GOINTOSUBMENU (0x10)
65 #define UpdateMenuItemState(state, change) \
67 if((change) & MFS_DISABLED) { \
68 (state) |= MFS_DISABLED; \
70 (state) &= ~MFS_DISABLED; \
72 if((change) & MFS_CHECKED) { \
73 (state) |= MFS_CHECKED; \
75 (state) &= ~MFS_CHECKED; \
77 if((change) & MFS_HILITE) { \
78 (state) |= MFS_HILITE; \
80 (state) &= ~MFS_HILITE; \
82 if((change) & MFS_DEFAULT) { \
83 (state) |= MFS_DEFAULT; \
85 (state) &= ~MFS_DEFAULT; \
87 if((change) & MF_MOUSESELECT) { \
88 (state) |= MF_MOUSESELECT; \
90 (state) &= ~MF_MOUSESELECT; \
94 #define FreeMenuText(MenuItem) \
96 if((MENU_ITEM_TYPE((MenuItem)->fType) == MF_STRING) && \
97 (MenuItem)->Text.Length) { \
98 ExFreePoolWithTag((MenuItem)->Text.Buffer, TAG_STRING); \
102 #define InRect(r, x, y) \
103 ( ( ((r).right >= x)) && \
104 ( ((r).left <= x)) && \
105 ( ((r).bottom >= y)) && \
111 return(STATUS_SUCCESS
);
115 CleanupMenuImpl(VOID
)
117 return(STATUS_SUCCESS
);
120 PMENU_OBJECT FASTCALL
UserGetMenuObject(HMENU hMenu
)
126 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
130 Menu
= (PMENU_OBJECT
)UserGetObject(gHandleTable
, hMenu
, otMenu
);
133 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
137 ASSERT(USER_BODY_TO_HEADER(Menu
)->RefCount
>= 0);
144 DumpMenuItemList(PMENU_ITEM MenuItem
)
149 if(MenuItem
->Text
.Length
)
150 DbgPrint(" %d. %wZ\n", ++cnt
, &MenuItem
->Text
);
152 DbgPrint(" %d. NO TEXT dwTypeData==%d\n", ++cnt
, (DWORD
)MenuItem
->Text
.Buffer
);
154 if(MFT_BITMAP
& MenuItem
->fType
)
155 DbgPrint("MFT_BITMAP ");
156 if(MFT_MENUBARBREAK
& MenuItem
->fType
)
157 DbgPrint("MFT_MENUBARBREAK ");
158 if(MFT_MENUBREAK
& MenuItem
->fType
)
159 DbgPrint("MFT_MENUBREAK ");
160 if(MFT_OWNERDRAW
& MenuItem
->fType
)
161 DbgPrint("MFT_OWNERDRAW ");
162 if(MFT_RADIOCHECK
& MenuItem
->fType
)
163 DbgPrint("MFT_RADIOCHECK ");
164 if(MFT_RIGHTJUSTIFY
& MenuItem
->fType
)
165 DbgPrint("MFT_RIGHTJUSTIFY ");
166 if(MFT_SEPARATOR
& MenuItem
->fType
)
167 DbgPrint("MFT_SEPARATOR ");
168 if(MFT_STRING
& MenuItem
->fType
)
169 DbgPrint("MFT_STRING ");
170 DbgPrint("\n fState=");
171 if(MFS_DISABLED
& MenuItem
->fState
)
172 DbgPrint("MFS_DISABLED ");
174 DbgPrint("MFS_ENABLED ");
175 if(MFS_CHECKED
& MenuItem
->fState
)
176 DbgPrint("MFS_CHECKED ");
178 DbgPrint("MFS_UNCHECKED ");
179 if(MFS_HILITE
& MenuItem
->fState
)
180 DbgPrint("MFS_HILITE ");
182 DbgPrint("MFS_UNHILITE ");
183 if(MFS_DEFAULT
& MenuItem
->fState
)
184 DbgPrint("MFS_DEFAULT ");
185 if(MFS_GRAYED
& MenuItem
->fState
)
186 DbgPrint("MFS_GRAYED ");
187 DbgPrint("\n wId=%d\n", MenuItem
->wID
);
188 MenuItem
= MenuItem
->Next
;
190 DbgPrint("Entries: %d\n", cnt
);
195 PMENU_OBJECT FASTCALL
196 IntGetMenuObject(HMENU hMenu
)
198 PMENU_OBJECT Menu
= UserGetMenuObject(hMenu
);
201 ASSERT(USER_BODY_TO_HEADER(Menu
)->RefCount
>= 0);
203 USER_BODY_TO_HEADER(Menu
)->RefCount
++;
209 IntFreeMenuItem(PMENU_OBJECT Menu
, PMENU_ITEM MenuItem
, BOOL bRecurse
)
211 FreeMenuText(MenuItem
);
212 if(bRecurse
&& MenuItem
->hSubMenu
)
214 PMENU_OBJECT SubMenu
;
215 SubMenu
= UserGetMenuObject(MenuItem
->hSubMenu
);
218 IntDestroyMenuObject(SubMenu
, bRecurse
, TRUE
);
223 ExFreePool(MenuItem
);
229 IntRemoveMenuItem(PMENU_OBJECT Menu
, UINT uPosition
, UINT uFlags
,
232 PMENU_ITEM PrevMenuItem
, MenuItem
;
233 if(IntGetMenuItemByFlag(Menu
, uPosition
, uFlags
, &Menu
, &MenuItem
,
239 PrevMenuItem
->Next
= MenuItem
->Next
;
242 Menu
->MenuItemList
= MenuItem
->Next
;
244 Menu
->MenuInfo
.MenuItemCount
--;
245 return IntFreeMenuItem(Menu
, MenuItem
, bRecurse
);
252 IntDeleteMenuItems(PMENU_OBJECT Menu
, BOOL bRecurse
)
256 PMENU_ITEM CurItem
= Menu
->MenuItemList
;
259 NextItem
= CurItem
->Next
;
260 IntFreeMenuItem(Menu
, CurItem
, bRecurse
);
264 Menu
->MenuInfo
.MenuItemCount
= 0;
265 Menu
->MenuItemList
= NULL
;
270 IntDestroyMenuObject(PMENU_OBJECT Menu
,
271 BOOL bRecurse
, BOOL RemoveFromProcess
)
275 PWINDOW_OBJECT Window
;
276 PWINSTATION_OBJECT WindowStation
;
279 /* remove all menu items */
280 IntDeleteMenuItems(Menu
, bRecurse
); /* do not destroy submenus */
282 if(RemoveFromProcess
)
284 RemoveEntryList(&Menu
->ListEntry
);
287 Status
= ObReferenceObjectByHandle(Menu
->Process
->Win32WindowStation
,
289 ExWindowStationObjectType
,
291 (PVOID
*)&WindowStation
,
293 if(NT_SUCCESS(Status
))
295 if (Menu
->MenuInfo
.Wnd
)
297 Window
= UserGetWindowObject(Menu
->MenuInfo
.Wnd
);
300 Window
->Wnd
->IDMenu
= 0;
303 // UserDereferenceObject(Menu);
304 BOOL ret
= UserDeleteObject(Menu
->MenuInfo
.Self
, otMenu
);
305 ObDereferenceObject(WindowStation
);
312 PMENU_OBJECT FASTCALL
313 IntCreateMenu(PHANDLE Handle
, BOOL IsMenuBar
)
316 PW32PROCESS CurrentWin32Process
;
318 Menu
= (PMENU_OBJECT
)UserCreateObject(
319 gHandleTable
, Handle
,
320 otMenu
, sizeof(MENU_OBJECT
));
328 Menu
->Process
= PsGetCurrentProcess();
329 Menu
->RtoL
= FALSE
; /* default */
330 Menu
->MenuInfo
.cbSize
= sizeof(MENUINFO
); /* not used */
331 Menu
->MenuInfo
.fMask
= 0; /* not used */
332 Menu
->MenuInfo
.dwStyle
= 0; /* FIXME */
333 Menu
->MenuInfo
.cyMax
= 0; /* default */
334 Menu
->MenuInfo
.hbrBack
= NULL
; /* no brush */
335 Menu
->MenuInfo
.dwContextHelpID
= 0; /* default */
336 Menu
->MenuInfo
.dwMenuData
= 0; /* default */
337 Menu
->MenuInfo
.Self
= *Handle
;
338 Menu
->MenuInfo
.FocusedItem
= NO_SELECTED_ITEM
;
339 Menu
->MenuInfo
.Flags
= (IsMenuBar
? 0 : MF_POPUP
);
340 Menu
->MenuInfo
.Wnd
= NULL
;
341 Menu
->MenuInfo
.WndOwner
= NULL
;
342 Menu
->MenuInfo
.Height
= 0;
343 Menu
->MenuInfo
.Width
= 0;
344 Menu
->MenuInfo
.TimeToHide
= FALSE
;
346 Menu
->MenuInfo
.MenuItemCount
= 0;
347 Menu
->MenuItemList
= NULL
;
349 /* Insert menu item into process menu handle list */
350 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
351 InsertTailList(&CurrentWin32Process
->MenuListHead
, &Menu
->ListEntry
);
357 IntCloneMenuItems(PMENU_OBJECT Destination
, PMENU_OBJECT Source
)
359 PMENU_ITEM MenuItem
, NewMenuItem
= NULL
;
360 PMENU_ITEM Old
= NULL
;
362 if(!Source
->MenuInfo
.MenuItemCount
)
365 MenuItem
= Source
->MenuItemList
;
370 NewMenuItem
->Next
= MenuItem
;
371 NewMenuItem
= ExAllocatePoolWithTag(PagedPool
, sizeof(MENU_ITEM
), TAG_MENUITEM
);
374 NewMenuItem
->fType
= MenuItem
->fType
;
375 NewMenuItem
->fState
= MenuItem
->fState
;
376 NewMenuItem
->wID
= MenuItem
->wID
;
377 NewMenuItem
->hSubMenu
= MenuItem
->hSubMenu
;
378 NewMenuItem
->hbmpChecked
= MenuItem
->hbmpChecked
;
379 NewMenuItem
->hbmpUnchecked
= MenuItem
->hbmpUnchecked
;
380 NewMenuItem
->dwItemData
= MenuItem
->dwItemData
;
381 if((MENU_ITEM_TYPE(NewMenuItem
->fType
) == MF_STRING
))
383 if(MenuItem
->Text
.Length
)
385 NewMenuItem
->Text
.Length
= 0;
386 NewMenuItem
->Text
.MaximumLength
= MenuItem
->Text
.MaximumLength
;
387 NewMenuItem
->Text
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, MenuItem
->Text
.MaximumLength
, TAG_STRING
);
388 if(!NewMenuItem
->Text
.Buffer
)
390 ExFreePoolWithTag(NewMenuItem
, TAG_MENUITEM
);
393 RtlCopyUnicodeString(&NewMenuItem
->Text
, &MenuItem
->Text
);
397 NewMenuItem
->Text
.Buffer
= MenuItem
->Text
.Buffer
;
402 NewMenuItem
->Text
.Buffer
= MenuItem
->Text
.Buffer
;
404 NewMenuItem
->hbmpItem
= MenuItem
->hbmpItem
;
406 NewMenuItem
->Next
= NULL
;
408 Old
->Next
= NewMenuItem
;
410 Destination
->MenuItemList
= NewMenuItem
;
411 Destination
->MenuInfo
.MenuItemCount
++;
412 MenuItem
= MenuItem
->Next
;
418 PMENU_OBJECT FASTCALL
419 IntCloneMenu(PMENU_OBJECT Source
)
421 PW32PROCESS CurrentWin32Process
;
428 Menu
= (PMENU_OBJECT
)UserCreateObject(
429 gHandleTable
, &hMenu
,
430 otMenu
, sizeof(MENU_OBJECT
));
435 Menu
->Process
= PsGetCurrentProcess();
436 Menu
->RtoL
= Source
->RtoL
;
437 Menu
->MenuInfo
.cbSize
= sizeof(MENUINFO
); /* not used */
438 Menu
->MenuInfo
.fMask
= Source
->MenuInfo
.fMask
;
439 Menu
->MenuInfo
.dwStyle
= Source
->MenuInfo
.dwStyle
;
440 Menu
->MenuInfo
.cyMax
= Source
->MenuInfo
.cyMax
;
441 Menu
->MenuInfo
.hbrBack
= Source
->MenuInfo
.hbrBack
;
442 Menu
->MenuInfo
.dwContextHelpID
= Source
->MenuInfo
.dwContextHelpID
;
443 Menu
->MenuInfo
.dwMenuData
= Source
->MenuInfo
.dwMenuData
;
444 Menu
->MenuInfo
.Self
= hMenu
;
445 Menu
->MenuInfo
.FocusedItem
= NO_SELECTED_ITEM
;
446 Menu
->MenuInfo
.Wnd
= NULL
;
447 Menu
->MenuInfo
.WndOwner
= NULL
;
448 Menu
->MenuInfo
.Height
= 0;
449 Menu
->MenuInfo
.Width
= 0;
450 Menu
->MenuInfo
.TimeToHide
= FALSE
;
452 Menu
->MenuInfo
.MenuItemCount
= 0;
453 Menu
->MenuItemList
= NULL
;
455 /* Insert menu item into process menu handle list */
456 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
457 InsertTailList(&CurrentWin32Process
->MenuListHead
, &Menu
->ListEntry
);
459 IntCloneMenuItems(Menu
, Source
);
465 IntSetMenuFlagRtoL(PMENU_OBJECT Menu
)
472 IntSetMenuContextHelpId(PMENU_OBJECT Menu
, DWORD dwContextHelpId
)
474 Menu
->MenuInfo
.dwContextHelpID
= dwContextHelpId
;
479 IntGetMenuInfo(PMENU_OBJECT Menu
, PROSMENUINFO lpmi
)
481 if(lpmi
->fMask
& MIM_BACKGROUND
)
482 lpmi
->hbrBack
= Menu
->MenuInfo
.hbrBack
;
483 if(lpmi
->fMask
& MIM_HELPID
)
484 lpmi
->dwContextHelpID
= Menu
->MenuInfo
.dwContextHelpID
;
485 if(lpmi
->fMask
& MIM_MAXHEIGHT
)
486 lpmi
->cyMax
= Menu
->MenuInfo
.cyMax
;
487 if(lpmi
->fMask
& MIM_MENUDATA
)
488 lpmi
->dwMenuData
= Menu
->MenuInfo
.dwMenuData
;
489 if(lpmi
->fMask
& MIM_STYLE
)
490 lpmi
->dwStyle
= Menu
->MenuInfo
.dwStyle
;
491 if (sizeof(MENUINFO
) < lpmi
->cbSize
)
493 RtlCopyMemory((char *) lpmi
+ sizeof(MENUINFO
),
494 (char *) &Menu
->MenuInfo
+ sizeof(MENUINFO
),
495 lpmi
->cbSize
- sizeof(MENUINFO
));
497 if (sizeof(ROSMENUINFO
) == lpmi
->cbSize
)
499 lpmi
->maxBmpSize
.cx
= Menu
->MenuInfo
.maxBmpSize
.cx
;
500 lpmi
->maxBmpSize
.cy
= Menu
->MenuInfo
.maxBmpSize
.cy
;
507 IntIsMenu(HMENU hMenu
)
511 if((Menu
= UserGetMenuObject(hMenu
)))
520 IntSetMenuInfo(PMENU_OBJECT Menu
, PROSMENUINFO lpmi
)
522 if(lpmi
->fMask
& MIM_BACKGROUND
)
523 Menu
->MenuInfo
.hbrBack
= lpmi
->hbrBack
;
524 if(lpmi
->fMask
& MIM_HELPID
)
525 Menu
->MenuInfo
.dwContextHelpID
= lpmi
->dwContextHelpID
;
526 if(lpmi
->fMask
& MIM_MAXHEIGHT
)
527 Menu
->MenuInfo
.cyMax
= lpmi
->cyMax
;
528 if(lpmi
->fMask
& MIM_MENUDATA
)
529 Menu
->MenuInfo
.dwMenuData
= lpmi
->dwMenuData
;
530 if(lpmi
->fMask
& MIM_STYLE
)
531 Menu
->MenuInfo
.dwStyle
= lpmi
->dwStyle
;
532 if(lpmi
->fMask
& MIM_APPLYTOSUBMENUS
)
536 if (sizeof(MENUINFO
) < lpmi
->cbSize
)
538 Menu
->MenuInfo
.FocusedItem
= lpmi
->FocusedItem
;
539 Menu
->MenuInfo
.Height
= lpmi
->Height
;
540 Menu
->MenuInfo
.Width
= lpmi
->Width
;
541 Menu
->MenuInfo
.Wnd
= lpmi
->Wnd
;
542 Menu
->MenuInfo
.WndOwner
= lpmi
->WndOwner
;
543 Menu
->MenuInfo
.TimeToHide
= lpmi
->TimeToHide
;
545 if (sizeof(ROSMENUINFO
) == lpmi
->cbSize
)
547 Menu
->MenuInfo
.maxBmpSize
.cx
= lpmi
->maxBmpSize
.cx
;
548 Menu
->MenuInfo
.maxBmpSize
.cy
= lpmi
->maxBmpSize
.cy
;
555 IntGetMenuItemByFlag(PMENU_OBJECT Menu
, UINT uSearchBy
, UINT fFlag
,
556 PMENU_OBJECT
*SubMenu
, PMENU_ITEM
*MenuItem
,
557 PMENU_ITEM
*PrevMenuItem
)
559 PMENU_ITEM PrevItem
= NULL
;
560 PMENU_ITEM CurItem
= Menu
->MenuItemList
;
564 if(MF_BYPOSITION
& fFlag
)
567 while(CurItem
&& (p
> 0))
570 CurItem
= CurItem
->Next
;
578 *PrevMenuItem
= PrevItem
;
585 *PrevMenuItem
= NULL
; /* ? */
589 return uSearchBy
- p
;
596 if(CurItem
->wID
== uSearchBy
)
601 *PrevMenuItem
= PrevItem
;
609 if(CurItem
->fType
& MF_POPUP
)
611 PMENU_OBJECT NewMenu
= UserGetMenuObject(CurItem
->hSubMenu
);
614 ret
= IntGetMenuItemByFlag(NewMenu
, uSearchBy
, fFlag
,
615 SubMenu
, MenuItem
, PrevMenuItem
);
624 CurItem
= CurItem
->Next
;
633 IntInsertMenuItemToList(PMENU_OBJECT Menu
, PMENU_ITEM MenuItem
, int pos
)
636 PMENU_ITEM LastItem
= NULL
;
639 CurItem
= Menu
->MenuItemList
;
640 while(CurItem
&& (pos
!= 0))
643 CurItem
= CurItem
->Next
;
650 /* insert the item after LastItem */
651 LastItem
->Next
= MenuItem
;
655 /* insert at the beginning */
656 Menu
->MenuItemList
= MenuItem
;
658 MenuItem
->Next
= CurItem
;
659 Menu
->MenuInfo
.MenuItemCount
++;
665 IntGetMenuItemInfo(PMENU_OBJECT Menu
, /* UNUSED PARAM!! */
666 PMENU_ITEM MenuItem
, PROSMENUITEMINFO lpmii
)
670 if(lpmii
->fMask
& (MIIM_FTYPE
| MIIM_TYPE
))
672 lpmii
->fType
= MenuItem
->fType
;
674 if(lpmii
->fMask
& MIIM_BITMAP
)
676 lpmii
->hbmpItem
= MenuItem
->hbmpItem
;
678 if(lpmii
->fMask
& MIIM_CHECKMARKS
)
680 lpmii
->hbmpChecked
= MenuItem
->hbmpChecked
;
681 lpmii
->hbmpUnchecked
= MenuItem
->hbmpUnchecked
;
683 if(lpmii
->fMask
& MIIM_DATA
)
685 lpmii
->dwItemData
= MenuItem
->dwItemData
;
687 if(lpmii
->fMask
& MIIM_ID
)
689 lpmii
->wID
= MenuItem
->wID
;
691 if(lpmii
->fMask
& MIIM_STATE
)
693 lpmii
->fState
= MenuItem
->fState
;
695 if(lpmii
->fMask
& MIIM_SUBMENU
)
697 lpmii
->hSubMenu
= MenuItem
->hSubMenu
;
700 if ((lpmii
->fMask
& MIIM_STRING
) ||
701 ((lpmii
->fMask
& MIIM_TYPE
) && (MENU_ITEM_TYPE(lpmii
->fType
) == MF_STRING
)))
703 if (lpmii
->dwTypeData
== NULL
)
705 lpmii
->cch
= MenuItem
->Text
.Length
/ sizeof(WCHAR
);
709 Status
= MmCopyToCaller(lpmii
->dwTypeData
, MenuItem
->Text
.Buffer
,
710 min(lpmii
->cch
* sizeof(WCHAR
),
711 MenuItem
->Text
.MaximumLength
));
712 if (! NT_SUCCESS(Status
))
714 SetLastNtError(Status
);
720 if (sizeof(ROSMENUITEMINFO
) == lpmii
->cbSize
)
722 lpmii
->Rect
= MenuItem
->Rect
;
723 lpmii
->XTab
= MenuItem
->XTab
;
724 lpmii
->Text
= MenuItem
->Text
.Buffer
;
731 IntSetMenuItemInfo(PMENU_OBJECT MenuObject
, PMENU_ITEM MenuItem
, PROSMENUITEMINFO lpmii
)
733 PMENU_OBJECT SubMenuObject
;
734 UINT fTypeMask
= (MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_MENUBREAK
| MFT_OWNERDRAW
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_SEPARATOR
| MF_POPUP
);
736 if(!MenuItem
|| !MenuObject
|| !lpmii
)
740 if( lpmii
->fType
& ~fTypeMask
)
742 DbgPrint("IntSetMenuItemInfo invalid fType flags %x\n", lpmii
->fType
& ~fTypeMask
);
743 lpmii
->fMask
&= ~(MIIM_TYPE
| MIIM_FTYPE
);
745 if(lpmii
->fMask
& MIIM_TYPE
)
747 if(lpmii
->fMask
& ( MIIM_STRING
| MIIM_FTYPE
| MIIM_BITMAP
))
749 DbgPrint("IntSetMenuItemInfo: Invalid combination of fMask bits used\n");
750 /* this does not happen on Win9x/ME */
751 SetLastNtError( ERROR_INVALID_PARAMETER
);
755 * Delete the menu item type when changing type from
758 if (MenuItem
->fType
!= lpmii
->fType
&&
759 MENU_ITEM_TYPE(MenuItem
->fType
) == MFT_STRING
)
761 FreeMenuText(MenuItem
);
762 RtlInitUnicodeString(&MenuItem
->Text
, NULL
);
764 if(lpmii
->fType
& MFT_BITMAP
)
767 MenuItem
->hbmpItem
= lpmii
->hbmpItem
;
769 { /* Win 9x/Me stuff */
770 MenuItem
->hbmpItem
= (HBITMAP
)((ULONG_PTR
)(LOWORD(lpmii
->dwTypeData
)));
773 MenuItem
->fType
|= lpmii
->fType
;
775 if (lpmii
->fMask
& MIIM_FTYPE
)
777 if(( lpmii
->fType
& MFT_BITMAP
))
779 DbgPrint("IntSetMenuItemInfo: Can not use FTYPE and MFT_BITMAP.\n");
780 SetLastNtError( ERROR_INVALID_PARAMETER
);
783 MenuItem
->fType
|= lpmii
->fType
; /* Need to save all the flags, this fixed MFT_RIGHTJUSTIFY */
785 if(lpmii
->fMask
& MIIM_BITMAP
)
787 MenuItem
->hbmpItem
= lpmii
->hbmpItem
;
789 if(lpmii
->fMask
& MIIM_CHECKMARKS
)
791 MenuItem
->hbmpChecked
= lpmii
->hbmpChecked
;
792 MenuItem
->hbmpUnchecked
= lpmii
->hbmpUnchecked
;
794 if(lpmii
->fMask
& MIIM_DATA
)
796 MenuItem
->dwItemData
= lpmii
->dwItemData
;
798 if(lpmii
->fMask
& MIIM_ID
)
800 MenuItem
->wID
= lpmii
->wID
;
802 if(lpmii
->fMask
& MIIM_STATE
)
804 /* remove MFS_DEFAULT flag from all other menu items if this item
805 has the MFS_DEFAULT state */
806 if(lpmii
->fState
& MFS_DEFAULT
)
807 UserSetMenuDefaultItem(MenuObject
, -1, 0);
808 /* update the menu item state flags */
809 UpdateMenuItemState(MenuItem
->fState
, lpmii
->fState
);
812 if(lpmii
->fMask
& MIIM_SUBMENU
)
814 MenuItem
->hSubMenu
= lpmii
->hSubMenu
;
815 /* Make sure the submenu is marked as a popup menu */
816 if (MenuItem
->hSubMenu
)
818 SubMenuObject
= UserGetMenuObject(MenuItem
->hSubMenu
);
819 if (SubMenuObject
!= NULL
)
821 SubMenuObject
->MenuInfo
.Flags
|= MF_POPUP
;
822 MenuItem
->fType
|= MF_POPUP
;
826 MenuItem
->fType
&= ~MF_POPUP
;
831 MenuItem
->fType
&= ~MF_POPUP
;
835 if ((lpmii
->fMask
& MIIM_STRING
) ||
836 ((lpmii
->fMask
& MIIM_TYPE
) && (MENU_ITEM_TYPE(lpmii
->fType
) == MF_STRING
)))
838 FreeMenuText(MenuItem
);
840 if(lpmii
->dwTypeData
&& lpmii
->cch
)
842 UNICODE_STRING Source
;
845 Source
.MaximumLength
= lpmii
->cch
* sizeof(WCHAR
);
846 Source
.Buffer
= lpmii
->dwTypeData
;
848 MenuItem
->Text
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(
849 PagedPool
, Source
.Length
+ sizeof(WCHAR
), TAG_STRING
);
850 if(MenuItem
->Text
.Buffer
!= NULL
)
852 MenuItem
->Text
.Length
= 0;
853 MenuItem
->Text
.MaximumLength
= Source
.Length
+ sizeof(WCHAR
);
854 RtlCopyUnicodeString(&MenuItem
->Text
, &Source
);
855 MenuItem
->Text
.Buffer
[MenuItem
->Text
.Length
/ sizeof(WCHAR
)] = 0;
859 RtlInitUnicodeString(&MenuItem
->Text
, NULL
);
864 if (0 == (MenuObject
->MenuInfo
.Flags
& MF_SYSMENU
))
866 MenuItem
->fType
|= MF_SEPARATOR
;
868 RtlInitUnicodeString(&MenuItem
->Text
, NULL
);
872 if (sizeof(ROSMENUITEMINFO
) == lpmii
->cbSize
)
874 MenuItem
->Rect
= lpmii
->Rect
;
875 MenuItem
->XTab
= lpmii
->XTab
;
876 lpmii
->Text
= MenuItem
->Text
.Buffer
; /* Send back new allocated string or zero */
883 IntInsertMenuItem(PMENU_OBJECT MenuObject
, UINT uItem
, BOOL fByPosition
,
884 PROSMENUITEMINFO ItemInfo
)
886 int pos
= (int)uItem
;
888 PMENU_OBJECT SubMenu
= NULL
;
890 if (MAX_MENU_ITEMS
<= MenuObject
->MenuInfo
.MenuItemCount
)
892 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
898 SubMenu
= MenuObject
;
899 /* calculate position */
900 if(MenuObject
->MenuInfo
.MenuItemCount
< pos
)
902 pos
= MenuObject
->MenuInfo
.MenuItemCount
;
907 pos
= IntGetMenuItemByFlag(MenuObject
, uItem
, MF_BYCOMMAND
, &SubMenu
, NULL
, NULL
);
911 /* default to last position of menu */
912 SubMenu
= MenuObject
;
913 pos
= MenuObject
->MenuInfo
.MenuItemCount
;
922 MenuItem
= ExAllocatePoolWithTag(PagedPool
, sizeof(MENU_ITEM
), TAG_MENUITEM
);
923 if (NULL
== MenuItem
)
925 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
929 MenuItem
->fType
= MFT_STRING
;
930 MenuItem
->fState
= MFS_ENABLED
| MFS_UNCHECKED
;
932 MenuItem
->hSubMenu
= (HMENU
)0;
933 MenuItem
->hbmpChecked
= (HBITMAP
)0;
934 MenuItem
->hbmpUnchecked
= (HBITMAP
)0;
935 MenuItem
->dwItemData
= 0;
936 RtlInitUnicodeString(&MenuItem
->Text
, NULL
);
937 MenuItem
->hbmpItem
= (HBITMAP
)0;
939 if(!IntSetMenuItemInfo(SubMenu
, MenuItem
, ItemInfo
))
941 ExFreePoolWithTag(MenuItem
, TAG_MENUITEM
);
945 /* Force size recalculation! */
946 MenuObject
->MenuInfo
.Height
= 0;
948 pos
= IntInsertMenuItemToList(SubMenu
, MenuItem
, pos
);
950 DPRINT("IntInsertMenuItemToList = %i\n", pos
);
956 IntEnableMenuItem(PMENU_OBJECT MenuObject
, UINT uIDEnableItem
, UINT uEnable
)
959 UINT res
= IntGetMenuItemByFlag(MenuObject
, uIDEnableItem
, uEnable
, NULL
, &MenuItem
, NULL
);
960 if(!MenuItem
|| (res
== (UINT
)-1))
965 res
= MenuItem
->fState
& (MF_GRAYED
| MF_DISABLED
);
967 if(uEnable
& MF_DISABLED
)
969 MenuItem
->fState
|= MF_DISABLED
;
970 MenuItem
->fState
|= uEnable
& MF_GRAYED
;
974 if(uEnable
& MF_GRAYED
)
976 MenuItem
->fState
|= (MF_GRAYED
| MF_DISABLED
);
980 MenuItem
->fState
&= ~(MF_DISABLED
| MF_GRAYED
);
989 IntBuildMenuItemList(PMENU_OBJECT MenuObject
, PVOID Buffer
, ULONG nMax
)
995 PMENU_ITEM CurItem
= MenuObject
->MenuItemList
;
1002 if (nMax
< MenuObject
->MenuInfo
.MenuItemCount
* sizeof(ROSMENUITEMINFO
))
1006 StrOut
= (PWCHAR
)((char *) Buffer
+ MenuObject
->MenuInfo
.MenuItemCount
1007 * sizeof(ROSMENUITEMINFO
));
1008 nMax
-= MenuObject
->MenuInfo
.MenuItemCount
* sizeof(ROSMENUITEMINFO
);
1009 sz
= sizeof(ROSMENUITEMINFO
);
1011 mii
.cbSize
= sizeof(ROSMENUITEMINFO
);
1015 while (NULL
!= CurItem
)
1017 mii
.cch
= CurItem
->Text
.Length
/ sizeof(WCHAR
);
1018 mii
.dwItemData
= CurItem
->dwItemData
;
1019 if (0 != CurItem
->Text
.Length
)
1021 mii
.dwTypeData
= StrOut
;
1025 mii
.dwTypeData
= NULL
;
1027 mii
.fState
= CurItem
->fState
;
1028 mii
.fType
= CurItem
->fType
;
1029 mii
.hbmpChecked
= CurItem
->hbmpChecked
;
1030 mii
.hbmpItem
= CurItem
->hbmpItem
;
1031 mii
.hbmpUnchecked
= CurItem
->hbmpUnchecked
;
1032 mii
.hSubMenu
= CurItem
->hSubMenu
;
1033 mii
.Rect
= CurItem
->Rect
;
1034 mii
.XTab
= CurItem
->XTab
;
1035 mii
.Text
= CurItem
->Text
.Buffer
;
1037 Status
= MmCopyToCaller(Buf
, &mii
, sizeof(ROSMENUITEMINFO
));
1038 if (! NT_SUCCESS(Status
))
1040 SetLastNtError(Status
);
1043 Buf
= (PVOID
)((ULONG_PTR
)Buf
+ sizeof(ROSMENUITEMINFO
));
1045 if (0 != CurItem
->Text
.Length
1046 && (nMax
>= CurItem
->Text
.Length
+ sizeof(WCHAR
)))
1049 Status
= MmCopyToCaller(StrOut
, CurItem
->Text
.Buffer
,
1050 CurItem
->Text
.Length
);
1051 if (! NT_SUCCESS(Status
))
1053 SetLastNtError(Status
);
1056 StrOut
+= CurItem
->Text
.Length
/ sizeof(WCHAR
);
1057 Status
= MmCopyToCaller(StrOut
, &NulByte
, sizeof(WCHAR
));
1058 if (! NT_SUCCESS(Status
))
1060 SetLastNtError(Status
);
1064 nMax
-= CurItem
->Text
.Length
+ sizeof(WCHAR
);
1066 else if (0 != CurItem
->Text
.Length
)
1071 CurItem
= CurItem
->Next
;
1077 while (NULL
!= CurItem
)
1079 res
+= sizeof(ROSMENUITEMINFO
) + CurItem
->Text
.Length
+ sizeof(WCHAR
);
1080 CurItem
= CurItem
->Next
;
1089 IntCheckMenuItem(PMENU_OBJECT MenuObject
, UINT uIDCheckItem
, UINT uCheck
)
1091 PMENU_ITEM MenuItem
;
1094 if((IntGetMenuItemByFlag(MenuObject
, uIDCheckItem
, uCheck
, NULL
, &MenuItem
, NULL
) < 0) || !MenuItem
)
1099 res
= (DWORD
)(MenuItem
->fState
& MF_CHECKED
);
1100 if(uCheck
& MF_CHECKED
)
1102 MenuItem
->fState
|= MF_CHECKED
;
1106 MenuItem
->fState
&= ~MF_CHECKED
;
1113 IntHiliteMenuItem(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
,
1114 UINT uItemHilite
, UINT uHilite
)
1116 PMENU_ITEM MenuItem
;
1117 BOOL res
= IntGetMenuItemByFlag(MenuObject
, uItemHilite
, uHilite
, NULL
, &MenuItem
, NULL
);
1118 if(!MenuItem
|| !res
)
1123 if(uHilite
& MF_HILITE
)
1125 MenuItem
->fState
|= MF_HILITE
;
1129 MenuItem
->fState
&= ~MF_HILITE
;
1132 /* FIXME - update the window's menu */
1138 UserSetMenuDefaultItem(PMENU_OBJECT MenuObject
, UINT uItem
, UINT fByPos
)
1141 PMENU_ITEM MenuItem
= MenuObject
->MenuItemList
;
1143 if(uItem
== (UINT
)-1)
1147 MenuItem
->fState
&= ~MFS_DEFAULT
;
1148 MenuItem
= MenuItem
->Next
;
1160 MenuItem
->fState
|= MFS_DEFAULT
;
1165 MenuItem
->fState
&= ~MFS_DEFAULT
;
1168 MenuItem
= MenuItem
->Next
;
1175 if(!ret
&& (MenuItem
->wID
== uItem
))
1177 MenuItem
->fState
|= MFS_DEFAULT
;
1182 MenuItem
->fState
&= ~MFS_DEFAULT
;
1184 MenuItem
= MenuItem
->Next
;
1192 IntGetMenuDefaultItem(PMENU_OBJECT MenuObject
, UINT fByPos
, UINT gmdiFlags
,
1198 PMENU_OBJECT SubMenuObject
;
1199 PMENU_ITEM MenuItem
= MenuObject
->MenuItemList
;
1203 if(MenuItem
->fState
& MFS_DEFAULT
)
1206 if(!(gmdiFlags
& GMDI_USEDISABLED
) && (MenuItem
->fState
& MFS_DISABLED
))
1212 res
= MenuItem
->wID
;
1214 if((*gismc
< MAX_GOINTOSUBMENU
) && (gmdiFlags
& GMDI_GOINTOPOPUPS
) &&
1218 SubMenuObject
= UserGetMenuObject(MenuItem
->hSubMenu
);
1219 if(!SubMenuObject
|| (SubMenuObject
== MenuObject
))
1223 sres
= IntGetMenuDefaultItem(SubMenuObject
, fByPos
, gmdiFlags
, gismc
);
1233 MenuItem
= MenuItem
->Next
;
1241 co_IntInitTracking(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
, BOOL Popup
,
1244 /* FIXME - hide caret */
1246 if(!(Flags
& TPM_NONOTIFY
))
1247 co_IntSendMessage(Window
->hSelf
, WM_SETCURSOR
, (WPARAM
)Window
->hSelf
, HTCAPTION
);
1249 /* FIXME - send WM_SETCURSOR message */
1251 if(!(Flags
& TPM_NONOTIFY
))
1252 co_IntSendMessage(Window
->hSelf
, WM_INITMENU
, (WPARAM
)Menu
->MenuInfo
.Self
, 0);
1256 co_IntExitTracking(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
, BOOL Popup
,
1259 if(!(Flags
& TPM_NONOTIFY
))
1260 co_IntSendMessage(Window
->hSelf
, WM_EXITMENULOOP
, 0 /* FIXME */, 0);
1262 /* FIXME - Show caret again */
1266 IntTrackMenu(PMENU_OBJECT Menu
, PWINDOW_OBJECT Window
, INT x
, INT y
,
1273 co_IntTrackPopupMenu(PMENU_OBJECT Menu
, PWINDOW_OBJECT Window
,
1274 UINT Flags
, POINT
*Pos
, UINT MenuPos
, RECT
*ExcludeRect
)
1276 co_IntInitTracking(Window
, Menu
, TRUE
, Flags
);
1278 co_IntExitTracking(Window
, Menu
, TRUE
, Flags
);
1283 IntSetMenuItemRect(PMENU_OBJECT Menu
, UINT Item
, BOOL fByPos
, RECT
*rcRect
)
1286 if(IntGetMenuItemByFlag(Menu
, Item
, (fByPos
? MF_BYPOSITION
: MF_BYCOMMAND
),
1287 NULL
, &mi
, NULL
) > -1)
1297 * Internal function. Called when the process is destroyed to free the remaining menu handles.
1300 IntCleanupMenus(struct _EPROCESS
*Process
, PW32PROCESS Win32Process
)
1302 PEPROCESS CurrentProcess
;
1303 PLIST_ENTRY LastHead
= NULL
;
1304 PMENU_OBJECT MenuObject
;
1306 CurrentProcess
= PsGetCurrentProcess();
1307 if (CurrentProcess
!= Process
)
1309 KeAttachProcess(&Process
->Pcb
);
1312 while (Win32Process
->MenuListHead
.Flink
!= &(Win32Process
->MenuListHead
) &&
1313 Win32Process
->MenuListHead
.Flink
!= LastHead
)
1315 LastHead
= Win32Process
->MenuListHead
.Flink
;
1316 MenuObject
= CONTAINING_RECORD(Win32Process
->MenuListHead
.Flink
, MENU_OBJECT
, ListEntry
);
1318 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
1321 if (CurrentProcess
!= Process
)
1329 co_InflateRect(LPRECT rect
, int dx
, int dy
)
1338 intGetTitleBarInfo(PWINDOW_OBJECT pWindowObject
, PTITLEBARINFO bti
)
1342 DWORD dwExStyle
= 0;
1343 BOOLEAN retValue
= TRUE
;
1345 if (bti
->cbSize
== sizeof(TITLEBARINFO
))
1347 RtlZeroMemory(&bti
->rgstate
[0],sizeof(DWORD
)*(CCHILDREN_TITLEBAR
+1));
1349 bti
->rgstate
[0] = STATE_SYSTEM_FOCUSABLE
;
1351 dwStyle
= pWindowObject
->Wnd
->Style
;
1352 dwExStyle
= pWindowObject
->Wnd
->ExStyle
;
1354 bti
->rcTitleBar
.top
= 0;
1355 bti
->rcTitleBar
.left
= 0;
1356 bti
->rcTitleBar
.right
= pWindowObject
->Wnd
->WindowRect
.right
- pWindowObject
->Wnd
->WindowRect
.left
;
1357 bti
->rcTitleBar
.bottom
= pWindowObject
->Wnd
->WindowRect
.bottom
- pWindowObject
->Wnd
->WindowRect
.top
;
1359 /* is it iconiced ? */
1360 if ((dwStyle
& WS_ICONIC
)!=WS_ICONIC
)
1362 /* Remove frame from rectangle */
1363 if (HAS_THICKFRAME( dwStyle
, dwExStyle
))
1365 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXFRAME) and UserGetSystemMetrics(SM_CYFRAME) */
1366 co_InflateRect( &bti
->rcTitleBar
, -UserGetSystemMetrics(SM_CXFRAME
), -UserGetSystemMetrics(SM_CYFRAME
) );
1368 else if (HAS_DLGFRAME( dwStyle
, dwExStyle
))
1370 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXDLGFRAME) and UserGetSystemMetrics(SM_CYDLGFRAME) */
1371 co_InflateRect( &bti
->rcTitleBar
, -UserGetSystemMetrics(SM_CXDLGFRAME
), -UserGetSystemMetrics(SM_CYDLGFRAME
));
1373 else if (HAS_THINFRAME( dwStyle
, dwExStyle
))
1375 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXBORDER) and UserGetSystemMetrics(SM_CYBORDER) */
1376 co_InflateRect( &bti
->rcTitleBar
, -UserGetSystemMetrics(SM_CXBORDER
), -UserGetSystemMetrics(SM_CYBORDER
) );
1379 /* We have additional border information if the window
1380 * is a child (but not an MDI child) */
1381 if ( (dwStyle
& WS_CHILD
) &&
1382 ((dwExStyle
& WS_EX_MDICHILD
) == 0 ) )
1384 if (dwExStyle
& WS_EX_CLIENTEDGE
)
1386 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXEDGE) and UserGetSystemMetrics(SM_CYEDGE) */
1387 co_InflateRect (&bti
->rcTitleBar
, -UserGetSystemMetrics(SM_CXEDGE
), -UserGetSystemMetrics(SM_CYEDGE
));
1390 if (dwExStyle
& WS_EX_STATICEDGE
)
1392 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXBORDER) and UserGetSystemMetrics(SM_CYBORDER) */
1393 co_InflateRect (&bti
->rcTitleBar
, -UserGetSystemMetrics(SM_CXBORDER
), -UserGetSystemMetrics(SM_CYBORDER
));
1398 bti
->rcTitleBar
.top
+= pWindowObject
->Wnd
->WindowRect
.top
;
1399 bti
->rcTitleBar
.left
+= pWindowObject
->Wnd
->WindowRect
.left
;
1400 bti
->rcTitleBar
.right
+= pWindowObject
->Wnd
->WindowRect
.left
;
1402 bti
->rcTitleBar
.bottom
= bti
->rcTitleBar
.top
;
1403 if (dwExStyle
& WS_EX_TOOLWINDOW
)
1405 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CYSMCAPTION) */
1406 bti
->rcTitleBar
.bottom
+= UserGetSystemMetrics(SM_CYSMCAPTION
);
1410 /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CYCAPTION) and UserGetSystemMetrics(SM_CXSIZE) */
1411 bti
->rcTitleBar
.bottom
+= UserGetSystemMetrics(SM_CYCAPTION
);
1412 bti
->rcTitleBar
.left
+= UserGetSystemMetrics(SM_CXSIZE
);
1415 if (dwStyle
& WS_CAPTION
)
1417 bti
->rgstate
[1] = STATE_SYSTEM_INVISIBLE
;
1418 if (dwStyle
& WS_SYSMENU
)
1420 if (!(dwStyle
& (WS_MINIMIZEBOX
|WS_MAXIMIZEBOX
)))
1422 bti
->rgstate
[2] = STATE_SYSTEM_INVISIBLE
;
1423 bti
->rgstate
[3] = STATE_SYSTEM_INVISIBLE
;
1427 if (!(dwStyle
& WS_MINIMIZEBOX
))
1429 bti
->rgstate
[2] = STATE_SYSTEM_UNAVAILABLE
;
1431 if (!(dwStyle
& WS_MAXIMIZEBOX
))
1433 bti
->rgstate
[3] = STATE_SYSTEM_UNAVAILABLE
;
1437 if (!(dwExStyle
& WS_EX_CONTEXTHELP
))
1439 bti
->rgstate
[4] = STATE_SYSTEM_INVISIBLE
;
1441 if (pWindowObject
->Wnd
->Class
->Style
& CS_NOCLOSE
)
1443 bti
->rgstate
[5] = STATE_SYSTEM_UNAVAILABLE
;
1448 bti
->rgstate
[2] = STATE_SYSTEM_INVISIBLE
;
1449 bti
->rgstate
[3] = STATE_SYSTEM_INVISIBLE
;
1450 bti
->rgstate
[4] = STATE_SYSTEM_INVISIBLE
;
1451 bti
->rgstate
[5] = STATE_SYSTEM_INVISIBLE
;
1456 bti
->rgstate
[0] |= STATE_SYSTEM_INVISIBLE
;
1461 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1468 /* FUNCTIONS *****************************************************************/
1476 NtUserBuildMenuItemList(
1484 DECLARE_RETURN(DWORD
);
1486 DPRINT("Enter NtUserBuildMenuItemList\n");
1487 UserEnterExclusive();
1489 if(!(Menu
= UserGetMenuObject(hMenu
)))
1496 res
= IntBuildMenuItemList(Menu
, Buffer
, nBufSize
);
1500 res
= Menu
->MenuInfo
.MenuItemCount
;
1506 DPRINT("Leave NtUserBuildMenuItemList, ret=%i\n",_ret_
);
1516 NtUserCheckMenuItem(
1522 DECLARE_RETURN(DWORD
);
1524 DPRINT("Enter NtUserCheckMenuItem\n");
1525 UserEnterExclusive();
1527 if(!(Menu
= UserGetMenuObject(hMenu
)))
1532 RETURN( IntCheckMenuItem(Menu
, uIDCheckItem
, uCheck
));
1535 DPRINT("Leave NtUserCheckMenuItem, ret=%i\n",_ret_
);
1541 HMENU FASTCALL
UserCreateMenu(BOOL PopupMenu
)
1543 PWINSTATION_OBJECT WinStaObject
;
1547 PEPROCESS CurrentProcess
= PsGetCurrentProcess();
1549 if (CsrProcess
!= CurrentProcess
)
1552 * CsrProcess does not have a Win32WindowStation
1556 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
1561 if (!NT_SUCCESS(Status
))
1563 DPRINT1("Validation of window station handle (0x%X) failed\n",
1564 CurrentProcess
->Win32WindowStation
);
1565 SetLastNtError(Status
);
1568 Menu
= IntCreateMenu(&Handle
, !PopupMenu
);
1569 ObDereferenceObject(WinStaObject
);
1573 Menu
= IntCreateMenu(&Handle
, !PopupMenu
);
1576 if (Menu
) UserDereferenceObject(Menu
);
1577 return (HMENU
)Handle
;
1591 DECLARE_RETURN(BOOL
);
1593 DPRINT("Enter NtUserDeleteMenu\n");
1594 UserEnterExclusive();
1596 if(!(Menu
= UserGetMenuObject(hMenu
)))
1601 RETURN( IntRemoveMenuItem(Menu
, uPosition
, uFlags
, TRUE
));
1604 DPRINT("Leave NtUserDeleteMenu, ret=%i\n",_ret_
);
1613 NtUserGetTitleBarInfo(
1617 PWINDOW_OBJECT WindowObject
;
1618 TITLEBARINFO bartitleinfo
;
1619 DECLARE_RETURN(BOOLEAN
);
1620 BOOLEAN retValue
= TRUE
;
1622 DPRINT("Enter NtUserGetTitleBarInfo\n");
1623 UserEnterExclusive();
1625 /* Vaildate the windows handle */
1626 if (!(WindowObject
= UserGetWindowObject(hwnd
)))
1628 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1634 /* Copy our usermode buffer bti to local buffer bartitleinfo */
1635 ProbeForRead(bti
, sizeof(TITLEBARINFO
), 1);
1636 RtlCopyMemory(&bartitleinfo
, bti
, sizeof(TITLEBARINFO
));
1638 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1640 /* Fail copy the data */
1641 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1646 /* Get the tile bar info */
1649 retValue
= intGetTitleBarInfo(WindowObject
, &bartitleinfo
);
1654 /* Copy our buffer to user mode buffer bti */
1655 ProbeForWrite(bti
, sizeof(TITLEBARINFO
), 1);
1656 RtlCopyMemory(bti
, &bartitleinfo
, sizeof(TITLEBARINFO
));
1658 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1660 /* Fail copy the data */
1661 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1671 DPRINT("Leave NtUserGetTitleBarInfo, ret=%i\n",_ret_
);
1681 BOOL FASTCALL
UserDestroyMenu(HMENU hMenu
)
1685 if(!(Menu
= UserGetMenuObject(hMenu
)))
1690 if(Menu
->Process
!= PsGetCurrentProcess())
1692 SetLastWin32Error(ERROR_ACCESS_DENIED
);
1696 return IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
1707 DECLARE_RETURN(BOOL
);
1709 DPRINT("Enter NtUserDestroyMenu\n");
1710 UserEnterExclusive();
1712 if(!(Menu
= UserGetMenuObject(hMenu
)))
1717 if(Menu
->Process
!= PsGetCurrentProcess())
1719 SetLastWin32Error(ERROR_ACCESS_DENIED
);
1723 RETURN( IntDestroyMenuObject(Menu
, TRUE
, TRUE
));
1726 DPRINT("Leave NtUserDestroyMenu, ret=%i\n",_ret_
);
1736 NtUserEnableMenuItem(
1742 DECLARE_RETURN(UINT
);
1744 DPRINT("Enter NtUserEnableMenuItem\n");
1745 UserEnterExclusive();
1747 if(!(Menu
= UserGetMenuObject(hMenu
)))
1752 RETURN( IntEnableMenuItem(Menu
, uIDEnableItem
, uEnable
));
1755 DPRINT("Leave NtUserEnableMenuItem, ret=%i\n",_ret_
);
1769 LPCMENUITEMINFOW UnsafeItemInfo
)
1773 ROSMENUITEMINFO ItemInfo
;
1774 DECLARE_RETURN(DWORD
);
1776 DPRINT("Enter UserInsertMenuItem\n");
1777 UserEnterExclusive();
1779 if(!(Menu
= UserGetMenuObject(hMenu
)))
1784 /* Try to copy the whole MENUITEMINFOW structure */
1785 Status
= MmCopyFromCaller(&ItemInfo
, UnsafeItemInfo
, sizeof(MENUITEMINFOW
));
1786 if (NT_SUCCESS(Status
))
1788 if (sizeof(MENUITEMINFOW
) != ItemInfo
.cbSize
1789 && FIELD_OFFSET(MENUITEMINFOW
, hbmpItem
) != ItemInfo
.cbSize
)
1791 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1794 RETURN( IntInsertMenuItem(Menu
, uItem
, fByPosition
, &ItemInfo
));
1797 /* Try to copy without last field (not present in older versions) */
1798 Status
= MmCopyFromCaller(&ItemInfo
, UnsafeItemInfo
, FIELD_OFFSET(MENUITEMINFOW
, hbmpItem
));
1799 if (NT_SUCCESS(Status
))
1801 if (FIELD_OFFSET(MENUITEMINFOW
, hbmpItem
) != ItemInfo
.cbSize
)
1803 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1806 ItemInfo
.hbmpItem
= (HBITMAP
)0;
1807 RETURN( IntInsertMenuItem(Menu
, uItem
, fByPosition
, &ItemInfo
));
1810 SetLastNtError(Status
);
1814 DPRINT("Leave UserInsertMenuItem, ret=%i\n",_ret_
);
1836 NtUserGetMenuDefaultItem(
1843 DECLARE_RETURN(UINT
);
1845 DPRINT("Enter NtUserGetMenuDefaultItem\n");
1846 UserEnterExclusive();
1848 if(!(Menu
= UserGetMenuObject(hMenu
)))
1853 RETURN( IntGetMenuDefaultItem(Menu
, fByPos
, gmdiFlags
, &gismc
));
1856 DPRINT("Leave NtUserGetMenuDefaultItem, ret=%i\n",_ret_
);
1866 NtUserGetMenuBarInfo(
1873 PMENU_OBJECT MenuObject
;
1875 PWINDOW_OBJECT WindowObject
;
1880 DECLARE_RETURN(BOOL
);
1882 DPRINT("Enter NtUserGetMenuBarInfo\n");
1885 if (!(WindowObject
= UserGetWindowObject(hwnd
)))
1887 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1891 hMenu
= (HMENU
)WindowObject
->Wnd
->IDMenu
;
1893 if (!(MenuObject
= UserGetMenuObject(hMenu
)))
1895 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
1899 if (pmbi
->cbSize
!= sizeof(MENUBARINFO
))
1901 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1905 kmbi
.cbSize
= sizeof(MENUBARINFO
);
1906 kmbi
.fBarFocused
= FALSE
;
1907 kmbi
.fFocused
= FALSE
;
1908 kmbi
.hwndMenu
= NULL
;
1914 PMENU_OBJECT SubMenuObject
;
1916 if (idItem
) /* Non-Zero-Based. */
1918 if (IntGetMenuItemByFlag(MenuObject
, idItem
-1, MF_BYPOSITION
, NULL
, &mi
, NULL
) > -1)
1919 kmbi
.rcBar
= mi
->Rect
;
1928 /* If items is zero we assume info for the menu itself. */
1929 if (!(IntGetClientOrigin(WindowObject
, &Offset
)))
1934 Rect
.left
= Offset
.x
;
1935 Rect
.right
= Offset
.x
+ MenuObject
->MenuInfo
.Width
;
1936 Rect
.top
= Offset
.y
;
1937 Rect
.bottom
= Offset
.y
+ MenuObject
->MenuInfo
.Height
;
1939 DPRINT("Rect top = %d bottom = %d left = %d right = %d \n",
1940 Rect
.top
, Rect
.bottom
, Rect
.left
, Rect
.right
);
1944 if (idItem
-1 == MenuObject
->MenuInfo
.FocusedItem
)
1945 kmbi
.fFocused
= TRUE
;
1947 if (MenuObject
->MenuInfo
.FocusedItem
!= NO_SELECTED_ITEM
)
1948 kmbi
.fBarFocused
= TRUE
;
1949 SubMenuObject
= UserGetMenuObject(MenuObject
->MenuItemList
->hSubMenu
);
1950 if(SubMenuObject
) kmbi
.hwndMenu
= SubMenuObject
->MenuInfo
.Wnd
;
1951 DPRINT("OBJID_MENU, idItem = %d\n",idItem
);
1956 PMENU_OBJECT SubMenuObject
, XSubMenuObject
;
1957 SubMenuObject
= UserGetMenuObject(MenuObject
->MenuItemList
->hSubMenu
);
1958 if(SubMenuObject
) kmbi
.hMenu
= SubMenuObject
->MenuInfo
.Self
;
1962 DPRINT1("OBJID_CLIENT, No SubMenu!\n");
1967 if (IntGetMenuItemByFlag(SubMenuObject
, idItem
-1, MF_BYPOSITION
, NULL
, &mi
, NULL
) > -1)
1968 kmbi
.rcBar
= mi
->Rect
;
1977 PWINDOW_OBJECT SubWinObj
;
1978 if (!(SubWinObj
= UserGetWindowObject(SubMenuObject
->MenuInfo
.Wnd
)))
1983 if (!(IntGetClientOrigin(SubWinObj
, &Offset
)))
1988 Rect
.left
= Offset
.x
;
1989 Rect
.right
= Offset
.x
+ SubMenuObject
->MenuInfo
.Width
;
1990 Rect
.top
= Offset
.y
;
1991 Rect
.bottom
= Offset
.y
+ SubMenuObject
->MenuInfo
.Height
;
1996 if (idItem
-1 == SubMenuObject
->MenuInfo
.FocusedItem
)
1997 kmbi
.fFocused
= TRUE
;
1999 if (SubMenuObject
->MenuInfo
.FocusedItem
!= NO_SELECTED_ITEM
)
2000 kmbi
.fBarFocused
= TRUE
;
2001 XSubMenuObject
= UserGetMenuObject(SubMenuObject
->MenuItemList
->hSubMenu
);
2002 if (XSubMenuObject
) kmbi
.hwndMenu
= XSubMenuObject
->MenuInfo
.Wnd
;
2003 DPRINT("OBJID_CLIENT, idItem = %d\n",idItem
);
2008 PMENU_OBJECT SysMenuObject
, SubMenuObject
;
2009 if(!(SysMenuObject
= IntGetSystemMenu(WindowObject
, FALSE
, FALSE
)))
2014 kmbi
.hMenu
= SysMenuObject
->MenuInfo
.Self
;
2017 if (IntGetMenuItemByFlag(SysMenuObject
, idItem
-1, MF_BYPOSITION
, NULL
, &mi
, NULL
) > -1)
2018 kmbi
.rcBar
= mi
->Rect
;
2027 PWINDOW_OBJECT SysWinObj
;
2028 if (!(SysWinObj
= UserGetWindowObject(SysMenuObject
->MenuInfo
.Wnd
)))
2033 if (!(IntGetClientOrigin(SysWinObj
, &Offset
)))
2038 Rect
.left
= Offset
.x
;
2039 Rect
.right
= Offset
.x
+ SysMenuObject
->MenuInfo
.Width
;
2040 Rect
.top
= Offset
.y
;
2041 Rect
.bottom
= Offset
.y
+ SysMenuObject
->MenuInfo
.Height
;
2046 if (idItem
-1 == SysMenuObject
->MenuInfo
.FocusedItem
)
2047 kmbi
.fFocused
= TRUE
;
2049 if (SysMenuObject
->MenuInfo
.FocusedItem
!= NO_SELECTED_ITEM
)
2050 kmbi
.fBarFocused
= TRUE
;
2051 SubMenuObject
= UserGetMenuObject(SysMenuObject
->MenuItemList
->hSubMenu
);
2052 if(SubMenuObject
) kmbi
.hwndMenu
= SubMenuObject
->MenuInfo
.Wnd
;
2053 DPRINT("OBJID_SYSMENU, idItem = %d\n",idItem
);
2058 DPRINT1("Unknown idObject = %d, idItem = %d\n",idObject
,idItem
);
2062 NTSTATUS Status
= MmCopyToCaller(pmbi
, &kmbi
, sizeof(MENUBARINFO
));
2063 if (! NT_SUCCESS(Status
))
2065 SetLastNtError(Status
);
2072 DPRINT("Leave NtUserGetMenuBarInfo, ret=%i\n",_ret_
);
2096 NtUserGetMenuItemRect(
2103 PWINDOW_OBJECT ReferenceWnd
;
2108 PMENU_ITEM MenuItem
;
2109 DECLARE_RETURN(BOOL
);
2111 DPRINT("Enter NtUserGetMenuItemRect\n");
2114 if (!(Menu
= UserGetMenuObject(hMenu
)))
2119 if (IntGetMenuItemByFlag(Menu
, uItem
, MF_BYPOSITION
, NULL
, &MenuItem
, NULL
) > -1)
2120 Rect
= MenuItem
->Rect
;
2126 if(!UserMenuInfo(Menu
, &mi
, FALSE
))
2132 if (lprcItem
== NULL
) RETURN( FALSE
);
2134 if (!(ReferenceWnd
= UserGetWindowObject(mi
.Wnd
))) RETURN( FALSE
);
2136 if(MenuItem
->fType
& MF_POPUP
)
2138 XMove
= ReferenceWnd
->Wnd
->ClientRect
.left
;
2139 YMove
= ReferenceWnd
->Wnd
->ClientRect
.top
;
2143 XMove
= ReferenceWnd
->Wnd
->WindowRect
.left
;
2144 YMove
= ReferenceWnd
->Wnd
->WindowRect
.top
;
2149 Rect
.right
+= XMove
;
2150 Rect
.bottom
+= YMove
;
2152 Status
= MmCopyToCaller(lprcItem
, &Rect
, sizeof(RECT
));
2153 if (! NT_SUCCESS(Status
))
2155 SetLastNtError(Status
);
2161 DPRINT("Leave NtUserGetMenuItemRect, ret=%i\n",_ret_
);
2171 NtUserHiliteMenuItem(
2178 PWINDOW_OBJECT Window
;
2179 DECLARE_RETURN(BOOLEAN
);
2181 DPRINT("Enter NtUserHiliteMenuItem\n");
2182 UserEnterExclusive();
2184 if(!(Window
= UserGetWindowObject(hWnd
)))
2189 if(!(Menu
= UserGetMenuObject(hMenu
)))
2194 if(Window
->Wnd
->IDMenu
== (UINT
)hMenu
)
2196 RETURN( IntHiliteMenuItem(Window
, Menu
, uItemHilite
, uHilite
));
2202 DPRINT("Leave NtUserHiliteMenuItem, ret=%i\n",_ret_
);
2212 PROSMENUINFO UnsafeMenuInfo
,
2218 ROSMENUINFO MenuInfo
;
2220 Status
= MmCopyFromCaller(&Size
, &UnsafeMenuInfo
->cbSize
, sizeof(DWORD
));
2221 if (! NT_SUCCESS(Status
))
2223 SetLastNtError(Status
);
2226 if(Size
< sizeof(MENUINFO
) || sizeof(ROSMENUINFO
) < Size
)
2228 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2231 Status
= MmCopyFromCaller(&MenuInfo
, UnsafeMenuInfo
, Size
);
2232 if (! NT_SUCCESS(Status
))
2234 SetLastNtError(Status
);
2241 Res
= IntSetMenuInfo(Menu
, &MenuInfo
);
2246 Res
= IntGetMenuInfo(Menu
, &MenuInfo
);
2249 Status
= MmCopyToCaller(UnsafeMenuInfo
, &MenuInfo
, Size
);
2250 if (! NT_SUCCESS(Status
))
2252 SetLastNtError(Status
);
2272 PROSMENUINFO UnsafeMenuInfo
,
2276 DECLARE_RETURN(BOOL
);
2278 DPRINT("Enter NtUserMenuInfo\n");
2281 if (!(Menu
= UserGetMenuObject(hMenu
)))
2286 RETURN(UserMenuInfo(Menu
, UnsafeMenuInfo
, SetOrGet
));
2289 DPRINT("Leave NtUserMenuInfo, ret=%i\n",_ret_
);
2300 NtUserMenuItemFromPoint(
2307 PWINDOW_OBJECT Window
= NULL
;
2310 DECLARE_RETURN(int);
2312 DPRINT("Enter NtUserMenuItemFromPoint\n");
2313 UserEnterExclusive();
2315 if (!(Menu
= UserGetMenuObject(hMenu
)))
2320 if (!(Window
= UserGetWindowObject(Menu
->MenuInfo
.Wnd
)))
2325 X
-= Window
->Wnd
->WindowRect
.left
;
2326 Y
-= Window
->Wnd
->WindowRect
.top
;
2328 mi
= Menu
->MenuItemList
;
2329 for (i
= 0; NULL
!= mi
; i
++)
2331 if (InRect(mi
->Rect
, X
, Y
))
2338 RETURN( (mi
? i
: NO_SELECTED_ITEM
));
2341 DPRINT("Leave NtUserMenuItemFromPoint, ret=%i\n",_ret_
);
2354 PROSMENUITEMINFO UnsafeItemInfo
,
2357 PMENU_ITEM MenuItem
;
2358 ROSMENUITEMINFO ItemInfo
;
2363 Status
= MmCopyFromCaller(&Size
, &UnsafeItemInfo
->cbSize
, sizeof(UINT
));
2364 if (! NT_SUCCESS(Status
))
2366 SetLastNtError(Status
);
2369 if (sizeof(MENUITEMINFOW
) != Size
2370 && FIELD_OFFSET(MENUITEMINFOW
, hbmpItem
) != Size
2371 && sizeof(ROSMENUITEMINFO
) != Size
)
2373 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2376 Status
= MmCopyFromCaller(&ItemInfo
, UnsafeItemInfo
, Size
);
2377 if (! NT_SUCCESS(Status
))
2379 SetLastNtError(Status
);
2382 /* If this is a pre-0x0500 _WIN32_WINNT MENUITEMINFOW, you can't
2384 if (FIELD_OFFSET(MENUITEMINFOW
, hbmpItem
) == Size
2385 && 0 != (ItemInfo
.fMask
& MIIM_BITMAP
))
2387 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2391 if (IntGetMenuItemByFlag(Menu
, Item
,
2392 (ByPosition
? MF_BYPOSITION
: MF_BYCOMMAND
),
2393 NULL
, &MenuItem
, NULL
) < 0)
2395 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2401 Ret
= IntSetMenuItemInfo(Menu
, MenuItem
, &ItemInfo
);
2405 Ret
= IntGetMenuItemInfo(Menu
, MenuItem
, &ItemInfo
);
2408 Status
= MmCopyToCaller(UnsafeItemInfo
, &ItemInfo
, Size
);
2409 if (! NT_SUCCESS(Status
))
2411 SetLastNtError(Status
);
2431 PROSMENUITEMINFO UnsafeItemInfo
,
2435 DECLARE_RETURN(BOOL
);
2437 DPRINT("Enter NtUserMenuItemInfo\n");
2438 UserEnterExclusive();
2440 if (!(Menu
= UserGetMenuObject(hMenu
)))
2445 RETURN( UserMenuItemInfo(Menu
, Item
, ByPosition
, UnsafeItemInfo
, SetOrGet
));
2448 DPRINT("Leave NtUserMenuItemInfo, ret=%i\n",_ret_
);
2465 DECLARE_RETURN(BOOL
);
2467 DPRINT("Enter NtUserRemoveMenu\n");
2468 UserEnterExclusive();
2470 if(!(Menu
= UserGetMenuObject(hMenu
)))
2475 RETURN(IntRemoveMenuItem(Menu
, uPosition
, uFlags
, FALSE
));
2478 DPRINT("Leave NtUserRemoveMenu, ret=%i\n",_ret_
);
2489 NtUserSetMenuContextHelpId(
2491 DWORD dwContextHelpId
)
2494 DECLARE_RETURN(BOOL
);
2496 DPRINT("Enter NtUserSetMenuContextHelpId\n");
2497 UserEnterExclusive();
2499 if(!(Menu
= UserGetMenuObject(hMenu
)))
2504 RETURN(IntSetMenuContextHelpId(Menu
, dwContextHelpId
));
2507 DPRINT("Leave NtUserSetMenuContextHelpId, ret=%i\n",_ret_
);
2518 NtUserSetMenuDefaultItem(
2524 DECLARE_RETURN(BOOL
);
2526 DPRINT("Enter NtUserSetMenuDefaultItem\n");
2527 UserEnterExclusive();
2529 if(!(Menu
= UserGetMenuObject(hMenu
)))
2534 RETURN( UserSetMenuDefaultItem(Menu
, uItem
, fByPos
));
2537 DPRINT("Leave NtUserSetMenuDefaultItem, ret=%i\n",_ret_
);
2547 NtUserSetMenuFlagRtoL(
2551 DECLARE_RETURN(BOOL
);
2553 DPRINT("Enter NtUserSetMenuFlagRtoL\n");
2554 UserEnterExclusive();
2556 if(!(Menu
= UserGetMenuObject(hMenu
)))
2561 RETURN(IntSetMenuFlagRtoL(Menu
));
2564 DPRINT("Leave NtUserSetMenuFlagRtoL, ret=%i\n",_ret_
);
2574 NtUserThunkedMenuInfo(
2579 /* This function seems just to call SetMenuInfo() */
2588 NtUserThunkedMenuItemInfo(
2593 LPMENUITEMINFOW lpmii
,
2594 PUNICODE_STRING lpszCaption
)
2597 /* lpszCaption may be NULL, check for it and call RtlInitUnicodeString()
2598 if bInsert == TRUE call NtUserInsertMenuItem() else NtUserSetMenuItemInfo() */
2600 if (bInsert
) return UserInsertMenuItem(hMenu
, uItem
, fByPosition
, lpmii
);
2610 /* NOTE: unused function */
2612 NtUserTrackPopupMenuEx(