📄 scrolledtext.itk
字号:
## Scrolledtext# ----------------------------------------------------------------------# Implements a scrolled text widget with additional options to manage# the vertical scrollbar. This includes options to control the method# in which the scrollbar is displayed, i.e. statically or dynamically.# Options also exist for adding a label to the scrolled text area and# controlling its position. Import/export of methods are provided for # file I/O.## ----------------------------------------------------------------------# AUTHOR: Mark L. Ulferts EMAIL: mulferts@austin.dsccc.com## @(#) $Id: scrolledtext.itk,v 1.5 2002/09/10 03:05:25 smithc Exp $# ----------------------------------------------------------------------# Copyright (c) 1995 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software # and its documentation for any purpose, and without fee or written # agreement with DSC, is hereby granted, provided that the above copyright # notice appears in all copies and that both the copyright notice and # warranty disclaimer below appear in supporting documentation, and that # the names of DSC Technologies Corporation or DSC Communications # Corporation not be used in advertising or publicity pertaining to the # software without specific, written prior permission.# # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE.# ======================================================================## Usual options.#itk::usual Scrolledtext { keep -activebackground -activerelief -background -borderwidth -cursor \ -elementborderwidth -foreground -highlightcolor -highlightthickness \ -insertbackground -insertborderwidth -insertofftime -insertontime \ -insertwidth -jump -labelfont -selectbackground -selectborderwidth \ -selectforeground -textbackground -textfont -troughcolor }# ------------------------------------------------------------------# SCROLLEDTEXT# ------------------------------------------------------------------itcl::class iwidgets::Scrolledtext { inherit iwidgets::Scrolledwidget constructor {args} {} destructor {} itk_option define -width width Width 0 itk_option define -height height Height 0 itk_option define -visibleitems visibleItems VisibleItems 80x24 public method bbox {index} public method childsite {} public method clear {} public method import {filename {index end}} public method export {filename} public method compare {index1 op index2} public method debug {args} public method delete {first {last {}}} public method dlineinfo {index} public method get {index1 {index2 {}}} public method image {option args} public method index {index} public method insert {args} public method mark {option args} public method scan {option args} public method search {args} public method see {index} public method tag {option args} public method window {option args} public method xview {args} public method yview {args} }## Provide a lowercased access method for the Scrolledtext class.# proc ::iwidgets::scrolledtext {pathName args} { uplevel ::iwidgets::Scrolledtext $pathName $args}## Use option database to override default resources of base classes.#option add *Scrolledtext.labelPos n widgetDefault# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------itcl::body iwidgets::Scrolledtext::constructor {args} { # # Our -width and -height options are slightly different than # those implemented by our base class, so we're going to # remove them and redefine our own. # itk_option remove iwidgets::Scrolledwidget::width itk_option remove iwidgets::Scrolledwidget::height # # Create a clipping frame which will provide the border for # relief display. # itk_component add clipper { frame $itk_interior.clipper } { usual keep -borderwidth -relief -highlightthickness -highlightcolor rename -highlightbackground -background background Background } grid $itk_component(clipper) -row 0 -column 0 -sticky nsew grid rowconfigure $_interior 0 -weight 1 grid columnconfigure $_interior 0 -weight 1 # # Create the text area. # itk_component add text { text $itk_component(clipper).text \ -width 1 -height 1 \ -xscrollcommand \ [itcl::code $this _scrollWidget $itk_interior.horizsb] \ -yscrollcommand \ [itcl::code $this _scrollWidget $itk_interior.vertsb] \ -borderwidth 0 -highlightthickness 0 } { usual ignore -highlightthickness -highlightcolor -borderwidth keep -exportselection -padx -pady -setgrid \ -spacing1 -spacing2 -spacing3 -state -tabs -wrap rename -font -textfont textFont Font rename -background -textbackground textBackground Background } grid $itk_component(text) -row 0 -column 0 -sticky nsew grid rowconfigure $itk_component(clipper) 0 -weight 1 grid columnconfigure $itk_component(clipper) 0 -weight 1 # # Configure the command on the vertical scroll bar in the base class. # $itk_component(vertsb) configure \ -command [itcl::code $itk_component(text) yview] # # Configure the command on the horizontal scroll bar in the base class. # $itk_component(horizsb) configure \ -command [itcl::code $itk_component(text) xview] # # Initialize the widget based on the command line options. # eval itk_initialize $args}# ------------------------------------------------------------------# DESTURCTOR# ------------------------------------------------------------------itcl::body iwidgets::Scrolledtext::destructor {} {}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -width## Specifies the width of the scrolled text as an entire unit.# The value may be specified in any of the forms acceptable to # Tk_GetPixels. Any additional space needed to display the other# components such as labels, margins, and scrollbars force the text# to be compressed. A value of zero along with the same value for # the height causes the value given for the visibleitems option # to be applied which administers geometry constraints in a different# manner.# ------------------------------------------------------------------itcl::configbody iwidgets::Scrolledtext::width { if {$itk_option(-width) != 0} { set shell [lindex [grid info $itk_component(clipper)] 1] # # Due to a bug in the tk4.2 grid, we have to check the # propagation before setting it. Setting it to the same # value it already is will cause it to toggle. # if {[grid propagate $shell]} { grid propagate $shell no } $itk_component(text) configure -width 1 $shell configure \ -width [winfo pixels $shell $itk_option(-width)] } else { configure -visibleitems $itk_option(-visibleitems) }}# ------------------------------------------------------------------# OPTION: -height## Specifies the height of the scrolled text as an entire unit.# The value may be specified in any of the forms acceptable to # Tk_GetPixels. Any additional space needed to display the other# components such as labels, margins, and scrollbars force the text# to be compressed. A value of zero along with the same value for # the width causes the value given for the visibleitems option # to be applied which administers geometry constraints in a different# manner.# ------------------------------------------------------------------itcl::configbody iwidgets::Scrolledtext::height { if {$itk_option(-height) != 0} { set shell [lindex [grid info $itk_component(clipper)] 1] # # Due to a bug in the tk4.2 grid, we have to check the # propagation before setting it. Setting it to the same # value it already is will cause it to toggle. # if {[grid propagate $shell]} { grid propagate $shell no } $itk_component(text) configure -height 1 $shell configure \ -height [winfo pixels $shell $itk_option(-height)] } else { configure -visibleitems $itk_option(-visibleitems) }}# ------------------------------------------------------------------# OPTION: -visibleitems## Specified the widthxheight in characters and lines for the text.# This option is only administered if the width and height options# are both set to zero, otherwise they take precedence. With the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -