⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-manipulatingthelistitself.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
字号:
<HTML><HEAD><TITLE>Manipulating the list itself</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="CList Widget"HREF="ch-clistwidget.html"><LINKREL="PREVIOUS"TITLE="Working with titles"HREF="sec-workingwithtitles.html"><LINKREL="NEXT"TITLE="Adding rows to the list"HREF="sec-addingrowstothelist.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-workingwithtitles.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 11. CList Widget</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-addingrowstothelist.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-MANIPULATINGTHELISTITSELF">11.4. Manipulating the list itself</A></H1><P>It is possible to change the justification for a column, and it isdone through</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_clist_set_column_justification( GtkCList         *clist,                                         gint              column,                                         GtkJustification  justification );</PRE></TD></TR></TABLE><P>The GtkJustification type can take the following values:</P><P></P><UL><LI><P><TTCLASS="LITERAL">GTK_JUSTIFY_LEFT</TT> - The text in the column will begin from theleft edge.</P></LI><LI><P><TTCLASS="LITERAL">GTK_JUSTIFY_RIGHT</TT> - The text in the column will begin from theright edge.</P></LI><LI><P><TTCLASS="LITERAL">GTK_JUSTIFY_CENTER</TT> - The text is placed in the center of thecolumn.</P></LI><LI><P><TTCLASS="LITERAL">GTK_JUSTIFY_FILL</TT> - The text will use up all available space inthe column. It is normally done by inserting extra blank spacesbetween words (or between individual letters if it's a singleword). Much in the same way as any ordinary WYSIWYG text editor.</P></LI></UL><P>The next function is a very important one, and should be standard inthe setup of all CList widgets. When the list is created, the widthof the various columns are chosen to match their titles, and sincethis is seldom the right width we have to set it using</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_clist_set_column_width( GtkCList *clist,                                 gint      column,                                 gint      width );</PRE></TD></TR></TABLE><P>Note that the width is given in pixels and not letters. The same goesfor the height of the cells in the columns, but as the default valueis the height of the current font this isn't as critical to theapplication. Still, it is done through</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_clist_set_row_height( GtkCList *clist,                               gint      height );</PRE></TD></TR></TABLE><P>Again, note that the height is given in pixels.</P><P>We can also move the list around without user interaction, however, itdoes require that we know what we are looking for. Or in other words,we need the row and column of the item we want to scroll to.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_clist_moveto( GtkCList *clist,                       gint      row,                       gint      column,                       gfloat    row_align,                       gfloat    col_align );</PRE></TD></TR></TABLE><P>The gfloat row_align is pretty important to understand. It's a valuebetween 0.0 and 1.0, where 0.0 means that we should scroll the list sothe row appears at the top, while if the value of row_align is 1.0,the row will appear at the bottom instead. All other values between0.0 and 1.0 are also valid and will place the row between the top andthe bottom. The last argument, gfloat col_align works in the same way,though 0.0 marks left and 1.0 marks right instead.</P><P>Depending on the application's needs, we don't have to scroll to anitem that is already visible to us. So how do we know if it isvisible? As usual, there is a function to find that out as well.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkVisibility gtk_clist_row_is_visible( GtkCList *clist,                                        gint      row );</PRE></TD></TR></TABLE><P>The return value is is one of the following:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  GTK_VISIBILITY_NONE  GTK_VISIBILITY_PARTIAL  GTK_VISIBILITY_FULL</PRE></TD></TR></TABLE><P>Note that it will only tell us if a row is visible. Currently there isno way to determine this for a column. We can get partial informationthough, because if the return is <TTCLASS="LITERAL">GTK_VISIBILITY_PARTIAL</TT>, thensome of it is hidden, but we don't know if it is the row that is beingcut by the lower edge of the listbox, or if the row has columns thatare outside.</P><P>We can also change both the foreground and background colors of aparticular row. This is useful for marking the row selected by theuser, and the two functions that is used to do it are</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_clist_set_foreground( GtkCList *clist,                               gint      row,                               GdkColor *color );void gtk_clist_set_background( GtkCList *clist,                               gint      row,                               GdkColor *color );</PRE></TD></TR></TABLE><P>Please note that the colors must have been previously allocated.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-workingwithtitles.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-addingrowstothelist.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Working with titles</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-clistwidget.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Adding rows to the list</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -