]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/window.h
mac adaptions
[wxWidgets.git] / include / wx / mac / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindow 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 // ---------------------------------------------------------------------------
20 // forward declarations
21 // ---------------------------------------------------------------------------
22
23 class WXDLLEXPORT wxButton;
24 class WXDLLEXPORT wxScrollBar;
25
26 // ---------------------------------------------------------------------------
27 // constants
28 // ---------------------------------------------------------------------------
29
30 // FIXME does anybody use those? they're unused by wxWindows...
31 enum
32 {
33 wxKEY_SHIFT = 1,
34 wxKEY_CTRL = 2
35 };
36
37 class WXDLLEXPORT wxWindow: public wxWindowBase
38 {
39 DECLARE_DYNAMIC_CLASS(wxWindow);
40
41 friend class wxDC;
42 friend class wxPaintDC;
43
44 public:
45 typedef struct MacWindowData
46 {
47 SInt16 m_macWindowBackgroundTheme ;
48 WindowRef m_macWindow ;
49 ControlHandle m_macRootControl ;
50 wxWindow* m_macFocus ;
51 } MacWindowData ;
52
53
54 wxWindow() { Init(); }
55
56 wxWindow(wxWindow *parent,
57 wxWindowID id,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 long style = 0,
61 const wxString& name = wxPanelNameStr)
62 {
63 Init();
64 Create(parent, id, pos, size, style, name);
65 }
66
67 virtual ~wxWindow();
68
69 bool Create(wxWindow *parent,
70 wxWindowID id,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxString& name = wxPanelNameStr);
75
76
77 // implement base class pure virtuals
78 virtual void SetTitle( const wxString& title);
79 virtual wxString GetTitle() const;
80
81 virtual void Raise();
82 virtual void Lower();
83
84 virtual bool Show( bool show = TRUE );
85 virtual bool Enable( bool enable = TRUE );
86
87 virtual void SetFocus();
88
89 virtual bool Reparent( wxWindow *newParent );
90
91 virtual void WarpPointer(int x, int y);
92 virtual void CaptureMouse();
93 virtual void ReleaseMouse();
94
95 virtual void Refresh( bool eraseBackground = TRUE,
96 const wxRect *rect = (const wxRect *) NULL );
97 virtual void Clear();
98
99 virtual bool SetCursor( const wxCursor &cursor );
100 virtual bool SetFont( const wxFont &font );
101
102 virtual int GetCharHeight() const;
103 virtual int GetCharWidth() const;
104 virtual void GetTextExtent(const wxString& string,
105 int *x, int *y,
106 int *descent = (int *) NULL,
107 int *externalLeading = (int *) NULL,
108 const wxFont *theFont = (const wxFont *) NULL)
109 const;
110
111 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
112
113 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
114 int range, bool refresh = TRUE );
115 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
116 virtual int GetScrollPos( int orient ) const;
117 virtual int GetScrollThumb( int orient ) const;
118 virtual int GetScrollRange( int orient ) const;
119 virtual void ScrollWindow( int dx, int dy,
120 const wxRect* rect = (wxRect *) NULL );
121
122 #if wxUSE_DRAG_AND_DROP
123 virtual void SetDropTarget( wxDropTarget *dropTarget );
124 #endif // wxUSE_DRAG_AND_DROP
125
126 // Accept files for dragging
127 virtual void DragAcceptFiles(bool accept);
128
129 #if WXWIN_COMPATIBILITY
130 // Set/get scroll attributes
131 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
132 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
133 virtual int OldGetScrollRange(int orient) const;
134 virtual int GetScrollPage(int orient) const;
135
136 // event handlers
137 // Handle a control command
138 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
139
140 // Override to define new behaviour for default action (e.g. double
141 // clicking on a listbox)
142 virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
143 #endif // WXWIN_COMPATIBILITY
144
145 #if wxUSE_CARET && WXWIN_COMPATIBILITY
146 // caret manipulation (old MSW only functions, see wxCaret class for the
147 // new API)
148 void CreateCaret(int w, int h);
149 void CreateCaret(const wxBitmap *bitmap);
150 void DestroyCaret();
151 void ShowCaret(bool show);
152 void SetCaretPos(int x, int y);
153 void GetCaretPos(int *x, int *y) const;
154 #endif // wxUSE_CARET
155
156 // Native resource loading (implemented in src/msw/nativdlg.cpp)
157 // FIXME: should they really be all virtual?
158 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
159 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
160 wxWindow* GetWindowChild1(wxWindowID id);
161 wxWindow* GetWindowChild(wxWindowID id);
162
163 // implementation from now on
164 // --------------------------
165
166 void MacClientToRootWindow( int *x , int *y ) const ;
167 void MacRootWindowToClient( int *x , int *y ) const ;
168
169
170 // simple accessors
171 // ----------------
172
173 // WXHWND GetHWND() const { return m_hWnd; }
174 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
175 virtual WXWidget GetHandle() const { return (WXWidget) NULL ; }
176
177 bool GetUseCtl3D() const { return m_useCtl3D; }
178 bool GetTransparentBackground() const { return m_backgroundTransparent; }
179 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
180
181 // event handlers
182 // --------------
183 void OnEraseBackground(wxEraseEvent& event);
184 void OnIdle(wxIdleEvent& event);
185
186 public:
187 // For implementation purposes - sometimes decorations make the client area
188 // smaller
189 virtual wxPoint GetClientAreaOrigin() const;
190
191 // Makes an adjustment to the window position (for example, a frame that has
192 // a toolbar that it manages itself).
193 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
194
195 wxWindow *FindItem(long id) const;
196 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
197
198 // Make a Windows extended style from the given wxWindows window style
199 static WXDWORD MakeExtendedStyle(long style,
200 bool eliminateBorders = TRUE);
201 // Determine whether 3D effects are wanted
202 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
203
204 // MSW only: TRUE if this control is part of the main control
205 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
206
207 #if WXWIN_COMPATIBILITY
208 wxObject *GetChild(int number) const;
209 virtual void MSWDeviceToLogical(float *x, float *y) const;
210 #endif // WXWIN_COMPATIBILITY
211
212 // Create an appropriate wxWindow from a HWND
213 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
214
215 // Make sure the window style reflects the HWND style (roughly)
216 virtual void AdoptAttributesFromHWND();
217
218 // Setup background and foreground colours correctly
219 virtual void SetupColours();
220
221
222 #if WXWIN_COMPATIBILITY
223 void SetShowing(bool show) { (void)Show(show); }
224 bool IsUserEnabled() const { return IsEnabled(); }
225 #endif // WXWIN_COMPATIBILITY
226
227 // Responds to colour changes: passes event on to children.
228 void OnSysColourChanged(wxSysColourChangedEvent& event);
229
230 public :
231 static bool MacGetWindowFromPoint( const wxPoint &point , wxWindow** outWin ) ;
232 virtual void MacActivate( EventRecord *ev , bool inIsActivating ) ;
233 virtual void MacUpdate( EventRecord *ev ) ;
234 virtual void MacUpdateImmediately() ;
235 virtual void MacRedraw( RgnHandle updatergn , long time) ;
236 virtual void MacMouseDown( EventRecord *ev , short windowPart ) ;
237 virtual void MacMouseUp( EventRecord *ev , short windowPart ) ;
238 virtual void MacMouseMoved( EventRecord *ev , short windowPart ) ;
239 virtual void MacKeyDown( EventRecord *ev ) ;
240 virtual bool MacCanFocus() const { return true ; }
241
242 virtual void MacFireMouseEvent( EventRecord *ev ) ;
243 virtual bool MacDispatchMouseEvent(wxMouseEvent& event ) ;
244 virtual void MacEraseBackground( Rect *rect ) ;
245 WindowRef GetMacRootWindow() const ;
246
247 virtual ControlHandle MacGetContainerForEmbedding() ;
248 virtual void MacSuperChangedPosition() ;
249
250 bool MacSetupFocusPort() ;
251 bool MacSetupDrawingPort() ;
252 bool MacSetupFocusClientPort() ;
253 bool MacSetupDrawingClientPort() ;
254
255 virtual bool MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ;
256 virtual bool MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ;
257
258 virtual void MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) ;
259 virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) ;
260 MacWindowData* MacGetWindowData() { return m_macWindowData ; }
261 static WindowRef MacGetWindowInUpdate() { return s_macWindowInUpdate ; }
262 static wxWindow* s_lastMouseWindow ;
263 private:
264 virtual bool MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin ) ;
265 protected:
266
267 MacWindowData* m_macWindowData ;
268 static WindowRef s_macWindowInUpdate ;
269
270 int m_x ;
271 int m_y ;
272 int m_width ;
273 int m_height ;
274
275 wxScrollBar* m_hScrollBar ;
276 wxScrollBar* m_vScrollBar ;
277 wxString m_label ;
278
279 void MacCreateScrollBars( long style ) ;
280 void MacRepositionScrollBars() ;
281
282 // additional (MSW specific) flags
283 bool m_useCtl3D:1; // Using CTL3D for this control
284 bool m_backgroundTransparent:1;
285 bool m_mouseInWindow:1;
286 bool m_doubleClickAllowed:1;
287 bool m_winCaptured:1;
288
289 // the size of one page for scrolling
290 int m_xThumbSize;
291 int m_yThumbSize;
292
293 // WXHMENU m_hMenu; // Menu, if any
294
295 // implement the base class pure virtuals
296 virtual void DoClientToScreen( int *x, int *y ) const;
297 virtual void DoScreenToClient( int *x, int *y ) const;
298 virtual void DoGetPosition( int *x, int *y ) const;
299 virtual void DoGetSize( int *width, int *height ) const;
300 virtual void DoGetClientSize( int *width, int *height ) const;
301 virtual void DoSetSize(int x, int y,
302 int width, int height,
303 int sizeFlags = wxSIZE_AUTO);
304 virtual void DoSetClientSize(int width, int height);
305
306 // get the size which best suits the window: e.g., for a static text it
307 // will be the width and height of the text
308 virtual wxSize DoGetBestSize();
309
310 // move the window to the specified location and resize it: this is called
311 // from both DoSetSize() and DoSetClientSize() and would usually just call
312 // ::MoveWindow() except for composite controls which will want to arrange
313 // themselves inside the given rectangle
314 virtual void DoMoveWindow(int x, int y, int width, int height);
315
316 #if wxUSE_TOOLTIPS
317 virtual void DoSetToolTip( wxToolTip *tip );
318 #endif // wxUSE_TOOLTIPS
319
320 private:
321 // common part of all ctors
322 void Init();
323
324 DECLARE_NO_COPY_CLASS(wxWindow);
325 DECLARE_EVENT_TABLE()
326 };
327
328 // associate mac windows with wx counterparts
329
330 wxWindow* wxFindWinFromMacWindow( WindowRef inWindow ) ;
331 void wxAssociateWinWithMacWindow(WindowRef inWindow, wxWindow *win) ;
332 void wxRemoveMacWindowAssociation(wxWindow *win) ;
333
334 class wxMacFocusHelper
335 {
336 public :
337 wxMacFocusHelper( wxWindow * theWindow ) ;
338 ~wxMacFocusHelper() ;
339 bool Ok() { return m_ok ; }
340
341 private :
342 GrafPtr m_formerPort ;
343 GrafPtr m_currentPort ;
344 bool m_ok ;
345 } ;
346
347 class wxMacDrawingHelper
348 {
349 public :
350 wxMacDrawingHelper( wxWindow * theWindow ) ;
351 ~wxMacDrawingHelper() ;
352 bool Ok() { return m_ok ; }
353
354 private :
355 GrafPtr m_formerPort ;
356 GrafPtr m_currentPort ;
357 PenState m_savedPenState ;
358 bool m_ok ;
359 } ;
360
361 class wxMacFocusClientHelper
362 {
363 public :
364 wxMacFocusClientHelper( wxWindow * theWindow ) ;
365 ~wxMacFocusClientHelper() ;
366 bool Ok() { return m_ok ; }
367
368 private :
369 GrafPtr m_formerPort ;
370 GrafPtr m_currentPort ;
371 bool m_ok ;
372 } ;
373
374 class wxMacDrawingClientHelper
375 {
376 public :
377 wxMacDrawingClientHelper( wxWindow * theWindow ) ;
378 ~wxMacDrawingClientHelper() ;
379 bool Ok() { return m_ok ; }
380
381 private :
382 GrafPtr m_formerPort ;
383 GrafPtr m_currentPort ;
384 PenState m_savedPenState ;
385 bool m_ok ;
386 } ;
387
388 #endif
389 // _WX_WINDOW_H_