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
;
23 // ========================================================================
25 // ========================================================================
26 class WXDLLEXPORT wxWindowCocoa
: public wxWindowBase
, protected wxCocoaNSView
28 DECLARE_DYNAMIC_CLASS(wxWindowCocoa
)
29 DECLARE_NO_COPY_CLASS(wxWindowCocoa
)
31 friend wxWindow
*wxWindowBase::GetCapture();
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 wxWindowCocoa() { Init(); }
37 inline wxWindowCocoa(wxWindow
*parent
, wxWindowID winid
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
,
41 const wxString
& name
= wxPanelNameStr
)
44 Create(parent
, winid
, pos
, size
, style
, name
);
47 virtual ~wxWindowCocoa();
49 bool Create(wxWindow
*parent
, wxWindowID winid
,
50 const wxPoint
& pos
= wxDefaultPosition
,
51 const wxSize
& size
= wxDefaultSize
,
53 const wxString
& name
= wxPanelNameStr
);
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 // Returns the content NSView (where children are added, drawing performed)
61 inline WX_NSView
GetNSView() { return m_cocoaNSView
; }
62 // Returns the NSView suitable for use as a subview
63 WX_NSView
GetNSViewForSuperview() const;
64 // Returns the NSView that may be hidden/is being hidden
65 WX_NSView
GetNSViewForHiding() const;
66 void CocoaAddChild(wxWindowCocoa
*child
);
67 void CocoaRemoveFromParent(void);
69 void InitMouseEvent(wxMouseEvent
&event
, WX_NSEvent cocoaEvent
);
70 virtual void Cocoa_FrameChanged(void);
71 virtual bool Cocoa_drawRect(const NSRect
&rect
);
72 virtual bool Cocoa_mouseDown(WX_NSEvent theEvent
);
73 virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent
);
74 virtual bool Cocoa_mouseUp(WX_NSEvent theEvent
);
75 virtual bool Cocoa_mouseMoved(WX_NSEvent theEvent
);
76 virtual bool Cocoa_mouseEntered(WX_NSEvent theEvent
);
77 virtual bool Cocoa_mouseExited(WX_NSEvent theEvent
);
78 virtual bool Cocoa_rightMouseDown(WX_NSEvent theEvent
);
79 virtual bool Cocoa_rightMouseDragged(WX_NSEvent theEvent
);
80 virtual bool Cocoa_rightMouseUp(WX_NSEvent theEvent
);
81 virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent
);
82 virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent
);
83 virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent
);
84 void SetNSView(WX_NSView cocoaNSView
);
85 WX_NSView m_cocoaNSView
;
86 wxWindowCocoaHider
*m_cocoaHider
;
88 static wxWindow
*sm_capturedWindow
;
89 virtual void CocoaReplaceView(WX_NSView oldView
, WX_NSView newView
);
90 void SetInitialFrameRect(const wxPoint
& pos
, const wxSize
& size
);
92 inline NSRect
MakeDefaultNSRect(const wxSize
& size
)
94 // NOTE: position is 10,10 to make it "obvious" that it's out of place
95 return NSMakeRect(10.0,10.0,WidthDefault(size
.x
),HeightDefault(size
.y
));
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 // Raise the window to the top of the Z order
104 virtual void Raise();
105 // Lower the window to the bottom of the Z order
106 virtual void Lower();
107 // Set the focus to this window
108 virtual void SetFocus();
109 // Warp the pointer the given position
110 virtual void WarpPointer(int x_pos
, int y_pos
) ;
111 // Send the window a refresh event
112 virtual void Refresh(bool eraseBack
= TRUE
, const wxRect
*rect
= NULL
);
113 // Set/get the window's font
114 virtual bool SetFont(const wxFont
& f
);
115 // inline virtual wxFont& GetFont() const;
116 // Get character size
117 virtual int GetCharHeight() const;
118 virtual int GetCharWidth() const;
119 virtual void GetTextExtent(const wxString
& string
, int *x
, int *y
,
121 int *externalLeading
= NULL
,
122 const wxFont
*theFont
= NULL
) const;
124 virtual void SetScrollbar(int orient
, int pos
, int thumbVisible
,
125 int range
, bool refresh
= TRUE
);
126 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= TRUE
);
127 virtual int GetScrollPos(int orient
) const;
128 virtual int GetScrollThumb(int orient
) const;
129 virtual int GetScrollRange(int orient
) const;
130 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
131 // Get the private handle (platform-dependent)
132 virtual WXWidget
GetHandle() const;
133 // Convert client to screen coordinates
134 virtual void DoClientToScreen(int *x
, int *y
) const;
135 // Convert screen to client coordinates
136 virtual void DoScreenToClient(int *x
, int *y
) const;
137 // Capture/release mouse
138 virtual void DoCaptureMouse();
139 virtual void DoReleaseMouse();
140 // Get window position, relative to parent (or screen if no parent)
141 virtual void DoGetPosition(int *x
, int *y
) const;
142 // Get overall window size
143 virtual void DoGetSize(int *width
, int *height
) const;
144 // Get/set client (application-useable) size
145 virtual void DoGetClientSize(int *width
, int *height
) const;
146 virtual void DoSetClientSize(int width
, int size
);
147 // Set overall size and position
148 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
= wxSIZE_AUTO
);
149 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
151 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
153 /* Other implementation */
155 // NOTE: typically Close() is not virtual, but we want this for Cocoa
156 virtual bool Close( bool force
= false );
157 virtual bool Show( bool show
= true );
160 #endif // __WX_COCOA_WINDOW_H__