# BaseWBCanvas.itcl 
# 
#       Interface between application code and the itcl runtime environment for
#       tcl applets.
#       
#       An itcl applet inherits this class which makes a number of methods
#       available from the actual application code.
#       
#       To be safe the code should run in a safe interpreter with all
#       methods and variables in this base class aliased.
# 
#  Copyright (c) 2007 Mats Bengtsson
#  
#   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 3 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, see <http://www.gnu.org/licenses/>.
#   
# $Id: BaseWBCanvas.itcl,v 1.6 2007-07-19 06:28:18 matben Exp $

class BaseWBCanvas {
	
    # ------------------
    # Class constructor.
    # ------------------

    protected {
	constructor {args} {}
	destructor {}
    }

    # ------------------------
    # Protected class methods.
    # ------------------------

    protected {
	method NewUtag {}
	method GetUtag {id}
	method NewImportAnchor
	method RegisterCanvasClassBinds {name canvasBindList}
	method DeregisterCanvasClassBinds {name}
	method RegisterCanvasInstBinds {name canvasBindList}
	method DeregisterCanvasInstBinds {{name {}}}
	method CancelBox {}
	method CreateItem {args}
	method ItemConfigure {id args}
	method InitMoveCurrent {x y}
	method DragMoveCurrent {x y {modifier {}}}
	method FinalMoveCurrent {x y}
	method FinalMoveCurrentGrid {x y grid}
	method AddUndo {undo redo}
	method DeleteCurrent {}
	method AddGarbageImages {name args}
	method Command {cmd {where all}}
	method CommandList {cmdList {where all}}
	method GenCommand {cmd {where all}}
    }

    # -------------------------
    # Protected static methods.
    # -------------------------

    protected {
	proc GetThis {key}
    }
    
    # ---------------------------
    # Private class data members.
    # ---------------------------
    
    protected {
	variable tkCanvas
    }
}

body BaseWBCanvas::constructor {args} {
    
    if {[llength $args] != 1} {
	return
    }
    set w [lindex $args 0]
    set tkCanvas $w
}

body BaseWBCanvas::destructor {} {

}

body BaseWBCanvas::NewUtag {} {
    return [::CanvasUtils::NewUtag]
}

body BaseWBCanvas::NewImportAnchor {} {
    return [::CanvasUtils::NewImportAnchor $tkCanvas]
}

body BaseWBCanvas::RegisterCanvasClassBinds {name canvasBindList} {
    ::WB::RegisterCanvasClassBinds $name $canvasBindList
}

body BaseWBCanvas::RegisterCanvasInstBinds {name canvasBindList} {
    ::WB::RegisterCanvasInstBinds $tkCanvas $name $canvasBindList
}

body BaseWBCanvas::DeregisterCanvasInstBinds {{name {}}} {
    ::Plugins::DeregisterCanvasInstBinds $tkCanvas $name
}

body BaseWBCanvas::CancelBox {} {
    ::CanvasDraw::CancelBox $tkCanvas
}

body BaseWBCanvas::CreateItem {args} {
    eval {::CanvasUtils::CreateItem $tkCanvas} $args
}

body BaseWBCanvas::ItemConfigure {id args} {
    eval {::CanvasUtils::ItemConfigure $tkCanvas $id} $args
}

body BaseWBCanvas::GetUtag {id} {
    return [::CanvasUtils::GetUtag $tkCanvas $id]
}

body BaseWBCanvas::GetThis {key} {
    global  this    
    return $this($key)
}

body BaseWBCanvas::InitMoveCurrent {x y} {
    ::CanvasDraw::InitMoveCurrent $tkCanvas $x $y
}

body BaseWBCanvas::DragMoveCurrent {x y {modifier {}}} {
    ::CanvasDraw::DragMoveCurrent $tkCanvas $x $y $modifier
}

body BaseWBCanvas::FinalMoveCurrent {x y} {   
    ::CanvasDraw::FinalMoveCurrent $tkCanvas $x $y
}

body BaseWBCanvas::FinalMoveCurrentGrid {x y grid} {   
    ::CanvasDraw::FinalMoveCurrentGrid $tkCanvas $x $y $grid
}

body BaseWBCanvas::AddUndo {undo redo} {
    undo::add [::WB::GetUndoToken $tkCanvas] $undo $redo
}

body BaseWBCanvas::DeleteCurrent {} {
    ::CanvasDraw::DeleteCurrent $tkCanvas
}

body BaseWBCanvas::AddGarbageImages {name args} {
    eval {::CanvasDraw::AddGarbageImages $name} $args
}

body BaseWBCanvas::Command {cmd {where all}} {
    set w [winfo toplevel $tkCanvas]
    ::CanvasUtils::Command $w $cmd $where
}

body BaseWBCanvas::CommandList {cmdList {where all}} {
    set w [winfo toplevel $tkCanvas]
    ::CanvasUtils::CommandList $w $cmdList $where
}

body BaseWBCanvas::GenCommand {cmd {where all}} {
    set w [winfo toplevel $tkCanvas]
    ::CanvasUtils::GenCommand $w $cmd $where
}





