]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/window.h
don't process VK_OEM_XXX key presses
[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();
bfc6fde4 93
cc2b7472
VZ
94 virtual bool SetCursor( const wxCursor &cursor );
95 virtual bool SetFont( const wxFont &font );
bfc6fde4 96
bfc6fde4
VZ
97 virtual int GetCharHeight() const;
98 virtual int GetCharWidth() const;
cc2b7472
VZ
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
1e6feb95 106#if wxUSE_MENUS_NATIVE
a1665b22 107 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
1e6feb95 108#endif // wxUSE_MENUS_NATIVE
cc2b7472
VZ
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 );
2bda0e17 118
47d67540 119#if wxUSE_DRAG_AND_DROP
cc2b7472
VZ
120 virtual void SetDropTarget( wxDropTarget *dropTarget );
121#endif // wxUSE_DRAG_AND_DROP
9f3362c4 122
bfc6fde4
VZ
123 // Accept files for dragging
124 virtual void DragAcceptFiles(bool accept);
2bda0e17 125
2bda0e17 126#if WXWIN_COMPATIBILITY
bfc6fde4
VZ
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;
42e69d6b
VZ
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)) { }
cc2b7472 140#endif // WXWIN_COMPATIBILITY
bfc6fde4 141
34636400 142#if wxUSE_CARET && WXWIN_COMPATIBILITY
789295bf
VZ
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
bfc6fde4 152
1e6feb95 153#ifndef __WXUNIVERSAL__
cc2b7472
VZ
154 // Native resource loading (implemented in src/msw/nativdlg.cpp)
155 // FIXME: should they really be all virtual?
bfc6fde4
VZ
156 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
157 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
42e69d6b
VZ
158 wxWindow* GetWindowChild1(wxWindowID id);
159 wxWindow* GetWindowChild(wxWindowID id);
1e6feb95 160#endif // __WXUNIVERSAL__
2bda0e17 161
f6bcfd97
BP
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
3cfcd50b
GT
164/*
165FUNCTION IS NOW A MEMBER OF wxFrame - gt
f6bcfd97 166 void SendSizeEvent();
3cfcd50b 167*/
f6bcfd97 168
cc2b7472
VZ
169 // implementation from now on
170 // --------------------------
2bda0e17 171
cc2b7472
VZ
172 // simple accessors
173 // ----------------
2bda0e17 174
d7c24517
VZ
175 WXHWND GetHWND() const { return m_hWnd; }
176 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
177 virtual WXWidget GetHandle() const { return GetHWND(); }
2bda0e17 178
cc2b7472
VZ
179 bool GetUseCtl3D() const { return m_useCtl3D; }
180 bool GetTransparentBackground() const { return m_backgroundTransparent; }
181 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
2bda0e17 182
cc2b7472
VZ
183 // event handlers
184 // --------------
00c4e897
VZ
185
186 void OnSetFocus(wxFocusEvent& event);
bfc6fde4 187 void OnEraseBackground(wxEraseEvent& event);
bfc6fde4 188 void OnIdle(wxIdleEvent& event);
63da7df7 189 void OnPaint(wxPaintEvent& event);
2bda0e17 190
2bda0e17 191public:
bfc6fde4
VZ
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();
bfc6fde4 203
a23fd0e1
VZ
204 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
205 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
bfc6fde4 206
197dd9af 207 wxWindow *FindItem(long id) const;
42e69d6b 208 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
bfc6fde4
VZ
209
210 // Make a Windows extended style from the given wxWindows window style
8d99be5f 211 static WXDWORD MakeExtendedStyle(long style,
df613907 212 bool eliminateBorders = FALSE);
bfc6fde4 213 // Determine whether 3D effects are wanted
8d99be5f 214 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
bfc6fde4 215
bfc6fde4
VZ
216 // MSW only: TRUE if this control is part of the main control
217 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
218
a23fd0e1
VZ
219 // returns TRUE if the window has been created
220 bool MSWCreate(int id,
221 wxWindow *parent,
9df8c2df 222 const wxChar *wclass,
a23fd0e1 223 wxWindow *wx_win,
9df8c2df 224 const wxChar *title,
a23fd0e1
VZ
225 int x, int y, int width, int height,
226 WXDWORD style,
9df8c2df 227 const wxChar *dialog_template = NULL,
a23fd0e1 228 WXDWORD exendedStyle = 0);
42e69d6b 229 virtual bool MSWCommand(WXUINT param, WXWORD id);
bfc6fde4 230
42e69d6b
VZ
231#if WXWIN_COMPATIBILITY
232 wxObject *GetChild(int number) const;
233 virtual void MSWDeviceToLogical(float *x, float *y) const;
234#endif // WXWIN_COMPATIBILITY
bfc6fde4 235
1e6feb95 236#ifndef __WXUNIVERSAL__
bfc6fde4
VZ
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();
1e6feb95 242#endif // __WXUNIVERSAL__
bfc6fde4
VZ
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);
d2c52078 330 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 331
33ac7e6f
KB
332 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE);
333 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
334 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
bfc6fde4 335
42e69d6b
VZ
336 bool HandleQueryDragIcon(WXHICON *hIcon);
337
338 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
bfc6fde4 339
bfc6fde4
VZ
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
a23fd0e1
VZ
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);
bfc6fde4 360
cc2b7472
VZ
361#if WXWIN_COMPATIBILITY
362 void SetShowing(bool show) { (void)Show(show); }
363 bool IsUserEnabled() const { return IsEnabled(); }
364#endif // WXWIN_COMPATIBILITY
bfc6fde4
VZ
365
366 // Responds to colour changes: passes event on to children.
367 void OnSysColourChanged(wxSysColourChangedEvent& event);
368
a23fd0e1
VZ
369 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
370 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
bfc6fde4 371
1e6feb95
VZ
372 // check if mouse is in the window
373 bool IsMouseInWindow() const;
374
2bda0e17 375protected:
d7c24517
VZ
376 // the window handle
377 WXHWND m_hWnd;
378
cc2b7472 379 // the old window proc (we subclass all windows)
bfc6fde4 380 WXFARPROC m_oldWndProc;
2bda0e17 381
cc2b7472
VZ
382 // additional (MSW specific) flags
383 bool m_useCtl3D:1; // Using CTL3D for this control
cc2b7472
VZ
384 bool m_backgroundTransparent:1;
385 bool m_mouseInWindow:1;
386 bool m_doubleClickAllowed:1;
bfc6fde4 387
cc2b7472 388 // the size of one page for scrolling
bfc6fde4
VZ
389 int m_xThumbSize;
390 int m_yThumbSize;
2bda0e17 391
a23fd0e1
VZ
392#if wxUSE_MOUSEEVENT_HACK
393 // the coordinates of the last mouse event and the type of it
cc2b7472
VZ
394 long m_lastMouseX,
395 m_lastMouseY;
396 int m_lastMouseEvent;
a23fd0e1 397#endif // wxUSE_MOUSEEVENT_HACK
bfc6fde4 398
bfc6fde4 399 WXHMENU m_hMenu; // Menu, if any
bfc6fde4 400
101f488c
VZ
401 // the return value of WM_GETDLGCODE handler
402 long m_lDlgCode;
403
cc2b7472 404 // implement the base class pure virtuals
dabc0cd5
VZ
405 virtual void DoClientToScreen( int *x, int *y ) const;
406 virtual void DoScreenToClient( int *x, int *y ) const;
cc2b7472
VZ
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);
bfc6fde4 413 virtual void DoSetClientSize(int width, int height);
2bda0e17 414
b782f2e0
VZ
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
cc2b7472
VZ
421#if wxUSE_TOOLTIPS
422 virtual void DoSetToolTip( wxToolTip *tip );
423#endif // wxUSE_TOOLTIPS
424
fd3f686c
VZ
425private:
426 // common part of all ctors
427 void Init();
428
a23fd0e1
VZ
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
c42404a5
VZ
437 // the helper functions used by HandleChar/KeyXXX methods
438 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
439
1e6feb95
VZ
440 DECLARE_DYNAMIC_CLASS(wxWindowMSW);
441 DECLARE_NO_COPY_CLASS(wxWindowMSW);
fd3f686c 442 DECLARE_EVENT_TABLE()
2bda0e17
KB
443};
444
cc2b7472
VZ
445// ---------------------------------------------------------------------------
446// global functions
447// ---------------------------------------------------------------------------
2bda0e17 448
cc2b7472 449// kbd code translation
184b5d99
JS
450WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
451WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
2bda0e17 452
2bda0e17 453#endif
bbcdf8bc 454 // _WX_WINDOW_H_