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