]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/window.h
use MSWCreateControl() instead of the old mess; implemented Get(Class)DefaultAttributes()
[wxWidgets.git] / include / wx / os2 / window.h
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose: wxWindow class
54da4255 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/12/99
0e320a79 7// RCS-ID: $Id$
cdf1e714
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
cdf1e714 15#define wxUSE_MOUSEEVENT_HACK 0
0e320a79 16
cdf1e714
DW
17// ---------------------------------------------------------------------------
18// headers
19// ---------------------------------------------------------------------------
63415778
DW
20#define INCL_DOS
21#define INCL_PM
22#define INCL_GPI
23#include <os2.h>
24
0e320a79 25
3011bf2b
DW
26// ---------------------------------------------------------------------------
27// forward declarations
28// ---------------------------------------------------------------------------
29#ifndef CW_USEDEFAULT
30# define CW_USEDEFAULT ((int)0x80000000)
31#endif
32
0e320a79
DW
33// ---------------------------------------------------------------------------
34// forward declarations
35// ---------------------------------------------------------------------------
36
37class WXDLLEXPORT wxButton;
38
cdf1e714
DW
39// ---------------------------------------------------------------------------
40// constants
41// ---------------------------------------------------------------------------
0e320a79 42
cdf1e714
DW
43// FIXME does anybody use those? they're unused by wxWindows...
44enum
45{
46 wxKEY_SHIFT = 1,
47 wxKEY_CTRL = 2
48};
54da4255 49
cdf1e714
DW
50// ---------------------------------------------------------------------------
51// wxWindow declaration for OS/2 PM
52// ---------------------------------------------------------------------------
54da4255 53
210a651b 54class WXDLLEXPORT wxWindowOS2 : public wxWindowBase
0e320a79 55{
0e320a79 56public:
210a651b 57 wxWindowOS2()
3e282d33
DW
58 {
59 Init();
60 }
cdf1e714 61
210a651b
DW
62 wxWindowOS2( wxWindow* pParent
63 ,wxWindowID vId
64 ,const wxPoint& rPos = wxDefaultPosition
65 ,const wxSize& rSize = wxDefaultSize
66 ,long lStyle = 0
67 ,const wxString& rName = wxPanelNameStr
68 )
0e320a79
DW
69 {
70 Init();
776d87d5
DW
71 Create( pParent
72 ,vId
73 ,rPos
74 ,rSize
75 ,lStyle
76 ,rName
77 );
0e320a79
DW
78 }
79
210a651b 80 virtual ~wxWindowOS2();
0e320a79 81
776d87d5
DW
82 bool Create( wxWindow* pParent
83 ,wxWindowID vId
84 ,const wxPoint& rPos = wxDefaultPosition
85 ,const wxSize& rSize = wxDefaultSize
86 ,long lStyle = 0
87 ,const wxString& rName = wxPanelNameStr
88 );
0e320a79 89
cdf1e714 90 // implement base class pure virtuals
776d87d5
DW
91 virtual void SetTitle(const wxString& rTitle);
92 virtual wxString GetTitle(void) const;
93 virtual void Raise(void);
94 virtual void Lower(void);
95 virtual bool Show(bool bShow = TRUE);
96 virtual bool Enable(bool bEnable = TRUE);
97 virtual void SetFocus(void);
1cee3f60 98 virtual void SetFocusFromKbd(void);
776d87d5
DW
99 virtual bool Reparent(wxWindow* pNewParent);
100 virtual void WarpPointer( int x
101 ,int y
102 );
776d87d5
DW
103 virtual void Refresh( bool bEraseBackground = TRUE
104 ,const wxRect* pRect = (const wxRect *)NULL
105 );
06519806
DW
106 virtual void Freeze(void);
107 virtual void Update(void);
108 virtual void Thaw(void);
b9b1d6c8 109 virtual void SetWindowStyleFlag(long lStyle);
776d87d5
DW
110 virtual bool SetCursor(const wxCursor& rCursor);
111 virtual bool SetFont(const wxFont& rFont);
112 virtual int GetCharHeight(void) const;
113 virtual int GetCharWidth(void) const;
114 virtual void GetTextExtent( const wxString& rString
115 ,int* pX
116 ,int* pY
117 ,int* pDescent = (int *)NULL
118 ,int* pExternalLeading = (int *)NULL
119 ,const wxFont* pTheFont = (const wxFont *)NULL
120 ) const;
19193a2c 121#if wxUSE_MENUS_NATIVE
776d87d5
DW
122 virtual bool DoPopupMenu( wxMenu* pMenu
123 ,int nX
124 ,int nY
125 );
19193a2c 126#endif // wxUSE_MENUS_NATIVE
776d87d5
DW
127
128 virtual void SetScrollbar( int nOrient
129 ,int nPos
130 ,int nThumbVisible
131 ,int nRange
132 ,bool bRefresh = TRUE
133 );
134 virtual void SetScrollPos( int nOrient
135 ,int nPos
136 ,bool bRefresh = TRUE
137 );
138 virtual int GetScrollPos(int nOrient) const;
139 virtual int GetScrollThumb(int nOrient) const;
140 virtual int GetScrollRange(int nOrient) const;
141 virtual void ScrollWindow( int nDx
142 ,int nDy
143 ,const wxRect* pRect = (wxRect *)NULL
144 );
0e320a79 145
45e0dc94
DW
146 inline HWND GetScrollBarHorz(void) const {return m_hWndScrollBarHorz;}
147 inline HWND GetScrollBarVert(void) const {return m_hWndScrollBarVert;};
cdf1e714 148#if wxUSE_DRAG_AND_DROP
776d87d5 149 virtual void SetDropTarget(wxDropTarget* pDropTarget);
cdf1e714 150#endif // wxUSE_DRAG_AND_DROP
0e320a79
DW
151
152 // Accept files for dragging
776d87d5 153 virtual void DragAcceptFiles(bool bAccept);
0e320a79 154
19193a2c 155#ifndef __WXUNIVERSAL__
776d87d5 156 // Native resource loading (implemented in src/os2/nativdlg.cpp)
cdf1e714 157 // FIXME: should they really be all virtual?
776d87d5
DW
158 virtual bool LoadNativeDialog( wxWindow* pParent
159 ,wxWindowID& vId
160 );
161 virtual bool LoadNativeDialog( wxWindow* pParent
162 ,const wxString& rName
163 );
164 wxWindow* GetWindowChild1(wxWindowID vId);
165 wxWindow* GetWindowChild(wxWindowID vId);
19193a2c 166#endif //__WXUNIVERSAL__
cdf1e714
DW
167
168 // implementation from now on
169 // --------------------------
170
171 // simple accessors
172 // ----------------
86de7616 173
776d87d5
DW
174 WXHWND GetHWND(void) const { return m_hWnd; }
175 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
176 virtual WXWidget GetHandle(void) const { return GetHWND(); }
177 bool GetUseCtl3D(void) const { return m_bUseCtl3D; }
178 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent; }
179 void SetTransparent(bool bT = TRUE) { m_bBackgroundTransparent = bT; }
54da4255 180
cdf1e714
DW
181 // event handlers
182 // --------------
a885d89a 183 void OnSetFocus(wxFocusEvent& rEvent);
776d87d5
DW
184 void OnEraseBackground(wxEraseEvent& rEvent);
185 void OnIdle(wxIdleEvent& rEvent);
cdf1e714
DW
186
187public:
f289196b 188
0e320a79
DW
189 // For implementation purposes - sometimes decorations make the client area
190 // smaller
776d87d5 191 virtual wxPoint GetClientAreaOrigin(void) const;
0e320a79 192
86de7616
DW
193 // Windows subclassing
194 void SubclassWin(WXHWND hWnd);
776d87d5 195 void UnsubclassWin(void);
86de7616 196
776d87d5
DW
197 WXFARPROC OS2GetOldWndProc(void) const { return m_fnOldWndProc; }
198 void OS2SetOldWndProc(WXFARPROC fnProc) { m_fnOldWndProc = fnProc; }
47df2b8c
DW
199 //
200 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
201 //
202 bool IsOfStandardClass(void) const { return m_fnOldWndProc != NULL; }
86de7616 203
776d87d5
DW
204 wxWindow* FindItem(long lId) const;
205 wxWindow* FindItemByHWND( WXHWND hWnd
206 ,bool bControlOnly = FALSE
207 ) const;
86de7616 208
776d87d5
DW
209 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
210 static WXDWORD MakeExtendedStyle( long lStyle
211 ,bool bEliminateBorders = TRUE
212 );
86de7616 213
776d87d5 214 // PM only: TRUE if this control is part of the main control
86de7616
DW
215 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
216
b9b1d6c8
DW
217 // translate wxWindows style flags for this control into the PM style
218 // and optional extended style for the corresponding native control
219 //
220 // this is the function that should be overridden in the derived classes,
221 // but you will mostly use OS2GetCreateWindowFlags() below
222 virtual WXDWORD OS2GetStyle( long lFlags
223 ,WXDWORD* pdwExstyle = NULL
224 ) const;
225
226 // get the MSW window flags corresponding to wxWindows ones
227 //
228 // the functions returns the flags (WS_XXX) directly and puts the ext
229 // (WS_EX_XXX) flags into the provided pointer if not NULL
230 WXDWORD OS2GetCreateWindowFlags(WXDWORD* pdwExflags = NULL) const
231 { return OS2GetStyle(GetWindowStyle(), pdwExflags); }
232
233
6ed98c6a
DW
234 // get the HWND to be used as parent of this window with CreateWindow()
235 virtual WXHWND OS2GetParent(void) const;
236
cdf1e714 237 // returns TRUE if the window has been created
3011bf2b
DW
238 bool OS2Create( PSZ zClass
239 ,const char* zTitle
240 ,WXDWORD dwStyle
241 ,const wxPoint& rPos
242 ,const wxSize& rSize
243 ,void* pCtlData
244 ,WXDWORD dwExStyle
245 ,bool bIsChild
246 );
776d87d5
DW
247 virtual bool OS2Command( WXUINT uParam
248 ,WXWORD nId
249 );
cdf1e714 250
19193a2c 251#ifndef __WXUNIVERSAL__
cdf1e714 252 // Create an appropriate wxWindow from a HWND
776d87d5
DW
253 virtual wxWindow* CreateWindowFromHWND( wxWindow* pParent
254 ,WXHWND hWnd
255 );
cdf1e714
DW
256
257 // Make sure the window style reflects the HWND style (roughly)
776d87d5 258 virtual void AdoptAttributesFromHWND(void);
19193a2c 259#endif
cdf1e714
DW
260
261 // Setup background and foreground colours correctly
776d87d5 262 virtual void SetupColours(void);
cdf1e714
DW
263
264 // ------------------------------------------------------------------------
265 // helpers for message handlers: these perform the same function as the
266 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
267 // the correct parameters
268 // ------------------------------------------------------------------------
269
776d87d5
DW
270 void UnpackCommand( WXWPARAM wParam
271 ,WXLPARAM lParam,
272 WXWORD* pId
273 ,WXHWND* pHwnd
274 ,WXWORD* pCmd
275 );
276 void UnpackActivate( WXWPARAM wParam
277 ,WXLPARAM lParam
278 ,WXWORD* pState
776d87d5
DW
279 ,WXHWND* pHwnd
280 );
281 void UnpackScroll( WXWPARAM wParam
282 ,WXLPARAM lParam
283 ,WXWORD* pCode
284 ,WXWORD* pPos
285 ,WXHWND* pHwnd
286 );
776d87d5
DW
287 void UnpackMenuSelect( WXWPARAM wParam
288 ,WXLPARAM lParam
289 ,WXWORD* pTtem
290 ,WXWORD* pFlags
291 ,WXHMENU* pHmenu
292 );
cdf1e714
DW
293
294 // ------------------------------------------------------------------------
776d87d5 295 // internal handlers for OS2 messages: all handlers return a boolen value:
cdf1e714
DW
296 // TRUE means that the handler processed the event and FALSE that it didn't
297 // ------------------------------------------------------------------------
298
776d87d5 299 // there are several cases where we have virtual functions for PM
cdf1e714
DW
300 // message processing: this is because these messages often require to be
301 // processed in a different manner in the derived classes. For all other
776d87d5 302 // messages, however, we do *not* have corresponding OS2OnXXX() function
cdf1e714 303 // and if the derived class wants to process them, it should override
776d87d5 304 // OS2WindowProc() directly.
cdf1e714
DW
305
306 // scroll event (both horizontal and vertical)
776d87d5
DW
307 virtual bool OS2OnScroll( int nOrientation
308 ,WXWORD nSBCode
309 ,WXWORD pos
310 ,WXHWND control
311 );
cdf1e714 312
cdf1e714 313 // owner-drawn controls need to process these messages
776d87d5
DW
314 virtual bool OS2OnDrawItem( int nId
315 ,WXDRAWITEMSTRUCT* pItem
316 );
f5ea767e 317 virtual long OS2OnMeasureItem( int nId
776d87d5
DW
318 ,WXMEASUREITEMSTRUCT* pItem
319 );
cdf1e714 320
9794cae1
DW
321 virtual void OnPaint(wxPaintEvent& rEvent);
322
cdf1e714 323 // the rest are not virtual
776d87d5
DW
324 bool HandleCreate( WXLPCREATESTRUCT vCs
325 ,bool* pMayCreate
326 );
cdf1e714 327 bool HandleInitDialog(WXHWND hWndFocus);
776d87d5
DW
328 bool HandleDestroy(void);
329 bool HandlePaint(void);
330 bool HandleEraseBkgnd(WXHDC vDC);
331 bool HandleMinimize(void);
332 bool HandleMaximize(void);
333 bool HandleSize( int nX
334 ,int nY
335 ,WXUINT uFlag
336 );
61243a51 337 bool HandleGetMinMaxInfo(PSWP pMmInfo);
776d87d5
DW
338 bool HandleShow( bool bShow
339 ,int nStatus
340 );
341 bool HandleActivate( int nFlag
776d87d5
DW
342 ,WXHWND hActivate
343 );
344 bool HandleCommand( WXWORD nId
345 ,WXWORD nCmd
346 ,WXHWND hControl
347 );
348 bool HandleSysCommand( WXWPARAM wParam
349 ,WXLPARAM lParam
350 );
1d0edc0f
DW
351 bool HandlePaletteChanged(void);
352 bool HandleQueryNewPalette(void);
776d87d5 353 bool HandleSysColorChange(void);
1d0edc0f
DW
354 bool HandleDisplayChange(void);
355 bool HandleCaptureChanged(WXHWND hBainedCapture);
356
61243a51 357 bool HandleCtlColor(WXHBRUSH* hBrush);
776d87d5
DW
358 bool HandleSetFocus(WXHWND hWnd);
359 bool HandleKillFocus(WXHWND hWnd);
61243a51 360 bool HandleEndDrag(WXWPARAM wParam);
776d87d5
DW
361 bool HandleMouseEvent( WXUINT uMsg
362 ,int nX
363 ,int nY
364 ,WXUINT uFlags
365 );
366 bool HandleMouseMove( int nX
367 ,int nY
368 ,WXUINT uFlags
369 );
598d8cac 370 bool HandleChar( WXWPARAM wParam
776d87d5
DW
371 ,WXLPARAM lParam
372 ,bool bIsASCII = FALSE
373 );
a086de98 374 bool HandleKeyDown( WXWPARAM wParam
776d87d5
DW
375 ,WXLPARAM lParam
376 );
a086de98 377 bool HandleKeyUp( WXWPARAM wParam
776d87d5
DW
378 ,WXLPARAM lParam
379 );
380 bool HandleQueryDragIcon(WXHICON* phIcon);
61243a51
DW
381 bool HandleSetCursor( USHORT vId
382 ,WXHWND hWnd
776d87d5 383 );
0e320a79 384
f9efbe3a
DW
385 bool IsMouseInWindow(void) const;
386 bool OS2GetCreateWindowCoords( const wxPoint& rPos
387 ,const wxSize& rSize
388 ,int& rnX
389 ,int& rnY
390 ,int& rnWidth
391 ,int& rnHeight
392 ) const;
393
cdf1e714 394 // Window procedure
a885d89a 395 virtual MRESULT OS2WindowProc( WXUINT uMsg
776d87d5
DW
396 ,WXWPARAM wParam
397 ,WXLPARAM lParam
398 );
0e320a79 399
cdf1e714 400 // Calls an appropriate default window procedure
a885d89a 401 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
776d87d5
DW
402 ,WXWPARAM wParam
403 ,WXLPARAM lParam
404 );
405 virtual bool OS2ProcessMessage(WXMSG* pMsg);
f140b352 406 virtual bool OS2ShouldPreProcessMessage(WXMSG* pMsg);
776d87d5
DW
407 virtual bool OS2TranslateMessage(WXMSG* pMsg);
408 virtual void OS2DestroyWindow(void);
0e320a79 409
cdf1e714
DW
410 // this function should return the brush to paint the window background
411 // with or 0 for the default brush
776d87d5
DW
412 virtual WXHBRUSH OnCtlColor( WXHDC hDC
413 ,WXHWND hWnd
414 ,WXUINT uCtlColor
415 ,WXUINT uMessage
416 ,WXWPARAM wParam
417 ,WXLPARAM lParam
418 );
27476f73 419
cdf1e714 420 // Responds to colour changes: passes event on to children.
776d87d5 421 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
0e320a79 422
776d87d5
DW
423 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
424 void InitMouseEvent( wxMouseEvent& rEvent
425 ,int nX
426 ,int nY
427 ,WXUINT uFlags
428 );
0e320a79 429
3a50d19c 430 void MoveChildren(int nDiff);
1b7735e1 431 PSWP GetSwp(void) {return &m_vWinSwp;}
3a50d19c 432
cdf1e714 433protected:
a885d89a
DW
434 // PM can't create some MSW styles natively but can perform these after
435 // creation by sending messages
436 typedef enum extra_flags { kFrameToolWindow = 0x0001
437 ,kVertCaption = 0x0002
438 ,kHorzCaption = 0x0004
439 } EExtraFlags;
440 // Some internal sizeing id's to make it easy for event handlers
441 typedef enum size_types { kSizeNormal
442 ,kSizeMax
443 ,kSizeMin
444 } ESizeTypes;
cdf1e714 445 // the window handle
776d87d5 446 WXHWND m_hWnd;
cdf1e714
DW
447
448 // the old window proc (we subclass all windows)
776d87d5 449 WXFARPROC m_fnOldWndProc;
cdf1e714 450
008089f6 451 // additional (OS2 specific) flags
776d87d5
DW
452 bool m_bUseCtl3D:1; // Using CTL3D for this control
453 bool m_bBackgroundTransparent:1;
454 bool m_bMouseInWindow:1;
3437f881 455 bool m_bLastKeydownProcessed:1;
776d87d5 456 bool m_bWinCaptured:1;
008089f6 457 WXDWORD m_dwExStyle;
849949b1
DW
458
459 // the size of one page for scrolling
776d87d5
DW
460 int m_nXThumbSize;
461 int m_nYThumbSize;
0e320a79 462
cdf1e714
DW
463#if wxUSE_MOUSEEVENT_HACK
464 // the coordinates of the last mouse event and the type of it
776d87d5
DW
465 long m_lLastMouseX,
466 long m_lLastMouseY;
467 int m_nLastMouseEvent;
cdf1e714
DW
468#endif // wxUSE_MOUSEEVENT_HACK
469
776d87d5 470 WXHMENU m_hMenu; // Menu, if any
0fe536e3 471 unsigned long m_ulMenubarId; // it's Id, if any
cdf1e714
DW
472
473 // the return value of WM_GETDLGCODE handler
776d87d5 474 long m_lDlgCode;
cdf1e714
DW
475
476 // implement the base class pure virtuals
776d87d5
DW
477 virtual void DoClientToScreen( int* pX
478 ,int* pY
479 ) const;
480 virtual void DoScreenToClient( int* pX
481 ,int* pY
482 ) const;
483 virtual void DoGetPosition( int* pX
484 ,int* pY
485 ) const;
486 virtual void DoGetSize( int* pWidth
487 ,int* pHeight
488 ) const;
489 virtual void DoGetClientSize( int* pWidth
490 ,int* pHeight
491 ) const;
492 virtual void DoSetSize( int nX
493 ,int nY
494 ,int nWidth
495 ,int nHeight
496 ,int nSizeFlags = wxSIZE_AUTO
497 );
498 virtual void DoSetClientSize( int nWidth
499 ,int nHeight
500 );
cdf1e714 501
4116c221
VZ
502 virtual void DoCaptureMouse(void);
503 virtual void DoReleaseMouse(void);
b9b1d6c8 504
cdf1e714
DW
505 // move the window to the specified location and resize it: this is called
506 // from both DoSetSize() and DoSetClientSize() and would usually just call
3e282d33 507 // ::WinSetWindowPos() except for composite controls which will want to arrange
cdf1e714 508 // themselves inside the given rectangle
776d87d5
DW
509 virtual void DoMoveWindow( int nX
510 ,int nY
511 ,int nWidth
512 ,int nHeight
513 );
cdf1e714
DW
514
515#if wxUSE_TOOLTIPS
776d87d5 516 virtual void DoSetToolTip(wxToolTip* pTip);
cdf1e714
DW
517#endif // wxUSE_TOOLTIPS
518
3a50d19c
DW
519 int GetOS2ParentHeight(wxWindowOS2* pParent);
520
0e320a79 521private:
cdf1e714 522 // common part of all ctors
776d87d5 523 void Init(void);
0e320a79 524
cdf1e714 525 // the (non-virtual) handlers for the events
776d87d5
DW
526 bool HandleMove( int nX
527 ,int nY
528 );
529 bool HandleJoystickEvent( WXUINT uMsg
530 ,int pX
531 ,int pY
532 ,WXUINT uFlags
533 );
534
535 bool HandleNotify( int nIdCtrl
536 ,WXLPARAM lParam
537 ,WXLPARAM* pResult
538 );
a885d89a 539 // the helper functions used by HandleChar/KeyXXX methods
a086de98
DW
540 wxKeyEvent CreateKeyEvent( wxEventType evType
541 ,int nId
542 ,WXLPARAM lParam = 0
543 ,WXWPARAM wParam = 0
544 ) const;
a885d89a 545
018d3030 546 wxWindowList* m_pChildrenDisabled;
c8b5f745
DW
547 HWND m_hWndScrollBarHorz;
548 HWND m_hWndScrollBarVert;
1b7735e1 549 SWP m_vWinSwp;
1c84ee88 550
018d3030
DW
551 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
552 DECLARE_NO_COPY_CLASS(wxWindowOS2)
553 DECLARE_EVENT_TABLE()
554
555 //
63415778 556 // Virtual function hiding supression
018d3030 557 //
776d87d5 558 inline virtual bool Reparent(wxWindowBase* pNewParent)
018d3030 559 { return(wxWindowBase::Reparent(pNewParent));}
a885d89a 560}; // end of wxWindow
0e320a79 561
06519806
DW
562class wxWindowCreationHook
563{
564public:
565 wxWindowCreationHook(wxWindow* pWinBeingCreated);
566 ~wxWindowCreationHook();
567}; // end of CLASS wxWindowCreationHook
568
cdf1e714
DW
569// ---------------------------------------------------------------------------
570// global functions
571// ---------------------------------------------------------------------------
0e320a79 572
cdf1e714 573// kbd code translation
776d87d5
DW
574WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
575WXDLLEXPORT int wxCharCodeWXToOS2( int nId
576 ,bool* pbIsVirtual
577 );
0e320a79
DW
578#endif
579 // _WX_WINDOW_H_