gtk2-perl / msg for other developers about enums and flags


Following my message of yesterday, here's how we'll use enums and
flags now.

Enums and flags are type checked quite differently, but the
macros we use are similar to the macros for converting perl
objects to gtk objects. The GtkWindowType enum:

SV* gtkperl_window_new(char* class, SV* type)
    return gtk2_perl_new_object(gtk_window_new(SvGtkWindowType(type)));

SvGtkWindowType will verify that the <type> contains a string
whose value is a member of GtkWindowType. If not:

FATAL: invalid enum GtkWindowType value topleel, expecting: toplevel / GTK_WINDOW_TOPLEVEL, popup / 
GTK_WINDOW_POPUP at <> line <line>.

The big difference with macros for objects, is that we also need
to convert back from the gtkenum to the perl value in some cases;
to do so, we'll use macros which are similar to existing perlapi
macros, newSV<type>:

SV* gtkperl_dialog_run(SV* dialog)
    return newSVGtkResponseType(gtk_dialog_run(SvGtkDialog(dialog)));

The function call below newSVGtkResponseType will convert the
"gint" value of the enum to the string value used in perl-gtk

Flags are handled in a very similar way (flags are just like
enums but using bits because several values coexist), the macros
are the same:

void gtkperl_widget_SET_FLAGS(SV* widget, SV* flags)
    GTK_WIDGET_SET_FLAGS(SvGtkWidget(widget), SvGtkWidgetFlags(flags)); 

SV* gtkperl_widget_FLAGS(SV* widget)
    return newSVGtkWidgetFlags(GTK_WIDGET_FLAGS(SvGtkWidget(widget)));

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]