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/] [tabnotebook.itk] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Tabnotebook Widget
3
# ----------------------------------------------------------------------
4
# The Tabnotebook command creates a new window (given by the pathName
5
# argument) and makes it into a Tabnotebook widget. Additional options,
6
# described above may be specified on the command line or in the option
7
# database to configure aspects of the Tabnotebook such as its colors,
8
# font, and text. The Tabnotebook command returns its pathName argument.
9
# At the time this command is invoked, there must not exist a window
10
# named pathName, but pathName's parent must exist.
11
#
12
# A Tabnotebook is a widget that contains a set of tabbed pages. It
13
# displays one page from the set as the selected page. A Tab displays
14
# the label for the page to which it is attached and serves as a page
15
# selector.   When a page's tab is selected, the page's contents are
16
# displayed in the page area. The selected tab has a three-dimensional
17
# effect to make it appear to float above the other tabs. The tabs are
18
# displayed as a group along either the left, top, right, or bottom
19
# edge. When first created a Tabnotebook has no pages. Pages may be
20
# added or deleted using widget commands described below.
21
#
22
# A special option may be provided to the Tabnotebook. The -auto
23
# option specifies whether the Tabnotebook will automatically handle
24
# the unpacking and packing of pages when pages are selected. A value
25
# of true sig nifies that the notebook will automatically manage it. This
26
# is the default value. A value of false signifies the notebook will not
27
# perform automatic switching of pages.
28
#
29
# ----------------------------------------------------------------------
30
#  AUTHOR: Bill W. Scott                 EMAIL: bscott@spd.dsccc.com
31
#
32
#  @(#) $Id: tabnotebook.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
33
# ----------------------------------------------------------------------
34
#            Copyright (c) 1995 DSC Technologies Corporation
35
# ======================================================================
36
# Permission to use, copy, modify, distribute and license this software
37
# and its documentation for any purpose, and without fee or written
38
# agreement with DSC, is hereby granted, provided that the above copyright
39
# notice appears in all copies and that both the copyright notice and
40
# warranty disclaimer below appear in supporting documentation, and that
41
# the names of DSC Technologies Corporation or DSC Communications
42
# Corporation not be used in advertising or publicity pertaining to the
43
# software without specific, written prior permission.
44
#
45
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
46
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
47
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
48
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
49
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
50
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
51
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
52
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
53
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
54
# SOFTWARE.
55
# ======================================================================
56
 
57
#
58
# Default resources.
59
#
60
option add *Tabnotebook.borderWidth 2 widgetDefault
61
option add *Tabnotebook.state normal widgetDefault
62
option add *Tabnotebook.disabledForeground #a3a3a3 widgetDefault
63
option add *Tabnotebook.scrollCommand {} widgetDefault
64
option add *Tabnotebook.equalTabs true widgetDefault
65
option add *Tabnotebook.font \
66
        -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-* widgetDefault
67
option add *Tabnotebook.width 300 widgetDefault
68
option add *Tabnotebook.height 150 widgetDefault
69
option add *Tabnotebook.foreground Black widgetDefault
70
option add *Tabnotebook.background #d9d9d9 widgetDefault
71
option add *Tabnotebook.tabForeground Black widgetDefault
72
option add *Tabnotebook.tabBackground #d9d9d9 widgetDefault
73
option add *Tabnotebook.backdrop #d9d9d9 widgetDefault
74
option add *Tabnotebook.margin 4 widgetDefault
75
option add *Tabnotebook.tabBorders true widgetDefault
76
option add *Tabnotebook.bevelAmount 0 widgetDefault
77
option add *Tabnotebook.raiseSelect false widgetDefault
78
option add *Tabnotebook.auto true widgetDefault
79
option add *Tabnotebook.start 4 widgetDefault
80
option add *Tabnotebook.padX 4 widgetDefault
81
option add *Tabnotebook.padY 4 widgetDefault
82
option add *Tabnotebook.gap overlap widgetDefault
83
option add *Tabnotebook.angle 15 widgetDefault
84
option add *Tabnotebook.tabPos s widgetDefault
85
 
86
#
87
# Usual options.
88
#
89
itk::usual Tabnotebook {
90
    keep -backdrop -background -borderwidth -cursor -disabledforeground \
91
         -font -foreground -tabbackground -tabforeground
92
}
93
 
