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