]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/window.h
moved MGL initialization to earlier stage (crashes otherwise...) and implemented...
[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 #define INCL_DOS
21 #define INCL_PM
22 #define INCL_GPI
23 #include <os2.h>
24
25
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
29
30 class WXDLLEXPORT wxButton;
31
32 // ---------------------------------------------------------------------------
33 // constants
34 // ---------------------------------------------------------------------------
35
36 // FIXME does anybody use those? they're unused by wxWindows...
37 enum
38 {
39 wxKEY_SHIFT = 1,
40 wxKEY_CTRL = 2
41 };
42
43 // ---------------------------------------------------------------------------
44 // wxWindow declaration for OS/2 PM
45 // ---------------------------------------------------------------------------
46
47 class WXDLLEXPORT wxWindowOS2 : public wxWindowBase
48 {
49 public:
50 wxWindowOS2()
51 {
52 Init();
53 }
54
55 wxWindowOS2( wxWindow* pParent
56 ,wxWindowID vId
57 ,const wxPoint& rPos = wxDefaultPosition
58 ,const wxSize& rSize = wxDefaultSize
59 ,long lStyle = 0
60 ,const wxString& rName = wxPanelNameStr
61 )
62 {
63 Init();
64 Create( pParent
65 ,vId
66 ,rPos
67 ,rSize
68 ,lStyle
69 ,rName
70 );
71 }
72
73 virtual ~wxWindowOS2();
74
75 bool Create( wxWindow* pParent
76 ,wxWindowID vId
77 ,const wxPoint& rPos = wxDefaultPosition
78 ,const wxSize& rSize = wxDefaultSize
79 ,long lStyle = 0
80 ,const wxString& rName = wxPanelNameStr
81 );
82
83 // implement base class pure virtuals
84 virtual void SetTitle(const wxString& rTitle);
85 virtual wxString GetTitle(void) const;
86 virtual void Raise(void);
87 virtual void Lower(void);
88 virtual bool Show(bool bShow = TRUE);
89 virtual bool Enable(bool bEnable = TRUE);
90 virtual void SetFocus(void);
91 virtual bool Reparent(wxWindow* pNewParent);
92 virtual void WarpPointer( int x
93 ,int y
94 );
95 virtual void CaptureMouse(void);
96 virtual void ReleaseMouse(void);
97 virtual void Refresh( bool bEraseBackground = TRUE
98 ,const wxRect* pRect = (const wxRect *)NULL
99 );
100 virtual void Clear(void);
101 virtual bool SetCursor(const wxCursor& rCursor);
102 virtual bool SetFont(const wxFont& rFont);
103 virtual int GetCharHeight(void) const;
104 virtual int GetCharWidth(void) const;
105 virtual void GetTextExtent( const wxString& rString
106 ,int* pX
107 ,int* pY
108 ,int* pDescent = (int *)NULL
109 ,int* pExternalLeading = (int *)NULL
110 ,const wxFont* pTheFont = (const wxFont *)NULL
111 ) const;
112 virtual bool DoPopupMenu( wxMenu* pMenu
113 ,int nX
114 ,int nY
115 );
116
117 virtual void SetScrollbar( int nOrient
118 ,int nPos
119 ,int nThumbVisible
120 ,int nRange
121 ,bool bRefresh = TRUE
122 );
123 virtual void SetScrollPos( int nOrient
124 ,int nPos
125 ,bool bRefresh = TRUE
126 );
127 virtual int GetScrollPos(int nOrient) const;
128 virtual int GetScrollThumb(int nOrient) const;
129 virtual int GetScrollRange(int nOrient) const;
130 virtual void ScrollWindow( int nDx
131 ,int nDy
132 ,const wxRect* pRect = (wxRect *)NULL
133 );
134
135 #if wxUSE_DRAG_AND_DROP
136 virtual void SetDropTarget(wxDropTarget* pDropTarget);
137 #endif // wxUSE_DRAG_AND_DROP
138
139 // Accept files for dragging
140 virtual void DragAcceptFiles(bool bAccept);
141
142 #if WXWIN_COMPATIBILITY
143 // Set/get scroll attributes
144 virtual void SetScrollRange( int nOrient
145 ,int nRange
146 ,bool bRefresh = TRUE
147 );
148 virtual void SetScrollPage( int nOrient
149 ,int nPage
150 ,bool bRefresh = TRUE
151 );
152 virtual int OldGetScrollRange(int nOrient) const;
153 virtual int GetScrollPage(int nOrient) const;
154
155 //
156 // event handlers
157 //
158 // Handle a control command
159 virtual void OnCommand( wxWindow& rWin
160 ,wxCommandEvent& rEvent
161 );
162
163 // Override to define new behaviour for default action (e.g. double
164 // clicking on a listbox)
165 virtual void OnDefaultAction(wxControl* WXUNUSED(pInitiatingItem)) { }
166 #endif // WXWIN_COMPATIBILITY
167
168 #if wxUSE_CARET && WXWIN_COMPATIBILITY
169 void CreateCaret( int nWidth
170 ,int nHeight
171 );
172 void CreateCaret(const wxBitmap* pBitmap);
173 void DestroyCaret(void);
174 void ShowCaret(bool bShow);
175 void SetCaretPos( int nX
176 ,int nY
177 );
178 void GetCaretPos( int* pX
179 ,int* pY
180 ) const;
181 #endif // wxUSE_CARET
182
183 // Native resource loading (implemented in src/os2/nativdlg.cpp)
184 // FIXME: should they really be all virtual?
185 virtual bool LoadNativeDialog( wxWindow* pParent
186 ,wxWindowID& vId
187 );
188 virtual bool LoadNativeDialog( wxWindow* pParent
189 ,const wxString& rName
190 );
191 wxWindow* GetWindowChild1(wxWindowID vId);
192 wxWindow* GetWindowChild(wxWindowID vId);
193
194 // implementation from now on
195 // --------------------------
196
197 // simple accessors
198 // ----------------
199
200 WXHWND GetHWND(void) const { return m_hWnd; }
201 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
202 virtual WXWidget GetHandle(void) const { return GetHWND(); }
203 bool GetUseCtl3D(void) const { return m_bUseCtl3D; }
204 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent; }
205 void SetTransparent(bool bT = TRUE) { m_bBackgroundTransparent = bT; }
206
207 // event handlers
208 // --------------
209 void OnSetFocus(wxFocusEvent& rEvent);
210 void OnEraseBackground(wxEraseEvent& rEvent);
211 void OnIdle(wxIdleEvent& rEvent);
212
213 public:
214 // For implementation purposes - sometimes decorations make the client area
215 // smaller
216 virtual wxPoint GetClientAreaOrigin(void) const;
217
218 // Windows subclassing
219 void SubclassWin(WXHWND hWnd);
220 void UnsubclassWin(void);
221
222 WXFARPROC OS2GetOldWndProc(void) const { return m_fnOldWndProc; }
223 void OS2SetOldWndProc(WXFARPROC fnProc) { m_fnOldWndProc = fnProc; }
224
225 wxWindow* FindItem(long lId) const;
226 wxWindow* FindItemByHWND( WXHWND hWnd
227 ,bool bControlOnly = FALSE
228 ) const;
229
230 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
231 static WXDWORD MakeExtendedStyle( long lStyle
232 ,bool bEliminateBorders = TRUE
233 );
234 // Determine whether 3D effects are wanted
235 WXDWORD Determine3DEffects( WXDWORD dwDefaultBorderStyle
236 ,bool* pbWant3D
237 ) const;
238
239 // PM only: TRUE if this control is part of the main control
240 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
241
242 // returns TRUE if the window has been created
243 bool OS2Create( WXHWND hParent
244 ,PSZ zClass
245 ,const wxChar* zTitle
246 ,WXDWORD dwStyle
247 ,long lX
248 ,long lY
249 ,long lWidth
250 ,long lHeight
251 ,WXHWND hOwner
252 ,WXHWND hZOrder
253 ,unsigned long lId
254 ,void* pCtlData = NULL
255 ,void* pPresParams = NULL
256 ,WXDWORD dwExStyle = 0L
257 );
258 virtual bool OS2Command( WXUINT uParam
259 ,WXWORD nId
260 );
261
262 #if WXWIN_COMPATIBILITY
263 wxObject* GetChild(int nNumber) const;
264 virtual void OS2DeviceToLogical( float* pfX
265 ,float* pfY
266 ) const;
267 #endif // WXWIN_COMPATIBILITY
268
269 // Create an appropriate wxWindow from a HWND
270 virtual wxWindow* CreateWindowFromHWND( wxWindow* pParent
271 ,WXHWND hWnd
272 );
273
274 // Make sure the window style reflects the HWND style (roughly)
275 virtual void AdoptAttributesFromHWND(void);
276
277 // Setup background and foreground colours correctly
278 virtual void SetupColours(void);
279
280 // ------------------------------------------------------------------------
281 // helpers for message handlers: these perform the same function as the
282 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
283 // the correct parameters
284 // ------------------------------------------------------------------------
285
286 void UnpackCommand( WXWPARAM wParam
287 ,WXLPARAM lParam,
288 WXWORD* pId
289 ,WXHWND* pHwnd
290 ,WXWORD* pCmd
291 );
292 void UnpackActivate( WXWPARAM wParam
293 ,WXLPARAM lParam
294 ,WXWORD* pState
295 ,WXHWND* pHwnd
296 );
297 void UnpackScroll( WXWPARAM wParam
298 ,WXLPARAM lParam
299 ,WXWORD* pCode
300 ,WXWORD* pPos
301 ,WXHWND* pHwnd
302 );
303 void UnpackMenuSelect( WXWPARAM wParam
304 ,WXLPARAM lParam
305 ,WXWORD* pTtem
306 ,WXWORD* pFlags
307 ,WXHMENU* pHmenu
308 );
309
310 // ------------------------------------------------------------------------
311 // internal handlers for OS2 messages: all handlers return a boolen value:
312 // TRUE means that the handler processed the event and FALSE that it didn't
313 // ------------------------------------------------------------------------
314
315 // there are several cases where we have virtual functions for PM
316 // message processing: this is because these messages often require to be
317 // processed in a different manner in the derived classes. For all other
318 // messages, however, we do *not* have corresponding OS2OnXXX() function
319 // and if the derived class wants to process them, it should override
320 // OS2WindowProc() directly.
321
322 // scroll event (both horizontal and vertical)
323 virtual bool OS2OnScroll( int nOrientation
324 ,WXWORD nSBCode
325 ,WXWORD pos
326 ,WXHWND control
327 );
328
329 // owner-drawn controls need to process these messages
330 virtual bool OS2OnDrawItem( int nId
331 ,WXDRAWITEMSTRUCT* pItem
332 );
333 virtual bool OS2OnMeasureItem( int nId
334 ,WXMEASUREITEMSTRUCT* pItem
335 );
336
337 // the rest are not virtual
338 bool HandleCreate( WXLPCREATESTRUCT vCs
339 ,bool* pMayCreate
340 );
341 bool HandleInitDialog(WXHWND hWndFocus);
342 bool HandleDestroy(void);
343 bool HandlePaint(void);
344 bool HandleEraseBkgnd(WXHDC vDC);
345 bool HandleMinimize(void);
346 bool HandleMaximize(void);
347 bool HandleSize( int nX
348 ,int nY
349 ,WXUINT uFlag
350 );
351 bool HandleGetMinMaxInfo(PSWP pMmInfo);
352 bool HandleShow( bool bShow
353 ,int nStatus
354 );
355 bool HandleActivate( int nFlag
356 ,WXHWND hActivate
357 );
358 bool HandleCommand( WXWORD nId
359 ,WXWORD nCmd
360 ,WXHWND hControl
361 );
362 bool HandleSysCommand( WXWPARAM wParam
363 ,WXLPARAM lParam
364 );
365 bool HandleWindowParams( PWNDPARAMS pParams
366 ,WXLPARAM lParam
367 );
368 bool HandlePaletteChanged();
369 bool HandlePresParamChanged(WXWPARAM wParam);
370 bool HandleSysColorChange(void);
371 bool HandleCtlColor(WXHBRUSH* hBrush);
372 bool HandleSetFocus(WXHWND hWnd);
373 bool HandleKillFocus(WXHWND hWnd);
374 bool HandleEndDrag(WXWPARAM wParam);
375 bool HandleMouseEvent( WXUINT uMsg
376 ,int nX
377 ,int nY
378 ,WXUINT uFlags
379 );
380 bool HandleMouseMove( int nX
381 ,int nY
382 ,WXUINT uFlags
383 );
384 bool HandleChar( WXWORD wParam
385 ,WXLPARAM lParam
386 ,bool bIsASCII = FALSE
387 );
388 bool HandleKeyDown( WXWORD wParam
389 ,WXLPARAM lParam
390 );
391 bool HandleKeyUp( WXWORD wParam
392 ,WXLPARAM lParam
393 );
394 bool HandleQueryDragIcon(WXHICON* phIcon);
395 bool HandleSetCursor( USHORT vId
396 ,WXHWND hWnd
397 );
398
399 // Window procedure
400 virtual MRESULT OS2WindowProc( WXUINT uMsg
401 ,WXWPARAM wParam
402 ,WXLPARAM lParam
403 );
404
405 // Calls an appropriate default window procedure
406 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
407 ,WXWPARAM wParam
408 ,WXLPARAM lParam
409 );
410 virtual bool OS2ProcessMessage(WXMSG* pMsg);
411 virtual bool OS2TranslateMessage(WXMSG* pMsg);
412 virtual void OS2DestroyWindow(void);
413
414 // Detach "Window" menu from menu bar so it doesn't get deleted
415 void OS2DetachWindowMenu(void);
416
417 // this function should return the brush to paint the window background
418 // with or 0 for the default brush
419 virtual WXHBRUSH OnCtlColor( WXHDC hDC
420 ,WXHWND hWnd
421 ,WXUINT uCtlColor
422 ,WXUINT uMessage
423 ,WXWPARAM wParam
424 ,WXLPARAM lParam
425 );
426
427 #if WXWIN_COMPATIBILITY
428 void SetShowing(bool bShow) { (void)Show(show); }
429 bool IsUserEnabled(void) const { return IsEnabled(); }
430 #endif // WXWIN_COMPATIBILITY
431
432 // Responds to colour changes: passes event on to children.
433 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
434
435 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
436 void InitMouseEvent( wxMouseEvent& rEvent
437 ,int nX
438 ,int nY
439 ,WXUINT uFlags
440 );
441
442 protected:
443 // PM can't create some MSW styles natively but can perform these after
444 // creation by sending messages
445 typedef enum extra_flags { kFrameToolWindow = 0x0001
446 ,kVertCaption = 0x0002
447 ,kHorzCaption = 0x0004
448 } EExtraFlags;
449 // Some internal sizeing id's to make it easy for event handlers
450 typedef enum size_types { kSizeNormal
451 ,kSizeMax
452 ,kSizeMin
453 } ESizeTypes;
454 // the window handle
455 WXHWND m_hWnd;
456
457 // the old window proc (we subclass all windows)
458 WXFARPROC m_fnOldWndProc;
459
460 // additional (OS2 specific) flags
461 bool m_bUseCtl3D:1; // Using CTL3D for this control
462 bool m_bBackgroundTransparent:1;
463 bool m_bMouseInWindow:1;
464 bool m_bDoubleClickAllowed:1;
465 bool m_bWinCaptured:1;
466 WXDWORD m_dwExStyle;
467
468 // the size of one page for scrolling
469 int m_nXThumbSize;
470 int m_nYThumbSize;
471
472 #if wxUSE_MOUSEEVENT_HACK
473 // the coordinates of the last mouse event and the type of it
474 long m_lLastMouseX,
475 long m_lLastMouseY;
476 int m_nLastMouseEvent;
477 #endif // wxUSE_MOUSEEVENT_HACK
478
479 WXHMENU m_hMenu; // Menu, if any
480 unsigned long m_ulMenubarId; // it's Id, if any
481
482 // the return value of WM_GETDLGCODE handler
483 long m_lDlgCode;
484
485 // implement the base class pure virtuals
486 virtual void DoClientToScreen( int* pX
487 ,int* pY
488 ) const;
489 virtual void DoScreenToClient( int* pX
490 ,int* pY
491 ) const;
492 virtual void DoGetPosition( int* pX
493 ,int* pY
494 ) const;
495 virtual void DoGetSize( int* pWidth
496 ,int* pHeight
497 ) const;
498 virtual void DoGetClientSize( int* pWidth
499 ,int* pHeight
500 ) const;
501 virtual void DoSetSize( int nX
502 ,int nY
503 ,int nWidth
504 ,int nHeight
505 ,int nSizeFlags = wxSIZE_AUTO
506 );
507 virtual void DoSetClientSize( int nWidth
508 ,int nHeight
509 );
510
511 // move the window to the specified location and resize it: this is called
512 // from both DoSetSize() and DoSetClientSize() and would usually just call
513 // ::WinSetWindowPos() except for composite controls which will want to arrange
514 // themselves inside the given rectangle
515 virtual void DoMoveWindow( int nX
516 ,int nY
517 ,int nWidth
518 ,int nHeight
519 );
520
521 #if wxUSE_TOOLTIPS
522 virtual void DoSetToolTip(wxToolTip* pTip);
523 #endif // wxUSE_TOOLTIPS
524
525 private:
526 // common part of all ctors
527 void Init(void);
528
529 // the (non-virtual) handlers for the events
530 bool HandleMove( int nX
531 ,int nY
532 );
533 bool HandleJoystickEvent( WXUINT uMsg
534 ,int pX
535 ,int pY
536 ,WXUINT uFlags
537 );
538
539 bool HandleNotify( int nIdCtrl
540 ,WXLPARAM lParam
541 ,WXLPARAM* pResult
542 );
543 // the helper functions used by HandleChar/KeyXXX methods
544 wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const;
545
546 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
547 DECLARE_NO_COPY_CLASS(wxWindowOS2)
548 DECLARE_EVENT_TABLE()
549 private:
550 HWND m_hWndScrollBarHorz;
551 HWND m_hWndScrollBarVert;
552
553 // Virtual function hiding supression
554 inline virtual bool Reparent(wxWindowBase* pNewParent)
555 { return(wxWindowBase::Reparent(pNewParent));};
556 }; // end of wxWindow
557
558 // ---------------------------------------------------------------------------
559 // global functions
560 // ---------------------------------------------------------------------------
561
562 // kbd code translation
563 WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
564 WXDLLEXPORT int wxCharCodeWXToOS2( int nId
565 ,bool* pbIsVirtual
566 );
567 #endif
568 // _WX_WINDOW_H_