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