]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxComboCtrl::SetHint(), GetHint()
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 26 Dec 2009 10:33:35 +0000 (10:33 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 26 Dec 2009 10:33:35 +0000 (10:33 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62989 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/combo.h
interface/wx/combo.h
src/common/combocmn.cpp
src/generic/odcombo.cpp

index 718adde3552bcbdf6d491dc90cce1f475ee835b8..2cdb81102aa9e48283bc88f147c0a9f969ea2bff 100644 (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;
index fc30d8c4c938a9df87455e60dc8deb28c57f980f..4a67cd784da88ce310e0ed5e6a286aa9c5b156c1 100644 (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.
 
index 10f41f8473843931fb28a9854393230f6bbf8a44..b45e28a2c69f6668c9f6fdd987a5f6a83a57ff69 100644 (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
index 83dc7cbb95bcbacbd954b03fd78209f31947b59a..e70047106d4b1c3202694400792f333de3ffb591 100644 (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 );
     }