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"
24 #include "wx/statusbr.h"
25 #include "wx/toolbar.h"
26 #include "wx/menuitem.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
31 //extern wxList wxPendingDelete;
33 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
34 EVT_ACTIVATE(wxFrame::OnActivate
)
35 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
36 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
37 // EVT_IDLE(wxFrame::OnIdle)
38 // EVT_CLOSE(wxFrame::OnCloseWindow)
41 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
43 #define WX_MAC_STATUSBAR_HEIGHT 18
45 // ----------------------------------------------------------------------------
46 // creation/destruction
47 // ----------------------------------------------------------------------------
51 m_frameMenuBar
= NULL
;
52 m_frameStatusBar
= NULL
;
53 m_winLastFocused
= NULL
;
56 m_frameToolBar
= NULL
;
60 // NB: is this used anywhere?
67 bool wxFrame::Create(wxWindow
*parent
,
69 const wxString
& title
,
76 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
79 wxModelessWindows
.Append(this);
86 m_isBeingDeleted
= true;
90 // get the origin of the client area in the client coordinates
91 wxPoint
wxFrame::GetClientAreaOrigin() const
93 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
95 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
96 wxToolBar
*toolbar
= GetToolBar();
97 if ( toolbar
&& toolbar
->IsShown() )
100 toolbar
->GetSize(&w
, &h
);
102 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
108 #if !wxMAC_USE_NATIVE_TOOLBAR
118 bool wxFrame::Enable(bool enable
)
120 if ( !wxWindow::Enable(enable
) )
123 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
125 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
126 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
128 m_frameMenuBar
->EnableTop( i
, enable
) ;
135 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
136 const wxString
& name
)
138 wxStatusBar
*statusBar
;
140 statusBar
= new wxStatusBar(this, id
, style
, name
);
141 statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
);
142 statusBar
->SetFieldsCount(number
);
147 void wxFrame::PositionStatusBar()
149 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
152 GetClientSize(&w
, &h
);
154 // Since we wish the status bar to be directly under the client area,
155 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
156 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
160 // Responds to colour changes, and passes event on to children.
161 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
163 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
166 if ( m_frameStatusBar
)
168 wxSysColourChangedEvent event2
;
170 event2
.SetEventObject( m_frameStatusBar
);
171 m_frameStatusBar
->ProcessEvent(event2
);
174 // Propagate the event to the non-top-level children
175 wxWindow::OnSysColourChanged(event
);
178 // Default activation behaviour - set the focus for the first child
180 void wxFrame::OnActivate(wxActivateEvent
& event
)
182 if ( !event
.GetActive() )
184 // remember the last focused child if it is our child
185 m_winLastFocused
= FindFocus();
187 // so we NULL it out if it's a child from some other frame
188 wxWindow
*win
= m_winLastFocused
;
191 if ( win
->IsTopLevel() )
194 m_winLastFocused
= NULL
;
199 win
= win
->GetParent();
206 // restore focus to the child which was last focused
207 wxWindow
*parent
= m_winLastFocused
208 ? m_winLastFocused
->GetParent()
214 wxSetFocusToChild(parent
, &m_winLastFocused
);
216 if (m_frameMenuBar
!= NULL
)
218 m_frameMenuBar
->MacInstallMenuBar();
222 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
225 // Trying top-level frame membar
226 if (tlf
->GetMenuBar())
227 tlf
->GetMenuBar()->MacInstallMenuBar();
233 void wxFrame::DetachMenuBar()
235 if ( m_frameMenuBar
)
236 m_frameMenuBar
->UnsetInvokingWindow();
238 wxFrameBase::DetachMenuBar();
241 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
243 wxFrame
* tlf
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame
);
244 bool makeCurrent
= false;
246 // if this is already the current menubar or we are the frontmost window
247 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
249 // or there is an app-level menubar like MDI
250 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
253 wxFrameBase::AttachMenuBar( menuBar
);
257 m_frameMenuBar
->SetInvokingWindow( this );
259 m_frameMenuBar
->MacInstallMenuBar();
263 void wxFrame::DoGetClientSize(int *x
, int *y
) const
265 wxTopLevelWindow::DoGetClientSize( x
, y
);
268 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
269 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
273 wxToolBar
*toolbar
= GetToolBar();
274 if ( toolbar
&& toolbar
->IsShown() )
277 toolbar
->GetSize(&w
, &h
);
279 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
286 #if !wxMAC_USE_NATIVE_TOOLBAR
295 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
298 if ( child
== GetStatusBar() )
303 if ( child
== GetToolBar() )
307 return wxFrameBase::MacIsChildOfClientArea( child
) ;
310 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
312 int currentclientwidth
, currentclientheight
;
313 int currentwidth
, currentheight
;
315 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
316 if ( clientwidth
== -1 )
317 clientwidth
= currentclientwidth
;
318 if ( clientheight
== -1 )
319 clientheight
= currentclientheight
;
320 GetSize( ¤twidth
, ¤theight
) ;
322 // find the current client size
324 // Find the difference between the entire window (title bar and all) and
325 // the client area; add this to the new client size to move the window
326 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
327 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
331 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
333 if ( m_frameToolBar
== toolbar
)
336 #if wxMAC_USE_NATIVE_TOOLBAR
337 if ( m_frameToolBar
)
338 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
341 m_frameToolBar
= toolbar
;
343 #if wxMAC_USE_NATIVE_TOOLBAR
345 toolbar
->MacInstallNativeToolbar( true ) ;
349 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
351 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
354 return m_frameToolBar
;
357 void wxFrame::PositionToolBar()
361 GetSize( &cw
, &ch
) ;
363 if (GetStatusBar() && GetStatusBar()->IsShown())
365 int statusX
, statusY
;
367 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
376 GetToolBar()->GetSize(&tw
, &th
);
377 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
379 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
380 // means, pretend we don't have toolbar/status bar, so we
381 // have the original client size.
382 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
386 #if !wxMAC_USE_NATIVE_TOOLBAR
387 // Use the 'real' position
388 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
394 void wxFrame::PositionBars()