]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/window.h
Committing in .
[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);
98 virtual bool Reparent(wxWindow* pNewParent);
99 virtual void WarpPointer( int x
100 ,int y
101 );
102 virtual void CaptureMouse(void);
103 virtual void ReleaseMouse(void);
104 virtual void Refresh( bool bEraseBackground = TRUE
105 ,const wxRect* pRect = (const wxRect *)NULL
106 );
107 virtual void Clear(void);
06519806
DW
108 virtual void Freeze(void);
109 virtual void Update(void);
110 virtual void Thaw(void);
776d87d5
DW
111 virtual bool SetCursor(const wxCursor& rCursor);
112 virtual bool SetFont(const wxFont& rFont);
113 virtual int GetCharHeight(void) const;
114 virtual int GetCharWidth(void) const;
115 virtual void GetTextExtent( const wxString& rString
116 ,int* pX
117 ,int* pY
118 ,int* pDescent = (int *)NULL
119 ,int* pExternalLeading = (int *)NULL
120 ,const wxFont* pTheFont = (const wxFont *)NULL
121 ) const;
19193a2c 122#if wxUSE_MENUS_NATIVE
776d87d5
DW
123 virtual bool DoPopupMenu( wxMenu* pMenu
124 ,int nX
125 ,int nY
126 );
19193a2c 127#endif // wxUSE_MENUS_NATIVE
776d87d5
DW
128
129 virtual void SetScrollbar( int nOrient
130 ,int nPos
131 ,int nThumbVisible
132 ,int nRange
133 ,bool bRefresh = TRUE
134 );
135 virtual void SetScrollPos( int nOrient
136 ,int nPos
137 ,bool bRefresh = TRUE
138 );
139 virtual int GetScrollPos(int nOrient) const;
140 virtual int GetScrollThumb(int nOrient) const;
141 virtual int GetScrollRange(int nOrient) const;
142 virtual void ScrollWindow( int nDx
143 ,int nDy
144 ,const wxRect* pRect = (wxRect *)NULL
145 );
0e320a79 146
cdf1e714 147#if wxUSE_DRAG_AND_DROP
776d87d5 148 virtual void SetDropTarget(wxDropTarget* pDropTarget);
cdf1e714 149#endif // wxUSE_DRAG_AND_DROP
0e320a79
DW
150
151 // Accept files for dragging
776d87d5 152 virtual void DragAcceptFiles(bool bAccept);
0e320a79 153
cdf1e714
DW
154#if WXWIN_COMPATIBILITY
155 // Set/get scroll attributes
776d87d5
DW
156 virtual void SetScrollRange( int nOrient
157 ,int nRange
158 ,bool bRefresh = TRUE
159 );
160 virtual void SetScrollPage( int nOrient
161 ,int nPage
162 ,bool bRefresh = TRUE
163 );
164 virtual int OldGetScrollRange(int nOrient) const;
165 virtual int GetScrollPage(int nOrient) const;
166
167 //
cdf1e714 168 // event handlers
776d87d5 169 //
cdf1e714 170 // Handle a control command
776d87d5
DW
171 virtual void OnCommand( wxWindow& rWin
172 ,wxCommandEvent& rEvent
173 );
0e320a79 174
cdf1e714
DW
175 // Override to define new behaviour for default action (e.g. double
176 // clicking on a listbox)
776d87d5 177 virtual void OnDefaultAction(wxControl* WXUNUSED(pInitiatingItem)) { }
cdf1e714 178#endif // WXWIN_COMPATIBILITY
0e320a79 179
cdf1e714 180#if wxUSE_CARET && WXWIN_COMPATIBILITY
776d87d5
DW
181 void CreateCaret( int nWidth
182 ,int nHeight
183 );
184 void CreateCaret(const wxBitmap* pBitmap);
185 void DestroyCaret(void);
186 void ShowCaret(bool bShow);
187 void SetCaretPos( int nX
188 ,int nY
189 );
190 void GetCaretPos( int* pX
191 ,int* pY
192 ) const;
cdf1e714
DW
193#endif // wxUSE_CARET
194
19193a2c 195#ifndef __WXUNIVERSAL__
776d87d5 196 // Native resource loading (implemented in src/os2/nativdlg.cpp)
cdf1e714 197 // FIXME: should they really be all virtual?
776d87d5
DW
198 virtual bool LoadNativeDialog( wxWindow* pParent
199 ,wxWindowID& vId
200 );
201 virtual bool LoadNativeDialog( wxWindow* pParent
202 ,const wxString& rName
203 );
204 wxWindow* GetWindowChild1(wxWindowID vId);
205 wxWindow* GetWindowChild(wxWindowID vId);
19193a2c 206#endif //__WXUNIVERSAL__
cdf1e714
DW
207
208 // implementation from now on
209 // --------------------------
210
211 // simple accessors
212 // ----------------
86de7616 213
776d87d5
DW
214 WXHWND GetHWND(void) const { return m_hWnd; }
215 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
216 virtual WXWidget GetHandle(void) const { return GetHWND(); }
217 bool GetUseCtl3D(void) const { return m_bUseCtl3D; }
218 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent; }
219 void SetTransparent(bool bT = TRUE) { m_bBackgroundTransparent = bT; }
54da4255 220
cdf1e714
DW
221 // event handlers
222 // --------------
a885d89a 223 void OnSetFocus(wxFocusEvent& rEvent);
776d87d5
DW
224 void OnEraseBackground(wxEraseEvent& rEvent);
225 void OnIdle(wxIdleEvent& rEvent);
cdf1e714
DW
226
227public:
0e320a79
DW
228 // For implementation purposes - sometimes decorations make the client area
229 // smaller
776d87d5 230 virtual wxPoint GetClientAreaOrigin(void) const;
0e320a79 231
86de7616
DW
232 // Windows subclassing
233 void SubclassWin(WXHWND hWnd);
776d87d5 234 void UnsubclassWin(void);
86de7616 235
776d87d5
DW
236 WXFARPROC OS2GetOldWndProc(void) const { return m_fnOldWndProc; }
237 void OS2SetOldWndProc(WXFARPROC fnProc) { m_fnOldWndProc = fnProc; }
86de7616 238
776d87d5
DW
239 wxWindow* FindItem(long lId) const;
240 wxWindow* FindItemByHWND( WXHWND hWnd
241 ,bool bControlOnly = FALSE
242 ) const;
86de7616 243
776d87d5
DW
244 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
245 static WXDWORD MakeExtendedStyle( long lStyle
246 ,bool bEliminateBorders = TRUE
247 );
86de7616 248 // Determine whether 3D effects are wanted
776d87d5
DW
249 WXDWORD Determine3DEffects( WXDWORD dwDefaultBorderStyle
250 ,bool* pbWant3D
251 ) const;
86de7616 252
776d87d5 253 // PM only: TRUE if this control is part of the main control
86de7616
DW
254 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
255
cdf1e714 256 // returns TRUE if the window has been created
3011bf2b
DW
257 bool OS2Create( PSZ zClass
258 ,const char* zTitle
259 ,WXDWORD dwStyle
260 ,const wxPoint& rPos
261 ,const wxSize& rSize
262 ,void* pCtlData
263 ,WXDWORD dwExStyle
264 ,bool bIsChild
265 );
776d87d5
DW
266 virtual bool OS2Command( WXUINT uParam
267 ,WXWORD nId
268 );
cdf1e714
DW
269
270#if WXWIN_COMPATIBILITY
776d87d5
DW
271 wxObject* GetChild(int nNumber) const;
272 virtual void OS2DeviceToLogical( float* pfX
273 ,float* pfY
274 ) const;
cdf1e714
DW
275#endif // WXWIN_COMPATIBILITY
276
19193a2c 277#ifndef __WXUNIVERSAL__
cdf1e714 278 // Create an appropriate wxWindow from a HWND
776d87d5
DW
279 virtual wxWindow* CreateWindowFromHWND( wxWindow* pParent
280 ,WXHWND hWnd
281 );
cdf1e714
DW
282
283 // Make sure the window style reflects the HWND style (roughly)
776d87d5 284 virtual void AdoptAttributesFromHWND(void);
19193a2c 285#endif
cdf1e714
DW
286
287 // Setup background and foreground colours correctly
776d87d5 288 virtual void SetupColours(void);
cdf1e714
DW
289
290 // ------------------------------------------------------------------------
291 // helpers for message handlers: these perform the same function as the
292 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
293 // the correct parameters
294 // ------------------------------------------------------------------------
295
776d87d5
DW
296 void UnpackCommand( WXWPARAM wParam
297 ,WXLPARAM lParam,
298 WXWORD* pId
299 ,WXHWND* pHwnd
300 ,WXWORD* pCmd
301 );
302 void UnpackActivate( WXWPARAM wParam
303 ,WXLPARAM lParam
304 ,WXWORD* pState
776d87d5
DW
305 ,WXHWND* pHwnd
306 );
307 void UnpackScroll( WXWPARAM wParam
308 ,WXLPARAM lParam
309 ,WXWORD* pCode
310 ,WXWORD* pPos
311 ,WXHWND* pHwnd
312 );
776d87d5
DW
313 void UnpackMenuSelect( WXWPARAM wParam
314 ,WXLPARAM lParam
315 ,WXWORD* pTtem
316 ,WXWORD* pFlags
317 ,WXHMENU* pHmenu
318 );
cdf1e714
DW
319
320 // ------------------------------------------------------------------------
776d87d5 321 // internal handlers for OS2 messages: all handlers return a boolen value:
cdf1e714
DW
322 // TRUE means that the handler processed the event and FALSE that it didn't
323 // ------------------------------------------------------------------------
324
776d87d5 325 // there are several cases where we have virtual functions for PM
cdf1e714
DW
326 // message processing: this is because these messages often require to be
327 // processed in a different manner in the derived classes. For all other
776d87d5 328 // messages, however, we do *not* have corresponding OS2OnXXX() function
cdf1e714 329 // and if the derived class wants to process them, it should override
776d87d5 330 // OS2WindowProc() directly.
cdf1e714
DW
331
332 // scroll event (both horizontal and vertical)
776d87d5
DW
333 virtual bool OS2OnScroll( int nOrientation
334 ,WXWORD nSBCode
335 ,WXWORD pos
336 ,WXHWND control
337 );
cdf1e714 338
cdf1e714 339 // owner-drawn controls need to process these messages
776d87d5
DW
340 virtual bool OS2OnDrawItem( int nId
341 ,WXDRAWITEMSTRUCT* pItem
342 );
343 virtual bool OS2OnMeasureItem( int nId
344 ,WXMEASUREITEMSTRUCT* pItem
345 );
cdf1e714
DW
346
347 // the rest are not virtual
776d87d5
DW
348 bool HandleCreate( WXLPCREATESTRUCT vCs
349 ,bool* pMayCreate
350 );
cdf1e714 351 bool HandleInitDialog(WXHWND hWndFocus);
776d87d5
DW
352 bool HandleDestroy(void);
353 bool HandlePaint(void);
354 bool HandleEraseBkgnd(WXHDC vDC);
355 bool HandleMinimize(void);
356 bool HandleMaximize(void);
357 bool HandleSize( int nX
358 ,int nY
359 ,WXUINT uFlag
360 );
61243a51 361 bool HandleGetMinMaxInfo(PSWP pMmInfo);
776d87d5
DW
362 bool HandleShow( bool bShow
363 ,int nStatus
364 );
365 bool HandleActivate( int nFlag
776d87d5
DW
366 ,WXHWND hActivate
367 );
368 bool HandleCommand( WXWORD nId
369 ,WXWORD nCmd
370 ,WXHWND hControl
371 );
372 bool HandleSysCommand( WXWPARAM wParam
373 ,WXLPARAM lParam
374 );
61243a51 375 bool HandlePaletteChanged();
776d87d5 376 bool HandleSysColorChange(void);
61243a51 377 bool HandleCtlColor(WXHBRUSH* hBrush);
776d87d5
DW
378 bool HandleSetFocus(WXHWND hWnd);
379 bool HandleKillFocus(WXHWND hWnd);
61243a51 380 bool HandleEndDrag(WXWPARAM wParam);
776d87d5
DW
381 bool HandleMouseEvent( WXUINT uMsg
382 ,int nX
383 ,int nY
384 ,WXUINT uFlags
385 );
386 bool HandleMouseMove( int nX
387 ,int nY
388 ,WXUINT uFlags
389 );
afa59b4e 390 bool HandleChar( WXDWORD wParam
776d87d5
DW
391 ,WXLPARAM lParam
392 ,bool bIsASCII = FALSE
393 );
394 bool HandleKeyDown( WXWORD wParam
395 ,WXLPARAM lParam
396 );
afa59b4e 397 bool HandleKeyUp( WXDWORD wParam
776d87d5
DW
398 ,WXLPARAM lParam
399 );
400 bool HandleQueryDragIcon(WXHICON* phIcon);
61243a51
DW
401 bool HandleSetCursor( USHORT vId
402 ,WXHWND hWnd
776d87d5 403 );
0e320a79 404
f9efbe3a
DW
405 bool IsMouseInWindow(void) const;
406 bool OS2GetCreateWindowCoords( const wxPoint& rPos
407 ,const wxSize& rSize
408 ,int& rnX
409 ,int& rnY
410 ,int& rnWidth
411 ,int& rnHeight
412 ) const;
413
cdf1e714 414 // Window procedure
a885d89a 415 virtual MRESULT OS2WindowProc( WXUINT uMsg
776d87d5
DW
416 ,WXWPARAM wParam
417 ,WXLPARAM lParam
418 );
0e320a79 419
cdf1e714 420 // Calls an appropriate default window procedure
a885d89a 421 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
776d87d5
DW
422 ,WXWPARAM wParam
423 ,WXLPARAM lParam
424 );
425 virtual bool OS2ProcessMessage(WXMSG* pMsg);
426 virtual bool OS2TranslateMessage(WXMSG* pMsg);
427 virtual void OS2DestroyWindow(void);
0e320a79 428
cdf1e714 429 // Detach "Window" menu from menu bar so it doesn't get deleted
776d87d5 430 void OS2DetachWindowMenu(void);
27476f73 431
cdf1e714
DW
432 // this function should return the brush to paint the window background
433 // with or 0 for the default brush
776d87d5
DW
434 virtual WXHBRUSH OnCtlColor( WXHDC hDC
435 ,WXHWND hWnd
436 ,WXUINT uCtlColor
437 ,WXUINT uMessage
438 ,WXWPARAM wParam
439 ,WXLPARAM lParam
440 );
27476f73 441
cdf1e714 442#if WXWIN_COMPATIBILITY
776d87d5
DW
443 void SetShowing(bool bShow) { (void)Show(show); }
444 bool IsUserEnabled(void) const { return IsEnabled(); }
cdf1e714 445#endif // WXWIN_COMPATIBILITY
0e320a79 446
cdf1e714 447 // Responds to colour changes: passes event on to children.
776d87d5 448 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
0e320a79 449
776d87d5
DW
450 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
451 void InitMouseEvent( wxMouseEvent& rEvent
452 ,int nX
453 ,int nY
454 ,WXUINT uFlags
455 );
0e320a79 456
3a50d19c
DW
457 void MoveChildren(int nDiff);
458
cdf1e714 459protected:
a885d89a
DW
460 // PM can't create some MSW styles natively but can perform these after
461 // creation by sending messages
462 typedef enum extra_flags { kFrameToolWindow = 0x0001
463 ,kVertCaption = 0x0002
464 ,kHorzCaption = 0x0004
465 } EExtraFlags;
466 // Some internal sizeing id's to make it easy for event handlers
467 typedef enum size_types { kSizeNormal
468 ,kSizeMax
469 ,kSizeMin
470 } ESizeTypes;
cdf1e714 471 // the window handle
776d87d5 472 WXHWND m_hWnd;
cdf1e714
DW
473
474 // the old window proc (we subclass all windows)
776d87d5 475 WXFARPROC m_fnOldWndProc;
cdf1e714 476
008089f6 477 // additional (OS2 specific) flags
776d87d5
DW
478 bool m_bUseCtl3D:1; // Using CTL3D for this control
479 bool m_bBackgroundTransparent:1;
480 bool m_bMouseInWindow:1;
481 bool m_bDoubleClickAllowed:1;
482 bool m_bWinCaptured:1;
008089f6 483 WXDWORD m_dwExStyle;
849949b1
DW
484
485 // the size of one page for scrolling
776d87d5
DW
486 int m_nXThumbSize;
487 int m_nYThumbSize;
0e320a79 488
cdf1e714
DW
489#if wxUSE_MOUSEEVENT_HACK
490 // the coordinates of the last mouse event and the type of it
776d87d5
DW
491 long m_lLastMouseX,
492 long m_lLastMouseY;
493 int m_nLastMouseEvent;
cdf1e714
DW
494#endif // wxUSE_MOUSEEVENT_HACK
495
776d87d5 496 WXHMENU m_hMenu; // Menu, if any
0fe536e3 497 unsigned long m_ulMenubarId; // it's Id, if any
cdf1e714
DW
498
499 // the return value of WM_GETDLGCODE handler
776d87d5 500 long m_lDlgCode;
cdf1e714
DW
501
502 // implement the base class pure virtuals
776d87d5
DW
503 virtual void DoClientToScreen( int* pX
504 ,int* pY
505 ) const;
506 virtual void DoScreenToClient( int* pX
507 ,int* pY
508 ) const;
509 virtual void DoGetPosition( int* pX
510 ,int* pY
511 ) const;
512 virtual void DoGetSize( int* pWidth
513 ,int* pHeight
514 ) const;
515 virtual void DoGetClientSize( int* pWidth
516 ,int* pHeight
517 ) const;
518 virtual void DoSetSize( int nX
519 ,int nY
520 ,int nWidth
521 ,int nHeight
522 ,int nSizeFlags = wxSIZE_AUTO
523 );
524 virtual void DoSetClientSize( int nWidth
525 ,int nHeight
526 );
cdf1e714 527
cdf1e714
DW
528 // move the window to the specified location and resize it: this is called
529 // from both DoSetSize() and DoSetClientSize() and would usually just call
3e282d33 530 // ::WinSetWindowPos() except for composite controls which will want to arrange
cdf1e714 531 // themselves inside the given rectangle
776d87d5
DW
532 virtual void DoMoveWindow( int nX
533 ,int nY
534 ,int nWidth
535 ,int nHeight
536 );
cdf1e714
DW
537
538#if wxUSE_TOOLTIPS
776d87d5 539 virtual void DoSetToolTip(wxToolTip* pTip);
cdf1e714
DW
540#endif // wxUSE_TOOLTIPS
541
3a50d19c
DW
542 int GetOS2ParentHeight(wxWindowOS2* pParent);
543
0e320a79 544private:
cdf1e714 545 // common part of all ctors
776d87d5 546 void Init(void);
0e320a79 547
cdf1e714 548 // the (non-virtual) handlers for the events
776d87d5
DW
549 bool HandleMove( int nX
550 ,int nY
551 );
552 bool HandleJoystickEvent( WXUINT uMsg
553 ,int pX
554 ,int pY
555 ,WXUINT uFlags
556 );
557
558 bool HandleNotify( int nIdCtrl
559 ,WXLPARAM lParam
560 ,WXLPARAM* pResult
561 );
a885d89a
DW
562 // the helper functions used by HandleChar/KeyXXX methods
563 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
564
210a651b
DW
565 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
566 DECLARE_NO_COPY_CLASS(wxWindowOS2)
cdf1e714 567 DECLARE_EVENT_TABLE()
63415778 568private:
c8b5f745
DW
569 HWND m_hWndScrollBarHorz;
570 HWND m_hWndScrollBarVert;
1c84ee88 571
63415778 572 // Virtual function hiding supression
776d87d5
DW
573 inline virtual bool Reparent(wxWindowBase* pNewParent)
574 { return(wxWindowBase::Reparent(pNewParent));};
a885d89a 575}; // end of wxWindow
0e320a79 576
06519806
DW
577class wxWindowCreationHook
578{
579public:
580 wxWindowCreationHook(wxWindow* pWinBeingCreated);
581 ~wxWindowCreationHook();
582}; // end of CLASS wxWindowCreationHook
583
cdf1e714
DW
584// ---------------------------------------------------------------------------
585// global functions
586// ---------------------------------------------------------------------------
0e320a79 587
cdf1e714 588// kbd code translation
776d87d5
DW
589WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
590WXDLLEXPORT int wxCharCodeWXToOS2( int nId
591 ,bool* pbIsVirtual
592 );
0e320a79
DW
593#endif
594 // _WX_WINDOW_H_