X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6418cb93022a02da40be0e50aea3d5615074fb71..61cca9d24ee3f935f2581e3cfb894e46181290e6:/src/mac/carbon/frame.cpp diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index ba1377151f..aded221ea5 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -29,13 +29,13 @@ extern wxList wxModelessWindows; extern wxList wxPendingDelete; #if !USE_SHARED_LIBRARY -BEGIN_EVENT_TABLE(wxFrame, wxWindow) - EVT_SIZE(wxFrame::OnSize) +BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) +// EVT_SIZE(wxFrame::OnSize) EVT_ACTIVATE(wxFrame::OnActivate) - EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) + // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) - EVT_IDLE(wxFrame::OnIdle) - EVT_CLOSE(wxFrame::OnCloseWindow) +// EVT_IDLE(wxFrame::OnIdle) +// EVT_CLOSE(wxFrame::OnCloseWindow) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) @@ -47,17 +47,43 @@ bool wxFrame::m_useNativeStatusBar = TRUE; bool wxFrame::m_useNativeStatusBar = FALSE; #endif -wxFrame::wxFrame() +#define WX_MAC_STATUSBAR_HEIGHT 15 +// ---------------------------------------------------------------------------- +// creation/destruction +// ---------------------------------------------------------------------------- + +void wxFrame::Init() { -#if wxUSE_TOOLBAR - m_frameToolBar = NULL ; + m_iconized = FALSE; + +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; #endif +} - // in order to be able to give size events on show - m_frameMenuBar = NULL; - m_frameStatusBar = NULL; - m_iconized = FALSE; - m_isShown = FALSE; +wxPoint wxFrame::GetClientAreaOrigin() const +{ + // on mac we are at position -1,-1 with the control + wxPoint pt(0, 0); + +#if wxUSE_TOOLBAR + if ( GetToolBar() ) + { + int w, h; + GetToolBar()->GetSize(& w, & h); + + if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) + { + pt.x += w - 1; + } + else + { + pt.y += h - 1 ; + } + } +#endif // wxUSE_TOOLBAR + + return pt; } bool wxFrame::Create(wxWindow *parent, @@ -68,18 +94,13 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if (!parent) - wxTopLevelWindows.Append(this); - - SetName(name); - m_windowStyle = style; m_frameMenuBar = NULL; - m_isShown = FALSE; #if wxUSE_TOOLBAR m_frameToolBar = NULL ; #endif m_frameStatusBar = NULL; + m_winLastFocused = NULL ; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); @@ -90,74 +111,24 @@ bool wxFrame::Create(wxWindow *parent, if (parent) parent->AddChild(this); - wxModelessWindows.Append(this); - - // create frame. - - Rect theBoundsRect; - - m_x = (int)pos.x; - m_y = (int)pos.y; - if ( m_y < 50 ) - m_y = 50 ; - if ( m_x < 20 ) - m_x = 20 ; - - m_width = size.x; - if (m_width == -1) - m_width = 20; - m_height = size.y; - if (m_height == -1) - m_height = 20; + if (!parent) + wxTopLevelWindows.Append(this); - m_macWindowData = new MacWindowData() ; + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); + wxModelessWindows.Append(this); - WindowClass wclass = kDocumentWindowClass ; - WindowAttributes attr = kWindowNoAttributes ; - - if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) - { - attr |= kWindowFullZoomAttribute ; - attr |= kWindowResizableAttribute ; - } - if ( m_windowStyle & wxSTAY_ON_TOP ) - { - wclass = kFloatingWindowClass ; - -// if ( m_windowStyle & wxCAPTION ) -// attr |= kHasPaletteTitlebarMask ; - } - else - { - } - if ( m_windowStyle & wxSYSTEM_MENU ) - { - attr |= kWindowCloseBoxAttribute ; - } - UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; - wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; - wxString label ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( title ) ; - else - label = title ; - UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; - UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; - m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - m_macWindowData->m_macFocus = NULL ; return TRUE; } wxFrame::~wxFrame() { + m_isBeingDeleted = TRUE; wxTopLevelWindows.DeleteObject(this); - if (m_frameStatusBar) - delete m_frameStatusBar; - if (m_frameMenuBar) - delete m_frameMenuBar; + DeleteAllBars(); /* Check if it's the last top-level window */ @@ -175,11 +146,21 @@ wxFrame::~wxFrame() } -void wxFrame::Iconize(bool iconize) +bool wxFrame::Enable(bool enable) { - // TODO -} + if ( !wxWindow::Enable(enable) ) + return FALSE; + + if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) + { + for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) + { + m_frameMenuBar->EnableTop( i , enable ) ; + } + } + return TRUE; +} // Equivalent to maximize/restore in Windows void wxFrame::Maximize(bool maximize) { @@ -192,6 +173,11 @@ bool wxFrame::IsIconized() const return FALSE; } +void wxFrame::Iconize(bool iconize) +{ + // TODO +} + // Is the frame maximized? bool wxFrame::IsMaximized(void) const { @@ -199,10 +185,14 @@ bool wxFrame::IsMaximized(void) const return FALSE; } +void wxFrame::Restore() +{ + // TODO +} + void wxFrame::SetIcon(const wxIcon& icon) { - m_icon = icon; - // TODO + wxFrameBase::SetIcon(icon); } wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, @@ -210,61 +200,13 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, { wxStatusBar *statusBar = NULL; - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 17), + statusBar = new wxStatusBar(this, id, style, name); - - // Set the height according to the font and the border size - // we shouldn't do this on the mac, because we have to fit the grow box - /* - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); - - long x, y; - dc.GetTextExtent("X", &x, &y); - - int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); - - statusBar->SetSize(-1, -1, 100, height); - - */ - + statusBar->SetSize( 100 , 15 ) ; statusBar->SetFieldsCount(number); return statusBar; } -wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) -{ - // Calling CreateStatusBar twice is an error. - wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, - "recreating status bar in wxFrame" ); - - m_frameStatusBar = OnCreateStatusBar(number, style, id, - name); - if ( m_frameStatusBar ) - { - PositionStatusBar(); - return m_frameStatusBar; - } - else - return NULL; -} - -void wxFrame::SetStatusText(const wxString& text, int number) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); - - m_frameStatusBar->SetStatusText(text, number); -} - -void wxFrame::SetStatusWidths(int n, const int widths_field[]) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); - - m_frameStatusBar->SetStatusWidths(n, widths_field); - PositionStatusBar(); -} - void wxFrame::PositionStatusBar() { if (m_frameStatusBar ) @@ -284,43 +226,15 @@ void wxFrame::SetMenuBar(wxMenuBar *menuBar) { if (!menuBar) { - m_frameMenuBar = NULL; return; } + m_frameMenuBar = NULL; m_frameMenuBar = menuBar; - // TODO : we move this into the app code - m_frameMenuBar->MacInstallMenuBar() ; +// m_frameMenuBar->MacInstallMenuBar() ; + m_frameMenuBar->Attach(this); } -void wxFrame::Fit() -{ - // Work out max. size - wxNode *node = GetChildren().First(); - int max_width = 0; - int max_height = 0; - while (node) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *win = (wxWindow *)node->Data(); - - if (!win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog))) - { - int width, height; - int x, y; - win->GetSize(&width, &height); - win->GetPosition(&x, &y); - - if ((x + width) > max_width) - max_width = x + width; - if ((y + height) > max_height) - max_height = y + height; - } - node = node->Next(); - } - SetClientSize(max_width, max_height); -} // Responds to colour changes, and passes event on to children. void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) @@ -339,217 +253,73 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxWindow::OnSysColourChanged(event); } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size -void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) ) -{ - DoMenuUpdates(); -} - - -// update all menus -void wxFrame::DoMenuUpdates() -{ - wxMenuBar* bar = GetMenuBar(); - - if ( bar != NULL ) - { - int nCount = bar->GetMenuCount(); - for (int n = 0; n < nCount; n++) - DoMenuUpdates(bar->GetMenu(n), (wxWindow*) NULL); - } -} - -// update a menu and all submenus recursively -void wxFrame::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin)) -{ - wxEvtHandler* evtHandler = GetEventHandler(); - wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst(); - while (node) - { - wxMenuItem* item = node->GetData(); - if ( !item->IsSeparator() ) - { - wxWindowID id = item->GetId(); - wxUpdateUIEvent event(id); - event.SetEventObject( this ); - - if (evtHandler->ProcessEvent(event)) - { - if (event.GetSetText()) - menu->SetLabel(id, event.GetText()); - if (event.GetSetChecked()) - menu->Check(id, event.GetChecked()); - if (event.GetSetEnabled()) - menu->Enable(id, event.GetEnabled()); - } - - if (item->GetSubMenu()) - DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL); - } - node = node->GetNext(); - } -} - -void wxFrame::OnSize(wxSizeEvent& event) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; - } - #endif - - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) -#if wxUSE_TOOLBAR - && - (win != GetToolBar()) -#endif - ) - { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; - } - } - - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); - - int x = 0; - int y = 0; - - child->SetSize(x, y, clientW, clientH); - } -} // Default activation behaviour - set the focus for the first child // subwindow found. void wxFrame::OnActivate(wxActivateEvent& event) { - for(wxNode *node = GetChildren().First(); node; node = node->Next()) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *child = (wxWindow *)node->Data(); - if (!child->IsKindOf(CLASSINFO(wxFrame)) && - !child->IsKindOf(CLASSINFO(wxDialog))) + if ( !event.GetActive() ) { - child->SetFocus(); - return; - } - } -} - -// The default implementation for the close window event. -void wxFrame::OnCloseWindow(wxCloseEvent& event) -{ - this->Destroy(); -} + // remember the last focused child + m_winLastFocused = FindFocus(); + while ( m_winLastFocused ) + { + if ( GetChildren().Find(m_winLastFocused) ) + break; -// Destroy the window (delayed, if a managed window) -bool wxFrame::Destroy() -{ - if (!wxPendingDelete.Member(this)) - wxPendingDelete.Append(this); - return TRUE; -} + m_winLastFocused = m_winLastFocused->GetParent(); + } -// Default menu selection behaviour - display a help string -void wxFrame::OnMenuHighlight(wxMenuEvent& event) -{ - if (GetStatusBar()) - { - if (event.GetMenuId() == -1) - SetStatusText(""); - else - { - wxMenuBar *menuBar = GetMenuBar(); - if (menuBar) - { - wxString helpString(menuBar->GetHelpString(event.GetMenuId())); - if (helpString != "") - SetStatusText(helpString); - } + event.Skip(); } - } -} - -wxMenuBar *wxFrame::GetMenuBar() const -{ - return m_frameMenuBar; -} - - -// Call this to simulate a menu command -void wxFrame::Command(int id) -{ - ProcessCommand(id); -} - -void wxFrame::ProcessCommand(int id) -{ - wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); - commandEvent.SetInt( id ); - commandEvent.SetEventObject( this ); - - wxMenuBar *bar = GetMenuBar() ; - if (!bar) - return; - -/* TODO: check the menu item if required - wxMenuItem *item = bar->FindItemForId(id) ; - if (item && item->IsCheckable()) - { - bar->Check(id,!bar->Checked(id)) ; - } -*/ + else + { +/* + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + // FIXME all this is totally bogus - we need to do the same as wxPanel, + // but how to do it without duplicating the code? - GetEventHandler()->ProcessEvent(commandEvent); -} + // restore focus + wxWindow *child = node->GetData(); -// Checks if there is a toolbar, and returns the first free client position -wxPoint wxFrame::GetClientAreaOrigin() const -{ - wxPoint pt(0, 0); + if ( !child->IsTopLevel() && child->AcceptsFocus() #if wxUSE_TOOLBAR - if (GetToolBar()) - { - int w, h; - GetToolBar()->GetSize(& w, & h); - - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) - { - pt.x += w; - } - else + && !wxDynamicCast(child, wxToolBar) +#endif // wxUSE_TOOLBAR +#if wxUSE_STATUSBAR + && !wxDynamicCast(child, wxStatusBar) +#endif // wxUSE_STATUSBAR + ) { - pt.y += h; + child->SetFocus(); + break; } } -#endif - return pt; + */ + wxSetFocusToChild(this, &m_winLastFocused); + + if ( m_frameMenuBar != NULL ) + { + m_frameMenuBar->MacInstallMenuBar() ; + } + } } void wxFrame::DoGetClientSize(int *x, int *y) const { wxWindow::DoGetClientSize( x , y ) ; +#if wxUSE_STATUSBAR if ( GetStatusBar() ) { int statusX, statusY; GetStatusBar()->GetClientSize(&statusX, &statusY); *y -= statusY; } +#endif // wxUSE_STATUSBAR wxPoint pt(GetClientAreaOrigin()); *y -= pt.y; @@ -578,39 +348,20 @@ void wxFrame::DoSetClientSize(int clientwidth, int clientheight) #if wxUSE_TOOLBAR wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { - wxCHECK_MSG( m_frameToolBar == NULL, FALSE, - "recreating toolbar in wxFrame" ); - - wxToolBar* toolBar = OnCreateToolBar(style, id, name); - if (toolBar) + if ( wxFrameBase::CreateToolBar(style, id, name) ) { - SetToolBar(toolBar); PositionToolBar(); - return toolBar; } - else - { - return NULL; - } -} -wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) -{ - return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return m_frameToolBar; } void wxFrame::PositionToolBar() { int cw, ch; - // TODO: we actually need to use the low-level client size, before - // the toolbar/status bar were added. - // So DEFINITELY replace the line below with something appropriate. - - // GetClientSize(& cw, &ch); - - cw = m_width ; - ch = m_height ; + cw = m_width ; + ch = m_height ; if ( GetStatusBar() ) { @@ -629,12 +380,12 @@ void wxFrame::PositionToolBar() // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS // means, pretend we don't have toolbar/status bar, so we // have the original client size. - GetToolBar()->SetSize(0, 0, tw, ch, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } else { // Use the 'real' position - GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } } }