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 	protected override void setStruct(GObject* obj)
80 	{
81 		gtkCalendar = cast(GtkCalendar*)obj;
82 		super.setStruct(obj);
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GtkCalendar* gtkCalendar, bool ownedRef = false)
89 	{
90 		this.gtkCalendar = gtkCalendar;
91 		super(cast(GtkWidget*)gtkCalendar, ownedRef);
92 	}
93 
94 
95 	/** */
96 	public static GType getType()
97 	{
98 		return gtk_calendar_get_type();
99 	}
100 
101 	/**
102 	 * Creates a new calendar, with the current date being selected.
103 	 *
104 	 * Returns: a newly #GtkCalendar widget
105 	 *
106 	 * Throws: ConstructionException GTK+ fails to create the object.
107 	 */
108 	public this()
109 	{
110 		auto p = gtk_calendar_new();
111 
112 		if(p is null)
113 		{
114 			throw new ConstructionException("null returned by new");
115 		}
116 
117 		this(cast(GtkCalendar*) p);
118 	}
119 
120 	/**
121 	 * Remove all visual markers.
122 	 */
123 	public void clearMarks()
124 	{
125 		gtk_calendar_clear_marks(gtkCalendar);
126 	}
127 
128 	/**
129 	 * Obtains the selected date from a #GtkCalendar.
130 	 *
131 	 * Params:
132 	 *     year = location to store the year as a decimal
133 	 *         number (e.g. 2011), or %NULL
134 	 *     month = location to store the month number
135 	 *         (between 0 and 11), or %NULL
136 	 *     day = location to store the day number (between
137 	 *         1 and 31), or %NULL
138 	 */
139 	public void getDate(out uint year, out uint month, out uint day)
140 	{
141 		gtk_calendar_get_date(gtkCalendar, &year, &month, &day);
142 	}
143 
144 	/**
145 	 * Returns if the @day of the @calendar is already marked.
146 	 *
147 	 * Params:
148 	 *     day = the day number between 1 and 31.
149 	 *
150 	 * Returns: whether the day is marked.
151 	 *
152 	 * Since: 3.0
153 	 */
154 	public bool getDayIsMarked(uint day)
155 	{
156 		return gtk_calendar_get_day_is_marked(gtkCalendar, day) != 0;
157 	}
158 
159 	/**
160 	 * Queries the height of detail cells, in rows.
161 	 * See #GtkCalendar:detail-width-chars.
162 	 *
163 	 * Returns: The height of detail cells, in rows.
164 	 *
165 	 * Since: 2.14
166 	 */
167 	public int getDetailHeightRows()
168 	{
169 		return gtk_calendar_get_detail_height_rows(gtkCalendar);
170 	}
171 
172 	/**
173 	 * Queries the width of detail cells, in characters.
174 	 * See #GtkCalendar:detail-width-chars.
175 	 *
176 	 * Returns: The width of detail cells, in characters.
177 	 *
178 	 * Since: 2.14
179 	 */
180 	public int getDetailWidthChars()
181 	{
182 		return gtk_calendar_get_detail_width_chars(gtkCalendar);
183 	}
184 
185 	/**
186 	 * Returns the current display options of @calendar.
187 	 *
188 	 * Returns: the display options.
189 	 *
190 	 * Since: 2.4
191 	 */
192 	public GtkCalendarDisplayOptions getDisplayOptions()
193 	{
194 		return gtk_calendar_get_display_options(gtkCalendar);
195 	}
196 
197 	/**
198 	 * Places a visual marker on a particular day.
199 	 *
200 	 * Params:
201 	 *     day = the day number to mark between 1 and 31.
202 	 */
203 	public void markDay(uint day)
204 	{
205 		gtk_calendar_mark_day(gtkCalendar, day);
206 	}
207 
208 	/**
209 	 * Selects a day from the current month.
210 	 *
211 	 * Params:
212 	 *     day = the day number between 1 and 31, or 0 to unselect
213 	 *         the currently selected day.
214 	 */
215 	public void selectDay(uint day)
216 	{
217 		gtk_calendar_select_day(gtkCalendar, day);
218 	}
219 
220 	/**
221 	 * Shifts the calendar to a different month.
222 	 *
223 	 * Params:
224 	 *     month = a month number between 0 and 11.
225 	 *     year = the year the month is in.
226 	 */
227 	public void selectMonth(uint month, uint year)
228 	{
229 		gtk_calendar_select_month(gtkCalendar, month, year);
230 	}
231 
232 	/**
233 	 * Installs a function which provides Pango markup with detail information
234 	 * for each day. Examples for such details are holidays or appointments. That
235 	 * information is shown below each day when #GtkCalendar:show-details is set.
236 	 * A tooltip containing with full detail information is provided, if the entire
237 	 * text should not fit into the details area, or if #GtkCalendar:show-details
238 	 * is not set.
239 	 *
240 	 * The size of the details area can be restricted by setting the
241 	 * #GtkCalendar:detail-width-chars and #GtkCalendar:detail-height-rows
242 	 * properties.
243 	 *
244 	 * Params:
245 	 *     func = a function providing details for each day.
246 	 *     data = data to pass to @func invokations.
247 	 *     destroy = a function for releasing @data.
248 	 *
249 	 * Since: 2.14
250 	 */
251 	public void setDetailFunc(GtkCalendarDetailFunc func, void* data, GDestroyNotify destroy)
252 	{
253 		gtk_calendar_set_detail_func(gtkCalendar, func, data, destroy);
254 	}
255 
256 	/**
257 	 * Updates the height of detail cells.
258 	 * See #GtkCalendar:detail-height-rows.
259 	 *
260 	 * Params:
261 	 *     rows = detail height in rows.
262 	 *
263 	 * Since: 2.14
264 	 */
265 	public void setDetailHeightRows(int rows)
266 	{
267 		gtk_calendar_set_detail_height_rows(gtkCalendar, rows);
268 	}
269 
270 	/**
271 	 * Updates the width of detail cells.
272 	 * See #GtkCalendar:detail-width-chars.
273 	 *
274 	 * Params:
275 	 *     chars = detail width in characters.
276 	 *
277 	 * Since: 2.14
278 	 */
279 	public void setDetailWidthChars(int chars)
280 	{
281 		gtk_calendar_set_detail_width_chars(gtkCalendar, chars);
282 	}
283 
284 	/**
285 	 * Sets display options (whether to display the heading and the month
286 	 * headings).
287 	 *
288 	 * Params:
289 	 *     flags = the display options to set
290 	 *
291 	 * Since: 2.4
292 	 */
293 	public void setDisplayOptions(GtkCalendarDisplayOptions flags)
294 	{
295 		gtk_calendar_set_display_options(gtkCalendar, flags);
296 	}
297 
298 	/**
299 	 * Removes the visual marker from a particular day.
300 	 *
301 	 * Params:
302 	 *     day = the day number to unmark between 1 and 31.
303 	 */
304 	public void unmarkDay(uint day)
305 	{
306 		gtk_calendar_unmark_day(gtkCalendar, day);
307 	}
308 
309 	protected class OnDaySelectedDelegateWrapper
310 	{
311 		void delegate(Calendar) dlg;
312 		gulong handlerId;
313 
314 		this(void delegate(Calendar) dlg)
315 		{
316 			this.dlg = dlg;
317 			onDaySelectedListeners ~= this;
318 		}
319 
320 		void remove(OnDaySelectedDelegateWrapper source)
321 		{
322 			foreach(index, wrapper; onDaySelectedListeners)
323 			{
324 				if (wrapper.handlerId == source.handlerId)
325 				{
326 					onDaySelectedListeners[index] = null;
327 					onDaySelectedListeners = std.algorithm.remove(onDaySelectedListeners, index);
328 					break;
329 				}
330 			}
331 		}
332 	}
333 	OnDaySelectedDelegateWrapper[] onDaySelectedListeners;
334 
335 	/**
336 	 * Emitted when the user selects a day.
337 	 */
338 	gulong addOnDaySelected(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
339 	{
340 		auto wrapper = new OnDaySelectedDelegateWrapper(dlg);
341 		wrapper.handlerId = Signals.connectData(
342 			this,
343 			"day-selected",
344 			cast(GCallback)&callBackDaySelected,
345 			cast(void*)wrapper,
346 			cast(GClosureNotify)&callBackDaySelectedDestroy,
347 			connectFlags);
348 		return wrapper.handlerId;
349 	}
350 
351 	extern(C) static void callBackDaySelected(GtkCalendar* calendarStruct, OnDaySelectedDelegateWrapper wrapper)
352 	{
353 		wrapper.dlg(wrapper.outer);
354 	}
355 
356 	extern(C) static void callBackDaySelectedDestroy(OnDaySelectedDelegateWrapper wrapper, GClosure* closure)
357 	{
358 		wrapper.remove(wrapper);
359 	}
360 
361 	protected class OnDaySelectedDoubleClickDelegateWrapper
362 	{
363 		void delegate(Calendar) dlg;
364 		gulong handlerId;
365 
366 		this(void delegate(Calendar) dlg)
367 		{
368 			this.dlg = dlg;
369 			onDaySelectedDoubleClickListeners ~= this;
370 		}
371 
372 		void remove(OnDaySelectedDoubleClickDelegateWrapper source)
373 		{
374 			foreach(index, wrapper; onDaySelectedDoubleClickListeners)
375 			{
376 				if (wrapper.handlerId == source.handlerId)
377 				{
378 					onDaySelectedDoubleClickListeners[index] = null;
379 					onDaySelectedDoubleClickListeners = std.algorithm.remove(onDaySelectedDoubleClickListeners, index);
380 					break;
381 				}
382 			}
383 		}
384 	}
385 	OnDaySelectedDoubleClickDelegateWrapper[] onDaySelectedDoubleClickListeners;
386 
387 	/**
388 	 * Emitted when the user double-clicks a day.
389 	 */
390 	gulong addOnDaySelectedDoubleClick(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
391 	{
392 		auto wrapper = new OnDaySelectedDoubleClickDelegateWrapper(dlg);
393 		wrapper.handlerId = Signals.connectData(
394 			this,
395 			"day-selected-double-click",
396 			cast(GCallback)&callBackDaySelectedDoubleClick,
397 			cast(void*)wrapper,
398 			cast(GClosureNotify)&callBackDaySelectedDoubleClickDestroy,
399 			connectFlags);
400 		return wrapper.handlerId;
401 	}
402 
403 	extern(C) static void callBackDaySelectedDoubleClick(GtkCalendar* calendarStruct, OnDaySelectedDoubleClickDelegateWrapper wrapper)
404 	{
405 		wrapper.dlg(wrapper.outer);
406 	}
407 
408 	extern(C) static void callBackDaySelectedDoubleClickDestroy(OnDaySelectedDoubleClickDelegateWrapper wrapper, GClosure* closure)
409 	{
410 		wrapper.remove(wrapper);
411 	}
412 
413 	protected class OnMonthChangedDelegateWrapper
414 	{
415 		void delegate(Calendar) dlg;
416 		gulong handlerId;
417 
418 		this(void delegate(Calendar) dlg)
419 		{
420 			this.dlg = dlg;
421 			onMonthChangedListeners ~= this;
422 		}
423 
424 		void remove(OnMonthChangedDelegateWrapper source)
425 		{
426 			foreach(index, wrapper; onMonthChangedListeners)
427 			{
428 				if (wrapper.handlerId == source.handlerId)
429 				{
430 					onMonthChangedListeners[index] = null;
431 					onMonthChangedListeners = std.algorithm.remove(onMonthChangedListeners, index);
432 					break;
433 				}
434 			}
435 		}
436 	}
437 	OnMonthChangedDelegateWrapper[] onMonthChangedListeners;
438 
439 	/**
440 	 * Emitted when the user clicks a button to change the selected month on a
441 	 * calendar.
442 	 */
443 	gulong addOnMonthChanged(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
444 	{
445 		auto wrapper = new OnMonthChangedDelegateWrapper(dlg);
446 		wrapper.handlerId = Signals.connectData(
447 			this,
448 			"month-changed",
449 			cast(GCallback)&callBackMonthChanged,
450 			cast(void*)wrapper,
451 			cast(GClosureNotify)&callBackMonthChangedDestroy,
452 			connectFlags);
453 		return wrapper.handlerId;
454 	}
455 
456 	extern(C) static void callBackMonthChanged(GtkCalendar* calendarStruct, OnMonthChangedDelegateWrapper wrapper)
457 	{
458 		wrapper.dlg(wrapper.outer);
459 	}
460 
461 	extern(C) static void callBackMonthChangedDestroy(OnMonthChangedDelegateWrapper wrapper, GClosure* closure)
462 	{
463 		wrapper.remove(wrapper);
464 	}
465 
466 	protected class OnNextMonthDelegateWrapper
467 	{
468 		void delegate(Calendar) dlg;
469 		gulong handlerId;
470 
471 		this(void delegate(Calendar) dlg)
472 		{
473 			this.dlg = dlg;
474 			onNextMonthListeners ~= this;
475 		}
476 
477 		void remove(OnNextMonthDelegateWrapper source)
478 		{
479 			foreach(index, wrapper; onNextMonthListeners)
480 			{
481 				if (wrapper.handlerId == source.handlerId)
482 				{
483 					onNextMonthListeners[index] = null;
484 					onNextMonthListeners = std.algorithm.remove(onNextMonthListeners, index);
485 					break;
486 				}
487 			}
488 		}
489 	}
490 	OnNextMonthDelegateWrapper[] onNextMonthListeners;
491 
492 	/**
493 	 * Emitted when the user switched to the next month.
494 	 */
495 	gulong addOnNextMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
496 	{
497 		auto wrapper = new OnNextMonthDelegateWrapper(dlg);
498 		wrapper.handlerId = Signals.connectData(
499 			this,
500 			"next-month",
501 			cast(GCallback)&callBackNextMonth,
502 			cast(void*)wrapper,
503 			cast(GClosureNotify)&callBackNextMonthDestroy,
504 			connectFlags);
505 		return wrapper.handlerId;
506 	}
507 
508 	extern(C) static void callBackNextMonth(GtkCalendar* calendarStruct, OnNextMonthDelegateWrapper wrapper)
509 	{
510 		wrapper.dlg(wrapper.outer);
511 	}
512 
513 	extern(C) static void callBackNextMonthDestroy(OnNextMonthDelegateWrapper wrapper, GClosure* closure)
514 	{
515 		wrapper.remove(wrapper);
516 	}
517 
518 	protected class OnNextYearDelegateWrapper
519 	{
520 		void delegate(Calendar) dlg;
521 		gulong handlerId;
522 
523 		this(void delegate(Calendar) dlg)
524 		{
525 			this.dlg = dlg;
526 			onNextYearListeners ~= this;
527 		}
528 
529 		void remove(OnNextYearDelegateWrapper source)
530 		{
531 			foreach(index, wrapper; onNextYearListeners)
532 			{
533 				if (wrapper.handlerId == source.handlerId)
534 				{
535 					onNextYearListeners[index] = null;
536 					onNextYearListeners = std.algorithm.remove(onNextYearListeners, index);
537 					break;
538 				}
539 			}
540 		}
541 	}
542 	OnNextYearDelegateWrapper[] onNextYearListeners;
543 
544 	/**
545 	 * Emitted when user switched to the next year.
546 	 */
547 	gulong addOnNextYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
548 	{
549 		auto wrapper = new OnNextYearDelegateWrapper(dlg);
550 		wrapper.handlerId = Signals.connectData(
551 			this,
552 			"next-year",
553 			cast(GCallback)&callBackNextYear,
554 			cast(void*)wrapper,
555 			cast(GClosureNotify)&callBackNextYearDestroy,
556 			connectFlags);
557 		return wrapper.handlerId;
558 	}
559 
560 	extern(C) static void callBackNextYear(GtkCalendar* calendarStruct, OnNextYearDelegateWrapper wrapper)
561 	{
562 		wrapper.dlg(wrapper.outer);
563 	}
564 
565 	extern(C) static void callBackNextYearDestroy(OnNextYearDelegateWrapper wrapper, GClosure* closure)
566 	{
567 		wrapper.remove(wrapper);
568 	}
569 
570 	protected class OnPrevMonthDelegateWrapper
571 	{
572 		void delegate(Calendar) dlg;
573 		gulong handlerId;
574 
575 		this(void delegate(Calendar) dlg)
576 		{
577 			this.dlg = dlg;
578 			onPrevMonthListeners ~= this;
579 		}
580 
581 		void remove(OnPrevMonthDelegateWrapper source)
582 		{
583 			foreach(index, wrapper; onPrevMonthListeners)
584 			{
585 				if (wrapper.handlerId == source.handlerId)
586 				{
587 					onPrevMonthListeners[index] = null;
588 					onPrevMonthListeners = std.algorithm.remove(onPrevMonthListeners, index);
589 					break;
590 				}
591 			}
592 		}
593 	}
594 	OnPrevMonthDelegateWrapper[] onPrevMonthListeners;
595 
596 	/**
597 	 * Emitted when the user switched to the previous month.
598 	 */
599 	gulong addOnPrevMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
600 	{
601 		auto wrapper = new OnPrevMonthDelegateWrapper(dlg);
602 		wrapper.handlerId = Signals.connectData(
603 			this,
604 			"prev-month",
605 			cast(GCallback)&callBackPrevMonth,
606 			cast(void*)wrapper,
607 			cast(GClosureNotify)&callBackPrevMonthDestroy,
608 			connectFlags);
609 		return wrapper.handlerId;
610 	}
611 
612 	extern(C) static void callBackPrevMonth(GtkCalendar* calendarStruct, OnPrevMonthDelegateWrapper wrapper)
613 	{
614 		wrapper.dlg(wrapper.outer);
615 	}
616 
617 	extern(C) static void callBackPrevMonthDestroy(OnPrevMonthDelegateWrapper wrapper, GClosure* closure)
618 	{
619 		wrapper.remove(wrapper);
620 	}
621 
622 	protected class OnPrevYearDelegateWrapper
623 	{
624 		void delegate(Calendar) dlg;
625 		gulong handlerId;
626 
627 		this(void delegate(Calendar) dlg)
628 		{
629 			this.dlg = dlg;
630 			onPrevYearListeners ~= this;
631 		}
632 
633 		void remove(OnPrevYearDelegateWrapper source)
634 		{
635 			foreach(index, wrapper; onPrevYearListeners)
636 			{
637 				if (wrapper.handlerId == source.handlerId)
638 				{
639 					onPrevYearListeners[index] = null;
640 					onPrevYearListeners = std.algorithm.remove(onPrevYearListeners, index);
641 					break;
642 				}
643 			}
644 		}
645 	}
646 	OnPrevYearDelegateWrapper[] onPrevYearListeners;
647 
648 	/**
649 	 * Emitted when user switched to the previous year.
650 	 */
651 	gulong addOnPrevYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
652 	{
653 		auto wrapper = new OnPrevYearDelegateWrapper(dlg);
654 		wrapper.handlerId = Signals.connectData(
655 			this,
656 			"prev-year",
657 			cast(GCallback)&callBackPrevYear,
658 			cast(void*)wrapper,
659 			cast(GClosureNotify)&callBackPrevYearDestroy,
660 			connectFlags);
661 		return wrapper.handlerId;
662 	}
663 
664 	extern(C) static void callBackPrevYear(GtkCalendar* calendarStruct, OnPrevYearDelegateWrapper wrapper)
665 	{
666 		wrapper.dlg(wrapper.outer);
667 	}
668 
669 	extern(C) static void callBackPrevYearDestroy(OnPrevYearDelegateWrapper wrapper, GClosure* closure)
670 	{
671 		wrapper.remove(wrapper);
672 	}
673 }