From 36ebfcd176806639de016b6428d27a63b818bbd8 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 25 Jan 2012 11:51:31 +0000 Subject: [PATCH] MGR: Fix sizes of task panes and buttons, elapsing button text if needed svn path=/trunk/boinc/; revision=25147 --- checkin_notes | 10 +++++++++ clientgui/BOINCBaseView.cpp | 16 -------------- clientgui/BOINCBaseView.h | 1 + clientgui/BOINCTaskCtrl.cpp | 44 ++++++++++++++++++++++++++++++++----- clientgui/BOINCTaskCtrl.h | 2 ++ clientgui/stdwx.h | 1 - 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/checkin_notes b/checkin_notes index 2e10ed467b..d13097c41b 100644 --- a/checkin_notes +++ b/checkin_notes @@ -1003,3 +1003,13 @@ Charlie 25 Jan 2012 samples/vboxwrapper/ vboxwrapper.cpp + +Charlie 25 Jan 2012 + - MGR: Make the task pane in the advanced view and its buttons fixed sizes; + ellipse the button contents if needed; show full button text plus + description in button tooltips; don't set button labels if unchanged. + + clientgui/ + BOINCBaseView.cpp, .h + BOINCTaskCtrl.cpp, .h + stdwx.h diff --git a/clientgui/BOINCBaseView.cpp b/clientgui/BOINCBaseView.cpp index f5b7f312d9..a8402f0ab7 100644 --- a/clientgui/BOINCBaseView.cpp +++ b/clientgui/BOINCBaseView.cpp @@ -733,22 +733,6 @@ void CBOINCBaseView::UpdateSelection(){ void CBOINCBaseView::PostUpdateSelection(){ wxASSERT(m_pTaskPane); m_pTaskPane->UpdateControls(); - - // Adjust the width of the task pane so that it can be fully displayed. - // - wxSize sz = m_pTaskPane->GetVirtualSize(); - if (sz.GetHeight() > m_pTaskPane->GetSize().GetHeight()) { - // Account for vertical scrollbar - if (m_pTaskPane->GetSize().GetWidth() != (sz.GetWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, NULL))) { - m_pTaskPane->SetSize( - sz.GetWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, NULL), - m_pTaskPane->GetSize().GetHeight() - ); - } - } else { - m_pTaskPane->SetSize(sz.GetWidth(), m_pTaskPane->GetSize().GetHeight()); - } - Layout(); } diff --git a/clientgui/BOINCBaseView.h b/clientgui/BOINCBaseView.h index f1263fea33..d3b1e2e429 100644 --- a/clientgui/BOINCBaseView.h +++ b/clientgui/BOINCBaseView.h @@ -53,6 +53,7 @@ public: ~CTaskItem() {}; wxString m_strName; + wxString m_strNameEllipsed; wxString m_strDescription; wxInt32 m_iEventID; diff --git a/clientgui/BOINCTaskCtrl.cpp b/clientgui/BOINCTaskCtrl.cpp index 44ca5acf93..fa37d164a0 100644 --- a/clientgui/BOINCTaskCtrl.cpp +++ b/clientgui/BOINCTaskCtrl.cpp @@ -23,6 +23,8 @@ #include "BOINCBaseView.h" #include "BOINCTaskCtrl.h" +#define TASKPANEWIDTH 200 +#define TASKBUTTONWIDTH (TASKPANEWIDTH - 55) IMPLEMENT_DYNAMIC_CLASS(CBOINCTaskCtrl, wxScrolledWindow) @@ -131,13 +133,18 @@ wxInt32 CBOINCTaskCtrl::EnableTask( CTaskItem* pItem ) { wxInt32 CBOINCTaskCtrl::UpdateTask( CTaskItem* pItem, wxString strName, wxString strDescription ) { if (pItem->m_pButton) { + if (!pItem->m_strName.Cmp(strName) && + !pItem->m_strDescription.Cmp(strDescription)) { + return 0; + } pItem->m_strName = strName; + pItem->m_strNameEllipsed = pItem->m_strName; + EllipseStringIfNeeded(pItem->m_strNameEllipsed, pItem->m_pButton); pItem->m_strDescription = strDescription; - - pItem->m_pButton->SetLabel( strName ); + pItem->m_pButton->SetLabel( pItem->m_strNameEllipsed ); pItem->m_pButton->SetHelpText( strDescription ); #if wxUSE_TOOLTIPS - pItem->m_pButton->SetToolTip( strDescription ); + pItem->m_pButton->SetToolTip(pItem->m_strName + wxT(": ") + pItem->m_strDescription); #endif } return 0; @@ -180,10 +187,13 @@ wxInt32 CBOINCTaskCtrl::UpdateControls() { pItem = pGroup->m_Tasks[j]; if (!pItem->m_pButton) { pItem->m_pButton = new wxButton; - pItem->m_pButton->Create(this, pItem->m_iEventID, pItem->m_strName, wxDefaultPosition, wxDefaultSize, 0); + pItem->m_strNameEllipsed = pItem->m_strName; + pItem->m_pButton->Create(this, pItem->m_iEventID, wxEmptyString, wxDefaultPosition, wxSize(TASKBUTTONWIDTH, -1), 0); + EllipseStringIfNeeded(pItem->m_strNameEllipsed, pItem->m_pButton); + pItem->m_pButton->SetLabel(pItem->m_strNameEllipsed); pItem->m_pButton->SetHelpText(pItem->m_strDescription); #if wxUSE_TOOLTIPS - pItem->m_pButton->SetToolTip(pItem->m_strDescription); + pItem->m_pButton->SetToolTip(pItem->m_strName + wxT(": ") + pItem->m_strDescription); #endif pGroup->m_pStaticBoxSizer->Add(pItem->m_pButton, 0, wxEXPAND|wxALL, 5); } @@ -241,3 +251,27 @@ bool CBOINCTaskCtrl::OnRestoreState(wxConfigBase* pConfig) { return true; } + +void CBOINCTaskCtrl::EllipseStringIfNeeded(wxString& s, wxWindow *win) { + int w, h; + wxSize sz = win->GetSize(); + int maxWidth = sz.GetWidth() - 10; + + win->GetTextExtent(s, &w, &h); + + // Adapted from ellipis code in wxRendererGeneric::DrawHeaderButtonContents() + if (w > maxWidth) { + int ellipsisWidth; + win->GetTextExtent( wxT("..."), &ellipsisWidth, NULL); + if (ellipsisWidth > maxWidth) { + s.Clear(); + w = 0; + } else { + do { + s.Truncate( s.length() - 1 ); + win->GetTextExtent( s, &w, &h); + } while (((w + ellipsisWidth) > maxWidth) && s.length() ); + s.append( wxT("...") ); + } + } +} diff --git a/clientgui/BOINCTaskCtrl.h b/clientgui/BOINCTaskCtrl.h index fc3b1bee7d..554708eedb 100644 --- a/clientgui/BOINCTaskCtrl.h +++ b/clientgui/BOINCTaskCtrl.h @@ -50,6 +50,8 @@ public: virtual bool OnSaveState( wxConfigBase* pConfig ); virtual bool OnRestoreState( wxConfigBase* pConfig ); + void EllipseStringIfNeeded( wxString& s, wxWindow *win ); + private: CBOINCBaseView* m_pParent; diff --git a/clientgui/stdwx.h b/clientgui/stdwx.h index a1fde13cb5..55a3e16d3e 100644 --- a/clientgui/stdwx.h +++ b/clientgui/stdwx.h @@ -115,7 +115,6 @@ #include #include #include -#include // splitter control support #ifdef _WIN32 // Visual Studio 2005 has extended the C Run-Time Library by including "secure"