]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/window.h
259366a6ce28700cbc8e86d0622493662672bdc1
[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 #ifdef __GNUG__
16 #pragma interface "window.h"
17 #endif
18
19 #include <wx/brush.h>
20 // ---------------------------------------------------------------------------
21 // forward declarations
22 // ---------------------------------------------------------------------------
23
24 class WXDLLEXPORT wxButton;
25 class WXDLLEXPORT wxScrollBar;
26 class WXDLLEXPORT wxTopLevelWindowMac;
27
28 // ---------------------------------------------------------------------------
29 // constants
30 // ---------------------------------------------------------------------------
31
32 // FIXME does anybody use those? they're unused by wxWindows...
33 enum
34 {
35 wxKEY_SHIFT = 1,
36 wxKEY_CTRL = 2
37 };
38
39 class WXDLLEXPORT wxWindowMac: public wxWindowBase
40 {
41 DECLARE_DYNAMIC_CLASS(wxWindowMac);
42
43 friend class wxDC;
44 friend class wxPaintDC;
45
46 public:
47
48 wxWindowMac() { 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 virtual void CaptureMouse();
85 virtual void ReleaseMouse();
86
87 virtual void Refresh( bool eraseBackground = TRUE,
88 const wxRect *rect = (const wxRect *) NULL );
89 virtual void Clear();
90
91 virtual bool SetCursor( const wxCursor &cursor );
92 virtual bool SetFont(const wxFont& font)
93 { return wxWindowBase::SetFont(font); }
94 virtual int GetCharHeight() const;
95 virtual int GetCharWidth() const;
96 virtual void GetTextExtent(const wxString& string,
97 int *x, int *y,
98 int *descent = (int *) NULL,
99 int *externalLeading = (int *) NULL,
100 const wxFont *theFont = (const wxFont *) NULL)
101 const;
102
103 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
104
105 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
106 int range, bool refresh = TRUE );
107 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
108 virtual int GetScrollPos( int orient ) const;
109 virtual int GetScrollThumb( int orient ) const;
110 virtual int GetScrollRange( int orient ) const;
111 virtual void ScrollWindow( int dx, int dy,
112 const wxRect* rect = (wxRect *) NULL );
113
114 #if wxUSE_DRAG_AND_DROP
115 virtual void SetDropTarget( wxDropTarget *dropTarget );
116 #endif // wxUSE_DRAG_AND_DROP
117
118 // Accept files for dragging
119 virtual void DragAcceptFiles(bool accept);
120
121 #if WXWIN_COMPATIBILITY
122 // Set/get scroll attributes
123 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
124 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
125 virtual int OldGetScrollRange(int orient) const;
126 virtual int GetScrollPage(int orient) const;
127
128 // event handlers
129 // Handle a control command
130 virtual void OnCommand(wxWindowMac& win, wxCommandEvent& event);
131
132 // Override to define new behaviour for default action (e.g. double
133 // clicking on a listbox)
134 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
135 #endif // WXWIN_COMPATIBILITY
136
137 #if wxUSE_CARET && WXWIN_COMPATIBILITY
138 // caret manipulation (old MSW only functions, see wxCaret class for the
139 // new API)
140 void CreateCaret(int w, int h);
141 void CreateCaret(const wxBitmap *bitmap);
142 void DestroyCaret();
143 void ShowCaret(bool show);
144 void SetCaretPos(int x, int y);
145 void GetCaretPos(int *x, int *y) const;
146 #endif // wxUSE_CARET
147
148 // Native resource loading (implemented in src/msw/nativdlg.cpp)
149 // FIXME: should they really be all virtual?
150 wxWindowMac* GetWindowChild1(wxWindowID id);
151 wxWindowMac* GetWindowChild(wxWindowID id);
152
153 // implementation from now on
154 // --------------------------
155
156 void MacClientToRootWindow( int *x , int *y ) const ;
157 void MacRootWindowToClient( int *x , int *y ) const ;
158 void MacWindowToRootWindow( int *x , int *y ) const ;
159 void MacRootWindowToWindow( int *x , int *y ) const ;
160
161 virtual wxString MacGetToolTipString( wxPoint &where ) ;
162
163 // simple accessors
164 // ----------------
165
166 // WXHWND GetHWND() const { return m_hWnd; }
167 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
168 virtual WXWidget GetHandle() const { return (WXWidget) NULL ; }
169
170 bool GetUseCtl3D() const { return m_useCtl3D; }
171 bool GetTransparentBackground() const { return m_backgroundTransparent; }
172 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
173
174 // event handlers
175 // --------------
176 void OnSetFocus(wxFocusEvent& event) ;
177 void OnNcPaint(wxNcPaintEvent& event);
178 void OnEraseBackground(wxEraseEvent& event);
179 void OnIdle(wxIdleEvent& event);
180 void MacOnScroll(wxScrollEvent&event ) ;
181
182 bool AcceptsFocus() const ;
183
184 public:
185 // For implementation purposes - sometimes decorations make the client area
186 // smaller
187 virtual wxPoint GetClientAreaOrigin() const;
188
189 wxWindowMac *FindItem(long id) const;
190 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
191
192 // Make a Windows extended style from the given wxWindows window style
193 static WXDWORD MakeExtendedStyle(long style,
194 bool eliminateBorders = TRUE);
195 // Determine whether 3D effects are wanted
196 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
197
198 // MSW only: TRUE if this control is part of the main control
199 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
200
201 #if WXWIN_COMPATIBILITY
202 wxObject *GetChild(int number) const;
203 virtual void MSWDeviceToLogical(float *x, float *y) const;
204 #endif // WXWIN_COMPATIBILITY
205
206 // Setup background and foreground colours correctly
207 virtual void SetupColours();
208
209
210 #if WXWIN_COMPATIBILITY
211 void SetShowing(bool show) { (void)Show(show); }
212 bool IsUserEnabled() const { return IsEnabled(); }
213 #endif // WXWIN_COMPATIBILITY
214
215 public :
216 static bool MacGetWindowFromPoint( const wxPoint &point , wxWindowMac** outWin ) ;
217 virtual void MacRedraw( RgnHandle updatergn , long time , bool erase) ;
218 virtual bool MacCanFocus() const { return true ; }
219
220 virtual bool MacDispatchMouseEvent(wxMouseEvent& event ) ;
221
222 virtual void MacPaintBorders() ;
223 WindowRef MacGetRootWindow() const ;
224 wxTopLevelWindowMac* MacGetTopLevelWindow() const ;
225
226 virtual ControlHandle 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 virtual void MacTopLevelWindowChangedPosition() ;
236 virtual void MacSuperShown( bool show ) ;
237 virtual void MacSuperEnabled( bool enable ) ;
238 bool MacIsReallyShown() const ;
239 virtual void Update() ;
240 // for compatibility
241 void MacUpdateImmediately() { Update() ; }
242
243 /*
244 bool MacSetupFocusPort() ;
245 bool MacSetupDrawingPort() ;
246 bool MacSetupFocusClientPort() ;
247 bool MacSetupDrawingClientPort() ;
248 */
249 virtual bool MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* rootwin ) ;
250 virtual bool MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* rootwin ) ;
251
252 virtual void MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) ;
253 virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin) ;
254 virtual void MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin) ;
255 const wxBrush& MacGetBackgroundBrush() ;
256 const wxRegion& MacGetVisibleRegion() ;
257 bool MacIsWindowScrollbar( const wxScrollBar* sb ) { return (m_hScrollBar == sb || m_vScrollBar == sb) ; }
258 static wxWindowMac* s_lastMouseWindow ;
259 private:
260 virtual bool MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) ;
261 protected:
262 // RgnHandle m_macUpdateRgn ;
263 // bool m_macEraseOnRedraw ;
264 wxBrush m_macBackgroundBrush ;
265 wxRegion m_macVisibleRegion ;
266 int m_x ;
267 int m_y ;
268 int m_width ;
269 int m_height ;
270
271 wxScrollBar* m_hScrollBar ;
272 wxScrollBar* m_vScrollBar ;
273 wxString m_label ;
274
275 void MacCreateScrollBars( long style ) ;
276 void MacRepositionScrollBars() ;
277
278 // additional (MSW specific) flags
279 bool m_useCtl3D:1; // Using CTL3D for this control
280 bool m_backgroundTransparent:1;
281 bool m_mouseInWindow:1;
282 bool m_doubleClickAllowed:1;
283 bool m_winCaptured:1;
284
285 // the size of one page for scrolling
286 int m_xThumbSize;
287 int m_yThumbSize;
288
289 // WXHMENU m_hMenu; // Menu, if any
290
291 // implement the base class pure virtuals
292 virtual void DoClientToScreen( int *x, int *y ) const;
293 virtual void DoScreenToClient( int *x, int *y ) const;
294 virtual void DoGetPosition( int *x, int *y ) const;
295 virtual void DoGetSize( int *width, int *height ) const;
296 virtual void DoGetClientSize( int *width, int *height ) const;
297 virtual void DoSetSize(int x, int y,
298 int width, int height,
299 int sizeFlags = wxSIZE_AUTO);
300 virtual void DoSetClientSize(int width, int height);
301
302 // move the window to the specified location and resize it: this is called
303 // from both DoSetSize() and DoSetClientSize() and would usually just call
304 // ::MoveWindow() except for composite controls which will want to arrange
305 // themselves inside the given rectangle
306 virtual void DoMoveWindow(int x, int y, int width, int height);
307
308 #if wxUSE_TOOLTIPS
309 virtual void DoSetToolTip( wxToolTip *tip );
310 #endif // wxUSE_TOOLTIPS
311
312 private:
313 // common part of all ctors
314 void Init();
315
316 DECLARE_NO_COPY_CLASS(wxWindowMac)
317 DECLARE_EVENT_TABLE()
318 };
319
320 /*
321 class wxMacFocusHelper
322 {
323 public :
324 wxMacFocusHelper( wxWindowMac * theWindow ) ;
325 ~wxMacFocusHelper() ;
326 bool Ok() { return m_ok ; }
327
328 private :
329 GrafPtr m_formerPort ;
330 GrafPtr m_currentPort ;
331 bool m_ok ;
332 } ;
333 */
334
335 class wxMacDrawingHelper
336 {
337 public :
338 wxMacDrawingHelper( wxWindowMac * theWindow ) ;
339 ~wxMacDrawingHelper() ;
340 bool Ok() { return m_ok ; }
341
342 private :
343 GrafPtr m_formerPort ;
344 GrafPtr m_currentPort ;
345 PenState m_savedPenState ;
346 bool m_ok ;
347 } ;
348 /*
349 class wxMacFocusClientHelper
350 {
351 public :
352 wxMacFocusClientHelper( wxWindowMac * theWindow ) ;
353 ~wxMacFocusClientHelper() ;
354 bool Ok() { return m_ok ; }
355
356 private :
357 GrafPtr m_formerPort ;
358 GrafPtr m_currentPort ;
359 bool m_ok ;
360 } ;
361 */
362 class wxMacDrawingClientHelper
363 {
364 public :
365 wxMacDrawingClientHelper( wxWindowMac * theWindow ) ;
366 ~wxMacDrawingClientHelper() ;
367 bool Ok() { return m_ok ; }
368
369 private :
370 GrafPtr m_formerPort ;
371 GrafPtr m_currentPort ;
372 PenState m_savedPenState ;
373 bool m_ok ;
374 } ;
375
376 #endif
377 // _WX_WINDOW_H_