# $Id: text.wgt,v 1.8 2002/03/09 21:55:30 cgavin Exp $

##############################################################################
#
# Visual TCL - A cross-platform application development environment
#
# Copyright (C) 2001 Damon Courtney
#
# Description file for Tk Widget
#
# This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.

##############################################################################
#

Class       Custom
Lib         ttk

Icon        ../lib/Widgets/ttk/custom-small.png

CreateCmd  vTcl::widgets::ttk::custom::CreateCmd

#InsertCmd   vTcl::widgets::ttk::custom::insertCmd
TreeLabel   Custom widget
#DefaultOptions  -background white -height 4 -width 10 -wrap word \
              -font \$vTcl(actual_gui_font_text_name) -foreground black \
              -highlightbackground \$vTcl(actual_gui_bg)

lappend vTcl(complex_class) Custom

#DefaultValues    -highlightbackground -highlightcolor \
                -selectbackground -selectforeground

#ClassOption    -_tooltip

#SpecialOpt -wrap        "wrap"    choice  "none char word"
#ClassOption -loadcommand                    ;# Rozen
#OptionConfigCmd -loadcommand get vTcl::widgets::ttk::texet::get_load_cmd
#OptionConfigCmd -loadcommand update vTcl::widgets::ttk::text::update_load_cmd
#OptionConfigCmd -loadcommand config vTcl::widgets::ttk::text::config_load_cmd


ClassOption    -variant
NewOption      -variant "variant" type

OptionConfigCmd -variant get    vTcl::widgets::ttk::custom::get_load_cmd
OptionConfigCmd -variant update vTcl::widgets::ttk::custom::update_load_cmd
OptionConfigCmd -variant config vTcl::widgets::ttk::custom::config_load_cmd

Function         "Fill Container"     vTcl::widgets::ttk::custom::fill_container
Function    "Set Tooltip"   vTcl::widgets::ttk::custom::setTooltip

namespace eval vTcl::widgets::ttk::custom {

    proc setTooltip {} {
        global vTcl
        vTcl:set_tooltip $vTcl(w,widget)
    }

    proc fill_container {} {
         # Rozen function to expand widget to fill container.
         set w $::vTcl(w,widget)
         vTcl:fill_container $w
    }

    proc CreateCmd {target args} {
        global vTcl
        namespace eval ::widgets::${target}::variant {}  ;# 8/26/18
        namespace eval ::widgets::${target}::options {}
        namespace eval ::widgets::${target}::save    {}
        namespace eval ::widgets::${target}.01::options {}
        namespace eval ::widgets::${target}.01::save    {}
        namespace eval ::widgets::${target}.02::options {}
        namespace eval ::widgets::${target}.02::save    {}
        namespace eval ::widgets::${target}.03::options {}
        namespace eval ::widgets::${target}.03::save    {}
#        set check [vTcl:check_parent $target]
#        if {[vTcl:check_parent $target]} {
#            return
#        }
        frame $target  -height 75 -width 125 -class Custom
        text $target.01  -background white  -foreground black \
            -font $vTcl(actual_gui_font_text_name)  -height 3 -width 10 \
            -insertborderwidth 3
        pack $target.01 -in $target -fill both -expand yes
        # Removed following line because multiple instances ended up
        # with the same name in the Python code. Don't know why it was
        # here in the first place. 10/23/10
        #vTcl:DefineAlias "$target" "Custom1" vTcl:WidgetProc "Toplevel1" 1
        $target.01 insert end "Custom\nwidget"  ;# insert caption
    }

    proc insertCmd {target} {
        global vTcl
        $target.01 configure -font $vTcl(actual_gui_font_text_name)
        $target.01 insert end "Custom\nwidget"
        # Removed following line because multiple instances ended up
        # with the same name in the Python code. Don't know why it was
        # here in the first place. 10/23/10
        #vTcl:DefineAlias "$target" "Custom1" vTcl:WidgetProc "Toplevel1" 1
    }

    proc dumpCmd {target basename} {
        global vTcl basenames classes
        set result [vTcl:dump_widget_opt $target $basename]
    }

    # procs below added by Rozen to handle the loadcommand option.
    proc get_load_cmd {target} {
        # Called by vTcl:widget:register_widget_custom in widget.tcl
        # At this point I don't know what it should return.
        global vTcl
        if {[info exist vTcl($target,-variant)]} {
            set v $vTcl($target,-variant)
        } else {
            set v ""
        }
        set vTcl(w,opt,-variant) $v

        if {![info exist ::widgets::${target}::variant]} {
            # namespace eval ::widgets::${target} {
            #     variable variant
            #     set variant $var
            # }  ;# 8/26/18
            namespace eval ::widgets::${target}:variant {}
        }
        set ::widgets::${target}::variant $v
        return [set ::widgets::${target}::variant]
    }

    proc update_load_cmd {target var} {
        global vTcl
        # Called to load the current value into the prop manager (propmgr.tcl)
        # What actually get stuffed in the Attribute Editor is
        # vTcl(w,opt,-variant)
        if {[info exist vTcl($target,-variant)]} {
            set [set var] $vTcl($target,-variant)
        } else {
            set [set $var]  ""
        }
        set ::widgets::${target}::variant $var   ;# 8/26/18
    }

    proc config_load_cmd {target var} {
        # Called when the value is changed by the prop manager.
        global vTcl
        # I should just store the var in the appropiate vTcl variable.
        regsub {\.bor[1-9]+} $target "\$top" target
        set vTcl($target,-variant) $var
        set ::widgets::${target}::ClassOption(-variant) $var
        set ::widgets::${target}::options(-variant) $var
        set ::widgets::${target}::save(-variant) [expr {$var != ""}]
        set ::widgets::${target}::variant $var   ;# 8/26/18
    }
}



