Hello, sorry for the broad question but I'm a noob in D, gtk and gtkD... I'll try to narrow the question as much as I can.
I'm using glade to design the interface of my program, and glib-compile-resources to generate a .c file that I link to my program. So at some point I have:
Builder builder = new Builder();
if (!builder.addFromResource("/org/gtk/testprogram/main.glade")) {
throw new GuiInitException("Error obtaining frmMain window");
}
...
builder.connectSignals(myData);
and then I have a bunch of extern(C) functions that are handling the signals.
Let's talk about myData now: at some point I realized some widgets needed to set the text of other widgets in response to the user's input, so I had to pass them some pointer. My first attempt was to set myData = cast(void*)builder. That worked, but I also needed other stuff initialized in main, and that I would normally pass to a constructor, ie:
void main() {
auto config = new Config("/path/to/config");
auto myWin = new MyWindow(config);
}
so I made a structure that paired together the builder and config. Good, it works, but what's the deal with all those cast!Label(cast!GlobalStruct*(myData).getObject("someLabel")) and asserting !is null...
So my last attempt was to make a class like this:
class MyWindow : ApplicationWindow {
this(Config conf) {
...
Builder builder = new Builder();
builder.addFromResource("/org/gtk/testprogram/main.glade");
m_label = cast!Label(builder.getObject("some_label");
...
//and finally:
super(cast!ApplicationWindow(builder.getObject("myWindow")));
}
with the intention of setting myData to an instance of this class, so that all the extern(C) events become methods (void* data representing "this").
I wish that worked... ApplicationWindow has no copy constructor, and getStruct() is protected so I can't get it from the object returned by the builder.
So my questions are:
- did I take any "right" approach at any point during my design?
- How is one supposed to inherit from classes the whose objects are automatically created by Builder?
- Is there a way to differentiate the data being passed to events, so that I can pass the correct "this" pointer even if I have more than one window in my program? Or am I obliged to pack all of my "this" pointers into a global structure that is passed to every signal handler and trust them to access the right one? (sometimes it might be tempting to take shortcuts...)