]> git.saurik.com Git - wxWidgets.git/commitdiff
added enabled and hidden attributes to radio box items in XRC
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 2 Aug 2008 18:21:38 +0000 (18:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 2 Aug 2008 18:21:38 +0000 (18:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/tech/tn0014.txt
include/wx/xrc/xh_radbx.h
include/wx/xrc/xmlres.h
samples/xrc/rc/controls.xrc
src/common/filename.cpp
src/xrc/xh_radbx.cpp
src/xrc/xmlres.cpp

index 41c0899b87ecaba6a87ae2a72c924851f2157eb7..13f9c16e4bb9357a43776bac0916b9b414dd888f 100644 (file)
@@ -377,6 +377,7 @@ All (GUI):
 - Added wxVListBox::GetItemRect() (Javier Urien).
 - Show busy cursor in wxLaunchDefaultBrowser and add wxBROWSER_NOBUSYCURSOR.
 - Added wxFlexGridSizer::Is{Row,Col}Growable() (Marcin Wojdyr).
+- Added "enabled" and "hidden" attributes to radio box items in XRC.
 
 wxGTK:
 
index 75b492fda06ba293d936f84510b6954f60b2fa7b..136a8c043d36faf1e94d6a69f812c111abbcec3d 100644 (file)
@@ -421,10 +421,13 @@ wxRadioBox
 ----------
 
 This control may have "dimension" (major dimension) and (initial) "selection"
-Integer subelements and a composite "content" element similar to wxCheckList.
-The only difference is that the "item" subelements can have an optional
-"tooltip=I18nString" and "helptext=I18nString" attributes to specify
-the per-item tooltip and helptext.
+Integer subelements and a composite "content" element similar to wxCheckList
+except that <item> subelements can have additional attributes:
+
+tooltip                    I18nString              ""
+helptext                   I18nString              ""
+enabled                    Boolean                 1
+hidden                     Boolean                 0
 
 
 wxScrolledWindow
index 94ee62498df6568a76dd0ef7e96fdbe8ae52456e..53638089f4b6e7bf2e3536e4124b1a0dc7cd973a 100644 (file)
@@ -28,14 +28,21 @@ private:
     bool m_insideBox;
 
     // the items labels
-    wxArrayString labels;
+    wxArrayString m_labels;
 
+#if wxUSE_TOOLTIPS
     // the items tooltips
-    wxArrayString tooltips;
+    wxArrayString m_tooltips;
+#endif // wxUSE_TOOLTIPS
 
     // the item help text
-    wxArrayString helptexts;
-    wxArrayInt    helptextSpecified;
+    wxArrayString m_helptexts;
+    wxArrayInt    m_helptextSpecified;
+
+    // if the corresponding array element is 1, the radiobox item is
+    // disabled/hidden
+    wxArrayInt m_isEnabled,
+               m_isShown;
 };
 
 #endif // wxUSE_XRC && wxUSE_RADIOBOX
index 9321e4c186d8af4590d8001b58ed246c191cb21b..2f941d9f00f77557e527647ad2a467b6b51745d0 100644 (file)
@@ -462,6 +462,10 @@ protected:
     // Gets a font.
     wxFont GetFont(const wxString& param = wxT("font"));
 
+    // Gets the value of a boolean attribute (only "0" and "1" are valid values)
+    bool GetBoolAttr(const wxString& attr, bool defaultv);
+
+
     // Sets common window options.
     void SetupWindow(wxWindow *wnd);
 
index d9cf1813b8e1f2104acdbdccafae49ff65dbe268..909bbef43333e598b6827949eea17ce1b3ba8767 100644 (file)
                                     <selection>0</selection>
                                     <content>
                                         <item tooltip="Powerful radio station" helptext="This station is for amateurs of hard rock and heavy metal">Power 108</item>
+                                        <item tooltip="Disabled radio station" enabled="0">Power 0</item>
                                         <item tooltip="">WMMS 100.7</item>
                                         <item tooltip="E=mc^2">Energy 98.3</item>
                                         <item helptext="Favourite chukcha's radio">CHUM FM</item>
                                         <item>92FM</item>
+                                        <item hidden="1">Very quite station</item>
                                     </content>
                                 </object>
                             </object>
index ee7e4d412adb2b587294f5717fabc377d6ed1d6d..1e3444bc87a029c34158026a7e6be46f01c1cc19 100644 (file)
@@ -1026,55 +1026,55 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFFile *fileTemp)
 // directory operations
 // ----------------------------------------------------------------------------
 
