[Vala] structs unions and types



I'm playing around trying to implement some C structures neatly in vala
and come over these strange situtions.

Case 1

  protected struct widgets {
    Gtk.Widget blah;
    Gtk.Widget blah2;
    }

public class PhoneUIGlade : Gtk.Object {
    protected Glade.XML xml;
    protected widgets widgets;
    private Module module;
}

src/phoneui.glade.vala:35.15-35.21: error: `PhoneUIGlade.widgets' is not
a type
    protected widgets widgets;
              ^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)


How was I supposed to refer to the outer struct type?


Case 2

public class PhoneUIGlade : Gtk.Object {
    protected Glade.XML xml;
    protected struct widgets {
      Gtk.Widget blah;
      Gtk.Widget blah2;
    } protected widgets x;
    private Module module;
}


(I call it x and not widgets otherwise I get
"src/phoneui.glade.vala:34.7-34.32: error: `PhoneUIGlade' already
contains a definition for `widgets'" even though one is a type and one
is a variable and so should be in different compiler namespaces)

In file included from ./src/mainwindow.h:30,
                 from src/mainwindow.c:22:
./src/phoneui.glade.h:50: error: field ‘widgets’ has incomplete type

the generated ./src/phoneui.glade.h has:

...
typedef struct _PhoneUIGladewidgets PhoneUIGladewidgets;

/*[CCode (cheader_filename="phoneui.glade.h")]*/
struct _PhoneUIGlade {
    GtkObject parent_instance;
    PhoneUIGladePrivate * priv;
    GladeXML* xml;
    PhoneUIGladewidgets x;
};

...
struct _PhoneUIGladewidgets {
    GtkWidget* blah;
    GtkWidget* blah2;
};


So we see that the struct _PhoneUIGladewidgets is not defined until
after class that holds and defines it _PhoneUIGlade.


Case 3

I can't get anything like this to compile in vala at all; please could
someone give me a clue.
I'm trying to define a protected type in an automatically generated
superclass of a glade window, so the manually generated subclass gets
delphi-like access to all the widgets.

union widgets {
  Gtk.Widget by_number[window1_WIDGET_COUNT];
  struct by_name {
    Gtk.Window window1; /* GtkWindow window1 */
    Gtk.VBox vbox1; /* GtkVBox vbox1 */
    Gtk.Image image1; /* GtkImage image1 */
    Gtk.Button button1; /* GtkButton button1 */
    Gtk.Statusbar statusbar1; /* GtkStatusbar statusbar1 */
  }
};/* widget name list for runtime binding */


Sam




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