]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
1. wxMSW seems to work (please test and send your bug reports!)
[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 void ClientToScreen( int *x, int *y ) const;
114 virtual void ScreenToClient( int *x, int *y ) const;
115 wxPoint ClientToScreen(const wxPoint& pt) const
116 { int x = pt.x; int y = pt.y; ClientToScreen(& x, & y); return wxPoint(x, y); }
117 wxPoint ScreenToClient(const wxPoint& pt) const
118 { int x = pt.x; int y = pt.y; ScreenToClient(& x, & y); return wxPoint(x, y); }
119
120 virtual bool PopupMenu( wxMenu *menu, int x, int y );
121
122 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
123 int range, bool refresh = TRUE );
124 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
125 virtual int GetScrollPos( int orient ) const;
126 virtual int GetScrollThumb( int orient ) const;
127 virtual int GetScrollRange( int orient ) const;
128 virtual void ScrollWindow( int dx, int dy,
129 const wxRect* rect = (wxRect *) NULL );
130
131 #if wxUSE_DRAG_AND_DROP
132 virtual void SetDropTarget( wxDropTarget *dropTarget );
133 #endif // wxUSE_DRAG_AND_DROP
134
135 // Accept files for dragging
136 virtual void DragAcceptFiles(bool accept);
137
138 #if WXWIN_COMPATIBILITY
139 // Set/get scroll attributes
140 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
141 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
142 virtual int OldGetScrollRange(int orient) const;
143 virtual int GetScrollPage(int orient) const;
144
145 // event handlers
146 // Handle a control command
147 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
148
149 // Override to define new behaviour for default action (e.g. double
150 // clicking on a listbox)
151 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
152 #endif // WXWIN_COMPATIBILITY
153
154 // caret manipulation (MSW only)
155 virtual void CreateCaret(int w, int h);
156 virtual void CreateCaret(const wxBitmap *bitmap);
157 virtual void DestroyCaret();
158 virtual void ShowCaret(bool show);
159 virtual void SetCaretPos(int x, int y);
160 virtual void GetCaretPos(int *x, int *y) const;
161
162 // Native resource loading (implemented in src/msw/nativdlg.cpp)
163 // FIXME: should they really be all virtual?
164 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
165 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
166 wxWindow* GetWindowChild1(wxWindowID id);
167 wxWindow* GetWindowChild(wxWindowID id);
168
169 // implementation from now on
170 // --------------------------
171
172 // simple accessors
173 // ----------------
174
175 WXHWND GetHWND() const { return m_hWnd; }
176 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
177 virtual WXWidget GetHandle() const { return GetHWND(); }
178
179 bool GetUseCtl3D() const { return m_useCtl3D; }
180 bool GetTransparentBackground() const { return m_backgroundTransparent; }
181 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
182
183 // event handlers
184 // --------------
185 void OnEraseBackground(wxEraseEvent& event);
186 void OnIdle(wxIdleEvent& event);
187
188 // a window may have a default button
189 // TODO move into wxPanel and/or wxFrame
190 wxButton *GetDefaultItem() const { return m_btnDefault; }
191 void SetDefaultItem(wxButton *btn) { m_btnDefault = btn; }
192
193 public:
194 // For implementation purposes - sometimes decorations make the client area
195 // smaller
196 virtual wxPoint GetClientAreaOrigin() const;
197
198 // Makes an adjustment to the window position (for example, a frame that has
199 // a toolbar that it manages itself).
200 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
201
202 // Windows subclassing
203 void SubclassWin(WXHWND hWnd);
204 void UnsubclassWin();
205
206 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
207 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
208
209 wxWindow *FindItem(int id) const;
210 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
211
212 // Make a Windows extended style from the given wxWindows window style
213 virtual WXDWORD MakeExtendedStyle(long style, bool eliminateBorders = TRUE);
214 // Determine whether 3D effects are wanted
215 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
216
217 // MSW only: TRUE if this control is part of the main control
218 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
219
220 // returns TRUE if the window has been created
221 bool MSWCreate(int id,
222 wxWindow *parent,
223 const char *wclass,
224 wxWindow *wx_win,
225 const char *title,
226 int x, int y, int width, int height,
227 WXDWORD style,
228 const char *dialog_template = NULL,
229 WXDWORD exendedStyle = 0);
230 virtual bool MSWCommand(WXUINT param, WXWORD id);
231
232 #if WXWIN_COMPATIBILITY
233 wxObject *GetChild(int number) const;
234 virtual void MSWDeviceToLogical(float *x, float *y) const;
235 #endif // WXWIN_COMPATIBILITY
236
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();
242
243 // Setup background and foreground colours correctly
244 virtual void SetupColours();
245
246 // ------------------------------------------------------------------------
247 // helpers for message handlers: these perform the same function as the
248 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
249 // the correct parameters
250 // ------------------------------------------------------------------------
251
252 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
253 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
254 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
255 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
256 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
257 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
258 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
259 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd);
260 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
261 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
262
263 // ------------------------------------------------------------------------
264 // internal handlers for MSW messages: all handlers return a boolen value:
265 // TRUE means that the handler processed the event and FALSE that it didn't
266 // ------------------------------------------------------------------------
267
268 // there are several cases where we have virtual functions for Windows
269 // message processing: this is because these messages often require to be
270 // processed in a different manner in the derived classes. For all other
271 // messages, however, we do *not* have corresponding MSWOnXXX() function
272 // and if the derived class wants to process them, it should override
273 // MSWWindowProc() directly.
274
275 // scroll event (both horizontal and vertical)
276 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
277 WXWORD pos, WXHWND control);
278
279 // child control notifications
280 #ifdef __WIN95__
281 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
282 #endif // __WIN95__
283
284 // owner-drawn controls need to process these messages
285 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
286 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
287
288 // the rest are not virtual
289 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
290 bool HandleInitDialog(WXHWND hWndFocus);
291 bool HandleDestroy();
292
293 bool HandlePaint();
294 bool HandleEraseBkgnd(WXHDC pDC);
295
296 bool HandleMinimize();
297 bool HandleMaximize();
298 bool HandleSize(int x, int y, WXUINT flag);
299 bool HandleGetMinMaxInfo(void *mmInfo);
300
301 bool HandleShow(bool show, int status);
302 bool HandleActivate(int flag, bool minimized, WXHWND activate);
303
304 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
305 bool HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam);
306
307 bool HandleCtlColor(WXHBRUSH *hBrush,
308 WXHDC hdc,
309 WXHWND hWnd,
310 WXUINT nCtlColor,
311 WXUINT message,
312 WXWPARAM wParam,
313 WXLPARAM lParam);
314
315 bool HandlePaletteChanged(WXHWND hWndPalChange);
316 bool HandleQueryNewPalette();
317 bool HandleSysColorChange();
318
319 bool HandleQueryEndSession(long logOff, bool *mayEnd);
320 bool HandleEndSession(bool endSession, long logOff);
321
322 bool HandleSetFocus(WXHWND wnd);
323 bool HandleKillFocus(WXHWND wnd);
324
325 bool HandleDropFiles(WXWPARAM wParam);
326
327 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
328 bool HandleMouseMove(int x, int y, WXUINT flags);
329
330 bool HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
331 bool HandleKeyDown(WXWORD wParam, WXLPARAM lParam);
332 bool HandleKeyUp(WXWORD wParam, WXLPARAM lParam);
333
334 bool HandleQueryDragIcon(WXHICON *hIcon);
335
336 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
337
338 // Window procedure
339 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
340
341 // Calls an appropriate default window procedure
342 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
343 virtual bool MSWProcessMessage(WXMSG* pMsg);
344 virtual bool MSWTranslateMessage(WXMSG* pMsg);
345 virtual void MSWDestroyWindow();
346
347 // Detach "Window" menu from menu bar so it doesn't get deleted
348 void MSWDetachWindowMenu();
349
350 // this function should return the brush to paint the window background
351 // with or 0 for the default brush
352 virtual WXHBRUSH OnCtlColor(WXHDC hDC,
353 WXHWND hWnd,
354 WXUINT nCtlColor,
355 WXUINT message,
356 WXWPARAM wParam,
357 WXLPARAM lParam);
358
359 #if WXWIN_COMPATIBILITY
360 void SetShowing(bool show) { (void)Show(show); }
361 bool IsUserEnabled() const { return IsEnabled(); }
362 #endif // WXWIN_COMPATIBILITY
363
364 // Responds to colour changes: passes event on to children.
365 void OnSysColourChanged(wxSysColourChangedEvent& event);
366
367 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
368 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
369
370 protected:
371 // the window handle
372 WXHWND m_hWnd;
373
374 // the old window proc (we subclass all windows)
375 WXFARPROC m_oldWndProc;
376
377 // additional (MSW specific) flags
378 bool m_useCtl3D:1; // Using CTL3D for this control
379 bool m_backgroundTransparent:1;
380 bool m_mouseInWindow:1;
381 bool m_doubleClickAllowed:1;
382 bool m_winCaptured:1;
383
384 // Caret data
385 bool m_caretEnabled:1;
386 bool m_caretShown:1;
387 int m_caretWidth;
388 int m_caretHeight;
389
390 // the size of one page for scrolling
391 int m_xThumbSize;
392 int m_yThumbSize;
393
394 #if wxUSE_MOUSEEVENT_HACK
395 // the coordinates of the last mouse event and the type of it
396 long m_lastMouseX,
397 m_lastMouseY;
398 int m_lastMouseEvent;
399 #endif // wxUSE_MOUSEEVENT_HACK
400
401 WXHMENU m_hMenu; // Menu, if any
402
403 wxButton *m_btnDefault;
404
405 // implement the base class pure virtuals
406 virtual void DoGetPosition( int *x, int *y ) const;
407 virtual void DoGetSize( int *width, int *height ) const;
408 virtual void DoGetClientSize( int *width, int *height ) const;
409 virtual void DoSetSize(int x, int y,
410 int width, int height,
411 int sizeFlags = wxSIZE_AUTO);
412 virtual void DoSetClientSize(int width, int height);
413
414 #if wxUSE_TOOLTIPS
415 virtual void DoSetToolTip( wxToolTip *tip );
416 #endif // wxUSE_TOOLTIPS
417
418 private:
419 // common part of all ctors
420 void Init();
421
422 // the (non-virtual) handlers for the events
423 bool HandleMove(int x, int y);
424 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
425
426 #ifdef __WIN95__
427 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
428 #endif // __WIN95__
429
430 DECLARE_NO_COPY_CLASS(wxWindow);
431 DECLARE_EVENT_TABLE()
432 };
433
434 // ---------------------------------------------------------------------------
435 // global functions
436 // ---------------------------------------------------------------------------
437
438 // kbd code translation
439 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
440 WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
441
442 #endif
443 // _WX_WINDOW_H_