source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/create_scrollform.tcl @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 4 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 6.4 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3###############################################
4# Scrolling form, with only vertical scrolling
5# Bindings of scrollbars are redefined to fix a -multiple match binding- problem
6# A binding on mouseWheel is added on the form and its children
7################################################
8
9# creation of the scrollform
10proc scrollform_create {win } {
11        global ScrollInfo widgetInfo
12       
13       
14        set ScrollInfo($win-y0) 0
15       
16        set ScrollInfo(count) 0
17       
18        # main frame
19        ttk::frame $win
20        pack $win -side top -expand 1 -fill both
21       
22        ttk::scrollbar $win.sbary -orient vertical -command [list $win.vport yview]
23        ttk::scrollbar $win.sbarx -orient horizontal -command [list $win.vport xview]
24       
25       
26        #bind $win.sbary <ButtonPress> [subst { puts "sby $win" }]
27       
28        canvas $win.vport  -xscrollcommand  [list $win.sbarx set] -yscrollcommand  [list $win.sbary set]  -borderwidth 0 -highlightthickness 0 -insertborderwidth 0 -background [ThemeColor 0.9]
29       
30   grid $win.vport -sticky news -column 0 -row 0
31   grid columnconfigure $win 0 -weight 1
32   grid rowconfigure $win 0 -weight 1
33
34   #### TEST ####
35   grid $win.sbary -sticky news -column 1 -row 0
36        grid $win.sbarx -sticky news -column 0 -row 1
37       
38   #### TEST ####
39   
40   #$win.vport configure -background [ThemeColor 1.0]
41   #bind . <<ThemeUpdate>> +[subst {$win.vport configure -background \[ThemeColor 1.0\]}]
42   
43   # form to be scrolled
44     ttk::frame $win.vport.form
45
46   set guiMode $widgetInfo(guimode)
47   set guiWidth $widgetInfo(guiwidth)
48   set guiHeight $widgetInfo(guiheight)
49   
50   
51    $win.vport create window 1 1 -window $win.vport.form 
52    #-width 2000 -height 2000
53               
54    #bind $win.vport.form <Visibility>  [subst { scrollform_upperleft $win}]
55       
56        bind $win.vport.form <Visibility>  [subst { scrollform_resize $win}]
57       
58   
59    bind . <<InitializeGUI>>  +[subst { scrollform_upperleft $win}]
60   
61    return $win
62}
63
64
65# procedure for scrolling using the drag and drop binding
66proc scrollform_scroll {win x y} {
67    global ScrollInfo
68       
69        set gap [expr ($y - $ScrollInfo($win-fy))]
70       
71        if { $gap > 0} {
72                $win.vport yview scroll 1 units
73        }
74        if { $gap < 0} {
75                $win.vport yview scroll -1 units
76        }
77        set ScrollInfo($win-fy) $y
78}
79
80# procedure for scrolling using the MouseWheel binding
81# warning, delta is negative with respect to canvas corrdinate
82proc scrollform_scrollwheel {win delta} {
83        global tabscroll
84       
85        if {$tabscroll} {       
86                set scrollamount [expr int(-$delta)]
87                $win.vport yview scroll $scrollamount units
88                #if {[expr abs($scrollamount) > 3]} {
89                #       set delta [expr int($delta*0.3)]
90                #        scrollform_scrollwheel $win $delta
91                #}
92        }
93}
94
95# procedure for scrolling using the MouseWheel binding
96# warning, delta is negative with respect to canvas corrdinate
97proc scrollform_lateralscroll {win delta} {
98        global tabscroll
99        if {$tabscroll} {       
100                set scrollamount [expr int(-$delta)]
101                $win.vport xview scroll $scrollamount units
102                #if {[expr abs($scrollamount) > 3]} {
103                #       set delta [expr int($delta*0.33)]
104                #        scrollform_lateralscroll $win $delta
105                #}
106        }
107}
108
109
110# resise the scrollform
111# update the scrollbar visibility
112# propagate mousewheel binding
113
114proc scrollform_resize {win} {
115        global ScrollInfo
116        set  frac_x [lindex [$win.sbarx  get] 0 ]
117        set  frac_y [lindex [$win.sbary  get] 0 ]
118        set bbox [$win.vport bbox all]
119       
120        $win.vport configure -scrollregion $bbox
121       
122        bind . <MouseWheel>  [subst {scrollform_scrollwheel $win %D}]
123        bind . <Shift-MouseWheel>  [subst {scrollform_lateralscroll $win %D}]
124       
125        $win.vport yview moveto $frac_y
126        $win.vport xview moveto $frac_x
127       
128       
129        ## get geometry of form
130        #set height [winfo height $win.vport.form]
131        #set width [winfo width $win.vport.form]
132        #
133        ## get the bbox of canvas
134        #set bbox [$win.vport bbox all]
135        #
136        ## toggle y scrollbar
137        #set win_height [winfo height $win.vport]
138        #if {$height > $win_height && [winfo viewable $win.vport.form ] } {
139        #       grid  $win.sbary -sticky news -column 1 -row 0
140        #       $win.vport configure -scrollregion $bbox
141        #       bind .  <MouseWheel> [subst {scrollform_scrollwheel $win %D}]
142        #} else {
143        #       $win.vport yview moveto 0.0
144        #       grid forget $win.sbary
145        #       bind . <MouseWheel> ""
146        #}
147        ## toggle x scrollbar
148        #set win_width [winfo width $win.vport]
149        #if {$width > $win_width} {
150        #       grid $win.sbarx -sticky news -column 0 -row 1
151        #       $win.vport configure -scrollregion $bbox
152        #       bind .  <Shift-MouseWheel> [subst {scrollform_lateralscroll $win %D}]
153        #} else {
154        #       $win.vport xview moveto 0.0
155        #       grid forget $win.sbarx
156        #       bind . <Shift-MouseWheel> ""
157        #}
158
159        return $win
160}
161
162# Only return where child widget must be packed
163proc scrollform_interior { win } {
164        return $win.vport.form
165
166}
167
168# Only return where child widget must be packed
169proc scrollform_upperleft { win } {
170        global widgetInfo
171        scrollform_resize $win
172       
173        $win.vport xview moveto 0.0
174        $win.vport yview moveto 0.0
175}
176
177
178
179
180#  Copyright CERFACS 2014
181#   
182#  antoine.dauptain@cerfacs.fr
183#   
184#  This software is a computer program whose purpose is to ensure technology
185#  transfer between academia and industry.
186#   
187#  This software is governed by the CeCILL-B license under French law and
188#  abiding by the rules of distribution of free software.  You can  use,
189#  modify and/ or redistribute the software under the terms of the CeCILL-B
190#  license as circulated by CEA, CNRS and INRIA at the following URL
191#  "http://www.cecill.info".
192#   
193#  As a counterpart to the access to the source code and  rights to copy,
194#  modify and redistribute granted by the license, users are provided only
195#  with a limited warranty  and the software's author,  the holder of the
196#  economic rights,  and the successive licensors  have only  limited
197#  liability.
198#   
199#  In this respect, the user's attention is drawn to the risks associated
200#  with loading,  using,  modifying and/or developing or reproducing the
201#  software by the user in light of its specific status of free software,
202#  that may mean  that it is complicated to manipulate,  and  that  also
203#  therefore means  that it is reserved for developers  and  experienced
204#  professionals having in-depth computer knowledge. Users are therefore
205#  encouraged to load and test the software's suitability as regards their
206#  requirements in conditions enabling the security of their systems and/or
207#  data to be ensured and,  more generally, to use and operate it in the
208#  same conditions as regards security.
209#   
210#  The fact that you are presently reading this means that you have had
211#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.