1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/frame.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/dcclient.h"
20 #include "wx/dialog.h"
21 #include "wx/settings.h"
22 #include "wx/toolbar.h"
23 #include "wx/statusbr.h"
24 #include "wx/menuitem.h"
27 #include "wx/mac/uma.h"
29 extern wxWindowList wxModelessWindows
;
31 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
32 EVT_ACTIVATE(wxFrame::OnActivate
)
33 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
34 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
35 // EVT_IDLE(wxFrame::OnIdle)
36 // EVT_CLOSE(wxFrame::OnCloseWindow)
39 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
41 #define WX_MAC_STATUSBAR_HEIGHT 18
43 // ----------------------------------------------------------------------------
44 // creation/destruction
45 // ----------------------------------------------------------------------------
49 m_frameMenuBar
= NULL
;
50 m_frameStatusBar
= NULL
;
51 m_winLastFocused
= NULL
;
54 m_frameToolBar
= NULL
;
58 // NB: is this used anywhere?
65 bool wxFrame::Create(wxWindow
*parent
,
67 const wxString
& title
,
74 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
77 wxModelessWindows
.Append(this);
84 m_isBeingDeleted
= true;
88 // get the origin of the client area in the client coordinates
89 wxPoint
wxFrame::GetClientAreaOrigin() const
91 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
93 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
94 wxToolBar
*toolbar
= GetToolBar();
95 if ( toolbar
&& toolbar
->IsShown() )
98 toolbar
->GetSize(&w
, &h
);
100 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
106 #if !wxMAC_USE_NATIVE_TOOLBAR
116 bool wxFrame::Enable(bool enable
)
118 if ( !wxWindow::Enable(enable
) )
121 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
123 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
124 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
126 m_frameMenuBar
->EnableTop( i
, enable
) ;
133 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
134 const wxString
& name
)
136 wxStatusBar
*statusBar
;
138 statusBar
= new wxStatusBar(this, id
, style
, name
);
139 statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
);
140 statusBar
->SetFieldsCount(number
);
145 void wxFrame::PositionStatusBar()
147 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
150 GetClientSize(&w
, &h
);
152 // Since we wish the status bar to be directly under the client area,
153 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
154 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
158 // Responds to colour changes, and passes event on to children.
159 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
161 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
164 if ( m_frameStatusBar
)
166 wxSysColourChangedEvent event2
;
168 event2
.SetEventObject( m_frameStatusBar
);
169 m_frameStatusBar
->ProcessEvent(event2
);
172 // Propagate the event to the non-top-level children
173 wxWindow::OnSysColourChanged(event
);
176 // Default activation behaviour - set the focus for the first child
178 void wxFrame::OnActivate(wxActivateEvent
& event
)
180 if ( !event
.GetActive() )
182 // remember the last focused child if it is our child
183 m_winLastFocused
= FindFocus();
185 // so we NULL it out if it's a child from some other frame
186 wxWindow
*win
= m_winLastFocused
;
189 if ( win
->IsTopLevel() )
192 m_winLastFocused
= NULL
;
197 win
= win
->GetParent();
204 // restore focus to the child which was last focused
205 wxWindow
*parent
= m_winLastFocused
206 ? m_winLastFocused
->GetParent()
212 wxSetFocusToChild(parent
, &m_winLastFocused
);
214 if (m_frameMenuBar
!= NULL
)
216 m_frameMenuBar
->MacInstallMenuBar();
220 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
223 // Trying top-level frame membar
224 if (tlf
->GetMenuBar())
225 tlf
->GetMenuBar()->MacInstallMenuBar();
231 void wxFrame::DetachMenuBar()
233 if ( m_frameMenuBar
)
234 m_frameMenuBar
->UnsetInvokingWindow();
236 wxFrameBase::DetachMenuBar();
239 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
241 wxFrame
* tlf
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame
);
242 bool makeCurrent
= false;
244 // if this is already the current menubar or we are the frontmost window
245 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
247 // or there is an app-level menubar like MDI
248 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
251 wxFrameBase::AttachMenuBar( menuBar
);
255 m_frameMenuBar
->SetInvokingWindow( this );
257 m_frameMenuBar
->MacInstallMenuBar();
261 void wxFrame::DoGetClientSize(int *x
, int *y
) const
263 wxTopLevelWindow::DoGetClientSize( x
, y
);
266 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
267 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
271 wxToolBar
*toolbar
= GetToolBar();
272 if ( toolbar
&& toolbar
->IsShown() )
275 toolbar
->GetSize(&w
, &h
);
277 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
284 #if !wxMAC_USE_NATIVE_TOOLBAR
293 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
296 if ( child
== GetStatusBar() )
301 if ( child
== GetToolBar() )
305 return wxFrameBase::MacIsChildOfClientArea( child
) ;
308 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
310 int currentclientwidth
, currentclientheight
;
311 int currentwidth
, currentheight
;
313 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
314 if ( clientwidth
== -1 )
315 clientwidth
= currentclientwidth
;
316 if ( clientheight
== -1 )
317 clientheight
= currentclientheight
;
318 GetSize( ¤twidth
, ¤theight
) ;
320 // find the current client size
322 // Find the difference between the entire window (title bar and all) and
323 // the client area; add this to the new client size to move the window
324 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
325 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
329 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
331 if ( m_frameToolBar
== toolbar
)
334 #if wxMAC_USE_NATIVE_TOOLBAR
335 if ( m_frameToolBar
)
336 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
339 m_frameToolBar
= toolbar
;
341 #if wxMAC_USE_NATIVE_TOOLBAR
343 toolbar
->MacInstallNativeToolbar( true ) ;
347 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
349 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
352 return m_frameToolBar
;
355 void wxFrame::PositionToolBar()
359 GetSize( &cw
, &ch
) ;
361 if (GetStatusBar() && GetStatusBar()->IsShown())
363 int statusX
, statusY
;
365 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
374 GetToolBar()->GetSize(&tw
, &th
);
375 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
377 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
378 // means, pretend we don't have toolbar/status bar, so we
379 // have the original client size.
380 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
384 #if !wxMAC_USE_NATIVE_TOOLBAR
385 // Use the 'real' position
386 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
392 void wxFrame::PositionBars()