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