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