UDefaultFunctions.h
00001 #ifndef _UDEFAULTFUNCTIONS_H
00002 #define _UDEFAULTFUNCTIONS_H
00003
00004 #include <UVoid.h>
00005 #include <UPixbufCache.h>
00006
00007 class GuiPM;
00008
00009 #define WRAPPED_TYPENAME( typename ) (std::string( g_type_name(typename) )+ "_uwrapped").c_str()
00010
00019 template<class GtkParentClass>
00020 class UDefaultFunctions : public GtkParentClass, public UVoid, public UPixbufCache
00021 {
00022 public:
00023 typedef GtkParentClass GtkmmBaseType;
00024 typedef UDefaultFunctions<GtkParentClass> BaseType;
00025 UDefaultFunctions() :
00026 Glib::ObjectBase(WRAPPED_TYPENAME(GtkParentClass::get_type()))
00027 ,UVoid(this)
00028 ,property_auto_connect_(*this, "auto-connect", true)
00029 ,property_disconnect_effect_(*this, "disconnect-effect", 1)
00030 ,property_lock_view_(*this, "lock-view", false)
00031 {}
00032
00033 explicit UDefaultFunctions(typename GtkParentClass::BaseObjectType* o) :
00034 GtkParentClass(o)
00035 ,UVoid(this)
00036 ,property_auto_connect_(*this, "auto-connect", true)
00037 ,property_disconnect_effect_(*this, "disconnect-effect", 1)
00038 ,property_lock_view_(*this, "lock-view", false)
00039 {}
00040
00041 UDefaultFunctions(const BaseType& p) :
00042 UVoid(this)
00043 ,property_auto_connect_(*this, "auto-connect", p.property_auto_connect_)
00044 ,property_disconnect_effect_(*this, "disconnect-effect", p.property_disconnect_effect_)
00045 ,property_lock_view_(*this, "lock-view", p.property_lock_view_)
00046 {}
00047
00048 virtual ~UDefaultFunctions() {}
00052 virtual void on_hierarchy_changed(Gtk::Widget* w);
00053
00054 GuiPM* search_gpm();
00055 ConnectorRef get_connector_from_hierarchy();
00056 virtual void add_lock(const Gtk::Widget& w);
00057 virtual void unlock_current();
00059 private:
00060 Glib::Property<bool> property_auto_connect_;
00061 Glib::Property<int> property_disconnect_effect_;
00062 Glib::Property<bool> property_lock_view_;
00063 };
00064
00065 inline Glib::PropertyProxy<bool>
00066 UVoid::property_auto_connect()
00067 {
00068 return Glib::PropertyProxy<bool>(obj_,"auto-connect");
00069 }
00070
00071 inline Glib::PropertyProxy_ReadOnly<bool>
00072 UVoid::property_auto_connect() const
00073 {
00074 return Glib::PropertyProxy_ReadOnly<bool>(obj_,"auto-connect");
00075 }
00076
00077 inline Glib::PropertyProxy<int>
00078 UVoid::property_disconnect_effect()
00079 {
00080 return Glib::PropertyProxy<int>(obj_,"disconnect-effect");
00081 }
00082
00083 inline Glib::PropertyProxy_ReadOnly<int>
00084 UVoid::property_disconnect_effect() const
00085 {
00086 return Glib::PropertyProxy_ReadOnly<int>(obj_,"disconnect-effect");
00087 }
00088
00089 inline Glib::PropertyProxy<bool>
00090 UVoid::property_lock_view()
00091 {
00092 return Glib::PropertyProxy<bool>(obj_,"lock-view");
00093 }
00094
00095 inline Glib::PropertyProxy_ReadOnly<bool>
00096 UVoid::property_lock_view() const
00097 {
00098 return Glib::PropertyProxy_ReadOnly<bool>(obj_,"lock-view");
00099 }
00100
00101
00102
00103
00104 template<class T>
00105 GuiPM* UDefaultFunctions<T>::search_gpm()
00106 {
00107 Gtk::Widget* parent = reinterpret_cast<Gtk::Widget*>(T::get_parent());
00108 for (Gtk::Widget* p = parent; p != NULL; p = reinterpret_cast<Gtk::Widget*>(p->get_parent()))
00109 if ( UVoid* uv = dynamic_cast<UVoid*>(p) )
00110 if ( uv->gpm != NULL) return uv->gpm;
00111 return NULL;
00112 }
00113
00114 template<class T> ConnectorRef
00115 UDefaultFunctions<T>::get_connector_from_hierarchy()
00116 {
00117 Gtk::Widget* parent = reinterpret_cast<Gtk::Widget*>(T::get_parent());
00118 while (parent != NULL) {
00119 if(UVoid* uv = dynamic_cast<UVoid*>(parent)) {
00120 ConnectorRef new_connector = uv->get_connector();
00121 return new_connector;
00122 }
00123 parent = reinterpret_cast<Gtk::Widget*>(parent->get_parent());
00124 }
00125 return ConnectorRef();
00126 }
00127
00128 template<class T> void
00129 UDefaultFunctions<T>::on_hierarchy_changed(Gtk::Widget* w)
00130 {
00131 GtkmmBaseType::on_hierarchy_changed(w);
00132 if ( !property_auto_connect_ )
00133 return;
00134 ConnectorRef connector = get_connector_from_hierarchy();
00135 set_connector(connector);
00136 }
00137
00138 template<class T>
00139 void UDefaultFunctions<T>::add_lock(const Gtk::Widget& w)
00140 {
00141 Gtk::Widget* prev = this;
00142 Gtk::Widget* next = reinterpret_cast<Gtk::Widget*>(T::get_parent());
00143 while (next != NULL) {
00144 if (UVoid* uv = dynamic_cast<UVoid*>(next)) {
00145 uv->add_lock(*prev);
00146 break;
00147 }
00148
00149 prev = next;
00150 next = reinterpret_cast<Gtk::Widget*>(next->get_parent());
00151 }
00152 }
00153
00154 template<class T>
00155 void UDefaultFunctions<T>::unlock_current()
00156 {
00157 Gtk::Widget* parent = reinterpret_cast<Gtk::Widget*>(T::get_parent());
00158 for (Gtk::Widget* p = parent; p != NULL; p = reinterpret_cast<Gtk::Widget*>(p->get_parent()))
00159 if (UVoid* uv = dynamic_cast<UVoid*>(p)) {
00160 uv->unlock_current();
00161 break;
00162 }
00163 }
00164
00165 #endif