]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/window.h
Changed generic wxScrolledWindow -> wxGenericScrolledWindow
[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// ---------------------------------------------------------------------------
b782f2e0 52
cc2b7472 53class WXDLLEXPORT wxWindow : public wxWindowBase
1e6d9499 54{
2bda0e17 55public:
cc2b7472
VZ
56 wxWindow() { Init(); }
57
58 wxWindow(wxWindow *parent,
59 wxWindowID id,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxString& name = wxPanelNameStr)
bfc6fde4
VZ
64 {
65 Init();
66 Create(parent, id, pos, size, style, name);
67 }
2bda0e17 68
bfc6fde4 69 virtual ~wxWindow();
2bda0e17 70
cc2b7472
VZ
71 bool Create(wxWindow *parent,
72 wxWindowID id,
73 const wxPoint& pos = wxDefaultPosition,
74 const wxSize& size = wxDefaultSize,
75 long style = 0,
76 const wxString& name = wxPanelNameStr);
bfc6fde4 77
cc2b7472 78 // implement base class pure virtuals
42e69d6b
VZ
79 virtual void SetTitle( const wxString& title);
80 virtual wxString GetTitle() const;
81
bfc6fde4 82 virtual void Raise();
bfc6fde4
VZ
83 virtual void Lower();
84
cc2b7472
VZ
85 virtual bool Show( bool show = TRUE );
86 virtual bool Enable( bool enable = TRUE );
bfc6fde4 87
cc2b7472 88 virtual void SetFocus();
bfc6fde4 89
cc2b7472 90 virtual bool Reparent( wxWindow *newParent );
bfc6fde4 91
cc2b7472
VZ
92 virtual void WarpPointer(int x, int y);
93 virtual void CaptureMouse();
94 virtual void ReleaseMouse();
bfc6fde4 95
cc2b7472
VZ
96 virtual void Refresh( bool eraseBackground = TRUE,
97 const wxRect *rect = (const wxRect *) NULL );
98 virtual void Clear();
bfc6fde4 99
cc2b7472
VZ
100 virtual bool SetCursor( const wxCursor &cursor );
101 virtual bool SetFont( const wxFont &font );
bfc6fde4 102
bfc6fde4
VZ
103 virtual int GetCharHeight() const;
104 virtual int GetCharWidth() const;
cc2b7472
VZ
105 virtual void GetTextExtent(const wxString& string,
106 int *x, int *y,
107 int *descent = (int *) NULL,
108 int *externalLeading = (int *) NULL,
109 const wxFont *theFont = (const wxFont *) NULL)
110 const;
111
a1665b22 112 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
cc2b7472
VZ
113
114 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
115 int range, bool refresh = TRUE );
116 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
117 virtual int GetScrollPos( int orient ) const;
118 virtual int GetScrollThumb( int orient ) const;
119 virtual int GetScrollRange( int orient ) const;
120 virtual void ScrollWindow( int dx, int dy,
121 const wxRect* rect = (wxRect *) NULL );
2bda0e17 122
47d67540 123#if wxUSE_DRAG_AND_DROP
cc2b7472
VZ
124 virtual void SetDropTarget( wxDropTarget *dropTarget );
125#endif // wxUSE_DRAG_AND_DROP
9f3362c4 126
bfc6fde4
VZ
127 // Accept files for dragging
128 virtual void DragAcceptFiles(bool accept);
2bda0e17 129
2bda0e17 130#if WXWIN_COMPATIBILITY
bfc6fde4
VZ
131 // Set/get scroll attributes
132 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
133 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
134 virtual int OldGetScrollRange(int orient) const;
135 virtual int GetScrollPage(int orient) const;
42e69d6b
VZ
136
137 // event handlers
138 // Handle a control command
139 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
140
141 // Override to define new behaviour for default action (e.g. double
142 // clicking on a listbox)
143 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
cc2b7472 144#endif // WXWIN_COMPATIBILITY
bfc6fde4 145
34636400 146#if wxUSE_CARET && WXWIN_COMPATIBILITY
789295bf
VZ
147 // caret manipulation (old MSW only functions, see wxCaret class for the
148 // new API)
149 void CreateCaret(int w, int h);
150 void CreateCaret(const wxBitmap *bitmap);
151 void DestroyCaret();
152 void ShowCaret(bool show);
153 void SetCaretPos(int x, int y);
154 void GetCaretPos(int *x, int *y) const;
155#endif // wxUSE_CARET
bfc6fde4 156
cc2b7472
VZ
157 // Native resource loading (implemented in src/msw/nativdlg.cpp)
158 // FIXME: should they really be all virtual?
bfc6fde4
VZ
159 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
160 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
42e69d6b
VZ
161 wxWindow* GetWindowChild1(wxWindowID id);
162 wxWindow* GetWindowChild(wxWindowID id);
2bda0e17 163
f6bcfd97
BP
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
3cfcd50b
GT
166/*
167FUNCTION IS NOW A MEMBER OF wxFrame - gt
f6bcfd97 168 void SendSizeEvent();
3cfcd50b 169*/
f6bcfd97 170
cc2b7472
VZ
171 // implementation from now on
172 // --------------------------
2bda0e17 173
cc2b7472
VZ
174 // simple accessors
175 // ----------------
2bda0e17 176
d7c24517
VZ
177 WXHWND GetHWND() const { return m_hWnd; }
178 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
179 virtual WXWidget GetHandle() const { return GetHWND(); }
2bda0e17 180
cc2b7472
VZ
181 bool GetUseCtl3D() const { return m_useCtl3D; }
182 bool GetTransparentBackground() const { return m_backgroundTransparent; }
183 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
2bda0e17 184
cc2b7472
VZ
185 // event handlers
186 // --------------
00c4e897
VZ
187
188 void OnSetFocus(wxFocusEvent& event);
bfc6fde4 189 void OnEraseBackground(wxEraseEvent& event);
bfc6fde4 190 void OnIdle(wxIdleEvent& event);
63da7df7 191 void OnPaint(wxPaintEvent& event);
2bda0e17 192
2bda0e17 193public:
bfc6fde4
VZ
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();
bfc6fde4 205
a23fd0e1
VZ
206 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
207 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
bfc6fde4 208
197dd9af 209 wxWindow *FindItem(long id) const;
42e69d6b 210 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
bfc6fde4
VZ
211
212 // Make a Windows extended style from the given wxWindows window style
8d99be5f 213 static WXDWORD MakeExtendedStyle(long style,
df613907 214 bool eliminateBorders = FALSE);
bfc6fde4 215 // Determine whether 3D effects are wanted
8d99be5f 216 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
bfc6fde4 217
bfc6fde4
VZ
218 // MSW only: TRUE if this control is part of the main control
219 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
220
a23fd0e1
VZ
221 // returns TRUE if the window has been created
222 bool MSWCreate(int id,
223 wxWindow *parent,
9df8c2df 224 const wxChar *wclass,
a23fd0e1 225 wxWindow *wx_win,
9df8c2df 226 const wxChar *title,
a23fd0e1
VZ
227 int x, int y, int width, int height,
228 WXDWORD style,
9df8c2df 229 const wxChar *dialog_template = NULL,
a23fd0e1 230 WXDWORD exendedStyle = 0);
42e69d6b 231 virtual bool MSWCommand(WXUINT param, WXWORD id);
bfc6fde4 232
42e69d6b
VZ
233#if WXWIN_COMPATIBILITY
234 wxObject *GetChild(int number) const;
235 virtual void MSWDeviceToLogical(float *x, float *y) const;
236#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
237
238 // Create an appropriate wxWindow from a HWND
239 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
240
241 // Make sure the window style reflects the HWND style (roughly)
242 virtual void AdoptAttributesFromHWND();
243
244 // Setup background and foreground colours correctly
245 virtual void SetupColours();
246
42e69d6b
VZ
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
a23fd0e1 264 // ------------------------------------------------------------------------
3cfcd50b 265 // internal handlers for MSW messages: all handlers return a boolean value:
a23fd0e1
VZ
266 // TRUE means that the handler processed the event and FALSE that it didn't
267 // ------------------------------------------------------------------------
bfc6fde4 268
42e69d6b
VZ
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.
a23fd0e1 275
42e69d6b 276 // scroll event (both horizontal and vertical)
a23fd0e1
VZ
277 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
278 WXWORD pos, WXHWND control);
279
42e69d6b 280 // child control notifications
a23fd0e1
VZ
281#ifdef __WIN95__
282 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
283#endif // __WIN95__
284
42e69d6b
VZ
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,
101f488c
VZ
309 WXHDC hdc,
310 WXHWND hWnd,
311 WXUINT nCtlColor,
312 WXUINT message,
313 WXWPARAM wParam,
314 WXLPARAM lParam);
a23fd0e1 315
42e69d6b
VZ
316 bool HandlePaletteChanged(WXHWND hWndPalChange);
317 bool HandleQueryNewPalette();
318 bool HandleSysColorChange();
a23fd0e1 319
42e69d6b
VZ
320 bool HandleQueryEndSession(long logOff, bool *mayEnd);
321 bool HandleEndSession(bool endSession, long logOff);
a23fd0e1 322
42e69d6b
VZ
323 bool HandleSetFocus(WXHWND wnd);
324 bool HandleKillFocus(WXHWND wnd);
bfc6fde4 325
42e69d6b 326 bool HandleDropFiles(WXWPARAM wParam);
bfc6fde4 327
42e69d6b
VZ
328 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
329 bool HandleMouseMove(int x, int y, WXUINT flags);
bfc6fde4 330
42e69d6b
VZ
331 bool HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
332 bool HandleKeyDown(WXWORD wParam, WXLPARAM lParam);
333 bool HandleKeyUp(WXWORD wParam, WXLPARAM lParam);
bfc6fde4 334
42e69d6b
VZ
335 bool HandleQueryDragIcon(WXHICON *hIcon);
336
337 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
bfc6fde4 338
bfc6fde4
VZ
339 // Window procedure
340 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
341
342 // Calls an appropriate default window procedure
343 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
344 virtual bool MSWProcessMessage(WXMSG* pMsg);
345 virtual bool MSWTranslateMessage(WXMSG* pMsg);
346 virtual void MSWDestroyWindow();
347
348 // Detach "Window" menu from menu bar so it doesn't get deleted
349 void MSWDetachWindowMenu();
350
a23fd0e1
VZ
351 // this function should return the brush to paint the window background
352 // with or 0 for the default brush
353 virtual WXHBRUSH OnCtlColor(WXHDC hDC,
354 WXHWND hWnd,
355 WXUINT nCtlColor,
356 WXUINT message,
357 WXWPARAM wParam,
358 WXLPARAM lParam);
bfc6fde4 359
cc2b7472
VZ
360#if WXWIN_COMPATIBILITY
361 void SetShowing(bool show) { (void)Show(show); }
362 bool IsUserEnabled() const { return IsEnabled(); }
363#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
364
365 // Responds to colour changes: passes event on to children.
366 void OnSysColourChanged(wxSysColourChangedEvent& event);
367
a23fd0e1
VZ
368 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
369 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
bfc6fde4 370
2bda0e17 371protected:
d7c24517
VZ
372 // the window handle
373 WXHWND m_hWnd;
374
cc2b7472 375 // the old window proc (we subclass all windows)
bfc6fde4 376 WXFARPROC m_oldWndProc;
2bda0e17 377
cc2b7472
VZ
378 // additional (MSW specific) flags
379 bool m_useCtl3D:1; // Using CTL3D for this control
cc2b7472
VZ
380 bool m_backgroundTransparent:1;
381 bool m_mouseInWindow:1;
382 bool m_doubleClickAllowed:1;
383 bool m_winCaptured:1;
bfc6fde4 384
cc2b7472 385 // the size of one page for scrolling
bfc6fde4
VZ
386 int m_xThumbSize;
387 int m_yThumbSize;
2bda0e17 388
a23fd0e1
VZ
389#if wxUSE_MOUSEEVENT_HACK
390 // the coordinates of the last mouse event and the type of it
cc2b7472
VZ
391 long m_lastMouseX,
392 m_lastMouseY;
393 int m_lastMouseEvent;
a23fd0e1 394#endif // wxUSE_MOUSEEVENT_HACK
bfc6fde4 395
bfc6fde4 396 WXHMENU m_hMenu; // Menu, if any
bfc6fde4 397
101f488c
VZ
398 // the return value of WM_GETDLGCODE handler
399 long m_lDlgCode;
400
cc2b7472 401 // implement the base class pure virtuals
dabc0cd5
VZ
402 virtual void DoClientToScreen( int *x, int *y ) const;
403 virtual void DoScreenToClient( int *x, int *y ) const;
cc2b7472
VZ
404 virtual void DoGetPosition( int *x, int *y ) const;
405 virtual void DoGetSize( int *width, int *height ) const;
406 virtual void DoGetClientSize( int *width, int *height ) const;
407 virtual void DoSetSize(int x, int y,
408 int width, int height,
409 int sizeFlags = wxSIZE_AUTO);
bfc6fde4 410 virtual void DoSetClientSize(int width, int height);
2bda0e17 411
b782f2e0
VZ
412 // move the window to the specified location and resize it: this is called
413 // from both DoSetSize() and DoSetClientSize() and would usually just call
414 // ::MoveWindow() except for composite controls which will want to arrange
415 // themselves inside the given rectangle
416 virtual void DoMoveWindow(int x, int y, int width, int height);
417
cc2b7472
VZ
418#if wxUSE_TOOLTIPS
419 virtual void DoSetToolTip( wxToolTip *tip );
420#endif // wxUSE_TOOLTIPS
421
fd3f686c
VZ
422private:
423 // common part of all ctors
424 void Init();
425
a23fd0e1
VZ
426 // the (non-virtual) handlers for the events
427 bool HandleMove(int x, int y);
428 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
429
430#ifdef __WIN95__
431 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
432#endif // __WIN95__
433
c42404a5
VZ
434 // the helper functions used by HandleChar/KeyXXX methods
435 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
436
437 DECLARE_DYNAMIC_CLASS(wxWindow);
a23fd0e1 438 DECLARE_NO_COPY_CLASS(wxWindow);
fd3f686c 439 DECLARE_EVENT_TABLE()
2bda0e17
KB
440};
441
cc2b7472
VZ
442// ---------------------------------------------------------------------------
443// global functions
444// ---------------------------------------------------------------------------
2bda0e17 445
cc2b7472 446// kbd code translation
184b5d99
JS
447WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
448WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
2bda0e17 449
2bda0e17 450#endif
bbcdf8bc 451 // _WX_WINDOW_H_