1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/window.h
3 // Purpose: wxWindow class
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #define wxUSE_MOUSEEVENT_HACK 0
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
26 // forward declarations
27 // ---------------------------------------------------------------------------
29 # define CW_USEDEFAULT ((int)0x80000000)
32 // ---------------------------------------------------------------------------
33 // forward declarations
34 // ---------------------------------------------------------------------------
36 class WXDLLIMPEXP_FWD_CORE wxButton
;
38 // ---------------------------------------------------------------------------
39 // wxWindow declaration for OS/2 PM
40 // ---------------------------------------------------------------------------
42 class WXDLLIMPEXP_CORE wxWindowOS2
: public wxWindowBase
50 wxWindowOS2( wxWindow
* pParent
52 ,const wxPoint
& rPos
= wxDefaultPosition
53 ,const wxSize
& rSize
= wxDefaultSize
55 ,const wxString
& rName
= wxPanelNameStr
68 virtual ~wxWindowOS2();
70 bool Create( wxWindow
* pParent
72 ,const wxPoint
& rPos
= wxDefaultPosition
73 ,const wxSize
& rSize
= wxDefaultSize
75 ,const wxString
& rName
= wxPanelNameStr
78 // implement base class pure virtuals
79 virtual void SetLabel(const wxString
& label
);
80 virtual wxString
GetLabel(void) const;
81 virtual void Raise(void);
82 virtual void Lower(void);
83 virtual bool Show(bool bShow
= true);
84 virtual void DoEnable(bool bEnable
);
85 virtual void SetFocus(void);
86 virtual void SetFocusFromKbd(void);
87 virtual bool Reparent(wxWindowBase
* pNewParent
);
88 virtual void WarpPointer( int x
91 virtual void Refresh( bool bEraseBackground
= true
92 ,const wxRect
* pRect
= (const wxRect
*)NULL
94 virtual void Update(void);
95 virtual void SetWindowStyleFlag(long lStyle
);
96 virtual bool SetCursor(const wxCursor
& rCursor
);
97 virtual bool SetFont(const wxFont
& rFont
);
98 virtual int GetCharHeight(void) const;
99 virtual int GetCharWidth(void) const;
101 virtual void SetScrollbar( int nOrient
105 ,bool bRefresh
= true
107 virtual void SetScrollPos( int nOrient
109 ,bool bRefresh
= true
111 virtual int GetScrollPos(int nOrient
) const;
112 virtual int GetScrollThumb(int nOrient
) const;
113 virtual int GetScrollRange(int nOrient
) const;
114 virtual void ScrollWindow( int nDx
116 ,const wxRect
* pRect
= NULL
119 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
120 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;}
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
123 #endif // wxUSE_DRAG_AND_DROP
125 // Accept files for dragging
126 virtual void DragAcceptFiles(bool bAccept
);
128 #ifndef __WXUNIVERSAL__
129 // Native resource loading (implemented in src/os2/nativdlg.cpp)
130 // FIXME: should they really be all virtual?
131 virtual bool LoadNativeDialog( wxWindow
* pParent
134 virtual bool LoadNativeDialog( wxWindow
* pParent
135 ,const wxString
& rName
137 wxWindow
* GetWindowChild1(wxWindowID vId
);
138 wxWindow
* GetWindowChild(wxWindowID vId
);
139 #endif //__WXUNIVERSAL__
141 // implementation from now on
142 // --------------------------
147 WXHWND
GetHWND(void) const { return m_hWnd
; }
148 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
149 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
150 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
151 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
152 void SetTransparentBackground(bool bT
= true) { m_bBackgroundTransparent
= bT
; }
156 void OnSetFocus(wxFocusEvent
& rEvent
);
157 void OnEraseBackground(wxEraseEvent
& rEvent
);
158 void OnIdle(wxIdleEvent
& rEvent
);
162 // Windows subclassing
163 void SubclassWin(WXHWND hWnd
);
164 void UnsubclassWin(void);
166 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
167 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
169 // Return true if the window is of a standard (i.e. not wxWidgets') class
171 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
173 wxWindow
* FindItem(long lId
) const;
174 wxWindow
* FindItemByHWND( WXHWND hWnd
175 ,bool bControlOnly
= false
178 // Make a Windows extended style from the given wxWidgets window style ?? applicable to OS/2??
179 static WXDWORD
MakeExtendedStyle( long lStyle
180 ,bool bEliminateBorders
= true
183 // PM only: true if this control is part of the main control
184 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; }
186 // translate wxWidgets style flags for this control into the PM style
187 // and optional extended style for the corresponding native control
189 // this is the function that should be overridden in the derived classes,
190 // but you will mostly use OS2GetCreateWindowFlags() below
191 virtual WXDWORD
OS2GetStyle( long lFlags
192 ,WXDWORD
* pdwExstyle
= NULL
195 // get the MSW window flags corresponding to wxWidgets ones
197 // the functions returns the flags (WS_XXX) directly and puts the ext
198 // (WS_EX_XXX) flags into the provided pointer if not NULL
199 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
200 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
203 // get the HWND to be used as parent of this window with CreateWindow()
204 virtual WXHWND
OS2GetParent(void) const;
206 // returns true if the window has been created
207 bool OS2Create( PSZ zClass
208 ,const wxChar
* zTitle
216 virtual bool OS2Command( WXUINT uParam
220 #ifndef __WXUNIVERSAL__
221 // Create an appropriate wxWindow from a HWND
222 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
226 // Make sure the window style reflects the HWND style (roughly)
227 virtual void AdoptAttributesFromHWND(void);
230 // Setup background and foreground colours correctly
231 virtual void SetupColours(void);
233 // ------------------------------------------------------------------------
234 // helpers for message handlers: these perform the same function as the
235 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
236 // the correct parameters
237 // ------------------------------------------------------------------------
239 void UnpackCommand( WXWPARAM wParam
245 void UnpackActivate( WXWPARAM wParam
250 void UnpackScroll( WXWPARAM wParam
256 void UnpackMenuSelect( WXWPARAM wParam
263 // ------------------------------------------------------------------------
264 // internal handlers for OS2 messages: all handlers return a boolen value:
265 // true means that the handler processed the event and false that it didn't
266 // ------------------------------------------------------------------------
268 // there are several cases where we have virtual functions for PM
269 // message processing: this is because these messages often require to be
270 // processed in a different manner in the derived classes. For all other
271 // messages, however, we do *not* have corresponding OS2OnXXX() function
272 // and if the derived class wants to process them, it should override
273 // OS2WindowProc() directly.
275 // scroll event (both horizontal and vertical)
276 virtual bool OS2OnScroll( int nOrientation
282 // owner-drawn controls need to process these messages
283 virtual bool OS2OnDrawItem( int nId
284 ,WXDRAWITEMSTRUCT
* pItem
286 virtual long OS2OnMeasureItem( int nId
287 ,WXMEASUREITEMSTRUCT
* pItem
290 virtual void OnPaint(wxPaintEvent
& rEvent
);
292 // the rest are not virtual
293 bool HandleCreate( WXLPCREATESTRUCT vCs
296 bool HandleInitDialog(WXHWND hWndFocus
);
297 bool HandleDestroy(void);
298 bool HandlePaint(void);
299 bool HandleEraseBkgnd(WXHDC vDC
);
300 bool HandleMinimize(void);
301 bool HandleMaximize(void);
302 bool HandleSize( int nX
306 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
307 bool HandleShow( bool bShow
310 bool HandleActivate( int nFlag
313 bool HandleCommand( WXWORD nId
317 bool HandleSysCommand( WXWPARAM wParam
320 bool HandlePaletteChanged(void);
321 bool HandleQueryNewPalette(void);
322 bool HandleSysColorChange(void);
323 bool HandleDisplayChange(void);
324 bool HandleCaptureChanged(WXHWND hBainedCapture
);
326 bool HandleCtlColor(WXHBRUSH
* hBrush
);
327 bool HandleSetFocus(WXHWND hWnd
);
328 bool HandleKillFocus(WXHWND hWnd
);
329 bool HandleEndDrag(WXWPARAM wParam
);
330 bool HandleMouseEvent( WXUINT uMsg
335 bool HandleMouseMove( int nX
339 bool HandleChar( WXWPARAM wParam
341 ,bool bIsASCII
= false
343 bool HandleKeyDown( WXWPARAM wParam
346 bool HandleKeyUp( WXWPARAM wParam
349 bool HandleQueryDragIcon(WXHICON
* phIcon
);
350 bool HandleSetCursor( USHORT vId
354 bool IsMouseInWindow(void) const;
355 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
364 virtual MRESULT
OS2WindowProc( WXUINT uMsg
369 // Calls an appropriate default window procedure
370 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
374 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
375 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
376 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
377 virtual void OS2DestroyWindow(void);
379 // this function should return the brush to paint the window background
380 // with or 0 for the default brush
381 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
389 // Responds to colour changes: passes event on to children.
390 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
392 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
393 void InitMouseEvent( wxMouseEvent
& rEvent
399 void MoveChildren(int nDiff
);
400 PSWP
GetSwp(void) {return &m_vWinSwp
;}
403 virtual void DoFreeze(void);
404 virtual void DoThaw(void);
406 // PM can't create some MSW styles natively but can perform these after
407 // creation by sending messages
408 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
409 ,kVertCaption
= 0x0002
410 ,kHorzCaption
= 0x0004
412 // Some internal sizeing id's to make it easy for event handlers
413 typedef enum size_types
{ kSizeNormal
420 // the old window proc (we subclass all windows)
421 WXFARPROC m_fnOldWndProc
;
423 // additional (OS2 specific) flags
424 bool m_bUseCtl3D
:1; // Using CTL3D for this control
425 bool m_bBackgroundTransparent
:1;
426 bool m_bMouseInWindow
:1;
427 bool m_bLastKeydownProcessed
:1;
428 bool m_bWinCaptured
:1;
431 // the size of one page for scrolling
435 #if wxUSE_MOUSEEVENT_HACK
436 // the coordinates of the last mouse event and the type of it
439 int m_nLastMouseEvent
;
440 #endif // wxUSE_MOUSEEVENT_HACK
442 WXHMENU m_hMenu
; // Menu, if any
443 unsigned long m_ulMenubarId
; // it's Id, if any
445 // the return value of WM_GETDLGCODE handler
448 // implement the base class pure virtuals
449 virtual void GetTextExtent( const wxString
& rString
452 ,int* pDescent
= NULL
453 ,int* pExternalLeading
= NULL
454 ,const wxFont
* pTheFont
= NULL
456 #if wxUSE_MENUS_NATIVE
457 virtual bool DoPopupMenu( wxMenu
* pMenu
461 #endif // wxUSE_MENUS_NATIVE
462 virtual void DoClientToScreen( int* pX
465 virtual void DoScreenToClient( int* pX
468 virtual void DoGetPosition( int* pX
471 virtual void DoGetSize( int* pWidth
474 virtual void DoGetClientSize( int* pWidth
477 virtual void DoSetSize( int nX
481 ,int nSizeFlags
= wxSIZE_AUTO
483 virtual void DoSetClientSize( int nWidth
487 virtual void DoCaptureMouse(void);
488 virtual void DoReleaseMouse(void);
490 // move the window to the specified location and resize it: this is called
491 // from both DoSetSize() and DoSetClientSize() and would usually just call
492 // ::WinSetWindowPos() except for composite controls which will want to arrange
493 // themselves inside the given rectangle
494 virtual void DoMoveWindow( int nX
501 virtual void DoSetToolTip(wxToolTip
* pTip
);
502 #endif // wxUSE_TOOLTIPS
504 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
507 // common part of all ctors
510 // the (non-virtual) handlers for the events
511 bool HandleMove( int nX
514 bool HandleJoystickEvent( WXUINT uMsg
520 bool HandleNotify( int nIdCtrl
524 // the helper functions used by HandleChar/KeyXXX methods
525 wxKeyEvent
CreateKeyEvent( wxEventType evType
531 HWND m_hWndScrollBarHorz
;
532 HWND m_hWndScrollBarVert
;
535 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
536 wxDECLARE_NO_COPY_CLASS(wxWindowOS2
);
537 DECLARE_EVENT_TABLE()
538 }; // end of wxWindow
540 class wxWindowCreationHook
543 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
544 ~wxWindowCreationHook();
545 }; // end of CLASS wxWindowCreationHook
547 // ---------------------------------------------------------------------------
549 // ---------------------------------------------------------------------------
551 // kbd code translation
552 WXDLLIMPEXP_CORE
int wxCharCodeOS2ToWX(int nKeySym
);
553 WXDLLIMPEXP_CORE
int wxCharCodeWXToOS2( int nId
554 ,bool* pbIsVirtual
= NULL
557 // ----------------------------------------------------------------------------
559 // ----------------------------------------------------------------------------
561 // notice that this hash must be defined after wxWindow declaration as it
562 // needs to "see" its dtor and not just forward declaration
565 // pseudo-template HWND <-> wxWindow hash table
566 WX_DECLARE_HASH(wxWindowOS2
, wxWindowList
, wxWinHashTable
);
568 extern wxWinHashTable
*wxWinHandleHash
;
570 #endif // _WX_WINDOW_H_