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"
26 #include "wx/menuitem.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
32 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
33 EVT_ACTIVATE(wxFrame::OnActivate
)
34 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
35 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
36 // EVT_IDLE(wxFrame::OnIdle)
37 // EVT_CLOSE(wxFrame::OnCloseWindow)
40 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
42 #define WX_MAC_STATUSBAR_HEIGHT 18
44 // ----------------------------------------------------------------------------
45 // creation/destruction
46 // ----------------------------------------------------------------------------
50 m_frameMenuBar
= NULL
;
51 m_frameStatusBar
= NULL
;
52 m_winLastFocused
= NULL
;
55 m_frameToolBar
= NULL
;
59 // NB: is this used anywhere?
66 bool wxFrame::Create(wxWindow
*parent
,
68 const wxString
& title
,
75 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
78 wxModelessWindows
.Append(this);
85 m_isBeingDeleted
= true;
89 // get the origin of the client area in the client coordinates
90 wxPoint
wxFrame::GetClientAreaOrigin() const
92 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
94 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
95 wxToolBar
*toolbar
= GetToolBar();
96 if ( toolbar
&& toolbar
->IsShown() )
99 toolbar
->GetSize(&w
, &h
);
101 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
107 #if !wxMAC_USE_NATIVE_TOOLBAR
117 bool wxFrame::Enable(bool enable
)
119 if ( !wxWindow::Enable(enable
) )
122 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
124 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
125 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
127 m_frameMenuBar
->EnableTop( i
, enable
) ;
134 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
135 const wxString
& name
)
137 wxStatusBar
*statusBar
;
139 statusBar
= new wxStatusBar(this, id
, style
, name
);
140 statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
);
141 statusBar
->SetFieldsCount(number
);
146 void wxFrame::PositionStatusBar()
148 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
151 GetClientSize(&w
, &h
);
153 // Since we wish the status bar to be directly under the client area,
154 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
155 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
159 // Responds to colour changes, and passes event on to children.
160 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
162 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
165 if ( m_frameStatusBar
)
167 wxSysColourChangedEvent event2
;
169 event2
.SetEventObject( m_frameStatusBar
);
170 m_frameStatusBar
->ProcessEvent(event2
);
173 // Propagate the event to the non-top-level children
174 wxWindow::OnSysColourChanged(event
);
177 // Default activation behaviour - set the focus for the first child
179 void wxFrame::OnActivate(wxActivateEvent
& event
)
181 if ( !event
.GetActive() )
183 // remember the last focused child if it is our child
184 m_winLastFocused
= FindFocus();
186 // so we NULL it out if it's a child from some other frame
187 wxWindow
*win
= m_winLastFocused
;
190 if ( win
->IsTopLevel() )
193 m_winLastFocused
= NULL
;
198 win
= win
->GetParent();
205 // restore focus to the child which was last focused
206 wxWindow
*parent
= m_winLastFocused
207 ? m_winLastFocused
->GetParent()
213 wxSetFocusToChild(parent
, &m_winLastFocused
);
215 if (m_frameMenuBar
!= NULL
)
217 m_frameMenuBar
->MacInstallMenuBar();
221 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
224 // Trying top-level frame membar
225 if (tlf
->GetMenuBar())
226 tlf
->GetMenuBar()->MacInstallMenuBar();
232 void wxFrame::DetachMenuBar()
234 if ( m_frameMenuBar
)
235 m_frameMenuBar
->UnsetInvokingWindow();
237 wxFrameBase::DetachMenuBar();
240 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
242 wxFrame
* tlf
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame
);
243 bool makeCurrent
= false;
245 // if this is already the current menubar or we are the frontmost window
246 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
248 // or there is an app-level menubar like MDI
249 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
252 wxFrameBase::AttachMenuBar( menuBar
);
256 m_frameMenuBar
->SetInvokingWindow( this );
258 m_frameMenuBar
->MacInstallMenuBar();
262 void wxFrame::DoGetClientSize(int *x
, int *y
) const
264 wxTopLevelWindow::DoGetClientSize( x
, y
);
267 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
268 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
272 wxToolBar
*toolbar
= GetToolBar();
273 if ( toolbar
&& toolbar
->IsShown() )
276 toolbar
->GetSize(&w
, &h
);
278 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
285 #if !wxMAC_USE_NATIVE_TOOLBAR
294 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
297 if ( child
== GetStatusBar() )
302 if ( child
== GetToolBar() )
306 return wxFrameBase::MacIsChildOfClientArea( child
) ;
309 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
311 int currentclientwidth
, currentclientheight
;
312 int currentwidth
, currentheight
;
314 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
315 if ( clientwidth
== -1 )
316 clientwidth
= currentclientwidth
;
317 if ( clientheight
== -1 )
318 clientheight
= currentclientheight
;
319 GetSize( ¤twidth
, ¤theight
) ;
321 // find the current client size
323 // Find the difference between the entire window (title bar and all) and
324 // the client area; add this to the new client size to move the window
325 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
326 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
330 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
332 if ( m_frameToolBar
== toolbar
)
335 #if wxMAC_USE_NATIVE_TOOLBAR
336 if ( m_frameToolBar
)
337 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
340 m_frameToolBar
= toolbar
;
342 #if wxMAC_USE_NATIVE_TOOLBAR
344 toolbar
->MacInstallNativeToolbar( true ) ;
348 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
350 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
353 return m_frameToolBar
;
356 void wxFrame::PositionToolBar()
360 GetSize( &cw
, &ch
) ;
362 if (GetStatusBar() && GetStatusBar()->IsShown())
364 int statusX
, statusY
;
366 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
375 GetToolBar()->GetSize(&tw
, &th
);
376 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
378 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
379 // means, pretend we don't have toolbar/status bar, so we
380 // have the original client size.
381 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
385 #if !wxMAC_USE_NATIVE_TOOLBAR
386 // Use the 'real' position
387 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
393 void wxFrame::PositionBars()