]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/window.h
Use wxClientDataDictionary for client data.
[wxWidgets.git] / include / wx / mac / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindowMac class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "window.h"
17 #endif
18
19 #include "wx/brush.h"
20
21 // ---------------------------------------------------------------------------
22 // forward declarations
23 // ---------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxButton;
26 class WXDLLEXPORT wxScrollBar;
27 class WXDLLEXPORT wxTopLevelWindowMac;
28
29 // ---------------------------------------------------------------------------
30 // constants
31 // ---------------------------------------------------------------------------
32
33 class WXDLLEXPORT wxWindowMac: public wxWindowBase
34 {
35 DECLARE_DYNAMIC_CLASS(wxWindowMac)
36
37 friend class wxDC;
38 friend class wxPaintDC;
39
40 public:
41
42 wxWindowMac()
43 : m_macBackgroundBrush()
44 , m_macVisibleRegion()
45 , m_x(0), m_y(0), m_width(0), m_height(0)
46 , m_hScrollBar(NULL), m_vScrollBar(NULL)
47 , m_label(wxEmptyString)
48 { Init(); }
49
50 wxWindowMac(wxWindowMac *parent,
51 wxWindowID id,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
54 long style = 0,
55 const wxString& name = wxPanelNameStr)
56 {
57 Init();
58 Create(parent, id, pos, size, style, name);
59 }
60
61 virtual ~wxWindowMac();
62
63 bool Create(wxWindowMac *parent,
64 wxWindowID id,
65 const wxPoint& pos = wxDefaultPosition,
66 const wxSize& size = wxDefaultSize,
67 long style = 0,
68 const wxString& name = wxPanelNameStr);
69
70
71 // implement base class pure virtuals
72 virtual void SetTitle( const wxString& title);
73 virtual wxString GetTitle() const;
74
75 virtual void Raise();
76 virtual void Lower();
77
78 virtual bool Show( bool show = TRUE );
79 virtual bool Enable( bool enable = TRUE );
80
81 virtual void SetFocus();
82
83 virtual void WarpPointer(int x, int y);
84
85 virtual void Refresh( bool eraseBackground = TRUE,
86 const wxRect *rect = (const wxRect *) NULL );
87 virtual void Clear();
88
89 virtual bool SetCursor( const wxCursor &cursor );
90 virtual bool SetFont(const wxFont& font)
91 { return wxWindowBase::SetFont(font); }
92 virtual int GetCharHeight() const;
93 virtual int GetCharWidth() const;
94 virtual void GetTextExtent(const wxString& string,
95 int *x, int *y,
96 int *descent = (int *) NULL,
97 int *externalLeading = (int *) NULL,
98 const wxFont *theFont = (const wxFont *) NULL)
99 const;
100
101 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
102
103 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
104 int range, bool refresh = TRUE );
105 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
106 virtual int GetScrollPos( int orient ) const;
107 virtual int GetScrollThumb( int orient ) const;
108 virtual int GetScrollRange( int orient ) const;
109 virtual void ScrollWindow( int dx, int dy,
110 const wxRect* rect = (wxRect *) NULL );
111
112 #if wxUSE_DRAG_AND_DROP
113 virtual void SetDropTarget( wxDropTarget *dropTarget );
114 #endif // wxUSE_DRAG_AND_DROP
115
116 // Accept files for dragging
117 virtual void DragAcceptFiles(bool accept);
118
119 #if WXWIN_COMPATIBILITY
120 // Set/get scroll attributes
121 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
122 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
123 virtual int OldGetScrollRange(int orient) const;
124 virtual int GetScrollPage(int orient) const;
125
126 // event handlers
127 // Handle a control command
128 virtual void OnCommand(wxWindowMac& win, wxCommandEvent& event);
129
130 // Override to define new behaviour for default action (e.g. double
131 // clicking on a listbox)
132 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
133 #endif // WXWIN_COMPATIBILITY
134
135 #if wxUSE_CARET && WXWIN_COMPATIBILITY
136 // caret manipulation (old MSW only functions, see wxCaret class for the
137 // new API)
138 void CreateCaret(int w, int h);
139 void CreateCaret(const wxBitmap *bitmap);
140 void DestroyCaret();
141 void ShowCaret(bool show);
142 void SetCaretPos(int x, int y);
143 void GetCaretPos(int *x, int *y) const;
144 #endif // wxUSE_CARET
145
146 // Native resource loading (implemented in src/msw/nativdlg.cpp)
147 // FIXME: should they really be all virtual?
148 wxWindowMac* GetWindowChild1(wxWindowID id);
149 wxWindowMac* GetWindowChild(wxWindowID id);
150
151 // implementation from now on
152 // --------------------------
153
154 void MacClientToRootWindow( int *x , int *y ) const ;
155 void MacRootWindowToClient( int *x , int *y ) const ;
156 void MacWindowToRootWindow( int *x , int *y ) const ;
157 void MacRootWindowToWindow( int *x , int *y ) const ;
158
159 virtual wxString MacGetToolTipString( wxPoint &where ) ;
160
161 // simple accessors
162 // ----------------
163
164 // WXHWND GetHWND() const { return m_hWnd; }
165 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
166 virtual WXWidget GetHandle() const { return (WXWidget) NULL ; }
167
168 bool GetUseCtl3D() const { return m_useCtl3D; }
169 bool GetTransparentBackground() const { return m_backgroundTransparent; }
170 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
171
172 // event handlers
173 // --------------
174 void OnSetFocus(wxFocusEvent& event) ;
175 void OnNcPaint(wxNcPaintEvent& event);
176 void OnEraseBackground(wxEraseEvent& event);
177 void OnIdle(wxIdleEvent& event);
178 void MacOnScroll(wxScrollEvent&event ) ;
179
180 bool AcceptsFocus() const ;
181
182 public:
183 // For implementation purposes - sometimes decorations make the client area
184 // smaller
185 virtual wxPoint GetClientAreaOrigin() const;
186
187 wxWindowMac *FindItem(long id) const;
188 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
189
190 // Make a Windows extended style from the given wxWindows window style
191 static WXDWORD MakeExtendedStyle(long style,
192 bool eliminateBorders = TRUE);
193 // Determine whether 3D effects are wanted
194 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
195
196 // MSW only: TRUE if this control is part of the main control
197 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
198
199 #if WXWIN_COMPATIBILITY
200 wxObject *GetChild(int number) const;
201 virtual void MSWDeviceToLogical(float *x, float *y) const;
202 #endif // WXWIN_COMPATIBILITY
203
204 // Setup background and foreground colours correctly
205 virtual void SetupColours();
206
207
208 #if WXWIN_COMPATIBILITY
209 void SetShowing(bool show) { (void)Show(show); }
210 bool IsUserEnabled() const { return IsEnabled(); }
211 #endif // WXWIN_COMPATIBILITY
212
213 public:
214 static bool MacGetWindowFromPoint( const wxPoint &point , wxWindowMac** outWin ) ;
215 virtual bool MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) ;
216 virtual void MacRedraw( WXHRGN updatergn , long time , bool erase) ;
217 virtual bool MacCanFocus() const { return true ; }
218
219 virtual bool MacDispatchMouseEvent(wxMouseEvent& event ) ;
220 // this should not be overriden in classes above wxWindowMac because it is called from its destructor via DeleteChildren
221 virtual void RemoveChild( wxWindowBase *child );
222 virtual void MacPaintBorders( int left , int top ) ;
223 WXWindow MacGetRootWindow() const ;
224 wxTopLevelWindowMac* MacGetTopLevelWindow() const ;
225
226 virtual WXWidget MacGetContainerForEmbedding() ;
227
228 virtual long MacGetLeftBorderSize() const ;
229 virtual long MacGetRightBorderSize() const ;
230 virtual long MacGetTopBorderSize() const ;
231 virtual long MacGetBottomBorderSize() const ;
232
233 static long MacRemoveBordersFromStyle( long style ) ;
234 virtual void MacSuperChangedPosition() ;
235 // the absolute coordinates of this item within the toplevel window may have changed
236 virtual void MacUpdateDimensions() {}
237 // the absolute coortinates of this window's root have changed
238 virtual void MacTopLevelWindowChangedPosition() ;
239 virtual void MacSuperShown( bool show ) ;
240 virtual void MacSuperEnabled( bool enable ) ;
241 bool MacIsReallyShown() const ;
242 virtual void Update() ;
243 // for compatibility
244 void MacUpdateImmediately() { Update() ; }
245 virtual bool MacSetupCursor( const wxPoint& pt ) ;
246
247 // virtual bool MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* rootwin ) ;
248 // virtual void MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) ;
249 // virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin) ;
250 const wxBrush& MacGetBackgroundBrush() ;
251 const wxRegion& MacGetVisibleRegion( bool respectChildrenAndSiblings = true ) ;
252 bool MacIsWindowScrollbar( const wxScrollBar* sb )
253 { return (m_hScrollBar == sb || m_vScrollBar == sb) ; }
254 static wxWindowMac* s_lastMouseWindow ;
255 private:
256 protected:
257 // RgnHandle m_macUpdateRgn ;
258 // bool m_macEraseOnRedraw ;
259 wxBrush m_macBackgroundBrush ;
260 wxRegion m_macVisibleRegion ;
261 int m_x ;
262 int m_y ;
263 int m_width ;
264 int m_height ;
265
266 wxScrollBar* m_hScrollBar ;
267 wxScrollBar* m_vScrollBar ;
268 wxString m_label ;
269
270 void MacCreateScrollBars( long style ) ;
271 void MacRepositionScrollBars() ;
272
273 // additional (MSW specific) flags
274 bool m_useCtl3D:1; // Using CTL3D for this control
275 bool m_backgroundTransparent:1;
276 bool m_mouseInWindow:1;
277 bool m_doubleClickAllowed:1;
278 bool m_winCaptured:1;
279
280 // the size of one page for scrolling
281 int m_xThumbSize;
282 int m_yThumbSize;
283
284 // WXHMENU m_hMenu; // Menu, if any
285
286 // implement the base class pure virtuals
287 virtual void DoClientToScreen( int *x, int *y ) const;
288 virtual void DoScreenToClient( int *x, int *y ) const;
289 virtual void DoGetPosition( int *x, int *y ) const;
290 virtual void DoGetSize( int *width, int *height ) const;
291 virtual void DoGetClientSize( int *width, int *height ) const;
292 virtual void DoSetSize(int x, int y,
293 int width, int height,
294 int sizeFlags = wxSIZE_AUTO);
295 virtual void DoSetClientSize(int width, int height);
296
297 virtual void DoCaptureMouse();
298 virtual void DoReleaseMouse();
299
300 // move the window to the specified location and resize it: this is called
301 // from both DoSetSize() and DoSetClientSize() and would usually just call
302 // ::MoveWindow() except for composite controls which will want to arrange
303 // themselves inside the given rectangle
304 virtual void DoMoveWindow(int x, int y, int width, int height);
305
306 #if wxUSE_TOOLTIPS
307 virtual void DoSetToolTip( wxToolTip *tip );
308 #endif // wxUSE_TOOLTIPS
309
310 private:
311 // common part of all ctors
312 void Init();
313
314 DECLARE_NO_COPY_CLASS(wxWindowMac)
315 DECLARE_EVENT_TABLE()
316 };
317
318 #endif
319 // _WX_WINDOW_H_