]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
GetHandle() added (back)
[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 m_hWnd; }
169 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
170 virtual WXWidget GetHandle() const { return GetHWND(); }
171
172 bool GetUseCtl3D() const { return m_useCtl3D; }
173 bool GetTransparentBackground() const { return m_backgroundTransparent; }
174 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
175
176 // event handlers
177 // --------------
178 void OnEraseBackground(wxEraseEvent& event);
179 void OnKeyDown(wxKeyEvent& event);
180 void OnKeyUp(wxKeyEvent& event);
181 void OnPaint(wxPaintEvent& event);
182 void OnChar(wxKeyEvent& event);
183 void OnIdle(wxIdleEvent& event);
184
185 // a window may have a default button
186 // TODO move into wxPanel and/or wxFrame
187 wxButton *GetDefaultItem() const { return m_btnDefault; }
188 void SetDefaultItem(wxButton *btn) { m_btnDefault = btn; }
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 virtual long Default();
203 virtual bool MSWCommand(WXUINT param, WXWORD id);
204
205 // returns TRUE if the event was processed
206 virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result);
207
208 virtual wxWindow *FindItem(int id) const;
209 virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ;
210 virtual void PreDelete(WXHDC dc); // Allows system cleanup
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 wxObject *GetChild(int number) const ;
221
222 void MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
223 int x, int y, int width, int height,
224 WXDWORD style, const char *dialog_template = NULL,
225 WXDWORD exendedStyle = 0);
226
227 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
228 virtual void MSWDeviceToLogical(float *x, float *y) const ;
229
230 // Create an appropriate wxWindow from a HWND
231 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
232
233 // Make sure the window style reflects the HWND style (roughly)
234 virtual void AdoptAttributesFromHWND();
235
236 // Setup background and foreground colours correctly
237 virtual void SetupColours();
238
239 // Saves the last message information before calling base version
240 virtual bool ProcessEvent(wxEvent& event);
241
242 // Handlers
243 virtual void MSWOnCreate(WXLPCREATESTRUCT cs);
244 virtual bool MSWOnPaint();
245 virtual WXHICON MSWOnQueryDragIcon() { return 0; }
246 virtual void MSWOnSize(int x, int y, WXUINT flag);
247 virtual void MSWOnWindowPosChanging(void *lpPos);
248 virtual void MSWOnHScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
249 virtual void MSWOnVScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
250 virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
251 virtual long MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam);
252 virtual long MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam);
253 virtual WXHBRUSH MSWOnCtlColor(WXHDC dc, WXHWND pWnd, WXUINT nCtlColor,
254 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
255 virtual bool MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
256 virtual long MSWOnPaletteChanged(WXHWND hWndPalChange);
257 virtual long MSWOnQueryNewPalette();
258 virtual bool MSWOnEraseBkgnd(WXHDC pDC);
259 virtual void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu);
260 virtual void MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem);
261 virtual bool MSWOnClose();
262 // Return TRUE to end session, FALSE to veto end session.
263 virtual bool MSWOnQueryEndSession(long logOff);
264 virtual bool MSWOnEndSession(bool endSession, long logOff);
265 virtual bool MSWOnDestroy();
266 virtual bool MSWOnSetFocus(WXHWND wnd);
267 virtual bool MSWOnKillFocus(WXHWND wnd);
268 virtual void MSWOnDropFiles(WXWPARAM wParam);
269 virtual bool MSWOnInitDialog(WXHWND hWndFocus);
270 virtual void MSWOnShow(bool show, int status);
271
272 // TODO: rationalise these functions into 1 or 2 which take the
273 // event type as argument.
274 virtual void MSWOnLButtonDown(int x, int y, WXUINT flags);
275 virtual void MSWOnLButtonUp(int x, int y, WXUINT flags);
276 virtual void MSWOnLButtonDClick(int x, int y, WXUINT flags);
277
278 virtual void MSWOnMButtonDown(int x, int y, WXUINT flags);
279 virtual void MSWOnMButtonUp(int x, int y, WXUINT flags);
280 virtual void MSWOnMButtonDClick(int x, int y, WXUINT flags);
281
282 virtual void MSWOnRButtonDown(int x, int y, WXUINT flags);
283 virtual void MSWOnRButtonUp(int x, int y, WXUINT flags);
284 virtual void MSWOnRButtonDClick(int x, int y, WXUINT flags);
285
286 virtual void MSWOnMouseMove(int x, int y, WXUINT flags);
287 virtual void MSWOnMouseEnter(int x, int y, WXUINT flags);
288 virtual void MSWOnMouseLeave(int x, int y, WXUINT flags);
289
290 // These return TRUE if an event handler was found, FALSE otherwise (not processed)
291 virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
292 virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam);
293 virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam);
294
295 virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate);
296 virtual long MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate);
297
298 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
299 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
300
301 virtual void MSWOnJoyDown(int joystick, int x, int y, WXUINT flags);
302 virtual void MSWOnJoyUp(int joystick, int x, int y, WXUINT flags);
303 virtual void MSWOnJoyMove(int joystick, int x, int y, WXUINT flags);
304 virtual void MSWOnJoyZMove(int joystick, int z, WXUINT flags);
305
306 virtual long MSWGetDlgCode();
307
308 // Window procedure
309 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
310
311 // Calls an appropriate default window procedure
312 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
313 virtual bool MSWProcessMessage(WXMSG* pMsg);
314 virtual bool MSWTranslateMessage(WXMSG* pMsg);
315 virtual void MSWDestroyWindow();
316
317 // Detach "Window" menu from menu bar so it doesn't get deleted
318 void MSWDetachWindowMenu();
319
320 inline WXFARPROC MSWGetOldWndProc() const;
321 inline void MSWSetOldWndProc(WXFARPROC proc);
322
323 // Define for each class of dialog and control
324 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
325 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
326
327 #if WXWIN_COMPATIBILITY
328 void SetShowing(bool show) { (void)Show(show); }
329 bool IsUserEnabled() const { return IsEnabled(); }
330 #endif // WXWIN_COMPATIBILITY
331
332 // Responds to colour changes: passes event on to children.
333 void OnSysColourChanged(wxSysColourChangedEvent& event);
334
335 // remember the parameters of the last message
336 void PushLastMessage(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
337 {
338 m_lastMsg = msg;
339 m_lastWParam = wParam;
340 m_lastLParam = lParam;
341 }
342
343 protected:
344 // the window handle
345 WXHWND m_hWnd;
346
347 // the old window proc (we subclass all windows)
348 WXFARPROC m_oldWndProc;
349
350 // additional (MSW specific) flags
351 bool m_useCtl3D:1; // Using CTL3D for this control
352 bool m_inOnSize:1; // Protection against OnSize reentry
353 bool m_backgroundTransparent:1;
354 bool m_mouseInWindow:1;
355 bool m_doubleClickAllowed:1;
356 bool m_winCaptured:1;
357
358 // Caret data
359 bool m_caretEnabled:1;
360 bool m_caretShown:1;
361 int m_caretWidth;
362 int m_caretHeight;
363
364 // the size of one page for scrolling
365 int m_xThumbSize;
366 int m_yThumbSize;
367
368 // the coordinates of the last mouse event and the typoe of it
369 long m_lastMouseX,
370 m_lastMouseY;
371 int m_lastMouseEvent;
372
373 // the parameters of the last message used in Default()
374 WXUINT m_lastMsg;
375 WXWPARAM m_lastWParam;
376 WXLPARAM m_lastLParam;
377
378 WXHMENU m_hMenu; // Menu, if any
379
380 wxButton *m_btnDefault;
381
382 // implement the base class pure virtuals
383 virtual void DoGetPosition( int *x, int *y ) const;
384 virtual void DoGetSize( int *width, int *height ) const;
385 virtual void DoGetClientSize( int *width, int *height ) const;
386 virtual void DoSetSize(int x, int y,
387 int width, int height,
388 int sizeFlags = wxSIZE_AUTO);
389 virtual void DoSetClientSize(int width, int height);
390
391 #if wxUSE_TOOLTIPS
392 virtual void DoSetToolTip( wxToolTip *tip );
393 #endif // wxUSE_TOOLTIPS
394
395 private:
396 // common part of all ctors
397 void Init();
398
399 DECLARE_EVENT_TABLE()
400 };
401
402 // ---------------------------------------------------------------------------
403 // global functions
404 // ---------------------------------------------------------------------------
405
406 // kbd code translation
407 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
408 WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
409
410 #endif
411 // _WX_WINDOW_H_