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