xml.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // Generated by gtkmmproc -- DO NOT MODIFY!
00003 #ifndef _LIBGLADEMM_XML_H
00004 #define _LIBGLADEMM_XML_H
00005 
00006 
00007 #include <glibmm.h>
00008 
00009 /* $Id: xml.hg,v 1.21 2004/09/19 12:55:53 murrayc Exp $ */
00010 
00011 /* Copyright (C) 2002 The libglademm Development Team
00012  *
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Library General Public
00015  * License as published by the Free Software Foundation; either
00016  * version 2 of the License, or (at your option) any later version.
00017  *
00018  * This library is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  * Library General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU Library General Public
00024  * License along with this library; if not, write to the Free
00025  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00026  */
00027 
00028 #include <gtkmm/container.h>
00029 
00030 
00031 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00032 typedef struct _GladeXML GladeXML;
00033 typedef struct _GladeXMLClass GladeXMLClass;
00034 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00035 
00036 
00037 namespace Gnome
00038 {
00039 
00040 namespace Glade
00041 { class Xml_Class; } // namespace Glade
00042 
00043 } // namespace Gnome
00044 namespace Gnome
00045 {
00046 
00047 namespace Glade
00048 {
00049 
00050 class XmlError : public Glib::Exception
00051 {
00052 public:
00053   explicit XmlError(const Glib::ustring& message);
00054   virtual ~XmlError() throw();
00055 
00056   XmlError(const XmlError& other);
00057   XmlError& operator=(const XmlError& other);
00058 
00059   virtual Glib::ustring what() const;
00060 
00061 private:
00062   Glib::ustring message_;
00063 };
00064 
00065 
00066 class Xml : public Glib::Object
00067 {
00068   
00069 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00070 
00071 public:
00072   typedef Xml CppObjectType;
00073   typedef Xml_Class CppClassType;
00074   typedef GladeXML BaseObjectType;
00075   typedef GladeXMLClass BaseClassType;
00076 
00077 private:  friend class Xml_Class;
00078   static CppClassType xml_class_;
00079 
00080 private:
00081   // noncopyable
00082   Xml(const Xml&);
00083   Xml& operator=(const Xml&);
00084 
00085 protected:
00086   explicit Xml(const Glib::ConstructParams& construct_params);
00087   explicit Xml(GladeXML* castitem);
00088 
00089 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00090 
00091 public:
00092   virtual ~Xml();
00093 
00094 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00095   static GType get_type()      G_GNUC_CONST;
00096   static GType get_base_type() G_GNUC_CONST;
00097 #endif
00098 
00100   GladeXML*       gobj()       { return reinterpret_cast<GladeXML*>(gobject_); }
00101 
00103   const GladeXML* gobj() const { return reinterpret_cast<GladeXML*>(gobject_); }
00104 
00106   GladeXML* gobj_copy();
00107 
00108 private:
00109 
00110   
00111    //Ignore private glade_xml functions.
00112 
00113 protected:
00117   Xml(const std::string& filename, const Glib::ustring& root, const Glib::ustring& domain);
00118 
00122   Xml(const char* buffer, int size, const Glib::ustring& root, const Glib::ustring& domain);
00123 
00124   Gtk::Widget* get_widget_checked(const Glib::ustring& name, GType type);
00125   GtkWidget* get_cwidget(const Glib::ustring& name);
00126 
00127 public:
00128   typedef Gnome::Glade::XmlError Error;
00129 
00133   static Glib::RefPtr<Xml> create(const std::string& filename,
00134                                   const Glib::ustring& root   = Glib::ustring(),
00135                                   const Glib::ustring& domain = Glib::ustring());
00136 
00140   static Glib::RefPtr<Xml> create_from_buffer(const char* buffer, int size,
00141                                               const Glib::ustring& root   = Glib::ustring(),
00142                                               const Glib::ustring& domain = Glib::ustring());
00143 
00144    std::string get_filename() const;
00145  
00146 //void       glade_xml_signal_connect      (GladeXML *self,
00147 //                                        const char *handlername,
00148 //                                        GCallback func);
00149 //void       glade_xml_signal_connect_data (GladeXML *self,
00150 //                                        const char *handlername,
00151 //                                        GCallback func,
00152 //                                        gpointer user_data);
00153 //
00154 //void       glade_xml_signal_autoconnect  (GladeXML *self);
00155 //
00156 //
00157 //typedef void (*GladeXMLConnectFunc) (const gchar *handler_name,
00158 //                                   GObject *object,
00159 //                                   const gchar *signal_name,
00160 //                                   const gchar *signal_data,
00161 //                                   GObject *connect_object,
00162 //                                   gboolean after,
00163 //                                   gpointer user_data);
00164 //
00165 //
00166 //void       glade_xml_signal_connect_full     (GladeXML *self,
00167 //                                            const gchar *handler_name,
00168 //                                            GladeXMLConnectFunc func,
00169 //                                            gpointer user_data);
00170 //
00171 //void       glade_xml_signal_autoconnect_full (GladeXML *self,
00172 //                                            GladeXMLConnectFunc func,
00173 //                                            gpointer user_data);
00174 //
00175 //
00185   Gtk::Widget* get_widget(const Glib::ustring& name);
00186 
00200   template <class T_Widget> inline
00201   T_Widget* get_widget(const Glib::ustring& name, T_Widget*& widget)
00202   {
00203     // The dynamic_cast<> should never fail if get_widget_checked() succeeded.
00204     widget = dynamic_cast<T_Widget*>(this->get_widget_checked(name, T_Widget::get_base_type()));
00205 
00206     if(!widget)
00207       g_critical("Gnome::Glade::Xml::get_widget(): dynamic_cast<> failed.");
00208       
00209     return widget;
00210   }
00211 
00229   template <class T_Widget> inline
00230   T_Widget* get_widget_derived(const Glib::ustring& name, T_Widget*& widget)
00231   {
00232      // initialize input parameter
00233      widget = 0;
00234      
00235      // Get the widget from the glade file.
00236      typedef  typename T_Widget::BaseObjectType cwidget_type;
00237      cwidget_type* pCWidget = (cwidget_type*)get_cwidget(name);
00238 
00239      //The error was already reported by get_cwidget().
00240      if(!pCWidget)
00241        return 0;
00242 
00243      //Check whether there is already a C++ wrapper instance associated with this C instance:
00244      Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);
00245 
00246      //If there is already a C++ instance, then return it again:
00247      if(pObjectBase)
00248      {
00249        widget = dynamic_cast<T_Widget*>( Glib::wrap((GtkWidget*)pCWidget) );
00250        //Newer, more spec-complaint, versions of g++ not resolve a specific wrap() function in a template.
00251 
00252        //The dynamic cast checks that it is of the correct type.
00253        //Somebody might be trying to call get_widget_derived() after already calling get_widget(),
00254        //or after already calling get_widget_derived() with a different derived C++ type.
00255        if(!widget)
00256         g_critical("Gnome::Glade::Xml::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");      
00257      }
00258      else
00259      {
00260        //Create a new C++ instance to wrap the existing C instance:
00261        
00262        //Set the output variable. We needed to do this because we can not template the return type.
00263        Glib::RefPtr<Gnome::Glade::Xml> refThis(this);
00264        refThis->reference(); //take a copy.
00265        widget = new T_Widget(pCWidget, refThis);
00266      }
00267 
00268      //We return it as well (we need the parameter as well, because C++ can not just template the return type.)
00269      return widget;
00270   }
00271 
00272   
00273   Glib::ListHandle<Gtk::Widget*> get_widget_prefix(const Glib::ustring& name);
00274 
00276   void reparent_widget(const Glib::ustring& name, Gtk::Container& container);
00277 
00278   
00279   std::string relative_file(const std::string& filename) const;
00280 
00281   
00282   static Glib::ustring get_widget_name(Gtk::Widget& widget);
00283   
00284   static Glib::RefPtr<Xml> get_widget_tree(Gtk::Widget& widget);
00285 
00286               
00297   void connect_clicked(const Glib::ustring& name, const sigc::slot<void>& slot_);
00298 
00299 
00301 //typedef GtkWidget *(* GladeXMLCustomWidgetHandler) (GladeXML *xml,
00302 //                                                  gchar *func_name,
00303 //                                                  gchar *name,
00304 //                                                  gchar *string1,
00305 //                                                  gchar *string2,
00306 //                                                  gint int1,
00307 //                                                  gint int2,
00308 //                                                  gpointer user_data);
00309 
00310 //void glade_set_custom_handler(GladeXMLCustomWidgetHandler handler,
00311 //                            gpointer user_data);
00312 
00313 
00314 protected:
00315 
00316   
00317   virtual GType lookup_type_vfunc(const Glib::ustring& classname);
00318 
00319 
00320 public:
00321 
00322 public:
00323   //C++ methods used to invoke GTK+ virtual functions:
00324 #ifdef GLIBMM_VFUNCS_ENABLED
00325 #endif //GLIBMM_VFUNCS_ENABLED
00326 
00327 protected:
00328   //GTK+ Virtual Functions (override these to change behaviour):
00329 #ifdef GLIBMM_VFUNCS_ENABLED
00330 #endif //GLIBMM_VFUNCS_ENABLED
00331 
00332   //Default Signal Handlers::
00333 
00334 
00335 };
00336 
00337 } // namespace Glade
00338 } // namespace Gnome
00339 
00340 
00341 namespace Glib
00342 {
00348   Glib::RefPtr<Gnome::Glade::Xml> wrap(GladeXML* object, bool take_copy = false);
00349 }
00350 
00351 
00352 #endif /* _LIBGLADEMM_XML_H */
00353 

Generated on Mon Oct 2 01:01:41 2006 for gnomemm2 by  doxygen 1.4.6