import gui
$include "guih.icn"

procedure fontdialog(font)
$ifdef _UNIX
   d := fdialog(font)
   d.show_modal()
   if font := \ (d.font) then {
      suspend font
      suspend d.fontcolor
      }
$else
   suspend WinFontDialog(font)
$endif
end

class fdialog : Dialog(cur_font,
   cancel, edit_fontcolor, label_4, label_5, ok,
   border_1, edit_fontname, edit_fontsize, edit_fontstyle, label_1, label_2,
   label_3, font, fn, fsz, fst, fontcolor, myanswer
   )
   method component_setup()
      local type, size, style                  
      if \cur_font then {
         cur_font ? {
            type := tab(upto(','))           
            tab(upto(&digits))
            size := integer(tab(many('0123456789.')))
            tab(many(','))
            style := tab(0)
            }
         fn := type
         fsz := size
         if style == "" then
            fst := &null
         else
            fst := style
         }
      if *self.children < 1 then
         self.setup()
   end

   method end_dialog()
   end

   method init_dialog()
   end

   method on_cancel(ev)
      font := &null
      myanswer := "Cancel"
      self.dispose()
   end

   method on_edit_fontcolor(ev)
      fontcolor := edit_fontcolor.selection_list[edit_fontcolor.get_selection()]
      label_5.set_attribs("font="||font,"fg="||fontcolor)
      self.init()
      self.resize()
      self.display()
   end

   method setfnt()
      font := (\fn | "sans")
      font ||:= "," || \fsz
      font ||:= "," || \fst
      label_5.set_attribs("font="||font)
      self.init()
      self.resize()
      self.display()
   end

   method on_edit_fontname(ev)
      fn := edit_fontname.selection_list[edit_fontname.get_selection()]
      setfnt()
   end

   method on_edit_fontsize(ev)
      fsz := edit_fontsize.selection_list[edit_fontsize.get_selection()]
      setfnt()
   end

   method on_edit_fontstyle(ev)
      fst := map(edit_fontstyle.selection_list[edit_fontstyle.get_selection()])
      if fst == "regular" then fst := &null
      else if fst == "bold italic" then fst := "bold,italic"
      setfnt()
   end

   method on_ok(ev)
      cur_font := font
      myanswer := "Okay"
      self.dispose()
   end

   method setup()
      self.set_attribs("size=519,231", "label=Choose a Font")
      label_1 := Label()
      label_1.set_pos(21, 31)
      label_1.set_internal_alignment("l")
      label_1.set_label("Font:")
      self.add(label_1)
      label_2 := Label()
      label_2.set_pos(155, 34)
      label_2.set_internal_alignment("l")
      label_2.set_label("Font style:")
      self.add(label_2)
      border_1 := Border()
      border_1.set_pos("37", "125")
      border_1.set_size("318", "78")
      border_1.set_internal_alignment("l")
      label_5 := Label()
      label_5.set_pos("7", "10")
      label_5.set_size("301", "61")
      label_5.set_attribs("font=sans,"||(\fsz|"11")||","||(\fst|""))
      label_5.set_internal_alignment("c")
      label_5.set_label("Sample")
      border_1.add(label_5)
      self.add(border_1)
      label_3 := Label()
      label_3.set_pos(277, 33)
      label_3.set_internal_alignment("l")
      label_3.set_label("Size:")
      self.add(label_3)
      edit_fontname := EditList()
      edit_fontname.set_pos(22, 60)
      edit_fontname.set_size(114, )
      edit_fontname.connect(self, "on_edit_fontname", SELECTION_CHANGED_EVENT)
      edit_fontname.set_selection_list(["sans", "serif", "mono", "typewriter"])
      edit_fontname.set_contents(\fn | "sans")
      self.add(edit_fontname)
      edit_fontstyle := EditList()
      edit_fontstyle.set_pos(153, 60)
      edit_fontstyle.set_size("100", )
      edit_fontstyle.connect(self, "on_edit_fontstyle", SELECTION_CHANGED_EVENT)
      edit_fontstyle.set_selection_list(["Regular", "Italic", "Bold", "Bold Italic"])
      edit_fontstyle.set_contents(\fst | "Regular")
      self.add(edit_fontstyle)
      edit_fontsize := EditList()
      edit_fontsize.set_pos(275, 60)
      edit_fontsize.set_size("100", )
      edit_fontsize.connect(self, "on_edit_fontsize", SELECTION_CHANGED_EVENT)
      edit_fontsize.set_selection_list(["7", "8", "9", "10", "11", "12", "13", "14", "16", "18", "20", "22", "24", "26", "30", "36", "44", "52", "60", "72"])
      edit_fontsize.set_contents(\fsz | "11")
      self.add(edit_fontsize)
      ok := TextButton()
      ok.set_pos("400", "124")
      ok.set_size("60", "25")
      ok.connect(self, "on_ok", ACTION_EVENT)
      ok.clear_toggles()
      ok.set_label("OK")
      ok.set_internal_alignment("c")
      self.add(ok)
      cancel := TextButton()
      cancel.set_pos("400", "174")
      cancel.set_size("60", "25")
      cancel.connect(self, "on_cancel", ACTION_EVENT)
      cancel.clear_toggles()
      cancel.set_label("Cancel")
      cancel.set_internal_alignment("c")
      self.add(cancel)
      label_4 := Label()
      label_4.set_pos(399, 33)
      label_4.set_internal_alignment("l")
      label_4.set_label("Color:")
      self.add(label_4)
      edit_fontcolor := EditList()
      edit_fontcolor.set_pos("400", "59")
      edit_fontcolor.set_size("100", )
      edit_fontcolor.connect(self, "on_edit_fontcolor", SELECTION_CHANGED_EVENT)
      edit_fontcolor.set_selection_list(["black", "red", "green", "blue", "cyan", "magenta", "yellow", "white"])
      self.add(edit_fontcolor)
   end

   initially
      self.Dialog.initially()
      font := \cur_font | "sans,11"
