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_W
idget>
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
Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((
GObject*)pCWidget);
00239
00240
00241
if(pObjectBase)
00242 {
00243 widget = dynamic_cast<T_Widget*>(
Glib::wrap(pCWidget) );
00244
00245
00246
00247
00248
if(!widget)
00249 g_critical(
"Gnome::Glade::Xml::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");
00250 }
00251
else
00252 {
00253
00254
00255
00256
Glib::RefPtr<Gnome::Glade::Xml> refThis(
this);
00257 refThis->reference();
00258 widget =
new T_Widget(pCWidget, refThis);
00259 }
00260
00261
00262
return widget;
00263 }
00264
00265
00266
Glib::ListHandle<Gtk::Widget*> get_widget_prefix(
const Glib::ustring& name);
00267
00269
void reparent_widget(
const Glib::ustring& name,
Gtk::Container& container);
00270
00271
00272 std::string relative_file(
const std::string& filename)
const;
00273
00274
00275
static Glib::ustring get_widget_name(
Gtk::Widget& widget);
00276
00277
static Glib::RefPtr<Xml> get_widget_tree(
Gtk::Widget& widget);
00278
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
protected:
00294
00295
00296
virtual GType lookup_type_vfunc(
const Glib::ustring& classname);
00297
00298
00299
public:
00300
00301
public:
00302
00303
00304
protected:
00305
00306
00307
00308
00309
00310 };
00311
00312 }
00313 }
00314
00315
00316
namespace Glib
00317 {
00319
Glib::RefPtr<Gnome::Glade::Xml> wrap(GladeXML* object,
bool take_copy =
false);
00320 }
00321
00322
00323
#endif
00324