]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/window.h
33ac3ce48baf5fe63d9f922b58219e34add3ba44
[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(void);
394 bool HandleQueryNewPalette(void);
395 bool HandleSysColorChange(void);
396 bool HandleDisplayChange(void);
397 bool HandleCaptureChanged(WXHWND hBainedCapture);
398
399 bool HandleCtlColor(WXHBRUSH* hBrush);
400 bool HandleSetFocus(WXHWND hWnd);
401 bool HandleKillFocus(WXHWND hWnd);
402 bool HandleEndDrag(WXWPARAM wParam);
403 bool HandleMouseEvent( WXUINT uMsg
404 ,int nX
405 ,int nY
406 ,WXUINT uFlags
407 );
408 bool HandleMouseMove( int nX
409 ,int nY
410 ,WXUINT uFlags
411 );
412 bool HandleChar( WXWPARAM wParam
413 ,WXLPARAM lParam
414 ,bool bIsASCII = FALSE
415 );
416 bool HandleKeyDown( WXWPARAM wParam
417 ,WXLPARAM lParam
418 );
419 bool HandleKeyUp( WXWPARAM wParam
420 ,WXLPARAM lParam
421 );
422 bool HandleQueryDragIcon(WXHICON* phIcon);
423 bool HandleSetCursor( USHORT vId
424 ,WXHWND hWnd
425 );
426
427 bool IsMouseInWindow(void) const;
428 bool OS2GetCreateWindowCoords( const wxPoint& rPos
429 ,const wxSize& rSize
430 ,int& rnX
431 ,int& rnY
432 ,int& rnWidth
433 ,int& rnHeight
434 ) const;
435
436 // Window procedure
437 virtual MRESULT OS2WindowProc( WXUINT uMsg
438 ,WXWPARAM wParam
439 ,WXLPARAM lParam
440 );
441
442 // Calls an appropriate default window procedure
443 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
444 ,WXWPARAM wParam
445 ,WXLPARAM lParam
446 );
447 virtual bool OS2ProcessMessage(WXMSG* pMsg);
448 virtual bool OS2ShouldPreProcessMessage(WXMSG* pMsg);
449 virtual bool OS2TranslateMessage(WXMSG* pMsg);
450 virtual void OS2DestroyWindow(void);
451
452 // this function should return the brush to paint the window background
453 // with or 0 for the default brush
454 virtual WXHBRUSH OnCtlColor( WXHDC hDC
455 ,WXHWND hWnd
456 ,WXUINT uCtlColor
457 ,WXUINT uMessage
458 ,WXWPARAM wParam
459 ,WXLPARAM lParam
460 );
461
462 #if WXWIN_COMPATIBILITY
463 void SetShowing(bool bShow) { (void)Show(show); }
464 bool IsUserEnabled(void) const { return IsEnabled(); }
465 #endif // WXWIN_COMPATIBILITY
466
467 // Responds to colour changes: passes event on to children.
468 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
469
470 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
471 void InitMouseEvent( wxMouseEvent& rEvent
472 ,int nX
473 ,int nY
474 ,WXUINT uFlags
475 );
476
477 void MoveChildren(int nDiff);
478 PSWP GetSwp(void) {return &m_vWinSwp;}
479
480 protected:
481 // PM can't create some MSW styles natively but can perform these after
482 // creation by sending messages
483 typedef enum extra_flags { kFrameToolWindow = 0x0001
484 ,kVertCaption = 0x0002
485 ,kHorzCaption = 0x0004
486 } EExtraFlags;
487 // Some internal sizeing id's to make it easy for event handlers
488 typedef enum size_types { kSizeNormal
489 ,kSizeMax
490 ,kSizeMin
491 } ESizeTypes;
492 // the window handle
493 WXHWND m_hWnd;
494
495 // the old window proc (we subclass all windows)
496 WXFARPROC m_fnOldWndProc;
497
498 // additional (OS2 specific) flags
499 bool m_bUseCtl3D:1; // Using CTL3D for this control
500 bool m_bBackgroundTransparent:1;
501 bool m_bMouseInWindow:1;
502 bool m_bDoubleClickAllowed:1;
503 bool m_bLastKeydownProcessed:1;
504 bool m_bWinCaptured:1;
505 WXDWORD m_dwExStyle;
506
507 // the size of one page for scrolling
508 int m_nXThumbSize;
509 int m_nYThumbSize;
510
511 #if wxUSE_MOUSEEVENT_HACK
512 // the coordinates of the last mouse event and the type of it
513 long m_lLastMouseX,
514 long m_lLastMouseY;
515 int m_nLastMouseEvent;
516 #endif // wxUSE_MOUSEEVENT_HACK
517
518 WXHMENU m_hMenu; // Menu, if any
519 unsigned long m_ulMenubarId; // it's Id, if any
520
521 // the return value of WM_GETDLGCODE handler
522 long m_lDlgCode;
523
524 // implement the base class pure virtuals
525 virtual void DoClientToScreen( int* pX
526 ,int* pY
527 ) const;
528 virtual void DoScreenToClient( int* pX
529 ,int* pY
530 ) const;
531 virtual void DoGetPosition( int* pX
532 ,int* pY
533 ) const;
534 virtual void DoGetSize( int* pWidth
535 ,int* pHeight
536 ) const;
537 virtual void DoGetClientSize( int* pWidth
538 ,int* pHeight
539 ) const;
540 virtual void DoSetSize( int nX
541 ,int nY
542 ,int nWidth
543 ,int nHeight
544 ,int nSizeFlags = wxSIZE_AUTO
545 );
546 virtual void DoSetClientSize( int nWidth
547 ,int nHeight
548 );
549
550 virtual void DoCaptureMouse(void);
551 virtual void DoReleaseMouse(void);
552
553 // move the window to the specified location and resize it: this is called
554 // from both DoSetSize() and DoSetClientSize() and would usually just call
555 // ::WinSetWindowPos() except for composite controls which will want to arrange
556 // themselves inside the given rectangle
557 virtual void DoMoveWindow( int nX
558 ,int nY
559 ,int nWidth
560 ,int nHeight
561 );
562
563 #if wxUSE_TOOLTIPS
564 virtual void DoSetToolTip(wxToolTip* pTip);
565 #endif // wxUSE_TOOLTIPS
566
567 int GetOS2ParentHeight(wxWindowOS2* pParent);
568
569 private:
570 // common part of all ctors
571 void Init(void);
572
573 // the (non-virtual) handlers for the events
574 bool HandleMove( int nX
575 ,int nY
576 );
577 bool HandleJoystickEvent( WXUINT uMsg
578 ,int pX
579 ,int pY
580 ,WXUINT uFlags
581 );
582
583 bool HandleNotify( int nIdCtrl
584 ,WXLPARAM lParam
585 ,WXLPARAM* pResult
586 );
587 // the helper functions used by HandleChar/KeyXXX methods
588 wxKeyEvent CreateKeyEvent( wxEventType evType
589 ,int nId
590 ,WXLPARAM lParam = 0
591 ,WXWPARAM wParam = 0
592 ) const;
593
594
595 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
596 DECLARE_NO_COPY_CLASS(wxWindowOS2)
597 DECLARE_EVENT_TABLE()
598
599 private:
600 HWND m_hWndScrollBarHorz;
601 HWND m_hWndScrollBarVert;
602 SWP m_vWinSwp;
603
604 // Virtual function hiding supression
605 inline virtual bool Reparent(wxWindowBase* pNewParent)
606 { return(wxWindowBase::Reparent(pNewParent));};
607 }; // end of wxWindow
608
609 class wxWindowCreationHook
610 {
611 public:
612 wxWindowCreationHook(wxWindow* pWinBeingCreated);
613 ~wxWindowCreationHook();
614 }; // end of CLASS wxWindowCreationHook
615
616 // ---------------------------------------------------------------------------
617 // global functions
618 // ---------------------------------------------------------------------------
619
620 // kbd code translation
621 WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
622 WXDLLEXPORT int wxCharCodeWXToOS2( int nId
623 ,bool* pbIsVirtual
624 );
625 #endif
626 // _WX_WINDOW_H_