end

#procedure main()
#   local d
#   d := Untitled()
#   d.show_modal()
#end

### Ivib-v2 layout ##
#class|Canvas|17|Name Table|table|integer|0|4|string|border|integer|1|s
#tring|edit_list|integer|4|string|label|integer|5|string|text_button|in
#teger|2|SuperClass Name|string|Dialog|Import Name|string|gui|Button Gr
#oups|class|ButtonGroupSet|2|Parent Canvas|1|Boxes|list|0|Checkbox Grou
#ps|class|CheckBoxGroupSet|2|Parent Canvas|1|Boxes|list|0|Gen Indent|in
#teger|3|Gen Main|integer|1|Gen Component Setup|integer|1|Gen Init Dial
#og|integer|1|Gen Initially|integer|1|Dialog Struct|class|CDialog|4|Min
# Width|null|Min Height|null|Ticker Rate|null|Attribs|list|1|string|lab
#el=Choose a Font|Name|string|fdialog|Width|integer|519|Height|integer|
#231|Items|list|11|class|CanvasLabel|27|Parent Canvas|1|Name|string|lab
#el_1|Class Name|string|Label|Import Name|string|gui|X Fix|null|Y Fix|n
#ull|W Fix|null|H Fix|null|W Default|integer|1|H Default|integer|1|X Sp
#ec|integer|21|Y Spec|integer|31|W Spec|integer|30|H Spec|integer|13|X 
#Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subclass|null
#|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null|Event Handler
#s|list|0|Class Variable|integer|1|Parent Component|1|Label|string|Font
#:|Internal Align|string|l|class|CanvasLabel|27|Parent Canvas|1|Name|st
#ring|label_2|Class Name|string|Label|Import Name|string|gui|X Fix|null
#|Y Fix|null|W Fix|null|H Fix|null|W Default|integer|1|H Default|intege
#r|1|X Spec|integer|155|Y Spec|integer|34|W Spec|integer|66|H Spec|inte
#ger|13|X Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subc
#lass|null|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null|Even
#t Handlers|list|0|Class Variable|integer|1|Parent Component|1|Label|st
#ring|Font style:|Internal Align|string|l|class|CanvasBorder|28|Parent 
#Canvas|1|Name|string|border_1|Class Name|string|Border|Import Name|str
#ing|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|null|W Default|null|H D
#efault|null|X Spec|string|37|Y Spec|string|125|W Spec|string|318|H Spe
#c|string|78|X Align|string|l|Y Align|string|t|Is shaded|null|Is Button
# Subclass|null|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null
#|Event Handlers|list|0|Class Variable|integer|1|Parent Component|1|Int
#ernal Alignment|string|l|Children|list|1|class|CanvasLabel|27|Parent C
#anvas|1|Name|string|label_5|Class Name|string|Label|Import Name|string
#|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|null|W Default|null|H Defa
#ult|null|X Spec|string|7|Y Spec|string|10|W Spec|string|301|H Spec|str
#ing|61|X Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subc
#lass|null|Draw Border|null|Attribs|list|1|string|font=sans,11|Tooltip|
#null|Accel|null|Event Handlers|list|0|Class Variable|integer|1|Parent 
#Component|16|Label|string|Sample|Internal Align|string|c|Title Obj|nul
#l|class|CanvasLabel|27|Parent Canvas|1|Name|string|label_3|Class Name|
#string|Label|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H
# Fix|null|W Default|integer|1|H Default|integer|1|X Spec|integer|277|Y
# Spec|integer|33|W Spec|integer|30|H Spec|integer|13|X Align|string|l|
#Y Align|string|t|Is shaded|null|Is Button Subclass|null|Draw Border|nu
#ll|Attribs|list|0|Tooltip|null|Accel|null|Event Handlers|list|0|Class 
#Variable|integer|1|Parent Component|1|Label|string|Size:|Internal Alig
#n|string|l|class|CanvasEditList|29|Parent Canvas|1|Name|string|edit_fo
#ntname|Class Name|string|EditList|Import Name|string|gui|X Fix|null|Y 
#Fix|null|W Fix|null|H Fix|null|W Default|null|H Default|integer|1|X Sp
#ec|integer|22|Y Spec|integer|60|W Spec|integer|114|H Spec|integer|23|X
# Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subclass|nul
#l|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null|Event Handle
#rs|list|1|list|2|string|SELECTION_CHANGED_EVENT|string|on_edit_fontnam
#e|Class Variable|integer|1|Parent Component|1|Contents|string|sans|Sel
#ection|integer|1|Selection List|list|4|string|sans|string|serif|string
#|mono|string|typewriter|Filter String|string||class|CanvasEditList|29|
#Parent Canvas|1|Name|string|edit_fontstyle|Class Name|string|EditList|
#Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|null|W D
#efault|null|H Default|integer|1|X Spec|integer|153|Y Spec|integer|60|W
# Spec|string|100|H Spec|integer|23|X Align|string|l|Y Align|string|t|I
#s shaded|null|Is Button Subclass|null|Draw Border|null|Attribs|list|0|
#Tooltip|null|Accel|null|Event Handlers|list|1|list|2|string|SELECTION_
#CHANGED_EVENT|string|on_edit_fontstyle|Class Variable|integer|1|Parent
# Component|1|Contents|string|Regular|Selection|integer|1|Selection Lis
#t|list|4|string|Regular|string|Italic|string|Bold|string|Bold Italic|F
#ilter String|string||class|CanvasEditList|29|Parent Canvas|1|Name|stri
#ng|edit_fontsize|Class Name|string|EditList|Import Name|string|gui|X F
#ix|null|Y Fix|null|W Fix|null|H Fix|null|W Default|null|H Default|inte
#ger|1|X Spec|integer|275|Y Spec|integer|60|W Spec|string|100|H Spec|in
#teger|23|X Align|string|l|Y Align|string|t|Is shaded|null|Is Button Su
#bclass|null|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null|Ev
#ent Handlers|list|1|list|2|string|SELECTION_CHANGED_EVENT|string|on_ed
#it_fontsize|Class Variable|integer|1|Parent Component|1|Contents|strin
#g|11|Selection|integer|1|Selection List|list|20|string|7|string|8|stri
#ng|9|string|10|string|11|string|12|string|13|string|14|string|16|strin
#g|18|string|20|string|22|string|24|string|26|string|30|string|36|strin
#g|44|string|52|string|60|string|72|Filter String|string||class|CanvasT
#extButton|36|Parent Canvas|1|Name|string|ok|Class Name|string|TextButt
#on|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|null|
#W Default|null|H Default|null|X Spec|string|400|Y Spec|string|124|W Sp
#ec|string|60|H Spec|string|25|X Align|string|l|Y Align|string|t|Is sha
#ded|null|Is Button Subclass|integer|1|Draw Border|null|Attribs|list|0|
#Tooltip|null|Accel|null|Event Handlers|list|1|list|2|string|ACTION_EVE
#NT|string|on_ok|Class Variable|integer|1|Parent Component|1|Label|stri
#ng|OK|No Keyboard|null|Img Up|null|Img Down|null|Img Width|null|Img He
#ight|null|Is Checked Flag|null|Is Checkbox Flag|null|Parent CheckBoxGr
#oup|null|Parent Button Group|null|Internal Align|string|c|class|Canvas
#TextButton|36|Parent Canvas|1|Name|string|cancel|Class Name|string|Tex
#tButton|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|
#null|W Default|null|H Default|null|X Spec|string|400|Y Spec|string|174
#|W Spec|string|60|H Spec|string|25|X Align|string|l|Y Align|string|t|I
#s shaded|null|Is Button Subclass|integer|1|Draw Border|null|Attribs|li
#st|0|Tooltip|null|Accel|null|Event Handlers|list|1|list|2|string|ACTIO
#N_EVENT|string|on_cancel|Class Variable|integer|1|Parent Component|1|L
#abel|string|Cancel|No Keyboard|null|Img Up|null|Img Down|null|Img Widt
#h|null|Img Height|null|Is Checked Flag|null|Is Checkbox Flag|null|Pare
#nt CheckBoxGroup|null|Parent Button Group|null|Internal Align|string|c
#|class|CanvasLabel|27|Parent Canvas|1|Name|string|label_4|Class Name|s
#tring|Label|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H 
#Fix|null|W Default|integer|1|H Default|integer|1|X Spec|integer|399|Y 
#Spec|integer|33|W Spec|integer|36|H Spec|integer|13|X Align|string|l|Y
# Align|string|t|Is shaded|null|Is Button Subclass|null|Draw Border|nul
#l|Attribs|list|0|Tooltip|null|Accel|null|Event Handlers|list|0|Class V
#ariable|integer|1|Parent Component|1|Label|string|Color:|Internal Alig
#n|string|l|class|CanvasEditList|29|Parent Canvas|1|Name|string|edit_fo
#ntcolor|Class Name|string|EditList|Import Name|string|gui|X Fix|null|Y
# Fix|null|W Fix|null|H Fix|null|W Default|null|H Default|integer|1|X S
#pec|string|400|Y Spec|string|59|W Spec|string|100|H Spec|integer|23|X 
#Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subclass|null
#|Draw Border|null|Attribs|list|0|Tooltip|null|Accel|null|Event Handler
#s|list|1|list|2|string|SELECTION_CHANGED_EVENT|string|on_edit_fontcolo
#r|Class Variable|integer|1|Parent Component|1|Contents|string|black|Se
#lection|integer|1|Selection List|list|8|string|black|string|red|string
#|green|string|blue|string|cyan|string|magenta|string|yellow|string|whi
#te|Filter String|string||Initial Focus|null|Event Handlers|list|0|
