diff options
| author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-26 13:58:11 +0000 |
|---|---|---|
| committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-26 13:58:11 +0000 |
| commit | 36012a9e55a6745b77ca3b929bbb4202fa538b77 (patch) | |
| tree | 6ee086fb50b03430ed910426c6cd676ea8de237d /ext/tk/sample/tkextlib/treectrl/help.rb | |
| parent | c5ae6f5bb44f901228e189079db6de26ed816f4c (diff) | |
| download | ruby-36012a9e55a6745b77ca3b929bbb4202fa538b77.tar.gz ruby-36012a9e55a6745b77ca3b929bbb4202fa538b77.tar.xz ruby-36012a9e55a6745b77ca3b929bbb4202fa538b77.zip | |
* ext/tk/lib/tk.rb (_callback_entry_class?): add for checking whether
a class is available for a callback entry.
* ext/tk/lib/tk.rb (after_cancel): add Tk.after_cancel(afterID) method.
* ext/tk/lib/tk.rb (array2tk_list): change from private module method
of TkComm to public module method.
* ext/tk/lib/tk.rb (cget): add check that slot argument is not empty string.
* ext/tk/lib/tk.rb (configinfo): ditto.
* ext/tk/lib/tk/itemconfig.rb (itemcget): add check that slot argument
is not empty string.
* ext/tk/lib/tk/itemconfig.rb (itemconfiginfo): ditto.
* ext/tk/lib/tk/entry.rb: add TkEntry#icursor and icursor= (alias of
cursor and cursor= method).
* ext/tk/lib/tk/font.rb: improve font treatment when the font name is
empty string.
* ext/tk/lib/tk/variable.rb: add :variable, :window and :procedure type.
* ext/tk/lib/tk/variable.rb: improve treatment of array-type tkvariable.
* ext/tk/lib/tkextlib/blt.rb: add commands for zooming.
* ext/tk/lib/tkextlib/blt/*: bug fix.
* ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix and add methods
to call TreeCtrl commands for bindings.
* ext/tk/sample/tkextlib/blt/*: new sample scritps.
* ext/tk/sample/tkextlib/treectrl/*: ditto.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkextlib/treectrl/help.rb')
| -rw-r--r-- | ext/tk/sample/tkextlib/treectrl/help.rb | 405 |
1 files changed, 405 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/treectrl/help.rb b/ext/tk/sample/tkextlib/treectrl/help.rb new file mode 100644 index 000000000..01e075bdf --- /dev/null +++ b/ext/tk/sample/tkextlib/treectrl/help.rb @@ -0,0 +1,405 @@ +# +# Demo: Help contents +# +def demoHelpContents(t) + height = t.font.metrics(:linespace) + 2 + hehght = 18 if height < 18 + t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false, + :itemheight=>height, :selectmode=>:browse) + + init_pics('help-*') + + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + t.column_create(:text=>'Help Contents') + else # TreeCtrl 1.0 + t.column_configure(0, :text=>'Help Contents') + end + + # Define a new item state + t.state_define('mouseover') + + t.element_create('e1', :image, :image=>@images['help-page']) + t.element_create('e2', :image, :image=>[ + @images['help-book-open'], ['open'], + @images['help-book-closed'], [], + ]) + t.element_create('e3', :text, + :font=>[t.font.dup.underline(true), ['mouseover']], + :fill=>[ + @SystemHighlightText, ['selected', 'focus'], + 'blue', ['mouseover'] + ]) + t.element_create('e4', :rect, :showfocus=>true, + :fill=>[@SystemHighligh, ['selected', 'focus']]) + + # book + s = t.style_create('s1') + t.style_elements(s, ['e4', 'e1', 'e3']) + t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e3', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2) + + # page + s = t.style_create('s2') + t.style_elements(s, ['e4', 'e2', 'e3']) + t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e3', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2) + + parentList = [:root, '', '', '', '', '', ''] + parent = :root + [ + [0, 's1', "Welcome to Help"], + [0, 's2', "Introducing Windows 98"], + [1, 's2', "How to Use Help"], + [2, 's1', "Find a topic"], + [2, 's1', "Get more out of help"], + [1, 's2', "Register Your Software"], + [2, 's1', "Registering Windows 98 online"], + [1, 's2', "What's New in Windows 98"], + [2, 's1', "Innovative, easy-to-use features"], + [2, 's1', "Improved reliability"], + [2, 's1', "A faster operating system"], + [2, 's1', "True Web integration"], + [2, 's1', "More entertaining and fun"], + [1, 's2', "If You're New to Windows 98"], + [2, 's2', "Tips for Macintosh Users"], + [3, 's1', "Why does the mouse have two buttons?"] + ].each{|depth, style, text| + item = t.item_create + t.item_style_set(item, 0, style) + t.item_element_configure(item, 0, 'e3', :text=>text) + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + t.item_collapse(item) + else # TreeCtrl 1.0 + t.collapse(item) + end + t.item_lastchild(parentList[depth], item) + depth += 1 + parentList[depth] = item + } + + treeCtrlHelp = TkBindTag.new + + treeCtrlHelp.bind('Double-ButtonPress-1', + proc{|w, x, y| + if w.identify(x, y)[0] == 'header' + Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y) + else + helpButton1(w, x, y) + end + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('ButtonPress-1', + proc{|w, x, y| + helpButton1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Motion', + proc{|w, x, y| + helpMotion1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Leave', + proc{|w, x, y| + helpLeave1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('ButtonRelease-1', + proc{|w, x, y| + helpRelease1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y') + + treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Motion', + proc{|w, x, y| + if w.selection_get.length == 1 + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, + '1.1') >= 0) + w.item_toggle(w.selection_get[0]) + else # TreeCtrl 1.0 + w.toggle(w.selection_get[0]) + end + end + Tk.callback_break + }, '%W %x %y') + + @Priv[:help, :prev] = '' + + t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ] +end + +# This is an alternate implementation that does not define a new item state +# to change the appearance of the item under the cursor. +def demoHelpContents2(t) + height = t.font.metrics(:linespace) + 2 + hehght = 18 if height < 18 + t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false, + :itemheight=>height, :selectmode=>:browse) + + init_pics('help-*') + + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + t.column_create(:text=>'Help Contents') + else # TreeCtrl 1.0 + t.column_configure(0, :text=>'Help Contents') + end + + t.element_create('e1', :image, :image=>@images['help-page']) + t.element_create('e2', :image, :image=>[ + @images['help-book-open'], ['open'], + @images['help-book-closed'], [], + ]) + t.element_create('e3', :text, + :fill=>[ + @SystemHighlightText, ['selected', 'focus'], + 'blue', [] + ]) + t.element_create('e4', :rect, :showfocus=>true, + :fill=>[@SystemHighligh, ['selected', 'focus']]) + t.element_create('e5', :text, :font=>t.font.dup.underline(true), + :fill=>[ + @SystemHighlightText, ['selected', 'focus'], + 'blue', [] + ]) + + # book + s = t.style_create('s1') + t.style_elements(s, ['e4', 'e1', 'e3']) + t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e3', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2) + + # page + s = t.style_create('s2') + t.style_elements(s, ['e4', 'e2', 'e3']) + t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e3', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2) + + # book (focus) + s = t.style_create('s1.f') + t.style_elements(s, ['e4', 'e1', 'e5']) + t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e5', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2) + + # page (focus) + s = t.style_create('s2') + t.style_elements(s, ['e4', 'e2', 'e5']) + t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns) + t.style_layout(s, 'e5', :expand=>:ns) + t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2) + + parentList = [:root, '', '', '', '', '', ''] + parent = :root + [ + [0, 's1', "Welcome to Help"], + [0, 's2', "Introducing Windows 98"], + [1, 's2', "How to Use Help"], + [2, 's1' "Find a topic"], + [2, 's1', "Get more out of help"], + [1, 's2', "Register Your Software"], + [2, 's1', "Registering Windows 98 online"], + [1, 's2', "What's New in Windows 98"], + [2, 's1', "Innovative, easy-to-use features"], + [2, 's1', "Improved reliability"], + [2, 's1', "A faster operating system"], + [2, 's1', "True Web integration"], + [2, 's1', "More entertaining and fun"], + [1, 's2', "If You're New to Windows 98"], + [2, 's2', "Tips for Macintosh Users"], + [3, 's1', "Why does the mouse have two buttons?"] + ].each{|depth, style, text| + item = t.item_create + t.item_style_set(item, 0, style) + t.item_element_configure(item, 0, 'e3', :text=>text) + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + t.item_collapse(item) + else # TreeCtrl 1.0 + t.collapse(item) + end + t.item_lastchild(parentList[depth], item) + depth += 1 + parentList[depth] = item + } + + treeCtrlHelp = TkBindTag.new + + treeCtrlHelp.bind('Double-ButtonPress-1', + proc{|w, x, y| + if w.identify(x, y)[0] == 'header' + Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y) + else + helpButton1(w, x, y) + end + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('ButtonPress-1', + proc{|w, x, y| + helpButton1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Motion', + proc{|w, x, y| + helpMotion1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Leave', + proc{|w, x, y| + helpLeave1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('ButtonRelease-1', + proc{|w, x, y| + helpRelease1(w, x, y) + Tk.callback_break + }, '%W %x %y') + + treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y') + + treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y') + + treeCtrlHelp.bind('Button1-Motion', + proc{|w, x, y| + if w.selection_get.length == 1 + w.item_toggle(w.selection_get[0]) + end + Tk.callback_break + }, '%W %x %y') + + @Priv[:help, :prev] = '' + + t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ] +end + +def helpButton1(w, x, y) + w.set_focus + id = w.identify(x, y) + @Priv['buttonMode'] = '' + if id[0] == 'header' + Tk::TreeCtrl::BindCallback.buttonPress1(w, x, y) + elsif id[0] == 'item' + item = id[1] + # didn't click an element + return if id.length != 6 + if w.selection_includes(item) + w.toggle(item) + return + end + if w.selection_get.length > 0 + item2 = w.selection_get[0] + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + w.item_collapse(item2) + else # TreeCtrl 1.0 + w.collapse(item2) + end + w.item_ancestors(item2).each{|i| + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + w.item_collapse(i) if w.compare(item, '!=', i) + else # TreeCtrl 1.0 + w.collapse(i) if w.compare(item, '!=', i) + end + } + end + w.activate(item) + if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) + w.item_ancestors(item).each{|i| + w.item_expand(i) + } + w.item_toggle(item) + else # TreeCtrl 1.0 + w.expand(*(w.item_ancestors(item))) + w.toggle(item) + end + w.selection_modify(item, :all) + end +end + +def helpMotion1(w, x, y) + case @Priv['buttonMode'] + when 'resize', 'header' + Tk::TreeCtrl::BindCallback.motion1(w, x, y) + end +end + +def helpLeave1(w, x, y) + # This is called when I do ButtonPress-1 on Unix for some reason, + # and buttonMode is undefined. + return unless @Priv.exist?('buttonMode') + case @Priv['buttonMode'] + when 'header' + w.column_configure(@Priv['column'], :sunken=>false) + end +end + +def helpRelease1(w, x, y) + case @Priv['buttonMode'] + when 'resize', 'header' + Tk::TreeCtrl::BindCallback.Release1(w, x, y) + end + @Priv['buttonMode'] = '' +end + +def helpMotion(w, x, y) + id = w.identify(x, y) + if id.empty? + elsif id[0] == 'header' + elsif id[0] == 'item' + item = id[1] + if id.length == 6 + if @Priv[:help, :prev] != TkComm._get_eval_string(item) + if @Priv[:help, :prev] != '' + w.item_state_set(@Priv[:help, :prev], '!mouseover') + end + w.item_state_set(item, 'mouseover') + @Priv[:help, :prev] = item + end + return + end + end + if @Priv[:help, :prev] != '' + w.item_state_set(@Priv[:help, :prev], '!mouseover') + @Priv[:help, :prev] = '' + end +end + +# Alternate implementation doesn't rely on mouseover state +def helpMotion2(w, x, y) + id = w.identify(x, y) + if id[0] == 'header' + elsif !id.empty? + item = id[1] + if id.kength == 6 + if @Priv[:help, :prev] != TkComm._get_eval_string(item) + if @Priv[:help, :prev] != '' + style = w.item_style_set(@Priv[:help, :prev], 0) + style.sub!(/\.f$/, '') + w.item_style_map(@Priv[:help, :prev], 0, style, ['e5', 'e3']) + end + style = w.item_style_set(item, 0) + w.item_style_map(item, 0, style + '.f', ['e3', 'e5']) + @Priv[:help, :prev] = item + end + return + end + end + if @Priv[:help, :prev] != '' + style = w.item_style_set(@Priv[:help, :prev], 0) + style.sub!(/\.f$/, '') + w.item_style_map(@Priv[:help, :prev], 0, style, ['e5', 'e3']) + @Priv[:help, :prev] = '' + end +end |
