]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch for ArtProvider.
authorRobert Roebling <robert@roebling.de>
Sat, 12 Mar 2005 10:33:00 +0000 (10:33 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 12 Mar 2005 10:33:00 +0000 (10:33 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32769 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/artprov.tex
include/wx/artprov.h
samples/artprov/artbrows.cpp
samples/artprov/artbrows.h
src/common/artprov.cpp
src/common/artstd.cpp
src/gtk/artgtk.cpp
src/gtk1/artgtk.cpp

index d0b0fde2b694ed8a4b40186d0cb482e6b893c104..fedf79d678928a321d88b41f66c48a4209e4e41c 100644 (file)
@@ -176,11 +176,12 @@ The bitmap if one of registered providers recognizes the ID or wxNullBitmap othe
 Same as \helpref{wxArtProvider::GetBitmap}{wxartprovidergetbitmap}, but
 return a wxIcon object (or wxNullIcon on failure).
 
-\func{static wxSize}{GetSize}{\param{const wxArtClient\& }{client}, \param{bool }{platform_default = false}}
+\func{static wxSize}{GetSizeHint}{\param{const wxArtClient\& }{client}, \param{bool }{platform_default = false}}
 
-Returns the default size for the given art {\it client} by either using the topmost 
-wxArtProvider or if {\it platform_default} is \true then return a suitable default size for 
-{\it client} depending on the current platform.
+Returns a suitable size hint for the given {\it wxArtClient}. If 
+{\it platform_default} is \true, return a size based on the current platform, 
+otherwise return the size from the topmost wxArtProvider. {\it wxDefaultSize} may be 
+returned if the client doesn't have a specified size, like wxART_OTHER for example.
 
 \membersection{wxArtProvider::PopProvider}\label{wxartproviderctor}
 
index 3576b4bad5fc766c2f2e186eb45f7987c155bdc0..7abfbfa7af78fbb02b300cc28195299a0e4af1f5 100644 (file)
@@ -137,9 +137,9 @@ public:
                           const wxArtClient& client = wxART_OTHER,
                           const wxSize& size = wxDefaultSize);
 
-    // Get the size of an icon from a specific wxArtClient, queries 
+    // Get the size hint of an icon from a specific wxArtClient, queries 
     // the topmost provider if platform_dependent = false
-    static wxSize GetSize(const wxArtClient& client, bool platform_dependent = false);
+    static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
 
 protected:
     friend class wxArtProviderModule;
@@ -151,9 +151,9 @@ protected:
     static void CleanUpProviders();
 
     // Get the default size of an icon for a specific client
-    virtual wxSize DoGetSize(const wxArtClient& client) 
+    virtual wxSize DoGetSizeHint(const wxArtClient& client) 
     {
-        return GetSize(client, true);
+        return GetSizeHint(client, true);
     }
                              
     // Derived classes must override this method to create requested
index fbeff12791abd3a678bdc241ed879849d4d1945b..b1ca0f16061ba9f6a20edce610d32fb1dbeb53d1 100644 (file)
@@ -146,6 +146,9 @@ wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
     subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10);
 
     wxSizer *subsub = new wxBoxSizer(wxVERTICAL);
+    m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333"));
+    subsub->Add(m_text);
+
     m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm));
     subsub->Add(m_canvas);
     subsub->Add(100, 100);
@@ -173,22 +176,24 @@ void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
     img->Add(wxIcon(null_xpm));
     int index = 0;
 
+    long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
+    if (sel < 0) sel = 0;
+
     m_list->DeleteAllItems();
     FillBitmaps(img, m_list, index, client, wxSize(16, 16));
     m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
     m_list->SetColumnWidth(0, wxLIST_AUTOSIZE);
 
+    m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+
     m_client = client;
+    SetArtBitmap((const wxChar*)m_list->GetItemData(sel), m_client);
 }
 
 void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
 {
-
     const wxChar *data = (const wxChar*)event.GetData();
-    wxBitmap bmp = wxArtProvider::GetBitmap(data, m_client);
-    m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
-    m_canvas->SetBitmap(bmp);
-    Refresh();
+    SetArtBitmap(data, m_client, wxDefaultSize);
 }
 
 void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
@@ -196,3 +201,12 @@ void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
     const wxChar *data = (const wxChar*)event.GetClientData();
     SetArtClient(data);
 }
+
+void wxArtBrowserDialog::SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
+{
+    wxBitmap bmp = wxArtProvider::GetBitmap(id, client, size);
+    m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
+    m_canvas->SetBitmap(bmp);
+    m_text->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp.GetWidth(), bmp.GetHeight()));
+    Refresh();
+}
index 40bca1ec81e0ce0bafb568c5cde3e34025120f5a..827df2e1df7e61b2fa0db522b336994f78beea09 100644 (file)
@@ -29,6 +29,7 @@ public:
     wxArtBrowserDialog(wxWindow *parent);
 
     void SetArtClient(const wxArtClient& client);
+    void SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size = wxDefaultSize);
 
 private:
     void OnSelectItem(wxListEvent &event);
@@ -36,6 +37,7 @@ private:
     
     wxListCtrl *m_list;
     wxStaticBitmap *m_canvas;
+    wxStaticText *m_text;
     wxString m_client;
 
     DECLARE_EVENT_TABLE()
index 52b8b8ab989ef6eb236368edc9b1ce4d2080a71b..4657066f9952b0232c05ea8401945b19bfb61009 100644 (file)
@@ -151,16 +151,14 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
 
 /*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
                                              const wxArtClient& client,
-                                             const wxSize& reqSize)
+                                             const wxSize& size)
 {
     // safety-check against writing client,id,size instead of id,client,size:
     wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") );
 
     wxCHECK_MSG( sm_providers, wxNullBitmap, _T("no wxArtProvider exists") );
 
-    wxSize bestSize = (reqSize != wxDefaultSize) ? reqSize : GetSize(client);
-
-    wxString hashId = wxArtProviderCache::ConstructHashID(id, client, bestSize);
+    wxString hashId = wxArtProviderCache::ConstructHashID(id, client, size);
 
     wxBitmap bmp;
     if ( !sm_cache->GetBitmap(hashId, &bmp) )
@@ -168,25 +166,15 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
         for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
              node; node = node->GetNext())
         {
-            bmp = node->GetData()->CreateBitmap(id, client, bestSize);
+            bmp = node->GetData()->CreateBitmap(id, client, size);
             if ( bmp.Ok() )
             {
 #if wxUSE_IMAGE
-                int bmp_w = bmp.GetWidth();
-                int bmp_h = bmp.GetHeight();
-                // want default size but it's smaller, paste into transparent image
-                if ((reqSize == wxDefaultSize) &&
-                    (bmp_h < bestSize.x) && (bmp_w < bestSize.y))
-                {
-                     wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
-                     wxImage img = bmp.ConvertToImage();
-                     img.Resize(bestSize, offset);
-                     bmp = wxBitmap(img);
-                }
-                else if ( (bmp_w != bestSize.x) || (bmp_h != bestSize.y) )
+                if ( size != wxDefaultSize &&
+                     (bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) )
                 {
                     wxImage img = bmp.ConvertToImage();
-                    img.Rescale(bestSize.x, bestSize.y);
+                    img.Rescale(size.x, size.y);
                     bmp = wxBitmap(img);
                 }
 #endif
@@ -218,36 +206,45 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
     #include <gtk/gtk.h>
     extern GtkIconSize wxArtClientToIconSize(const wxArtClient& client);
-#endif // __WXGTK__
+#endif // defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
 
-/*static*/ wxSize wxArtProvider::GetSize(const wxArtClient& client,
+/*static*/ wxSize wxArtProvider::GetSizeHint(const wxArtClient& client,
                                          bool platform_dependent)
 {
     if (!platform_dependent)
     {
         wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
         if (node)
-            return node->GetData()->DoGetSize(client);
+            return node->GetData()->DoGetSizeHint(client);
+    }
 
         // else return platform dependent size
-    }
 
 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
+    // Gtk has specific sizes for each client, see artgtk.cpp
     GtkIconSize gtk_size = wxArtClientToIconSize(client);
+    // no size hints for this client
+    if (gtk_size == GTK_ICON_SIZE_INVALID)
+        return wxDefaultSize;
     gint width, height;
     gtk_icon_size_lookup( gtk_size, &width, &height);
     return wxSize(width, height);
 #else // !GTK+ 2
+    // NB: These size hints may have to be adjusted per platform
     if (client == wxART_TOOLBAR)
-        return wxSize(32, 32);
+        return wxSize(16, 15);
     else if (client == wxART_MENU)
         return wxSize(16, 15);
+    else if (client == wxART_FRAME_ICON)
+        return wxSize(16, 15);
     else if (client == wxART_CMN_DIALOG || client == wxART_MESSAGE_BOX)
         return wxSize(32, 32);
+    else if (client == wxART_HELP_BROWSER)
+        return wxSize(16, 15);
     else if (client == wxART_BUTTON)
         return wxSize(16, 15);
-    else
-        return wxSize(16, 15); // this is arbitrary
+    else // wxART_OTHER or perhaps a user's client, no specified size
+        return wxDefaultSize;      
 #endif // GTK+ 2/else
 }
 
