window.h 22 KB

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