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

📄 sec-adjustmentinternals.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
字号:
<HTML><HEAD><TITLE>Adjustment Internals</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="Adjustments"HREF="ch-adjustments.html"><LINKREL="PREVIOUS"TITLE="Using Adjustments the Easy Way"HREF="sec-usingadjustments.html"><LINKREL="NEXT"TITLE="Range Widgets"HREF="ch-rangewidgets.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-usingadjustments.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 7. Adjustments</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ch-rangewidgets.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-ADJUSTMENTINTERNALS">7.3. Adjustment Internals</A></H1><P>Ok, you say, that's nice, but what if I want to create my own handlersto respond when the user adjusts a range widget or a spin button, andhow do I get at the value of the adjustment in these handlers?  Toanswer these questions and more, let's start by taking a look at<TTCLASS="LITERAL">struct _GtkAdjustment</TT> itself:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">struct _GtkAdjustment{  GtkData data;    gfloat lower;  gfloat upper;  gfloat value;  gfloat step_increment;  gfloat page_increment;  gfloat page_size;};</PRE></TD></TR></TABLE><P>The first thing you should know is that there aren't any handy-dandymacros or accessor functions for getting the <TTCLASS="LITERAL">value</TT> out of anAdjustment, so you'll have to (horror of horrors) do it like a<ICLASS="EMPHASIS">real</I> C programmer.  Don't worry - the <TTCLASS="LITERAL">GTK_ADJUSTMENT(Object)</TT> macro does run-time type checking (as do all the GTKtype-casting macros, actually).</P><P>Since, when you set the <TTCLASS="LITERAL">value</TT> of an adjustment, you generallywant the change to be reflected by every widget that uses thisadjustment, GTK provides this convenience function to do this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_adjustment_set_value( GtkAdjustment *adjustment,                               gfloat         value );</PRE></TD></TR></TABLE><P>As mentioned earlier, Adjustment is a subclass of Object justlike all the various widgets, and thus it is able to emit signals.This is, of course, why updates happen automagically when you share anadjustment object between a scrollbar and another adjustable widget;all adjustable widgets connect signal handlers to their adjustment's<TTCLASS="LITERAL">value_changed</TT> signal, as can your program. Here's the definitionof this signal in <TTCLASS="LITERAL">struct _GtkAdjustmentClass</TT>:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  void (* value_changed) (GtkAdjustment *adjustment);</PRE></TD></TR></TABLE><P>The various widgets that use the Adjustment object will emit thissignal on an adjustment whenever they change its value. This happensboth when user input causes the slider to move on a range widget, aswell as when the program explicitly changes the value with<TTCLASS="LITERAL">gtk_adjustment_set_value()</TT>. So, for example, if you have a scalewidget, and you want to change the rotation of a picture whenever itsvalue changes, you would create a callback like this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void cb_rotate_picture (GtkAdjustment *adj, GtkWidget *picture){  set_picture_rotation (picture, adj-&#62;value);...</PRE></TD></TR></TABLE><P>and connect it to the scale widget's adjustment like this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gtk_signal_connect (GTK_OBJECT (adj), "value_changed",	            GTK_SIGNAL_FUNC (cb_rotate_picture), picture);</PRE></TD></TR></TABLE><P>What about when a widget reconfigures the <TTCLASS="LITERAL">upper</TT> or <TTCLASS="LITERAL">lower</TT>fields of its adjustment, such as when a user adds more text to a textwidget?  In this case, it emits the <TTCLASS="LITERAL">changed</TT> signal, which lookslike this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  void (* changed) (GtkAdjustment *adjustment);</PRE></TD></TR></TABLE><P>Range widgets typically connect a handler to this signal, whichchanges their appearance to reflect the change - for example, the sizeof the slider in a scrollbar will grow or shrink in inverse proportionto the difference between the <TTCLASS="LITERAL">lower</TT> and <TTCLASS="LITERAL">upper</TT> values of itsadjustment.</P><P>You probably won't ever need to attach a handler to this signal,unless you're writing a new type of range widget.  However, if youchange any of the values in a Adjustment directly, you should emitthis signal on it to reconfigure whatever widgets are using it, likethis:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gtk_signal_emit_by_name (GTK_OBJECT (adjustment), "changed");</PRE></TD></TR></TABLE><P>Now go forth and adjust!</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-usingadjustments.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="ch-rangewidgets.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Using Adjustments the Easy Way</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-adjustments.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Range Widgets</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

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