Add foreigndrawing example to gtk3-demo
This makes it easier accessible and nicer to refer to from the documentation.
This commit is contained in:
@ -27,6 +27,7 @@ demos_base = \
|
|||||||
expander.c \
|
expander.c \
|
||||||
filtermodel.c \
|
filtermodel.c \
|
||||||
font_features.c \
|
font_features.c \
|
||||||
|
foreigndrawing.c \
|
||||||
gestures.c \
|
gestures.c \
|
||||||
glarea.c \
|
glarea.c \
|
||||||
headerbar.c \
|
headerbar.c \
|
||||||
|
@ -140,6 +140,7 @@
|
|||||||
<file>expander.c</file>
|
<file>expander.c</file>
|
||||||
<file>filtermodel.c</file>
|
<file>filtermodel.c</file>
|
||||||
<file>flowbox.c</file>
|
<file>flowbox.c</file>
|
||||||
|
<file>foreigndrawing.c</file>
|
||||||
<file>font_features.c</file>
|
<file>font_features.c</file>
|
||||||
<file>gestures.c</file>
|
<file>gestures.c</file>
|
||||||
<file>glarea.c</file>
|
<file>glarea.c</file>
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
/* foreign-drawing.c
|
/* Foreign drawing
|
||||||
* Copyright (C) 2015 Red Hat, Inc
|
|
||||||
* Author: Matthias Clasen
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* Many applications can't use GTK+ widgets, for a variety of reasons,
|
||||||
* modify it under the terms of the GNU Library General Public
|
* but still want their user interface to appear integrated with the
|
||||||
* License as published by the Free Software Foundation; either
|
* rest of the desktop, and follow GTK+ themes.
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This demo shows how to use GtkStyleContext and the gtk_render_ APIs
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* to achieve this. Note that this is a very simple, non-interactive
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* example.
|
||||||
* 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/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -133,8 +125,6 @@ get_style (GtkStyleContext *parent,
|
|||||||
context = gtk_style_context_new ();
|
context = gtk_style_context_new ();
|
||||||
gtk_style_context_set_path (context, path);
|
gtk_style_context_set_path (context, path);
|
||||||
gtk_style_context_set_parent (context, parent);
|
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);
|
gtk_widget_path_unref (path);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
@ -309,16 +299,23 @@ draw_cb (GtkWidget *widget,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
GtkWidget *
|
||||||
main (int argc, char *argv[])
|
do_foreigndrawing (GtkWidget *do_widget)
|
||||||
|
{
|
||||||
|
static GtkWidget *window = NULL;
|
||||||
|
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
GtkWidget *da;
|
GtkWidget *da;
|
||||||
|
|
||||||
gtk_init (NULL, NULL);
|
|
||||||
|
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
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);
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
||||||
gtk_container_add (GTK_CONTAINER (window), box);
|
gtk_container_add (GTK_CONTAINER (window), box);
|
||||||
da = gtk_drawing_area_new ();
|
da = gtk_drawing_area_new ();
|
||||||
@ -329,10 +326,12 @@ main (int argc, char *argv[])
|
|||||||
gtk_container_add (GTK_CONTAINER (box), da);
|
gtk_container_add (GTK_CONTAINER (box), da);
|
||||||
|
|
||||||
g_signal_connect (da, "draw", G_CALLBACK (draw_cb), NULL);
|
g_signal_connect (da, "draw", G_CALLBACK (draw_cb), NULL);
|
||||||
|
}
|
||||||
gtk_widget_show_all (window);
|
|
||||||
|
if (!gtk_widget_get_visible (window))
|
||||||
gtk_main ();
|
gtk_widget_show_all (window);
|
||||||
|
else
|
||||||
return 0;
|
gtk_widget_destroy (window);
|
||||||
|
|
||||||
|
return window;
|
||||||
}
|
}
|
@ -169,7 +169,6 @@ noinst_PROGRAMS = $(TEST_PROGS) \
|
|||||||
testpopover \
|
testpopover \
|
||||||
gdkgears \
|
gdkgears \
|
||||||
listmodel \
|
listmodel \
|
||||||
foreigndrawing \
|
|
||||||
testpopup \
|
testpopup \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user