]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | |
cc2b7472 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_WINDOW_H_ |
13 | #define _WX_WINDOW_H_ | |
2bda0e17 | 14 | |
cc2b7472 VZ |
15 | // --------------------------------------------------------------------------- |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
2bda0e17 | 19 | #ifdef __GNUG__ |
cc2b7472 | 20 | #pragma interface "window.h" |
2bda0e17 KB |
21 | #endif |
22 | ||
cc2b7472 VZ |
23 | // windows.h #defines the following identifiers which are also used in wxWin |
24 | #ifdef GetCharWidth | |
25 | #undef GetCharWidth | |
2bda0e17 KB |
26 | #endif |
27 | ||
cc2b7472 VZ |
28 | #ifdef FindWindow |
29 | #undef FindWindow | |
2bda0e17 KB |
30 | #endif |
31 | ||
a23fd0e1 VZ |
32 | // VZ: apparently some version of Windows send extra mouse move messages after |
33 | // a mouse click. My tests under NT 4.0 and 95 didn't show it so I'm | |
34 | // tempted to think that it was just an effect of a poor mouse and so the | |
35 | // code to work around this is currently disabled - just define this as 1 | |
36 | // to reenable it | |
37 | #define wxUSE_MOUSEEVENT_HACK 0 | |
38 | ||
cc2b7472 VZ |
39 | // --------------------------------------------------------------------------- |
40 | // forward declarations | |
41 | // --------------------------------------------------------------------------- | |
2bda0e17 | 42 | |
cc2b7472 | 43 | class WXDLLEXPORT wxButton; |
2bda0e17 | 44 | |
cc2b7472 VZ |
45 | // --------------------------------------------------------------------------- |
46 | // constants | |
47 | // --------------------------------------------------------------------------- | |
1e6d9499 | 48 | |
cc2b7472 VZ |
49 | // FIXME does anybody use those? they're unused by wxWindows... |
50 | enum | |
1e6d9499 | 51 | { |
cc2b7472 VZ |
52 | wxKEY_SHIFT = 1, |
53 | wxKEY_CTRL = 2 | |
1e6d9499 JS |
54 | }; |
55 | ||
cc2b7472 VZ |
56 | // --------------------------------------------------------------------------- |
57 | // wxWindow declaration for MSW | |
58 | // --------------------------------------------------------------------------- | |
59 | class WXDLLEXPORT wxWindow : public wxWindowBase | |
1e6d9499 | 60 | { |
cc2b7472 | 61 | DECLARE_DYNAMIC_CLASS(wxWindow); |
2bda0e17 KB |
62 | |
63 | public: | |
cc2b7472 VZ |
64 | wxWindow() { Init(); } |
65 | ||
66 | wxWindow(wxWindow *parent, | |
67 | wxWindowID id, | |
68 | const wxPoint& pos = wxDefaultPosition, | |
69 | const wxSize& size = wxDefaultSize, | |
70 | long style = 0, | |
71 | const wxString& name = wxPanelNameStr) | |
bfc6fde4 VZ |
72 | { |
73 | Init(); | |
74 | Create(parent, id, pos, size, style, name); | |
75 | } | |
2bda0e17 | 76 | |
bfc6fde4 | 77 | virtual ~wxWindow(); |
2bda0e17 | 78 | |
cc2b7472 VZ |
79 | bool Create(wxWindow *parent, |
80 | wxWindowID id, | |
81 | const wxPoint& pos = wxDefaultPosition, | |
82 | const wxSize& size = wxDefaultSize, | |
83 | long style = 0, | |
84 | const wxString& name = wxPanelNameStr); | |
bfc6fde4 | 85 | |
cc2b7472 | 86 | // implement base class pure virtuals |
bfc6fde4 | 87 | virtual void Raise(); |
bfc6fde4 VZ |
88 | virtual void Lower(); |
89 | ||
cc2b7472 VZ |
90 | virtual bool Show( bool show = TRUE ); |
91 | virtual bool Enable( bool enable = TRUE ); | |
bfc6fde4 | 92 | |
cc2b7472 | 93 | virtual void SetFocus(); |
bfc6fde4 | 94 | |
cc2b7472 | 95 | virtual bool Reparent( wxWindow *newParent ); |
bfc6fde4 | 96 | |
cc2b7472 VZ |
97 | virtual void WarpPointer(int x, int y); |
98 | virtual void CaptureMouse(); | |
99 | virtual void ReleaseMouse(); | |
bfc6fde4 | 100 | |
cc2b7472 VZ |
101 | virtual void Refresh( bool eraseBackground = TRUE, |
102 | const wxRect *rect = (const wxRect *) NULL ); | |
103 | virtual void Clear(); | |
bfc6fde4 | 104 | |
cc2b7472 VZ |
105 | virtual bool SetCursor( const wxCursor &cursor ); |
106 | virtual bool SetFont( const wxFont &font ); | |
bfc6fde4 | 107 | |
bfc6fde4 VZ |
108 | virtual int GetCharHeight() const; |
109 | virtual int GetCharWidth() const; | |
cc2b7472 VZ |
110 | virtual void GetTextExtent(const wxString& string, |
111 | int *x, int *y, | |
112 | int *descent = (int *) NULL, | |
113 | int *externalLeading = (int *) NULL, | |
114 | const wxFont *theFont = (const wxFont *) NULL) | |
115 | const; | |
116 | ||
117 | virtual void ClientToScreen( int *x, int *y ) const; | |
118 | virtual void ScreenToClient( int *x, int *y ) const; | |
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 ); | |
2bda0e17 | 130 | |
47d67540 | 131 | #if wxUSE_DRAG_AND_DROP |
cc2b7472 VZ |
132 | virtual void SetDropTarget( wxDropTarget *dropTarget ); |
133 | #endif // wxUSE_DRAG_AND_DROP | |
9f3362c4 | 134 | |
bfc6fde4 VZ |
135 | // Accept files for dragging |
136 | virtual void DragAcceptFiles(bool accept); | |
2bda0e17 | 137 | |
2bda0e17 | 138 | #if WXWIN_COMPATIBILITY |
bfc6fde4 VZ |
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; | |
cc2b7472 | 144 | #endif // WXWIN_COMPATIBILITY |
bfc6fde4 | 145 | |
cc2b7472 | 146 | // caret manipulation (MSW only) |
bfc6fde4 VZ |
147 | virtual void CreateCaret(int w, int h); |
148 | virtual void CreateCaret(const wxBitmap *bitmap); | |
149 | virtual void DestroyCaret(); | |
150 | virtual void ShowCaret(bool show); | |
151 | virtual void SetCaretPos(int x, int y); | |
152 | virtual void GetCaretPos(int *x, int *y) const; | |
153 | ||
cc2b7472 VZ |
154 | // event handlers (FIXME: shouldn't they be inside WXWIN_COMPATIBILITY?) |
155 | // Handle a control command | |
bfc6fde4 VZ |
156 | virtual void OnCommand(wxWindow& win, wxCommandEvent& event); |
157 | ||
cc2b7472 VZ |
158 | // Override to define new behaviour for default action (e.g. double |
159 | // clicking on a listbox) | |
bfc6fde4 VZ |
160 | virtual void OnDefaultAction(wxControl *initiatingItem); |
161 | ||
cc2b7472 VZ |
162 | // Native resource loading (implemented in src/msw/nativdlg.cpp) |
163 | // FIXME: should they really be all virtual? | |
bfc6fde4 VZ |
164 | virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id); |
165 | virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name); | |
cc2b7472 VZ |
166 | virtual wxWindow* GetWindowChild1(wxWindowID id); |
167 | virtual wxWindow* GetWindowChild(wxWindowID id); | |
2bda0e17 | 168 | |
cc2b7472 VZ |
169 | // implementation from now on |
170 | // -------------------------- | |
2bda0e17 | 171 | |
cc2b7472 VZ |
172 | // simple accessors |
173 | // ---------------- | |
2bda0e17 | 174 | |
d7c24517 VZ |
175 | WXHWND GetHWND() const { return m_hWnd; } |
176 | void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } | |
177 | virtual WXWidget GetHandle() const { return GetHWND(); } | |
2bda0e17 | 178 | |
cc2b7472 VZ |
179 | bool GetUseCtl3D() const { return m_useCtl3D; } |
180 | bool GetTransparentBackground() const { return m_backgroundTransparent; } | |
181 | void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; } | |
2bda0e17 | 182 | |
cc2b7472 VZ |
183 | // event handlers |
184 | // -------------- | |
bfc6fde4 | 185 | void OnEraseBackground(wxEraseEvent& event); |
bfc6fde4 | 186 | void OnIdle(wxIdleEvent& event); |
2bda0e17 | 187 | |
cc2b7472 VZ |
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; } | |
52476186 | 192 | |
2bda0e17 | 193 | public: |
bfc6fde4 VZ |
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(); | |
bfc6fde4 VZ |
205 | virtual bool MSWCommand(WXUINT param, WXWORD id); |
206 | ||
a23fd0e1 VZ |
207 | WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; } |
208 | void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; } | |
bfc6fde4 VZ |
209 | |
210 | virtual wxWindow *FindItem(int id) const; | |
211 | virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ; | |
212 | virtual void PreDelete(WXHDC dc); // Allows system cleanup | |
bfc6fde4 VZ |
213 | |
214 | // Make a Windows extended style from the given wxWindows window style | |
215 | virtual WXDWORD MakeExtendedStyle(long style, bool eliminateBorders = TRUE); | |
216 | // Determine whether 3D effects are wanted | |
217 | virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D); | |
218 | ||
bfc6fde4 VZ |
219 | // MSW only: TRUE if this control is part of the main control |
220 | virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; }; | |
221 | ||
bfc6fde4 VZ |
222 | wxObject *GetChild(int number) const ; |
223 | ||
a23fd0e1 VZ |
224 | // returns TRUE if the window has been created |
225 | bool MSWCreate(int id, | |
226 | wxWindow *parent, | |
227 | const char *wclass, | |
228 | wxWindow *wx_win, | |
229 | const char *title, | |
230 | int x, int y, int width, int height, | |
231 | WXDWORD style, | |
232 | const char *dialog_template = NULL, | |
233 | WXDWORD exendedStyle = 0); | |
bfc6fde4 VZ |
234 | |
235 | // Actually defined in wx_canvs.cc since requires wxCanvas declaration | |
236 | virtual void MSWDeviceToLogical(float *x, float *y) const ; | |
237 | ||
238 | // Create an appropriate wxWindow from a HWND | |
239 | virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd); | |
240 | ||
241 | // Make sure the window style reflects the HWND style (roughly) | |
242 | virtual void AdoptAttributesFromHWND(); | |
243 | ||
244 | // Setup background and foreground colours correctly | |
245 | virtual void SetupColours(); | |
246 | ||
a23fd0e1 VZ |
247 | // ------------------------------------------------------------------------ |
248 | // internal handlers for MSW messages: all handlers return a boolen value: | |
249 | // TRUE means that the handler processed the event and FALSE that it didn't | |
250 | // ------------------------------------------------------------------------ | |
bfc6fde4 | 251 | |
a23fd0e1 VZ |
252 | // TODO: all this should go away, overriding MSWWindowProc() is enough to |
253 | // implement this functionality | |
254 | virtual bool MSWOnCreate(WXLPCREATESTRUCT cs, bool *mayCreate); | |
bfc6fde4 | 255 | virtual bool MSWOnPaint(); |
bfc6fde4 | 256 | virtual bool MSWOnEraseBkgnd(WXHDC pDC); |
a23fd0e1 VZ |
257 | virtual bool MSWOnSize(int x, int y, WXUINT flag); |
258 | ||
259 | virtual bool MSWOnQueryDragIcon(WXHICON *hIcon); | |
260 | virtual bool MSWOnWindowPosChanging(void *lpPos); | |
261 | ||
262 | // both horizontal and vertical | |
263 | virtual bool MSWOnScroll(int orientation, WXWORD nSBCode, | |
264 | WXWORD pos, WXHWND control); | |
265 | ||
266 | virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); | |
267 | virtual bool MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam); | |
268 | ||
269 | #ifdef __WIN95__ | |
270 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); | |
271 | #endif // __WIN95__ | |
272 | ||
273 | virtual bool MSWOnCtlColor(WXHBRUSH *hBrush, | |
274 | WXHDC hdc, | |
275 | WXHWND hWnd, | |
276 | WXUINT nCtlColor, | |
277 | WXUINT message, | |
278 | WXWPARAM wParam, | |
279 | WXLPARAM lParam); | |
280 | ||
281 | virtual bool MSWOnPaletteChanged(WXHWND hWndPalChange); | |
282 | virtual bool MSWOnQueryNewPalette(); | |
283 | ||
284 | virtual bool MSWOnQueryEndSession(long logOff, bool *mayEnd); | |
bfc6fde4 | 285 | virtual bool MSWOnEndSession(bool endSession, long logOff); |
a23fd0e1 | 286 | |
bfc6fde4 VZ |
287 | virtual bool MSWOnDestroy(); |
288 | virtual bool MSWOnSetFocus(WXHWND wnd); | |
289 | virtual bool MSWOnKillFocus(WXHWND wnd); | |
a23fd0e1 | 290 | virtual bool MSWOnDropFiles(WXWPARAM wParam); |
bfc6fde4 | 291 | virtual bool MSWOnInitDialog(WXHWND hWndFocus); |
a23fd0e1 | 292 | virtual bool MSWOnShow(bool show, int status); |
bfc6fde4 | 293 | |
a23fd0e1 VZ |
294 | virtual bool MSWOnMouseEvent(WXUINT msg, int x, int y, WXUINT flags); |
295 | virtual bool MSWOnMouseMove(int x, int y, WXUINT flags); | |
bfc6fde4 | 296 | |
bfc6fde4 | 297 | virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE); |
4d91c1d1 VZ |
298 | virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam); |
299 | virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam); | |
bfc6fde4 VZ |
300 | |
301 | virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate); | |
a23fd0e1 | 302 | virtual bool MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate); |
bfc6fde4 VZ |
303 | |
304 | virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item); | |
305 | virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); | |
306 | ||
bfc6fde4 VZ |
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 | ||
a23fd0e1 VZ |
319 | // this function should return the brush to paint the window background |
320 | // with or 0 for the default brush | |
321 | virtual WXHBRUSH OnCtlColor(WXHDC hDC, | |
322 | WXHWND hWnd, | |
323 | WXUINT nCtlColor, | |
324 | WXUINT message, | |
325 | WXWPARAM wParam, | |
326 | WXLPARAM lParam); | |
bfc6fde4 | 327 | |
cc2b7472 VZ |
328 | #if WXWIN_COMPATIBILITY |
329 | void SetShowing(bool show) { (void)Show(show); } | |
330 | bool IsUserEnabled() const { return IsEnabled(); } | |
331 | #endif // WXWIN_COMPATIBILITY | |
bfc6fde4 VZ |
332 | |
333 | // Responds to colour changes: passes event on to children. | |
334 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
335 | ||
a23fd0e1 VZ |
336 | // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX) |
337 | void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags); | |
bfc6fde4 | 338 | |
2bda0e17 | 339 | protected: |
d7c24517 VZ |
340 | // the window handle |
341 | WXHWND m_hWnd; | |
342 | ||
cc2b7472 | 343 | // the old window proc (we subclass all windows) |
bfc6fde4 | 344 | WXFARPROC m_oldWndProc; |
2bda0e17 | 345 | |
cc2b7472 VZ |
346 | // additional (MSW specific) flags |
347 | bool m_useCtl3D:1; // Using CTL3D for this control | |
cc2b7472 VZ |
348 | bool m_backgroundTransparent:1; |
349 | bool m_mouseInWindow:1; | |
350 | bool m_doubleClickAllowed:1; | |
351 | bool m_winCaptured:1; | |
bfc6fde4 VZ |
352 | |
353 | // Caret data | |
cc2b7472 VZ |
354 | bool m_caretEnabled:1; |
355 | bool m_caretShown:1; | |
bfc6fde4 VZ |
356 | int m_caretWidth; |
357 | int m_caretHeight; | |
2bda0e17 | 358 | |
cc2b7472 | 359 | // the size of one page for scrolling |
bfc6fde4 VZ |
360 | int m_xThumbSize; |
361 | int m_yThumbSize; | |
2bda0e17 | 362 | |
a23fd0e1 VZ |
363 | #if wxUSE_MOUSEEVENT_HACK |
364 | // the coordinates of the last mouse event and the type of it | |
cc2b7472 VZ |
365 | long m_lastMouseX, |
366 | m_lastMouseY; | |
367 | int m_lastMouseEvent; | |
a23fd0e1 | 368 | #endif // wxUSE_MOUSEEVENT_HACK |
bfc6fde4 | 369 | |
bfc6fde4 | 370 | WXHMENU m_hMenu; // Menu, if any |
bfc6fde4 | 371 | |
cc2b7472 VZ |
372 | wxButton *m_btnDefault; |
373 | ||
374 | // implement the base class pure virtuals | |
375 | virtual void DoGetPosition( int *x, int *y ) const; | |
376 | virtual void DoGetSize( int *width, int *height ) const; | |
377 | virtual void DoGetClientSize( int *width, int *height ) const; | |
378 | virtual void DoSetSize(int x, int y, | |
379 | int width, int height, | |
380 | int sizeFlags = wxSIZE_AUTO); | |
bfc6fde4 | 381 | virtual void DoSetClientSize(int width, int height); |
2bda0e17 | 382 | |
cc2b7472 VZ |
383 | #if wxUSE_TOOLTIPS |
384 | virtual void DoSetToolTip( wxToolTip *tip ); | |
385 | #endif // wxUSE_TOOLTIPS | |
386 | ||
fd3f686c VZ |
387 | private: |
388 | // common part of all ctors | |
389 | void Init(); | |
390 | ||
a23fd0e1 VZ |
391 | // the (non-virtual) handlers for the events |
392 | bool HandleMove(int x, int y); | |
393 | bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); | |
394 | ||
395 | #ifdef __WIN95__ | |
396 | bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); | |
397 | #endif // __WIN95__ | |
398 | ||
399 | DECLARE_NO_COPY_CLASS(wxWindow); | |
fd3f686c | 400 | DECLARE_EVENT_TABLE() |
2bda0e17 KB |
401 | }; |
402 | ||
cc2b7472 VZ |
403 | // --------------------------------------------------------------------------- |
404 | // global functions | |
405 | // --------------------------------------------------------------------------- | |
2bda0e17 | 406 | |
cc2b7472 | 407 | // kbd code translation |
184b5d99 JS |
408 | WXDLLEXPORT int wxCharCodeMSWToWX(int keySym); |
409 | WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual); | |
2bda0e17 | 410 | |
2bda0e17 | 411 | #endif |
bbcdf8bc | 412 | // _WX_WINDOW_H_ |