94
# ------------------------------------------------------------------
95
#                            TABNOTEBOOK
96
# ------------------------------------------------------------------
97
class iwidgets::Tabnotebook {
98
    inherit itk::Widget
99
 
100
    constructor {args} {}
101
    destructor {}
102
 
103
    itk_option define -borderwidth borderWidth BorderWidth 2
104
    itk_option define -state state State normal
105
    itk_option define \
106
            -disabledforeground disabledForeground DisabledForeground #a3a3a3
107
    itk_option define -scrollcommand scrollCommand ScrollCommand {}
108
    itk_option define -equaltabs equalTabs EqualTabs true
109
    itk_option define -font font Font \
110
            -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*
111
    itk_option define -width width Width 300
112
    itk_option define -height height Height 150
113
    itk_option define -foreground foreground Foreground Black
114
    itk_option define -background background Background  #d9d9d9
115
    itk_option define -tabforeground tabForeground TabForeground Black
116
    itk_option define -tabbackground tabBackground TabBackground #d9d9d9
117
    itk_option define -backdrop backdrop Backdrop #d9d9d9
118
    itk_option define -margin margin Margin 4
119
    itk_option define -tabborders tabBorders TabBorders true
120
    itk_option define -bevelamount bevelAmount BevelAmount 0
121
    itk_option define -raiseselect raiseSelect RaiseSelect false
122
    itk_option define -auto auto Auto true
123
    itk_option define -start start Start 4
124
    itk_option define -padx padX PadX 4
125
    itk_option define -pady padY PadY 4
126
    itk_option define -gap gap Gap overlap
127
    itk_option define -angle angle Angle 15
128
    itk_option define -tabpos tabPos TabPos s
129
 
130
    public method add { args }
131
    public method configure { args }
132
    public method childsite { args }
133
    public method delete { args }
134
    public method index { args }
135
    public method insert { index args }
136
    public method prev { }
137
    public method next { }
138
    public method pageconfigure { index args }
139
    public method select { index }
140
    public method view { args }
141
 
142
    protected method _reconfigureTabset { }
143
    protected method _canvasReconfigure { wid hgt }
144
    protected method _pageReconfigure { pageName page wid hgt }
145
 
146
    private method _getArgs { optList args }
147
    private method _redrawBorder { wid hgt }
148
    private method _recomputeBorder { }
149
    private method _pack { tabPos }
150
 
151
    private variable _canvasWidth 0       ;# currently tabnote canvas width
152
    private variable _canvasHeight 0      ;# currently tabnote canvas height
153
    private variable _nbOptList {}        ;# list of notebook options available
154
    private variable _tsOptList {}        ;# list of tabset options available
155
 
156
    private variable _tabPos s            ;# holds -tabPos, because of ordering
157
 
158
    private variable _borderRecompute false   ;# did we dirty border after cfg?
159
    private variable _tabsetReconfigure false ;# did we dirty tabsets after cfg?
160
 
161
}
162
 
163
# ----------------------------------------------------------------------
164
#                              CONSTRUCTOR
165
# ----------------------------------------------------------------------
166
body iwidgets::Tabnotebook::constructor {args} {
167
    component hull configure -borderwidth 0
168
 
169
    #
170
    # Create the outermost canvas to maintain geometry.
171
    #
172
    itk_component add canvas {
173
        canvas $itk_interior.canvas -highlightthickness 0
174
    } {
175
        keep -cursor -background -width -height
176
    }
177
    bind $itk_component(canvas)  \
178
            [code $this _canvasReconfigure %w %h]
179
 
180
 
181
    # .......................
182
    # Create the NOTEBOOK
183
    #
184
    itk_component add notebook {
185
        iwidgets::Notebook $itk_interior.canvas.notebook
186
    } {
187
        keep -cursor -background
188
    }
189
 
190
    #
191
    # Ouch, create a dummy page, go pageconfigure to get its options
192
    # and munge them into a list for later doling by pageconfigure
193
    #
194
    $itk_component(notebook) add
195
    set nbConfigList [$itk_component(notebook) pageconfigure 0]
196
    foreach config $nbConfigList {
197
        lappend _nbOptList [lindex $config 0]
198
    }
199
    $itk_component(notebook) delete 0
200
 
201
    #
202
    # Create the tabset.
203
    #
204
    itk_component add tabset {
205
        iwidgets::Tabset $itk_interior.canvas.tabset \
206
                -command [code $this component notebook select]
207
    } {
208
        keep -cursor
209
    }
210
 
211
    eval itk_initialize $args
212
 
213
    #
214
    # Ouch, create a dummy tab, go tabconfigure to get its options
215
    # and munge them into a list for later doling by pageconfigure
216
    #
217
    $itk_component(tabset) add
218
    set tsConfigList [$itk_component(tabset) tabconfigure 0]
219
    foreach config $tsConfigList {
220
        lappend _tsOptList [lindex $config 0]
221
    }
222
    $itk_component(tabset) delete 0
223
 
224
    bind $itk_component(tabset)  \
225
            [code $this _reconfigureTabset]
226
 
227
    _pack $_tabPos
228
 
229
}
230
 
231
proc ::iwidgets::tabnotebook {pathName args} {
232
    uplevel ::iwidgets::Tabnotebook $pathName $args
233
}
234
 
235
 
236
# -------------------------------------------------------------
237
# DESTRUCTOR: destroy the Tabnotebook
238
# -------------------------------------------------------------
239
body iwidgets::Tabnotebook::destructor {} {
240
}
241
 
