-- dialogs.exw
include win32lib.ew
include std/pretty.e
without warning

constant
Dialogs  = create( Window, "Screen Dialogs", 0, 50, 50, 520, 310, 0), 
Menu1  = create( Menu, "Dialog", Dialogs, 0, 0, 0, 0, 0), 
Menu2  = create( MenuItem, "Color", Menu1, 0, 0, 0, 0, 0), 
Menu3  = create( MenuItem, "Font", Menu1, 0, 0, 0, 0, 0), 
Menu4  = create( MenuItem, "&Exit", Menu1, 0, 0, 0, 0, 0), 
Result = create( LText, "", Dialogs, 0, 0, 512, 258, 0)


procedure get_font( integer self, integer event, sequence params )
    object font, font_style, font_height
    sequence fontsize
        
    -- call the dialog
    font = getFontDialogEx( Dialogs, w32GFD_DEFAULT_FLAGS, 0  )

    -- I'm cheating a bit here, since there
    -- are actually a few more possible return values.
    if sequence( font ) then
    
        -- we're in business!
        if equal( font[3], 3 ) then font_style = "Bold Italic"
        elsif equal( font[3], 2 ) then font_style = "Italic"
        elsif equal( font[3], 1 ) then font_style = "Bold"
        else font_style = "Regular"
        end if

        -- set the chosen font, and use it
        -- to report the results.
        setFont( Result, font[1], font[2], font[3] )
        -- font_height = getFontMetric( Result, tmHeight)    -- formally ok, but getFontMetric bombs here
        fontsize = getFontSize ( Result )                    -- try another way
        
        -- fontsize[3] is the height
        setText( Result, font[1] & ' '  &
        sprintf( "%d", {font[2]} ) & ' ' & font_style & "\nheight=" &
        sprintf( "%d", {fontsize[3]} ) )
    end if
    
end procedure

atom color
color=BrightWhite

procedure get_color( integer self, integer event, sequence params )
    atom chosencolor
    
    -- call the dialog
    chosencolor=getColorDialog( Dialogs, color )
    
    if chosencolor != -1 then
        setWindowBackColor( Result, chosencolor )
        setWindowBackColor( Dialogs, chosencolor )
    end if
    
end procedure

procedure get_lost( integer self, integer event, sequence params )
    closeWindow( Dialogs )
end procedure

setHandler( Menu2, w32HClick, routine_id( "get_color" ))
setHandler( Menu3, w32HClick, routine_id( "get_font" ))
setHandler( Menu4, w32HClick, routine_id( "get_lost" ))

WinMain( Dialogs, Normal )
--end