#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

UseGettext {$NSCDE_ROOT/share/locale;NsCDE-FontMgr}
WindowLocaleTitle {Style Manager - Font}
WindowSize 528 692
Colorset 22

Init
Begin
   Set $FontDPI = (GetOutput {echo $NSCDE_FONT_DPI} 1 1)
   Set $StaticConfCheckCmd = {test -f "$FVWM_USERDIR/Font-} $FontDPI {dpi.fvwmconf" && echo 1}
   Set $StaticConfCheck = (GetOutput $StaticConfCheckCmd 1 1)
   If $StaticConfCheck == 1 Then
   Begin
      Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" }
         {"$[gt.Static Font configuration file exists and is read }
         {instead of regular one generated by Font Style Manager. In }
         {order to use Font Style Manager, static file must be removed:] }
         {$[FVWM_USERDIR]/Font-} $FontDPI {dpi.fvwmconf."}
      Quit
   End

   # Locale stuff: Hack to keep leading or ending space(s)
   # which will be trimmed by LocaleTitle Widget directive.
   ChangeLocaleTitle 2 (GetTitle 2)
   ChangeLocaleTitle 22 (GetTitle 22)
   ChangeLocaleTitle 23 (GetTitle 23)
   ChangeLocaleTitle 24 (GetTitle 24)

   # CheckBox buttons get smaller font size
   Set $SmallLabelFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s small -Z 10.5} 1 -1)
   ChangeFont 2 $SmallLabelFont
   ChangeFont 22 $SmallLabelFont
   ChangeFont 23 $SmallLabelFont
   ChangeFont 24 $SmallLabelFont

   # Rest of the widgets will get standard fonts
   Set $LabelFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 12.5} 1 -1)
   ChangeFont 3 $LabelFont
   ChangeFont 4 $LabelFont
   ChangeFont 5 $LabelFont
   ChangeFont 6 $LabelFont
   ChangeFont 7 $LabelFont
   ChangeFont 9 $LabelFont
   ChangeFont 10 $LabelFont
   ChangeFont 11 $LabelFont
   ChangeFont 12 $LabelFont
   ChangeFont 13 $LabelFont
   ChangeFont 14 $LabelFont
   ChangeFont 26 $LabelFont
   ChangeFont 27 $LabelFont
   ChangeFont 28 $LabelFont

   # Fill initial preview values
   Set $FontExampleText = (Gettext {Quick Brown Fox Jumps Over a Lazy Dog ...})
   ChangeLocaleTitle 15 $FontExampleText
   ChangeLocaleTitle 16 $FontExampleText
   ChangeLocaleTitle 17 $FontExampleText
   ChangeLocaleTitle 18 $FontExampleText
   ChangeLocaleTitle 19 $FontExampleText

   # Fill List Widget 5 with font names
   Set $FontList = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -p} 1 -1)
   Set $FontTotalNum = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -p} 2 -1)
   ChangeTitle 5 $FontList

   # Set Font Size Group choices, select Medium to be displayed by default
   Set $SizeGroupMenu = { Small| Medium| Large}
   ChangeLocaleTitle 10 $SizeGroupMenu
   ChangeValue 10 2

   # Static list of choices for font sizes, size 11 is initial default
   Set $FontSizes = {4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26}
   ChangeLocaleTitle 14 $FontSizes
   ChangeValue 14 8

   # Default Fonts: set initial values
   Set $FontNormalSmallStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s small} 1 -1)
   Set $FontBoldSmallStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t bold -s small} 1 -1)
   Set $FontItalicSmallStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t italic -s small} 1 -1)
   Set $FontMonoSmallStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t normal -s small} 1 -1)
   Set $FontMonoBoldSmallStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t bold -s small} 1 -1)

   Set $FontNormalMediumStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium} 1 -1)
   Set $FontBoldMediumStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t bold -s medium} 1 -1)
   Set $FontItalicMediumStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t italic -s medium} 1 -1)
   Set $FontMonoMediumStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t normal -s medium} 1 -1)
   Set $FontMonoBoldMediumStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t bold -s medium} 1 -1)

   Set $FontNormalLargeStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s large} 1 -1)
   Set $FontBoldLargeStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t bold -s large} 1 -1)
   Set $FontItalicLargeStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t italic -s large} 1 -1)
   Set $FontMonoLargeStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t normal -s large} 1 -1)
   Set $FontMonoBoldLargeStr = (GetOutput {$NSCDE_TOOLSDIR/getfont -m -t bold -s large} 1 -1)

   # Apply Medium as previews initially
   ChangeFont 15 $FontNormalMediumStr
   ChangeFont 16 $FontBoldMediumStr
   ChangeFont 17 $FontItalicMediumStr
   ChangeFont 18 $FontMonoMediumStr
   ChangeFont 19 $FontMonoBoldMediumStr
   ChangeFont 20 $FontNormalMediumStr

   # Select Default font, it's style, and size
   Set $FontNormalMediumStrCmd = {$NSCDE_TOOLSDIR/fontmgr -r '} $FontNormalMediumStr {'}
   Set $FontNormalMediumStrNameNum = (GetOutput $FontNormalMediumStrCmd 1 -1)
   Set $FontNormalMediumStrStyleNum = (GetOutput $FontNormalMediumStrCmd 2 -1)
   Set $FontNormalMediumStrSizeNum = (Add (GetOutput $FontNormalMediumStrCmd 3 1) -3)
   Set $FontNormalMediumStrName = (GetOutput $FontNormalMediumStrCmd 4 -1)

   # Initial styles menu for regular variable font of medium size
   Set $FontNormalMediumStrMenuCmd = {$NSCDE_TOOLSDIR/fontmgr -G menu -g '} $FontNormalMediumStrName {'}
   Set $FontNormalMediumStrMenu = (GetOutput $FontNormalMediumStrMenuCmd 1 -1)

   # Select variable font of medium size, display styles for that font, select style and set size
   # from parsing $FontNormalMediumStrNameNum above
   ChangeValue 5 $FontNormalMediumStrNameNum
   ChangeTitle 7 $FontNormalMediumStrMenu
   ChangeValue 7 $FontNormalMediumStrStyleNum
   ChangeValue 14 $FontNormalMediumStrSizeNum

   # Key bindings
   Key Q C 27 1 {KeyClose}
   Key Return C 26 5 {KeySave}
   Key F1 A 28 1 {KeyHelp}
   Key Help A 28 1 {KeyHelp}
   Key Prior A 101 5 {PreviewUp}
   Key Next A 101 5 {PreviewDown}
   Key Up A 101 6 {ListUp}
   Key Down A 101 6 {ListDown}
   Key S C 101 7 {KeySmall}
   Key M C 101 7 {KeyMedium}
   Key L C 101 7 {KeyLarge}
   Key Plus C 101 8 {KeyIncrease}
   Key Minus C 101 8 {KeyDecrease}
   Key Equal C 101 8 {KeyDefSize}
   Key F C 101 9 {KeyFlipOprMode}

   # Initial defaults: Manual font selection $OperationMode, Regular Medium Variable font
   Set $OperationMode = 1
   Set $ActivePreviewField = 15
   Do {Schedule 1000 SendToModule FontMgr SendString 101 2 initial}

   # Defaults for Font Size Popup - same as above, select initial default on startup
   Set $FontConstruct = $FontNormalMediumStr

   # Defaults for fontset
   Set $DefaultFontset = {DejaVuSerif}
   Set $DefaultFontsetPath = {$NSCDE_DATADIR/fontsets/} $DefaultFontset {.fontset}
   Set $FontsetPath = $DefaultFontsetPath

   # For Fontset info when some font from fontset does not exist, having
   # this in variable does not produce "}" on fvwm stderr / xsession-errors
   Set $Notavail = (Gettext {Not available})

   # Manage race condition between messages for InputForm and ChoiceForm
   # Default will be the messages listening for InputForm
   Set $QuitStarted = 0