-wxString wxFileName::GetTempDir()
+// helper of GetTempDir(): check if the given directory exists and return it if
+// it does or an empty string otherwise
+namespace
 {
-    wxString dir;
-    dir = wxGetenv(_T("TMPDIR"));
-    if (dir.empty())
-    {
-        dir = wxGetenv(_T("TMP"));
-        if (dir.empty())
-        {
-            dir = wxGetenv(_T("TEMP"));
-        }
-    }
 
-#if defined(__WXWINCE__)
-    if (dir.empty())
+wxString CheckIfDirExists(const wxString& dir)
+{
+    return wxFileName::DirExists(dir) ? dir : wxString();
+}
+
+} // anonymous namespace
+
+wxString wxFileName::GetTempDir()
+{
+    // first try getting it from environment: this allows overriding the values
+    // used by default if the user wants to create temporary files in another
+    // directory
+    wxString dir = CheckIfDirExists(wxGetenv("TMPDIR"));
+    if ( dir.empty() )
     {
-        // FIXME. Create \temp dir?
-        if (DirExists(wxT("\\temp")))
-            dir = wxT("\\temp");
+        dir = CheckIfDirExists(wxGetenv("TMP"));
+        if ( dir.empty() )
+            dir = CheckIfDirExists(wxGetenv("TEMP"));
     }
-#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
 
+    // if no environment variables are set, use the system default
     if ( dir.empty() )
     {
+#if defined(__WXWINCE__)
+        dir = CheckIfDirExists(wxT("\\temp"));
+#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
         if ( !::GetTempPath(MAX_PATH, wxStringBuffer(dir, MAX_PATH + 1)) )
         {
             wxLogLastError(_T("GetTempPath"));
         }
-
-        if ( dir.empty() )
-        {
-            // GetTempFileName() fails if we pass it an empty string
-            dir = _T('.');
-        }
+#elif defined(__WXMAC__) && wxOSX_USE_CARBON
+        dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder);
+#endif // systems with native way
     }
-#else // !Windows
 
+    // fall back to hard coded value
     if ( dir.empty() )
     {
-        // default
-#if defined(__DOS__) || defined(__OS2__)
-        dir = _T(".");
-#elif defined(__WXMAC__) && wxOSX_USE_CARBON
-        dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder);
-#else
-        dir = _T("/tmp");
-#endif
+#ifdef __UNIX_LIKE__
+        dir = CheckIfDirExists("/tmp");
+        if ( dir.empty() )
+#endif // __UNIX_LIKE__
+            dir = ".";
     }
-#endif
 
     return dir;
 }
index dbbf54b5e450b55e82489f4f3bb01d3f605030f0..c6ee9307a685b10ea9ce1342a4a56580dce7febc 100644 (file)
@@ -47,66 +47,66 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
         m_insideBox = true;
         CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
 
-        wxString *strings;
-        if ( !labels.empty() )
-        {
-            strings = new wxString[labels.size()];
-            const unsigned count = labels.size();
-            for( unsigned i = 0; i < count; i++ )
-                strings[i] = labels[i];
-        }
-        else
-        {
-            strings = NULL;
-        }
-
         XRC_MAKE_INSTANCE(control, wxRadioBox)
 
         control->Create(m_parentAsWindow,
                         GetID(),
                         GetText(wxT("label")),
                         GetPosition(), GetSize(),
-                        labels.size(),
-                        strings,
+                        m_labels,
                         GetLong(wxT("dimension"), 1),
                         GetStyle(),
                         wxDefaultValidator,
                         GetName());
 
