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(wxFrameMac
, wxFrameBase
)
33 // EVT_SIZE(wxFrameMac::OnSize)
34 EVT_ACTIVATE(wxFrameMac::OnActivate
)
35 // EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight)
36 EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged
)
37 // EVT_IDLE(wxFrameMac::OnIdle)
38 // EVT_CLOSE(wxFrameMac::OnCloseWindow)
41 IMPLEMENT_DYNAMIC_CLASS(wxFrameMac
, wxWindow
)
43 #ifndef __WXUNIVERSAL__
44 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxFrameMac
)
47 #if wxUSE_NATIVE_STATUSBAR
48 bool wxFrameMac::m_useNativeStatusBar
= TRUE
;
50 bool wxFrameMac::m_useNativeStatusBar
= FALSE
;
53 #define WX_MAC_STATUSBAR_HEIGHT 15
54 // ----------------------------------------------------------------------------
55 // creation/destruction
56 // ----------------------------------------------------------------------------
58 void wxFrameMac::Init()
60 m_frameMenuBar
= NULL
;
63 m_frameToolBar
= NULL
;
65 m_frameStatusBar
= NULL
;
66 m_winLastFocused
= NULL
;
75 wxPoint
wxFrameMac::GetClientAreaOrigin() const
77 // on mac we are at position -1,-1 with the control
84 GetToolBar()->GetSize(& w
, & h
);
86 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
95 #endif // wxUSE_TOOLBAR
100 bool wxFrameMac::Create(wxWindow
*parent
,
102 const wxString
& title
,
106 const wxString
& name
)
108 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
113 m_windowId
= (int)NewControlId();
115 if (parent
) parent
->AddChild(this);
118 wxTopLevelWindows
.Append(this);
120 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
122 m_macWindowData
->m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
124 wxModelessWindows
.Append(this);
129 wxFrameMac::~wxFrameMac()
131 m_isBeingDeleted
= TRUE
;
132 wxTopLevelWindows
.DeleteObject(this);
136 /* Check if it's the last top-level window */
138 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
140 wxTheApp
->SetTopWindow(NULL
);
142 if (wxTheApp
->GetExitOnFrameDelete())
144 wxTheApp
->ExitMainLoop() ;
148 wxModelessWindows
.DeleteObject(this);
152 bool wxFrameMac::Enable(bool enable
)
154 if ( !wxWindow::Enable(enable
) )
157 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
159 for ( int i
= 0 ; i
< m_frameMenuBar
->GetMenuCount() ; ++ i
)
161 m_frameMenuBar
->EnableTop( i
, enable
) ;
167 // Equivalent to maximize/restore in Windows
168 void wxFrameMac::Maximize(bool maximize
)
173 bool wxFrameMac::IsIconized() const
179 void wxFrameMac::Iconize(bool iconize
)
184 // Is the frame maximized?
185 bool wxFrameMac::IsMaximized(void) const
191 void wxFrameMac::Restore()
196 void wxFrameMac::SetIcon(const wxIcon
& icon
)
198 wxFrameBase::SetIcon(icon
);
201 wxStatusBar
*wxFrameMac::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
202 const wxString
& name
)
204 wxStatusBar
*statusBar
= NULL
;
206 statusBar
= new wxStatusBar(this, id
,
208 statusBar
->SetSize( 100 , 15 ) ;
209 statusBar
->SetFieldsCount(number
);
213 void wxFrameMac::PositionStatusBar()
215 if (m_frameStatusBar
)
218 GetClientSize(&w
, &h
);
220 m_frameStatusBar
->GetSize(&sw
, &sh
);
222 // Since we wish the status bar to be directly under the client area,
223 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
224 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
228 void wxFrameMac::SetMenuBar(wxMenuBar
*menuBar
)
235 m_frameMenuBar
= menuBar
;
236 // m_frameMenuBar->MacInstallMenuBar() ;
237 m_frameMenuBar
->Attach((wxFrame
*)this);
241 // Responds to colour changes, and passes event on to children.
242 void wxFrameMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
244 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
247 if ( m_frameStatusBar
)
249 wxSysColourChangedEvent event2
;
250 event2
.SetEventObject( m_frameStatusBar
);
251 m_frameStatusBar
->ProcessEvent(event2
);
254 // Propagate the event to the non-top-level children
255 wxWindow::OnSysColourChanged(event
);
259 // Default activation behaviour - set the focus for the first child
261 void wxFrameMac::OnActivate(wxActivateEvent
& event
)
263 if ( !event
.GetActive() )
265 // remember the last focused child
266 m_winLastFocused
= FindFocus();
267 while ( m_winLastFocused
)
269 if ( GetChildren().Find(m_winLastFocused
) )
272 m_winLastFocused
= m_winLastFocused
->GetParent();
280 for ( wxWindowList::Node *node = GetChildren().GetFirst();
282 node = node->GetNext() )
284 // FIXME all this is totally bogus - we need to do the same as wxPanel,
285 // but how to do it without duplicating the code?
288 wxWindow *child = node->GetData();
290 if ( !child->IsTopLevel() && child->AcceptsFocus()
292 && !wxDynamicCast(child, wxToolBar)
293 #endif // wxUSE_TOOLBAR
295 && !wxDynamicCast(child, wxStatusBar)
296 #endif // wxUSE_STATUSBAR
304 wxSetFocusToChild(this, &m_winLastFocused
);
306 if ( m_frameMenuBar
!= NULL
)
308 m_frameMenuBar
->MacInstallMenuBar() ;
313 void wxFrameMac::DoGetClientSize(int *x
, int *y
) const
315 wxWindow::DoGetClientSize( x
, y
) ;
318 if ( GetStatusBar() )
320 int statusX
, statusY
;
321 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
324 #endif // wxUSE_STATUSBAR
326 wxPoint
pt(GetClientAreaOrigin());
331 void wxFrameMac::DoSetClientSize(int clientwidth
, int clientheight
)
333 int currentclientwidth
, currentclientheight
;
334 int currentwidth
, currentheight
;
336 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
337 GetSize( ¤twidth
, ¤theight
) ;
339 // find the current client size
341 // Find the difference between the entire window (title bar and all)
342 // and the client area; add this to the new client size to move the
345 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
346 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
351 wxToolBar
* wxFrameMac::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
353 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
358 return m_frameToolBar
;
361 void wxFrameMac::PositionToolBar()
368 if ( GetStatusBar() )
370 int statusX
, statusY
;
371 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
378 GetToolBar()->GetSize(& tw
, & th
);
380 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
382 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
383 // means, pretend we don't have toolbar/status bar, so we
384 // have the original client size.
385 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
389 // Use the 'real' position
390 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);