📄 gtk.html
字号:
<DD><A NAME="IDX27"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_getv</B> <I>(GtkObject *<VAR>object</VAR>, guint <VAR>nargs</VAR>, GtkArg *<VAR>args</VAR>)</I><DD><A NAME="IDX28"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_set</B> <I>(GtkObject *<VAR>object</VAR>, ...)</I><DD><A NAME="IDX29"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_setv</B> <I>(GtkObject *<VAR>object</VAR>, guint <VAR>nargs</VAR>, GtkArg *<VAR>args</VAR>)</I><DD><A NAME="IDX30"></A></DL></P><P><DL><DT><U>Function:</U> GtkArg* <B>gtk_object_query_args</B> <I>(GtkType <VAR>class_type</VAR>, guint *<VAR>nargs</VAR>)</I><DD><A NAME="IDX31"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_add_arg_type</B> <I>(gchar *<VAR>arg_name</VAR>, GtkType <VAR>arg_type</VAR>, guint <VAR>arg_id</VAR>)</I><DD><A NAME="IDX32"></A></DL></P><P><DL><DT><U>Function:</U> GtkType <B>gtk_object_get_arg_type</B> <I>(gchar *<VAR>arg_name</VAR>)</I><DD><A NAME="IDX33"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_destroy</B> <I>(GtkObject *<VAR>object</VAR>)</I><DD><A NAME="IDX34"></A>Performs checks to make sure it is alright to destroy <VAR>object</VAR> andthen emits the <CODE>destroy</CODE> signal. The check which is performed is tomake sure <VAR>object</VAR> is not already processing another signal. If thiswere the case then destroying the object immediately would undoubtedlycause problems as the other signal would not be able to tell the objectwas destroyed. The solution is that if <VAR>object</VAR> is processing anothersignal we mark <VAR>object</VAR> is needing to be destroyed. When we finishprocessing of the other signal we check whether the object needs to bedestroyed.</DL></P><P>The GtkObject type provides a mechanism for associating arbitraryamounts of data with an object. The data is associated with the objectusing a character string key. The functions <CODE>gtk_object_set_data</CODE>,<CODE>gtk_object_get_data</CODE>, and <CODE>gtk_object_remove_data</CODE> are theinterface to this mechanism. Two other routines,<CODE>gtk_object_set_user_data</CODE> and <CODE>gtk_object_get_user_data</CODE>,exist as convenience functions which simply use the same mechanism.</P><P><DL><DT><U>Function:</U> void <B>gtk_object_set_data</B> <I>(GtkObject *<VAR>object</VAR>, const char *<VAR>key</VAR>, gpointer <VAR>data</VAR>)</I><DD><A NAME="IDX35"></A>Associate <VAR>data</VAR> with <VAR>key</VAR> in the data list of <VAR>object</VAR>.</DL></P><P><DL><DT><U>Function:</U> gpointer <B>gtk_object_get_data</B> <I>(GtkObject *<VAR>object</VAR>, const char *<VAR>key</VAR>)</I><DD><A NAME="IDX36"></A>Retrieve the data associated with <VAR>key</VAR> in the data list of <VAR>object</VAR>.</DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_remove_data</B> <I>(GtkObject *<VAR>object</VAR>, const char *<VAR>key</VAR>)</I><DD><A NAME="IDX37"></A>Remove the data associated with <VAR>key</VAR> in the data list of <VAR>object</VAR>.</DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_set_user_data</B> <I>(GtkObject *<VAR>object</VAR>, gpointer <VAR>data</VAR>)</I><DD><A NAME="IDX38"></A>Sets <VAR>data</VAR> into the <CODE>user_data</CODE> field of <VAR>object</VAR>.</DL></P><P><DL><DT><U>Function:</U> gpointer <B>gtk_object_get_user_data</B> <I>(GtkObject *<VAR>object</VAR>)</I><DD><A NAME="IDX39"></A>Returns the <CODE>user_data</CODE> field of <VAR>object</VAR>.</DL></P><P>The GtkObject type also provides a mechanism for specifyinginitialization values for fields. This general mechanism is calledobject value stacks. The reason for using value stacks is that they cansimplify the life of the programmer. For instance, by default widgetsare non-visible when created. However, the "visible" value for widgetsmay be specified so that widgets are made visible when created. (FIXME:unfinished).</P><P><DL><DT><U>Function:</U> void <B>gtk_object_value_stack_new</B> <I>(guint <VAR>object_type</VAR>, const gchar *<VAR>value_id</VAR>, GtkParamType <VAR>value_type</VAR>)</I><DD><A NAME="IDX40"></A></DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_push_value</B> <I>(guint <VAR>object_type</VAR>, const gchar *<VAR>value_id</VAR>, ...)</I><DD><A NAME="IDX41"></A>Push a value on the value stack specified by <VAR>object_type</VAR> and<VAR>value_id</VAR>. The type of value is implicitly given in the context of<VAR>object_type</VAR> and <VAR>value_id</VAR>. (That is, it is not specifiedexplicitly in the function call). Only a single extra argument isexpected which is the data which is to be placed on the stack.</DL></P><P><DL><DT><U>Function:</U> void <B>gtk_object_pop_value</B> <I>(guint <VAR>object_type</VAR>, const gchar *<VAR>value_id</VAR>)</I><DD><A NAME="IDX42"></A>Pop a value of the value stack specified by <VAR>object_type</VAR> and<VAR>value_id</VAR>.</DL></P><P><DL><DT><U>Function:</U> gint <B>gtk_object_peek_value</B> <I>(guint <VAR>object_type</VAR>, const gchar *<VAR>value_id</VAR>, gpointer <VAR>data</VAR>)</I><DD><A NAME="IDX43"></A>Peek at the value on the top of the value stack specified by<VAR>object_type</VAR> and <VAR>value_id</VAR>. The <VAR>data</VAR> argument isinterpreted as the location of where to place the "peeked" data. Forinstance, if the peeked data is of type <CODE>GTK_PARAM_POINTER</CODE>, then<VAR>data</VAR> will be a pointer to a pointer. If the value stack is emptyor does not exist or an error occurs, <CODE>gtk_object_peek_value</CODE> willreturn <CODE>FALSE</CODE>. On success it will return <CODE>TRUE</CODE>.</DL></P><H1><A NAME="SEC14" HREF="gtk_toc.html#TOC14">Signals Overview</A></H1><P><A NAME="IDX44"></A></P><P>Signals are GTK's method for objects to perform callbacks. A signal isan event which occurs upon an object. The programmer can connect to asignal of an object which involves specifying a function to be calledwhen that signal is emitted in the specified object.</P><P>When a signal is emitted, both the class function associated with thesignal (when it was defined) and all signal handlers installed for thatsignal on the particular object emitting the signal are called. Thewidget programmer can specify whether the class function is to be calledbefore after or both before and after the signal handlers installed bythe widget user. The widget user can, however, specify that their signalhandler is to be run after the class function (using the "_after"signal connection routines). Any signal handling function can emit thesame signal on the same object while it is running causing that signalemission to either restart or to run recursively. Additionally, signalemission can be terminated prematurely. While both such abilities arerarely used, they do allow for greater flexibility in regards tosignals. For instance, a programmer can attach to the key press eventsignal and intercept all tab key presses from a widget. This particularexample is used in the file selection dialog to implement tab completionof filenames and prevent the entry widget from inserting the tab intoits buffer.</P><P>Signals are selected using either an integer identifier or a characterstring name. It is convention to name the signal the same as the classfunction which is associated with it. There are two versions of most ofthe signal functions, one which takes an integer identifier and onewhich takes a character string name for the signal.</P><P><DL><DT><U>Function:</U> gint <B>gtk_signal_new</B> <I>(gchar *<VAR>name</VAR>, GtkSignalRunType <VAR>run_type</VAR>, gint <VAR>object_type</VAR>, gint <VAR>function_offset</VAR>, GtkSignalMarshaller <VAR>marshaller</VAR>, GtkParamType <VAR>return_val</VAR>, gint <VAR>nparams</VAR>, ...)</I><DD><A NAME="IDX45"></A>Create a new signal and give it the character string identifier<VAR>name</VAR>. <VAR>name</VAR> needs to be unique in the context of<VAR>object_type</VAR>'s branch of the class hierarchy. That is,<VAR>object_type</VAR> cannot create a signal type with the same name as asignal type created by one of its parent types.</P><P><VAR>run_type</VAR> specifies whether the class function should be run before(<CODE>GTK_RUN_FIRST</CODE>), after (<CODE>GTK_RUN_LAST</CODE>) or both before andafter normal signal handlers (<CODE>GTK_RUN_BOTH</CODE>). Additionally, the<CODE>GTK_RUN_NO_RECURSE</CODE> value can be or'ed with any of those values tospecify that the signal should not be recursive. By default, emittingthe same signal on the same widget will cause the signal to be emittedtwice. However, if the <CODE>GTK_RUN_NO_RECURSE</CODE> flag is specified,emitting the same signal on the same widget will cause the currentsignal emission to be restarted. This allows the widget programmer tospecify the semantics of signal emission on a per signalbasis. (The <CODE>GTK_RUN_NO_RECURSE</CODE> flag is used by the GtkAdjustmentwidget).</P><P>The <VAR>function_offset</VAR> is the byte offset from the start of the classstructure to the class function field within the class structure. Theeasiest means to compute this offset is by using the<CODE>GTK_SIGNAL_OFFSET</CODE> macro which takes the class structure type asthe first argument and the field as the second argument. For example,<CODE>GTK_SIGNAL_OFFSET (GtkObjectClass, destroy)</CODE> will give the offsetof the <CODE>destroy</CODE> class function within the<CODE>GtkObjectClass</CODE>. Note: An offset is specified instead of anabsolute location since there will be multiple instances of a classstructure being referenced. (The <CODE>GtkWidgetClass</CODE> structure "isa" <CODE>GtkObjectClass</CODE> structure, etc.)</P><P>The <VAR>marshaller</VAR> function is used to invoke a signal handler. Sincesignal handlers may take different parameters and return values and ageneral mechanism for invoking them is not apparent, the approach ofmaking the signal creator responsible for invoking the signal handlerwas taken. (FIXME: unfinished).</P><P>The <VAR>return_val</VAR> and <VAR>nparams</VAR> and the remaining argumentsspecify the return value and the arguments to the signal handlerrespectively. Note: There is an implicit first argument to every signalhandler which is the widget the signal has been emitted from. Thevariable argument list (<VAR>...</VAR>) specifies the types of thearguments. These can be one of <CODE>GTK_PARAM_CHAR</CODE>,<CODE>GTK_PARAM_SHORT</CODE>, <CODE>GTK_PARAM_INT</CODE>, <CODE>GTK_PARAM_LONG</CODE>,<CODE>GTK_PARAM_POINTER</CODE> or <CODE>GTK_PARAM_FUNCTION</CODE>. It is undefinedto specify <CODE>GTK_PARAM_NONE</CODE> as an argument type, however it is OKto use <CODE>GTK_PARAM_NONE</CODE> for <VAR>return_val</VAR>. (This corresponds toreturning a <CODE>void</CODE>).</P><P><CODE>gtk_signal_new</CODE> returns the integer identifier of the newlycreated signal. Signal identifiers start numbering at 1 and increaseupwards. A value of -1 will be returned if an error occurs.</P><P><STRONG>Note:</STRONG> <CODE>gtk_signal_new</CODE> is only needed by widget writers. Anormal user of GTK will never needed to invoke this function.</DL></P><P><DL><DT><U>Function:</U> gint <B>gtk_signal_lookup</B> <I>(gchar *<VAR>name</VAR>, gint <VAR>object_type</VAR>)</I><DD><A NAME="IDX46"></A>Returns the integer identifier for the signal referenced by <VAR>name</VAR>and <VAR>object_type</VAR>. If <VAR>object_type</VAR> does not define the signal<VAR>name</VAR>, then the signal is looked for in <VAR>object_type</VAR>'s parenttype recursively.</DL></P><P><DL><DT><U>Function:</U> gchar* <B>gtk_signal_name</B> <I>(gint <VAR>signal_num</VAR>)</I><DD><A NAME="IDX47"></A></DL></P><P><DL><DT><U>Function:</U> gint <B>gtk_signal_emit</B> <I>(GtkObject *<VAR>object</VAR>, gint <VAR>signal_type</VAR>, ...)</I><DD><A NAME="IDX48"></A>Emit the signal specified by the integer identifier <VAR>signal_type</VAR>from <VAR>object</VAR>. If an error occurs, <CODE>gtk_signal_emit</CODE> willreturn <CODE>FALSE</CODE> and will return <CODE>TRUE</CODE> on success. The signaldefinition determines the parameters passed in the variable argumentlist (<CODE>...</CODE>). For example, if the signal is defined as:</P><PRE> gint (* event) (GtkWidget *widget, GdkEvent *event);</PRE><P>Then a call to emit the "event" signal would look like:</P><PRE> GdkEvent event; gint return_val; ... gtk_signal_emit (some_object, gtk_signal_lookup ("event", GTK_OBJECT_TYPE (some_object)), &event, &return_val);</PRE><P>Notice that the <CODE>widget</CODE> argument is implicit in that the firstargument to every signal is a type derived from <CODE>GtkObject</CODE>. The<VAR>return_val</VAR> argument is actually a pointer to the return value typesince the signal mechanism needs to be able to place the return value inan actual location. And lastly, the <CODE>gtk_signal_lookup</CODE> call isnormally avoided by using the <CODE>gtk_signal_emit_by_name</CODE> functioninstead. <CODE>gtk_signal_emit</CODE> is normally used internally by widgetswhich know the signal identifier (since they defined the signal) and cantherefore side-step the cost of calling <CODE>gtk_signal_lookup</CODE>.</DL></P><P><DL><DT><U>Function:</U> gint <B>gtk_signal_emit_by_name</B> <I>(GtkObject *<VAR>object</VAR>, gchar *<VAR>name</VAR>, ...)</I><DD><A NAME="IDX49"></A>Similar to <CODE>gtk_signal_emit</CODE> except that the signal is referencedby <VAR>name</VAR> instead of by its integer identifier.</DL></P><P><DL><DT><U>Function:</U> void <B>gtk_signal_emit_stop</B> <I>(GtkObject *<VAR>object</VAR>, gint <VAR>signal_type</VAR>)</I><DD><A NAME="IDX50"></A>Stop the emission of the signal <VAR>signal_type</VAR> on<VAR>object</VAR>. <VAR>signal_type</VAR> is the integer identifier for the signaland can be determined using the function<CODE>gtk_signal_lookup</CODE>. Alternatively, the function<CODE>gtk_signal_emit_stop_by_name</CODE> can be used to refer to the signalby name. Attempting to stop the emission of a signal that isn't beingemitted does nothing.</DL></P><P><DL><DT><U>Function:</U> void <B>gtk_signal_emit_stop_by_name</B> <I>(GtkObject *<VAR>object</VAR>, gchar *<VAR>name</VAR>)</I><DD><A NAME="IDX51"></A>Similar to <CODE>gtk_signal_emit_stop</CODE> except that the signal isreferenced by <VAR>name</VAR> instead of by its integer identifier.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -