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 bool Reparent(wxWindow
* pNewParent
);
99 virtual void WarpPointer( int x
102 virtual void Refresh( bool bEraseBackground
= TRUE
103 ,const wxRect
* pRect
= (const wxRect
*)NULL
105 virtual void Clear(void);
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 #if WXWIN_COMPATIBILITY
156 // Set/get scroll attributes
157 virtual void SetScrollRange( int nOrient
159 ,bool bRefresh
= TRUE
161 virtual void SetScrollPage( int nOrient
163 ,bool bRefresh
= TRUE
165 virtual int OldGetScrollRange(int nOrient
) const;
166 virtual int GetScrollPage(int nOrient
) const;
171 // Handle a control command
172 virtual void OnCommand( wxWindow
& rWin
173 ,wxCommandEvent
& rEvent
176 // Override to define new behaviour for default action (e.g. double
177 // clicking on a listbox)
178 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
179 #endif // WXWIN_COMPATIBILITY
181 #if wxUSE_CARET && WXWIN_COMPATIBILITY
182 void CreateCaret( int nWidth
185 void CreateCaret(const wxBitmap
* pBitmap
);
186 void DestroyCaret(void);
187 void ShowCaret(bool bShow
);
188 void SetCaretPos( int nX
191 void GetCaretPos( int* pX
194 #endif // wxUSE_CARET
196 #ifndef __WXUNIVERSAL__
197 // Native resource loading (implemented in src/os2/nativdlg.cpp)
198 // FIXME: should they really be all virtual?
199 virtual bool LoadNativeDialog( wxWindow
* pParent
202 virtual bool LoadNativeDialog( wxWindow
* pParent
203 ,const wxString
& rName
205 wxWindow
* GetWindowChild1(wxWindowID vId
);
206 wxWindow
* GetWindowChild(wxWindowID vId
);
207 #endif //__WXUNIVERSAL__
209 // implementation from now on
210 // --------------------------
215 WXHWND
GetHWND(void) const { return m_hWnd
; }
216 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
217 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
218 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
219 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
220 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
224 void OnSetFocus(wxFocusEvent
& rEvent
);
225 void OnEraseBackground(wxEraseEvent
& rEvent
);
226 void OnIdle(wxIdleEvent
& rEvent
);
229 // For implementation purposes - sometimes decorations make the client area
231 virtual wxPoint
GetClientAreaOrigin(void) const;
233 // Windows subclassing
234 void SubclassWin(WXHWND hWnd
);
235 void UnsubclassWin(void);
237 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
238 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
240 wxWindow
* FindItem(long lId
) const;
241 wxWindow
* FindItemByHWND( WXHWND hWnd
242 ,bool bControlOnly
= FALSE
245 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
246 static WXDWORD
MakeExtendedStyle( long lStyle
247 ,bool bEliminateBorders
= TRUE
249 // Determine whether 3D effects are wanted
250 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
254 // PM only: TRUE if this control is part of the main control
255 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
257 // translate wxWindows style flags for this control into the PM style
258 // and optional extended style for the corresponding native control
260 // this is the function that should be overridden in the derived classes,
261 // but you will mostly use OS2GetCreateWindowFlags() below
262 virtual WXDWORD
OS2GetStyle( long lFlags
263 ,WXDWORD
* pdwExstyle
= NULL
266 // get the MSW window flags corresponding to wxWindows ones
268 // the functions returns the flags (WS_XXX) directly and puts the ext
269 // (WS_EX_XXX) flags into the provided pointer if not NULL
270 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
271 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
274 // returns TRUE if the window has been created
275 bool OS2Create( PSZ zClass
284 virtual bool OS2Command( WXUINT uParam
288 #if WXWIN_COMPATIBILITY
289 wxObject
* GetChild(int nNumber
) const;
290 virtual void OS2DeviceToLogical( float* pfX
293 #endif // WXWIN_COMPATIBILITY
295 #ifndef __WXUNIVERSAL__
296 // Create an appropriate wxWindow from a HWND
297 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
301 // Make sure the window style reflects the HWND style (roughly)
302 virtual void AdoptAttributesFromHWND(void);
305 // Setup background and foreground colours correctly
306 virtual void SetupColours(void);
308 // ------------------------------------------------------------------------
309 // helpers for message handlers: these perform the same function as the
310 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
311 // the correct parameters
312 // ------------------------------------------------------------------------
314 void UnpackCommand( WXWPARAM wParam
320 void UnpackActivate( WXWPARAM wParam
325 void UnpackScroll( WXWPARAM wParam
331 void UnpackMenuSelect( WXWPARAM wParam
338 // ------------------------------------------------------------------------
339 // internal handlers for OS2 messages: all handlers return a boolen value:
340 // TRUE means that the handler processed the event and FALSE that it didn't
341 // ------------------------------------------------------------------------
343 // there are several cases where we have virtual functions for PM
344 // message processing: this is because these messages often require to be
345 // processed in a different manner in the derived classes. For all other
346 // messages, however, we do *not* have corresponding OS2OnXXX() function
347 // and if the derived class wants to process them, it should override
348 // OS2WindowProc() directly.
350 // scroll event (both horizontal and vertical)
351 virtual bool OS2OnScroll( int nOrientation
357 // owner-drawn controls need to process these messages
358 virtual bool OS2OnDrawItem( int nId
359 ,WXDRAWITEMSTRUCT
* pItem
361 virtual bool OS2OnMeasureItem( int nId
362 ,WXMEASUREITEMSTRUCT
* pItem
365 // the rest are not virtual
366 bool HandleCreate( WXLPCREATESTRUCT vCs
369 bool HandleInitDialog(WXHWND hWndFocus
);
370 bool HandleDestroy(void);
371 bool HandlePaint(void);
372 bool HandleEraseBkgnd(WXHDC vDC
);
373 bool HandleMinimize(void);
374 bool HandleMaximize(void);
375 bool HandleSize( int nX
379 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
380 bool HandleShow( bool bShow
383 bool HandleActivate( int nFlag
386 bool HandleCommand( WXWORD nId
390 bool HandleSysCommand( WXWPARAM wParam
393 bool HandlePaletteChanged(void);
394 bool HandleQueryNewPalette(void);
395 bool HandleSysColorChange(void);
396 bool HandleDisplayChange(void);
397 bool HandleCaptureChanged(WXHWND hBainedCapture
);
399 bool HandleCtlColor(WXHBRUSH
* hBrush
);
400 bool HandleSetFocus(WXHWND hWnd
);
401 bool HandleKillFocus(WXHWND hWnd
);
402 bool HandleEndDrag(WXWPARAM wParam
);
403 bool HandleMouseEvent( WXUINT uMsg
408 bool HandleMouseMove( int nX
412 bool HandleChar( WXWPARAM wParam
414 ,bool bIsASCII
= FALSE
416 bool HandleKeyDown( WXWPARAM wParam
419 bool HandleKeyUp( WXWPARAM wParam
422 bool HandleQueryDragIcon(WXHICON
* phIcon
);
423 bool HandleSetCursor( USHORT vId
427 bool IsMouseInWindow(void) const;
428 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
437 virtual MRESULT
OS2WindowProc( WXUINT uMsg
442 // Calls an appropriate default window procedure
443 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
447 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
448 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
449 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
450 virtual void OS2DestroyWindow(void);
452 // this function should return the brush to paint the window background
453 // with or 0 for the default brush
454 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
462 #if WXWIN_COMPATIBILITY
463 void SetShowing(bool bShow
) { (void)Show(show
); }
464 bool IsUserEnabled(void) const { return IsEnabled(); }
465 #endif // WXWIN_COMPATIBILITY
467 // Responds to colour changes: passes event on to children.
468 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
470 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
471 void InitMouseEvent( wxMouseEvent
& rEvent
477 void MoveChildren(int nDiff
);
478 PSWP
GetSwp(void) {return &m_vWinSwp
;}
481 // PM can't create some MSW styles natively but can perform these after
482 // creation by sending messages
483 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
484 ,kVertCaption
= 0x0002
485 ,kHorzCaption
= 0x0004
487 // Some internal sizeing id's to make it easy for event handlers
488 typedef enum size_types
{ kSizeNormal
495 // the old window proc (we subclass all windows)
496 WXFARPROC m_fnOldWndProc
;
498 // additional (OS2 specific) flags
499 bool m_bUseCtl3D
:1; // Using CTL3D for this control
500 bool m_bBackgroundTransparent
:1;
501 bool m_bMouseInWindow
:1;
502 bool m_bDoubleClickAllowed
:1;
503 bool m_bLastKeydownProcessed
:1;
504 bool m_bWinCaptured
:1;
507 // the size of one page for scrolling
511 #if wxUSE_MOUSEEVENT_HACK
512 // the coordinates of the last mouse event and the type of it
515 int m_nLastMouseEvent
;
516 #endif // wxUSE_MOUSEEVENT_HACK
518 WXHMENU m_hMenu
; // Menu, if any
519 unsigned long m_ulMenubarId
; // it's Id, if any
521 // the return value of WM_GETDLGCODE handler
524 // implement the base class pure virtuals
525 virtual void DoClientToScreen( int* pX
528 virtual void DoScreenToClient( int* pX
531 virtual void DoGetPosition( int* pX
534 virtual void DoGetSize( int* pWidth
537 virtual void DoGetClientSize( int* pWidth
540 virtual void DoSetSize( int nX
544 ,int nSizeFlags
= wxSIZE_AUTO
546 virtual void DoSetClientSize( int nWidth
550 virtual void DoCaptureMouse(void);
551 virtual void DoReleaseMouse(void);
553 // move the window to the specified location and resize it: this is called
554 // from both DoSetSize() and DoSetClientSize() and would usually just call
555 // ::WinSetWindowPos() except for composite controls which will want to arrange
556 // themselves inside the given rectangle
557 virtual void DoMoveWindow( int nX
564 virtual void DoSetToolTip(wxToolTip
* pTip
);
565 #endif // wxUSE_TOOLTIPS
567 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
570 // common part of all ctors
573 // the (non-virtual) handlers for the events
574 bool HandleMove( int nX
577 bool HandleJoystickEvent( WXUINT uMsg
583 bool HandleNotify( int nIdCtrl
587 // the helper functions used by HandleChar/KeyXXX methods
588 wxKeyEvent
CreateKeyEvent( wxEventType evType
595 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
596 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
597 DECLARE_EVENT_TABLE()
600 HWND m_hWndScrollBarHorz
;
601 HWND m_hWndScrollBarVert
;
604 // Virtual function hiding supression
605 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
606 { return(wxWindowBase::Reparent(pNewParent
));};
607 }; // end of wxWindow
609 class wxWindowCreationHook
612 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
613 ~wxWindowCreationHook();
614 }; // end of CLASS wxWindowCreationHook
616 // ---------------------------------------------------------------------------
618 // ---------------------------------------------------------------------------
620 // kbd code translation
621 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
622 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId