1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/frame.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/dcclient.h"
20 #include "wx/dialog.h"
21 #include "wx/settings.h"
22 #include "wx/toolbar.h"
23 #include "wx/statusbr.h"
24 #include "wx/menuitem.h"
27 #include "wx/mac/uma.h"
29 extern wxWindowList wxModelessWindows
;
31 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
32 EVT_ACTIVATE(wxFrame::OnActivate
)
33 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
34 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
35 // EVT_IDLE(wxFrame::OnIdle)
36 // EVT_CLOSE(wxFrame::OnCloseWindow)
39 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
41 #define WX_MAC_STATUSBAR_HEIGHT 15
42 // ----------------------------------------------------------------------------
43 // creation/destruction
44 // ----------------------------------------------------------------------------
48 m_frameMenuBar
= NULL
;
51 m_frameToolBar
= NULL
;
53 m_frameStatusBar
= NULL
;
54 m_winLastFocused
= NULL
;
63 wxPoint
wxFrame::GetClientAreaOrigin() const
65 // on mac we are at position -1,-1 with the control
72 GetToolBar()->GetSize(& w
, & h
);
74 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
83 #endif // wxUSE_TOOLBAR
88 bool wxFrame::Create(wxWindow
*parent
,
90 const wxString
& title
,
96 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
98 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
101 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
103 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
104 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
106 wxModelessWindows
.Append(this);
113 m_isBeingDeleted
= true;
118 bool wxFrame::Enable(bool enable
)
120 if ( !wxWindow::Enable(enable
) )
123 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
125 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
126 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
128 m_frameMenuBar
->EnableTop( i
, enable
) ;
135 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
136 const wxString
& name
)
138 wxStatusBar
*statusBar
= NULL
;
140 statusBar
= new wxStatusBar(this, id
,
142 statusBar
->SetSize( 100 , 15 ) ;
143 statusBar
->SetFieldsCount(number
);
147 void wxFrame::PositionStatusBar()
149 if (m_frameStatusBar
)
152 GetClientSize(&w
, &h
);
154 m_frameStatusBar
->GetSize(&sw
, &sh
);
156 // Since we wish the status bar to be directly under the client area,
157 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
158 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
162 // Responds to colour changes, and passes event on to children.
163 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
165 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
168 if ( m_frameStatusBar
)
170 wxSysColourChangedEvent event2
;
171 event2
.SetEventObject( m_frameStatusBar
);
172 m_frameStatusBar
->ProcessEvent(event2
);
175 // Propagate the event to the non-top-level children
176 wxWindow::OnSysColourChanged(event
);
180 // Default activation behaviour - set the focus for the first child
182 void wxFrame::OnActivate(wxActivateEvent
& event
)
184 if ( !event
.GetActive() )
186 // remember the last focused child if it is our child
187 m_winLastFocused
= FindFocus();
189 // so we NULL it out if it's a child from some other frame
190 wxWindow
*win
= m_winLastFocused
;
193 if ( win
->IsTopLevel() )
197 m_winLastFocused
= NULL
;
203 win
= win
->GetParent();
210 // restore focus to the child which was last focused
211 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
218 wxSetFocusToChild(parent
, &m_winLastFocused
);
220 if ( m_frameMenuBar
!= NULL
)
222 m_frameMenuBar
->MacInstallMenuBar() ;
224 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
226 // Trying toplevel frame menbar
227 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
228 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
233 void wxFrame::DetachMenuBar()
235 if ( m_frameMenuBar
)
237 m_frameMenuBar
->UnsetInvokingWindow();
240 wxFrameBase::DetachMenuBar();
243 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
245 wxFrameBase::AttachMenuBar(menuBar
);
249 m_frameMenuBar
->SetInvokingWindow( this );
253 void wxFrame::DoGetClientSize(int *x
, int *y
) const
255 wxWindow::DoGetClientSize( x
, y
) ;
258 if ( GetStatusBar() && y
)
260 int statusX
, statusY
;
261 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
264 #endif // wxUSE_STATUSBAR
266 wxPoint
pt(GetClientAreaOrigin());
273 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
275 int currentclientwidth
, currentclientheight
;
276 int currentwidth
, currentheight
;
278 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
279 GetSize( ¤twidth
, ¤theight
) ;
281 // find the current client size
283 // Find the difference between the entire window (title bar and all)
284 // and the client area; add this to the new client size to move the
287 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
288 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
293 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
295 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
300 return m_frameToolBar
;
303 void wxFrame::PositionToolBar()
310 if ( GetStatusBar() )
312 int statusX
, statusY
;
313 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
320 GetToolBar()->GetSize(& tw
, & th
);
322 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
324 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
325 // means, pretend we don't have toolbar/status bar, so we
326 // have the original client size.
327 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
331 // Use the 'real' position
332 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);