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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [ResizeH.tcl] - Blame information for rev 1771

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

Line No. Rev Author Line
1 578 markom
# ResizeH.tcl --
2
#
3
#       tixResizeHandle: A general purpose "resizing handle"
4
#       widget. You can use it to resize pictures, widgets, etc. When
5
#       using it to resize a widget, you can use the "attachwidget"
6
#       command to attach it to a widget and it will handle all the
7
#       events for you.
8
#
9
# Copyright (c) 1996, Expert Interface Technologies
10
#
11
# See the file "license.terms" for information on usage and redistribution
12
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
#
14
#
15
#
16
 
17
tixWidgetClass tixResizeHandle {
18
    -classname TixResizeHandle
19
    -superclass tixVResize
20
 
21
    -method {
22
        attachwidget detachwidget hide show
23
    }
24
    -flag {
25
        -command -cursorfg -cursorbg -handlesize -hintcolor -hintwidth -x -y
26
    }
27
    -configspec {
28
        {-command command Command ""}
29
        {-cursorfg cursorFg CursorColor white}
30
        {-cursorbg cursorBg CursorColor red}
31
        {-handlesize handleSize HandleSize 6}
32
        {-hintcolor hintColor HintColor red}
33
        {-hintwidth hintWidth HintWidth 1}
34
        {-x x X 0}
35
        {-y y Y 0}
36
    }
37
}
38
 
39
proc tixResizeHandle:InitWidgetRec {w} {
40
    upvar #0 $w data
41
 
42
    tixChainMethod $w InitWidgetRec
43
 
44
    set data(shown)  0
45
    set data(widget) ""
46
}
47
 
48
proc tixResizeHandle:ConstructWidget {w} {
49
    upvar #0 $w data
50
 
51
    tixChainMethod $w ConstructWidget
52
 
53
    # Create the hints
54
    #
55
    set data(w_ht) $w:tix_priv_ht
56
    set data(w_hb) $w:tix_priv_hb
57
    set data(w_hl) $w:tix_priv_hl
58
    set data(w_hr) $w:tix_priv_hr
59
 
60
    frame $data(w_ht) -height $data(-hintwidth) -bg $data(-background)
61
    frame $data(w_hb) -height $data(-hintwidth) -bg $data(-background)
62
    frame $data(w_hl) -width  $data(-hintwidth) -bg $data(-background)
63
    frame $data(w_hr) -width  $data(-hintwidth) -bg $data(-background)
64
 
65
    # Create the corner resize handles
66
    #
67
    set data(w_r00) $w
68
 
69
#   Windows don't like this
70
#    $data(rootCmd) config\
71
#       -cursor "top_left_corner $data(-cursorbg) $data(-cursorfg)"
72
 
73
    $data(rootCmd) config -cursor top_left_corner
74
 
75
    set data(w_r01) $w:tix_priv_01
76
    set data(w_r10) $w:tix_priv_10
77
    set data(w_r11) $w:tix_priv_11
78
 
79
    frame $data(w_r01) -relief $data(-relief) -bd $data(-borderwidth) \
80
        -cursor "bottom_left_corner"\
81
        -bg $data(-background)
82
    frame $data(w_r10) -relief $data(-relief) -bd $data(-borderwidth) \
83
        -cursor "top_right_corner"\
84
        -bg $data(-background)
85
    frame $data(w_r11) -relief $data(-relief) -bd $data(-borderwidth) \
86
        -cursor "bottom_right_corner"\
87
        -bg $data(-background)
88
 
89
    # Create the border resize handles
90
    #
91
    set data(w_bt)  $w:tix_priv_bt
92
    set data(w_bb)  $w:tix_priv_bb
93
    set data(w_bl)  $w:tix_priv_bl
94
    set data(w_br)  $w:tix_priv_br
95
 
96
    frame $data(w_bt) -relief $data(-relief) -bd $data(-borderwidth) \
97
        -cursor "top_side"\
98
        -bg $data(-background)
99
    frame $data(w_bb) -relief $data(-relief) -bd $data(-borderwidth) \
100
        -cursor "bottom_side"\
101
        -bg $data(-background)
102
    frame $data(w_bl) -relief $data(-relief) -bd $data(-borderwidth) \
103
        -cursor "left_side"\
104
        -bg $data(-background)
105
    frame $data(w_br) -relief $data(-relief) -bd $data(-borderwidth) \
106
        -cursor "right_side"\
107
        -bg $data(-background)
108
}
109
 
110
proc tixResizeHandle:SetBindings {w} {
111
    upvar #0 $w data
112
 
113
    tixChainMethod $w SetBindings
114
 
115
    bind $data(w_r00)   <1> \
116
        "tixResizeHandle:dragstart $w $data(w_r00)   1 %X %Y  {1  1 -1 -1}"
117
    bind $data(w_r01)   <1> \
118
        "tixResizeHandle:dragstart $w $data(w_r01)   1 %X %Y  {1  0 -1  1}"
119
    bind $data(w_r10)   <1> \
120
        "tixResizeHandle:dragstart $w $data(w_r10)   1 %X %Y  {0  1  1 -1}"
121
    bind $data(w_r11)   <1> \
122
        "tixResizeHandle:dragstart $w $data(w_r11)   1 %X %Y  {0  0  1  1}"
123
    bind $data(w_bt)    <1> \
124
        "tixResizeHandle:dragstart $w $data(w_bt)    1 %X %Y  {0  1  0 -1}"
125
    bind $data(w_bb)    <1> \
126
        "tixResizeHandle:dragstart $w $data(w_bb)    1 %X %Y  {0  0  0  1}"
127
    bind $data(w_bl)    <1> \
128
        "tixResizeHandle:dragstart $w $data(w_bl)    1 %X %Y  {1  0 -1  0}"
129
    bind $data(w_br)    <1> \
130
        "tixResizeHandle:dragstart $w $data(w_br)    1 %X %Y  {0  0  1  0}"
131
 
132
    foreach win [list \
133
                 $data(w_r00)\
134
                 $data(w_r01)\
135
                 $data(w_r10)\
136
                 $data(w_r11)\
137
                 $data(w_bt)\
138
                 $data(w_bb)\
139
                 $data(w_bl)\
140
                 $data(w_br)\
141
                 ] {
142
        bind $win <B1-Motion>       "tixVResize:drag    $w %X %Y"
143
        bind $win <ButtonRelease-1> "tixVResize:dragend $w $win 0 %X %Y"
144
        bind $win <Any-Escape>      "tixVResize:dragend $w $win 1  0  0"
145
    }
146
}
147
 
148
#----------------------------------------------------------------------
149
#               Config Methods
150
#----------------------------------------------------------------------
151
proc tixResizeHandle:config-width {w value} {
152
    tixWidgetDoWhenIdle tixResizeHandle:ComposeWindow $w
153
}
154
 
155
proc tixResizeHandle:config-height {w value} {
156
    tixWidgetDoWhenIdle tixResizeHandle:ComposeWindow $w
157
}
158
 
159
proc tixResizeHandle:config-x {w value} {
160
    tixWidgetDoWhenIdle tixResizeHandle:ComposeWindow $w
161
}
162
 
163
proc tixResizeHandle:config-y {w value} {
164
    tixWidgetDoWhenIdle tixResizeHandle:ComposeWindow $w
165
}
166
 
167
 
168
#----------------------------------------------------------------------
169
#               Public Methods
170
#----------------------------------------------------------------------
171
proc tixResizeHandle:dragstart {w win depress rootx rooty mrect} {
172
    upvar #0 $w data
173
 
174
    set wx $data(-x)
175
    set wy $data(-y)
176
    set ww $data(-width)
177
    set wh $data(-height)
178
 
179
    tixVResize:dragstart $w $win $depress $rootx $rooty \
180
        [list $wx $wy $ww $wh] $mrect
181
}
182
 
