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