added support for ellipsization and markup in wxStaticText (modified patch 1629946)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -46,11 +46,36 @@ public:
|
||||
// get the control alignment (left/right/centre, top/bottom/centre)
|
||||
int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
|
||||
|
||||
// get just the text of the label, without mnemonic characters ('&')
|
||||
wxString GetLabelText() const { return GetLabelText(GetLabel()); }
|
||||
|
||||
virtual void SetLabel(const wxString& label)
|
||||
{
|
||||
m_labelOrig = label;
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
wxWindow::SetLabel(label);
|
||||
}
|
||||
|
||||
virtual wxString GetLabel() const
|
||||
{
|
||||
// return the original string, as it was passed to SetLabel()
|
||||
// (i.e. with wx-style mnemonics)
|
||||
return m_labelOrig;
|
||||
}
|
||||
|
||||
// static utilities:
|
||||
|
||||
// get the string without mnemonic characters ('&')
|
||||
static wxString GetLabelText(const wxString& label);
|
||||
|
||||
// get just the text of the label, without mnemonic characters ('&')
|
||||
wxString GetLabelText() const { return GetLabelText(GetLabel()); }
|
||||
// removes the mnemonics characters
|
||||
static wxString RemoveMnemonics(const wxString& str);
|
||||
|
||||
// escapes the mnemonics characters ('&') by doubling them
|
||||
static wxString EscapeMnemonics(const wxString& str);
|
||||
|
||||
|
||||
// controls by default inherit the colours of their parents, if a
|
||||
// particular control class doesn't want to do it, it can override
|
||||
@@ -64,7 +89,6 @@ public:
|
||||
// if the button was clicked)
|
||||
virtual void Command(wxCommandEvent &event);
|
||||
|
||||
virtual void SetLabel( const wxString &label );
|
||||
virtual bool SetFont(const wxFont& font);
|
||||
|
||||
// wxControl-specific processing after processing the update event
|
||||
@@ -84,6 +108,9 @@ protected:
|
||||
// initialize the common fields of wxCommandEvent
|
||||
void InitCommandEvent(wxCommandEvent& event) const;
|
||||
|
||||
// this field contains the label in wx format, i.e. with '&' mnemonics
|
||||
wxString m_labelOrig;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxControlBase)
|
||||
};
|
||||
|
||||
|
||||
@@ -1603,13 +1603,6 @@ enum wxBorder
|
||||
*/
|
||||
#define wxST_SIZEGRIP 0x0010
|
||||
|
||||
/*
|
||||
* wxStaticText flags
|
||||
*/
|
||||
#define wxST_NO_AUTORESIZE 0x0001
|
||||
#define wxST_DOTS_MIDDLE 0x0002
|
||||
#define wxST_DOTS_END 0x0004
|
||||
|
||||
/*
|
||||
* wxStaticBitmap flags
|
||||
*/
|
||||
|
||||
@@ -43,8 +43,6 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxControlNameStr);
|
||||
|
||||
virtual void SetLabel( const wxString &label );
|
||||
virtual wxString GetLabel() const;
|
||||
|
||||
virtual wxVisualAttributes GetDefaultAttributes() const;
|
||||
|
||||
@@ -56,6 +54,7 @@ protected:
|
||||
|
||||
// sets the label to the given string and also sets it for the given widget
|
||||
void GTKSetLabelForLabel(GtkLabel *w, const wxString& label);
|
||||
void GTKSetLabelWithMarkupForLabel(GtkLabel *w, const wxString& label);
|
||||
|
||||
// GtkFrame helpers
|
||||
GtkWidget* GTKCreateFrame(const wxString& label);
|
||||
@@ -67,11 +66,11 @@ protected:
|
||||
static wxString GTKRemoveMnemonics(const wxString& label);
|
||||
|
||||
// converts wx label to GTK+ label, i.e. basically replace "&"s with "_"s
|
||||
//
|
||||
// for GTK+ 1 (which doesn't support mnemonics) this is the same as
|
||||
// GTKRemoveMnemonics()
|
||||
static wxString GTKConvertMnemonics(const wxString &label);
|
||||
|
||||
// converts wx label to GTK+ labels preserving Pango markup
|
||||
static wxString GTKConvertMnemonicsWithMarkup(const wxString& label);
|
||||
|
||||
// These are used by GetDefaultAttributes
|
||||
static wxVisualAttributes
|
||||
GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
@@ -95,9 +94,6 @@ protected:
|
||||
// override this and return true.
|
||||
virtual bool UseGTKStyleBase() const { return false; }
|
||||
|
||||
// this field contains the label in wx format, i.e. with "&" mnemonics
|
||||
wxString m_label;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxControl)
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// wxStaticText
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_CORE wxStaticText : public wxControl
|
||||
class WXDLLIMPEXP_CORE wxStaticText : public wxStaticTextBase
|
||||
{
|
||||
public:
|
||||
wxStaticText();
|
||||
@@ -43,8 +43,7 @@ public:
|
||||
static wxVisualAttributes
|
||||
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
|
||||
|
||||
// see wx/stattext.h
|
||||
void Wrap(int width);
|
||||
|
||||
|
||||
// implementation
|
||||
// --------------
|
||||
@@ -59,6 +58,9 @@ protected:
|
||||
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
virtual wxString DoGetLabel() const;
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxStaticText)
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
|
||||
protected :
|
||||
|
||||
virtual wxString DoGetLabel() const;
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
|
||||
virtual wxSize DoGetBestSize() const ;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxStaticText)
|
||||
|
||||
@@ -52,6 +52,9 @@ public:
|
||||
virtual WXWidget GetLabelWidget() const
|
||||
{ return m_labelWidget; }
|
||||
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
virtual wxString DoGetLabel() const;
|
||||
|
||||
protected:
|
||||
WXWidget m_labelWidget;
|
||||
};
|
||||
|
||||
@@ -49,6 +49,9 @@ protected:
|
||||
int sizeFlags = wxSIZE_AUTO);
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
virtual wxString DoGetLabel() const;
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxStaticText)
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,9 @@ protected:
|
||||
);
|
||||
virtual wxSize DoGetBestSize(void) const;
|
||||
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
virtual wxString DoGetLabel() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxStaticText)
|
||||
}; // end of CLASS wxStaticText
|
||||
|
||||
95
include/wx/private/stattext.h
Normal file
95
include/wx/private/stattext.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: include/wx/private/stattext.h
|
||||
// Purpose: Internal declarations for dlgcmn.cpp and stattextcmn.cpp
|
||||
// Author: Francesco Montorsi
|
||||
// Created: 2007-01-07 (extracted from dlgcmn.cpp)
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 Vadim Zeitlin
|
||||
// (c) 2007 wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_STATTEXT_H_
|
||||
#define _WX_PRIVATE_STATTEXT_H_
|
||||
|
||||
#if wxUSE_STATTEXT
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTextWrapper
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// this class is used to wrap the text on word boundary: wrapping is done by
|
||||
// calling OnStartLine() and OnOutputLine() functions
|
||||
class wxTextWrapper
|
||||
{
|
||||
public:
|
||||
wxTextWrapper() { m_eol = false; }
|
||||
|
||||
// win is used for getting the font, text is the text to wrap, width is the
|
||||
// max line width or -1 to disable wrapping
|
||||
void Wrap(wxWindow *win, const wxString& text, int widthMax);
|
||||
|
||||
// we don't need it, but just to avoid compiler warnings
|
||||
virtual ~wxTextWrapper() { }
|
||||
|
||||
protected:
|
||||
// line may be empty
|
||||
virtual void OnOutputLine(const wxString& line) = 0;
|
||||
|
||||
// called at the start of every new line (except the very first one)
|
||||
virtual void OnNewLine() { }
|
||||
|
||||
private:
|
||||
// call OnOutputLine() and set m_eol to true
|
||||
void DoOutputLine(const wxString& line)
|
||||
{
|
||||
OnOutputLine(line);
|
||||
|
||||
m_eol = true;
|
||||
}
|
||||
|
||||
// this function is a destructive inspector: when it returns true it also
|
||||
// resets the flag to false so calling it again woulnd't return true any
|
||||
// more
|
||||
bool IsStartOfNewLine()
|
||||
{
|
||||
if ( !m_eol )
|
||||
return false;
|
||||
|
||||
m_eol = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool m_eol;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
wxMARKUP_ENTITY_AMP,
|
||||
wxMARKUP_ENTITY_LT,
|
||||
wxMARKUP_ENTITY_GT,
|
||||
wxMARKUP_ENTITY_APOS,
|
||||
wxMARKUP_ENTITY_QUOT,
|
||||
wxMARKUP_ENTITY_MAX
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
wxMARKUP_ELEMENT_NAME,
|
||||
wxMARKUP_ELEMENT_VALUE,
|
||||
wxMARKUP_ELEMENT_MAX
|
||||
};
|
||||
|
||||
// these are the only entities treated in a special way by wxStaticText::SetLabel()
|
||||
// when the wxST_MARKUP style is used; use as:
|
||||
//
|
||||
// wxMarkupEntities[wxMARKUP_ELEMENT_NAME][wxMARKUP_ENTITY_GT] == ">"
|
||||
// wxMarkupEntities[wxMARKUP_ELEMENT_VALUE][wxMARKUP_ENTITY_GT] == ">"
|
||||
//
|
||||
extern const wxChar *wxMarkupEntities[wxMARKUP_ELEMENT_MAX][wxMARKUP_ENTITY_MAX];
|
||||
|
||||
#endif // wxUSE_STATTEXT
|
||||
|
||||
#endif // _WX_PRIVATE_STATTEXT_H_
|
||||
@@ -18,6 +18,17 @@
|
||||
|
||||
#include "wx/control.h"
|
||||
|
||||
/*
|
||||
* wxStaticText flags
|
||||
*/
|
||||
#define wxST_NO_AUTORESIZE 0x0001
|
||||
#define wxST_MARKUP 0x0002
|
||||
|
||||
#define wxST_ELLIPSIZE_START 0x0004
|
||||
#define wxST_ELLIPSIZE_MIDDLE 0x0008
|
||||
#define wxST_ELLIPSIZE_END 0x0010
|
||||
|
||||
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticTextNameStr[];
|
||||
|
||||
class WXDLLEXPORT wxStaticTextBase : public wxControl
|
||||
@@ -25,20 +36,60 @@ class WXDLLEXPORT wxStaticTextBase : public wxControl
|
||||
public:
|
||||
wxStaticTextBase() { }
|
||||
|
||||
// in wxGTK wxStaticText doesn't derive from wxStaticTextBase so we have to
|
||||
// declare this function directly in gtk header
|
||||
#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
|
||||
// wrap the text of the control so that no line is longer than the given
|
||||
// width (if possible: this function won't break words)
|
||||
//
|
||||
// NB: implemented in dlgcmn.cpp for now
|
||||
// This function will modify the value returned by GetLabel()!
|
||||
void Wrap(int width);
|
||||
#endif // ! native __WXGTK__
|
||||
|
||||
// overriden base virtuals
|
||||
virtual bool AcceptsFocus() const { return false; }
|
||||
virtual bool HasTransparentBackground() { return true; }
|
||||
|
||||
bool IsEllipsized() const
|
||||
{
|
||||
return HasFlag(wxST_ELLIPSIZE_START) ||
|
||||
HasFlag(wxST_ELLIPSIZE_MIDDLE) ||
|
||||
HasFlag(wxST_ELLIPSIZE_END);
|
||||
}
|
||||
|
||||
// get the string without mnemonic characters ('&') and without markup
|
||||
// (if wxST_MARKUP is being used)
|
||||
virtual wxString GetLabelText() const;
|
||||
|
||||
// public utilities (symmetric to those in wxControl about mnemonics):
|
||||
|
||||
// removes the markup accepted by wxStaticText when wxST_MARKUP is used,
|
||||
// and then returns the cleaned string
|
||||
static wxString RemoveMarkup(const wxString& str);
|
||||
|
||||
// escapes the alls special symbols (<>"'&) present inside the given string
|
||||
// using the corresponding entities (< > " ' &)
|
||||
static wxString EscapeMarkup(const wxString& str);
|
||||
|
||||
|
||||
protected: // functions required for wxST_ELLIPSIZE_* support
|
||||
|
||||
// just calls RemoveMarkup & Ellipsize on the original label.
|
||||
virtual wxString GetEllipsizedLabelWithoutMarkup() const;
|
||||
|
||||
// replaces parts of the string with ellipsis if needed
|
||||
wxString Ellipsize(const wxString& label) const;
|
||||
|
||||
// to be called when updating the size of the static text:
|
||||
// updates the label redoing ellipsization calculations
|
||||
void UpdateLabel();
|
||||
|
||||
// These functions are platform-specific and must be overridden in ports
|
||||
// which do not natively support ellipsization and they must be implemented
|
||||
// in a way so that the m_label member of wxControl is not touched:
|
||||
|
||||
// returns the real label currently displayed inside the control.
|
||||
virtual wxString DoGetLabel() const { return wxEmptyString; }
|
||||
|
||||
// sets the real label currently displayed inside the control,
|
||||
// _without_ invalidating the size. The text passed is always markup-free.
|
||||
virtual void DoSetLabel(const wxString& WXUNUSED(str)) { }
|
||||
|
||||
private:
|
||||
DECLARE_NO_COPY_CLASS(wxStaticTextBase)
|
||||
};
|
||||
|
||||
@@ -64,13 +64,15 @@ public:
|
||||
|
||||
// this function will filter out '&' characters and will put the
|
||||
// accelerator char (the one immediately after '&') into m_chAccel
|
||||
virtual void SetLabel(const wxString &label);
|
||||
virtual wxString GetLabel() const;
|
||||
virtual void SetLabel(const wxString& label);
|
||||
|
||||
// return the current label
|
||||
virtual wxString GetLabel() const { return m_label; }
|
||||
|
||||
// wxUniversal-specific methods
|
||||
|
||||
// return the accel index in the string or -1 if none and puts the modified
|
||||
// string intosecond parameter if non NULL
|
||||
// string into second parameter if non NULL
|
||||
static int FindAccelIndex(const wxString& label,
|
||||
wxString *labelOnly = NULL);
|
||||
|
||||
@@ -89,6 +91,11 @@ protected:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
// set m_label and m_indexAccel and refresh the control to show the new
|
||||
// label (but, unlike SetLabel(), don't call the base class SetLabel() thus
|
||||
// avoiding to change wxControlBase::m_labelOrig)
|
||||
void UnivDoSetLabel(const wxString& label);
|
||||
|
||||
private:
|
||||
// label and accel info
|
||||
wxString m_label;
|
||||
|
||||
@@ -60,6 +60,9 @@ protected:
|
||||
// draw the control
|
||||
virtual void DoDraw(wxControlRenderer *renderer);
|
||||
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
virtual wxString DoGetLabel() const;
|
||||
|
||||
DECLARE_ABSTRACT_CLASS(wxStaticText)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user