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