1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Calendar
--
-- Author : Axel Simon
--
-- Created: 23 May 2001
--
-- Copyright (C) 1999-2005 Axel Simon
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Displays a calendar and allows the user to select a date
--
module Graphics.UI.Gtk.Misc.Calendar (
-- * Detail
--
-- | 'Calendar' is a widget that displays a calendar, one month at a time. It
-- can be created with 'calendarNew'.
--
-- The month and year currently displayed can be altered with
-- 'calendarSelectMonth'. The exact day can be selected from the displayed
-- month using 'calendarSelectDay'.
--
-- To place a visual marker on a particular day, use 'calendarMarkDay' and
-- to remove the marker, 'calendarUnmarkDay'. Alternative, all marks can be
-- cleared with 'calendarClearMarks'.
--
-- The way in which the calendar itself is displayed can be altered using
-- 'calendarSetDisplayOptions'.
--
-- The selected date can be retrieved from a 'Calendar' using
-- 'calendarGetDate'.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----Calendar
-- @
-- * Types
Calendar,
CalendarClass,
castToCalendar, gTypeCalendar,
toCalendar,
CalendarDisplayOptions(..),
-- * Constructors
calendarNew,
-- * Methods
calendarSelectMonth,
calendarSelectDay,
calendarMarkDay,
calendarUnmarkDay,
calendarClearMarks,
#ifndef DISABLE_DEPRECATED
calendarDisplayOptions,
#endif
#if GTK_CHECK_VERSION(2,4,0)
calendarSetDisplayOptions,
calendarGetDisplayOptions,
#endif
calendarGetDate,
#ifndef DISABLE_DEPRECATED
calendarFreeze,
#endif
-- * Attributes
calendarYear,
calendarMonth,
calendarDay,
#if GTK_CHECK_VERSION(2,4,0)
calendarShowHeading,
calendarShowDayNames,
calendarNoMonthChange,
calendarShowWeekNumbers,
#endif
-- calendarDisplayOptions,
-- * Signals
onDaySelected,
afterDaySelected,
onDaySelectedDoubleClick,
afterDaySelectedDoubleClick,
onMonthChanged,
afterMonthChanged,
onNextMonth,
afterNextMonth,
onNextYear,
afterNextYear,
onPrevMonth,
afterPrevMonth,
onPrevYear,
afterPrevYear,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Flags (fromFlags, toFlags)
import System.Glib.Attributes
import System.Glib.Properties
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
import Graphics.UI.Gtk.General.Enums (CalendarDisplayOptions(..))
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Creates a new calendar, with the current date being selected.
--
calendarNew :: IO Calendar
calendarNew =
makeNewObject mkCalendar $
liftM (castPtr :: Ptr Widget -> Ptr Calendar) $
{# call unsafe calendar_new #}
--------------------
-- Methods
-- | Shifts the calendar to a different month.
--
calendarSelectMonth :: CalendarClass self => self
-> Int -- ^ @month@ - a month number between 0 and 11.
-> Int -- ^ @year@ - the year the month is in.
-> IO Bool -- ^ returns @True@, always
calendarSelectMonth self month year =
liftM toBool $
{# call calendar_select_month #}
(toCalendar self)
(fromIntegral month)
(fromIntegral year)
-- | Selects a day from the current month.
--
calendarSelectDay :: CalendarClass self => self
-> Int -- ^ @day@ - the day number between 1 and 31, or 0 to unselect the
-- currently selected day.
-> IO ()
calendarSelectDay self day =
{# call calendar_select_day #}
(toCalendar self)
(fromIntegral day)
-- | Places a visual marker on a particular day.
--
calendarMarkDay :: CalendarClass self => self
-> Int -- ^ @day@ - the day number to mark between 1 and 31.
-> IO Bool -- ^ returns @True@, always
calendarMarkDay self day =
liftM toBool $
{# call calendar_mark_day #}
(toCalendar self)
(fromIntegral day)
-- | Removes the visual marker from a particular day.
--
calendarUnmarkDay :: CalendarClass self => self
-> Int -- ^ @day@ - the day number to unmark between 1 and 31.
-> IO Bool -- ^ returns @True@, always
calendarUnmarkDay self day =
liftM toBool $
{# call calendar_unmark_day #}
(toCalendar self)
(fromIntegral day)
-- | Remove all visual markers.
--
calendarClearMarks :: CalendarClass self => self -> IO ()
calendarClearMarks self =
{# call calendar_clear_marks #}
(toCalendar self)
#if GTK_CHECK_VERSION(2,4,0)
-- | Sets display options (whether to display the heading and the month
-- headings).
--
-- * Available since Gtk+ version 2.4
--
calendarSetDisplayOptions :: CalendarClass self => self
-> [CalendarDisplayOptions]
-> IO ()
calendarSetDisplayOptions self flags =
{# call calendar_set_display_options #}
(toCalendar self)
((fromIntegral . fromFlags) flags)
-- | Returns the current display options for the calendar.
--
-- * Available since Gtk+ version 2.4
--
calendarGetDisplayOptions :: CalendarClass self => self
-> IO [CalendarDisplayOptions]
calendarGetDisplayOptions self =
liftM (toFlags . fromIntegral) $
{# call calendar_get_display_options #}
(toCalendar self)
#endif
#ifndef DISABLE_DEPRECATED
-- | Sets display options (whether to display the heading and the month
-- headings).
--
-- * Warning: this function is deprecated and should not be used in
-- newly-written code. Use 'calendarSetDisplayOptions' instead.
--
calendarDisplayOptions :: CalendarClass self => self
-> [CalendarDisplayOptions] -> IO ()
calendarDisplayOptions self flags =
{# call calendar_display_options #}
(toCalendar self)
((fromIntegral . fromFlags) flags)
#endif
-- | Retrieve the currently selected date.
--
calendarGetDate :: CalendarClass self => self
-> IO (Int,Int,Int) -- ^ @(year, month, day)@
calendarGetDate self =
alloca $ \yearPtr ->
alloca $ \monthPtr ->
alloca $ \dayPtr -> do
{# call unsafe calendar_get_date #}
(toCalendar self)
yearPtr
monthPtr
dayPtr
year <- liftM fromIntegral $ peek yearPtr
month <- liftM fromIntegral $ peek monthPtr
day <- liftM fromIntegral $ peek dayPtr
return (year,month,day)
#ifndef DISABLE_DEPRECATED
-- | Does nothing. Previously locked the display of the calendar for several
-- update operations.
--
-- * Warning: this function is deprecated and should not be used in
-- newly-written code.
--
calendarFreeze :: CalendarClass self => self
-> IO a -- ^ An action that performs several update operations on the
-- calendar. After the action finnishes all the changes made by it
-- are displayed.
-> IO a
calendarFreeze self update = do
{# call unsafe calendar_freeze #} (toCalendar self)
res <- update
{# call calendar_thaw #} (toCalendar self)
return res
#endif
--------------------
-- Attributes
-- | The selected year.
--
-- Allowed values: >= 0
--
-- Default value: 0
--
calendarYear :: CalendarClass self => Attr self Int
calendarYear = newAttrFromIntProperty "year"
-- | The selected month (as a number between 0 and 11).
--
-- Allowed values: [0,11]
--
-- Default value: 0
--
calendarMonth :: CalendarClass self => Attr self Int
calendarMonth = newAttrFromIntProperty "month"
-- | The selected day (as a number between 1 and 31, or 0 to unselect the
-- currently selected day).
--
-- Allowed values: [0,31]
--
-- Default value: 0
--
calendarDay :: CalendarClass self => Attr self Int
calendarDay = newAttrFromIntProperty "day"
#if GTK_CHECK_VERSION(2,4,0)
-- | Determines whether a heading is displayed.
--
-- Default value: @True@
--
calendarShowHeading :: CalendarClass self => Attr self Bool
calendarShowHeading = newAttrFromBoolProperty "show-heading"
-- | Determines whether day names are displayed.
--
-- Default value: @True@
--
calendarShowDayNames :: CalendarClass self => Attr self Bool
calendarShowDayNames = newAttrFromBoolProperty "show-day-names"
-- | Determines whether the selected month can be changed.
--
-- Default value: @False@
--
calendarNoMonthChange :: CalendarClass self => Attr self Bool
calendarNoMonthChange = newAttrFromBoolProperty "no-month-change"
-- | Determines whether week numbers are displayed.
--
-- Default value: @False@
--
calendarShowWeekNumbers :: CalendarClass self => Attr self Bool
calendarShowWeekNumbers = newAttrFromBoolProperty "show-week-numbers"
#endif
-- | \'displayOptions\' property. See 'calendarGetDisplayOptions' and
-- 'calendarSetDisplayOptions'
--
--calendarDisplayOptions :: CalendarClass self => Attr self [CalendarDisplayOptions]
--calendarDisplayOptions = newAttr
-- calendarGetDisplayOptions
-- calendarSetDisplayOptions
--------------------
-- Signals
-- | Emitted when a day was selected.
--
onDaySelected, afterDaySelected :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onDaySelected = connect_NONE__NONE "day-selected" False
afterDaySelected = connect_NONE__NONE "day-selected" True
-- | Emitted when a day received a double click.
--
onDaySelectedDoubleClick, afterDaySelectedDoubleClick :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onDaySelectedDoubleClick =
connect_NONE__NONE "day-selected-double-click" False
afterDaySelectedDoubleClick =
connect_NONE__NONE "day-selected-double-click" True
-- | The month changed.
--
onMonthChanged, afterMonthChanged :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onMonthChanged = connect_NONE__NONE "month-changed" False
afterMonthChanged = connect_NONE__NONE "month-changed" True
-- | The next month was selected.
--
onNextMonth, afterNextMonth :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onNextMonth = connect_NONE__NONE "next-month" False
afterNextMonth = connect_NONE__NONE "next-month" True
-- | The next year was selected.
--
onNextYear, afterNextYear :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onNextYear = connect_NONE__NONE "next-year" False
afterNextYear = connect_NONE__NONE "next-year" True
-- | The previous month was selected.
--
onPrevMonth, afterPrevMonth :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onPrevMonth = connect_NONE__NONE "prev-month" False
afterPrevMonth = connect_NONE__NONE "prev-month" True
-- | The previous year was selected.
--
onPrevYear, afterPrevYear :: CalendarClass self => self
-> IO ()
-> IO (ConnectId self)
onPrevYear = connect_NONE__NONE "prev-year" False
afterPrevYear = connect_NONE__NONE "prev-year" True
|