Maintainer | gtk2hs-users@lists.sourceforge.net |
---|---|
Stability | provisional |
Portability | portable (depends on GHC) |
Safe Haskell | None |
Language | Haskell98 |
Create popup windows
NOTE:
Now FFI haven't support variadic function gtk_dialog_set_alternative_button_order
- data Dialog
- class WindowClass o => DialogClass o
- castToDialog :: GObjectClass obj => obj -> Dialog
- gTypeDialog :: GType
- toDialog :: DialogClass o => o -> Dialog
- data ResponseId
- dialogNew :: IO Dialog
- dialogGetContentArea :: DialogClass self => self -> IO Widget
- dialogGetActionArea :: DialogClass self => self -> IO Widget
- dialogRun :: DialogClass self => self -> IO ResponseId
- dialogResponse :: DialogClass self => self -> ResponseId -> IO ()
- dialogAddButton :: (DialogClass self, GlibString string) => self -> string -> ResponseId -> IO Button
- dialogAddActionWidget :: (DialogClass self, WidgetClass child) => self -> child -> ResponseId -> IO ()
- dialogSetDefaultResponse :: DialogClass self => self -> ResponseId -> IO ()
- dialogSetResponseSensitive :: DialogClass self => self -> ResponseId -> Bool -> IO ()
- dialogGetResponseForWidget :: (DialogClass self, WidgetClass widget) => self -> widget -> IO ResponseId
- dialogAlternativeDialogButtonOrder :: Maybe Screen -> IO Bool
- dialogSetAlternativeButtonOrderFromArray :: DialogClass self => self -> [ResponseId] -> IO ()
- dialogGetWidgetForResponse :: DialogClass self => self -> ResponseId -> IO (Maybe Widget)
- dialogActionAreaBorder :: DialogClass self => ReadAttr self Int
- dialogButtonSpacing :: DialogClass self => ReadAttr self Int
- dialogContentAreaBorder :: DialogClass self => ReadAttr self Int
- dialogContentAreaSpacing :: DialogClass self => ReadAttr self Int
- response :: DialogClass self => Signal self (ResponseId -> IO ())
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
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
class WindowClass o => DialogClass o Source
castToDialog :: GObjectClass obj => obj -> Dialog Source
toDialog :: DialogClass o => o -> Dialog Source
Enums
data ResponseId Source
Some constructors that can be used as response numbers for dialogs.
ResponseNone | GTK returns this if a response widget has no |
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.
|
ResponseCancel | "Cancel" was pressed.
|
ResponseClose | "Close" was pressed.
|
ResponseYes | "Yes" was pressed.
|
ResponseNo | "No" was pressed.
|
ResponseApply | "Apply" was pressed.
|
ResponseHelp | "Help" was pressed.
|
ResponseUser Int | A user-defined response
|
Constructors
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
dialogGetContentArea :: DialogClass self => self -> IO Widget Source
Returns the content area of dialog.
dialogGetActionArea :: DialogClass self => self -> IO Widget Source
Returns the action area of dialog.
- This is useful to add some special widgets that cannot be added with dialogAddActionWidget.
dialogRun :: DialogClass self => self -> IO ResponseId Source
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 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 () Source
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.
:: (DialogClass self, GlibString string) | |
=> self | |
-> string |
|
-> ResponseId |
|
-> 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.
:: (DialogClass self, WidgetClass child) | |
=> self | |
-> child |
|
-> ResponseId |
|
-> 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.
dialogSetDefaultResponse :: DialogClass self => self -> ResponseId -> IO () Source
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.
dialogSetResponseSensitive Source
:: DialogClass self | |
=> self | |
-> ResponseId |
|
-> Bool |
|
-> IO () |
Calls
for each widget in the
dialog's action area with the given widgetSetSensitive
widget settingresponseId
. A convenient way to
sensitize/desensitize dialog buttons.
dialogGetResponseForWidget Source
:: (DialogClass self, WidgetClass widget) | |
=> self | |
-> widget |
|
-> IO ResponseId | return the response id of widget, or |
Gets the response id of a widget in the action area of a dialog.
dialogAlternativeDialogButtonOrder Source
:: Maybe Screen |
|
-> IO Bool | returns whether the alternative button order should be used |
Returns True
if dialogs are expected to use an alternative button order on the screen screen.
See dialogSetAlternativeButtonOrder
for more details about alternative button order.
If you need to use this function, you should probably connect to the alternativeButtonOrder
signal on the GtkSettings object associated to screen, in order to be notified if the button order setting changes.
- Available since Gtk+ version 2.6
dialogSetAlternativeButtonOrderFromArray Source
:: DialogClass self | |
=> self | |
-> [ResponseId] |
|
-> IO () |
Sets an alternative button order.
If the alternativeButtonOrder
setting is set to True
, the dialog
buttons are reordered according to the order of the response ids in
newOrder
.
See dialogSetAlternativeButtonOrder
for more information.
This function is for use by language bindings.
- Available since Gtk+ version 2.6
dialogGetWidgetForResponse Source
:: DialogClass self | |
=> self | |
-> ResponseId |
|
-> IO (Maybe Widget) | returns the widget button that uses the given |
Gets the widget button that uses the given response ID in the action area of a dialog.
Attributes
dialogActionAreaBorder :: DialogClass self => ReadAttr self Int Source
Width of border around the button area at the bottom of the dialog.
Allowed values: >= 0
Default value: 5
dialogButtonSpacing :: DialogClass self => ReadAttr self Int Source
Spacing between buttons.
Allowed values: >= 0
Default value: 6
dialogContentAreaBorder :: DialogClass self => ReadAttr self Int Source
Width of border around the main dialog area.
Allowed values: >= 0
Default value: 2
dialogContentAreaSpacing :: DialogClass self => ReadAttr self Int Source
The default spacing used between elements of the content area of the dialog,
as returned by dialogSetContentArea
, unless boxSetSpacing
was called on that widget directly.
Allowed values: >= 0
Default value: 0
- Available since Gtk+ version 2.16
Signals
response :: DialogClass self => Signal self (ResponseId -> IO ()) Source
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.