242
# ----------------------------------------------------------------------
243
# OPTION -borderwidth
244
#
245
# Thickness of Notebook Border
246
# ----------------------------------------------------------------------
247
configbody iwidgets::Tabnotebook::borderwidth {
248
    if {$itk_option(-borderwidth) != {}} {
249
        #_recomputeBorder
250
        set _borderRecompute true
251
    }
252
}
253
 
254
# ----------------------------------------------------------------------
255
# OPTION -state
256
#
257
# State of the tabs in the tab notebook: normal or disabled
258
# ----------------------------------------------------------------------
259
configbody iwidgets::Tabnotebook::state {
260
    if {$itk_option(-state) != {}} {
261
        $itk_component(tabset) configure -state $itk_option(-state)
262
        #_reconfigureTabset
263
        set _tabsetReconfigure true
264
 
265
    }
266
}
267
 
268
# ----------------------------------------------------------------------
269
# OPTION -disabledforeground
270
#
271
# Specifies a foreground color to use for displaying a
272
# tab's label when its state is disabled.
273
# ----------------------------------------------------------------------
274
configbody iwidgets::Tabnotebook::disabledforeground {
275
 
276
    if {$itk_option(-disabledforeground) != {}} {
277
        $itk_component(tabset) configure \
278
                -disabledforeground $itk_option(-disabledforeground)
279
        #_reconfigureTabset
280
        set _tabsetReconfigure true
281
    }
282
}
283
 
284
# ----------------------------------------------------------------------
285
# OPTION -scrollcommand
286
#
287
# Standard option. See options man pages.
288
# ----------------------------------------------------------------------
289
configbody iwidgets::Tabnotebook::scrollcommand {
290
 
291
    if {$itk_option(-scrollcommand) != {}} {
292
        $itk_component(notebook) \
293
                configure -scrollcommand $itk_option(-scrollcommand)
294
    }
295
}
296
 
297
# ----------------------------------------------------------------------
298
# OPTION -equaltabs
299
#
300
# Specifies whether to force tabs to be equal sized or not.
301
# A value of true means constrain tabs to be equal sized.
302
# A value of false allows each tab to size based on the text
303
# label size. The value may have any of the forms accepted by
304
# the Tcl_GetBoolean, such as true, false, 0, 1, yes, or no.
305
# ----------------------------------------------------------------------
306
configbody iwidgets::Tabnotebook::equaltabs {
307
 
308
    if {$itk_option(-equaltabs) != {}} {
309
        $itk_component(tabset) \
310
                configure -equaltabs $itk_option(-equaltabs)
311
        #_reconfigureTabset
312
        set _tabsetReconfigure true
313
    }
314
}
315
 
316
# ----------------------------------------------------------------------
317
# OPTION -font
318
#
319
# Font for tab labels when they are set to text (-label set)
320
# ----------------------------------------------------------------------
321
configbody iwidgets::Tabnotebook::font {
322
 
323
    if {$itk_option(-font) != {}} {
324
        $itk_component(tabset) configure -font $itk_option(-font)
325
        #_reconfigureTabset
326
        set _tabsetReconfigure true
327
    }
328
}
329
 
330
# ----------------------------------------------------------------------
331
# OPTION -width
332
#
333
# Width of the Tabnotebook
334
# ----------------------------------------------------------------------
335
configbody iwidgets::Tabnotebook::width {
336
    if {$itk_option(-width) != {}} {
337
        $itk_component(canvas) configure -width $itk_option(-width)
338
        #_recomputeBorder
339
        set _borderRecompute true
340
    }
341
}
342
 
343
# ----------------------------------------------------------------------
344
# OPTION -height
345
#
346
# Height of the Tabnotebook
347
# ----------------------------------------------------------------------
348
configbody iwidgets::Tabnotebook::height {
349
    if {$itk_option(-height) != {}} {
350
        $itk_component(canvas) configure -height $itk_option(-height)
351
        #_recomputeBorder
352
        set _borderRecompute true
353
    }
354
}
355
 
356
# ----------------------------------------------------------------------
357
# OPTION -foreground
358
#
359
# Specifies a foreground color to use for displaying a page
360
# and its associated tab label (this is the selected state).
361
# ----------------------------------------------------------------------
362
configbody iwidgets::Tabnotebook::foreground {
363
 
364
    if {$itk_option(-foreground) != {}} {
365
        $itk_component(tabset) configure \
366
                -selectforeground $itk_option(-foreground)
367
    }
368
}
369
 
370
# ----------------------------------------------------------------------
371
# OPTION -background
372
#
373
# Specifies a background color to use for displaying a page
374
# and its associated tab bg (this is the selected state).
375
# ----------------------------------------------------------------------
376
configbody iwidgets::Tabnotebook::background {
377
 
378
    if {$itk_option(-background) != {}} {
379
        $itk_component(tabset) configure \
380
                -selectbackground $itk_option(-background)
381
        #_recomputeBorder
382
        set _borderRecompute true
383
    }
384
}
385
 
