| Gtk2Hs | Contents | Index

Graphics.UI.Gtk.Windows.Dialog

Portability | portable (depends on GHC)
Stability | provisional
Maintainer | gtk2hs-users@lists.sourceforge.net

Contents

Detail
Class Hierarchy
Types
Constructors
Methods
Attributes
Signals

Description
Create popup windows
Synopsis

data Dialog
class WindowClass o => DialogClass o
castToDialog :: GObjectClass obj => obj -> Dialog
toDialog :: DialogClass o => o -> Dialog
dialogNew :: IO Dialog
dialogGetUpper :: DialogClass dc => dc -> IO VBox
dialogGetActionArea :: DialogClass dc => dc -> IO HBox
dialogRun :: DialogClass self => self -> IO ResponseId
dialogResponse :: DialogClass self => self -> ResponseId -> IO ()

data ResponseId

= ResponseNone
| ResponseReject
| ResponseAccept
| ResponseDeleteEvent
| ResponseOk
| ResponseCancel
| ResponseClose
| ResponseYes
| ResponseNo
| ResponseApply
| ResponseHelp
| ResponseUser Int

dialogAddButton :: DialogClass self => self -> String -> ResponseId -> IO Button
dialogAddActionWidget :: (DialogClass self, WidgetClass child) => self -> child -> ResponseId -> IO ()
dialogGetHasSeparator :: DialogClass self => self -> IO Bool
dialogSetDefaultResponse :: DialogClass self => self -> ResponseId -> IO ()
dialogSetHasSeparator :: DialogClass self => self -> Bool -> IO ()
dialogSetResponseSensitive :: DialogClass self => self -> ResponseId -> Bool -> IO ()
dialogHasSeparator :: DialogClass self => Attr self Bool
onResponse :: DialogClass self => self -> (ResponseId -> IO ()) -> IO (ConnectId self)
afterResponse :: DialogClass self => self -> (ResponseId -> IO ()) -> IO (ConnectId self)

Detail

Dialog boxes are a convenient way to prompt the user for a small amount of input, e.g. to display a message, ask a question, or anything else that does not require extensive effort on the user's part.

Gtk+ treats a dialog as a window split vertically. The top section is a `VBox`, and is where widgets such as a `Label` or a `Entry` should be packed. The bottom area is known as the action_area. This is generally used for packing buttons into the dialog which may perform functions such as cancel, ok, or apply. The two areas are separated by a `HSeparator`.

`Dialog` boxes are created with a call to `dialogNew` or dialogNewWithButtons. dialogNewWithButtons is recommended; it allows you to set the dialog title, some convenient flags, and add simple buttons.

If 'dialog' is a newly created dialog, the two primary areas of the window can be accessed using `dialogGetUpper` and `dialogGetActionArea`.

A 'modal' dialog (that is, one which freezes the rest of the application from user input), can be created by calling windowSetModal on the dialog. When using dialogNewWithButtons you can also pass the DialogModal flag to make a dialog modal.

If you add buttons to `Dialog` using dialogNewWithButtons, `dialogAddButton`, dialogAddButtons, or `dialogAddActionWidget`, clicking the button will emit a signal called "response" with a response ID that you specified. Gtk+ will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in the ResponseType enumeration (these all have values less than zero). If a dialog receives a delete event, the "response" signal will be emitted with a response ID of `ResponseNone`.

If you want to block waiting for a dialog to return before returning control flow to your code, you can call `dialogRun`. This function enters a recursive main loop and waits for the user to respond to the dialog, returning the response ID corresponding to the button the user clicked.

For a simple message box, you probably want to use Graphics.UI.Gtk.Windows.MessageDialog.MessageDialog which provides convenience functions for creating standard dialogs containing simple messages to inform or ask the user.

Class Hierarchy

     |  GObject
     |   +----Object
     |         +----Widget
     |               +----Container
     |                     +----Bin
     |                           +----Window
     |                                 +----Dialog
     |                                       +----AboutDialog
     |                                       +----ColorSelectionDialog
     |                                       +----FileChooserDialog
     |                                       +----FileSelection
     |                                       +----FontSelectionDialog
     |                                       +----InputDialog
     |                                       +----MessageDialog

Types
data Dialog

Instances

GObjectClass Dialog
DialogClass Dialog
WindowClass Dialog
BinClass Dialog
ContainerClass Dialog
WidgetClass Dialog
ObjectClass Dialog

class WindowClass o => DialogClass o

Instances

DialogClass MessageDialog
DialogClass InputDialog
DialogClass FontSelectionDialog
DialogClass FileChooserDialog
DialogClass FileSelection
DialogClass ColorSelectionDialog
DialogClass AboutDialog
DialogClass Dialog

castToDialog :: GObjectClass obj => obj -> Dialog
toDialog :: DialogClass o => o -> Dialog
Constructors
dialogNew :: IO Dialog
Creates a new dialog box. Widgets should not be packed into this `Window` directly, but into the "upper" and "action area", which are obtained using `dialogGetUpper` and `dialogGetActionArea`.
Methods
dialogGetUpper :: DialogClass dc => dc -> IO VBox

Get the upper part of a dialog.

- The upper part of a dialog window consists of a `VBox`. Add the required widgets into this box.

dialogGetActionArea :: DialogClass dc => dc -> IO HBox

Extract the action area of a dialog box.

