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