Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gtk/gtk.h>
- GtkWidget *window, *child, *subchild;
- #define EXAMPLE_FIXED_TYPE (example_fixed_get_type())
- G_DECLARE_FINAL_TYPE(ExampleFixed, example_fixed, Example, Fixed, GtkFixed)
- #define EXAMPLE_BOX_TYPE (example_box_get_type())
- G_DECLARE_FINAL_TYPE(ExampleBox, example_box, Example, Box, GtkBox)
- struct _ExampleFixed
- {
- GtkFixed parent;
- };
- struct _ExampleBox
- {
- GtkBox parent;
- };
- G_DEFINE_TYPE(ExampleFixed, example_fixed, GTK_TYPE_FIXED);
- G_DEFINE_TYPE(ExampleBox, example_box, GTK_TYPE_BOX);
- static void example_fixed_init(ExampleFixed *fixed)
- {
- gtk_widget_set_has_surface (GTK_WIDGET (fixed), TRUE);
- }
- static void example_box_init(ExampleBox *box)
- {
- gtk_widget_set_has_surface (GTK_WIDGET (box), TRUE);
- }
- static void example_fixed_realize(GtkWidget *widget)
- {
- const GtkAllocation allocation;
- GdkSurface *surface, *fixedsurf;
- surface = gtk_widget_get_surface(window);
- fixedsurf = gdk_surface_new_child(surface, &allocation);
- gtk_widget_set_surface(widget, fixedsurf);
- gtk_widget_register_surface(widget, fixedsurf);
- GTK_WIDGET_CLASS(example_fixed_parent_class)->realize(widget);
- }
- static void example_box_realize(GtkWidget *widget)
- {
- const GtkAllocation allocation;
- GdkSurface *surface, *boxsurf;
- surface = gtk_widget_get_surface(window);
- boxsurf = gdk_surface_new_child(surface, &allocation);
- gtk_widget_set_surface(widget, boxsurf);
- gtk_widget_register_surface(widget, boxsurf);
- GTK_WIDGET_CLASS(example_box_parent_class)->realize(widget);
- }
- static void example_fixed_class_init(ExampleFixedClass *klass)
- {
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
- widget_class->realize = example_fixed_realize;
- }
- static void example_box_class_init(ExampleBoxClass *klass)
- {
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
- widget_class->realize = example_box_realize;
- }
- GtkWidget *example_fixed_new()
- {
- return g_object_new(EXAMPLE_FIXED_TYPE, NULL);
- }
- GtkWidget *example_box_new()
- {
- return g_object_new(EXAMPLE_BOX_TYPE, NULL);
- }
- static void activate (GtkApplication* app, gpointer user_data)
- {
- window = gtk_application_window_new (app);
- gtk_window_set_title (GTK_WINDOW (window), "Window");
- gtk_window_set_default_size (GTK_WINDOW (window), 1024, 768);
- child = example_fixed_new();
- subchild = example_box_new();
- gtk_container_add(GTK_CONTAINER(child), subchild);
- gtk_container_add(GTK_CONTAINER(window), child);
- gtk_widget_show (window);
- }
- int main (int argc, char **argv)
- {
- GtkApplication *app;
- int status;
- app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
- g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
- status = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (app);
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement