]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/window.h
set eol-style
[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 // 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 // Change the window's cursor
146 virtual bool SetCursor( const wxCursor &cursor );
147 // Send the window a refresh event
148 virtual void Refresh(bool eraseBack = true, const wxRect *rect = NULL);
149 // Set/get the window's font
150 virtual bool SetFont(const wxFont& f);
151 // inline virtual wxFont& GetFont() const;
152 virtual void SetLabel(const wxString& label);
153 virtual wxString GetLabel() const;
154 // label handling
155 // Get character size
156 virtual int GetCharHeight() const;
157 virtual int GetCharWidth() const;
158 virtual void GetTextExtent(const wxString& string, int *x, int *y,
159 int *descent = NULL,
160 int *externalLeading = NULL,
161 const wxFont *theFont = NULL) const;
162 // Scroll stuff
163 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
164 int range, bool refresh = true);
165 virtual void SetScrollPos(int orient, int pos, bool refresh = true);
166 virtual int GetScrollPos(int orient) const;
167 virtual int GetScrollThumb(int orient) const;
168 virtual int GetScrollRange(int orient) const;
169 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
170 virtual void DoSetVirtualSize(int x, int y);
171 // Get the private handle (platform-dependent)
172 virtual WXWidget GetHandle() const;
173 // Convert client to screen coordinates
174 virtual void DoClientToScreen(int *x, int *y) const;
175 // Convert screen to client coordinates
176 virtual void DoScreenToClient(int *x, int *y) const;
177 // Capture/release mouse
178 virtual void DoCaptureMouse();
179 virtual void DoReleaseMouse();
180 // Get window position, relative to parent (or screen if no parent)
181 virtual void DoGetPosition(int *x, int *y) const;
182 // Get overall window size
183 virtual void DoGetSize(int *width, int *height) const;
184 // Get/set client (application-useable) size
185 virtual void DoGetClientSize(int *width, int *height) const;
186 virtual void DoSetClientSize(int width, int size);
187 // Set this window's tooltip
188 virtual void DoSetToolTip( wxToolTip *tip );
189 // Set the size of the wxWindow (the contentView of an NSWindow)
190 // wxTopLevelWindow will override this and set the NSWindow size
191 // such that the contentView will be this size
192 virtual void CocoaSetWxWindowSize(int width, int height);
193 // Set overall size and position
194 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
195 virtual void DoMoveWindow(int x, int y, int width, int height);
196 // Popup a menu
197 virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
198
199 /* Other implementation */
200
201 // NOTE: typically Close() is not virtual, but we want this for Cocoa
202 virtual bool Close( bool force = false );
203 virtual bool Show( bool show = true );
204 virtual void DoEnable( bool enable );
205
206 virtual bool IsDoubleBuffered() const { return true; }
207 };
208
209 #endif // __WX_COCOA_WINDOW_H__