]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
added more reserved functions
[wxWidgets.git] / include / wx / msw / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/window.h
3 // Purpose: wxWindow class
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin on 13.05.99: complete refont of message handling,
6 // elimination of Default(), ...
7 // Created: 01/02/97
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_WINDOW_H_
14 #define _WX_WINDOW_H_
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma interface "window.h"
22 #endif
23
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...
29 #define wxUSE_MOUSEEVENT_HACK 0
30
31 // ---------------------------------------------------------------------------
32 // constants
33 // ---------------------------------------------------------------------------
34
35 #if WXWIN_COMPATIBILITY_2_4
36 // they're unused by wxWidgets...
37 enum
38 {
39 wxKEY_SHIFT = 1,
40 wxKEY_CTRL = 2
41 };
42 #endif
43
44 // ---------------------------------------------------------------------------
45 // wxWindow declaration for MSW
46 // ---------------------------------------------------------------------------
47
48 class WXDLLEXPORT wxWindowMSW : public wxWindowBase
49 {
50 public:
51 wxWindowMSW() { Init(); }
52
53 wxWindowMSW(wxWindow *parent,
54 wxWindowID id,
55 const wxPoint& pos = wxDefaultPosition,
56 const wxSize& size = wxDefaultSize,
57 long style = 0,
58 const wxString& name = wxPanelNameStr)
59 {
60 Init();
61 Create(parent, id, pos, size, style, name);
62 }
63
64 virtual ~wxWindowMSW();
65
66 bool Create(wxWindow *parent,
67 wxWindowID id,
68 const wxPoint& pos = wxDefaultPosition,
69 const wxSize& size = wxDefaultSize,
70 long style = 0,
71 const wxString& name = wxPanelNameStr);
72
73 // implement base class pure virtuals
74 virtual void SetTitle( const wxString& title);
75 virtual wxString GetTitle() const;
76
77 virtual void Raise();
78 virtual void Lower();
79
80 virtual bool Show( bool show = true );
81 virtual bool Enable( bool enable = true );
82
83 virtual void SetFocus();
84 virtual void SetFocusFromKbd();
85
86 virtual bool Reparent(wxWindowBase *newParent);
87
88 virtual void WarpPointer(int x, int y);
89
90 virtual void Refresh( bool eraseBackground = true,
91 const wxRect *rect = (const wxRect *) NULL );
92 virtual void Update();
93 virtual void Freeze();
94 virtual void Thaw();
95
96 virtual void SetWindowStyleFlag( long style );
97 virtual bool SetCursor( const wxCursor &cursor );
98 virtual bool SetFont( const wxFont &font );
99
100 virtual int GetCharHeight() const;
101 virtual int GetCharWidth() const;
102 virtual void GetTextExtent(const wxString& string,
103 int *x, int *y,
104 int *descent = (int *) NULL,
105 int *externalLeading = (int *) NULL,
106 const wxFont *theFont = (const wxFont *) NULL)
107 const;
108
109 #if wxUSE_MENUS_NATIVE
110 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
111 #endif // wxUSE_MENUS_NATIVE
112
113 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
114 int range, bool refresh = true );
115 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
116 virtual int GetScrollPos( int orient ) const;
117 virtual int GetScrollThumb( int orient ) const;
118 virtual int GetScrollRange( int orient ) const;
119 virtual void ScrollWindow( int dx, int dy,
120 const wxRect* rect = (wxRect *) NULL );
121
122 virtual bool ScrollLines(int lines);
123 virtual bool ScrollPages(int pages);
124
125 #if wxUSE_DRAG_AND_DROP
126 virtual void SetDropTarget( wxDropTarget *dropTarget );
127 #endif // wxUSE_DRAG_AND_DROP
128
129 // Accept files for dragging
130 virtual void DragAcceptFiles(bool accept);
131
132 #if WXWIN_COMPATIBILITY_2_4
133 wxDEPRECATED( bool GetUseCtl3D() const );
134 wxDEPRECATED( bool GetTransparentBackground() const );
135 wxDEPRECATED( void SetTransparent(bool t = true) );
136 #endif // WXWIN_COMPATIBILITY_2_4
137
138 #ifndef __WXUNIVERSAL__
139 // Native resource loading (implemented in src/msw/nativdlg.cpp)
140 // FIXME: should they really be all virtual?
141 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
142 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
143 wxWindow* GetWindowChild1(wxWindowID id);
144 wxWindow* GetWindowChild(wxWindowID id);
145 #endif // __WXUNIVERSAL__
146
147 #if wxUSE_HOTKEY
148 // install and deinstall a system wide hotkey
149 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
150 virtual bool UnregisterHotKey(int hotkeyId);
151 #endif // wxUSE_HOTKEY
152
153 // window handle stuff
154 // -------------------
155
156 WXHWND GetHWND() const { return m_hWnd; }
157 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
158 virtual WXWidget GetHandle() const { return GetHWND(); }
159
160 void AssociateHandle(WXWidget handle);
161 void DissociateHandle();
162
163
164 // implementation from now on
165 // ==========================
166
167 // event handlers
168 // --------------
169
170 void OnPaint(wxPaintEvent& event);
171 void OnEraseBackground(wxEraseEvent& event);
172 #ifdef __WXWINCE__
173 void OnInitDialog(wxInitDialogEvent& event);
174 #endif
175
176 public:
177 // Windows subclassing
178 void SubclassWin(WXHWND hWnd);
179 void UnsubclassWin();
180
181 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
182 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
183
184 // return true if the window is of a standard (i.e. not wxWidgets') class
185 //
186 // to understand why does it work, look at SubclassWin() code and comments
187 bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
188
189 wxWindow *FindItem(long id) const;
190 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
191
192 // MSW only: true if this control is part of the main control
193 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; };
194
195 // translate wxWidgets style flags for this control into the Windows style
196 // and optional extended style for the corresponding native control
197 //
198 // this is the function that should be overridden in the derived classes,
199 // but you will mostly use MSWGetCreateWindowFlags() below
200 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const ;
201
202 // get the MSW window flags corresponding to wxWidgets ones
203 //
204 // the functions returns the flags (WS_XXX) directly and puts the ext
205 // (WS_EX_XXX) flags into the provided pointer if not NULL
206 WXDWORD MSWGetCreateWindowFlags(WXDWORD *exflags = NULL) const
207 { return MSWGetStyle(GetWindowStyle(), exflags); }
208
209 // translate wxWidgets coords into Windows ones suitable to be passed to
210 // ::CreateWindow()
211 //
212 // returns true if non default coords are returned, false otherwise
213 bool MSWGetCreateWindowCoords(const wxPoint& pos,
214 const wxSize& size,
215 int& x, int& y,
216 int& w, int& h) const;
217
218 // get the HWND to be used as parent of this window with CreateWindow()
219 virtual WXHWND MSWGetParent() const;
220
221 // creates the window of specified Windows class with given style, extended
222 // style, title and geometry (default values
223 //
224 // returns true if the window has been created, false if creation failed
225 bool MSWCreate(const wxChar *wclass,
226 const wxChar *title = NULL,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& size = wxDefaultSize,
229 WXDWORD style = 0,
230 WXDWORD exendedStyle = 0);
231
232 virtual bool MSWCommand(WXUINT param, WXWORD id);
233
234 #ifndef __WXUNIVERSAL__
235 // Create an appropriate wxWindow from a HWND
236 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
237
238 // Make sure the window style reflects the HWND style (roughly)
239 virtual void AdoptAttributesFromHWND();
240 #endif // __WXUNIVERSAL__
241
242 // Setup background and foreground colours correctly
243 virtual void SetupColours();
244
245 // ------------------------------------------------------------------------
246 // helpers for message handlers: these perform the same function as the
247 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
248 // the correct parameters
249 // ------------------------------------------------------------------------
250
251 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
252 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
253 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
254 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
255 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
256 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
257 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
258 WXHDC *hdc, WXHWND *hwnd);
259 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
260 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
261
262 // ------------------------------------------------------------------------
263 // internal handlers for MSW messages: all handlers return a boolean value:
264 // true means that the handler processed the event and false that it didn't
265 // ------------------------------------------------------------------------
266
267 // there are several cases where we have virtual functions for Windows
268 // message processing: this is because these messages often require to be
269 // processed in a different manner in the derived classes. For all other
270 // messages, however, we do *not* have corresponding MSWOnXXX() function
271 // and if the derived class wants to process them, it should override
272 // MSWWindowProc() directly.
273
274 // scroll event (both horizontal and vertical)
275 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
276 WXWORD pos, WXHWND control);
277
278 // child control notifications
279 #ifdef __WIN95__
280 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
281 #endif // __WIN95__
282
283 // owner-drawn controls need to process these messages
284 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
285 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
286
287 // the rest are not virtual
288 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
289 bool HandleInitDialog(WXHWND hWndFocus);
290 bool HandleDestroy();
291
292 bool HandlePaint();
293 bool HandlePrintClient(WXHDC hDC);
294 bool HandleEraseBkgnd(WXHDC hDC);
295
296 bool HandleMinimize();
297 bool HandleMaximize();
298 bool HandleSize(int x, int y, WXUINT flag);
299 bool HandleSizing(wxRect& rect);
300 bool HandleGetMinMaxInfo(void *mmInfo);
301
302 bool HandleShow(bool show, int status);
303 bool HandleActivate(int flag, bool minimized, WXHWND activate);
304
305 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
306
307 bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
308
309 bool HandlePaletteChanged(WXHWND hWndPalChange);
310 bool HandleQueryNewPalette();
311 bool HandleSysColorChange();
312 bool HandleDisplayChange();
313 bool HandleCaptureChanged(WXHWND gainedCapture);
314
315 bool HandleQueryEndSession(long logOff, bool *mayEnd);
316 bool HandleEndSession(bool endSession, long logOff);
317
318 bool HandleSetFocus(WXHWND wnd);
319 bool HandleKillFocus(WXHWND wnd);
320
321 bool HandleDropFiles(WXWPARAM wParam);
322
323 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
324 bool HandleMouseMove(int x, int y, WXUINT flags);
325 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
326
327 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
328 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
329 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
330 #if wxUSE_ACCEL
331 bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
332 #endif
333 #ifdef __WIN32__
334 int HandleMenuChar(int chAccel, WXLPARAM lParam);
335 #endif
336
337 bool HandleQueryDragIcon(WXHICON *hIcon);
338
339 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
340
341 // Window procedure
342 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
343
344 // Calls an appropriate default window procedure
345 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
346
347 // message processing helpers
348
349 // return false if the message shouldn't be translated/preprocessed but
350 // dispatched normally
351 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
352
353 // return true if the message was preprocessed and shouldn't be dispatched
354 virtual bool MSWProcessMessage(WXMSG* pMsg);
355
356 // return true if the message was translated and shouldn't be dispatched
357 virtual bool MSWTranslateMessage(WXMSG* pMsg);
358
359 // called when the window is about to be destroyed
360 virtual void MSWDestroyWindow();
361
362
363 // this function should return the brush to paint the children controls
364 // background or 0 if this window doesn't impose any particular background
365 // on its children
366 //
367 // the base class version returns a solid brush if we have a non default
368 // background colour or 0 otherwise
369 virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd);
370
371 // return the background brush to use for painting the given window by
372 // quering the parent windows via their MSWGetBgBrushForChild() recursively
373 //
374 // hWndToPaint is normally NULL meaning this window itself, but it can also
375 // be a child of this window which is used by the static box and could be
376 // potentially useful for other transparent controls
377 WXHBRUSH MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint = NULL);
378
379 // gives the parent the possibility to draw its children background, e.g.
380 // this is used by wxNotebook to do it using DrawThemeBackground()
381 //
382 // return true if background was drawn, false otherwise
383 virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child))
384 {
385 return false;
386 }
387
388
389 // Responds to colour changes: passes event on to children.
390 void OnSysColourChanged(wxSysColourChangedEvent& event);
391
392 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
393 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
394
395 // check if mouse is in the window
396 bool IsMouseInWindow() const;
397
398 // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
399 void GenerateMouseLeave();
400
401 // virtual function for implementing internal idle
402 // behaviour
403 virtual void OnInternalIdle();
404
405 protected:
406 // the window handle
407 WXHWND m_hWnd;
408
409 // the old window proc (we subclass all windows)
410 WXFARPROC m_oldWndProc;
411
412 // additional (MSW specific) flags
413 bool m_mouseInWindow:1;
414 bool m_lastKeydownProcessed:1;
415
416 // the size of one page for scrolling
417 int m_xThumbSize;
418 int m_yThumbSize;
419
420 #if wxUSE_MOUSEEVENT_HACK
421 // the coordinates of the last mouse event and the type of it
422 long m_lastMouseX,
423 m_lastMouseY;
424 int m_lastMouseEvent;
425 #endif // wxUSE_MOUSEEVENT_HACK
426
427 // implement the base class pure virtuals
428 virtual void DoClientToScreen( int *x, int *y ) const;
429 virtual void DoScreenToClient( int *x, int *y ) const;
430 virtual void DoGetPosition( int *x, int *y ) const;
431 virtual void DoGetSize( int *width, int *height ) const;
432 virtual void DoGetClientSize( int *width, int *height ) const;
433 virtual void DoSetSize(int x, int y,
434 int width, int height,
435 int sizeFlags = wxSIZE_AUTO);
436 virtual void DoSetClientSize(int width, int height);
437
438 virtual void DoCaptureMouse();
439 virtual void DoReleaseMouse();
440
441 // has the window been frozen by Freeze()?
442 bool IsFrozen() const { return m_frozenness > 0; }
443
444 // move the window to the specified location and resize it: this is called
445 // from both DoSetSize() and DoSetClientSize() and would usually just call
446 // ::MoveWindow() except for composite controls which will want to arrange
447 // themselves inside the given rectangle
448 virtual void DoMoveWindow(int x, int y, int width, int height);
449
450 #if wxUSE_TOOLTIPS
451 virtual void DoSetToolTip( wxToolTip *tip );
452
453 // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
454 // comctl32.dll in our code -- see the function body for more info)
455 bool HandleTooltipNotify(WXUINT code,
456 WXLPARAM lParam,
457 const wxString& ttip);
458 #endif // wxUSE_TOOLTIPS
459
460 // the helper functions used by HandleChar/KeyXXX methods
461 wxKeyEvent CreateKeyEvent(wxEventType evType, int id,
462 WXLPARAM lParam = 0, WXWPARAM wParam = 0) const;
463
464
465 // default OnEraseBackground() implementation, return true if we did erase
466 // the background, false otherwise (i.e. the system should erase it)
467 bool DoEraseBackground(WXHDC hDC);
468
469 private:
470 // common part of all ctors
471 void Init();
472
473 // the (non-virtual) handlers for the events
474 bool HandleMove(int x, int y);
475 bool HandleMoving(wxRect& rect);
476 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
477
478 #ifdef __WIN95__
479 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
480 #endif // __WIN95__
481
482 // list of disabled children before last call to our Disable()
483 wxWindowList *m_childrenDisabled;
484
485 // number of calls to Freeze() minus number of calls to Thaw()
486 unsigned int m_frozenness;
487
488 // current defer window position operation handle (may be NULL)
489 WXHANDLE m_hDWP;
490
491
492 DECLARE_DYNAMIC_CLASS(wxWindowMSW)
493 DECLARE_NO_COPY_CLASS(wxWindowMSW)
494 DECLARE_EVENT_TABLE()
495 };
496
497 // ----------------------------------------------------------------------------
498 // inline functions
499 // ----------------------------------------------------------------------------
500
501 #if WXWIN_COMPATIBILITY_2_4
502
503 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
504 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
505 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t)) { }
506
507 #endif // WXWIN_COMPATIBILITY_2_4
508
509 // ---------------------------------------------------------------------------
510 // global functions
511 // ---------------------------------------------------------------------------
512
513 // kbd code translation
514 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
515 WXDLLEXPORT WXWORD wxCharCodeWXToMSW(int id, bool *IsVirtual);
516
517 // window creation helper class: before creating a new HWND, instantiate an
518 // object of this class on stack - this allows to process the messages sent to
519 // the window even before CreateWindow() returns
520 class wxWindowCreationHook
521 {
522 public:
523 wxWindowCreationHook(wxWindowMSW *winBeingCreated);
524 ~wxWindowCreationHook();
525 };
526
527 // ----------------------------------------------------------------------------
528 // global objects
529 // ----------------------------------------------------------------------------
530
531 // notice that this hash must be defined after wxWindow declaration as it
532 // needs to "see" its dtor and not just forward declaration
533 #include "wx/hash.h"
534
535 // pseudo-template HWND <-> wxWindow hash table
536 #if WXWIN_COMPATIBILITY_2_4
537 WX_DECLARE_HASH(wxWindow, wxWindowList, wxWinHashTable);
538 #else
539 WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
540 #endif
541
542 extern wxWinHashTable *wxWinHandleHash;
543
544 #endif
545 // _WX_WINDOW_H_