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 Freeze(void);
107 virtual void Update(void);
108 virtual void Thaw(void);
109 virtual void SetWindowStyleFlag(long lStyle
);
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
117 ,int* pDescent
= (int *)NULL
118 ,int* pExternalLeading
= (int *)NULL
119 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
121 #if wxUSE_MENUS_NATIVE
122 virtual bool DoPopupMenu( wxMenu
* pMenu
126 #endif // wxUSE_MENUS_NATIVE
128 virtual void SetScrollbar( int nOrient
132 ,bool bRefresh
= TRUE
134 virtual void SetScrollPos( int nOrient
136 ,bool bRefresh
= TRUE
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
143 ,const wxRect
* pRect
= (wxRect
*)NULL
146 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
147 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;};
148 #if wxUSE_DRAG_AND_DROP
149 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
150 #endif // wxUSE_DRAG_AND_DROP
152 // Accept files for dragging
153 virtual void DragAcceptFiles(bool bAccept
);
155 #ifndef __WXUNIVERSAL__
156 // Native resource loading (implemented in src/os2/nativdlg.cpp)
157 // FIXME: should they really be all virtual?
158 virtual bool LoadNativeDialog( wxWindow
* pParent
161 virtual bool LoadNativeDialog( wxWindow
* pParent
162 ,const wxString
& rName
164 wxWindow
* GetWindowChild1(wxWindowID vId
);
165 wxWindow
* GetWindowChild(wxWindowID vId
);
166 #endif //__WXUNIVERSAL__
168 // implementation from now on
169 // --------------------------
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
; }
183 void OnSetFocus(wxFocusEvent
& rEvent
);
184 void OnEraseBackground(wxEraseEvent
& rEvent
);
185 void OnIdle(wxIdleEvent
& rEvent
);
189 // For implementation purposes - sometimes decorations make the client area
191 virtual wxPoint
GetClientAreaOrigin(void) const;
193 // Windows subclassing
194 void SubclassWin(WXHWND hWnd
);
195 void UnsubclassWin(void);
197 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
198 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
200 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
202 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
204 wxWindow
* FindItem(long lId
) const;
205 wxWindow
* FindItemByHWND( WXHWND hWnd
206 ,bool bControlOnly
= FALSE
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
213 // Determine whether 3D effects are wanted
214 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
218 // PM only: TRUE if this control is part of the main control
219 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
221 // translate wxWindows style flags for this control into the PM style
222 // and optional extended style for the corresponding native control
224 // this is the function that should be overridden in the derived classes,
225 // but you will mostly use OS2GetCreateWindowFlags() below
226 virtual WXDWORD
OS2GetStyle( long lFlags
227 ,WXDWORD
* pdwExstyle
= NULL
230 // get the MSW window flags corresponding to wxWindows ones
232 // the functions returns the flags (WS_XXX) directly and puts the ext
233 // (WS_EX_XXX) flags into the provided pointer if not NULL
234 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
235 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
238 // get the HWND to be used as parent of this window with CreateWindow()
239 virtual WXHWND
OS2GetParent(void) const;
241 // returns TRUE if the window has been created
242 bool OS2Create( PSZ zClass
251 virtual bool OS2Command( WXUINT uParam
255 #ifndef __WXUNIVERSAL__
256 // Create an appropriate wxWindow from a HWND
257 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
261 // Make sure the window style reflects the HWND style (roughly)
262 virtual void AdoptAttributesFromHWND(void);
265 // Setup background and foreground colours correctly
266 virtual void SetupColours(void);
268 // ------------------------------------------------------------------------
269 // helpers for message handlers: these perform the same function as the
270 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
271 // the correct parameters
272 // ------------------------------------------------------------------------
274 void UnpackCommand( WXWPARAM wParam
280 void UnpackActivate( WXWPARAM wParam
285 void UnpackScroll( WXWPARAM wParam
291 void UnpackMenuSelect( WXWPARAM wParam
298 // ------------------------------------------------------------------------
299 // internal handlers for OS2 messages: all handlers return a boolen value:
300 // TRUE means that the handler processed the event and FALSE that it didn't
301 // ------------------------------------------------------------------------
303 // there are several cases where we have virtual functions for PM
304 // message processing: this is because these messages often require to be
305 // processed in a different manner in the derived classes. For all other
306 // messages, however, we do *not* have corresponding OS2OnXXX() function
307 // and if the derived class wants to process them, it should override
308 // OS2WindowProc() directly.
310 // scroll event (both horizontal and vertical)
311 virtual bool OS2OnScroll( int nOrientation
317 // owner-drawn controls need to process these messages
318 virtual bool OS2OnDrawItem( int nId
319 ,WXDRAWITEMSTRUCT
* pItem
321 virtual long OS2OnMeasureItem( int nId
322 ,WXMEASUREITEMSTRUCT
* pItem
325 virtual void OnPaint(wxPaintEvent
& rEvent
);
327 // the rest are not virtual
328 bool HandleCreate( WXLPCREATESTRUCT vCs
331 bool HandleInitDialog(WXHWND hWndFocus
);
332 bool HandleDestroy(void);
333 bool HandlePaint(void);
334 bool HandleEraseBkgnd(WXHDC vDC
);
335 bool HandleMinimize(void);
336 bool HandleMaximize(void);
337 bool HandleSize( int nX
341 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
342 bool HandleShow( bool bShow
345 bool HandleActivate( int nFlag
348 bool HandleCommand( WXWORD nId
352 bool HandleSysCommand( WXWPARAM wParam
355 bool HandlePaletteChanged(void);
356 bool HandleQueryNewPalette(void);
357 bool HandleSysColorChange(void);
358 bool HandleDisplayChange(void);
359 bool HandleCaptureChanged(WXHWND hBainedCapture
);
361 bool HandleCtlColor(WXHBRUSH
* hBrush
);
362 bool HandleSetFocus(WXHWND hWnd
);
363 bool HandleKillFocus(WXHWND hWnd
);
364 bool HandleEndDrag(WXWPARAM wParam
);
365 bool HandleMouseEvent( WXUINT uMsg
370 bool HandleMouseMove( int nX
374 bool HandleChar( WXWPARAM wParam
376 ,bool bIsASCII
= FALSE
378 bool HandleKeyDown( WXWPARAM wParam
381 bool HandleKeyUp( WXWPARAM wParam
384 bool HandleQueryDragIcon(WXHICON
* phIcon
);
385 bool HandleSetCursor( USHORT vId
389 bool IsMouseInWindow(void) const;
390 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
399 virtual MRESULT
OS2WindowProc( WXUINT uMsg
404 // Calls an appropriate default window procedure
405 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
409 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
410 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
411 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
412 virtual void OS2DestroyWindow(void);
414 // this function should return the brush to paint the window background
415 // with or 0 for the default brush
416 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
424 // Responds to colour changes: passes event on to children.
425 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
427 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
428 void InitMouseEvent( wxMouseEvent
& rEvent
434 void MoveChildren(int nDiff
);
435 PSWP
GetSwp(void) {return &m_vWinSwp
;}
438 // PM can't create some MSW styles natively but can perform these after
439 // creation by sending messages
440 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
441 ,kVertCaption
= 0x0002
442 ,kHorzCaption
= 0x0004
444 // Some internal sizeing id's to make it easy for event handlers
445 typedef enum size_types
{ kSizeNormal
452 // the old window proc (we subclass all windows)
453 WXFARPROC m_fnOldWndProc
;
455 // additional (OS2 specific) flags
456 bool m_bUseCtl3D
:1; // Using CTL3D for this control
457 bool m_bBackgroundTransparent
:1;
458 bool m_bMouseInWindow
:1;
459 bool m_bLastKeydownProcessed
:1;
460 bool m_bWinCaptured
:1;
463 // the size of one page for scrolling
467 #if wxUSE_MOUSEEVENT_HACK
468 // the coordinates of the last mouse event and the type of it
471 int m_nLastMouseEvent
;
472 #endif // wxUSE_MOUSEEVENT_HACK
474 WXHMENU m_hMenu
; // Menu, if any
475 unsigned long m_ulMenubarId
; // it's Id, if any
477 // the return value of WM_GETDLGCODE handler
480 // implement the base class pure virtuals
481 virtual void DoClientToScreen( int* pX
484 virtual void DoScreenToClient( int* pX
487 virtual void DoGetPosition( int* pX
490 virtual void DoGetSize( int* pWidth
493 virtual void DoGetClientSize( int* pWidth
496 virtual void DoSetSize( int nX
500 ,int nSizeFlags
= wxSIZE_AUTO
502 virtual void DoSetClientSize( int nWidth
506 virtual void DoCaptureMouse(void);
507 virtual void DoReleaseMouse(void);
509 // move the window to the specified location and resize it: this is called
510 // from both DoSetSize() and DoSetClientSize() and would usually just call
511 // ::WinSetWindowPos() except for composite controls which will want to arrange
512 // themselves inside the given rectangle
513 virtual void DoMoveWindow( int nX
520 virtual void DoSetToolTip(wxToolTip
* pTip
);
521 #endif // wxUSE_TOOLTIPS
523 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
526 // common part of all ctors
529 // the (non-virtual) handlers for the events
530 bool HandleMove( int nX
533 bool HandleJoystickEvent( WXUINT uMsg
539 bool HandleNotify( int nIdCtrl
543 // the helper functions used by HandleChar/KeyXXX methods
544 wxKeyEvent
CreateKeyEvent( wxEventType evType
550 wxWindowList
* m_pChildrenDisabled
;
551 HWND m_hWndScrollBarHorz
;
552 HWND m_hWndScrollBarVert
;
555 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
556 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
557 DECLARE_EVENT_TABLE()
560 // Virtual function hiding supression
562 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
563 { return(wxWindowBase::Reparent(pNewParent
));}
564 }; // end of wxWindow
566 class wxWindowCreationHook
569 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
570 ~wxWindowCreationHook();
571 }; // end of CLASS wxWindowCreationHook
573 // ---------------------------------------------------------------------------
575 // ---------------------------------------------------------------------------
577 // kbd code translation
578 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
579 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId