libgnomeuimm 2.28.0
app-helper.h
Go to the documentation of this file.
1/*
2 * Copyright 2000 Karl Nelson
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * UIInfo "huffs goat choad" but we will try to make the best of it.
19 */
20
21#ifndef GNOMEMM_APP_HELPER_H
22#define GNOMEMM_APP_HELPER_H
23
24#include <new>
25#include <gtkmm/menushell.h>
26#include <gtkmm/toolbar.h>
27#include <gtkmm/accelgroup.h>
29#include <libgnomeui/gnome-app.h>
30#include <libgnomeui/gnome-app-helper.h>
31#include <vector>
32
33namespace Gnome
34{
35
36namespace UI
37{
38
39namespace Items
40{
41
42class Icon;
43
44/*******************************************************/
45// Info is the base of the UI item tree it represents broad types
46// of GUI items for construction later.
47
48template<class T_Info>
49class Array;
50
51class InfoData;
52
53/*** Derived GnomeUIInfo
54 * Note: When deriving this, you must not add any fields or add any virtuals
55 */
56class Info : public GnomeUIInfo
57{
58 friend class InfoData;
59 friend class Array<Info>;
60
61 // must not be dynamic
62 void* operator new(size_t s);
63public:
64 void* operator new(size_t s, void* v) {return ::operator new(s, v);}
65
67 Info(const Info& src);
69 Info& operator=(const Info& src);
70
71 Gtk::Widget* get_widget();
72 const Gtk::Widget* get_widget() const;
73
74 enum Type
75 {
76 END = GNOME_APP_UI_ENDOFINFO,
77 ITEM = GNOME_APP_UI_ITEM,
78 TOGGLEITEM = GNOME_APP_UI_TOGGLEITEM,
79 RADIOITEMS = GNOME_APP_UI_RADIOITEMS,
80 SUBTREE = GNOME_APP_UI_SUBTREE,
81 SEPARATOR = GNOME_APP_UI_SEPARATOR,
82 HELP = GNOME_APP_UI_HELP,
83 BUILDER = GNOME_APP_UI_BUILDER_DATA,
84 CONFIGURABLE = GNOME_APP_UI_ITEM_CONFIGURABLE,
85 SUBTREE_STOCK = GNOME_APP_UI_SUBTREE_STOCK
86 };
87
88 Type type() const;
89
90 const gchar* debug_get_icon_info() const;
91
92 void set_accel(const Gtk::AccelKey& ak = Gtk::AccelKey());
93
94 typedef sigc::slot<void> Callback;
95
96protected:
97 void init(Type type_);
98 void init_cb(Type type_, const Icon& icon,
99 const Glib::ustring& label, const Callback& cb,
100 const Glib::ustring& tooltip);
101 void init_sub(Type type_, const Icon& icon,
102 const Glib::ustring& label, const Array<Info>& sub,
103 const Glib::ustring& tooltip);
104 InfoData* init_common(Type type_, const Icon& icon_,
105 const Glib::ustring& label_, const Glib::ustring& hint_);
106
108 const InfoData* get_data_() const;
109
110 void set_data_(InfoData* infodata);
111};
112
113
114
115
116
117
118// subtree or submenu
119class SubTree : public Info
120{
121protected:
123public:
124 SubTree(const Glib::ustring& label, const Array<Info>& uitree,
125 const Glib::ustring& tip = Glib::ustring());
126 SubTree(const Icon& icon, const Glib::ustring& label,
127 const Array<Info>& uitree, const Glib::ustring& tip = Glib::ustring());
129
131};
132typedef SubTree Menu;
133
134
135
136#ifndef DOXYGEN_SHOULD_SKIP_THIS
137// begin marker for C structures (not really for user use)
138class Begin : public Info
139{
140public:
141 Begin();
142
143private:
144 static GnomeUIBuilderData build_data_;
145};
146
147// end marker for C structures (not really for user use)
148class End : public Info
149{
150public:
151 End();
152};
153#endif /* DOXYGEN_SHOULD_SKIP_THIS */
154
155namespace Array_Helpers
156{
157
158template<class T>
159struct Traits
160{
161 typedef typename T::const_iterator iterator;
162 static iterator begin(const T& t) {return t.begin();}
163 static iterator end(const T& t) {return t.end();}
164};
165
166// You must place an End() to use this type
167template<class T_Info>
168struct Traits<T_Info*>
169{
170 typedef const T_Info* iterator;
171 static iterator begin(const T_Info* t) {return t;}
172 static iterator end( T_Info* t) {return t+64;} //64?
173};
174
175template<size_t N, class T_Info>
176struct Traits<T_Info[N]>
177{
178 typedef const T_Info* iterator;
179 static iterator begin(const T_Info* t) {return t;}
180 static iterator end(const T_Info* t) {return &t[N];}
181};
182
183} /* namespace Array_Helpers */
184
185
186
187// Array converter class
188template<class T_Info>
189class Array
190{
191 //void* operator new (size_t s); // not implemented
192 Info* data_;
193 Info* begin_;
194 int size_;
195
196 template <class I> void create(I b, I e);
197public:
198 typedef T_Info value_type;
199 typedef T_Info& reference_type;
200 typedef T_Info* iterator;
201 typedef T_Info* const const_iterator;
202 typedef T_Info* const pointer;
203 typedef T_Info* const const_pointer;
204 typedef size_t size_type;
205 typedef ptrdiff_t difference_type;
206
208 {
209 if (this == &a)
210 return *this;
211
212 delete [] data_;
213 data_ = 0;
214 size_ = 0;
215
216 create(a.begin(), a.end());
217 return *this;
218 }
219
221 : data_(0), begin_(0), size_(0)
222 { create((T_Info*)0, (T_Info*)0); }
223
225 : data_(0), begin_(0), size_(0)
226 { create(a.begin(), a.end()); }
227
228 template <class T>
229 Array(const T& t)
230 : data_(0), begin_(0), size_(0)
233 }
234
235 template <class I>
236 Array(I b, I e)
237 : data_(0), begin_(0), size_(0)
238 { create(b, e); }
239
241 {
242 delete [] data_;
243 data_ = 0;
244 size_ = 0;
245 }
246
247 size_t size() const { return size_; }
248
250 { return static_cast<T_Info*>(begin_); }
251
252 iterator end() const
253 { return static_cast<T_Info*>(begin_ + size_); }
254
256 { return static_cast<T_Info&>(begin_[n]); }
257
258
260 { return static_cast<GnomeUIInfo*>(data_); }
261
262};
263
264
265template <class T_Info>
266template <class I>
267void
268Array<T_Info>::create(I b, I e)
269{
270
271 // NULL list
272 if (b == e)
273 {
274 data_ = new End[1];
275 return;
276 }
277
278 // determine number of Items
279 for (I b2 = b ; b2 != e; ++b2, ++size_)
280 {
281 if (b2->type() == Info::END)
282 break;
283 }
284
285 // must have a builder data on head
286 if (b->type() != Info::BUILDER)
287 {
288 begin_ = data_ = new Info[size_+2]; //plus space for BEGIN and END.
289 new (begin_) Begin(); //constructor without allocation.
290 begin_++; //Hide Begin() element from outside, by keeping it before begin().
291 }
292 else
293 begin_ = data_ = new Info[size_+1]; //plus space for END.
294
295 // Copy data
296 for (int i = 0; b != e; ++b, ++i)
297 {
298 new (&begin_[i]) T_Info(*b); //constructor without allocation.
299 }
300
301 new (&begin_[size_]) End(); //constructor without allocation.
302
303 //At this point _size excludes the Begin() and End() GNOME internals elements,
304 //so users of begin() and end() will never see them.
305}
306
307
308#ifndef DOXYGEN_SHOULD_SKIP_THIS
309// This is a refcounted holder to deal with C interface badness
310// users don't need to deal with these unless they are making new Info types.
311// This is probably refcounted because that's easier than copying in copy constructors, given that we can't
312// add member data to the Info class.
313class InfoData
314{
315public:
316 InfoData();
317 InfoData(const Glib::ustring& label, const Glib::ustring& hint, const Icon& icon = Icon());
318
319private:
320 InfoData(const InfoData&); //Prevent use of copy constructor.
321protected:
322 virtual ~InfoData();
323
324public:
325
326 void ref();
327 void unref();
328
329 virtual void connect(Info&);
330
331 typedef sigc::slot<void> Callback;
332
333 void set_callback(const Callback& callback);
334 void set_subtree(const Array<Info>& subtree);
335 Array<Info>& get_subtree();
336
337
338 Callback callback_;
339 Array<Info> subtree_;
340 Glib::ustring label_;
341 Glib::ustring hint_;
342 Icon icon_;
343
344private:
345 int ref_count_;
346};
347#endif /* DOXYGEN_SHOULD_SKIP_THIS */
348
349
353Items::Array<Info> fill (Gtk::MenuShell &menu_shell,
354 const Items::Array<Info> &info,
355 const Glib::RefPtr<Gtk::AccelGroup> &accel_group,
356 bool uline_accels = true,
357 int pos = 0);
358
359
363Items::Array<Info> fill (Gtk::Toolbar &toolbar,
364 const Items::Array<Info> &info,
365 const Glib::RefPtr<Gtk::AccelGroup> &accel_group);
366
367
368
369//: Utility functions for Gtk::MenuShell.
370//- These should really be member methods of Gtk::MenuShell,
371//- but they're part of gnomeui, not gtk, and they didn't subclass GtkMenuShell.
372//static Gtk::MenuShell* MenuShell_find_menu_pos(const Gtk::MenuShell& parent,
373// const Glib::ustring &path,
374// int& pos);
375
376//IGNORED gnome_app_fill_menu_with_data()
377//IGNORED gnome_app_fill_menu_custom()
378//IGNORED gnome_app_fill_toolbar_with_data()
379//IGNORED gnome_app_fill_toolbar_custom()
380
381} /* namespace Items */
382} /* namespace UI */
383} /* namespace Gnome */
384
385#endif //GNOMEMM_APP_HELPER_H
Definition: app-helper.h:190
Array(const T &t)
Definition: app-helper.h:229
size_t size_type
Definition: app-helper.h:204
size_t size() const
Definition: app-helper.h:247
iterator begin() const
Definition: app-helper.h:249
T_Info *const const_iterator
Definition: app-helper.h:201
T_Info & reference_type
Definition: app-helper.h:199
ptrdiff_t difference_type
Definition: app-helper.h:205
Array(I b, I e)
Definition: app-helper.h:236
T_Info value_type
Definition: app-helper.h:198
GnomeUIInfo * gobj() const
Definition: app-helper.h:259
Array(Array &a)
Definition: app-helper.h:224
T_Info * iterator
Definition: app-helper.h:200
T_Info *const pointer
Definition: app-helper.h:202
reference_type operator[](size_t n) const
Definition: app-helper.h:255
~Array()
Definition: app-helper.h:240
Array()
Definition: app-helper.h:220
T_Info *const const_pointer
Definition: app-helper.h:203
Array & operator=(const Array &a)
Definition: app-helper.h:207
iterator end() const
Definition: app-helper.h:252
Icons represent a standard Pixmap with various states.
Definition: ui-items-icon.h:39
Definition: app-helper.h:57
InfoData * get_data_()
Type
Definition: app-helper.h:75
@ HELP
Definition: app-helper.h:82
@ SEPARATOR
Definition: app-helper.h:81
@ SUBTREE
Definition: app-helper.h:80
@ BUILDER
Definition: app-helper.h:83
@ END
Definition: app-helper.h:76
@ TOGGLEITEM
Definition: app-helper.h:78
@ RADIOITEMS
Definition: app-helper.h:79
@ SUBTREE_STOCK
Definition: app-helper.h:85
@ ITEM
Definition: app-helper.h:77
@ CONFIGURABLE
Definition: app-helper.h:84
Gtk::Widget * get_widget()
friend class InfoData
Definition: app-helper.h:58
void set_data_(InfoData *infodata)
const gchar * debug_get_icon_info() const
const Gtk::Widget * get_widget() const
void init_cb(Type type_, const Icon &icon, const Glib::ustring &label, const Callback &cb, const Glib::ustring &tooltip)
InfoData * init_common(Type type_, const Icon &icon_, const Glib::ustring &label_, const Glib::ustring &hint_)
Info & operator=(const Info &src)
void set_accel(const Gtk::AccelKey &ak=Gtk::AccelKey())
Info(const Info &src)
void init(Type type_)
sigc::slot< void > Callback
Definition: app-helper.h:94
void init_sub(Type type_, const Icon &icon, const Glib::ustring &label, const Array< Info > &sub, const Glib::ustring &tooltip)
const InfoData * get_data_() const
Definition: app-helper.h:120
SubTree(const Glib::ustring &label, const Array< Info > &uitree, const Glib::ustring &tip=Glib::ustring())
Array< Info > & get_uitree()
SubTree(const Icon &icon, const Glib::ustring &label, const Array< Info > &uitree, const Glib::ustring &tip=Glib::ustring())
Items::Array< Info > fill(Gtk::MenuShell &menu_shell, const Items::Array< Info > &info, const Glib::RefPtr< Gtk::AccelGroup > &accel_group, bool uline_accels=true, int pos=0)
Fill a menu with Items::Info items.
SubTree Menu
Definition: app-helper.h:132
Definition: about.h:46
sigc::slot< void > Callback
Definition: types.h:30
static iterator end(T_Info *t)
Definition: app-helper.h:172
static iterator begin(const T_Info *t)
Definition: app-helper.h:171
const T_Info * iterator
Definition: app-helper.h:170
static iterator begin(const T_Info *t)
Definition: app-helper.h:179
static iterator end(const T_Info *t)
Definition: app-helper.h:180
const T_Info * iterator
Definition: app-helper.h:178
Definition: app-helper.h:160
static iterator begin(const T &t)
Definition: app-helper.h:162
static iterator end(const T &t)
Definition: app-helper.h:163
T::const_iterator iterator
Definition: app-helper.h:161