# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#-----------------------------------------------------------------------------
# Copyright 2000, Olivier Chapuis
#-----------------------------------------------------------------------------


WindowTitle {FVWM Themes: Component Properties}
WindowSize 320 300
Font		-adobe-helvetica-bold-r-*-*-12-*

Init
Begin

    # --------------------------------------- Arguments
    Set $i = 1
    Set $arg = (GetScriptArgument $i)
    While $arg <> {} Do
    Begin
	Set $j = (Add $i 1)
	If $arg == {--session} Then
	    Set $Session = (GetScriptArgument $j)
	If $arg == {--viewer-colorset} Then
	    Set $ViewerColorset = (GetScriptArgument $j)
	If $arg == {--text-colorset} Then
	    Set $TextColorset = (GetScriptArgument $j)
	If $arg == {--icon-colorset} Then
	    Set $IconColorset = (GetScriptArgument $j)
	If $arg == {--com-pid} Then
	    Set $pid = (GetScriptArgument $j)
	If $arg == {--component} Then
	    Set $MainComponent = (GetScriptArgument $j)
	If $arg == {--theme} Then
	    Set $MainTheme = (GetScriptArgument $j)
	If $arg == {--lang} Then
	    Set $Lang = (GetScriptArgument $j)
	Set $i = (Add $i 2)
	Set $arg = (GetScriptArgument $i)
    End

    If $TextColorset <> {} Then
    Begin
	ChangeColorset 5 $TextColorset
    End

    #Set $Lang = {en}
    #Set $Lang = {ru}
    # ------------------------------- Internationalization. 
    If $Lang == {} Then
    Begin
	Set $cmd = {echo "$LANG" | cut -c1-2}
	Set $Lang = (GetOutput $cmd 1 -1)
    End
    If $Lang == {} Then
	Set $Lang = {C}

    Set $msg = {}
    Set $id = {}
    Set $cmd = {fvwm-themes-script --get-msg FvwmScript-ComponentProperties --lang }$Lang
    Set $MSG = (GetOutput $cmd 1 -1)
    Set $index = 0
    Set $notdone = 1
    While $notdone == 1 Do
    Begin
	Set $index = (Add $index 1)
	Set $id = (StrCopy $MSG $index (Add $index 11))
	Set $index = (Add $index 12)
	Set $tmp = (StrCopy $MSG $index (Add $index 3))
	Set $index = (Add $index 4)
	Set $pos = (Add $index $tmp)
	Set $msg = (StrCopy $MSG $index $pos)
	Set $index = (Add $index $tmp)
	#Do {Echo id:}$id{:msg:}$msg{:}

	If $index > 9999 Then
	    Set $notdone = 0
	If $id == {END         } Then
	    Set $notdone = 0
	If $id == {} Then
	    Set $notdone = 0

	If $id == {SendModif   } Then
	    ChangeTitle 6 $msg
	If $id == {Set         } Then
	    ChangeTitle 97 $msg
	If $id == {SetQuit     } Then
	    ChangeTitle 98 $msg
	If $id == {Quit        } Then
	    ChangeTitle 99 $msg
	If $id == {for         } Then
	    Set $l_for = $msg
	If $id == {ChangeFont  } Then
	    Set $ChangeFont = $msg
	If $id == {SelFont     } Then
	    Set $SelFont = $msg
	If $id == {ShadeFont   } Then
	    Set $ShadeFont = $msg
	If $id == {FixedFont   } Then
	    Set $FixedFont = $msg
	End

    If $ChangeFont == 1 Then
    Begin
	ChangeFont 1 $SelFont
	ChangeFont 2 $SelFont
	ChangeFont 3 $SelFont
	ChangeFont 5 $FixedFont
	ChangeFont 6 $SelFont
	ChangeFont 97 $SelFont
	ChangeFont 98 $SelFont
	ChangeFont 99 $SelFont
    End

    # ------------------------------------- com and init
    # to send fvwm-themes-com command
    Set $SendMsgAndGet = {fvwm-themes-com --name config-}$pid{ --lock-and-get --message=}
    Set $SendMsgAndGetBuff = {fvwm-themes-com --name config-}$pid{ --lock-and-get --buffer-name config-bis-}$pid{ --message=}
    Set $SendMsg = {fvwm-themes-com --name config-}$pid{ --message=}
    Set $GetLine = {fvwm-themes-com --name config-}$pid{ --buffer-name config-bis-}$pid{ --get-buffer --line=}	
     # Get all the options
    Set $cmd = $SendMsgAndGetBuff{"options }$MainComponent{ }$MainTheme{" --line 1}
    Set $NbrOfOptions = (GetOutput $cmd 1 -1)
    Set $cmd = $GetLine{2}
    Set $Type = (GetOutput $cmd 1 -1)
    Set $tmp = $Type{ }$l_for{ }$MainComponent{@}$MainTheme
    ChangeTitle 1 $tmp
    Set $cmd = $GetLine{3 --clear-buffer}
    Set $Options = (GetOutput $cmd 1 -1)
    If $NbrOfOptions == 1 Then
    Begin
	HideWidget 3
	ChangeTitle 2 $Options
    End
    Else
    Begin
	HideWidget 2
	ChangeTitle 3 $Options
    End

    # Get the "current" options List
    Set $CurrentOptionsIndex = 1
    Set $UpdateList = 1

    # the selected option
    Set $OptionIndex = 0

    Set $SendUpdateMsg = 0
    Set $Father = (GetScriptFather)
    Set $Quit = 0
    Set $CountQuit = 0
    HideWidget 6
End

# ---------------------------------------------------------------------------
#
# Periodic Task
#
# ---------------------------------------------------------------------------

PeriodicTasks
Begin

    If $Quit == 1 Then
    Begin
	If $CountQuit == 0 Then
	Begin
	    HideWidget 1
	    HideWidget 2
	    HideWidget 3
	    #HideWidget 4
	    HideWidget 5
	    ShowWidget 6
	End
	Set $CountQuit = (Add $CountQuit 1)
	If $CountQuit == 20 Then
	    Quit
    End

    Set $MSG = (ReceivFromScript $Father)
    If $MSG <> {No message} Then
    Begin
	If $MSG == {exit} Then
	    Quit
	If $MSG == {update} Then
	    Set $UpdateList = 1
    End

    If $UpdateList == 1 Then
    Begin
	Set $UpdateList = 0
	Set $cmd = $SendMsgAndGet{"options-variants }$MainComponent{ }$MainTheme{ }$CurrentOptionsIndex{"}
	Set $CurrentVariants = (GetOutput $cmd 1 -1)
	ChangeTitle 5 $CurrentVariants
    End

    # better to send here
    If $SendUpdateMsg == 1 Then
    Begin
	Set $SendUpdateMsg = 0
	SendToScript $Father {update}
    End
    If $SendUpdateQuit == 1 Then
    Begin
	Set $SendUpdateQuit = 0
	SendToScript $Father {updatequit}
	Set $Quit = 1
    End
    If $SendQuit == 1 Then
    Begin
	Set $SendQuit = 0
	SendToScript $Father {quit}
	Set $Quit = 1
    End
End

# ---------------------------------------------------------------------------
#
# Now the widgets
#
# ---------------------------------------------------------------------------

Widget 1
Property
    Flags NoReliefString
    Position 20 5
    Size 280 20 
    Type ItemDraw
    Title {}
Main
Case message of
    SingleClic :
    Begin
    End
End

Widget 2
Property
    Flags NoReliefString
    Position 20 35
    Size 280 20 
    Type ItemDraw
    Title {}
Main
Case message of
    SingleClic :
    Begin
    End
End

Widget 3
Property
    Flags NoReliefString
    Position 20 35
    Size 240 20 
    Type PopupMenu
    Title {Test Option                          }
Main
Case message of
SingleClic :
 Begin
    Set $value = (GetValue 3)
    If $value <> $CurrentOptionsIndex Then
    Begin
	Set $CurrentOptionsIndex = $value
	Set $UpdateList = 1
	Set $OptionIndex = 0
	ChangeValue 5 0
    End
 End
End

Widget 5
Property
    Flags NoReliefString
    Position 20 65
    Size 280 195 
    Type List
    Font Fixed
    Title {}
Main
Case message of
SingleClic :
 Begin
    
 End
End

Widget 6
Property
    Flags NoReliefString
    Position 1 35
    Size 318 20 
    Type ItemDraw
    Title {}
Main
Case message of
    SingleClic :
    Begin
    End
End

Widget 97
Property
    Flags NoReliefString
    Position 10 270
    Size 90 20
    Type PushButton
    Title {}
Main
Case message of
 SingleClic :
 Begin
    Set $OptionIndex = (GetValue 5)
    If $OptionIndex <> 0 Then 
    Begin
	Set $cmd = $SendMsgAndGet{"set-options }$MainComponent{ }$MainTheme{ }$CurrentOptionsIndex{ }$OptionIndex{"}
	Set $dummy = (GetOutput $cmd 1 -1)
	Set $UpdateList = 1
	Set $SendUpdateMsg = 1
    End
    
 End
End

Widget 98
Property
    Flags NoReliefString
    Position 115 270
    Size 90 20
    Type PushButton
    Title {}
Main
 Case message of
  SingleClic :
  Begin
    Set $OptionIndex = (GetValue 5)
    If $OptionIndex <> 0 Then 
    Begin
	Set $cmd = $SendMsgAndGet{"set-options }$MainComponent{ }$MainTheme{ }$CurrentOptionsIndex{ }$OptionIndex{"}
	Set $dummy = (GetOutput $cmd 1 -1)
    End
    #SendToScript $Father {updatequit}
    #Quit
    Set $SendUpdateQuit = 1
  End
End

Widget 99
Property
    Flags NoReliefString
 Position 220 270
 Size 90 20
 Type PushButton
 Title {}
Main
 Case message of
  SingleClic :
  Begin
    #SendToScript $Father {quit}
    #Quit
    Set $SendQuit = 1
  End
End
