libpanelappletmm
2.26.0
|
00001 /* Copyright 2003 libpanelappletmm Development Team 00002 * 00003 * This library is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU Lesser General Public 00005 * License as published by the Free Software Foundation; either 00006 * version 2.1 of the License, or (at your option) any later version. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public 00014 * License along with this library; if not, write to the Free 00015 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00016 */ 00017 00018 00019 #ifndef _LIBPANELAPPLETMM_FACTORY_H 00020 #define _LIBPANELAPPLETMM_FACTORY_H 00021 00022 #include <glibmm.h> 00023 #include <libpanelappletmm/applet.h> 00024 00025 namespace Gnome 00026 { 00027 00028 namespace Panel 00029 { 00030 00031 typedef sigc::slot<bool, PanelApplet*, const Glib::ustring&> SlotFactory; 00032 00033 namespace 00034 { 00035 00036 //SignalProxy_Factory 00037 //This Signal Proxy allows the C++ coder to specify a SigC::Slot instead of a static function 00038 class SignalProxy_Factory 00039 { 00040 public: 00041 typedef Gnome::Panel::SlotFactory SlotType; 00042 00043 SignalProxy_Factory(const SlotType& slot); 00044 ~SignalProxy_Factory(); 00045 00046 static gboolean c_callback(PanelApplet* applet, const gchar* iid, void* data); 00047 00048 SlotType slot_; 00049 }; 00050 00051 SignalProxy_Factory::SignalProxy_Factory(const SlotType& slot) : slot_(slot) 00052 { 00053 } 00054 00055 SignalProxy_Factory::~SignalProxy_Factory() 00056 {} 00057 00058 gboolean SignalProxy_Factory::c_callback(PanelApplet* applet, const gchar* iid, void* data) 00059 { 00060 SignalProxy_Factory *const self = (SignalProxy_Factory*)(data); 00061 00062 const Glib::ustring sp_iid = Glib::convert_const_gchar_ptr_to_ustring(iid); 00063 00064 // Just pass the PanelApplet* because the developer will need to wrap 00065 // it with their own class that derives from Gnome::Panel::Applet. 00066 return (self->slot_)(applet, sp_iid); 00067 } 00068 00069 template<class DerivedApplet> 00070 bool applet_factory_callback(PanelApplet* panel_applet, const Glib::ustring& /* iid */) 00071 { 00072 //TODO: When will this C++ wrapper be deleted? 00073 //When the C object is deleted? When is that? murrayc 00074 DerivedApplet* applet = Gtk::manage(new DerivedApplet(panel_applet)); 00075 00076 applet->show(); 00077 00078 return true; 00079 } 00080 00081 } // anonymous namespace 00082 00083 template<class DerivedApplet> 00084 int factory_main(const Glib::ustring& iid); 00085 00086 template<class DerivedApplet> 00087 Bonobo_Unknown shlib_factory(const Glib::ustring& iid, PortableServer_POA poa, void* impl_ptr, const SlotFactory& slot, CORBA_Environment* ev); 00088 00089 int factory_main_closure(const Glib::ustring& iid, GClosure *closure); 00090 00091 Bonobo_Unknown shlib_factory_closure(const Glib::ustring& iid, PortableServer_POA poa, void* impl_ptr, GClosure* closure, CORBA_Environment* ev); 00092 00093 00094 template<class DerivedApplet> 00095 int factory_main(const Glib::ustring& iid) 00096 { 00097 SignalProxy_Factory proxy( sigc::ptr_fun(&applet_factory_callback<DerivedApplet>) ); 00098 00099 return panel_applet_factory_main( iid.c_str(), Applet::get_type(), SignalProxy_Factory::c_callback, &proxy); 00100 } 00101 00102 template<class DerivedApplet> 00103 Bonobo_Unknown shlib_factory(const Glib::ustring& iid, PortableServer_POA poa, void* impl_ptr, const SlotFactory& slot, CORBA_Environment* ev) 00104 { 00105 SignalProxy_Factory proxy( sigc::ptr_fun(&applet_factory_callback<DerivedApplet>) ); 00106 00107 return panel_applet_shlib_factory( iid.c_str(), Applet::get_type(), poa, impl_ptr, SignalProxy_Factory::c_callback, &proxy, ev); 00108 } 00109 00110 } // namespace Panel 00111 } // namespace Gnome 00112 00113 #endif /* _LIBPANELAPPLETMM_FACTORY_H */