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

📄 sec-gtkarg.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
      </p>      <ul>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_INVALID</span>: used            to signal errors.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_NONE</span>: used to            indicate a <span class="STRUCTNAME">void</span> return            value when specifying the signature of a signal.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_BOXED</span>:            Subtypes of <span class="STRUCTNAME">            GTK_TYPE_BOXED</span> are used to mark the type of a            generic pointer; language bindings will special case            these types. Most GDK types, such as <span class=             "STRUCTNAME">GdkWindow</span>, are registered as boxed            types.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_SIGNAL</span>:            special-cased in <span class="STRUCTNAME">            GtkObject</span>; it allows users to connect signal            handlers with <tt class="FUNCTION">            gtk_object_set()</tt>. It should not be useful in            application code. &#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_ARGS</span>: type of            an array of <span class="STRUCTNAME">GtkArg</span>            (when used with <tt class="FUNCTION">            gtk_object_set()</tt>, an integer array length followed            by the array itself are expected as arguments).&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_CALLBACK</span>:            interpreted language bindings can use this to pass            signal callbacks around.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_C_CALLBACK</span>:            this is used for other kinds of callbacks, i.e.            callbacks that are not attached to signals (such as the            argument to a <span class="STRUCTNAME">            _foreach()</span> function).&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GTK_TYPE_FOREIGN</span>:            unused in current GTK+ code. Represents a pointer plus            a function used to destroy the pointed-to resource;            intended to represent object data (see <a href=             "sec-objectdata.html">the section called <i>Attaching            Data to Objects</i></a>), for example.&#13;          </p>        </li>      </ul>      <p>        A fundamental type describes not only describe the data        layout but also how memory is managed. For values passed in        as arguments, the called function is not allowed to retain        the pointer beyond the duration of the call. For returned        values, the caller assumes ownership of the memory. <span        class="STRUCTNAME">GTK_TYPE_BOXED</span>, <span class=         "STRUCTNAME">GTK_TYPE_ARGS</span>, and <span class=         "STRUCTNAME">GTK_TYPE_STRING</span> obey this rule.      </p>      <p>        Note that you should almost always use the most informative        type available. Notably, <span class="STRUCTNAME">        GTK_TYPE_POINTER</span> should only be used for generic        pointers (<span class="STRUCTNAME">gpointer</span>);        whenever possible, prefer a "subclass" of <span class=         "STRUCTNAME">GTK_TYPE_BOXED</span> such as <span class=         "STRUCTNAME">GTK_TYPE_GDK_WINDOW</span> or <span class=         "STRUCTNAME">GTK_TYPE_GDK_EVENT</span>. Similarly, it is        better to use a specific enumeration type, rather than        <span class="STRUCTNAME">GTK_TYPE_ENUM</span>. <span class=         "STRUCTNAME">GTK_TYPE_CALLBACK</span> is normally preferred        to <span class="STRUCTNAME">GTK_TYPE_C_CALLBACK</span> or        <span class="STRUCTNAME">GTK_TYPE_SIGNAL</span>, because        <span class="STRUCTNAME">GTK_TYPE_CALLBACK</span> includes        information about how to marshal the function and destroy        the callback data.      </p>      <p>        GTK+ has a consistent interface for passing typed values        around; to do this, it needs a data structure which stores        a type tag and a value. <span class="STRUCTNAME">        GtkArg</span> fills the bill. Here is its definition, from        <tt class="FILENAME">gtk/gtktypeutils.h</tt>:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;typedef struct _GtkArg GtkArg;struct _GtkArg{  GtkType type;  gchar *name;  union {    gchar char_data;    guchar uchar_data;    gboolean bool_data;    gint int_data;    guint uint_data;    glong long_data;    gulong ulong_data;    gfloat float_data;    gdouble double_data;    gchar *string_data;    gpointer pointer_data;    GtkObject *object_data;        struct {      GtkSignalFunc f;      gpointer d;    } signal_data;    struct {      gint n_args;      GtkArg *args;    } args_data;    struct {      GtkCallbackMarshal marshal;      gpointer data;      GtkDestroyNotify notify;    } callback_data;    struct {      GtkFunction func;      gpointer func_data;    } c_callback_data;    struct {      gpointer data;      GtkDestroyNotify notify;    } foreign_data;  } d;};&#13;</pre>          </td>        </tr>      </table>      <p>        The <span class="STRUCTNAME">type</span> field contains the        value's <span class="STRUCTNAME">GtkType</span>, as you        might expect. The <span class="STRUCTNAME">name</span>        field is an object argument name---more on arguments in a        moment. The final union stores a value of the appropriate        type; there is one union member for each fundamental type.        This value field should be accessed using a special set of        macros provided for the purpose, listed in <a href=         "sec-gtkarg.html#ML-ARGVALUE">Figure 2</a>; each macro        corresponds to a fundamental type. These macros are defined        so that you can use the <span class="STRUCTNAME">        &amp;</span> operator on them; e.g. <span class=        "STRUCTNAME">&amp;GTK_VALUE_CHAR(arg)</span>.      </p>      <p>        To print a <span class="STRUCTNAME">GtkArg</span>'s value,        you might write code like this:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;   GtkArg arg;   /* ... */   switch (GTK_FUNDAMENTAL_TYPE (arg.type))     {     case GTK_TYPE_INT:       printf("arg: %d\n", GTK_VALUE_INT(arg));       break;     /* ... case for each type ... */     }&#13;</pre>          </td>        </tr>      </table>      <div class="FIGURE">        <a name="ML-ARGVALUE"></a>        <div class="FUNCSYNOPSIS">          <a name="ML-ARGVALUE.SYNOPSIS"></a>          <table border="0" bgcolor="#E0E0E0" width="100%">            <tr>              <td><pre class="FUNCSYNOPSISINFO">#include &lt;gtk/gtktypeutils.h&gt;</pre>              </td>            </tr>          </table>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_CHAR</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_UCHAR</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_BOOL</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_INT</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_UINT</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_LONG</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_ULONG</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_FLOAT</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_DOUBLE</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_STRING</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_ENUM</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_FLAGS</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_BOXED</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_POINTER</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_OBJECT</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_SIGNAL</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_ARGS</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_CALLBACK</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_C_CALLBACK</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>          <p>            <code><code class="FUNCDEF"><tt class="FUNCTION">            GTK_VALUE_FOREIGN</tt></code>(<tt class=            "PARAMETER"><i>arg</i></tt>);</code>          </p>        </div>        <p>          <b>Figure 2. Macros for Accessing <span class=          "STRUCTNAME">GtkArg</span> Values</b>        </p>      </div>      <p>        Some uses of <span class="STRUCTNAME">GtkArg</span> require        you to assign a value to it. The <span class="STRUCTNAME">        GTK_VALUE_</span> macros are not appropriate here; instead,        a parallel set of macros exist which return a pointer to an        assignable location. These are called <span class=         "STRUCTNAME">GTK_RETLOC_CHAR()</span>, <span class=         "STRUCTNAME">GTK_RETLOC_UCHAR()</span>, and so on.      </p>    </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-classinit.html"><font color="#0000ff"            size="2"><b>&lt;&lt;&lt; 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="hc-objectargs.html"><font color="#0000ff"            size="2"><b>Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>        <tr>          <td colspan="2" align="left">            <font color="#000000" size="2"><b>Initializing a New            Class</b></font>          </td>          <td colspan="2" align="right">            <font color="#000000" size="2"><b>Object            Arguments</b></font>          </td>        </tr>      </table>    </div>  </body></html>

⌨️ 快捷键说明

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