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