Added wxComboCtrl::SetHint(), GetHint()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62989 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-12-26 10:33:35 +00:00
parent 1665389a9a
commit 107defe36a
4 changed files with 68 additions and 1 deletions

View File

@@ -385,6 +385,10 @@ public:
const wxBitmap& GetBitmapHover() const { return m_bmpHover; }
const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
// Hint functions mirrored from TextEntryBase
virtual bool SetHint(const wxString& hint);
virtual wxString GetHint() const;
// Margins functions mirrored from TextEntryBase
// (wxComboCtrl does not inherit from wxTextEntry, but may embed a
// wxTextCtrl, so we need these). Also note that these functions
@@ -427,6 +431,16 @@ public:
protected:
// Returns true if hint text should be drawn in the control
bool ShouldUseHintText(int flags = 0) const
{
return ( !m_text &&
!(flags & wxCONTROL_ISSUBMENU) &&
!m_valueString.length() &&
m_hintText.length() &&
!ShouldDrawFocus() );
}
//
// Override these for customization purposes
//
@@ -544,6 +558,9 @@ protected:
// This is used when m_text is hidden (readonly).
wxString m_valueString;
// This is used when control is unfocused and m_valueString is empty
wxString m_hintText;
// the text control and button we show all the time
wxTextCtrl* m_text;
wxWindow* m_btn;

View File

@@ -448,6 +448,15 @@ public:
*/
static int GetFeatures();
/**
Returns the current hint string.
See SetHint() for more information about hints.
@since 2.9.1
*/
virtual wxString GetHint() const;
/**
Returns the insertion point for the combo control's text field.
@@ -620,6 +629,18 @@ public:
*/
void SetCustomPaintWidth(int width);
/**
Sets a hint shown in an empty unfocused combo control.
Notice that hints are known as <em>cue banners</em> under MSW or
<em>placeholder strings</em> under OS X.
@see wxTextEntry::SetHint()
@since 2.9.1
*/
virtual void SetHint(const wxString& hint);
/**
Sets the insertion point in the text field.

View File

@@ -904,6 +904,7 @@ wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
m_text->Create(this, wxID_ANY, m_valueString,
wxDefaultPosition, wxSize(10,-1),
style, validator);
m_text->SetHint(m_hintText);
}
}
@@ -2539,4 +2540,19 @@ void wxComboCtrlBase::Undo()
m_text->Undo();
}
bool wxComboCtrlBase::SetHint(const wxString& hint)
{
m_hintText = hint;
bool res = true;
if ( m_text )
res = m_text->SetHint(hint);
Refresh();
return res;
}
wxString wxComboCtrlBase::GetHint() const
{
return m_hintText;
}
#endif // wxUSE_COMBOCTRL

View File

@@ -1089,7 +1089,20 @@ void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc,
{
if ( flags & wxODCB_PAINTING_CONTROL )
{
dc.DrawText( GetValue(),
wxString text;
if ( !ShouldUseHintText() )
{
text = GetValue();
}
else
{
text = GetHint();
wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
dc.SetTextForeground(col);
}
dc.DrawText( text,
rect.x + GetMargins().x,
(rect.height-dc.GetCharHeight())/2 + rect.y );
}