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