📄 gtk.texi
字号:
marked as @samp{out} or @samp{inout} it means that the called module isallowed to change the contents of the composite value and that thesechanges need to be propagated back to the originator of the value. Mode@samp{out} means that the argument has no meaningful value at thebeginning and should not be read. Mode @samp{in} specifies that thecalled module is not allowed to change the value in any way.The type system allows for an unbounded number of types. Every widgetis a type for example and you can add new widget types at any timewithout confusing the run-time implementation of the type system.Nevertheless, all types are derived from a certain @dfn{fundamental}type, and there are only a small and finite number of fundamental types.We only specify rules for the fundamental types and all other typesinherit these rules from their fundamental type. For example,@samp{int} is a fundamental type, as is @samp{GtkObject}. All widgetsderive from @samp{GtkObject} and so the rules for @samp{GtkObject} applyto all widgets as well.This derivation defines a type hierachy, but this hierachy is notcompletely general. You can't derive from @samp{int} for example, andyou can only have one level of derivation from @samp{enum}. Thefundamental type @samp{GtkObject}, however, is the basis for the largeand deep hierarchy of widget types.The individual fundamental types are defined and explained in thefollowing sections. Here is a complete list of them:@table @samp@item noneThe not-a-value type, similar to @samp{void}.@item charA character. Internationalization issues are still undecided.@item boolTrue or false.@item byte, ubyte, int, uint, long, ulong, float, doubleThe usual assortment of scalar types.@item stringA string. Internationalization issues are still undecided.@item enum, flagsEnumerations with a fixed set of literals. Either used to express asingle choice from this set or to individually turn on and off severalflags.@item boxedA pointer to an opaque structure that can be copied and destroyed.@item callbackA pointer to a function with enough extra information so that it canalso be used for functions written in languages completely differentfrom C.@item GtkObjectA pointer to a GtkObject or derived type. The fun starts here.@item args, slist, dlist, cvec, tvecAn assortment of composite types like linked lists and counted orzero-terminated arrays.@item pointer, signal, c_callbackObsolete types.@end table@node Basics, Simple types, Type introduction, Types@section Basic ConceptsThe basis for the type system are the fundamental types. At run-time,they are represented by members of the @code{GtkFundamentalType}enumeration. For the static declarations, they are identified with aunique name.@deftp {Enumeration} GtkFundamentalTypeThis enumeration contains a member for each defined fundamental type.Most members are listed along with the description of their semantics,but one is listed here:@table @code@item GTK_TYPE_INVALIDNo valid type is derived from this. Use @code{GTK_TYPE_INVALID} toexpress exceptional situations. This member does not really correspondto a fundamental type and thus there is no name for it.@end table@end deftp@deftp {Data type} GtkTypeThe type @code{GtkType} holds the run-time representation of a type. Itis a integer of a certain size. The follwing macros are defined toaccess the basic properties of a @code{GtkType}:@deftypefn {Macro} {unsigned int} GTK_TYPE_SEQNO (GtkType type)Returns the sequence number of @var{type}. The sequence numbers areguaranteed to be dense, i.e., you can use them to index a table and thetable need not be much larger than the number of different GtkTypes thatyou might encounter.@end deftypefn@deftypefn {Macro} GtkFundamentalType GTK_FUNDAMENTAL_TYPE (GtkType type)Returns the fundamental type of @var{type}.@end deftypefnBoth macros simply access different bit-fields of a @code{GtkType}, sothey are very efficient.@end deftpNew types are registered with the @code{gtk_type_unique} function. Anykind oftype can be registered with @code{gtk_type_unique} but there areconvenience functions for most fundamental types. Each fundamental typehas its own interpretation of the rules below and these conveniencefunctions should be used to automatically get the type registrationright. So, don't be put off by the apparent complexity of the interfaceto @code{gtk_type_unique}. You will be using it only for new widgets,and there the rules are simple.The @code{GtkTypeInfo} structure is used to communicate information to@code{gtk_type_unique} as opposed to passing in large numbers ofparameters.@exampletypedef struct _GtkTypeInfo GtkTypeInfo;struct _GtkTypeInfo@{ gchar *type_name; guint object_size; guint class_size; GtkClassInitFunc class_init_func; GtkObjectInitFunc object_init_func; gpointer reserved_1; gpointer reserved_2; GtkClassInitFunc base_class_init_func;@}@end example@itemize @bullet@itemThe @code{type_name} field refers to the name of the type. This is thesame name that is used in the static definitions. It is convention forthe type name to be closely related to the name of the underlying Ctype. For example, the type name of the @code{GtkObject} structure is``GtkObject'', and the name of the @code{GtkWindowType} enumeration is``GtkWindowType''. Note that the C type corresponding to ``GtkObject''is really a pointer to a @code{GtkObject} struct, but the name has no``*'' in it.@itemThe @code{object_size} field refers to the size in bytes of the Cstructure for types that have such a structure. The easiest (andportable) means of computing this size is by using the C @code{sizeof}operator. For instance, the sizeof of the @code{GtkObject} structure iscomputed by doing @code{sizeof (GtkObject)}. When the type has noassociated structure or when you do not want to support the@code{gtk_type_new} function for the new type, set @code{object_size} to0. Only types derived from GTK_TYPE_OBJECT can be handled by@code{gtk_type_new}, anyway.@itemThe @code{class_size} field refers to the size in bytes of the Cstructure for the class. Again, the @code{sizeof} operator should beused to compute this value. If you don't want to have a class structurefor this type, set the field to 0. @code{gtk_type_class} will thenalways return @code{NULL}.@itemThe @code{class_init_func} and @code{base_class_init_func} fields arecallbacks which are used by the type mechanism to initialize classspecific fields. The single argument these function taks is a pointer toa class structure. When you do not need one or both of them, set thecorresponding field to @code{NULL}. The @code{class_init_func} will becalled at most once, right after the class structure of size@code{class_size} has been allocated. The interaction between@code{class_init_func} and @code{base_class_init_func} is only reallyuseful for the full-fledged object system. It is described there@pxref{Objects}.@itemThe @code{object_init_func} field is a callback which is used by thetype mechanism to initialize object specific fields for structures thathave been allocated via @code{gtk_type_new}. The single argument thisfunctions takes is a pointer to an object structure. If you do not wantany special object initialization to take place, set this to@code{NULL}. All object initialization functions for all types that arepart of the inheritance chain are called, starting with the most basictype.@end itemize@deftypefun guint gtk_type_unique (GtkType @var{parent_type}, GtkTypeInfo *@var{type_info})The @var{parent_type} is simply the new types parent type. If@var{parent_type} is GTK_TYPE_INVALID, then the new type is a newfundamental type. You should @b{never} register new fundamental types.@var{type_info} is a pointer to a structure which contains necessaryinformation for construction of the new type.You can only register a specific name once.@end deftypefun@deftypefun gchar* gtk_type_name (GtkType @var{type})The returned string is the name of @var{type} as specified to@code{gtk_type_unique}.@end deftypefun@deftypefun GtkType gtk_type_from_name (guchar *@var{name})Return the type associated with @var{name}. If there is no typeassociated with @var{name}, then GTK_TYPE_INVALID will be returned.@end deftypefun@deftypefun GtkType gtk_type_parent (GtkType @var{type})Returns the parent type of @var{type} or GTK_TYPE_INVALID if @var{type}is a fundamental type.@end deftypefun@deftypefun gpointer gtk_type_class (GtkType @var{type})Returns the initialized class structure for @var{type}. The classstructure is actually created and initialized the first time it isneeded. Refer to @pxref{Objects} for details on how this initialization works for GTK_TYPE_OBJECT derived types.@c If creation and initialization occurs, the @code{class_size}@c field of the @code{GtkTypeInfo} structure used to initialize this type@c is used to determine how large the class structure is. The@c @code{class_init_func} field from the @code{GtkTypeInfo} structure is@c called for all the members in the types ancestry, including the@c type. The order of this invocation proceeds from the root on down. For@c example, the @code{GtkWidgetClass} is first initialized as an@c @code{GtkObjectClass} by the object class initialization routine and@c then by the widget class initialization routine. This allows the widget@c class initialization routine to override values set by the object class@c initialization routine.The returned structure is shared by all objects of @var{type} and, assuch, should not be modified.@end deftypefun@deftypefun gpointer gtk_type_new (GtkType @var{type})Returns a new instance of an @var{type} object. This works only for GTK_TYPE_OBJECT derived types. Please see @pxref{Objects}.@c The @code{object_size}@c and @code{object_init_func} fields of the @code{GtkTypeInfo} structure@c are used to determine the objects allocated size and the object specific@c initialization routine. Similarly to the class initialization, all the@c object initialization routines from the root on down to the particular@c type being created are invoked.@end deftypefun@deftypefun void gtk_type_describe_heritage (GtkType @var{type})Prints the type heritage for @var{type}. The heritage for a typeincludes the type and all its parent types up the type tree.@end deftypefun@deftypefun void gtk_type_describe_tree (GtkType @var{type}, gboolean @var{show_size})Prints the type tree which starts at @var{type}. @var{show_size} is aboolean which determines whether type sizes are printed.@end deftypefun@deftypefun gboolean gtk_type_is_a (GtkType @var{type}, GtkType @var{is_a_type})A predicate function which determines whether the relation @var{type}is_a @var{is_a_type} is true.@end deftypefun@c @deftypefun void gtk_type_get_arg (GtkObject *@var{object}, GtkType @var{type}, GtkArg *@var{arg}, guint @var{arg_id})@c @end deftypefun@c @deftypefun void gtk_type_set_arg (GtkObject *@var{object}, GtkType @var{type}, GtkArg *@var{arg}, guint @var{arg_id})@c @end deftypefunValues of all types can be handled uniformly by storing them into a@code{GtkArg} structure. The @code{GtkArg} has the following fields:@table @code@item gchar *nameThis can be used to give the value represented by this @code{GtkArg}structure a name. It is not used much.@item GtkType typeThe type of this value.@item union dA big union that has (at least conceptually) one member for eachfundamental type. You should not access these members directly.Rather, use the @code{GTK_VALUE_*} macros. There is one macro for eachfundamental type, and its name is derived from the name of theGtkFundamentalType enumeration members simply by replacing ``Gtk_TYPE''with ``GTK_VALUE''. All @code{GTK_VALUE_*} macros take a @code{GtkArg}structure as their only parameter (@emph{not} a pointer) and evaluate toa lvalue.@end tableFor example, the accessor for the fundamental type GTK_TYPE_INT iscalled GTK_VALUE_INT and you could use it like this:@exampleGtkArg value;value.name = NULL;value.type = GTK_TYPE_INT;GTK_VALUE_INT(value) = 7;@end example@node Simple types, Enumerations and flags, Basics, Types@section Simple TypesThe Gtk type system has a full set of the usual simple types: integers,floating point numbers, but also boolean and character. You can notderive new types from these.@multitable {GTK_TYPE_POINTER} {"gpointer"} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}@item Enum @tab Name @tab Description@item GTK_TYPE_NONE @tab "void"@tab A type without value.@item GTK_TYPE_CHAR @tab "char"@tab A 8-bit unsigned number representing a character. Numbers between 0 and 127 are ASCII, the rest is undefined.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -