source: trunk/src/user32/win32wbase.h@ 2391

Last change on this file since 2391 was 2391, checked in by sandervl, 26 years ago

System menu commands now work

File size: 17.7 KB
Line 
1/* $Id: win32wbase.h,v 1.70 2000-01-09 17:57:49 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#ifndef __WIN32WNDBASE_H__
14#define __WIN32WNDBASE_H__
15
16#ifdef __cplusplus
17
18#include <win32class.h>
19#include "open32wbase.h"
20#include <gen_object.h>
21#include <win32wndchild.h>
22#include <winres.h>
23#include <winconst.h>
24#include <scroll.h>
25
26class Win32BaseWindow;
27
28#define OFFSET_WIN32WNDPTR 0
29#define OFFSET_WIN32PM_MAGIC 4
30#define NROF_WIN32WNDBYTES 8
31
32#define WIN32PM_MAGIC 0x12345678
33#define CheckMagicDword(a) (a==WIN32PM_MAGIC)
34
35typedef struct {
36 USHORT cb;
37 Win32BaseWindow *win32wnd;
38 ULONG win32CreateStruct; //or dialog create dword
39} CUSTOMWNDDATA;
40
41//PostThreadMessage is done through Open32; which means the message id will be translated
42//(0xc00 added)
43#define OPEN32_MSGDIFF 0xC00
44#define WIN32APP_POSTMSG (0x1000+OPEN32_MSGDIFF)
45
46#define WIN32MSG_MAGICA 0x12345678
47#define WIN32MSG_MAGICW 0x12345679
48
49typedef struct
50{
51 ULONG Msg;
52 ULONG wParam;
53 ULONG lParam;
54} POSTMSG_PACKET;
55
56#define BROADCAST_SEND 0
57#define BROADCAST_POST 1
58
59class Win32BaseWindow : public GenericObject, public ChildWindow
60{
61public:
62 DWORD magic;
63
64 Win32BaseWindow(DWORD objType);
65 Win32BaseWindow(HWND os2Handle,VOID* win32WndProc);
66 Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
67virtual ~Win32BaseWindow();
68
69virtual ULONG MsgCreate(HWND hwndFrame, HWND hwndClient);
70 ULONG MsgQuit();
71 ULONG MsgClose();
72 ULONG MsgDestroy();
73virtual ULONG MsgEnable(BOOL fEnable);
74 ULONG MsgShow(BOOL fShow);
75 ULONG MsgPosChanging(LPARAM lp);
76 ULONG MsgPosChanged(LPARAM lp);
77virtual ULONG MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd);
78 ULONG MsgSetFocus(HWND hwnd);
79 ULONG MsgKillFocus(HWND hwnd);
80 ULONG MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos);
81 ULONG MsgButton(MSG *msg);
82 ULONG MsgMouseMove(MSG *msg);
83 ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
84 ULONG MsgEraseBackGround(HDC hdc);
85 ULONG MsgInitMenu(MSG *msg);
86 ULONG MsgHitTest(ULONG x, ULONG y);
87 ULONG MsgNCPaint();
88 ULONG DispatchMsgA(MSG *msg);
89 ULONG DispatchMsgW(MSG *msg);
90
91 ULONG MsgSetText(LPSTR lpsz, LONG cch);
92 ULONG MsgGetTextLength();
93 char *MsgGetText();
94 ULONG MsgContextMenu(ULONG x,ULONG y);
95 VOID updateWindowStyle(DWORD oldExStyle,DWORD oldStyle);
96
97virtual LONG SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
98virtual ULONG GetWindowLongA(int index, BOOL fUnicode = FALSE);
99virtual WORD SetWindowWord(int index, WORD value);
100virtual WORD GetWindowWord(int index);
101
102 DWORD getStyle() { return dwStyle; };
103 void setStyle(DWORD newstyle) { dwStyle = newstyle; };
104 DWORD getExStyle() { return dwExStyle; };
105 void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
106 ULONG getInstance() { return hInstance; };
107 void setInstance(ULONG newinstance) { hInstance = newinstance; };
108 HWND getWindowHandle() { return Win32Hwnd; };
109 HWND getOS2WindowHandle() { return OS2Hwnd; };
110 HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
111 Win32WndClass *getWindowClass() { return windowClass; };
112
113 BOOL getDefWndProcCalled() { return fDefWndProcCalled; };
114 void clearDefWndProcCalled() { fDefWndProcCalled = 0; };
115
116 DWORD getWindowContextHelpId() { return contextHelpId; };
117 void setWindowContextHelpId(DWORD id){ contextHelpId = id; };
118
119 BOOL isFrameWindow();
120virtual BOOL isMDIClient();
121virtual BOOL isMDIChild();
122
123 BOOL fHasParentDC() { return fParentDC; };
124
125Win32BaseWindow *getParent();
126 void setParent(Win32BaseWindow *pwindow) { ChildWindow::SetParent((ChildWindow *)pwindow); };
127 WNDPROC getWindowProc() { return win32wndproc; };
128 void setWindowProc(WNDPROC newproc) { win32wndproc = newproc; };
129 DWORD getWindowId() { return windowId; };
130 void setWindowId(DWORD id);
131 ULONG getWindowHeight() { return rectWindow.bottom - rectWindow.top; };
132 ULONG getWindowWidth() { return rectWindow.right - rectWindow.left; };
133 ULONG getClientHeight() { return rectClient.bottom - rectClient.top; };
134 ULONG getClientWidth() { return rectClient.right - rectClient.left; };
135 BOOL isChild();
136 PRECT getClientRect() { return &rectClient; };
137 void setClientRect(PRECT rect) { rectClient = *rect; };
138 void setClientRect(LONG left, LONG top, LONG right, LONG bottom)
139 {
140 rectClient.left = left; rectClient.top = top;
141 rectClient.right = right; rectClient.bottom = bottom;
142 };
143 PRECT getWindowRect();
144 void setWindowRect(LONG left, LONG top, LONG right, LONG bottom);
145 void setWindowRect(PRECT rect);
146 void setWindowRectChanged();
147
148 DWORD getFlags() { return flags; };
149 void setFlags(DWORD newflags) { flags = newflags; };
150
151 HMENU GetMenu() { return (HMENU) OS2HwndMenu; };
152 BOOL SetMenu(ULONG hMenu);
153 HMENU GetSystemMenu(BOOL fRevert);
154 HMENU getSystemMenu();
155
156 BOOL SetIcon(HICON hIcon);
157 HICON GetIcon() { return (HICON) iconResource; };
158
159 void SetWindowRegion(HRGN hRegion) { hWindowRegion = hRegion; };
160 HRGN GetWindowRegion() { return hWindowRegion; };
161
162 BOOL ShowWindow(ULONG nCmdShow);
163 BOOL SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
164 BOOL SetWindowPlacement(WINDOWPLACEMENT *winpos);
165 BOOL DestroyWindow();
166 HWND SetActiveWindow();
167 HWND GetParent();
168 HWND SetParent(HWND hwndNewParent);
169 BOOL IsChild(HWND hwndParent);
170 HWND GetTopWindow();
171Win32BaseWindow *GetTopParent();
172 BOOL UpdateWindow();
173 BOOL IsIconic();
174 HWND GetWindow(UINT uCmd);
175 virtual BOOL EnableWindow(BOOL fEnable);
176 BOOL CloseWindow();
177 static HWND GetActiveWindow();
178 //Window handle has already been verified, so just return true
179 BOOL IsWindow() { return TRUE; };
180 BOOL IsDialog() { return fIsDialog; };
181 BOOL IsModalDialog() { return fIsModalDialog; };
182 BOOL IsModalDialogOwner() { return fIsModalDialogOwner; };
183 VOID setModalDialogOwner(BOOL fMDO) { fIsModalDialogOwner = fMDO; };
184 VOID setOS2HwndModalDialog(HWND aHwnd) { OS2HwndModalDialog = aHwnd; };
185 HWND getOS2HwndModalDialog() { return OS2HwndModalDialog; };
186 BOOL CanReceiveSizeMsgs() { return !fNoSizeMsg; };
187 BOOL IsWindowDestroyed() { return fIsDestroyed; };
188 BOOL IsWindowEnabled();
189 BOOL IsWindowVisible();
190 //Created with CreateWindowExA or ExW
191// BOOL IsUnicode() { return isUnicode; };
192 //Window procedure type
193 BOOL IsWindowUnicode();
194
195 int GetWindowTextLength();
196 int GetWindowTextA(LPSTR lpsz, int cch);
197 int GetWindowTextW(LPWSTR lpsz, int cch);
198 BOOL SetWindowTextA(LPSTR lpsz);
199 BOOL SetWindowTextW(LPWSTR lpsz);
200 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
201 CHAR *getWindowNamePtrA();
202 WCHAR *getWindowNamePtrW();
203 VOID freeWindowNamePtr(PVOID namePtr);
204 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
205 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
206Win32WndClass *getClass() { return windowClass; };
207Win32BaseWindow *getOwner() { return owner; };
208 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
209
210 SCROLLBAR_INFO *getScrollInfo(int nBar);
211 HWND getVertScrollHandle() { return hwndVertScroll; };
212 VOID setVertScrollHandle(HWND newHandle) { hwndVertScroll = newHandle; }
213 HWND getHorzScrollHandle() { return hwndHorzScroll; };
214 VOID setHorzScrollHandle(HWND newHandle) { hwndHorzScroll = newHandle; }
215 VOID subclassScrollBars(BOOL subHorz,BOOL subVert);
216 BOOL showScrollBars(BOOL changeHorz,BOOL changeVert,BOOL fShow);
217
218 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
219 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
220static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
221static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
222 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
223
224 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
225 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
226
227 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
228 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
229
230 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
231
232Win32BaseWindow *FindWindowById(int id);
233
234 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
235 BOOL fUnicode = 0);
236
237 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
238 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
239 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
240
241 HWND getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious);
242 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
243
244 static HWND Win32ToOS2Handle(HWND hwnd);
245 static HWND Win32ToOS2FrameHandle(HWND hwnd);
246 static HWND OS2ToWin32Handle(HWND hwnd);
247
248static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
249static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
250static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
251
252 static void DestroyAll();
253
254 PVOID getOldFrameProc() { return pOldFrameProc; };
255 VOID setOldFrameProc(PVOID aOldFrameProc) { pOldFrameProc = aOldFrameProc; };
256 PVOID getOldTitleBarProc() { return pOldTitleBarProc; };
257 VOID setOldTitleBarProc(PVOID aOldTitleBarProc) { pOldTitleBarProc = aOldTitleBarProc; };
258 PVOID getOldMenuProc() { return pOldMenuProc; };
259 VOID setOldMenuProc(PVOID aOldMenuProc) { pOldMenuProc = aOldMenuProc; };
260 ULONG getBorderWidth() { return borderWidth; };
261 ULONG getBorderHeight() { return borderHeight; };
262
263static void NC_AdjustRectInner(LPRECT rect, DWORD style, DWORD exStyle);
264static void NC_AdjustRectOuter(LPRECT rect, DWORD style, BOOL menu, DWORD exStyle);
265static BOOL WindowNeedsWMBorder( DWORD style, DWORD exStyle );
266
267 PVOID getOldWndProc() { return pOldWndProc; }
268 VOID setOldWndProc(PVOID aOldWndProc) { pOldWndProc = aOldWndProc; }
269 BOOL isSubclassedOS2Wnd() { return fIsSubclassedOS2Wnd; };
270
271protected:
272#ifndef OS2_INCLUDED
273 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
274#endif
275 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
276 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
277 void Init();
278 void setExtendedKey(ULONG virtualkey, ULONG *lParam);
279
280 HWND OS2Hwnd;
281 HWND OS2HwndFrame;
282 HWND OS2HwndMenu;
283 HMENU OS2SysMenu;
284 HWND Win32Hwnd;
285 BOOL isUnicode;
286
287 int posx, posy, width, height;
288
289 // values normally contained in the standard window words
290 ULONG dwExStyle; //GWL_EXSTYLE
291 ULONG dwStyle; //GWL_STYLE
292 WNDPROC win32wndproc; //GWL_WNDPROC
293 ULONG hInstance; //GWL_HINSTANCE
294//Moved in ChildWindow class
295///// Win32BaseWindow *parent; //GWL_HWNDPARENT
296 ULONG windowId; //GWL_ID
297 ULONG userData; //GWL_USERDATA
298
299 HWND hwndLinkAfter;
300 DWORD flags;
301 DWORD contextHelpId;
302 LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
303
304 HWND OS2HwndModalDialog;
305
306 ULONG isIcon :1,
307 fFirstShow :1,
308 fIsDialog :1,
309 fIsModalDialog :1,
310 fIsModalDialogOwner :1,
311 fInternalMsg :1, //Used to distinguish between messages
312 //sent by PM and those sent by apps
313 fNoSizeMsg :1,
314 fIsDestroyed :1,
315 fDestroyWindowCalled :1, //DestroyWindow was called for this window
316 fCreated :1,
317 fTaskList :1, //should be listed in PM tasklist or not
318 fParentDC :1,
319 fIsSubclassedOS2Wnd :1, //subclassed OS/2 window: Netscape plug-in/scrollbar
320 fDefWndProcCalled :1, //set when DefWndProc called; used in PM window handlers to determine what to do next
321 fWindowRectChanged :1; //Set when parent window has been moved; cleared when window rect is updated
322
323 HRGN hWindowRegion;
324
325 DWORD dwThreadId; //id of thread that created this window
326 DWORD dwProcessId; //id of process that created this window
327 PVOID pOldFrameProc;
328 PVOID pOldTitleBarProc;
329 PVOID pOldMenuProc;
330 ULONG borderWidth;
331 ULONG borderHeight;
332
333 PVOID pOldWndProc;
334
335 Win32BaseWindow *owner;
336 Win32Resource *iconResource;
337
338 char *windowNameA;
339 WCHAR *windowNameW;
340 ULONG wndNameLength; //including 0 terminator
341
342 ULONG *userWindowLong;
343 ULONG nrUserWindowLong;
344
345 RECT rectWindow;
346 RECT rectClient;
347
348CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
349 ULONG sw; //set in CreateWindowExA, used in MsgCreate method
350
351SCROLLBAR_INFO *vertScrollInfo;
352SCROLLBAR_INFO *horzScrollInfo;
353 HWND hwndHorzScroll; //os/2 handle
354 HWND hwndVertScroll; //os/2 handle
355
356Win32WndClass *windowClass;
357
358static GenericObject *windows;
359
360private:
361#ifndef OS2_INCLUDED
362 void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
363 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
364 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
365
366 LONG SendNCCalcSize(BOOL calcValidRect,
367 RECT *newWindowRect, RECT *oldWindowRect,
368 RECT *oldClientRect, WINDOWPOS *winpos,
369 RECT *newClientRect );
370
371 LONG NCHandleCalcSize(WPARAM wParam, NCCALCSIZE_PARAMS *ncsize);
372
373 LRESULT SendInternalMessage(ULONG msg, WPARAM wParam, LPARAM lParam)
374 {
375 if(isUnicode)
376 return SendInternalMessageW(msg, wParam, lParam);
377 else return SendInternalMessageA(msg, wParam, lParam);
378 }
379#else
380friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
381#endif
382
383 //painting & non-client methods
384 BOOL DrawSysButton(HDC hdc,BOOL down);
385 BOOL DrawGrayButton(HDC hdc,int x,int y);
386 VOID DrawCloseButton(HDC hdc,BOOL down,BOOL bGrayed);
387 VOID DrawMaxButton(HDC hdc,BOOL down,BOOL bGrayed);
388 VOID DrawMinButton(HDC hdc,BOOL down,BOOL bGrayed);
389 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
390 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
391
392 VOID GetInsideRect(RECT *rect);
393
394 VOID TrackMinMaxBox(WORD wParam);
395 VOID TrackCloseButton(WORD wParam);
396
397 VOID HandleNCPaint(HRGN clip,BOOL suppress_menupaint);
398 LONG HandleNCHitTest(POINT pt);
399 LONG HandleNCActivate(WPARAM wParam);
400 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
401 LONG HandleNCLButtonUp(WPARAM wParam,LPARAM lParam);
402 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
403
404public:
405 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
406 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
407
408 fakeOpen32WinBaseClass fakeWinBase;
409
410 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC_W); }
411 HDC getOwnDC() { return ownDC; }
412 void setOwnDC(HDC hdc) { ownDC = hdc; }
413protected:
414 HDC ownDC;
415
416 ULONG EraseBkgndFlag:1,
417 PSEraseFlag:1,
418 SuppressEraseFlag:1,
419 filler:29;
420public:
421 VOID setEraseBkgnd (BOOL erase, BOOL PSErase = FALSE)
422 { EraseBkgndFlag = erase; PSEraseFlag = PSErase; }
423 VOID setSuppressErase (BOOL erase = FALSE)
424 { SuppressEraseFlag = erase; }
425 BOOL isEraseBkgnd() { return EraseBkgndFlag; }
426 BOOL isPSErase() { return EraseBkgndFlag | PSEraseFlag; }
427 BOOL isSuppressErase() { return SuppressEraseFlag; }
428};
429
430#endif //__cplusplus
431
432#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.