changed menu code to use UNICODE_STRING

svn path=/trunk/; revision=5889
This commit is contained in:
Thomas Bluemel 2003-08-27 22:58:12 +00:00
parent 22f4e1ae9e
commit 9cfd31e787
3 changed files with 69 additions and 75 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: menu.c,v 1.29 2003/08/23 17:06:07 weiden Exp $
/* $Id: menu.c,v 1.30 2003/08/27 22:58:12 weiden Exp $
*
* PROJECT: ReactOS user32.dll
* FILE: lib/user32/windows/menu.c
@ -318,7 +318,7 @@ MenuDrawMenuBar(HDC hDC, LPRECT Rect, HWND hWnd, BOOL Draw)
/* FIXME cache menu bar items using NtUserDrawMenuBarTemp() */
/* FIXME select menu font first */
SetTextColor(hDC, COLOR_MENUTEXT);
DrawTextW(hDC, L"FIXME: Draw Menubar", -1, Rect, DT_SINGLELINE | DT_VCENTER);
return(Rect->bottom - Rect->top);
@ -750,26 +750,26 @@ InsertMenuA(
mii.cbSize = sizeof(MENUITEMINFOA);
mii.fMask = MIIM_FTYPE | MIIM_STRING;
mii.fType = 0;
if(uFlags & MF_BITMAP)
mii.fType |= MFT_BITMAP;
else
{
if(uFlags & MF_STRING)
{
mii.fType |= MFT_STRING;
}
else if(uFlags & MF_OWNERDRAW)
{
mii.fType |= MFT_OWNERDRAW;
}
else
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
mii.fType |= MFT_BITMAP;
}
else if(uFlags & MF_OWNERDRAW)
{
mii.fType |= MFT_OWNERDRAW;
}
mii.dwTypeData = (LPSTR)lpNewItem;
if(uFlags & MF_POPUP)
{
mii.fMask |= MIIM_SUBMENU;
mii.hSubMenu = (HMENU)uIDNewItem;
}
else
{
mii.fMask |= MIIM_ID;
mii.wID = (UINT)uIDNewItem;
}
return InsertMenuItemA(hMenu, uPosition, (WINBOOL)!(MF_BYPOSITION & uFlags), &mii);
}
@ -786,6 +786,7 @@ InsertMenuItemA(
LPCMENUITEMINFOA lpmii)
{
MENUITEMINFOW mi;
UNICODE_STRING MenuText;
WINBOOL res = FALSE;
BOOL CleanHeap = FALSE;
NTSTATUS Status;
@ -805,6 +806,8 @@ InsertMenuItemA(
SetLastError (RtlNtStatusToDosError(Status));
return FALSE;
}
RtlInitUnicodeString(&MenuText, (PWSTR)mi.dwTypeData);
mi.dwTypeData = (LPWSTR)&MenuText;
CleanHeap = TRUE;
}
@ -828,9 +831,9 @@ InsertMenuItemW(
LPCMENUITEMINFOW lpmii)
{
MENUITEMINFOW mi;
UNICODE_STRING MenuText;
WINBOOL res = FALSE;
BOOL CleanHeap = FALSE;
ULONG len = 0;
HANDLE hHeap = RtlGetProcessHeap();
mi.hbmpItem = (HBITMAP)0;
@ -849,16 +852,14 @@ InsertMenuItemW(
{
if(lpmii->cch > 0)
{
len = lstrlenW(lpmii->dwTypeData);
mi.dwTypeData = RtlAllocateHeap(hHeap, 0, (len + 1) * sizeof(WCHAR));
if(!mi.dwTypeData)
if(!RtlCreateUnicodeString(&MenuText, (PWSTR)lpmii->dwTypeData))
{
SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
return FALSE;
}
memcpy(&mi.dwTypeData, &lpmii->dwTypeData, len);
mi.dwTypeData = (LPWSTR)&MenuText;
mi.cch = MenuText.Length / sizeof(WCHAR);
CleanHeap = TRUE;
mi.cch = len;
}
};
@ -895,14 +896,17 @@ InsertMenuW(
{
mii.fType |= MFT_OWNERDRAW;
}
else if(uFlags & MF_POPUP)
mii.dwTypeData = (LPWSTR)lpNewItem;
if(uFlags & MF_POPUP)
{
mii.fMask |= MIIM_SUBMENU;
mii.hSubMenu = (HMENU)uIDNewItem;
mii.wID = 0;
}
mii.dwTypeData = (LPWSTR)lpNewItem;
else
{
mii.fMask |= MIIM_ID;
mii.wID = (UINT)uIDNewItem;
}
return InsertMenuItemW(hMenu, uPosition, (WINBOOL)!(MF_BYPOSITION & uFlags), &mii);
}

View file

@ -24,8 +24,7 @@ typedef struct _MENU_ITEM
HBITMAP hbmpChecked;
HBITMAP hbmpUnchecked;
ULONG_PTR dwItemData;
LPWSTR dwTypeData;
UINT cch;
UNICODE_STRING Text;
HBITMAP hbmpItem;
} MENU_ITEM, *PMENU_ITEM;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: menu.c,v 1.27 2003/08/22 16:01:01 weiden Exp $
/* $Id: menu.c,v 1.28 2003/08/27 22:58:12 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -75,11 +75,8 @@
#define FreeMenuText(MenuItem) \
{ \
if((MENU_ITEM_TYPE((MenuItem)->fType) == MF_STRING) && \
(MenuItem)->dwTypeData) { \
if((MenuItem)->cch) \
ExFreePool((MenuItem)->dwTypeData); \
(MenuItem)->dwTypeData = 0; \
(MenuItem)->cch = 0; \
(MenuItem)->Text.Length) { \
RtlFreeUnicodeString(&(MenuItem)->Text); \
} \
}
@ -95,17 +92,17 @@ CleanupMenuImpl(VOID)
return(STATUS_SUCCESS);
}
#if 1
#if 0
void FASTCALL
DumpMenuItemList(PMENU_ITEM MenuItem)
{
UINT cnt = 0;
while(MenuItem)
{
if(MenuItem->dwTypeData)
DbgPrint(" %d. %ws\n", ++cnt, (LPWSTR)MenuItem->dwTypeData);
if(MenuItem->Text.Length)
DbgPrint(" %d. %wZ\n", ++cnt, &MenuItem->Text);
else
DbgPrint(" %d. NO TEXT dwTypeData==%d\n", ++cnt, MenuItem->dwTypeData);
DbgPrint(" %d. NO TEXT dwTypeData==%d\n", ++cnt, (DWORD)MenuItem->Text.Buffer);
DbgPrint(" fType=");
if(MFT_BITMAP & MenuItem->fType) DbgPrint("MFT_BITMAP ");
if(MFT_MENUBARBREAK & MenuItem->fType) DbgPrint("MFT_MENUBARBREAK ");
@ -315,31 +312,29 @@ IntCloneMenuItems(PMENU_OBJECT Destination, PMENU_OBJECT Source)
NewMenuItem->hbmpChecked = MenuItem->hbmpChecked;
NewMenuItem->hbmpUnchecked = MenuItem->hbmpUnchecked;
NewMenuItem->dwItemData = MenuItem->dwItemData;
NewMenuItem->dwTypeData = MenuItem->dwTypeData;
if((MENU_ITEM_TYPE(NewMenuItem->fType) == MF_STRING))
{
if(MenuItem->cch && NewMenuItem->dwTypeData)
if(MenuItem->Text.Length)
{
NewMenuItem->dwTypeData = (LPWSTR)ExAllocatePool(PagedPool, (MenuItem->cch + 1) * sizeof(WCHAR));
if(!NewMenuItem->dwTypeData)
NewMenuItem->Text.Length = 0;
NewMenuItem->Text.MaximumLength = MenuItem->Text.MaximumLength;
NewMenuItem->Text.Buffer = (PWSTR)ExAllocatePool(PagedPool, MenuItem->Text.MaximumLength);
if(!NewMenuItem->Text.Buffer)
{
ExFreePool(NewMenuItem);
break;
}
memcpy(NewMenuItem->dwTypeData, MenuItem->dwTypeData, (MenuItem->cch + 1) * sizeof(WCHAR));
RtlCopyUnicodeString(&NewMenuItem->Text, &MenuItem->Text);
}
else
{
NewMenuItem->cch = MenuItem->cch;
NewMenuItem->dwTypeData = MenuItem->dwTypeData;
NewMenuItem->Text.Buffer = MenuItem->Text.Buffer;
}
}
else
{
NewMenuItem->cch = MenuItem->cch;
NewMenuItem->dwTypeData = MenuItem->dwTypeData;
NewMenuItem->Text.Buffer = MenuItem->Text.Buffer;
}
NewMenuItem->cch = MenuItem->cch;
NewMenuItem->hbmpItem = MenuItem->hbmpItem;
NewMenuItem->Next = NULL;
@ -566,7 +561,7 @@ IntGetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, LPMENUITEMINFOW
return FALSE;
}
lpmii->cch = MenuItem->cch;
lpmii->cch = MenuItem->Text.Length;
if(lpmii->fMask & MIIM_BITMAP)
{
@ -604,23 +599,15 @@ IntGetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, LPMENUITEMINFOW
BOOL FASTCALL
IntSetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, LPCMENUITEMINFOW lpmii)
{
PUNICODE_STRING Source;
UINT copylen = 0;
if(!MenuItem || !MenuObject || !lpmii)
{
return FALSE;
}
/*if((MenuItem->fMask & (MIIM_TYPE | MIIM_STRING)) &&
(MENU_ITEM_TYPE(MenuItem->fType) == MF_STRING) &&
MenuItem->dwTypeData)
{
// delete old string
ExFreePool(MenuItem->dwTypeData);
MenuItem->dwTypeData = 0;
MenuItem->cch = 0;
}*/
MenuItem->fType = lpmii->fType;
MenuItem->cch = lpmii->cch;
if(lpmii->fMask & MIIM_BITMAP)
{
@ -662,28 +649,32 @@ IntSetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, LPCMENUITEMINFO
{
if(lpmii->dwTypeData && lpmii->cch)
{
Source = (PUNICODE_STRING)lpmii->dwTypeData;
FreeMenuText(MenuItem);
MenuItem->dwTypeData = (LPWSTR)ExAllocatePool(PagedPool, (lpmii->cch + 1) * sizeof(WCHAR));
if(!MenuItem->dwTypeData)
copylen = min((UINT)Source->MaximumLength, (lpmii->cch + 1) * sizeof(WCHAR));
MenuItem->Text.Buffer = (PWSTR)ExAllocatePool(PagedPool, copylen);
if(MenuItem->Text.Buffer)
{
MenuItem->cch = 0;
/* FIXME Set last error code? */
SetLastWin32Error(STATUS_NO_MEMORY);
return FALSE;
MenuItem->Text.Length = 0;
MenuItem->Text.MaximumLength = copylen;
RtlCopyUnicodeString(&MenuItem->Text, Source);
}
else
{
MenuItem->Text.Length = 0;
MenuItem->Text.MaximumLength = 0;
MenuItem->Text.Buffer = NULL;
}
MenuItem->cch = lpmii->cch;
memcpy(MenuItem->dwTypeData, lpmii->dwTypeData, (lpmii->cch + 1) * sizeof(WCHAR));
}
else
{
FreeMenuText(MenuItem);
MenuItem->fType = MF_SEPARATOR;
MenuItem->dwTypeData = NULL;
MenuItem->cch = 0;
}
}
else
{
MenuItem->dwTypeData = NULL;
RtlInitUnicodeString(&MenuItem->Text, NULL);
}
return TRUE;
@ -729,8 +720,8 @@ IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, WINBOOL fByPosition,
MenuItem->hSubMenu = (HMENU)0;
MenuItem->hbmpChecked = (HBITMAP)0;
MenuItem->hbmpUnchecked = (HBITMAP)0;
MenuItem->dwItemData = (ULONG_PTR)NULL;
MenuItem->cch = 0;
MenuItem->dwItemData = 0;
RtlInitUnicodeString(&MenuItem->Text, NULL);
MenuItem->hbmpItem = (HBITMAP)0;
if(!IntSetMenuItemInfo(MenuObject, MenuItem, lpmii))