183
# tixDeleteBindTag --
184
#
185
#       Delete the bindtag(s) in the args list from the bindtags of the widget
186
#
187
proc tixDeleteBindTag {w args} {
188
    if ![winfo exists $w] {
189
        return
190
    }
191
    set newtags ""
192
 
193
    foreach tag [bindtags $w] {
194
        if {[lsearch $args $tag] == -1} {
195
            lappend newtags $tag
196
        }
197
    }
198
    bindtags $w $newtags
199
}
200
 
201
proc tixAddBindTag {w args} {
202
    bindtags $w [concat [bindtags $w] $args]
203
}
204
 
205
proc tixResizeHandle:attachwidget {w widget args} {
206
    upvar #0 $w data
207
 
208
    set opt(-move) 0
209
    tixHandleOptions opt {-move} $args
210
 
211
    if {$data(widget) != ""} {
212
        tixDeleteBindTag $data(widget) TixResizeHandleTag:$w
213
    }
214
 
215
    set data(widget) $widget
216
 
217
    if {$data(widget) != ""} {
218
        # Just in case TixResizeHandleTag was already there
219
        tixDeleteBindTag $data(widget) TixResizeHandleTag:$w
220
        tixAddBindTag $data(widget) TixResizeHandleTag:$w
221
 
222
 
223
        set data(-x)      [winfo x      $data(widget)]
224
        set data(-y)      [winfo y      $data(widget)]
225
        set data(-width)  [winfo width  $data(widget)]
226
        set data(-height) [winfo height $data(widget)]
227
 
228
        tixResizeHandle:show $w
229
        tixResizeHandle:ComposeWindow $w
230
 
231
        # Now set the bindings
232
        #
233
        if {$opt(-move)} {
234
            bind TixResizeHandleTag:$w <1> \
235
                "tixResizeHandle:Attach $w %X %Y"
236
            bind TixResizeHandleTag:$w <B1-Motion> \
237
                "tixResizeHandle:BMotion $w %X %Y"
238
            bind TixResizeHandleTag:$w <Any-Escape> \
239
                "tixResizeHandle:BRelease $w 1 %X %Y"
240
            bind TixResizeHandleTag:$w <ButtonRelease-1>\
241
                "tixResizeHandle:BRelease $w 0 %X %Y"
242
        } else {
243
            # if "move" is false, then the widget won't be moved as a whole -- 
244
            # ResizeHandle will only move its sides
245
            bind TixResizeHandleTag:$w <1>               {;}
246
            bind TixResizeHandleTag:$w <B1-Motion>       {;}
247
            bind TixResizeHandleTag:$w <Any-Escape>      {;}
248
            bind TixResizeHandleTag:$w <ButtonRelease-1> {;}
249
        }
250
    }
251
}
252
 
253
proc tixResizeHandle:detachwidget {w} {
254
    upvar #0 $w data
255
 
256
    if {$data(widget) != ""} {
257
        tixDeleteBindTag $data(widget) TixResizeHandleTag:$w
258
    }
259
    tixResizeHandle:hide $w
260
}
261
 
262
proc tixResizeHandle:show {w} {
263
    upvar #0 $w data
264
 
265
    set data(shown) 1
266
 
267
    raise $data(w_ht)
268
    raise $data(w_hb)
269
    raise $data(w_hl)
270
    raise $data(w_hr)
271
 
272
    raise $data(w_r00)
273
    raise $data(w_r01)
274
    raise $data(w_r10)
275
    raise $data(w_r11)
276
 
277
    raise $data(w_bt)
278
    raise $data(w_bb)
279
    raise $data(w_bl)
280
    raise $data(w_br)
281
 
282
#   tixCancleIdleTask tixResizeHandle:ComposeWindow $w
283
    tixResizeHandle:ComposeWindow $w
284
}
285
 
