2 * ROSky - SkyOS Application Layer
3 * Copyright (C) 2004 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * PROJECT: SkyOS GI library
22 * FILE: lib/libskygi/libskygi.c
23 * PURPOSE: SkyOS GI library
30 #include <rosky/rosky.h>
39 } SKY_WINDOW
, *PSKY_WINDOW
;
45 } SKY_MENU
, *PSKY_MENU
;
49 widget_menu_item MenuItem
;
50 MENUITEMINFOW MenuItemInfo
;
51 } SKY_MENUITEM
, *PSKY_MENUITEM
;
66 static ATOM SkyClassAtom
;
67 static BOOL SkyClassRegistered
= FALSE
;
70 * Map a SkyOS window style to Windows one.
72 * @param SkyStyle SkyOS window style (WF_* flags).
73 * @param ExStyle Contains Windows extended window style on exit.
75 * @return Windows window style (WS_* flags).
78 * WF_MODAL, WF_HAS_MENU, WF_HAS_STATUSBAR, WF_FREEFORM, WF_FOCUSABLE,
79 * WF_USER, WF_DESKTOP, WF_NOT_MOVEABLE, WF_NO_BUTTONS, WF_TRANSPARENT,
80 * WF_NO_INITIAL_DRAW, WF_USE_BACKGROUND, WF_DONT_EREASE_BACKGROUND,
84 IntMapWindowStyle(ULONG SkyStyle
, ULONG
*ExStyle
)
88 Style
= (SkyStyle
& WF_HIDE
) ? 0 : WS_VISIBLE
;
89 Style
|= (SkyStyle
& WF_NO_TITLE
) ? 0 : WS_CAPTION
;
90 Style
|= (SkyStyle
& WF_NOT_SIZEABLE
) ? WS_THICKFRAME
: 0;
91 Style
|= (SkyStyle
& WF_POPUP
) ? WS_POPUP
: 0;
92 Style
|= (SkyStyle
& WF_NO_BUTTONS
) ? 0 :
93 ((SkyStyle
& WF_NOT_SIZEABLE
) ? 0 : WS_MAXIMIZEBOX
) |
94 WS_MINIMIZEBOX
| WS_SYSMENU
;
95 *ExStyle
= (SkyStyle
& WF_SMALL_TITLE
) ? WS_EX_TOOLWINDOW
: 0;
102 * Dispatch a Sky Message to the appropriate window callback
104 * @param win Specifies the destination window
105 * @param type The type of the message (see MSG_ constants)
106 * @param para1 Additional parameter 1
107 * @param para2 Additional parameter 2
109 * @return Returns the return value of the window callback function
112 IntDispatchMsg(s_window
*win
, unsigned int type
, unsigned int para1
, unsigned int para2
)
117 /* fill the members of the struct */
122 msg
.next
= NULL
; /* ??? */
123 msg
.prev
= NULL
; /* ??? */
125 msg
.timestamp
= (unsigned long long)GetTickCount() * 1000LL;
127 DBG("Dispatching window (0x%x) message type %d\n", win
, type
);
128 Ret
= win
->win_func(win
, &msg
);
129 DBG("Dispatched window (0x%x) message type %d, returned 0x%x\n", win
, type
, Ret
);
135 * Dispatch a Sky Message with a update rect to the appropriate window callback
137 * @param win Specifies the destination window
138 * @param type The type of the message (see MSG_ constants)
139 * @param para1 Additional parameter 1
140 * @param para2 Additional parameter 2
141 * @param rect Rectangle of the window to be repainted
143 * @return Returns the return value of the window callback function
146 IntDispatchMsgRect(s_window
*win
, unsigned int type
, unsigned int para1
, unsigned int para2
, s_region
*rect
)
151 /* fill the members of the struct */
156 msg
.next
= NULL
; /* ??? */
157 msg
.prev
= NULL
; /* ??? */
160 msg
.timestamp
= (unsigned long long)GetTickCount() * 1000LL;
162 DBG("Dispatching window (0x%x) message type %d\n", win
, type
);
163 Ret
= win
->win_func(win
, &msg
);
164 DBG("Dispatched window (0x%x) message type %d, returned 0x%x\n", win
, type
, Ret
);
170 * Determines whether a win32 message should cause a Sky message to be dispatched
172 * @param skw Specifies the destination window
173 * @param Msg Contains the win32 message
174 * @param smsg Address to the sky message structure that will be filled in with
175 * appropriate information in case a sky message should be dispatched
177 * @return Returns TRUE if a Sky message should be dispatched
180 IntIsSkyMessage(PSKY_WINDOW skw
, MSG
*Msg
, s_gi_msg
*smsg
)
187 smsg
->type
= MSG_DESTROY
;
197 if(GetUpdateRect(skw
->hWnd
, &rc
, FALSE
))
199 BeginPaint(skw
->hWnd
, &ps
);
200 EndPaint(skw
->hWnd
, &ps
);
202 smsg
->type
= MSG_GUI_REDRAW
;
206 smsg
->rect
.x1
= rc
.left
;
207 smsg
->rect
.y1
= rc
.top
;
208 smsg
->rect
.x2
= rc
.right
;
209 smsg
->rect
.y2
= rc
.bottom
;
217 smsg
->type
= MSG_QUIT
;
223 smsg
->type
= MSG_COMMAND
;
224 smsg
->para1
= LOWORD(Msg
->wParam
);
230 smsg
->type
= MSG_MOUSE_MOVED
;
231 goto DoMouseInputMessage
;
236 smsg
->type
= MSG_MOUSE_BUT1_PRESSED
;
237 goto DoMouseInputMessage
;
240 smsg
->type
= MSG_MOUSE_BUT1_RELEASED
;
241 goto DoMouseInputMessage
;
244 smsg
->type
= MSG_MOUSE_BUT2_PRESSED
;
245 goto DoMouseInputMessage
;
251 smsg
->type
= MSG_MOUSE_BUT2_RELEASED
;
255 pt
.x
= LOWORD(Msg
->lParam
);
256 pt
.y
= HIWORD(Msg
->lParam
);
259 MapWindowPoints(NULL
, skw
->hWnd
, &pt
, 1);
272 * The standard win32 window procedure that handles win32 messages delivered from ReactOS
274 * @param hWnd Handle of the window
275 * @param msg Specifies the type of the message
276 * @param wParam Additional data to the message
277 * @param lParam Additional data to the message
279 * @return Depends on the message type
282 IntDefaultWin32Proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
286 if (msg
== WM_NCCREATE
)
289 * Save the pointer to the structure so we can access it later when
290 * dispatching the Win32 messages so we know which sky window it is
291 * and dispatch the right messages.
293 skw
= (PSKY_WINDOW
)((LPCREATESTRUCTW
)lParam
)->lpCreateParams
;
294 SetWindowLongPtr(hWnd
, GWL_USERDATA
, (ULONG_PTR
)skw
);
298 skw
= (PSKY_WINDOW
)GetWindowLongPtr(hWnd
, GWL_USERDATA
);
300 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
306 IntDispatchMsg(&skw
->Window
, MSG_DESTROY
, 0, 0);
312 /* FIXME: Find a more general solution! */
313 /* We can get there for message sent by SendMessage. */
319 BeginPaint(hWnd
, &ps
);
320 srect
.x1
= ps
.rcPaint
.left
;
321 srect
.y1
= ps
.rcPaint
.top
;
322 srect
.x2
= ps
.rcPaint
.right
;
323 srect
.y2
= ps
.rcPaint
.bottom
;
324 IntDispatchMsgRect(&skw
->Window
, MSG_GUI_REDRAW
, 0, 0, &srect
);
331 IntDispatchMsg(&skw
->Window
, MSG_COMMAND
, LOWORD(wParam
), 0);
335 return 1; /* don't handle this message */
338 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
343 * Registers a Win32 window class for all Sky windows
345 * @return Returns the atom of the class registered.
348 IntRegisterClass(void)
352 wc
.lpszClassName
= L
"ROSkyWindow";
353 wc
.lpfnWndProc
= IntDefaultWin32Proc
;
354 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
355 wc
.hInstance
= GetModuleHandleW(NULL
);
356 wc
.hIcon
= LoadIcon(NULL
, (LPCTSTR
)IDI_APPLICATION
);
357 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
)IDC_ARROW
);
358 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
359 wc
.lpszMenuName
= NULL
;
363 return RegisterClassW(&wc
);
371 GI_create_app(app_para
*p
)
374 ULONG Style
, ExStyle
;
375 WCHAR WindowName
[sizeof(p
->cpName
) / sizeof(p
->cpName
[0])];
378 DBG("GI_create_app(0x%x)\n", p
);
381 if(!SkyClassRegistered
)
383 SkyClassAtom
= IntRegisterClass();
384 SkyClassRegistered
= SkyClassAtom
!= 0;
386 if(!SkyClassRegistered
)
388 DBG("Unable to register the ROSkyWindow class\n");
394 skw
= (PSKY_WINDOW
)HeapAlloc(GetProcessHeap(),
399 DBG("Not enough memory to allocate a SKY_WINDOW structure!\n");
403 /* Convert the Sky window style to a Win32 window style */
404 Style
= IntMapWindowStyle(p
->ulStyle
, &ExStyle
);
406 /* convert the window caption to unicode */
407 MultiByteToWideChar(CP_UTF8
, 0, (char*)p
->cpName
, -1, WindowName
,
408 sizeof(WindowName
) / sizeof(WindowName
[0]));
410 skw
->Window
.win_func
= p
->win_func
;
411 /* FIXME - fill the window structure */
414 * We must convert the client rect passed in to the window rect expected
415 * by CreateWindowExW.
419 ClientRect
.right
= 0 + p
->ulWidth
;
420 ClientRect
.bottom
= 0 + p
->ulHeight
;
421 AdjustWindowRectEx(&ClientRect
, Style
, p
->ulStyle
& WF_HAS_MENU
, ExStyle
);
423 DBG("Menu: %x\n", p
->pMenu
? ((PSKY_MENU
)p
->pMenu
)->hMenu
: NULL
);
425 /* create the Win32 window */
426 skw
->hWnd
= CreateWindowExW(ExStyle
,
432 ClientRect
.right
- ClientRect
.left
,
433 ClientRect
.bottom
- ClientRect
.top
,
435 p
->pMenu
? ((PSKY_MENU
)p
->pMenu
)->hMenu
: NULL
,
436 GetModuleHandleW(NULL
),
439 if(skw
->hWnd
== NULL
)
441 DBG("CreateWindow() failed!\n");
442 HeapFree(GetProcessHeap(), 0, skw
);
446 DBG("Created Win32 window: 0x%x\n", skw
->hWnd
);
455 GI_destroy_window(s_window
*win
)
457 PSKY_WINDOW skw
= (PSKY_WINDOW
)win
;
459 DBG("GI_destroy_window(0x%x)\n", win
);
460 DestroyWindow(skw
->hWnd
);
461 HeapFree(GetProcessHeap(), 0, skw
);
471 GI_wait_message(s_gi_msg
*m
,
475 BOOL Ret
, SkyMessage
;
479 DBG("GI_wait_message(0x%x, 0x%x)\n", m
, w
);
481 hwndFilter
= (w
!= NULL
? ((PSKY_WINDOW
)w
)->hWnd
: NULL
);
484 Ret
= GetMessage(&Msg
, hwndFilter
, 0, 0);
486 /* loop until we found a message that a sky app would handle, too */
487 RtlZeroMemory(m
, sizeof(s_gi_msg
));
489 if(Msg
.hwnd
!= NULL
&& (msgwnd
= (PSKY_WINDOW
)GetWindowLongPtrW(Msg
.hwnd
, GWL_USERDATA
)))
491 SkyMessage
= IntIsSkyMessage(msgwnd
, &Msg
, m
);
500 /* We're not interested in dispatching a sky message, try again */
501 TranslateMessage(&Msg
);
502 DispatchMessage(&Msg
);
515 GI_dispatch_message(s_window
*win
,
518 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
519 DBG("GI_dispatch_message(0x%x, 0x%x - %d)\n", win
, m
, m
->type
);
520 /* dispatch the SkyOS message to the SkyOS window procedure */
522 return skywnd
->Window
.win_func(win
, m
);
531 GI_ShowApplicationWindow(s_window
*win
)
533 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
534 DBG("GI_ShowApplicationWindow(0x%x)\n", win
);
535 ShowWindow(skywnd
->hWnd
, SW_SHOW
);
544 GI_redraw_window(s_window
*win
)
546 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
547 DBG("GI_redraw_window(0x%x)!\n", win
);
550 RedrawWindow(skywnd
->hWnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_UPDATENOW
);
560 GI_post_quit(s_window
*win
)
562 DBG("GI_post_quit(0x%x)\n", win
);
563 PostMessage(((PSKY_WINDOW
)win
)->hWnd
, WM_QUIT
, 0, 0);
570 sCreateApplication
* __cdecl
571 GI_CreateApplicationStruct(void)
573 sCreateApplication
*app
;
575 app
= (sCreateApplication
*)HeapAlloc(GetProcessHeap(),
577 sizeof(sCreateApplication
));
578 STUB("GI_CreateApplicationStruct() returns 0x%x (allocated structure on the heap)!\n", app
);
588 GI_GetWindowX(s_window
*win
)
591 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
592 if((skywnd
!= NULL
) && GetWindowRect(skywnd
->hWnd
, &rc
))
594 MapWindowPoints(HWND_DESKTOP
, GetParent(skywnd
->hWnd
), (LPPOINT
)&rc
, 2);
595 DBG("GI_GetWindowS(0x%x) returns %d!\n", win
, rc
.left
);
601 DBG("GI_GetWindowS(0x%x) failed!\n", win
);
612 GI_GetWindowY(s_window
*win
)
615 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
616 if((skywnd
!= NULL
) && GetWindowRect(skywnd
->hWnd
, &rc
))
618 MapWindowPoints(HWND_DESKTOP
, GetParent(skywnd
->hWnd
), (LPPOINT
)&rc
, 2);
619 DBG("GI_GetWindowY(0x%x) returns %d!\n", win
, rc
.top
);
625 DBG("GI_GetWindowY(0x%x) failed!\n", win
);
636 GI_GetWindowWidth(s_window
*win
)
639 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
640 if((skywnd
!= NULL
) && GetWindowRect(skywnd
->hWnd
, &rc
))
642 DBG("GI_GetWindowWidth(0x%x) returns %d!\n", win
, (rc
.right
- rc
.left
));
643 return (rc
.right
- rc
.left
);
648 DBG("GI_GetWindowWidth(0x%x) failed!\n", win
);
659 GI_GetWindowHeight(s_window
*win
)
662 PSKY_WINDOW skywnd
= (PSKY_WINDOW
)win
;
663 if((skywnd
!= NULL
) && GetWindowRect(skywnd
->hWnd
, &rc
))
665 DBG("GI_GetWindowHeight(0x%x) returns %d!\n", win
, (rc
.bottom
- rc
.top
));
666 return (rc
.bottom
- rc
.top
);
671 DBG("GI_GetWindowHeight(0x%x) failed!\n", win
);
682 GI_GetTopLevelWindow(s_window
*win
)
684 STUB("GI_GetTopLevelWindow(0x%x) returns 0x%x!\n", win
, win
);
693 GI_create_DIB(void *Data
,
698 unsigned int PaletteSize
)
701 BITMAPINFO
*BitmapInfo
;
703 DBG("GI_create_DIB(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
704 Data
, Width
, Height
, Bpp
, Palette
, PaletteSize
);
706 Dib
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SKY_DIB
));
712 BitmapInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER
) +
713 PaletteSize
* sizeof(RGBQUAD
));
714 if (BitmapInfo
== NULL
)
716 HeapFree(GetProcessHeap(), 0, Dib
);
720 Dib
->Dib
.color
= Bpp
;
721 Dib
->Dib
.width
= Width
;
722 Dib
->Dib
.height
= Height
;
723 Dib
->Dib
.data
= Data
;
724 Dib
->Dib
.palette_size
= PaletteSize
;
725 Dib
->Dib
.palette
= Palette
;
727 BitmapInfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
728 BitmapInfo
->bmiHeader
.biWidth
= Width
;
729 BitmapInfo
->bmiHeader
.biHeight
= Height
;
730 BitmapInfo
->bmiHeader
.biPlanes
= 1;
731 BitmapInfo
->bmiHeader
.biBitCount
= Bpp
;
732 BitmapInfo
->bmiHeader
.biCompression
= BI_RGB
;
733 BitmapInfo
->bmiHeader
.biSizeImage
= 0;
734 BitmapInfo
->bmiHeader
.biXPelsPerMeter
= 0;
735 BitmapInfo
->bmiHeader
.biYPelsPerMeter
= 0;
736 BitmapInfo
->bmiHeader
.biClrUsed
= PaletteSize
;
737 BitmapInfo
->bmiHeader
.biClrImportant
= 0;
738 RtlCopyMemory(BitmapInfo
->bmiColors
, Palette
, PaletteSize
* sizeof(RGBQUAD
));
740 Dib
->hBitmap
= CreateDIBSection(NULL
,
746 HeapFree(GetProcessHeap(), 0, BitmapInfo
);
747 if (Dib
->hBitmap
== NULL
)
749 HeapFree(GetProcessHeap(), 0, Dib
);
761 GC_create_connected(unsigned int Type
,
768 DBG("GC_create_connected(0x%x, 0x%x, 0x%x, 0x%x)\n",
769 Type
, Width
, Height
, Win
);
773 DBG("GC_create_connected: no window specified! returned NULL!\n");
777 Gc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SKY_GC
));
783 Gc
->GraphicsContext
.type
= Type
;
784 Gc
->GraphicsContext
.width
= Width
;
785 Gc
->GraphicsContext
.height
= Height
;
790 Gc
->hDC
= CreateCompatibleDC(0);
793 Gc
->GraphicsContext
.hDIB
= (DIB
*)Win
;
794 SelectObject(Gc
->hDC
, ((PSKY_DIB
)Win
)->hBitmap
);
795 ((PSKY_DIB
)Win
)->hAssociateDC
= Gc
->hDC
;
800 Gc
->hDC
= GetDC(((PSKY_WINDOW
)Win
)->hWnd
);
801 Gc
->GraphicsContext
.window
= Win
;
805 DBG("Unknown GC type: %x\n", Type
);
810 HeapFree(GetProcessHeap(), 0, Gc
);
815 SelectObject(Gc
->hDC
, GetStockObject(DC_BRUSH
));
816 SelectObject(Gc
->hDC
, GetStockObject(DC_PEN
));
827 GC_set_fg_color(GC
*Gc
,
832 Gc
->fg_color
= Color
;
833 SetDCPenColor(((PSKY_GC
)Gc
)->hDC
, Color
);
839 DBG("GC_set_fg_color: Gc == NULL!\n");
850 GC_set_bg_color(GC
*Gc
,
855 Gc
->bg_color
= Color
;
856 SetDCBrushColor(((PSKY_GC
)Gc
)->hDC
, Color
);
862 DBG("GC_set_bg_color: Gc == NULL!\n");
873 GC_draw_pixel(GC
*Gc
,
879 SetPixelV(((PSKY_GC
)Gc
)->hDC
, X
, Y
, Gc
->fg_color
);
885 DBG("GC_draw_pixel: Gc == NULL!\n");
896 GC_blit_from_DIB(GC
*Gc
,
903 HBITMAP hOldBitmap
= NULL
;
905 DBG("GC_blit_from_DIB(0x%x, 0x%x, 0x%x, 0x%x)\n", Gc
, Dib
, X
, Y
);
907 if (((PSKY_DIB
)Dib
)->hAssociateDC
== NULL
)
909 hSrcDC
= CreateCompatibleDC(0);
910 hOldBitmap
= SelectObject(hSrcDC
, ((PSKY_DIB
)Dib
)->hBitmap
);
914 hSrcDC
= ((PSKY_DIB
)Dib
)->hAssociateDC
;
917 Result
= BitBlt(((PSKY_GC
)Gc
)->hDC
, X
, Y
, Dib
->width
, Dib
->height
,
918 hSrcDC
, 0, 0, SRCCOPY
);
920 if (((PSKY_DIB
)Dib
)->hAssociateDC
== NULL
)
922 SelectObject(hSrcDC
, hOldBitmap
);
934 GC_draw_rect_fill(GC
*Gc
,
940 DBG("GC_draw_rect_fill(0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
941 Gc
, X
, Y
, Width
, Height
);
950 Rect
.right
= X
+ Width
;
951 Rect
.bottom
= Y
+ Height
;
953 hBrush
= CreateSolidBrush(Gc
->bg_color
);
954 FillRect(((PSKY_GC
)Gc
)->hDC
, &Rect
, hBrush
);
955 DeleteObject(hBrush
);
962 DBG("GC_draw_rect_fill: Gc == NULL!\n");
979 DBG("GC_draw_line(0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", Gc
, x1
, y1
, x2
, y2
);
982 MoveToEx(((PSKY_GC
)Gc
)->hDC
, x1
, y1
, NULL
);
983 LineTo(((PSKY_GC
)Gc
)->hDC
, x2
, y2
);
989 DBG("GC_draw_line: Gc == NULL!\n");
1002 DBG("GC_destroy(0x%x)\n", Gc
);
1008 DeleteDC(((PSKY_GC
)Gc
)->hDC
);
1011 case GC_TYPE_WINDOW
:
1012 ReleaseDC(((PSKY_WINDOW
)Gc
->window
)->hWnd
, ((PSKY_GC
)Gc
)->hDC
);
1016 DBG("Unknown GC type: %x\n", Gc
->type
);
1018 HeapFree(GetProcessHeap(), 0, Gc
);
1024 DBG("GC_destroy: Gc == NULL!\n");
1034 widget_menu
* __cdecl
1035 GI_create_menu(s_window
*win
)
1039 DBG("GI_create_menu(0x%x)\n", win
);
1041 Menu
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SKY_MENU
));
1047 /* Shouldn't we use CreatePopupMenu in some cases? */
1048 Menu
->hMenu
= CreateMenu();
1049 if (Menu
->hMenu
== NULL
)
1051 HeapFree(GetProcessHeap(), 0, Menu
);
1057 SetMenu(((PSKY_WINDOW
)win
)->hWnd
, Menu
->hMenu
);
1060 return (widget_menu
*)Menu
;
1067 widget_menu_item
* __cdecl
1068 GI_create_menu_item(unsigned char *Text
,
1071 unsigned int Enabled
)
1073 PSKY_MENUITEM MenuItem
;
1076 DBG("GI_create_menu_item(0x%x, 0x%x, 0x%x, 0x%x)\n",
1077 Text
, Id
, Flags
, Enabled
);
1079 TextLength
= MultiByteToWideChar(CP_UTF8
, 0, (char*)Text
, -1, NULL
, 0);
1080 MenuItem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1081 sizeof(SKY_MENUITEM
) + TextLength
* sizeof(WCHAR
));
1082 if (MenuItem
== NULL
)
1087 lstrcpyA((char*)MenuItem
->MenuItem
.text
, (char*)Text
);
1088 MenuItem
->MenuItem
.ID
= Id
;
1089 MenuItem
->MenuItem
.flags
= Flags
;
1090 MenuItem
->MenuItem
.enabled
= Enabled
;
1092 MenuItem
->MenuItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
1093 MenuItem
->MenuItemInfo
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
1094 if (Flags
& MENU_SEPERATOR
)
1095 MenuItem
->MenuItemInfo
.fType
= MF_SEPARATOR
;
1097 MenuItem
->MenuItemInfo
.fType
= MF_STRING
;
1098 MenuItem
->MenuItemInfo
.fState
= Enabled
? MFS_ENABLED
: 0;
1099 MenuItem
->MenuItemInfo
.wID
= Id
;
1100 MenuItem
->MenuItemInfo
.dwTypeData
= (LPWSTR
)(MenuItem
+ 1);
1101 MenuItem
->MenuItemInfo
.cch
= TextLength
;
1102 MultiByteToWideChar(CP_UTF8
, 0, (char*)Text
, TextLength
, (LPWSTR
)(MenuItem
+ 1),
1105 return (widget_menu_item
*)MenuItem
;
1113 GI_add_menu_item(widget_menu
*Menu
,
1114 widget_menu_item
*Item
)
1116 DBG("GI_add_menu_item(0x%x, 0x%x)\n", Menu
, Item
);
1117 InsertMenuItemW(((PSKY_MENU
)Menu
)->hMenu
, -1, TRUE
,
1118 &((PSKY_MENUITEM
)Item
)->MenuItemInfo
);
1127 GI_add_menu_sub(widget_menu
*Menu
,
1128 widget_menu_item
*Item
,
1131 PSKY_MENUITEM MenuItem
= (PSKY_MENUITEM
)Item
;
1133 DBG("GI_add_menu_sub(0x%x, 0x%x, 0x%x)\n", Menu
, Item
, Sub
);
1134 MenuItem
->MenuItemInfo
.fMask
|= MIIM_SUBMENU
;
1135 MenuItem
->MenuItemInfo
.hSubMenu
= ((PSKY_MENU
)Sub
)->hMenu
;
1136 InsertMenuItemW(((PSKY_MENU
)Menu
)->hMenu
, -1, TRUE
,
1137 &MenuItem
->MenuItemInfo
);
1146 GI_messagebox(s_window
*Window
,
1154 ULONG MbFlags
, MbResult
;
1156 DBG("GI_messagebox(0x%x, 0x%x, 0x%x, 0x%x, ...)\n",
1157 Window
, Flags
, Title
, Fmt
);
1159 va_start(ArgList
, Fmt
);
1160 _vsnprintf(Buffer
, sizeof(Buffer
) / sizeof(Buffer
[0]), Fmt
, ArgList
);
1163 if ((Flags
& (WGF_MB_CANCEL
| WGF_MB_YESNO
)) ==
1164 (WGF_MB_CANCEL
| WGF_MB_YESNO
))
1165 MbFlags
= MB_YESNOCANCEL
;
1166 else if (Flags
& WGF_MB_YESNO
)
1168 else /* if (Flags & WGF_MB_OK) */
1170 MbFlags
|= (Flags
& WGF_MB_ICON_INFO
) ? MB_ICONASTERISK
: 0;
1171 MbFlags
|= (Flags
& WGF_MB_ICON_ASK
) ? MB_ICONQUESTION
: 0;
1172 MbFlags
|= (Flags
& WGF_MB_ICON_STOP
) ? MB_ICONERROR
: 0;
1174 MbResult
= MessageBoxA(Window
? ((PSKY_WINDOW
)Window
)->hWnd
: NULL
,
1175 Buffer
, Title
, MbFlags
);
1179 case IDOK
: return ID_OK
;
1180 case IDYES
: return ID_YES
;
1181 case IDNO
: return ID_NO
;
1182 case IDCANCEL
: return ID_CANCEL
;
1193 GI_EnableMouseTracking(s_window
*win
)
1195 DBG("GI_EnableMouseTracking(0x%x)!\n", win
);
1198 ((PSKY_WINDOW
)win
)->MouseInput
= TRUE
;
1204 DBG("GI_EnableMouseTracking: win == NULL!\n");