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 protected class OnDaySelectedDelegateWrapper 304 { 305 void delegate(Calendar) dlg; 306 gulong handlerId; 307 308 this(void delegate(Calendar) dlg) 309 { 310 this.dlg = dlg; 311 onDaySelectedListeners ~= this; 312 } 313 314 void remove(OnDaySelectedDelegateWrapper source) 315 { 316 foreach(index, wrapper; onDaySelectedListeners) 317 { 318 if (wrapper.handlerId == source.handlerId) 319 { 320 onDaySelectedListeners[index] = null; 321 onDaySelectedListeners = std.algorithm.remove(onDaySelectedListeners, index); 322 break; 323 } 324 } 325 } 326 } 327 OnDaySelectedDelegateWrapper[] onDaySelectedListeners; 328 329 /** 330 * Emitted when the user selects a day. 331 */ 332 gulong addOnDaySelected(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 333 { 334 auto wrapper = new OnDaySelectedDelegateWrapper(dlg); 335 wrapper.handlerId = Signals.connectData( 336 this, 337 "day-selected", 338 cast(GCallback)&callBackDaySelected, 339 cast(void*)wrapper, 340 cast(GClosureNotify)&callBackDaySelectedDestroy, 341 connectFlags); 342 return wrapper.handlerId; 343 } 344 345 extern(C) static void callBackDaySelected(GtkCalendar* calendarStruct, OnDaySelectedDelegateWrapper wrapper) 346 { 347 wrapper.dlg(wrapper.outer); 348 } 349 350 extern(C) static void callBackDaySelectedDestroy(OnDaySelectedDelegateWrapper wrapper, GClosure* closure) 351 { 352 wrapper.remove(wrapper); 353 } 354 355 protected class OnDaySelectedDoubleClickDelegateWrapper 356 { 357 void delegate(Calendar) dlg; 358 gulong handlerId; 359 360 this(void delegate(Calendar) dlg) 361 { 362 this.dlg = dlg; 363 onDaySelectedDoubleClickListeners ~= this; 364 } 365 366 void remove(OnDaySelectedDoubleClickDelegateWrapper source) 367 { 368 foreach(index, wrapper; onDaySelectedDoubleClickListeners) 369 { 370 if (wrapper.handlerId == source.handlerId) 371 { 372 onDaySelectedDoubleClickListeners[index] = null; 373 onDaySelectedDoubleClickListeners = std.algorithm.remove(onDaySelectedDoubleClickListeners, index); 374 break; 375 } 376 } 377 } 378 } 379 OnDaySelectedDoubleClickDelegateWrapper[] onDaySelectedDoubleClickListeners; 380 381 /** 382 * Emitted when the user double-clicks a day. 383 */ 384 gulong addOnDaySelectedDoubleClick(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 385 { 386 auto wrapper = new OnDaySelectedDoubleClickDelegateWrapper(dlg); 387 wrapper.handlerId = Signals.connectData( 388 this, 389 "day-selected-double-click", 390 cast(GCallback)&callBackDaySelectedDoubleClick, 391 cast(void*)wrapper, 392 cast(GClosureNotify)&callBackDaySelectedDoubleClickDestroy, 393 connectFlags); 394 return wrapper.handlerId; 395 } 396 397 extern(C) static void callBackDaySelectedDoubleClick(GtkCalendar* calendarStruct, OnDaySelectedDoubleClickDelegateWrapper wrapper) 398 { 399 wrapper.dlg(wrapper.outer); 400 } 401 402 extern(C) static void callBackDaySelectedDoubleClickDestroy(OnDaySelectedDoubleClickDelegateWrapper wrapper, GClosure* closure) 403 { 404 wrapper.remove(wrapper); 405 } 406 407 protected class OnMonthChangedDelegateWrapper 408 { 409 void delegate(Calendar) dlg; 410 gulong handlerId; 411 412 this(void delegate(Calendar) dlg) 413 { 414 this.dlg = dlg; 415 onMonthChangedListeners ~= this; 416 } 417 418 void remove(OnMonthChangedDelegateWrapper source) 419 { 420 foreach(index, wrapper; onMonthChangedListeners) 421 { 422 if (wrapper.handlerId == source.handlerId) 423 { 424 onMonthChangedListeners[index] = null; 425 onMonthChangedListeners = std.algorithm.remove(onMonthChangedListeners, index); 426 break; 427 } 428 } 429 } 430 } 431 OnMonthChangedDelegateWrapper[] onMonthChangedListeners; 432 433 /** 434 * Emitted when the user clicks a button to change the selected month on a 435 * calendar. 436 */ 437 gulong addOnMonthChanged(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 438 { 439 auto wrapper = new OnMonthChangedDelegateWrapper(dlg); 440 wrapper.handlerId = Signals.connectData( 441 this, 442 "month-changed", 443 cast(GCallback)&callBackMonthChanged, 444 cast(void*)wrapper, 445 cast(GClosureNotify)&callBackMonthChangedDestroy, 446 connectFlags); 447 return wrapper.handlerId; 448 } 449 450 extern(C) static void callBackMonthChanged(GtkCalendar* calendarStruct, OnMonthChangedDelegateWrapper wrapper) 451 { 452 wrapper.dlg(wrapper.outer); 453 } 454 455 extern(C) static void callBackMonthChangedDestroy(OnMonthChangedDelegateWrapper wrapper, GClosure* closure) 456 { 457 wrapper.remove(wrapper); 458 } 459 460 protected class OnNextMonthDelegateWrapper 461 { 462 void delegate(Calendar) dlg; 463 gulong handlerId; 464 465 this(void delegate(Calendar) dlg) 466 { 467 this.dlg = dlg; 468 onNextMonthListeners ~= this; 469 } 470 471 void remove(OnNextMonthDelegateWrapper source) 472 { 473 foreach(index, wrapper; onNextMonthListeners) 474 { 475 if (wrapper.handlerId == source.handlerId) 476 { 477 onNextMonthListeners[index] = null; 478 onNextMonthListeners = std.algorithm.remove(onNextMonthListeners, index); 479 break; 480 } 481 } 482 } 483 } 484 OnNextMonthDelegateWrapper[] onNextMonthListeners; 485 486 /** 487 * Emitted when the user switched to the next month. 488 */ 489 gulong addOnNextMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 490 { 491 auto wrapper = new OnNextMonthDelegateWrapper(dlg); 492 wrapper.handlerId = Signals.connectData( 493 this, 494 "next-month", 495 cast(GCallback)&callBackNextMonth, 496 cast(void*)wrapper, 497 cast(GClosureNotify)&callBackNextMonthDestroy, 498 connectFlags); 499 return wrapper.handlerId; 500 } 501 502 extern(C) static void callBackNextMonth(GtkCalendar* calendarStruct, OnNextMonthDelegateWrapper wrapper) 503 { 504 wrapper.dlg(wrapper.outer); 505 } 506 507 extern(C) static void callBackNextMonthDestroy(OnNextMonthDelegateWrapper wrapper, GClosure* closure) 508 { 509 wrapper.remove(wrapper); 510 } 511 512 protected class OnNextYearDelegateWrapper 513 { 514 void delegate(Calendar) dlg; 515 gulong handlerId; 516 517 this(void delegate(Calendar) dlg) 518 { 519 this.dlg = dlg; 520 onNextYearListeners ~= this; 521 } 522 523 void remove(OnNextYearDelegateWrapper source) 524 { 525 foreach(index, wrapper; onNextYearListeners) 526 { 527 if (wrapper.handlerId == source.handlerId) 528 { 529 onNextYearListeners[index] = null; 530 onNextYearListeners = std.algorithm.remove(onNextYearListeners, index); 531 break; 532 } 533 } 534 } 535 } 536 OnNextYearDelegateWrapper[] onNextYearListeners; 537 538 /** 539 * Emitted when user switched to the next year. 540 */ 541 gulong addOnNextYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 542 { 543 auto wrapper = new OnNextYearDelegateWrapper(dlg); 544 wrapper.handlerId = Signals.connectData( 545 this, 546 "next-year", 547 cast(GCallback)&callBackNextYear, 548 cast(void*)wrapper, 549 cast(GClosureNotify)&callBackNextYearDestroy, 550 connectFlags); 551 return wrapper.handlerId; 552 } 553 554 extern(C) static void callBackNextYear(GtkCalendar* calendarStruct, OnNextYearDelegateWrapper wrapper) 555 { 556 wrapper.dlg(wrapper.outer); 557 } 558 559 extern(C) static void callBackNextYearDestroy(OnNextYearDelegateWrapper wrapper, GClosure* closure) 560 { 561 wrapper.remove(wrapper); 562 } 563 564 protected class OnPrevMonthDelegateWrapper 565 { 566 void delegate(Calendar) dlg; 567 gulong handlerId; 568 569 this(void delegate(Calendar) dlg) 570 { 571 this.dlg = dlg; 572 onPrevMonthListeners ~= this; 573 } 574 575 void remove(OnPrevMonthDelegateWrapper source) 576 { 577 foreach(index, wrapper; onPrevMonthListeners) 578 { 579 if (wrapper.handlerId == source.handlerId) 580 { 581 onPrevMonthListeners[index] = null; 582 onPrevMonthListeners = std.algorithm.remove(onPrevMonthListeners, index); 583 break; 584 } 585 } 586 } 587 } 588 OnPrevMonthDelegateWrapper[] onPrevMonthListeners; 589 590 /** 591 * Emitted when the user switched to the previous month. 592 */ 593 gulong addOnPrevMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 594 { 595 auto wrapper = new OnPrevMonthDelegateWrapper(dlg); 596 wrapper.handlerId = Signals.connectData( 597 this, 598 "prev-month", 599 cast(GCallback)&callBackPrevMonth, 600 cast(void*)wrapper, 601 cast(GClosureNotify)&callBackPrevMonthDestroy, 602 connectFlags); 603 return wrapper.handlerId; 604 } 605 606 extern(C) static void callBackPrevMonth(GtkCalendar* calendarStruct, OnPrevMonthDelegateWrapper wrapper) 607 { 608 wrapper.dlg(wrapper.outer); 609 } 610 611 extern(C) static void callBackPrevMonthDestroy(OnPrevMonthDelegateWrapper wrapper, GClosure* closure) 612 { 613 wrapper.remove(wrapper); 614 } 615 616 protected class OnPrevYearDelegateWrapper 617 { 618 void delegate(Calendar) dlg; 619 gulong handlerId; 620 621 this(void delegate(Calendar) dlg) 622 { 623 this.dlg = dlg; 624 onPrevYearListeners ~= this; 625 } 626 627 void remove(OnPrevYearDelegateWrapper source) 628 { 629 foreach(index, wrapper; onPrevYearListeners) 630 { 631 if (wrapper.handlerId == source.handlerId) 632 { 633 onPrevYearListeners[index] = null; 634 onPrevYearListeners = std.algorithm.remove(onPrevYearListeners, index); 635 break; 636 } 637 } 638 } 639 } 640 OnPrevYearDelegateWrapper[] onPrevYearListeners; 641 642 /** 643 * Emitted when user switched to the previous year. 644 */ 645 gulong addOnPrevYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 646 { 647 auto wrapper = new OnPrevYearDelegateWrapper(dlg); 648 wrapper.handlerId = Signals.connectData( 649 this, 650 "prev-year", 651 cast(GCallback)&callBackPrevYear, 652 cast(void*)wrapper, 653 cast(GClosureNotify)&callBackPrevYearDestroy, 654 connectFlags); 655 return wrapper.handlerId; 656 } 657 658 extern(C) static void callBackPrevYear(GtkCalendar* calendarStruct, OnPrevYearDelegateWrapper wrapper) 659 { 660 wrapper.dlg(wrapper.outer); 661 } 662 663 extern(C) static void callBackPrevYearDestroy(OnPrevYearDelegateWrapper wrapper, GClosure* closure) 664 { 665 wrapper.remove(wrapper); 666 } 667 }