]> git.saurik.com Git - wxWidgets.git/blobdiff - src/xrc/xmlres.cpp
re-renamed DoCreate() to XmDoCreateTLW() to avoid virtual function hiding in other...
[wxWidgets.git] / src / xrc / xmlres.cpp
index 4aa3658c3d77313a49d96064c259361582152125..ba4e8648705a26cb6e345481447b37eac1c8226e 100644 (file)
@@ -8,10 +8,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "xmlres.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -46,7 +42,7 @@
 #include "wx/xrc/xmlres.h"
 
 #include "wx/arrimpl.cpp"
-WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
+WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords)
 
 
 wxXmlResource *wxXmlResource::ms_instance = NULL;
@@ -84,6 +80,46 @@ wxXmlResource::~wxXmlResource()
 }
 
 
+/* static */
+wxString wxXmlResource::ConvertFileNameToURL(const wxString& filename)
+{
+    wxString fnd(filename);
+
+    // NB: as Load() and Unload() accept both filenames and URLs (should
+    //     probably be changed to filenames only, but embedded resources
+    //     currently rely on its ability to handle URLs - FIXME) we need to
+    //     determine whether found name is filename and not URL and this is the
+    //     fastest/simplest way to do it
+    if (wxFileName::FileExists(fnd))
+    {
+        // Make the name absolute filename, because the app may
+        // change working directory later:
+        wxFileName fn(fnd);
+        if (fn.IsRelative())
+        {
+            fn.MakeAbsolute();
+            fnd = fn.GetFullPath();
+        }
+#if wxUSE_FILESYSTEM
+        fnd = wxFileSystem::FileNameToURL(fnd);
+#endif
+    }
+
+    return fnd;
+}
+
+#if wxUSE_FILESYSTEM
+
+/* static */
+bool wxXmlResource::IsArchive(const wxString& filename)
+{
+    const wxString fnd = filename.Lower();
+
+    return fnd.Matches(wxT("*.zip")) || fnd.Matches(wxT("*.xrs"));
+}
+
+#endif // wxUSE_FILESYSTEM
+
 bool wxXmlResource::Load(const wxString& filemask)
 {
     wxString fnd;
@@ -105,34 +141,15 @@ bool wxXmlResource::Load(const wxString& filemask)
         fnd = filemask;
     while (!fnd.empty())
     {
-        // NB: Load() accepts both filenames and URLs (should probably be
-        //     changed to filenames only, but embedded resources currently
-        //     rely on its ability to handle URLs - FIXME). This check
-        //     serves as a quick way to determine whether found name is
-        //     filename and not URL:
-        if (wxFileName::FileExists(fnd))
-        {
-            // Make the name absolute filename, because the app may
-            // change working directory later:
-            wxFileName fn(fnd);
-            if (fn.IsRelative())
-            {
-                fn.MakeAbsolute();
-                fnd = fn.GetFullPath();
-            }
-#if wxUSE_FILESYSTEM
-            fnd = wxFileSystem::FileNameToURL(fnd);
-#endif
-        }
+        fnd = ConvertFileNameToURL(fnd);
 
 #if wxUSE_FILESYSTEM
-        if (fnd.Lower().Matches(wxT("*.zip")) ||
-            fnd.Lower().Matches(wxT("*.xrs")))
+        if ( IsArchive(fnd) )
         {
             rt = rt && Load(fnd + wxT("#zip:*.xrc"));
         }
-        else
-#endif
+        else // a single resource URL
+#endif // wxUSE_FILESYSTEM
         {
             drec = new wxXmlResourceDataRecord;
             drec->File = fnd;
@@ -149,6 +166,46 @@ bool wxXmlResource::Load(const wxString& filemask)
     return rt && UpdateResources();
 }
 
+bool wxXmlResource::Unload(const wxString& filename)
+{
+    wxASSERT_MSG( !wxIsWild(filename),
+                    _T("wildcards not supported by wxXmlResource::Unload()") );
+
+    wxString fnd = ConvertFileNameToURL(filename);
+#if wxUSE_FILESYSTEM
+    const bool isArchive = IsArchive(fnd);
+    if ( isArchive )
+        fnd += _T("#zip:");
+#endif // wxUSE_FILESYSTEM
+
+    bool unloaded = false;
+    const size_t count = m_data.GetCount();
+    for ( size_t i = 0; i < count; i++ )
+    {
+#if wxUSE_FILESYSTEM
+        if ( isArchive )
+        {
+            if ( m_data[i].File.StartsWith(fnd) )
+                unloaded = true;
+            // don't break from the loop, we can have other matching files
+        }
+        else // a single resource URL
+#endif // wxUSE_FILESYSTEM
+        {
+            if ( m_data[i].File == fnd )
+            {
+                m_data.RemoveAt(i);
+                unloaded = true;
+
+                // no sense in continuing, there is only one file with this URL
+                break;
+            }
+        }
+    }
+
+    return unloaded;
+}
+
 
 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler, wxObject)
 
@@ -622,7 +679,7 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
 
 #include "wx/listimpl.cpp"
 WX_DECLARE_LIST(wxXmlSubclassFactory, wxXmlSubclassFactoriesList);
-WX_DEFINE_LIST(wxXmlSubclassFactoriesList);
+WX_DEFINE_LIST(wxXmlSubclassFactoriesList)
 
 wxXmlSubclassFactoriesList *wxXmlResource::ms_subclassFactories = NULL;
 
@@ -879,7 +936,7 @@ float wxXmlResourceHandler::GetFloat(const wxString& param, float defaultv)
     setlocale(LC_NUMERIC, prevlocale);
 #endif
 
-    return value;
+    return wx_truncate_cast(float, value);
 }
 
 
@@ -1356,6 +1413,8 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
 #endif
     if (HasParam(wxT("font")))
         wnd->SetFont(GetFont());
+    if (HasParam(wxT("help")))
+        wnd->SetHelpText(GetText(wxT("help")));
 }
 
 
@@ -1455,8 +1514,18 @@ static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2)
     return (*rec_var)->id;
 }
 
+static void AddStdXRCID_Records();
+
 /*static*/ int wxXmlResource::GetXRCID(const wxChar *str_id)
 {
+    static bool s_stdIDsAdded = false;
+
+    if ( !s_stdIDsAdded )
+    {
+        s_stdIDsAdded = true;
+        AddStdXRCID_Records();
+    }
+
     return XRCID_Lookup(str_id);
 }
 
@@ -1601,7 +1670,6 @@ public:
     wxXmlResourceModule() {}
     bool OnInit()
     {
-        AddStdXRCID_Records();
         wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX);
         return true;
     }