]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
fixed a design flaw in wxFontMapper that prevented automatic creation of wxConfig...
[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 // 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__
38
39 // ---------------------------------------------------------------------------
40 // constants
41 // ---------------------------------------------------------------------------
42
43 // FIXME does anybody use those? they're unused by wxWindows...
44 enum
45 {
46 wxKEY_SHIFT = 1,
47 wxKEY_CTRL = 2
48 };
49
50 // ---------------------------------------------------------------------------
51 // wxWindow declaration for MSW
52 // ---------------------------------------------------------------------------
53
54 class WXDLLEXPORT wxWindowMSW : public wxWindowBase
55 {
56 public:
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)
65 {
66 Init();
67 Create(parent, id, pos, size, style, name);
68 }
69
70 virtual ~wxWindowMSW();
71
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);
78
79 // implement base class pure virtuals
80 virtual void SetTitle( const wxString& title);
81 virtual wxString GetTitle() const;
82
83 virtual void Raise();
84 virtual void Lower();
85
86 virtual bool Show( bool show = TRUE );
87 virtual bool Enable( bool enable = TRUE );
88
89 virtual void SetFocus();
90
91 virtual bool Reparent(wxWindowBase *newParent);
92
93 virtual void WarpPointer(int x, int y);
94 virtual void CaptureMouse();
95 virtual void ReleaseMouse();
96
97 virtual void Refresh( bool eraseBackground = TRUE,
98 const wxRect *rect = (const wxRect *) NULL );
99 virtual void Update();
100 virtual void Clear();
101
102 virtual bool SetCursor( const wxCursor &cursor );
103 virtual bool SetFont( const wxFont &font );
104
105 virtual int GetCharHeight() const;
106 virtual int GetCharWidth() const;
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
114 #if wxUSE_MENUS_NATIVE
115 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
116 #endif // wxUSE_MENUS_NATIVE
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 );
126
127 #if wxUSE_DRAG_AND_DROP
128 virtual void SetDropTarget( wxDropTarget *dropTarget );
129 #endif // wxUSE_DRAG_AND_DROP
130
131 // Accept files for dragging
132 virtual void DragAcceptFiles(bool accept);
133
134 #if WXWIN_COMPATIBILITY
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;
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)) { }
148 #endif // WXWIN_COMPATIBILITY
149
150 #if wxUSE_CARET && WXWIN_COMPATIBILITY
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
160
161 #ifndef __WXUNIVERSAL__
162 // Native resource loading (implemented in src/msw/nativdlg.cpp)
163 // FIXME: should they really be all virtual?
164 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
165 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
166 wxWindow* GetWindowChild1(wxWindowID id);
167 wxWindow* GetWindowChild(wxWindowID id);
168 #endif // __WXUNIVERSAL__
169
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
172 /*
173 FUNCTION IS NOW A MEMBER OF wxFrame - gt
174 void SendSizeEvent();
175 */
176
177 // implementation from now on
178 // --------------------------
179
180 // simple accessors
181 // ----------------
182
183 WXHWND GetHWND() const { return m_hWnd; }
184 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
185 virtual WXWidget GetHandle() const { return GetHWND(); }
186
187 bool GetUseCtl3D() const { return m_useCtl3D; }
188 bool GetTransparentBackground() const { return m_backgroundTransparent; }
189 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
190
191 // event handlers
192 // --------------
193
194 void OnSetFocus(wxFocusEvent& event);
195 void OnEraseBackground(wxEraseEvent& event);
196 void OnIdle(wxIdleEvent& event);
197 void OnPaint(wxPaintEvent& event);
198
199 public:
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();
211
212 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
213 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
214
215 wxWindow *FindItem(long id) const;
216 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
217
218 // Make a Windows extended style from the given wxWindows window style
219 static WXDWORD MakeExtendedStyle(long style,
220 bool eliminateBorders = FALSE);
221 // Determine whether 3D effects are wanted
222 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
223
224 // MSW only: TRUE if this control is part of the main control
225 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
226
227 // returns TRUE if the window has been created
228 bool MSWCreate(int id,
229 wxWindow *parent,
230 const wxChar *wclass,
231 wxWindow *wx_win,
232 const wxChar *title,
233 int x, int y, int width, int height,
234 WXDWORD style,
235 const wxChar *dialog_template = NULL,
236 WXDWORD exendedStyle = 0);
237 virtual bool MSWCommand(WXUINT param, WXWORD id);
238
239 #if WXWIN_COMPATIBILITY
240 wxObject *GetChild(int number) const;
241 virtual void MSWDeviceToLogical(float *x, float *y) const;
242 #endif // WXWIN_COMPATIBILITY
243
244 #ifndef __WXUNIVERSAL__
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();
250 #endif // __WXUNIVERSAL__
251
252 // Setup background and foreground colours correctly
253 virtual void SetupColours();
254
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
272 // ------------------------------------------------------------------------
273 // internal handlers for MSW messages: all handlers return a boolean value:
274 // TRUE means that the handler processed the event and FALSE that it didn't
275 // ------------------------------------------------------------------------
276
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.
283
284 // scroll event (both horizontal and vertical)
285 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
286 WXWORD pos, WXHWND control);
287
288 // child control notifications
289 #ifdef __WIN95__
290 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
291 #endif // __WIN95__
292
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,
317 WXHDC hdc,
318 WXHWND hWnd,
319 WXUINT nCtlColor,
320 WXUINT message,
321 WXWPARAM wParam,
322 WXLPARAM lParam);
323
324 bool HandlePaletteChanged(WXHWND hWndPalChange);
325 bool HandleQueryNewPalette();
326 bool HandleSysColorChange();
327
328 bool HandleQueryEndSession(long logOff, bool *mayEnd);
329 bool HandleEndSession(bool endSession, long logOff);
330
331 bool HandleSetFocus(WXHWND wnd);
332 bool HandleKillFocus(WXHWND wnd);
333
334 bool HandleDropFiles(WXWPARAM wParam);
335
336 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
337 bool HandleMouseMove(int x, int y, WXUINT flags);
338 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
339
340 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE);
341 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
342 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
343
344 bool HandleQueryDragIcon(WXHICON *hIcon);
345
346 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
347
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
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);
368
369 #if WXWIN_COMPATIBILITY
370 void SetShowing(bool show) { (void)Show(show); }
371 bool IsUserEnabled() const { return IsEnabled(); }
372 #endif // WXWIN_COMPATIBILITY
373
374 // Responds to colour changes: passes event on to children.
375 void OnSysColourChanged(wxSysColourChangedEvent& event);
376
377 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
378 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
379
380 // check if mouse is in the window
381 bool IsMouseInWindow() const;
382
383 protected:
384 // the window handle
385 WXHWND m_hWnd;
386
387 // the old window proc (we subclass all windows)
388 WXFARPROC m_oldWndProc;
389
390 // additional (MSW specific) flags
391 bool m_useCtl3D:1; // Using CTL3D for this control
392 bool m_backgroundTransparent:1;
393 bool m_mouseInWindow:1;
394 bool m_doubleClickAllowed:1;
395
396 // the size of one page for scrolling
397 int m_xThumbSize;
398 int m_yThumbSize;
399
400 #if wxUSE_MOUSEEVENT_HACK
401 // the coordinates of the last mouse event and the type of it
402 long m_lastMouseX,
403 m_lastMouseY;
404 int m_lastMouseEvent;
405 #endif // wxUSE_MOUSEEVENT_HACK
406
407 WXHMENU m_hMenu; // Menu, if any
408
409 // the return value of WM_GETDLGCODE handler
410 long m_lDlgCode;
411
412 // implement the base class pure virtuals
413 virtual void DoClientToScreen( int *x, int *y ) const;
414 virtual void DoScreenToClient( int *x, int *y ) const;
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);
421 virtual void DoSetClientSize(int width, int height);
422
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
429 #if wxUSE_TOOLTIPS
430 virtual void DoSetToolTip( wxToolTip *tip );
431 #endif // wxUSE_TOOLTIPS
432
433 private:
434 // common part of all ctors
435 void Init();
436
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
445 // the helper functions used by HandleChar/KeyXXX methods
446 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
447
448 DECLARE_DYNAMIC_CLASS(wxWindowMSW);
449 DECLARE_NO_COPY_CLASS(wxWindowMSW);
450 DECLARE_EVENT_TABLE()
451 };
452
453 // ---------------------------------------------------------------------------
454 // global functions
455 // ---------------------------------------------------------------------------
456
457 // kbd code translation
458 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
459 WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
460
461 #endif
462 // _WX_WINDOW_H_