From b5ba0a23cf05a1187dace0d718c15714962f569c Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 13 Aug 2004 20:14:40 +0000 Subject: [PATCH] - SkyOS menu functions implementation. svn path=/trunk/; revision=10517 --- reactos/include/rosky/defines.h | 4 + reactos/lib/rosky/libskygi/libskygi.c | 165 +++++++++++++++++++++++++- reactos/lib/rosky/libskygi/stubs.c | 69 +---------- 3 files changed, 169 insertions(+), 69 deletions(-) diff --git a/reactos/include/rosky/defines.h b/reactos/include/rosky/defines.h index 7e9732f7bc0..4de7c5d4d77 100644 --- a/reactos/include/rosky/defines.h +++ b/reactos/include/rosky/defines.h @@ -7,6 +7,7 @@ #define MSG_MOUSE_BUT1_RELEASED 164 #define MSG_MOUSE_BUT2_RELEASED 165 #define MSG_GUI_REDRAW 170 +#define MSG_COMMAND 2505 #define MSG_QUIT 2600 #define MSG_DESTROY 2700 @@ -35,4 +36,7 @@ #define GC_TYPE_WINDOW 0x00000002 #define GC_TYPE_DIB 0x00000004 +/* Menu flags */ +#define MENU_SEPERATOR 0x00000001 + #endif /* __RSK_DEFINES_H */ diff --git a/reactos/lib/rosky/libskygi/libskygi.c b/reactos/lib/rosky/libskygi/libskygi.c index 8756e68493b..91a2f383a8f 100644 --- a/reactos/lib/rosky/libskygi/libskygi.c +++ b/reactos/lib/rosky/libskygi/libskygi.c @@ -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: libskygi.c,v 1.6 2004/08/13 17:10:22 navaraf Exp $ +/* $Id: libskygi.c,v 1.7 2004/08/13 20:14:40 navaraf Exp $ * * PROJECT: SkyOS GI library * FILE: lib/libskygi/libskygi.c @@ -26,6 +26,7 @@ * 08/12/2004 Created */ #include +#include #include #include "libskygi.h" #include "resource.h" @@ -36,6 +37,18 @@ typedef struct HWND hWnd; } SKY_WINDOW, *PSKY_WINDOW; +typedef struct +{ + widget_menu Menu; + HMENU hMenu; +} SKY_MENU, *PSKY_MENU; + +typedef struct +{ + widget_menu_item MenuItem; + MENUITEMINFOW MenuItemInfo; +} SKY_MENUITEM, *PSKY_MENUITEM; + typedef struct { GC GraphicsContext; @@ -230,6 +243,11 @@ IntIsSkyMessage(PSKY_WINDOW skw, MSG *Msg, s_gi_msg *smsg) smsg->para2 = pt.y; return TRUE; } + + case WM_COMMAND: + smsg->type = MSG_COMMAND; + smsg->para1 = LOWORD(Msg->wParam); + return TRUE; } return FALSE; @@ -295,6 +313,10 @@ IntDefaultWin32Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0; } + case WM_COMMAND: + IntDispatchMsg(&skw->Window, MSG_COMMAND, LOWORD(wParam), 0); + return 0; + case WM_ERASEBKGND: return 1; /* don't handle this message */ } @@ -384,6 +406,8 @@ GI_create_app(app_para *p) ClientRect.bottom = 0 + p->ulHeight; AdjustWindowRectEx(&ClientRect, Style, p->ulStyle & WF_HAS_MENU, ExStyle); + DBG("Menu: %x\n", p->pMenu ? ((PSKY_MENU)p->pMenu)->hMenu : NULL); + /* create the Win32 window */ skw->hWnd = CreateWindowExW(ExStyle, L"ROSkyWindow", @@ -394,7 +418,7 @@ GI_create_app(app_para *p) ClientRect.right - ClientRect.left, ClientRect.bottom - ClientRect.top, NULL, - NULL, + p->pMenu ? ((PSKY_MENU)p->pMenu)->hMenu : NULL, GetModuleHandleW(NULL), skw); @@ -989,4 +1013,141 @@ GC_destroy(GC *Gc) return 0; } + +/* + * @implemented + */ +widget_menu* __cdecl +GI_create_menu(HANDLE Window) +{ + PSKY_MENU Menu; + + DBG("GI_create_menu(0x%x)\n", Window); + + Menu = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SKY_MENU)); + if (Menu == NULL) + { + return NULL; + } + + /* Shouldn't we use CreatePopupMenu in some cases? */ + Menu->hMenu = CreateMenu(); + if (Menu->hMenu == NULL) + { + HeapFree(GetProcessHeap(), 0, Menu); + return NULL; + } + + if (Window) + SetMenu(((PSKY_WINDOW)Window)->hWnd, Menu->hMenu); + + return (widget_menu *)Menu; +} + + +/* + * @implemented + */ +widget_menu_item* __cdecl +GI_create_menu_item(unsigned char *Text, + unsigned int Id, + unsigned int Flags, + unsigned int Enabled) +{ + PSKY_MENUITEM MenuItem; + ULONG TextLength; + + DBG("GI_create_menu_item(0x%x, 0x%x, 0x%x, 0x%x)\n", + Text, Id, Flags, Enabled); + + TextLength = MultiByteToWideChar(CP_UTF8, 0, Text, -1, NULL, 0); + MenuItem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, + sizeof(SKY_MENUITEM) + TextLength * sizeof(WCHAR)); + if (MenuItem == NULL) + { + return NULL; + } + + lstrcpyA(MenuItem->MenuItem.text, Text); + MenuItem->MenuItem.ID = Id; + MenuItem->MenuItem.flags = Flags; + MenuItem->MenuItem.enabled = Enabled; + + MenuItem->MenuItemInfo.cbSize = sizeof(MENUITEMINFOW); + MenuItem->MenuItemInfo.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE; + if (Flags & MENU_SEPERATOR) + MenuItem->MenuItemInfo.fType = MF_SEPARATOR; + else + MenuItem->MenuItemInfo.fType = MF_STRING; + MenuItem->MenuItemInfo.fState = Enabled ? MFS_ENABLED : 0; + MenuItem->MenuItemInfo.wID = Id; + MenuItem->MenuItemInfo.dwTypeData = (LPWSTR)(MenuItem + 1); + MenuItem->MenuItemInfo.cch = TextLength; + MultiByteToWideChar(CP_UTF8, 0, Text, TextLength, (LPWSTR)(MenuItem + 1), + TextLength); + + return (widget_menu_item *)MenuItem; +} + + +/* + * @implemented + */ +int __cdecl +GI_add_menu_item(widget_menu *Menu, + widget_menu_item *Item) +{ + DBG("GI_add_menu_item(0x%x, 0x%x)\n", Menu, Item); + InsertMenuItemW(((PSKY_MENU)Menu)->hMenu, -1, TRUE, + &((PSKY_MENUITEM)Item)->MenuItemInfo); + return 1; +} + + +/* + * @implemented + */ +int __cdecl +GI_add_menu_sub(widget_menu *Menu, + widget_menu_item *Item, + widget_menu *Sub) +{ + PSKY_MENUITEM MenuItem = (PSKY_MENUITEM)Item; + + DBG("GI_add_menu_sub(0x%x, 0x%x, 0x%x)\n", Menu, Item, Sub); + MenuItem->MenuItemInfo.fMask |= MIIM_SUBMENU; + MenuItem->MenuItemInfo.hSubMenu = ((PSKY_MENU)Sub)->hMenu; + InsertMenuItemW(((PSKY_MENU)Menu)->hMenu, -1, TRUE, + &MenuItem->MenuItemInfo); + return 1; +} + + +/* + * @unimplemented + */ +int __cdecl +GI_messagebox(HANDLE Window, + unsigned int Flags, + char *Title, + char *Fmt, + ...) +{ + CHAR Buffer[4096]; + va_list ArgList; + + DBG("GI_messagebox(0x%x, 0x%x, 0x%x, 0x%x, ...)\n", + Window, Flags, Title, Fmt); + + va_start(ArgList, Fmt); + _vsnprintf(Buffer, sizeof(Buffer) / sizeof(Buffer[0]), Fmt, ArgList); + va_end(ArgList); + + /** @todo Convert flags and fix return value! */ + MessageBoxA(Window ? ((PSKY_WINDOW)Window)->hWnd : NULL, + Buffer, Title, MB_OK); + + return 1; +} + /* EOF */ diff --git a/reactos/lib/rosky/libskygi/stubs.c b/reactos/lib/rosky/libskygi/stubs.c index c7ea91a5cae..c9c8c23e687 100644 --- a/reactos/lib/rosky/libskygi/stubs.c +++ b/reactos/lib/rosky/libskygi/stubs.c @@ -1,4 +1,4 @@ -/* $Id: stubs.c,v 1.6 2004/08/13 12:29:19 weiden Exp $ +/* $Id: stubs.c,v 1.7 2004/08/13 20:14:40 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: SkyOS GI library @@ -49,31 +49,6 @@ GC_blit(GC *gc, } -/* - * @unimplemented - */ -int __cdecl -GI_add_menu_item(widget_menu *menu, - widget_menu_item *item) -{ - STUB("GI_add_menu_item(0x%x, 0x%x) returns 0!\n", menu, item); - return 0; -} - - -/* - * @unimplemented - */ -int __cdecl -GI_add_menu_sub(widget_menu *menu, - widget_menu_item *item, - widget_menu *sub) -{ - STUB("GI_add_menu_sub(0x%x, 0x%x, 0x%x) returns 0!\n", menu, item, sub); - return 0; -} - - /* * @unimplemented */ @@ -85,31 +60,6 @@ GI_create_DDB_from_DIB(DIB *dib) } -/* - * @unimplemented - */ -widget_menu* __cdecl -GI_create_menu(HANDLE win) -{ - STUB("GI_create_menu(0x%x) returns NULL!\n", win); - return NULL; -} - - -/* - * @unimplemented - */ -widget_menu_item* __cdecl -GI_create_menu_item(unsigned char *text, - unsigned int ID, - unsigned int flags, - unsigned int enabled) -{ - STUB("GI_create_menu_item(0x%x, 0x%x, 0x%x, 0x%x) returns NULL!\n", text, ID, flags, enabled); - return NULL; -} - - /* * @unimplemented */ @@ -121,21 +71,6 @@ GI_kill_timer(unsigned int uiID) } -/* - * @unimplemented - */ -int __cdecl -GI_messagebox(HANDLE hWnd, - unsigned int flags, - char *titel, - char *fmt, - ...) -{ - STUB("GI_messagebox(0x%x, 0x%x, 0x%x, 0x%x, ...) returns 0!\n", hWnd, flags, titel, fmt); - return 0; -} - - /* * @unimplemented */ @@ -357,7 +292,7 @@ DIB* __cdecl GI_load_bitmap(char *filename, unsigned int ImageIndex) { - STUB("GI_load_bitmap(0x%x, 0x%x) returns NULL!\n", filename, ImageIndex); + STUB("GI_load_bitmap(%s, 0x%x) returns NULL!\n", filename, ImageIndex); return NULL; }