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