Main Page - Header
Author: The Inti Development Team

Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# itemfactory.h

Go to the documentation of this file.

    00001 /*  Inti: Integrated Foundation Classes
    00002  *  Copyright (C) 2002 The Inti Development Team.
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  */
    00018
    00035
    00036 #ifndef INTI_GTK_ITEM_FACTORY_H
    00037 #define INTI_GTK_ITEM_FACTORY_H
    00038
    00039 #ifndef INTI_GTK_OBJECT_H
    00040 #include <inti/gtk/object.h>
    00041 #endif
    00042
    00043 #ifndef __GTK_ITEM_FACTORY_H__
    00044 #include <gtk/gtkitemfactory.h>
    00045 #endif
    00046
    00047 #ifndef _CPP_VECTOR
    00048 #include <vector>
    00049 #endif
    00050
    00051 namespace Inti {
    00052
    00053 namespace G {
    00054 class Scanner;
    00055 }
    00056
    00057 namespace Gtk {
    00058
    00059 class AccelGroup;
    00060 class ItemFactoryClass;
    00061 class MenuBar;
    00062 class Menu;
    00063 class MenuItem;
    00064 class OptionMenu;
    00065 class Widget;
    00066
    00096
    00097 template<typename T> struct ItemFactoryEntry
    00098 {
    00099         typedef void (T::*PMF)();
    00100         const char *path;
    00101         const char *accelerator;
    00102         GtkItemFactoryCallback callback;
    00103         unsigned int callback_action;
    00104         const char *item_type;
    00105         const void* image_item_or_stock_item;
    00106         PMF pmf;
    00107 };
    00108
    00154
    00155 class ItemFactory : public Object
    00156 {
    00157         friend class G::Object;
    00158         friend class ItemFactoryClass;
    00159
    00160         ItemFactory(const ItemFactory&);
    00161         ItemFactory& operator=(const ItemFactory&);
    00162
    00163 protected:
    00166
    00167         explicit ItemFactory(GtkItemFactory *item_factory, bool reference = true);
    00174
    00176
    00177 public:
    00178         typedef Slot0<void> DestroySlot;
    00184
    00187
    00188         ItemFactory();
    00191
    00192         ItemFactory(GType container_type, const char *path, AccelGroup *accel_group = 0);
    00199
    00200         virtual ~ItemFactory();
    00202
    00206
    00207         GtkItemFactory* gtk_item_factory() const { return (GtkItemFactory*)instance; }
    00209
    00210         GtkItemFactoryClass* gtk_item_factory_class() const;
    00212
    00213         operator GtkItemFactory* () const;
    00215
    00216         AccelGroup* accel_group() const;
    00218
    00219         MenuBar* menu_bar() const;
    00221
    00222         Menu* menu() const;
    00224
    00225         OptionMenu* option_menu() const;
    00227
    00228         Menu* submenu(const char* path) const;
    00232
    00233         Menu* submenu_by_action(unsigned int action) const;
    00239
    00240         MenuItem* get_item(const char *path) const;
    00244
    00245         MenuItem* get_item_by_action(unsigned int action) const;
    00249
    00251
    00252         static String path_from_widget(const Widget& widget);
    00260
    00261         static String path_from_entry(const char *entry_path);
    00270
    00273
    00274         void delete_item(const char *path);
    00277
    00278         void popup(unsigned int x, unsigned int y, unsigned int mouse_button, unsigned int time = GDK_CURRENT_TIME);
    00291
    00292         void popup(unsigned int x, unsigned int y, unsigned int mouse_button, const DestroySlot *destroy, unsigned int time = GDK_CURRENT_TIME);
    00306
    00308
    00309         static ItemFactory* from_widget(const Widget& widget);
    00313
    00316
    00317         template<typename T>
    00318         void create_item(T& owner, ItemFactoryEntry<T>& entry)
    00319         {
    00320                 gtk_item_factory_create_item(gtk_item_factory(), reinterpret_cast<GtkItemFactoryEntry*>(&entry), 0, 1);
    00321                 if (entry.pmf)
    00322                         get_item(path_from_entry(entry.path).c_str())->sig_activate().connect(slot(&owner, entry.pmf));
    00323         }
    00327
    00328         template<typename T>
    00329         void create_items(T& owner, std::vector<ItemFactoryEntry<T>*>& entries)
    00330         {
    00331                 g_return_if_fail(!entries.empty());
    00332                 for (int i = 0; i < entries.size(); i++)
    00333                         create_item(owner, *entries[i]);
    00334         }
    00338
    00339         template<typename T>
    00340         void create_items(T& owner)
    00341         {
    00342                 int i = 0;
    00343                 while (owner.item_factory_map[i].path)
    00344                 {
    00345                         create_item(owner, owner.item_factory_map[i]);
    00346                         i++;
    00347                 }
    00348         }
    00351
    00352         template<typename T>
    00353         void delete_entry(ItemFactoryEntry<T>& entry)
    00354         {
    00355                 gtk_item_factory_delete_entry(gtk_item_factory(), reinterpret_cast<GtkItemFactoryEntry*>(&entry));
    00356         }
    00359
    00360         template<typename T>
    00361         void delete_entries(std::vector<ItemFactoryEntry<T>*>& entries)
    00362         {
    00363                 g_return_if_fail(!entries.empty());
    00364                 for (int i = 0; i < entries.size(); i++)
    00365                         delete_entry(*entries[i]);
    00366         }
    00369
    00370         template<typename T>
    00371         void delete_entries(T& owner)
    00372         {
    00373                 int i = 0;
    00374                 while ((owner.item_factory_map[i]).path)
    00375                 {
    00376                         delete_entry(item_factory_map[i]);
    00377                         i++;
    00378                 }
    00379         }
    00382
    00384 };
    00385
    00386 } // namespace Gtk
    00387
    00388 } // namespace Inti
    00389
    00392
    00393 #define DECLARE_ITEM_FACTORY_MAP(klass)\
    00394 private:\
    00395         friend class Gtk::ItemFactory;\
    00396         static Inti::Gtk::ItemFactoryEntry< klass > item_factory_map[];\
    00397         typedef Inti::Gtk::ItemFactoryEntry< klass >::PMF MyPMF;\
    00398         typedef klass MyClass;\
    00399 public:
    00400
    00403
    00404 #define BEGIN_ITEM_FACTORY_MAP(klass)\
    00405         Inti::Gtk::ItemFactoryEntry< klass > klass::item_factory_map[] = {
    00406
    00408
    00409 #define END_ITEM_FACTORY_MAP\
    00410         { 0, 0, 0, 0, 0, 0, 0 }};
    00411
    00416
    00417 #define IFM_TITLE(path, accelerator, function)\
    00418         { path, accelerator, 0, 0, "<Title>", 0, (MyPMF)&MyClass::function }
    00419
    00424
    00425 #define IFM_ITEM(path, accelerator, function)\
    00426         { path, accelerator, 0, 0, "<Item>", 0, (MyPMF)&MyClass::function }
    00427
    00433
    00434 #define IFM_IMAGE_ITEM(path, accelerator, function, pixbuf_stream)\
    00435         { path, accelerator, 0, 0, "<ImageItem>", pixbuf_stream, (MyPMF)&MyClass::function }
    00436
    00442
    00443 #define IFM_STOCK_ITEM(path, accelerator, function, stock_id)\
    00444         { path, accelerator, 0, 0, "<StockItem>", (gconstpointer)stock_id, (MyPMF)&MyClass::function }
    00445
    00450
    00451 #define IFM_CHECK_ITEM(path, accelerator, function)\
    00452         { path, accelerator, 0, 0, "<CheckItem>", 0, (MyPMF)&MyClass::function }
    00453
    00458
    00459 #define IFM_TOGGLE_ITEM(path, accelerator, function)\
    00460         { path, accelerator, 0, 0, "<CheckItem>", 0, (MyPMF)&MyClass::function }
    00461
    00471
    00472 #define IFM_RADIO_ITEM(path, accelerator, function)\
    00473         { path, accelerator, 0, 0, "<RadioItem>", 0, (MyPMF)&MyClass::function }
    00474
    00480
    00481 #define IFM_RADIO_ITEM_LINK(path, function, link_path)\
    00482         { path, 0, 0, 0, link_path, 0, (MyPMF)&MyClass::function }
    00483
    00487
    00488 #define IFM_TEAROFF_ITEM(path, function)\
    00489         { path, 0, 0, 0, "<Tearoff>", 0, (MyPMF)&MyClass::function }
    00490
    00493
    00494 #define IFM_SEPARATOR(path)\
    00495         { path, 0, 0, 0, "<Separator>", 0, 0 }
    00496
    00499
    00500 #define IFM_BRANCH(path)\
    00501         { path, 0, 0, 0, "<Branch>", 0, 0 }
    00502
    00505
    00506 #define IFM_LAST_BRANCH(path)\
    00507         { path, 0, 0, 0, "<LastBranch>", 0, 0 }
    00508
    00509 #endif // INTI_GTK_ITEM_FACTORY_H
    00510

Main Page - Footer