]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: window.h | |
3 | // Purpose: wxWindow class | |
54da4255 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
cdf1e714 | 6 | // Created: 10/12/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
cdf1e714 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_WINDOW_H_ | |
13 | #define _WX_WINDOW_H_ | |
14 | ||
cdf1e714 | 15 | #define wxUSE_MOUSEEVENT_HACK 0 |
0e320a79 | 16 | |
cdf1e714 DW |
17 | // --------------------------------------------------------------------------- |
18 | // headers | |
19 | // --------------------------------------------------------------------------- | |
0e320a79 DW |
20 | |
21 | // --------------------------------------------------------------------------- | |
22 | // forward declarations | |
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | class WXDLLEXPORT wxButton; | |
26 | ||
cdf1e714 DW |
27 | // --------------------------------------------------------------------------- |
28 | // constants | |
29 | // --------------------------------------------------------------------------- | |
0e320a79 | 30 | |
cdf1e714 DW |
31 | // FIXME does anybody use those? they're unused by wxWindows... |
32 | enum | |
33 | { | |
34 | wxKEY_SHIFT = 1, | |
35 | wxKEY_CTRL = 2 | |
36 | }; | |
54da4255 | 37 | |
cdf1e714 DW |
38 | // --------------------------------------------------------------------------- |
39 | // wxWindow declaration for OS/2 PM | |
40 | // --------------------------------------------------------------------------- | |
54da4255 | 41 | |
cdf1e714 | 42 | class WXDLLEXPORT wxWindow : public wxWindowBase |
0e320a79 | 43 | { |
cdf1e714 | 44 | DECLARE_DYNAMIC_CLASS(wxWindow); |
0e320a79 DW |
45 | |
46 | public: | |
cdf1e714 DW |
47 | wxWindow() { Init(); } |
48 | ||
49 | wxWindow(wxWindow *parent, | |
50 | wxWindowID id, | |
51 | const wxPoint& pos = wxDefaultPosition, | |
52 | const wxSize& size = wxDefaultSize, | |
53 | long style = 0, | |
54 | const wxString& name = wxPanelNameStr) | |
0e320a79 DW |
55 | { |
56 | Init(); | |
57 | Create(parent, id, pos, size, style, name); | |
58 | } | |
59 | ||
60 | virtual ~wxWindow(); | |
61 | ||
cdf1e714 DW |
62 | bool Create(wxWindow *parent, |
63 | wxWindowID id, | |
64 | const wxPoint& pos = wxDefaultPosition, | |
65 | const wxSize& size = wxDefaultSize, | |
66 | long style = 0, | |
67 | const wxString& name = wxPanelNameStr); | |
0e320a79 | 68 | |
cdf1e714 DW |
69 | // implement base class pure virtuals |
70 | virtual void SetTitle( const wxString& title); | |
71 | virtual wxString GetTitle() const; | |
0e320a79 DW |
72 | |
73 | virtual void Raise(); | |
74 | virtual void Lower(); | |
0e320a79 | 75 | |
cdf1e714 DW |
76 | virtual bool Show( bool show = TRUE ); |
77 | virtual bool Enable( bool enable = TRUE ); | |
0e320a79 | 78 | |
cdf1e714 | 79 | virtual void SetFocus(); |
0e320a79 | 80 | |
cdf1e714 | 81 | virtual bool Reparent( wxWindow *newParent ); |
0e320a79 | 82 | |
cdf1e714 DW |
83 | virtual void WarpPointer(int x, int y); |
84 | virtual void CaptureMouse(); | |
85 | virtual void ReleaseMouse(); | |
1408104d | 86 | |
cdf1e714 DW |
87 | virtual void Refresh( bool eraseBackground = TRUE, |
88 | const wxRect *rect = (const wxRect *) NULL ); | |
89 | virtual void Clear(); | |
1408104d | 90 | |
cdf1e714 DW |
91 | virtual bool SetCursor( const wxCursor &cursor ); |
92 | virtual bool SetFont( const wxFont &font ); | |
0e320a79 | 93 | |
cdf1e714 DW |
94 | virtual int GetCharHeight() const; |
95 | virtual int GetCharWidth() const; | |
96 | virtual void GetTextExtent(const wxString& string, | |
97 | int *x, int *y, | |
98 | int *descent = (int *) NULL, | |
99 | int *externalLeading = (int *) NULL, | |
100 | const wxFont *theFont = (const wxFont *) NULL) | |
101 | const; | |
0e320a79 | 102 | |
cdf1e714 | 103 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); |
0e320a79 | 104 | |
cdf1e714 DW |
105 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, |
106 | int range, bool refresh = TRUE ); | |
107 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); | |
108 | virtual int GetScrollPos( int orient ) const; | |
109 | virtual int GetScrollThumb( int orient ) const; | |
110 | virtual int GetScrollRange( int orient ) const; | |
111 | virtual void ScrollWindow( int dx, int dy, | |
112 | const wxRect* rect = (wxRect *) NULL ); | |
0e320a79 | 113 | |
cdf1e714 DW |
114 | #if wxUSE_DRAG_AND_DROP |
115 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
116 | #endif // wxUSE_DRAG_AND_DROP | |
0e320a79 DW |
117 | |
118 | // Accept files for dragging | |
119 | virtual void DragAcceptFiles(bool accept); | |
120 | ||
cdf1e714 DW |
121 | #if WXWIN_COMPATIBILITY |
122 | // Set/get scroll attributes | |
123 | virtual void SetScrollRange(int orient, int range, bool refresh = TRUE); | |
124 | virtual void SetScrollPage(int orient, int page, bool refresh = TRUE); | |
125 | virtual int OldGetScrollRange(int orient) const; | |
126 | virtual int GetScrollPage(int orient) const; | |
54da4255 | 127 | |
cdf1e714 DW |
128 | // event handlers |
129 | // Handle a control command | |
0e320a79 DW |
130 | virtual void OnCommand(wxWindow& win, wxCommandEvent& event); |
131 | ||
cdf1e714 DW |
132 | // Override to define new behaviour for default action (e.g. double |
133 | // clicking on a listbox) | |
134 | virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { } | |
135 | #endif // WXWIN_COMPATIBILITY | |
0e320a79 | 136 | |
cdf1e714 DW |
137 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
138 | // caret manipulation (old MSW only functions, see wxCaret class for the | |
139 | // new API) | |
140 | void CreateCaret(int w, int h); | |
141 | void CreateCaret(const wxBitmap *bitmap); | |
142 | void DestroyCaret(); | |
143 | void ShowCaret(bool show); | |
144 | void SetCaretPos(int x, int y); | |
145 | void GetCaretPos(int *x, int *y) const; | |
146 | #endif // wxUSE_CARET | |
147 | ||
148 | // Native resource loading (implemented in src/msw/nativdlg.cpp) | |
149 | // FIXME: should they really be all virtual? | |
150 | virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id); | |
151 | virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name); | |
152 | wxWindow* GetWindowChild1(wxWindowID id); | |
153 | wxWindow* GetWindowChild(wxWindowID id); | |
154 | ||
155 | // implementation from now on | |
156 | // -------------------------- | |
157 | ||
158 | // simple accessors | |
159 | // ---------------- | |
86de7616 DW |
160 | |
161 | WXHWND GetHWND() const { return m_hWnd; } | |
cdf1e714 | 162 | void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } |
86de7616 | 163 | virtual WXWidget GetHandle() const { return GetHWND(); } |
54da4255 | 164 | |
cdf1e714 DW |
165 | bool GetUseCtl3D() const { return m_useCtl3D; } |
166 | bool GetTransparentBackground() const { return m_backgroundTransparent; } | |
167 | void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; } | |
54da4255 | 168 | |
cdf1e714 DW |
169 | // event handlers |
170 | // -------------- | |
171 | void OnEraseBackground(wxEraseEvent& event); | |
172 | void OnIdle(wxIdleEvent& event); | |
173 | ||
174 | public: | |
0e320a79 DW |
175 | // For implementation purposes - sometimes decorations make the client area |
176 | // smaller | |
177 | virtual wxPoint GetClientAreaOrigin() const; | |
178 | ||
179 | // Makes an adjustment to the window position (for example, a frame that has | |
180 | // a toolbar that it manages itself). | |
181 | virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags); | |
182 | ||
86de7616 DW |
183 | // Windows subclassing |
184 | void SubclassWin(WXHWND hWnd); | |
185 | void UnsubclassWin(); | |
186 | ||
187 | WXFARPROC OS2GetOldWndProc() const { return m_oldWndProc; } | |
188 | void OS2SetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; } | |
189 | ||
190 | wxWindow *FindItem(long id) const; | |
191 | wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const; | |
192 | ||
cdf1e714 DW |
193 | // Make a Windows extended style from the given wxWindows window style |
194 | static WXDWORD MakeExtendedStyle(long style, | |
195 | bool eliminateBorders = TRUE); | |
86de7616 DW |
196 | // Determine whether 3D effects are wanted |
197 | WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const; | |
198 | ||
cdf1e714 | 199 | // MSW only: TRUE if this control is part of the main control |
86de7616 DW |
200 | virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; }; |
201 | ||
cdf1e714 DW |
202 | // returns TRUE if the window has been created |
203 | bool OS2Create(int id, | |
204 | wxWindow *parent, | |
205 | const wxChar *wclass, | |
206 | wxWindow *wx_win, | |
207 | const wxChar *title, | |
208 | int x, int y, int width, int height, | |
209 | WXDWORD style, | |
210 | const wxChar *dialog_template = NULL, | |
211 | WXDWORD exendedStyle = 0); | |
212 | virtual bool OS2Command(WXUINT param, WXWORD id); | |
213 | ||
214 | #if WXWIN_COMPATIBILITY | |
215 | wxObject *GetChild(int number) const; | |
216 | virtual void OS2DeviceToLogical(float *x, float *y) const; | |
217 | #endif // WXWIN_COMPATIBILITY | |
218 | ||
219 | // Create an appropriate wxWindow from a HWND | |
220 | virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd); | |
221 | ||
222 | // Make sure the window style reflects the HWND style (roughly) | |
223 | virtual void AdoptAttributesFromHWND(); | |
224 | ||
225 | // Setup background and foreground colours correctly | |
226 | virtual void SetupColours(); | |
227 | ||
228 | // ------------------------------------------------------------------------ | |
229 | // helpers for message handlers: these perform the same function as the | |
230 | // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into | |
231 | // the correct parameters | |
232 | // ------------------------------------------------------------------------ | |
233 | ||
234 | void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, | |
235 | WXWORD *id, WXHWND *hwnd, WXWORD *cmd); | |
236 | void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, | |
237 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd); | |
238 | void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, | |
239 | WXWORD *code, WXWORD *pos, WXHWND *hwnd); | |
240 | void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, | |
241 | WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd); | |
242 | void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, | |
243 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu); | |
244 | ||
245 | // ------------------------------------------------------------------------ | |
246 | // internal handlers for MSW messages: all handlers return a boolen value: | |
247 | // TRUE means that the handler processed the event and FALSE that it didn't | |
248 | // ------------------------------------------------------------------------ | |
249 | ||
250 | // there are several cases where we have virtual functions for Windows | |
251 | // message processing: this is because these messages often require to be | |
252 | // processed in a different manner in the derived classes. For all other | |
253 | // messages, however, we do *not* have corresponding MSWOnXXX() function | |
254 | // and if the derived class wants to process them, it should override | |
255 | // MSWWindowProc() directly. | |
256 | ||
257 | // scroll event (both horizontal and vertical) | |
258 | virtual bool OS2OnScroll(int orientation, WXWORD nSBCode, | |
259 | WXWORD pos, WXHWND control); | |
260 | ||
261 | virtual bool OS2OnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); | |
262 | ||
263 | // owner-drawn controls need to process these messages | |
264 | virtual bool OS2OnDrawItem(int id, WXDRAWITEMSTRUCT *item); | |
265 | virtual bool OS2OnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); | |
266 | ||
267 | // the rest are not virtual | |
268 | bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate); | |
269 | bool HandleInitDialog(WXHWND hWndFocus); | |
270 | bool HandleDestroy(); | |
271 | ||
272 | bool HandlePaint(); | |
273 | bool HandleEraseBkgnd(WXHDC pDC); | |
274 | ||
275 | bool HandleMinimize(); | |
276 | bool HandleMaximize(); | |
277 | bool HandleSize(int x, int y, WXUINT flag); | |
278 | bool HandleGetMinMaxInfo(void *mmInfo); | |
279 | ||
280 | bool HandleShow(bool show, int status); | |
281 | bool HandleActivate(int flag, bool minimized, WXHWND activate); | |
282 | ||
283 | bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); | |
284 | bool HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam); | |
285 | ||
286 | bool HandleCtlColor(WXHBRUSH *hBrush, | |
287 | WXHDC hdc, | |
288 | WXHWND hWnd, | |
289 | WXUINT nCtlColor, | |
290 | WXUINT message, | |
291 | WXWPARAM wParam, | |
292 | WXLPARAM lParam); | |
293 | ||
294 | bool HandlePaletteChanged(WXHWND hWndPalChange); | |
295 | bool HandleQueryNewPalette(); | |
296 | bool HandleSysColorChange(); | |
297 | ||
298 | bool HandleQueryEndSession(long logOff, bool *mayEnd); | |
299 | bool HandleEndSession(bool endSession, long logOff); | |
300 | ||
301 | bool HandleSetFocus(WXHWND wnd); | |
302 | bool HandleKillFocus(WXHWND wnd); | |
303 | ||
304 | bool HandleDropFiles(WXWPARAM wParam); | |
305 | ||
306 | bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags); | |
307 | bool HandleMouseMove(int x, int y, WXUINT flags); | |
308 | ||
309 | bool HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE); | |
310 | bool HandleKeyDown(WXWORD wParam, WXLPARAM lParam); | |
311 | bool HandleKeyUp(WXWORD wParam, WXLPARAM lParam); | |
0e320a79 | 312 | |
cdf1e714 DW |
313 | bool HandleQueryDragIcon(WXHICON *hIcon); |
314 | ||
315 | bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg); | |
0e320a79 | 316 | |
cdf1e714 DW |
317 | // Window procedure |
318 | virtual MRESULT OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
0e320a79 | 319 | |
cdf1e714 DW |
320 | // Calls an appropriate default window procedure |
321 | virtual MRESULT OS2DefWindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
322 | virtual bool OS2ProcessMessage(WXMSG* pMsg); | |
323 | virtual bool OS2TranslateMessage(WXMSG* pMsg); | |
324 | virtual void OS2DestroyWindow(); | |
0e320a79 | 325 | |
cdf1e714 DW |
326 | // Detach "Window" menu from menu bar so it doesn't get deleted |
327 | void OS2DetachWindowMenu(); | |
27476f73 | 328 | |
cdf1e714 DW |
329 | // this function should return the brush to paint the window background |
330 | // with or 0 for the default brush | |
331 | virtual WXHBRUSH OnCtlColor(WXHDC hDC, | |
332 | WXHWND hWnd, | |
333 | WXUINT nCtlColor, | |
334 | WXUINT message, | |
335 | WXWPARAM wParam, | |
336 | WXLPARAM lParam); | |
27476f73 | 337 | |
cdf1e714 DW |
338 | #if WXWIN_COMPATIBILITY |
339 | void SetShowing(bool show) { (void)Show(show); } | |
340 | bool IsUserEnabled() const { return IsEnabled(); } | |
341 | #endif // WXWIN_COMPATIBILITY | |
0e320a79 | 342 | |
cdf1e714 DW |
343 | // Responds to colour changes: passes event on to children. |
344 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
0e320a79 | 345 | |
cdf1e714 DW |
346 | // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX) |
347 | void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags); | |
0e320a79 | 348 | |
cdf1e714 DW |
349 | protected: |
350 | // the window handle | |
849949b1 | 351 | WXHWND m_hWnd; |
cdf1e714 DW |
352 | |
353 | // the old window proc (we subclass all windows) | |
354 | WXFARPROC m_oldWndProc; | |
355 | ||
356 | // additional (MSW specific) flags | |
357 | bool m_useCtl3D:1; // Using CTL3D for this control | |
358 | bool m_backgroundTransparent:1; | |
359 | bool m_mouseInWindow:1; | |
360 | bool m_doubleClickAllowed:1; | |
361 | bool m_winCaptured:1; | |
849949b1 DW |
362 | |
363 | // the size of one page for scrolling | |
364 | int m_xThumbSize; | |
365 | int m_yThumbSize; | |
0e320a79 | 366 | |
cdf1e714 DW |
367 | #if wxUSE_MOUSEEVENT_HACK |
368 | // the coordinates of the last mouse event and the type of it | |
369 | long m_lastMouseX, | |
370 | m_lastMouseY; | |
371 | int m_lastMouseEvent; | |
372 | #endif // wxUSE_MOUSEEVENT_HACK | |
373 | ||
374 | WXHMENU m_hMenu; // Menu, if any | |
375 | ||
376 | // the return value of WM_GETDLGCODE handler | |
377 | long m_lDlgCode; | |
378 | ||
379 | // implement the base class pure virtuals | |
380 | virtual void DoClientToScreen( int *x, int *y ) const; | |
381 | virtual void DoScreenToClient( int *x, int *y ) const; | |
382 | virtual void DoGetPosition( int *x, int *y ) const; | |
383 | virtual void DoGetSize( int *width, int *height ) const; | |
384 | virtual void DoGetClientSize( int *width, int *height ) const; | |
385 | virtual void DoSetSize(int x, int y, | |
386 | int width, int height, | |
387 | int sizeFlags = wxSIZE_AUTO); | |
388 | virtual void DoSetClientSize(int width, int height); | |
389 | ||
390 | // get the size which best suits the window: e.g., for a static text it | |
391 | // will be the width and height of the text | |
392 | virtual wxSize DoGetBestSize(); | |
393 | ||
394 | // move the window to the specified location and resize it: this is called | |
395 | // from both DoSetSize() and DoSetClientSize() and would usually just call | |
396 | // ::MoveWindow() except for composite controls which will want to arrange | |
397 | // themselves inside the given rectangle | |
398 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
399 | ||
400 | #if wxUSE_TOOLTIPS | |
401 | virtual void DoSetToolTip( wxToolTip *tip ); | |
402 | #endif // wxUSE_TOOLTIPS | |
403 | ||
0e320a79 | 404 | private: |
cdf1e714 DW |
405 | // common part of all ctors |
406 | void Init(); | |
0e320a79 | 407 | |
cdf1e714 DW |
408 | // the (non-virtual) handlers for the events |
409 | bool HandleMove(int x, int y); | |
410 | bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); | |
54da4255 | 411 | |
cdf1e714 DW |
412 | bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); |
413 | DECLARE_NO_COPY_CLASS(wxWindow); | |
414 | DECLARE_EVENT_TABLE() | |
415 | }; | |
0e320a79 | 416 | |
cdf1e714 DW |
417 | // --------------------------------------------------------------------------- |
418 | // global functions | |
419 | // --------------------------------------------------------------------------- | |
0e320a79 | 420 | |
cdf1e714 DW |
421 | // kbd code translation |
422 | WXDLLEXPORT int wxCharCodeOS2ToWX(int keySym); | |
423 | WXDLLEXPORT int wxCharCodeWXToOS2(int id, bool *IsVirtual); | |
0e320a79 DW |
424 | #endif |
425 | // _WX_WINDOW_H_ |