]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/window.h
More OS/2 stuff
[wxWidgets.git] / include / wx / os2 / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindow class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #define wxUSE_MOUSEEVENT_HACK 0
16
17 // ---------------------------------------------------------------------------
18 // headers
19 // ---------------------------------------------------------------------------
20
21 // ---------------------------------------------------------------------------
22 // forward declarations
23 // ---------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxButton;
26
27 // ---------------------------------------------------------------------------
28 // constants
29 // ---------------------------------------------------------------------------
30
31 // FIXME does anybody use those? they're unused by wxWindows...
32 enum
33 {
34 wxKEY_SHIFT = 1,
35 wxKEY_CTRL = 2
36 };
37
38 // ---------------------------------------------------------------------------
39 // wxWindow declaration for OS/2 PM
40 // ---------------------------------------------------------------------------
41
42 class WXDLLEXPORT wxWindow : public wxWindowBase
43 {
44 DECLARE_DYNAMIC_CLASS(wxWindow);
45
46 public:
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)
55 {
56 Init();
57 Create(parent, id, pos, size, style, name);
58 }
59
60 virtual ~wxWindow();
61
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);
68
69 // implement base class pure virtuals
70 virtual void SetTitle( const wxString& title);
71 virtual wxString GetTitle() const;
72
73 virtual void Raise();
74 virtual void Lower();
75
76 virtual bool Show( bool show = TRUE );
77 virtual bool Enable( bool enable = TRUE );
78
79 virtual void SetFocus();
80
81 virtual bool Reparent( wxWindow *newParent );
82
83 virtual void WarpPointer(int x, int y);
84 virtual void CaptureMouse();
85 virtual void ReleaseMouse();
86
87 virtual void Refresh( bool eraseBackground = TRUE,
88 const wxRect *rect = (const wxRect *) NULL );
89 virtual void Clear();
90
91 virtual bool SetCursor( const wxCursor &cursor );
92 virtual bool SetFont( const wxFont &font );
93
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;
102
103 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
104
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 );
113
114 #if wxUSE_DRAG_AND_DROP
115 virtual void SetDropTarget( wxDropTarget *dropTarget );
116 #endif // wxUSE_DRAG_AND_DROP
117
118 // Accept files for dragging
119 virtual void DragAcceptFiles(bool accept);
120
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;
127
128 // event handlers
129 // Handle a control command
130 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
131
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
136
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 // ----------------
160
161 WXHWND GetHWND() const { return m_hWnd; }
162 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
163 virtual WXWidget GetHandle() const { return GetHWND(); }
164
165 bool GetUseCtl3D() const { return m_useCtl3D; }
166 bool GetTransparentBackground() const { return m_backgroundTransparent; }
167 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
168
169 // event handlers
170 // --------------
171 void OnEraseBackground(wxEraseEvent& event);
172 void OnIdle(wxIdleEvent& event);
173
174 public:
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
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
193 // Make a Windows extended style from the given wxWindows window style
194 static WXDWORD MakeExtendedStyle(long style,
195 bool eliminateBorders = TRUE);
196 // Determine whether 3D effects are wanted
197 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
198
199 // MSW only: TRUE if this control is part of the main control
200 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
201
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);
312
313 bool HandleQueryDragIcon(WXHICON *hIcon);
314
315 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
316
317 // Window procedure
318 virtual MRESULT OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
319
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();
325
326 // Detach "Window" menu from menu bar so it doesn't get deleted
327 void OS2DetachWindowMenu();
328
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);
337
338 #if WXWIN_COMPATIBILITY
339 void SetShowing(bool show) { (void)Show(show); }
340 bool IsUserEnabled() const { return IsEnabled(); }
341 #endif // WXWIN_COMPATIBILITY
342
343 // Responds to colour changes: passes event on to children.
344 void OnSysColourChanged(wxSysColourChangedEvent& event);
345
346 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
347 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
348
349 protected:
350 // the window handle
351 WXHWND m_hWnd;
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;
362
363 // the size of one page for scrolling
364 int m_xThumbSize;
365 int m_yThumbSize;
366
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
404 private:
405 // common part of all ctors
406 void Init();
407
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);
411
412 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
413 DECLARE_NO_COPY_CLASS(wxWindow);
414 DECLARE_EVENT_TABLE()
415 };
416
417 // ---------------------------------------------------------------------------
418 // global functions
419 // ---------------------------------------------------------------------------
420
421 // kbd code translation
422 WXDLLEXPORT int wxCharCodeOS2ToWX(int keySym);
423 WXDLLEXPORT int wxCharCodeWXToOS2(int id, bool *IsVirtual);
424 #endif
425 // _WX_WINDOW_H_