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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Assistant
--
-- Author : Andy Stewart
--
-- Created: 22 Mar 2010
--
-- Copyright (C) 2010 Andy Stewart
--
-- 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)
--
-- A widget used to guide users through multi-step operations
--
-- * Module available since Gtk+ version 2.10
--
module Graphics.UI.Gtk.Windows.Assistant (
-- * Detail
--
-- | A 'Assistant' is a widget used to represent a generally complex operation
-- splitted in several steps, guiding the user through its pages and
-- controlling the page flow to collect the necessary data.
-- ** GtkAssistant as GtkBuildable
--
-- | The 'Assistant' implementation of the 'Buildable' interface exposes the
-- @actionArea@ as internal children with the name \"action_area\".
--
-- To add pages to an assistant in 'Builder', simply add it as a \<child> to
-- the 'Assistant' object, and set its child properties as necessary.
-- * Class Hierarchy
--
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----'Window'
-- | +----Assistant
-- @
#if GTK_CHECK_VERSION(2,10,0)
-- * Types
Assistant,
AssistantClass,
castToAssistant,
toAssistant,
-- * Enums.
AssistantPageType(..),
-- * Constructors
assistantNew,
-- * Methods
assistantGetNPages,
assistantGetNthPage,
assistantPrependPage,
assistantAppendPage,
assistantInsertPage,
assistantSetForwardPageFunc,
assistantAddActionWidget,
assistantRemoveActionWidget,
assistantUpdateButtonsState,
assistantSetPageType,
assistantGetPageType,
assistantSetPageTitle,
assistantGetPageTitle,
assistantSetPageHeaderImage,
assistantGetPageHeaderImage,
assistantSetPageSideImage,
assistantGetPageSideImage,
assistantSetPageComplete,
assistantGetPageComplete,
#if GTK_CHECK_VERSION(2,22,0)
assistantCommit,
#endif
-- * Attributes
assistantCurrentPage,
-- * Child Attributes
assistantChildPageType,
assistantChildTitle,
assistantChildHeaderImage,
assistantChildSidebarImage,
assistantChildComplete,
-- * Signals
assistantCancel,
assistantPrepare,
assistantApply,
assistantClose,
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
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#}
{# context lib="gtk" prefix="gtk" #}
#if GTK_CHECK_VERSION(2,10,0)
--------------------
-- Enum
{#enum GtkAssistantPageType as AssistantPageType {underscoreToCase} deriving (Bounded,Eq,Show)#}
--------------------
-- Constructors
-- | Creates a new 'Assistant'.
--
-- * Available since Gtk+ version 2.10
--
assistantNew :: IO Assistant
assistantNew =
makeNewObject mkAssistant $
liftM (castPtr :: Ptr Widget -> Ptr Assistant) $
{# call gtk_assistant_new #}
--------------------
-- Methods
-- | Returns the page number of the current page
--
-- * Available since Gtk+ version 2.10
--
assistantGetCurrentPage :: AssistantClass self => self
-> IO Int -- ^ returns The index (starting from 0) of the current page in the
-- @assistant@, if the @assistant@ has no pages, -1 will be returned
assistantGetCurrentPage self =
liftM fromIntegral $
{# call gtk_assistant_get_current_page #}
(toAssistant self)
-- | Switches the page to @pageNum@. Note that this will only be necessary in custom buttons, as the
-- assistant flow can be set with 'assistantSetForwardPageFunc'.
--
-- * Available since Gtk+ version 2.10
--
assistantSetCurrentPage :: AssistantClass self => self
-> Int -- ^ @pageNum@ - index of the page to switch to, starting from 0. If
-- negative, the last page will be used. If greater than the number of
-- pages in the @assistant@, nothing will be done.
-> IO ()
assistantSetCurrentPage self pageNum =
{# call gtk_assistant_set_current_page #}
(toAssistant self)
(fromIntegral pageNum)
-- | Returns the number of pages in the @assistant@
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetNPages :: AssistantClass self => self
-> IO Int -- ^ returns The number of pages in the @assistant@.
assistantGetNPages self =
liftM fromIntegral $
{# call gtk_assistant_get_n_pages #}
(toAssistant self)
-- | Returns the child widget contained in page number @pageNum@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetNthPage :: AssistantClass self => self
-> Int -- ^ @pageNum@ - The index of a page in the @assistant@, or -1
-- to get the last page;
-> IO (Maybe Widget) -- ^ returns The child widget, or 'Nothing' if @pageNum@ is out of bounds.
assistantGetNthPage self pageNum =
maybeNull (makeNewObject mkWidget) $
{# call gtk_assistant_get_nth_page #}
(toAssistant self)
(fromIntegral pageNum)
-- | Prepends a page to the @assistant@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantPrependPage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a 'Widget'
-> IO Int -- ^ returns the index (starting at 0) of the inserted page
assistantPrependPage self page =
liftM fromIntegral $
{# call gtk_assistant_prepend_page #}
(toAssistant self)
(toWidget page)
-- | Appends a page to the @assistant@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantAppendPage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a 'Widget'
-> IO Int -- ^ returns the index (starting at 0) of the inserted page
assistantAppendPage self page =
liftM fromIntegral $
{# call gtk_assistant_append_page #}
(toAssistant self)
(toWidget page)
-- | Inserts a page in the @assistant@ at a given position.
--
--
-- * Available since Gtk+ version 2.10
--
assistantInsertPage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a 'Widget'
-> Int -- ^ @position@ - the index (starting at 0) at which to insert the
-- page, or -1 to append the page to the @assistant@
-> IO Int -- ^ returns the index (starting from 0) of the inserted page
assistantInsertPage self page position =
liftM fromIntegral $
{# call gtk_assistant_insert_page #}
(toAssistant self)
(toWidget page)
(fromIntegral position)
-- | Sets the page forwarding function to be @pageFunc@, this function will be
-- used to determine what will be the next page when the user presses the
-- forward button. Setting @pageFunc@ to 'Nothing' will make the assistant to use the
-- default forward function, which just goes to the next visible page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetForwardPageFunc :: AssistantClass self => self
-> Maybe (Int -> IO Int) -- ^ @pageFunc@ - the 'AssistantPage', or 'Nothing' to use the default one.
-> IO ()
assistantSetForwardPageFunc self Nothing = do
{# call gtk_assistant_set_forward_page_func #}
(toAssistant self)
nullFunPtr
(castFunPtrToPtr nullFunPtr)
destroyFunPtr
assistantSetForwardPageFunc self (Just pageFunc) = do
pfPtr <- mkAssistantPageFunc $ \ c _ -> do
result <- pageFunc (fromIntegral c)
return $ fromIntegral result
{# call gtk_assistant_set_forward_page_func #}
(toAssistant self)
pfPtr
(castFunPtrToPtr pfPtr)
destroyFunPtr
{#pointer AssistantPageFunc#}
foreign import ccall "wrapper" mkAssistantPageFunc ::
({#type gint#} -> Ptr () -> IO {#type gint#})
-> IO AssistantPageFunc
-- | Sets the page type for @page@. The page type determines the page behavior
-- in the @assistant@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetPageType :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> AssistantPageType -- ^ @type@ - the new type for @page@
-> IO ()
assistantSetPageType self page type_ =
{# call gtk_assistant_set_page_type #}
(toAssistant self)
(toWidget page)
((fromIntegral . fromEnum) type_)
-- | Gets the page type of @page@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetPageType :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> IO AssistantPageType -- ^ returns the page type of @page@.
assistantGetPageType self page =
liftM (toEnum . fromIntegral) $
{# call gtk_assistant_get_page_type #}
(toAssistant self)
(toWidget page)
-- | Sets a title for @page@. The title is displayed in the header area of the
-- assistant when @page@ is the current page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetPageTitle :: (AssistantClass self, WidgetClass page, GlibString string) => self
-> page -- ^ @page@ - a page of @assistant@
-> string -- ^ @title@ - the new title for @page@
-> IO ()
assistantSetPageTitle self page title =
withUTFString title $ \titlePtr ->
{# call gtk_assistant_set_page_title #}
(toAssistant self)
(toWidget page)
titlePtr
-- | Gets the title for @page@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetPageTitle :: (AssistantClass self, WidgetClass page, GlibString string) => self
-> page -- ^ @page@ - a page of @assistant@
-> IO string -- ^ returns the title for @page@.
assistantGetPageTitle self page =
{# call gtk_assistant_get_page_title #}
(toAssistant self)
(toWidget page)
>>= peekUTFString
-- | Sets a header image for @page@. This image is displayed in the header
-- area of the assistant when @page@ is the current page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetPageHeaderImage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> Pixbuf -- ^ @pixbuf@ - the new header image @page@
-> IO ()
assistantSetPageHeaderImage self page pixbuf =
{# call gtk_assistant_set_page_header_image #}
(toAssistant self)
(toWidget page)
pixbuf
-- | Gets the header image for @page@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetPageHeaderImage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> IO (Maybe Pixbuf) -- ^ returns the header image for @page@, or 'Nothing' if there's no header image for the page.
assistantGetPageHeaderImage self page =
maybeNull (makeNewGObject mkPixbuf) $
{# call gtk_assistant_get_page_header_image #}
(toAssistant self)
(toWidget page)
-- | Sets a header image for @page@. This image is displayed in the side area
-- of the assistant when @page@ is the current page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetPageSideImage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> Pixbuf -- ^ @pixbuf@ - the new header image @page@
-> IO ()
assistantSetPageSideImage self page pixbuf =
{# call gtk_assistant_set_page_side_image #}
(toAssistant self)
(toWidget page)
pixbuf
-- | Gets the header image for @page@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetPageSideImage :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> IO (Maybe Pixbuf) -- ^ returns the side image for @page@, or 'Nothing' if there's no side image for the page.
assistantGetPageSideImage self page =
maybeNull (makeNewGObject mkPixbuf) $
{# call gtk_assistant_get_page_side_image #}
(toAssistant self)
(toWidget page)
-- | Sets whether @page@ contents are complete. This will make @assistant@
-- update the buttons state to be able to continue the task.
--
--
-- * Available since Gtk+ version 2.10
--
assistantSetPageComplete :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> Bool -- ^ @complete@ - the completeness status of the page
-> IO ()
assistantSetPageComplete self page complete =
{# call gtk_assistant_set_page_complete #}
(toAssistant self)
(toWidget page)
(fromBool complete)
-- | Gets whether @page@ is complete.
--
--
-- * Available since Gtk+ version 2.10
--
assistantGetPageComplete :: (AssistantClass self, WidgetClass page) => self
-> page -- ^ @page@ - a page of @assistant@
-> IO Bool -- ^ returns @True@ if @page@ is complete.
assistantGetPageComplete self page =
liftM toBool $
{# call gtk_assistant_get_page_complete #}
(toAssistant self)
(toWidget page)
#if GTK_CHECK_VERSION(2,22,0)
-- | Erases the visited page history so the back button is not shown on the current page, and removes the
-- cancel button from subsequent pages.
--
-- Use this when the information provided up to the current page is hereafter deemed permanent and
-- cannot be modified or undone. For example, showing a progress page to track a long-running,
-- unreversible operation after the user has clicked apply on a confirmation page.
--
-- * Available since Gtk+ version 2.22
--
assistantCommit :: AssistantClass self => self -> IO ()
assistantCommit self =
{#call gtk_assistant_commit#} (toAssistant self)
#endif
-- | Adds a widget to the action area of a 'Assistant'.
--
--
-- * Available since Gtk+ version 2.10
--
assistantAddActionWidget :: (AssistantClass self, WidgetClass child) => self
-> child -- ^ @child@ - a 'Widget'
-> IO ()
assistantAddActionWidget self child =
{# call gtk_assistant_add_action_widget #}
(toAssistant self)
(toWidget child)
-- | Removes a widget from the action area of a 'Assistant'.
--
--
-- * Available since Gtk+ version 2.10
--
assistantRemoveActionWidget :: (AssistantClass self, WidgetClass child) => self
-> child -- ^ @child@ - a 'Widget'
-> IO ()
assistantRemoveActionWidget self child =
{# call gtk_assistant_remove_action_widget #}
(toAssistant self)
(toWidget child)
-- | Forces @assistant@ to recompute the buttons state.
--
-- Gtk+ automatically takes care of this in most situations, e.g. when the
-- user goes to a different page, or when the visibility or completeness of a
-- page changes.
--
-- One situation where it can be necessary to call this function is when
-- changing a value on the current page affects the future page flow of the
-- assistant.
--
--
-- * Available since Gtk+ version 2.10
--
assistantUpdateButtonsState :: AssistantClass self => self -> IO ()
assistantUpdateButtonsState self =
{# call gtk_assistant_update_buttons_state #}
(toAssistant self)
--------------------
-- Attributes
-- | Switches the page to @pageNum@. Note that this will only be necessary in
-- custom buttons, as the @assistant@ flow can be set with
-- 'assistantSetForwardPageFunc'.
--
-- Returns the page number of the current page
--
--
-- * Available since Gtk+ version 2.10
--
assistantCurrentPage :: AssistantClass self => Attr self Int
assistantCurrentPage = newAttr
assistantGetCurrentPage
assistantSetCurrentPage
--------------------
-- Child Attributes
-- | The type of the assistant page.
--
-- Default value: 'AssistantPageContent'
--
--
-- * Available since Gtk+ version 2.10
--
assistantChildPageType :: AssistantClass self => Attr self AssistantPageType
assistantChildPageType =
newAttrFromEnumProperty "page-type" {#call pure unsafe assistant_page_type_get_type#}
-- | The title that is displayed in the page header.
--
-- If title and header-image are both, no header is displayed.
--
--
-- * Available since Gtk+ version 2.10
--
assistantChildTitle :: (AssistantClass self, GlibString string) => Attr self string
assistantChildTitle = newAttrFromStringProperty "title"
-- | The image that is displayed next to the page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantChildHeaderImage :: AssistantClass self => Attr self Pixbuf
assistantChildHeaderImage = newAttrFromObjectProperty "header-image"
{# call pure unsafe gdk_pixbuf_get_type #}
-- | Sidebar image for the assistant page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantChildSidebarImage :: AssistantClass self => Attr self Pixbuf
assistantChildSidebarImage = newAttrFromObjectProperty "sidebar-image"
{# call pure unsafe gdk_pixbuf_get_type #}
-- | Setting the \"complete\" child property to @True@ marks a page as
-- complete (i.e.: all the required fields are filled out). Gtk+ uses this
-- information to control the sensitivity of the navigation buttons.
--
-- Default value: @False@
--
--
-- * Available since Gtk+ version 2.10
--
assistantChildComplete :: AssistantClass self => Attr self Bool
assistantChildComplete = newAttrFromBoolProperty "complete"
--------------------
-- Signals
-- | The ::assistantCancel signal is emitted when then the assistantCancel button is clicked.
--
--
-- * Available since Gtk+ version 2.10
--
assistantCancel :: AssistantClass self => Signal self (IO ())
assistantCancel = Signal (connect_NONE__NONE "cancel")
-- | The ::assistantPrepare signal is emitted when a new page is set as the assistant's
-- current page, before making the new page visible. A handler for this signal
-- can do any preparation which are necessary before showing @page@.
--
--
-- * Available since Gtk+ version 2.10
--
assistantPrepare :: AssistantClass self => Signal self (Widget -> IO ())
assistantPrepare = Signal (connect_OBJECT__NONE "prepare")
-- | The ::assistantApply signal is emitted when the assistantApply button is clicked. The
-- default behavior of the 'Assistant' is to switch to the page after the
-- current page, unless the current page is the last one.
--
-- A handler for the ::assistantApply signal should carry out the actions for which
-- the wizard has collected data. If the action takes a long time to complete,
-- you might consider to put a page of type 'AssistantPageProgress' after the
-- confirmation page and handle this operation within the 'assistantPrepare' signal of the progress page.
--
--
-- * Available since Gtk+ version 2.10
--
assistantApply :: AssistantClass self => Signal self (IO ())
assistantApply = Signal (connect_NONE__NONE "apply")
-- | The ::assistantClose signal is emitted either when the assistantClose button of a summary
-- page is clicked, or when the apply button in the last page in the flow (of
-- type 'AssistantPageConfirm') is clicked.
--
assistantClose :: AssistantClass self => Signal self (IO ())
assistantClose = Signal (connect_NONE__NONE "close")
#endif
|