00001
00002
00003 #ifndef _LIBGLADEMM_XML_H
00004 #define _LIBGLADEMM_XML_H
00005
00006 #include <glibmm.h>
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <gtkmm/container.h>
00028
00029
00030 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00031 typedef struct _GladeXML GladeXML;
00032 typedef struct _GladeXMLClass GladeXMLClass;
00033 #endif
00034
00035
00036 namespace Gnome
00037 {
00038
00039 namespace Glade
00040 { class Xml_Class; }
00041
00042 }
00043 namespace Gnome
00044 {
00045
00046 namespace Glade
00047 {
00048
00049 class XmlError : public Glib::Exception
00050 {
00051 public:
00052 explicit XmlError(const Glib::ustring& message);
00053 virtual ~XmlError() throw();
00054
00055 XmlError(const XmlError& other);
00056 XmlError& operator=(const XmlError& other);
00057
00058 virtual Glib::ustring what() const;
00059
00060 private:
00061 Glib::ustring message_;
00062 };
00063
00064
00065 class Xml : public Glib::Object
00066 {
00067
00068 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00069
00070 public:
00071 typedef Xml CppObjectType;
00072 typedef Xml_Class CppClassType;
00073 typedef GladeXML BaseObjectType;
00074 typedef GladeXMLClass BaseClassType;
00075
00076 private: friend class Xml_Class;
00077 static CppClassType xml_class_;
00078
00079 private:
00080
00081 Xml(const Xml&);
00082 Xml& operator=(const Xml&);
00083
00084 protected:
00085 explicit Xml(const Glib::ConstructParams& construct_params);
00086 explicit Xml(GladeXML* castitem);
00087
00088 #endif
00089
00090 public:
00091 virtual ~Xml();
00092
00093 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00094 static GType get_type() G_GNUC_CONST;
00095 static GType get_base_type() G_GNUC_CONST;
00096 #endif
00097
00099 GladeXML* gobj() { return reinterpret_cast<GladeXML*>(gobject_); }
00100
00102 const GladeXML* gobj() const { return reinterpret_cast<GladeXML*>(gobject_); }
00103
00104 GladeXML* gobj_copy();
00105
00106 private:
00107
00108
00109
00110
00111 protected:
00115 Xml(const std::string& filename, const Glib::ustring& root, const Glib::ustring& domain);
00116
00120 Xml(const char* buffer, int size, const Glib::ustring& root, const Glib::ustring& domain);
00121
00122 Gtk::Widget* get_widget_checked(const Glib::ustring& name, GType type);
00123 GtkWidget* get_cwidget(const Glib::ustring& name);
00124
00125 public:
00126 typedef Gnome::Glade::XmlError Error;
00127
00131 static Glib::RefPtr<Xml> create(const std::string& filename,
00132 const Glib::ustring& root = Glib::ustring(),
00133 const Glib::ustring& domain = Glib::ustring());
00134
00138 static Glib::RefPtr<Xml> create_from_buffer(const char* buffer, int size,
00139 const Glib::ustring& root = Glib::ustring(),
00140 const Glib::ustring& domain = Glib::ustring());
00141
00142 std::string get_filename() const;
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00183 Gtk::Widget* get_widget(const Glib::ustring& name);
00184
00198 template <class T_Widget> inline
00199 T_Widget* get_widget(const Glib::ustring& name, T_Widget*& widget)
00200 {
00201
00202 widget = dynamic_cast<T_Widget*>(this->get_widget_checked(name, T_Widget::get_base_type()));
00203
00204 if(!widget)
00205 g_critical("Gnome::Glade::Xml::get_widget(): dynamic_cast<> failed.");
00206
00207 return widget;
00208 }
00209
00227 template <class T_Widget> inline
00228 T_Widget* get_widget_derived(const Glib::ustring& name, T_Widget*& widget)
00229 {
00230
00231 widget = 0;
00232
00233
00234 typedef typename T_Widget::BaseObjectType cwidget_type;
00235 cwidget_type* pCWidget = (cwidget_type*)get_cwidget(name);
00236
00237
00238 if(!pCWidget)
00239 return 0;
00240
00241
00242 Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);
00243
00244
00245 if(pObjectBase)
00246 {
00247 widget = dynamic_cast<T_Widget*>( Glib::wrap(pCWidget) );
00248
00249
00250
00251
00252 if(!widget)
00253 g_critical("Gnome::Glade::Xml::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");
00254 }
00255 else
00256 {
00257
00258
00259
00260 Glib::RefPtr<Gnome::Glade::Xml> refThis(this);
00261 refThis->reference();
00262 widget = new T_Widget(pCWidget, refThis);
00263 }
00264
00265
00266 return widget;
00267 }
00268
00269
00270 Glib::ListHandle<Gtk::Widget*> get_widget_prefix(const Glib::ustring& name);
00271
00273 void reparent_widget(const Glib::ustring& name, Gtk::Container& container);
00274
00275
00276 std::string relative_file(const std::string& filename) const;
00277
00278
00279 static Glib::ustring get_widget_name(Gtk::Widget& widget);
00280
00281 static Glib::RefPtr<Xml> get_widget_tree(Gtk::Widget& widget);
00282
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 protected:
00298
00299
00300 virtual GType lookup_type_vfunc(const Glib::ustring& classname);
00301
00302
00303 public:
00304
00305 public:
00306
00307
00308 protected:
00309
00310
00311
00312
00313
00314 };
00315
00316 }
00317 }
00318
00319
00320 namespace Glib
00321 {
00323 Glib::RefPtr<Gnome::Glade::Xml> wrap(GladeXML* object, bool take_copy = false);
00324 }
00325
00326
00327 #endif
00328