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