End

# In PeriodicTasks be careful not to mess messages from two different dialogs.
# MSG is the waiting for InputForm, while QUITMSG is the waiting for ChoiceForm
# See Widget 26 - Save button - click and routine 3.
PeriodicTasks
Begin
   If $QuitStarted == 0 Then
   Begin
      Set $MSG = (ReceivFromScript $INPUTFORM)
      # Do {Echo >>> >>> >>> INPUT-FORM MESSAGE: } $MSG
      If $MSG <> {No message} Then
      Begin
        If $MSG <> {Go} Then
        Begin
           Do {Schedule 250 SendToModule FontMgr SendString 26 1 } $MSG
        End
      End
   End
   Else
   Begin
      Set $QUITMSG = (ReceivFromScript $QUITFORM)
      # Do {Echo >>> >>> >>> QUIT-FORM MESSAGE: } $QUITMSG
      If $QUITMSG <> {No message} Then
      Begin
         Do {SendToModule FontMgr SendString 26 4 } $QUITMSG
      End
   End
End

# Icon Logo top left
Widget 1
   Property
   Position 10 8
   Flags NoReliefString NoFocus
   Type ItemDraw
   Icon NsCDE/DtFont.xpm
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Fontset or manual font selection choice
# Value 2 == fontset list
# Value 1 == manual fonts selection
# $OperationMode spreads this globally
Widget 2
   Property
   Position 108 14
   Size 180 20
   Flags NoReliefString
   Type CheckBox
   Font "xft:::pixelsize=15"
   Value 0
   Title { Use Predefined Font Set          }
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 2 1
      End
      1 :
      Begin
         If (GetValue 2) == 1 Then
         Begin
            Set $FontsetList = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -P} 1 -1)
            Set $FontsetTotalNum = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -P} 2 -1)
            ChangeTitle 5 $FontsetList
            ChangeLocaleTitle 3 {Default|Default|Delete Fontset}
            ChangeColorset 7 22
            ChangeTitle 7 {}
            ChangeLocaleTitle 4 {Font Sets}
            HideWidget 13
            HideWidget 14
            Set $OperationMode = 2
            Set $SelectDefaultFontsetCmd = {$NSCDE_TOOLSDIR/fontmgr -f "} $DefaultFontset {"}
            Set $SelectDefaultFontset = (GetOutput $SelectDefaultFontsetCmd 1 -1)
            ChangeValue 5 $SelectDefaultFontset
            # Fill all 15 font variables for widgets 15 - 19
            SendSignal 5 2
         End
         Else
         Begin
            Set $FontList = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -p} 1 -1)
            Set $FontTotalNum = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -p} 2 -1)
            ChangeTitle 5 $FontList
            ChangeLocaleTitle 3 {Default|Default|Cancel}
            ChangeColorset 7 20
            ChangeLocaleTitle 4 {Fonts}
            ShowWidget 13
            ShowWidget 14
            Set $OperationMode = 1
            # Call hidden worker widget to split and parse XFT font str
            # serves also as light TextField Colorset 20 workaround when
            # Colorset 22 is dark with white foreground
            SendSignal 101 3
         End
      End
End

# Default button and hidden delete fontset functionality
Widget 3
   Property
   Position 396 10
   Size 120 30
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Default|Default|Cancel}
   Main
      Case message of
      SingleClic :
      Begin
         If $OperationMode == 1 Then
         Begin
            If (GetValue 3) <> 2 Then
            Begin
               SendSignal 3 1
            End
         End
         If $OperationMode == 2 Then
         Begin
            If (GetValue 3) == 1 Then
            Begin
               SendSignal 3 1
            End
            If (GetValue 3) == 2 Then
            Begin
               Do {f_RunQuickScriptDialog ActionForm "$[gt.Delete Fontset] \"} $FontsetName {\"" "$[gt.Yes]" "$[gt.No]" "$[gt.Delete Fontset]" "SendToModule FontMgr SendString 3 2 confirmed"}
               SendSignal 3 2
            End
         End
      End
      1 :
      Begin
         # Set default values
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t normal -s small}
         Set $FontNormalSmallStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t bold -s small}
         Set $FontBoldSmallStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t italic -s small}
         Set $FontItalicSmallStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t normal -s small}
         Set $FontMonoSmallStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t bold -s small}
         Set $FontMonoBoldSmallStr = (GetOutput $FontGetCmd 1 -1)

         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t normal -s medium}
         Set $FontNormalMediumStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t bold -s medium}
         Set $FontBoldMediumStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t italic -s medium}
         Set $FontItalicMediumStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t normal -s medium}
         Set $FontMonoMediumStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t bold -s medium}
         Set $FontMonoBoldMediumStr = (GetOutput $FontGetCmd 1 -1)

         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t normal -s large}
         Set $FontNormalLargeStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t bold -s large}
         Set $FontBoldLargeStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -v -t italic -s large}
         Set $FontItalicLargeStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t normal -s large}
         Set $FontMonoLargeStr = (GetOutput $FontGetCmd 1 -1)
         Set $FontGetCmd = {$NSCDE_TOOLSDIR/getfont -f "} $DefaultFontsetPath {" -m -t bold -s large}
         Set $FontMonoBoldLargeStr = (GetOutput $FontGetCmd 1 -1)

         Set $SelectDefaultFontsetCmd = {$NSCDE_TOOLSDIR/fontmgr -f "} $DefaultFontset {"}
         Set $SelectDefaultFontset = (GetOutput $SelectDefaultFontsetCmd 1 -1)

         ChangeValue 5 $SelectDefaultFontset
         Set $FontsetName = $DefaultFontset
         # 10 1 is small, medium or large font group
         SendSignal 10 1
      End
      2 :
      Begin
         # XXX select default after deletion
         If (LastString) == {confirmed} Then
         Begin
            Set $DeleteFontsetCmd = {rm -f '} $FontsetPath {' 2>&1}
            Set $DeleteFontset = (GetOutput $DeleteFontsetCmd 1 -1)

            If $DeleteFontset == {} Then
            Begin
               Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Info.xpm" "$[gt.Fontset file] \\\"} $FontsetName {\\\" $[gt.removed from inventory.]"}
               Set $FontsetList = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -P} 1 -1)
               Set $FontsetTotalNum = (GetOutput {$NSCDE_TOOLSDIR/fontmgr -P} 2 -1)
               # Refill fontset list
               ChangeTitle 5 $FontsetList
               # Refill all 15 font variables
               SendSignal 3 1
               # 10 1 is small, medium or large font group
               SendSignal 10 1
            End
            Else
            Begin
               Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error removing] \\\"} $FontsetName {\\\": } $DeleteFontset {"}
            End
         End
      End
End

# Label above font/fontset list
Widget 4
   Property
   Position 22 62
   Size 200 20
   Flags NoReliefString NoFocus Left
   Type ItemDraw
   LocaleTitle {Fonts}
   Font "xft:::pixelsize=16"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Main Font and Fontset list
