X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/38ddd614f2329793d7b5a75c4c2fa1e3b5f0fb76..092162bc12858d6912ea6d5371d271ceebd18c49:/src/common/ctrlcmn.cpp diff --git a/src/common/ctrlcmn.cpp b/src/common/ctrlcmn.cpp old mode 100755 new mode 100644 index ce76a88625..32bce06c6f --- a/src/common/ctrlcmn.cpp +++ b/src/common/ctrlcmn.cpp @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 26.07.99 -// RCS-ID: $Id$ // Copyright: (c) wxWidgets team // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -38,6 +37,8 @@ #include "wx/settings.h" #endif +#include "wx/private/markupparser.h" + const char wxControlNameStr[] = "control"; // ============================================================================ @@ -147,6 +148,12 @@ void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event) #endif // wxUSE_RADIOBTN } +wxSize wxControlBase::DoGetSizeFromTextSize(int WXUNUSED(xlen), + int WXUNUSED(ylen)) const +{ + return wxSize(-1, -1); +} + /* static */ wxString wxControlBase::GetLabelText(const wxString& label) { @@ -230,6 +237,31 @@ wxControlBase::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(va return attrs; } +// ---------------------------------------------------------------------------- +// wxControl markup support +// ---------------------------------------------------------------------------- + +#if wxUSE_MARKUP + +/* static */ +wxString wxControlBase::RemoveMarkup(const wxString& markup) +{ + return wxMarkupParser::Strip(markup); +} + +bool wxControlBase::DoSetLabelMarkup(const wxString& markup) +{ + const wxString label = RemoveMarkup(markup); + if ( label.empty() && !markup.empty() ) + return false; + + SetLabel(label); + + return true; +} + +#endif // wxUSE_MARKUP + // ---------------------------------------------------------------------------- // wxControlBase - ellipsization code // ---------------------------------------------------------------------------- @@ -402,6 +434,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD calc.Init(0, 1); while ( !calc.IsShortEnough() ) calc.RemoveFromEnd(); + + // always show at least one character of the string: + if ( calc.m_nCharsToRemove == len ) + return wxString(wxELLIPSE_REPLACEMENT) + curLine[len-1]; + break; } @@ -444,6 +481,15 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD else calc.RemoveFromEnd(); } + + // Always show at least one character of the string. + // Additionally, if there's only one character left, prefer + // "a..." to "...a": + if ( calc.m_nCharsToRemove == len || + calc.m_nCharsToRemove == len - 1 ) + { + return curLine[0] + wxString(wxELLIPSE_REPLACEMENT); + } } break; @@ -452,6 +498,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD calc.Init(len - 1, 1); while ( !calc.IsShortEnough() ) calc.RemoveFromStart(); + + // always show at least one character of the string: + if ( calc.m_nCharsToRemove == len ) + return curLine[0] + wxString(wxELLIPSE_REPLACEMENT); + break; } @@ -488,15 +539,10 @@ wxString wxControlBase::Ellipsize(const wxString& label, const wxDC& dc, // add this (ellipsized) row to the rest of the label ret << curLine; if ( pc == label.end() ) - { - // NOTE: this is the return which always exits the function - return ret; - } - else - { - ret << *pc; - curLine.clear(); - } + break; + + ret << *pc; + curLine.clear(); } // we need to remove mnemonics from the label for correct calculations else if ( *pc == wxS('&') && (flags & wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS) ) @@ -519,14 +565,9 @@ wxString wxControlBase::Ellipsize(const wxString& label, const wxDC& dc, } } - // this return would generate a - // warning C4702: unreachable code - // with MSVC since the function always exits from inside the loop - //return ret; + return ret; } - - // ---------------------------------------------------------------------------- // wxStaticBitmap // ---------------------------------------------------------------------------- @@ -542,7 +583,7 @@ wxSize wxStaticBitmapBase::DoGetBestSize() const { wxSize best; wxBitmap bmp = GetBitmap(); - if ( bmp.Ok() ) + if ( bmp.IsOk() ) best = wxSize(bmp.GetWidth(), bmp.GetHeight()); else // this is completely arbitrary