window.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/window.h
  3. // Purpose: wxWindowMac class
  4. // Author: Stefan Csomor
  5. // Modified by:
  6. // Created: 1998-01-01
  7. // Copyright: (c) Stefan Csomor
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_WINDOW_H_
  11. #define _WX_WINDOW_H_
  12. #include "wx/brush.h"
  13. #include "wx/dc.h"
  14. class WXDLLIMPEXP_FWD_CORE wxButton;
  15. class WXDLLIMPEXP_FWD_CORE wxScrollBar;
  16. class WXDLLIMPEXP_FWD_CORE wxPanel;
  17. class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
  18. #if wxOSX_USE_CARBON
  19. class WXDLLIMPEXP_FWD_CORE wxMacControl ;
  20. typedef wxMacControl wxOSXWidgetImpl;
  21. #elif wxOSX_USE_COCOA_OR_IPHONE
  22. class WXDLLIMPEXP_FWD_CORE wxWidgetImpl ;
  23. typedef wxWidgetImpl wxOSXWidgetImpl;
  24. #endif
  25. class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
  26. {
  27. DECLARE_DYNAMIC_CLASS(wxWindowMac)
  28. friend class wxDC;
  29. friend class wxPaintDC;
  30. public:
  31. wxWindowMac();
  32. wxWindowMac( wxWindowMac *parent,
  33. wxWindowID id,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize,
  36. long style = 0,
  37. const wxString& name = wxPanelNameStr );
  38. virtual ~wxWindowMac();
  39. bool Create( wxWindowMac *parent,
  40. wxWindowID id,
  41. const wxPoint& pos = wxDefaultPosition,
  42. const wxSize& size = wxDefaultSize,
  43. long style = 0,
  44. const wxString& name = wxPanelNameStr );
  45. virtual void SendSizeEvent(int flags = 0);
  46. // implement base class pure virtuals
  47. virtual void SetLabel( const wxString& label );
  48. virtual wxString GetLabel() const;
  49. virtual void Raise();
  50. virtual void Lower();
  51. virtual bool Show( bool show = true );
  52. virtual bool ShowWithEffect(wxShowEffect effect,
  53. unsigned timeout = 0)
  54. {
  55. return OSXShowWithEffect(true, effect, timeout);
  56. }
  57. virtual bool HideWithEffect(wxShowEffect effect,
  58. unsigned timeout = 0)
  59. {
  60. return OSXShowWithEffect(false, effect, timeout);
  61. }
  62. virtual bool IsShownOnScreen() const;
  63. virtual void SetFocus();
  64. virtual void WarpPointer( int x, int y );
  65. virtual void Refresh( bool eraseBackground = true,
  66. const wxRect *rect = NULL );
  67. virtual void Update() ;
  68. virtual void ClearBackground();
  69. virtual bool SetCursor( const wxCursor &cursor );
  70. virtual bool SetFont( const wxFont &font );
  71. virtual bool SetBackgroundColour( const wxColour &colour );
  72. virtual bool SetForegroundColour( const wxColour &colour );
  73. virtual bool SetBackgroundStyle(wxBackgroundStyle style);
  74. virtual int GetCharHeight() const;
  75. virtual int GetCharWidth() const;
  76. public:
  77. virtual void SetScrollbar( int orient, int pos, int thumbVisible,
  78. int range, bool refresh = true );
  79. virtual void SetScrollPos( int orient, int pos, bool refresh = true );
  80. virtual int GetScrollPos( int orient ) const;
  81. virtual int GetScrollThumb( int orient ) const;
  82. virtual int GetScrollRange( int orient ) const;
  83. virtual void ScrollWindow( int dx, int dy,
  84. const wxRect* rect = NULL );
  85. virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
  86. virtual bool IsScrollbarAlwaysShown(int orient) const
  87. {
  88. return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
  89. : m_vScrollBarAlwaysShown;
  90. }
  91. virtual bool Reparent( wxWindowBase *newParent );
  92. #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
  93. // hot keys (system wide accelerators)
  94. // -----------------------------------
  95. virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
  96. virtual bool UnregisterHotKey(int hotkeyId);
  97. #endif // wxUSE_HOTKEY
  98. #if wxUSE_DRAG_AND_DROP
  99. virtual void SetDropTarget( wxDropTarget *dropTarget );
  100. #endif
  101. // Accept files for dragging
  102. virtual void DragAcceptFiles( bool accept );
  103. // implementation from now on
  104. // --------------------------
  105. void MacClientToRootWindow( int *x , int *y ) const;
  106. void MacWindowToRootWindow( int *x , int *y ) const;
  107. void MacRootWindowToWindow( int *x , int *y ) const;
  108. virtual wxString MacGetToolTipString( wxPoint &where );
  109. // simple accessors
  110. // ----------------
  111. virtual WXWidget GetHandle() const;
  112. virtual bool SetTransparent(wxByte alpha);
  113. virtual bool CanSetTransparent();
  114. virtual wxByte GetTransparent() const ;
  115. // event handlers
  116. // --------------
  117. void OnMouseEvent( wxMouseEvent &event );
  118. void MacOnScroll( wxScrollEvent&event );
  119. virtual bool AcceptsFocus() const;
  120. virtual bool IsDoubleBuffered() const { return true; }
  121. public:
  122. static long MacRemoveBordersFromStyle( long style ) ;
  123. public:
  124. // For implementation purposes:
  125. // sometimes decorations make the client area smaller
  126. virtual wxPoint GetClientAreaOrigin() const;
  127. wxWindowMac *FindItem(long id) const;
  128. wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
  129. virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
  130. // this should not be overridden in classes above wxWindowMac
  131. // because it is called from its destructor via DeleteChildren
  132. virtual void RemoveChild( wxWindowBase *child );
  133. virtual bool MacDoRedraw( long time ) ;
  134. virtual void MacPaintChildrenBorders();
  135. virtual void MacPaintBorders( int left , int top ) ;
  136. void MacPaintGrowBox();
  137. // invalidates the borders and focus area around the control;
  138. // must not be virtual as it will be called during destruction
  139. void MacInvalidateBorders() ;
  140. WXWindow MacGetTopLevelWindowRef() const ;
  141. wxNonOwnedWindow* MacGetTopLevelWindow() const ;
  142. virtual long MacGetWXBorderSize() const;
  143. virtual long MacGetLeftBorderSize() const ;
  144. virtual long MacGetRightBorderSize() const ;
  145. virtual long MacGetTopBorderSize() const ;
  146. virtual long MacGetBottomBorderSize() const ;
  147. virtual void MacSuperChangedPosition() ;
  148. // absolute coordinates of this window's root have changed
  149. virtual void MacTopLevelWindowChangedPosition() ;
  150. virtual void MacChildAdded() ;
  151. virtual void MacVisibilityChanged() ;
  152. virtual void MacEnabledStateChanged() ;
  153. virtual void MacHiliteChanged() ;
  154. virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
  155. bool MacIsReallyEnabled() ;
  156. bool MacIsReallyHilited() ;
  157. #if WXWIN_COMPATIBILITY_2_8
  158. bool MacIsUserPane();
  159. #endif
  160. bool MacIsUserPane() const;
  161. virtual bool MacSetupCursor( const wxPoint& pt ) ;
  162. // return the rectangle that would be visible of this control,
  163. // regardless whether controls are hidden
  164. // only taking into account clipping by parent windows
  165. const wxRect& MacGetClippedClientRect() const ;
  166. const wxRect& MacGetClippedRect() const ;
  167. const wxRect& MacGetClippedRectWithOuterStructure() const ;
  168. // returns the visible region of this control in window ie non-client coordinates
  169. const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
  170. // returns true if children have to clipped to the content area
  171. // (e.g., scrolled windows)
  172. bool MacClipChildren() const { return m_clipChildren ; }
  173. void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
  174. // returns true if the grandchildren need to be clipped to the children's content area
  175. // (e.g., splitter windows)
  176. virtual bool MacClipGrandChildren() const { return false ; }
  177. bool MacIsWindowScrollbar( const wxWindow* sb ) const
  178. { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
  179. virtual bool IsClientAreaChild(const wxWindow *child) const
  180. {
  181. return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
  182. wxWindowBase::IsClientAreaChild(child);
  183. }
  184. void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
  185. wxList& GetSubcontrols() { return m_subControls; }
  186. // translate wxWidgets coords into ones suitable
  187. // to be passed to CreateControl calls
  188. //
  189. // returns true if non-default coords are returned, false otherwise
  190. bool MacGetBoundsForControl(const wxPoint& pos,
  191. const wxSize& size,
  192. int& x, int& y,
  193. int& w, int& h , bool adjustForOrigin ) const ;
  194. // the 'true' OS level control for this wxWindow
  195. wxOSXWidgetImpl* GetPeer() const;
  196. // optimization to avoid creating a user pane in wxWindow::Create if we already know
  197. // we will replace it with our own peer
  198. void DontCreatePeer();
  199. // return true unless DontCreatePeer() had been called
  200. bool ShouldCreatePeer() const;
  201. // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
  202. // release existing peer
  203. void SetPeer(wxOSXWidgetImpl* peer);
  204. // wraps the already existing peer with the wrapper
  205. void SetWrappingPeer(wxOSXWidgetImpl* wrapper);
  206. #if wxOSX_USE_COCOA_OR_IPHONE
  207. // the NSView or NSWindow of this window: can be used for both child and
  208. // non-owned windows
  209. //
  210. // this is useful for a few Cocoa function which can work with either views
  211. // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
  212. virtual void *OSXGetViewOrWindow() const;
  213. #endif // Cocoa
  214. void * MacGetCGContextRef() { return m_cgContextRef ; }
  215. void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
  216. // osx specific event handling common for all osx-ports
  217. virtual bool OSXHandleClicked( double timestampsec );
  218. virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
  219. virtual void OSXSimulateFocusEvents();
  220. bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
  221. double GetContentScaleFactor() const ;
  222. // internal response to size events
  223. virtual void MacOnInternalSize() {}
  224. protected:
  225. // For controls like radio buttons which are genuinely composite
  226. wxList m_subControls;
  227. // the peer object, allowing for cleaner API support
  228. void * m_cgContextRef ;
  229. // cache the clipped rectangles within the window hierarchy
  230. void MacUpdateClippedRects() const ;
  231. mutable bool m_cachedClippedRectValid ;
  232. mutable wxRect m_cachedClippedRectWithOuterStructure ;
  233. mutable wxRect m_cachedClippedRect ;
  234. mutable wxRect m_cachedClippedClientRect ;
  235. mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
  236. mutable wxRegion m_cachedClippedRegion ;
  237. mutable wxRegion m_cachedClippedClientRegion ;
  238. // insets of the mac control from the wx top left corner
  239. wxPoint m_macTopLeftInset ;
  240. wxPoint m_macBottomRightInset ;
  241. wxByte m_macAlpha ;
  242. wxScrollBar* m_hScrollBar ;
  243. wxScrollBar* m_vScrollBar ;
  244. bool m_hScrollBarAlwaysShown;
  245. bool m_vScrollBarAlwaysShown;
  246. wxWindow* m_growBox ;
  247. wxString m_label ;
  248. bool m_isNativeWindowWrapper;
  249. // set to true if we do a sharp clip at the content area of this window
  250. // must be dynamic as eg a panel normally is not clipping precisely, but if
  251. // it becomes the target window of a scrolled window it has to...
  252. bool m_clipChildren ;
  253. virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
  254. bool MacHasScrollBarCorner() const;
  255. void MacCreateScrollBars( long style ) ;
  256. void MacRepositionScrollBars() ;
  257. void MacUpdateControlFont() ;
  258. // implement the base class pure virtuals
  259. virtual void DoGetTextExtent(const wxString& string,
  260. int *x, int *y,
  261. int *descent = NULL,
  262. int *externalLeading = NULL,
  263. const wxFont *theFont = NULL ) const;
  264. virtual void DoEnable( bool enable );
  265. #if wxUSE_MENUS
  266. virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
  267. #endif
  268. virtual void DoFreeze();
  269. virtual void DoThaw();
  270. virtual wxSize DoGetBestSize() const;
  271. virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
  272. virtual void DoClientToScreen( int *x, int *y ) const;
  273. virtual void DoScreenToClient( int *x, int *y ) const;
  274. virtual void DoGetPosition( int *x, int *y ) const;
  275. virtual void DoGetSize( int *width, int *height ) const;
  276. virtual void DoGetClientSize( int *width, int *height ) const;
  277. virtual void DoSetSize(int x, int y,
  278. int width, int height,
  279. int sizeFlags = wxSIZE_AUTO);
  280. virtual void DoSetClientSize(int width, int height);
  281. virtual void DoCaptureMouse();
  282. virtual void DoReleaseMouse();
  283. // move the window to the specified location and resize it: this is called
  284. // from both DoSetSize() and DoSetClientSize() and would usually just call
  285. // ::MoveWindow() except for composite controls which will want to arrange
  286. // themselves inside the given rectangle
  287. virtual void DoMoveWindow( int x, int y, int width, int height );
  288. virtual void DoSetWindowVariant( wxWindowVariant variant );
  289. #if wxUSE_TOOLTIPS
  290. virtual void DoSetToolTip( wxToolTip *tip );
  291. #endif
  292. // common part of Show/HideWithEffect()
  293. virtual bool OSXShowWithEffect(bool show,
  294. wxShowEffect effect,
  295. unsigned timeout);
  296. private:
  297. wxOSXWidgetImpl * m_peer ;
  298. // common part of all ctors
  299. void Init();
  300. // show/hide scrollbars as needed, common part of SetScrollbar() and
  301. // AlwaysShowScrollbars()
  302. void DoUpdateScrollbarVisibility();
  303. wxDECLARE_NO_COPY_CLASS(wxWindowMac);
  304. DECLARE_EVENT_TABLE()
  305. };
  306. #endif // _WX_WINDOW_H_