]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
cleaning up warnings, more common event code
[wxWidgets.git] / include / wx / osx / cocoa / private.h
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
19 #include "wx/defs.h"
20
21 #include <ApplicationServices/ApplicationServices.h>
22
23 #if wxOSX_USE_ATSU_TEXT
24 // we need theming and atsu
25 #include <Carbon/Carbon.h>
26 #endif
27
28 #ifdef __OBJC__
29 #import <Cocoa/Cocoa.h>
30 #endif
31
32 //
33 // shared between Cocoa and Carbon
34 //
35
36 // bring in themeing types without pulling in the headers
37
38 #if wxUSE_GUI
39 typedef SInt16 ThemeBrush;
40 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
41 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
42 CGContextRef inContext,
43 const CGRect * inBounds,
44 CGImageRef inImage) ;
45 WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image );
46 #endif
47
48 long UMAGetSystemVersion() ;
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
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 ;
70 virtual void SetVisibility(bool);
71
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
80 virtual void SetBackgroundColour(const wxColour&);
81
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;
86 virtual void SetControlSize( wxWindowVariant variant );
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 );
98
99 void SetDefaultButton( bool isDefault );
100 void PerformClick();
101 void SetLabel(const wxString& title, wxFontEncoding encoding);
102
103 wxInt32 GetValue() const;
104 void SetValue( wxInt32 v );
105 void SetBitmap( const wxBitmap& bitmap );
106 void SetupTabs( const wxNotebook &notebook );
107 void GetBestRect( wxRect *r ) const;
108 bool IsEnabled() const;
109 void Enable( bool enable );
110 bool ButtonClickDidStateChange() { return true ;}
111 void SetMinimum( wxInt32 v );
112 void SetMaximum( wxInt32 v );
113 void PulseGauge();
114 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
115
116 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
117
118 void InstallEventHandler( WXWidget control = NULL );
119
120 virtual bool DoHandleMouseEvent(NSEvent *event);
121 virtual bool DoHandleKeyEvent(NSEvent *event);
122
123 protected:
124 WXWidget m_osxView;
125 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
126 };
127
128 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
129
130 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
131 {
132 public :
133 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
134 wxNonOwnedWindowCocoaImpl();
135
136 virtual ~wxNonOwnedWindowCocoaImpl();
137
138 virtual void Destroy() ;
139 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
140 long style, long extraStyle, const wxString& name ) ;
141
142 WXWindow GetWXWindow() const;
143 void Raise();
144 void Lower();
145 bool Show(bool show);
146 bool ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout);
147
148 void Update();
149 bool SetTransparent(wxByte alpha);
150 bool SetBackgroundColour(const wxColour& col );
151 void SetExtraStyle( long exStyle );
152 bool SetBackgroundStyle(wxBackgroundStyle style);
153 bool CanSetTransparent();
154
155 void MoveWindow(int x, int y, int width, int height);
156 void GetPosition( int &x, int &y ) const;
157 void GetSize( int &width, int &height ) const;
158
159 void GetContentArea( int &left , int &top , int &width , int &height ) const;
160 bool SetShape(const wxRegion& region);
161
162 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
163
164 virtual bool IsMaximized() const;
165
166 virtual bool IsIconized() const;
167
168 virtual void Iconize( bool iconize );
169
170 virtual void Maximize(bool maximize);
171
172 virtual bool IsFullScreen() const;
173
174 virtual bool ShowFullScreen(bool show, long style);
175
176 virtual void RequestUserAttention(int flags);
177
178 virtual void ScreenToWindow( int *x, int *y );
179
180 virtual void WindowToScreen( int *x, int *y );
181
182 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
183 protected :
184 WX_wxNSWindow m_macWindow;
185 void * m_macFullScreenData ;
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
187 };
188
189 #ifdef __OBJC__
190
191 extern NSRect wxToNSRect( NSView* parent, const wxRect& r );
192 extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
193 extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
194 extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
195
196 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
197 bool adjustForOrigin = true );
198
199 // common code snippets for cocoa implementations
200 // later to be done using injection in method table
201
202 #define WXCOCOAIMPL_COMMON_MOUSE_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
203 -(void)rightMouseDown:(NSEvent *)event ;\
204 -(void)otherMouseDown:(NSEvent *)event ;\
205 -(void)mouseUp:(NSEvent *)event ;\
206 -(void)rightMouseUp:(NSEvent *)event ;\
207 -(void)otherMouseUp:(NSEvent *)event ;\
208 - (void)keyDown:(NSEvent *)event;\
209 - (void)keyUp:(NSEvent *)event;\
210 - (void)flagsChanged:(NSEvent *)event;\
211
212 #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
213 {\
214 if ( !impl->DoHandleMouseEvent(event) )\
215 [super mouseDown:event];\
216 }\
217 -(void)rightMouseDown:(NSEvent *)event\
218 {\
219 if ( !impl->DoHandleMouseEvent(event) )\
220 [super rightMouseDown:event];\
221 }\
222 -(void)otherMouseDown:(NSEvent *)event\
223 {\
224 if ( !impl->DoHandleMouseEvent(event) )\
225 [super otherMouseDown:event];\
226 }\
227 -(void)mouseUp:(NSEvent *)event\
228 {\
229 if ( !impl->DoHandleMouseEvent(event) )\
230 [super mouseUp:event];\
231 }\
232 -(void)rightMouseUp:(NSEvent *)event\
233 {\
234 if ( !impl->DoHandleMouseEvent(event) )\
235 [super rightMouseUp:event];\
236 }\
237 -(void)otherMouseUp:(NSEvent *)event\
238 {\
239 if ( !impl->DoHandleMouseEvent(event) )\
240 [super otherMouseUp:event];\
241 }\
242 -(void)keyDown:(NSEvent *)event\
243 {\
244 if ( !impl->DoHandleKeyEvent(event) )\
245 [super keyDown:event];\
246 }\
247 -(void)keyUp:(NSEvent *)event\
248 {\
249 if ( !impl->DoHandleKeyEvent(event) )\
250 [super keyUp:event];\
251 }\
252 -(void)flagsChanged:(NSEvent *)event\
253 {\
254 if ( !impl->DoHandleKeyEvent(event) )\
255 [super flagsChanged:event];\
256 }
257
258 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
259
260 #define WXCOCOAIMPL_COMMON_INTERFACE \
261 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
262 - (wxWidgetCocoaImpl*) implementation;\
263 - (BOOL) isFlipped;\
264 WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
265
266 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION \
267 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
268 {\
269 impl = theImplementation;\
270 }\
271 - (wxWidgetCocoaImpl*) implementation\
272 {\
273 return impl;\
274 }\
275 - (BOOL) isFlipped\
276 {\
277 return YES;\
278 }\
279
280 // used for many wxControls
281
282 @interface wxNSButton : NSButton
283 {
284 WXCOCOAIMPL_COMMON_MEMBERS
285 }
286
287 WXCOCOAIMPL_COMMON_INTERFACE
288 - (void) clickedAction: (id) sender;
289
290 @end
291
292 @interface wxNSBox : NSBox
293 {
294 WXCOCOAIMPL_COMMON_MEMBERS
295 }
296
297 WXCOCOAIMPL_COMMON_INTERFACE
298
299 @end
300
301 @interface wxNSTextField : NSTextField
302 {
303 WXCOCOAIMPL_COMMON_MEMBERS
304 }
305
306 WXCOCOAIMPL_COMMON_INTERFACE
307
308 @end
309
310 @interface wxNSMenu : NSMenu
311 {
312 wxMenuImpl* impl;
313 }
314
315 - (void) setImplementation:(wxMenuImpl*) item;
316 - (wxMenuImpl*) implementation;
317
318 @end
319
320 @interface wxNSMenuItem : NSMenuItem
321 {
322 wxMenuItemImpl* impl;
323 }
324
325 - (void) setImplementation:(wxMenuItemImpl*) item;
326 - (wxMenuItemImpl*) implementation;
327
328 - (void)clickedAction:(id)sender;
329 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
330
331 @end
332
333 #endif // __OBJC__
334
335 // NSCursor
336
337 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
338 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
339 void wxMacCocoaSetCursor( WX_NSCursor cursor );
340 void wxMacCocoaHideCursor();
341 void wxMacCocoaShowCursor();
342
343 typedef struct tagClassicCursor
344 {
345 wxUint16 bits[16];
346 wxUint16 mask[16];
347 wxInt16 hotspot[2];
348 }ClassicCursor;
349
350 const short kwxCursorBullseye = 0;
351 const short kwxCursorBlank = 1;
352 const short kwxCursorPencil = 2;
353 const short kwxCursorMagnifier = 3;
354 const short kwxCursorNoEntry = 4;
355 const short kwxCursorPaintBrush = 5;
356 const short kwxCursorPointRight = 6;
357 const short kwxCursorPointLeft = 7;
358 const short kwxCursorQuestionArrow = 8;
359 const short kwxCursorRightArrow = 9;
360 const short kwxCursorSizeNS = 10;
361 const short kwxCursorSize = 11;
362 const short kwxCursorSizeNESW = 12;
363 const short kwxCursorSizeNWSE = 13;
364 const short kwxCursorRoller = 14;
365 const short kwxCursorLast = kwxCursorRoller;
366
367 // exposing our fallback cursor map
368
369 extern ClassicCursor gMacCursors[];
370
371 #endif
372
373 #endif
374 // _WX_PRIVATE_COCOA_H_
375