286
 
287
proc tixResizeHandle:hide {w} {
288
    upvar #0 $w data
289
 
290
    if {!$data(shown)} {
291
        return
292
    }
293
 
294
    set data(shown) 0
295
 
296
    place forget $data(w_r00)
297
    place forget $data(w_r01)
298
    place forget $data(w_r10)
299
    place forget $data(w_r11)
300
 
301
    place forget $data(w_bt)
302
    place forget $data(w_bb)
303
    place forget $data(w_bl)
304
    place forget $data(w_br)
305
 
306
    place forget $data(w_ht)
307
    place forget $data(w_hb)
308
    place forget $data(w_hl)
309
    place forget $data(w_hr)
310
}
311
 
312
proc tixResizeHandle:Destructor {w} {
313
    upvar #0 $w data
314
 
315
    if {$data(widget) != ""} {
316
        tixDeleteBindTag $data(widget) TixResizeHandleTag:$w
317
    }
318
 
319
    catch {destroy $data(w_r01)}
320
    catch {destroy $data(w_r10)}
321
    catch {destroy $data(w_r11)}
322
 
323
    catch {destroy $data(w_bt)}
324
    catch {destroy $data(w_bb)}
325
    catch {destroy $data(w_bl)}
326
    catch {destroy $data(w_br)}
327
 
328
    catch {destroy $data(w_ht)}
329
    catch {destroy $data(w_hb)}
330
    catch {destroy $data(w_hl)}
331
    catch {destroy $data(w_hr)}
332
 
333
    tixChainMethod $w Destructor
334
}
335
 
336
#----------------------------------------------------------------------
337
#         Private Methods Dealing With Attached Widgets
338
#----------------------------------------------------------------------
339
proc tixResizeHandle:Attach {w rx ry} {
340
    upvar #0 $w data
341
 
342
    tixResizeHandle:dragstart $w $data(widget) 0 $rx $ry {1 1 0 0}
343
}
344
 
345
proc tixResizeHandle:BMotion {w rx ry} {
346
    tixVResize:drag $w $rx $ry
347
}
348
 
349
 
350
proc tixResizeHandle:BRelease {w isAbort rx ry} {
351
    upvar #0 $w data
352
 
353
    tixVResize:dragend $w $data(widget) $isAbort $rx $ry
354
}
355
 
356
#----------------------------------------------------------------------
357
#               Private Methods
358
#----------------------------------------------------------------------
359
proc tixResizeHandle:DrawTmpLines {w} {
360
    upvar #0 $w data
361
 
362
    set x1 $data(hf:x1)
363
    set y1 $data(hf:y1)
364
    set x2 $data(hf:x2)
365
    set y2 $data(hf:y2)
366
 
367
    tixTmpLine $x1 $y1 $x2 $y1 $w
368
    tixTmpLine $x1 $y2 $x2 $y2 $w
369
    tixTmpLine $x1 $y1 $x1 $y2 $w
370
    tixTmpLine $x2 $y1 $x2 $y2 $w
371
}
372
 
373
# Place the hint frame to indicate the changes
374
#
375
proc tixResizeHandle:SetHintFrame {w x1 y1 width height} {
376
    upvar #0 $w data
377
 
378
    # The four sides of the window
379
    #
380
    set x2 [expr "$x1+$width"]
381
    set y2 [expr "$y1+$height"]
382
 
383
    set rx [winfo rootx [winfo parent $w]]
384
    set ry [winfo rooty [winfo parent $w]]
385
 
386
    incr x1 $rx
387
    incr y1 $ry
388
    incr x2 $rx
389
    incr y2 $ry
390
 
391
    if {[info exists data(hf:x1)]} {
392
        tixResizeHandle:DrawTmpLines $w
393
    }
394
 
395
    set data(hf:x1) $x1
396
    set data(hf:y1) $y1
397
    set data(hf:x2) $x2
398
    set data(hf:y2) $y2
399
 
400
    tixResizeHandle:DrawTmpLines $w
401
}
402
 
