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