]>
Commit | Line | Data |
---|---|---|
4849f027 SC |
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 | // RCS-ID: $Id: private.h 53819 2008-05-29 14:11:45Z SC $ | |
10 | // Copyright: (c) Stefan Csomor | |
11 | // Licence: wxWindows licence | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifndef _WX_PRIVATE_COCOA_H_ | |
15 | #define _WX_PRIVATE_COCOA_H_ | |
16 | ||
17 | #include "wx/osx/core/private.h" | |
18 | ||
935e6c7d SC |
19 | #include "wx/defs.h" |
20 | ||
21 | #include <ApplicationServices/ApplicationServices.h> | |
22 | ||
7ac5e1c9 SC |
23 | #if wxOSX_USE_ATSU_TEXT |
24 | // we need theming and atsu | |
25 | #include <Carbon/Carbon.h> | |
26 | #endif | |
27 | ||
4849f027 | 28 | #ifdef __OBJC__ |
4849f027 | 29 | #import <Cocoa/Cocoa.h> |
4850cc8b | 30 | #endif |
4849f027 | 31 | |
524c47aa SC |
32 | // |
33 | // shared between Cocoa and Carbon | |
34 | // | |
35 | ||
36 | // bring in themeing types without pulling in the headers | |
37 | ||
935e6c7d | 38 | #if wxUSE_GUI |
524c47aa | 39 | typedef SInt16 ThemeBrush; |
6da991db | 40 | CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ; |
524c47aa SC |
41 | OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( |
42 | CGContextRef inContext, | |
43 | const CGRect * inBounds, | |
44 | CGImageRef inImage) ; | |
6da991db | 45 | WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image ); |
935e6c7d | 46 | #endif |
524c47aa | 47 | |
935e6c7d | 48 | long UMAGetSystemVersion() ; |
524c47aa SC |
49 | WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to ); |
50 | WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ); | |
51 | WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ); | |
52 | WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ); | |
53 | ||
54 | // | |
55 | // | |
56 | // | |
57 | ||
4849f027 SC |
58 | #if wxUSE_GUI |
59 | ||
60 | class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl | |
61 | { | |
62 | public : | |
63 | wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ; | |
64 | wxWidgetCocoaImpl() ; | |
65 | ~wxWidgetCocoaImpl(); | |
66 | ||
67 | void Init(); | |
68 | ||
69 | virtual bool IsVisible() const ; | |
524c47aa SC |
70 | virtual void SetVisibility(bool); |
71 | ||
4849f027 SC |
72 | virtual void Raise(); |
73 | ||
74 | virtual void Lower(); | |
75 | ||
76 | virtual void ScrollRect( const wxRect *rect, int dx, int dy ); | |
77 | ||
78 | virtual WXWidget GetWXWidget() const { return m_osxView; } | |
79 | ||
524c47aa SC |
80 | virtual void SetBackgroundColour(const wxColour&); |
81 | ||
4849f027 SC |
82 | virtual void GetContentArea( int &left , int &top , int &width , int &height ) const; |
83 | virtual void Move(int x, int y, int width, int height); | |
84 | virtual void GetPosition( int &x, int &y ) const; | |
85 | virtual void GetSize( int &width, int &height ) const; | |
524c47aa | 86 | virtual void SetControlSize( wxWindowVariant variant ); |
4849f027 SC |
87 | |
88 | virtual void SetNeedsDisplay( const wxRect* where = NULL ); | |
89 | virtual bool GetNeedsDisplay() const; | |
90 | ||
91 | virtual bool CanFocus() const; | |
92 | // return true if successful | |
93 | virtual bool SetFocus(); | |
94 | virtual bool HasFocus() const; | |
95 | ||
96 | void RemoveFromParent(); | |
97 | void Embed( wxWidgetImpl *parent ); | |
524c47aa SC |
98 | |
99 | void SetDefaultButton( bool isDefault ); | |
100 | void PerformClick(); | |
101 | void SetLabel(const wxString& title, wxFontEncoding encoding); | |
102 | ||
54f11060 SC |
103 | void SetCursor( const wxCursor & cursor ); |
104 | void CaptureMouse(); | |
105 | void ReleaseMouse(); | |
106 | ||
524c47aa SC |
107 | wxInt32 GetValue() const; |
108 | void SetValue( wxInt32 v ); | |
109 | void SetBitmap( const wxBitmap& bitmap ); | |
110 | void SetupTabs( const wxNotebook ¬ebook ); | |
111 | void GetBestRect( wxRect *r ) const; | |
112 | bool IsEnabled() const; | |
113 | void Enable( bool enable ); | |
114 | bool ButtonClickDidStateChange() { return true ;} | |
115 | void SetMinimum( wxInt32 v ); | |
116 | void SetMaximum( wxInt32 v ); | |
19c7ac3d SC |
117 | wxInt32 GetMinimum() const; |
118 | wxInt32 GetMaximum() const; | |
524c47aa SC |
119 | void PulseGauge(); |
120 | void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ); | |
121 | ||
1e181c7a SC |
122 | void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ); |
123 | ||
c4825ef7 | 124 | void InstallEventHandler( WXWidget control = NULL ); |
4850cc8b | 125 | |
b466e85a | 126 | virtual bool DoHandleMouseEvent(NSEvent *event); |
ffad7b0d | 127 | virtual bool DoHandleKeyEvent(NSEvent *event); |
0c530e5a | 128 | virtual void DoNotifyFocusEvent(bool receivedFocus); |
4850cc8b | 129 | |
4849f027 SC |
130 | protected: |
131 | WXWidget m_osxView; | |
132 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl) | |
133 | }; | |
134 | ||
ffad7b0d SC |
135 | DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow ); |
136 | ||
4849f027 SC |
137 | class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl |
138 | { | |
139 | public : | |
140 | wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ; | |
141 | wxNonOwnedWindowCocoaImpl(); | |
142 | ||
143 | virtual ~wxNonOwnedWindowCocoaImpl(); | |
144 | ||
145 | virtual void Destroy() ; | |
146 | void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, | |
147 | long style, long extraStyle, const wxString& name ) ; | |
148 | ||
149 | WXWindow GetWXWindow() const; | |
150 | void Raise(); | |
151 | void Lower(); | |
152 | bool Show(bool show); | |
153 | bool ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout); | |
154 | ||
155 | void Update(); | |
156 | bool SetTransparent(wxByte alpha); | |
157 | bool SetBackgroundColour(const wxColour& col ); | |
158 | void SetExtraStyle( long exStyle ); | |
159 | bool SetBackgroundStyle(wxBackgroundStyle style); | |
160 | bool CanSetTransparent(); | |
161 | ||
162 | void MoveWindow(int x, int y, int width, int height); | |
163 | void GetPosition( int &x, int &y ) const; | |
164 | void GetSize( int &width, int &height ) const; | |
165 | ||
166 | void GetContentArea( int &left , int &top , int &width , int &height ) const; | |
167 | bool SetShape(const wxRegion& region); | |
168 | ||
169 | virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ; | |
170 | ||
171 | virtual bool IsMaximized() const; | |
172 | ||
173 | virtual bool IsIconized() const; | |
174 | ||
175 | virtual void Iconize( bool iconize ); | |
176 | ||
177 | virtual void Maximize(bool maximize); | |
178 | ||
179 | virtual bool IsFullScreen() const; | |
180 | ||
181 | virtual bool ShowFullScreen(bool show, long style); | |
182 | ||
183 | virtual void RequestUserAttention(int flags); | |
184 | ||
185 | virtual void ScreenToWindow( int *x, int *y ); | |
186 | ||
187 | virtual void WindowToScreen( int *x, int *y ); | |
188 | ||
189 | wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; } | |
190 | protected : | |
ffad7b0d | 191 | WX_wxNSWindow m_macWindow; |
4849f027 SC |
192 | void * m_macFullScreenData ; |
193 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl) | |
194 | }; | |
195 | ||
4850cc8b SC |
196 | #ifdef __OBJC__ |
197 | ||
198 | extern NSRect wxToNSRect( NSView* parent, const wxRect& r ); | |
199 | extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect ); | |
200 | extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p ); | |
201 | extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p ); | |
202 | ||
4850cc8b SC |
203 | NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , |
204 | bool adjustForOrigin = true ); | |
205 | ||
206 | // common code snippets for cocoa implementations | |
207 | // later to be done using injection in method table | |
208 | ||
0c530e5a | 209 | #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\ |
54f11060 SC |
210 | - (void)rightMouseDown:(NSEvent *)event ;\ |
211 | - (void)otherMouseDown:(NSEvent *)event ;\ | |
212 | - (void)mouseUp:(NSEvent *)event ;\ | |
213 | - (void)rightMouseUp:(NSEvent *)event ;\ | |
214 | - (void)otherMouseUp:(NSEvent *)event ;\ | |
215 | - (void)mouseMoved:(NSEvent *)event;\ | |
216 | - (void)mouseDragged:(NSEvent *)event;\ | |
217 | - (void)rightMouseDragged:(NSEvent *)event;\ | |
218 | - (void)otherMouseDragged:(NSEvent *)event;\ | |
219 | - (void)scrollWheel:(NSEvent *)theEvent;\ | |
220 | - (void)mouseEntered:(NSEvent *)event;\ | |
221 | - (void)mouseExited:(NSEvent *)event;\ | |
ffad7b0d SC |
222 | - (void)keyDown:(NSEvent *)event;\ |
223 | - (void)keyUp:(NSEvent *)event;\ | |
19c7ac3d | 224 | - (BOOL)performKeyEquivalent:(NSEvent *)event;\ |
ffad7b0d | 225 | - (void)flagsChanged:(NSEvent *)event;\ |
19c7ac3d SC |
226 | - (BOOL)becomeFirstResponder;\ |
227 | - (BOOL)resignFirstResponder;\ | |
228 | - (void)resetCursorRects; | |
4850cc8b | 229 | |
19c7ac3d SC |
230 | |
231 | #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN -(void)rightMouseDown:(NSEvent *)event\ | |
4850cc8b | 232 | {\ |
b466e85a SC |
233 | if ( !impl->DoHandleMouseEvent(event) )\ |
234 | [super rightMouseDown:event];\ | |
4850cc8b SC |
235 | }\ |
236 | -(void)otherMouseDown:(NSEvent *)event\ | |
237 | {\ | |
b466e85a SC |
238 | if ( !impl->DoHandleMouseEvent(event) )\ |
239 | [super otherMouseDown:event];\ | |
4850cc8b SC |
240 | }\ |
241 | -(void)mouseUp:(NSEvent *)event\ | |
242 | {\ | |
b466e85a SC |
243 | if ( !impl->DoHandleMouseEvent(event) )\ |
244 | [super mouseUp:event];\ | |
4850cc8b SC |
245 | }\ |
246 | -(void)rightMouseUp:(NSEvent *)event\ | |
247 | {\ | |
b466e85a SC |
248 | if ( !impl->DoHandleMouseEvent(event) )\ |
249 | [super rightMouseUp:event];\ | |
4850cc8b SC |
250 | }\ |
251 | -(void)otherMouseUp:(NSEvent *)event\ | |
252 | {\ | |
b466e85a SC |
253 | if ( !impl->DoHandleMouseEvent(event) )\ |
254 | [super otherMouseUp:event];\ | |
ffad7b0d | 255 | }\ |
54f11060 SC |
256 | -(void)mouseMoved:(NSEvent *)event\ |
257 | {\ | |
258 | if ( !impl->DoHandleMouseEvent(event) )\ | |
259 | [super mouseMoved:event];\ | |
260 | }\ | |
261 | -(void)mouseDragged:(NSEvent *)event\ | |
262 | {\ | |
263 | if ( !impl->DoHandleMouseEvent(event) )\ | |
264 | [super mouseDragged:event];\ | |
265 | }\ | |
266 | -(void)rightMouseDragged:(NSEvent *)event\ | |
267 | {\ | |
268 | if ( !impl->DoHandleMouseEvent(event) )\ | |
269 | [super rightMouseDragged:event];\ | |
270 | }\ | |
271 | -(void)otherMouseDragged:(NSEvent *)event\ | |
272 | {\ | |
273 | if ( !impl->DoHandleMouseEvent(event) )\ | |
274 | [super otherMouseDragged:event];\ | |
275 | }\ | |
276 | -(void)scrollWheel:(NSEvent *)event\ | |
277 | {\ | |
278 | if ( !impl->DoHandleMouseEvent(event) )\ | |
279 | [super scrollWheel:event];\ | |
280 | }\ | |
281 | -(void)mouseEntered:(NSEvent *)event\ | |
282 | {\ | |
283 | if ( !impl->DoHandleMouseEvent(event) )\ | |
284 | [super mouseEntered:event];\ | |
285 | }\ | |
286 | -(void)mouseExited:(NSEvent *)event\ | |
287 | {\ | |
288 | if ( !impl->DoHandleMouseEvent(event) )\ | |
289 | [super mouseExited:event];\ | |
290 | }\ | |
19c7ac3d SC |
291 | -(BOOL)performKeyEquivalent:(NSEvent *)event\ |
292 | {\ | |
293 | if ( !impl->DoHandleKeyEvent(event) )\ | |
294 | return [super performKeyEquivalent:event];\ | |
295 | return YES;\ | |
296 | }\ | |
ffad7b0d SC |
297 | -(void)keyDown:(NSEvent *)event\ |
298 | {\ | |
299 | if ( !impl->DoHandleKeyEvent(event) )\ | |
300 | [super keyDown:event];\ | |
301 | }\ | |
302 | -(void)keyUp:(NSEvent *)event\ | |
303 | {\ | |
304 | if ( !impl->DoHandleKeyEvent(event) )\ | |
305 | [super keyUp:event];\ | |
306 | }\ | |
307 | -(void)flagsChanged:(NSEvent *)event\ | |
308 | {\ | |
309 | if ( !impl->DoHandleKeyEvent(event) )\ | |
310 | [super flagsChanged:event];\ | |
0c530e5a SC |
311 | }\ |
312 | - (BOOL) becomeFirstResponder\ | |
313 | {\ | |
314 | BOOL r = [super becomeFirstResponder];\ | |
315 | if ( r )\ | |
316 | impl->DoNotifyFocusEvent( true );\ | |
317 | return r;\ | |
318 | }\ | |
319 | - (BOOL) resignFirstResponder\ | |
320 | {\ | |
321 | BOOL r = [super resignFirstResponder];\ | |
322 | if ( r )\ | |
323 | impl->DoNotifyFocusEvent( false );\ | |
324 | return r;\ | |
19c7ac3d SC |
325 | }\ |
326 | - (void) resetCursorRects\ | |
327 | {\ | |
328 | if ( impl )\ | |
329 | {\ | |
330 | wxWindow* wxpeer = impl->GetWXPeer();\ | |
331 | if ( wxpeer )\ | |
332 | {\ | |
333 | NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\ | |
334 | if (cursor == NULL)\ | |
335 | [super resetCursorRects];\ | |
336 | else\ | |
337 | [self addCursorRect: [self bounds]\ | |
338 | cursor: cursor];\ | |
339 | }\ | |
340 | }\ | |
4850cc8b | 341 | } |
19c7ac3d SC |
342 | |
343 | #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \ | |
344 | {\ | |
345 | if ( !impl->DoHandleMouseEvent(event) )\ | |
346 | [super mouseDown:event];\ | |
347 | }\ | |
348 | WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN | |
349 | ||
b466e85a SC |
350 | #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl; |
351 | ||
352 | #define WXCOCOAIMPL_COMMON_INTERFACE \ | |
353 | - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\ | |
354 | - (wxWidgetCocoaImpl*) implementation;\ | |
355 | - (BOOL) isFlipped;\ | |
0c530e5a | 356 | WXCOCOAIMPL_COMMON_EVENTS_INTERFACE |
b466e85a | 357 | |
19c7ac3d | 358 | #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\ |
b466e85a SC |
359 | {\ |
360 | impl = theImplementation;\ | |
361 | }\ | |
362 | - (wxWidgetCocoaImpl*) implementation\ | |
363 | {\ | |
364 | return impl;\ | |
365 | }\ | |
19c7ac3d SC |
366 | |
367 | #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ | |
368 | WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ | |
b466e85a SC |
369 | - (BOOL) isFlipped\ |
370 | {\ | |
371 | return YES;\ | |
19c7ac3d | 372 | } |
0c530e5a | 373 | |
19c7ac3d SC |
374 | #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \ |
375 | WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ | |
376 | - (BOOL) isFlipped\ | |
0c530e5a | 377 | {\ |
19c7ac3d SC |
378 | return YES;\ |
379 | } | |
380 | ||
381 | ||
382 | #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ | |
383 | WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ | |
0c530e5a SC |
384 | - (BOOL) isFlipped\ |
385 | {\ | |
386 | return NO;\ | |
19c7ac3d | 387 | } |
b466e85a SC |
388 | |
389 | // used for many wxControls | |
390 | ||
391 | @interface wxNSButton : NSButton | |
392 | { | |
393 | WXCOCOAIMPL_COMMON_MEMBERS | |
394 | } | |
395 | ||
396 | WXCOCOAIMPL_COMMON_INTERFACE | |
397 | - (void) clickedAction: (id) sender; | |
398 | ||
399 | @end | |
400 | ||
401 | @interface wxNSBox : NSBox | |
402 | { | |
403 | WXCOCOAIMPL_COMMON_MEMBERS | |
404 | } | |
405 | ||
406 | WXCOCOAIMPL_COMMON_INTERFACE | |
407 | ||
408 | @end | |
409 | ||
410 | @interface wxNSTextField : NSTextField | |
411 | { | |
412 | WXCOCOAIMPL_COMMON_MEMBERS | |
413 | } | |
414 | ||
415 | WXCOCOAIMPL_COMMON_INTERFACE | |
416 | ||
417 | @end | |
418 | ||
ffad7b0d SC |
419 | @interface wxNSMenu : NSMenu |
420 | { | |
421 | wxMenuImpl* impl; | |
422 | } | |
423 | ||
424 | - (void) setImplementation:(wxMenuImpl*) item; | |
425 | - (wxMenuImpl*) implementation; | |
426 | ||
427 | @end | |
428 | ||
429 | @interface wxNSMenuItem : NSMenuItem | |
430 | { | |
431 | wxMenuItemImpl* impl; | |
432 | } | |
433 | ||
434 | - (void) setImplementation:(wxMenuItemImpl*) item; | |
435 | - (wxMenuItemImpl*) implementation; | |
436 | ||
437 | - (void)clickedAction:(id)sender; | |
438 | - (BOOL)validateMenuItem:(NSMenuItem *)menuItem; | |
439 | ||
440 | @end | |
b466e85a | 441 | |
4850cc8b SC |
442 | #endif // __OBJC__ |
443 | ||
4849f027 SC |
444 | // NSCursor |
445 | ||
446 | WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type ); | |
447 | WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY ); | |
448 | void wxMacCocoaSetCursor( WX_NSCursor cursor ); | |
449 | void wxMacCocoaHideCursor(); | |
450 | void wxMacCocoaShowCursor(); | |
451 | ||
452 | typedef struct tagClassicCursor | |
453 | { | |
454 | wxUint16 bits[16]; | |
455 | wxUint16 mask[16]; | |
456 | wxInt16 hotspot[2]; | |
457 | }ClassicCursor; | |
458 | ||
524c47aa SC |
459 | const short kwxCursorBullseye = 0; |
460 | const short kwxCursorBlank = 1; | |
461 | const short kwxCursorPencil = 2; | |
462 | const short kwxCursorMagnifier = 3; | |
463 | const short kwxCursorNoEntry = 4; | |
464 | const short kwxCursorPaintBrush = 5; | |
465 | const short kwxCursorPointRight = 6; | |
466 | const short kwxCursorPointLeft = 7; | |
467 | const short kwxCursorQuestionArrow = 8; | |
468 | const short kwxCursorRightArrow = 9; | |
469 | const short kwxCursorSizeNS = 10; | |
470 | const short kwxCursorSize = 11; | |
471 | const short kwxCursorSizeNESW = 12; | |
472 | const short kwxCursorSizeNWSE = 13; | |
473 | const short kwxCursorRoller = 14; | |
474 | const short kwxCursorLast = kwxCursorRoller; | |
475 | ||
476 | // exposing our fallback cursor map | |
477 | ||
478 | extern ClassicCursor gMacCursors[]; | |
479 | ||
4849f027 SC |
480 | #endif |
481 | ||
482 | #endif | |
483 | // _WX_PRIVATE_COCOA_H_ | |
484 |