403
proc tixResizeHandle:ShowHintFrame {w} {
404
    upvar #0 $w data
405
 
406
    place forget $data(w_ht)
407
    place forget $data(w_hb)
408
    place forget $data(w_hl)
409
    place forget $data(w_hr)
410
 
411
    update
412
}
413
 
414
proc tixResizeHandle:HideHintFrame {w} {
415
    upvar #0 $w data
416
 
417
    tixResizeHandle:DrawTmpLines $w
418
    unset data(hf:x1)
419
    unset data(hf:y1)
420
    unset data(hf:x2)
421
    unset data(hf:y2)
422
}
423
 
424
proc tixResizeHandle:UpdateSize {w x y width height} {
425
    upvar #0 $w data
426
 
427
    set data(-x)      $x
428
    set data(-y)      $y
429
    set data(-width)  $width
430
    set data(-height) $height
431
 
432
    tixResizeHandle:ComposeWindow $w
433
 
434
    if {$data(widget) != ""} {
435
        place $data(widget) -x $x -y $y -width $width -height $height
436
    }
437
 
438
    if {$data(-command) != ""} {
439
        eval $data(-command) $x $y $width $height
440
    }
441
}
442
 
443
proc tixResizeHandle:ComposeWindow {w} {
444
    upvar #0 $w data
445
 
446
    set px $data(-x)
447
    set py $data(-y)
448
    set pw $data(-width)
449
    set ph $data(-height)
450
 
451
    # Show the hint frames
452
    #
453
    set x1 $px
454
    set y1 $py
455
    set x2 [expr "$px+$pw"]
456
    set y2 [expr "$py+$ph"]
457
 
458
    place $data(w_ht) -x $x1 -y $y1 -width  $pw -bordermode outside
459
    place $data(w_hb) -x $x1 -y $y2 -width  $pw -bordermode outside
460
    place $data(w_hl) -x $x1 -y $y1 -height $ph -bordermode outside
461
    place $data(w_hr) -x $x2 -y $y1 -height $ph -bordermode outside
462
 
463
    # Set the four corner resize handles
464
    #
465
    set sz_2 [expr $data(-handlesize)/2]
466
 
467
    set x1 [expr "$px - $sz_2"]
468
    set y1 [expr "$py - $sz_2"]
469
    set x2 [expr "$px - $sz_2" + $pw]
470
    set y2 [expr "$py - $sz_2" + $ph]
471
 
472
    place $data(w_r00) -x $x1 -y $y1 \
473
        -width $data(-handlesize) -height $data(-handlesize)
474
    place $data(w_r01) -x $x1 -y $y2\
475
        -width $data(-handlesize) -height $data(-handlesize)
476
    place $data(w_r10) -x $x2 -y $y1\
477
        -width $data(-handlesize) -height $data(-handlesize)
478
    place $data(w_r11) -x $x2 -y $y2\
479
        -width $data(-handlesize) -height $data(-handlesize)
480
 
481
 
482
    # Set the four border resize handles
483
    #
484
    set mx [expr "$px + $pw/2 - $sz_2"]
485
    set my [expr "$py + $ph/2 - $sz_2"]
486
 
487
    place $data(w_bt) -x $mx -y $y1 \
488
        -width $data(-handlesize) -height $data(-handlesize)
489
    place $data(w_bb) -x $mx -y $y2 \
490
        -width $data(-handlesize) -height $data(-handlesize)
491
    place $data(w_bl) -x $x1 -y $my \
492
        -width $data(-handlesize) -height $data(-handlesize)
493
    place $data(w_br) -x $x2 -y $my \
494
        -width $data(-handlesize) -height $data(-handlesize)
495
}

powered by: WebSVN 2.1.0

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