1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/window.h
3 // Purpose: wxWindowCocoa
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_WINDOW_H__
13 #define __WX_COCOA_WINDOW_H__
15 #include "wx/cocoa/NSView.h"
18 #import <Foundation/NSGeometry.h>
21 // We can only import Foundation/NSGeometry.h from Objective-C code but it's
22 // nice to be able to use NSPoint and NSRect in the declarations of helper
23 // methods so we must define them as opaque structs identically to the way
24 // they are defined by the real header.
25 // NOTE: We specifically use these regardless of C++ or Objective-C++ mode so
26 // the compiler will complain if we got the definitions wrong. In regular
27 // C++ mode there is no way to know if we got the definitons right so
28 // we depend on at least one Objective-C++ file including this header.
29 #if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64)
30 typedef struct CGPoint NSPoint
;
31 typedef struct CGRect NSRect
;
33 typedef struct _NSPoint NSPoint
;
34 typedef struct _NSRect NSRect
;
37 DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform
);
39 class wxWindowCocoaHider
;
40 class wxWindowCocoaScrollView
;
41 class wxCocoaTrackingRectManager
;
43 // ========================================================================
45 // ========================================================================
46 class WXDLLEXPORT wxWindowCocoa
: public wxWindowBase
, protected wxCocoaNSView
48 DECLARE_DYNAMIC_CLASS(wxWindowCocoa
)
49 DECLARE_NO_COPY_CLASS(wxWindowCocoa
)
51 friend wxWindow
*wxWindowBase::GetCapture();
52 friend class wxWindowCocoaScrollView
;
53 friend class wxCocoaTrackingRectManager
;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 wxWindowCocoa() { Init(); }
59 inline wxWindowCocoa(wxWindow
*parent
, wxWindowID winid
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxString
& name
= wxPanelNameStr
)
66 Create(parent
, winid
, pos
, size
, style
, name
);
69 virtual ~wxWindowCocoa();
71 bool Create(wxWindow
*parent
, wxWindowID winid
,
72 const wxPoint
& pos
= wxDefaultPosition
,
73 const wxSize
& size
= wxDefaultSize
,
75 const wxString
& name
= wxPanelNameStr
);
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
82 // Returns the content NSView (where children are added, drawing performed)
83 inline WX_NSView
GetNSView() { return m_cocoaNSView
; }
84 // Returns the NSView suitable for use as a subview
85 WX_NSView
GetNSViewForSuperview() const;
86 // Returns the NSView that may be hidden/is being hidden
87 WX_NSView
GetNSViewForHiding() const;
88 // Returns the NSView for non-client drawing
89 virtual WX_NSView
GetNonClientNSView() { return GetNSViewForSuperview(); }
90 // Add/remove children
91 void CocoaAddChild(wxWindowCocoa
*child
);
92 void CocoaRemoveFromParent(void);
94 // Returns an autoreleased NSAffineTransform which can be applied
95 // to a graphics context currently using the view's coordinate system
96 // (such as the one locked when drawRect is called or after a call
97 // to [NSView lockFocus]) such that further drawing is done using
98 // the wxWidgets coordinate system.
99 WX_NSAffineTransform
CocoaGetWxToBoundsTransform();
100 #endif //def __OBJC__
102 // actually enable/disable the cocoa control, overridden by subclasses
103 virtual void CocoaSetEnabled(bool enable
) { }
105 void CocoaCreateNSScrollView();
106 void InitMouseEvent(wxMouseEvent
&event
, WX_NSEvent cocoaEvent
);
107 virtual wxWindow
* GetWxWindow() const;
108 virtual void Cocoa_FrameChanged(void);
109 virtual void Cocoa_synthesizeMouseMoved(void);
110 virtual bool Cocoa_drawRect(const NSRect
&rect
);
111 virtual bool Cocoa_mouseDown(WX_NSEvent theEvent
);
112 virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent
);
113 virtual bool Cocoa_mouseUp(WX_NSEvent theEvent
);
114 virtual bool Cocoa_mouseMoved(WX_NSEvent theEvent
);
115 virtual bool Cocoa_mouseEntered(WX_NSEvent theEvent
);
116 virtual bool Cocoa_mouseExited(WX_NSEvent theEvent
);
117 virtual bool Cocoa_rightMouseDown(WX_NSEvent theEvent
);
118 virtual bool Cocoa_rightMouseDragged(WX_NSEvent theEvent
);
119 virtual bool Cocoa_rightMouseUp(WX_NSEvent theEvent
);
120 virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent
);
121 virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent
);
122 virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent
);
123 virtual bool Cocoa_resetCursorRects();
124 virtual bool Cocoa_viewDidMoveToWindow();
125 virtual bool Cocoa_viewWillMoveToWindow(WX_NSWindow newWindow
);
126 void SetNSView(WX_NSView cocoaNSView
);
127 WX_NSView m_cocoaNSView
;
128 wxWindowCocoaHider
*m_cocoaHider
;
129 wxWindowCocoaScrollView
*m_wxCocoaScrollView
;
131 wxCocoaTrackingRectManager
*m_visibleTrackingRectManager
;
132 static wxWindow
*sm_capturedWindow
;
133 virtual void CocoaReplaceView(WX_NSView oldView
, WX_NSView newView
);
134 void SetInitialFrameRect(const wxPoint
& pos
, const wxSize
& size
);
136 inline NSRect
MakeDefaultNSRect(const wxSize
& size
)
138 // NOTE: position is 10,10 to make it "obvious" that it's out of place
139 return NSMakeRect(10.0,10.0,WidthDefault(size
.x
),HeightDefault(size
.y
));
141 // These functions translate NSPoint or NSRect between the coordinate
142 // system of Cocoa's boudns rect and wx's coordinate system.
143 NSPoint
CocoaTransformBoundsToWx(NSPoint pointBounds
);
144 NSRect
CocoaTransformBoundsToWx(NSRect rectBounds
);
145 NSPoint
CocoaTransformWxToBounds(NSPoint pointWx
);
146 NSRect
CocoaTransformWxToBounds(NSRect rectWx
);
147 #endif //def __OBJC__
148 static wxPoint
OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame
);
149 static NSPoint
OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, bool keepOriginVisible
);
150 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
155 // Raise the window to the top of the Z order
156 virtual void Raise();
157 // Lower the window to the bottom of the Z order
158 virtual void Lower();
159 // Set the focus to this window
160 virtual void SetFocus();
161 // Warp the pointer the given position
162 virtual void WarpPointer(int x_pos
, int y_pos
) ;
163 // Change the window's cursor
164 virtual bool SetCursor( const wxCursor
&cursor
);
165 // Send the window a refresh event
166 virtual void Refresh(bool eraseBack
= true, const wxRect
*rect
= NULL
);
167 // Set/get the window's font
168 virtual bool SetFont(const wxFont
& f
);
169 // inline virtual wxFont& GetFont() const;
170 virtual void SetLabel(const wxString
& label
);
171 virtual wxString
GetLabel() const;
173 // Get character size
174 virtual int GetCharHeight() const;
175 virtual int GetCharWidth() const;
176 virtual void GetTextExtent(const wxString
& string
, int *x
, int *y
,
178 int *externalLeading
= NULL
,
179 const wxFont
*theFont
= NULL
) const;
181 virtual void SetScrollbar(int orient
, int pos
, int thumbVisible
,
182 int range
, bool refresh
= true);
183 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= true);
184 virtual int GetScrollPos(int orient
) const;
185 virtual int GetScrollThumb(int orient
) const;
186 virtual int GetScrollRange(int orient
) const;
187 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
188 virtual void DoSetVirtualSize(int x
, int y
);
189 // Get the private handle (platform-dependent)
190 virtual WXWidget
GetHandle() const;
191 // Convert client to screen coordinates
192 virtual void DoClientToScreen(int *x
, int *y
) const;
193 // Convert screen to client coordinates
194 virtual void DoScreenToClient(int *x
, int *y
) const;
195 // Capture/release mouse
196 virtual void DoCaptureMouse();
197 virtual void DoReleaseMouse();
198 // Get window position, relative to parent (or screen if no parent)
199 virtual void DoGetPosition(int *x
, int *y
) const;
200 // Get overall window size
201 virtual void DoGetSize(int *width
, int *height
) const;
202 // Get/set client (application-useable) size
203 virtual void DoGetClientSize(int *width
, int *height
) const;
204 virtual void DoSetClientSize(int width
, int size
);
205 // Set this window's tooltip
206 virtual void DoSetToolTip( wxToolTip
*tip
);
207 // Set the size of the wxWindow (the contentView of an NSWindow)
208 // wxTopLevelWindow will override this and set the NSWindow size
209 // such that the contentView will be this size
210 virtual void CocoaSetWxWindowSize(int width
, int height
);
211 // Set overall size and position
212 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
= wxSIZE_AUTO
);
213 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
215 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
217 /* Other implementation */
219 // NOTE: typically Close() is not virtual, but we want this for Cocoa
220 virtual bool Close( bool force
= false );
221 virtual bool Show( bool show
= true );
222 virtual void DoEnable( bool enable
);
224 virtual bool IsDoubleBuffered() const { return true; }
227 #endif // __WX_COCOA_WINDOW_H__