1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/statusbr.h"
14 #include "wx/toolbar.h"
15 #include "wx/menuitem.h"
17 #include "wx/dcclient.h"
18 #include "wx/dialog.h"
19 #include "wx/settings.h"
22 #include "wx/mac/uma.h"
24 extern wxWindowList wxModelessWindows
;
25 extern wxList wxPendingDelete
;
27 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
28 EVT_ACTIVATE(wxFrame::OnActivate
)
29 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
30 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
31 // EVT_IDLE(wxFrame::OnIdle)
32 // EVT_CLOSE(wxFrame::OnCloseWindow)
35 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
37 #define WX_MAC_STATUSBAR_HEIGHT 15
38 // ----------------------------------------------------------------------------
39 // creation/destruction
40 // ----------------------------------------------------------------------------
44 m_frameMenuBar
= NULL
;
47 m_frameToolBar
= NULL
;
49 m_frameStatusBar
= NULL
;
50 m_winLastFocused
= NULL
;
59 wxPoint
wxFrame::GetClientAreaOrigin() const
61 // on mac we are at position -1,-1 with the control
68 GetToolBar()->GetSize(& w
, & h
);
70 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
79 #endif // wxUSE_TOOLBAR
84 bool wxFrame::Create(wxWindow
*parent
,
86 const wxString
& title
,
92 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
94 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
97 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
99 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
100 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
102 wxModelessWindows
.Append(this);
109 m_isBeingDeleted
= TRUE
;
114 bool wxFrame::Enable(bool enable
)
116 if ( !wxWindow::Enable(enable
) )
119 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
121 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
122 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
124 m_frameMenuBar
->EnableTop( i
, enable
) ;
131 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
132 const wxString
& name
)
134 wxStatusBar
*statusBar
= NULL
;
136 statusBar
= new wxStatusBar(this, id
,
138 statusBar
->SetSize( 100 , 15 ) ;
139 statusBar
->SetFieldsCount(number
);
143 void wxFrame::PositionStatusBar()
145 if (m_frameStatusBar
)
148 GetClientSize(&w
, &h
);
150 m_frameStatusBar
->GetSize(&sw
, &sh
);
152 // Since we wish the status bar to be directly under the client area,
153 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
154 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
158 // Responds to colour changes, and passes event on to children.
159 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
161 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
164 if ( m_frameStatusBar
)
166 wxSysColourChangedEvent event2
;
167 event2
.SetEventObject( m_frameStatusBar
);
168 m_frameStatusBar
->ProcessEvent(event2
);
171 // Propagate the event to the non-top-level children
172 wxWindow::OnSysColourChanged(event
);
176 // Default activation behaviour - set the focus for the first child
178 void wxFrame::OnActivate(wxActivateEvent
& event
)
180 if ( !event
.GetActive() )
182 // remember the last focused child if it is our child
183 m_winLastFocused
= FindFocus();
185 // so we NULL it out if it's a child from some other frame
186 wxWindow
*win
= m_winLastFocused
;
189 if ( win
->IsTopLevel() )
193 m_winLastFocused
= NULL
;
199 win
= win
->GetParent();
206 // restore focus to the child which was last focused
207 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
214 wxSetFocusToChild(parent
, &m_winLastFocused
);
216 if ( m_frameMenuBar
!= NULL
)
218 m_frameMenuBar
->MacInstallMenuBar() ;
220 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
222 // Trying toplevel frame menbar
223 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
224 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
229 void wxFrame::DetachMenuBar()
231 if ( m_frameMenuBar
)
233 m_frameMenuBar
->UnsetInvokingWindow();
236 wxFrameBase::DetachMenuBar();
239 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
241 wxFrameBase::AttachMenuBar(menuBar
);
245 m_frameMenuBar
->SetInvokingWindow( this );
249 void wxFrame::DoGetClientSize(int *x
, int *y
) const
251 wxWindow::DoGetClientSize( x
, y
) ;
254 if ( GetStatusBar() && y
)
256 int statusX
, statusY
;
257 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
260 #endif // wxUSE_STATUSBAR
262 wxPoint
pt(GetClientAreaOrigin());
269 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
271 int currentclientwidth
, currentclientheight
;
272 int currentwidth
, currentheight
;
274 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
275 GetSize( ¤twidth
, ¤theight
) ;
277 // find the current client size
279 // Find the difference between the entire window (title bar and all)
280 // and the client area; add this to the new client size to move the
283 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
284 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
289 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
291 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
296 return m_frameToolBar
;
299 void wxFrame::PositionToolBar()
306 if ( GetStatusBar() )
308 int statusX
, statusY
;
309 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
316 GetToolBar()->GetSize(& tw
, & th
);
318 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
320 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
321 // means, pretend we don't have toolbar/status bar, so we
322 // have the original client size.
323 GetToolBar()->SetSize(-1, -1, tw
, ch
+ 2 , wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);
327 // Use the 'real' position
328 GetToolBar()->SetSize(-1, -1, cw
+ 2, th
, wxSIZE_NO_ADJUSTMENTS
| wxSIZE_ALLOW_MINUS_ONE
);