]> git.saurik.com Git - wxWidgets.git/blobdiff - src/xrc/xmlres.cpp
Applied patch [ 566816 ] adds xBase type for Sequiter's SQL/ODBC
[wxWidgets.git] / src / xrc / xmlres.cpp
index 8a630df247f49595afa36930e8d284bfbb10146c..2106d04ff7220635293bf413fd7866a23f7ce8b3 100644 (file)
@@ -32,6 +32,7 @@
 #include "wx/bitmap.h"
 #include "wx/image.h"
 #include "wx/fontmap.h"
+#include "wx/artprov.h"
 
 #include "wx/xrc/xml.h"
 #include "wx/xrc/xmlres.h"
@@ -372,9 +373,9 @@ void wxXmlResource::UpdateResources()
 }
 
 
-wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, 
-                                         const wxString& name, 
-                                         const wxString& classname, 
+wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
+                                         const wxString& name,
+                                         const wxString& classname,
                                          bool recursive)
 {
     wxString dummy;
@@ -384,10 +385,10 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
     // where the resource is most commonly looked for):
     for (node = parent->GetChildren(); node; node = node->GetNext())
     {
-        if ( node->GetType() == wxXML_ELEMENT_NODE && 
-                 (node->GetName() == wxT("object") || 
+        if ( node->GetType() == wxXML_ELEMENT_NODE &&
+                 (node->GetName() == wxT("object") ||
                   node->GetName() == wxT("object_ref")) &&
-                (!classname || 
+                (!classname ||
                  node->GetPropVal(wxT("class"), wxEmptyString) == classname) &&
                 node->GetPropVal(wxT("name"), &dummy) && dummy == name )
             return node;
@@ -396,8 +397,8 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
     if ( recursive )
         for (node = parent->GetChildren(); node; node = node->GetNext())
         {
-            if ( node->GetType() == wxXML_ELEMENT_NODE && 
-                 (node->GetName() == wxT("object") || 
+            if ( node->GetType() == wxXML_ELEMENT_NODE &&
+                 (node->GetName() == wxT("object") ||
                   node->GetName() == wxT("object_ref")) )
             {
                 wxXmlNode* found = DoFindResource(node, name, classname, TRUE);
@@ -409,7 +410,7 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
    return NULL;
 }
 
-wxXmlNode *wxXmlResource::FindResource(const wxString& name, 
+wxXmlNode *wxXmlResource::FindResource(const wxString& name,
                                        const wxString& classname,
                                        bool recursive)
 {
@@ -421,7 +422,7 @@ wxXmlNode *wxXmlResource::FindResource(const wxString& name,
         if ( m_data[f].Doc == NULL || m_data[f].Doc->GetRoot() == NULL )
             continue;
 
-        wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(), 
+        wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(),
                                           name, classname, recursive);
         if ( found )
         {
@@ -445,7 +446,7 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
         wxXmlProperty *dprop;
         for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext())
         {
-       
+
             if ( dprop->GetName() == prop->GetName() )
             {
                 dprop->SetValue(prop->GetValue());
@@ -494,7 +495,7 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx
 
         if ( !refNode )
         {
-            wxLogError(_("Referenced object node with ref=\"%s\" not found!"), 
+            wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
                        refName.c_str());
             return NULL;
         }
@@ -543,7 +544,7 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent
     wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow;
 
     m_instance = instance;
-    if (!m_instance && node->HasProp(wxT("subclass")) && 
+    if (!m_instance && node->HasProp(wxT("subclass")) &&
         !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
     {
         wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);
@@ -551,7 +552,7 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent
 
         if (classInfo)
             m_instance = classInfo->CreateObject();
-        
+
         if (!m_instance)
         {
             wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
@@ -633,19 +634,14 @@ int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults)
 
 wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
 {
-    wxString str1;
+    wxString str1(GetParamValue(param));
     wxString str2;
     const wxChar *dt;
     wxChar amp_char;
 
-    if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)
-        str1 = wxGetTranslation(GetParamValue(param));
-    else
-        str1 = GetParamValue(param);
-
-    // VS: First version of XRC resources used $ instead of & (which is illegal in XML),
-    //     but later I realized that '_' fits this purpose much better (because
-    //     &File means "File with F underlined").
+    // VS: First version of XRC resources used $ instead of & (which is
+    //     illegal in XML), but later I realized that '_' fits this purpose
+    //     much better (because &File means "File with F underlined").
     if (m_resource->CompareVersion(2,3,0,1) < 0)
         amp_char = wxT('$');
     else
@@ -673,8 +669,12 @@ wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
             }
         else str2 << *dt;
     }
-    
-    return str2;
+
+    if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)
+        return wxGetTranslation(str2);
+    else
+        return str2;
+
 }
 
 
@@ -691,6 +691,7 @@ long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
 }
 
 
+
 int wxXmlResourceHandler::GetID()
 {
     wxString sid = GetName();
@@ -717,6 +718,68 @@ int wxXmlResourceHandler::GetID()
 }
 
 
+
+wxArtID wxXmlResourceHandler::GetStockID(const wxString& param)
+{
+    wxXmlNode *stockIDNode = GetParamNode(param);
+    if (stockIDNode == NULL)    
+        return wxEmptyString;
+    
+    wxXmlNode *oldnode = m_node;
+    m_node = stockIDNode;
+    
+    wxArtID sid = m_node->GetPropVal(wxT("stock_id"), wxT(""));      
+   
+    m_node = oldnode;
+
+    if (sid.IsEmpty()) return wxEmptyString;
+#define stdID(id) else if (sid == wxT(#id)) return id
+    stdID(wxART_ADD_BOOKMARK); stdID(wxART_DEL_BOOKMARK);
+    stdID(wxART_HELP_SIDE_PANEL); stdID(wxART_HELP_SETTINGS);
+    stdID(wxART_HELP_BOOK); stdID(wxART_HELP_FOLDER);
+    stdID(wxART_HELP_PAGE); stdID(wxART_GO_BACK);
+    stdID(wxART_GO_FORWARD); stdID(wxART_GO_UP);
+    stdID(wxART_GO_DOWN); stdID(wxART_GO_TO_PARENT);
+    stdID(wxART_GO_HOME); stdID(wxART_FILE_OPEN);
+    stdID(wxART_PRINT); stdID(wxART_HELP); stdID(wxART_TIP);
+    stdID(wxART_REPORT_VIEW); stdID(wxART_LIST_VIEW);
+    stdID(wxART_NEW_DIR); stdID(wxART_FOLDER); 
+    stdID(wxART_GO_DIR_UP); stdID(wxART_EXECUTABLE_FILE);
+    stdID(wxART_NORMAL_FILE); stdID(wxART_TICK_MARK);
+    stdID(wxART_CROSS_MARK); stdID(wxART_ERROR);
+    stdID(wxART_QUESTION);   stdID(wxART_WARNING);
+    stdID(wxART_INFORMATION);
+#undef stdID
+    else return sid;
+}
+
+
+
+wxArtClient wxXmlResourceHandler::GetStockClient(const wxString& param)
+{
+    wxXmlNode *stockClientNode = GetParamNode(param);
+    if (stockClientNode == NULL)
+        return wxEmptyString;
+    
+    wxXmlNode *oldnode = m_node;
+    m_node = stockClientNode;
+
+    wxArtClient sid = m_node->GetPropVal(wxT("stock_client"), wxT("wxART_OTHER"));
+
+    m_node = oldnode;
+
+    if (sid.IsEmpty()) return wxEmptyString;
+#define stdID(id) else if (sid == wxT(#id)) return id
+    stdID(wxART_TOOLBAR); stdID(wxART_MENU);
+    stdID(wxART_FRAME_ICON); stdID(wxART_CMN_DIALOG); 
+    stdID(wxART_HELP_BROWSER); stdID(wxART_MESSAGE_BOX);
+    stdID(wxART_OTHER); 
+#undef stdID
+    else return sid;
+}
+
+
+
 wxString wxXmlResourceHandler::GetName()
 {
     return m_node->GetPropVal(wxT("name"), wxT("-1"));
@@ -756,8 +819,17 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param)
 
 wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size)
 {
+    wxString stk = param;
+    if (!GetStockID(stk).IsEmpty())
+    {
+        wxBitmap stockArt = wxArtProvider::GetBitmap(GetStockID(stk),
+                                                     GetStockClient(stk), size);
+        if (stockArt != wxNullBitmap)
+            return stockArt;
+    }
+
     wxString name = GetParamValue(param);
-    if (name.IsEmpty()) return wxNullBitmap;
+    if (name.IsEmpty()) return wxNullBitmap;        
 #if wxUSE_FILESYSTEM
     wxFSFile *fsfile = GetCurFileSystem().OpenFile(name);
     if (fsfile == NULL)
@@ -770,13 +842,15 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size)
 #else
     wxImage img(GetParamValue(wxT("bitmap")));
 #endif
+
     if (!img.Ok())
     {
         wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), param.c_str());
         return wxNullBitmap;
     }
     if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y);
-    return img.ConvertToBitmap();
+    return wxBitmap(img);
+
 }