📄 sec-gtkarg.html
字号:
</p> <ul> <li> <p> <span class="STRUCTNAME">GTK_TYPE_INVALID</span>: used to signal errors. </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. </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. </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. </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). </p> </li> <li> <p> <span class="STRUCTNAME">GTK_TYPE_CALLBACK</span>: interpreted language bindings can use this to pass signal callbacks around. </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). </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. </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"> 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;}; </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"> &</span> operator on them; e.g. <span class= "STRUCTNAME">&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"> 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 ... */ } </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 <gtk/gtktypeutils.h></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><<< 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 >>></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 + -