Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 9f53138a531066fad3ff013246a3463c > files > 379

gtk2-devel-docs-2.24.4-1.fc15.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Packing Using Tables</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="GTK+ 2.0 Tutorial"
HREF="book1.html"><LINK
REL="UP"
TITLE="Packing Widgets"
HREF="c354.html"><LINK
REL="PREVIOUS"
TITLE="Packing Demonstration Program"
HREF="x386.html"><LINK
REL="NEXT"
TITLE="Table Packing Example"
HREF="x441.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GTK+ 2.0 Tutorial</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x386.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Packing Widgets</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x441.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="SEC-PACKINGUSINGTABLES"
>Packing Using Tables</A
></H1
><P
>Let's take a look at another way of packing - Tables. These can be
extremely useful in certain situations.</P
><P
>Using tables, we create a grid that we can place widgets in. The
widgets may take up as many spaces as we specify.</P
><P
>The first thing to look at, of course, is the gtk_table_new() function:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>GtkWidget *gtk_table_new( guint    rows,
                          guint    columns,
                          gboolean homogeneous );</PRE
></TD
></TR
></TABLE
><P
>The first argument is the number of rows to make in the table, while
the second, obviously, is the number of columns.</P
><P
>The homogeneous argument has to do with how the table's boxes are
sized. If homogeneous is TRUE, the table boxes are resized to the size
of the largest widget in the table. If homogeneous is FALSE, the size
of a table boxes is dictated by the tallest widget in its same row,
and the widest widget in its column.</P
><P
>The rows and columns are laid out from 0 to n, where n was the number
specified in the call to gtk_table_new. So, if you specify rows = 2
and columns = 2, the layout would look something like this:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 0          1          2
0+----------+----------+
 |          |          |
1+----------+----------+
 |          |          |
2+----------+----------+</PRE
></TD
></TR
></TABLE
><P
>Note that the coordinate system starts in the upper left hand corner.
To place a widget into a box, use the following function:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_attach( GtkTable         *table,
                       GtkWidget        *child,
                       guint            left_attach,
                       guint            right_attach,
                       guint            top_attach,
                       guint            bottom_attach,
                       GtkAttachOptions xoptions,
                       GtkAttachOptions yoptions,
                       guint            xpadding,
                       guint            ypadding );</PRE
></TD
></TR
></TABLE
><P
>The first argument ("table") is the table you've created and the
second ("child") the widget you wish to place in the table.</P
><P
>The left and right attach arguments specify where to place the widget,
and how many boxes to use. If you want a button in the lower right
table entry of our 2x2 table, and want it to fill that entry <I
CLASS="EMPHASIS"
>only</I
>,
left_attach would be = 1, right_attach = 2, top_attach = 1,
bottom_attach = 2.</P
><P
>Now, if you wanted a widget to take up the whole top row of our 2x2
table, you'd use left_attach = 0, right_attach = 2, top_attach = 0,
bottom_attach = 1.</P
><P
>The xoptions and yoptions are used to specify packing options and may
be bitwise OR'ed together to allow multiple options.</P
><P
>These options are:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>GTK_FILL</TT
></DT
><DD
><P
>If the table box is larger than the widget, and
<TT
CLASS="LITERAL"
>GTK_FILL</TT
> is specified, the widget will expand to use all the room
available.</P
></DD
><DT
><TT
CLASS="LITERAL"
>GTK_SHRINK</TT
></DT
><DD
><P
>If the table widget was allocated less space
then was requested (usually by the user resizing the window), then the
widgets would normally just be pushed off the bottom of the window and
disappear. If <TT
CLASS="LITERAL"
>GTK_SHRINK</TT
> is specified, the widgets will shrink
with the table.</P
></DD
><DT
><TT
CLASS="LITERAL"
>GTK_EXPAND</TT
></DT
><DD
><P
>This will cause the table to expand to use up
any remaining space in the window.</P
></DD
></DL
></DIV
><P
>Padding is just like in boxes, creating a clear area around the widget
specified in pixels.</P
><P
>gtk_table_attach() has a <I
CLASS="EMPHASIS"
>lot</I
> of options.  
So, there's a shortcut:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_attach_defaults( GtkTable  *table,
                                GtkWidget *widget,
                                guint      left_attach,
                                guint      right_attach,
                                guint      top_attach,
                                guint      bottom_attach );</PRE
></TD
></TR
></TABLE
><P
>The X and Y options default to <TT
CLASS="LITERAL"
>GTK_FILL | GTK_EXPAND</TT
>, 
and X and Y padding are set to 0. The rest of the arguments are identical to the
previous function.</P
><P
>We also have gtk_table_set_row_spacing() and
gtk_table_set_col_spacing(). These places spacing between the rows at
the specified row or column.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_set_row_spacing( GtkTable *table,
                                guint     row,
                                guint     spacing );</PRE
></TD
></TR
></TABLE
><P
>and</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_set_col_spacing ( GtkTable *table,
                                 guint     column,
                                 guint     spacing );</PRE
></TD
></TR
></TABLE
><P
>Note that for columns, the space goes to the right of the column, and
for rows, the space goes below the row.</P
><P
>You can also set a consistent spacing of all rows and/or columns with:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_set_row_spacings( GtkTable *table,
                                 guint    spacing );</PRE
></TD
></TR
></TABLE
><P
>And,</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void gtk_table_set_col_spacings( GtkTable *table,
                                 guint     spacing );</PRE
></TD
></TR
></TABLE
><P
>Note that with these calls, the last row and last column do not get
any spacing.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x386.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x441.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Packing Demonstration Program</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c354.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Table Packing Example</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>