]> git.saurik.com Git - wxWidgets.git/commitdiff
set icons bundle, not single icon, for frames loaded from XRC
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 29 Mar 2009 21:25:23 +0000 (21:25 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 29 Mar 2009 21:25:23 +0000 (21:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59931 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/xrc/xmlres.h
interface/wx/xrc/xmlres.h
src/xrc/xh_dlg.cpp
src/xrc/xh_frame.cpp
src/xrc/xh_mdi.cpp
src/xrc/xh_propdlg.cpp
src/xrc/xmlres.cpp

index 0f0b69aa92bb8e92a9dc57e216f0c34d01795641..3ec28e0da7c3d846920e4131c336de3bbff4809b 100644 (file)
@@ -33,6 +33,7 @@
 
 class WXDLLIMPEXP_FWD_BASE wxFileName;
 
+class WXDLLIMPEXP_FWD_CORE wxIconBundle;
 class WXDLLIMPEXP_FWD_CORE wxMenu;
 class WXDLLIMPEXP_FWD_CORE wxMenuBar;
 class WXDLLIMPEXP_FWD_CORE wxDialog;
@@ -508,6 +509,10 @@ protected:
                    const wxArtClient& defaultArtClient = wxART_OTHER,
                    wxSize size = wxDefaultSize);
 
+    // Gets an icon bundle.
+    wxIconBundle GetIconBundle(const wxString& param,
+                               const wxArtClient& defaultArtClient = wxART_OTHER);
+
 #if wxUSE_ANIMATIONCTRL
     // Gets an animation.
     wxAnimation GetAnimation(const wxString& param = wxT("animation"));
index 5bd3bce792769d0ad64b2a74e97eb64224061488..c07f44c0171be55b56f1bfde0c9738d89ce97371 100644 (file)
@@ -532,6 +532,19 @@ protected:
                    const wxArtClient& defaultArtClient = wxART_OTHER,
                    wxSize size = wxDefaultSize);
 
+    /**
+        Returns an icon bundle.
+
+        @note
+        Bundles can be loaded either with stock IDs or from files that contain
+        more than one image (e.g. Windows icon files). If a file contains only
+        single image, a bundle with only one icon will be created.
+
+        @since 2.9.0
+     */
+    wxIconBundle GetIconBundle(const wxString& param,
+                               const wxArtClient& defaultArtClient = wxART_OTHER);
+
     /**
         Gets the integer value from the parameter.
     */
index cd50f4a96cc561c9f646748fa7dbde451b282a85..268d60f4f14654115d39e694d713c36d9a4337b4 100644 (file)
@@ -73,7 +73,7 @@ wxObject *wxDialogXmlHandler::DoCreateResource()
     if (HasParam(wxT("pos")))
         dlg->Move(GetPosition());
     if (HasParam(wxT("icon")))
-        dlg->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON));
+        dlg->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON));
 
     SetupWindow(dlg);
 
index 892a9e38aa8cc2d98d4b8b16ff258ef762313c25..b575f8bd8bfadce6d3eb0698149917994cedfdff 100644 (file)
@@ -79,7 +79,7 @@ wxObject *wxFrameXmlHandler::DoCreateResource()
     if (HasParam(wxT("pos")))
         frame->Move(GetPosition());
     if (HasParam(wxT("icon")))
-        frame->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON));
+        frame->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON));
 
     SetupWindow(frame);
 
index f6fea842ddcb9ac6041a4a896fcc0b33d1814143..50a7ed1cb79f8cccf9f59e24cf7988d8019301c6 100644 (file)
@@ -117,7 +117,7 @@ wxObject *wxMdiXmlHandler::DoCreateResource()
     {
         wxFrame* f = wxDynamicCast(frame, wxFrame);
         if (f)
-            f->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON));
+            f->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON));
     }
 
     SetupWindow(frame);
index 0dd4f168f86eb683294d72eb2bb0a73cad23d510..8a7b102e9346cf65a3efd97125263b4db25f4e8b 100644 (file)
@@ -113,7 +113,8 @@ wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource()
                    GetStyle(),
                    GetName());
 
