00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GNOMEMM_APP_HELPER_H
00022 #define GNOMEMM_APP_HELPER_H
00023
00024 #include <new>
00025 #include <gtkmm/menushell.h>
00026 #include <gtkmm/toolbar.h>
00027 #include <gtkmm/accelgroup.h>
00028 #include <libgnomeuimm/ui-items-icon.h>
00029 #include <libgnomeui/gnome-app.h>
00030 #include <libgnomeui/gnome-app-helper.h>
00031 #include <vector>
00032
00033 namespace Gnome
00034 {
00035
00036 namespace UI
00037 {
00038
00039 namespace Items
00040 {
00041
00042 class Icon;
00043
00044
00045
00046
00047
00048 template<class T_Info>
00049 class Array;
00050
00051 class InfoData;
00052
00053
00054
00055
00056 class Info : public GnomeUIInfo
00057 {
00058 friend class InfoData;
00059 friend class Array<Info>;
00060
00061
00062 void* operator new(size_t s);
00063 public:
00064 void* operator new(size_t s, void* v) {return ::operator new(s, v);}
00065
00066 Info();
00067 Info(const Info& src);
00068 ~Info();
00069 Info& operator=(const Info& src);
00070
00071 Gtk::Widget* get_widget();
00072 const Gtk::Widget* get_widget() const;
00073
00074 enum Type
00075 {
00076 END = GNOME_APP_UI_ENDOFINFO,
00077 ITEM = GNOME_APP_UI_ITEM,
00078 TOGGLEITEM = GNOME_APP_UI_TOGGLEITEM,
00079 RADIOITEMS = GNOME_APP_UI_RADIOITEMS,
00080 SUBTREE = GNOME_APP_UI_SUBTREE,
00081 SEPARATOR = GNOME_APP_UI_SEPARATOR,
00082 HELP = GNOME_APP_UI_HELP,
00083 BUILDER = GNOME_APP_UI_BUILDER_DATA,
00084 CONFIGURABLE = GNOME_APP_UI_ITEM_CONFIGURABLE,
00085 SUBTREE_STOCK = GNOME_APP_UI_SUBTREE_STOCK
00086 };
00087
00088 Type type() const;
00089
00090 const gchar* debug_get_icon_info() const;
00091
00092 void set_accel(const Gtk::AccelKey& ak = Gtk::AccelKey());
00093
00094 typedef sigc::slot<void> Callback;
00095
00096 protected:
00097 void init(Type type_);
00098 void init_cb(Type type_, const Icon& icon,
00099 const Glib::ustring& label, const Callback& cb,
00100 const Glib::ustring& tooltip);
00101 void init_sub(Type type_, const Icon& icon,
00102 const Glib::ustring& label, const Array<Info>& sub,
00103 const Glib::ustring& tooltip);
00104 InfoData* init_common(Type type_, const Icon& icon_,
00105 const Glib::ustring& label_, const Glib::ustring& hint_);
00106
00107 InfoData* get_data_();
00108 const InfoData* get_data_() const;
00109
00110 void set_data_(InfoData* infodata);
00111 };
00112
00113
00114
00115
00116
00117
00118
00119 class SubTree : public Info
00120 {
00121 protected:
00122 SubTree();
00123 public:
00124 SubTree(const Glib::ustring& label, const Array<Info>& uitree,
00125 const Glib::ustring& tip = Glib::ustring());
00126 SubTree(const Icon& icon, const Glib::ustring& label,
00127 const Array<Info>& uitree, const Glib::ustring& tip = Glib::ustring());
00128 ~SubTree();
00129
00130 Array<Info>& get_uitree();
00131 };
00132 typedef SubTree Menu;
00133
00134
00135
00136 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00137
00138 class Begin : public Info
00139 {
00140 public:
00141 Begin();
00142
00143 private:
00144 static GnomeUIBuilderData build_data_;
00145 };
00146
00147
00148 class End : public Info
00149 {
00150 public:
00151 End();
00152 };
00153 #endif
00154
00155 namespace Array_Helpers
00156 {
00157
00158 template<class T>
00159 struct Traits
00160 {
00161 typedef typename T::const_iterator iterator;
00162 static iterator begin(const T& t) {return t.begin();}
00163 static iterator end(const T& t) {return t.end();}
00164 };
00165
00166
00167 template<class T_Info>
00168 struct Traits<T_Info*>
00169 {
00170 typedef const T_Info* iterator;
00171 static iterator begin(const T_Info* t) {return t;}
00172 static iterator end( T_Info* t) {return t+64;}
00173 };
00174
00175 template<size_t N, class T_Info>
00176 struct Traits<T_Info[N]>
00177 {
00178 typedef const T_Info* iterator;
00179 static iterator begin(const T_Info* t) {return t;}
00180 static iterator end(const T_Info* t) {return &t[N];}
00181 };
00182
00183 }
00184
00185
00186
00187
00188 template<class T_Info>
00189 class Array
00190 {
00191
00192 Info* data_;
00193 Info* begin_;
00194 int size_;
00195
00196 template <class I> void create(I b, I e);
00197 public:
00198 typedef T_Info value_type;
00199 typedef T_Info& reference_type;
00200 typedef T_Info* iterator;
00201 typedef T_Info* const const_iterator;
00202 typedef T_Info* const pointer;
00203 typedef T_Info* const const_pointer;
00204 typedef size_t size_type;
00205 typedef ptrdiff_t difference_type;
00206
00207 Array& operator=(const Array& a)
00208 {
00209 if (this == &a)
00210 return *this;
00211
00212 delete [] data_;
00213 data_ = 0;
00214 size_ = 0;
00215
00216 create(a.begin(), a.end());
00217 return *this;
00218 }
00219
00220 Array()
00221 : data_(0), begin_(0), size_(0)
00222 { create((T_Info*)0, (T_Info*)0); }
00223
00224 Array(Array& a)
00225 : data_(0), begin_(0), size_(0)
00226 { create(a.begin(), a.end()); }
00227
00228 template <class T>
00229 Array(const T& t)
00230 : data_(0), begin_(0), size_(0)
00231 { create(Array_Helpers::Traits<T>::begin(t),
00232 Array_Helpers::Traits<T>::end(t));
00233 }
00234
00235 template <class I>
00236 Array(I b, I e)
00237 : data_(0), begin_(0), size_(0)
00238 { create(b, e); }
00239
00240 ~Array()
00241 {
00242 delete [] data_;
00243 data_ = 0;
00244 size_ = 0;
00245 }
00246
00247 size_t size() const { return size_; }
00248
00249 iterator begin() const
00250 { return static_cast<T_Info*>(begin_); }
00251
00252 iterator end() const
00253 { return static_cast<T_Info*>(begin_ + size_); }
00254
00255 reference_type operator[](size_t n) const
00256 { return static_cast<T_Info&>(begin_[n]); }
00257
00258
00259 GnomeUIInfo* gobj() const
00260 { return static_cast<GnomeUIInfo*>(data_); }
00261
00262 };
00263
00264
00265 template <class T_Info>
00266 template <class I>
00267 void
00268 Array<T_Info>::create(I b, I e)
00269 {
00270
00271
00272 if (b == e)
00273 {
00274 data_ = new End[1];
00275 return;
00276 }
00277
00278
00279 for (I b2 = b ; b2 != e; ++b2, ++size_)
00280 {
00281 if (b2->type() == Info::END)
00282 break;
00283 }
00284
00285
00286 if (b->type() != Info::BUILDER)
00287 {
00288 begin_ = data_ = new Info[size_+2];
00289 new (begin_) Begin();
00290 begin_++;
00291 }
00292 else
00293 begin_ = data_ = new Info[size_+1];
00294
00295
00296 for (int i = 0; b != e; ++b, ++i)
00297 {
00298 new (&begin_[i]) T_Info(*b);
00299 }
00300
00301 new (&begin_[size_]) End();
00302
00303
00304
00305 }
00306
00307
00308 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00309
00310
00311
00312
00313 class InfoData
00314 {
00315 public:
00316 InfoData();
00317 InfoData(const Glib::ustring& label, const Glib::ustring& hint, const Icon& icon = Icon());
00318
00319 private:
00320 InfoData(const InfoData&);
00321 protected:
00322 virtual ~InfoData();
00323
00324 public:
00325
00326 void ref();
00327 void unref();
00328
00329 virtual void connect(Info&);
00330
00331 typedef sigc::slot<void> Callback;
00332
00333 void set_callback(const Callback& callback);
00334 void set_subtree(const Array<Info>& subtree);
00335 Array<Info>& get_subtree();
00336
00337
00338 Callback callback_;
00339 Array<Info> subtree_;
00340 Glib::ustring label_;
00341 Glib::ustring hint_;
00342 Icon icon_;
00343
00344 private:
00345 int ref_count_;
00346 };
00347 #endif
00348
00349
00353 Items::Array<Info> fill (Gtk::MenuShell &menu_shell,
00354 const Items::Array<Info> &info,
00355 const Glib::RefPtr<Gtk::AccelGroup> &accel_group,
00356 bool uline_accels = true,
00357 int pos = 0);
00358
00359
00363 Items::Array<Info> fill (Gtk::Toolbar &toolbar,
00364 const Items::Array<Info> &info,
00365 const Glib::RefPtr<Gtk::AccelGroup> &accel_group);
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 }
00382 }
00383 }
00384
00385 #endif //GNOMEMM_APP_HELPER_H