index 23bbfb70530087d074a774248065b542b8f9cbaa..a96e970d22b1bf02278466dbfb5551b517df5ec8 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include "wx/artprov.h"
+#include "wx/image.h"
 
 // ----------------------------------------------------------------------------
 // wxDefaultArtProvider
@@ -143,13 +144,7 @@ protected:
 
 #undef static
 
-// ----------------------------------------------------------------------------
-// CreateBitmap routine
-// ----------------------------------------------------------------------------
-
-wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
-                                            const wxArtClient& WXUNUSED(client),
-                                            const wxSize& WXUNUSED(size))
+wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
 {
     // wxMessageBox icons:
     ART_MSGBOX(wxART_ERROR,       wxICON_ERROR,       error)
@@ -195,3 +190,38 @@ wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
 
     return wxNullBitmap;
 }
+
+// ----------------------------------------------------------------------------
+// CreateBitmap routine
+// ----------------------------------------------------------------------------
+
+wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
+                                            const wxArtClient& client,
+                                            const wxSize& reqSize)
+{
+    wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
+
+    if (bmp.Ok())
+    {
+        // fit into transparent image with desired size hint from the client
+        if (reqSize == wxDefaultSize)
+        {
+            // find out if there is a desired size for this client
+            wxSize bestSize = GetSizeHint(client);
+            if (bestSize != wxDefaultSize)
+            {
+                int bmp_w = bmp.GetWidth();
+                int bmp_h = bmp.GetHeight();
+                // want default size but it's smaller, paste into transparent image
+                if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
+                {
+                    wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
+                    wxImage img = bmp.ConvertToImage();
+                    img.Resize(bestSize, offset);
+                    bmp = wxBitmap(img);
+                }        
+            }
+        }      
+    }
+    return bmp;
+}
index 47aa4c93db6a2f7ed2641bc82938611b264b644b..a936c31900f5087e0edc592a74a18bf579fe681f 100644 (file)
@@ -136,7 +136,7 @@ GtkIconSize wxArtClientToIconSize(const wxArtClient& client)
     else if (client == wxART_BUTTON)
         return GTK_ICON_SIZE_BUTTON;
     else
-        return GTK_ICON_SIZE_BUTTON; // this is arbitrary
+        return GTK_ICON_SIZE_INVALID; // this is arbitrary
 }
 
 static GtkIconSize FindClosestIconSize(const wxSize& size)
@@ -245,6 +245,10 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
                                 wxArtClientToIconSize(client) : 
                                 FindClosestIconSize(size);
 
+    // we must have some size, this is arbitrary
+    if (stocksize == GTK_ICON_SIZE_INVALID)
+        stocksize = GTK_ICON_SIZE_BUTTON;
+
     // allow passing GTK+ stock IDs to wxArtProvider:
     if (!stockid)
         stockid = id.ToAscii();
index 47aa4c93db6a2f7ed2641bc82938611b264b644b..a936c31900f5087e0edc592a74a18bf579fe681f 100644 (file)
@@ -136,7 +136,7 @@ GtkIconSize wxArtClientToIconSize(const wxArtClient& client)
     else if (client == wxART_BUTTON)
         return GTK_ICON_SIZE_BUTTON;
     else
-        return GTK_ICON_SIZE_BUTTON; // this is arbitrary
+        return GTK_ICON_SIZE_INVALID; // this is arbitrary
 }
 
 static GtkIconSize FindClosestIconSize(const wxSize& size)
@@ -245,6 +245,10 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
                                 wxArtClientToIconSize(client) : 
                                 FindClosestIconSize(size);
 
+    // we must have some size, this is arbitrary
+    if (stocksize == GTK_ICON_SIZE_INVALID)
+        stocksize = GTK_ICON_SIZE_BUTTON;
+
     // allow passing GTK+ stock IDs to wxArtProvider:
     if (!stockid)
         stockid = id.ToAscii();