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 glib.DateTime; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Widget; 32 private import gtk.c.functions; 33 public import gtk.c.types; 34 private import std.algorithm; 35 36 37 /** 38 * `GtkCalendar` is a widget that displays a Gregorian calendar, one month 39 * at a time. 40 * 41 * ![An example GtkCalendar](calendar.png) 42 * 43 * A `GtkCalendar` can be created with [ctor@Gtk.Calendar.new]. 44 * 45 * The date that is currently displayed can be altered with 46 * [method@Gtk.Calendar.select_day]. 47 * 48 * To place a visual marker on a particular day, use 49 * [method@Gtk.Calendar.mark_day] and to remove the marker, 50 * [method@Gtk.Calendar.unmark_day]. Alternative, all 51 * marks can be cleared with [method@Gtk.Calendar.clear_marks]. 52 * 53 * The selected date can be retrieved from a `GtkCalendar` using 54 * [method@Gtk.Calendar.get_date]. 55 * 56 * Users should be aware that, although the Gregorian calendar is the 57 * legal calendar in most countries, it was adopted progressively 58 * between 1582 and 1929. Display before these dates is likely to be 59 * historically incorrect. 60 * 61 * # CSS nodes 62 * 63 * ``` 64 * calendar.view 65 * ├── header 66 * │ ├── button 67 * │ ├── stack.month 68 * │ ├── button 69 * │ ├── button 70 * │ ├── label.year 71 * │ ╰── button 72 * ╰── grid 73 * ╰── label[.day-name][.week-number][.day-number][.other-month][.today] 74 * ``` 75 * 76 * `GtkCalendar` has a main node with name calendar. It contains a subnode 77 * called header containing the widgets for switching between years and months. 78 * 79 * The grid subnode contains all day labels, including week numbers on the left 80 * (marked with the .week-number css class) and day names on top (marked with the 81 * .day-name css class). 82 * 83 * Day labels that belong to the previous or next month get the .other-month 84 * style class. The label of the current day get the .today style class. 85 * 86 * Marked day labels get the :selected state assigned. 87 */ 88 public class Calendar : Widget 89 { 90 /** the main Gtk struct */ 91 protected GtkCalendar* gtkCalendar; 92 93 /** Get the main Gtk struct */ 94 public GtkCalendar* getCalendarStruct(bool transferOwnership = false) 95 { 96 if (transferOwnership) 97 ownedRef = false; 98 return gtkCalendar; 99 } 100 101 /** the main Gtk struct as a void* */ 102 protected override void* getStruct() 103 { 104 return cast(void*)gtkCalendar; 105 } 106 107 /** 108 * Sets our main struct and passes it to the parent class. 109 */ 110 public this (GtkCalendar* gtkCalendar, bool ownedRef = false) 111 { 112 this.gtkCalendar = gtkCalendar; 113 super(cast(GtkWidget*)gtkCalendar, ownedRef); 114 } 115 116 117 /** */ 118 public static GType getType() 119 { 120 return gtk_calendar_get_type(); 121 } 122 123 /** 124 * Creates a new calendar, with the current date being selected. 125 * 126 * Returns: a newly `GtkCalendar` widget 127 * 128 * Throws: ConstructionException GTK+ fails to create the object. 129 */ 130 public this() 131 { 132 auto __p = gtk_calendar_new(); 133 134 if(__p is null) 135 { 136 throw new ConstructionException("null returned by new"); 137 } 138 139 this(cast(GtkCalendar*) __p); 140 } 141 142 /** 143 * Remove all visual markers. 144 */ 145 public void clearMarks() 146 { 147 gtk_calendar_clear_marks(gtkCalendar); 148 } 149 150 /** 151 * Returns a #GDateTime representing the shown 152 * year, month and the selected day. 153 * 154 * The returned date is in the local time zone. 155 * 156 * Returns: the `GDate` representing 157 * the shown date. 158 */ 159 public DateTime getDate() 160 { 161 auto __p = gtk_calendar_get_date(gtkCalendar); 162 163 if(__p is null) 164 { 165 return null; 166 } 167 168 return new DateTime(cast(GDateTime*) __p, true); 169 } 170 171 /** 172 * Returns if the @day of the @calendar is already marked. 173 * 174 * Params: 175 * day = the day number between 1 and 31. 176 * 177 * Returns: whether the day is marked. 178 */ 179 public bool getDayIsMarked(uint day) 180 { 181 return gtk_calendar_get_day_is_marked(gtkCalendar, day) != 0; 182 } 183 184 /** 185 * Returns whether @self is currently showing the names 186 * of the week days. 187 * 188 * This is the value of the [property@Gtk.Calendar:show-day-names] 189 * property. 190 * 191 * Returns: Whether the calendar shows day names. 192 */ 193 public bool getShowDayNames() 194 { 195 return gtk_calendar_get_show_day_names(gtkCalendar) != 0; 196 } 197 198 /** 199 * Returns whether @self is currently showing the heading. 200 * 201 * This is the value of the [property@Gtk.Calendar:show-heading] 202 * property. 203 * 204 * Returns: Whether the calendar is showing a heading. 205 */ 206 public bool getShowHeading() 207 { 208 return gtk_calendar_get_show_heading(gtkCalendar) != 0; 209 } 210 211 /** 212 * Returns whether @self is showing week numbers right 213 * now. 214 * 215 * This is the value of the [property@Gtk.Calendar:show-week-numbers] 216 * property. 217 * 218 * Returns: Whether the calendar is showing week numbers. 219 */ 220 public bool getShowWeekNumbers() 221 { 222 return gtk_calendar_get_show_week_numbers(gtkCalendar) != 0; 223 } 224 225 /** 226 * Places a visual marker on a particular day. 227 * 228 * Params: 229 * day = the day number to mark between 1 and 31. 230 */ 231 public void markDay(uint day) 232 { 233 gtk_calendar_mark_day(gtkCalendar, day); 234 } 235 236 /** 237 * Switches to @date's year and month and select its day. 238 * 239 * Params: 240 * date = a #GDateTime representing the day to select 241 */ 242 public void selectDay(DateTime date) 243 { 244 gtk_calendar_select_day(gtkCalendar, (date is null) ? null : date.getDateTimeStruct()); 245 } 246 247 /** 248 * Sets whether the calendar shows day names. 249 * 250 * Params: 251 * value = Whether to show day names above the day numbers 252 */ 253 public void setShowDayNames(bool value) 254 { 255 gtk_calendar_set_show_day_names(gtkCalendar, value); 256 } 257 258 /** 259 * Sets whether the calendar should show a heading. 260 * 261 * The heading contains the current year and month as well as 262 * buttons for changing both. 263 * 264 * Params: 265 * value = Whether to show the heading in the calendar 266 */ 267 public void setShowHeading(bool value) 268 { 269 gtk_calendar_set_show_heading(gtkCalendar, value); 270 } 271 272 /** 273 * Sets whether week numbers are shown in the calendar. 274 * 275 * Params: 276 * value = whether to show week numbers on the left of the days 277 */ 278 public void setShowWeekNumbers(bool value) 279 { 280 gtk_calendar_set_show_week_numbers(gtkCalendar, value); 281 } 282 283 /** 284 * Removes the visual marker from a particular day. 285 * 286 * Params: 287 * day = the day number to unmark between 1 and 31. 288 */ 289 public void unmarkDay(uint day) 290 { 291 gtk_calendar_unmark_day(gtkCalendar, day); 292 } 293 294 /** 295 * Emitted when the user selects a day. 296 */ 297 gulong addOnDaySelected(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 298 { 299 return Signals.connect(this, "day-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED); 300 } 301 302 /** 303 * Emitted when the user switched to the next month. 304 */ 305 gulong addOnNextMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 306 { 307 return Signals.connect(this, "next-month", dlg, connectFlags ^ ConnectFlags.SWAPPED); 308 } 309 310 /** 311 * Emitted when user switched to the next year. 312 */ 313 gulong addOnNextYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 314 { 315 return Signals.connect(this, "next-year", dlg, connectFlags ^ ConnectFlags.SWAPPED); 316 } 317 318 /** 319 * Emitted when the user switched to the previous month. 320 */ 321 gulong addOnPrevMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 322 { 323 return Signals.connect(this, "prev-month", dlg, connectFlags ^ ConnectFlags.SWAPPED); 324 } 325 326 /** 327 * Emitted when user switched to the previous year. 328 */ 329 gulong addOnPrevYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 330 { 331 return Signals.connect(this, "prev-year", dlg, connectFlags ^ ConnectFlags.SWAPPED); 332 } 333 }