]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
Build fix for OS X <= 10.5.
[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 #else
27 // we only need theming, if we find a better include replace the following
28 #include <Carbon/Carbon.h>
29 #endif
30
31 #ifdef __OBJC__
32 #import <Cocoa/Cocoa.h>
33 #endif
34
35 //
36 // shared between Cocoa and Carbon
37 //
38
39 // bring in theming types without pulling in the headers
40
41 #if wxUSE_GUI
42 typedef SInt16 ThemeBrush;
43 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
44 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
45 CGContextRef inContext,
46 const CGRect * inBounds,
47 CGImageRef inImage) ;
48 WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image );
49 CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage );
50 #endif
51
52 long UMAGetSystemVersion() ;
53 WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
54 WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
55 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
56 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
57
58 //
59 //
60 //
61
62 #if wxUSE_GUI
63
64 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
65 {
66 public :
67 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ;
68 wxWidgetCocoaImpl() ;
69 ~wxWidgetCocoaImpl();
70
71 void Init();
72
73 virtual bool IsVisible() const ;
74 virtual void SetVisibility(bool);
75
76 // we provide a static function which can be reused from
77 // wxNonOwnedWindowCocoaImpl too
78 static bool ShowViewOrWindowWithEffect(wxWindow *win,
79 bool show,
80 wxShowEffect effect,
81 unsigned timeout);
82
83 virtual bool ShowWithEffect(bool show,
84 wxShowEffect effect,
85 unsigned timeout);
86
87 virtual void Raise();
88
89 virtual void Lower();
90
91 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
92
93 virtual WXWidget GetWXWidget() const { return m_osxView; }
94
95 virtual void SetBackgroundColour(const wxColour&);
96
97 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const;
98 virtual void Move(int x, int y, int width, int height);
99 virtual void GetPosition( int &x, int &y ) const;
100 virtual void GetSize( int &width, int &height ) const;
101 virtual void SetControlSize( wxWindowVariant variant );
102
103 virtual void SetNeedsDisplay( const wxRect* where = NULL );
104 virtual bool GetNeedsDisplay() const;
105
106 virtual bool CanFocus() const;
107 // return true if successful
108 virtual bool SetFocus();
109 virtual bool HasFocus() const;
110
111 void RemoveFromParent();
112 void Embed( wxWidgetImpl *parent );
113
114 void SetDefaultButton( bool isDefault );
115 void PerformClick();
116 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
117
118 void SetCursor( const wxCursor & cursor );
119 void CaptureMouse();
120 void ReleaseMouse();
121
122 wxInt32 GetValue() const;
123 void SetValue( wxInt32 v );
124 wxBitmap GetBitmap() const;
125 void SetBitmap( const wxBitmap& bitmap );
126 void SetBitmapPosition( wxDirection dir );
127 void SetupTabs( const wxNotebook &notebook );
128 void GetBestRect( wxRect *r ) const;
129 bool IsEnabled() const;
130 void Enable( bool enable );
131 bool ButtonClickDidStateChange() { return true ;}
132 void SetMinimum( wxInt32 v );
133 void SetMaximum( wxInt32 v );
134 wxInt32 GetMinimum() const;
135 wxInt32 GetMaximum() const;
136 void PulseGauge();
137 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
138
139 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
140
141 void InstallEventHandler( WXWidget control = NULL );
142
143 virtual bool DoHandleMouseEvent(NSEvent *event);
144 virtual bool DoHandleKeyEvent(NSEvent *event);
145 virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
146 virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
147
148 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
149 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
150
151
152 void SetFlipped(bool flipped);
153 virtual bool IsFlipped() const { return m_isFlipped; }
154
155 // cocoa thunk connected calls
156
157 virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
158 virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
159 virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
160 virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
161 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
162 virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
163 virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
164 virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
165 virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
166 virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
167 virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
168 virtual void resetCursorRects(WXWidget slf, void* _cmd);
169 virtual bool isFlipped(WXWidget slf, void* _cmd);
170 virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
171
172 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
173 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
174
175 protected:
176 WXWidget m_osxView;
177 NSEvent* m_lastKeyDownEvent;
178 bool m_isFlipped;
179 // if it the control has an editor, that editor will already send some
180 // events, don't resend them
181 bool m_hasEditor;
182
183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
184 };
185
186 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
187
188 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
189 {
190 public :
191 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
192 wxNonOwnedWindowCocoaImpl();
193
194 virtual ~wxNonOwnedWindowCocoaImpl();
195
196 virtual void Destroy() ;
197 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
198 long style, long extraStyle, const wxString& name ) ;
199
200 WXWindow GetWXWindow() const;
201 void Raise();
202 void Lower();
203 bool Show(bool show);
204
205 virtual bool ShowWithEffect(bool show,
206 wxShowEffect effect,
207 unsigned timeout);
208
209 void Update();
210 bool SetTransparent(wxByte alpha);
211 bool SetBackgroundColour(const wxColour& col );
212 void SetExtraStyle( long exStyle );
213 void SetWindowStyleFlag( long style );
214 bool SetBackgroundStyle(wxBackgroundStyle style);
215 bool CanSetTransparent();
216
217 void MoveWindow(int x, int y, int width, int height);
218 void GetPosition( int &x, int &y ) const;
219 void GetSize( int &width, int &height ) const;
220
221 void GetContentArea( int &left , int &top , int &width , int &height ) const;
222 bool SetShape(const wxRegion& region);
223
224 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
225
226 virtual bool IsMaximized() const;
227
228 virtual bool IsIconized() const;
229
230 virtual void Iconize( bool iconize );
231
232 virtual void Maximize(bool maximize);
233
234 virtual bool IsFullScreen() const;
235
236 virtual bool ShowFullScreen(bool show, long style);
237
238 virtual void ShowWithoutActivating();
239
240 virtual void RequestUserAttention(int flags);
241
242 virtual void ScreenToWindow( int *x, int *y );
243
244 virtual void WindowToScreen( int *x, int *y );
245
246 virtual bool IsActive();
247
248 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
249 protected :
250 WX_wxNSWindow m_macWindow;
251 void * m_macFullScreenData ;
252 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
253 };
254
255 #ifdef __OBJC__
256
257 WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
258 WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
259 WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
260 WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
261
262 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
263 bool adjustForOrigin = true );
264
265 // used for many wxControls
266
267 @interface wxNSButton : NSButton
268 {
269 NSTrackingRectTag rectTag;
270 }
271
272 @end
273
274 @interface wxNSBox : NSBox
275 {
276 }
277
278 @end
279
280 @interface wxNSTextFieldEditor : NSTextView
281 {
282 NSEvent* lastKeyDownEvent;
283 }
284
285 @end
286
287 @interface wxNSTextField : NSTextField
288 {
289 wxNSTextFieldEditor* fieldEditor;
290 }
291
292 - (wxNSTextFieldEditor*) fieldEditor;
293 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
294
295 @end
296
297 @interface wxNSSecureTextField : NSSecureTextField
298 {
299 }
300
301 @end
302
303
304 @interface wxNSTextView : NSTextView
305 {
306 }
307
308 - (void)textDidChange:(NSNotification *)aNotification;
309
310 @end
311
312 @interface wxNSMenu : NSMenu
313 {
314 wxMenuImpl* impl;
315 }
316
317 - (void) setImplementation:(wxMenuImpl*) item;
318 - (wxMenuImpl*) implementation;
319
320 @end
321
322 @interface wxNSMenuItem : NSMenuItem
323 {
324 wxMenuItemImpl* impl;
325 }
326
327 - (void) setImplementation:(wxMenuItemImpl*) item;
328 - (wxMenuItemImpl*) implementation;
329
330 - (void)clickedAction:(id)sender;
331 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
332
333 @end
334
335 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
336
337 /*
338 We need this for ShowModal, as the sheet just disables the parent window and
339 returns control to the app, whereas we don't want to return from ShowModal
340 until the sheet has been dismissed.
341 */
342 @interface ModalDialogDelegate : NSObject
343 {
344 BOOL sheetFinished;
345 int resultCode;
346 }
347
348 - (BOOL)finished;
349 - (int)code;
350 - (void)waitForSheetToFinish;
351 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
352 @end
353
354
355 #endif // __OBJC__
356
357 // NSCursor
358
359 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
360 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
361 void wxMacCocoaSetCursor( WX_NSCursor cursor );
362 void wxMacCocoaHideCursor();
363 void wxMacCocoaShowCursor();
364
365 typedef struct tagClassicCursor
366 {
367 wxUint16 bits[16];
368 wxUint16 mask[16];
369 wxInt16 hotspot[2];
370 }ClassicCursor;
371
372 const short kwxCursorBullseye = 0;
373 const short kwxCursorBlank = 1;
374 const short kwxCursorPencil = 2;
375 const short kwxCursorMagnifier = 3;
376 const short kwxCursorNoEntry = 4;
377 const short kwxCursorPaintBrush = 5;
378 const short kwxCursorPointRight = 6;
379 const short kwxCursorPointLeft = 7;
380 const short kwxCursorQuestionArrow = 8;
381 const short kwxCursorRightArrow = 9;
382 const short kwxCursorSizeNS = 10;
383 const short kwxCursorSize = 11;
384 const short kwxCursorSizeNESW = 12;
385 const short kwxCursorSizeNWSE = 13;
386 const short kwxCursorRoller = 14;
387 const short kwxCursorLast = kwxCursorRoller;
388
389 // exposing our fallback cursor map
390
391 extern ClassicCursor gMacCursors[];
392
393 #endif
394
395 #endif
396 // _WX_PRIVATE_COCOA_H_
397