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 // ---------------------------------------------------------------------------
21 // ---------------------------------------------------------------------------
22 // forward declarations
23 // ---------------------------------------------------------------------------
25 class WXDLLEXPORT wxButton
;
27 // ---------------------------------------------------------------------------
29 // ---------------------------------------------------------------------------
31 // FIXME does anybody use those? they're unused by wxWindows...
38 // ---------------------------------------------------------------------------
39 // wxWindow declaration for OS/2 PM
40 // ---------------------------------------------------------------------------
42 class WXDLLEXPORT wxWindow
: public wxWindowBase
44 DECLARE_DYNAMIC_CLASS(wxWindow
);
47 wxWindow() { Init(); }
49 wxWindow(wxWindow
*parent
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
54 const wxString
& name
= wxPanelNameStr
)
57 Create(parent
, id
, pos
, size
, style
, name
);
62 bool Create(wxWindow
*parent
,
64 const wxPoint
& pos
= wxDefaultPosition
,
65 const wxSize
& size
= wxDefaultSize
,
67 const wxString
& name
= wxPanelNameStr
);
69 // implement base class pure virtuals
70 virtual void SetTitle( const wxString
& title
);
71 virtual wxString
GetTitle() const;
76 virtual bool Show( bool show
= TRUE
);
77 virtual bool Enable( bool enable
= TRUE
);
79 virtual void SetFocus();
81 virtual bool Reparent( wxWindow
*newParent
);
83 virtual void WarpPointer(int x
, int y
);
84 virtual void CaptureMouse();
85 virtual void ReleaseMouse();
87 virtual void Refresh( bool eraseBackground
= TRUE
,
88 const wxRect
*rect
= (const wxRect
*) NULL
);
91 virtual bool SetCursor( const wxCursor
&cursor
);
92 virtual bool SetFont( const wxFont
&font
);
94 virtual int GetCharHeight() const;
95 virtual int GetCharWidth() const;
96 virtual void GetTextExtent(const wxString
& string
,
98 int *descent
= (int *) NULL
,
99 int *externalLeading
= (int *) NULL
,
100 const wxFont
*theFont
= (const wxFont
*) NULL
)
103 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
105 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
106 int range
, bool refresh
= TRUE
);
107 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
108 virtual int GetScrollPos( int orient
) const;
109 virtual int GetScrollThumb( int orient
) const;
110 virtual int GetScrollRange( int orient
) const;
111 virtual void ScrollWindow( int dx
, int dy
,
112 const wxRect
* rect
= (wxRect
*) NULL
);
114 #if wxUSE_DRAG_AND_DROP
115 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
116 #endif // wxUSE_DRAG_AND_DROP
118 // Accept files for dragging
119 virtual void DragAcceptFiles(bool accept
);
121 #if WXWIN_COMPATIBILITY
122 // Set/get scroll attributes
123 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
124 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
125 virtual int OldGetScrollRange(int orient
) const;
126 virtual int GetScrollPage(int orient
) const;
129 // Handle a control command
130 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
132 // Override to define new behaviour for default action (e.g. double
133 // clicking on a listbox)
134 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
135 #endif // WXWIN_COMPATIBILITY
137 #if wxUSE_CARET && WXWIN_COMPATIBILITY
138 // caret manipulation (old MSW only functions, see wxCaret class for the
140 void CreateCaret(int w
, int h
);
141 void CreateCaret(const wxBitmap
*bitmap
);
143 void ShowCaret(bool show
);
144 void SetCaretPos(int x
, int y
);
145 void GetCaretPos(int *x
, int *y
) const;
146 #endif // wxUSE_CARET
148 // Native resource loading (implemented in src/msw/nativdlg.cpp)
149 // FIXME: should they really be all virtual?
150 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
151 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
152 wxWindow
* GetWindowChild1(wxWindowID id
);
153 wxWindow
* GetWindowChild(wxWindowID id
);
155 // implementation from now on
156 // --------------------------
161 WXHWND
GetHWND() const { return m_hWnd
; }
162 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
163 virtual WXWidget
GetHandle() const { return GetHWND(); }
165 bool GetUseCtl3D() const { return m_useCtl3D
; }
166 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
167 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
171 void OnEraseBackground(wxEraseEvent
& event
);
172 void OnIdle(wxIdleEvent
& event
);
175 // For implementation purposes - sometimes decorations make the client area
177 virtual wxPoint
GetClientAreaOrigin() const;
179 // Makes an adjustment to the window position (for example, a frame that has
180 // a toolbar that it manages itself).
181 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
183 // Windows subclassing
184 void SubclassWin(WXHWND hWnd
);
185 void UnsubclassWin();
187 WXFARPROC
OS2GetOldWndProc() const { return m_oldWndProc
; }
188 void OS2SetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
190 wxWindow
*FindItem(long id
) const;
191 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
193 // Make a Windows extended style from the given wxWindows window style
194 static WXDWORD
MakeExtendedStyle(long style
,
195 bool eliminateBorders
= TRUE
);
196 // Determine whether 3D effects are wanted
197 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
199 // MSW only: TRUE if this control is part of the main control
200 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
202 // returns TRUE if the window has been created
203 bool OS2Create(int id
,
205 const wxChar
*wclass
,
208 int x
, int y
, int width
, int height
,
210 const wxChar
*dialog_template
= NULL
,
211 WXDWORD exendedStyle
= 0);
212 virtual bool OS2Command(WXUINT param
, WXWORD id
);
214 #if WXWIN_COMPATIBILITY
215 wxObject
*GetChild(int number
) const;
216 virtual void OS2DeviceToLogical(float *x
, float *y
) const;
217 #endif // WXWIN_COMPATIBILITY
219 // Create an appropriate wxWindow from a HWND
220 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
222 // Make sure the window style reflects the HWND style (roughly)
223 virtual void AdoptAttributesFromHWND();
225 // Setup background and foreground colours correctly
226 virtual void SetupColours();
228 // ------------------------------------------------------------------------
229 // helpers for message handlers: these perform the same function as the
230 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
231 // the correct parameters
232 // ------------------------------------------------------------------------
234 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
235 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
236 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
237 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
238 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
239 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
240 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
241 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
242 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
243 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
245 // ------------------------------------------------------------------------
246 // internal handlers for MSW messages: all handlers return a boolen value:
247 // TRUE means that the handler processed the event and FALSE that it didn't
248 // ------------------------------------------------------------------------
250 // there are several cases where we have virtual functions for Windows
251 // message processing: this is because these messages often require to be
252 // processed in a different manner in the derived classes. For all other
253 // messages, however, we do *not* have corresponding MSWOnXXX() function
254 // and if the derived class wants to process them, it should override
255 // MSWWindowProc() directly.
257 // scroll event (both horizontal and vertical)
258 virtual bool OS2OnScroll(int orientation
, WXWORD nSBCode
,
259 WXWORD pos
, WXHWND control
);
261 virtual bool OS2OnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
263 // owner-drawn controls need to process these messages
264 virtual bool OS2OnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
265 virtual bool OS2OnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
267 // the rest are not virtual
268 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
269 bool HandleInitDialog(WXHWND hWndFocus
);
270 bool HandleDestroy();
273 bool HandleEraseBkgnd(WXHDC pDC
);
275 bool HandleMinimize();
276 bool HandleMaximize();
277 bool HandleSize(int x
, int y
, WXUINT flag
);
278 bool HandleGetMinMaxInfo(void *mmInfo
);
280 bool HandleShow(bool show
, int status
);
281 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
283 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
284 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
286 bool HandleCtlColor(WXHBRUSH
*hBrush
,
294 bool HandlePaletteChanged(WXHWND hWndPalChange
);
295 bool HandleQueryNewPalette();
296 bool HandleSysColorChange();
298 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
299 bool HandleEndSession(bool endSession
, long logOff
);
301 bool HandleSetFocus(WXHWND wnd
);
302 bool HandleKillFocus(WXHWND wnd
);
304 bool HandleDropFiles(WXWPARAM wParam
);
306 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
307 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
309 bool HandleChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
310 bool HandleKeyDown(WXWORD wParam
, WXLPARAM lParam
);
311 bool HandleKeyUp(WXWORD wParam
, WXLPARAM lParam
);
313 bool HandleQueryDragIcon(WXHICON
*hIcon
);
315 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
318 virtual MRESULT
OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
320 // Calls an appropriate default window procedure
321 virtual MRESULT
OS2DefWindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
322 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
323 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
324 virtual void OS2DestroyWindow();
326 // Detach "Window" menu from menu bar so it doesn't get deleted
327 void OS2DetachWindowMenu();
329 // this function should return the brush to paint the window background
330 // with or 0 for the default brush
331 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
338 #if WXWIN_COMPATIBILITY
339 void SetShowing(bool show
) { (void)Show(show
); }
340 bool IsUserEnabled() const { return IsEnabled(); }
341 #endif // WXWIN_COMPATIBILITY
343 // Responds to colour changes: passes event on to children.
344 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
346 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
347 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
353 // the old window proc (we subclass all windows)
354 WXFARPROC m_oldWndProc
;
356 // additional (MSW specific) flags
357 bool m_useCtl3D
:1; // Using CTL3D for this control
358 bool m_backgroundTransparent
:1;
359 bool m_mouseInWindow
:1;
360 bool m_doubleClickAllowed
:1;
361 bool m_winCaptured
:1;
363 // the size of one page for scrolling
367 #if wxUSE_MOUSEEVENT_HACK
368 // the coordinates of the last mouse event and the type of it
371 int m_lastMouseEvent
;
372 #endif // wxUSE_MOUSEEVENT_HACK
374 WXHMENU m_hMenu
; // Menu, if any
376 // the return value of WM_GETDLGCODE handler
379 // implement the base class pure virtuals
380 virtual void DoClientToScreen( int *x
, int *y
) const;
381 virtual void DoScreenToClient( int *x
, int *y
) const;
382 virtual void DoGetPosition( int *x
, int *y
) const;
383 virtual void DoGetSize( int *width
, int *height
) const;
384 virtual void DoGetClientSize( int *width
, int *height
) const;
385 virtual void DoSetSize(int x
, int y
,
386 int width
, int height
,
387 int sizeFlags
= wxSIZE_AUTO
);
388 virtual void DoSetClientSize(int width
, int height
);
390 // get the size which best suits the window: e.g., for a static text it
391 // will be the width and height of the text
392 virtual wxSize
DoGetBestSize();
394 // move the window to the specified location and resize it: this is called
395 // from both DoSetSize() and DoSetClientSize() and would usually just call
396 // ::MoveWindow() except for composite controls which will want to arrange
397 // themselves inside the given rectangle
398 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
401 virtual void DoSetToolTip( wxToolTip
*tip
);
402 #endif // wxUSE_TOOLTIPS
405 // common part of all ctors
408 // the (non-virtual) handlers for the events
409 bool HandleMove(int x
, int y
);
410 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
412 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
413 DECLARE_NO_COPY_CLASS(wxWindow
);
414 DECLARE_EVENT_TABLE()
417 // ---------------------------------------------------------------------------
419 // ---------------------------------------------------------------------------
421 // kbd code translation
422 WXDLLEXPORT
int wxCharCodeOS2ToWX(int keySym
);
423 WXDLLEXPORT
int wxCharCodeWXToOS2(int id
, bool *IsVirtual
);