Chinaunix首页 | 论坛 | 博客
  • 博客访问: 456757
  • 博文数量: 64
  • 博客积分: 3271
  • 博客等级: 中校
  • 技术积分: 727
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 18:42
文章分类

全部博文(64)

文章存档

2013年(1)

2011年(19)

2010年(42)

2009年(2)

分类: C/C++

2011-07-27 23:26:31

在evince 中使用了多个 自定义类型,主要 的是
。EvWindow
。EvApplication
定义分别如下:
  1. struct _EvWindow {
  2.     GtkWindow        base_instance;
  3.     EvWindowPrivate        *priv;
  4. };

  5. struct _EvWindowPrivate {
  6.     /* UI */
  7.     EvChrome chrome;

  8.     GtkWidget *main_box;
  9.     GtkWidget *menubar;
  10.     GtkWidget *toolbar;
  11.     GtkWidget *hpaned;
  12.     GtkWidget *view_box;
  13.     GtkWidget *sidebar;
  14.     GtkWidget *find_bar;
  15.     GtkWidget *scrolled_window;
  16.     GtkWidget *view;
  17.     GtkWidget *presentation_view;
  18.     GtkWidget *message_area;
  19.     GtkWidget *password_view;
  20.     GtkWidget *sidebar_thumbs;
  21.     GtkWidget *sidebar_links;
  22.     GtkWidget *sidebar_attachments;
  23.     GtkWidget *sidebar_layers;
  24.     GtkWidget *sidebar_annots;
  25.     GtkWidget *sidebar_bookmarks;

  26.     /* Settings */
  27.     GSettings *settings;
  28.     GSettings *default_settings;
  29.     GSettings *lockdown_settings;

  30.     /* Menubar accels */
  31.     guint menubar_accel_keyval;
  32.     GdkModifierType menubar_accel_modifier;

  33.     /* Progress Messages */
  34.     guint progress_idle;
  35.     GCancellable *progress_cancellable;

  36.     /* Dialogs */
  37.     GtkWidget *properties;
  38.     GtkWidget *print_dialog;

  39.     /* UI Builders */
  40.     GtkActionGroup *action_group;
  41.     GtkActionGroup *view_popup_action_group;
  42.     GtkActionGroup *attachment_popup_action_group;
  43.     GtkRecentManager *recent_manager;
  44.     GtkActionGroup *recent_action_group;
  45.     guint recent_ui_id;
  46.     GtkActionGroup *bookmarks_action_group;
  47.     guint bookmarks_ui_id;
  48.     GtkUIManager *ui_manager;

  49.     /* Fullscreen mode */
  50.     GtkWidget *fullscreen_toolbar;

  51.     /* Popup view */
  52.     GtkWidget *view_popup;
  53.     EvLink *link;
  54.     EvImage *image;
  55.     EvAnnotation *annot;

  56.     /* Popup attachment */
  57.     GtkWidget *attachment_popup;
  58.     GList *attach_list;

  59.     /* Document */
  60.     EvDocumentModel *model;
  61.     char *uri;
  62.     glong uri_mtime;
  63.     char *local_uri;
  64.     gboolean in_reload;
  65.     EvFileMonitor *monitor;
  66.     guint setup_document_idle;
  67.     
  68.     EvDocument *document;
  69.     EvHistory *history;
  70.     EvWindowPageMode page_mode;
  71.     EvWindowTitle *title;
  72.     EvMetadata *metadata;
  73.     EvBookmarks *bookmarks;
  74.     gboolean is_new_doc;

  75.     /* Load params */
  76.     EvLinkDest *dest;
  77.     gchar *search_string;
  78.     EvWindowRunMode window_mode;

  79.     EvJob *load_job;
  80.     EvJob *reload_job;
  81.     EvJob *thumbnail_job;
  82.     EvJob *save_job;
  83.     EvJob *find_job;

  84.     /* Printing */
  85.     GQueue *print_queue;
  86.     GtkPrintSettings *print_settings;
  87.     GtkPageSetup *print_page_setup;
  88.     gboolean close_after_print;

  89. #ifdef ENABLE_DBUS
  90.     /* DBus */
  91.     guint dbus_object_id;
  92.     gchar *dbus_object_path;
  93. #endif
  94. };

  1. struct _EvApplication {
  2.     GObject base_instance;

  3.     gchar *uri;

  4.     gchar *dot_dir;
  5.     gchar *data_dir;

  6. #ifdef ENABLE_DBUS
  7.     GDBusConnection *connection;
  8.         guint registration_id;
  9.     EvMediaPlayerKeys *keys;
  10.     gboolean doc_registered;
  11. #endif

  12.     TotemScrsaver *scr_saver;

  13. #ifdef WITH_SMCLIENT
  14.     EggSMClient *smclient;
  15. #endif

  16.     gchar *filechooser_open_uri;
  17.     gchar *filechooser_save_uri;
  18. };