Widget 5
   Property
   Position 20 84
   Size 292 168
   Flags NoReliefString
   Type List
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
         If $OperationMode == 1 Then
         Begin
            # Manual font name selection
            SendSignal 5 1
         End
         If $OperationMode == 2 Then
         Begin
            # Fontset selection
            SendSignal 5 2
         End
      End
      # 5 1 - Manual font name selection on list widget
      1 :
      Begin
         # Find font name, and fill font styles in list of widget 7
         Set $ListFontNameCmd = {$NSCDE_TOOLSDIR/fontmgr -N } (GetValue 5)
         Set $ListFontName = (GetOutput $ListFontNameCmd 1 -1)
         Set $FontStylesCmd = {$NSCDE_TOOLSDIR/fontmgr -G menu -g '} $ListFontName {'}
         Set $FontStyles = (GetOutput $FontStylesCmd 1 -1)
         ChangeTitle 7 $FontStyles

         # Change selection of the style list
         If (GetValue 7) == 0 Then
         Begin
            Set $SizeValCmd = {$NSCDE_TOOLSDIR/fontmgr -G total -g '} $ListFontName {'}
            Set $SizeVal = (GetOutput $SizeValCmd 1 -1)
            ChangeValue 7 $SizeVal
         End
         Else
         Begin
            Set $SizeVal = (GetValue 7)
         End

         # fontmgr -s - get style name from it's number
         Set $FontStyleListCmd = {$NSCDE_TOOLSDIR/fontmgr -s } $SizeVal { -g '} $ListFontName {'}
         Set $FontStyleList = (GetOutput $FontStyleListCmd 1 -1)

         # Construct controlled XFT font spec and set active preview field with it
         Set $FontConstruct = {xft:} $ListFontName {:Medium:} $FontStyleList {:size=} (Add (GetValue 14) 3)
         ChangeFont $ActivePreviewField $FontConstruct
         ChangeFont 20 $FontConstruct

         # Set active preview field with parsed font
         # small group:
         If (GetValue 10) == 1 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldSmallStr = $FontConstruct
            End
         End

         # Set active preview field with parsed font
         # medium group:
         If (GetValue 10) == 2 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldMediumStr = $FontConstruct
            End
         End

         # Set active preview field with parsed font
         # large group:
         If (GetValue 10) == 3 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldLargeStr = $FontConstruct
            End
         End
      End
      # 5 2 - Fontset name selection on list widget
      2 :
      Begin
         Set $FontsetNameCmd = {$NSCDE_TOOLSDIR/fontmgr -F } (GetValue 5)
         Set $FontsetName = (GetOutput $FontsetNameCmd 1 -1)
         Set $FontsetDir = (GetOutput $FontsetNameCmd 2 -1)
         Set $FontsetPath = $FontsetDir $FontsetName {.fontset}

         Set $FontNormalSmallStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t normal -s small}
         Set $FontNormalSmallStr = (GetOutput $FontNormalSmallStrCmd 1 -1)

         Set $FontBoldSmallStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t bold -s small}
         Set $FontBoldSmallStr = (GetOutput $FontBoldSmallStrCmd 1 -1)

         Set $FontItalicSmallStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t italic -s small}
         Set $FontItalicSmallStr = (GetOutput $FontItalicSmallStrCmd 1 -1)

         Set $FontMonoSmallStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t normal -s small}
         Set $FontMonoSmallStr = (GetOutput $FontMonoSmallStrCmd 1 -1)

         Set $FontMonoBoldSmallStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t bold -s small}
         Set $FontMonoBoldSmallStr = (GetOutput $FontMonoBoldSmallStrCmd 1 -1)

         Set $FontNormalMediumStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t normal -s medium}
         Set $FontNormalMediumStr = (GetOutput $FontNormalMediumStrCmd 1 -1)

         Set $FontBoldMediumStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t bold -s medium}
         Set $FontBoldMediumStr = (GetOutput $FontBoldMediumStrCmd 1 -1)

         Set $FontItalicMediumStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t italic -s medium}
         Set $FontItalicMediumStr = (GetOutput $FontItalicMediumStrCmd 1 -1)

         Set $FontMonoMediumStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t normal -s medium}
         Set $FontMonoMediumStr = (GetOutput $FontMonoMediumStrCmd 1 -1)

         Set $FontMonoBoldMediumStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t bold -s medium}
         Set $FontMonoBoldMediumStr = (GetOutput $FontMonoBoldMediumStrCmd 1 -1)

         Set $FontNormalLargeStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t normal -s large}
         Set $FontNormalLargeStr = (GetOutput $FontNormalLargeStrCmd 1 -1)

         Set $FontBoldLargeStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t bold -s large}
         Set $FontBoldLargeStr = (GetOutput $FontBoldLargeStrCmd 1 -1)

         Set $FontItalicLargeStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -v -t italic -s large}
         Set $FontItalicLargeStr = (GetOutput $FontItalicLargeStrCmd 1 -1)

         Set $FontMonoLargeStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t normal -s large}
         Set $FontMonoLargeStr = (GetOutput $FontMonoLargeStrCmd 1 -1)

         Set $FontMonoBoldLargeStrCmd = {$NSCDE_TOOLSDIR/getfont -f } $FontsetPath { -m -t bold -s large}
         Set $FontMonoBoldLargeStr = (GetOutput $FontMonoBoldLargeStrCmd 1 -1)

         # 10 1 is small, medium or large font group
         SendSignal 10 1
      End
End

# Label above font style / fontset info list
Widget 6
   Property
   Position 334 62
   Flags NoReliefString NoFocus Left
   Type ItemDraw
   LocaleTitle {Font Style}
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Font Style / Fontset info list
Widget 7
   Property
   Position 326 84
   Size 182 168
   Flags NoReliefString
   Type List
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
         If $OperationMode == 1 Then
         Begin
            # Update font list and variables, workaround light cs 20 vs dark cs 22 bug too
            SendSignal 5 1
         End
      End
End

Widget 8
   Property
   Position 10 56
   Size 508 206
   Flags NoReliefString NoFocus
   Type Rectangle
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Label above font size group PopupMenu
Widget 9
   Property
   Position 12 270
   Flags NoReliefString NoFocus Left
   Type ItemDraw
   LocaleTitle {Font Size Group:}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Font size group: small, medium or large
# Changes preview in widgets 15 - 19
Widget 10
   Property
   Position 12 296
   Size 540 244
   Flags NoReliefString
   Type PopupMenu
   Font "xft:::pixelsize=15"
   Title {xxxxxxxxxxxxxx}
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 10 1
      End
      1 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            # Holder for black on white - examine, extend if needed
            Do {Schedule 120 SendToModule FontMgr SendString } $ActivePreviewField { 1 dummy}
            ChangeFont 15 $FontNormalSmallStr
            ChangeFont 16 $FontBoldSmallStr
            ChangeFont 17 $FontItalicSmallStr
            ChangeFont 18 $FontMonoSmallStr
            ChangeFont 19 $FontMonoBoldSmallStr
            If $ActivePreviewField == 15 Then
            Begin
               ChangeFont 20 $FontNormalSmallStr
            End
            If $ActivePreviewField == 16 Then
            Begin
               ChangeFont 20 $FontBoldSmallStr
            End
            If $ActivePreviewField == 17 Then
            Begin
               ChangeFont 20 $FontItalicSmallStr
            End
            If $ActivePreviewField == 18 Then
            Begin
               ChangeFont 20 $FontMonoSmallStr
            End
            If $ActivePreviewField == 19 Then
            Begin
               ChangeFont 20 $FontMonoBoldSmallStr
            End
         End
         If (GetValue 10) == 2 Then
         Begin
            # Holder for black on white - examine, extend if needed
            Do {Schedule 120 SendToModule FontMgr SendString } $ActivePreviewField { 1 dummy}
            ChangeFont 15 $FontNormalMediumStr
            ChangeFont 16 $FontBoldMediumStr
            ChangeFont 17 $FontItalicMediumStr
            ChangeFont 18 $FontMonoMediumStr
            ChangeFont 19 $FontMonoBoldMediumStr
            If $ActivePreviewField == 15 Then
            Begin
               ChangeFont 20 $FontNormalMediumStr
            End
            If $ActivePreviewField == 16 Then
            Begin
               ChangeFont 20 $FontBoldMediumStr
            End
            If $ActivePreviewField == 17 Then
            Begin
               ChangeFont 20 $FontItalicMediumStr
            End
            If $ActivePreviewField == 18 Then
            Begin
               ChangeFont 20 $FontMonoMediumStr
            End
            If $ActivePreviewField == 19 Then
            Begin
               ChangeFont 20 $FontMonoBoldMediumStr
            End
         End
         If (GetValue 10) == 3 Then
         Begin
            # Holder for black on white - examine, extend if needed
            Do {Schedule 120 SendToModule FontMgr SendString } $ActivePreviewField { 1 dummy}
            ChangeFont 15 $FontNormalLargeStr
            ChangeFont 16 $FontBoldLargeStr
            ChangeFont 17 $FontItalicLargeStr
            ChangeFont 18 $FontMonoLargeStr
            ChangeFont 19 $FontMonoBoldLargeStr
            If $ActivePreviewField == 15 Then
            Begin
               ChangeFont 20 $FontNormalLargeStr
            End
            If $ActivePreviewField == 16 Then
            Begin
               ChangeFont 20 $FontBoldLargeStr
            End
            If $ActivePreviewField == 17 Then
            Begin
               ChangeFont 20 $FontItalicLargeStr
            End
            If $ActivePreviewField == 18 Then
            Begin
               ChangeFont 20 $FontMonoLargeStr
            End
            If $ActivePreviewField == 19 Then
            Begin
               ChangeFont 20 $FontMonoBoldLargeStr
            End
         End
      End
End

# Label above Font Style Group PopupMenu
Widget 11
   Property
   Position 210 270
   Flags NoReliefString NoFocus Left
   Type ItemDraw
   LocaleTitle {Font Style Group:}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Font Style PopupMenu
Widget 12
   Property
   Size 180 244
   Position 212 296
   Flags NoReliefString
   Type PopupMenu
   Font "xft:::pixelsize=15"
   LocaleTitle {Regular|Bold|Italic|Monospaced|Monospaced Bold}
   Value 5
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 12 1
      End
      # Refill the right font preview field based on this popup menu selection
      1 :
      Begin
         If (GetValue 12) == 1 Then
         Begin
            SendSignal 15 1
         End
         If (GetValue 12) == 2 Then
         Begin
            SendSignal 16 1
         End
         If (GetValue 12) == 3 Then
         Begin
            SendSignal 17 1
         End
         If (GetValue 12) == 4 Then
         Begin
            SendSignal 18 1
         End
         If (GetValue 12) == 5 Then
         Begin
            SendSignal 19 1
         End
      End
End

# Label above font size PopupMenu
Widget 13
   Property
   Position 428 270
   Flags NoReliefString NoFocus Left
   Type ItemDraw
   LocaleTitle {Set Size:}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Rightmost PopupMenu ... size
Widget 14
   Property
   Size 120 244
   Position 428 296
   Flags NoReliefString
   Type PopupMenu
   Font "xft:::pixelsize=15"
   Title { xxxx }
   Main
      Case message of
      SingleClic :
      Begin
         If $OperationMode == 1 Then
         Begin
            # Update font list prior to calling own routine 1
            # Updates also styles and preview fields 15 - 19
            SendSignal 5 1
            SendSignal 14 1
         End
      End
      1 :
      Begin
         # Parse font, make XFT font construction, update font variables for a size group
         Set $SplitFontStrCmd = {$NSCDE_TOOLSDIR/fontmgr -r '} $FontConstruct {'}
         Set $FontNameNum = (GetOutput $SplitFontStrCmd 1 -1)
         Set $FontStyleNum = (GetOutput $SplitFontStrCmd 2 -1)
         Set $FontSizeNum = (Add (GetValue 14) 3)
         Set $FontName = (GetOutput $SplitFontStrCmd 4 -1)
         Set $FontStyleCmd = {$NSCDE_TOOLSDIR/fontmgr -s } (GetValue 7) { -g '} $FontConstruct {'}
         Set $FontStyle = (GetOutput $FontStyleListCmd 1 -1)
         Set $FontConstruct = {xft:} $FontName {:Medium:} $FontStyle {:size=} $FontSizeNum

         # W10 value #1 - small
         If (GetValue 10) == 1 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoSmallStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldSmallStr = $FontConstruct
            End
         End

         # W10 value #2 - medium
         If (GetValue 10) == 2 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoMediumStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldMediumStr = $FontConstruct
            End
         End

         # W10 value #3 - large
         If (GetValue 10) == 3 Then
         Begin
            If $ActivePreviewField == 15 Then
            Begin
               Set $FontNormalLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 16 Then
            Begin
               Set $FontBoldLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 17 Then
            Begin
               Set $FontItalicLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 18 Then
            Begin
               Set $FontMonoLargeStr = $FontConstruct
            End
            If $ActivePreviewField == 19 Then
            Begin
               Set $FontMonoBoldLargeStr = $FontConstruct
            End
         End

         # Holder for black on white - examine, extend if needed
         Do {Schedule 120 SendToModule FontMgr SendString } $ActivePreviewField { 1 dummy}
      End
End

# Preview ItemDraw widget for variable regular font
# Font "xft:::pixelsize=24" guarantees height of the widget
Widget 15
   Property
   Position 18 344
   Size 490 4
   Colorset 22
   Flags NoReliefString Left
   Type ItemDraw
   Title {Quick Brown Fox}
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 15 1
      End
      1 :
      Begin
         # ActivePreviewField refers to the past selected preview field here
         # until it is set to the current one.
         If $ActivePreviewField <> 15 Then
         Begin
            ShowWidget $ActivePreviewField
            # Preserve manual preview field modifications for a session
            If (GetTitle 20) <> $FontExampleText Then
            Begin
               ChangeTitle $ActivePreviewField (GetTitle 20)
            End
         End
         # Hide ItemDraw, position TextField Widget 20, change W20 title to ItemDraw
         # from W10 values 1, 2 or 3.
         HideWidget 15
         ChangePosition 20 18 344
         ChangeTitle 20 (GetTitle 15)
         ShowWidget 20
         # Set ActivePreviewField, 15 2 - set $FontConstruct for small, normal or large
         Set $ActivePreviewField = 15
         SendSignal 15 2
         # 101 1 - set active and inactive preview fields, change font size group popup menu label
         # Change TextField font to current ItemDraw
         SendSignal 101 1

         # Fontset operation mode
         # Fill W7 List with fontset and selected font info.
         # Match the existing font, handle missing fonts from fontset.
         SendSignal 101 4
      End
      # Set $FontConstruct for small, normal or large
      # 101 3 must be called again because of light cs 20 vs dark cs 22 TextField bug
      2 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            Set $FontConstruct = $FontNormalSmallStr
            SendSignal 101 3
         End
         If (GetValue 10) == 2 Then
         Begin
            Set $FontConstruct = $FontNormalMediumStr
            SendSignal 101 3
         End
         If (GetValue 10) == 3 Then
         Begin
            Set $FontConstruct = $FontNormalLargeStr
            SendSignal 101 3
         End
      End
End

# Preview ItemDraw widget for variable bold font
# Font "xft:::pixelsize=24" guarantees height of the widget
Widget 16
   Property
   Position 18 394
   Size 490 4
   Colorset 22
   Flags NoReliefString Left
   Type ItemDraw
   Title {Quick Brown Fox}
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 16 1
      End
      1 :
      Begin
         # ActivePreviewField refers to the past selected preview field here
         # until it is set to the current one.
         If $ActivePreviewField <> 16 Then
         Begin
            ShowWidget $ActivePreviewField
            # Preserve manual preview field modifications for a session
            If (GetTitle 20) <> $FontExampleText Then
            Begin
               ChangeTitle $ActivePreviewField (GetTitle 20)
            End
         End
         # Hide ItemDraw, position TextField Widget 20, change W20 title to ItemDraw
         # from W10 values 1, 2 or 3.
         HideWidget 16
         ChangePosition 20 18 394
         ChangeTitle 20 (GetTitle 16)
         ShowWidget 20
         # Set ActivePreviewField, 16 2 - set $FontConstruct for small, normal or large
         Set $ActivePreviewField = 16
         SendSignal 16 2
         # 101 1 - set active and inactive preview fields, change font size group popup menu label
         # Change TextField font to current ItemDraw
         SendSignal 101 1

         # Fontset operation mode
         # Fill W7 List with fontset and selected font info.
         # Match the existing font, handle missing fonts from fontset.
         SendSignal 101 4
      End
      # Set $FontConstruct for small, normal or large
      # 101 3 must be called again because of light cs 20 vs dark cs 22 TextField bug
      2 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            Set $FontConstruct = $FontBoldSmallStr
            SendSignal 101 3
         End
         If (GetValue 10) == 2 Then
         Begin
            Set $FontConstruct = $FontBoldMediumStr
            SendSignal 101 3
         End
         If (GetValue 10) == 3 Then
         Begin
            Set $FontConstruct = $FontBoldLargeStr
            SendSignal 101 3
         End
      End
