]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/window.h
MSW fixes; added wxUSE_XPM to wxUniv's setup.h so now widgets sample works
[wxWidgets.git] / include / wx / msw / window.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: wx/msw/window.h
2bda0e17
KB
3// Purpose: wxWindow class
4// Author: Julian Smart
1e6feb95
VZ
5// Modified by: Vadim Zeitlin on 13.05.99: complete refont of message handling,
6// elimination of Default(), ...
2bda0e17
KB
7// Created: 01/02/97
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart and Markus Holzem
cc2b7472 10// Licence: wxWindows licence
2bda0e17
KB
11/////////////////////////////////////////////////////////////////////////////
12
bbcdf8bc
JS
13#ifndef _WX_WINDOW_H_
14#define _WX_WINDOW_H_
2bda0e17 15
cc2b7472
VZ
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
cc2b7472 21 #pragma interface "window.h"
2bda0e17
KB
22#endif
23
1e6feb95
VZ
24// [at least] some version of Windows send extra mouse move messages after
25// a mouse click or a key press - to temporarily fix this problem, set the
26// define below to 1
27//
28// a better solution should be found later...
a23fd0e1
VZ
29#define wxUSE_MOUSEEVENT_HACK 0
30
1e6feb95
VZ
31// when building wxUniv/MSW we don't want the code for native menu use to be
32// compiled in - it should only be used when building real wxMSW
33#ifdef __WXUNIVERSAL__
34 #define wxUSE_MENUS_NATIVE 0
35#else // __WXMSW__
36 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
37#endif // __WXUNIVERSAL__/__WXMSW__
2bda0e17 38
cc2b7472
VZ
39// ---------------------------------------------------------------------------
40// constants
41// ---------------------------------------------------------------------------
1e6d9499 42
cc2b7472
VZ
43// FIXME does anybody use those? they're unused by wxWindows...
44enum
1e6d9499 45{
cc2b7472
VZ
46 wxKEY_SHIFT = 1,
47 wxKEY_CTRL = 2
1e6d9499
JS
48};
49
cc2b7472
VZ
50// ---------------------------------------------------------------------------
51// wxWindow declaration for MSW
52// ---------------------------------------------------------------------------
b782f2e0 53
1e6feb95 54class WXDLLEXPORT wxWindowMSW : public wxWindowBase
1e6d9499 55{
2bda0e17 56public:
1e6feb95
VZ
57 wxWindowMSW() { Init(); }
58
59 wxWindowMSW(wxWindow *parent,
60 wxWindowID id,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = 0,
64 const wxString& name = wxPanelNameStr)
bfc6fde4
VZ
65 {
66 Init();
67 Create(parent, id, pos, size, style, name);
68 }
2bda0e17 69
1e6feb95 70 virtual ~wxWindowMSW();
2bda0e17 71
cc2b7472
VZ
72 bool Create(wxWindow *parent,
73 wxWindowID id,
74 const wxPoint& pos = wxDefaultPosition,
75 const wxSize& size = wxDefaultSize,
76 long style = 0,
77 const wxString& name = wxPanelNameStr);
bfc6fde4 78
cc2b7472 79 // implement base class pure virtuals
42e69d6b
VZ
80 virtual void SetTitle( const wxString& title);
81 virtual wxString GetTitle() const;
82
bfc6fde4 83 virtual void Raise();
bfc6fde4
VZ
84 virtual void Lower();
85
cc2b7472
VZ
86 virtual bool Show( bool show = TRUE );
87 virtual bool Enable( bool enable = TRUE );
bfc6fde4 88
cc2b7472 89 virtual void SetFocus();
bfc6fde4 90
1e6feb95 91 virtual bool Reparent(wxWindowBase *newParent);
bfc6fde4 92
cc2b7472
VZ
93 virtual void WarpPointer(int x, int y);
94 virtual void CaptureMouse();
95 virtual void ReleaseMouse();
bfc6fde4 96
cc2b7472
VZ
97 virtual void Refresh( bool eraseBackground = TRUE,
98 const wxRect *rect = (const wxRect *) NULL );
1e6feb95 99 virtual void Update();
cc2b7472 100 virtual void Clear();
bfc6fde4 101
cc2b7472
VZ
102 virtual bool SetCursor( const wxCursor &cursor );
103 virtual bool SetFont( const wxFont &font );
bfc6fde4 104
bfc6fde4
VZ
105 virtual int GetCharHeight() const;
106 virtual int GetCharWidth() const;
cc2b7472
VZ
107 virtual void GetTextExtent(const wxString& string,
108 int *x, int *y,
109 int *descent = (int *) NULL,
110 int *externalLeading = (int *) NULL,
111 const wxFont *theFont = (const wxFont *) NULL)
112 const;
113
1e6feb95 114#if wxUSE_MENUS_NATIVE
a1665b22 115 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
1e6feb95 116#endif // wxUSE_MENUS_NATIVE
cc2b7472
VZ
117
118 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
119 int range, bool refresh = TRUE );
120 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
121 virtual int GetScrollPos( int orient ) const;
122 virtual int GetScrollThumb( int orient ) const;
123 virtual int GetScrollRange( int orient ) const;
124 virtual void ScrollWindow( int dx, int dy,
125 const wxRect* rect = (wxRect *) NULL );
2bda0e17 126
47d67540 127#if wxUSE_DRAG_AND_DROP
cc2b7472
VZ
128 virtual void SetDropTarget( wxDropTarget *dropTarget );
129#endif // wxUSE_DRAG_AND_DROP
9f3362c4 130
bfc6fde4
VZ
131 // Accept files for dragging
132 virtual void DragAcceptFiles(bool accept);
2bda0e17 133
2bda0e17 134#if WXWIN_COMPATIBILITY
bfc6fde4
VZ
135 // Set/get scroll attributes
136 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
137 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
138 virtual int OldGetScrollRange(int orient) const;
139 virtual int GetScrollPage(int orient) const;
42e69d6b
VZ
140
141 // event handlers
142 // Handle a control command
143 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
144
145 // Override to define new behaviour for default action (e.g. double
146 // clicking on a listbox)
147 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
cc2b7472 148#endif // WXWIN_COMPATIBILITY
bfc6fde4 149
34636400 150#if wxUSE_CARET && WXWIN_COMPATIBILITY
789295bf
VZ
151 // caret manipulation (old MSW only functions, see wxCaret class for the
152 // new API)
153 void CreateCaret(int w, int h);
154 void CreateCaret(const wxBitmap *bitmap);
155 void DestroyCaret();
156 void ShowCaret(bool show);
157 void SetCaretPos(int x, int y);
158 void GetCaretPos(int *x, int *y) const;
159#endif // wxUSE_CARET
bfc6fde4 160
1e6feb95 161#ifndef __WXUNIVERSAL__
cc2b7472
VZ
162 // Native resource loading (implemented in src/msw/nativdlg.cpp)
163 // FIXME: should they really be all virtual?
bfc6fde4
VZ
164 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
165 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
42e69d6b
VZ
166 wxWindow* GetWindowChild1(wxWindowID id);
167 wxWindow* GetWindowChild(wxWindowID id);
1e6feb95 168#endif // __WXUNIVERSAL__
2bda0e17 169
f6bcfd97
BP
170 // a MSW only function which sends a size event to the window using its
171 // current size - this has an effect of refreshing the window layout
3cfcd50b
GT
172/*
173FUNCTION IS NOW A MEMBER OF wxFrame - gt
f6bcfd97 174 void SendSizeEvent();
3cfcd50b 175*/
f6bcfd97 176
cc2b7472
VZ
177 // implementation from now on
178 // --------------------------
2bda0e17 179
cc2b7472
VZ
180 // simple accessors
181 // ----------------
2bda0e17 182
d7c24517
VZ
183 WXHWND GetHWND() const { return m_hWnd; }
184 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
185 virtual WXWidget GetHandle() const { return GetHWND(); }
2bda0e17 186
cc2b7472
VZ
187 bool GetUseCtl3D() const { return m_useCtl3D; }
188 bool GetTransparentBackground() const { return m_backgroundTransparent; }
189 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
2bda0e17 190
cc2b7472
VZ
191 // event handlers
192 // --------------
00c4e897
VZ
193
194 void OnSetFocus(wxFocusEvent& event);
bfc6fde4 195 void OnEraseBackground(wxEraseEvent& event);
bfc6fde4 196 void OnIdle(wxIdleEvent& event);
63da7df7 197 void OnPaint(wxPaintEvent& event);
2bda0e17 198
2bda0e17 199public:
bfc6fde4
VZ
200 // For implementation purposes - sometimes decorations make the client area
201 // smaller
202 virtual wxPoint GetClientAreaOrigin() const;
203
204 // Makes an adjustment to the window position (for example, a frame that has
205 // a toolbar that it manages itself).
206 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
207
208 // Windows subclassing
209 void SubclassWin(WXHWND hWnd);
210 void UnsubclassWin();
bfc6fde4 211
a23fd0e1
VZ
212 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
213 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
bfc6fde4 214
197dd9af 215 wxWindow *FindItem(long id) const;
42e69d6b 216 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
bfc6fde4
VZ
217
218 // Make a Windows extended style from the given wxWindows window style
8d99be5f 219 static WXDWORD MakeExtendedStyle(long style,
df613907 220 bool eliminateBorders = FALSE);
bfc6fde4 221 // Determine whether 3D effects are wanted
8d99be5f 222 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
bfc6fde4 223
bfc6fde4
VZ
224 // MSW only: TRUE if this control is part of the main control
225 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
226
a23fd0e1
VZ
227 // returns TRUE if the window has been created
228 bool MSWCreate(int id,
229 wxWindow *parent,
9df8c2df 230 const wxChar *wclass,
a23fd0e1 231 wxWindow *wx_win,
9df8c2df 232 const wxChar *title,
a23fd0e1
VZ
233 int x, int y, int width, int height,
234 WXDWORD style,
9df8c2df 235 const wxChar *dialog_template = NULL,
a23fd0e1 236 WXDWORD exendedStyle = 0);
42e69d6b 237 virtual bool MSWCommand(WXUINT param, WXWORD id);
bfc6fde4 238
42e69d6b
VZ
239#if WXWIN_COMPATIBILITY
240 wxObject *GetChild(int number) const;
241 virtual void MSWDeviceToLogical(float *x, float *y) const;
242#endif // WXWIN_COMPATIBILITY
bfc6fde4 243
1e6feb95 244#ifndef __WXUNIVERSAL__
bfc6fde4
VZ
245 // Create an appropriate wxWindow from a HWND
246 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
247
248 // Make sure the window style reflects the HWND style (roughly)
249 virtual void AdoptAttributesFromHWND();
1e6feb95 250#endif // __WXUNIVERSAL__
bfc6fde4
VZ
251
252 // Setup background and foreground colours correctly
253 virtual void SetupColours();
254
42e69d6b
VZ
255 // ------------------------------------------------------------------------
256 // helpers for message handlers: these perform the same function as the
257 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
258 // the correct parameters
259 // ------------------------------------------------------------------------
260
261 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
262 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
263 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
264 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
265 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
266 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
267 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
268 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd);
269 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
270 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
271
a23fd0e1 272 // ------------------------------------------------------------------------
3cfcd50b 273 // internal handlers for MSW messages: all handlers return a boolean value:
a23fd0e1
VZ
274 // TRUE means that the handler processed the event and FALSE that it didn't
275 // ------------------------------------------------------------------------
bfc6fde4 276
42e69d6b
VZ
277 // there are several cases where we have virtual functions for Windows
278 // message processing: this is because these messages often require to be
279 // processed in a different manner in the derived classes. For all other
280 // messages, however, we do *not* have corresponding MSWOnXXX() function
281 // and if the derived class wants to process them, it should override
282 // MSWWindowProc() directly.
a23fd0e1 283
42e69d6b 284 // scroll event (both horizontal and vertical)
a23fd0e1
VZ
285 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
286 WXWORD pos, WXHWND control);
287
42e69d6b 288 // child control notifications
a23fd0e1
VZ
289#ifdef __WIN95__
290 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
291#endif // __WIN95__
292
42e69d6b
VZ
293 // owner-drawn controls need to process these messages
294 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
295 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
296
297 // the rest are not virtual
298 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
299 bool HandleInitDialog(WXHWND hWndFocus);
300 bool HandleDestroy();
301
302 bool HandlePaint();
303 bool HandleEraseBkgnd(WXHDC pDC);
304
305 bool HandleMinimize();
306 bool HandleMaximize();
307 bool HandleSize(int x, int y, WXUINT flag);
308 bool HandleGetMinMaxInfo(void *mmInfo);
309
310 bool HandleShow(bool show, int status);
311 bool HandleActivate(int flag, bool minimized, WXHWND activate);
312
313 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
314 bool HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam);
315
316 bool HandleCtlColor(WXHBRUSH *hBrush,
101f488c
VZ
317 WXHDC hdc,
318 WXHWND hWnd,
319 WXUINT nCtlColor,
320 WXUINT message,
321 WXWPARAM wParam,
322 WXLPARAM lParam);
a23fd0e1 323
42e69d6b
VZ
324 bool HandlePaletteChanged(WXHWND hWndPalChange);
325 bool HandleQueryNewPalette();
326 bool HandleSysColorChange();
a23fd0e1 327
42e69d6b
VZ
328 bool HandleQueryEndSession(long logOff, bool *mayEnd);
329 bool HandleEndSession(bool endSession, long logOff);
a23fd0e1 330
42e69d6b
VZ
331 bool HandleSetFocus(WXHWND wnd);
332 bool HandleKillFocus(WXHWND wnd);
bfc6fde4 333
42e69d6b 334 bool HandleDropFiles(WXWPARAM wParam);
bfc6fde4 335
42e69d6b
VZ
336 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
337 bool HandleMouseMove(int x, int y, WXUINT flags);
d2c52078 338 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 339
33ac7e6f
KB
340 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE);
341 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
342 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 343
42e69d6b
VZ
344 bool HandleQueryDragIcon(WXHICON *hIcon);
345
346 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
bfc6fde4 347
bfc6fde4
VZ
348 // Window procedure
349 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
350
351 // Calls an appropriate default window procedure
352 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
353 virtual bool MSWProcessMessage(WXMSG* pMsg);
354 virtual bool MSWTranslateMessage(WXMSG* pMsg);
355 virtual void MSWDestroyWindow();
356
357 // Detach "Window" menu from menu bar so it doesn't get deleted
358 void MSWDetachWindowMenu();
359
a23fd0e1
VZ
360 // this function should return the brush to paint the window background
361 // with or 0 for the default brush
362 virtual WXHBRUSH OnCtlColor(WXHDC hDC,
363 WXHWND hWnd,
364 WXUINT nCtlColor,
365 WXUINT message,
366 WXWPARAM wParam,
367 WXLPARAM lParam);
bfc6fde4 368
cc2b7472
VZ
369#if WXWIN_COMPATIBILITY
370 void SetShowing(bool show) { (void)Show(show); }
371 bool IsUserEnabled() const { return IsEnabled(); }
372#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
373
374 // Responds to colour changes: passes event on to children.
375 void OnSysColourChanged(wxSysColourChangedEvent& event);
376
a23fd0e1
VZ
377 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
378 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
bfc6fde4 379
1e6feb95
VZ
380 // check if mouse is in the window
381 bool IsMouseInWindow() const;
382
2bda0e17 383protected:
d7c24517
VZ
384 // the window handle
385 WXHWND m_hWnd;
386
cc2b7472 387 // the old window proc (we subclass all windows)
bfc6fde4 388 WXFARPROC m_oldWndProc;
2bda0e17 389
cc2b7472
VZ
390 // additional (MSW specific) flags
391 bool m_useCtl3D:1; // Using CTL3D for this control
cc2b7472
VZ
392 bool m_backgroundTransparent:1;
393 bool m_mouseInWindow:1;
394 bool m_doubleClickAllowed:1;
bfc6fde4 395
cc2b7472 396 // the size of one page for scrolling
bfc6fde4
VZ
397 int m_xThumbSize;
398 int m_yThumbSize;
2bda0e17 399
a23fd0e1
VZ
400#if wxUSE_MOUSEEVENT_HACK
401 // the coordinates of the last mouse event and the type of it
cc2b7472
VZ
402 long m_lastMouseX,
403 m_lastMouseY;
404 int m_lastMouseEvent;
a23fd0e1 405#endif // wxUSE_MOUSEEVENT_HACK
bfc6fde4 406
bfc6fde4 407 WXHMENU m_hMenu; // Menu, if any
bfc6fde4 408
101f488c
VZ
409 // the return value of WM_GETDLGCODE handler
410 long m_lDlgCode;
411
cc2b7472 412 // implement the base class pure virtuals
dabc0cd5
VZ
413 virtual void DoClientToScreen( int *x, int *y ) const;
414 virtual void DoScreenToClient( int *x, int *y ) const;
cc2b7472
VZ
415 virtual void DoGetPosition( int *x, int *y ) const;
416 virtual void DoGetSize( int *width, int *height ) const;
417 virtual void DoGetClientSize( int *width, int *height ) const;
418 virtual void DoSetSize(int x, int y,
419 int width, int height,
420 int sizeFlags = wxSIZE_AUTO);
bfc6fde4 421 virtual void DoSetClientSize(int width, int height);
2bda0e17 422
b782f2e0
VZ
423 // move the window to the specified location and resize it: this is called
424 // from both DoSetSize() and DoSetClientSize() and would usually just call
425 // ::MoveWindow() except for composite controls which will want to arrange
426 // themselves inside the given rectangle
427 virtual void DoMoveWindow(int x, int y, int width, int height);
428
cc2b7472
VZ
429#if wxUSE_TOOLTIPS
430 virtual void DoSetToolTip( wxToolTip *tip );
431#endif // wxUSE_TOOLTIPS
432
fd3f686c
VZ
433private:
434 // common part of all ctors
435 void Init();
436
a23fd0e1
VZ
437 // the (non-virtual) handlers for the events
438 bool HandleMove(int x, int y);
439 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
440
441#ifdef __WIN95__
442 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
443#endif // __WIN95__
444
c42404a5
VZ
445 // the helper functions used by HandleChar/KeyXXX methods
446 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
447
1e6feb95
VZ
448 DECLARE_DYNAMIC_CLASS(wxWindowMSW);
449 DECLARE_NO_COPY_CLASS(wxWindowMSW);
fd3f686c 450 DECLARE_EVENT_TABLE()
2bda0e17
KB
451};
452
cc2b7472
VZ
453// ---------------------------------------------------------------------------
454// global functions
455// ---------------------------------------------------------------------------
2bda0e17 456
cc2b7472 457// kbd code translation
184b5d99
JS
458WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
459WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
2bda0e17 460
2bda0e17 461#endif
bbcdf8bc 462 // _WX_WINDOW_H_