?? z166.html
字號:
nvis_children = 0; nexpand_children = 0; children = box->children; while (children) { child = children->data; children = children->next; if (GTK_WIDGET_VISIBLE (child->widget)) { nvis_children += 1; if (child->expand) nexpand_children += 1; } } if (nvis_children > 0) { if (box->homogeneous) { height = (allocation->height - GTK_CONTAINER (box)->border_width * 2 - (nvis_children - 1) * box->spacing); extra = height / nvis_children; } else if (nexpand_children > 0) { height = (gint) allocation->height - (gint) widget->requisition.height; extra = height / nexpand_children; } else { height = 0; extra = 0; } y = allocation->y + GTK_CONTAINER (box)->border_width; child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width; child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2); children = box->children; while (children) { child = children->data; children = children->next; if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget)) { if (box->homogeneous) { if (nvis_children == 1) child_height = height; else child_height = extra; nvis_children -= 1; height -= extra; } else { GtkRequisition child_requisition; gtk_widget_get_child_requisition (child->widget, &child_requisition); child_height = child_requisition.height + child->padding * 2; if (child->expand) { if (nexpand_children == 1) child_height += height; else child_height += extra; nexpand_children -= 1; height -= extra; } } if (child->fill) { child_allocation.height = MAX (1, child_height - (gint)child->padding * 2); child_allocation.y = y + child->padding; } else { GtkRequisition child_requisition; gtk_widget_get_child_requisition (child->widget, &child_requisition); child_allocation.height = child_requisition.height; child_allocation.y = y + (child_height - child_allocation.height) / 2; } gtk_widget_size_allocate (child->widget, &child_allocation); y += child_height + box->spacing; } } y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width; children = box->children; while (children) { child = children->data; children = children->next; if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget)) { GtkRequisition child_requisition; gtk_widget_get_child_requisition (child->widget, &child_requisition); if (box->homogeneous) { if (nvis_children == 1) child_height = height; else child_height = extra; nvis_children -= 1; height -= extra; } else { child_height = child_requisition.height + child->padding * 2; if (child->expand) { if (nexpand_children == 1) child_height += height; else child_height += extra; nexpand_children -= 1; height -= extra; } } if (child->fill) { child_allocation.height = MAX (1, child_height - (gint)child->padding * 2); child_allocation.y = y + child->padding - child_height; } else { child_allocation.height = child_requisition.height; child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height; } gtk_widget_size_allocate (child->widget, &child_allocation); y -= (child_height + box->spacing); } } }} </pre> </td> </tr> </table> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z169">Child Arguments</a> </h2> <p> <tt class="CLASSNAME">GtkBox</tt> implements <i class= "FIRSTTERM">child arguments</i>, which were briefly described in <a href="hc-objectargs.html#SEC-GETSETARG"> the section called <i>Using Object Arguments in Your Own <span class="STRUCTNAME">GtkObject</span> Subclass</i> in the chapter called <i>The GTK+ Object and Type System</i></a>. Child arguments represent a property of a pair of objects. In this case, the box-packing flags for each child can be read and written using the object argument system. </p> <p> Here's how <tt class="CLASSNAME">GtkBox</tt> registers its child arguments, in <tt class="FUNCTION"> gtk_box_class_init()</tt>: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> gtk_container_add_child_arg_type ("GtkBox::expand", GTK_TYPE_BOOL, GTK_ARG_READWRITE, CHILD_ARG_EXPAND); gtk_container_add_child_arg_type ("GtkBox::fill", GTK_TYPE_BOOL, GTK_ARG_READWRITE, CHILD_ARG_FILL); gtk_container_add_child_arg_type ("GtkBox::padding", GTK_TYPE_ULONG, GTK_ARG_READWRITE, CHILD_ARG_PADDING); gtk_container_add_child_arg_type ("GtkBox::pack_type", GTK_TYPE_PACK_TYPE, GTK_ARG_READWRITE, CHILD_ARG_PACK_TYPE); gtk_container_add_child_arg_type ("GtkBox::position", GTK_TYPE_LONG, GTK_ARG_READWRITE, CHILD_ARG_POSITION); </pre> </td> </tr> </table> <p> <tt class="CLASSNAME">GtkBox</tt> then implements the <span class="STRUCTNAME">get_child_arg</span> and <span class="STRUCTNAME">set_child_arg</span> methods from <span class="STRUCTNAME">GtkContainerClass</span>. Here's <tt class="FUNCTION">gtk_box_get_child_arg()</tt>; the <tt class="FUNCTION">gtk_box_set_child_arg()</tt> is analagous. </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> static voidgtk_box_get_child_arg (GtkContainer *container, GtkWidget *child, GtkArg *arg, guint arg_id){ gboolean expand = 0; gboolean fill = 0; guint padding = 0; GtkPackType pack_type = 0; GList *list; if (arg_id != CHILD_ARG_POSITION) gtk_box_query_child_packing (GTK_BOX (container), child, &expand, &fill, &padding, &pack_type); switch (arg_id) { case CHILD_ARG_EXPAND: GTK_VALUE_BOOL (*arg) = expand; break; case CHILD_ARG_FILL: GTK_VALUE_BOOL (*arg) = fill; break; case CHILD_ARG_PADDING: GTK_VALUE_ULONG (*arg) = padding; break; case CHILD_ARG_PACK_TYPE: GTK_VALUE_ENUM (*arg) = pack_type; break; case CHILD_ARG_POSITION: GTK_VALUE_LONG (*arg) = 0; for (list = GTK_BOX (container)->children; list; list = list->next) { GtkBoxChild *child_entry; child_entry = list->data; if (child_entry->widget == child) break; GTK_VALUE_LONG (*arg)++; } if (!list) GTK_VALUE_LONG (*arg) = -1; break; default: arg->type = GTK_TYPE_INVALID; break; }} </pre> </td> </tr> </table> </div> </div> <div class="NAVFOOTER"> <br> <br> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-widgetindetail.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="z170.html"><font color="#0000ff" size="2"><b> Next >>></b></font></a> </td> </tr> <tr> <td colspan="2" align="left"> <font color="#000000" size="2"><b><tt class= "CLASSNAME">GtkWidget</tt> In Detail</b></font> </td> <td colspan="2" align="right"> <font color="#000000" size="2"><b><tt class= "CLASSNAME">GnomeAppBar</tt>: A Trivial Composite Widget</b></font> </td> </tr> </table> </div> </body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -