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