End

# Preview ItemDraw widget for variable italic font
# Font "xft:::pixelsize=24" guarantees height of the widget
Widget 17
   Property
   Position 18 444
   Size 490 4
   Colorset 22
   Flags NoReliefString Left
   Type ItemDraw
   Title {Quick Brown Fox}
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 17 1
      End
      1 :
      Begin
         # ActivePreviewField refers to the past selected preview field here
         # until it is set to the current one.
         If $ActivePreviewField <> 17 Then
         Begin
           ShowWidget $ActivePreviewField
            # Preserve manual preview field modifications for a session
            If (GetTitle 20) <> $FontExampleText Then
            Begin
               ChangeTitle $ActivePreviewField (GetTitle 20)
            End
         End
         # Hide ItemDraw, position TextField Widget 20, change W20 title to ItemDraw
         # from W10 values 1, 2 or 3.
         HideWidget 17
         ChangePosition 20 18 444
         ChangeTitle 20 (GetTitle 17)
         ShowWidget 20
         # Set ActivePreviewField, 17 2 - set $FontConstruct for small, normal or large
         Set $ActivePreviewField = 17
         SendSignal 17 2
         # 101 1 - set active and inactive preview fields, change font size group popup menu label
         # Change TextField font to current ItemDraw
         SendSignal 101 1

         # Fontset operation mode
         # Fill W7 List with fontset and selected font info.
         # Match the existing font, handle missing fonts from fontset.
         SendSignal 101 4
      End
      # Set $FontConstruct for small, normal or large
      # 101 3 must be called again because of light cs 20 vs dark cs 22 TextField bug
      2 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            Set $FontConstruct = $FontItalicSmallStr
            SendSignal 101 3
         End
         If (GetValue 10) == 2 Then
         Begin
            Set $FontConstruct = $FontItalicMediumStr
            SendSignal 101 3
         End
         If (GetValue 10) == 3 Then
         Begin
            Set $FontConstruct = $FontItalicLargeStr
            SendSignal 101 3
         End
      End
End

# Preview ItemDraw widget for monospaced regular font
# Font "xft:::pixelsize=24" guarantees height of the widget
Widget 18
   Property
   Position 18 494
   Size 490 4
   Colorset 22
   Flags NoReliefString Left
   Type ItemDraw
   Title {Quick Brown Fox}
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 18 1
      End
      1 :
      Begin
         # ActivePreviewField refers to the past selected preview field here
         # until it is set to the current one.
         If $ActivePreviewField <> 18 Then
         Begin
            ShowWidget $ActivePreviewField
            # Preserve manual preview field modifications for a session
            If (GetTitle 20) <> $FontExampleText Then
            Begin
               ChangeTitle $ActivePreviewField (GetTitle 20)
            End
         End
         # Hide ItemDraw, position TextField Widget 20, change W20 title to ItemDraw
         # from W10 values 1, 2 or 3.
         HideWidget 18
         ChangePosition 20 18 494
         ChangeTitle 20 (GetTitle 18)
         ShowWidget 20
         # Set ActivePreviewField, 18 2 - set $FontConstruct for small, normal or large
         Set $ActivePreviewField = 18
         SendSignal 18 2
         # 101 1 - set active and inactive preview fields, change font size group popup menu label
         # Change TextField font to current ItemDraw
         SendSignal 101 1

         # Fontset operation mode
         # Fill W7 List with fontset and selected font info.
         # Match the existing font, handle missing fonts from fontset.
         SendSignal 101 4
      End
      # Set $FontConstruct for small, normal or large
      # 101 3 must be called again because of light cs 20 vs dark cs 22 TextField bug
      2 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            Set $FontConstruct = $FontMonoSmallStr
            SendSignal 101 3
         End
         If (GetValue 10) == 2 Then
         Begin
            Set $FontConstruct = $FontMonoMediumStr
            SendSignal 101 3
         End
         If (GetValue 10) == 3 Then
         Begin
            Set $FontConstruct = $FontMonoLargeStr
            SendSignal 101 3
         End
      End
End

# Preview ItemDraw widget for monospaced bold font
# Font "xft:::pixelsize=24" guarantees height of the widget
Widget 19
   Property
   Position 18 544
   Size 490 4
   Colorset 22
   Flags NoReliefString Left
   Type ItemDraw
   Title {Quick Brown Fox}
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 19 1
      End
      1 :
      Begin
         # ActivePreviewField refers to the past selected preview field here
         # until it is set to the current one.
         If $ActivePreviewField <> 19 Then
         Begin
            ShowWidget $ActivePreviewField
            # Preserve manual preview field modifications for a session
            If (GetTitle 20) <> $FontExampleText Then
            Begin
               ChangeTitle $ActivePreviewField (GetTitle 20)
            End
         End
         # Hide ItemDraw, position TextField Widget 20, change W20 title to ItemDraw
         # from W10 values 1, 2 or 3.
         HideWidget 19
         ChangePosition 20 18 544
         ChangeTitle 20 (GetTitle 19)
         ChangeColorset 19 20
         ShowWidget 20
         # Set ActivePreviewField, 19 2 - set $FontConstruct for small, normal or large
         Set $ActivePreviewField = 19
         SendSignal 19 2
         # 101 1 - set active and inactive preview fields, change font size group popup menu label
         # Change TextField font to current ItemDraw
         SendSignal 101 1

         # Fontset operation mode
         # Fill W7 List with fontset and selected font info.
         # Match the existing font, handle missing fonts from fontset.
         SendSignal 101 4
      End
      # Set $FontConstruct for small, normal or large
      # 101 3 must be called again because of light cs 20 vs dark cs 22 TextField bug
      2 :
      Begin
         If (GetValue 10) == 1 Then
         Begin
            Set $FontConstruct = $FontMonoBoldSmallStr
            SendSignal 101 3
         End
         If (GetValue 10) == 2 Then
         Begin
            Set $FontConstruct = $FontMonoBoldMediumStr
            SendSignal 101 3
         End
         If (GetValue 10) == 3 Then
         Begin
            Set $FontConstruct = $FontMonoBoldLargeStr
            SendSignal 101 3
         End
      End
End

# Mobile editable TextField widget used on positions of W15 - W19
Widget 20
   Property
   Position 18 554
   Size 490 24
   Flags NoReliefString Hidden Left
   Type TextField
   Colorset 20
   Font "xft:::pixelsize=24"
   Main
      Case message of
      SingleClic :
      Begin
         # Update values and widget colorsets
         SendSignal 101 1
      End
End

Widget 21
   Property
   Position 10 334
   Size 508 260
   Flags NoReliefString NoFocus
   Type Rectangle
   Main
      Case message of
      SingleClic :
      Begin
      End
End

