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()
126 	{
127 		return gtkDrawingArea;
128 	}
129 
130 	/** the main Gtk struct as a void* */
131 	protected override void* getStruct()
132 	{
133 		return cast(void*)gtkDrawingArea;
134 	}
135 
136 	protected override void setStruct(GObject* obj)
137 	{
138 		gtkDrawingArea = cast(GtkDrawingArea*)obj;
139 		super.setStruct(obj);
140 	}
141 
142 	/**
143 	 * Sets our main struct and passes it to the parent class.
144 	 */
145 	public this (GtkDrawingArea* gtkDrawingArea, bool ownedRef = false)
146 	{
147 		this.gtkDrawingArea = gtkDrawingArea;
148 		super(cast(GtkWidget*)gtkDrawingArea, ownedRef);
149 	}
150 
151 	/**
152 	 * Create a new DrawingArea and sets the SizeRequest
153 	 * Params:
154 	 *    	width =
155 	 *    	height =
156 	 */
157 	this(int width, int height)
158 	{
159 		this();
160 		setSizeRequest(width, height);
161 	}
162 
163 	/**
164 	 */
165 
166 	/** */
167 	public static GType getType()
168 	{
169 		return gtk_drawing_area_get_type();
170 	}
171 
172 	/**
173 	 * Creates a new drawing area.
174 	 *
175 	 * Return: a new #GtkDrawingArea
176 	 *
177 	 * Throws: ConstructionException GTK+ fails to create the object.
178 	 */
179 	public this()
180 	{
181 		auto p = gtk_drawing_area_new();
182 		
183 		if(p is null)
184 		{
185 			throw new ConstructionException("null returned by new");
186 		}
187 		
188 		this(cast(GtkDrawingArea*) p);
189 	}
190 }