]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/window.h
added inactive titlebar text colour
[wxWidgets.git] / include / wx / msw / window.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: wx/msw/window.h
2bda0e17
KB
3// Purpose: wxWindow class
4// Author: Julian Smart
1e6feb95
VZ
5// Modified by: Vadim Zeitlin on 13.05.99: complete refont of message handling,
6// elimination of Default(), ...
2bda0e17
KB
7// Created: 01/02/97
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart and Markus Holzem
cc2b7472 10// Licence: wxWindows licence
2bda0e17
KB
11/////////////////////////////////////////////////////////////////////////////
12
bbcdf8bc
JS
13#ifndef _WX_WINDOW_H_
14#define _WX_WINDOW_H_
2bda0e17 15
cc2b7472
VZ
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
cc2b7472 21 #pragma interface "window.h"
2bda0e17
KB
22#endif
23
1e6feb95
VZ
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...
a23fd0e1
VZ
29#define wxUSE_MOUSEEVENT_HACK 0
30
cc2b7472
VZ
31// ---------------------------------------------------------------------------
32// constants
33// ---------------------------------------------------------------------------
1e6d9499 34
cc2b7472
VZ
35// FIXME does anybody use those? they're unused by wxWindows...
36enum
1e6d9499 37{
cc2b7472
VZ
38 wxKEY_SHIFT = 1,
39 wxKEY_CTRL = 2
1e6d9499
JS
40};
41
cc2b7472
VZ
42// ---------------------------------------------------------------------------
43// wxWindow declaration for MSW
44// ---------------------------------------------------------------------------
b782f2e0 45
1e6feb95 46class WXDLLEXPORT wxWindowMSW : public wxWindowBase
1e6d9499 47{
2bda0e17 48public:
1e6feb95
VZ
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)
bfc6fde4
VZ
57 {
58 Init();
59 Create(parent, id, pos, size, style, name);
60 }
2bda0e17 61
1e6feb95 62 virtual ~wxWindowMSW();
2bda0e17 63
cc2b7472
VZ
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);
bfc6fde4 70
cc2b7472 71 // implement base class pure virtuals
42e69d6b
VZ
72 virtual void SetTitle( const wxString& title);
73 virtual wxString GetTitle() const;
74
bfc6fde4 75 virtual void Raise();
bfc6fde4
VZ
76 virtual void Lower();
77
cc2b7472
VZ
78 virtual bool Show( bool show = TRUE );
79 virtual bool Enable( bool enable = TRUE );
bfc6fde4 80
cc2b7472 81 virtual void SetFocus();
bfc6fde4 82
1e6feb95 83 virtual bool Reparent(wxWindowBase *newParent);
bfc6fde4 84
cc2b7472
VZ
85 virtual void WarpPointer(int x, int y);
86 virtual void CaptureMouse();
87 virtual void ReleaseMouse();
bfc6fde4 88
cc2b7472
VZ
89 virtual void Refresh( bool eraseBackground = TRUE,
90 const wxRect *rect = (const wxRect *) NULL );
1e6feb95 91 virtual void Update();
cc2b7472 92 virtual void Clear();
a0e449ff
VZ
93 virtual void Freeze();
94 virtual void Thaw();
bfc6fde4 95
cc2b7472
VZ
96 virtual bool SetCursor( const wxCursor &cursor );
97 virtual bool SetFont( const wxFont &font );
bfc6fde4 98
bfc6fde4
VZ
99 virtual int GetCharHeight() const;
100 virtual int GetCharWidth() const;
cc2b7472
VZ
101 virtual void GetTextExtent(const wxString& string,
102 int *x, int *y,
103 int *descent = (int *) NULL,
104 int *externalLeading = (int *) NULL,
105 const wxFont *theFont = (const wxFont *) NULL)
106 const;
107
1e6feb95 108#if wxUSE_MENUS_NATIVE
a1665b22 109 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
1e6feb95 110#endif // wxUSE_MENUS_NATIVE
cc2b7472
VZ
111
112 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
113 int range, bool refresh = TRUE );
114 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
115 virtual int GetScrollPos( int orient ) const;
116 virtual int GetScrollThumb( int orient ) const;
117 virtual int GetScrollRange( int orient ) const;
118 virtual void ScrollWindow( int dx, int dy,
119 const wxRect* rect = (wxRect *) NULL );
2bda0e17 120
9cd6d737
VZ
121 virtual bool ScrollLines(int lines);
122 virtual bool ScrollPages(int pages);
b9b3393e 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
1e6feb95 158#ifndef __WXUNIVERSAL__
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);
1e6feb95 165#endif // __WXUNIVERSAL__
2bda0e17 166
f6bcfd97
BP
167 // a MSW only function which sends a size event to the window using its
168 // current size - this has an effect of refreshing the window layout
3cfcd50b
GT
169/*
170FUNCTION IS NOW A MEMBER OF wxFrame - gt
f6bcfd97 171 void SendSizeEvent();
3cfcd50b 172*/
f6bcfd97 173
cc2b7472
VZ
174 // implementation from now on
175 // --------------------------
2bda0e17 176
cc2b7472
VZ
177 // simple accessors
178 // ----------------
2bda0e17 179
d7c24517
VZ
180 WXHWND GetHWND() const { return m_hWnd; }
181 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
182 virtual WXWidget GetHandle() const { return GetHWND(); }
2bda0e17 183
cc2b7472
VZ
184 bool GetUseCtl3D() const { return m_useCtl3D; }
185 bool GetTransparentBackground() const { return m_backgroundTransparent; }
186 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
2bda0e17 187
cc2b7472
VZ
188 // event handlers
189 // --------------
00c4e897
VZ
190
191 void OnSetFocus(wxFocusEvent& event);
bfc6fde4 192 void OnEraseBackground(wxEraseEvent& event);
bfc6fde4 193 void OnIdle(wxIdleEvent& event);
63da7df7 194 void OnPaint(wxPaintEvent& event);
2bda0e17 195
2bda0e17 196public:
bfc6fde4
VZ
197 // For implementation purposes - sometimes decorations make the client area
198 // smaller
199 virtual wxPoint GetClientAreaOrigin() const;
200
bfc6fde4
VZ
201 // Windows subclassing
202 void SubclassWin(WXHWND hWnd);
203 void UnsubclassWin();
bfc6fde4 204
a23fd0e1
VZ
205 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
206 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
bfc6fde4 207
197dd9af 208 wxWindow *FindItem(long id) const;
42e69d6b 209 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
bfc6fde4
VZ
210
211 // Make a Windows extended style from the given wxWindows window style
8d99be5f 212 static WXDWORD MakeExtendedStyle(long style,
df613907 213 bool eliminateBorders = FALSE);
bfc6fde4 214 // Determine whether 3D effects are wanted
8d99be5f 215 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
bfc6fde4 216
bfc6fde4
VZ
217 // MSW only: TRUE if this control is part of the main control
218 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
219
b225f659
VZ
220 // translate wxWindows coords into Windows ones suitable to be passed to
221 // ::CreateWindow()
222 //
223 // returns TRUE if non default coords are returned, FALSE otherwise
224 bool MSWGetCreateWindowCoords(const wxPoint& pos,
225 const wxSize& size,
226 int& x, int& y,
227 int& w, int& h) const;
228
229 // creates the window of specified Windows class with given style, extended
230 // style, title and geometry (default values
231 //
232 // returns TRUE if the window has been created, FALSE if creation failed
233 bool MSWCreate(const wxChar *wclass,
234 const wxChar *title = NULL,
235 const wxPoint& pos = wxDefaultPosition,
236 const wxSize& size = wxDefaultSize,
237 WXDWORD style = 0,
a23fd0e1 238 WXDWORD exendedStyle = 0);
b225f659 239
42e69d6b 240 virtual bool MSWCommand(WXUINT param, WXWORD id);
bfc6fde4 241
42e69d6b
VZ
242#if WXWIN_COMPATIBILITY
243 wxObject *GetChild(int number) const;
244 virtual void MSWDeviceToLogical(float *x, float *y) const;
245#endif // WXWIN_COMPATIBILITY
bfc6fde4 246
1e6feb95 247#ifndef __WXUNIVERSAL__
bfc6fde4
VZ
248 // Create an appropriate wxWindow from a HWND
249 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
250
251 // Make sure the window style reflects the HWND style (roughly)
252 virtual void AdoptAttributesFromHWND();
1e6feb95 253#endif // __WXUNIVERSAL__
bfc6fde4
VZ
254
255 // Setup background and foreground colours correctly
256 virtual void SetupColours();
257
42e69d6b
VZ
258 // ------------------------------------------------------------------------
259 // helpers for message handlers: these perform the same function as the
260 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
261 // the correct parameters
262 // ------------------------------------------------------------------------
263
264 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
265 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
266 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
267 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
268 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
269 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
270 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
271 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd);
272 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
273 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
274
a23fd0e1 275 // ------------------------------------------------------------------------
3cfcd50b 276 // internal handlers for MSW messages: all handlers return a boolean value:
a23fd0e1
VZ
277 // TRUE means that the handler processed the event and FALSE that it didn't
278 // ------------------------------------------------------------------------
bfc6fde4 279
42e69d6b
VZ
280 // there are several cases where we have virtual functions for Windows
281 // message processing: this is because these messages often require to be
282 // processed in a different manner in the derived classes. For all other
283 // messages, however, we do *not* have corresponding MSWOnXXX() function
284 // and if the derived class wants to process them, it should override
285 // MSWWindowProc() directly.
a23fd0e1 286
42e69d6b 287 // scroll event (both horizontal and vertical)
a23fd0e1
VZ
288 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
289 WXWORD pos, WXHWND control);
290
42e69d6b 291 // child control notifications
a23fd0e1
VZ
292#ifdef __WIN95__
293 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
294#endif // __WIN95__
295
42e69d6b
VZ
296 // owner-drawn controls need to process these messages
297 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
298 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
299
300 // the rest are not virtual
301 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
302 bool HandleInitDialog(WXHWND hWndFocus);
303 bool HandleDestroy();
304
305 bool HandlePaint();
306 bool HandleEraseBkgnd(WXHDC pDC);
307
308 bool HandleMinimize();
309 bool HandleMaximize();
310 bool HandleSize(int x, int y, WXUINT flag);
311 bool HandleGetMinMaxInfo(void *mmInfo);
312
313 bool HandleShow(bool show, int status);
314 bool HandleActivate(int flag, bool minimized, WXHWND activate);
315
316 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
317 bool HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam);
318
319 bool HandleCtlColor(WXHBRUSH *hBrush,
101f488c
VZ
320 WXHDC hdc,
321 WXHWND hWnd,
322 WXUINT nCtlColor,
323 WXUINT message,
324 WXWPARAM wParam,
325 WXLPARAM lParam);
a23fd0e1 326
42e69d6b
VZ
327 bool HandlePaletteChanged(WXHWND hWndPalChange);
328 bool HandleQueryNewPalette();
329 bool HandleSysColorChange();
a23fd0e1 330
42e69d6b
VZ
331 bool HandleQueryEndSession(long logOff, bool *mayEnd);
332 bool HandleEndSession(bool endSession, long logOff);
a23fd0e1 333
42e69d6b
VZ
334 bool HandleSetFocus(WXHWND wnd);
335 bool HandleKillFocus(WXHWND wnd);
bfc6fde4 336
42e69d6b 337 bool HandleDropFiles(WXWPARAM wParam);
bfc6fde4 338
42e69d6b
VZ
339 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
340 bool HandleMouseMove(int x, int y, WXUINT flags);
d2c52078 341 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 342
33ac7e6f
KB
343 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE);
344 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
345 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 346
42e69d6b
VZ
347 bool HandleQueryDragIcon(WXHICON *hIcon);
348
349 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
bfc6fde4 350
bfc6fde4
VZ
351 // Window procedure
352 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
353
354 // Calls an appropriate default window procedure
355 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
a37d422a
VZ
356
357 // message processing helpers
358
359 // return FALSE if the message shouldn't be translated/preprocessed but
360 // dispatched normally
361 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
362
363 // return TRUE if the message was preprocessed and shouldn't be dispatched
bfc6fde4 364 virtual bool MSWProcessMessage(WXMSG* pMsg);
a37d422a
VZ
365
366 // return TRUE if the message was translated and shouldn't be dispatched
bfc6fde4 367 virtual bool MSWTranslateMessage(WXMSG* pMsg);
a37d422a
VZ
368
369 // called when the window is about to be destroyed
bfc6fde4
VZ
370 virtual void MSWDestroyWindow();
371
372 // Detach "Window" menu from menu bar so it doesn't get deleted
373 void MSWDetachWindowMenu();
374
a23fd0e1
VZ
375 // this function should return the brush to paint the window background
376 // with or 0 for the default brush
377 virtual WXHBRUSH OnCtlColor(WXHDC hDC,
378 WXHWND hWnd,
379 WXUINT nCtlColor,
380 WXUINT message,
381 WXWPARAM wParam,
382 WXLPARAM lParam);
bfc6fde4 383
cc2b7472
VZ
384#if WXWIN_COMPATIBILITY
385 void SetShowing(bool show) { (void)Show(show); }
386 bool IsUserEnabled() const { return IsEnabled(); }
387#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
388
389 // Responds to colour changes: passes event on to children.
390 void OnSysColourChanged(wxSysColourChangedEvent& event);
391
a23fd0e1
VZ
392 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
393 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
bfc6fde4 394
1e6feb95
VZ
395 // check if mouse is in the window
396 bool IsMouseInWindow() const;
397
2bda0e17 398protected:
d7c24517
VZ
399 // the window handle
400 WXHWND m_hWnd;
401
cc2b7472 402 // the old window proc (we subclass all windows)
bfc6fde4 403 WXFARPROC m_oldWndProc;
2bda0e17 404
cc2b7472
VZ
405 // additional (MSW specific) flags
406 bool m_useCtl3D:1; // Using CTL3D for this control
cc2b7472
VZ
407 bool m_backgroundTransparent:1;
408 bool m_mouseInWindow:1;
409 bool m_doubleClickAllowed:1;
bfc6fde4 410
cc2b7472 411 // the size of one page for scrolling
bfc6fde4
VZ
412 int m_xThumbSize;
413 int m_yThumbSize;
2bda0e17 414
a23fd0e1
VZ
415#if wxUSE_MOUSEEVENT_HACK
416 // the coordinates of the last mouse event and the type of it
cc2b7472
VZ
417 long m_lastMouseX,
418 m_lastMouseY;
419 int m_lastMouseEvent;
a23fd0e1 420#endif // wxUSE_MOUSEEVENT_HACK
bfc6fde4 421
bfc6fde4 422 WXHMENU m_hMenu; // Menu, if any
bfc6fde4 423
101f488c
VZ
424 // the return value of WM_GETDLGCODE handler
425 long m_lDlgCode;
426
cc2b7472 427 // implement the base class pure virtuals
dabc0cd5
VZ
428 virtual void DoClientToScreen( int *x, int *y ) const;
429 virtual void DoScreenToClient( int *x, int *y ) const;
cc2b7472
VZ
430 virtual void DoGetPosition( int *x, int *y ) const;
431 virtual void DoGetSize( int *width, int *height ) const;
432 virtual void DoGetClientSize( int *width, int *height ) const;
433 virtual void DoSetSize(int x, int y,
434 int width, int height,
435 int sizeFlags = wxSIZE_AUTO);
bfc6fde4 436 virtual void DoSetClientSize(int width, int height);
2bda0e17 437
b782f2e0
VZ
438 // move the window to the specified location and resize it: this is called
439 // from both DoSetSize() and DoSetClientSize() and would usually just call
440 // ::MoveWindow() except for composite controls which will want to arrange
441 // themselves inside the given rectangle
442 virtual void DoMoveWindow(int x, int y, int width, int height);
443
cc2b7472
VZ
444#if wxUSE_TOOLTIPS
445 virtual void DoSetToolTip( wxToolTip *tip );
446#endif // wxUSE_TOOLTIPS
447
b09bda68
VZ
448 // the helper functions used by HandleChar/KeyXXX methods
449 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
450
fd3f686c
VZ
451private:
452 // common part of all ctors
453 void Init();
454
a23fd0e1
VZ
455 // the (non-virtual) handlers for the events
456 bool HandleMove(int x, int y);
457 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
458
459#ifdef __WIN95__
460 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
461#endif // __WIN95__
462
e8e4fa12
GT
463 DECLARE_DYNAMIC_CLASS(wxWindowMSW)
464 DECLARE_NO_COPY_CLASS(wxWindowMSW)
fd3f686c 465 DECLARE_EVENT_TABLE()
2bda0e17
KB
466};
467
cc2b7472
VZ
468// ---------------------------------------------------------------------------
469// global functions
470// ---------------------------------------------------------------------------
2bda0e17 471
cc2b7472 472// kbd code translation
184b5d99
JS
473WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
474WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
2bda0e17 475
b225f659
VZ
476// window creation helper class: before creating a new HWND, instantiate an
477// object of this class on stack - this allows to process the messages sent to
478// the window even before CreateWindow() returns
479class wxWindowCreationHook
480{
481public:
482 wxWindowCreationHook(wxWindowMSW *winBeingCreated);
483 ~wxWindowCreationHook();
484};
485
2bda0e17 486#endif
bbcdf8bc 487 // _WX_WINDOW_H_