save the current status text for each pane inside wxStatusBarPane: native controls now store the (eventually) ellipsized version of the string; remove code for managing the status strings currently inside the [native|generic] control; add ellipsization support under wxMSW; now that all SetFieldsCount() implementation rrely on wxStatusBarBase::SetFieldsCount document how it behaves when adding new panes.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58786 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -36,6 +36,9 @@
|
||||
#include "wx/msw/uxtheme.h"
|
||||
#endif
|
||||
|
||||
// no idea for a default width, just choose something
|
||||
#define DEFAULT_FIELD_WIDTH 25
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -59,6 +62,7 @@ wxStatusBar::wxStatusBar()
|
||||
SetParent(NULL);
|
||||
m_hWnd = 0;
|
||||
m_windowId = 0;
|
||||
m_pDC = NULL;
|
||||
}
|
||||
|
||||
bool wxStatusBar::Create(wxWindow *parent,
|
||||
@@ -131,6 +135,9 @@ bool wxStatusBar::Create(wxWindow *parent,
|
||||
// work correctly, we need to wait until we return to the main loop
|
||||
PostSizeEventToParent();
|
||||
|
||||
// cache the DC instance used by UpdateFieldText
|
||||
m_pDC = new wxClientDC(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,6 +149,15 @@ wxStatusBar::~wxStatusBar()
|
||||
PostSizeEventToParent();
|
||||
}
|
||||
|
||||
bool wxStatusBar::SetFont(const wxFont& font)
|
||||
{
|
||||
if (!wxWindow::SetFont(font))
|
||||
return false;
|
||||
|
||||
m_pDC->SetFont(font);
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxStatusBar::SetFieldsCount(int nFields, const int *widths)
|
||||
{
|
||||
// this is a Windows limitation
|
||||
@@ -198,6 +214,16 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
|
||||
return;
|
||||
}
|
||||
|
||||
wxStatusBarBase::SetStatusText(strText, nField);
|
||||
|
||||
UpdateFieldText(nField);
|
||||
}
|
||||
|
||||
void wxStatusBar::UpdateFieldText(int nField)
|
||||
{
|
||||
if (!m_pDC)
|
||||
return;
|
||||
|
||||
// Get field style, if any
|
||||
int style;
|
||||
switch(m_panes[nField].nStyle)
|
||||
@@ -215,29 +241,30 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
|
||||
break;
|
||||
}
|
||||
|
||||
wxRect rc;
|
||||
GetFieldRect(nField, rc);
|
||||
|
||||
int margin;
|
||||
if (nField == GetFieldsCount()-1)
|
||||
margin = -6; // windows reports a smaller rect for the last field; enlarge it
|
||||
else
|
||||
margin = 4;
|
||||
|
||||
// do we need to ellipsize this string?
|
||||
wxString ellipsizedStr =
|
||||
wxControl::Ellipsize(GetStatusText(nField), *m_pDC,
|
||||
GetLayoutDirection() == wxLayout_RightToLeft ? wxELLIPSIZE_START : wxELLIPSIZE_END,
|
||||
rc.GetWidth() - margin, // leave a small margin
|
||||
wxELLIPSIZE_EXPAND_TAB);
|
||||
|
||||
// Pass both field number and style. MSDN library doesn't mention
|
||||
// that nField and style have to be 'ORed'
|
||||
if ( !StatusBar_SetText(GetHwnd(), nField | style, strText.wx_str()) )
|
||||
if ( !StatusBar_SetText(GetHwnd(), nField | style, ellipsizedStr.wx_str()) )
|
||||
{
|
||||
wxLogLastError(wxT("StatusBar_SetText"));
|
||||
}
|
||||
}
|
||||
|
||||
wxString wxStatusBar::GetStatusText(int nField) const
|
||||
{
|
||||
wxCHECK_MSG( (nField >= 0) && ((size_t)nField < m_panes.GetCount()), wxEmptyString,
|
||||
_T("invalid statusbar field index") );
|
||||
|
||||
wxString str;
|
||||
int len = StatusBar_GetTextLen(GetHwnd(), nField);
|
||||
if ( len > 0 )
|
||||
{
|
||||
StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len));
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int wxStatusBar::GetBorderX() const
|
||||
{
|
||||
int aBorders[3];
|
||||
@@ -295,9 +322,6 @@ bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
|
||||
return true;
|
||||
}
|
||||
|
||||
// no idea for a default width, just choose something
|
||||
#define DEFAULT_FIELD_WIDTH 25
|
||||
|
||||
wxSize wxStatusBar::DoGetBestSize() const
|
||||
{
|
||||
int borders[3];
|
||||
@@ -330,7 +354,6 @@ wxSize wxStatusBar::DoGetBestSize() const
|
||||
width = 2*DEFAULT_FIELD_WIDTH;
|
||||
}
|
||||
|
||||
|
||||
// calculate height
|
||||
int height;
|
||||
wxGetCharSize(GetHWND(), NULL, &height, GetFont());
|
||||
@@ -454,6 +477,14 @@ wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( nMsg == WM_SIZE )
|
||||
{
|
||||
for (int i=0; i<GetFieldsCount(); i++)
|
||||
UpdateFieldText(i);
|
||||
// re-set the field text, in case we need to ellipsize
|
||||
// (or de-ellipsize) some parts of it
|
||||
}
|
||||
|
||||
return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user