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