[gtk+] Add foreigndrawing example to gtk3-demo



commit 7ee65da0e3c4a7e5552450ec37e691abb1c62b28
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 10 15:32:53 2016 -0500

    Add foreigndrawing example to gtk3-demo
    
    This makes it easier accessible and nicer to refer to
    from the documentation.

 demos/gtk-demo/Makefile.am                 |    1 +
 demos/gtk-demo/demo.gresource.xml          |    1 +
 {tests => demos/gtk-demo}/foreigndrawing.c |   77 ++++++++++++++--------------
 tests/Makefile.am                          |    1 -
 4 files changed, 40 insertions(+), 40 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index e93a450..bbe91ea 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -27,6 +27,7 @@ demos_base =                                  \
        expander.c                              \
         filtermodel.c                          \
        font_features.c                         \
+       foreigndrawing.c                        \
        gestures.c                              \
        glarea.c                                \
        headerbar.c                             \
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index d0e80f2..7301b40 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -140,6 +140,7 @@
     <file>expander.c</file>
     <file>filtermodel.c</file>
     <file>flowbox.c</file>
+    <file>foreigndrawing.c</file>
     <file>font_features.c</file>
     <file>gestures.c</file>
     <file>glarea.c</file>
diff --git a/tests/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c
similarity index 84%
rename from tests/foreigndrawing.c
rename to demos/gtk-demo/foreigndrawing.c
index 3320cb6..5a7a3f3 100644
--- a/tests/foreigndrawing.c
+++ b/demos/gtk-demo/foreigndrawing.c
@@ -1,23 +1,15 @@
-/* foreign-drawing.c
- * Copyright (C) 2015 Red Hat, Inc
- * Author: Matthias Clasen
+/* Foreign drawing
  *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Many applications can't use GTK+ widgets, for a variety of reasons,
+ * but still want their user interface to appear integrated with the
+ * rest of the desktop, and follow GTK+ themes.
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ * This demo shows how to use GtkStyleContext and the gtk_render_ APIs
+ * to achieve this. Note that this is a very simple, non-interactive
+ * example.
  */
 
 #include <gtk/gtk.h>
-
 #include <string.h>
 
 static void
@@ -133,8 +125,6 @@ get_style (GtkStyleContext *parent,
   context = gtk_style_context_new ();
   gtk_style_context_set_path (context, path);
   gtk_style_context_set_parent (context, parent);
-  /* XXX: Why is this necessary? */
-  gtk_style_context_set_state (context, gtk_widget_path_iter_get_state (path, -1));
   gtk_widget_path_unref (path);
 
   return context;
@@ -309,30 +299,39 @@ draw_cb (GtkWidget *widget,
   return FALSE;
 }
 
-int
-main (int argc, char *argv[])
+GtkWidget *
+do_foreigndrawing (GtkWidget *do_widget)
 {
-  GtkWidget *window;
-  GtkWidget *box;
-  GtkWidget *da;
-
-  gtk_init (NULL, NULL);
-
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
-  gtk_container_add (GTK_CONTAINER (window), box);
-  da = gtk_drawing_area_new ();
-  gtk_widget_set_size_request (da, 200, 200);
-  gtk_widget_set_hexpand (da, TRUE);
-  gtk_widget_set_vexpand (da, TRUE);
-  gtk_widget_set_app_paintable (da, TRUE);
-  gtk_container_add (GTK_CONTAINER (box), da);
+  static GtkWidget *window = NULL;
 
-  g_signal_connect (da, "draw", G_CALLBACK (draw_cb), NULL);
-
-  gtk_widget_show_all (window);
+  if (!window)
+    {
+      GtkWidget *box;
+      GtkWidget *da;
+
+      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_title (GTK_WINDOW (window), "Foreign drawing");
+      gtk_window_set_screen (GTK_WINDOW (window),
+                             gtk_widget_get_screen (do_widget));
+      g_signal_connect (window, "destroy",
+                        G_CALLBACK (gtk_widget_destroyed), &window);
+
+      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+      gtk_container_add (GTK_CONTAINER (window), box);
+      da = gtk_drawing_area_new ();
+      gtk_widget_set_size_request (da, 200, 200);
+      gtk_widget_set_hexpand (da, TRUE);
+      gtk_widget_set_vexpand (da, TRUE);
+      gtk_widget_set_app_paintable (da, TRUE);
+      gtk_container_add (GTK_CONTAINER (box), da);
+
+      g_signal_connect (da, "draw", G_CALLBACK (draw_cb), NULL);
+    }
 
-  gtk_main ();
+  if (!gtk_widget_get_visible (window))
+    gtk_widget_show_all (window);
+  else
+    gtk_widget_destroy (window);
 
-  return 0;
+  return window;
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 85d06ba..7fd8a88 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -169,7 +169,6 @@ noinst_PROGRAMS =  $(TEST_PROGS)    \
        testpopover                     \
        gdkgears                        \
        listmodel                       \
-       foreigndrawing                  \
        testpopup                       \
        $(NULL)
 


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