1 | /* $Id: pmwindow.cpp,v 1.230 2004-05-24 09:01:59 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Managment Code for OS/2
|
---|
4 | *
|
---|
5 | * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
6 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_WIN
|
---|
13 | #define INCL_GPI
|
---|
14 | #define INCL_DEV /* Device Function definitions */
|
---|
15 | #define INCL_GPICONTROL /* GPI control Functions */
|
---|
16 | #define INCL_DOSPROCESS
|
---|
17 | #define INCL_DOSMODULEMGR
|
---|
18 | #define INCL_DOSDEVICES
|
---|
19 | #define INCL_DOSDEVIOCTL
|
---|
20 | #define INCL_WINTRACKRECT
|
---|
21 | #define INCL_BASE
|
---|
22 |
|
---|
23 | #include <os2wrap.h>
|
---|
24 | #include <odinwrap.h>
|
---|
25 | #include <stdio.h>
|
---|
26 | #include <stdlib.h>
|
---|
27 | #include <string.h>
|
---|
28 | #include <win32type.h>
|
---|
29 | #include <win32api.h>
|
---|
30 | #include <winconst.h>
|
---|
31 | #include <winuser32.h>
|
---|
32 | #include <wprocess.h>
|
---|
33 | #include <dbglog.h>
|
---|
34 | #include <win32wbase.h>
|
---|
35 | #include <win32wfake.h>
|
---|
36 | #include <win32dlg.h>
|
---|
37 | #include "win32wdesktop.h"
|
---|
38 | #include "pmwindow.h"
|
---|
39 | #include "oslibwin.h"
|
---|
40 | #include "oslibutil.h"
|
---|
41 | #include "oslibgdi.h"
|
---|
42 | #include "oslibmsg.h"
|
---|
43 | #define INCLUDED_BY_DC
|
---|
44 | #include "dc.h"
|
---|
45 | #include <thread.h>
|
---|
46 | #include <wprocess.h>
|
---|
47 | #include <objhandle.h>
|
---|
48 | #include "caret.h"
|
---|
49 | #include "timer.h"
|
---|
50 | #include <codepage.h>
|
---|
51 | #include "syscolor.h"
|
---|
52 | #include "options.h"
|
---|
53 | #include "menu.h"
|
---|
54 | #include <pmkbdhk.h>
|
---|
55 | #include <pmscan.h>
|
---|
56 | #include <winscan.h>
|
---|
57 | #include <oslibdnd.h>
|
---|
58 | #include <custombuild.h>
|
---|
59 | #include <win\dbt.h>
|
---|
60 | #include "dragdrop.h"
|
---|
61 | #include "menu.h"
|
---|
62 | #include "user32api.h"
|
---|
63 | #include <kbdhook.h>
|
---|
64 | #include <heapstring.h>
|
---|
65 |
|
---|
66 | #include <os2im.h>
|
---|
67 | #include <im32.h>
|
---|
68 |
|
---|
69 | #define DBG_LOCALLOG DBG_pmwindow
|
---|
70 | #include "dbglocal.h"
|
---|
71 |
|
---|
72 |
|
---|
73 | // Notification that focus change has completed (UNDOCUMENTED)
|
---|
74 | #define WM_FOCUSCHANGED 0x000e
|
---|
75 |
|
---|
76 | //define this to use the new code for WM_CALCVALIDRECT handling
|
---|
77 | //#define USE_CALCVALIDRECT
|
---|
78 |
|
---|
79 | HMQ hmq = 0; /* Message queue handle */
|
---|
80 | HAB hab = 0;
|
---|
81 | RECTL desktopRectl = {0};
|
---|
82 | ULONG ScreenWidth = 0;
|
---|
83 | ULONG ScreenHeight = 0;
|
---|
84 | ULONG ScreenBitsPerPel = 0;
|
---|
85 | BOOL fOS2Look = FALSE;
|
---|
86 | BOOL fForceMonoCursor = FALSE;
|
---|
87 | BOOL fDragDropActive = FALSE;
|
---|
88 | BOOL fDragDropDisabled = FALSE;
|
---|
89 |
|
---|
90 | const char WIN32_CDCLASS[] = ODIN_WIN32_CDCLASS;
|
---|
91 | char WIN32_STDCLASS[255] = ODIN_WIN32_STDCLASS;
|
---|
92 |
|
---|
93 | #define PMMENU_MINBUTTON 0
|
---|
94 | #define PMMENU_MAXBUTTON 1
|
---|
95 | #define PMMENU_RESTOREBUTTON 2
|
---|
96 | #define PMMENU_CLOSEBUTTON 3
|
---|
97 | #define PMMENU_MINBUTTONDOWN 4
|
---|
98 | #define PMMENU_MAXBUTTONDOWN 5
|
---|
99 | #define PMMENU_RESTOREBUTTONDOWN 6
|
---|
100 | #define PMMENU_CLOSEBUTTONDOWN 7
|
---|
101 |
|
---|
102 | HBITMAP hbmFrameMenu[8] = {0};
|
---|
103 |
|
---|
104 | //Win32 bitmap handles of the OS/2 min, max and restore buttons
|
---|
105 | HBITMAP hBmpMinButton = 0;
|
---|
106 | HBITMAP hBmpMaxButton = 0;
|
---|
107 | HBITMAP hBmpRestoreButton = 0;
|
---|
108 | HBITMAP hBmpCloseButton = 0;
|
---|
109 | HBITMAP hBmpMinButtonDown = 0;
|
---|
110 | HBITMAP hBmpMaxButtonDown = 0;
|
---|
111 | HBITMAP hBmpRestoreButtonDown = 0;
|
---|
112 | HBITMAP hBmpCloseButtonDown = 0;
|
---|
113 |
|
---|
114 | PFNWP pfnFrameWndProc = NULL;
|
---|
115 | static HWND hwndFocusChange = 0;
|
---|
116 | HWND hwndCD = 0;
|
---|
117 |
|
---|
118 | // this holds the font height that the display driver returns using DevQueryCaps
|
---|
119 | // 13 would be small fonts, 16 medium fonts and 20 large fonts
|
---|
120 | LONG CapsCharHeight = 0;
|
---|
121 |
|
---|
122 | // Note:
|
---|
123 | // For a "lonekey"-press of AltGr, we only receive WM_KEYUP
|
---|
124 | // messages. If the key is pressed longer and starts to repeat,
|
---|
125 | // WM_KEYDOWN messages come in properly.
|
---|
126 | static BOOL fKeyAltGrDown = FALSE;
|
---|
127 | static BOOL fEnableCDPolling = FALSE;
|
---|
128 |
|
---|
129 | static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes);
|
---|
130 | static BOOL PMDragValidate(PDRAGINFO pDragInfo);
|
---|
131 | static void QueryPMMenuBitmaps();
|
---|
132 |
|
---|
133 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
---|
134 | MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
---|
135 | MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
---|
136 | void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
|
---|
137 | HBITMAP hbmNew);
|
---|
138 | void FrameSetFocus(HWND hwnd);
|
---|
139 |
|
---|
140 | VOID APIENTRY DspInitSystemDriverName(PSZ pszDriverName, ULONG lenDriverName);
|
---|
141 |
|
---|
142 | #ifdef DEBUG_LOGGING
|
---|
143 | static char *DbgGetStringSWPFlags(ULONG flags);
|
---|
144 | static char *DbgPrintQFCFlags(ULONG flags);
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | extern "C" ULONG OSLibImSetMsgQueueProperty( ULONG, ULONG );
|
---|
148 |
|
---|
149 | int cp2cp(char *cp1, char *cp2, char *src, char *dst, int len);
|
---|
150 |
|
---|
151 | //******************************************************************************
|
---|
152 | // Initialize PM; create hab, message queue and register special Win32 window classes
|
---|
153 | //
|
---|
154 | // This is called from the initterm, so we call it only once for each process.
|
---|
155 | // We make sure PM is up and running for our purposes and init the existing
|
---|
156 | // thread 0.
|
---|
157 | //*******************************************************************************
|
---|
158 | BOOL InitPM()
|
---|
159 | {
|
---|
160 | hab = WinInitialize(0);
|
---|
161 | dprintf(("Winitialize returned %x", hab));
|
---|
162 | hmq = WinCreateMsgQueue(hab, 0);
|
---|
163 |
|
---|
164 | if(!hab || !hmq)
|
---|
165 | {
|
---|
166 | UINT error;
|
---|
167 | //CB: only fail on real error
|
---|
168 | error = WinGetLastError(hab) & 0xFFFF; //error code
|
---|
169 | if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
|
---|
170 | {
|
---|
171 | dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
|
---|
172 | dprintf((" Error = %x",error));
|
---|
173 | if(error == PMERR_NOT_IN_A_PM_SESSION) return TRUE;
|
---|
174 |
|
---|
175 | return(FALSE);
|
---|
176 | }
|
---|
177 | else
|
---|
178 | {
|
---|
179 | if(!hab) {
|
---|
180 | hab = WinQueryAnchorBlock(HWND_DESKTOP);
|
---|
181 | dprintf(("WinQueryAnchorBlock returned %x", hab));
|
---|
182 | }
|
---|
183 | if(!hmq) {
|
---|
184 | PTIB ptib;
|
---|
185 | PPIB ppib;
|
---|
186 |
|
---|
187 | DosGetInfoBlocks(&ptib, &ppib);
|
---|
188 |
|
---|
189 | hmq = WinQueueFromID(hab, ppib->pib_ulpid, ptib->tib_ptib2->tib2_ultid);
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | // store our HAB and HMQ in the TEB - we need it quite often
|
---|
195 | // and they don't map 1:1 to Windows entities
|
---|
196 | SetThreadHAB(hab);
|
---|
197 | dprintf(("InitPM: hmq = %x", hmq));
|
---|
198 | SetThreadMessageQueue(hmq);
|
---|
199 |
|
---|
200 | //initialize keyboard hook for first thread
|
---|
201 | hookInit(hab);
|
---|
202 |
|
---|
203 | // we don't want to change the code page of the main thread because it may
|
---|
204 | // be a foreign thread (such as when we are dragged by the Flash plugin
|
---|
205 | // into the Firefox process) which has already performed its own
|
---|
206 | // initialization and does not expect the code page change
|
---|
207 | #if 0
|
---|
208 | BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
|
---|
209 | dprintf(("InitPM: WinSetCP(%d) was %sOK", GetDisplayCodepage(), rc ? "" : "not "));
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | /* IM instace is created per message queue, that is, thread */
|
---|
213 | if( IsDBCSEnv())
|
---|
214 | OSLibImSetMsgQueueProperty( hmq, MQP_INSTANCE_PERMQ );
|
---|
215 |
|
---|
216 | //CD polling window class
|
---|
217 | if(!WinRegisterClass( /* Register window class */
|
---|
218 | hab, /* Anchor block handle */
|
---|
219 | (PSZ)WIN32_CDCLASS, /* Window class name */
|
---|
220 | (PFNWP)Win32CDWindowProc, /* Address of window procedure */
|
---|
221 | 0,
|
---|
222 | 0))
|
---|
223 | {
|
---|
224 | dprintf(("WinRegisterClass Win32BaseWindow failed"));
|
---|
225 | return(FALSE);
|
---|
226 | }
|
---|
227 |
|
---|
228 | //Standard Odin window class
|
---|
229 | if(!WinRegisterClass( /* Register window class */
|
---|
230 | hab, /* Anchor block handle */
|
---|
231 | (PSZ)WIN32_STDCLASS, /* Window class name */
|
---|
232 | (PFNWP)Win32WindowProc, /* Address of window procedure */
|
---|
233 | 0,
|
---|
234 | NROF_WIN32WNDBYTES))
|
---|
235 | {
|
---|
236 | dprintf(("WinRegisterClass Win32BaseWindow failed"));
|
---|
237 | return(FALSE);
|
---|
238 | }
|
---|
239 |
|
---|
240 | //We no longer register our own frame window class as there is code in PM
|
---|
241 | //that makes assumptions about frame window class names.
|
---|
242 | //Instead we subclass the frame window right after creating it.
|
---|
243 | CLASSINFO FrameClassInfo;
|
---|
244 | if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
|
---|
245 | dprintf (("WinQueryClassInfo WC_FRAME failed"));
|
---|
246 | return (FALSE);
|
---|
247 | }
|
---|
248 | pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
|
---|
249 |
|
---|
250 | dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
|
---|
251 |
|
---|
252 | // get the screen dimensions and store them
|
---|
253 | WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
|
---|
254 | ScreenWidth = desktopRectl.xRight;
|
---|
255 | ScreenHeight = desktopRectl.yTop;
|
---|
256 |
|
---|
257 | HDC hdc; /* Device-context handle */
|
---|
258 | /* context data structure */
|
---|
259 | DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
|
---|
260 | NULL, NULL, NULL};
|
---|
261 |
|
---|
262 | /* create memory device context - it's temporary to query some information */
|
---|
263 | hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
|
---|
264 |
|
---|
265 | // check if we have the OS/2 Look and Feel enabled
|
---|
266 | fOS2Look = PROFILE_GetOdinIniBool(ODINSYSTEM_SECTION, "OS2Look", TRUE);
|
---|
267 | if(fOS2Look)
|
---|
268 | {
|
---|
269 | SYSCOLOR_Init(FALSE); //use OS/2 colors
|
---|
270 | QueryPMMenuBitmaps();
|
---|
271 | }
|
---|
272 |
|
---|
273 | // find out which colordepth we're running
|
---|
274 | DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
|
---|
275 |
|
---|
276 | // query the font height to find out whether we have small or large fonts
|
---|
277 | DevQueryCaps(hdc, CAPS_GRAPHICS_CHAR_HEIGHT, 1, (PLONG)&CapsCharHeight);
|
---|
278 | dprintf(("CAPS_GRAPHICS_CHAR_HEIGHT = %d", CapsCharHeight));
|
---|
279 | if(CapsCharHeight > 16) {
|
---|
280 | CapsCharHeight = 16;
|
---|
281 | }
|
---|
282 |
|
---|
283 | #ifdef DEBUG
|
---|
284 | ULONG temp;
|
---|
285 | DevQueryCaps(hdc, CAPS_GRAPHICS_CHAR_WIDTH, 1, (PLONG)&temp);
|
---|
286 | dprintf(("CAPS_GRAPHICS_CHAR_WIDTH = %d", temp));
|
---|
287 | DevQueryCaps(hdc, CAPS_CHAR_HEIGHT, 1, (PLONG)&temp);
|
---|
288 | dprintf(("CAPS_CHAR_HEIGTH = %d", temp));
|
---|
289 | DevQueryCaps(hdc, CAPS_CHAR_WIDTH, 1, (PLONG)&temp);
|
---|
290 | dprintf(("CAPS_CHAR_WIDTH = %d", temp));
|
---|
291 | DevQueryCaps(hdc, CAPS_SMALL_CHAR_HEIGHT, 1, (PLONG)&temp);
|
---|
292 | dprintf(("CAPS_SMALL_CHAR_HEIGTH = %d", temp));
|
---|
293 | DevQueryCaps(hdc, CAPS_SMALL_CHAR_WIDTH, 1, (PLONG)&temp);
|
---|
294 | dprintf(("CAPS_SMALL_CHAR_WIDTH = %d", temp));
|
---|
295 | DevQueryCaps(hdc, CAPS_VERTICAL_FONT_RES, 1,(PLONG)&temp);
|
---|
296 | dprintf(("CAPS_VERTICAL_FONT_RES = %d", temp));
|
---|
297 | DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 1,(PLONG)&temp);
|
---|
298 | dprintf(("CAPS_HORIZONTAL_FONT_RES = %d", temp));
|
---|
299 | #endif
|
---|
300 |
|
---|
301 | DevCloseDC(hdc);
|
---|
302 |
|
---|
303 | dprintf(("InitPM: Desktop (%d,%d) bpp %d font size %d", ScreenWidth, ScreenHeight, ScreenBitsPerPel, CapsCharHeight));
|
---|
304 | return TRUE;
|
---|
305 | } /* End of main */
|
---|
306 | //******************************************************************************
|
---|
307 | HBITMAP OPEN32API _O32_CreateBitmapFromPMHandle(HBITMAP hPMBitmap);
|
---|
308 |
|
---|
309 | inline HBITMAP O32_CreateBitmapFromPMHandle(HBITMAP hPMBitmap)
|
---|
310 | {
|
---|
311 | HBITMAP yyrc;
|
---|
312 | USHORT sel = RestoreOS2FS();
|
---|
313 |
|
---|
314 | yyrc = _O32_CreateBitmapFromPMHandle(hPMBitmap);
|
---|
315 | SetFS(sel);
|
---|
316 |
|
---|
317 | return yyrc;
|
---|
318 | }
|
---|
319 | //******************************************************************************
|
---|
320 | static void QueryPMMenuBitmaps()
|
---|
321 | {
|
---|
322 | CHAR szDisplay[30];
|
---|
323 | HMODULE hModDisplay;
|
---|
324 |
|
---|
325 | if(hbmFrameMenu[0] == 0)
|
---|
326 | {
|
---|
327 | CHAR szDisplay[30];
|
---|
328 | HMODULE hModDisplay;
|
---|
329 | HDC hdc; /* Device-context handle */
|
---|
330 | DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
|
---|
331 | NULL, NULL, NULL};
|
---|
332 |
|
---|
333 | /* create memory device context */
|
---|
334 | hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
|
---|
335 |
|
---|
336 | DspInitSystemDriverName(szDisplay, sizeof(szDisplay));
|
---|
337 | DosQueryModuleHandleStrict(szDisplay, &hModDisplay);
|
---|
338 |
|
---|
339 | hbmFrameMenu[PMMENU_MINBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTON, 0, 0);
|
---|
340 | hbmFrameMenu[PMMENU_MINBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTONDEP, 0, 0);
|
---|
341 | hbmFrameMenu[PMMENU_MAXBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTON, 0, 0);
|
---|
342 | hbmFrameMenu[PMMENU_MAXBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTONDEP, 0, 0);
|
---|
343 | hbmFrameMenu[PMMENU_RESTOREBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTON, 0, 0);
|
---|
344 | hbmFrameMenu[PMMENU_RESTOREBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTONDEP, 0, 0);
|
---|
345 | hbmFrameMenu[PMMENU_CLOSEBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_CLOSE, 0, 0);
|
---|
346 | hbmFrameMenu[PMMENU_CLOSEBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_CLOSEDEP, 0, 0);
|
---|
347 |
|
---|
348 | //Create win32 bitmap handles of the OS/2 min, max and restore buttons
|
---|
349 | hBmpMinButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MINBUTTON]);
|
---|
350 | ObjSetHandleFlag(hBmpMinButton, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
351 | hBmpMinButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MINBUTTONDOWN]);
|
---|
352 | ObjSetHandleFlag(hBmpMinButtonDown, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
353 | hBmpMaxButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MAXBUTTON]);
|
---|
354 | ObjSetHandleFlag(hBmpMaxButton, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
355 | hBmpMaxButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MAXBUTTONDOWN]);
|
---|
356 | ObjSetHandleFlag(hBmpMaxButtonDown, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
357 | hBmpRestoreButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_RESTOREBUTTON]);
|
---|
358 | ObjSetHandleFlag(hBmpRestoreButton, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
359 | hBmpRestoreButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_RESTOREBUTTONDOWN]);
|
---|
360 | ObjSetHandleFlag(hBmpRestoreButtonDown, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
361 | hBmpCloseButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_CLOSEBUTTON]);
|
---|
362 | ObjSetHandleFlag(hBmpCloseButton, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
363 | hBmpCloseButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_CLOSEBUTTONDOWN]);
|
---|
364 | ObjSetHandleFlag(hBmpCloseButtonDown, OBJHANDLE_FLAG_NODELETE, 1);
|
---|
365 | DevCloseDC(hdc);
|
---|
366 | }
|
---|
367 | }
|
---|
368 | //******************************************************************************
|
---|
369 | //******************************************************************************
|
---|
370 | void WIN32API SetWindowAppearance(int fLooks)
|
---|
371 | {
|
---|
372 | if(fLooks == OS2_APPEARANCE || fLooks == OS2_APPEARANCE_SYSMENU)
|
---|
373 | {
|
---|
374 | SYSCOLOR_Init(FALSE); //use OS/2 colors
|
---|
375 | QueryPMMenuBitmaps();
|
---|
376 | }
|
---|
377 | fOS2Look = fLooks;
|
---|
378 | MENU_Init();
|
---|
379 | }
|
---|
380 | //******************************************************************************
|
---|
381 | //******************************************************************************
|
---|
382 | void WIN32API CustForceMonoCursor()
|
---|
383 | {
|
---|
384 | fForceMonoCursor = TRUE;
|
---|
385 | }
|
---|
386 | //******************************************************************************
|
---|
387 | //******************************************************************************
|
---|
388 | void WIN32API DisableDragDrop(BOOL fDisabled)
|
---|
389 | {
|
---|
390 | fDragDropDisabled = fDisabled;
|
---|
391 | }
|
---|
392 | //******************************************************************************
|
---|
393 | // Turn on CD Polling (window with 2 second timer to check CD disk presence)
|
---|
394 | //
|
---|
395 | // NOTE: This can cause PM hangs when executing a program for a very long time
|
---|
396 | // (block in IOCtl)
|
---|
397 | //******************************************************************************
|
---|
398 | void WIN32API CustEnableCDPolling()
|
---|
399 | {
|
---|
400 | fEnableCDPolling = TRUE;
|
---|
401 | }
|
---|
402 | //******************************************************************************
|
---|
403 | //CD notification window class
|
---|
404 | //******************************************************************************
|
---|
405 | MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
406 | {
|
---|
407 | #pragma pack(1)
|
---|
408 | typedef struct
|
---|
409 | {
|
---|
410 | BYTE ucCommandInfo;
|
---|
411 | WORD usDriveUnit;
|
---|
412 | } ParameterBlock;
|
---|
413 | #pragma pack()
|
---|
414 |
|
---|
415 | MRESULT rc = 0;
|
---|
416 | static ULONG drives[26] = {0};
|
---|
417 | static int drivestatus[26] = {0};
|
---|
418 |
|
---|
419 | switch( msg )
|
---|
420 | {
|
---|
421 | //OS/2 msgs
|
---|
422 | case WM_CREATE:
|
---|
423 | {
|
---|
424 | char drive[4];
|
---|
425 |
|
---|
426 | //skip floppy drives
|
---|
427 | drive[0] = 'C';
|
---|
428 | drive[1] = ':';
|
---|
429 | drive[2] = '\0';
|
---|
430 |
|
---|
431 | for(int i=2;i<26;i++) {
|
---|
432 | drives[i] = GetDriveTypeA(drive);
|
---|
433 | if(drives[i] == DRIVE_CDROM_W)
|
---|
434 | {
|
---|
435 | DWORD parsize = sizeof(ParameterBlock);
|
---|
436 | DWORD datasize = 2;
|
---|
437 | WORD status = 0;
|
---|
438 | DWORD rc;
|
---|
439 | ParameterBlock parm;
|
---|
440 |
|
---|
441 | parm.ucCommandInfo = 0;
|
---|
442 | parm.usDriveUnit = i;
|
---|
443 | rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
|
---|
444 | &status, sizeof(status), &datasize);
|
---|
445 | if(rc != NO_ERROR) {
|
---|
446 | dprintf(("DosDevIOCtl failed with rc %d", rc));
|
---|
447 | drives[i] = 0;
|
---|
448 | continue;
|
---|
449 | }
|
---|
450 | //if no disk present, return FALSE
|
---|
451 | if(status & 4) {
|
---|
452 | drivestatus[i] = status & 4;
|
---|
453 | }
|
---|
454 | }
|
---|
455 | drive[0]++;
|
---|
456 | }
|
---|
457 | WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*60);
|
---|
458 | //// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*3);
|
---|
459 | //// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 5000);
|
---|
460 | rc = (MRESULT)FALSE;
|
---|
461 | break;
|
---|
462 | }
|
---|
463 | case WM_TIMER:
|
---|
464 | {
|
---|
465 | for(int i=0;i<26;i++)
|
---|
466 | {
|
---|
467 | //for now only cdrom/dvd drives
|
---|
468 | if(drives[i] == DRIVE_CDROM_W)
|
---|
469 | {
|
---|
470 | DWORD parsize = sizeof(ParameterBlock);
|
---|
471 | DWORD datasize = 2;
|
---|
472 | WORD status = 0;
|
---|
473 | DWORD rc;
|
---|
474 | ParameterBlock parm;
|
---|
475 |
|
---|
476 | parm.ucCommandInfo = 0;
|
---|
477 | parm.usDriveUnit = i;
|
---|
478 | rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
|
---|
479 | &status, sizeof(status), &datasize);
|
---|
480 | if(rc != NO_ERROR) {
|
---|
481 | dprintf(("DosDevIOCtl failed with rc %d", rc));
|
---|
482 | return FALSE;
|
---|
483 | }
|
---|
484 | //Send WM_DEVICECHANGE message when CD status changes
|
---|
485 | if((status & 4) != drivestatus[i])
|
---|
486 | {
|
---|
487 | PID pidThis, pidTemp;
|
---|
488 | HENUM henum;
|
---|
489 | HWND hwndEnum;
|
---|
490 | DEV_BROADCAST_VOLUME volchange;
|
---|
491 |
|
---|
492 | dprintf(("Disk status 0x%x", status));
|
---|
493 |
|
---|
494 | volchange.dbcv_size = sizeof(volchange);
|
---|
495 | volchange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
|
---|
496 | volchange.dbcv_reserved = 0;
|
---|
497 | volchange.dbcv_unitmask = (1 << i);
|
---|
498 | volchange.dbcv_flags = DBTF_MEDIA;
|
---|
499 |
|
---|
500 | WinQueryWindowProcess(hwnd, &pidThis, NULL);
|
---|
501 |
|
---|
502 | //Iterate over all child windows of the desktop
|
---|
503 | henum = WinBeginEnumWindows(HWND_DESKTOP);
|
---|
504 |
|
---|
505 | SetWin32TIB();
|
---|
506 | while((hwndEnum = WinGetNextWindow(henum)) != 0)
|
---|
507 | {
|
---|
508 | WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
|
---|
509 | if(pidTemp == pidThis)
|
---|
510 | {
|
---|
511 | HWND hwndWin32 = OS2ToWin32Handle(hwndEnum);
|
---|
512 | if(hwndWin32) {
|
---|
513 | SendMessageA(hwndWin32,
|
---|
514 | WM_DEVICECHANGE_W,
|
---|
515 | (status & 4) ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
|
---|
516 | (LPARAM)&volchange);
|
---|
517 | }
|
---|
518 | }
|
---|
519 | }
|
---|
520 | RestoreOS2TIB();
|
---|
521 | WinEndEnumWindows(henum);
|
---|
522 |
|
---|
523 | drivestatus[i] = (status & 4);
|
---|
524 | }
|
---|
525 | }
|
---|
526 | }
|
---|
527 | break;
|
---|
528 | }
|
---|
529 |
|
---|
530 | case WM_DESTROY:
|
---|
531 | dprintf(("WM_DESTROY for CD notification window"));
|
---|
532 | WinStopTimer(hab, hwnd, TIMERID_DRIVEPOLL);
|
---|
533 | break;
|
---|
534 |
|
---|
535 | default:
|
---|
536 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
537 | }
|
---|
538 | return (MRESULT)rc;
|
---|
539 | }
|
---|
540 | //******************************************************************************
|
---|
541 | // Win32 window message handler
|
---|
542 | // The PM window procedure for our client window class (non frame)
|
---|
543 | //******************************************************************************
|
---|
544 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
545 | {
|
---|
546 | Win32BaseWindow *win32wnd;
|
---|
547 | TEB *teb;
|
---|
548 | MSG winMsg, *pWinMsg;
|
---|
549 | MRESULT rc = 0;
|
---|
550 | POSTMSG_PACKET *postmsg;
|
---|
551 | OSLIBPOINT point, ClientPoint;
|
---|
552 | EXCEPTIONREGISTRATIONRECORD exceptRegRec = {0,0};
|
---|
553 |
|
---|
554 | ODIN_SetExceptionHandler(&exceptRegRec);
|
---|
555 | // restore our FS selector
|
---|
556 | SetWin32TIB();
|
---|
557 |
|
---|
558 | #ifdef DEBUG
|
---|
559 | dbg_ThreadPushCall("Win32WindowProc");
|
---|
560 | #endif
|
---|
561 |
|
---|
562 | // BEGIN NOTE-------------->>>>>> If this is changed, also change Win32FrameWindowProc!! <<<<<<<<<<<-------------------- BEGIN
|
---|
563 | teb = GetThreadTEB();
|
---|
564 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
---|
565 |
|
---|
566 | //// dprintf(("window %x msg %x", (win32wnd) ? win32wnd->getWindowHandle() : 0, msg));
|
---|
567 |
|
---|
568 | // do some sanity checking here:
|
---|
569 | // - we need to have a TEB handle
|
---|
570 | // - unless this is WM_CREATE (the very first message), there has to be
|
---|
571 | // a USER32 window object for this window handle
|
---|
572 | // - thread must not be suspended in WaitMessage
|
---|
573 | if(!teb || (msg != WM_CREATE && win32wnd == NULL) || teb->o.odin.fWaitMessageSuspend) {
|
---|
574 | if(teb && teb->o.odin.fWaitMessageSuspend)
|
---|
575 | dprintf(("OS2: fWaitMessageSuspend window %x msg %x -> run default frame proc", hwnd, msg));
|
---|
576 | else dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
|
---|
577 | goto RunDefWndProc;
|
---|
578 | }
|
---|
579 | //// if(teb->o.odin.fIgnoreMsgs) {
|
---|
580 | //// goto RunDefWndProc;
|
---|
581 | //// }
|
---|
582 |
|
---|
583 | // check if the message state counter in the TEB is odd
|
---|
584 | // This means the message has been sent directly from PM to our message
|
---|
585 | // handler (so it is the first time we know about this PM message).
|
---|
586 | // If this is the case, we have to translate it here to a Win32
|
---|
587 | // message first. The other case is that the message is the result of a
|
---|
588 | // WinDispatchMsg call and therefore has already been translated.
|
---|
589 | if((teb->o.odin.msgstate & 1) == 0)
|
---|
590 | {
|
---|
591 | // message that was sent directly to our window proc handler; translate it here
|
---|
592 | QMSG qmsg;
|
---|
593 |
|
---|
594 | qmsg.msg = msg;
|
---|
595 | qmsg.hwnd = hwnd;
|
---|
596 | qmsg.mp1 = mp1;
|
---|
597 | qmsg.mp2 = mp2;
|
---|
598 | qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
|
---|
599 | WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
|
---|
600 | qmsg.reserved = 0;
|
---|
601 |
|
---|
602 | /* sometimes MSG_REMOVE here caused to double free of the message */
|
---|
603 | if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
|
---|
604 | {//message was not translated
|
---|
605 | memset(&winMsg, 0, sizeof(MSG));
|
---|
606 | }
|
---|
607 | pWinMsg = &winMsg;
|
---|
608 |
|
---|
609 | }
|
---|
610 | else {
|
---|
611 | // message has already been translated before (GetMessage/PeekMessage).
|
---|
612 | // Use the translated information. Flip the translation flag.
|
---|
613 | pWinMsg = &teb->o.odin.msg;
|
---|
614 | teb->o.odin.msgstate++;
|
---|
615 | }
|
---|
616 | // END NOTE-------------->>>>>> If this is changed, also change Win32FrameWindowProc!! <<<<<<<<<<<-------------------- END
|
---|
617 |
|
---|
618 | if(msg >= WIN32APP_POSTMSG) {
|
---|
619 | //probably win32 app user message
|
---|
620 | dprintf2(("Posted message %x->%x", msg, msg-WIN32APP_POSTMSG));
|
---|
621 | if((ULONG)mp1 == WIN32MSG_MAGICA) {
|
---|
622 | rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
|
---|
623 | }
|
---|
624 | else
|
---|
625 | if((ULONG)mp1 == WIN32MSG_MAGICW) {
|
---|
626 | rc = (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
|
---|
627 | }
|
---|
628 | else {//broadcasted message
|
---|
629 | rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
|
---|
630 | }
|
---|
631 | RELEASE_WNDOBJ(win32wnd);
|
---|
632 | RestoreOS2TIB();
|
---|
633 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
634 |
|
---|
635 | #ifdef DEBUG
|
---|
636 | dbg_ThreadPopCall();
|
---|
637 | #endif
|
---|
638 | return rc;
|
---|
639 | }
|
---|
640 |
|
---|
641 | switch( msg )
|
---|
642 | {
|
---|
643 | //OS/2 msgs
|
---|
644 | case WM_CREATE:
|
---|
645 | {
|
---|
646 | if(teb->o.odin.newWindow == 0)
|
---|
647 | goto createfail;
|
---|
648 |
|
---|
649 | //Processing is done in after WinCreateWindow returns
|
---|
650 | dprintf(("OS2: WM_CREATE %x", hwnd));
|
---|
651 | win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
|
---|
652 | win32wnd->addRef();
|
---|
653 | teb->o.odin.newWindow = 0;
|
---|
654 | if(win32wnd->MsgCreate(hwnd) == FALSE)
|
---|
655 | {
|
---|
656 | rc = (MRESULT)TRUE; //discontinue window creation
|
---|
657 | break;
|
---|
658 | }
|
---|
659 |
|
---|
660 | //Create CD notification window
|
---|
661 | if(hwndCD == 0 && fEnableCDPolling) {
|
---|
662 | hwndCD = WinCreateWindow(HWND_DESKTOP, WIN32_CDCLASS,
|
---|
663 | NULL, 0, 0, 0, 0, 0,
|
---|
664 | HWND_DESKTOP, HWND_TOP, 0, NULL, NULL);
|
---|
665 | }
|
---|
666 |
|
---|
667 | createfail:
|
---|
668 | rc = (MRESULT)FALSE;
|
---|
669 | break;
|
---|
670 | }
|
---|
671 |
|
---|
672 | case WM_QUIT:
|
---|
673 | dprintf(("OS2: WM_QUIT %x", hwnd));
|
---|
674 | win32wnd->MsgQuit();
|
---|
675 | break;
|
---|
676 |
|
---|
677 | case WM_CLOSE:
|
---|
678 | dprintf(("OS2: WM_CLOSE %x", hwnd));
|
---|
679 | win32wnd->MsgClose();
|
---|
680 | break;
|
---|
681 |
|
---|
682 | case WM_DESTROY:
|
---|
683 | dprintf(("OS2: WM_DESTROY %x", hwnd));
|
---|
684 | win32wnd->MsgDestroy();
|
---|
685 | WinSetVisibleRegionNotify(hwnd, FALSE);
|
---|
686 | goto RunDefWndProc;
|
---|
687 |
|
---|
688 | case WM_ENABLE:
|
---|
689 | dprintf(("OS2: WM_ENABLE %x", hwnd));
|
---|
690 | break;
|
---|
691 |
|
---|
692 | case WM_SHOW:
|
---|
693 | {
|
---|
694 | dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
|
---|
695 | win32wnd->MsgShow((ULONG)mp1);
|
---|
696 |
|
---|
697 | //if a child window is hidden, then the update region of the
|
---|
698 | //parent changes and a WM_ERASEBKGND is required during the next
|
---|
699 | //BeginPaint call.
|
---|
700 | if((ULONG)mp1 == FALSE)
|
---|
701 | {
|
---|
702 | Win32BaseWindow *parent = win32wnd->getParent();
|
---|
703 | if(parent) {
|
---|
704 | dprintf(("PM Update region changed for parent %x", win32wnd->getWindowHandle()));
|
---|
705 | parent->SetPMUpdateRegionChanged(TRUE);
|
---|
706 | }
|
---|
707 | }
|
---|
708 | break;
|
---|
709 | }
|
---|
710 |
|
---|
711 | case WM_ACTIVATE:
|
---|
712 | {
|
---|
713 | ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
|
---|
714 |
|
---|
715 | dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
|
---|
716 | WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
|
---|
717 | if(win32wnd->IsWindowCreated())
|
---|
718 | {
|
---|
719 | win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
|
---|
720 | }
|
---|
721 | break;
|
---|
722 | }
|
---|
723 |
|
---|
724 | case WM_SIZE:
|
---|
725 | {
|
---|
726 | dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)));
|
---|
727 | win32wnd->SetPMUpdateRegionChanged(TRUE);
|
---|
728 |
|
---|
729 | goto RunDefWndProc;
|
---|
730 | }
|
---|
731 |
|
---|
732 |
|
---|
733 | case WM_VRNENABLED:
|
---|
734 | {
|
---|
735 | dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
736 | //Always call handler; even if mp1 is 0. If we don't do this, the
|
---|
737 | //DivX 4 player will never be allowed to draw after putting another window
|
---|
738 | //on top of it.
|
---|
739 |
|
---|
740 | win32wnd->callVisibleRgnNotifyProc(TRUE);
|
---|
741 |
|
---|
742 | //Workaround for PM/GPI bug when moving/sizing a window with open DCs
|
---|
743 | //
|
---|
744 | //Windows applictions often get a DC and keep it open for the duration
|
---|
745 | //of the application. When the DC's window is moved (full window dragging on)
|
---|
746 | //PM/GPI doesn't seem to update the DC properly/in time.
|
---|
747 | //This can result is visible distortions on the screen.
|
---|
748 | //Debugging showed that querying the visible region of a DC will cure
|
---|
749 | //this problem (GPI probably recalculates the visible region). (#334)
|
---|
750 |
|
---|
751 | int nrdcs = 0;
|
---|
752 | HDC hdcWindow[MAX_OPENDCS];
|
---|
753 |
|
---|
754 | if(win32wnd->queryOpenDCs(hdcWindow, MAX_OPENDCS, &nrdcs))
|
---|
755 | {
|
---|
756 | RECTL rcl = {0,0,1,1};
|
---|
757 | HRGN hrgnRect;
|
---|
758 |
|
---|
759 | for(int i=0;i<nrdcs;i++) {
|
---|
760 | dprintf(("Recalc visible region of DC %x for window %x", hdcWindow[i], win32wnd->getWindowHandle()));
|
---|
761 |
|
---|
762 | hrgnRect = GreCreateRectRegion(hdcWindow[i], &rcl, 1);
|
---|
763 | GreCopyClipRegion(hdcWindow[i], hrgnRect, 0, COPYCRGN_VISRGN);
|
---|
764 | GreDestroyRegion(hdcWindow[i], hrgnRect);
|
---|
765 | }
|
---|
766 | }
|
---|
767 | //Workaround END
|
---|
768 |
|
---|
769 | if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
|
---|
770 | {
|
---|
771 | HWND hwndrelated;
|
---|
772 | Win32BaseWindow *topwindow;
|
---|
773 |
|
---|
774 | win32wnd->setComingToTop(TRUE);
|
---|
775 |
|
---|
776 | hwndrelated = WinQueryWindow(hwnd, QW_PREV);
|
---|
777 | dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
|
---|
778 | topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
|
---|
779 | if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
|
---|
780 | //put window at the top of z order
|
---|
781 | WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
|
---|
782 | }
|
---|
783 | if(topwindow) RELEASE_WNDOBJ(topwindow);
|
---|
784 |
|
---|
785 | win32wnd->setComingToTop(FALSE);
|
---|
786 | break;
|
---|
787 | }
|
---|
788 | goto RunDefWndProc;
|
---|
789 | }
|
---|
790 |
|
---|
791 | case WM_VRNDISABLED:
|
---|
792 | {
|
---|
793 | dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
794 | //visible region is about to change or WinLockWindowUpdate called
|
---|
795 | //suspend window drawing
|
---|
796 |
|
---|
797 | win32wnd->callVisibleRgnNotifyProc(FALSE);
|
---|
798 | goto RunDefWndProc;
|
---|
799 | }
|
---|
800 |
|
---|
801 | case WIN32APP_DDRAWFULLSCREEN:
|
---|
802 | //Changing the size of the win32 window in SetCooperativeLevel can
|
---|
803 | //fail if this happens during WM_ADJUSTWINDOWPOS
|
---|
804 | //NOTE: This is not a good solution, but a proper fix is more difficult
|
---|
805 | // with the current window mess
|
---|
806 | dprintf(("WIN32APP_DDRAWFULLSCREEN %x (%d,%d)", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
807 | SetWindowPos(win32wnd->getWindowHandle(), HWND_TOP_W, 0, 0, (DWORD)mp1, (DWORD)mp2, 0);
|
---|
808 | ShowWindow(win32wnd->getWindowHandle(), SW_SHOW_W);
|
---|
809 | break;
|
---|
810 |
|
---|
811 | case WIN32APP_CHNGEFRAMECTRLS:
|
---|
812 | {
|
---|
813 | dprintf(("OS2: WIN32APP_CHANGEFRAMECTRLS"));
|
---|
814 | OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), (ULONG)mp1, win32wnd->getExStyle(), (ULONG)mp2);
|
---|
815 | break;
|
---|
816 | }
|
---|
817 |
|
---|
818 | #ifdef DEBUG
|
---|
819 | case WM_SETFOCUS:
|
---|
820 | {
|
---|
821 | HWND hwndFocus = (HWND)mp1;
|
---|
822 | dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d cur focus %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2, WinQueryFocus(HWND_DESKTOP)));
|
---|
823 | if(WinQueryFocus(HWND_DESKTOP) == win32wnd->getOS2FrameWindowHandle()) {
|
---|
824 | dprintf(("WARNING: Focus set to frame window"));
|
---|
825 | }
|
---|
826 | break;
|
---|
827 | }
|
---|
828 | #endif
|
---|
829 |
|
---|
830 | //Handle all focus processed during WM_FOCUSCHANGED; PM doesn't like focus
|
---|
831 | //changes during focus processing (WM_SETFOCUS). This message is sent
|
---|
832 | //after all focus work has been completed.
|
---|
833 | case WM_FOCUSCHANGED:
|
---|
834 | {
|
---|
835 | HWND hwndFocus = (HWND)mp1;
|
---|
836 | HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
|
---|
837 |
|
---|
838 | dprintf(("OS2: WM_FOCUSCHANGED %x %x (%x) %d cur focus %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2, WinQueryFocus(HWND_DESKTOP)));
|
---|
839 |
|
---|
840 | //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
|
---|
841 | //must delay this function call
|
---|
842 |
|
---|
843 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
|
---|
844 | {
|
---|
845 | //another (non-win32) application's window
|
---|
846 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
---|
847 | hwndFocus = 0;
|
---|
848 | hwndFocusWin32 = 0;
|
---|
849 | }
|
---|
850 | if((ULONG)mp2 == TRUE) {
|
---|
851 | recreateCaret(hwndFocusWin32);
|
---|
852 | win32wnd->MsgSetFocus(hwndFocusWin32);
|
---|
853 | }
|
---|
854 | else {
|
---|
855 | //If SetFocus(0) was called, then the window has already received
|
---|
856 | //a WM_KILLFOCUS; don't send another one
|
---|
857 | if(!fIgnoreKeystrokes) {
|
---|
858 | win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
|
---|
859 | }
|
---|
860 | else dprintf(("Window has already received a WM_KILLFOCUS (SetFocus(0)); ignore"));
|
---|
861 | }
|
---|
862 | break;
|
---|
863 | }
|
---|
864 |
|
---|
865 | //**************************************************************************
|
---|
866 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
|
---|
867 | //**************************************************************************
|
---|
868 |
|
---|
869 | case WM_BUTTON1DOWN:
|
---|
870 | case WM_BUTTON1UP:
|
---|
871 | case WM_BUTTON1DBLCLK:
|
---|
872 | case WM_BUTTON2DOWN:
|
---|
873 | case WM_BUTTON2UP:
|
---|
874 | case WM_BUTTON2DBLCLK:
|
---|
875 | case WM_BUTTON3DOWN:
|
---|
876 | case WM_BUTTON3UP:
|
---|
877 | case WM_BUTTON3DBLCLK:
|
---|
878 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
|
---|
879 | RELEASE_WNDOBJ(win32wnd);
|
---|
880 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
|
---|
881 | }
|
---|
882 | if(win32wnd)
|
---|
883 | {
|
---|
884 | dprintf(("Mouse click: %x, msg: %x, mp1: %x, mp2: %x",
|
---|
885 | pWinMsg->hwnd, pWinMsg->message, pWinMsg->wParam, pWinMsg->lParam));
|
---|
886 | win32wnd->MsgButton(pWinMsg);
|
---|
887 | }
|
---|
888 | rc = (MRESULT)TRUE;
|
---|
889 | break;
|
---|
890 |
|
---|
891 | case WM_BUTTON2MOTIONSTART:
|
---|
892 | case WM_BUTTON2MOTIONEND:
|
---|
893 | case WM_BUTTON2CLICK:
|
---|
894 | case WM_BUTTON1MOTIONSTART:
|
---|
895 | case WM_BUTTON1MOTIONEND:
|
---|
896 | case WM_BUTTON1CLICK:
|
---|
897 | case WM_BUTTON3MOTIONSTART:
|
---|
898 | case WM_BUTTON3MOTIONEND:
|
---|
899 | case WM_BUTTON3CLICK:
|
---|
900 | rc = (MRESULT)TRUE;
|
---|
901 | break;
|
---|
902 |
|
---|
903 | case WM_MOUSEMOVE:
|
---|
904 | {
|
---|
905 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
|
---|
906 | RELEASE_WNDOBJ(win32wnd);
|
---|
907 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
|
---|
908 | }
|
---|
909 | if(win32wnd)
|
---|
910 | win32wnd->MsgMouseMove(pWinMsg);
|
---|
911 | break;
|
---|
912 | }
|
---|
913 |
|
---|
914 | case WM_CONTROL:
|
---|
915 | goto RunDefWndProc;
|
---|
916 |
|
---|
917 | case WM_COMMAND:
|
---|
918 | dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
|
---|
919 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
920 | break;
|
---|
921 |
|
---|
922 | case WM_SYSCOMMAND:
|
---|
923 | dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
924 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
925 | break;
|
---|
926 |
|
---|
927 | case WM_RENDERFMT:
|
---|
928 | case WM_RENDERALLFMTS:
|
---|
929 | case WM_DESTROYCLIPBOARD:
|
---|
930 | case WM_DRAWCLIPBOARD:
|
---|
931 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
932 | break;
|
---|
933 |
|
---|
934 | case WM_CHAR_SPECIAL:
|
---|
935 | /* NO BREAK! FALLTHRU CASE! */
|
---|
936 |
|
---|
937 | case WM_CHAR:
|
---|
938 | dprintf(("OS2: WM_CHAR %x %x %x, %x %x msg: %x focus wnd %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam, pWinMsg->message, WinQueryFocus(HWND_DESKTOP)));
|
---|
939 | win32wnd->MsgChar(pWinMsg);
|
---|
940 | /*
|
---|
941 | * now, we need to send WM_CHAR message
|
---|
942 | * to inform Win32 window that an char was input
|
---|
943 | * We ignoring wm_char sending in case of Ctrl or Alt pressed
|
---|
944 | * Also we
|
---|
945 | */
|
---|
946 | /* sending only after WINWM_KEYDOWN */
|
---|
947 | /* checking for alphanum chars and number. did I miss something?
|
---|
948 | */
|
---|
949 | if (WINWM_KEYDOWN == pWinMsg->message &&
|
---|
950 | (((SHORT1FROMMP(mp1) & KC_CHAR) &&
|
---|
951 | !(SHORT1FROMMP(mp1) & KC_VIRTUALKEY)) || (SHORT1FROMMP(mp1) & KC_DEADKEY)) ||
|
---|
952 | (SHORT1FROMMP(mp2) == 0x20) //special case for space
|
---|
953 | )
|
---|
954 | {
|
---|
955 | MSG extramsg;
|
---|
956 | memcpy(&extramsg, pWinMsg, sizeof(MSG));
|
---|
957 | extramsg.message = WINWM_CHAR;
|
---|
958 |
|
---|
959 | // convert character code if needed (normally, only on the main
|
---|
960 | // thread since Win32ThreadProc() sets the HMQ code page to the
|
---|
961 | // Windows ANSI code page so that all threads created by Win32 API
|
---|
962 | // will be already in the ANSI code page)
|
---|
963 | ULONG cpFrom = WinQueryCp(HMQ_CURRENT);
|
---|
964 | ULONG cpTo = GetDisplayCodepage();
|
---|
965 | if (cpFrom != cpTo) {
|
---|
966 | char from[3], to[3];
|
---|
967 | *((USHORT*)&from) = SHORT1FROMMP(mp2);
|
---|
968 | from[2] = '\0';
|
---|
969 | if (WinCpTranslateString(hab, cpFrom, from, cpTo, 3, to)) {
|
---|
970 | extramsg.wParam = *((USHORT*)&to);
|
---|
971 | dprintf(("OS2: WM_CHAR cp%d->cp%d: %08X->%08X", cpFrom, cpTo,
|
---|
972 | (int)SHORT1FROMMP(mp2), (int)extramsg.wParam));
|
---|
973 | } else {
|
---|
974 | dprintf(("ERROR: cp%d->cp%d failed!", cpFrom, cpTo));
|
---|
975 | }
|
---|
976 | } else {
|
---|
977 | extramsg.wParam = SHORT1FROMMP(mp2);
|
---|
978 | }
|
---|
979 |
|
---|
980 | if(SHORT1FROMMP(mp1) & KC_DEADKEY)
|
---|
981 | {
|
---|
982 | extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
|
---|
983 | }
|
---|
984 |
|
---|
985 | win32wnd->MsgChar(&extramsg);
|
---|
986 | goto RunDefWndProc;
|
---|
987 | }
|
---|
988 | break;
|
---|
989 |
|
---|
990 | case WM_TIMER:
|
---|
991 | dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
|
---|
992 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
993 | goto RunDefWndProc;
|
---|
994 |
|
---|
995 | case WM_SETWINDOWPARAMS:
|
---|
996 | {
|
---|
997 | WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
|
---|
998 |
|
---|
999 | dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
|
---|
1000 | if(wndParams->fsStatus & WPM_TEXT) {
|
---|
1001 | win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
|
---|
1002 | }
|
---|
1003 | goto RunDefWndProc;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | case WM_QUERYWINDOWPARAMS:
|
---|
1007 | {
|
---|
1008 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
|
---|
1009 | ULONG textlen;
|
---|
1010 | PSZ wintext;
|
---|
1011 |
|
---|
1012 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
|
---|
1013 | {
|
---|
1014 | if(wndpars->fsStatus & WPM_TEXT)
|
---|
1015 | win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
|
---|
1016 | if(wndpars->fsStatus & WPM_CCHTEXT)
|
---|
1017 | wndpars->cchText = win32wnd->MsgGetTextLength();
|
---|
1018 |
|
---|
1019 | wndpars->fsStatus = 0;
|
---|
1020 | wndpars->cbCtlData = 0;
|
---|
1021 | wndpars->cbPresParams = 0;
|
---|
1022 | rc = (MRESULT)TRUE;
|
---|
1023 | break;
|
---|
1024 | }
|
---|
1025 | goto RunDefWndProc;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | case WM_PAINT:
|
---|
1029 | {
|
---|
1030 | RECTL rectl;
|
---|
1031 | BOOL rc;
|
---|
1032 |
|
---|
1033 | win32wnd->checkForDirtyUpdateRegion();
|
---|
1034 |
|
---|
1035 | rc = WinQueryUpdateRect(hwnd, &rectl);
|
---|
1036 | dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
|
---|
1037 |
|
---|
1038 | if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
|
---|
1039 | rectl.yBottom != rectl.yTop) && !IsIconic(win32wnd->GetTopParent()))
|
---|
1040 | {
|
---|
1041 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
1042 | if(WinQueryUpdateRect(hwnd, NULL) == TRUE)
|
---|
1043 | {//the application didn't validate the update region; Windows
|
---|
1044 | //will only send a WM_PAINT once until another part of the
|
---|
1045 | //window is invalidated. Unfortunately PM keeps on sending
|
---|
1046 | //WM_PAINT messages until we validate the update region.
|
---|
1047 |
|
---|
1048 | win32wnd->saveAndValidateUpdateRegion();
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | else goto RunDefWndProc;
|
---|
1052 | break;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | case WM_ERASEBACKGROUND:
|
---|
1056 | {
|
---|
1057 | dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
|
---|
1058 | rc = (MRESULT)FALSE;
|
---|
1059 | break;
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | case WM_CALCVALIDRECTS:
|
---|
1063 | dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
|
---|
1064 | rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
|
---|
1065 | break;
|
---|
1066 |
|
---|
1067 | case WM_REALIZEPALETTE:
|
---|
1068 | {
|
---|
1069 | dprintf(("OS2: WM_REALIZEPALETTE %x", win32wnd->getWindowHandle()));
|
---|
1070 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
1071 | break;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | case WM_HSCROLL:
|
---|
1075 | case WM_VSCROLL:
|
---|
1076 | dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
1077 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
1078 | break;
|
---|
1079 |
|
---|
1080 | case WM_IMEREQUEST:
|
---|
1081 | case WM_IMECONTROL:
|
---|
1082 | case WM_IMENOTIFY:
|
---|
1083 | if( pWinMsg->message )
|
---|
1084 | {
|
---|
1085 | win32wnd->DispatchMsgA( pWinMsg );
|
---|
1086 |
|
---|
1087 | if(( pWinMsg->message = WM_IME_NOTIFY_W ) &&
|
---|
1088 | ( pWinMsg->wParam == IMN_SETOPENSTATUS_W ))
|
---|
1089 | {
|
---|
1090 | MSG m;
|
---|
1091 |
|
---|
1092 | m.message = WM_IME_NOTIFY_W;
|
---|
1093 | m.wParam = IMN_SETCONVERSIONMODE_W;
|
---|
1094 | m.lParam = 0;
|
---|
1095 |
|
---|
1096 | win32wnd->DispatchMsgA( &m );
|
---|
1097 | }
|
---|
1098 | }
|
---|
1099 | else
|
---|
1100 | goto RunDefWndProc;
|
---|
1101 | break;
|
---|
1102 |
|
---|
1103 | case DM_DRAGOVER:
|
---|
1104 | {
|
---|
1105 | PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
|
---|
1106 | PDRAGITEM pDragItem;
|
---|
1107 | USHORT sxDrop = SHORT1FROMMP(mp2);
|
---|
1108 | USHORT syDrop = SHORT2FROMMP(mp2);
|
---|
1109 |
|
---|
1110 | dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
|
---|
1111 |
|
---|
1112 | /* Get access to the DRAGINFO data structure */
|
---|
1113 | if(!DrgAccessDraginfo(pDragInfo)) {
|
---|
1114 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1115 | break;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /* We send DM_DRAGOVER/DM_DROP events to ourselves using WinSendMsg()
|
---|
1119 | * in OSLibDragOver()/OSLibDragDrop() but this is not correct to the
|
---|
1120 | * extent that it does not set up some internal PM structures so that
|
---|
1121 | * DrgFreeDraginfo() called to pair DrgAccessDraginfo() in this message
|
---|
1122 | * handler actually frees the structure whilie it is still in use by
|
---|
1123 | * DoDragDrop() and causes a crash upon the next access. We avoid to
|
---|
1124 | * do a free call in this case. This solution may have side effects...
|
---|
1125 | */
|
---|
1126 | BOOL freeDragInfo = TRUE;
|
---|
1127 | PID pid;
|
---|
1128 | TID tid;
|
---|
1129 | if (WinQueryWindowProcess(pDragInfo->hwndSource, &pid, &tid)) {
|
---|
1130 | PPIB ppib;
|
---|
1131 | DosGetInfoBlocks(0, &ppib);
|
---|
1132 | dprintf(("OS2: DM_DRAGOVER source PID %d, this PID %d", pid, ppib->pib_ulpid));
|
---|
1133 | if (ppib->pib_ulpid == pid)
|
---|
1134 | freeDragInfo = FALSE;
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | do {
|
---|
1138 | if(fDragDropDisabled) {
|
---|
1139 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1140 | break;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | //does this window accept dropped files?
|
---|
1144 | if(!DragDropAccept(win32wnd->getWindowHandle())) {
|
---|
1145 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1146 | break;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | if(PMDragValidate(pDragInfo) == FALSE) {
|
---|
1150 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1151 | break;
|
---|
1152 | }
|
---|
1153 | if(win32wnd->isDragDropActive() == FALSE) {
|
---|
1154 | ULONG ulBytes, cItems;
|
---|
1155 | char *pszFiles;
|
---|
1156 |
|
---|
1157 | pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
|
---|
1158 | if(pszFiles) {
|
---|
1159 | POINT point = {sxDrop, syDrop};
|
---|
1160 | if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
|
---|
1161 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1162 | }
|
---|
1163 | else {
|
---|
1164 | fDragDropActive = TRUE;
|
---|
1165 | rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
|
---|
1166 | win32wnd->setDragDropActive(TRUE);
|
---|
1167 | }
|
---|
1168 | free(pszFiles);
|
---|
1169 | }
|
---|
1170 | else {
|
---|
1171 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1172 | }
|
---|
1173 | }
|
---|
1174 | else {
|
---|
1175 | if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
|
---|
1176 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1177 | }
|
---|
1178 | else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
|
---|
1179 | }
|
---|
1180 | break;
|
---|
1181 | } while (0);
|
---|
1182 |
|
---|
1183 | /* Release the draginfo data structure */
|
---|
1184 | if (freeDragInfo)
|
---|
1185 | DrgFreeDraginfo(pDragInfo);
|
---|
1186 |
|
---|
1187 | break;
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | case DM_DRAGLEAVE:
|
---|
1191 | {
|
---|
1192 | dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle()));
|
---|
1193 |
|
---|
1194 | if(fDragDropDisabled) {
|
---|
1195 | break;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | fDragDropActive = FALSE;
|
---|
1199 |
|
---|
1200 | //does this window accept dropped files?
|
---|
1201 | if(!DragDropAccept(win32wnd->getWindowHandle())) {
|
---|
1202 | break;
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | DragDropDragLeave(win32wnd->getWindowHandle());
|
---|
1206 | win32wnd->setDragDropActive(FALSE);
|
---|
1207 | break;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | case DM_DROP:
|
---|
1211 | {
|
---|
1212 | PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
|
---|
1213 | PDRAGITEM pDragItem;
|
---|
1214 | USHORT sxDrop = SHORT1FROMMP(mp2);
|
---|
1215 | USHORT syDrop = SHORT2FROMMP(mp2);
|
---|
1216 | USHORT usIndicator, usOp;
|
---|
1217 |
|
---|
1218 | dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
|
---|
1219 |
|
---|
1220 | /* Get access to the DRAGINFO data structure */
|
---|
1221 | if(!DrgAccessDraginfo(pDragInfo)) {
|
---|
1222 | rc = (MRFROM2SHORT (DOR_NODROP, 0));
|
---|
1223 | break;
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | /* We send DM_DRAGOVER/DM_DROP events to ourselves using WinSendMsg()
|
---|
1227 | * in OSLibDragOver()/OSLibDragDrop() but this is not correct to the
|
---|
1228 | * extent that it does not set up some internal PM structures so that
|
---|
1229 | * DrgFreeDraginfo() called to pair DrgAccessDraginfo() in this message
|
---|
1230 | * handler actually frees the structure whilie it is still in use by
|
---|
1231 | * DoDragDrop() and causes a crash upon the next access. We avoid to
|
---|
1232 | * do a free call in this case. This solution may have side effects...
|
---|
1233 | */
|
---|
1234 | BOOL freeDragInfo = TRUE;
|
---|
1235 | PID pid;
|
---|
1236 | TID tid;
|
---|
1237 | if (WinQueryWindowProcess(pDragInfo->hwndSource, &pid, &tid)) {
|
---|
1238 | PPIB ppib;
|
---|
1239 | DosGetInfoBlocks(0, &ppib);
|
---|
1240 | dprintf(("OS2: DM_DRAGOVER source PID %d, this PID %d", pid, ppib->pib_ulpid));
|
---|
1241 | if (ppib->pib_ulpid == pid)
|
---|
1242 | freeDragInfo = FALSE;
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | do {
|
---|
1246 | fDragDropActive = FALSE;
|
---|
1247 | rc = (MRFROM2SHORT (DOR_NODROP, 0));
|
---|
1248 |
|
---|
1249 | if(fDragDropDisabled) {
|
---|
1250 | rc = (MRFROM2SHORT (DOR_NODROP, 0));
|
---|
1251 | break;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | //does this window accept dropped files?
|
---|
1255 | if(!DragDropAccept(win32wnd->getWindowHandle())) {
|
---|
1256 | break;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | ULONG ulBytes, cItems;
|
---|
1260 | char *pszFiles;
|
---|
1261 |
|
---|
1262 | pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
|
---|
1263 | if(pszFiles) {
|
---|
1264 | POINT point = {sxDrop, syDrop};
|
---|
1265 | if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
|
---|
1266 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1267 | }
|
---|
1268 | else {
|
---|
1269 | rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
|
---|
1270 | win32wnd->setDragDropActive(FALSE);
|
---|
1271 | }
|
---|
1272 | free(pszFiles);
|
---|
1273 | }
|
---|
1274 | else {
|
---|
1275 | rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
|
---|
1276 | }
|
---|
1277 | break;
|
---|
1278 | } while (0);
|
---|
1279 |
|
---|
1280 | /* Release the draginfo data structure */
|
---|
1281 | if (freeDragInfo)
|
---|
1282 | DrgFreeDraginfo(pDragInfo);
|
---|
1283 |
|
---|
1284 | break;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | case DM_RENDER:
|
---|
1288 | {
|
---|
1289 | PDRAGTRANSFER pDragTransfer = (PDRAGTRANSFER)mp1;
|
---|
1290 |
|
---|
1291 | dprintf(("OS2: DM_RENDER %x", pDragTransfer));
|
---|
1292 |
|
---|
1293 | rc = (MRESULT)OSLibRenderFormat(pDragTransfer);
|
---|
1294 | break;
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | case DM_RENDERPREPARE:
|
---|
1298 | {
|
---|
1299 | PDRAGTRANSFER pDragTransfer = (PDRAGTRANSFER)mp1;
|
---|
1300 |
|
---|
1301 | dprintf(("OS2: DM_RENDERPREPARE %x", pDragTransfer));
|
---|
1302 | break;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | case DM_ENDCONVERSATION:
|
---|
1306 | {
|
---|
1307 | dprintf(("OS2: DM_ENDCONVERSATION"));
|
---|
1308 | rc = (MRESULT)OSLibEndConversation();
|
---|
1309 | break;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | case DM_RENDERFILE:
|
---|
1313 | {
|
---|
1314 | dprintf(("OS2: DM_ENDCONVERSATION"));
|
---|
1315 | rc = FALSE;
|
---|
1316 | break;
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | case WM_DDE_INITIATE:
|
---|
1320 | case WM_DDE_INITIATEACK:
|
---|
1321 | case WM_DDE_REQUEST:
|
---|
1322 | case WM_DDE_ACK:
|
---|
1323 | case WM_DDE_DATA:
|
---|
1324 | case WM_DDE_ADVISE:
|
---|
1325 | case WM_DDE_UNADVISE:
|
---|
1326 | case WM_DDE_POKE:
|
---|
1327 | case WM_DDE_EXECUTE:
|
---|
1328 | case WM_DDE_TERMINATE:
|
---|
1329 | dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
|
---|
1330 | goto RunDefWndProc;
|
---|
1331 |
|
---|
1332 | case WM_INITMENU:
|
---|
1333 | case WM_MENUSELECT:
|
---|
1334 | case WM_MENUEND:
|
---|
1335 | case WM_NEXTMENU:
|
---|
1336 | case WM_SYSCOLORCHANGE:
|
---|
1337 | case WM_SYSVALUECHANGED:
|
---|
1338 | case WM_SETSELECTION:
|
---|
1339 | case WM_PPAINT:
|
---|
1340 | case WM_PSETFOCUS:
|
---|
1341 | case WM_PSYSCOLORCHANGE:
|
---|
1342 | case WM_PSIZE:
|
---|
1343 | case WM_PACTIVATE:
|
---|
1344 | case WM_PCONTROL:
|
---|
1345 | case WM_HELP:
|
---|
1346 | case WM_APPTERMINATENOTIFY:
|
---|
1347 | case WM_PRESPARAMCHANGED:
|
---|
1348 | case WM_DRAWITEM:
|
---|
1349 | case WM_MEASUREITEM:
|
---|
1350 | case WM_CONTROLPOINTER:
|
---|
1351 | case WM_QUERYDLGCODE:
|
---|
1352 | case WM_SUBSTITUTESTRING:
|
---|
1353 | case WM_MATCHMNEMONIC:
|
---|
1354 | case WM_SAVEAPPLICATION:
|
---|
1355 | case WM_SEMANTICEVENT:
|
---|
1356 | default:
|
---|
1357 | dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
|
---|
1358 | goto RunDefWndProc;
|
---|
1359 | }
|
---|
1360 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
1361 | RestoreOS2TIB();
|
---|
1362 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
1363 |
|
---|
1364 | #ifdef DEBUG
|
---|
1365 | dbg_ThreadPopCall();
|
---|
1366 | #endif
|
---|
1367 | return (MRESULT)rc;
|
---|
1368 |
|
---|
1369 | RunDefWndProc:
|
---|
1370 | // dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
|
---|
1371 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
1372 |
|
---|
1373 | RestoreOS2TIB();
|
---|
1374 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
1375 |
|
---|
1376 | #ifdef DEBUG
|
---|
1377 | dbg_ThreadPopCall();
|
---|
1378 | #endif
|
---|
1379 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
1380 | } /* End of Win32WindowProc */
|
---|
1381 | //******************************************************************************
|
---|
1382 | //******************************************************************************
|
---|
1383 | MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
1384 | {
|
---|
1385 | POSTMSG_PACKET *postmsg;
|
---|
1386 | OSLIBPOINT point, ClientPoint;
|
---|
1387 | Win32BaseWindow *win32wnd;
|
---|
1388 | TEB *teb;
|
---|
1389 | MRESULT rc = 0;
|
---|
1390 | MSG winMsg, *pWinMsg;
|
---|
1391 | EXCEPTIONREGISTRATIONRECORD exceptRegRec = {0,0};
|
---|
1392 |
|
---|
1393 | #ifdef DEBUG
|
---|
1394 | dbg_ThreadPushCall("Win32FrameWindowProc");
|
---|
1395 | #endif
|
---|
1396 |
|
---|
1397 | ODIN_SetExceptionHandler(&exceptRegRec);
|
---|
1398 | //Restore our FS selector
|
---|
1399 | SetWin32TIB();
|
---|
1400 |
|
---|
1401 | // BEGIN NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
|
---|
1402 | teb = GetThreadTEB();
|
---|
1403 | win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
|
---|
1404 |
|
---|
1405 | // do some sanity checking here:
|
---|
1406 | // - we need to have a TEB handle
|
---|
1407 | // - unless this is WM_CREATE (the very first message), there has to be
|
---|
1408 | // a USER32 window object for this window handle
|
---|
1409 | // - thread must not be suspended in WaitMessage
|
---|
1410 | if(!teb || (msg != WM_CREATE && win32wnd == NULL) || teb->o.odin.fWaitMessageSuspend) {
|
---|
1411 | if(teb && teb->o.odin.fWaitMessageSuspend)
|
---|
1412 | dprintf(("PMFRAME: fWaitMessageSuspend window %x msg %x -> run default frame proc", hwnd, msg));
|
---|
1413 | else dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
|
---|
1414 | goto RunDefFrameWndProc;
|
---|
1415 | }
|
---|
1416 | //// if(teb->o.odin.fIgnoreMsgs) {
|
---|
1417 | //// goto RunDefWndProc;
|
---|
1418 | //// }
|
---|
1419 |
|
---|
1420 | // check if the message state counter in the TEB is odd
|
---|
1421 | // This means the message has been sent directly from PM to our message
|
---|
1422 | // handler (so it is the first time we know about this PM message).
|
---|
1423 | // If this is the case, we have to translate it here to a Win32
|
---|
1424 | // message first. The other case is that the message is the result of a
|
---|
1425 | // WinDispatchMsg call and therefore has already been translated.
|
---|
1426 | if((teb->o.odin.msgstate & 1) == 0)
|
---|
1427 | {//message that was sent directly to our window proc handler; translate it here
|
---|
1428 | QMSG qmsg;
|
---|
1429 |
|
---|
1430 | qmsg.msg = msg;
|
---|
1431 | qmsg.hwnd = hwnd;
|
---|
1432 | qmsg.mp1 = mp1;
|
---|
1433 | qmsg.mp2 = mp2;
|
---|
1434 | qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
|
---|
1435 | WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
|
---|
1436 | qmsg.reserved = 0;
|
---|
1437 |
|
---|
1438 | if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
|
---|
1439 | {//message was not translated
|
---|
1440 | memset(&winMsg, 0, sizeof(MSG));
|
---|
1441 | }
|
---|
1442 | pWinMsg = &winMsg;
|
---|
1443 | }
|
---|
1444 | else {
|
---|
1445 | // message has already been translated before (GetMessage/PeekMessage).
|
---|
1446 | // Use the translated information. Flip the translation flag.
|
---|
1447 | pWinMsg = &teb->o.odin.msg;
|
---|
1448 | teb->o.odin.msgstate++;
|
---|
1449 | }
|
---|
1450 | // END NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
|
---|
1451 |
|
---|
1452 | switch( msg )
|
---|
1453 | {
|
---|
1454 | case WM_CREATE:
|
---|
1455 | {
|
---|
1456 | //WM_CREATE handled during client window creation
|
---|
1457 | dprintf(("PMFRAME: WM_CREATE %x", hwnd));
|
---|
1458 | goto RunDefFrameWndProc;
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 | //hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
|
---|
1462 | // handler; must postpone it, so do it here
|
---|
1463 | case WIN32APP_POSTPONEDESTROY:
|
---|
1464 | OSLibWinDestroyWindow(hwnd);
|
---|
1465 | break;
|
---|
1466 | //hack end
|
---|
1467 |
|
---|
1468 | #ifdef DEBUG
|
---|
1469 | case WM_CLOSE:
|
---|
1470 | {
|
---|
1471 | dprintf(("PMFRAME: WM_CLOSE %x", hwnd));
|
---|
1472 | goto RunDefFrameWndProc;
|
---|
1473 | }
|
---|
1474 | #endif
|
---|
1475 |
|
---|
1476 | case WM_PAINT:
|
---|
1477 | {
|
---|
1478 | RECTL rectl;
|
---|
1479 | HRGN hrgn;
|
---|
1480 |
|
---|
1481 | hrgn = CreateRectRgn(0, 0, 0, 0);
|
---|
1482 | GetUpdateRgnFrame(win32wnd->getWindowHandle(), hrgn);
|
---|
1483 |
|
---|
1484 | HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
|
---|
1485 | dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
|
---|
1486 |
|
---|
1487 | if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
|
---|
1488 | rectl.yBottom != rectl.yTop))
|
---|
1489 | {
|
---|
1490 | PRECT pClient = win32wnd->getClientRectPtr();
|
---|
1491 | PRECT pWindow = win32wnd->getWindowRect();
|
---|
1492 |
|
---|
1493 | if(!(pClient->left == 0 && pClient->top == 0 &&
|
---|
1494 | win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
|
---|
1495 | win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
|
---|
1496 | {
|
---|
1497 | RECT rectUpdate;
|
---|
1498 |
|
---|
1499 | mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
|
---|
1500 | win32wnd->MsgNCPaint(&rectUpdate, hrgn);
|
---|
1501 | }
|
---|
1502 | }
|
---|
1503 | WinEndPaint(hps);
|
---|
1504 |
|
---|
1505 | DeleteObject(hrgn);
|
---|
1506 | break;
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | case WM_ERASEBACKGROUND:
|
---|
1510 | {
|
---|
1511 | dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
|
---|
1512 | rc = (MRESULT)FALSE;
|
---|
1513 | break;
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | //**************************************************************************
|
---|
1517 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
|
---|
1518 | //**************************************************************************
|
---|
1519 |
|
---|
1520 | case WM_BUTTON1DOWN:
|
---|
1521 | case WM_BUTTON1UP:
|
---|
1522 | case WM_BUTTON1DBLCLK:
|
---|
1523 | case WM_BUTTON2DOWN:
|
---|
1524 | case WM_BUTTON2UP:
|
---|
1525 | case WM_BUTTON2DBLCLK:
|
---|
1526 | case WM_BUTTON3DOWN:
|
---|
1527 | case WM_BUTTON3UP:
|
---|
1528 | case WM_BUTTON3DBLCLK:
|
---|
1529 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
|
---|
1530 | RELEASE_WNDOBJ(win32wnd);
|
---|
1531 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
|
---|
1532 | }
|
---|
1533 | if(win32wnd)
|
---|
1534 | win32wnd->MsgButton(pWinMsg);
|
---|
1535 |
|
---|
1536 | rc = (MRESULT)TRUE;
|
---|
1537 | break;
|
---|
1538 |
|
---|
1539 | case WM_BUTTON2MOTIONSTART:
|
---|
1540 | case WM_BUTTON2MOTIONEND:
|
---|
1541 | case WM_BUTTON2CLICK:
|
---|
1542 | case WM_BUTTON1MOTIONSTART:
|
---|
1543 | case WM_BUTTON1MOTIONEND:
|
---|
1544 | case WM_BUTTON1CLICK:
|
---|
1545 | case WM_BUTTON3MOTIONSTART:
|
---|
1546 | case WM_BUTTON3MOTIONEND:
|
---|
1547 | case WM_BUTTON3CLICK:
|
---|
1548 | rc = (MRESULT)TRUE;
|
---|
1549 | break;
|
---|
1550 |
|
---|
1551 | case WM_MOUSEMOVE:
|
---|
1552 | {
|
---|
1553 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
|
---|
1554 | RELEASE_WNDOBJ(win32wnd);
|
---|
1555 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
|
---|
1556 | }
|
---|
1557 | if(win32wnd)
|
---|
1558 | win32wnd->MsgMouseMove(pWinMsg);
|
---|
1559 | break;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | case WM_CHAR_SPECIAL_CONSOLE_BREAK:
|
---|
1563 | {
|
---|
1564 | //ignore this message. don't forward it to the default PM frame window handler
|
---|
1565 | //as that one sends it to the client. as a result we end up translating
|
---|
1566 | //it twice
|
---|
1567 | break;
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | case WM_CHAR:
|
---|
1571 | {
|
---|
1572 | dprintf(("PMFRAME:WM_CHAR"));
|
---|
1573 | break;
|
---|
1574 | }
|
---|
1575 |
|
---|
1576 | case WM_ADJUSTWINDOWPOS:
|
---|
1577 | {
|
---|
1578 | PSWP pswp = (PSWP)mp1;
|
---|
1579 | SWP swpOld;
|
---|
1580 | WINDOWPOS wp,wpOld;
|
---|
1581 | ULONG ulFlags;
|
---|
1582 | ULONG ret = 0;
|
---|
1583 | HWND hParent = NULLHANDLE, hwndAfter;
|
---|
1584 |
|
---|
1585 | dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
1586 |
|
---|
1587 | ulFlags = pswp->fl;
|
---|
1588 |
|
---|
1589 | if(win32wnd->IsParentChanging()) {
|
---|
1590 | rc = 0;
|
---|
1591 | break;
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | //@@PF all commands from minimized window viewer or from Ctrl-Esc
|
---|
1595 | //are 'pure' and should be handled only by DeFrameProc - this is weird
|
---|
1596 | //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
|
---|
1597 | if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
|
---|
1598 | // note the purity of SWP no other SWP_FLAGS allowed
|
---|
1599 | goto RunDefFrameWndProc;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | if(pswp->fl & SWP_NOADJUST) {
|
---|
1603 | //ignore weird messages (TODO: why are they sent?)
|
---|
1604 | dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
|
---|
1605 | break;
|
---|
1606 |
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | //PF Pure flags should not cause any subsequent messages to win32 windows
|
---|
1610 | //we should route them to DefFrameWndProc and check highlight.
|
---|
1611 |
|
---|
1612 | if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
|
---|
1613 | {
|
---|
1614 | if (fOS2Look)
|
---|
1615 | {
|
---|
1616 | if(pswp->fl == SWP_FOCUSACTIVATE)
|
---|
1617 | {
|
---|
1618 | dprintf2(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
|
---|
1619 | WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
|
---|
1620 | }
|
---|
1621 | else
|
---|
1622 | {
|
---|
1623 | dprintf2(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
|
---|
1624 | WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
|
---|
1625 | }
|
---|
1626 | }
|
---|
1627 | goto RunDefFrameWndProc;
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 | //CB: show dialog in front of owner
|
---|
1631 | if (win32wnd->IsModalDialogOwner())
|
---|
1632 | {
|
---|
1633 | dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
|
---|
1634 | pswp->fl |= SWP_ZORDER;
|
---|
1635 | pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
|
---|
1636 | if (pswp->fl & SWP_ACTIVATE)
|
---|
1637 | {
|
---|
1638 | pswp->fl &= ~SWP_ACTIVATE;
|
---|
1639 | WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
|
---|
1640 | }
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | if(!win32wnd->CanReceiveSizeMsgs())
|
---|
1644 | break;
|
---|
1645 |
|
---|
1646 | WinQueryWindowPos(hwnd, &swpOld);
|
---|
1647 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
|
---|
1648 | if (win32wnd->isChild()) {
|
---|
1649 | if(win32wnd->getParent()) {
|
---|
1650 | hParent = win32wnd->getParent()->getOS2WindowHandle();
|
---|
1651 | }
|
---|
1652 | else goto RunDefFrameWndProc;
|
---|
1653 | }
|
---|
1654 | }
|
---|
1655 | hwndAfter = pswp->hwndInsertBehind;
|
---|
1656 | if(win32wnd->getParent()) {
|
---|
1657 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
|
---|
1658 | }
|
---|
1659 | else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
|
---|
1660 |
|
---|
1661 | wp.hwnd = win32wnd->getWindowHandle();
|
---|
1662 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
|
---|
1663 | {
|
---|
1664 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
|
---|
1665 | dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
|
---|
1666 | if(wndAfter) {
|
---|
1667 | wp.hwndInsertAfter = wndAfter->getWindowHandle();
|
---|
1668 | RELEASE_WNDOBJ(wndAfter);
|
---|
1669 | }
|
---|
1670 | else wp.hwndInsertAfter = HWND_TOP_W;
|
---|
1671 | }
|
---|
1672 |
|
---|
1673 | wpOld = wp;
|
---|
1674 | win32wnd->MsgPosChanging((LPARAM)&wp);
|
---|
1675 |
|
---|
1676 | if(win32wnd->getOldStyle() != win32wnd->getStyle())
|
---|
1677 | {
|
---|
1678 | OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle(), win32wnd->getStyle());
|
---|
1679 | if(fOS2Look) {
|
---|
1680 | DWORD dwOldStyle = win32wnd->getOldStyle();
|
---|
1681 | DWORD dwStyle = win32wnd->getStyle();
|
---|
1682 |
|
---|
1683 | win32wnd->setOldStyle(dwStyle);
|
---|
1684 | if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
|
---|
1685 | //SC_RESTORE -> SC_MINIMIZE
|
---|
1686 | dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
|
---|
1687 | FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[PMMENU_MINBUTTON]);
|
---|
1688 | if(dwStyle & WS_MAXIMIZE_W) {
|
---|
1689 | //SC_MAXIMIZE -> SC_RESTORE
|
---|
1690 | dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (1)", win32wnd->getWindowHandle()));
|
---|
1691 | FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
|
---|
1692 | }
|
---|
1693 | }
|
---|
1694 | else
|
---|
1695 | if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
|
---|
1696 | //SC_RESTORE -> SC_MAXIMIZE
|
---|
1697 | dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
|
---|
1698 | FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[PMMENU_MAXBUTTON]);
|
---|
1699 | }
|
---|
1700 | else
|
---|
1701 | if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
|
---|
1702 | //SC_MINIMIZE -> SC_RESTORE
|
---|
1703 | dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
|
---|
1704 | FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
|
---|
1705 | }
|
---|
1706 | else
|
---|
1707 | if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
|
---|
1708 | //SC_MAXIMIZE -> SC_RESTORE
|
---|
1709 | dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (2)", win32wnd->getWindowHandle()));
|
---|
1710 | FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
|
---|
1711 | }
|
---|
1712 | }
|
---|
1713 | }
|
---|
1714 |
|
---|
1715 | if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
|
---|
1716 | (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
|
---|
1717 | {
|
---|
1718 | ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
|
---|
1719 |
|
---|
1720 | dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
|
---|
1721 | dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
1722 |
|
---|
1723 | if(win32wnd->getParent()) {
|
---|
1724 | OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
---|
1725 | hwnd);
|
---|
1726 | }
|
---|
1727 | else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
|
---|
1728 |
|
---|
1729 | dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
1730 |
|
---|
1731 | //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
|
---|
1732 | if(pswp->fl & SWP_SIZE)
|
---|
1733 | flags |= SWP_SIZE;
|
---|
1734 |
|
---|
1735 | if(pswp->fl & SWP_MOVE)
|
---|
1736 | flags |= SWP_MOVE;
|
---|
1737 |
|
---|
1738 | pswp->fl = flags; //restore flags
|
---|
1739 |
|
---|
1740 | pswp->fl |= SWP_NOADJUST;
|
---|
1741 | pswp->hwndInsertBehind = hwndAfter;
|
---|
1742 | pswp->hwnd = hwnd;
|
---|
1743 |
|
---|
1744 | ret = 0xf;
|
---|
1745 | }
|
---|
1746 | adjustend:
|
---|
1747 | //The next part needs to be done for top-level windows only
|
---|
1748 | if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
|
---|
1749 | {
|
---|
1750 | //Setting these flags is necessary to avoid activation/focus problems
|
---|
1751 | if(ulFlags & SWP_DEACTIVATE) {
|
---|
1752 | ret |= AWP_DEACTIVATE;
|
---|
1753 | }
|
---|
1754 | if(ulFlags & SWP_ACTIVATE)
|
---|
1755 | {
|
---|
1756 | if(ulFlags & SWP_ZORDER) {
|
---|
1757 | dprintf(("Set FF_NOACTIVATESWP"));
|
---|
1758 | ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
|
---|
1759 | WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | if(!(ulFlags & SWP_SHOW))
|
---|
1763 | {
|
---|
1764 | ret |= AWP_ACTIVATE;
|
---|
1765 | }
|
---|
1766 | else
|
---|
1767 | {
|
---|
1768 | FrameSetFocus(hwnd);
|
---|
1769 | }
|
---|
1770 | }
|
---|
1771 | }
|
---|
1772 | else {
|
---|
1773 | if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
|
---|
1774 | {
|
---|
1775 | win32wnd->MsgChildActivate(TRUE);
|
---|
1776 | if(fOS2Look) {
|
---|
1777 | dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
|
---|
1778 | WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
|
---|
1779 | }
|
---|
1780 | }
|
---|
1781 | else
|
---|
1782 | if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
|
---|
1783 | {
|
---|
1784 | win32wnd->MsgChildActivate(FALSE);
|
---|
1785 | if(fOS2Look) {
|
---|
1786 | dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
|
---|
1787 | WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
|
---|
1788 | }
|
---|
1789 | }
|
---|
1790 | }
|
---|
1791 | #ifdef DEBUG
|
---|
1792 | dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
|
---|
1793 | if(ret == 0x0f) {
|
---|
1794 | dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
|
---|
1795 | dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
1796 | }
|
---|
1797 | #endif
|
---|
1798 | rc = (MRESULT)ret;
|
---|
1799 | break;
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | case WM_WINDOWPOSCHANGED:
|
---|
1803 | {
|
---|
1804 | PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
|
---|
1805 | SWP swpOld = *(pswp + 1);
|
---|
1806 | WINDOWPOS wp;
|
---|
1807 | ULONG flAfp = (ULONG)mp2;
|
---|
1808 | HWND hParent = NULLHANDLE;
|
---|
1809 | RECTL rect;
|
---|
1810 |
|
---|
1811 | dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%s) (%d,%d) (%d,%d) z %x", mp2, win32wnd->getWindowHandle(), pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy, Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind)));
|
---|
1812 | if(win32wnd->IsParentChanging()) {
|
---|
1813 | goto PosChangedEnd;
|
---|
1814 | }
|
---|
1815 |
|
---|
1816 | // PF: MDI window is not a common OS/2 frame window so we just skipped all
|
---|
1817 | // PM default processing for it that basicly moved this window to 0,0 point
|
---|
1818 | // and changed frame controls. Now do our own processing.
|
---|
1819 |
|
---|
1820 | if ((pswp->fl & SWP_MAXIMIZE) && (win32wnd->getExStyle() & WS_EX_MDICHILD_W))
|
---|
1821 | {
|
---|
1822 | SendMessageA(win32wnd->getWindowHandle(), WM_SYSCOMMAND_W, SC_MAXIMIZE_W, 0);
|
---|
1823 | goto PosChangedEnd;
|
---|
1824 | }
|
---|
1825 |
|
---|
1826 | //SvL: When a window is made visible, then we don't receive a
|
---|
1827 | // WM_VRNENABLED message (for some weird reason)
|
---|
1828 | if(pswp->fl & SWP_SHOW) {
|
---|
1829 | win32wnd->callVisibleRgnNotifyProc(TRUE);
|
---|
1830 | }
|
---|
1831 | else
|
---|
1832 | if(pswp->fl & SWP_HIDE) {
|
---|
1833 | win32wnd->callVisibleRgnNotifyProc(FALSE);
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | if(pswp->fl & (SWP_MOVE | SWP_SIZE))
|
---|
1837 | {
|
---|
1838 | if(win32wnd->isChild())
|
---|
1839 | {
|
---|
1840 | if(win32wnd->getParent()) {
|
---|
1841 | hParent = win32wnd->getParent()->getOS2WindowHandle();
|
---|
1842 | }
|
---|
1843 | else goto PosChangedEnd; //parent has just been destroyed
|
---|
1844 | }
|
---|
1845 | }
|
---|
1846 |
|
---|
1847 |
|
---|
1848 | if(win32wnd->getParent()) {
|
---|
1849 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
---|
1850 | hwnd);
|
---|
1851 | }
|
---|
1852 | else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
|
---|
1853 |
|
---|
1854 | wp.hwnd = win32wnd->getWindowHandle();
|
---|
1855 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
|
---|
1856 | {
|
---|
1857 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
|
---|
1858 | dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
|
---|
1859 | if(wndAfter) {
|
---|
1860 | wp.hwndInsertAfter = wndAfter->getWindowHandle();
|
---|
1861 | RELEASE_WNDOBJ(wndAfter);
|
---|
1862 | }
|
---|
1863 | else wp.hwndInsertAfter = HWND_TOP_W;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
|
---|
1867 | {
|
---|
1868 | if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
|
---|
1869 | dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
|
---|
1870 | win32wnd->ShowWindow(SW_RESTORE_W);
|
---|
1871 | }
|
---|
1872 | if(pswp->fl & SWP_SHOW) {
|
---|
1873 | WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
|
---|
1874 | }
|
---|
1875 | else
|
---|
1876 | if(pswp->fl & SWP_HIDE) {
|
---|
1877 | WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
|
---|
1878 | }
|
---|
1879 | if(pswp->fl & (SWP_SHOW|SWP_HIDE))
|
---|
1880 | {//TODO: necessary for more options? (activate?)
|
---|
1881 | if(win32wnd->CanReceiveSizeMsgs())
|
---|
1882 | win32wnd->MsgPosChanged((LPARAM)&wp);
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | //MUST call the old frame window proc!
|
---|
1886 | goto RunDefFrameWndProc;
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | if(pswp->fl & SWP_SHOW) {
|
---|
1890 | WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
|
---|
1891 | }
|
---|
1892 | else
|
---|
1893 | if(pswp->fl & SWP_HIDE) {
|
---|
1894 | WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
|
---|
1895 | }
|
---|
1896 |
|
---|
1897 | if(flAfp & AWP_ACTIVATE)
|
---|
1898 | {
|
---|
1899 | FrameSetFocus(hwnd);
|
---|
1900 | }
|
---|
1901 |
|
---|
1902 | #ifndef USE_CALCVALIDRECT
|
---|
1903 | if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
|
---|
1904 | {
|
---|
1905 | //CB: todo: use result for WM_CALCVALIDRECTS
|
---|
1906 | //Get old client rectangle (for invalidation of frame window parts later on)
|
---|
1907 | //Use new window height to calculate the client area
|
---|
1908 | mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
|
---|
1909 |
|
---|
1910 | //Note: Also updates the new window rectangle
|
---|
1911 | win32wnd->MsgFormatFrame(&wp);
|
---|
1912 |
|
---|
1913 | if(win32wnd->isOwnDC()) {
|
---|
1914 | setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
|
---|
1915 | }
|
---|
1916 |
|
---|
1917 | if(win32wnd->CanReceiveSizeMsgs())
|
---|
1918 | win32wnd->MsgPosChanged((LPARAM)&wp);
|
---|
1919 |
|
---|
1920 | if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
|
---|
1921 | {
|
---|
1922 | //redraw the frame (to prevent unnecessary client updates)
|
---|
1923 | BOOL redrawAll = FALSE;
|
---|
1924 |
|
---|
1925 | dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
|
---|
1926 | if (win32wnd->getWindowClass())
|
---|
1927 | {
|
---|
1928 | DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
|
---|
1929 |
|
---|
1930 | if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
|
---|
1931 | redrawAll = TRUE;
|
---|
1932 | else
|
---|
1933 | if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
|
---|
1934 | redrawAll = TRUE;
|
---|
1935 | }
|
---|
1936 | else redrawAll = TRUE;
|
---|
1937 |
|
---|
1938 | if(win32wnd->IsMixMaxStateChanging()) {
|
---|
1939 | dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
|
---|
1940 | redrawAll = TRUE;
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 | if (redrawAll)
|
---|
1944 | {
|
---|
1945 | //CB: redraw all children for now
|
---|
1946 | // -> problems with update region if we don't do it
|
---|
1947 | // todo: rewrite whole handling
|
---|
1948 | dprintf(("PMFRAME: WM_WINDOWPOSCHANGED invalidate all"));
|
---|
1949 | WinInvalidateRect(hwnd,NULL,TRUE);
|
---|
1950 | }
|
---|
1951 | else
|
---|
1952 | {
|
---|
1953 | HPS hps = WinGetPS(hwnd);
|
---|
1954 | RECTL frame,client,arcl[4];
|
---|
1955 |
|
---|
1956 | WinQueryWindowRect(hwnd,&frame);
|
---|
1957 |
|
---|
1958 | //top
|
---|
1959 | arcl[0].xLeft = 0;
|
---|
1960 | arcl[0].xRight = frame.xRight;
|
---|
1961 | arcl[0].yBottom = rect.yTop;
|
---|
1962 | arcl[0].yTop = frame.yTop;
|
---|
1963 | //right
|
---|
1964 | arcl[1].xLeft = rect.xRight;
|
---|
1965 | arcl[1].xRight = frame.xRight;
|
---|
1966 | arcl[1].yBottom = 0;
|
---|
1967 | arcl[1].yTop = frame.yTop;
|
---|
1968 | //left
|
---|
1969 | arcl[2].xLeft = 0;
|
---|
1970 | arcl[2].xRight = rect.xLeft;
|
---|
1971 | arcl[2].yBottom = 0;
|
---|
1972 | arcl[2].yTop = frame.yTop;
|
---|
1973 | //bottom
|
---|
1974 | arcl[3].xLeft = 0;
|
---|
1975 | arcl[3].xRight = frame.xRight;
|
---|
1976 | arcl[3].yBottom = 0;
|
---|
1977 | arcl[3].yTop = rect.yBottom;
|
---|
1978 |
|
---|
1979 | HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
|
---|
1980 |
|
---|
1981 | WinInvalidateRegion(hwnd,hrgn,FALSE);
|
---|
1982 | GpiDestroyRegion(hps,hrgn);
|
---|
1983 | WinReleasePS(hps);
|
---|
1984 | }
|
---|
1985 | }
|
---|
1986 | }
|
---|
1987 | else
|
---|
1988 | {
|
---|
1989 | #endif //USE_CALCVALIDRECT
|
---|
1990 | if(win32wnd->CanReceiveSizeMsgs())
|
---|
1991 | win32wnd->MsgPosChanged((LPARAM)&wp);
|
---|
1992 | #ifndef USE_CALCVALIDRECT
|
---|
1993 | }
|
---|
1994 | #endif
|
---|
1995 | //PF This is the final step of PM restoration - should end up
|
---|
1996 | //in default handler.
|
---|
1997 | if (win32wnd->getOldStyle() & WS_MINIMIZE_W && pswp->fl & SWP_RESTORE)
|
---|
1998 | goto RunDefFrameWndProc;
|
---|
1999 |
|
---|
2000 | //PF This is the final step of PM minimization - shoukd end up
|
---|
2001 | //in default handler
|
---|
2002 | if (win32wnd->getStyle() & WS_MINIMIZE_W && pswp->fl & SWP_MINIMIZE)
|
---|
2003 | goto RunDefFrameWndProc;
|
---|
2004 |
|
---|
2005 | PosChangedEnd:
|
---|
2006 | rc = (MRESULT)FALSE;
|
---|
2007 | break;
|
---|
2008 | }
|
---|
2009 |
|
---|
2010 | case WM_CALCVALIDRECTS:
|
---|
2011 | #ifdef USE_CALCVALIDRECT
|
---|
2012 | {
|
---|
2013 | PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
|
---|
2014 | PSWP pswp = (PSWP)mp2;
|
---|
2015 | SWP swpOld;
|
---|
2016 | WINDOWPOS wp;
|
---|
2017 | RECTL newClientRect, oldClientRect;
|
---|
2018 | ULONG nccalcret;
|
---|
2019 | // UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
|
---|
2020 | UINT res = 0;
|
---|
2021 |
|
---|
2022 | dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
|
---|
2023 |
|
---|
2024 | //Get old position info
|
---|
2025 | WinQueryWindowPos(hwnd, &swpOld);
|
---|
2026 |
|
---|
2027 | if(win32wnd->getParent()) {
|
---|
2028 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
---|
2029 | win32wnd->getParent()->getClientRectPtr()->left,
|
---|
2030 | win32wnd->getParent()->getClientRectPtr()->top,
|
---|
2031 | hwnd);
|
---|
2032 | }
|
---|
2033 | else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
|
---|
2034 |
|
---|
2035 | wp.hwnd = win32wnd->getWindowHandle();
|
---|
2036 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
|
---|
2037 | {
|
---|
2038 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
|
---|
2039 | if(wndAfter) {
|
---|
2040 | wp.hwndInsertAfter = wndAfter->getWindowHandle();
|
---|
2041 | RELEASE_WNDOBJ(wndAfter);
|
---|
2042 | }
|
---|
2043 | else wp.hwndInsertAfter = HWND_TOP_W;
|
---|
2044 | }
|
---|
2045 |
|
---|
2046 | //Get old client rectangle
|
---|
2047 | mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
|
---|
2048 |
|
---|
2049 | //Note: Also updates the new window rectangle
|
---|
2050 | nccalcret = win32wnd->MsgFormatFrame(&wp);
|
---|
2051 |
|
---|
2052 | //Get new client rectangle
|
---|
2053 | mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
|
---|
2054 |
|
---|
2055 | if(nccalcret == 0) {
|
---|
2056 | res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
|
---|
2057 | }
|
---|
2058 | else {
|
---|
2059 | if(nccalcret & WVR_ALIGNTOP_W) {
|
---|
2060 | res |= CVR_ALIGNTOP;
|
---|
2061 | }
|
---|
2062 | else
|
---|
2063 | if(nccalcret & WVR_ALIGNBOTTOM_W) {
|
---|
2064 | res |= CVR_ALIGNBOTTOM;
|
---|
2065 | }
|
---|
2066 |
|
---|
2067 | if(nccalcret & WVR_ALIGNLEFT_W) {
|
---|
2068 | res |= CVR_ALIGNLEFT;
|
---|
2069 | }
|
---|
2070 | else
|
---|
2071 | if(nccalcret & WVR_ALIGNRIGHT_W) {
|
---|
2072 | res |= CVR_ALIGNRIGHT;
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
|
---|
2076 | res |= CVR_REDRAW;
|
---|
2077 | }
|
---|
2078 | else
|
---|
2079 | if(nccalcret & WVR_VALIDRECTS_W) {
|
---|
2080 | //TODO:
|
---|
2081 | //res = 0;
|
---|
2082 | }
|
---|
2083 | }
|
---|
2084 | if(win32wnd->IsMixMaxStateChanging()) {
|
---|
2085 | dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
|
---|
2086 | res |= CVR_REDRAW;
|
---|
2087 | }
|
---|
2088 | if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
|
---|
2089 | oldRect->xRight -= oldClientRect.xLeft;
|
---|
2090 | oldRect->yBottom += oldClientRect.yBottom;
|
---|
2091 | newRect->xRight -= newClientRect.xLeft;
|
---|
2092 | newRect->yBottom += newClientRect.yBottom;
|
---|
2093 | }
|
---|
2094 | rc = res;
|
---|
2095 | break;
|
---|
2096 | }
|
---|
2097 | #else
|
---|
2098 | dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
|
---|
2099 | rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
|
---|
2100 | break;
|
---|
2101 | #endif
|
---|
2102 |
|
---|
2103 | case WM_CALCFRAMERECT:
|
---|
2104 | dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
|
---|
2105 | rc = (MRESULT)TRUE;
|
---|
2106 | break;
|
---|
2107 |
|
---|
2108 | case WM_QUERYCTLTYPE:
|
---|
2109 | // This is a frame window
|
---|
2110 | dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
|
---|
2111 | rc = (MRESULT)CCT_FRAME;
|
---|
2112 | break;
|
---|
2113 |
|
---|
2114 | #ifdef DEBUG
|
---|
2115 | case WM_QUERYFOCUSCHAIN:
|
---|
2116 | dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x (%s) parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), DbgPrintQFCFlags(SHORT1FROMMP(mp1)), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
|
---|
2117 |
|
---|
2118 | RestoreOS2TIB();
|
---|
2119 | rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
|
---|
2120 | SetWin32TIB();
|
---|
2121 | dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x (%x)", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0, (rc) ? OS2ToWin32Handle((DWORD)rc) : 0, rc));
|
---|
2122 | break;
|
---|
2123 | // goto RunDefFrameWndProc;
|
---|
2124 | #endif
|
---|
2125 |
|
---|
2126 | case WM_FOCUSCHANGE:
|
---|
2127 | {
|
---|
2128 | HWND hwndFocus = (HWND)mp1;
|
---|
2129 | HWND hwndLoseFocus, hwndGainFocus;
|
---|
2130 | USHORT usSetFocus = SHORT1FROMMP(mp2);
|
---|
2131 | USHORT fsFocusChange = SHORT2FROMMP(mp2);
|
---|
2132 |
|
---|
2133 | //Save window that gains focus so we can determine which
|
---|
2134 | //process we lose activation to
|
---|
2135 | hwndFocusChange = (HWND)mp1;
|
---|
2136 |
|
---|
2137 | dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
|
---|
2138 | goto RunDefFrameWndProc;
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | #ifdef DEBUG
|
---|
2142 | case WM_SETFOCUS:
|
---|
2143 | {
|
---|
2144 | dprintf(("PMFRAME: WM_SETFOCUS %x %x %d -> %x", win32wnd->getWindowHandle(), hwnd, mp2, mp1));
|
---|
2145 | goto RunDefFrameWndProc;
|
---|
2146 | }
|
---|
2147 | #endif
|
---|
2148 |
|
---|
2149 | case WM_ACTIVATE:
|
---|
2150 | {
|
---|
2151 | HWND hwndTitle;
|
---|
2152 | USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
|
---|
2153 |
|
---|
2154 | dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
|
---|
2155 | if (win32wnd->IsWindowCreated())
|
---|
2156 | {
|
---|
2157 | WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
|
---|
2158 | if(fOS2Look) {
|
---|
2159 | dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
|
---|
2160 | WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
|
---|
2161 | }
|
---|
2162 | if(SHORT1FROMMP(mp1) == 0) {
|
---|
2163 | //deactivate
|
---|
2164 | WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
|
---|
2165 | }
|
---|
2166 | PID pidThis, pidPartner, pidTemp;
|
---|
2167 | TID tidPartner;
|
---|
2168 | HENUM henum;
|
---|
2169 | HWND hwndEnum;
|
---|
2170 |
|
---|
2171 | WinQueryWindowProcess(hwnd, &pidThis, NULL);
|
---|
2172 | WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
|
---|
2173 |
|
---|
2174 | if(pidThis != pidPartner) {
|
---|
2175 | //Gain or lose activation to window in other process
|
---|
2176 | //must send WM_ACTIVATEAPP to top-level windows
|
---|
2177 |
|
---|
2178 | //Iterate over all child windows of the desktop
|
---|
2179 | henum = WinBeginEnumWindows(HWND_DESKTOP);
|
---|
2180 |
|
---|
2181 | while((hwndEnum = WinGetNextWindow(henum)) != 0)
|
---|
2182 | {
|
---|
2183 | WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
|
---|
2184 | if(pidTemp == pidThis)
|
---|
2185 | {
|
---|
2186 | SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
|
---|
2187 | }
|
---|
2188 | }
|
---|
2189 | WinEndEnumWindows(henum);
|
---|
2190 | }
|
---|
2191 | if(SHORT1FROMMP(mp1)) {
|
---|
2192 | //activate
|
---|
2193 | WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
|
---|
2194 | }
|
---|
2195 |
|
---|
2196 | //CB: show owner behind the dialog
|
---|
2197 | if (win32wnd->IsModalDialog())
|
---|
2198 | {
|
---|
2199 | if(win32wnd->getOwner()) {
|
---|
2200 | Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
|
---|
2201 |
|
---|
2202 | if (topOwner) {
|
---|
2203 | WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
|
---|
2204 | RELEASE_WNDOBJ(topOwner);
|
---|
2205 | }
|
---|
2206 | }
|
---|
2207 | }
|
---|
2208 | }
|
---|
2209 | else
|
---|
2210 | {
|
---|
2211 | WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
|
---|
2212 | }
|
---|
2213 | rc = 0;
|
---|
2214 | break;
|
---|
2215 | }
|
---|
2216 |
|
---|
2217 | case WM_ENABLE:
|
---|
2218 | dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
|
---|
2219 | win32wnd->MsgEnable(SHORT1FROMMP(mp1));
|
---|
2220 | break;
|
---|
2221 |
|
---|
2222 | case WM_SHOW:
|
---|
2223 | dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
|
---|
2224 | //show client window
|
---|
2225 | WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
|
---|
2226 | break;
|
---|
2227 |
|
---|
2228 | case WM_QUERYTRACKINFO:
|
---|
2229 | {
|
---|
2230 | PTRACKINFO trackInfo = (PTRACKINFO)mp2;
|
---|
2231 |
|
---|
2232 | dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
|
---|
2233 | trackInfo->cxBorder = 4;
|
---|
2234 | trackInfo->cyBorder = 4;
|
---|
2235 | win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
|
---|
2236 | rc = (MRESULT)TRUE;
|
---|
2237 | break;
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | case WM_QUERYBORDERSIZE:
|
---|
2241 | {
|
---|
2242 | PWPOINT size = (PWPOINT)mp1;
|
---|
2243 |
|
---|
2244 | dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
|
---|
2245 |
|
---|
2246 | size->x = 0;
|
---|
2247 | size->y = 0;
|
---|
2248 | rc = (MRESULT)TRUE;
|
---|
2249 | break;
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | #ifdef DEBUG
|
---|
2253 | case WM_QUERYFRAMEINFO:
|
---|
2254 | dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
|
---|
2255 | goto RunDefFrameWndProc;
|
---|
2256 | #endif
|
---|
2257 |
|
---|
2258 | case WM_FORMATFRAME:
|
---|
2259 | dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
|
---|
2260 | break;
|
---|
2261 |
|
---|
2262 | case WM_ADJUSTFRAMEPOS:
|
---|
2263 | {
|
---|
2264 | PSWP pswp = (PSWP)mp1;
|
---|
2265 |
|
---|
2266 | dprintf(("PMFRAME:WM_ADJUSTFRAMEPOS %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
2267 | //hack alert: the PM frame control changes the z-order of a child window
|
---|
2268 | // if it receives focus after a window has been destroyed
|
---|
2269 | // We can't let this happen as this messes up assumptions
|
---|
2270 | // elsewhere (e.g. GetNextDlgGroupItem)
|
---|
2271 | // By returning 0 here, we prevent the default frame handler
|
---|
2272 | // from messing things up. (one example is a group of radio buttons)
|
---|
2273 | //NOTE: We really need to get rid of frame & client windows for each
|
---|
2274 | // win32 window
|
---|
2275 | if(pswp->fl == SWP_FOCUSACTIVATE && win32wnd->isChild()) {
|
---|
2276 | rc = 0;
|
---|
2277 | break;
|
---|
2278 | }
|
---|
2279 | //hack alert: as we return zero as border size (check handler) we need
|
---|
2280 | //to do adjustments here as well or PM will calculate it for us and
|
---|
2281 | //result will be illegal. Btw we do not honour PM border size settings
|
---|
2282 | //and never will. I was unable to figure out why only X coordinate
|
---|
2283 | //is being broken but not Y as well.
|
---|
2284 |
|
---|
2285 | if ((pswp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
|
---|
2286 | {
|
---|
2287 | RECT rect;
|
---|
2288 | rect.left = rect.top = rect.right = rect.bottom = 0;
|
---|
2289 | win32wnd->AdjustMaximizedRect(&rect);
|
---|
2290 |
|
---|
2291 | pswp->x += rect.left;
|
---|
2292 | }
|
---|
2293 | goto RunDefFrameWndProc;
|
---|
2294 | }
|
---|
2295 |
|
---|
2296 | #ifdef DEBUG
|
---|
2297 | case WM_OWNERPOSCHANGE:
|
---|
2298 | {
|
---|
2299 | PSWP pswp = (PSWP)mp1;
|
---|
2300 |
|
---|
2301 | dprintf(("PMFRAME:WM_OWNERPOSCHANGE %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
2302 | RestoreOS2TIB();
|
---|
2303 | rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
|
---|
2304 | SetWin32TIB();
|
---|
2305 | dprintf(("PMFRAME: DEF WM_OWNERPOSCHANGE %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
|
---|
2306 | break;
|
---|
2307 | }
|
---|
2308 | #endif
|
---|
2309 |
|
---|
2310 | case WM_MINMAXFRAME:
|
---|
2311 | {
|
---|
2312 | PSWP swp = (PSWP)mp1;
|
---|
2313 |
|
---|
2314 | if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
|
---|
2315 |
|
---|
2316 | dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
|
---|
2317 | if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
|
---|
2318 | {
|
---|
2319 | // MDI frame windows are not common PM windows so we need to
|
---|
2320 | // drop-out WHOLE chain of WM_X commands with SWP_MAXIMIZE flag
|
---|
2321 | // finally last WM_WINDOWPOSCHANGED will take care of maximization
|
---|
2322 |
|
---|
2323 | if (win32wnd->getExStyle() & WS_EX_MDICHILD_W) {
|
---|
2324 | rc = 0;
|
---|
2325 | break;
|
---|
2326 | }
|
---|
2327 |
|
---|
2328 | RECT rect;
|
---|
2329 | rect.left = rect.top = rect.right = rect.bottom = 0;
|
---|
2330 | win32wnd->AdjustMaximizedRect(&rect);
|
---|
2331 |
|
---|
2332 | swp->x += rect.left;
|
---|
2333 | swp->cx += rect.right-rect.left;
|
---|
2334 | swp->y -= rect.bottom;
|
---|
2335 | swp->cy += rect.bottom-rect.top;
|
---|
2336 |
|
---|
2337 | win32wnd->ShowWindow(SW_RESTORE_W);
|
---|
2338 | }
|
---|
2339 | else
|
---|
2340 | if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
|
---|
2341 | {
|
---|
2342 | win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
|
---|
2343 | }
|
---|
2344 | else
|
---|
2345 | if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
|
---|
2346 | {
|
---|
2347 | win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
|
---|
2348 | }
|
---|
2349 | goto RunDefWndProc;
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | #ifdef DEBUG
|
---|
2353 | case WM_UPDATEFRAME:
|
---|
2354 | dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
|
---|
2355 | goto RunDefFrameWndProc;
|
---|
2356 | #endif
|
---|
2357 |
|
---|
2358 | case WM_TRACKFRAME:
|
---|
2359 | dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
2360 | if(fOS2Look) {//sent by titlebar control
|
---|
2361 | Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
|
---|
2362 | }
|
---|
2363 | rc = 0;
|
---|
2364 | break;
|
---|
2365 |
|
---|
2366 | case WM_SYSCOMMAND:
|
---|
2367 | dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
|
---|
2368 | if (fOS2Look == OS2_APPEARANCE_SYSMENU && mp1 == (MPARAM)OSSC_SYSMENU)
|
---|
2369 | goto RunDefFrameWndProc;
|
---|
2370 |
|
---|
2371 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
|
---|
2372 | RELEASE_WNDOBJ(win32wnd);
|
---|
2373 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
|
---|
2374 | }
|
---|
2375 | if(win32wnd)
|
---|
2376 | win32wnd->DispatchMsgA(pWinMsg);
|
---|
2377 | break;
|
---|
2378 |
|
---|
2379 | case WM_IMEREQUEST:
|
---|
2380 | case WM_IMECONTROL:
|
---|
2381 | case WM_IMENOTIFY:
|
---|
2382 | if( pWinMsg->message )
|
---|
2383 | {
|
---|
2384 | dprintf(("Frame window received IME message"));
|
---|
2385 | win32wnd->DispatchMsgA( pWinMsg );
|
---|
2386 |
|
---|
2387 | if(( pWinMsg->message = WM_IME_NOTIFY_W ) &&
|
---|
2388 | ( pWinMsg->wParam == IMN_SETOPENSTATUS_W ))
|
---|
2389 | {
|
---|
2390 | MSG m;
|
---|
2391 |
|
---|
2392 | m.message = WM_IME_NOTIFY_W;
|
---|
2393 | m.wParam = IMN_SETCONVERSIONMODE_W;
|
---|
2394 | m.lParam = 0;
|
---|
2395 |
|
---|
2396 | win32wnd->DispatchMsgA( &m );
|
---|
2397 | }
|
---|
2398 | }
|
---|
2399 | else
|
---|
2400 | goto RunDefWndProc;
|
---|
2401 | break;
|
---|
2402 |
|
---|
2403 | #ifdef DEBUG
|
---|
2404 | case WM_DDE_INITIATE:
|
---|
2405 | case WM_DDE_INITIATEACK:
|
---|
2406 | case WM_DDE_REQUEST:
|
---|
2407 | case WM_DDE_ACK:
|
---|
2408 | case WM_DDE_DATA:
|
---|
2409 | case WM_DDE_ADVISE:
|
---|
2410 | case WM_DDE_UNADVISE:
|
---|
2411 | case WM_DDE_POKE:
|
---|
2412 | case WM_DDE_EXECUTE:
|
---|
2413 | case WM_DDE_TERMINATE:
|
---|
2414 | dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
|
---|
2415 | break;
|
---|
2416 | #endif
|
---|
2417 |
|
---|
2418 | default:
|
---|
2419 | goto RunDefFrameWndProc;
|
---|
2420 | }
|
---|
2421 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
2422 | RestoreOS2TIB();
|
---|
2423 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
2424 |
|
---|
2425 | #ifdef DEBUG
|
---|
2426 | dbg_ThreadPopCall();
|
---|
2427 | #endif
|
---|
2428 | return (MRESULT)rc;
|
---|
2429 |
|
---|
2430 | RunDefFrameWndProc:
|
---|
2431 | dprintf2(("RunDefFrameWndProc"));
|
---|
2432 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
2433 | RestoreOS2TIB();
|
---|
2434 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
2435 |
|
---|
2436 | #ifdef DEBUG
|
---|
2437 | dbg_ThreadPopCall();
|
---|
2438 | #endif
|
---|
2439 | return pfnFrameWndProc(hwnd, msg, mp1, mp2);
|
---|
2440 |
|
---|
2441 | RunDefWndProc:
|
---|
2442 | dprintf2(("RunDefWndProc"));
|
---|
2443 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
2444 | RestoreOS2TIB();
|
---|
2445 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
2446 |
|
---|
2447 | //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
|
---|
2448 | // return pfnFrameWndProc(hwnd, msg, mp1, mp2);
|
---|
2449 |
|
---|
2450 | #ifdef DEBUG
|
---|
2451 | dbg_ThreadPopCall();
|
---|
2452 | #endif
|
---|
2453 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
2454 | }
|
---|
2455 | //******************************************************************************
|
---|
2456 | //******************************************************************************
|
---|
2457 | MRESULT EXPENTRY Win32FakeWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
2458 | {
|
---|
2459 | PFNWP pfnOldWindowProc;
|
---|
2460 | Win32BaseWindow *win32wnd, *win32wndchild;
|
---|
2461 | TEB *teb;
|
---|
2462 | MRESULT rc = 0;
|
---|
2463 | EXCEPTIONREGISTRATIONRECORD exceptRegRec = {0,0};
|
---|
2464 |
|
---|
2465 | //Restore our FS selector
|
---|
2466 | SetWin32TIB();
|
---|
2467 |
|
---|
2468 | win32wnd = Win32FakeWindow::GetWindowFromOS2Handle(hwnd);
|
---|
2469 | if(win32wnd == NULL) {
|
---|
2470 | DebugInt3();
|
---|
2471 | goto RunDefWndProc;
|
---|
2472 | }
|
---|
2473 |
|
---|
2474 | pfnOldWindowProc = (PFNWP)win32wnd->getOldPMWindowProc();
|
---|
2475 | if(pfnOldWindowProc == NULL) {
|
---|
2476 | DebugInt3();
|
---|
2477 | goto RunDefWndProc;
|
---|
2478 | }
|
---|
2479 |
|
---|
2480 | RestoreOS2TIB();
|
---|
2481 | rc = pfnOldWindowProc(hwnd, msg, mp1, mp2);
|
---|
2482 |
|
---|
2483 | ODIN_SetExceptionHandler(&exceptRegRec);
|
---|
2484 | SetWin32TIB();
|
---|
2485 | switch(msg) {
|
---|
2486 | case WM_WINDOWPOSCHANGED:
|
---|
2487 | {
|
---|
2488 | PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
|
---|
2489 | SWP swpOld = *(pswp + 1);
|
---|
2490 | WINDOWPOS wp;
|
---|
2491 |
|
---|
2492 | if(win32wnd->getParent()) {
|
---|
2493 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
---|
2494 | hwnd);
|
---|
2495 | }
|
---|
2496 | else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
|
---|
2497 |
|
---|
2498 | win32wnd->SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
|
---|
2499 | break;
|
---|
2500 | }
|
---|
2501 |
|
---|
2502 | }
|
---|
2503 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
2504 | RestoreOS2TIB();
|
---|
2505 | ODIN_UnsetExceptionHandler(&exceptRegRec);
|
---|
2506 | return rc;
|
---|
2507 |
|
---|
2508 | RunDefWndProc:
|
---|
2509 | RestoreOS2TIB();
|
---|
2510 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
2511 | }
|
---|
2512 | //******************************************************************************
|
---|
2513 | // PMWinSubclassFakeWindow
|
---|
2514 | //
|
---|
2515 | // Subclass a fake window (converted PM window)
|
---|
2516 | //
|
---|
2517 | // Parameters
|
---|
2518 | //
|
---|
2519 | // HWND hwndOS2 - PM handle of fake window
|
---|
2520 | //
|
---|
2521 | // Returns
|
---|
2522 | // NULL - Failure
|
---|
2523 | // else - Old PM window procedure
|
---|
2524 | //
|
---|
2525 | //******************************************************************************
|
---|
2526 | PVOID PMWinSubclassFakeWindow(HWND hwndOS2)
|
---|
2527 | {
|
---|
2528 | return WinSubclassWindow(hwndOS2, Win32FakeWindowProc);
|
---|
2529 | }
|
---|
2530 | //******************************************************************************
|
---|
2531 | //******************************************************************************
|
---|
2532 | void FrameSetFocus(HWND hwnd)
|
---|
2533 | {
|
---|
2534 | HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
|
---|
2535 | if(!WinIsWindow(hab, hwndFocusSave)) {
|
---|
2536 | hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
|
---|
2537 | WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
|
---|
2538 | }
|
---|
2539 | dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
|
---|
2540 | dprintf(("FrameSetFocus: cur focus=%x (%x) cur active=%x (%x)\n",
|
---|
2541 | WinQueryFocus(HWND_DESKTOP), OS2ToWin32Handle(WinQueryFocus(HWND_DESKTOP)),
|
---|
2542 | WinQueryActiveWindow(HWND_DESKTOP), OS2ToWin32Handle(WinQueryActiveWindow(HWND_DESKTOP))));
|
---|
2543 | WinSetFocus(HWND_DESKTOP, hwndFocusSave);
|
---|
2544 |
|
---|
2545 | ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
|
---|
2546 | ulFrameFlags &= ~FF_NOACTIVATESWP;
|
---|
2547 | WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
|
---|
2548 | }
|
---|
2549 | //******************************************************************************
|
---|
2550 | //******************************************************************************
|
---|
2551 | void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
|
---|
2552 | HBITMAP hbmNew)
|
---|
2553 | {
|
---|
2554 | MENUITEM mi;
|
---|
2555 |
|
---|
2556 | if (!hwndMenu)
|
---|
2557 | return;
|
---|
2558 |
|
---|
2559 | WinEnableWindowUpdate(hwndMenu, FALSE);
|
---|
2560 |
|
---|
2561 | if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
|
---|
2562 | {
|
---|
2563 | WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
|
---|
2564 | mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
|
---|
2565 | mi.afAttribute = 0;
|
---|
2566 | mi.hwndSubMenu = 0;
|
---|
2567 | mi.id = idNew;
|
---|
2568 | mi.hItem = (ULONG)hbmNew;
|
---|
2569 | WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
|
---|
2570 | }
|
---|
2571 | else
|
---|
2572 | dprintf(("WARNING: FrameReplaceMenuItem control %x not found",idOld));
|
---|
2573 |
|
---|
2574 | WinEnableWindowUpdate(hwndMenu, TRUE);
|
---|
2575 |
|
---|
2576 | WinInvalidateRect(hwndMenu, NULL, TRUE);
|
---|
2577 | }
|
---|
2578 | //******************************************************************************
|
---|
2579 | //******************************************************************************
|
---|
2580 | void RecalcVisibleRegion(Win32BaseWindow *win32wnd)
|
---|
2581 | {
|
---|
2582 | //Workaround for PM/GPI bug when moving/sizing a window with open DCs
|
---|
2583 | //
|
---|
2584 | //Windows applictions often get a DC and keep it open for the duration
|
---|
2585 | //of the application. When the DC's window is moved (full window dragging on)
|
---|
2586 | //PM/GPI doesn't seem to update the DC properly/in time.
|
---|
2587 | //This can result is visible distortions on the screen.
|
---|
2588 |
|
---|
2589 | //We need to reset our DC (transformation & y-inversion) (#945)
|
---|
2590 | //Debugging showed that querying the visible region of a DC will cure
|
---|
2591 | //this problem (GPI probably recalculates the visible region). (#334)
|
---|
2592 |
|
---|
2593 | int nrdcs = 0;
|
---|
2594 | HDC hdcWindow[MAX_OPENDCS];
|
---|
2595 |
|
---|
2596 | if(win32wnd->queryOpenDCs(hdcWindow, MAX_OPENDCS, &nrdcs))
|
---|
2597 | {
|
---|
2598 | for(int i=0;i<nrdcs;i++)
|
---|
2599 | {
|
---|
2600 | dprintf(("Recalc visible region of DC %x for window %x", hdcWindow[i], win32wnd->getWindowHandle()));
|
---|
2601 |
|
---|
2602 | pDCData pHps = (pDCData)GpiQueryDCData (hdcWindow[i]);
|
---|
2603 |
|
---|
2604 | if(pHps) setPageXForm (win32wnd, pHps);
|
---|
2605 | else DebugInt3();
|
---|
2606 | }
|
---|
2607 | }
|
---|
2608 | //Workaround END
|
---|
2609 | }
|
---|
2610 | //******************************************************************************
|
---|
2611 | //******************************************************************************
|
---|
2612 | static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
|
---|
2613 | {
|
---|
2614 | PDRAGITEM pDragItem;
|
---|
2615 | int i, cItems;
|
---|
2616 | BOOL ret;
|
---|
2617 | char szFileName[CCHMAXPATH];
|
---|
2618 | char szContainerName[CCHMAXPATH];
|
---|
2619 | ULONG ulBytes;
|
---|
2620 | char *pszCurFile = NULL;
|
---|
2621 |
|
---|
2622 | cItems = DrgQueryDragitemCount(pDragInfo);
|
---|
2623 |
|
---|
2624 | //compute memory required to hold all filenames
|
---|
2625 | int bufsize = 0;
|
---|
2626 | for (i = 0; i < cItems; i++) {
|
---|
2627 | pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
|
---|
2628 |
|
---|
2629 | bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
|
---|
2630 | bufsize++; //0 terminator
|
---|
2631 | bufsize++; //+ potential missing backslash
|
---|
2632 | }
|
---|
2633 | bufsize++; //extra 0 terminator
|
---|
2634 | char *pszFiles = (char *)malloc(bufsize);
|
---|
2635 | if(pszFiles == NULL) {
|
---|
2636 | dprintf(("Out of memory!!"));
|
---|
2637 | DebugInt3();
|
---|
2638 | goto failure;
|
---|
2639 | }
|
---|
2640 | memset(pszFiles, 0, bufsize);
|
---|
2641 |
|
---|
2642 | pszCurFile = pszFiles;
|
---|
2643 |
|
---|
2644 | //copy all filenames
|
---|
2645 | for (i = 0; i < cItems; i++) {
|
---|
2646 | char *pszTemp = pszCurFile;
|
---|
2647 |
|
---|
2648 | pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
|
---|
2649 |
|
---|
2650 | ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
|
---|
2651 | ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
|
---|
2652 | ulBytes, pszCurFile);
|
---|
2653 | if(pszCurFile[ulBytes-1] != '\\') {
|
---|
2654 | pszCurFile[ulBytes] = '\\';
|
---|
2655 | pszCurFile++;
|
---|
2656 | }
|
---|
2657 | pszCurFile += ulBytes;
|
---|
2658 |
|
---|
2659 | ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
|
---|
2660 | ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
|
---|
2661 | ulBytes+1, pszCurFile);
|
---|
2662 | pszCurFile += ulBytes + 1; //+ terminator
|
---|
2663 |
|
---|
2664 | dprintf(("dropped file %s", pszTemp));
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | *pulBytes = bufsize;
|
---|
2668 | *pcItems = cItems;
|
---|
2669 |
|
---|
2670 | return pszFiles;
|
---|
2671 |
|
---|
2672 | failure:
|
---|
2673 | if(pszFiles) {
|
---|
2674 | free(pszFiles);
|
---|
2675 | }
|
---|
2676 | return NULL;
|
---|
2677 | }
|
---|
2678 | //******************************************************************************
|
---|
2679 | //******************************************************************************
|
---|
2680 | static BOOL PMDragValidate(PDRAGINFO pDragInfo)
|
---|
2681 | {
|
---|
2682 | PDRAGITEM pDragItem;
|
---|
2683 | ULONG ulBytes;
|
---|
2684 | int i, cItems;
|
---|
2685 | BOOL ret;
|
---|
2686 | char szFileName[CCHMAXPATH];
|
---|
2687 | char szContainerName[CCHMAXPATH];
|
---|
2688 | USHORT usOp = DO_MOVE;
|
---|
2689 |
|
---|
2690 | /* Get access to the DRAGINFO data structure */
|
---|
2691 |
|
---|
2692 | /* Can we accept this drop? */
|
---|
2693 | switch (pDragInfo->usOperation) {
|
---|
2694 | /* Return DOR_NODROPOP if current operation */
|
---|
2695 | /* is link or unknown */
|
---|
2696 | case DO_LINK:
|
---|
2697 | case DO_COPY:
|
---|
2698 | case DO_UNKNOWN:
|
---|
2699 | goto failure;
|
---|
2700 |
|
---|
2701 | /* Our default operation is Move */
|
---|
2702 | case DO_MOVE:
|
---|
2703 | case DO_DEFAULT:
|
---|
2704 | pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
|
---|
2705 | ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
|
---|
2706 | sizeof(szContainerName),
|
---|
2707 | szContainerName);
|
---|
2708 | ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
|
---|
2709 | sizeof(szFileName),
|
---|
2710 | szFileName);
|
---|
2711 | if (!ulBytes) {
|
---|
2712 | goto failure;
|
---|
2713 | }
|
---|
2714 |
|
---|
2715 | dprintf(("dropped file %s%s", szContainerName, szFileName));
|
---|
2716 | break;
|
---|
2717 | }
|
---|
2718 |
|
---|
2719 | cItems = DrgQueryDragitemCount(pDragInfo);
|
---|
2720 |
|
---|
2721 | /* Now, we need to look at each item in turn */
|
---|
2722 | for (i = 0; i < cItems; i++) {
|
---|
2723 | pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
|
---|
2724 |
|
---|
2725 | /* Make sure we can move for a Move request */
|
---|
2726 | if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
|
---|
2727 | (usOp == (USHORT)DO_MOVE)))
|
---|
2728 | {
|
---|
2729 | dprintf(("item %d not accepted", i));
|
---|
2730 | goto failure;
|
---|
2731 | }
|
---|
2732 | }
|
---|
2733 | /* Release the draginfo data structure */
|
---|
2734 | return TRUE;
|
---|
2735 |
|
---|
2736 | failure:
|
---|
2737 | return FALSE;
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | //******************************************************************************
|
---|
2741 | // Override std class names we use in Odin (necessary for keyboard hook)
|
---|
2742 | //******************************************************************************
|
---|
2743 | void WIN32API SetCustomStdClassName(LPSTR pszStdClassName)
|
---|
2744 | {
|
---|
2745 | strcpy(WIN32_STDCLASS, pszStdClassName);
|
---|
2746 | }
|
---|
2747 | //******************************************************************************
|
---|
2748 | //******************************************************************************
|
---|
2749 | char *WIN32API QueryCustomStdClassName()
|
---|
2750 | {
|
---|
2751 | return WIN32_STDCLASS;
|
---|
2752 | }
|
---|
2753 | //******************************************************************************
|
---|
2754 | //******************************************************************************
|
---|
2755 |
|
---|
2756 | #ifdef DEBUG_LOGGING
|
---|
2757 | static char *DbgGetStringSWPFlags(ULONG flags)
|
---|
2758 | {
|
---|
2759 | static char szSWPFlags[512];
|
---|
2760 |
|
---|
2761 | szSWPFlags[0] = 0;
|
---|
2762 |
|
---|
2763 | if(flags & SWP_SIZE) {
|
---|
2764 | strcat(szSWPFlags, "SWP_SIZE ");
|
---|
2765 | }
|
---|
2766 | if(flags & SWP_MOVE) {
|
---|
2767 | strcat(szSWPFlags, "SWP_MOVE ");
|
---|
2768 | }
|
---|
2769 | if(flags & SWP_ZORDER) {
|
---|
2770 | strcat(szSWPFlags, "SWP_ZORDER ");
|
---|
2771 | }
|
---|
2772 | if(flags & SWP_SHOW) {
|
---|
2773 | strcat(szSWPFlags, "SWP_SHOW ");
|
---|
2774 | }
|
---|
2775 | if(flags & SWP_HIDE) {
|
---|
2776 | strcat(szSWPFlags, "SWP_HIDE ");
|
---|
2777 | }
|
---|
2778 | if(flags & SWP_NOREDRAW) {
|
---|
2779 | strcat(szSWPFlags, "SWP_NOREDRAW ");
|
---|
2780 | }
|
---|
2781 | if(flags & SWP_NOADJUST) {
|
---|
2782 | strcat(szSWPFlags, "SWP_NOADJUST ");
|
---|
2783 | }
|
---|
2784 | if(flags & SWP_ACTIVATE) {
|
---|
2785 | strcat(szSWPFlags, "SWP_ACTIVATE ");
|
---|
2786 | }
|
---|
2787 | if(flags & SWP_DEACTIVATE) {
|
---|
2788 | strcat(szSWPFlags, "SWP_DEACTIVATE ");
|
---|
2789 | }
|
---|
2790 | if(flags & SWP_EXTSTATECHANGE) {
|
---|
2791 | strcat(szSWPFlags, "SWP_EXTSTATECHANGE ");
|
---|
2792 | }
|
---|
2793 | if(flags & SWP_MINIMIZE) {
|
---|
2794 | strcat(szSWPFlags, "SWP_MINIMIZE ");
|
---|
2795 | }
|
---|
2796 | if(flags & SWP_MAXIMIZE) {
|
---|
2797 | strcat(szSWPFlags, "SWP_MAXIMIZE ");
|
---|
2798 | }
|
---|
2799 | if(flags & SWP_RESTORE) {
|
---|
2800 | strcat(szSWPFlags, "SWP_RESTORE ");
|
---|
2801 | }
|
---|
2802 | if(flags & SWP_FOCUSACTIVATE) {
|
---|
2803 | strcat(szSWPFlags, "SWP_FOCUSACTIVATE ");
|
---|
2804 | }
|
---|
2805 | if(flags & SWP_FOCUSDEACTIVATE) {
|
---|
2806 | strcat(szSWPFlags, "SWP_FOCUSDEACTIVATE ");
|
---|
2807 | }
|
---|
2808 | if(flags & SWP_NOAUTOCLOSE) {
|
---|
2809 | strcat(szSWPFlags, "SWP_NOAUTOCLOSE ");
|
---|
2810 | }
|
---|
2811 | return szSWPFlags;
|
---|
2812 | }
|
---|
2813 | static char *DbgPrintQFCFlags(ULONG flags)
|
---|
2814 | {
|
---|
2815 | static char szQFCFlags[64];
|
---|
2816 |
|
---|
2817 | szQFCFlags[0] = 0;
|
---|
2818 |
|
---|
2819 | if(flags & QFC_NEXTINCHAIN) {
|
---|
2820 | strcat(szQFCFlags, "QFC_NEXTINCHAIN");
|
---|
2821 | }
|
---|
2822 | else
|
---|
2823 | if(flags & QFC_ACTIVE) {
|
---|
2824 | strcat(szQFCFlags, "QFC_ACTIVE");
|
---|
2825 | }
|
---|
2826 | else
|
---|
2827 | if(flags & QFC_FRAME) {
|
---|
2828 | strcat(szQFCFlags, "QFC_FRAME");
|
---|
2829 | }
|
---|
2830 | else
|
---|
2831 | if(flags & QFC_SELECTACTIVE) {
|
---|
2832 | strcat(szQFCFlags, "QFC_SELECTACTIVE");
|
---|
2833 | }
|
---|
2834 | else
|
---|
2835 | if(flags & QFC_PARTOFCHAIN) {
|
---|
2836 | strcat(szQFCFlags, "QFC_PARTOFCHAIN");
|
---|
2837 | }
|
---|
2838 |
|
---|
2839 | return szQFCFlags;
|
---|
2840 | }
|
---|
2841 | #endif
|
---|
2842 |
|
---|