1 /////////////////////////////////////////////////////////////////////////////
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 WXDLLEXPORT wxButton
;
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // FIXME does anybody use those? they're unused by wxWindows...
50 // ---------------------------------------------------------------------------
51 // wxWindow declaration for OS/2 PM
52 // ---------------------------------------------------------------------------
54 class WXDLLEXPORT wxWindowOS2
: public wxWindowBase
62 wxWindowOS2( wxWindow
* pParent
64 ,const wxPoint
& rPos
= wxDefaultPosition
65 ,const wxSize
& rSize
= wxDefaultSize
67 ,const wxString
& rName
= wxPanelNameStr
80 virtual ~wxWindowOS2();
82 bool Create( wxWindow
* pParent
84 ,const wxPoint
& rPos
= wxDefaultPosition
85 ,const wxSize
& rSize
= wxDefaultSize
87 ,const wxString
& rName
= wxPanelNameStr
90 // implement base class pure virtuals
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 void SetFocusFromKbd(void);
99 virtual bool Reparent(wxWindow
* pNewParent
);
100 virtual void WarpPointer( int x
103 virtual void Refresh( bool bEraseBackground
= TRUE
104 ,const wxRect
* pRect
= (const wxRect
*)NULL
106 virtual void Clear(void);
107 virtual void Freeze(void);
108 virtual void Update(void);
109 virtual void Thaw(void);
110 virtual void SetWindowStyleFlag(long lStyle
);
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
118 ,int* pDescent
= (int *)NULL
119 ,int* pExternalLeading
= (int *)NULL
120 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
122 #if wxUSE_MENUS_NATIVE
123 virtual bool DoPopupMenu( wxMenu
* pMenu
127 #endif // wxUSE_MENUS_NATIVE
129 virtual void SetScrollbar( int nOrient
133 ,bool bRefresh
= TRUE
135 virtual void SetScrollPos( int nOrient
137 ,bool bRefresh
= TRUE
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
144 ,const wxRect
* pRect
= (wxRect
*)NULL
147 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
148 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;};
149 #if wxUSE_DRAG_AND_DROP
150 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
151 #endif // wxUSE_DRAG_AND_DROP
153 // Accept files for dragging
154 virtual void DragAcceptFiles(bool bAccept
);
156 #if WXWIN_COMPATIBILITY
157 // Set/get scroll attributes
158 virtual void SetScrollRange( int nOrient
160 ,bool bRefresh
= TRUE
162 virtual void SetScrollPage( int nOrient
164 ,bool bRefresh
= TRUE
166 virtual int OldGetScrollRange(int nOrient
) const;
167 virtual int GetScrollPage(int nOrient
) const;
172 // Handle a control command
173 virtual void OnCommand( wxWindow
& rWin
174 ,wxCommandEvent
& rEvent
177 // Override to define new behaviour for default action (e.g. double
178 // clicking on a listbox)
179 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
180 #endif // WXWIN_COMPATIBILITY
182 #if wxUSE_CARET && WXWIN_COMPATIBILITY
183 void CreateCaret( int nWidth
186 void CreateCaret(const wxBitmap
* pBitmap
);
187 void DestroyCaret(void);
188 void ShowCaret(bool bShow
);
189 void SetCaretPos( int nX
192 void GetCaretPos( int* pX
195 #endif // wxUSE_CARET
197 #ifndef __WXUNIVERSAL__
198 // Native resource loading (implemented in src/os2/nativdlg.cpp)
199 // FIXME: should they really be all virtual?
200 virtual bool LoadNativeDialog( wxWindow
* pParent
203 virtual bool LoadNativeDialog( wxWindow
* pParent
204 ,const wxString
& rName
206 wxWindow
* GetWindowChild1(wxWindowID vId
);
207 wxWindow
* GetWindowChild(wxWindowID vId
);
208 #endif //__WXUNIVERSAL__
210 // implementation from now on
211 // --------------------------
216 WXHWND
GetHWND(void) const { return m_hWnd
; }
217 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
218 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
219 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
220 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
221 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
225 void OnSetFocus(wxFocusEvent
& rEvent
);
226 void OnEraseBackground(wxEraseEvent
& rEvent
);
227 void OnIdle(wxIdleEvent
& rEvent
);
231 // For implementation purposes - sometimes decorations make the client area
233 virtual wxPoint
GetClientAreaOrigin(void) const;
235 // Windows subclassing
236 void SubclassWin(WXHWND hWnd
);
237 void UnsubclassWin(void);
239 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
240 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
242 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
244 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
246 wxWindow
* FindItem(long lId
) const;
247 wxWindow
* FindItemByHWND( WXHWND hWnd
248 ,bool bControlOnly
= FALSE
251 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
252 static WXDWORD
MakeExtendedStyle( long lStyle
253 ,bool bEliminateBorders
= TRUE
255 // Determine whether 3D effects are wanted
256 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
260 // PM only: TRUE if this control is part of the main control
261 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
263 // translate wxWindows style flags for this control into the PM style
264 // and optional extended style for the corresponding native control
266 // this is the function that should be overridden in the derived classes,
267 // but you will mostly use OS2GetCreateWindowFlags() below
268 virtual WXDWORD
OS2GetStyle( long lFlags
269 ,WXDWORD
* pdwExstyle
= NULL
272 // get the MSW window flags corresponding to wxWindows ones
274 // the functions returns the flags (WS_XXX) directly and puts the ext
275 // (WS_EX_XXX) flags into the provided pointer if not NULL
276 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
277 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
280 // get the HWND to be used as parent of this window with CreateWindow()
281 virtual WXHWND
OS2GetParent(void) const;
283 // returns TRUE if the window has been created
284 bool OS2Create( PSZ zClass
293 virtual bool OS2Command( WXUINT uParam
297 #if WXWIN_COMPATIBILITY
298 wxObject
* GetChild(int nNumber
) const;
299 virtual void OS2DeviceToLogical( float* pfX
302 #endif // WXWIN_COMPATIBILITY
304 #ifndef __WXUNIVERSAL__
305 // Create an appropriate wxWindow from a HWND
306 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
310 // Make sure the window style reflects the HWND style (roughly)
311 virtual void AdoptAttributesFromHWND(void);
314 // Setup background and foreground colours correctly
315 virtual void SetupColours(void);
317 // ------------------------------------------------------------------------
318 // helpers for message handlers: these perform the same function as the
319 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
320 // the correct parameters
321 // ------------------------------------------------------------------------
323 void UnpackCommand( WXWPARAM wParam
329 void UnpackActivate( WXWPARAM wParam
334 void UnpackScroll( WXWPARAM wParam
340 void UnpackMenuSelect( WXWPARAM wParam
347 // ------------------------------------------------------------------------
348 // internal handlers for OS2 messages: all handlers return a boolen value:
349 // TRUE means that the handler processed the event and FALSE that it didn't
350 // ------------------------------------------------------------------------
352 // there are several cases where we have virtual functions for PM
353 // message processing: this is because these messages often require to be
354 // processed in a different manner in the derived classes. For all other
355 // messages, however, we do *not* have corresponding OS2OnXXX() function
356 // and if the derived class wants to process them, it should override
357 // OS2WindowProc() directly.
359 // scroll event (both horizontal and vertical)
360 virtual bool OS2OnScroll( int nOrientation
366 // owner-drawn controls need to process these messages
367 virtual bool OS2OnDrawItem( int nId
368 ,WXDRAWITEMSTRUCT
* pItem
370 virtual long OS2OnMeasureItem( int nId
371 ,WXMEASUREITEMSTRUCT
* pItem
374 virtual void OnPaint(wxPaintEvent
& rEvent
);
376 // the rest are not virtual
377 bool HandleCreate( WXLPCREATESTRUCT vCs
380 bool HandleInitDialog(WXHWND hWndFocus
);
381 bool HandleDestroy(void);
382 bool HandlePaint(void);
383 bool HandleEraseBkgnd(WXHDC vDC
);
384 bool HandleMinimize(void);
385 bool HandleMaximize(void);
386 bool HandleSize( int nX
390 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
391 bool HandleShow( bool bShow
394 bool HandleActivate( int nFlag
397 bool HandleCommand( WXWORD nId
401 bool HandleSysCommand( WXWPARAM wParam
404 bool HandlePaletteChanged(void);
405 bool HandleQueryNewPalette(void);
406 bool HandleSysColorChange(void);
407 bool HandleDisplayChange(void);
408 bool HandleCaptureChanged(WXHWND hBainedCapture
);
410 bool HandleCtlColor(WXHBRUSH
* hBrush
);
411 bool HandleSetFocus(WXHWND hWnd
);
412 bool HandleKillFocus(WXHWND hWnd
);
413 bool HandleEndDrag(WXWPARAM wParam
);
414 bool HandleMouseEvent( WXUINT uMsg
419 bool HandleMouseMove( int nX
423 bool HandleChar( WXWPARAM wParam
425 ,bool bIsASCII
= FALSE
427 bool HandleKeyDown( WXWPARAM wParam
430 bool HandleKeyUp( WXWPARAM wParam
433 bool HandleQueryDragIcon(WXHICON
* phIcon
);
434 bool HandleSetCursor( USHORT vId
438 bool IsMouseInWindow(void) const;
439 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
448 virtual MRESULT
OS2WindowProc( WXUINT uMsg
453 // Calls an appropriate default window procedure
454 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
458 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
459 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
460 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
461 virtual void OS2DestroyWindow(void);
463 // this function should return the brush to paint the window background
464 // with or 0 for the default brush
465 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
473 #if WXWIN_COMPATIBILITY
474 void SetShowing(bool bShow
) { (void)Show(show
); }
475 bool IsUserEnabled(void) const { return IsEnabled(); }
476 #endif // WXWIN_COMPATIBILITY
478 // Responds to colour changes: passes event on to children.
479 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
481 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
482 void InitMouseEvent( wxMouseEvent
& rEvent
488 void MoveChildren(int nDiff
);
489 PSWP
GetSwp(void) {return &m_vWinSwp
;}
492 // PM can't create some MSW styles natively but can perform these after
493 // creation by sending messages
494 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
495 ,kVertCaption
= 0x0002
496 ,kHorzCaption
= 0x0004
498 // Some internal sizeing id's to make it easy for event handlers
499 typedef enum size_types
{ kSizeNormal
506 // the old window proc (we subclass all windows)
507 WXFARPROC m_fnOldWndProc
;
509 // additional (OS2 specific) flags
510 bool m_bUseCtl3D
:1; // Using CTL3D for this control
511 bool m_bBackgroundTransparent
:1;
512 bool m_bMouseInWindow
:1;
513 bool m_bLastKeydownProcessed
:1;
514 bool m_bWinCaptured
:1;
517 // the size of one page for scrolling
521 #if wxUSE_MOUSEEVENT_HACK
522 // the coordinates of the last mouse event and the type of it
525 int m_nLastMouseEvent
;
526 #endif // wxUSE_MOUSEEVENT_HACK
528 WXHMENU m_hMenu
; // Menu, if any
529 unsigned long m_ulMenubarId
; // it's Id, if any
531 // the return value of WM_GETDLGCODE handler
534 // implement the base class pure virtuals
535 virtual void DoClientToScreen( int* pX
538 virtual void DoScreenToClient( int* pX
541 virtual void DoGetPosition( int* pX
544 virtual void DoGetSize( int* pWidth
547 virtual void DoGetClientSize( int* pWidth
550 virtual void DoSetSize( int nX
554 ,int nSizeFlags
= wxSIZE_AUTO
556 virtual void DoSetClientSize( int nWidth
560 virtual void DoCaptureMouse(void);
561 virtual void DoReleaseMouse(void);
563 // move the window to the specified location and resize it: this is called
564 // from both DoSetSize() and DoSetClientSize() and would usually just call
565 // ::WinSetWindowPos() except for composite controls which will want to arrange
566 // themselves inside the given rectangle
567 virtual void DoMoveWindow( int nX
574 virtual void DoSetToolTip(wxToolTip
* pTip
);
575 #endif // wxUSE_TOOLTIPS
577 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
580 // common part of all ctors
583 // the (non-virtual) handlers for the events
584 bool HandleMove( int nX
587 bool HandleJoystickEvent( WXUINT uMsg
593 bool HandleNotify( int nIdCtrl
597 // the helper functions used by HandleChar/KeyXXX methods
598 wxKeyEvent
CreateKeyEvent( wxEventType evType
604 wxWindowList
* m_pChildrenDisabled
;
605 HWND m_hWndScrollBarHorz
;
606 HWND m_hWndScrollBarVert
;
609 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
610 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
611 DECLARE_EVENT_TABLE()
614 // Virtual function hiding supression
616 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
617 { return(wxWindowBase::Reparent(pNewParent
));}
618 }; // end of wxWindow
620 class wxWindowCreationHook
623 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
624 ~wxWindowCreationHook();
625 }; // end of CLASS wxWindowCreationHook
627 // ---------------------------------------------------------------------------
629 // ---------------------------------------------------------------------------
631 // kbd code translation
632 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
633 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId