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 // ----------------------------------------------------------------------------
57 m_frameMenuBar
= NULL
;
60 m_frameToolBar
= NULL
;
62 m_frameStatusBar
= NULL
;
63 m_winLastFocused
= NULL
;
72 wxPoint
wxFrame::GetClientAreaOrigin() const
74 // on mac we are at position -1,-1 with the control
81 GetToolBar()->GetSize(& w
, & h
);
83 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
92 #endif // wxUSE_TOOLBAR
97 bool wxFrame::Create(wxWindow
*parent
,
99 const wxString
& title
,
103 const wxString
& name
)
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
= 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() )
262 // remember the last focused child
263 m_winLastFocused
= FindFocus();
264 while ( m_winLastFocused
)
266 if ( GetChildren().Find(m_winLastFocused
) )
269 m_winLastFocused
= m_winLastFocused
->GetParent();
277 for ( wxWindowList::Node *node = GetChildren().GetFirst();
279 node = node->GetNext() )
281 // FIXME all this is totally bogus - we need to do the same as wxPanel,
282 // but how to do it without duplicating the code?
285 wxWindow *child = node->GetData();
287 if ( !child->IsTopLevel() && child->AcceptsFocus()
289 && !wxDynamicCast(child, wxToolBar)
290 #endif // wxUSE_TOOLBAR
292 && !wxDynamicCast(child, wxStatusBar)
293 #endif // wxUSE_STATUSBAR
301 wxSetFocusToChild(this, &m_winLastFocused
);
303 if ( m_frameMenuBar
!= NULL
)
305 m_frameMenuBar
->MacInstallMenuBar() ;
310 void wxFrame::DoGetClientSize(int *x
, int *y
) const
312 wxWindow::DoGetClientSize( x
, y
) ;
315 if ( GetStatusBar() )
317 int statusX
, statusY
;
318 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
321 #endif // wxUSE_STATUSBAR
323 wxPoint
pt(GetClientAreaOrigin());
328 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
330 int currentclientwidth
, currentclientheight
;
331 int currentwidth
, currentheight
;
333 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
334 GetSize( ¤twidth
, ¤theight
) ;
336 // find the current client size
338 // Find the difference between the entire window (title bar and all)
339 // and the client area; add this to the new client size to move the
342 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
343 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
348 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
350 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
355 return m_frameToolBar
;
358 void wxFrame::PositionToolBar()
365 if ( GetStatusBar() )
367 int statusX
, statusY
;
368 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
375 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(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
386 // Use the 'real' position
387 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);