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