386
# ----------------------------------------------------------------------
387
# OPTION -tabforeground
388
#
389
# Specifies a foreground color to use for displaying tab labels
390
# when they are in their unselected state.
391
# ----------------------------------------------------------------------
392
configbody iwidgets::Tabnotebook::tabforeground {
393
 
394
    if {$itk_option(-tabforeground) != {}} {
395
        $itk_component(tabset) configure \
396
                -foreground $itk_option(-tabforeground)
397
    }
398
}
399
 
400
# ----------------------------------------------------------------------
401
# OPTION -tabbackground
402
#
403
# Specifies a background color to use for displaying tab backgrounds
404
# when they are in their unselected state.
405
# ----------------------------------------------------------------------
406
configbody iwidgets::Tabnotebook::tabbackground {
407
 
408
    if {$itk_option(-tabbackground) != {}} {
409
        $itk_component(tabset) configure \
410
                -background $itk_option(-tabbackground)
411
    }
412
}
413
 
414
# ----------------------------------------------------------------------
415
# OPTION -backdrop
416
#
417
# Specifies a background color to use when filling in the
418
# area behind the tabs.
419
# ----------------------------------------------------------------------
420
configbody iwidgets::Tabnotebook::backdrop {
421
 
422
    if {$itk_option(-backdrop) != {}} {
423
        $itk_component(tabset) configure \
424
                -backdrop $itk_option(-backdrop)
425
    }
426
}
427
 
428
# ----------------------------------------------------------------------
429
# OPTION -margin
430
#
431
# Sets the backdrop margin between tab edge and backdrop edge
432
# ----------------------------------------------------------------------
433
configbody iwidgets::Tabnotebook::margin {
434
    if {$itk_option(-margin) != {}} {
435
        $itk_component(tabset) configure -margin $itk_option(-margin)
436
    }
437
}
438
 
439
# ----------------------------------------------------------------------
440
# OPTION -tabborders
441
#
442
# Boolean that specifies whether to draw the borders of
443
# the unselected tabs (tabs in background)
444
# ----------------------------------------------------------------------
445
configbody iwidgets::Tabnotebook::tabborders {
446
    if {$itk_option(-tabborders) != {}} {
447
        $itk_component(tabset) \
448
                configure -tabborders $itk_option(-tabborders)
449
        #_reconfigureTabset
450
        set _tabsetReconfigure true
451
    }
452
}
453
 
454
# ----------------------------------------------------------------------
455
# OPTION -bevelamount
456
#
457
# Specifies pixel size of tab corners. 0 means no corners.
458
# ----------------------------------------------------------------------
459
configbody iwidgets::Tabnotebook::bevelamount {
460
    if {$itk_option(-bevelamount) != {}} {
461
        $itk_component(tabset) \
462
                configure -bevelamount $itk_option(-bevelamount)
463
        #_reconfigureTabset
464
        set _tabsetReconfigure true
465
    }
466
}
467
 
468
# ----------------------------------------------------------------------
469
# OPTION -raiseselect
470
#
471
# Sets whether to raise selected tabs
472
# ----------------------------------------------------------------------
473
configbody iwidgets::Tabnotebook::raiseselect {
474
    if {$itk_option(-raiseselect) != {}} {
475
        $itk_component(tabset) \
476
                configure -raiseselect $itk_option(-raiseselect)
477
        #_reconfigureTabset
478
        set _tabsetReconfigure true
479
    }
480
}
481
 
482
# ----------------------------------------------------------------------
483
# OPTION -auto
484
#
485
# Determines whether pages are automatically unpacked and
486
# packed when pages get selected.
487
# ----------------------------------------------------------------------
488
configbody iwidgets::Tabnotebook::auto {
489
    if {$itk_option(-auto) != {}} {
490
        $itk_component(notebook) configure -auto $itk_option(-auto)
491
    }
492
}
493
 
494
# ----------------------------------------------------------------------
495
# OPTION -start
496
# ----------------------------------------------------------------------
497
configbody iwidgets::Tabnotebook::start {
498
 
499
    if {$itk_option(-start) != {}} {
500
        $itk_component(tabset) configure \
501
                -start $itk_option(-start)
502
        #_reconfigureTabset
503
        set _tabsetReconfigure true
504
    }
505
}
506
 
507
# ----------------------------------------------------------------------
508
# OPTION -padx
509
#
510
# Specifies a non-negative value indicating how much extra space
511
# to request for a tab around its label in the X-direction.
512
# When computing how large a window it needs, the tab will add
513
# this amount to the width it would normally need The tab will
514
# end up with extra internal space to the left and right of its
515
# text label. This value may have any of the forms acceptable
516
# to Tk_GetPixels.
517
# ----------------------------------------------------------------------
518
configbody iwidgets::Tabnotebook::padx {
519
 
520
    if {$itk_option(-padx) != {}} {
521
        $itk_component(tabset) configure -padx $itk_option(-padx)
522
        #_reconfigureTabset
523
        set _tabsetReconfigure true
524
    }
525
}
526
 
527
# ----------------------------------------------------------------------
528
# OPTION -pady
529
#
530
# Specifies a non-negative value indicating how much extra space to
531
# request for a tab around its label in the Y-direction. When computing
532
# how large a window it needs, the tab will add this amount to the
533
# height it would normally need The tab will end up with extra internal
534
# space to the top and bot tom of its text label. This value may have
535
# any of the forms acceptable to Tk_GetPixels.
536
# ----------------------------------------------------------------------
537
configbody iwidgets::Tabnotebook::pady {
538
 
539
    if {$itk_option(-pady) != {}} {
540
        $itk_component(tabset) configure -pady $itk_option(-pady)
541
        #_reconfigureTabset
542
        set _tabsetReconfigure true
543
    }
544
}
545
 
546
# ----------------------------------------------------------------------
547
# OPTION -gap
548
#
549
# Specifies the amount of pixel space to place between each tab.
550
# Value may be any pixel offset value. In addition, a special keyword
551
# 'overlap' can be used as the value to achieve a standard overlap of
552
# tabs. This value may have any of the forms acceptable to Tk_GetPixels.
553
# ----------------------------------------------------------------------
554
configbody iwidgets::Tabnotebook::gap {
555
 
556
    if {$itk_option(-gap) != {}} {
557
        $itk_component(tabset) configure -gap $itk_option(-gap)
558
        #_reconfigureTabset
559
        set _tabsetReconfigure true
560
    }
561
}
562
 
563
# ----------------------------------------------------------------------
564
# OPTION -angle
565
#
566
# Specifes the angle of slope from the inner edge to the outer edge
567
# of the tab. An angle of 0 specifies square tabs. Valid ranges are
568
# 0 to 45 degrees inclusive. Default is 15 degrees. If tabPos is
569
# e or w, this option is ignored.
570
# ----------------------------------------------------------------------
571
configbody iwidgets::Tabnotebook::angle {
572
 
573
    if {$itk_option(-angle) != {}} {
574
        $itk_component(tabset) configure -angle $itk_option(-angle)
575
        #_reconfigureTabset
576
        set _tabsetReconfigure true
577
    }
578
}
579
 
580
# ----------------------------------------------------------------------
581
# OPTION -tabpos
582
#
583
# Specifies the location of the set of tabs in relation to the
584
# Notebook area. Must be n, s, e, or w.   Defaults to s.
585
# ----------------------------------------------------------------------
586
configbody iwidgets::Tabnotebook::tabpos {
587
 
588
    if {$itk_option(-tabpos) != {}} {
589
        set _tabPos $itk_option(-tabpos)
590
        $itk_component(tabset) configure \
591
                -tabpos $itk_option(-tabpos)
592
        pack forget $itk_component(canvas)
593
        pack forget $itk_component(tabset)
594
        pack forget $itk_component(notebook)
595
        _pack $_tabPos
596
    }
597
}
598
 
599
# -------------------------------------------------------------
600
# METHOD: configure ?
601
#
602
# Acts as an addendum to the itk::Widget::configure method.
603
#
604
# Checks the _recomputeBorder flag and the _tabsetReconfigure to
605
# determine what work has been batched to after the configure
606
# -------------------------------------------------------------
607
body iwidgets::Tabnotebook::configure { args } {
608
    set result [eval itk::Archetype::configure $args]
609
 
610
    # check for flags then do update...
611
    if { $_borderRecompute == "true" } {
612
        _recomputeBorder
613
        set _borderRecompute false
614
    }
615
 
616
    if { $_tabsetReconfigure == "true" } {
617
        _reconfigureTabset
618
        set _tabsetReconfigure false
619
    }
620
 
621
    return $result
622
 
623
}
624
 
625
# -------------------------------------------------------------
626
# METHOD: add ?
627
#
628
# Creates a page and appends it to the list of pages.
629
# processes pageconfigure for the page added.
630
#
631
# Returns the page's childsite frame
632
# -------------------------------------------------------------
633
body iwidgets::Tabnotebook::add { args } {
634
 
635
    # The args list should be an even # of params, if not then
636
    # prob missing value for last item in args list. Signal error.
637
    set len [llength $args]
638
    if { [expr $len % 2] } {
639
        error "value for \"[lindex $args [expr $len - 1]]\" missing"
640
    }
641
 
642
    # pick out the notebook args
643
    set nbArgs [eval _getArgs [list $_nbOptList] $args]
644
    set pageName [eval $itk_component(notebook) add $nbArgs]
645
 
646
    # pick out the tabset args
647
    set tsArgs [eval _getArgs [list $_tsOptList] $args]
648
    eval $itk_component(tabset)   add $tsArgs
649
 
650
    set page [index end]
651
    bind $pageName  \
652
            [code $this _pageReconfigure $pageName $page %w %h]
653
    return $pageName
654
}
655
 
656
# -------------------------------------------------------------
657
# METHOD: childsite ??
658
#
659
# If index is supplied, returns the child site widget
660
# corresponding to the page index.  If called with no arguments,
661
# returns a list of all child sites
662
# -------------------------------------------------------------
663
body iwidgets::Tabnotebook::childsite { args } {
664
    return [eval $itk_component(notebook) childsite $args]
665
}
666
 
667
# -------------------------------------------------------------
668
# METHOD: delete  ??
669
#
670
# Deletes a page or range of pages from the notebook
671
# -------------------------------------------------------------
672
body iwidgets::Tabnotebook::delete { args } {
673
    eval $itk_component(notebook) delete $args
674
    eval $itk_component(tabset)   delete $args
675
}
676
 
677
 
678
# -------------------------------------------------------------
679
# METHOD: index 
680
#
681
# Given an index identifier returns the numeric index of the page
682
# -------------------------------------------------------------
683
body iwidgets::Tabnotebook::index { args } {
684
    return [eval $itk_component(notebook) index $args]
685
}
686
 
687
# -------------------------------------------------------------
688
# METHOD: insert  ?
689
#
690
# Inserts a page before a index. The before page may
691
# be specified as a label or a page position.
692
#
693
# Note that since we use eval to preserve the $args list,
694
# we must use list around $index to keep it together as a unit
695
#
696
# Returns the name of the page's child site
697
# -------------------------------------------------------------
698
body iwidgets::Tabnotebook::insert { index args } {
699
 
700
    # pick out the notebook args
701
    set nbArgs [eval _getArgs [list $_nbOptList] $args]
702
    set pageName [eval $itk_component(notebook) insert [list $index] $nbArgs]
703
 
704
    # pick out the tabset args
705
    set tsArgs [eval _getArgs [list $_tsOptList] $args]
706
    eval $itk_component(tabset)   insert [list $index] $tsArgs
707
 
708
    return $pageName
709
 
710
}
711
 
712
# -------------------------------------------------------------
713
# METHOD: prev
714
#
715
# Selects the previous page. Wraps at first back to last page.
716
# -------------------------------------------------------------
717
body iwidgets::Tabnotebook::prev { } {
718
    eval $itk_component(notebook) prev
719
    eval $itk_component(tabset)   prev
720
}
721
 
722
# -------------------------------------------------------------
723
# METHOD: next
724
#
725
# Selects the next page. Wraps at last back to first page.
726
# -------------------------------------------------------------
727
body iwidgets::Tabnotebook::next { } {
728
    eval $itk_component(notebook) next
729
    eval $itk_component(tabset)   next
730
}
731
 
732
# -------------------------------------------------------------
733
# METHOD: pageconfigure  ?
734
#
735
# Performs configure on a given page denoted by index.
736
# Index may be a page number or a pattern matching the label
737
# associated with a page.
738
# -------------------------------------------------------------
739
body iwidgets::Tabnotebook::pageconfigure { index args } {
740
 
741
    set nbArgs [eval _getArgs [list $_nbOptList] $args]
742
    set tsArgs [eval _getArgs [list $_tsOptList] $args]
743
 
744
    set len [llength $args]
745
    switch $len {
746
 
747
            # Here is the case where they just want to query options
748
            set nbConfig \
749
                    [eval $itk_component(notebook) pageconfigure $index $nbArgs]
750
            set tsConfig \
751
                    [eval $itk_component(tabset)   tabconfigure $index $tsArgs]
752
            #
753
            # BUG: this currently just concatenates a page and a tab's
754
            # config lists together... We should bias to the Page
755
            # since this is what we are using as primary when both??
756
            #
757
            # a pageconfigure index -background will return something like:
758
            # -background background Background #9D008FF583C1 gray70 \
759
                    # -background background background white gray 70
760
            #
761
            return [concat $nbConfig $tsConfig]
762
        }
763
        1 {
764
            # Here is the case where they are asking for only one
765
            # one options value... need to figure out which one
766
            # (page or tab) can service this. Then only return
767
            # that one's result.
768
 
769
            if { [llength $nbArgs] != 0 } {
770
                return [eval $itk_component(notebook) \
771
                        pageconfigure $index $nbArgs]
772
            } elseif { [llength $tsArgs] != 0 } {
773
                return [eval $itk_component(tabset) \
774
                        tabconfigure $index $tsArgs]
775
            } else {
776
                error "unknown option \"$args\""
777
            }
778
 
779
        }
780
        default {
781
 
782
            # pick out the notebook args
783
            set nbConfig \
784
                    [eval $itk_component(notebook) \
785
                    pageconfigure [list $index] $nbArgs]
786
 
787
            # pick out the tabset args
788
            set tsConfig \
789
                    [eval $itk_component(tabset)   \
790
                    tabconfigure [list $index] $tsArgs]
791
 
792
            return ""
793
            #return [concat $nbConfig $tsConfig]
794
 
795
        }
796
    }
