📄 gtktoolbar.c
字号:
child_space->alloc_x + toolbar->button_maxw * SPACE_LINE_END / SPACE_LINE_DIVISION, child_space->alloc_y + (toolbar->space_size - widget->style->klass->ythickness) / 2);}static voidgtk_toolbar_draw (GtkWidget *widget, GdkRectangle *area){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; GdkRectangle child_area; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TOOLBAR (widget)); if (GTK_WIDGET_DRAWABLE (widget)) { toolbar = GTK_TOOLBAR (widget); for (children = toolbar->children; children; children = children->next) { child = children->data; if (child->type == GTK_TOOLBAR_CHILD_SPACE) { if (toolbar->space_style == GTK_TOOLBAR_SPACE_LINE) gtk_toolbar_paint_space_line (widget, area, child); } else if (gtk_widget_intersect (child->widget, area, &child_area)) gtk_widget_draw (child->widget, &child_area); } }}static gintgtk_toolbar_expose (GtkWidget *widget, GdkEventExpose *event){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; GdkEventExpose child_event; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_TOOLBAR (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (GTK_WIDGET_DRAWABLE (widget)) { toolbar = GTK_TOOLBAR (widget); child_event = *event; for (children = toolbar->children; children; children = children->next) { child = children->data; if (child->type == GTK_TOOLBAR_CHILD_SPACE) { if (toolbar->space_style == GTK_TOOLBAR_SPACE_LINE) gtk_toolbar_paint_space_line (widget, &event->area, child); } else if (GTK_WIDGET_NO_WINDOW (child->widget) && gtk_widget_intersect (child->widget, &event->area, &child_event.area)) gtk_widget_event (child->widget, (GdkEvent *) &child_event); } } return FALSE;}static voidgtk_toolbar_size_request (GtkWidget *widget, GtkRequisition *requisition){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; gint nbuttons; gint button_maxw, button_maxh; gint widget_maxw, widget_maxh; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TOOLBAR (widget)); g_return_if_fail (requisition != NULL); toolbar = GTK_TOOLBAR (widget); requisition->width = GTK_CONTAINER (toolbar)->border_width * 2; requisition->height = GTK_CONTAINER (toolbar)->border_width * 2; nbuttons = 0; button_maxw = 0; button_maxh = 0; widget_maxw = 0; widget_maxh = 0; for (children = toolbar->children; children; children = children->next) { child = children->data; switch (child->type) { case GTK_TOOLBAR_CHILD_SPACE: if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) requisition->width += toolbar->space_size; else requisition->height += toolbar->space_size; break; case GTK_TOOLBAR_CHILD_BUTTON: case GTK_TOOLBAR_CHILD_RADIOBUTTON: case GTK_TOOLBAR_CHILD_TOGGLEBUTTON: if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_size_request (child->widget, &child_requisition); nbuttons++; button_maxw = MAX (button_maxw, child_requisition.width); button_maxh = MAX (button_maxh, child_requisition.height); } break; case GTK_TOOLBAR_CHILD_WIDGET: if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_size_request (child->widget, &child_requisition); widget_maxw = MAX (widget_maxw, child_requisition.width); widget_maxh = MAX (widget_maxh, child_requisition.height); if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) requisition->width += child_requisition.width; else requisition->height += child_requisition.height; } break; default: g_assert_not_reached (); } } if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) { requisition->width += nbuttons * button_maxw; requisition->height += MAX (button_maxh, widget_maxh); } else { requisition->width += MAX (button_maxw, widget_maxw); requisition->height += nbuttons * button_maxh; } toolbar->button_maxw = button_maxw; toolbar->button_maxh = button_maxh;}static voidgtk_toolbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; GtkToolbarChildSpace *child_space; GtkAllocation alloc; GtkRequisition child_requisition; gint border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TOOLBAR (widget)); g_return_if_fail (allocation != NULL); toolbar = GTK_TOOLBAR (widget); widget->allocation = *allocation; border_width = GTK_CONTAINER (toolbar)->border_width; if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) alloc.x = allocation->x + border_width; else alloc.y = allocation->y + border_width; for (children = toolbar->children; children; children = children->next) { child = children->data; switch (child->type) { case GTK_TOOLBAR_CHILD_SPACE: child_space = (GtkToolbarChildSpace *) child; if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) { child_space->alloc_x = alloc.x; child_space->alloc_y = allocation->y + (allocation->height - toolbar->button_maxh) / 2; alloc.x += toolbar->space_size; } else { child_space->alloc_x = allocation->x + (allocation->width - toolbar->button_maxw) / 2; child_space->alloc_y = alloc.y; alloc.y += toolbar->space_size; } break; case GTK_TOOLBAR_CHILD_BUTTON: case GTK_TOOLBAR_CHILD_RADIOBUTTON: case GTK_TOOLBAR_CHILD_TOGGLEBUTTON: if (!GTK_WIDGET_VISIBLE (child->widget)) break; alloc.width = toolbar->button_maxw; alloc.height = toolbar->button_maxh; if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) alloc.y = allocation->y + (allocation->height - toolbar->button_maxh) / 2; else alloc.x = allocation->x + (allocation->width - toolbar->button_maxw) / 2; gtk_widget_size_allocate (child->widget, &alloc); if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) alloc.x += toolbar->button_maxw; else alloc.y += toolbar->button_maxh; break; case GTK_TOOLBAR_CHILD_WIDGET: if (!GTK_WIDGET_VISIBLE (child->widget)) break; gtk_widget_get_child_requisition (child->widget, &child_requisition); alloc.width = child_requisition.width; alloc.height = child_requisition.height; if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) alloc.y = allocation->y + (allocation->height - child_requisition.height) / 2; else alloc.x = allocation->x + (allocation->width - child_requisition.width) / 2; gtk_widget_size_allocate (child->widget, &alloc); if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) alloc.x += child_requisition.width; else alloc.y += child_requisition.height; break; default: g_assert_not_reached (); } }}static voidgtk_toolbar_add (GtkContainer *container, GtkWidget *widget){ g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TOOLBAR (container)); g_return_if_fail (widget != NULL); gtk_toolbar_append_widget (GTK_TOOLBAR (container), widget, NULL, NULL);}static voidgtk_toolbar_remove (GtkContainer *container, GtkWidget *widget){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TOOLBAR (container)); g_return_if_fail (widget != NULL); toolbar = GTK_TOOLBAR (container); for (children = toolbar->children; children; children = children->next) { child = children->data; if ((child->type != GTK_TOOLBAR_CHILD_SPACE) && (child->widget == widget)) { gboolean was_visible; was_visible = GTK_WIDGET_VISIBLE (widget); gtk_widget_unparent (widget); toolbar->children = g_list_remove_link (toolbar->children, children); g_free (child); g_list_free (children); toolbar->num_children--; if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); break; } }}static voidgtk_toolbar_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data){ GtkToolbar *toolbar; GList *children; GtkToolbarChild *child; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TOOLBAR (container)); g_return_if_fail (callback != NULL); toolbar = GTK_TOOLBAR (container); for (children = toolbar->children; children; children = children->next) { child = children->data; if (child->type != GTK_TOOLBAR_CHILD_SPACE) (*callback) (child->widget, callback_data); }}GtkWidget *gtk_toolbar_append_item (GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data){ return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, NULL, text, tooltip_text, tooltip_private_text, icon, callback, user_data, toolbar->num_children);}GtkWidget *gtk_toolbar_prepend_item (GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data){ return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, NULL, text, tooltip_text, tooltip_private_text, icon, callback, user_data, 0);}GtkWidget *gtk_toolbar_insert_item (GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data, gint position){ return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, NULL, text, tooltip_text, tooltip_private_text, icon, callback, user_data, position);}voidgtk_toolbar_append_space (GtkToolbar *toolbar){ gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -