]> git.saurik.com Git - wxWidgets.git/commitdiff
Added support for 'AutoComplete' attribute, automatically used by any wxTextCtrl...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 8 Mar 2009 11:34:01 +0000 (11:34 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 8 Mar 2009 11:34:01 +0000 (11:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59429 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/property.h
interface/wx/propgrid/property.h
samples/propgrid/propgrid.cpp
src/propgrid/editors.cpp

index 94733f21e22cb94b9da1ce341d968da1493b1ca1..f934e1b319616beac537f874b2e0d734e8a38eb1 100644 (file)
@@ -515,6 +515,11 @@ wxPG_PROP_CLASS_SPECIFIC_2          = 0x00100000
 */
 #define wxPG_ATTR_INLINE_HELP               wxS("InlineHelp")
 
+/** Universal, wxArrayString. Set to enable auto-completion in any
+    wxTextCtrl-based property editor.
+*/
+#define wxPG_ATTR_AUTOCOMPLETE              wxS("AutoComplete")
+
 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
     use checkbox instead of choice.
 */
index d8197e0abd141b00a60c469a5d2b09b43c337e14..087010636b176cd0adf91e7e4fd138d109a08e49 100644 (file)
 */
 #define wxPG_ATTR_INLINE_HELP               wxS("InlineHelp")
 
+/** Universal, wxArrayString. Set to enable auto-completion in any
+    wxTextCtrl-based property editor.
+*/
+#define wxPG_ATTR_AUTOCOMPLETE              wxS("AutoComplete")
+
 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
     use checkbox instead of choice.
 */
 
     Simple string property. wxPG_STRING_PASSWORD attribute may be used
     to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
+    wxPG_ATTR_AUTOCOMPLETE attribute may be used to enable auto-completion
+    (use a wxArrayString value), and is also supported by any property that
+    happens to use a wxTextCtrl-based editor.
 
     @remarks wxStringProperty has a special trait: if it has value of
             "<composed>", and also has child properties, then its displayed
index 6a37ae4d25334c65de9fa167d1f7307508a4750c..56abbad6d29b28cc8038b8e0a8a9ee29f6030b69 100644 (file)
@@ -1531,6 +1531,25 @@ void FormMain::PopulateWithExamples ()
     // Set value after limiting so that it will be applied
     pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
 
+    //
+    // Demonstrate "AutoComplete" attribute
+    pg->Append( new wxStringProperty( "StringProperty AutoComplete",
+                                      wxPG_LABEL ) );
+
+    wxArrayString autoCompleteStrings;
+    autoCompleteStrings.Add("One choice");
+    autoCompleteStrings.Add("Another choice");
+    autoCompleteStrings.Add("Another choice, yeah");
+    autoCompleteStrings.Add("Yet another choice");
+    autoCompleteStrings.Add("Yet another choice, bear with me");
+    pg->SetPropertyAttribute( "StringProperty AutoComplete",
+                              "AutoComplete",
+                              autoCompleteStrings );
+
+    pg->SetPropertyHelpString( "StringProperty AutoComplete",
+        "AutoComplete attribute has been set for this property "
+        "(try writing something beginning with 'a', 'o' or 'y').");
+
     // Add string property with arbitrarily wide bitmap in front of it. We
     // intentionally lower-than-typical row height here so that the ugly
     // scaling code wont't be run.
index 07df5fb839ee951e1d92240da0024c74dd0fa41d..2080439da9b64d36fac9dcbf7b3748e33e6dc9b9 100644 (file)
@@ -1633,12 +1633,12 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
                                                   int maxLen )
 {
     wxWindowID id = wxPG_SUBID1;
-    wxPGProperty* selected = m_selected;
-    wxASSERT(selected);
+    wxPGProperty* prop = m_selected;
+    wxASSERT(prop);
 
     int tcFlags = wxTE_PROCESS_ENTER | extraStyle;
 
-    if ( selected->HasFlag(wxPG_PROP_READONLY) )
+    if ( prop->HasFlag(wxPG_PROP_READONLY) )
         tcFlags |= wxTE_READONLY;
 
     wxPoint p(pos.x,pos.y);
@@ -1675,14 +1675,12 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
     SetupTextCtrlValue(value);
     tc->Create(ctrlParent,id,value, p, s,tcFlags);
     
-    wxWindow* ed = tc;
-
     // Center the control vertically
     if ( !hasSpecialSize )
-        FixPosForTextCtrl(ed);
+        FixPosForTextCtrl(tc);
 
 #ifdef __WXMSW__
-    ed->Show();
+    tc->Show();
     if ( secondary )
         secondary->Show();
 #endif
@@ -1691,7 +1689,14 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
     if ( maxLen > 0 )
         tc->SetMaxLength( maxLen );
 
-    return (wxWindow*) ed;
+    wxVariant attrVal = prop->GetAttribute(wxPG_ATTR_AUTOCOMPLETE);
+    if ( !attrVal.IsNull() )
+    {
+        wxASSERT(attrVal.GetType() == wxS("arrstring"));
+        tc->AutoComplete(attrVal.GetArrayString());
+    }
+
+    return tc;
 }
 
 // -----------------------------------------------------------------------