gtk+中使用 G_DEFINE_TYPE() 来定义自定义类型。然后调用
  1. gpointer g_object_new (GType object_type,  const gchar *first_property_name, ...);
来创建一个新自定义类型。

以Ev_window为例:

ev_window.c 370:
  1. G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
ev_window.h 54:
  1. #define EV_TYPE_WINDOW            (ev_window_get_type())
根据G_DEFINE_TYPE的定义:
  1. #define G_DEFINE_TYPE(TN, t_n, T_P)     G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})

  1. #define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)   
  2.                        _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_)
  3.                         {_C_;}
  4.                        _G_DEFINE_TYPE_EXTENDED_END()

  1. #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
  2. \
  3. static void type_name##_init (TypeName *self); \
  4. static void type_name##_class_init (TypeName##Class *klass); \
  5. static gpointer type_name##_parent_class = NULL; \
  6. static void type_name##_class_intern_init (gpointer klass) \
  7. { \
  8.   type_name##_parent_class = g_type_class_peek_parent (klass); \
  9.   type_name##_class_init ((TypeName##Class*) klass); \
  10. } \
  11. \
  12. GType \
  13. type_name##_get_type (void) \
  14. { \
  15.   static volatile gsize g_define_type_id__volatile = 0; \
  16.   if (g_once_init_enter (&g_define_type_id__volatile)) \
  17.     { \
  18.       GType g_define_type_id = \
  19.         g_type_register_static_simple (TYPE_PARENT, \
  20.                                        g_intern_static_string (#TypeName), \
  21.                                        sizeof (TypeName##Class), \
  22.                                        (GClassInitFunc) type_name##_class_intern_init, \
  23.                                        sizeof (TypeName), \
  24.                                        (GInstanceInitFunc) type_name##_init, \
  25.                                        (GTypeFlags) flags); \
  26.       { /* custom code follows */
  27. #define _G_DEFINE_TYPE_EXTENDED_END()    \
  28.         /* following custom code */    \
  29.       }                    \
  30.       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
  31.     }                    \
  32.   return g_define_type_id__volatile;    \
  33. } /* closes type_name##_get_type() */
  1. G_DEFINE_TYPE_EXTENDED (EvWindow, ev_window, GTK_TYPE_WIDGET, 0, {});
  2.     将扩展成:
  3.         
  4.     static void ev_window_init (EvWindow *self);
  5.     static void ev_window_class_init (EvWindowClass *klass);
  6.     static gpointer ev_window_parent_class = NULL;
  7.     static void ev_window_class_intern_init (gpointer klass)
  8.     {
  9.       ev_window_parent_class = g_type_class_peek_parent (klass);
  10.       ev_window_class_init ((EvWindowClass*) klass);
  11.     }
  12.     GType ev_window_get_type (void)
  13.     {
  14.       static volatile gsize g_define_type_id__volatile = 0;
  15.       if (g_once_init_enter (&g_define_type_id__volatile))
  16.         {
  17.           GType g_define_type_id =
  18.             g_type_register_static_simple (GTK_TYPE_WIDGET,
  19.                                            g_intern_static_string ("EvWindow"),
  20.                                            sizeof (EvWindowClass),
  21.                                            (GClassInitFunc) ev_window_class_intern_init,
  22.                                            sizeof (EvWindow),
  23.                                            (GInstanceInitFunc) ev_window_init,
  24.                                            (GTypeFlags) flags);
  25.             
  26.           g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
  27.         }
  28.       return g_define_type_id__volatile;
  29.     }
当调用
  1. ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
  2.                           "type", GTK_WINDOW_TOPLEVEL,
  3.                           NULL));
时,EV_TYPE_WINDOW -> ev_window_get_type -> ev_window_init。
阅读(1655) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~