| 1 | /* $Id: win32wmisc.cpp,v 1.1 2001-09-19 15:39:51 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Misc. functions for window management
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 6 | *
|
|---|
| 7 | * Parts based on Wine (windows\mdi.c; windows\win.c)
|
|---|
| 8 | *
|
|---|
| 9 | * Copyright 1994, Bob Amstadt
|
|---|
| 10 | * 1995,1996 Alex Korobka
|
|---|
| 11 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 12 | *
|
|---|
| 13 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 14 | *
|
|---|
| 15 | */
|
|---|
| 16 | #include <os2win.h>
|
|---|
| 17 | #include <win.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <stdarg.h>
|
|---|
| 21 | #include <assert.h>
|
|---|
| 22 | #include <misc.h>
|
|---|
| 23 | #include <win32wnd.h>
|
|---|
| 24 | #include <heapstring.h>
|
|---|
| 25 | #include <spy.h>
|
|---|
| 26 | #include "wndmsg.h"
|
|---|
| 27 | #include <oslibwin.h>
|
|---|
| 28 | #include <oslibutil.h>
|
|---|
| 29 | #include <oslibgdi.h>
|
|---|
| 30 | #include <oslibres.h>
|
|---|
| 31 | #include "oslibdos.h"
|
|---|
| 32 | #include "win32wndhandle.h"
|
|---|
| 33 | #include "win32wmisc.h"
|
|---|
| 34 |
|
|---|
| 35 | //******************************************************************************
|
|---|
| 36 | //******************************************************************************
|
|---|
| 37 | /*******************************************************************
|
|---|
| 38 | * WIN_ListChildren
|
|---|
| 39 | *
|
|---|
| 40 | * Build an array of the children of a given window. The array must be
|
|---|
| 41 | * freed with HeapFree. Returns NULL when no windows are found.
|
|---|
| 42 | */
|
|---|
| 43 | HWND *WIN_ListChildren( HWND hwnd )
|
|---|
| 44 | {
|
|---|
| 45 | Win32BaseWindow *parent = Win32BaseWindow::GetWindowFromHandle(hwnd), *win32wnd;
|
|---|
| 46 | HWND *list, *phwnd;
|
|---|
| 47 | UINT count = 0;
|
|---|
| 48 |
|
|---|
| 49 | if(parent == NULL) {
|
|---|
| 50 | dprintf(("ERROR: WIN_ListChildren invalid hwnd %x", hwnd));
|
|---|
| 51 | return 0;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | /* First count the windows */
|
|---|
| 55 | win32wnd = (Win32BaseWindow*)parent->getFirstChild();
|
|---|
| 56 | while (win32wnd)
|
|---|
| 57 | {
|
|---|
| 58 | count++;
|
|---|
| 59 | win32wnd = (Win32BaseWindow*)win32wnd->getNextChild();
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | if( count )
|
|---|
| 63 | {
|
|---|
| 64 | /* Now build the list of all windows */
|
|---|
| 65 |
|
|---|
| 66 | if ((list = (HWND *)HeapAlloc( GetProcessHeap(), 0, sizeof(HWND) * (count + 1))))
|
|---|
| 67 | {
|
|---|
| 68 | win32wnd = (Win32BaseWindow*)parent->getFirstChild();
|
|---|
| 69 | phwnd = list;
|
|---|
| 70 | count = 0;
|
|---|
| 71 | while(win32wnd)
|
|---|
| 72 | {
|
|---|
| 73 | *phwnd++ = win32wnd->getWindowHandle();
|
|---|
| 74 | count++;
|
|---|
| 75 | win32wnd = (Win32BaseWindow*)win32wnd->getNextChild();
|
|---|
| 76 | }
|
|---|
| 77 | *phwnd = 0;
|
|---|
| 78 | }
|
|---|
| 79 | else count = 0;
|
|---|
| 80 | } else list = NULL;
|
|---|
| 81 |
|
|---|
| 82 | RELEASE_WNDOBJ(parent);
|
|---|
| 83 | return list;
|
|---|
| 84 | }
|
|---|
| 85 | //******************************************************************************
|
|---|
| 86 | //******************************************************************************
|
|---|
| 87 | MDICLIENTINFO *get_client_info( HWND hwndClient )
|
|---|
| 88 | {
|
|---|
| 89 | MDICLIENTINFO *ret = NULL;
|
|---|
| 90 | Win32BaseWindow *client = Win32BaseWindow::GetWindowFromHandle(hwndClient);
|
|---|
| 91 |
|
|---|
| 92 | if (client)
|
|---|
| 93 | {
|
|---|
| 94 | if (client->getCBExtra() < sizeof(MDICLIENTINFO)) {
|
|---|
| 95 | dprintf(("WARNING: get_client_info %x is not an MDI client", hwndClient ));
|
|---|
| 96 | }
|
|---|
| 97 | else ret = (MDICLIENTINFO*)client->getExtraPtr();
|
|---|
| 98 | RELEASE_WNDOBJ(client);
|
|---|
| 99 | }
|
|---|
| 100 | return ret;
|
|---|
| 101 | }
|
|---|
| 102 | //******************************************************************************
|
|---|
| 103 | //******************************************************************************
|
|---|
| 104 | void GetWindowRectParent(HWND hwnd, RECT *pRect)
|
|---|
| 105 | {
|
|---|
| 106 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 107 |
|
|---|
| 108 | if (window)
|
|---|
| 109 | {
|
|---|
| 110 | *pRect = *window->getWindowRect();
|
|---|
| 111 | RELEASE_WNDOBJ(window);
|
|---|
| 112 | }
|
|---|
| 113 | }
|
|---|
| 114 | //******************************************************************************
|
|---|
| 115 | //******************************************************************************
|
|---|
| 116 | HMENU WIN32API getSysMenu(HWND hwnd)
|
|---|
| 117 | {
|
|---|
| 118 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 119 |
|
|---|
| 120 | if(win32wnd) {
|
|---|
| 121 | HMENU hmenu = win32wnd->GetSysMenu();
|
|---|
| 122 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 123 | return hmenu;
|
|---|
| 124 | }
|
|---|
| 125 | return (HMENU)0;
|
|---|
| 126 | }
|
|---|
| 127 | //******************************************************************************
|
|---|
| 128 | //******************************************************************************
|
|---|
| 129 | VOID setSysMenu(HWND hwnd,HMENU hMenu)
|
|---|
| 130 | {
|
|---|
| 131 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 132 |
|
|---|
| 133 | if(win32wnd) {
|
|---|
| 134 | win32wnd->SetSysMenu(hMenu);
|
|---|
| 135 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|
| 138 | /***********************************************************************
|
|---|
| 139 | * NC_GetSysPopupPos
|
|---|
| 140 | */
|
|---|
| 141 | void NC_GetSysPopupPos( HWND hwnd, RECT* rect )
|
|---|
| 142 | {
|
|---|
| 143 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 144 |
|
|---|
| 145 | if (!win32wnd) return;
|
|---|
| 146 |
|
|---|
| 147 | win32wnd->GetSysPopupPos(rect);
|
|---|
| 148 | RELEASE_WNDOBJ(win32wnd);
|
|---|
| 149 | }
|
|---|
| 150 | //******************************************************************************
|
|---|
| 151 | //******************************************************************************
|
|---|