1 | /* $Id: oslibmenu.cpp,v 1.12 2000-03-13 13:10:46 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Window Menu wrapper functions for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_WIN
|
---|
13 | #define INCL_PM
|
---|
14 | #include <os2wrap.h>
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <string.h>
|
---|
17 |
|
---|
18 | #include <misc.h>
|
---|
19 | #include <winconst.h>
|
---|
20 | #include "oslibwin.h"
|
---|
21 | #include "oslibutil.h"
|
---|
22 | #include "oslibmenu.h"
|
---|
23 |
|
---|
24 | #define DBG_LOCALLOG DBG_oslibmenu
|
---|
25 | #include "dbglocal.h"
|
---|
26 |
|
---|
27 | //******************************************************************************
|
---|
28 | //******************************************************************************
|
---|
29 | HWND OSLibWinSetMenu(HWND hwndParent, HMENU hMenu)
|
---|
30 | {
|
---|
31 | // Remove current menu from window
|
---|
32 | HWND currMenu = WinWindowFromID( (HWND)hwndParent, FID_MENU );
|
---|
33 | if (currMenu)
|
---|
34 | {
|
---|
35 | dprintf(("OSLibWinSetMenu: old menu %x, new menu %x", currMenu, hMenu));
|
---|
36 | WinSetOwner (currMenu, HWND_OBJECT);
|
---|
37 | WinSetParent(currMenu, HWND_OBJECT, FALSE);
|
---|
38 | }
|
---|
39 |
|
---|
40 | if (hMenu)
|
---|
41 | {
|
---|
42 | if(WinIsWindow(GetThreadHAB(), hMenu) == TRUE)
|
---|
43 | {
|
---|
44 | WinSetOwner (hMenu, hwndParent);
|
---|
45 | WinSetParent(hMenu, hwndParent, FALSE );
|
---|
46 | WinSetWindowUShort(hMenu, QWS_ID, FID_MENU);
|
---|
47 | WinSendMsg(hwndParent, WM_UPDATEFRAME, (MPARAM)FCF_MENU, 0);
|
---|
48 | return hMenu;
|
---|
49 | }
|
---|
50 | else {
|
---|
51 | dprintf(("OSLibWinSetMenu: %x = invalid menu handle", hMenu));
|
---|
52 | }
|
---|
53 | }
|
---|
54 | return 0;
|
---|
55 | }
|
---|
56 | //******************************************************************************
|
---|
57 | //******************************************************************************
|
---|
58 | int OSLibGetMenuItemCount(HWND hMenu)
|
---|
59 | {
|
---|
60 | return (int)SHORT1FROMMR(WinSendMsg(hMenu, MM_QUERYITEMCOUNT, NULL, NULL));
|
---|
61 | }
|
---|
62 | //******************************************************************************
|
---|
63 | //******************************************************************************
|
---|
64 | HMENU OSLibWinCreateMenu(PVOID menutemplate)
|
---|
65 | {
|
---|
66 | return (HMENU)WinCreateMenu(HWND_OBJECT, menutemplate);
|
---|
67 | }
|
---|
68 | //******************************************************************************
|
---|
69 | //******************************************************************************
|
---|
70 | HMENU OSLibWinCreateEmptyMenu()
|
---|
71 | {
|
---|
72 | return WinCreateWindow(HWND_OBJECT, WC_MENU, NULL, MS_ACTIONBAR | 0x0008 | WS_SAVEBITS,
|
---|
73 | 0, 0, 0, 0, HWND_OBJECT, HWND_TOP, 0, NULL, NULL);
|
---|
74 | }
|
---|
75 | //******************************************************************************
|
---|
76 | //******************************************************************************
|
---|
77 | HMENU OSLibWinCreateEmptyPopupMenu()
|
---|
78 | {
|
---|
79 | return WinCreateWindow(HWND_OBJECT, WC_MENU, NULL, WS_CLIPSIBLINGS | WS_SAVEBITS,
|
---|
80 | 0, 0, 0, 0, HWND_OBJECT, HWND_TOP, 0, NULL, NULL);
|
---|
81 | }
|
---|
82 | //******************************************************************************
|
---|
83 | //Returns menu item rectange in screen coordinates
|
---|
84 | //******************************************************************************
|
---|
85 | BOOL OSLibGetMenuItemRect(HWND hMenu, int index, LPRECT pRect)
|
---|
86 | {
|
---|
87 | RECTL rectl;
|
---|
88 | BOOL rc;
|
---|
89 | ULONG id;
|
---|
90 |
|
---|
91 | //First get id from menu index
|
---|
92 | id = (ULONG)WinSendMsg(hMenu, MM_ITEMIDFROMPOSITION, MPARAM(index), 0);
|
---|
93 |
|
---|
94 | rc = (BOOL)WinSendMsg(hMenu, MM_QUERYITEMRECT, MPARAM(id), (MPARAM)&rectl);
|
---|
95 | if(rc == FALSE) {
|
---|
96 | dprintf(("OSLibGetMenuItemRect %x %d %d failed!", hMenu, index, id));
|
---|
97 | return FALSE;
|
---|
98 | }
|
---|
99 | WinMapWindowPoints(hMenu, HWND_DESKTOP, (PPOINTL)&rectl, 2);
|
---|
100 | pRect->left = rectl.xLeft;
|
---|
101 | pRect->right = rectl.xRight;
|
---|
102 | pRect->top = OSLibQueryScreenHeight() - rectl.yTop;
|
---|
103 | pRect->bottom= OSLibQueryScreenHeight() - rectl.yBottom;
|
---|
104 | return TRUE;
|
---|
105 | }
|
---|
106 | //******************************************************************************
|
---|
107 | //******************************************************************************
|
---|
108 |
|
---|