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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [VResize.tcl] - Blame information for rev 1781

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# VResize.tcl --
2
#
3
#       tixVResize:
4
#       Virtual base class for all classes that provide resize capability,
5
#       such as the resize handle and the MDI client window.
6
#
7
# Copyright (c) 1996, Expert Interface Technologies
8
#
9
# See the file "license.terms" for information on usage and redistribution
10
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
#
12
 
13
tixWidgetClass tixVResize {
14
    -virtual true
15
    -classname TixVResize
16
    -superclass tixPrimitive
17
    -method {
18
        drag dragend dragstart
19
    }
20
    -flag {
21
        -gridded -gridx -gridy -minwidth -minheight
22
    }
23
    -configspec {
24
        {-gridded gridded Gridded false}
25
        {-gridx gridX Grid 10}
26
        {-gridy gridY Grid 10}
27
        {-minwidth minWidth MinWidth 0}
28
        {-minheight minHeight MinHeight 0}
29
   }
30
}
31
 
32
 
33
proc tixVResize:InitWidgetRec {w} {
34
    upvar #0 $w data
35
 
36
    tixChainMethod $w InitWidgetRec
37
 
38
    set data(movePending) 0
39
    set data(aborted) 0
40
    set data(depress) 0
41
}
42
 
43
#----------------------------------------------------------------------
44
#                    Public methods
45
#----------------------------------------------------------------------
46
# Start dragging a window
47
#
48
proc tixVResize:dragstart {w win depress rootx rooty wrect mrect} {
49
    upvar #0 $w data
50
 
51
    set data(rootx) $rootx
52
    set data(rooty) $rooty
53
 
54
    set data(mx) [lindex $mrect 0]
55
    set data(my) [lindex $mrect 1]
56
    set data(mw) [lindex $mrect 2]
57
    set data(mh) [lindex $mrect 3]
58
 
59
    set data(fx) [lindex $wrect 0]
60
    set data(fy) [lindex $wrect 1]
61
    set data(fw) [lindex $wrect 2]
62
    set data(fh) [lindex $wrect 3]
63
 
64
    set data(old_x) [lindex $wrect 0]
65
    set data(old_y) [lindex $wrect 1]
66
    set data(old_w) [lindex $wrect 2]
67
    set data(old_h) [lindex $wrect 3]
68
 
69
    if {$data(mw) < 0} {
70
        set data(maxx)  [expr "$data(fx) + $data(old_w) - $data(-minwidth)"]
71
    } else {
72
        set data(maxx) 32000
73
    }
74
    if {$data(mh) < 0} {
75
        set data(maxy)  [expr "$data(fy) + $data(old_h) - $data(-minheight)"]
76
    } else {
77
        set data(maxy) 32000
78
    }
79
 
80
    set data(aborted) 0
81
 
82
    tixCallMethod $w ShowHintFrame
83
    tixCallMethod $w SetHintFrame $data(fx) $data(fy) $data(fw) $data(fh)
84
 
85
    # Grab so that all button events are captured
86
    #
87
    grab $win
88
    focus $win
89
 
90
    set data(depress) $depress
91
    if {$depress} {
92
        set data(oldRelief) [$win cget -relief]
93
        $win config -relief sunken
94
    }
95
}
96
 
97
 
98
proc tixVResize:drag {w rootx rooty} {
99
    upvar #0 $w data
100
 
101
    if {$data(aborted) == 0} {
102
        set data(newrootx) $rootx
103
        set data(newrooty) $rooty
104
 
105
        if {$data(movePending) == 0} {
106
            set data(movePending) 1
107
            after 2 tixVResize:DragCompressed $w
108
        }
109
    }
110
}
111
 
112
proc tixVResize:dragend {w win isAbort rootx rooty} {
113
    upvar #0 $w data
114
 
115
    if {$data(aborted)} {
116
        if {$isAbort == 0} {
117
            grab release $win
118
        }
119
        return
120
    }
121
 
122
    # Just in case some draggings are not applied.
123
    #
124
    update
125
 
126
    tixCallMethod $w HideHintFrame
127
 
128
    if {$isAbort} {
129
        set data(aborted) 1
130
    } else {
131
        # Apply the changes
132
        #
133
        tixCallMethod $w UpdateSize $data(fx) $data(fy) $data(fw) $data(fh)
134
 
135
        # Release the grab
136
        #
137
        grab release $win
138
    }
139
 
140
    if {$data(depress)} {
141
        $win config -relief $data(oldRelief)
142
    }
143
}
144
 
145
#----------------------------------------------------------------------
146
#                    Internal methods
147
#----------------------------------------------------------------------
148
 
149
proc tixVResize:DragCompressed {w} {
150
    if {![winfo exists $w]} {
151
        return
152
    }
153
 
154
    upvar #0 $w data
155
 
156
    if {$data(aborted) == 1 || $data(movePending) == 0} {
157
        return
158
    }
159
 
160
    set dx [expr "$data(newrootx) - $data(rootx)"]
161
    set dy [expr "$data(newrooty) - $data(rooty)"]
162
 
163
    set data(fx) [expr "$data(old_x) + ($dx * $data(mx))"]
164
    set data(fy) [expr "$data(old_y) + ($dy * $data(my))"]
165
    set data(fw) [expr "$data(old_w) + ($dx * $data(mw))"]
166
    set data(fh) [expr "$data(old_h) + ($dy * $data(mh))"]
167
 
168
    if {$data(fw) < $data(-minwidth)} {
169
        set data(fw) $data(-minwidth)
170
    }
171
    if {$data(fh) < $data(-minheight)} {
172
        set data(fh) $data(-minheight)
173
    }
174
 
175
    if {$data(fx) > $data(maxx)} {
176
        set data(fx) $data(maxx)
177
    }
178
    if {$data(fy) > $data(maxy)} {
179
        set data(fy) $data(maxy)
180
    }
181
 
182
    # If we need grid, set x,y,w,h to fit the grid
183
    #
184
    # *note* grid overrides minwidth and maxwidth ...
185
    #
186
    if {$data(-gridded)} {
187
        set data(fx) [expr "round($data(fx).0/$data(-gridx)) * $data(-gridx)"]
188
        set data(fy) [expr "round($data(fy).0/$data(-gridy)) * $data(-gridy)"]
189
 
190
        set fx2  [expr $data(fx) + $data(fw) - 2]
191
        set fy2  [expr $data(fy) + $data(fh) - 2]
192
 
193
        set fx2 [expr "round($fx2.0/$data(-gridx)) * $data(-gridx)"]
194
        set fy2 [expr "round($fy2.0/$data(-gridy)) * $data(-gridy)"]
195
 
196
        set data(fw) [expr $fx2 - $data(fx) + 1]
197
        set data(fh) [expr $fy2 - $data(fy) + 1]
198
    }
199
 
200
    tixCallMethod $w SetHintFrame $data(fx) $data(fy) $data(fw) $data(fh)
201
 
202
    update idletasks
203
 
204
    set data(movePending) 0
205
}

powered by: WebSVN 2.1.0

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