-        if (HasParam(wxT("icon"))) dlg->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON));
+        if (HasParam(wxT("icon")))
+            dlg->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON));
 
         SetupWindow(dlg);
 
index 075489d9e7cecbd6809d58d921e0e4d2a02b9d61..d16bc62363f511dec33998b635977366b6f0f171 100644 (file)
@@ -1230,31 +1230,49 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param, const wxColour&
     return clr;
 }
 
+namespace
+{
+
+// if 'param' has stock_id/stock_client, extracts them and returns true
+bool GetStockArtAttrs(const wxXmlNode *paramNode,
+                      const wxString& defaultArtClient,
+                      wxString& art_id, wxString& art_client)
+{
+    if ( paramNode )
+    {
+        art_id = paramNode->GetAttribute("stock_id", "");
+
+        if ( !art_id.empty() )
+        {
+            art_id = wxART_MAKE_ART_ID_FROM_STR(art_id);
+
+            art_client = paramNode->GetAttribute("stock_client", "");
+            if ( art_client.empty() )
+                art_client = defaultArtClient;
+            else
+                art_client = wxART_MAKE_CLIENT_ID_FROM_STR(art_client);
 
+            return true;
+        }
+    }
+
+    return false;
+}
+
+} // anonymous namespace
 
 wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,
                                          const wxArtClient& defaultArtClient,
                                          wxSize size)
 {
     /* If the bitmap is specified as stock item, query wxArtProvider for it: */
-    wxXmlNode *bmpNode = GetParamNode(param);
-    if ( bmpNode )
+    wxString art_id, art_client;
+    if ( GetStockArtAttrs(GetParamNode(param), defaultArtClient,
+                          art_id, art_client) )
     {
-        wxString sid = bmpNode->GetAttribute(wxT("stock_id"), wxEmptyString);
-        if ( !sid.empty() )
-        {
-            wxString scl = bmpNode->GetAttribute(wxT("stock_client"), wxEmptyString);
-            if (scl.empty())
-                scl = defaultArtClient;
-            else
-                scl = wxART_MAKE_CLIENT_ID_FROM_STR(scl);
-
-            wxBitmap stockArt =
-                wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid),
-                                         scl, size);
-            if ( stockArt.Ok() )
-                return stockArt;
-        }
+        wxBitmap stockArt(wxArtProvider::GetBitmap(art_id, art_client, size));
+        if ( stockArt.Ok() )
+            return stockArt;
     }
 
     /* ...or load the bitmap from file: */
@@ -1300,6 +1318,52 @@ wxIcon wxXmlResourceHandler::GetIcon(const wxString& param,
     return icon;
 }
 
+wxIconBundle wxXmlResourceHandler::GetIconBundle(const wxString& param,
+                                                 const wxArtClient& defaultArtClient)
+{
+    wxString art_id, art_client;
+    if ( GetStockArtAttrs(GetParamNode(param), defaultArtClient,
+                          art_id, art_client) )
+    {
+        wxIconBundle stockArt(wxArtProvider::GetIconBundle(art_id, art_client));
+        if ( stockArt.IsOk() )
+            return stockArt;
+    }
+
+    const wxString name = GetParamValue(param);
+    if ( name.empty() )
+        return wxNullIconBundle;
+
+#if wxUSE_FILESYSTEM
+    wxFSFile *fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);
+    if ( fsfile == NULL )
+    {
+        ReportParamError
+        (
+            param,
+            wxString::Format("cannot open icon resource \"%s\"", name)
+        );
+        return wxNullIconBundle;
+    }
+
+    wxIconBundle bundle(*(fsfile->GetStream()));
+    delete fsfile;
+#else
+    wxIconBundle bundle(name);
+#endif
+
+    if ( !bundle.IsOk() )
+    {
+        ReportParamError
+        (
+            param,
+            wxString::Format("cannot create icon from \"%s\"", name)
+        );
+        return wxNullIconBundle;
+    }
+
+    return bundle;
+}
 
 
 wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param)