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"
20 #include "wx/statusbr.h"
21 #include "wx/toolbar.h"
22 #include "wx/menuitem.h"
24 #include "wx/dcclient.h"
25 #include "wx/dialog.h"
26 #include "wx/settings.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
31 extern wxList wxPendingDelete
;
33 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
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
, wxTopLevelWindow
)
43 #define WX_MAC_STATUSBAR_HEIGHT 15
44 // ----------------------------------------------------------------------------
45 // creation/destruction
46 // ----------------------------------------------------------------------------
50 m_frameMenuBar
= NULL
;
53 m_frameToolBar
= NULL
;
55 m_frameStatusBar
= NULL
;
56 m_winLastFocused
= NULL
;
65 wxPoint
wxFrame::GetClientAreaOrigin() const
67 // on mac we are at position -1,-1 with the control
74 GetToolBar()->GetSize(& w
, & h
);
76 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
85 #endif // wxUSE_TOOLBAR
90 bool wxFrame::Create(wxWindow
*parent
,
92 const wxString
& title
,
98 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
100 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
103 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
105 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
106 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
108 wxModelessWindows
.Append(this);
115 m_isBeingDeleted
= true;
120 bool wxFrame::Enable(bool enable
)
122 if ( !wxWindow::Enable(enable
) )
125 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
127 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
128 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
130 m_frameMenuBar
->EnableTop( i
, enable
) ;
137 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
138 const wxString
& name
)
140 wxStatusBar
*statusBar
= NULL
;
142 statusBar
= new wxStatusBar(this, id
,
144 statusBar
->SetSize( 100 , 15 ) ;
145 statusBar
->SetFieldsCount(number
);
149 void wxFrame::PositionStatusBar()
151 if (m_frameStatusBar
)
154 GetClientSize(&w
, &h
);
156 m_frameStatusBar
->GetSize(&sw
, &sh
);
158 // Since we wish the status bar to be directly under the client area,
159 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
160 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
164 // Responds to colour changes, and passes event on to children.
165 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
167 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
170 if ( m_frameStatusBar
)
172 wxSysColourChangedEvent event2
;
173 event2
.SetEventObject( m_frameStatusBar
);
174 m_frameStatusBar
->ProcessEvent(event2
);
177 // Propagate the event to the non-top-level children
178 wxWindow::OnSysColourChanged(event
);
182 // Default activation behaviour - set the focus for the first child
184 void wxFrame::OnActivate(wxActivateEvent
& event
)
186 if ( !event
.GetActive() )
188 // remember the last focused child if it is our child
189 m_winLastFocused
= FindFocus();
191 // so we NULL it out if it's a child from some other frame
192 wxWindow
*win
= m_winLastFocused
;
195 if ( win
->IsTopLevel() )
199 m_winLastFocused
= NULL
;
205 win
= win
->GetParent();
212 // restore focus to the child which was last focused
213 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
220 wxSetFocusToChild(parent
, &m_winLastFocused
);
222 if ( m_frameMenuBar
!= NULL
)
224 m_frameMenuBar
->MacInstallMenuBar() ;
226 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
228 // Trying toplevel frame menbar
229 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
230 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
235 void wxFrame::DetachMenuBar()
237 if ( m_frameMenuBar
)
239 m_frameMenuBar
->UnsetInvokingWindow();
242 wxFrameBase::DetachMenuBar();
245 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
247 wxFrameBase::AttachMenuBar(menuBar
);
251 m_frameMenuBar
->SetInvokingWindow( this );
255 void wxFrame::DoGetClientSize(int *x
, int *y
) const
257 wxWindow::DoGetClientSize( x
, y
) ;
260 if ( GetStatusBar() && y
)
262 int statusX
, statusY
;
263 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
266 #endif // wxUSE_STATUSBAR
268 wxPoint
pt(GetClientAreaOrigin());
275 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
277 int currentclientwidth
, currentclientheight
;
278 int currentwidth
, currentheight
;
280 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
281 GetSize( ¤twidth
, ¤theight
) ;
283 // find the current client size
285 // Find the difference between the entire window (title bar and all)
286 // and the client area; add this to the new client size to move the
289 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
290 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
295 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
297 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
302 return m_frameToolBar
;
305 void wxFrame::PositionToolBar()
312 if ( GetStatusBar() )
314 int statusX
, statusY
;
315 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
322 GetToolBar()->GetSize(& tw
, & th
);
324 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
326 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
327 // means, pretend we don't have toolbar/status bar, so we
328 // have the original client size.
329 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
333 // Use the 'real' position
334 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);