Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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.
Dialog
boxes are created with a call to dialogNew
or
gtk_dialog_new_with_buttons()
. gtk_dialog_new_with_buttons()
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 through dialogGetContentArea
and
dialogGetActionArea
, as can be seen from the example below.
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. Use the GTK_WINDOW()
macro to cast the widget returned from
dialogNew
into a Window
. When using gtk_dialog_new_with_buttons()
you can also pass the GTK_DIALOG_MODAL
flag to make a dialog modal.
If you add buttons to Dialog
using gtk_dialog_new_with_buttons()
,
dialogAddButton
, gtk_dialog_add_buttons()
, or
dialogAddActionWidget
, clicking the button will emit a signal
called Dialog::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 Dialog::response signal will
be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT
.
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 the simple dialog in the following example, in reality you’d probably
use MessageDialog
to save yourself some effort. But you’d need to
create the dialog contents manually if you had more than a simple message
in the dialog.
An example for simple GtkDialog usage:
C code
// Function to open a dialog box with a message void quick_message (GtkWindow *parent, gchar *message) { GtkWidget *dialog, *label, *content_area; GtkDialogFlags flags; // Create the widgets flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons ("Message", parent, flags, _("_OK"), GTK_RESPONSE_NONE, NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); label = gtk_label_new (message); // Ensure that the dialog box is destroyed when the user responds g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); // Add the label, and show everything we’ve added gtk_container_add (GTK_CONTAINER (content_area), label); gtk_widget_show_all (dialog); }
GtkDialog as GtkBuildable
The GtkDialog implementation of the Buildable
interface exposes the
vbox
and actionArea
as internal children with the names “vbox” and
“action_area”.
GtkDialog supports a custom <action-widgets>
element, which can contain
multiple <action-widget>
elements. The “response” attribute specifies a
numeric response, and the content of the element is the id of widget
(which should be a child of the dialogs actionArea
). To mark a response
as default, set the “default“ attribute of the <action-widget>
element
to true.
GtkDialog supports adding action widgets by specifying “action“ as
the “type“ attribute of a <child>
element. The widget will be added
either to the action area or the headerbar of the dialog, depending
on the “use-header-bar“ property. The response id has to be associated
with the action widget using the <action-widgets>
element.
An example of a Dialog
UI definition fragment:
xml code
<object class="GtkDialog" id="dialog1"> <child type="action"> <object class="GtkButton" id="button_cancel"/> </child> <child type="action"> <object class="GtkButton" id="button_ok"> <property name="can-default">True</property> </object> </child> <action-widgets> <action-widget response="cancel">button_cancel</action-widget> <action-widget response="ok" default="true">button_ok</action-widget> </action-widgets> </object>
Synopsis
- newtype Dialog = Dialog (ManagedPtr Dialog)
- class (GObject o, IsDescendantOf Dialog o) => IsDialog o
- toDialog :: (MonadIO m, IsDialog o) => o -> m Dialog
- dialogAddActionWidget :: (HasCallStack, MonadIO m, IsDialog a, IsWidget b) => a -> b -> Int32 -> m ()
- dialogAddButton :: (HasCallStack, MonadIO m, IsDialog a) => a -> Text -> Int32 -> m Widget
- dialogGetActionArea :: (HasCallStack, MonadIO m, IsDialog a) => a -> m Box
- dialogGetContentArea :: (HasCallStack, MonadIO m, IsDialog a) => a -> m Box
- dialogGetHeaderBar :: (HasCallStack, MonadIO m, IsDialog a) => a -> m HeaderBar
- dialogGetResponseForWidget :: (HasCallStack, MonadIO m, IsDialog a, IsWidget b) => a -> b -> m Int32
- dialogGetWidgetForResponse :: (HasCallStack, MonadIO m, IsDialog a) => a -> Int32 -> m (Maybe Widget)
- dialogNew :: (HasCallStack, MonadIO m) => m Dialog
- dialogResponse :: (HasCallStack, MonadIO m, IsDialog a) => a -> Int32 -> m ()
- dialogRun :: (HasCallStack, MonadIO m, IsDialog a) => a -> m Int32
- dialogSetAlternativeButtonOrderFromArray :: (HasCallStack, MonadIO m, IsDialog a) => a -> [Int32] -> m ()
- dialogSetDefaultResponse :: (HasCallStack, MonadIO m, IsDialog a) => a -> Int32 -> m ()
- dialogSetResponseSensitive :: (HasCallStack, MonadIO m, IsDialog a) => a -> Int32 -> Bool -> m ()
- constructDialogUseHeaderBar :: (IsDialog o, MonadIO m) => Int32 -> m (GValueConstruct o)
- getDialogUseHeaderBar :: (MonadIO m, IsDialog o) => o -> m Int32
- type DialogCloseCallback = IO ()
- afterDialogClose :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogCloseCallback) -> m SignalHandlerId
- onDialogClose :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogCloseCallback) -> m SignalHandlerId
- type DialogResponseCallback = Int32 -> IO ()
- afterDialogResponse :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogResponseCallback) -> m SignalHandlerId
- onDialogResponse :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogResponseCallback) -> m SignalHandlerId
Exported types
Memory-managed wrapper type.
Instances
Eq Dialog Source # | |
GObject Dialog Source # | |
Defined in GI.Gtk.Objects.Dialog | |
ManagedPtrNewtype Dialog Source # | |
Defined in GI.Gtk.Objects.Dialog toManagedPtr :: Dialog -> ManagedPtr Dialog | |
TypedObject Dialog Source # | |
Defined in GI.Gtk.Objects.Dialog | |
HasParentTypes Dialog Source # | |
Defined in GI.Gtk.Objects.Dialog | |
IsGValue (Maybe Dialog) Source # | Convert |
Defined in GI.Gtk.Objects.Dialog gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe Dialog -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe Dialog) | |
type ParentTypes Dialog Source # | |
class (GObject o, IsDescendantOf Dialog o) => IsDialog o Source #
Instances
(GObject o, IsDescendantOf Dialog o) => IsDialog o Source # | |
Defined in GI.Gtk.Objects.Dialog |
Methods
Click to display all available methods, including inherited ones
Methods
activate, activateDefault, activateFocus, activateKey, add, addAccelGroup, addAccelerator, addActionWidget, addButton, addChild, addDeviceEvents, addEvents, addMnemonic, addMnemonicLabel, addTickCallback, beginMoveDrag, beginResizeDrag, bindProperty, bindPropertyFull, canActivateAccel, checkResize, childFocus, childGetProperty, childNotify, childNotifyByPspec, childSetProperty, childType, classPath, close, computeExpand, constructChild, createPangoContext, createPangoLayout, customFinished, customTagEnd, customTagStart, deiconify, destroy, destroyed, deviceIsShadowed, dragBegin, dragBeginWithCoordinates, dragCheckThreshold, dragDestAddImageTargets, dragDestAddTextTargets, dragDestAddUriTargets, dragDestFindTarget, dragDestGetTargetList, dragDestGetTrackMotion, dragDestSet, dragDestSetProxy, dragDestSetTargetList, dragDestSetTrackMotion, dragDestUnset, dragGetData, dragHighlight, dragSourceAddImageTargets, dragSourceAddTextTargets, dragSourceAddUriTargets, dragSourceGetTargetList, dragSourceSet, dragSourceSetIconGicon, dragSourceSetIconName, dragSourceSetIconPixbuf, dragSourceSetIconStock, dragSourceSetTargetList, dragSourceUnset, dragUnhighlight, draw, ensureStyle, errorBell, event, forall, forceFloating, foreach, freezeChildNotify, freezeNotify, fullscreen, fullscreenOnMonitor, getv, grabAdd, grabDefault, grabFocus, grabRemove, hasDefault, hasFocus, hasGrab, hasGroup, hasRcStyle, hasScreen, hasToplevelFocus, hasVisibleFocus, hide, hideOnDelete, iconify, inDestruction, initTemplate, inputShapeCombineRegion, insertActionGroup, intersect, isActive, isAncestor, isComposited, isDrawable, isFloating, isFocus, isMaximized, isSensitive, isToplevel, isVisible, keynavFailed, listAccelClosures, listActionPrefixes, listMnemonicLabels, map, maximize, mnemonicActivate, modifyBase, modifyBg, modifyCursor, modifyFg, modifyFont, modifyStyle, modifyText, move, notify, notifyByPspec, overrideBackgroundColor, overrideColor, overrideCursor, overrideFont, overrideSymbolicColor, parseGeometry, parserFinished, path, present, presentWithTime, propagateDraw, propagateKeyEvent, queueAllocate, queueComputeExpand, queueDraw, queueDrawArea, queueDrawRegion, queueResize, queueResizeNoRedraw, realize, ref, refSink, regionIntersect, registerWindow, remove, removeAccelGroup, removeAccelerator, removeMnemonic, removeMnemonicLabel, removeTickCallback, renderIcon, renderIconPixbuf, reparent, resetRcStyles, resetStyle, reshowWithInitialSize, resize, resizeChildren, resizeGripIsVisible, resizeToGeometry, response, run, runDispose, sendExpose, sendFocusChange, shapeCombineRegion, show, showAll, showNow, sizeAllocate, sizeAllocateWithBaseline, sizeRequest, stealData, stealQdata, stick, styleAttach, styleGetProperty, thawChildNotify, thawNotify, translateCoordinates, triggerTooltipQuery, unfullscreen, unmap, unmaximize, unparent, unrealize, unref, unregisterWindow, unsetFocusChain, unsetStateFlags, unstick, watchClosure.
Getters
getAcceptFocus, getAccessible, getActionArea, getActionGroup, getAllocatedBaseline, getAllocatedHeight, getAllocatedSize, getAllocatedWidth, getAllocation, getAncestor, getAppPaintable, getApplication, getAttachedTo, getBorderWidth, getCanDefault, getCanFocus, getChild, getChildRequisition, getChildVisible, getChildren, getClip, getClipboard, getCompositeName, getContentArea, getData, getDecorated, getDefaultSize, getDefaultWidget, getDeletable, getDestroyWithParent, getDeviceEnabled, getDeviceEvents, getDirection, getDisplay, getDoubleBuffered, getEvents, getFocus, getFocusChain, getFocusChild, getFocusHadjustment, getFocusOnClick, getFocusOnMap, getFocusVadjustment, getFocusVisible, getFontMap, getFontOptions, getFrameClock, getGravity, getGroup, getHalign, getHasResizeGrip, getHasTooltip, getHasWindow, getHeaderBar, getHexpand, getHexpandSet, getHideTitlebarWhenMaximized, getIcon, getIconList, getIconName, getInternalChild, getMapped, getMarginBottom, getMarginEnd, getMarginLeft, getMarginRight, getMarginStart, getMarginTop, getMnemonicModifier, getMnemonicsVisible, getModal, getModifierMask, getModifierStyle, getName, getNoShowAll, getOpacity, getPangoContext, getParent, getParentWindow, getPath, getPathForChild, getPointer, getPosition, getPreferredHeight, getPreferredHeightAndBaselineForWidth, getPreferredHeightForWidth, getPreferredSize, getPreferredWidth, getPreferredWidthForHeight, getProperty, getQdata, getRealized, getReceivesDefault, getRequestMode, getRequisition, getResizable, getResizeGripArea, getResizeMode, getResponseForWidget, getRole, getRootWindow, getScaleFactor, getScreen, getSensitive, getSettings, getSize, getSizeRequest, getSkipPagerHint, getSkipTaskbarHint, getState, getStateFlags, getStyle, getStyleContext, getSupportMultidevice, getTemplateChild, getTitle, getTitlebar, getTooltipMarkup, getTooltipText, getTooltipWindow, getToplevel, getTransientFor, getTypeHint, getUrgencyHint, getValign, getValignWithBaseline, getVexpand, getVexpandSet, getVisible, getVisual, getWidgetForResponse, getWindow, getWindowType.
Setters
setAccelPath, setAcceptFocus, setAllocation, setAlternativeButtonOrderFromArray, setAppPaintable, setApplication, setAttachedTo, setBorderWidth, setBuildableProperty, setCanDefault, setCanFocus, setChildVisible, setClip, setCompositeName, setData, setDataFull, setDecorated, setDefault, setDefaultGeometry, setDefaultResponse, setDefaultSize, setDeletable, setDestroyWithParent, setDeviceEnabled, setDeviceEvents, setDirection, setDoubleBuffered, setEvents, setFocus, setFocusChain, setFocusChild, setFocusHadjustment, setFocusOnClick, setFocusOnMap, setFocusVadjustment, setFocusVisible, setFontMap, setFontOptions, setGeometryHints, setGravity, setHalign, setHasResizeGrip, setHasTooltip, setHasUserRefCount, setHasWindow, setHexpand, setHexpandSet, setHideTitlebarWhenMaximized, setIcon, setIconFromFile, setIconList, setIconName, setKeepAbove, setKeepBelow, setMapped, setMarginBottom, setMarginEnd, setMarginLeft, setMarginRight, setMarginStart, setMarginTop, setMnemonicModifier, setMnemonicsVisible, setModal, setName, setNoShowAll, setOpacity, setParent, setParentWindow, setPosition, setProperty, setRealized, setReallocateRedraws, setReceivesDefault, setRedrawOnAllocate, setResizable, setResizeMode, setResponseSensitive, setRole, setScreen, setSensitive, setSizeRequest, setSkipPagerHint, setSkipTaskbarHint, setStartupId, setState, setStateFlags, setStyle, setSupportMultidevice, setTitle, setTitlebar, setTooltipMarkup, setTooltipText, setTooltipWindow, setTransientFor, setTypeHint, setUrgencyHint, setValign, setVexpand, setVexpandSet, setVisible, setVisual, setWindow, setWmclass.
addActionWidget
dialogAddActionWidget Source #
:: (HasCallStack, MonadIO m, IsDialog a, IsWidget b) | |
=> a |
|
-> b |
|
-> Int32 |
|
-> m () |
Adds an activatable widget to the action area of a Dialog
,
connecting a signal handler that will emit the Dialog::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 actionArea
field
of the Dialog
struct.
addButton
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> m Widget | Returns: the |
Adds a button with the given text and sets things up so that
clicking the button will emit the Dialog::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.
getActionArea
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> m Box | Returns: the action area |
Deprecated: (Since version 3.12)Direct access to the action area is discouraged; use dialogAddButton
, etc.
Returns the action area of dialog
.
Since: 2.14
getContentArea
Returns the content area of dialog
.
Since: 2.14
getHeaderBar
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> m HeaderBar | Returns: the header bar |
Returns the header bar of dialog
. Note that the
headerbar is only used by the dialog if the
Dialog:useHeaderBar property is True
.
Since: 3.12
getResponseForWidget
dialogGetResponseForWidget Source #
:: (HasCallStack, MonadIO m, IsDialog a, IsWidget b) | |
=> a |
|
-> b |
|
-> m Int32 | Returns: the response id of |
Gets the response id of a widget in the action area of a dialog.
Since: 2.8
getWidgetForResponse
dialogGetWidgetForResponse Source #
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> Int32 |
|
-> m (Maybe Widget) | Returns: the |
Gets the widget button that uses the given response ID in the action area of a dialog.
Since: 2.20
new
:: (HasCallStack, MonadIO m) | |
=> m Dialog | Returns: the new dialog as a |
Creates a new dialog box.
Widgets should not be packed into this Window
directly, but into the vbox
and actionArea
, as described above.
response
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> Int32 |
|
-> m () |
Emits the Dialog::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.
run
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> m Int32 | Returns: response ID |
Blocks in a recursive main loop until the dialog
either emits the
Dialog::response signal, or is destroyed. If the dialog is
destroyed during the call to dialogRun
, dialogRun
returns
GTK_RESPONSE_NONE
. 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 Widget::deleteEvent
is disabled; if the dialog receives delete_event, it will not be
destroyed as windows usually are, and dialogRun
will return
GTK_RESPONSE_DELETE_EVENT
. 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.
After dialogRun
returns, you are responsible for hiding or
destroying the dialog if you wish to do so.
Typical usage of this function might be:
C code
GtkWidget *dialog = gtk_dialog_new (); // Set up dialog... int result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: // do_application_specific_something (); break; default: // do_nothing_since_dialog_was_cancelled (); break; } gtk_widget_destroy (dialog);
Note that even though the recursive main loop gives the effect of a
modal dialog (it prevents the user from interacting with other
windows in the same window group while the dialog is run), callbacks
such as timeouts, IO channel watches, DND drops, etc, will
be triggered during a dialogRun
call.
setAlternativeButtonOrderFromArray
dialogSetAlternativeButtonOrderFromArray Source #
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> [Int32] |
|
-> m () |
Deprecated: (Since version 3.10)Deprecated
Sets an alternative button order. If the
Settings:gtkAlternativeButtonOrder setting is set to True
,
the dialog buttons are reordered according to the order of the
response ids in newOrder
.
See gtk_dialog_set_alternative_button_order()
for more information.
This function is for use by language bindings.
Since: 2.6
setDefaultResponse
dialogSetDefaultResponse Source #
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> Int32 |
|
-> m () |
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.
setResponseSensitive
dialogSetResponseSensitive Source #
:: (HasCallStack, MonadIO m, IsDialog a) | |
=> a |
|
-> Int32 |
|
-> Bool |
|
-> m () |
Calls gtk_widget_set_sensitive (widget, @setting)
for each widget in the dialog’s action area with the given responseId
.
A convenient way to sensitize/desensitize dialog buttons.
Properties
useHeaderBar
True
if the dialog uses a HeaderBar
for action buttons
instead of the action-area.
For technical reasons, this property is declared as an integer
property, but you should only set it to True
or False
.
Since: 3.12
constructDialogUseHeaderBar :: (IsDialog o, MonadIO m) => Int32 -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “use-header-bar
” property. This is rarely needed directly, but it is used by new
.
getDialogUseHeaderBar :: (MonadIO m, IsDialog o) => o -> m Int32 Source #
Get the value of the “use-header-bar
” property.
When overloading is enabled, this is equivalent to
get
dialog #useHeaderBar
Signals
close
type DialogCloseCallback = IO () Source #
The close signal is a [keybinding signal][GtkBindingSignal] which gets emitted when the user uses a keybinding to close the dialog.
The default binding for this signal is the Escape key.
afterDialogClose :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogCloseCallback) -> m SignalHandlerId Source #
Connect a signal handler for the close signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dialog #close callback
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onDialogClose :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogCloseCallback) -> m SignalHandlerId Source #
Connect a signal handler for the close signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dialog #close callback
response
type DialogResponseCallback 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 GTK_RESPONSE_DELETE_EVENT
.
Otherwise, it depends on which action widget was clicked.
afterDialogResponse :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogResponseCallback) -> m SignalHandlerId Source #
Connect a signal handler for the response signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dialog #response callback
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onDialogResponse :: (IsDialog a, MonadIO m) => a -> ((?self :: a) => DialogResponseCallback) -> m SignalHandlerId Source #
Connect a signal handler for the response signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dialog #response callback