1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.DrawingArea;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gtk.Widget;
30 private import gtk.c.functions;
31 public  import gtk.c.types;
32 public  import gtkc.gtktypes;
33 
34 
35 /**
36  * The #GtkDrawingArea widget is used for creating custom user interface
37  * elements. It’s essentially a blank widget; you can draw on it. After
38  * creating a drawing area, the application may want to connect to:
39  * 
40  * - Mouse and button press signals to respond to input from
41  * the user. (Use gtk_widget_add_events() to enable events
42  * you wish to receive.)
43  * 
44  * - The #GtkWidget::realize signal to take any necessary actions
45  * when the widget is instantiated on a particular display.
46  * (Create GDK resources in response to this signal.)
47  * 
48  * - The #GtkWidget::size-allocate signal to take any necessary
49  * actions when the widget changes size.
50  * 
51  * - The #GtkWidget::draw signal to handle redrawing the
52  * contents of the widget.
53  * 
54  * The following code portion demonstrates using a drawing
55  * area to display a circle in the normal widget foreground
56  * color.
57  * 
58  * Note that GDK automatically clears the exposed area before sending
59  * the expose event, and that drawing is implicitly clipped to the exposed
60  * area. If you want to have a theme-provided background, you need
61  * to call gtk_render_background() in your ::draw method.
62  * 
63  * ## Simple GtkDrawingArea usage
64  * 
65  * |[<!-- language="C" -->
66  * gboolean
67  * draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
68  * {
69  * guint width, height;
70  * GdkRGBA color;
71  * GtkStyleContext *context;
72  * 
73  * context = gtk_widget_get_style_context (widget);
74  * 
75  * width = gtk_widget_get_allocated_width (widget);
76  * height = gtk_widget_get_allocated_height (widget);
77  * 
78  * gtk_render_background (context, cr, 0, 0, width, height);
79  * 
80  * cairo_arc (cr,
81  * width / 2.0, height / 2.0,
82  * MIN (width, height) / 2.0,
83  * 0, 2 * G_PI);
84  * 
85  * gtk_style_context_get_color (context,
86  * gtk_style_context_get_state (context),
87  * &color);
88  * gdk_cairo_set_source_rgba (cr, &color);
89  * 
90  * cairo_fill (cr);
91  * 
92  * return FALSE;
93  * }
94  * [...]
95  * GtkWidget *drawing_area = gtk_drawing_area_new ();
96  * gtk_widget_set_size_request (drawing_area, 100, 100);
97  * g_signal_connect (G_OBJECT (drawing_area), "draw",
98  * G_CALLBACK (draw_callback), NULL);
99  * ]|
100  * 
101  * Draw signals are normally delivered when a drawing area first comes
102  * onscreen, or when it’s covered by another window and then uncovered.
103  * You can also force an expose event by adding to the “damage region”
104  * of the drawing area’s window; gtk_widget_queue_draw_area() and
105  * gdk_window_invalidate_rect() are equally good ways to do this.
106  * You’ll then get a draw signal for the invalid region.
107  * 
108  * The available routines for drawing are documented on the
109  * [GDK Drawing Primitives][gdk3-Cairo-Interaction] page
110  * and the cairo documentation.
111  * 
112  * To receive mouse events on a drawing area, you will need to enable
113  * them with gtk_widget_add_events(). To receive keyboard events, you
114  * will need to set the “can-focus” property on the drawing area, and you
115  * should probably draw some user-visible indication that the drawing
116  * area is focused. Use gtk_widget_has_focus() in your expose event
117  * handler to decide whether to draw the focus indicator. See
118  * gtk_render_focus() for one way to draw focus.
119  */
120 public class DrawingArea : Widget
121 {
122 	/** the main Gtk struct */
123 	protected GtkDrawingArea* gtkDrawingArea;
124 
125 	/** Get the main Gtk struct */
126 	public GtkDrawingArea* getDrawingAreaStruct(bool transferOwnership = false)
127 	{
128 		if (transferOwnership)
129 			ownedRef = false;
130 		return gtkDrawingArea;
131 	}
132 
133 	/** the main Gtk struct as a void* */
134 	protected override void* getStruct()
135 	{
136 		return cast(void*)gtkDrawingArea;
137 	}
138 
139 	/**
140 	 * Sets our main struct and passes it to the parent class.
141 	 */
142 	public this (GtkDrawingArea* gtkDrawingArea, bool ownedRef = false)
143 	{
144 		this.gtkDrawingArea = gtkDrawingArea;
145 		super(cast(GtkWidget*)gtkDrawingArea, ownedRef);
146 	}
147 
148 	/**
149 	 * Create a new DrawingArea and sets the SizeRequest
150 	 * Params:
151 	 *    	width =
152 	 *    	height =
153 	 */
154 	this(int width, int height)
155 	{
156 		this();
157 		setSizeRequest(width, height);
158 	}
159 
160 	/**
161 	 */
162 
163 	/** */
164 	public static GType getType()
165 	{
166 		return gtk_drawing_area_get_type();
167 	}
168 
169 	/**
170 	 * Creates a new drawing area.
171 	 *
172 	 * Returns: a new #GtkDrawingArea
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this()
177 	{
178 		auto p = gtk_drawing_area_new();
179 
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by new");
183 		}
184 
185 		this(cast(GtkDrawingArea*) p);
186 	}
187 }