]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/window.h
Catching dclick event from a spinbutton or spin 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
231 // For implementation purposes - sometimes decorations make the client area
232 // smaller
233 virtual wxPoint GetClientAreaOrigin(void) const;
234
235 // Windows subclassing
236 void SubclassWin(WXHWND hWnd);
237 void UnsubclassWin(void);
238
239 WXFARPROC OS2GetOldWndProc(void) const { return m_fnOldWndProc; }
240 void OS2SetOldWndProc(WXFARPROC fnProc) { m_fnOldWndProc = fnProc; }
241 //
242 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
243 //
244 bool IsOfStandardClass(void) const { return m_fnOldWndProc != NULL; }
245
246 wxWindow* FindItem(long lId) const;
247 wxWindow* FindItemByHWND( WXHWND hWnd
248 ,bool bControlOnly = FALSE
249 ) const;
250
251 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
252 static WXDWORD MakeExtendedStyle( long lStyle
253 ,bool bEliminateBorders = TRUE
254 );
255 // Determine whether 3D effects are wanted
256 WXDWORD Determine3DEffects( WXDWORD dwDefaultBorderStyle
257 ,bool* pbWant3D
258 ) const;
259
260 // PM only: TRUE if this control is part of the main control
261 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
262
263 // translate wxWindows style flags for this control into the PM style
264 // and optional extended style for the corresponding native control
265 //
266 // this is the function that should be overridden in the derived classes,
267 // but you will mostly use OS2GetCreateWindowFlags() below
268 virtual WXDWORD OS2GetStyle( long lFlags
269 ,WXDWORD* pdwExstyle = NULL
270 ) const;
271
272 // get the MSW window flags corresponding to wxWindows ones
273 //
274 // the functions returns the flags (WS_XXX) directly and puts the ext
275 // (WS_EX_XXX) flags into the provided pointer if not NULL
276 WXDWORD OS2GetCreateWindowFlags(WXDWORD* pdwExflags = NULL) const
277 { return OS2GetStyle(GetWindowStyle(), pdwExflags); }
278
279
280 // get the HWND to be used as parent of this window with CreateWindow()
281 virtual WXHWND OS2GetParent(void) const;
282
283 // returns TRUE if the window has been created
284 bool OS2Create( PSZ zClass
285 ,const char* zTitle
286 ,WXDWORD dwStyle
287 ,const wxPoint& rPos
288 ,const wxSize& rSize
289 ,void* pCtlData
290 ,WXDWORD dwExStyle
291 ,bool bIsChild
292 );
293 virtual bool OS2Command( WXUINT uParam
294 ,WXWORD nId
295 );
296
297 #if WXWIN_COMPATIBILITY
298 wxObject* GetChild(int nNumber) const;
299 virtual void OS2DeviceToLogical( float* pfX
300 ,float* pfY
301 ) const;
302 #endif // WXWIN_COMPATIBILITY
303
304 #ifndef __WXUNIVERSAL__
305 // Create an appropriate wxWindow from a HWND
306 virtual wxWindow* CreateWindowFromHWND( wxWindow* pParent
307 ,WXHWND hWnd
308 );
309
310 // Make sure the window style reflects the HWND style (roughly)
311 virtual void AdoptAttributesFromHWND(void);
312 #endif
313
314 // Setup background and foreground colours correctly
315 virtual void SetupColours(void);
316
317 // ------------------------------------------------------------------------
318 // helpers for message handlers: these perform the same function as the
319 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
320 // the correct parameters
321 // ------------------------------------------------------------------------
322
323 void UnpackCommand( WXWPARAM wParam
324 ,WXLPARAM lParam,
325 WXWORD* pId
326 ,WXHWND* pHwnd
327 ,WXWORD* pCmd
328 );
329 void UnpackActivate( WXWPARAM wParam
330 ,WXLPARAM lParam
331 ,WXWORD* pState
332 ,WXHWND* pHwnd
333 );
334 void UnpackScroll( WXWPARAM wParam
335 ,WXLPARAM lParam
336 ,WXWORD* pCode
337 ,WXWORD* pPos
338 ,WXHWND* pHwnd
339 );
340 void UnpackMenuSelect( WXWPARAM wParam
341 ,WXLPARAM lParam
342 ,WXWORD* pTtem
343 ,WXWORD* pFlags
344 ,WXHMENU* pHmenu
345 );
346
347 // ------------------------------------------------------------------------
348 // internal handlers for OS2 messages: all handlers return a boolen value:
349 // TRUE means that the handler processed the event and FALSE that it didn't
350 // ------------------------------------------------------------------------
351
352 // there are several cases where we have virtual functions for PM
353 // message processing: this is because these messages often require to be
354 // processed in a different manner in the derived classes. For all other
355 // messages, however, we do *not* have corresponding OS2OnXXX() function
356 // and if the derived class wants to process them, it should override
357 // OS2WindowProc() directly.
358
359 // scroll event (both horizontal and vertical)
360 virtual bool OS2OnScroll( int nOrientation
361 ,WXWORD nSBCode
362 ,WXWORD pos
363 ,WXHWND control
364 );
365
366 // owner-drawn controls need to process these messages
367 virtual bool OS2OnDrawItem( int nId
368 ,WXDRAWITEMSTRUCT* pItem
369 );
370 virtual long OS2OnMeasureItem( int nId
371 ,WXMEASUREITEMSTRUCT* pItem
372 );
373
374 // the rest are not virtual
375 bool HandleCreate( WXLPCREATESTRUCT vCs
376 ,bool* pMayCreate
377 );
378 bool HandleInitDialog(WXHWND hWndFocus);
379 bool HandleDestroy(void);
380 bool HandlePaint(void);
381 bool HandleEraseBkgnd(WXHDC vDC);
382 bool HandleMinimize(void);
383 bool HandleMaximize(void);
384 bool HandleSize( int nX
385 ,int nY
386 ,WXUINT uFlag
387 );
388 bool HandleGetMinMaxInfo(PSWP pMmInfo);
389 bool HandleShow( bool bShow
390 ,int nStatus
391 );
392 bool HandleActivate( int nFlag
393 ,WXHWND hActivate
394 );
395 bool HandleCommand( WXWORD nId
396 ,WXWORD nCmd
397 ,WXHWND hControl
398 );
399 bool HandleSysCommand( WXWPARAM wParam
400 ,WXLPARAM lParam
401 );
402 bool HandlePaletteChanged(void);
403 bool HandleQueryNewPalette(void);
404 bool HandleSysColorChange(void);
405 bool HandleDisplayChange(void);
406 bool HandleCaptureChanged(WXHWND hBainedCapture);
407
408 bool HandleCtlColor(WXHBRUSH* hBrush);
409 bool HandleSetFocus(WXHWND hWnd);
410 bool HandleKillFocus(WXHWND hWnd);
411 bool HandleEndDrag(WXWPARAM wParam);
412 bool HandleMouseEvent( WXUINT uMsg
413 ,int nX
414 ,int nY
415 ,WXUINT uFlags
416 );
417 bool HandleMouseMove( int nX
418 ,int nY
419 ,WXUINT uFlags
420 );
421 bool HandleChar( WXWPARAM wParam
422 ,WXLPARAM lParam
423 ,bool bIsASCII = FALSE
424 );
425 bool HandleKeyDown( WXWPARAM wParam
426 ,WXLPARAM lParam
427 );
428 bool HandleKeyUp( WXWPARAM wParam
429 ,WXLPARAM lParam
430 );
431 bool HandleQueryDragIcon(WXHICON* phIcon);
432 bool HandleSetCursor( USHORT vId
433 ,WXHWND hWnd
434 );
435
436 bool IsMouseInWindow(void) const;
437 bool OS2GetCreateWindowCoords( const wxPoint& rPos
438 ,const wxSize& rSize
439 ,int& rnX
440 ,int& rnY
441 ,int& rnWidth
442 ,int& rnHeight
443 ) const;
444
445 // Window procedure
446 virtual MRESULT OS2WindowProc( WXUINT uMsg
447 ,WXWPARAM wParam
448 ,WXLPARAM lParam
449 );
450
451 // Calls an appropriate default window procedure
452 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
453 ,WXWPARAM wParam
454 ,WXLPARAM lParam
455 );
456 virtual bool OS2ProcessMessage(WXMSG* pMsg);
457 virtual bool OS2ShouldPreProcessMessage(WXMSG* pMsg);
458 virtual bool OS2TranslateMessage(WXMSG* pMsg);
459 virtual void OS2DestroyWindow(void);
460
461 // this function should return the brush to paint the window background
462 // with or 0 for the default brush
463 virtual WXHBRUSH OnCtlColor( WXHDC hDC
464 ,WXHWND hWnd
465 ,WXUINT uCtlColor
466 ,WXUINT uMessage
467 ,WXWPARAM wParam
468 ,WXLPARAM lParam
469 );
470
471 #if WXWIN_COMPATIBILITY
472 void SetShowing(bool bShow) { (void)Show(show); }
473 bool IsUserEnabled(void) const { return IsEnabled(); }
474 #endif // WXWIN_COMPATIBILITY
475
476 // Responds to colour changes: passes event on to children.
477 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
478
479 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
480 void InitMouseEvent( wxMouseEvent& rEvent
481 ,int nX
482 ,int nY
483 ,WXUINT uFlags
484 );
485
486 void MoveChildren(int nDiff);
487 PSWP GetSwp(void) {return &m_vWinSwp;}
488
489 protected:
490 // PM can't create some MSW styles natively but can perform these after
491 // creation by sending messages
492 typedef enum extra_flags { kFrameToolWindow = 0x0001
493 ,kVertCaption = 0x0002
494 ,kHorzCaption = 0x0004
495 } EExtraFlags;
496 // Some internal sizeing id's to make it easy for event handlers
497 typedef enum size_types { kSizeNormal
498 ,kSizeMax
499 ,kSizeMin
500 } ESizeTypes;
501 // the window handle
502 WXHWND m_hWnd;
503
504 // the old window proc (we subclass all windows)
505 WXFARPROC m_fnOldWndProc;
506
507 // additional (OS2 specific) flags
508 bool m_bUseCtl3D:1; // Using CTL3D for this control
509 bool m_bBackgroundTransparent:1;
510 bool m_bMouseInWindow:1;
511 bool m_bLastKeydownProcessed:1;
512 bool m_bWinCaptured:1;
513 WXDWORD m_dwExStyle;
514
515 // the size of one page for scrolling
516 int m_nXThumbSize;
517 int m_nYThumbSize;
518
519 #if wxUSE_MOUSEEVENT_HACK
520 // the coordinates of the last mouse event and the type of it
521 long m_lLastMouseX,
522 long m_lLastMouseY;
523 int m_nLastMouseEvent;
524 #endif // wxUSE_MOUSEEVENT_HACK
525
526 WXHMENU m_hMenu; // Menu, if any
527 unsigned long m_ulMenubarId; // it's Id, if any
528
529 // the return value of WM_GETDLGCODE handler
530 long m_lDlgCode;
531
532 // implement the base class pure virtuals
533 virtual void DoClientToScreen( int* pX
534 ,int* pY
535 ) const;
536 virtual void DoScreenToClient( int* pX
537 ,int* pY
538 ) const;
539 virtual void DoGetPosition( int* pX
540 ,int* pY
541 ) const;
542 virtual void DoGetSize( int* pWidth
543 ,int* pHeight
544 ) const;
545 virtual void DoGetClientSize( int* pWidth
546 ,int* pHeight
547 ) const;
548 virtual void DoSetSize( int nX
549 ,int nY
550 ,int nWidth
551 ,int nHeight
552 ,int nSizeFlags = wxSIZE_AUTO
553 );
554 virtual void DoSetClientSize( int nWidth
555 ,int nHeight
556 );
557
558 virtual void DoCaptureMouse(void);
559 virtual void DoReleaseMouse(void);
560
561 // move the window to the specified location and resize it: this is called
562 // from both DoSetSize() and DoSetClientSize() and would usually just call
563 // ::WinSetWindowPos() except for composite controls which will want to arrange
564 // themselves inside the given rectangle
565 virtual void DoMoveWindow( int nX
566 ,int nY
567 ,int nWidth
568 ,int nHeight
569 );
570
571 #if wxUSE_TOOLTIPS
572 virtual void DoSetToolTip(wxToolTip* pTip);
573 #endif // wxUSE_TOOLTIPS
574
575 int GetOS2ParentHeight(wxWindowOS2* pParent);
576
577 private:
578 // common part of all ctors
579 void Init(void);
580
581 // the (non-virtual) handlers for the events
582 bool HandleMove( int nX
583 ,int nY
584 );
585 bool HandleJoystickEvent( WXUINT uMsg
586 ,int pX
587 ,int pY
588 ,WXUINT uFlags
589 );
590
591 bool HandleNotify( int nIdCtrl
592 ,WXLPARAM lParam
593 ,WXLPARAM* pResult
594 );
595 // the helper functions used by HandleChar/KeyXXX methods
596 wxKeyEvent CreateKeyEvent( wxEventType evType
597 ,int nId
598 ,WXLPARAM lParam = 0
599 ,WXWPARAM wParam = 0
600 ) const;
601
602 wxWindowList* m_pChildrenDisabled;
603 HWND m_hWndScrollBarHorz;
604 HWND m_hWndScrollBarVert;
605 SWP m_vWinSwp;
606
607 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
608 DECLARE_NO_COPY_CLASS(wxWindowOS2)
609 DECLARE_EVENT_TABLE()
610
611 //
612 // Virtual function hiding supression
613 //
614 inline virtual bool Reparent(wxWindowBase* pNewParent)
615 { return(wxWindowBase::Reparent(pNewParent));}
616 }; // end of wxWindow
617
618 class wxWindowCreationHook
619 {
620 public:
621 wxWindowCreationHook(wxWindow* pWinBeingCreated);
622 ~wxWindowCreationHook();
623 }; // end of CLASS wxWindowCreationHook
624
625 // ---------------------------------------------------------------------------
626 // global functions
627 // ---------------------------------------------------------------------------
628
629 // kbd code translation
630 WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
631 WXDLLEXPORT int wxCharCodeWXToOS2( int nId
632 ,bool* pbIsVirtual
633 );
634 #endif
635 // _WX_WINDOW_H_