自定义小部件开发全解析
在开发自定义小部件时,有多个关键方面需要我们去关注和实现。下面我们将详细探讨这些内容,包括大小请求与分配、小部件的显示、绘制函数、公共函数的实现、小部件的测试以及接口的实现与使用。
1. 大小请求与分配
在自定义小部件时,我们需要重写父类GtkWindowClass的大小请求和分配函数。以下是具体的代码实现:
/* 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_si