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

UseGettext {$NSCDE_ROOT/share/locale;NsCDE}
WindowLocaleTitle {User Input Required}
WindowSize 320 124
Colorset 22

Init
Begin
   Set $TaskText = (GetScriptArgument 1)
   If $TaskText == {} Then
   Begin
      ChangeTitle 1 {Enter Required Parameter:}
   End
   Else
   Begin
      ChangeTitle 1 $TaskText
   End

   Set $DefaultText = (GetScriptArgument 2)
   If $DefaultText <> {} Then
   Begin
      ChangeTitle 2 $DefaultText
      ChangeValue 2 228
   End

   Set $WindowTitle = (GetScriptArgument 3)
   If $WindowTitle <> {} Then
   Begin
      ChangeWindowTitle $WindowTitle
   End

   # Can be "stdalone" or anything other for script father/child interaction
   Set $OpMode = (GetScriptArgument 4)

   Set $OkAction = (GetScriptArgument 5)

   Set $CancelAction = (GetScriptArgument 6)

   Set $BtnFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 15} 1 -1)
   ChangeFont 1 $BtnFont
   ChangeFont 2 $BtnFont
   ChangeFont 4 $BtnFont
   ChangeFont 5 $BtnFont

   WarpPointer 2
   Key Escape A 5 1 {Quit}
   Key Return A 4 1 {Go}

   # Nasty workaround because ForeColor of the TextField
   # widget is not applied and global value is used anyway.
   # How it works: if wanted Colorset is applied with
   # ChangeColorset to (any?) other widget after initialization
   # of the script, colorset foreground color will be properly
   # applied to TextField widget too. Even if fake widget is
   # hidden, this workaround still works as it should. 
   # We define hidden PushButton widhet on the end of the script
   # and send string "workaround" to routine 1 of the TextField
   # widget ("1 : " can be attached to any widget in fact ...).
   # This routine than changes the colorset of the hidden
   # PushButton widget, and this then triggers change in buggy
   # TextField to be applied.
   # This bug can be seen when default colorset for the script has
   # different foreground color than colorset applied to the
   # TextField widget. Another possible workaround is to define
   # globally back/fore/sh/hi colors for the script instead of
   # (or after definition) of a colorset, but this is unflexible,
   # since script background cannot be changed dinamically or
   # from outside of the script as colorset functionality allows.
   Do {Schedule 50 SendToModule InputForm SendString 10 1 workaround}
   Do {Schedule 250 SendToModule InputForm SendString 10 1 workaround}
   Do {Schedule 350 SendToModule InputForm SendString 10 1 workaround}
End

Widget 1
   Property
   Size 0 0
   Position 72 6
   Type ItemDraw
   Flags NoReliefString NoFocus Left
   Title {Enter Required Parameter: }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 2
   Property
   Size 230 20
   Position 74 32
   Type TextField
   Flags NoReliefString
   Title {}
   Font "xft:::pixelsize=15"
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
      1 :
      Begin
      End
End

Widget 3
   Property
   Size 36 32
   Position 12 24
   Type ItemDraw
   Flags NoReliefString NoFocus
   Title {}
   Icon NsCDE/Question.xpm
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 4
   Property
   Size 96 0
   Position 16 86
   Type PushButton
   LocaleTitle {OK}
   Font "xft:::pixelsize=15"
   Flags NoReliefString Center
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 4 1
      End
   1 :
   Begin
      If $OpMode == {stdalone} Then
      Begin
         Do {InfoStoreAdd inputform.text "} (GetTitle 2) {"}
         Do {Schedule 1250 } $OkAction
         Do {Schedule 3000 InfoStoreRemove inputform.text}
      End
      Else
      Begin
         SendToScript (GetScriptFather) (GetTitle 2)
      End
      SendSignal 4 2
   End
   2 :
   Begin
      Quit
   End
End

Widget 5
   Property
   Size 96 0
   Position 208 86
   Type PushButton
   LocaleTitle {Dismiss}
   Font "xft:::pixelsize=15"
   Flags NoReliefString Center
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 5 1
      End
   1 :
   Begin
      If $OpMode == {stdalone} Then
      Begin
         Do $CancelAction
      End
      Else
      Begin
         SendToScript (GetScriptFather) {Cancel}
      End
      SendSignal 5 2
   End
   2 :
   Begin
      Quit
   End
End

Widget 6
   Property
   Size 312 0
   Position 4 74
   Type Rectangle
   Flags NoReliefString NoFocus
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Nasty workaround because ForeColor of the TextField
# widget is not applied and global value is used anyway.
# See end of the Init procedure for explanation.
Widget 10
   Property
   Size 40 10
   Position 10 10
   Type PushButton
   Flags NoReliefString NoFocus Hidden
   Title {XXXXXXXXXXXXXXXXXXXXXXXXXXX}
   Main
      Case message of
      1 :
      Begin
         If (LastString) == {workaround} Then
         Begin
            ChangeColorset 10 20
            ChangeColorset 2 20
         End
      End
End

