自定义小部件开发与接口实现
1. 尺寸请求与分配
在开发自定义小部件时,我们通常需要重写父类GtkWindowClass的尺寸请求和分配函数。以下是my_marquee_size_request()和my_marquee_size_allocate()函数的实现:
/* Handle size requests for the widget. This function forces the widget to have * an initial size set according to the predefined width and the font size. */ static void my_marquee_size_request (GtkWidget *widget, GtkRequisition *requisition) { PangoFontDescription *fd; g_return_if_fail (widget != NULL || requisition != NULL); g_return_if_fail (IS_MY_MARQUEE (widget)); fd = widget->style->font_desc; requisition->width = MARQUEE_MIN_WIDTH; requisition->height = (pango_font_description_get_size (fd)