#  If $FVWM_USERDIR/libexec/fontmgr.local exists, run it
Widget 22
   Property
   Position 14 604
   Size 100 20
   Flags NoReliefString
   Type CheckBox
   Font "xft:::pixelsize=14"
   Value 1
   Title { Run User Script}
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# GTK2/GTK3 (and Qt4/Qt5) font theme synchronization
Widget 23
   Property
   Position 166 604
   Size 100 30
   Flags NoReliefString
   Type CheckBox
   Value 1
   Title { Refresh GTK and QT}
   Font "xft:::pixelsize=14"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# X Resources integration
Widget 24
   Property
   Position 344 604
   Size 100 30
   Flags NoReliefString
   Type CheckBox
   Value 1
   Title { Refresh X Resources}
   Font "xft:::pixelsize=14"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 25
   Property
   Position 4 638
   Size 518 0
   Flags NoReliefString NoFocus
   Type Rectangle
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Main Save button
Widget 26
   Property
   Position 14 652
   Size 120 20
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Save ...}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 26 5
      End
      1 :
      Begin
         # (LastString) is here fontset name from the InputForm
         # act upon that and write new fontset file from the current
         # font variable values
         If (LastString) <> {Cancel} Then
         Begin
            # Sanity check for input
            Set $UserFontsetCmd = {echo '} (LastString) {' | $NSCDE_TOOLSDIR/ised -c 's/>\|<\|\/\|;\|:\|\[\|\]\|\\\|\$\|#\|%\|\&\|"\|\!\|\^\|\*\|(\|)\||\|?\| //g' -o -f -}
            Set $UserFontset = (GetOutput $UserFontsetCmd 1 1)

            If $UserFontset == {} Then
            Begin
               # Sanity check for input
               Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Warning.xpm" "$[gt.Fontset name must be defined before saving it!]"}
            End
            Else
            Begin
               # Define $UserFontsetFile - path and file, make sure fontsets directory exists
               Set $UserConfigDir = (GetOutput {echo $FVWM_USERDIR} 1 -1)
               Set $UserFontsetFile = $UserConfigDir {/fontsets/} $UserFontset {.fontset}
               Do {Exec exec mkdir -p "$[FVWM_USERDIR]/fontsets"}
   
               # Write fontset
               Do {Schedule 20 Exec exec echo 'InfoStoreAdd font.variable.normal.small "} $FontNormalSmallStr {"' > '} $UserFontsetFile {'}
               Do {Schedule 40 Exec exec echo 'InfoStoreAdd font.variable.bold.small "} $FontBoldSmallStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 60 Exec exec echo 'InfoStoreAdd font.variable.italic.small "} $FontItalicSmallStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 80 Exec exec echo 'InfoStoreAdd font.monospaced.normal.small "} $FontMonoSmallStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 100 Exec exec echo 'InfoStoreAdd font.monospaced.bold.small "} $FontMonoBoldSmallStr {"' >> '} $UserFontsetFile {'}
   
               Do {Schedule 120 Exec exec echo 'InfoStoreAdd font.variable.normal.medium "} $FontNormalMediumStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 140 Exec exec echo 'InfoStoreAdd font.variable.bold.medium "} $FontBoldMediumStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 160 Exec exec echo 'InfoStoreAdd font.variable.italic.medium "} $FontItalicMediumStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 180 Exec exec echo 'InfoStoreAdd font.monospaced.normal.medium "} $FontMonoMediumStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 200 Exec exec echo 'InfoStoreAdd font.monospaced.bold.medium "} $FontMonoBoldMediumStr {"' >> '} $UserFontsetFile {'}
   
               Do {Schedule 220 Exec exec echo 'InfoStoreAdd font.variable.normal.large "} $FontNormalLargeStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 240 Exec exec echo 'InfoStoreAdd font.variable.bold.large "} $FontBoldLargeStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 260 Exec exec echo 'InfoStoreAdd font.variable.italic.large "} $FontItalicLargeStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 280 Exec exec echo 'InfoStoreAdd font.monospaced.normal.large "} $FontMonoLargeStr {"' >> '} $UserFontsetFile {'}
               Do {Schedule 300 Exec exec echo 'InfoStoreAdd font.monospaced.bold.large "} $FontMonoBoldLargeStr {"' >> '} $UserFontsetFile {'}
   
               # Link configuration to the new fontset
               Do {Schedule 340 Exec exec ln -sf "} $UserFontsetFile {" "$[FVWM_USERDIR]/Font-$[NSCDE_FONT_DPI]dpi.fvwmgen"}
   
               # Do widget and script integrations and move to finish
               SendSignal 26 3
            End
         End
      End
      2 :
      Begin
            # 26 2 - called when selecting existing fontset
            Set $UserFontsetFile = $FontsetPath
            Do {Exec exec ln -sf "} $UserFontsetFile {" "$[FVWM_USERDIR]/Font-$[NSCDE_FONT_DPI]dpi.fvwmgen"}
            SendSignal 26 3
      End
      # Sleeps in integrations are set to allow asyncronous "Do" to write fontset file to the end
      3 :
      Begin
            # User script (if exists)
            If (GetValue 22) == 1 Then
            Begin
               Set $CheckUserCustomScriptExist = (GetOutput {ls -1 "$FVWM_USERDIR/libexec/fontmgr.local" > /dev/null 2>&1; echo $?} 1 -1)
               If $CheckUserCustomScriptExist == 0 Then
               Begin
                  Set $RunUserScriptCmd = {sleep 1; $FVWM_USERDIR/libexec/fontmgr.local "} $UserFontsetFile {"}
                  Set $RunUserScript = (GetOutput $RunUserScriptCmd 1 -1)
               End
            End

            # GTK2/GTK3, Qt5, Xsettingsd, X ...
            If (GetValue 23) == 1 Then
            Begin
               # GTK2
               Set $PrepareFontCmd = {$NSCDE_TOOLSDIR/fontmgr -T "} $FontNormalMediumStr {"}
               Set $PrepareFont = (GetOutput $PrepareFontCmd 1 -1)
               Set $Gtk2FontCmd = {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-font-name -v ' "} $PrepareFont {"' 2>&1}
               Set $Gtk2Font = (GetOutput $Gtk2FontCmd 1 -1)
               If $Gtk2Font <> {} Then
               Begin
                  Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error editing] $HOME/.gtkrc-2.0: \\\"} $Gtk2Font {\\\""}
               End

               # GTK3
               Set $Gtk3FontCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-font-name -v "} $PrepareFont {" 2>&1}
               Set $Gtk3Font = (GetOutput $Gtk3FontCmd 1 -1)
               If $Gtk3Font <> {} Then
               Begin
                  Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error editing] $HOME/.config/gtk-3.0/settings.ini: \\\"} $Gtk3Font {\\\""}
               End

               # Qt5 "general" font
               Set $PrepareQFontCmd = {$NSCDE_TOOLSDIR/fontmgr -Q "} $FontNormalMediumStr {"}
               Set $PrepareQFont = (GetOutput $PrepareQFontCmd 1 -1)
               Set $Qt5FontCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Fonts -k general -v '} $PrepareQFont {' 2>&1}
               Set $Qt5Font = (GetOutput $Qt5FontCmd 1 -1)
               If $Qt5Font <> {} Then
               Begin
                  Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error editing] $HOME/.config/qt5ct/qt5ct.conf: \\"} $PrepareQFont {\\""}
               End

               # Qt5 "fixed" font
               Set $PrepareQfFontCmd = {$NSCDE_TOOLSDIR/fontmgr -Q "} $FontMonoMediumStr {"}
               Set $PrepareQfFont = (GetOutput $PrepareQfFontCmd 1 -1)
               Set $Qt5fFontCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Fonts -k fixed -v '} $PrepareQfFont {' 2>&1}
               Set $Qt5fFont = (GetOutput $Qt5fFontCmd 1 -1)
               If $Qt5fFont <> {} Then
               Begin
                  Do {f_Notifier "Font Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error editing] $HOME/.config/qt5ct/qt5ct.conf: \\"} $PrepareQfFont {\\""}
               End

               # XSETTINGS Daemon Integration
               Set $XSETTINGSFILE = (GetOutput {ls -1 "$FVWM_USERDIR/Xsettingsd.conf" 2>/dev/null} -1 1)
   
               # Xsettingsd Integration - only if $FVWM_USERDIR/Xsettingsd.conf is found
               If $XSETTINGSFILE <> {} Then
               Begin
                  Set $XsettingsParamExistanceCmd = {egrep -q '^([[:space:]]+)?Gtk\/FontName[[:space:]]+' "} $XSETTINGSFILE {"; echo $?}
                  Set $XsettingsParamExistance = (GetOutput $XsettingsParamExistanceCmd 1 1)
                  If $XsettingsParamExistance == 0 Then
                  Begin
                     Set $WriteXSettingsdCmd = {$NSCDE_TOOLSDIR/ised -c 's/\(^\([[:space:]]\+\)\?Gtk\/FontName[[:space:]]\+\)\(\([[:space:]]\+\)\?\([[:space:]]\+\)\?\).*/\1\"} $PrepareFont {\"/g' -f "} $XSETTINGSFILE {"}
                  End
                  Else
                  Begin
                     Set $WriteXSettingsdCmd = {echo -ne "\n# Added by Font Style Manager\nGtk/FontName \"} $PrepareFont {\"\n" >> "} $XSETTINGSFILE {"}
                  End
                  Set $WriteXSettingsd = (GetOutput $WriteXSettingsdCmd 1 -1)

                  # Custom DPI handling
                  Set $CustomDPI = (GetOutput {echo "$XFT_USE_DPI"} 1 -1)
                  If $CustomDPI <> {} Then
                  Begin
                     Set $XsettingsDpiParamExistanceCmd = {egrep -q '^([[:space:]]+)?Xft\/DPI[[:space:]]+' "} $XSETTINGSFILE {"; echo $?}
                     Set $XsettingsDpiParamExistance = (GetOutput $XsettingsDpiParamExistanceCmd 1 1)
                     If $XsettingsDpiParamExistance == 0 Then
                     Begin
                        Set $WriteXSettingsdDpiCmd = {$NSCDE_TOOLSDIR/ised -c 's/\(^\([[:space:]]\+\)\?Xft\/DPI[[:space:]]\+\)\(\([[:space:]]\+\)\?\([[:space:]]\+\)\?\).*/\1} (Mult $CustomDPI 1024) {/g' -f "} $XSETTINGSFILE {"}
                     End
                     Else
                     Begin
                        Set $WriteXSettingsdDpiCmd = {echo -ne "\n# Added by Font Style Manager\nXft/DPI } (Mult $CustomDPI 1024) {\n" >> "} $XSETTINGSFILE {"}
                     End
                     Set $WriteXSettingsdDpi = (GetOutput $WriteXSettingsdDpiCmd 1 -1)
                  End
               End
            End

            # X resources
            If (GetValue 24) == 1 Then
            Begin
               # Wait a second for $UserFontsetFile to be written ... a race.
               Set $DoXresourcesCmd = {sleep 1; $NSCDE_TOOLSDIR/fontmgr -X "} $UserFontsetFile {" > "$FVWM_USERDIR/Xdefaults.fontdefs"}
               Set $DoXresources = (GetOutput $DoXresourcesCmd 1 -1)
               Set $DoMiscXCmd = {sleep 1; $NSCDE_TOOLSDIR/fontmgr -M '} $FontNormalMediumStr {'}
               Set $DoXMiscX = (GetOutput $DoMiscXCmd 1 -1)
               Do {Test (EnvMatch infostore.nscde_use_rofi 1, F $[FVWM_USERDIR]/NsCDE.rasi) Exec exec rm -f $[FVWM_USERDIR]/NsCDE.rasi}
            End

            # Spawn ChoiceForm to quit after saving changes
            Set $QUITARG = {ChoiceForm "$[gt.Do you want to restart NsCDE with new font properties now?]" "$[gt.Yes]" "$[gt.No]" "$[gt.User Action Required]"}
            Set $QUITFORM = (LaunchScript $QUITARG )
            Set $QuitStarted = 1
            SendSignal 26 4
      End
      4 :
      Begin
         # Finish
         If (LastString) == {Go} Then
         Begin
            Do {Exec exec /bin/ksh93 -c "cd $[HOME]; xrdb -remove; xrdb -cpp /usr/bin/cpp < .NsCDE/Xdefaults"}
            Do {Test (EnvIsSet XFT_USE_DPI) SetEnv NSCDE_FONT_DPI $[XFT_USE_DPI]}
            # Restart NsCDE here, give it a delay, not to kill "Do" until it is executed
            Do {Schedule 380 Restart}
            Quit
         End
         If (LastString) == {Cancel} Then
         Begin
            # On cancel, simply quit.
            Quit
         End
      End
      5 :
      Begin
         If $OperationMode == 1 Then
         Begin
            # Spawn InputForm, suggest new fontset name "Custom"
            Set $ARG = {InputForm "$[gt.Enter New Fontset Name:]" "Custom"}
            Set $INPUTFORM = (LaunchScript $ARG )
         End
         If $OperationMode == 2 Then
         Begin
            # For existing fontset selection, skip 26 1, go to 26 2
            SendSignal 26 2
         End
      End
