[beast: 3/4] BSE: turn Item::icon into a read-wrtie property



commit 485bf49d288aa04a1ebd5aa1a4501de22a21c2d3
Author: Tim Janik <timj gnu org>
Date:   Mon Feb 20 18:59:20 2017 +0100

    BSE: turn Item::icon into a read-wrtie property
    
    Signed-off-by: Tim Janik <timj gnu org>

 bse/bseapi.idl |    2 +-
 bse/bseitem.cc |   19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index d0d0e50..293c197 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -467,7 +467,7 @@ interface Object {
 
 /// Base interface type for objects that can be added to a container.
 interface Item : Object {
-  Icon icon = Record ("Icon", "State dependent icon representation of this item", "r:G");
+  Icon icon = Record ("Icon", "State dependent icon representation of this item", "rw:G");
   Item common_ancestor (Item other);    ///< Find a common container (parent or grand-parent) of two items 
if any.
 
   // bool   check_is_a        (String type_name); ///< Check whether an item has a certain type.
diff --git a/bse/bseitem.cc b/bse/bseitem.cc
index 2f4c18b..627adf5 100644
--- a/bse/bseitem.cc
+++ b/bse/bseitem.cc
@@ -1358,16 +1358,31 @@ ItemImpl::common_ancestor (ItemIface &other)
   return common->as<ItemIfaceP>();
 }
 
+class CustomIconKey : public DataKey<Icon*> {
+  virtual void destroy (Icon *icon) override    { delete icon; }
+};
+static CustomIconKey custom_icon_key;
+
 Icon
 ItemImpl::icon () const
 {
   BseItem *self = const_cast<ItemImpl*> (this)->as<BseItem*>();
-  return bse_object_get_icon (self);
+  Icon *icon = get_data (&custom_icon_key);
+  return icon ? *icon : bse_object_get_icon (self);
 }
 
 void
-ItemImpl::icon (const Icon&)
+ItemImpl::icon (const Icon &icon)
 {
+  Icon *custom_icon = new Icon (icon);
+  icon_sanitize (custom_icon);
+  if (custom_icon->width != 0)
+    set_data (&custom_icon_key, custom_icon);
+  else
+    {
+      delete custom_icon;
+      delete_data (&custom_icon_key);
+    }
 }
 
 } // Bse


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]