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
, style
, name
);
204 statusBar
->SetFieldsCount(number
);
208 void wxFrame::PositionStatusBar()
210 if (m_frameStatusBar
)
213 GetClientSize(&w
, &h
);
215 m_frameStatusBar
->GetSize(&sw
, &sh
);
217 // Since we wish the status bar to be directly under the client area,
218 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
219 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
223 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
230 m_frameMenuBar
= NULL
;
231 m_frameMenuBar
= menuBar
;
232 m_frameMenuBar
->MacInstallMenuBar() ;
233 m_frameMenuBar
->Attach(this);
237 // Responds to colour changes, and passes event on to children.
238 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
240 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
243 if ( m_frameStatusBar
)
245 wxSysColourChangedEvent event2
;
246 event2
.SetEventObject( m_frameStatusBar
);
247 m_frameStatusBar
->ProcessEvent(event2
);
250 // Propagate the event to the non-top-level children
251 wxWindow::OnSysColourChanged(event
);
255 // Default activation behaviour - set the focus for the first child
257 void wxFrame::OnActivate(wxActivateEvent
& event
)
259 if ( !event
.GetActive() )
265 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
267 node
= node
->GetNext() )
269 // FIXME all this is totally bogus - we need to do the same as wxPanel,
270 // but how to do it without duplicating the code?
273 wxWindow
*child
= node
->GetData();
275 if ( !child
->IsTopLevel()
277 && !wxDynamicCast(child
, wxToolBar
)
278 #endif // wxUSE_TOOLBAR
280 && !wxDynamicCast(child
, wxStatusBar
)
281 #endif // wxUSE_STATUSBAR
290 void wxFrame::DoGetClientSize(int *x
, int *y
) const
292 wxWindow::DoGetClientSize( x
, y
) ;
295 if ( GetStatusBar() )
297 int statusX
, statusY
;
298 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
299 // right now this is a constant, this might change someday
300 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
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
);