797
}
798
 
799
# -------------------------------------------------------------
800
# METHOD: select index
801
#
802
# Select a page by index
803
# -------------------------------------------------------------
804
body iwidgets::Tabnotebook::select { index } {
805
    $itk_component(notebook) select $index
806
    $itk_component(tabset)   select $index
807
}
808
 
809
# -------------------------------------------------------------
810
# METHOD: view
811
#
812
# Return the current page
813
#
814
#         view index
815
#
816
# Selects the page denoted by index to be current page
817
#
818
#         view 'moveto' fraction
819
#
820
# Selects the page by using fraction amount
821
#
822
#         view 'scroll' num what
823
#
824
# Selects the page by using num as indicator of next or
825
# previous
826
#
827
# -------------------------------------------------------------
828
body iwidgets::Tabnotebook::view { args } {
829
    eval $itk_component(notebook) view $args
830
    $itk_component(tabset) select [index select]
831
}
832
 
833
# -------------------------------------------------------------
834
# PRIVATE METHOD: _getArgs
835
#
836
# Given an optList returned from a configure on an object and
837
# given a candidate argument list, peruse throught the optList
838
# and build a new argument list with only those options found
839
# in optList.
840
#
841
# This is used by the add, insert, and pageconfigure methods.
842
# It is useful for a container kind of class like Tabnotebook
843
# to be smart about args it gets for its concept of a "page"
844
# which is actually a Notebook Page and a Tabset Tab.
845
#
846
# -------------------------------------------------------------
847
body iwidgets::Tabnotebook::_getArgs { optList args } {
848
 
849
    set len [llength $args]
850
 
851
    set retArgs {}
852
 
853
    for {set i 0} {$i < $len} {incr i} {
854
        # get the option for this pair
855
        set opt [lindex $args $i]
856
 
857
        # move ahead to the value
858
        incr i
859
 
860
        # option exists!
861
        if { [lsearch -exact $optList $opt] != -1} {
862
            lappend retArgs $opt
863
            if {$i < [llength $args]} {
864
                lappend retArgs [lindex $args $i]
865
            }
866
            # option does not exist
867
        }
868
    }
869
 
870
    return $retArgs
871
}
872
 
873
# -------------------------------------------------------------
874
# PROTECTED METHOD: _reconfigureTabset
875
#
876
# bound to the tabset reconfigure... We call our canvas
877
# reconfigure as if the canvas resized, it then configures
878
# the tabset correctly.
879
# -------------------------------------------------------------
880
body iwidgets::Tabnotebook::_reconfigureTabset { } {
881
 
882
    _canvasReconfigure $_canvasWidth $_canvasHeight
883
 
884
}
885
 
886
# -------------------------------------------------------------
887
# PROTECTED METHOD: _canvasReconfigure
888
#
889
# bound to window Reconfigure event of the canvas
890
# keeps the tabset area stretched in its major dimension.
891
# -------------------------------------------------------------
892
body iwidgets::Tabnotebook::_canvasReconfigure { wid hgt } {
893
 
894
    if { $_tabPos == "n" || $_tabPos == "s" } {
895
        $itk_component(tabset) configure -width $wid
896
    } else {
897
        $itk_component(tabset) configure -height $hgt
898
    }
899
 
900
    set _canvasWidth $wid
901
    set _canvasHeight $hgt
902
 
903
    _redrawBorder $wid $hgt
904
 
905
}
906
 
