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 static OnDaySelectedDelegateWrapper[] listeners; 311 void delegate(Calendar) dlg; 312 gulong handlerId; 313 314 this(void delegate(Calendar) dlg) 315 { 316 this.dlg = dlg; 317 this.listeners ~= this; 318 } 319 320 void remove(OnDaySelectedDelegateWrapper source) 321 { 322 foreach(index, wrapper; listeners) 323 { 324 if (wrapper.handlerId == source.handlerId) 325 { 326 listeners[index] = null; 327 listeners = std.algorithm.remove(listeners, index); 328 break; 329 } 330 } 331 } 332 } 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 static OnDaySelectedDoubleClickDelegateWrapper[] listeners; 363 void delegate(Calendar) dlg; 364 gulong handlerId; 365 366 this(void delegate(Calendar) dlg) 367 { 368 this.dlg = dlg; 369 this.listeners ~= this; 370 } 371 372 void remove(OnDaySelectedDoubleClickDelegateWrapper source) 373 { 374 foreach(index, wrapper; listeners) 375 { 376 if (wrapper.handlerId == source.handlerId) 377 { 378 listeners[index] = null; 379 listeners = std.algorithm.remove(listeners, index); 380 break; 381 } 382 } 383 } 384 } 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 static OnMonthChangedDelegateWrapper[] listeners; 415 void delegate(Calendar) dlg; 416 gulong handlerId; 417 418 this(void delegate(Calendar) dlg) 419 { 420 this.dlg = dlg; 421 this.listeners ~= this; 422 } 423 424 void remove(OnMonthChangedDelegateWrapper source) 425 { 426 foreach(index, wrapper; listeners) 427 { 428 if (wrapper.handlerId == source.handlerId) 429 { 430 listeners[index] = null; 431 listeners = std.algorithm.remove(listeners, index); 432 break; 433 } 434 } 435 } 436 } 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 static OnNextMonthDelegateWrapper[] listeners; 468 void delegate(Calendar) dlg; 469 gulong handlerId; 470 471 this(void delegate(Calendar) dlg) 472 { 473 this.dlg = dlg; 474 this.listeners ~= this; 475 } 476 477 void remove(OnNextMonthDelegateWrapper source) 478 { 479 foreach(index, wrapper; listeners) 480 { 481 if (wrapper.handlerId == source.handlerId) 482 { 483 listeners[index] = null; 484 listeners = std.algorithm.remove(listeners, index); 485 break; 486 } 487 } 488 } 489 } 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 static OnNextYearDelegateWrapper[] listeners; 520 void delegate(Calendar) dlg; 521 gulong handlerId; 522 523 this(void delegate(Calendar) dlg) 524 { 525 this.dlg = dlg; 526 this.listeners ~= this; 527 } 528 529 void remove(OnNextYearDelegateWrapper source) 530 { 531 foreach(index, wrapper; listeners) 532 { 533 if (wrapper.handlerId == source.handlerId) 534 { 535 listeners[index] = null; 536 listeners = std.algorithm.remove(listeners, index); 537 break; 538 } 539 } 540 } 541 } 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 static OnPrevMonthDelegateWrapper[] listeners; 572 void delegate(Calendar) dlg; 573 gulong handlerId; 574 575 this(void delegate(Calendar) dlg) 576 { 577 this.dlg = dlg; 578 this.listeners ~= this; 579 } 580 581 void remove(OnPrevMonthDelegateWrapper source) 582 { 583 foreach(index, wrapper; listeners) 584 { 585 if (wrapper.handlerId == source.handlerId) 586 { 587 listeners[index] = null; 588 listeners = std.algorithm.remove(listeners, index); 589 break; 590 } 591 } 592 } 593 } 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 static OnPrevYearDelegateWrapper[] listeners; 624 void delegate(Calendar) dlg; 625 gulong handlerId; 626 627 this(void delegate(Calendar) dlg) 628 { 629 this.dlg = dlg; 630 this.listeners ~= this; 631 } 632 633 void remove(OnPrevYearDelegateWrapper source) 634 { 635 foreach(index, wrapper; listeners) 636 { 637 if (wrapper.handlerId == source.handlerId) 638 { 639 listeners[index] = null; 640 listeners = std.algorithm.remove(listeners, index); 641 break; 642 } 643 } 644 } 645 } 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 }