1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/window.h
3 // Purpose: wxWindow class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #define wxUSE_MOUSEEVENT_HACK 0
17 // ---------------------------------------------------------------------------
19 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
30 # define CW_USEDEFAULT ((int)0x80000000)
33 // ---------------------------------------------------------------------------
34 // forward declarations
35 // ---------------------------------------------------------------------------
37 class WXDLLIMPEXP_FWD_CORE wxButton
;
39 // ---------------------------------------------------------------------------
40 // wxWindow declaration for OS/2 PM
41 // ---------------------------------------------------------------------------
43 class WXDLLIMPEXP_CORE wxWindowOS2
: public wxWindowBase
51 wxWindowOS2( wxWindow
* pParent
53 ,const wxPoint
& rPos
= wxDefaultPosition
54 ,const wxSize
& rSize
= wxDefaultSize
56 ,const wxString
& rName
= wxPanelNameStr
69 virtual ~wxWindowOS2();
71 bool Create( wxWindow
* pParent
73 ,const wxPoint
& rPos
= wxDefaultPosition
74 ,const wxSize
& rSize
= wxDefaultSize
76 ,const wxString
& rName
= wxPanelNameStr
79 // implement base class pure virtuals
80 virtual void SetLabel(const wxString
& label
);
81 virtual wxString
GetLabel(void) const;
82 virtual void Raise(void);
83 virtual void Lower(void);
84 virtual bool Show(bool bShow
= true);
85 virtual void DoEnable(bool bEnable
);
86 virtual void SetFocus(void);
87 virtual void SetFocusFromKbd(void);
88 virtual bool Reparent(wxWindowBase
* pNewParent
);
89 virtual void WarpPointer( int x
92 virtual void Refresh( bool bEraseBackground
= true
93 ,const wxRect
* pRect
= (const wxRect
*)NULL
95 virtual void Update(void);
96 virtual void SetWindowStyleFlag(long lStyle
);
97 virtual bool SetCursor(const wxCursor
& rCursor
);
98 virtual bool SetFont(const wxFont
& rFont
);
99 virtual int GetCharHeight(void) const;
100 virtual int GetCharWidth(void) const;
102 virtual void SetScrollbar( int nOrient
106 ,bool bRefresh
= true
108 virtual void SetScrollPos( int nOrient
110 ,bool bRefresh
= true
112 virtual int GetScrollPos(int nOrient
) const;
113 virtual int GetScrollThumb(int nOrient
) const;
114 virtual int GetScrollRange(int nOrient
) const;
115 virtual void ScrollWindow( int nDx
117 ,const wxRect
* pRect
= NULL
120 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
121 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;}
122 #if wxUSE_DRAG_AND_DROP
123 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
124 #endif // wxUSE_DRAG_AND_DROP
126 // Accept files for dragging
127 virtual void DragAcceptFiles(bool bAccept
);
129 #ifndef __WXUNIVERSAL__
130 // Native resource loading (implemented in src/os2/nativdlg.cpp)
131 // FIXME: should they really be all virtual?
132 virtual bool LoadNativeDialog( wxWindow
* pParent
135 virtual bool LoadNativeDialog( wxWindow
* pParent
136 ,const wxString
& rName
138 wxWindow
* GetWindowChild1(wxWindowID vId
);
139 wxWindow
* GetWindowChild(wxWindowID vId
);
140 #endif //__WXUNIVERSAL__
142 // implementation from now on
143 // --------------------------
148 WXHWND
GetHWND(void) const { return m_hWnd
; }
149 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
150 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
151 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
152 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
153 void SetTransparentBackground(bool bT
= true) { m_bBackgroundTransparent
= bT
; }
157 void OnSetFocus(wxFocusEvent
& rEvent
);
158 void OnEraseBackground(wxEraseEvent
& rEvent
);
159 void OnIdle(wxIdleEvent
& rEvent
);
163 // Windows subclassing
164 void SubclassWin(WXHWND hWnd
);
165 void UnsubclassWin(void);
167 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
168 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
170 // Return true if the window is of a standard (i.e. not wxWidgets') class
172 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
174 wxWindow
* FindItem(long lId
) const;
175 wxWindow
* FindItemByHWND( WXHWND hWnd
176 ,bool bControlOnly
= false
179 // Make a Windows extended style from the given wxWidgets window style ?? applicable to OS/2??
180 static WXDWORD
MakeExtendedStyle( long lStyle
181 ,bool bEliminateBorders
= true
184 // PM only: true if this control is part of the main control
185 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; }
187 // translate wxWidgets style flags for this control into the PM style
188 // and optional extended style for the corresponding native control
190 // this is the function that should be overridden in the derived classes,
191 // but you will mostly use OS2GetCreateWindowFlags() below
192 virtual WXDWORD
OS2GetStyle( long lFlags
193 ,WXDWORD
* pdwExstyle
= NULL
196 // get the MSW window flags corresponding to wxWidgets ones
198 // the functions returns the flags (WS_XXX) directly and puts the ext
199 // (WS_EX_XXX) flags into the provided pointer if not NULL
200 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
201 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
204 // get the HWND to be used as parent of this window with CreateWindow()
205 virtual WXHWND
OS2GetParent(void) const;
207 // returns true if the window has been created
208 bool OS2Create( PSZ zClass
209 ,const wxChar
* zTitle
217 virtual bool OS2Command( WXUINT uParam
221 #ifndef __WXUNIVERSAL__
222 // Create an appropriate wxWindow from a HWND
223 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
227 // Make sure the window style reflects the HWND style (roughly)
228 virtual void AdoptAttributesFromHWND(void);
231 // Setup background and foreground colours correctly
232 virtual void SetupColours(void);
234 // ------------------------------------------------------------------------
235 // helpers for message handlers: these perform the same function as the
236 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
237 // the correct parameters
238 // ------------------------------------------------------------------------
240 void UnpackCommand( WXWPARAM wParam
246 void UnpackActivate( WXWPARAM wParam
251 void UnpackScroll( WXWPARAM wParam
257 void UnpackMenuSelect( WXWPARAM wParam
264 // ------------------------------------------------------------------------
265 // internal handlers for OS2 messages: all handlers return a boolen value:
266 // true means that the handler processed the event and false that it didn't
267 // ------------------------------------------------------------------------
269 // there are several cases where we have virtual functions for PM
270 // message processing: this is because these messages often require to be
271 // processed in a different manner in the derived classes. For all other
272 // messages, however, we do *not* have corresponding OS2OnXXX() function
273 // and if the derived class wants to process them, it should override
274 // OS2WindowProc() directly.
276 // scroll event (both horizontal and vertical)
277 virtual bool OS2OnScroll( int nOrientation
283 // owner-drawn controls need to process these messages
284 virtual bool OS2OnDrawItem( int nId
285 ,WXDRAWITEMSTRUCT
* pItem
287 virtual long OS2OnMeasureItem( int nId
288 ,WXMEASUREITEMSTRUCT
* pItem
291 virtual void OnPaint(wxPaintEvent
& rEvent
);
293 // the rest are not virtual
294 bool HandleCreate( WXLPCREATESTRUCT vCs
297 bool HandleInitDialog(WXHWND hWndFocus
);
298 bool HandleDestroy(void);
299 bool HandlePaint(void);
300 bool HandleEraseBkgnd(WXHDC vDC
);
301 bool HandleMinimize(void);
302 bool HandleMaximize(void);
303 bool HandleSize( int nX
307 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
308 bool HandleShow( bool bShow
311 bool HandleActivate( int nFlag
314 bool HandleCommand( WXWORD nId
318 bool HandleSysCommand( WXWPARAM wParam
321 bool HandlePaletteChanged(void);
322 bool HandleQueryNewPalette(void);
323 bool HandleSysColorChange(void);
324 bool HandleDisplayChange(void);
325 bool HandleCaptureChanged(WXHWND hBainedCapture
);
327 bool HandleCtlColor(WXHBRUSH
* hBrush
);
328 bool HandleSetFocus(WXHWND hWnd
);
329 bool HandleKillFocus(WXHWND hWnd
);
330 bool HandleEndDrag(WXWPARAM wParam
);
331 bool HandleMouseEvent( WXUINT uMsg
336 bool HandleMouseMove( int nX
340 bool HandleChar( WXWPARAM wParam
342 ,bool bIsASCII
= false
344 bool HandleKeyDown( WXWPARAM wParam
347 bool HandleKeyUp( WXWPARAM wParam
350 bool HandleQueryDragIcon(WXHICON
* phIcon
);
351 bool HandleSetCursor( USHORT vId
355 bool IsMouseInWindow(void) const;
356 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
365 virtual MRESULT
OS2WindowProc( WXUINT uMsg
370 // Calls an appropriate default window procedure
371 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
375 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
376 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
377 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
378 virtual void OS2DestroyWindow(void);
380 // this function should return the brush to paint the window background
381 // with or 0 for the default brush
382 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
390 // Responds to colour changes: passes event on to children.
391 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
393 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
394 void InitMouseEvent( wxMouseEvent
& rEvent
400 void MoveChildren(int nDiff
);
401 PSWP
GetSwp(void) {return &m_vWinSwp
;}
404 virtual void DoFreeze(void);
405 virtual void DoThaw(void);
407 // PM can't create some MSW styles natively but can perform these after
408 // creation by sending messages
409 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
410 ,kVertCaption
= 0x0002
411 ,kHorzCaption
= 0x0004
413 // Some internal sizeing id's to make it easy for event handlers
414 typedef enum size_types
{ kSizeNormal
421 // the old window proc (we subclass all windows)
422 WXFARPROC m_fnOldWndProc
;
424 // additional (OS2 specific) flags
425 bool m_bUseCtl3D
:1; // Using CTL3D for this control
426 bool m_bBackgroundTransparent
:1;
427 bool m_bMouseInWindow
:1;
428 bool m_bLastKeydownProcessed
:1;
429 bool m_bWinCaptured
:1;
432 // the size of one page for scrolling
436 #if wxUSE_MOUSEEVENT_HACK
437 // the coordinates of the last mouse event and the type of it
440 int m_nLastMouseEvent
;
441 #endif // wxUSE_MOUSEEVENT_HACK
443 WXHMENU m_hMenu
; // Menu, if any
444 unsigned long m_ulMenubarId
; // it's Id, if any
446 // the return value of WM_GETDLGCODE handler
449 // implement the base class pure virtuals
450 virtual void GetTextExtent( const wxString
& rString
453 ,int* pDescent
= NULL
454 ,int* pExternalLeading
= NULL
455 ,const wxFont
* pTheFont
= NULL
457 #if wxUSE_MENUS_NATIVE
458 virtual bool DoPopupMenu( wxMenu
* pMenu
462 #endif // wxUSE_MENUS_NATIVE
463 virtual void DoClientToScreen( int* pX
466 virtual void DoScreenToClient( int* pX
469 virtual void DoGetPosition( int* pX
472 virtual void DoGetSize( int* pWidth
475 virtual void DoGetClientSize( int* pWidth
478 virtual void DoSetSize( int nX
482 ,int nSizeFlags
= wxSIZE_AUTO
484 virtual void DoSetClientSize( int nWidth
488 virtual void DoCaptureMouse(void);
489 virtual void DoReleaseMouse(void);
491 // move the window to the specified location and resize it: this is called
492 // from both DoSetSize() and DoSetClientSize() and would usually just call
493 // ::WinSetWindowPos() except for composite controls which will want to arrange
494 // themselves inside the given rectangle
495 virtual void DoMoveWindow( int nX
502 virtual void DoSetToolTip(wxToolTip
* pTip
);
503 #endif // wxUSE_TOOLTIPS
505 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
508 // common part of all ctors
511 // the (non-virtual) handlers for the events
512 bool HandleMove( int nX
515 bool HandleJoystickEvent( WXUINT uMsg
521 bool HandleNotify( int nIdCtrl
525 // the helper functions used by HandleChar/KeyXXX methods
526 wxKeyEvent
CreateKeyEvent( wxEventType evType
532 HWND m_hWndScrollBarHorz
;
533 HWND m_hWndScrollBarVert
;
536 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
537 wxDECLARE_NO_COPY_CLASS(wxWindowOS2
);
538 DECLARE_EVENT_TABLE()
539 }; // end of wxWindow
541 class wxWindowCreationHook
544 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
545 ~wxWindowCreationHook();
546 }; // end of CLASS wxWindowCreationHook
548 // ---------------------------------------------------------------------------
550 // ---------------------------------------------------------------------------
552 // kbd code translation
553 WXDLLIMPEXP_CORE
int wxCharCodeOS2ToWX(int nKeySym
);
554 WXDLLIMPEXP_CORE
int wxCharCodeWXToOS2( int nId
555 ,bool* pbIsVirtual
= NULL
558 // ----------------------------------------------------------------------------
560 // ----------------------------------------------------------------------------
562 // notice that this hash must be defined after wxWindow declaration as it
563 // needs to "see" its dtor and not just forward declaration
566 // pseudo-template HWND <-> wxWindow hash table
567 WX_DECLARE_HASH(wxWindowOS2
, wxWindowList
, wxWinHashTable
);
569 extern wxWinHashTable
*wxWinHandleHash
;
571 #endif // _WX_WINDOW_H_