]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
wxWindow split (MSW part of changes)
[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 // windows.h #defines the following identifiers which are also used in wxWin
24 #ifdef GetCharWidth
25 #undef GetCharWidth
26 #endif
27
28 #ifdef FindWindow
29 #undef FindWindow
30 #endif
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 Raise();
81 virtual void Lower();
82
83 virtual bool Show( bool show = TRUE );
84 virtual bool Enable( bool enable = TRUE );
85
86 virtual void SetFocus();
87
88 virtual bool Reparent( wxWindow *newParent );
89
90 virtual void WarpPointer(int x, int y);
91 virtual void CaptureMouse();
92 virtual void ReleaseMouse();
93
94 virtual void Refresh( bool eraseBackground = TRUE,
95 const wxRect *rect = (const wxRect *) NULL );
96 virtual void Clear();
97
98 virtual bool SetCursor( const wxCursor &cursor );
99 virtual bool SetFont( const wxFont &font );
100
101 virtual int GetCharHeight() const;
102 virtual int GetCharWidth() const;
103 virtual void GetTextExtent(const wxString& string,
104 int *x, int *y,
105 int *descent = (int *) NULL,
106 int *externalLeading = (int *) NULL,
107 const wxFont *theFont = (const wxFont *) NULL)
108 const;
109
110 virtual void ClientToScreen( int *x, int *y ) const;
111 virtual void ScreenToClient( int *x, int *y ) 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 #endif // WXWIN_COMPATIBILITY
138
139 // caret manipulation (MSW only)
140 virtual void CreateCaret(int w, int h);
141 virtual void CreateCaret(const wxBitmap *bitmap);
142 virtual void DestroyCaret();
143 virtual void ShowCaret(bool show);
144 virtual void SetCaretPos(int x, int y);
145 virtual void GetCaretPos(int *x, int *y) const;
146
147 // event handlers (FIXME: shouldn't they be inside WXWIN_COMPATIBILITY?)
148 // Handle a control command
149 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
150
151 // Override to define new behaviour for default action (e.g. double
152 // clicking on a listbox)
153 virtual void OnDefaultAction(wxControl *initiatingItem);
154
155 // Native resource loading (implemented in src/msw/nativdlg.cpp)
156 // FIXME: should they really be all virtual?
157 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
158 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
159 virtual wxWindow* GetWindowChild1(wxWindowID id);
160 virtual wxWindow* GetWindowChild(wxWindowID id);
161
162 // implementation from now on
163 // --------------------------
164
165 // simple accessors
166 // ----------------
167
168 WXHWND GetHWND() const { return GetHandle(); }
169 void SetHWND(WXHWND hWnd) { m_widget = hWnd; }
170
171 bool GetUseCtl3D() const { return m_useCtl3D; }
172 bool GetTransparentBackground() const { return m_backgroundTransparent; }
173 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
174
175 // event handlers
176 // --------------
177 void OnEraseBackground(wxEraseEvent& event);
178 void OnKeyDown(wxKeyEvent& event);
179 void OnKeyUp(wxKeyEvent& event);
180 void OnPaint(wxPaintEvent& event);
181 void OnChar(wxKeyEvent& 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 virtual long Default();
202 virtual bool MSWCommand(WXUINT param, WXWORD id);
203
204 // returns TRUE if the event was processed
205 virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result);
206
207 virtual wxWindow *FindItem(int id) const;
208 virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ;
209 virtual void PreDelete(WXHDC dc); // Allows system cleanup
210
211 // Make a Windows extended style from the given wxWindows window style
212 virtual WXDWORD MakeExtendedStyle(long style, bool eliminateBorders = TRUE);
213 // Determine whether 3D effects are wanted
214 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
215
216 // MSW only: TRUE if this control is part of the main control
217 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
218
219 wxObject *GetChild(int number) const ;
220
221 void MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
222 int x, int y, int width, int height,
223 WXDWORD style, const char *dialog_template = NULL,
224 WXDWORD exendedStyle = 0);
225
226 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
227 virtual void MSWDeviceToLogical(float *x, float *y) const ;
228
229 // Create an appropriate wxWindow from a HWND
230 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
231
232 // Make sure the window style reflects the HWND style (roughly)
233 virtual void AdoptAttributesFromHWND();
234
235 // Setup background and foreground colours correctly
236 virtual void SetupColours();
237
238 // Saves the last message information before calling base version
239 virtual bool ProcessEvent(wxEvent& event);
240
241 // Handlers
242 virtual void MSWOnCreate(WXLPCREATESTRUCT cs);
243 virtual bool MSWOnPaint();
244 virtual WXHICON MSWOnQueryDragIcon() { return 0; }
245 virtual void MSWOnSize(int x, int y, WXUINT flag);
246 virtual void MSWOnWindowPosChanging(void *lpPos);
247 virtual void MSWOnHScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
248 virtual void MSWOnVScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
249 virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
250 virtual long MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam);
251 virtual long MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam);
252 virtual WXHBRUSH MSWOnCtlColor(WXHDC dc, WXHWND pWnd, WXUINT nCtlColor,
253 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
254 virtual bool MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
255 virtual long MSWOnPaletteChanged(WXHWND hWndPalChange);
256 virtual long MSWOnQueryNewPalette();
257 virtual bool MSWOnEraseBkgnd(WXHDC pDC);
258 virtual void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu);
259 virtual void MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem);
260 virtual bool MSWOnClose();
261 // Return TRUE to end session, FALSE to veto end session.
262 virtual bool MSWOnQueryEndSession(long logOff);
263 virtual bool MSWOnEndSession(bool endSession, long logOff);
264 virtual bool MSWOnDestroy();
265 virtual bool MSWOnSetFocus(WXHWND wnd);
266 virtual bool MSWOnKillFocus(WXHWND wnd);
267 virtual void MSWOnDropFiles(WXWPARAM wParam);
268 virtual bool MSWOnInitDialog(WXHWND hWndFocus);
269 virtual void MSWOnShow(bool show, int status);
270
271 // TODO: rationalise these functions into 1 or 2 which take the
272 // event type as argument.
273 virtual void MSWOnLButtonDown(int x, int y, WXUINT flags);
274 virtual void MSWOnLButtonUp(int x, int y, WXUINT flags);
275 virtual void MSWOnLButtonDClick(int x, int y, WXUINT flags);
276
277 virtual void MSWOnMButtonDown(int x, int y, WXUINT flags);
278 virtual void MSWOnMButtonUp(int x, int y, WXUINT flags);
279 virtual void MSWOnMButtonDClick(int x, int y, WXUINT flags);
280
281 virtual void MSWOnRButtonDown(int x, int y, WXUINT flags);
282 virtual void MSWOnRButtonUp(int x, int y, WXUINT flags);
283 virtual void MSWOnRButtonDClick(int x, int y, WXUINT flags);
284
285 virtual void MSWOnMouseMove(int x, int y, WXUINT flags);
286 virtual void MSWOnMouseEnter(int x, int y, WXUINT flags);
287 virtual void MSWOnMouseLeave(int x, int y, WXUINT flags);
288
289 // These return TRUE if an event handler was found, FALSE otherwise (not processed)
290 virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
291 virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam);
292 virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam);
293
294 virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate);
295 virtual long MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate);
296
297 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
298 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
299
300 virtual void MSWOnJoyDown(int joystick, int x, int y, WXUINT flags);
301 virtual void MSWOnJoyUp(int joystick, int x, int y, WXUINT flags);
302 virtual void MSWOnJoyMove(int joystick, int x, int y, WXUINT flags);
303 virtual void MSWOnJoyZMove(int joystick, int z, WXUINT flags);
304
305 virtual long MSWGetDlgCode();
306
307 // Window procedure
308 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
309
310 // Calls an appropriate default window procedure
311 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
312 virtual bool MSWProcessMessage(WXMSG* pMsg);
313 virtual bool MSWTranslateMessage(WXMSG* pMsg);
314 virtual void MSWDestroyWindow();
315
316 // Detach "Window" menu from menu bar so it doesn't get deleted
317 void MSWDetachWindowMenu();
318
319 inline WXFARPROC MSWGetOldWndProc() const;
320 inline void MSWSetOldWndProc(WXFARPROC proc);
321
322 // Define for each class of dialog and control
323 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
324 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
325
326 #if WXWIN_COMPATIBILITY
327 void SetShowing(bool show) { (void)Show(show); }
328 bool IsUserEnabled() const { return IsEnabled(); }
329 #endif // WXWIN_COMPATIBILITY
330
331 // Responds to colour changes: passes event on to children.
332 void OnSysColourChanged(wxSysColourChangedEvent& event);
333
334 // remember the parameters of the last message
335 void PushLastMessage(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
336 {
337 m_lastMsg = msg;
338 m_lastWParam = wParam;
339 m_lastLParam = lParam;
340 }
341
342 protected:
343 // the old window proc (we subclass all windows)
344 WXFARPROC m_oldWndProc;
345
346 // additional (MSW specific) flags
347 bool m_useCtl3D:1; // Using CTL3D for this control
348 bool m_inOnSize:1; // Protection against OnSize reentry
349 bool m_backgroundTransparent:1;
350 bool m_mouseInWindow:1;
351 bool m_doubleClickAllowed:1;
352 bool m_winCaptured:1;
353
354 // Caret data
355 bool m_caretEnabled:1;
356 bool m_caretShown:1;
357 int m_caretWidth;
358 int m_caretHeight;
359
360 // the size of one page for scrolling
361 int m_xThumbSize;
362 int m_yThumbSize;
363
364 // the coordinates of the last mouse event and the typoe of it
365 long m_lastMouseX,
366 m_lastMouseY;
367 int m_lastMouseEvent;
368
369 // the parameters of the last message used in Default()
370 WXUINT m_lastMsg;
371 WXWPARAM m_lastWParam;
372 WXLPARAM m_lastLParam;
373
374 WXHMENU m_hMenu; // Menu, if any
375
376 wxButton *m_btnDefault;
377
378 // implement the base class pure virtuals
379 virtual void DoGetPosition( int *x, int *y ) const;
380 virtual void DoGetSize( int *width, int *height ) const;
381 virtual void DoGetClientSize( int *width, int *height ) const;
382 virtual void DoSetSize(int x, int y,
383 int width, int height,
384 int sizeFlags = wxSIZE_AUTO);
385 virtual void DoSetClientSize(int width, int height);
386
387 #if wxUSE_TOOLTIPS
388 virtual void DoSetToolTip( wxToolTip *tip );
389 #endif // wxUSE_TOOLTIPS
390
391 private:
392 // common part of all ctors
393 void Init();
394
395 DECLARE_EVENT_TABLE()
396 };
397
398 // ---------------------------------------------------------------------------
399 // global functions
400 // ---------------------------------------------------------------------------
401
402 // kbd code translation
403 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
404 WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
405
406 #endif
407 // _WX_WINDOW_H_