[10119] | 1 | /* $Id: win32wmisc.cpp,v 1.3 2003-05-27 09:46:30 sandervl Exp $ */
|
---|
[6762] | 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>
|
---|
[10119] | 22 | #include <dbglog.h>
|
---|
[21916] | 23 | #include "win32wnd.h"
|
---|
[6762] | 24 | #include <heapstring.h>
|
---|
| 25 | #include <spy.h>
|
---|
| 26 | #include "wndmsg.h"
|
---|
[21916] | 27 | #include "oslibwin.h"
|
---|
| 28 | #include "oslibutil.h"
|
---|
| 29 | #include "oslibgdi.h"
|
---|
| 30 | #include "oslibres.h"
|
---|
[6762] | 31 | #include "oslibdos.h"
|
---|
| 32 | #include "win32wndhandle.h"
|
---|
| 33 | #include "win32wmisc.h"
|
---|
[9598] | 34 | #include "ctrlconf.h"
|
---|
[6762] | 35 |
|
---|
| 36 | //******************************************************************************
|
---|
| 37 | //******************************************************************************
|
---|
| 38 | /*******************************************************************
|
---|
| 39 | * WIN_ListChildren
|
---|
| 40 | *
|
---|
| 41 | * Build an array of the children of a given window. The array must be
|
---|
| 42 | * freed with HeapFree. Returns NULL when no windows are found.
|
---|
| 43 | */
|
---|
| 44 | HWND *WIN_ListChildren( HWND hwnd )
|
---|
| 45 | {
|
---|
| 46 | Win32BaseWindow *parent = Win32BaseWindow::GetWindowFromHandle(hwnd), *win32wnd;
|
---|
| 47 | HWND *list, *phwnd;
|
---|
| 48 | UINT count = 0;
|
---|
| 49 |
|
---|
| 50 | if(parent == NULL) {
|
---|
| 51 | dprintf(("ERROR: WIN_ListChildren invalid hwnd %x", hwnd));
|
---|
| 52 | return 0;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /* First count the windows */
|
---|
| 56 | win32wnd = (Win32BaseWindow*)parent->getFirstChild();
|
---|
| 57 | while (win32wnd)
|
---|
| 58 | {
|
---|
| 59 | count++;
|
---|
| 60 | win32wnd = (Win32BaseWindow*)win32wnd->getNextChild();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | if( count )
|
---|
| 64 | {
|
---|
| 65 | /* Now build the list of all windows */
|
---|
| 66 |
|
---|
[21356] | 67 | if ((list = (HWND *)HeapAlloc( GetProcessHeap(), 0, sizeof(HWND) * (count + 1))) != NULL)
|
---|
[6762] | 68 | {
|
---|
| 69 | win32wnd = (Win32BaseWindow*)parent->getFirstChild();
|
---|
| 70 | phwnd = list;
|
---|
| 71 | count = 0;
|
---|
| 72 | while(win32wnd)
|
---|
| 73 | {
|
---|
| 74 | *phwnd++ = win32wnd->getWindowHandle();
|
---|
| 75 | count++;
|
---|
| 76 | win32wnd = (Win32BaseWindow*)win32wnd->getNextChild();
|
---|
| 77 | }
|
---|
| 78 | *phwnd = 0;
|
---|
| 79 | }
|
---|
| 80 | else count = 0;
|
---|
| 81 | } else list = NULL;
|
---|
| 82 |
|
---|
| 83 | RELEASE_WNDOBJ(parent);
|
---|
| 84 | return list;
|
---|
| 85 | }
|
---|
| 86 | //******************************************************************************
|
---|
| 87 | //******************************************************************************
|
---|
| 88 | MDICLIENTINFO *get_client_info( HWND hwndClient )
|
---|
| 89 | {
|
---|
| 90 | MDICLIENTINFO *ret = NULL;
|
---|
| 91 | Win32BaseWindow *client = Win32BaseWindow::GetWindowFromHandle(hwndClient);
|
---|
| 92 |
|
---|
| 93 | if (client)
|
---|
| 94 | {
|
---|
| 95 | if (client->getCBExtra() < sizeof(MDICLIENTINFO)) {
|
---|
| 96 | dprintf(("WARNING: get_client_info %x is not an MDI client", hwndClient ));
|
---|
| 97 | }
|
---|
| 98 | else ret = (MDICLIENTINFO*)client->getExtraPtr();
|
---|
| 99 | RELEASE_WNDOBJ(client);
|
---|
| 100 | }
|
---|
| 101 | return ret;
|
---|
| 102 | }
|
---|
| 103 | //******************************************************************************
|
---|
| 104 | //******************************************************************************
|
---|
| 105 | void GetWindowRectParent(HWND hwnd, RECT *pRect)
|
---|
| 106 | {
|
---|
| 107 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 108 |
|
---|
| 109 | if (window)
|
---|
| 110 | {
|
---|
| 111 | *pRect = *window->getWindowRect();
|
---|
| 112 | RELEASE_WNDOBJ(window);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | //******************************************************************************
|
---|
| 116 | //******************************************************************************
|
---|
| 117 | HMENU WIN32API getSysMenu(HWND hwnd)
|
---|
| 118 | {
|
---|
| 119 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 120 |
|
---|
| 121 | if(win32wnd) {
|
---|
| 122 | HMENU hmenu = win32wnd->GetSysMenu();
|
---|
| 123 | RELEASE_WNDOBJ(win32wnd);
|
---|
| 124 | return hmenu;
|
---|
| 125 | }
|
---|
| 126 | return (HMENU)0;
|
---|
| 127 | }
|
---|
| 128 | //******************************************************************************
|
---|
| 129 | //******************************************************************************
|
---|
| 130 | VOID setSysMenu(HWND hwnd,HMENU hMenu)
|
---|
| 131 | {
|
---|
| 132 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 133 |
|
---|
| 134 | if(win32wnd) {
|
---|
| 135 | win32wnd->SetSysMenu(hMenu);
|
---|
| 136 | RELEASE_WNDOBJ(win32wnd);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | /***********************************************************************
|
---|
| 140 | * NC_GetSysPopupPos
|
---|
| 141 | */
|
---|
| 142 | void NC_GetSysPopupPos( HWND hwnd, RECT* rect )
|
---|
| 143 | {
|
---|
[9598] | 144 | if (IsIconic(hwnd)) GetWindowRect( hwnd, rect );
|
---|
| 145 | else
|
---|
| 146 | {
|
---|
| 147 | #ifdef __WIN32OS2__
|
---|
| 148 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 149 | if (!win32wnd) return;
|
---|
[6762] | 150 |
|
---|
[9598] | 151 | win32wnd->GetSysPopupPos(rect);
|
---|
[6762] | 152 |
|
---|
[9598] | 153 | RELEASE_WNDOBJ(win32wnd);
|
---|
| 154 | #else
|
---|
| 155 | WND *wndPtr = WIN_FindWndPtr( hwnd );
|
---|
| 156 | if (!wndPtr) return;
|
---|
| 157 |
|
---|
| 158 | NC_GetInsideRect( hwnd, rect );
|
---|
| 159 | OffsetRect( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
|
---|
| 160 | if (wndPtr->dwStyle & WS_CHILD)
|
---|
| 161 | ClientToScreen( GetParent(hwnd), (POINT *)rect );
|
---|
| 162 | if (TWEAK_WineLook == WIN31_LOOK) {
|
---|
| 163 | rect->right = rect->left + GetSystemMetrics(SM_CXSIZE);
|
---|
| 164 | rect->bottom = rect->top + GetSystemMetrics(SM_CYSIZE);
|
---|
| 165 | }
|
---|
| 166 | else {
|
---|
| 167 | rect->right = rect->left + GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
| 168 | rect->bottom = rect->top + GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
| 169 | }
|
---|
| 170 | WIN_ReleaseWndPtr( wndPtr );
|
---|
| 171 | #endif
|
---|
| 172 | }
|
---|
[6762] | 173 | }
|
---|
[9598] | 174 | //*****************************************************************************
|
---|
| 175 | //*****************************************************************************
|
---|
| 176 | BOOL NC_DrawSysButton95 (HWND hwnd, HDC hdc, BOOL down)
|
---|
| 177 | {
|
---|
| 178 | BOOL ret;
|
---|
| 179 |
|
---|
| 180 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 181 | if (!win32wnd) return FALSE;
|
---|
| 182 |
|
---|
| 183 | ret = win32wnd->DrawSysButton(hdc, NULL);
|
---|
| 184 |
|
---|
| 185 | RELEASE_WNDOBJ(win32wnd);
|
---|
| 186 |
|
---|
| 187 | return ret;
|
---|
| 188 | }
|
---|
| 189 | //*****************************************************************************
|
---|
| 190 | //*****************************************************************************
|
---|
| 191 | INT NC_HandleNCHitTest( HWND hwnd, POINT pt)
|
---|
| 192 | {
|
---|
| 193 | INT ht;
|
---|
| 194 |
|
---|
| 195 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 196 | if(win32wnd==NULL) {
|
---|
| 197 | //SvL: This happens in Moraff's YourJongg 2.0, return here
|
---|
| 198 | //TODO: Check if this is supposed to happen at all...
|
---|
| 199 | return HTERROR;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | ht = win32wnd->HandleNCHitTest(pt);
|
---|
| 203 | RELEASE_WNDOBJ(win32wnd);
|
---|
| 204 |
|
---|
| 205 | return ht;
|
---|
| 206 | }
|
---|
| 207 | //*****************************************************************************
|
---|
| 208 | //*****************************************************************************
|
---|