]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/window.h
Added files to make patch.
[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 wxWindow* GetWindowChild1(wxWindowID id);
159 wxWindow* GetWindowChild(wxWindowID id);
160
161 // implementation from now on
162 // --------------------------
163
164 void MacClientToRootWindow( int *x , int *y ) const ;
165 void MacRootWindowToClient( int *x , int *y ) const ;
166
167
168 // simple accessors
169 // ----------------
170
171 // WXHWND GetHWND() const { return m_hWnd; }
172 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
173 virtual WXWidget GetHandle() const { return (WXWidget) NULL ; }
174
175 bool GetUseCtl3D() const { return m_useCtl3D; }
176 bool GetTransparentBackground() const { return m_backgroundTransparent; }
177 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
178
179 // event handlers
180 // --------------
181 void OnEraseBackground(wxEraseEvent& event);
182 void OnIdle(wxIdleEvent& event);
183
184 public:
185 // For implementation purposes - sometimes decorations make the client area
186 // smaller
187 virtual wxPoint GetClientAreaOrigin() const;
188
189 // Makes an adjustment to the window position (for example, a frame that has
190 // a toolbar that it manages itself).
191 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
192
193 wxWindow *FindItem(long id) const;
194 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
195
196 // Make a Windows extended style from the given wxWindows window style
197 static WXDWORD MakeExtendedStyle(long style,
198 bool eliminateBorders = TRUE);
199 // Determine whether 3D effects are wanted
200 WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) const;
201
202 // MSW only: TRUE if this control is part of the main control
203 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
204
205 #if WXWIN_COMPATIBILITY
206 wxObject *GetChild(int number) const;
207 virtual void MSWDeviceToLogical(float *x, float *y) const;
208 #endif // WXWIN_COMPATIBILITY
209
210 // Setup background and foreground colours correctly
211 virtual void SetupColours();
212
213
214 #if WXWIN_COMPATIBILITY
215 void SetShowing(bool show) { (void)Show(show); }
216 bool IsUserEnabled() const { return IsEnabled(); }
217 #endif // WXWIN_COMPATIBILITY
218
219 // Responds to colour changes: passes event on to children.
220 void OnSysColourChanged(wxSysColourChangedEvent& event);
221
222 public :
223 static bool MacGetWindowFromPoint( const wxPoint &point , wxWindow** outWin ) ;
224 virtual void MacActivate( EventRecord *ev , bool inIsActivating ) ;
225 virtual void MacUpdate( EventRecord *ev ) ;
226 virtual void MacUpdateImmediately() ;
227 virtual void MacRedraw( RgnHandle updatergn , long time) ;
228 virtual void MacMouseDown( EventRecord *ev , short windowPart ) ;
229 virtual void MacMouseUp( EventRecord *ev , short windowPart ) ;
230 virtual void MacMouseMoved( EventRecord *ev , short windowPart ) ;
231 virtual void MacKeyDown( EventRecord *ev ) ;
232 virtual bool MacCanFocus() const { return true ; }
233
234 virtual void MacFireMouseEvent( EventRecord *ev ) ;
235 virtual bool MacDispatchMouseEvent(wxMouseEvent& event ) ;
236 virtual void MacEraseBackground( Rect *rect ) ;
237 WindowRef GetMacRootWindow() const ;
238
239 virtual ControlHandle MacGetContainerForEmbedding() ;
240 virtual void MacSuperChangedPosition() ;
241
242 bool MacSetupFocusPort() ;
243 bool MacSetupDrawingPort() ;
244 bool MacSetupFocusClientPort() ;
245 bool MacSetupDrawingClientPort() ;
246
247 virtual bool MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ;
248 virtual bool MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ;
249
250 virtual void MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) ;
251 virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) ;
252 MacWindowData* MacGetWindowData() { return m_macWindowData ; }
253 static WindowRef MacGetWindowInUpdate() { return s_macWindowInUpdate ; }
254 static wxWindow* s_lastMouseWindow ;
255 private:
256 virtual bool MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin ) ;
257 protected:
258
259 MacWindowData* m_macWindowData ;
260 static WindowRef s_macWindowInUpdate ;
261
262 int m_x ;
263 int m_y ;
264 int m_width ;
265 int m_height ;
266
267 wxScrollBar* m_hScrollBar ;
268 wxScrollBar* m_vScrollBar ;
269 wxString m_label ;
270
271 void MacCreateScrollBars( long style ) ;
272 void MacRepositionScrollBars() ;
273
274 // additional (MSW specific) flags
275 bool m_useCtl3D:1; // Using CTL3D for this control
276 bool m_backgroundTransparent:1;
277 bool m_mouseInWindow:1;
278 bool m_doubleClickAllowed:1;
279 bool m_winCaptured:1;
280
281 // the size of one page for scrolling
282 int m_xThumbSize;
283 int m_yThumbSize;
284
285 // WXHMENU m_hMenu; // Menu, if any
286
287 // implement the base class pure virtuals
288 virtual void DoClientToScreen( int *x, int *y ) const;
289 virtual void DoScreenToClient( int *x, int *y ) const;
290 virtual void DoGetPosition( int *x, int *y ) const;
291 virtual void DoGetSize( int *width, int *height ) const;
292 virtual void DoGetClientSize( int *width, int *height ) const;
293 virtual void DoSetSize(int x, int y,
294 int width, int height,
295 int sizeFlags = wxSIZE_AUTO);
296 virtual void DoSetClientSize(int width, int height);
297
298 // get the size which best suits the window: e.g., for a static text it
299 // will be the width and height of the text
300 virtual wxSize DoGetBestSize();
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(wxWindow);
317 DECLARE_EVENT_TABLE()
318 };
319
320 // associate mac windows with wx counterparts
321
322 wxWindow* wxFindWinFromMacWindow( WindowRef inWindow ) ;
323 void wxAssociateWinWithMacWindow(WindowRef inWindow, wxWindow *win) ;
324 void wxRemoveMacWindowAssociation(wxWindow *win) ;
325
326 class wxMacFocusHelper
327 {
328 public :
329 wxMacFocusHelper( wxWindow * theWindow ) ;
330 ~wxMacFocusHelper() ;
331 bool Ok() { return m_ok ; }
332
333 private :
334 GrafPtr m_formerPort ;
335 GrafPtr m_currentPort ;
336 bool m_ok ;
337 } ;
338
339 class wxMacDrawingHelper
340 {
341 public :
342 wxMacDrawingHelper( wxWindow * theWindow ) ;
343 ~wxMacDrawingHelper() ;
344 bool Ok() { return m_ok ; }
345
346 private :
347 GrafPtr m_formerPort ;
348 GrafPtr m_currentPort ;
349 PenState m_savedPenState ;
350 bool m_ok ;
351 } ;
352
353 class wxMacFocusClientHelper
354 {
355 public :
356 wxMacFocusClientHelper( wxWindow * theWindow ) ;
357 ~wxMacFocusClientHelper() ;
358 bool Ok() { return m_ok ; }
359
360 private :
361 GrafPtr m_formerPort ;
362 GrafPtr m_currentPort ;
363 bool m_ok ;
364 } ;
365
366 class wxMacDrawingClientHelper
367 {
368 public :
369 wxMacDrawingClientHelper( wxWindow * theWindow ) ;
370 ~wxMacDrawingClientHelper() ;
371 bool Ok() { return m_ok ; }
372
373 private :
374 GrafPtr m_formerPort ;
375 GrafPtr m_currentPort ;
376 PenState m_savedPenState ;
377 bool m_ok ;
378 } ;
379
380 #endif
381 // _WX_WINDOW_H_