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"
24 #include "wx/statusbr.h"
25 #include "wx/toolbar.h"
26 #include "wx/menuitem.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
32 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
33 EVT_ACTIVATE(wxFrame::OnActivate
)
34 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
35 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
36 // EVT_IDLE(wxFrame::OnIdle)
37 // EVT_CLOSE(wxFrame::OnCloseWindow)
40 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
42 #define WX_MAC_STATUSBAR_HEIGHT 15
43 // ----------------------------------------------------------------------------
44 // creation/destruction
45 // ----------------------------------------------------------------------------
49 m_frameMenuBar
= NULL
;
52 m_frameToolBar
= NULL
;
54 m_frameStatusBar
= NULL
;
55 m_winLastFocused
= NULL
;
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 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
99 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
102 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
104 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
105 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
107 wxModelessWindows
.Append(this);
114 m_isBeingDeleted
= true;
119 bool wxFrame::Enable(bool enable
)
121 if ( !wxWindow::Enable(enable
) )
124 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
126 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
127 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
129 m_frameMenuBar
->EnableTop( i
, enable
) ;
136 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
137 const wxString
& name
)
139 wxStatusBar
*statusBar
= NULL
;
141 statusBar
= new wxStatusBar(this, id
,
143 statusBar
->SetSize( 100 , 15 ) ;
144 statusBar
->SetFieldsCount(number
);
148 void wxFrame::PositionStatusBar()
150 if (m_frameStatusBar
)
153 GetClientSize(&w
, &h
);
155 m_frameStatusBar
->GetSize(&sw
, &sh
);
157 // Since we wish the status bar to be directly under the client area,
158 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
159 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
163 // Responds to colour changes, and passes event on to children.
164 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
166 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
169 if ( m_frameStatusBar
)
171 wxSysColourChangedEvent event2
;
172 event2
.SetEventObject( m_frameStatusBar
);
173 m_frameStatusBar
->ProcessEvent(event2
);
176 // Propagate the event to the non-top-level children
177 wxWindow::OnSysColourChanged(event
);
181 // Default activation behaviour - set the focus for the first child
183 void wxFrame::OnActivate(wxActivateEvent
& event
)
185 if ( !event
.GetActive() )
187 // remember the last focused child if it is our child
188 m_winLastFocused
= FindFocus();
190 // so we NULL it out if it's a child from some other frame
191 wxWindow
*win
= m_winLastFocused
;
194 if ( win
->IsTopLevel() )
198 m_winLastFocused
= NULL
;
204 win
= win
->GetParent();
211 // restore focus to the child which was last focused
212 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
219 wxSetFocusToChild(parent
, &m_winLastFocused
);
221 if ( m_frameMenuBar
!= NULL
)
223 m_frameMenuBar
->MacInstallMenuBar() ;
225 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
227 // Trying toplevel frame menbar
228 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
229 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
234 void wxFrame::DetachMenuBar()
236 if ( m_frameMenuBar
)
238 m_frameMenuBar
->UnsetInvokingWindow();
241 wxFrameBase::DetachMenuBar();
244 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
246 wxFrameBase::AttachMenuBar(menuBar
);
250 m_frameMenuBar
->SetInvokingWindow( this );
254 void wxFrame::DoGetClientSize(int *x
, int *y
) const
256 wxWindow::DoGetClientSize( x
, y
) ;
259 if ( GetStatusBar() && y
)
261 int statusX
, statusY
;
262 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
265 #endif // wxUSE_STATUSBAR
267 wxPoint
pt(GetClientAreaOrigin());
274 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
276 int currentclientwidth
, currentclientheight
;
277 int currentwidth
, currentheight
;
279 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
280 GetSize( ¤twidth
, ¤theight
) ;
282 // find the current client size
284 // Find the difference between the entire window (title bar and all)
285 // and the client area; add this to the new client size to move the
288 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
289 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
294 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
296 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
301 return m_frameToolBar
;
304 void wxFrame::PositionToolBar()
311 if ( GetStatusBar() )
313 int statusX
, statusY
;
314 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
321 GetToolBar()->GetSize(& tw
, & th
);
323 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
325 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
326 // means, pretend we don't have toolbar/status bar, so we
327 // have the original client size.
328 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
332 // Use the 'real' position
333 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);