2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
|
# File 'lib/a-tkcommons.rb', line 2821
def __initialize_posting(_widget=self)
chs = TkWinfo.children(_widget)
hh = 22
@last_post = nil
@posting_on = true
@event_posting_on = false
@m_show = Hash.new
chs.each{|ch|
next if ch.kind_of?(String)
ch..bind_append("Map", proc{ @m_show[ch.] = true })
ch..bind_append("Unmap", proc{ @m_show[ch.] = false })
ch.bind_append("Enter", proc{|x,y,rx,ry|
if @posting_on
if @last_post && @last_post != ch.
@last_post.unpost
@last_post=nil
end
if @last_clicked && @last_clicked != ch.
@last_clicked.unpost
@last_clicked = nil
end
ch..post(x-rx,y-ry+hh)
= TkWinfo.children(ch)
@last_menu_posted = [0]
@last_menu_posted.set_focus
@last_menu_posted.bind("Enter", proc{
@last_menu_posted.bind("Leave", proc{
if @posting_on
@last_post.unpost if @last_post
@last_post = nil
@last_menu_posted.bind("Enter", proc{})
@last_menu_posted.bind("Leave", proc{})
end
})
})
end
}, "%X %Y %x %y")
ch.bind_append("Leave", proc{
ch.configure("state"=>:normal, "relief"=>:flat)
if @posting_on
if @last_post
_x = TkWinfo.x(@last_post)
_y = TkWinfo.y(@last_post)
ch.event_generate("KeyPress", :keysym=>"Escape") if Tk.focus.kind_of?(TkMenu) && Tk.focus != ch.
@last_post.post(_x,_y) if @last_clicked && @last_clicked == ch.
end
if @last_post!=ch.
@last_post=ch.
else
@last_post=nil
end
if !Tk.focus.kind_of?(TkMenu)
@last_post.unpost if @last_post
@last_post=nil
end
end
})
ch.bind_append("1", proc{|x,y,rx,ry|
@posting_on=true if @event_posting_on
if @last_post && @last_post != ch.
@last_post.unpost
@last_post = nil
end
@last_post=ch. ch.configure('state'=>'normal')
@last_clicked = ch.
@posting_on=true if @event_posting_on
}, "%X %Y %x %y")
}
_widget.bind_append("Leave", proc{
if @posting_on && Tk.focus != @last_menu_posted
@last_post.unpost if @last_post
@last_post=nil
@posting_on = false if @event_posting_on
end
TkAfter.new(1000,1, proc{
one_post = false
@m_show.each{|m,v|
one_post = v
break if v
}
@posting_on = one_post if @event_posting_on
}).start
})
end
|