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 gtkc.gtk;
31 public  import gtkc.gtktypes;
32 
33 
34 /**
35  * The #GtkDrawingArea widget is used for creating custom user interface
36  * elements. It’s essentially a blank widget; you can draw on it. After
37  * creating a drawing area, the application may want to connect to:
38  * 
39  * - Mouse and button press signals to respond to input from
40  * the user. (Use gtk_widget_add_events() to enable events
41  * you wish to receive.)
42  * 
43  * - The #GtkWidget::realize signal to take any necessary actions
44  * when the widget is instantiated on a particular display.
45  * (Create GDK resources in response to this signal.)
46  * 
47  * - The #GtkWidget::size-allocate signal to take any necessary
48  * actions when the widget changes size.
49  * 
50  * - The #GtkWidget::draw signal to handle redrawing the
51  * contents of the widget.
52  * 
53  * The following code portion demonstrates using a drawing
54  * area to display a circle in the normal widget foreground
55  * color.
56  * 
57  * Note that GDK automatically clears the exposed area before sending
58  * the expose event, and that drawing is implicitly clipped to the exposed
59  * area. If you want to have a theme-provided background, you need
60  * to call gtk_render_background() in your ::draw method.
61  * 
62  * ## Simple GtkDrawingArea usage
63  * 
64  * |[<!-- language="C" -->
65  * gboolean
66  * draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
67  * {
68  * guint width, height;
69  * GdkRGBA color;
70  * GtkStyleContext *context;
71  * 
72  * context = gtk_widget_get_style_context (widget);
73  * 
74  * width = gtk_widget_get_allocated_width (widget);
75  * height = gtk_widget_get_allocated_height (widget);
76  * 
77  * gtk_render_background (context, cr, 0, 0, width, height);
78  * 
79  * cairo_arc (cr,
80  * width / 2.0, height / 2.0,
81  * MIN (width, height) / 2.0,
82  * 0, 2 * G_PI);
83  * 
84  * gtk_style_context_get_color (context,
85  * gtk_style_context_get_state (context),
86  * &color);
87  * gdk_cairo_set_source_rgba (cr, &color);
88  * 
89  * cairo_fill (cr);
90  * 
91  * return FALSE;
92  * }
93  * [...]
94  * GtkWidget *drawing_area = gtk_drawing_area_new ();
95  * gtk_widget_set_size_request (drawing_area, 100, 100);
96  * g_signal_connect (G_OBJECT (drawing_area), "draw",
97  * G_CALLBACK (draw_callback), NULL);
98  * ]|
99  * 
100  * Draw signals are normally delivered when a drawing area first comes
101  * onscreen, or when it’s covered by another window and then uncovered.
102  * You can also force an expose event by adding to the “damage region”
103  * of the drawing area’s window; gtk_widget_queue_draw_area() and
104  * gdk_window_invalidate_rect() are equally good ways to do this.
105  * You’ll then get a draw signal for the invalid region.
106  * 
107  * The available routines for drawing are documented on the
108  * [GDK Drawing Primitives][gdk3-Cairo-Interaction] page
109  * and the cairo documentation.
110  * 
111  * To receive mouse events on a drawing area, you will need to enable
112  * them with gtk_widget_add_events(). To receive keyboard events, you
113  * will need to set the “can-focus” property on the drawing area, and you
114  * should probably draw some user-visible indication that the drawing
115  * area is focused. Use gtk_widget_has_focus() in your expose event
116  * handler to decide whether to draw the focus indicator. See
117  * gtk_render_focus() for one way to draw focus.
118  */
119 public class DrawingArea : Widget
120 {
121 	/** the main Gtk struct */
122 	protected GtkDrawingArea* gtkDrawingArea;
123 
124 	/** Get the main Gtk struct */
125 	public GtkDrawingArea* getDrawingAreaStruct(bool transferOwnership = false)
126 	{
127 		if (transferOwnership)
128 			ownedRef = false;
129 		return gtkDrawingArea;
130 	}
131 
132 	/** the main Gtk struct as a void* */
133 	protected override void* getStruct()
134 	{
135 		return cast(void*)gtkDrawingArea;
136 	}
137 
138 	protected override void setStruct(GObject* obj)
139 	{
140 		gtkDrawingArea = cast(GtkDrawingArea*)obj;
141 		super.setStruct(obj);
142 	}
143 
144 	/**
145 	 * Sets our main struct and passes it to the parent class.
146 	 */
147 	public this (GtkDrawingArea* gtkDrawingArea, bool ownedRef = false)
148 	{
149 		this.gtkDrawingArea = gtkDrawingArea;
150 		super(cast(GtkWidget*)gtkDrawingArea, ownedRef);
151 	}
152 
153 	/**
154 	 * Create a new DrawingArea and sets the SizeRequest
155 	 * Params:
156 	 *    	width =
157 	 *    	height =
158 	 */
159 	this(int width, int height)
160 	{
161 		this();
162 		setSizeRequest(width, height);
163 	}
164 
165 	/**
166 	 */
167 
168 	/** */
169 	public static GType getType()
170 	{
171 		return gtk_drawing_area_get_type();
172 	}
173 
174 	/**
175 	 * Creates a new drawing area.
176 	 *
177 	 * Returns: a new #GtkDrawingArea
178 	 *
179 	 * Throws: ConstructionException GTK+ fails to create the object.
180 	 */
181 	public this()
182 	{
183 		auto p = gtk_drawing_area_new();
184 		
185 		if(p is null)
186 		{
187 			throw new ConstructionException("null returned by new");
188 		}
189 		
190 		this(cast(GtkDrawingArea*) p);
191 	}
192 }