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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [PopMenu.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
# PopMenu.tcl --
2
#
3
#       This file implements the TixPopupMenu widget
4
#
5
# Copyright (c) 1996, Expert Interface Technologies
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
 
11
tixWidgetClass tixPopupMenu {
12
    -classname TixPopupMenu
13
    -superclass tixShell
14
    -method {
15
        bind post unbind
16
    }
17
    -flag {
18
         -buttons -installcolormap -postcmd -spring -state -title
19
    }
20
    -configspec {
21
        {-buttons buttons Buttons {{3 {Any}}}}
22
        {-installcolormap installColormap InstallColormap false}
23
        {-postcmd postCmd PostCmd ""}
24
        {-spring spring Spring 1 tixVerifyBoolean}
25
        {-state state State normal}
26
 
27
        {-cursor corsor Cursur arrow}
28
    }
29
    -static {
30
        -buttons
31
    }
32
    -default  {
33
        {*Menu.tearOff                  0}
34
    }
35
}
36
 
37
proc tixPopupMenu:InitWidgetRec {w} {
38
    upvar #0 $w data
39
 
40
    tixChainMethod $w InitWidgetRec
41
 
42
    set data(g:clients)   ""
43
}
44
 
45
proc tixPopupMenu:ConstructWidget {w} {
46
    upvar #0 $w data
47
 
48
    tixChainMethod $w ConstructWidget
49
 
50
    wm overrideredirect $w 1
51
    wm withdraw $w
52
 
53
    set data(w:menubutton) [menubutton $w.menubutton -text $data(-title) \
54
                            -menu $w.menubutton.menu -anchor w]
55
    set data(w:menu) [menu $w.menubutton.menu]
56
 
57
    pack $data(w:menubutton) -expand yes -fill both
58
}
59
 
60
proc tixPopupMenu:SetBindings {w} {
61
    upvar #0 $w data
62
 
63
    tixChainMethod $w SetBindings
64
 
65
    foreach elm $data(-buttons) {
66
        set btn [lindex $elm 0]
67
        foreach mod [lindex $elm 1] {
68
            tixBind TixPopupMenu:MB:$w <$mod-ButtonPress-$btn> \
69
                "tixPopupMenu:Unpost $w"
70
 
71
            tixBind TixPopupMenu:$w <$mod-ButtonPress-$btn> \
72
                "tixPopupMenu:post $w %W %x %y"
73
        }
74
 
75
        tixBind TixPopupMenu:MB:$w <ButtonRelease-$btn> \
76
            "tixPopupMenu:BtnRelease $w %X %Y"
77
 
78
        tixBind TixPopupMenu:M:$w <Unmap> \
79
            "tixPopupMenu:Unmap $w"
80
        tixBind TixPopupMenu:$w <ButtonRelease-$btn> \
81
            "tixPopupMenu:BtnRelease $w %X %Y"
82
 
83
        tixAddBindTag $data(w:menubutton) TixPopupMenu:MB:$w
84
        tixAddBindTag $data(w:menu)       TixPopupMenu:M:$w
85
    }
86
}
87
 
88
 
89
#----------------------------------------------------------------------
90
# PrivateMethods:
91
#----------------------------------------------------------------------
92
proc tixPopupMenu:Unpost {w} {
93
    upvar #0 $w data
94
 
95
    catch {
96
        tkMenuUnpost ""
97
    }
98
#   tkMbButtonUp $data(w:menubutton)
99
}
100
 
101
proc tixPopupMenu:BtnRelease {w rootX rootY} {
102
    upvar #0 $w data
103
 
104
    set cW [winfo containing $rootX $rootY]
105
 
106
    if {$data(-spring)} {
107
        tixPopupMenu:Unpost $w
108
    }
109
}
110
 
111
proc tixPopupMenu:Unmap {w} {
112
    upvar #0 $w data
113
    wm withdraw $w
114
}
115
 
116
proc tixPopupMenu:Destructor {w} {
117
    upvar #0 $w data
118
 
119
    foreach client $data(g:clients) {
120
        if [winfo exists $client] {
121
            tixDeleteBindTag $client TixPopupMenu:$w
122
        }
123
    }
124
 
125
    # delete the extra bindings
126
    #
127
    foreach tag [list TixPopupMenu:MB:$w TixPopupMenu:M:$w] {
128
        foreach e [bind $tag] {
129
            bind $tag $e ""
130
        }
131
    }
132
 
133
    tixChainMethod $w Destructor
134
}
135
 
136
proc tixPopupMenu:config-title {w value} {
137
    upvar #0 $w data
138
 
139
    $data(w:menubutton) config -text $value
140
}
141
 
142
#----------------------------------------------------------------------
143
# PublicMethods:
144
#----------------------------------------------------------------------
145
proc tixPopupMenu:bind {w args} {
146
    upvar #0 $w data
147
 
148
    foreach client $args {
149
        if {[lsearch $data(g:clients) $client] == -1} {
150
            lappend data(g:clients) $client
151
            tixAppendBindTag $client TixPopupMenu:$w
152
        }
153
    }
154
}
155
 
156
proc tixPopupMenu:unbind {w args} {
157
    upvar #0 $w data
158
 
159
    foreach client $args {
160
        if [winfo exists $client] {
161
            set index [lsearch $data(g:clients) $client]
162
            if {$index != -1} {
163
                tixDeleteBindTag $client TixPopupMenu:$w
164
                set data(g:clients) [lreplace $data(g:clients) $index $index]
165
            }
166
        }
167
    }
168
}
169
 
170
proc tixPopupMenu:post {w client x y} {
171
    upvar #0 $w data
172
    global tkPriv
173
 
174
    if {$data(-state)  == "disabled"} {
175
        return
176
    }
177
 
178
    set rootx [expr $x + [winfo rootx $client]]
179
    set rooty [expr $y + [winfo rooty $client]]
180
 
181
    if {$data(-postcmd) != ""} {
182
        set ret [tixEvalCmdBinding $w $data(-postcmd) "" $rootx $rooty]
183
        if ![tixGetBoolean $ret] {
184
            return
185
        }
186
    }
187
 
188
    if [tixGetBoolean -nocomplain $data(-installcolormap)] {
189
        wm colormapwindows . "$w"
190
    }
191
 
192
 
193
    set menuWidth [winfo reqwidth $data(w:menu)]
194
    set width     [winfo reqwidth  $w]
195
    set height    [winfo reqheight $w]
196
 
197
    if {$width < $menuWidth} {
198
        set width $menuWidth
199
    }
200
 
201
    set wx $rootx
202
    set wy $rooty
203
 
204
    # trick: the following lines allow the popup menu
205
    # acquire a stable width and height when it is finally
206
    # put on the visible screen. Advoid flashing
207
    #
208
    wm geometry $w +10000+10000
209
    wm deiconify $w
210
    raise $w
211
 
212
    update
213
    wm geometry $w $width\x$height+$wx+$wy
214
    update
215
 
216
    tkMbEnter $data(w:menubutton)
217
    tkMbPost $tkPriv(inMenubutton) $rootx $rooty
218
}

powered by: WebSVN 2.1.0

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