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