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(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
) 
  43 #if wxUSE_NATIVE_STATUSBAR 
  44 bool wxFrame::m_useNativeStatusBar 
= TRUE
; 
  46 bool wxFrame::m_useNativeStatusBar 
= FALSE
; 
  49 #define WX_MAC_STATUSBAR_HEIGHT 15  
  50 // ---------------------------------------------------------------------------- 
  51 // creation/destruction 
  52 // ---------------------------------------------------------------------------- 
  56   m_frameMenuBar 
= NULL
; 
  59   m_frameToolBar 
= NULL 
; 
  61   m_frameStatusBar 
= NULL
; 
  62   m_winLastFocused 
= NULL 
; 
  71 wxPoint 
wxFrame::GetClientAreaOrigin() const 
  73         // on mac we are at position -1,-1 with the control 
  80         GetToolBar()->GetSize(& w
, & h
); 
  82         if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL 
) 
  91 #endif // wxUSE_TOOLBAR 
  96 bool wxFrame::Create(wxWindow 
*parent
, 
  98            const wxString
& title
, 
 102            const wxString
& name
) 
 104   SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
)); 
 106     if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) ) 
 109   MacCreateRealWindow( title
, pos 
, size 
, MacRemoveBordersFromStyle(style
) , name 
) ; 
 111         m_macWindowData
->m_macWindowBackgroundTheme 
= kThemeBrushDocumentWindowBackground 
; 
 113   wxModelessWindows
.Append(this); 
 120   m_isBeingDeleted 
= TRUE
; 
 127 bool wxFrame::Enable(bool enable
) 
 129     if ( !wxWindow::Enable(enable
) ) 
 132         if ( m_frameMenuBar 
&& m_frameMenuBar 
== wxMenuBar::MacGetInstalledMenuBar() ) 
 134                 for ( int i 
= 0 ; i 
< m_frameMenuBar
->GetMenuCount() ; ++ i 
) 
 136                         m_frameMenuBar
->EnableTop( i 
, enable 
) ; 
 143 wxStatusBar 
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
, 
 144     const wxString
& name
) 
 146     wxStatusBar 
*statusBar 
= NULL
; 
 148     statusBar 
= new wxStatusBar(this, id
, 
 150         statusBar
->SetSize( 100 , 15 ) ; 
 151     statusBar
->SetFieldsCount(number
); 
 155 void wxFrame::PositionStatusBar() 
 157   if (m_frameStatusBar 
) 
 160     GetClientSize(&w
, &h
); 
 162     m_frameStatusBar
->GetSize(&sw
, &sh
); 
 164     // Since we wish the status bar to be directly under the client area, 
 165     // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. 
 166     m_frameStatusBar
->SetSize(0, h
, w
, sh
); 
 170 // Responds to colour changes, and passes event on to children. 
 171 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
 173     SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
)); 
 176     if ( m_frameStatusBar 
) 
 178         wxSysColourChangedEvent event2
; 
 179         event2
.SetEventObject( m_frameStatusBar 
); 
 180         m_frameStatusBar
->ProcessEvent(event2
); 
 183     // Propagate the event to the non-top-level children 
 184     wxWindow::OnSysColourChanged(event
); 
 188 // Default activation behaviour - set the focus for the first child 
 190 void wxFrame::OnActivate(wxActivateEvent
& event
) 
 192     if ( !event
.GetActive() ) 
 194        // remember the last focused child if it is our child 
 195         m_winLastFocused 
= FindFocus(); 
 197         // so we NULL it out if it's a child from some other frame 
 198         wxWindow 
*win 
= m_winLastFocused
; 
 201             if ( win
->IsTopLevel() ) 
 205                     m_winLastFocused 
= NULL
; 
 211             win 
= win
->GetParent(); 
 218         // restore focus to the child which was last focused 
 219         wxWindow 
*parent 
= m_winLastFocused 
? m_winLastFocused
->GetParent() 
 226         wxSetFocusToChild(parent
, &m_winLastFocused
); 
 228             if ( m_frameMenuBar 
!= NULL 
) 
 230                 m_frameMenuBar
->MacInstallMenuBar() ; 
 235 void wxFrame::DoGetClientSize(int *x
, int *y
) const 
 237         wxWindow::DoGetClientSize( x 
, y 
) ; 
 240   if ( GetStatusBar() && y 
) 
 242     int statusX
, statusY
; 
 243     GetStatusBar()->GetClientSize(&statusX
, &statusY
); 
 246 #endif // wxUSE_STATUSBAR 
 248   wxPoint 
pt(GetClientAreaOrigin()); 
 255 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
) 
 257         int currentclientwidth 
, currentclientheight 
; 
 258         int currentwidth 
, currentheight 
; 
 260         GetClientSize( ¤tclientwidth 
, ¤tclientheight 
) ; 
 261         GetSize( ¤twidth 
, ¤theight 
) ; 
 263         // find the current client size 
 265   // Find the difference between the entire window (title bar and all) 
 266   // and the client area; add this to the new client size to move the 
 269         DoSetSize( -1 , -1 , currentwidth 
+ clientwidth 
- currentclientwidth 
, 
 270                 currentheight 
+ clientheight 
- currentclientheight 
, wxSIZE_USE_EXISTING 
) ; 
 275 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
) 
 277     if ( wxFrameBase::CreateToolBar(style
, id
, name
) ) 
 282     return m_frameToolBar
; 
 285 void wxFrame::PositionToolBar() 
 292     if ( GetStatusBar() ) 
 294       int statusX
, statusY
; 
 295       GetStatusBar()->GetClientSize(&statusX
, &statusY
); 
 302         GetToolBar()->GetSize(& tw
, & th
); 
 304         if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
) 
 306             // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS 
 307             // means, pretend we don't have toolbar/status bar, so we 
 308             // have the original client size. 
 309             GetToolBar()->SetSize(-1, -1, tw
, ch 
+ 2 , wxSIZE_NO_ADJUSTMENTS 
| wxSIZE_ALLOW_MINUS_ONE 
); 
 313             // Use the 'real' position 
 314             GetToolBar()->SetSize(-1, -1, cw 
+ 2, th
, wxSIZE_NO_ADJUSTMENTS 
| wxSIZE_ALLOW_MINUS_ONE 
);