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