OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [tags/] [start/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [scrolledtext.itk] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Scrolledtext
3
# ----------------------------------------------------------------------
4
# Implements a scrolled text widget with additional options to manage
5
# the vertical scrollbar.  This includes options to control the method
6
# in which the scrollbar is displayed, i.e. statically or  dynamically.
7
# Options also exist for adding a label to the scrolled text area and
8
# controlling its position.  Import/export of methods are provided for
9
# file I/O.
10
#
11
# ----------------------------------------------------------------------
12
#  AUTHOR: Mark L. Ulferts              EMAIL: mulferts@austin.dsccc.com
13
#
14
#  @(#) $Id: scrolledtext.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
15
# ----------------------------------------------------------------------
16
#            Copyright (c) 1995 DSC Technologies Corporation
17
# ======================================================================
18
# Permission to use, copy, modify, distribute and license this software
19
# and its documentation for any purpose, and without fee or written
20
# agreement with DSC, is hereby granted, provided that the above copyright
21
# notice appears in all copies and that both the copyright notice and
22
# warranty disclaimer below appear in supporting documentation, and that
23
# the names of DSC Technologies Corporation or DSC Communications
24
# Corporation not be used in advertising or publicity pertaining to the
25
# software without specific, written prior permission.
26
#
27
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
28
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
29
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
30
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
31
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
32
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
33
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
34
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
35
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
36
# SOFTWARE.
37
# ======================================================================
38
 
39
#
40
# Usual options.
41
#
42
itk::usual Scrolledtext {
43
    keep -activebackground -activerelief -background -borderwidth -cursor \
44
         -elementborderwidth -foreground -highlightcolor -highlightthickness \
45
         -insertbackground -insertborderwidth -insertofftime -insertontime \
46
         -insertwidth -jump -labelfont -selectbackground -selectborderwidth \
47
         -selectforeground -textbackground -textfont -troughcolor
48
}
49
 
50
#
51
#  The default case is to have no label, so we set the default spacings
52
#  to reflect this...
53
#
54
 
55
option add *Scrolledtext.labelMargin    0      widgetDefault
56
option add *Scrolledtext.labelFont     \
57
      "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*"  widgetDefault
58
option add *Scrolledtext.labelPos       n       widgetDefault
59
option add *Scrolledtext.labelBorderWidth    0      widgetDefault
60
option add *Scrolledtext.labelRelief         groove widgetDefault
61
 
62
# ------------------------------------------------------------------
63
#                           SCROLLEDTEXT
64
# ------------------------------------------------------------------
65
class iwidgets::Scrolledtext {
66
    inherit iwidgets::Scrolledwidget
67
 
68
    constructor {args} {}
69
    destructor {}
70
 
71
    itk_option define -width width Width 0
72
    itk_option define -height height Height 0
73
    itk_option define -visibleitems visibleItems VisibleItems 80x24
74
 
75
    public method bbox {index}
76
    public method clear {}
77
    public method import {filename {index end}}
78
    public method export {filename}
79
    public method compare {index1 op index2}
80
    public method debug {args}
81
    public method delete {first {last {}}}
82
    public method dlineinfo {index}
83
    public method get {index1 {index2 {}}}
84
    public method index {index}
85
    public method insert {args}
86
    public method mark {option args}
87
    public method scan {option args}
88
    public method search {args}
89
    public method see {index}
90
    public method tag {option args}
91
    public method window {option args}
92
    public method xview {args}
93
    public method yview {args}
94
}
95
 
96
#
97
# Provide a lowercased access method for the Scrolledtext class.
98
#
99
proc ::iwidgets::scrolledtext {pathName args} {
100
    uplevel ::iwidgets::Scrolledtext $pathName $args
101
}
102
 
103
#
104
# Use option database to override default resources of base classes.
105
#
106
option add *Scrolledtext.labelPos n widgetDefault
107
 
108
# ------------------------------------------------------------------
109
#                        CONSTRUCTOR
110
# ------------------------------------------------------------------
111
body iwidgets::Scrolledtext::constructor {args} {
112
    #
113
    # Our -width and -height options are slightly different than
114
    # those implemented by our base class, so we're going to
115
    # remove them and redefine our own.
116
    #
117
    itk_option remove iwidgets::Scrolledwidget::width
118
    itk_option remove iwidgets::Scrolledwidget::height
119
 
120
    #
121
    # Create a clipping frame which will provide the border for
122
    # relief display.
123
    #
124
    itk_component add clipper {
125
        frame $itk_interior.clipper
126
    } {
127
        usual
128
 
129
        keep -borderwidth -relief -highlightthickness -highlightcolor
130
        rename -highlightbackground -background background Background
131
    }
132
    grid $itk_component(clipper) -row 1 -column 1 -sticky nsew
133
    grid rowconfigure $_interior 1 -weight 1
134
    grid columnconfigure $_interior 1 -weight 1
135
 
136
    #
137
    # Create the text area.
138
    #
139
    itk_component add text {
140
        text $itk_component(clipper).text \
141
                -width 1 -height 1 \
142
                -xscrollcommand \
143
                [code $this _scrollWidget $itk_interior.horizsb] \
144
                -yscrollcommand \
145
                [code $this _scrollWidget $itk_interior.vertsb] \
146
                -borderwidth 0 -highlightthickness 0
147
    } {
148
        usual
149
 
150
        ignore -highlightthickness -highlightcolor -borderwidth
151
 
152
        keep -exportselection -padx -pady -setgrid \
153
             -spacing1 -spacing2 -spacing3 -state -wrap
154
 
155
        rename -font -textfont textFont Font
156
        rename -background -textbackground textBackground Background
157
    }
158
    grid $itk_component(text) -row 0 -column 0 -sticky nsew
159
    grid rowconfigure $itk_component(clipper) 0 -weight 1
160
    grid columnconfigure $itk_component(clipper) 0 -weight 1
161
 
162
    #
163
    # Configure the command on the vertical scroll bar in the base class.
164
    #
165
    $itk_component(vertsb) configure \
166
        -command [code $itk_component(text) yview]
167
 
168
    #
169
    # Configure the command on the horizontal scroll bar in the base class.
170
    #
171
    $itk_component(horizsb) configure \
172
                -command [code $itk_component(text) xview]
173
 
174
    #
175
    # Initialize the widget based on the command line options.
176
    #
177
    eval itk_initialize $args
178
}
179
 
180
# ------------------------------------------------------------------
181
#                           DESTURCTOR
182
# ------------------------------------------------------------------
183
body iwidgets::Scrolledtext::destructor {} {
184
}
185
 
186
# ------------------------------------------------------------------
187
#                             OPTIONS
188
# ------------------------------------------------------------------
189
 
190
# ------------------------------------------------------------------
191
# OPTION: -width
192
#
193
# Specifies the width of the scrolled text as an entire unit.
194
# The value may be specified in any of the forms acceptable to
195
# Tk_GetPixels.  Any additional space needed to display the other
196
# components such as labels, margins, and scrollbars force the text
197
# to be compressed.  A value of zero along with the same value for
198
# the height causes the value given for the visibleitems option
199
# to be applied which administers geometry constraints in a different
200
# manner.
201
# ------------------------------------------------------------------
202
configbody iwidgets::Scrolledtext::width {
203
    if {$itk_option(-width) != 0} {
204
        set shell [lindex [grid info $itk_component(clipper)] 1]
205
 
206
        #
207
        # Due to a bug in the tk4.2 grid, we have to check the
208
        # propagation before setting it.  Setting it to the same
209
        # value it already is will cause it to toggle.
210
        #
211
        if {[grid propagate $shell]} {
212
            grid propagate $shell no
213
        }
214
 
215
        $itk_component(text) configure -width 1
216
        $shell configure \
217
                -width [winfo pixels $shell $itk_option(-width)]
218
    } else {
219
        configure -visibleitems $itk_option(-visibleitems)
220
    }
221
}
222
 
223
# ------------------------------------------------------------------
224
# OPTION: -height
225
#
226
# Specifies the height of the scrolled text as an entire unit.
227
# The value may be specified in any of the forms acceptable to
228
# Tk_GetPixels.  Any additional space needed to display the other
229
# components such as labels, margins, and scrollbars force the text
230
# to be compressed.  A value of zero along with the same value for
231
# the width causes the value given for the visibleitems option
232
# to be applied which administers geometry constraints in a different
233
# manner.
234
# ------------------------------------------------------------------
235
configbody iwidgets::Scrolledtext::height {
236
    if {$itk_option(-height) != 0} {
237
        set shell [lindex [grid info $itk_component(clipper)] 1]
238
 
239
        #
240
        # Due to a bug in the tk4.2 grid, we have to check the
241
        # propagation before setting it.  Setting it to the same
242
        # value it already is will cause it to toggle.
243
        #
244
        if {[grid propagate $shell]} {
245
            grid propagate $shell no
246
        }
247
 
248
        $itk_component(text) configure -height 1
249
        $shell configure \
250
                -height [winfo pixels $shell $itk_option(-height)]
251
    } else {
252
        configure -visibleitems $itk_option(-visibleitems)
253
    }
254
}
255
 
256
# ------------------------------------------------------------------
257
# OPTION: -visibleitems
258
#
259
# Specified the widthxheight in characters and lines for the text.
260
# This option is only administered if the width and height options
261
# are both set to zero, otherwise they take precedence.  With the
262
# visibleitems option engaged, geometry constraints are maintained
263
# only on the text.  The size of the other components such as
264
# labels, margins, and scroll bars, are additive and independent,
265
# effecting the overall size of the scrolled text.  In contrast,
266
# should the width and height options have non zero values, they
267
# are applied to the scrolled text as a whole.  The text is
268
# compressed or expanded to maintain the geometry constraints.
269
# ------------------------------------------------------------------
270
configbody iwidgets::Scrolledtext::visibleitems {
271
    if {[regexp {^[0-9]+x[0-9]+$} $itk_option(-visibleitems)]} {
272
        if {($itk_option(-width) == 0) && \
273
                ($itk_option(-height) == 0)} {
274
            set chars [lindex [split $itk_option(-visibleitems) x] 0]
275
            set lines [lindex [split $itk_option(-visibleitems) x] 1]
276
 
277
            set shell [lindex [grid info $itk_component(clipper)] 1]
278
 
279
            #
280
            # Due to a bug in the tk4.2 grid, we have to check the
281
            # propagation before setting it.  Setting it to the same
282
            # value it already is will cause it to toggle.
283
            #
284
            if {! [grid propagate $shell]} {
285
                grid propagate $shell yes
286
            }
287
 
288
            $itk_component(text) configure -width $chars -height $lines
289
        }
290
 
291
    } else {
292
        error "bad visibleitems option\
293
                \"$itk_option(-visibleitems)\": should be\
294
                widthxheight"
295
    }
296
}
297
 
298
# ------------------------------------------------------------------
299
#                            METHODS
300
# ------------------------------------------------------------------
301
 
302
# ------------------------------------------------------------------
303
# METHOD: bbox index
304
#
305
# Returns four element list describing the bounding box for the list
306
# item at index
307
# ------------------------------------------------------------------
308
body iwidgets::Scrolledtext::bbox {index} {
309
    return [$itk_component(text) bbox $index]
310
}
311
 
312
# ------------------------------------------------------------------
313
# METHOD clear
314
#
315
# Clear the text area.
316
# ------------------------------------------------------------------
317
body iwidgets::Scrolledtext::clear {} {
318
    $itk_component(text) delete 1.0 end
319
}
320
 
321
# ------------------------------------------------------------------
322
# METHOD import filename
323
#
324
# Load text from an existing file (import filename)
325
# ------------------------------------------------------------------
326
body iwidgets::Scrolledtext::import {filename {index end}} {
327
    set f [open $filename r]
328
    insert $index [read $f]
329
    close $f
330
}
331
 
332
# ------------------------------------------------------------------
333
# METHOD export filename
334
#
335
# write text to a file (export filename)
336
# ------------------------------------------------------------------
337
body iwidgets::Scrolledtext::export {filename} {
338
    set f [open $filename w]
339
 
340
    set txt [$itk_component(text) get 1.0 end]
341
    puts $f $txt
342
 
343
    flush $f
344
    close $f
345
}
346
 
347
# ------------------------------------------------------------------
348
# METHOD compare index1 op index2
349
#
350
# Compare indices according to relational operator.
351
# ------------------------------------------------------------------
352
body iwidgets::Scrolledtext::compare {index1 op index2} {
353
    return [$itk_component(text) compare $index1 $op $index2]
354
}
355
 
356
# ------------------------------------------------------------------
357
# METHOD debug ?boolean?
358
#
359
# Activates consistency checks in B-tree code associated with text
360
# widgets.
361
# ------------------------------------------------------------------
362
body iwidgets::Scrolledtext::debug {args} {
363
    eval $itk_component(text) debug $args
364
}
365
 
366
# ------------------------------------------------------------------
367
# METHOD delete first ?last?
368
#
369
# Delete a range of characters from the text.
370
# ------------------------------------------------------------------
371
body iwidgets::Scrolledtext::delete {first {last {}}} {
372
    $itk_component(text) delete $first $last
373
}
374
 
375
# ------------------------------------------------------------------
376
# METHOD dlineinfo index
377
#
378
# Returns a five element list describing the area occupied by the
379
# display line containing index.
380
# ------------------------------------------------------------------
381
body iwidgets::Scrolledtext::dlineinfo {index} {
382
    return [$itk_component(text) dlineinfo $index]
383
}
384
 
385
# ------------------------------------------------------------------
386
# METHOD get index1 ?index2?
387
#
388
# Return text from start index to end index.
389
# ------------------------------------------------------------------
390
body iwidgets::Scrolledtext::get {index1 {index2 {}}} {
391
    return [$itk_component(text) get $index1 $index2]
392
}
393
 
394
# ------------------------------------------------------------------
395
# METHOD index index
396
#
397
# Return position corresponding to index.
398
# ------------------------------------------------------------------
399
body iwidgets::Scrolledtext::index {index} {
400
    return [$itk_component(text) index $index]
401
}
402
 
403
# ------------------------------------------------------------------
404
# METHOD insert index chars ?tagList?
405
#
406
# Insert text at index.
407
# ------------------------------------------------------------------
408
body iwidgets::Scrolledtext::insert {args} {
409
    eval $itk_component(text) insert $args
410
}
411
 
412
# ------------------------------------------------------------------
413
# METHOD mark option ?arg arg ...?
414
#
415
# Manipulate marks dependent on options.
416
# ------------------------------------------------------------------
417
body iwidgets::Scrolledtext::mark {option args} {
418
    return [eval $itk_component(text) mark $option $args]
419
}
420
 
421
# ------------------------------------------------------------------
422
# METHOD scan option args
423
#
424
# Implements scanning on texts.
425
# ------------------------------------------------------------------
426
body iwidgets::Scrolledtext::scan {option args} {
427
    eval $itk_component(text) scan $option $args
428
}
429
 
430
# ------------------------------------------------------------------
431
# METHOD search ?switches? pattern index ?varName?
432
#
433
# Searches the text for characters matching a pattern.
434
# ------------------------------------------------------------------
435
body iwidgets::Scrolledtext::search {args} {
436
    return [eval $itk_component(text) search $args]
437
}
438
 
439
# ------------------------------------------------------------------
440
# METHOD see index
441
#
442
# Adjusts the view in the window so the character at index is
443
# visible.
444
# ------------------------------------------------------------------
445
body iwidgets::Scrolledtext::see {index} {
446
    $itk_component(text) see $index
447
}
448
 
449
# ------------------------------------------------------------------
450
# METHOD tag option ?arg arg ...?
451
#
452
# Manipulate tags dependent on options.
453
# ------------------------------------------------------------------
454
body iwidgets::Scrolledtext::tag {option args} {
455
    return [eval $itk_component(text) tag $option $args]
456
}
457
 
458
# ------------------------------------------------------------------
459
# METHOD window option ?arg arg ...?
460
#
461
# Manipulate embedded windows.
462
# ------------------------------------------------------------------
463
body iwidgets::Scrolledtext::window {option args} {
464
    return [eval $itk_component(text) window $option $args]
465
}
466
 
467
# ------------------------------------------------------------------
468
# METHOD xview
469
#
470
# Changes x view in widget's window.
471
# ------------------------------------------------------------------
472
body iwidgets::Scrolledtext::xview {args} {
473
    return [eval $itk_component(text) xview $args]
474
}
475
 
476
# ------------------------------------------------------------------
477
# METHOD yview
478
#
479
# Changes y view in widget's window.
480
# ------------------------------------------------------------------
481
body iwidgets::Scrolledtext::yview {args} {
482
    return [eval $itk_component(text) yview $args]
483
}
484
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.