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.Calendar;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Widget;
31 private import gtk.c.functions;
32 public  import gtk.c.types;
33 public  import gtkc.gtktypes;
34 private import std.algorithm;
35 
36 
37 /**
38  * #GtkCalendar is a widget that displays a Gregorian calendar, one month
39  * at a time. It can be created with gtk_calendar_new().
40  * 
41  * The month and year currently displayed can be altered with
42  * gtk_calendar_select_month(). The exact day can be selected from the
43  * displayed month using gtk_calendar_select_day().
44  * 
45  * To place a visual marker on a particular day, use gtk_calendar_mark_day()
46  * and to remove the marker, gtk_calendar_unmark_day(). Alternative, all
47  * marks can be cleared with gtk_calendar_clear_marks().
48  * 
49  * The way in which the calendar itself is displayed can be altered using
50  * gtk_calendar_set_display_options().
51  * 
52  * The selected date can be retrieved from a #GtkCalendar using
53  * gtk_calendar_get_date().
54  * 
55  * Users should be aware that, although the Gregorian calendar is the
56  * legal calendar in most countries, it was adopted progressively
57  * between 1582 and 1929. Display before these dates is likely to be
58  * historically incorrect.
59  */
60 public class Calendar : Widget
61 {
62 	/** the main Gtk struct */
63 	protected GtkCalendar* gtkCalendar;
64 
65 	/** Get the main Gtk struct */
66 	public GtkCalendar* getCalendarStruct(bool transferOwnership = false)
67 	{
68 		if (transferOwnership)
69 			ownedRef = false;
70 		return gtkCalendar;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)gtkCalendar;
77 	}
78 
79 	/**
80 	 * Sets our main struct and passes it to the parent class.
81 	 */
82 	public this (GtkCalendar* gtkCalendar, bool ownedRef = false)
83 	{
84 		this.gtkCalendar = gtkCalendar;
85 		super(cast(GtkWidget*)gtkCalendar, ownedRef);
86 	}
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return gtk_calendar_get_type();
93 	}
94 
95 	/**
96 	 * Creates a new calendar, with the current date being selected.
97 	 *
98 	 * Returns: a newly #GtkCalendar widget
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this()
103 	{
104 		auto p = gtk_calendar_new();
105 
106 		if(p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 
111 		this(cast(GtkCalendar*) p);
112 	}
113 
114 	/**
115 	 * Remove all visual markers.
116 	 */
117 	public void clearMarks()
118 	{
119 		gtk_calendar_clear_marks(gtkCalendar);
120 	}
121 
122 	/**
123 	 * Obtains the selected date from a #GtkCalendar.
124 	 *
125 	 * Params:
126 	 *     year = location to store the year as a decimal
127 	 *         number (e.g. 2011), or %NULL
128 	 *     month = location to store the month number
129 	 *         (between 0 and 11), or %NULL
130 	 *     day = location to store the day number (between
131 	 *         1 and 31), or %NULL
132 	 */
133 	public void getDate(out uint year, out uint month, out uint day)
134 	{
135 		gtk_calendar_get_date(gtkCalendar, &year, &month, &day);
136 	}
137 
138 	/**
139 	 * Returns if the @day of the @calendar is already marked.
140 	 *
141 	 * Params:
142 	 *     day = the day number between 1 and 31.
143 	 *
144 	 * Returns: whether the day is marked.
145 	 *
146 	 * Since: 3.0
147 	 */
148 	public bool getDayIsMarked(uint day)
149 	{
150 		return gtk_calendar_get_day_is_marked(gtkCalendar, day) != 0;
151 	}
152 
153 	/**
154 	 * Queries the height of detail cells, in rows.
155 	 * See #GtkCalendar:detail-width-chars.
156 	 *
157 	 * Returns: The height of detail cells, in rows.
158 	 *
159 	 * Since: 2.14
160 	 */
161 	public int getDetailHeightRows()
162 	{
163 		return gtk_calendar_get_detail_height_rows(gtkCalendar);
164 	}
165 
166 	/**
167 	 * Queries the width of detail cells, in characters.
168 	 * See #GtkCalendar:detail-width-chars.
169 	 *
170 	 * Returns: The width of detail cells, in characters.
171 	 *
172 	 * Since: 2.14
173 	 */
174 	public int getDetailWidthChars()
175 	{
176 		return gtk_calendar_get_detail_width_chars(gtkCalendar);
177 	}
178 
179 	/**
180 	 * Returns the current display options of @calendar.
181 	 *
182 	 * Returns: the display options.
183 	 *
184 	 * Since: 2.4
185 	 */
186 	public GtkCalendarDisplayOptions getDisplayOptions()
187 	{
188 		return gtk_calendar_get_display_options(gtkCalendar);
189 	}
190 
191 	/**
192 	 * Places a visual marker on a particular day.
193 	 *
194 	 * Params:
195 	 *     day = the day number to mark between 1 and 31.
196 	 */
197 	public void markDay(uint day)
198 	{
199 		gtk_calendar_mark_day(gtkCalendar, day);
200 	}
201 
202 	/**
203 	 * Selects a day from the current month.
204 	 *
205 	 * Params:
206 	 *     day = the day number between 1 and 31, or 0 to unselect
207 	 *         the currently selected day.
208 	 */
209 	public void selectDay(uint day)
210 	{
211 		gtk_calendar_select_day(gtkCalendar, day);
212 	}
213 
214 	/**
215 	 * Shifts the calendar to a different month.
216 	 *
217 	 * Params:
218 	 *     month = a month number between 0 and 11.
219 	 *     year = the year the month is in.
220 	 */
221 	public void selectMonth(uint month, uint year)
222 	{
223 		gtk_calendar_select_month(gtkCalendar, month, year);
224 	}
225 
226 	/**
227 	 * Installs a function which provides Pango markup with detail information
228 	 * for each day. Examples for such details are holidays or appointments. That
229 	 * information is shown below each day when #GtkCalendar:show-details is set.
230 	 * A tooltip containing with full detail information is provided, if the entire
231 	 * text should not fit into the details area, or if #GtkCalendar:show-details
232 	 * is not set.
233 	 *
234 	 * The size of the details area can be restricted by setting the
235 	 * #GtkCalendar:detail-width-chars and #GtkCalendar:detail-height-rows
236 	 * properties.
237 	 *
238 	 * Params:
239 	 *     func = a function providing details for each day.
240 	 *     data = data to pass to @func invokations.
241 	 *     destroy = a function for releasing @data.
242 	 *
243 	 * Since: 2.14
244 	 */
245 	public void setDetailFunc(GtkCalendarDetailFunc func, void* data, GDestroyNotify destroy)
246 	{
247 		gtk_calendar_set_detail_func(gtkCalendar, func, data, destroy);
248 	}
249 
250 	/**
251 	 * Updates the height of detail cells.
252 	 * See #GtkCalendar:detail-height-rows.
253 	 *
254 	 * Params:
255 	 *     rows = detail height in rows.
256 	 *
257 	 * Since: 2.14
258 	 */
259 	public void setDetailHeightRows(int rows)
260 	{
261 		gtk_calendar_set_detail_height_rows(gtkCalendar, rows);
262 	}
263 
264 	/**
265 	 * Updates the width of detail cells.
266 	 * See #GtkCalendar:detail-width-chars.
267 	 *
268 	 * Params:
269 	 *     chars = detail width in characters.
270 	 *
271 	 * Since: 2.14
272 	 */
273 	public void setDetailWidthChars(int chars)
274 	{
275 		gtk_calendar_set_detail_width_chars(gtkCalendar, chars);
276 	}
277 
278 	/**
279 	 * Sets display options (whether to display the heading and the month
280 	 * headings).
281 	 *
282 	 * Params:
283 	 *     flags = the display options to set
284 	 *
285 	 * Since: 2.4
286 	 */
287 	public void setDisplayOptions(GtkCalendarDisplayOptions flags)
288 	{
289 		gtk_calendar_set_display_options(gtkCalendar, flags);
290 	}
291 
292 	/**
293 	 * Removes the visual marker from a particular day.
294 	 *
295 	 * Params:
296 	 *     day = the day number to unmark between 1 and 31.
297 	 */
298 	public void unmarkDay(uint day)
299 	{
300 		gtk_calendar_unmark_day(gtkCalendar, day);
301 	}
302 
303 	/**
304 	 * Emitted when the user selects a day.
305 	 */
306 	gulong addOnDaySelected(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
307 	{
308 		return Signals.connect(this, "day-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED);
309 	}
310 
311 	/**
312 	 * Emitted when the user double-clicks a day.
313 	 */
314 	gulong addOnDaySelectedDoubleClick(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
315 	{
316 		return Signals.connect(this, "day-selected-double-click", dlg, connectFlags ^ ConnectFlags.SWAPPED);
317 	}
318 
319 	/**
320 	 * Emitted when the user clicks a button to change the selected month on a
321 	 * calendar.
322 	 */
323 	gulong addOnMonthChanged(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
324 	{
325 		return Signals.connect(this, "month-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
326 	}
327 
328 	/**
329 	 * Emitted when the user switched to the next month.
330 	 */
331 	gulong addOnNextMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
332 	{
333 		return Signals.connect(this, "next-month", dlg, connectFlags ^ ConnectFlags.SWAPPED);
334 	}
335 
336 	/**
337 	 * Emitted when user switched to the next year.
338 	 */
339 	gulong addOnNextYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
340 	{
341 		return Signals.connect(this, "next-year", dlg, connectFlags ^ ConnectFlags.SWAPPED);
342 	}
343 
344 	/**
345 	 * Emitted when the user switched to the previous month.
346 	 */
347 	gulong addOnPrevMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
348 	{
349 		return Signals.connect(this, "prev-month", dlg, connectFlags ^ ConnectFlags.SWAPPED);
350 	}
351 
352 	/**
353 	 * Emitted when user switched to the previous year.
354 	 */
355 	gulong addOnPrevYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
356 	{
357 		return Signals.connect(this, "prev-year", dlg, connectFlags ^ ConnectFlags.SWAPPED);
358 	}
359 }