tailieunhanh - apress foundations_of gtk plus development 2007 phần 8

Tham khảo tài liệu 'apress foundations_of gtk plus development 2007 phần 8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 408 CHAPTER 11 CREATING CUSTOM WIDGETS G_BEGIN_DECLS define MY_MARQUEE_TYPE my_marquee_get_type define MY_MARQUEE obj g_TYPE_CHEcK_INsTaNcE_CAST obj MY_MARQUEE_TYPE MyMarquee define MY_MARQUEE_CLASS klass G_TYPE_CHECK_CLASS_CAST klass MY_MARQUEE_TYPE MyMarqueeClass define IS_MY_MARQUEE obj G_TYPE_CHECK_INSTANCE_TYPE obj MY_MARQUEE_TYPE define IS_MY_MARQUEE_CLASS klass G_TYPE_CHECK_CLASS_TYPE klass MY_MARQUEE_TYPE typedef struct _MyMarquee MyMarquee typedef struct _MyMarqueeClass MyMarqueeClass struct _MyMarquee GtkWidget widget struct _MyMarqueeClass GtkWidgetClass parent_class GType my_marquee_get_type void G_GNUC_CONST GtkWidget my_marquee_new void void my_marquee_set_message MyMarquee marquee const gchar message gchar my_marquee_get_message MyMarquee marquee void my_marquee_set_speed MyMarquee marquee gint speed gint my_marquee_get_speed MyMarquee marquee void my_marquee_slide MyMarquee marquee G_END_DECLS endif __MY_MARQUEE_H__ Since MyMarquee is a new widget it will be directly derived from GtkWidget. This is shown by the fact that MyMarquee contains a GtkWidget object and MyMarqueeClass contains a GtkWidgetClass class. Recall that neither of these members should be declared as pointers Deriving the widget from GtkWidget allows you to take advantage of all of the signals and properties that are common to every widget including event handling. CHAPTER 11 CREATING CUSTOM WIDGETS 409 The widget will have two properties that the programmer can set and retrieve. The user can use my_marquee_set_message to change the message that is scrolled by the widget. The speed is an integer between 1 and 50. The message will be moved this many pixels to the left every time my_marquee_slide is called. Creating the MyMarquee Widget Now that the header file is created Listing 11-18 performs basic initialization such as declaring the private class enumerating properties and creating a new GType. There are no new signals associated with this widget so the signal enumeration and .