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
49 DECLARE_DYNAMIC_CLASS(wxWindow
);
52 wxWindow() { Init(); }
54 wxWindow(wxWindow
*parent
,
56 const wxPoint
& pos
= wxDefaultPosition
,
57 const wxSize
& size
= wxDefaultSize
,
59 const wxString
& name
= wxPanelNameStr
)
62 Create(parent
, id
, pos
, size
, style
, name
);
67 bool Create(wxWindow
*parent
,
69 const wxPoint
& pos
= wxDefaultPosition
,
70 const wxSize
& size
= wxDefaultSize
,
72 const wxString
& name
= wxPanelNameStr
);
74 // implement base class pure virtuals
75 virtual void SetTitle( const wxString
& title
);
76 virtual wxString
GetTitle() const;
81 virtual bool Show( bool show
= TRUE
);
82 virtual bool Enable( bool enable
= TRUE
);
84 virtual void SetFocus();
86 virtual bool Reparent( wxWindow
*newParent
);
88 virtual void WarpPointer(int x
, int y
);
89 virtual void CaptureMouse();
90 virtual void ReleaseMouse();
92 virtual void Refresh( bool eraseBackground
= TRUE
,
93 const wxRect
*rect
= (const wxRect
*) NULL
);
96 virtual bool SetCursor( const wxCursor
&cursor
);
97 virtual bool SetFont( const wxFont
&font
);
99 virtual int GetCharHeight() const;
100 virtual int GetCharWidth() const;
101 virtual void GetTextExtent(const wxString
& string
,
103 int *descent
= (int *) NULL
,
104 int *externalLeading
= (int *) NULL
,
105 const wxFont
*theFont
= (const wxFont
*) NULL
)
108 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
110 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
111 int range
, bool refresh
= TRUE
);
112 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
113 virtual int GetScrollPos( int orient
) const;
114 virtual int GetScrollThumb( int orient
) const;
115 virtual int GetScrollRange( int orient
) const;
116 virtual void ScrollWindow( int dx
, int dy
,
117 const wxRect
* rect
= (wxRect
*) NULL
);
119 #if wxUSE_DRAG_AND_DROP
120 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
121 #endif // wxUSE_DRAG_AND_DROP
123 // Accept files for dragging
124 virtual void DragAcceptFiles(bool accept
);
126 #if WXWIN_COMPATIBILITY
127 // Set/get scroll attributes
128 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
129 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
130 virtual int OldGetScrollRange(int orient
) const;
131 virtual int GetScrollPage(int orient
) const;
134 // Handle a control command
135 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
137 // Override to define new behaviour for default action (e.g. double
138 // clicking on a listbox)
139 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
140 #endif // WXWIN_COMPATIBILITY
142 #if wxUSE_CARET && WXWIN_COMPATIBILITY
143 // caret manipulation (old MSW only functions, see wxCaret class for the
145 void CreateCaret(int w
, int h
);
146 void CreateCaret(const wxBitmap
*bitmap
);
148 void ShowCaret(bool show
);
149 void SetCaretPos(int x
, int y
);
150 void GetCaretPos(int *x
, int *y
) const;
151 #endif // wxUSE_CARET
153 // Native resource loading (implemented in src/msw/nativdlg.cpp)
154 // FIXME: should they really be all virtual?
155 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
156 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
157 wxWindow
* GetWindowChild1(wxWindowID id
);
158 wxWindow
* GetWindowChild(wxWindowID id
);
160 // implementation from now on
161 // --------------------------
166 WXHWND
GetHWND() const { return m_hWnd
; }
167 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
168 virtual WXWidget
GetHandle() const { return GetHWND(); }
170 bool GetUseCtl3D() const { return m_useCtl3D
; }
171 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
172 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
176 void OnEraseBackground(wxEraseEvent
& event
);
177 void OnIdle(wxIdleEvent
& event
);
180 // For implementation purposes - sometimes decorations make the client area
182 virtual wxPoint
GetClientAreaOrigin() const;
184 // Makes an adjustment to the window position (for example, a frame that has
185 // a toolbar that it manages itself).
186 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
188 // Windows subclassing
189 void SubclassWin(WXHWND hWnd
);
190 void UnsubclassWin();
192 WXFARPROC
OS2GetOldWndProc() const { return m_oldWndProc
; }
193 void OS2SetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
195 wxWindow
*FindItem(long id
) const;
196 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
198 // Make a Windows extended style from the given wxWindows window style
199 static WXDWORD
MakeExtendedStyle(long style
,
200 bool eliminateBorders
= TRUE
);
201 // Determine whether 3D effects are wanted
202 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
204 // MSW only: TRUE if this control is part of the main control
205 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
207 // returns TRUE if the window has been created
208 bool OS2Create(int id
,
210 const wxChar
*wclass
,
213 int x
, int y
, int width
, int height
,
215 const wxChar
*dialog_template
= NULL
,
216 WXDWORD exendedStyle
= 0);
217 virtual bool OS2Command(WXUINT param
, WXWORD id
);
219 #if WXWIN_COMPATIBILITY
220 wxObject
*GetChild(int number
) const;
221 virtual void OS2DeviceToLogical(float *x
, float *y
) const;
222 #endif // WXWIN_COMPATIBILITY
224 // Create an appropriate wxWindow from a HWND
225 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
227 // Make sure the window style reflects the HWND style (roughly)
228 virtual void AdoptAttributesFromHWND();
230 // Setup background and foreground colours correctly
231 virtual void SetupColours();
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
, WXLPARAM lParam
,
240 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
241 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
242 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
243 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
244 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
245 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
246 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
247 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
248 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
250 // ------------------------------------------------------------------------
251 // internal handlers for MSW messages: all handlers return a boolen value:
252 // TRUE means that the handler processed the event and FALSE that it didn't
253 // ------------------------------------------------------------------------
255 // there are several cases where we have virtual functions for Windows
256 // message processing: this is because these messages often require to be
257 // processed in a different manner in the derived classes. For all other
258 // messages, however, we do *not* have corresponding MSWOnXXX() function
259 // and if the derived class wants to process them, it should override
260 // MSWWindowProc() directly.
262 // scroll event (both horizontal and vertical)
263 virtual bool OS2OnScroll(int orientation
, WXWORD nSBCode
,
264 WXWORD pos
, WXHWND control
);
266 virtual bool OS2OnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
268 // owner-drawn controls need to process these messages
269 virtual bool OS2OnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
270 virtual bool OS2OnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
272 // the rest are not virtual
273 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
274 bool HandleInitDialog(WXHWND hWndFocus
);
275 bool HandleDestroy();
278 bool HandleEraseBkgnd(WXHDC pDC
);
280 bool HandleMinimize();
281 bool HandleMaximize();
282 bool HandleSize(int x
, int y
, WXUINT flag
);
283 bool HandleGetMinMaxInfo(void *mmInfo
);
285 bool HandleShow(bool show
, int status
);
286 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
288 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
289 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
291 bool HandleCtlColor(WXHBRUSH
*hBrush
,
299 bool HandlePaletteChanged(WXHWND hWndPalChange
);
300 bool HandleQueryNewPalette();
301 bool HandleSysColorChange();
303 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
304 bool HandleEndSession(bool endSession
, long logOff
);
306 bool HandleSetFocus(WXHWND wnd
);
307 bool HandleKillFocus(WXHWND wnd
);
309 bool HandleDropFiles(WXWPARAM wParam
);
311 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
312 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
314 bool HandleChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
315 bool HandleKeyDown(WXWORD wParam
, WXLPARAM lParam
);
316 bool HandleKeyUp(WXWORD wParam
, WXLPARAM lParam
);
318 bool HandleQueryDragIcon(WXHICON
*hIcon
);
320 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
323 virtual MRESULT
OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
325 // Calls an appropriate default window procedure
326 virtual MRESULT
OS2DefWindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
327 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
328 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
329 virtual void OS2DestroyWindow();
331 // Detach "Window" menu from menu bar so it doesn't get deleted
332 void OS2DetachWindowMenu();
334 // this function should return the brush to paint the window background
335 // with or 0 for the default brush
336 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
343 #if WXWIN_COMPATIBILITY
344 void SetShowing(bool show
) { (void)Show(show
); }
345 bool IsUserEnabled() const { return IsEnabled(); }
346 #endif // WXWIN_COMPATIBILITY
348 // Responds to colour changes: passes event on to children.
349 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
351 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
352 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
358 // the old window proc (we subclass all windows)
359 WXFARPROC m_oldWndProc
;
361 // additional (MSW specific) flags
362 bool m_useCtl3D
:1; // Using CTL3D for this control
363 bool m_backgroundTransparent
:1;
364 bool m_mouseInWindow
:1;
365 bool m_doubleClickAllowed
:1;
366 bool m_winCaptured
:1;
368 // the size of one page for scrolling
372 #if wxUSE_MOUSEEVENT_HACK
373 // the coordinates of the last mouse event and the type of it
376 int m_lastMouseEvent
;
377 #endif // wxUSE_MOUSEEVENT_HACK
379 WXHMENU m_hMenu
; // Menu, if any
381 // the return value of WM_GETDLGCODE handler
384 // implement the base class pure virtuals
385 virtual void DoClientToScreen( int *x
, int *y
) const;
386 virtual void DoScreenToClient( int *x
, int *y
) const;
387 virtual void DoGetPosition( int *x
, int *y
) const;
388 virtual void DoGetSize( int *width
, int *height
) const;
389 virtual void DoGetClientSize( int *width
, int *height
) const;
390 virtual void DoSetSize(int x
, int y
,
391 int width
, int height
,
392 int sizeFlags
= wxSIZE_AUTO
);
393 virtual void DoSetClientSize(int width
, int height
);
395 // get the size which best suits the window: e.g., for a static text it
396 // will be the width and height of the text
397 virtual wxSize
DoGetBestSize();
399 // move the window to the specified location and resize it: this is called
400 // from both DoSetSize() and DoSetClientSize() and would usually just call
401 // ::MoveWindow() except for composite controls which will want to arrange
402 // themselves inside the given rectangle
403 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
406 virtual void DoSetToolTip( wxToolTip
*tip
);
407 #endif // wxUSE_TOOLTIPS
410 // common part of all ctors
413 // the (non-virtual) handlers for the events
414 bool HandleMove(int x
, int y
);
415 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
417 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
418 DECLARE_NO_COPY_CLASS(wxWindow
);
419 DECLARE_EVENT_TABLE()
421 // Virtual function hiding supression
422 inline virtual bool Reparent( wxWindowBase
*newParent
)
423 { return(wxWindowBase::Reparent(newParent
));};
426 // ---------------------------------------------------------------------------
428 // ---------------------------------------------------------------------------
430 // kbd code translation
431 WXDLLEXPORT
int wxCharCodeOS2ToWX(int keySym
);
432 WXDLLEXPORT
int wxCharCodeWXToOS2(int id
, bool *IsVirtual
);