]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
File/dir dialog styles and other changes (patch 1488371):
[wxWidgets.git] / include / wx / msw / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/window.h
3 // Purpose: wxWindowMSW 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 // constants
18 // ---------------------------------------------------------------------------
19
20 #if WXWIN_COMPATIBILITY_2_4
21 // they're unused by wxWidgets...
22 enum
23 {
24 wxKEY_SHIFT = 1,
25 wxKEY_CTRL = 2
26 };
27 #endif
28
29 // ---------------------------------------------------------------------------
30 // wxWindow declaration for MSW
31 // ---------------------------------------------------------------------------
32
33 class WXDLLEXPORT wxWindowMSW : public wxWindowBase
34 {
35 friend class wxSpinCtrl;
36 friend class wxSlider;
37 friend class wxRadioBox;
38 #if defined __VISUALC__ && __VISUALC__ <= 1200
39 friend class wxWindowMSW;
40 #endif
41 public:
42 wxWindowMSW() { Init(); }
43
44 wxWindowMSW(wxWindow *parent,
45 wxWindowID id,
46 const wxPoint& pos = wxDefaultPosition,
47 const wxSize& size = wxDefaultSize,
48 long style = 0,
49 const wxString& name = wxPanelNameStr)
50 {
51 Init();
52 Create(parent, id, pos, size, style, name);
53 }
54
55 virtual ~wxWindowMSW();
56
57 bool Create(wxWindow *parent,
58 wxWindowID id,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = 0,
62 const wxString& name = wxPanelNameStr);
63
64 // implement base class pure virtuals
65 virtual void SetLabel(const wxString& label);
66 virtual wxString GetLabel() const;
67
68 virtual void Raise();
69 virtual void Lower();
70
71 virtual bool Show( bool show = true );
72 virtual bool Enable( bool enable = true );
73
74 virtual void SetFocus();
75 virtual void SetFocusFromKbd();
76
77 virtual bool Reparent(wxWindowBase *newParent);
78
79 virtual void WarpPointer(int x, int y);
80
81 virtual void Refresh( bool eraseBackground = true,
82 const wxRect *rect = (const wxRect *) NULL );
83 virtual void Update();
84 virtual void Freeze();
85 virtual void Thaw();
86
87 virtual void SetWindowStyleFlag( long style );
88 virtual bool SetCursor( const wxCursor &cursor );
89 virtual bool SetFont( const wxFont &font );
90
91 virtual int GetCharHeight() const;
92 virtual int GetCharWidth() const;
93 virtual void GetTextExtent(const wxString& string,
94 int *x, int *y,
95 int *descent = (int *) NULL,
96 int *externalLeading = (int *) NULL,
97 const wxFont *theFont = (const wxFont *) NULL)
98 const;
99
100 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
101 int range, bool refresh = true );
102 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
103 virtual int GetScrollPos( int orient ) const;
104 virtual int GetScrollThumb( int orient ) const;
105 virtual int GetScrollRange( int orient ) const;
106 virtual void ScrollWindow( int dx, int dy,
107 const wxRect* rect = (wxRect *) NULL );
108
109 virtual bool ScrollLines(int lines);
110 virtual bool ScrollPages(int pages);
111
112 #if wxUSE_DRAG_AND_DROP
113 virtual void SetDropTarget( wxDropTarget *dropTarget );
114 #endif // wxUSE_DRAG_AND_DROP
115
116 // Accept files for dragging
117 virtual void DragAcceptFiles(bool accept);
118
119 #if WXWIN_COMPATIBILITY_2_4
120 wxDEPRECATED( bool GetUseCtl3D() const );
121 wxDEPRECATED( bool GetTransparentBackground() const );
122 wxDEPRECATED( void SetTransparent(bool t = true) );
123 #endif // WXWIN_COMPATIBILITY_2_4
124
125 #ifndef __WXUNIVERSAL__
126 // Native resource loading (implemented in src/msw/nativdlg.cpp)
127 // FIXME: should they really be all virtual?
128 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
129 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
130 wxWindow* GetWindowChild1(wxWindowID id);
131 wxWindow* GetWindowChild(wxWindowID id);
132 #endif // __WXUNIVERSAL__
133
134 #if wxUSE_HOTKEY
135 // install and deinstall a system wide hotkey
136 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
137 virtual bool UnregisterHotKey(int hotkeyId);
138 #endif // wxUSE_HOTKEY
139
140 #ifdef __POCKETPC__
141 bool IsContextMenuEnabled() const { return m_contextMenuEnabled; }
142 void EnableContextMenu(bool enable = true) { m_contextMenuEnabled = enable; }
143 #endif
144
145 // window handle stuff
146 // -------------------
147
148 WXHWND GetHWND() const { return m_hWnd; }
149 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
150 virtual WXWidget GetHandle() const { return GetHWND(); }
151
152 void AssociateHandle(WXWidget handle);
153 void DissociateHandle();
154
155 // does this window have deferred position and/or size?
156 bool IsSizeDeferred() const;
157
158
159 // implementation from now on
160 // ==========================
161
162 // event handlers
163 // --------------
164
165 void OnPaint(wxPaintEvent& event);
166 void OnEraseBackground(wxEraseEvent& event);
167 #ifdef __WXWINCE__
168 void OnInitDialog(wxInitDialogEvent& event);
169 #endif
170
171 public:
172 // Windows subclassing
173 void SubclassWin(WXHWND hWnd);
174 void UnsubclassWin();
175
176 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
177 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
178
179 // return true if the window is of a standard (i.e. not wxWidgets') class
180 //
181 // to understand why does it work, look at SubclassWin() code and comments
182 bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
183
184 wxWindow *FindItem(long id) const;
185 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
186
187 // MSW only: true if this control is part of the main control
188 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; };
189
190 #if wxUSE_TOOLTIPS
191 // MSW only: true if this window or any of its children have a tooltip
192 virtual bool HasToolTips() const { return GetToolTip() != NULL; }
193 #endif // wxUSE_TOOLTIPS
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 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
280
281 // owner-drawn controls need to process these messages
282 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
283 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
284
285 // the rest are not virtual
286 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
287 bool HandleInitDialog(WXHWND hWndFocus);
288 bool HandleDestroy();
289
290 bool HandlePaint();
291 bool HandlePrintClient(WXHDC hDC);
292 bool HandleEraseBkgnd(WXHDC hDC);
293
294 bool HandleMinimize();
295 bool HandleMaximize();
296 bool HandleSize(int x, int y, WXUINT flag);
297 bool HandleSizing(wxRect& rect);
298 bool HandleGetMinMaxInfo(void *mmInfo);
299
300 bool HandleShow(bool show, int status);
301 bool HandleActivate(int flag, bool minimized, WXHWND activate);
302
303 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
304
305 bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
306
307 bool HandlePaletteChanged(WXHWND hWndPalChange);
308 bool HandleQueryNewPalette();
309 bool HandleSysColorChange();
310 bool HandleDisplayChange();
311 bool HandleCaptureChanged(WXHWND gainedCapture);
312 virtual bool HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam);
313
314 bool HandleQueryEndSession(long logOff, bool *mayEnd);
315 bool HandleEndSession(bool endSession, long logOff);
316
317 bool HandleSetFocus(WXHWND wnd);
318 bool HandleKillFocus(WXHWND wnd);
319
320 bool HandleDropFiles(WXWPARAM wParam);
321
322 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
323 bool HandleMouseMove(int x, int y, WXUINT flags);
324 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
325
326 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
327 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
328 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
329 #if wxUSE_ACCEL
330 bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
331 #endif
332 #ifdef __WIN32__
333 int HandleMenuChar(int chAccel, WXLPARAM lParam);
334 #endif
335 // Create and process a clipboard event specified by type.
336 bool HandleClipboardEvent( WXUINT nMsg );
337
338 bool HandleQueryDragIcon(WXHICON *hIcon);
339
340 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
341
342 bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed);
343
344
345 // Window procedure
346 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
347
348 // Calls an appropriate default window procedure
349 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
350
351 // message processing helpers
352
353 // return false if the message shouldn't be translated/preprocessed but
354 // dispatched normally
355 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
356
357 // return true if the message was preprocessed and shouldn't be dispatched
358 virtual bool MSWProcessMessage(WXMSG* pMsg);
359
360 // return true if the message was translated and shouldn't be dispatched
361 virtual bool MSWTranslateMessage(WXMSG* pMsg);
362
363 // called when the window is about to be destroyed
364 virtual void MSWDestroyWindow();
365
366
367 // this function should return the brush to paint the children controls
368 // background or 0 if this window doesn't impose any particular background
369 // on its children
370 //
371 // the base class version returns a solid brush if we have a non default
372 // background colour or 0 otherwise
373 virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd);
374
375 // return the background brush to use for painting the given window by
376 // quering the parent windows via their MSWGetBgBrushForChild() recursively
377 //
378 // hWndToPaint is normally NULL meaning this window itself, but it can also
379 // be a child of this window which is used by the static box and could be
380 // potentially useful for other transparent controls
381 WXHBRUSH MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint = NULL);
382
383 // gives the parent the possibility to draw its children background, e.g.
384 // this is used by wxNotebook to do it using DrawThemeBackground()
385 //
386 // return true if background was drawn, false otherwise
387 virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child))
388 {
389 return false;
390 }
391
392 // some controls (e.g. wxListBox) need to set the return value themselves
393 //
394 // return true to let parent handle it if we don't, false otherwise
395 virtual bool MSWShouldPropagatePrintChild()
396 {
397 return true;
398 }
399
400
401 // Responds to colour changes: passes event on to children.
402 void OnSysColourChanged(wxSysColourChangedEvent& event);
403
404 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
405 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
406
407 // check if mouse is in the window
408 bool IsMouseInWindow() const;
409
410 // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
411 void GenerateMouseLeave();
412
413 // virtual function for implementing internal idle
414 // behaviour
415 virtual void OnInternalIdle();
416
417 protected:
418
419 #if wxUSE_MENUS_NATIVE
420 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
421 #endif // wxUSE_MENUS_NATIVE
422
423 // the window handle
424 WXHWND m_hWnd;
425
426 // the old window proc (we subclass all windows)
427 WXFARPROC m_oldWndProc;
428
429 // additional (MSW specific) flags
430 bool m_mouseInWindow:1;
431 bool m_lastKeydownProcessed:1;
432
433 // the size of one page for scrolling
434 int m_xThumbSize;
435 int m_yThumbSize;
436
437 // implement the base class pure virtuals
438 virtual void DoClientToScreen( int *x, int *y ) const;
439 virtual void DoScreenToClient( int *x, int *y ) const;
440 virtual void DoGetPosition( int *x, int *y ) const;
441 virtual void DoGetSize( int *width, int *height ) const;
442 virtual void DoGetClientSize( int *width, int *height ) const;
443 virtual void DoSetSize(int x, int y,
444 int width, int height,
445 int sizeFlags = wxSIZE_AUTO);
446 virtual void DoSetClientSize(int width, int height);
447
448 virtual void DoCaptureMouse();
449 virtual void DoReleaseMouse();
450
451 // has the window been frozen by Freeze()?
452 bool IsFrozen() const { return m_frozenness > 0; }
453
454 // this simply moves/resizes the given HWND which is supposed to be our
455 // sibling (this is useful for controls which are composite at MSW level
456 // and for which DoMoveWindow() is not enough)
457 //
458 // returns true if the window move was deferred, false if it was moved
459 // immediately (no error return)
460 bool DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height);
461
462 // move the window to the specified location and resize it: this is called
463 // from both DoSetSize() and DoSetClientSize() and would usually just call
464 // ::MoveWindow() except for composite controls which will want to arrange
465 // themselves inside the given rectangle
466 virtual void DoMoveWindow(int x, int y, int width, int height);
467
468 #if wxUSE_TOOLTIPS
469 virtual void DoSetToolTip( wxToolTip *tip );
470
471 // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
472 // comctl32.dll in our code -- see the function body for more info)
473 bool HandleTooltipNotify(WXUINT code,
474 WXLPARAM lParam,
475 const wxString& ttip);
476 #endif // wxUSE_TOOLTIPS
477
478 // the helper functions used by HandleChar/KeyXXX methods
479 wxKeyEvent CreateKeyEvent(wxEventType evType, int id,
480 WXLPARAM lParam = 0, WXWPARAM wParam = 0) const;
481
482
483 // default OnEraseBackground() implementation, return true if we did erase
484 // the background, false otherwise (i.e. the system should erase it)
485 bool DoEraseBackground(WXHDC hDC);
486
487 // generate WM_CHANGEUISTATE if it's needed for the OS we're running under
488 //
489 // action should be one of the UIS_XXX constants
490 // state should be one or more of the UISF_XXX constants
491 // if action == UIS_INITIALIZE then it doesn't seem to matter what we use
492 // for state as the system will decide for us what needs to be set
493 void MSWUpdateUIState(int action, int state = 0);
494
495 private:
496 // common part of all ctors
497 void Init();
498
499 // the (non-virtual) handlers for the events
500 bool HandleMove(int x, int y);
501 bool HandleMoving(wxRect& rect);
502 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
503 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
504
505 // list of disabled children before last call to our Disable()
506 wxWindowList *m_childrenDisabled;
507
508 // number of calls to Freeze() minus number of calls to Thaw()
509 unsigned int m_frozenness;
510
511 // current defer window position operation handle (may be NULL)
512 WXHANDLE m_hDWP;
513
514 // When deferred positioning is done these hold the pending changes, and
515 // are used for the default values if another size/pos changes is done on
516 // this window before the group of deferred changes is completed.
517 wxPoint m_pendingPosition;
518 wxSize m_pendingSize;
519
520 #ifdef __POCKETPC__
521 bool m_contextMenuEnabled;
522 #endif
523
524 DECLARE_DYNAMIC_CLASS(wxWindowMSW)
525 DECLARE_NO_COPY_CLASS(wxWindowMSW)
526 DECLARE_EVENT_TABLE()
527 };
528
529 // ----------------------------------------------------------------------------
530 // inline functions
531 // ----------------------------------------------------------------------------
532
533 #if WXWIN_COMPATIBILITY_2_4
534
535 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
536 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
537 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t)) { }
538
539 #endif // WXWIN_COMPATIBILITY_2_4
540
541 // ---------------------------------------------------------------------------
542 // global functions
543 // ---------------------------------------------------------------------------
544
545 // kbd code translation
546 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
547 WXDLLEXPORT WXWORD wxCharCodeWXToMSW(int id, bool *IsVirtual);
548
549 // window creation helper class: before creating a new HWND, instantiate an
550 // object of this class on stack - this allows to process the messages sent to
551 // the window even before CreateWindow() returns
552 class wxWindowCreationHook
553 {
554 public:
555 wxWindowCreationHook(wxWindowMSW *winBeingCreated);
556 ~wxWindowCreationHook();
557 };
558
559 // ----------------------------------------------------------------------------
560 // global objects
561 // ----------------------------------------------------------------------------
562
563 // notice that this hash must be defined after wxWindow declaration as it
564 // needs to "see" its dtor and not just forward declaration
565 #include "wx/hash.h"
566
567 // pseudo-template HWND <-> wxWindow hash table
568 #if WXWIN_COMPATIBILITY_2_4
569 WX_DECLARE_HASH(wxWindow, wxWindowList, wxWinHashTable);
570 #else
571 WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
572 #endif
573
574 extern wxWinHashTable *wxWinHandleHash;
575
576 #endif // _WX_WINDOW_H_