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/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ============================================================================
57 // wxTopLevelWindowMac implementation
58 // ============================================================================
60 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
63 // ----------------------------------------------------------------------------
64 // wxTopLevelWindowMac creation
65 // ----------------------------------------------------------------------------
74 void wxTopLevelWindowMac::Init()
77 m_maximizeOnShow
= false;
78 m_macFullScreenData
= NULL
;
81 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
83 const wxString
& title
,
89 if ( !wxNonOwnedWindow::Create(parent
, id
, pos
, size
, style
, name
) )
92 wxWindow::SetLabel( title
) ;
93 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) );
94 wxTopLevelWindows
.Append(this);
99 wxTopLevelWindowMac::~wxTopLevelWindowMac()
101 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
103 m_macFullScreenData
= NULL
;
107 // ----------------------------------------------------------------------------
108 // wxTopLevelWindowMac maximize/minimize
109 // ----------------------------------------------------------------------------
111 void wxTopLevelWindowMac::Maximize(bool maximize
)
113 Point idealSize
= { 0 , 0 } ;
116 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
118 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
120 idealSize
.h
= bounds
.size
.width
;
121 idealSize
.v
= bounds
.size
.height
;
124 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
125 idealSize
.h
= rect
.right
- rect
.left
;
126 idealSize
.v
= rect
.bottom
- rect
.top
;
129 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
132 bool wxTopLevelWindowMac::IsMaximized() const
134 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
137 void wxTopLevelWindowMac::Iconize(bool iconize
)
139 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
140 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
143 bool wxTopLevelWindowMac::IsIconized() const
145 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
148 void wxTopLevelWindowMac::Restore()
152 else if ( IsIconized() )
156 // ----------------------------------------------------------------------------
157 // wxTopLevelWindowMac misc
158 // ----------------------------------------------------------------------------
160 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
162 return wxPoint(0, 0) ;
165 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
167 wxWindow::SetLabel( title
) ;
168 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) ) ;
171 wxString
wxTopLevelWindowMac::GetTitle() const
173 return wxWindow::GetLabel();
176 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
180 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
182 data
= new FullScreenData() ;
184 m_macFullScreenData
= data
;
185 data
->m_position
= GetPosition() ;
186 data
->m_size
= GetSize() ;
187 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
189 if ( style
& wxFULLSCREEN_NOMENUBAR
)
192 wxRect client
= wxGetClientDisplayRect() ;
194 int left
, top
, right
, bottom
;
202 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
204 if ( style
& wxFULLSCREEN_NOCAPTION
)
210 if ( style
& wxFULLSCREEN_NOBORDER
)
217 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
222 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
227 SetSize( x
, y
, w
, h
) ;
228 if ( data
->m_wasResizable
)
229 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
231 else if ( m_macFullScreenData
!= NULL
)
234 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
235 if ( data
->m_wasResizable
)
236 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
237 SetPosition( data
->m_position
) ;
238 SetSize( data
->m_size
) ;
241 m_macFullScreenData
= NULL
;
247 bool wxTopLevelWindowMac::IsFullScreen() const
249 return m_macFullScreenData
!= NULL
;
252 // Attracts the users attention to this window if the application is
253 // inactive (should be called when a background event occurs)
255 static pascal void wxMacNMResponse( NMRecPtr ptr
)
258 DisposePtr( (Ptr
)ptr
) ;
261 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
263 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
264 static wxMacNMUPP
nmupp( wxMacNMResponse
);
266 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
267 notificationRequest
->qType
= nmType
;
268 notificationRequest
->nmMark
= 1 ;
269 notificationRequest
->nmIcon
= 0 ;
270 notificationRequest
->nmSound
= 0 ;
271 notificationRequest
->nmStr
= NULL
;
272 notificationRequest
->nmResp
= nmupp
;
274 verify_noerr( NMInstall( notificationRequest
) ) ;