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