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 wxWindowList wxModelessWindows
;
29 extern wxList wxPendingDelete
;
31 #if !USE_SHARED_LIBRARY
32 BEGIN_EVENT_TABLE(wxFrameMac
, wxFrameBase
)
33 EVT_ACTIVATE(wxFrameMac::OnActivate
)
34 // EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight)
35 EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged
)
36 // EVT_IDLE(wxFrameMac::OnIdle)
37 // EVT_CLOSE(wxFrameMac::OnCloseWindow)
40 IMPLEMENT_DYNAMIC_CLASS(wxFrameMac
, wxWindow
)
42 #ifndef __WXUNIVERSAL__
43 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxFrameMac
)
46 #if wxUSE_NATIVE_STATUSBAR
47 bool wxFrameMac::m_useNativeStatusBar
= TRUE
;
49 bool wxFrameMac::m_useNativeStatusBar
= FALSE
;
52 #define WX_MAC_STATUSBAR_HEIGHT 15
53 // ----------------------------------------------------------------------------
54 // creation/destruction
55 // ----------------------------------------------------------------------------
57 void wxFrameMac::Init()
59 m_frameMenuBar
= NULL
;
62 m_frameToolBar
= NULL
;
64 m_frameStatusBar
= NULL
;
65 m_winLastFocused
= NULL
;
74 wxPoint
wxFrameMac::GetClientAreaOrigin() const
76 // on mac we are at position -1,-1 with the control
83 GetToolBar()->GetSize(& w
, & h
);
85 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
94 #endif // wxUSE_TOOLBAR
99 bool wxFrameMac::Create(wxWindow
*parent
,
101 const wxString
& title
,
105 const wxString
& name
)
107 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
109 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
112 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
114 m_macWindowData
->m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
116 wxModelessWindows
.Append(this);
121 wxFrameMac::~wxFrameMac()
123 m_isBeingDeleted
= TRUE
;
130 bool wxFrameMac::Enable(bool enable
)
132 if ( !wxWindow::Enable(enable
) )
135 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
137 for ( int i
= 0 ; i
< m_frameMenuBar
->GetMenuCount() ; ++ i
)
139 m_frameMenuBar
->EnableTop( i
, enable
) ;
146 wxStatusBar
*wxFrameMac::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
147 const wxString
& name
)
149 wxStatusBar
*statusBar
= NULL
;
151 statusBar
= new wxStatusBar(this, id
,
153 statusBar
->SetSize( 100 , 15 ) ;
154 statusBar
->SetFieldsCount(number
);
158 void wxFrameMac::PositionStatusBar()
160 if (m_frameStatusBar
)
163 GetClientSize(&w
, &h
);
165 m_frameStatusBar
->GetSize(&sw
, &sh
);
167 // Since we wish the status bar to be directly under the client area,
168 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
169 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
173 // Responds to colour changes, and passes event on to children.
174 void wxFrameMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
176 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
179 if ( m_frameStatusBar
)
181 wxSysColourChangedEvent event2
;
182 event2
.SetEventObject( m_frameStatusBar
);
183 m_frameStatusBar
->ProcessEvent(event2
);
186 // Propagate the event to the non-top-level children
187 wxWindow::OnSysColourChanged(event
);
191 // Default activation behaviour - set the focus for the first child
193 void wxFrameMac::OnActivate(wxActivateEvent
& event
)
195 if ( !event
.GetActive() )
197 // remember the last focused child if it is our child
198 m_winLastFocused
= FindFocus();
200 // so we NULL it out if it's a child from some other frame
201 wxWindow
*win
= m_winLastFocused
;
204 if ( win
->IsTopLevel() )
208 m_winLastFocused
= NULL
;
214 win
= win
->GetParent();
221 // restore focus to the child which was last focused
222 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
229 wxSetFocusToChild(parent
, &m_winLastFocused
);
231 if ( m_frameMenuBar
!= NULL
)
233 m_frameMenuBar
->MacInstallMenuBar() ;
238 void wxFrameMac::DoGetClientSize(int *x
, int *y
) const
240 wxWindow::DoGetClientSize( x
, y
) ;
243 if ( GetStatusBar() && y
)
245 int statusX
, statusY
;
246 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
249 #endif // wxUSE_STATUSBAR
251 wxPoint
pt(GetClientAreaOrigin());
258 void wxFrameMac::DoSetClientSize(int clientwidth
, int clientheight
)
260 int currentclientwidth
, currentclientheight
;
261 int currentwidth
, currentheight
;
263 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
264 GetSize( ¤twidth
, ¤theight
) ;
266 // find the current client size
268 // Find the difference between the entire window (title bar and all)
269 // and the client area; add this to the new client size to move the
272 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
273 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
278 wxToolBar
* wxFrameMac::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
280 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
285 return m_frameToolBar
;
288 void wxFrameMac::PositionToolBar()
295 if ( GetStatusBar() )
297 int statusX
, statusY
;
298 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
305 GetToolBar()->GetSize(& tw
, & th
);
307 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
309 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
310 // means, pretend we don't have toolbar/status bar, so we
311 // have the original client size.
312 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
316 // Use the 'real' position
317 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);