49 lines
1.4 KiB
Elixir
49 lines
1.4 KiB
Elixir
|
|
||
|
--------------------------------------------------------
|
||
|
--# 'Trapping' the delete event
|
||
|
--------------------------------------------------------
|
||
|
|
||
|
include GtkEngine.e
|
||
|
|
||
|
constant docs = `
|
||
|
_____<u><b>Trapping delete event</b></u>
|
||
|
Try closing the window with the titlebar <b>[X]</b>
|
||
|
`
|
||
|
constant win = create(GtkWindow,
|
||
|
"size=300x100,border=10,position=1,$delete-event=Bar,$destroy=Quit")
|
||
|
-- note: here we trap the delete-event first.
|
||
|
-- event signals occur *before* the action takes place,
|
||
|
-- while the other signals (clicked, destroy, etc) occur *after*
|
||
|
-- the action is finished.
|
||
|
|
||
|
constant panel = create(GtkBox,VERTICAL)
|
||
|
add(win,panel)
|
||
|
|
||
|
constant lbl = create(GtkLabel)
|
||
|
set(lbl,"markup",docs)
|
||
|
add(panel,lbl)
|
||
|
|
||
|
constant btnbox = create(GtkButtonBox)
|
||
|
set(btnbox,"layout",GTK_BUTTONBOX_START)
|
||
|
pack(panel,-btnbox)
|
||
|
|
||
|
constant btn = create(GtkButton,"gtk-quit","Quit")
|
||
|
add(btnbox,btn)
|
||
|
|
||
|
show_all(win)
|
||
|
main()
|
||
|
|
||
|
------------------------------------------------------------------------
|
||
|
global function Bar()
|
||
|
------------------------------------------------------------------------
|
||
|
-- here you might save work, clean up temp files, etc. before closing!
|
||
|
-- return value (1 or 0) determines whether further signals will be
|
||
|
-- processed.
|
||
|
if Question(win,"Close?","Are you sure?") = MB_YES then
|
||
|
return 0 -- next connection will be activated (quit)
|
||
|
else
|
||
|
return 1 -- following connections will be ignored
|
||
|
end if
|
||
|
end function
|
||
|
|