-        delete[] strings;
-
         if (selection != -1)
             control->SetSelection(selection);
 
         SetupWindow(control);
 
-        const unsigned count = labels.size();
+        const unsigned count = m_labels.size();
         for( unsigned i = 0; i < count; i++ )
         {
 #if wxUSE_TOOLTIPS
-            if ( !tooltips[i].empty() )
-                control->SetItemToolTip(i, tooltips[i]);
+            if ( !m_tooltips[i].empty() )
+                control->SetItemToolTip(i, m_tooltips[i]);
 #endif // wxUSE_TOOLTIPS
 #if wxUSE_HELP
-            if ( helptextSpecified[i] )
-                control->SetItemHelpText(i, helptexts[i]);
+            if ( m_helptextSpecified[i] )
+                control->SetItemHelpText(i, m_helptexts[i]);
 #endif // wxUSE_HELP
+
+            if ( !m_isShown[i] )
+                control->Show(i, false);
+            if ( !m_isEnabled[i] )
+                control->Enable(i, false);
         }
 
-        labels.clear();    // dump the strings
 
-        tooltips.clear();    // dump the tooltips
+        // forget information about the items of this radiobox, we should start
+        // afresh for the next one
+        m_labels.clear();
 
-        helptexts.clear();   // dump the helptexts
-        helptextSpecified.clear();
+#if wxUSE_TOOLTIPS
+        m_tooltips.clear();
+#endif // wxUSE_TOOLTIPS
+
+#if wxUSE_HELP
+        m_helptexts.clear();
+        m_helptextSpecified.clear();
+#endif // wxUSE_HELP
+
+        m_isShown.clear();
+        m_isEnabled.clear();
 
         return control;
     }
     else // inside the radiobox element
     {
-        // we handle handle <item tooltip="..." helptext="...">Label</item> constructs here
+        // we handle handle <item>Label</item> constructs here, and the item
+        // tag can have tooltip, helptext, enabled and hidden attributes
 
-        wxString str = GetNodeContent(m_node);
+        wxString label = GetNodeContent(m_node);
 
         wxString tooltip;
         m_node->GetAttribute(wxT("tooltip"), &tooltip);
@@ -116,17 +116,23 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
 
         if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
         {
-            str = wxGetTranslation(str, m_resource->GetDomain());
+            label = wxGetTranslation(label, m_resource->GetDomain());
             if ( !tooltip.empty() )
                 tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
             if ( hasHelptext )
                 helptext = wxGetTranslation(helptext, m_resource->GetDomain());
         }
 
-        labels.push_back(str);
-        tooltips.push_back(tooltip);
-        helptexts.push_back(helptext);
-        helptextSpecified.push_back(hasHelptext);
+        m_labels.push_back(label);
+#if wxUSE_TOOLTIPS
+        m_tooltips.push_back(tooltip);
+#endif // wxUSE_TOOLTIPS
+#if wxUSE_HELP
+        m_helptexts.push_back(helptext);
+        m_helptextSpecified.push_back(hasHelptext);
+#endif // wxUSE_HELP
+        m_isEnabled.push_back(GetBoolAttr("enabled", 1));
+        m_isShown.push_back(!GetBoolAttr("hidden", 0));
 
         return NULL;
     }
index dd6447b9fabe16a56bdeb84f1e9ffacec27ce854..3a6cbefc6bf3d4b5e31e428c9a3a51d7e9675076 100644 (file)
@@ -1031,13 +1031,17 @@ wxString wxXmlResourceHandler::GetName()
 
 
 
+bool wxXmlResourceHandler::GetBoolAttr(const wxString& attr, bool defaultv)
+{
+    wxString v;
+    return m_node->GetAttribute(attr, &v) ? v == '1' : defaultv;
+}
+
 bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
 {
-    wxString v = GetParamValue(param);
-    v.MakeLower();
-    if (!v) return defaultv;
+    const wxString v = GetParamValue(param);
 
-    return (v == wxT("1"));
+    return v.empty() ? defaultv : (v == '1');
 }