
------------------------------------------------------------------------
--# Demo of a NON-MODAL dialog
------------------------------------------------------------------------

include GtkEngine.e
include resources/mongoose.e

constant docs = `<b><u>Non-Modal Dialogs</u></b>

These should be used with caution, as they tend to clutter
up the screen, and there are usually better ways to
accomplish the same purpose.

Click the OK button below to pop up a non-modal dialog.
Repeat and then try changing various settings, and clicking
Apply.
`
integer ct = 0
constant say = call_back(routine_id("Say"))
constant apply_colors = call_back(routine_id("ApplyColors"))

constant win = create(GtkWindow,{
     {"position",GTK_WIN_POS_CENTER},
     {"border width",10},
     {"default size",300,-1},
     {"connect","enter-notify-event","ChangeFocus"},
     {"connect","destroy","Quit"}})

constant panel = add(win,create(GtkBox,VERTICAL))
     add(panel,create(GtkLabel,{{"markup",docs}}))

constant box = pack_end(panel,create(GtkButtonBox,HORIZONTAL)),
     btn1 = create(GtkButton,"gtk-quit","Quit"),
     btn2 = create(GtkButton,"gtk-ok","ShowNonModalDialog")
     add(box,{btn1,btn2})
     set(btn2,"name","btn2")

show_all(win)
main()

------------------------------------
function Say(atom ctl, object data)
------------------------------------
     display(unpack(data))
 return 1
end function

------------------------------------------
function ApplyColors(atom ctl, atom data)
------------------------------------------
     set(win,"background",get(data,"rgba"))
 return 1
end function

-------------------------------------
global function ChangeFocus(atom ctl)
-------------------------------------
? ctl = win
 set(ctl,"present")
 set(ctl,"grab focus")
 return 1
end function

-------------------------------------
global function ShowNonModalDialog()
-------------------------------------
object -- these will be added to the dialog's main panel (above the buttons)
     colorbutton = create(GtkColorButton,{
          {"rgba",rand(#FFFFFF)},
          {"tooltip text","Choose a color for the main window\nclick Apply"}}),
     colorlbl = create(GtkLabel,"Choose a color"),
     colorbox = create(GtkButtonBox,HORIZONTAL) -- holder for label and colorbutton
     set(colorbox,"layout",GTK_BUTTONBOX_CENTER)
     add(colorbox,{colorlbl,colorbutton})
     connect(colorbutton,"color-set",say,"Color selected!") -- optional, just for show

object testbtns = { -- these will be added along the bottom of the dialog in the usual button location
     {"gtk-cancel"},
     {"gtk-apply",apply_colors,colorbutton}
     }  
    
    ct += 1
    Custom(win,               -- 1: parent
	  "test200",          -- 2: titlebar caption
	  "Non modal dialog", -- 3: primary text
	  sprintf(`<span font="32">  %d</span>`,ct), -- 4: secondary text 
	  testbtns,           -- 5: array of buttons, add to the dialog's content area.
	  "thumbnails/user_icon.gif", -- 6: icon 
	  oeu_logo,    -- 7: titlebar icon from mongoose.e include
	  GTK_DIALOG_NON_MODAL, -- 8: mode
	  colorbox,  -- 9: add-on widget, 
	  rand(800), -- 10: x location
	  rand(600)) -- 11: y location
return 1
end function
