1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/osx/uma.h"
41 #include "wx/tooltip.h"
44 #if wxUSE_SYSTEM_OPTIONS
45 #include "wx/sysopt.h"
49 #include <ToolUtils.h>
53 #include "wx/osx/private.h"
55 // ============================================================================
56 // wxTopLevelWindowMac implementation
57 // ============================================================================
59 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
62 // ----------------------------------------------------------------------------
63 // wxTopLevelWindowMac creation
64 // ----------------------------------------------------------------------------
73 void wxTopLevelWindowMac::Init()
76 m_maximizeOnShow
= false;
77 m_macFullScreenData
= NULL
;
80 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
82 const wxString
& title
,
88 if ( !wxNonOwnedWindow::Create(parent
, id
, pos
, size
, style
, name
) )
91 wxWindow::SetLabel( title
) ;
92 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) );
93 wxTopLevelWindows
.Append(this);
98 wxTopLevelWindowMac::~wxTopLevelWindowMac()
100 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
102 m_macFullScreenData
= NULL
;
106 // ----------------------------------------------------------------------------
107 // wxTopLevelWindowMac maximize/minimize
108 // ----------------------------------------------------------------------------
110 void wxTopLevelWindowMac::Maximize(bool maximize
)
112 Point idealSize
= { 0 , 0 } ;
115 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
117 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
119 idealSize
.h
= bounds
.size
.width
;
120 idealSize
.v
= bounds
.size
.height
;
123 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
124 idealSize
.h
= rect
.right
- rect
.left
;
125 idealSize
.v
= rect
.bottom
- rect
.top
;
128 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
131 bool wxTopLevelWindowMac::IsMaximized() const
133 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
136 void wxTopLevelWindowMac::Iconize(bool iconize
)
138 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
139 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
142 bool wxTopLevelWindowMac::IsIconized() const
144 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
147 void wxTopLevelWindowMac::Restore()
151 else if ( IsIconized() )
155 // ----------------------------------------------------------------------------
156 // wxTopLevelWindowMac misc
157 // ----------------------------------------------------------------------------
159 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
161 return wxPoint(0, 0) ;
164 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
166 wxWindow::SetLabel( title
) ;
167 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) ) ;
170 wxString
wxTopLevelWindowMac::GetTitle() const
172 return wxWindow::GetLabel();
175 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
179 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
181 data
= new FullScreenData() ;
183 m_macFullScreenData
= data
;
184 data
->m_position
= GetPosition() ;
185 data
->m_size
= GetSize() ;
186 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
188 if ( style
& wxFULLSCREEN_NOMENUBAR
)
191 wxRect client
= wxGetClientDisplayRect() ;
193 int left
, top
, right
, bottom
;
201 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
203 if ( style
& wxFULLSCREEN_NOCAPTION
)
209 if ( style
& wxFULLSCREEN_NOBORDER
)
216 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
221 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
226 SetSize( x
, y
, w
, h
) ;
227 if ( data
->m_wasResizable
)
228 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
230 else if ( m_macFullScreenData
!= NULL
)
233 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
234 if ( data
->m_wasResizable
)
235 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
236 SetPosition( data
->m_position
) ;
237 SetSize( data
->m_size
) ;
240 m_macFullScreenData
= NULL
;
246 bool wxTopLevelWindowMac::IsFullScreen() const
248 return m_macFullScreenData
!= NULL
;
251 // Attracts the users attention to this window if the application is
252 // inactive (should be called when a background event occurs)
254 static pascal void wxMacNMResponse( NMRecPtr ptr
)
257 DisposePtr( (Ptr
)ptr
) ;
260 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
262 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
263 static wxMacNMUPP
nmupp( wxMacNMResponse
);
265 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
266 notificationRequest
->qType
= nmType
;
267 notificationRequest
->nmMark
= 1 ;
268 notificationRequest
->nmIcon
= 0 ;
269 notificationRequest
->nmSound
= 0 ;
270 notificationRequest
->nmStr
= NULL
;
271 notificationRequest
->nmResp
= nmupp
;
273 verify_noerr( NMInstall( notificationRequest
) ) ;