1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "frame.h"
16 #include "wx/wxprec.h"
19 #include "wx/statusbr.h"
20 #include "wx/toolbar.h"
21 #include "wx/menuitem.h"
23 #include "wx/dcclient.h"
24 #include "wx/dialog.h"
25 #include "wx/settings.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
44 // ----------------------------------------------------------------------------
45 // creation/destruction
46 // ----------------------------------------------------------------------------
50 m_frameMenuBar
= NULL
;
53 m_frameToolBar
= NULL
;
55 m_frameStatusBar
= NULL
;
56 m_winLastFocused
= NULL
;
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
111 #endif // wxUSE_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
= NULL
;
138 statusBar
= new wxStatusBar(this, id
,
140 statusBar
->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT
) ;
141 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
;
167 event2
.SetEventObject( m_frameStatusBar
);
168 m_frameStatusBar
->ProcessEvent(event2
);
171 // Propagate the event to the non-top-level children
172 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() )
193 m_winLastFocused
= NULL
;
199 win
= win
->GetParent();
206 // restore focus to the child which was last focused
207 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
214 wxSetFocusToChild(parent
, &m_winLastFocused
);
216 if ( m_frameMenuBar
!= NULL
)
218 m_frameMenuBar
->MacInstallMenuBar() ;
220 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
222 // Trying toplevel frame menbar
223 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
224 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
229 void wxFrame::DetachMenuBar()
231 if ( m_frameMenuBar
)
233 m_frameMenuBar
->UnsetInvokingWindow();
236 wxFrameBase::DetachMenuBar();
239 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
241 wxFrameBase::AttachMenuBar(menuBar
);
245 m_frameMenuBar
->SetInvokingWindow( this );
249 void wxFrame::DoGetClientSize(int *x
, int *y
) const
251 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
254 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
256 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
258 #endif // wxUSE_STATUSBAR
261 wxToolBar
*toolbar
= GetToolBar();
262 if ( toolbar
&& toolbar
->IsShown() )
265 toolbar
->GetSize(&w
, &h
);
267 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
273 //#if wxMAC_USE_NATIVE_TOOLBAR
274 // todo verify whether HIToolBox is giving correct sizes here for the tlw
279 #endif // wxUSE_TOOLBAR
282 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
285 if ( child
== GetStatusBar() )
287 #endif // wxUSE_STATUSBAR
290 if ( child
== GetToolBar() )
292 #endif // wxUSE_TOOLBAR
294 return wxFrameBase::MacIsChildOfClientArea( child
) ;
297 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
299 int currentclientwidth
, currentclientheight
;
300 int currentwidth
, currentheight
;
302 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
303 if ( clientwidth
== -1 )
304 clientwidth
= currentclientwidth
;
305 if ( clientheight
== -1 )
306 clientheight
= currentclientheight
;
307 GetSize( ¤twidth
, ¤theight
) ;
309 // find the current client size
311 // Find the difference between the entire window (title bar and all)
312 // and the client area; add this to the new client size to move the
315 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
316 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
321 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
323 if ( m_frameToolBar
== toolbar
)
326 #if wxMAC_USE_NATIVE_TOOLBAR
327 if ( m_frameToolBar
)
328 m_frameToolBar
->MacInstallNativeToolbar(false) ;
331 m_frameToolBar
= toolbar
;
332 #if wxMAC_USE_NATIVE_TOOLBAR
334 toolbar
->MacInstallNativeToolbar( true ) ;
338 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
340 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
345 return m_frameToolBar
;
348 void wxFrame::PositionToolBar()
352 GetSize( &cw
, &ch
) ;
354 if ( GetStatusBar() && GetStatusBar()->IsShown())
356 int statusX
, statusY
;
357 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
366 GetToolBar()->GetSize(& tw
, & th
);
367 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
369 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
370 // means, pretend we don't have toolbar/status bar, so we
371 // have the original client size.
372 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
376 #if !wxMAC_USE_NATIVE_TOOLBAR
377 // Use the 'real' position
378 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);