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