private.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/cocoa/private.h
  3. // Purpose: Private declarations: as this header is only included by
  4. // wxWidgets itself, it may contain identifiers which don't start
  5. // with "wx".
  6. // Author: Stefan Csomor
  7. // Modified by:
  8. // Created: 1998-01-01
  9. // Copyright: (c) Stefan Csomor
  10. // Licence: wxWindows licence
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef _WX_PRIVATE_COCOA_H_
  13. #define _WX_PRIVATE_COCOA_H_
  14. #include <ApplicationServices/ApplicationServices.h>
  15. #ifdef __OBJC__
  16. #import <Cocoa/Cocoa.h>
  17. #endif
  18. //
  19. // shared between Cocoa and Carbon
  20. //
  21. // bring in theming types without pulling in the headers
  22. #if wxUSE_GUI
  23. typedef SInt16 ThemeBrush;
  24. CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
  25. OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
  26. CGContextRef inContext,
  27. const CGRect * inBounds,
  28. CGImageRef inImage) ;
  29. WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0 );
  30. CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
  31. CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage);
  32. wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
  33. WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
  34. class WXDLLIMPEXP_FWD_CORE wxDialog;
  35. class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
  36. {
  37. public :
  38. wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false, bool isUserPane = false ) ;
  39. wxWidgetCocoaImpl() ;
  40. ~wxWidgetCocoaImpl();
  41. void Init();
  42. virtual bool IsVisible() const ;
  43. virtual void SetVisibility(bool);
  44. // we provide a static function which can be reused from
  45. // wxNonOwnedWindowCocoaImpl too
  46. static bool ShowViewOrWindowWithEffect(wxWindow *win,
  47. bool show,
  48. wxShowEffect effect,
  49. unsigned timeout);
  50. virtual bool ShowWithEffect(bool show,
  51. wxShowEffect effect,
  52. unsigned timeout);
  53. virtual void Raise();
  54. virtual void Lower();
  55. virtual void ScrollRect( const wxRect *rect, int dx, int dy );
  56. virtual WXWidget GetWXWidget() const { return m_osxView; }
  57. virtual void SetBackgroundColour(const wxColour&);
  58. virtual bool SetBackgroundStyle(wxBackgroundStyle style);
  59. virtual void GetContentArea( int &left , int &top , int &width , int &height ) const;
  60. virtual void Move(int x, int y, int width, int height);
  61. virtual void GetPosition( int &x, int &y ) const;
  62. virtual void GetSize( int &width, int &height ) const;
  63. virtual void SetControlSize( wxWindowVariant variant );
  64. virtual void SetNeedsDisplay( const wxRect* where = NULL );
  65. virtual bool GetNeedsDisplay() const;
  66. virtual void SetDrawingEnabled(bool enabled);
  67. virtual bool CanFocus() const;
  68. // return true if successful
  69. virtual bool SetFocus();
  70. virtual bool HasFocus() const;
  71. void RemoveFromParent();
  72. void Embed( wxWidgetImpl *parent );
  73. void SetDefaultButton( bool isDefault );
  74. void PerformClick();
  75. virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
  76. void SetCursor( const wxCursor & cursor );
  77. void CaptureMouse();
  78. void ReleaseMouse();
  79. #if wxUSE_DRAG_AND_DROP
  80. void SetDropTarget(wxDropTarget* target);
  81. #endif
  82. wxInt32 GetValue() const;
  83. void SetValue( wxInt32 v );
  84. wxBitmap GetBitmap() const;
  85. void SetBitmap( const wxBitmap& bitmap );
  86. void SetBitmapPosition( wxDirection dir );
  87. void SetupTabs( const wxNotebook &notebook );
  88. void GetBestRect( wxRect *r ) const;
  89. bool IsEnabled() const;
  90. void Enable( bool enable );
  91. bool ButtonClickDidStateChange() { return true ;}
  92. void SetMinimum( wxInt32 v );
  93. void SetMaximum( wxInt32 v );
  94. wxInt32 GetMinimum() const;
  95. wxInt32 GetMaximum() const;
  96. void PulseGauge();
  97. void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
  98. void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
  99. void SetToolTip( wxToolTip* tooltip );
  100. void InstallEventHandler( WXWidget control = NULL );
  101. virtual bool DoHandleMouseEvent(NSEvent *event);
  102. virtual bool DoHandleKeyEvent(NSEvent *event);
  103. virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
  104. virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
  105. virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
  106. virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
  107. void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
  108. virtual bool SetupCursor(NSEvent* event);
  109. #if !wxOSX_USE_NATIVE_FLIPPED
  110. void SetFlipped(bool flipped);
  111. virtual bool IsFlipped() const { return m_isFlipped; }
  112. #endif
  113. virtual double GetContentScaleFactor() const;
  114. // cocoa thunk connected calls
  115. #if wxUSE_DRAG_AND_DROP
  116. virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
  117. virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
  118. virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
  119. virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
  120. #endif
  121. virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
  122. virtual void cursorUpdate(WX_NSEvent event, WXWidget slf, void* _cmd);
  123. virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
  124. virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
  125. virtual void doCommandBySelector(void* sel, WXWidget slf, void* _cmd);
  126. virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
  127. virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
  128. virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
  129. virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
  130. #if !wxOSX_USE_NATIVE_FLIPPED
  131. virtual bool isFlipped(WXWidget slf, void* _cmd);
  132. #endif
  133. virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
  134. virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
  135. virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
  136. // for wxTextCtrl-derived classes, put here since they don't all derive
  137. // from the same pimpl class.
  138. virtual void controlTextDidChange();
  139. protected:
  140. WXWidget m_osxView;
  141. NSEvent* m_lastKeyDownEvent;
  142. #if !wxOSX_USE_NATIVE_FLIPPED
  143. bool m_isFlipped;
  144. #endif
  145. // if it the control has an editor, that editor will already send some
  146. // events, don't resend them
  147. bool m_hasEditor;
  148. DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
  149. };
  150. DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
  151. class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
  152. {
  153. public :
  154. wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
  155. wxNonOwnedWindowCocoaImpl();
  156. virtual ~wxNonOwnedWindowCocoaImpl();
  157. virtual void WillBeDestroyed() ;
  158. void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
  159. long style, long extraStyle, const wxString& name ) ;
  160. void Create( wxWindow* parent, WXWindow nativeWindow );
  161. WXWindow GetWXWindow() const;
  162. void Raise();
  163. void Lower();
  164. bool Show(bool show);
  165. virtual bool ShowWithEffect(bool show,
  166. wxShowEffect effect,
  167. unsigned timeout);
  168. void Update();
  169. bool SetTransparent(wxByte alpha);
  170. bool SetBackgroundColour(const wxColour& col );
  171. void SetExtraStyle( long exStyle );
  172. void SetWindowStyleFlag( long style );
  173. bool SetBackgroundStyle(wxBackgroundStyle style);
  174. bool CanSetTransparent();
  175. void MoveWindow(int x, int y, int width, int height);
  176. void GetPosition( int &x, int &y ) const;
  177. void GetSize( int &width, int &height ) const;
  178. void GetContentArea( int &left , int &top , int &width , int &height ) const;
  179. bool SetShape(const wxRegion& region);
  180. virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
  181. virtual bool IsMaximized() const;
  182. virtual bool IsIconized() const;
  183. virtual void Iconize( bool iconize );
  184. virtual void Maximize(bool maximize);
  185. virtual bool IsFullScreen() const;
  186. virtual bool ShowFullScreen(bool show, long style);
  187. virtual void ShowWithoutActivating();
  188. virtual void RequestUserAttention(int flags);
  189. virtual void ScreenToWindow( int *x, int *y );
  190. virtual void WindowToScreen( int *x, int *y );
  191. virtual bool IsActive();
  192. virtual void SetModified(bool modified);
  193. virtual bool IsModified() const;
  194. virtual void SetRepresentedFilename(const wxString& filename);
  195. wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
  196. CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; }
  197. void RestoreWindowLevel();
  198. static WX_NSResponder GetNextFirstResponder() ;
  199. protected :
  200. CGWindowLevel m_macWindowLevel;
  201. WXWindow m_macWindow;
  202. void * m_macFullScreenData ;
  203. DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
  204. };
  205. DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton );
  206. class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
  207. {
  208. public:
  209. wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v);
  210. virtual void SetBitmap(const wxBitmap& bitmap);
  211. #if wxUSE_MARKUP
  212. virtual void SetLabelMarkup(const wxString& markup);
  213. #endif // wxUSE_MARKUP
  214. void SetPressedBitmap( const wxBitmap& bitmap );
  215. void GetLayoutInset(int &left , int &top , int &right, int &bottom) const;
  216. void SetAcceleratorFromLabel(const wxString& label);
  217. NSButton *GetNSButton() const;
  218. };
  219. #ifdef __OBJC__
  220. typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
  221. typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
  222. typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
  223. typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
  224. WXDLLIMPEXP_CORE NSScreen* wxOSXGetMenuScreen();
  225. WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
  226. WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
  227. WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
  228. WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
  229. NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
  230. bool adjustForOrigin = true );
  231. WXDLLIMPEXP_CORE NSView* wxOSXGetViewFromResponder( NSResponder* responder );
  232. // used for many wxControls
  233. @interface wxNSButton : NSButton
  234. {
  235. NSTrackingRectTag rectTag;
  236. }
  237. @end
  238. @interface wxNSBox : NSBox
  239. {
  240. }
  241. @end
  242. @interface wxNSTextFieldEditor : NSTextView
  243. {
  244. NSEvent* lastKeyDownEvent;
  245. }
  246. @end
  247. @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
  248. {
  249. wxNSTextFieldEditor* fieldEditor;
  250. }
  251. - (wxNSTextFieldEditor*) fieldEditor;
  252. - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
  253. @end
  254. @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
  255. {
  256. }
  257. @end
  258. @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
  259. {
  260. }
  261. - (void)textDidChange:(NSNotification *)aNotification;
  262. @end
  263. @interface wxNSComboBox : NSComboBox
  264. {
  265. wxNSTextFieldEditor* fieldEditor;
  266. }
  267. - (wxNSTextFieldEditor*) fieldEditor;
  268. - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
  269. @end
  270. @interface wxNSMenu : NSMenu
  271. {
  272. wxMenuImpl* impl;
  273. }
  274. - (void) setImplementation:(wxMenuImpl*) item;
  275. - (wxMenuImpl*) implementation;
  276. @end
  277. @interface wxNSMenuItem : NSMenuItem
  278. {
  279. wxMenuItemImpl* impl;
  280. }
  281. - (void) setImplementation:(wxMenuItemImpl*) item;
  282. - (wxMenuItemImpl*) implementation;
  283. - (void)clickedAction:(id)sender;
  284. - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
  285. @end
  286. void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
  287. /*
  288. We need this for ShowModal, as the sheet just disables the parent window and
  289. returns control to the app, whereas we don't want to return from ShowModal
  290. until the sheet has been dismissed.
  291. */
  292. @interface ModalDialogDelegate : NSObject
  293. {
  294. BOOL sheetFinished;
  295. int resultCode;
  296. wxDialog* impl;
  297. }
  298. - (void)setImplementation: (wxDialog *)dialog;
  299. - (BOOL)finished;
  300. - (int)code;
  301. - (void)waitForSheetToFinish;
  302. - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
  303. @end
  304. // This interface must be exported in shared 64 bit multilib build but
  305. // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
  306. // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
  307. // builds but seems to be unnecessary there so to avoid the expense of a
  308. // configure check verifying if this does work or not with the current
  309. // compiler we just only use it for 64 bit builds where this is always
  310. // supported.
  311. //
  312. // NB: Currently this is the only place where we need to export an
  313. // interface but if we need to do it elsewhere we should define a
  314. // WXEXPORT_OBJC macro once and reuse it in all places it's needed
  315. // instead of duplicating this preprocessor check.
  316. #ifdef __LP64__
  317. WXEXPORT
  318. #endif // 64 bit builds
  319. @interface wxNSAppController : NSObject wxOSX_10_6_AND_LATER(<NSApplicationDelegate>)
  320. {
  321. }
  322. @end
  323. #endif // __OBJC__
  324. // NSCursor
  325. WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
  326. WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
  327. void wxMacCocoaSetCursor( WX_NSCursor cursor );
  328. void wxMacCocoaHideCursor();
  329. void wxMacCocoaShowCursor();
  330. typedef struct tagClassicCursor
  331. {
  332. wxUint16 bits[16];
  333. wxUint16 mask[16];
  334. wxInt16 hotspot[2];
  335. }ClassicCursor;
  336. const short kwxCursorBullseye = 0;
  337. const short kwxCursorBlank = 1;
  338. const short kwxCursorPencil = 2;
  339. const short kwxCursorMagnifier = 3;
  340. const short kwxCursorNoEntry = 4;
  341. const short kwxCursorPaintBrush = 5;
  342. const short kwxCursorPointRight = 6;
  343. const short kwxCursorPointLeft = 7;
  344. const short kwxCursorQuestionArrow = 8;
  345. const short kwxCursorRightArrow = 9;
  346. const short kwxCursorSizeNS = 10;
  347. const short kwxCursorSize = 11;
  348. const short kwxCursorSizeNESW = 12;
  349. const short kwxCursorSizeNWSE = 13;
  350. const short kwxCursorRoller = 14;
  351. const short kwxCursorWatch = 15;
  352. const short kwxCursorLast = kwxCursorWatch;
  353. // exposing our fallback cursor map
  354. extern ClassicCursor gMacCursors[];
  355. extern NSLayoutManager* gNSLayoutManager;
  356. #endif
  357. #endif
  358. // _WX_PRIVATE_COCOA_H_