End

# Bail out - main cancel button which can be called any time
Widget 27
   Property
   Position 202 652
   Size 120 20
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Cancel}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 27 1
      End
      1 :
      Begin
         Quit
      End
End

# Help button
Widget 28
   Property
   Position 392 652
   Size 120 20
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Help}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 28 1
      End
      1 :
      Begin
         Do {f_DisplayURL "$[gt.Font Style Manager]" html/NsCDE-FontMgr.html}
      End
End

# Hidden worker Widget 101 and its routines
# Called from W15 - W19 and others, also workarounds bug
# when cs #20 is light and cs #22 dark
Widget 101
   Property
   Position 18 564
   Size 490 48
   Flags NoReliefString NoFocus Hidden
   Type PushButton
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
      # 101 1 - set active and inactive preview fields, change font size group popup menu label
      # Change TextField font to current ItemDraw
      1 :
      Begin
         # Variable Regular
         If $ActivePreviewField == 15 Then
         Begin
            ChangeValue 12 1
            ChangeColorset 16 22
            ChangeColorset 17 22
            ChangeColorset 18 22
            ChangeColorset 19 22
            ChangeColorset 15 20
            If (GetValue 10) == 1 Then
            Begin
               ChangeFont 20 $FontNormalSmallStr
            End
            If (GetValue 10) == 2 Then
            Begin
               ChangeFont 20 $FontNormalMediumStr
            End
            If (GetValue 10) == 3 Then
            Begin
               ChangeFont 20 $FontNormalLargeStr
            End
         End
         # Variable Bold
         If $ActivePreviewField == 16 Then
         Begin
            ChangeValue 12 2
            ChangeColorset 15 22
            ChangeColorset 17 22
            ChangeColorset 18 22
            ChangeColorset 19 22
            ChangeColorset 16 20
            If (GetValue 10) == 1 Then
            Begin
               ChangeFont 20 $FontBoldSmallStr
            End
            If (GetValue 10) == 2 Then
            Begin
               ChangeFont 20 $FontBoldMediumStr
            End
            If (GetValue 10) == 3 Then
            Begin
               ChangeFont 20 $FontBoldLargeStr
            End
         End
         # Variable Italic
         If $ActivePreviewField == 17 Then
         Begin
            ChangeValue 12 3
            ChangeColorset 15 22
            ChangeColorset 16 22
            ChangeColorset 18 22
            ChangeColorset 19 22
            ChangeColorset 17 20
            If (GetValue 10) == 1 Then
            Begin
               ChangeFont 20 $FontItalicSmallStr
            End
            If (GetValue 10) == 2 Then
            Begin
               ChangeFont 20 $FontItalicMediumStr
            End
            If (GetValue 10) == 3 Then
            Begin
               ChangeFont 20 $FontItalicLargeStr
            End
         End
         # Monospaced Regular
         If $ActivePreviewField == 18 Then
         Begin
            ChangeValue 12 4
            ChangeColorset 15 22
            ChangeColorset 16 22
            ChangeColorset 17 22
            ChangeColorset 19 22
            ChangeColorset 18 20
            If (GetValue 10) == 1 Then
            Begin
               ChangeFont 20 $FontMonoSmallStr
            End
            If (GetValue 10) == 2 Then
            Begin
               ChangeFont 20 $FontMonoMediumStr
            End
            If (GetValue 10) == 3 Then
            Begin
               ChangeFont 20 $FontMonoLargeStr
            End
         End
         # Monospaced Bold
         If $ActivePreviewField == 19 Then
         Begin
            ChangeValue 12 5
            ChangeColorset 15 22
            ChangeColorset 16 22
            ChangeColorset 17 22
            ChangeColorset 18 22
            ChangeColorset 19 20
            If (GetValue 10) == 1 Then
            Begin
               ChangeFont 20 $FontMonoBoldSmallStr
            End
            If (GetValue 10) == 2 Then
            Begin
               ChangeFont 20 $FontMonoBoldMediumStr
            End
            If (GetValue 10) == 3 Then
            Begin
               ChangeFont 20 $FontMonoBoldLargeStr
            End
         End
      End
   2 :
   Begin
      # This is used for setting initial value on start.
      # 12 1 - Font Style Group to Regular
      # 15 1 - Select Variable Normal Font Preview Field
      ChangeValue 12 1
      SendSignal 15 1
   End
   3 :
   Begin
      # Split and parse font, in manual font selection, change
      # font list name, style list name and size
      Set $SplitFontStrCmd = {$NSCDE_TOOLSDIR/fontmgr -r '} $FontConstruct {'}
      Set $FontNameNum = (GetOutput $SplitFontStrCmd 1 -1)
      Set $FontStyleNum = (GetOutput $SplitFontStrCmd 2 -1)
      Set $FontSizeNum = (Add (GetOutput $SplitFontStrCmd 3 -1) -3)
      Set $FontName = (GetOutput $SplitFontStrCmd 4 -1)
      Set $FontStyle = (GetOutput $SplitFontStrCmd 5 -1)
   
      # Refresh style list menu variables
      Set $StyleListMenuCmd = {$NSCDE_TOOLSDIR/fontmgr -G menu -g '} $FontName {'}
      Set $StyleListMenu = (GetOutput $StyleListMenuCmd 1 -1)
   
      # Change font list name, style list name and size
      # Important: serves as light cs #20 vs dark cs #22 bug workaround
      If $OperationMode == 1 Then
      Begin
         ChangeValue 5 $FontNameNum
         ChangeTitle 7 $StyleListMenu
         ChangeValue 7 $FontStyleNum
         ChangeValue 14 $FontSizeNum
      End
   End
   4 :
   Begin
      # Fontset operation mode - fill info about fontset and fonts in it
      If $OperationMode == 2 Then
      Begin
         # Fill W7 List with fontset and selected font info.
         If $FontNameNum <> 0 Then
         Begin
            Set $FontsetInfo = {Fontset:|} $FontsetName {||} $FontName {|Style: } $FontStyle {|Size: } (Add $FontSizeNum 3)
         End
         Else
         Begin
            # Match the existing font, handle missing fonts from fontset.
            Set $SubstNameCmd = {$NSCDE_TOOLSDIR/fontmgr -m "} $FontName {"}
            Set $SubstName = (GetOutput $SubstNameCmd 1 -1)
            Set $SubstStyle = (GetOutput $SubstNameCmd 2 -1)
            Set $FontsetInfo = {Fontset:|} $FontsetName {||} $SubstName {|Style: } $SubstStyle {|Size: } (Add $FontSizeNum 3){|(} $Notavail {)}
         End
         ChangeTitle 7 $FontsetInfo
      End
   End
   5 :
   Begin
      # Keyboard walk up and down of font previews with Page Up and Page Down
      If (LastString) == {PreviewUp} Then
      Begin
         If $ActivePreviewField <> 15 Then
         Begin
            SendSignal (Add $ActivePreviewField -1) 1
         End
         Else
         Begin
            SendSignal 19 1
         End
      End
      If (LastString) == {PreviewDown} Then
      Begin
         If $ActivePreviewField <> 19 Then
         Begin
            SendSignal (Add $ActivePreviewField 1) 1
         End
         Else
         Begin
            SendSignal 15 1
         End
      End
   End
   6 :
   Begin
      # Keyboard walk up and down of fonts and fontsets on the list with Up and Down arrows
      If $OperationMode == 1 Then
      Begin
         # Set in the Init and W5
         Set $MaxVal = $FontTotalNum
         # 5 1
         Set $ListRoutine = 1
      End
      If $OperationMode == 2 Then
      Begin
         # Set in the W2 and W5
         Set $MaxVal = $FontsetTotalNum
         # 5 2
         Set $ListRoutine = 2
      End

      If (LastString) == {ListUp} Then
      Begin
         If (GetValue 5) <> 1 Then
         Begin
            ChangeValue 5 (Add (GetValue 5) -1)
         End
         Else
         Begin
            ChangeValue 5 $MaxVal
         End
         SendSignal 5 $ListRoutine
      End
      If (LastString) == {ListDown} Then
      Begin
         If (GetValue 5) <> $MaxVal Then
         Begin
            ChangeValue 5 (Add (GetValue 5) 1)
         End
         Else
         Begin
            ChangeValue 5 1
         End
         SendSignal 5 $ListRoutine
      End
   End
   7 :
   Begin
      # Small Medium and Large preview on the List W5
      # That is: Ctrl+S, Ctrl+M and Ctrl+L
      If (LastString) == {KeySmall} Then
      Begin
         ChangeValue 10 1
      End
      If (LastString) == {KeyMedium} Then
      Begin
         ChangeValue 10 2
      End
      If (LastString) == {KeyLarge} Then
      Begin
         ChangeValue 10 3
      End
      # Do what Widget 10 PopupMenu will do when clicked
      SendSignal 10 1
   End
   8 :
   Begin
      # Ctrl + / Ctrl - and Ctrl 0 - change size of the font
      # when $OperationMode == 1
      If $OperationMode == 1 Then
      Begin
         If (LastString) == {KeyIncrease} Then
         Begin
            # Value 23 is size 26
            If (GetValue 14) < 23 Then
            Begin
               ChangeValue 14 (Add (GetValue 14) 1)
            End
         End
         If (LastString) == {KeyDecrease} Then
         Begin
            # Value 1 is size 4
            If (GetValue 14) <> 1 Then
            Begin
               ChangeValue 14 (Add (GetValue 14) -1)
            End
         End
         # Ctrl + Equal - set default size in the previewed group
         If (LastString) == {KeyDefSize} Then
         Begin
            If (GetValue 10) == 1 Then
            Begin
               # Value 7 is size 10
               ChangeValue 14 7
            End
            If (GetValue 10) == 2 Then
            Begin
               # Value 8 is size 11
               ChangeValue 14 8
            End
            If (GetValue 10) == 3 Then
            Begin
               # Value 9 is size 12
               ChangeValue 14 9
            End
         End
         # Do what Widget 14 PopupMenu will do when clicked
         SendSignal 5 1
         SendSignal 14 1
      End
   End
   9 :
   Begin
      # Flip flop operation mode with Ctrl F
      If (LastString) == {KeyFlipOprMode} Then
      Begin
         If (GetValue 2) == 0 Then
         Begin
            ChangeValue 2 1
            SendSignal 2 1
         End
         Else
         Begin
            ChangeValue 2 0
            SendSignal 2 1
         End
      End
   End
End

