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 class WXDLLEXPORT wxButton
;
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 // FIXME does anybody use those? they're unused by wxWindows...
43 // ---------------------------------------------------------------------------
44 // wxWindow declaration for OS/2 PM
45 // ---------------------------------------------------------------------------
47 class WXDLLEXPORT wxWindow
: public wxWindowBase
55 wxWindow( wxWindow
* pParent
57 ,const wxPoint
& rPos
= wxDefaultPosition
58 ,const wxSize
& rSize
= wxDefaultSize
60 ,const wxString
& rName
= wxPanelNameStr
75 bool Create( wxWindow
* pParent
77 ,const wxPoint
& rPos
= wxDefaultPosition
78 ,const wxSize
& rSize
= wxDefaultSize
80 ,const wxString
& rName
= wxPanelNameStr
83 // implement base class pure virtuals
84 virtual void SetTitle(const wxString
& rTitle
);
85 virtual wxString
GetTitle(void) const;
86 virtual void Raise(void);
87 virtual void Lower(void);
88 virtual bool Show(bool bShow
= TRUE
);
89 virtual bool Enable(bool bEnable
= TRUE
);
90 virtual void SetFocus(void);
91 virtual bool Reparent(wxWindow
* pNewParent
);
92 virtual void WarpPointer( int x
95 virtual void CaptureMouse(void);
96 virtual void ReleaseMouse(void);
97 virtual void Refresh( bool bEraseBackground
= TRUE
98 ,const wxRect
* pRect
= (const wxRect
*)NULL
100 virtual void Clear(void);
101 virtual bool SetCursor(const wxCursor
& rCursor
);
102 virtual bool SetFont(const wxFont
& rFont
);
103 virtual int GetCharHeight(void) const;
104 virtual int GetCharWidth(void) const;
105 virtual void GetTextExtent( const wxString
& rString
108 ,int* pDescent
= (int *)NULL
109 ,int* pExternalLeading
= (int *)NULL
110 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
112 virtual bool DoPopupMenu( wxMenu
* pMenu
117 virtual void SetScrollbar( int nOrient
121 ,bool bRefresh
= TRUE
123 virtual void SetScrollPos( int nOrient
125 ,bool bRefresh
= TRUE
127 virtual int GetScrollPos(int nOrient
) const;
128 virtual int GetScrollThumb(int nOrient
) const;
129 virtual int GetScrollRange(int nOrient
) const;
130 virtual void ScrollWindow( int nDx
132 ,const wxRect
* pRect
= (wxRect
*)NULL
135 #if wxUSE_DRAG_AND_DROP
136 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
137 #endif // wxUSE_DRAG_AND_DROP
139 // Accept files for dragging
140 virtual void DragAcceptFiles(bool bAccept
);
142 #if WXWIN_COMPATIBILITY
143 // Set/get scroll attributes
144 virtual void SetScrollRange( int nOrient
146 ,bool bRefresh
= TRUE
148 virtual void SetScrollPage( int nOrient
150 ,bool bRefresh
= TRUE
152 virtual int OldGetScrollRange(int nOrient
) const;
153 virtual int GetScrollPage(int nOrient
) const;
158 // Handle a control command
159 virtual void OnCommand( wxWindow
& rWin
160 ,wxCommandEvent
& rEvent
163 // Override to define new behaviour for default action (e.g. double
164 // clicking on a listbox)
165 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
166 #endif // WXWIN_COMPATIBILITY
168 #if wxUSE_CARET && WXWIN_COMPATIBILITY
169 void CreateCaret( int nWidth
172 void CreateCaret(const wxBitmap
* pBitmap
);
173 void DestroyCaret(void);
174 void ShowCaret(bool bShow
);
175 void SetCaretPos( int nX
178 void GetCaretPos( int* pX
181 #endif // wxUSE_CARET
183 // Native resource loading (implemented in src/os2/nativdlg.cpp)
184 // FIXME: should they really be all virtual?
185 virtual bool LoadNativeDialog( wxWindow
* pParent
188 virtual bool LoadNativeDialog( wxWindow
* pParent
189 ,const wxString
& rName
191 wxWindow
* GetWindowChild1(wxWindowID vId
);
192 wxWindow
* GetWindowChild(wxWindowID vId
);
194 // implementation from now on
195 // --------------------------
200 WXHWND
GetHWND(void) const { return m_hWnd
; }
201 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
202 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
203 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
204 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
205 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
209 void OnSetFocus(wxFocusEvent
& rEvent
);
210 void OnEraseBackground(wxEraseEvent
& rEvent
);
211 void OnIdle(wxIdleEvent
& rEvent
);
214 // For implementation purposes - sometimes decorations make the client area
216 virtual wxPoint
GetClientAreaOrigin(void) const;
218 // Makes an adjustment to the window position (for example, a frame that has
219 // a toolbar that it manages itself).
220 virtual void AdjustForParentClientOrigin( int& rX
225 // Windows subclassing
226 void SubclassWin(WXHWND hWnd
);
227 void UnsubclassWin(void);
229 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
230 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
232 wxWindow
* FindItem(long lId
) const;
233 wxWindow
* FindItemByHWND( WXHWND hWnd
234 ,bool bControlOnly
= FALSE
237 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
238 static WXDWORD
MakeExtendedStyle( long lStyle
239 ,bool bEliminateBorders
= TRUE
241 // Determine whether 3D effects are wanted
242 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
246 // PM only: TRUE if this control is part of the main control
247 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
249 // returns TRUE if the window has been created
250 bool OS2Create( WXHWND hParent
252 ,const wxChar
* zTitle
261 ,void* pCtlData
= NULL
262 ,void* pPresParams
= NULL
263 ,WXDWORD dwExStyle
= 0L
265 virtual bool OS2Command( WXUINT uParam
269 #if WXWIN_COMPATIBILITY
270 wxObject
* GetChild(int nNumber
) const;
271 virtual void OS2DeviceToLogical( float* pfX
274 #endif // WXWIN_COMPATIBILITY
276 // Create an appropriate wxWindow from a HWND
277 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
281 // Make sure the window style reflects the HWND style (roughly)
282 virtual void AdoptAttributesFromHWND(void);
284 // Setup background and foreground colours correctly
285 virtual void SetupColours(void);
287 // ------------------------------------------------------------------------
288 // helpers for message handlers: these perform the same function as the
289 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
290 // the correct parameters
291 // ------------------------------------------------------------------------
293 void UnpackCommand( WXWPARAM wParam
299 void UnpackActivate( WXWPARAM wParam
304 void UnpackScroll( WXWPARAM wParam
310 void UnpackMenuSelect( WXWPARAM wParam
317 // ------------------------------------------------------------------------
318 // internal handlers for OS2 messages: all handlers return a boolen value:
319 // TRUE means that the handler processed the event and FALSE that it didn't
320 // ------------------------------------------------------------------------
322 // there are several cases where we have virtual functions for PM
323 // message processing: this is because these messages often require to be
324 // processed in a different manner in the derived classes. For all other
325 // messages, however, we do *not* have corresponding OS2OnXXX() function
326 // and if the derived class wants to process them, it should override
327 // OS2WindowProc() directly.
329 // scroll event (both horizontal and vertical)
330 virtual bool OS2OnScroll( int nOrientation
336 // owner-drawn controls need to process these messages
337 virtual bool OS2OnDrawItem( int nId
338 ,WXDRAWITEMSTRUCT
* pItem
340 virtual bool OS2OnMeasureItem( int nId
341 ,WXMEASUREITEMSTRUCT
* pItem
344 // the rest are not virtual
345 bool HandleCreate( WXLPCREATESTRUCT vCs
348 bool HandleInitDialog(WXHWND hWndFocus
);
349 bool HandleDestroy(void);
350 bool HandlePaint(void);
351 bool HandleEraseBkgnd(WXHDC vDC
);
352 bool HandleMinimize(void);
353 bool HandleMaximize(void);
354 bool HandleSize( int nX
358 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
359 bool HandleShow( bool bShow
362 bool HandleActivate( int nFlag
365 bool HandleCommand( WXWORD nId
369 bool HandleSysCommand( WXWPARAM wParam
372 bool HandleWindowParams( PWNDPARAMS pParams
375 bool HandlePaletteChanged();
376 bool HandlePresParamChanged(WXWPARAM wParam
);
377 bool HandleSysColorChange(void);
378 bool HandleCtlColor(WXHBRUSH
* hBrush
);
379 bool HandleSetFocus(WXHWND hWnd
);
380 bool HandleKillFocus(WXHWND hWnd
);
381 bool HandleEndDrag(WXWPARAM wParam
);
382 bool HandleMouseEvent( WXUINT uMsg
387 bool HandleMouseMove( int nX
391 bool HandleChar( WXWORD wParam
393 ,bool bIsASCII
= FALSE
395 bool HandleKeyDown( WXWORD wParam
398 bool HandleKeyUp( WXWORD wParam
401 bool HandleQueryDragIcon(WXHICON
* phIcon
);
402 bool HandleSetCursor( USHORT vId
407 virtual MRESULT
OS2WindowProc( WXUINT uMsg
412 // Calls an appropriate default window procedure
413 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
417 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
418 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
419 virtual void OS2DestroyWindow(void);
421 // Detach "Window" menu from menu bar so it doesn't get deleted
422 void OS2DetachWindowMenu(void);
424 // this function should return the brush to paint the window background
425 // with or 0 for the default brush
426 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
434 #if WXWIN_COMPATIBILITY
435 void SetShowing(bool bShow
) { (void)Show(show
); }
436 bool IsUserEnabled(void) const { return IsEnabled(); }
437 #endif // WXWIN_COMPATIBILITY
439 // Responds to colour changes: passes event on to children.
440 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
442 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
443 void InitMouseEvent( wxMouseEvent
& rEvent
450 // PM can't create some MSW styles natively but can perform these after
451 // creation by sending messages
452 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
453 ,kVertCaption
= 0x0002
454 ,kHorzCaption
= 0x0004
456 // Some internal sizeing id's to make it easy for event handlers
457 typedef enum size_types
{ kSizeNormal
464 // the old window proc (we subclass all windows)
465 WXFARPROC m_fnOldWndProc
;
467 // additional (OS2 specific) flags
468 bool m_bUseCtl3D
:1; // Using CTL3D for this control
469 bool m_bBackgroundTransparent
:1;
470 bool m_bMouseInWindow
:1;
471 bool m_bDoubleClickAllowed
:1;
472 bool m_bWinCaptured
:1;
475 // the size of one page for scrolling
479 #if wxUSE_MOUSEEVENT_HACK
480 // the coordinates of the last mouse event and the type of it
483 int m_nLastMouseEvent
;
484 #endif // wxUSE_MOUSEEVENT_HACK
486 WXHMENU m_hMenu
; // Menu, if any
487 unsigned long m_ulMenubarId
; // it's Id, if any
489 // the return value of WM_GETDLGCODE handler
492 // implement the base class pure virtuals
493 virtual void DoClientToScreen( int* pX
496 virtual void DoScreenToClient( int* pX
499 virtual void DoGetPosition( int* pX
502 virtual void DoGetSize( int* pWidth
505 virtual void DoGetClientSize( int* pWidth
508 virtual void DoSetSize( int nX
512 ,int nSizeFlags
= wxSIZE_AUTO
514 virtual void DoSetClientSize( int nWidth
518 // move the window to the specified location and resize it: this is called
519 // from both DoSetSize() and DoSetClientSize() and would usually just call
520 // ::WinSetWindowPos() except for composite controls which will want to arrange
521 // themselves inside the given rectangle
522 virtual void DoMoveWindow( int nX
529 virtual void DoSetToolTip(wxToolTip
* pTip
);
530 #endif // wxUSE_TOOLTIPS
533 // common part of all ctors
536 // the (non-virtual) handlers for the events
537 bool HandleMove( int nX
540 bool HandleJoystickEvent( WXUINT uMsg
546 bool HandleNotify( int nIdCtrl
550 // the helper functions used by HandleChar/KeyXXX methods
551 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
553 DECLARE_DYNAMIC_CLASS(wxWindow
);
554 DECLARE_NO_COPY_CLASS(wxWindow
);
555 DECLARE_EVENT_TABLE()
557 HWND m_hWndScrollBarHorz
;
558 HWND m_hWndScrollBarVert
;
560 // Virtual function hiding supression
561 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
562 { return(wxWindowBase::Reparent(pNewParent
));};
563 }; // end of wxWindow
565 // ---------------------------------------------------------------------------
567 // ---------------------------------------------------------------------------
569 // kbd code translation
570 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
571 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId