00001
00002
00003 #ifndef _LIBGLADEMM_XML_H
00004 #define _LIBGLADEMM_XML_H
00005
00006
00007 #include <glibmm.h>
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00035
00036
00037 namespace Gnome
00038 {
00039
00040 namespace Glade
00041 { class Xml_Class; }
00042
00043 }
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
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
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
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
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
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
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
00233 widget = 0;
00234
00235
00236 typedef typename T_Widget::BaseObjectType cwidget_type;
00237 cwidget_type* pCWidget = (cwidget_type*)get_cwidget(name);
00238
00239
00240 if(!pCWidget)
00241 return 0;
00242
00243
00244 Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);
00245
00246
00247 if(pObjectBase)
00248 {
00249 widget = dynamic_cast<T_Widget*>( Glib::wrap((GtkWidget*)pCWidget) );
00250
00251
00252
00253
00254
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
00261
00262
00263 Glib::RefPtr<Gnome::Glade::Xml> refThis(this);
00264 refThis->reference();
00265 widget = new T_Widget(pCWidget, refThis);
00266 }
00267
00268
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
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 protected:
00315
00316
00317 virtual GType lookup_type_vfunc(const Glib::ustring& classname);
00318
00319
00320 public:
00321
00322 public:
00323
00324 #ifdef GLIBMM_VFUNCS_ENABLED
00325 #endif //GLIBMM_VFUNCS_ENABLED
00326
00327 protected:
00328
00329 #ifdef GLIBMM_VFUNCS_ENABLED
00330 #endif //GLIBMM_VFUNCS_ENABLED
00331
00332
00333
00334
00335 };
00336
00337 }
00338 }
00339
00340
00341 namespace Glib
00342 {
00348 Glib::RefPtr<Gnome::Glade::Xml> wrap(GladeXML* object, bool take_copy = false);
00349 }
00350
00351
00352 #endif
00353