1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
17 #include "wx/mac/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
;
104 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
109 m_windowId
= (int)NewControlId();
111 if (parent
) parent
->AddChild(this);
114 wxTopLevelWindows
.Append(this);
116 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
118 m_macWindowData
->m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
120 wxModelessWindows
.Append(this);
127 m_isBeingDeleted
= TRUE
;
128 wxTopLevelWindows
.DeleteObject(this);
132 /* Check if it's the last top-level window */
134 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
136 wxTheApp
->SetTopWindow(NULL
);
138 if (wxTheApp
->GetExitOnFrameDelete())
140 wxTheApp
->ExitMainLoop() ;
144 wxModelessWindows
.DeleteObject(this);
148 bool wxFrame::Enable(bool enable
)
150 if ( !wxWindow::Enable(enable
) )
153 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
155 for ( int i
= 0 ; i
< m_frameMenuBar
->GetMenuCount() ; ++ i
)
157 m_frameMenuBar
->EnableTop( i
, enable
) ;
163 // Equivalent to maximize/restore in Windows
164 void wxFrame::Maximize(bool maximize
)
169 bool wxFrame::IsIconized() const
175 void wxFrame::Iconize(bool iconize
)
180 // Is the frame maximized?
181 bool wxFrame::IsMaximized(void) const
187 void wxFrame::Restore()
192 void wxFrame::SetIcon(const wxIcon
& icon
)
194 wxFrameBase::SetIcon(icon
);
197 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
198 const wxString
& name
)
200 wxStatusBar
*statusBar
= NULL
;
202 statusBar
= new wxStatusBar(this, id
,
204 statusBar
->SetSize( 100 , 15 ) ;
205 statusBar
->SetFieldsCount(number
);
209 void wxFrame::PositionStatusBar()
211 if (m_frameStatusBar
)
214 GetClientSize(&w
, &h
);
216 m_frameStatusBar
->GetSize(&sw
, &sh
);
218 // Since we wish the status bar to be directly under the client area,
219 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
220 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
224 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
231 m_frameMenuBar
= NULL
;
232 m_frameMenuBar
= menuBar
;
233 m_frameMenuBar
->MacInstallMenuBar() ;
234 m_frameMenuBar
->Attach(this);
238 // Responds to colour changes, and passes event on to children.
239 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
241 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
244 if ( m_frameStatusBar
)
246 wxSysColourChangedEvent event2
;
247 event2
.SetEventObject( m_frameStatusBar
);
248 m_frameStatusBar
->ProcessEvent(event2
);
251 // Propagate the event to the non-top-level children
252 wxWindow::OnSysColourChanged(event
);
256 // Default activation behaviour - set the focus for the first child
258 void wxFrame::OnActivate(wxActivateEvent
& event
)
260 if ( !event
.GetActive() )
266 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
268 node
= node
->GetNext() )
270 // FIXME all this is totally bogus - we need to do the same as wxPanel,
271 // but how to do it without duplicating the code?
274 wxWindow
*child
= node
->GetData();
276 if ( !child
->IsTopLevel()
278 && !wxDynamicCast(child
, wxToolBar
)
279 #endif // wxUSE_TOOLBAR
281 && !wxDynamicCast(child
, wxStatusBar
)
282 #endif // wxUSE_STATUSBAR
291 void wxFrame::DoGetClientSize(int *x
, int *y
) const
293 wxWindow::DoGetClientSize( x
, y
) ;
296 if ( GetStatusBar() )
298 int statusX
, statusY
;
299 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
302 #endif // wxUSE_STATUSBAR
304 wxPoint
pt(GetClientAreaOrigin());
309 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
311 int currentclientwidth
, currentclientheight
;
312 int currentwidth
, currentheight
;
314 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
315 GetSize( ¤twidth
, ¤theight
) ;
317 // find the current client size
319 // Find the difference between the entire window (title bar and all)
320 // and the client area; add this to the new client size to move the
323 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
324 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
329 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
331 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
336 return m_frameToolBar
;
339 void wxFrame::PositionToolBar()
346 if ( GetStatusBar() )
348 int statusX
, statusY
;
349 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
356 GetToolBar()->GetSize(& tw
, & th
);
358 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
360 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
361 // means, pretend we don't have toolbar/status bar, so we
362 // have the original client size.
363 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
367 // Use the 'real' position
368 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);