3
;; Create a canvas demonstration consisting of a ruler.
6
;; w - Name to use for new top-level window.
7
;; This file implements a canvas widget that displays a ruler with tab stops
8
;; that can be set individually. The only procedure that should be invoked
9
;; from outside the file is the first one, which creates the canvas.
13
(defun mkRuler (&optional (w '.ruler))
14
(if (winfo :exists w :return 'boolean) (destroy w))
17
(wm :title w "Ruler Demonstration")
18
(wm :iconname w "Ruler")
21
(message (conc w '.msg) :font :Adobe-Times-Medium-R-Normal-*-180-* :width "13c"
22
:relief "raised" :bd 2 :text "This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. (if :you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button.")
23
(canvas c :width "14.8c" :height "2.5c" :relief "raised")
24
(button (conc w '.ok) :text "OK" :command (tk-conc "destroy " w))
25
(pack (conc w '.msg) (conc w '.c) :side "top" :fill "x")
26
(pack (conc w '.ok) :side "bottom" :pady 5)
28
(setf (get *v* 'grid) '.25c)
29
(setf (get *v* 'left) (winfo :fpixels c "1c" :return t))
30
(setf (get *v* 'right) (winfo :fpixels c "13c" :return t))
31
(setf (get *v* 'top) (winfo :fpixels c "1c" :return t))
32
(setf (get *v* 'bottom) (winfo :fpixels c "1.5c" :return t))
33
(setf (get *v* 'size) (winfo :fpixels c '.2c :return t))
34
(setf (get *v* 'normalStyle) '(:fill "black"))
35
(if (equal (tk :colormodel c) "color")
37
(setf (get *v* 'activeStyle) '(:fill "red" :stipple ""))
38
(setf (get *v* 'deleteStyle)
39
`(:stipple "@" : ,*tk-library* :"/demos/bitmaps/grey.25"
43
(setf (get *v* 'activeStyle) '(:fill "black" :stipple "" ))
44
(setf (get *v* 'deleteStyle)
45
`(:stipple "@" : ,*tk-library* : "/demos/bitmaps/grey.25"
49
(funcall c :create "line" "1c" "0.5c" "1c" "1c" "13c" "1c" "13c" "0.5c" :width 1)
53
(funcall c :create "line" x :"c" "1c" x :"c" "0.6c" :width 1)
54
(funcall c :create "line" x :".25c" "1c" x :".25c" "0.8c" :width 1)
55
(funcall c :create "line" x :".5c" "1c" x :".5c" "0.7c" :width 1)
56
(funcall c :create "line" x :".75c" "1c" x :".75c" "0.8c" :width 1)
57
(funcall c :create "text" x :".15c" '.75c :text i :anchor "sw")
59
(funcall c :addtag "well" "withtag"
60
(funcall c :create "rect" "13.2c" "1c" "13.8c" "0.5c"
61
:outline "black" :fill
62
(nth 4 (funcall c :config :background
63
:return 'list-strings))))
64
(funcall c :addtag "well" "withtag"
65
(rulerMkTab c (winfo :pixels c "13.5c" :return t)
66
(winfo :pixels c '.65c :return t)))
68
(funcall c :bind "well" "<1>" `(rulerNewTab ',c |%x| |%y|))
69
(funcall c :bind "tab" "<1>" `(demo_selectTab ',c |%x| |%y|))
70
(bind c "<B1-Motion>" `(rulerMoveTab ',c |%x| |%y|))
71
(bind c "<Any-ButtonRelease-1>" `(rulerReleaseTab ',c))
74
(defun rulerMkTab (c x y)
76
(funcall c :create "polygon" x y (+ x (get *v* 'size))
85
(defun rulerNewTab (c x y)
87
(funcall c :addtag "active" "withtag" (rulerMkTab c x y))
88
(funcall c :addtag "tab" "withtag" "active")
93
(defvar *recursive* nil)
94
;; prevent recursive calls
95
(defun rulerMoveTab (c x y &aux cx cy (*recursive* *recursive*) )
96
(cond (*recursive* (return-from rulerMoveTab))
97
(t (setq *recursive* t)))
98
(if (equal (funcall c :find "withtag" "active" :return 'string) "")
99
(return-from rulerMoveTab nil))
100
(setq cx (funcall c :canvasx x (get *v* 'grid) :return t))
101
(setq cy (funcall c :canvasy y :return t))
102
(if (< cx (get *v* 'left))(setq cx (get *v* 'left)))
103
(if (> cx (get *v* 'right))(setq cx (get *v* 'right)))
105
(if (and (>= cy (get *v* 'top)) (<= cy (get *v* 'bottom)))
107
(setq cy (+ 2 (get *v* 'top)))
108
(apply c :itemconf "active" (get *v* 'activestyle)))
111
(setq cy (- cy (get *v* 'size) 2))
112
(apply c :itemconf "active"(get *v* 'deletestyle)))
114
(funcall c :move "active" (- cx (get *v* 'x))
115
(- cy (get *v* 'y)) )
116
(setf (get *v* 'x) cx)
117
(setf (get *v* 'y) cy)
120
(defun demo_selectTab (c x y)
122
(setf (get *v* 'x) (funcall c :canvasx x (get *v* 'grid) :return t))
123
(setf (get *v* 'y) (+ 2 (get *v* 'top)))
124
(funcall c :addtag "active" "withtag" "current")
125
(apply c :itemconf "active" (get *v* 'activeStyle))
126
(funcall c :raise "active")
129
(defun rulerReleaseTab (c )
131
(if (equal (funcall c :find "withtag" "active" :return 'string)
132
"") (return-from rulerReleaseTab nil))
134
(if (not (eql (get *v* 'y) (+ 2 (get *v* 'top))))
135
(funcall c :delete "active")
137
(apply c :itemconf "active" (get *v* 'normalStyle))
138
(funcall c :dtag "active")