907
# -------------------------------------------------------------
908
# PRIVATE METHOD: _redrawBorder
909
#
910
# called by methods when the packing changes, borderwidths, etc.
911
# and height
912
# -------------------------------------------------------------
913
body iwidgets::Tabnotebook::_redrawBorder { wid hgt } {
914
 
915
    # Get the top of the Notebook area...
916
 
917
    set nbTop [winfo y $itk_component(notebook)]
918
    set canTop [expr $nbTop - $itk_option(-borderwidth)]
919
 
920
    $itk_component(canvas) delete BORDER
921
    if { $itk_option(-borderwidth) > 0 } {
922
 
923
        # For south, east, and west -- draw the top/north edge
924
        if { $_tabPos != "n" } {
925
            $itk_component(canvas) create line \
926
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
927
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
928
                    $wid \
929
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
930
                    -width $itk_option(-borderwidth) \
931
                    -fill [iwidgets::colors::topShadow $itk_option(-background)] \
932
                    -tags BORDER
933
        }
934
 
935
        # For north, east, and west -- draw the bottom/south edge
936
        if { $_tabPos != "s" } {
937
            $itk_component(canvas) create line \
938
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
939
                    [expr floor($hgt - ($itk_option(-borderwidth)/2.0))] \
940
                    [expr floor($wid - ($itk_option(-borderwidth)/2.0))] \
941
                    [expr floor($hgt - ($itk_option(-borderwidth)/2.0))] \
942
                    -width $itk_option(-borderwidth) \
943
                    -fill [iwidgets::colors::bottomShadow $itk_option(-background)] \
944
                    -tags BORDER
945
        }
946
 
947
        # For north, south, and east -- draw the left/west edge
948
        if { $_tabPos != "w" } {
949
            $itk_component(canvas) create line \
950
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
951
 
952
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
953
                    $hgt \
954
                    -width $itk_option(-borderwidth) \
955
                    -fill [iwidgets::colors::topShadow $itk_option(-background)] \
956
                    -tags BORDER
957
        }
958
 
959
        # For north, south, and west -- draw the right/east edge
960
        if { $_tabPos != "e" } {
961
            $itk_component(canvas) create line \
962
                    [expr floor($wid - ($itk_option(-borderwidth)/2.0))] \
963
                    [expr floor(0 + ($itk_option(-borderwidth)/2.0))] \
964
                    [expr floor($wid - ($itk_option(-borderwidth)/2.0))] \
965
                    $hgt \
966
                    -width $itk_option(-borderwidth) \
967
                    -fill [iwidgets::colors::bottomShadow $itk_option(-background)] \
968
                    -tags BORDER
969
        }
970
    }
971
 
972
}
973
 
974
# -------------------------------------------------------------
975
# PRIVATE METHOD: _recomputeBorder
976
#
977
# Based on current width and height of our canvas, repacks
978
# the notebook with padding for borderwidth, and calls
979
# redraw border method
980
# -------------------------------------------------------------
981
body iwidgets::Tabnotebook::_recomputeBorder { } {
982
 
983
    set wid [winfo width $itk_component(canvas)]
984
    set hgt [winfo height $itk_component(canvas)]
985
 
986
    _pack $_tabPos
987
    _redrawBorder $wid $hgt
988
}
989
 
990
# -------------------------------------------------------------
991
# PROTECTED METHOD: _pageReconfigure
992
#
993
# This method will eventually reconfigure the tab notebook's
994
# notebook area to contain the resized child site
995
# -------------------------------------------------------------
996
body iwidgets::Tabnotebook::_pageReconfigure { pageName page wid hgt } {
997
 
998
}
999
 
1000
# -------------------------------------------------------------
1001
# PRIVATE METHOD: _pack
1002
#
1003
# This method packs the notebook and tabset correctly according
1004
# to the current $tabPos
1005
# -------------------------------------------------------------
1006
body iwidgets::Tabnotebook::_pack { tabPos } {
1007
 
1008
    pack $itk_component(canvas) -fill both -expand yes
1009
    pack propagate $itk_component(canvas) no
1010
 
1011
    switch $tabPos {
1012
        n {
1013
            # north
1014
            pack $itk_component(tabset) \
1015
                    -anchor nw \
1016
                    -fill x \
1017
                    -expand no
1018
            pack $itk_component(notebook) \
1019
                    -fill both \
1020
                    -expand yes \
1021
                    -padx $itk_option(-borderwidth) \
1022
                    -pady $itk_option(-borderwidth) \
1023
                    -side bottom
1024
        }
1025
        s {
1026
            # south
1027
            pack $itk_component(notebook) \
1028
                    -anchor nw \
1029
                    -fill both \
1030
                    -expand yes \
1031
                    -padx $itk_option(-borderwidth) \
1032
                    -pady $itk_option(-borderwidth)
1033
 
1034
            pack $itk_component(tabset) \
1035
                    -side left \
1036
                    -fill x \
1037
                    -expand yes
1038
        }
1039
        w {
1040
            # west
1041
            pack $itk_component(tabset) \
1042
                    -anchor nw \
1043
                    -side left \
1044
                    -fill y \
1045
                    -expand no
1046
            pack $itk_component(notebook) \
1047
                    -anchor nw \
1048
                    -side left \
1049
                    -fill both \
1050
                    -expand yes \
1051
                    -padx $itk_option(-borderwidth) \
1052
                    -pady $itk_option(-borderwidth)
1053
 
1054
        }
1055
        e {
1056
            # east
1057
            pack $itk_component(notebook) \
1058
                    -side left \
1059
                    -anchor nw \
1060
                    -fill both \
1061
                    -expand yes \
1062
                    -padx $itk_option(-borderwidth) \
1063
                    -pady $itk_option(-borderwidth)
1064
 
1065
            pack $itk_component(tabset) \
1066
                    -fill y \
1067
                    -expand yes
1068
        }
1069
    }
1070
 
1071
    set wid [winfo width $itk_component(canvas)]
1072
    set hgt [winfo height $itk_component(canvas)]
1073
 
1074
    _redrawBorder $wid $hgt
1075
}

powered by: WebSVN 2.1.0

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