- This is useful to add some special widgets that cannot be added with dialogAddActionWidget.

dialogRun :: DialogClass self => self -> IO ResponseId

Blocks in a recursive main loop until the dialog either emits the response signal, or is destroyed. If the dialog is destroyed during the call to `dialogRun`, it returns `ResponseNone`. Otherwise, it returns the response ID from the "response" signal emission. Before entering the recursive main loop, `dialogRun` calls widgetShow on the dialog for you. Note that you still need to show any children of the dialog yourself.

During `dialogRun`, the default behavior of "delete_event" is disabled; if the dialog receives "delete_event", it will not be destroyed as windows usually are, and `dialogRun` will return `ResponseDeleteEvent`. Also, during `dialogRun` the dialog will be modal. You can force `dialogRun` to return at any time by calling `dialogResponse` to emit the "response" signal. Destroying the dialog during `dialogRun` is a very bad idea, because your post-run code won't know whether the dialog was destroyed or not. Hence, you should not call Graphics.UI.Gtk.Abstract.widgetDestroy before `dialogRun` has returned.

After `dialogRun` returns, you are responsible for hiding or destroying the dialog if you wish to do so.

Note that even though the recursive main loop gives the effect of a modal dialog (it prevents the user from interacting with other windows while the dialog is run), callbacks such as timeouts, IO channel watches, DND drops, etc, will be triggered during a `dialogRun` call.

dialogResponse :: DialogClass self => self -> ResponseId -> IO ()
Emits the "response" signal with the given response ID. Used to indicate that the user has responded to the dialog in some way; typically either you or `dialogRun` will be monitoring the "response" signal and take appropriate action. This function can be used to add a custom widget to the action area that should close the dialog when activated or to close the dialog otherwise.
data ResponseId

Some constructors that can be used as response numbers for dialogs.
Constructors

ResponseNone | GTK returns this if a response widget has no `response_id`, or if the dialog gets programmatically hidden or destroyed.
ResponseReject | GTK won't return these unless you pass them in as the response for an action widget. They are for your convenience.
ResponseAccept | (as above)
ResponseDeleteEvent | If the dialog is deleted.

ResponseOk

"Ok" was pressed.

- This value is returned from the "Ok" stock dialog button.

ResponseCancel

"Cancel" was pressed.

- These value is returned from the "Cancel" stock dialog button.

ResponseClose

"Close" was pressed.

- This value is returned from the "Close" stock dialog button.

ResponseYes

"Yes" was pressed.

- This value is returned from the "Yes" stock dialog button.

ResponseNo

"No" was pressed.

- This value is returned from the "No" stock dialog button.

ResponseApply

"Apply" was pressed.

- This value is returned from the "Apply" stock dialog button.

ResponseHelp

"Help" was pressed.

- This value is returned from the "Help" stock dialog button.

ResponseUser Int

A user-defined response

- This value is returned from a user defined button

Instances

Eq ResponseId
Show ResponseId

dialogAddButton

:: DialogClass self |
=> self |
-> String | `buttonText` - text of button, or stock ID
-> ResponseId | `responseId` - response ID for the button
-> IO Button | returns the button widget that was added
Adds a button with the given text (or a stock button, if `buttonText` is a stock ID) and sets things up so that clicking the button will emit the "response" signal with the given `responseId`. The button is appended to the end of the dialog's action area. The button widget is returned, but usually you don't need it.

dialogAddActionWidget

:: (DialogClass self, WidgetClass child) |
=> self |
-> child | `child` - an activatable widget
-> ResponseId | `responseId` - response ID for `child`
-> IO () |
Adds an activatable widget to the action area of a `Dialog`, connecting a signal handler that will emit the "response" signal on the dialog when the widget is activated. The widget is appended to the end of the dialog's action area. If you want to add a non-activatable widget, simply pack it into the action area.

dialogGetHasSeparator :: DialogClass self => self -> IO Bool
Query if the dialog has a visible horizontal separator.
dialogSetDefaultResponse :: DialogClass self => self -> ResponseId -> IO ()

Sets the last widget in the dialog's action area with the given `ResponseId` as the default widget for the dialog. Pressing "Enter" normally activates the default widget.

- The default response is reset once it is triggered. Hence, if you hide the dialog (rather than closing it) and re-display it later, you need to call this function again.

dialogSetHasSeparator :: DialogClass self => self -> Bool -> IO ()
Sets whether the dialog has a separator above the buttons. `True` by default.
dialogSetResponseSensitive

:: DialogClass self |
=> self |
-> ResponseId | `responseId` - a response ID
-> Bool | `setting` - `True` for sensitive
-> IO () |
Calls `widgetSetSensitive widget setting` for each widget in the dialog's action area with the given `responseId`. A convenient way to sensitize/desensitize dialog buttons.

Attributes
dialogHasSeparator :: DialogClass self => Attr self Bool
The dialog has a separator bar above its buttons. Default value: `True`
Signals
onResponse :: DialogClass self => self -> (ResponseId -> IO ()) -> IO (ConnectId self)
afterResponse :: DialogClass self => self -> (ResponseId -> IO ()) -> IO (ConnectId self)
Emitted when an action widget is clicked, the dialog receives a delete event, or the application programmer calls `dialogResponse`. On a delete event, the response ID is `ResponseNone`. Otherwise, it depends on which action widget was clicked.
Produced by Haddock version 2.4.2