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