1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/window.h
3 // Purpose: wxWindowCocoa
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_WINDOW_H__
13 #define __WX_COCOA_WINDOW_H__
15 #include "wx/cocoa/NSView.h"
18 #import <Foundation/NSGeometry.h>
21 class wxWindowCocoaHider
;
22 class wxWindowCocoaScroller
;
24 // ========================================================================
26 // ========================================================================
27 class WXDLLEXPORT wxWindowCocoa
: public wxWindowBase
, protected wxCocoaNSView
29 DECLARE_DYNAMIC_CLASS(wxWindowCocoa
)
30 DECLARE_NO_COPY_CLASS(wxWindowCocoa
)
32 friend wxWindow
*wxWindowBase::GetCapture();
33 friend class wxWindowCocoaScroller
;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 wxWindowCocoa() { Init(); }
39 inline wxWindowCocoa(wxWindow
*parent
, wxWindowID winid
,
40 const wxPoint
& pos
= wxDefaultPosition
,
41 const wxSize
& size
= wxDefaultSize
,
43 const wxString
& name
= wxPanelNameStr
)
46 Create(parent
, winid
, pos
, size
, style
, name
);
49 virtual ~wxWindowCocoa();
51 bool Create(wxWindow
*parent
, wxWindowID winid
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
55 const wxString
& name
= wxPanelNameStr
);
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
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);
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
;
82 void CocoaCreateNSScrollView();
83 void InitMouseEvent(wxMouseEvent
&event
, WX_NSEvent cocoaEvent
);
84 virtual void Cocoa_FrameChanged(void);
85 virtual bool Cocoa_drawRect(const NSRect
&rect
);
86 virtual bool Cocoa_mouseDown(WX_NSEvent theEvent
);
87 virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent
);
88 virtual bool Cocoa_mouseUp(WX_NSEvent theEvent
);
89 virtual bool Cocoa_mouseMoved(WX_NSEvent theEvent
);
90 virtual bool Cocoa_mouseEntered(WX_NSEvent theEvent
);
91 virtual bool Cocoa_mouseExited(WX_NSEvent theEvent
);
92 virtual bool Cocoa_rightMouseDown(WX_NSEvent theEvent
);
93 virtual bool Cocoa_rightMouseDragged(WX_NSEvent theEvent
);
94 virtual bool Cocoa_rightMouseUp(WX_NSEvent theEvent
);
95 virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent
);
96 virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent
);
97 virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent
);
98 void SetNSView(WX_NSView cocoaNSView
);
99 WX_NSView m_cocoaNSView
;
100 wxWindowCocoaHider
*m_cocoaHider
;
101 wxWindowCocoaScroller
*m_cocoaScroller
;
103 static wxWindow
*sm_capturedWindow
;
104 virtual void CocoaReplaceView(WX_NSView oldView
, WX_NSView newView
);
105 void SetInitialFrameRect(const wxPoint
& pos
, const wxSize
& size
);
107 inline NSRect
MakeDefaultNSRect(const wxSize
& size
)
109 // NOTE: position is 10,10 to make it "obvious" that it's out of place
110 return NSMakeRect(10.0,10.0,WidthDefault(size
.x
),HeightDefault(size
.y
));
112 #endif //def __OBJC__
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
118 // Raise the window to the top of the Z order
119 virtual void Raise();
120 // Lower the window to the bottom of the Z order
121 virtual void Lower();
122 // Set the focus to this window
123 virtual void SetFocus();
124 // Warp the pointer the given position
125 virtual void WarpPointer(int x_pos
, int y_pos
) ;
126 // Send the window a refresh event
127 virtual void Refresh(bool eraseBack
= TRUE
, const wxRect
*rect
= NULL
);
128 // Set/get the window's font
129 virtual bool SetFont(const wxFont
& f
);
130 // inline virtual wxFont& GetFont() const;
131 // Get character size
132 virtual int GetCharHeight() const;
133 virtual int GetCharWidth() const;
134 virtual void GetTextExtent(const wxString
& string
, int *x
, int *y
,
136 int *externalLeading
= NULL
,
137 const wxFont
*theFont
= NULL
) const;
139 virtual void SetScrollbar(int orient
, int pos
, int thumbVisible
,
140 int range
, bool refresh
= TRUE
);
141 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= TRUE
);
142 virtual int GetScrollPos(int orient
) const;
143 virtual int GetScrollThumb(int orient
) const;
144 virtual int GetScrollRange(int orient
) const;
145 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
146 virtual void DoSetVirtualSize(int x
, int y
);
147 // Get the private handle (platform-dependent)
148 virtual WXWidget
GetHandle() const;
149 // Convert client to screen coordinates
150 virtual void DoClientToScreen(int *x
, int *y
) const;
151 // Convert screen to client coordinates
152 virtual void DoScreenToClient(int *x
, int *y
) const;
153 // Capture/release mouse
154 virtual void DoCaptureMouse();
155 virtual void DoReleaseMouse();
156 // Get window position, relative to parent (or screen if no parent)
157 virtual void DoGetPosition(int *x
, int *y
) const;
158 // Get overall window size
159 virtual void DoGetSize(int *width
, int *height
) const;
160 // Get/set client (application-useable) size
161 virtual void DoGetClientSize(int *width
, int *height
) const;
162 virtual void DoSetClientSize(int width
, int size
);
163 // Set the size of the wxWindow (the contentView of an NSWindow)
164 // wxTopLevelWindow will override this and set the NSWindow size
165 // such that the contentView will be this size
166 virtual void CocoaSetWxWindowSize(int width
, int height
);
167 // Set overall size and position
168 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
= wxSIZE_AUTO
);
169 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
171 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
173 /* Other implementation */
175 // NOTE: typically Close() is not virtual, but we want this for Cocoa
176 virtual bool Close( bool force
= false );
177 virtual bool Show( bool show
= true );
178 virtual bool Enable( bool enable
= true );
181 #endif // __WX_COCOA_WINDOW_H__