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