1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
17 #include "wx/statusbr.h"
18 #include "wx/toolbar.h"
19 #include "wx/menuitem.h"
21 #include "wx/dcclient.h"
22 #include "wx/dialog.h"
23 #include "wx/settings.h"
26 #include <wx/mac/uma.h>
28 extern wxList wxModelessWindows
;
29 extern wxList wxPendingDelete
;
31 #if !USE_SHARED_LIBRARY
32 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
33 // EVT_SIZE(wxFrame::OnSize)
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
, wxWindow
)
44 #if wxUSE_NATIVE_STATUSBAR
45 bool wxFrame::m_useNativeStatusBar
= TRUE
;
47 bool wxFrame::m_useNativeStatusBar
= FALSE
;
50 #define WX_MAC_STATUSBAR_HEIGHT 15
51 // ----------------------------------------------------------------------------
52 // creation/destruction
53 // ----------------------------------------------------------------------------
64 wxPoint
wxFrame::GetClientAreaOrigin() const
66 // on mac we are at position -1,-1 with the control
73 GetToolBar()->GetSize(& w
, & h
);
75 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
84 #endif // wxUSE_TOOLBAR
89 bool wxFrame::Create(wxWindow
*parent
,
91 const wxString
& title
,
97 m_frameMenuBar
= NULL
;
100 m_frameToolBar
= NULL
;
102 m_frameStatusBar
= NULL
;
103 m_winLastFocused
= NULL
;
105 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
110 m_windowId
= (int)NewControlId();
112 if (parent
) parent
->AddChild(this);
115 wxTopLevelWindows
.Append(this);
117 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
119 m_macWindowData
->m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
121 wxModelessWindows
.Append(this);
128 m_isBeingDeleted
= TRUE
;
129 wxTopLevelWindows
.DeleteObject(this);
133 /* Check if it's the last top-level window */
135 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
137 wxTheApp
->SetTopWindow(NULL
);
139 if (wxTheApp
->GetExitOnFrameDelete())
141 wxTheApp
->ExitMainLoop() ;
145 wxModelessWindows
.DeleteObject(this);
149 bool wxFrame::Enable(bool enable
)
151 if ( !wxWindow::Enable(enable
) )
154 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
156 for ( int i
= 0 ; i
< m_frameMenuBar
->GetMenuCount() ; ++ i
)
158 m_frameMenuBar
->EnableTop( i
, enable
) ;
164 // Equivalent to maximize/restore in Windows
165 void wxFrame::Maximize(bool maximize
)
170 bool wxFrame::IsIconized() const
176 void wxFrame::Iconize(bool iconize
)
181 // Is the frame maximized?
182 bool wxFrame::IsMaximized(void) const
188 void wxFrame::Restore()
193 void wxFrame::SetIcon(const wxIcon
& icon
)
195 wxFrameBase::SetIcon(icon
);
198 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
199 const wxString
& name
)
201 wxStatusBar
*statusBar
= NULL
;
203 statusBar
= new wxStatusBar(this, id
,
205 statusBar
->SetSize( 100 , 15 ) ;
206 statusBar
->SetFieldsCount(number
);
210 void wxFrame::PositionStatusBar()
212 if (m_frameStatusBar
)
215 GetClientSize(&w
, &h
);
217 m_frameStatusBar
->GetSize(&sw
, &sh
);
219 // Since we wish the status bar to be directly under the client area,
220 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
221 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
225 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
232 m_frameMenuBar
= NULL
;
233 m_frameMenuBar
= menuBar
;
234 // m_frameMenuBar->MacInstallMenuBar() ;
235 m_frameMenuBar
->Attach(this);
239 // Responds to colour changes, and passes event on to children.
240 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
242 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
245 if ( m_frameStatusBar
)
247 wxSysColourChangedEvent event2
;
248 event2
.SetEventObject( m_frameStatusBar
);
249 m_frameStatusBar
->ProcessEvent(event2
);
252 // Propagate the event to the non-top-level children
253 wxWindow::OnSysColourChanged(event
);
257 // Default activation behaviour - set the focus for the first child
259 void wxFrame::OnActivate(wxActivateEvent
& event
)
261 if ( !event
.GetActive() )
263 // remember the last focused child
264 m_winLastFocused
= FindFocus();
265 while ( m_winLastFocused
)
267 if ( GetChildren().Find(m_winLastFocused
) )
270 m_winLastFocused
= m_winLastFocused
->GetParent();
278 for ( wxWindowList::Node *node = GetChildren().GetFirst();
280 node = node->GetNext() )
282 // FIXME all this is totally bogus - we need to do the same as wxPanel,
283 // but how to do it without duplicating the code?
286 wxWindow *child = node->GetData();
288 if ( !child->IsTopLevel() && child->AcceptsFocus()
290 && !wxDynamicCast(child, wxToolBar)
291 #endif // wxUSE_TOOLBAR
293 && !wxDynamicCast(child, wxStatusBar)
294 #endif // wxUSE_STATUSBAR
302 wxSetFocusToChild(this, &m_winLastFocused
);
304 if ( m_frameMenuBar
!= NULL
)
306 m_frameMenuBar
->MacInstallMenuBar() ;
311 void wxFrame::DoGetClientSize(int *x
, int *y
) const
313 wxWindow::DoGetClientSize( x
, y
) ;
316 if ( GetStatusBar() )
318 int statusX
, statusY
;
319 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
322 #endif // wxUSE_STATUSBAR
324 wxPoint
pt(GetClientAreaOrigin());
329 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
331 int currentclientwidth
, currentclientheight
;
332 int currentwidth
, currentheight
;
334 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
335 GetSize( ¤twidth
, ¤theight
) ;
337 // find the current client size
339 // Find the difference between the entire window (title bar and all)
340 // and the client area; add this to the new client size to move the
343 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
344 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
349 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
351 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
356 return m_frameToolBar
;
359 void wxFrame::PositionToolBar()
366 if ( GetStatusBar() )
368 int statusX
, statusY
;
369 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
376 GetToolBar()->GetSize(& tw
, & th
);
378 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
380 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
381 // means, pretend we don't have toolbar/status bar, so we
382 // have the original client size.
383 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
387 // Use the 'real' position
388 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);