2004-07-01 09:38:48 +00:00
|
|
|
#
|
|
|
|
# tkextlib/tcllib/autoscroll.rb
|
|
|
|
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
|
|
|
#
|
|
|
|
# * Part of tcllib extension
|
|
|
|
# * Provides for a scrollbar to automatically mapped and unmapped as needed
|
|
|
|
#
|
|
|
|
# (The following is the original description of the library.)
|
|
|
|
#
|
2009-03-06 03:56:38 +00:00
|
|
|
# This package allows scrollbars to be mapped and unmapped as needed
|
|
|
|
# depending on the size and content of the scrollbars scrolled widget.
|
|
|
|
# The scrollbar must be managed by either pack or grid, other geometry
|
2004-07-01 09:38:48 +00:00
|
|
|
# managers are not supported.
|
|
|
|
#
|
2009-03-06 03:56:38 +00:00
|
|
|
# When managed by pack, any geometry changes made in the scrollbars parent
|
|
|
|
# between the time a scrollbar is unmapped, and when it is mapped will be
|
|
|
|
# lost. It is an error to destroy any of the scrollbars siblings while the
|
|
|
|
# scrollbar is unmapped. When managed by grid, if anything becomes gridded
|
|
|
|
# in the same row and column the scrollbar occupied it will be replaced by
|
2004-07-01 09:38:48 +00:00
|
|
|
# the scrollbar when remapped.
|
|
|
|
#
|
2009-03-06 03:56:38 +00:00
|
|
|
# This package may be used on any scrollbar-like widget as long as it
|
|
|
|
# supports the set subcommand in the same style as scrollbar. If the set
|
2004-07-01 09:38:48 +00:00
|
|
|
# subcommand is not used then this package will have no effect.
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'tk'
|
|
|
|
require 'tk/scrollbar'
|
2004-07-06 09:42:12 +00:00
|
|
|
require 'tkextlib/tcllib.rb'
|
2004-07-01 09:38:48 +00:00
|
|
|
|
|
|
|
module Tk
|
2004-07-06 09:42:12 +00:00
|
|
|
module Tcllib
|
|
|
|
module Autoscroll
|
2005-05-30 14:53:52 +00:00
|
|
|
PACKAGE_NAME = 'autoscroll'.freeze
|
|
|
|
def self.package_name
|
|
|
|
PACKAGE_NAME
|
|
|
|
end
|
|
|
|
|
2004-07-06 09:42:12 +00:00
|
|
|
def self.package_version
|
2004-10-11 04:51:21 +00:00
|
|
|
begin
|
|
|
|
TkPackage.require('autoscroll')
|
|
|
|
rescue
|
|
|
|
''
|
|
|
|
end
|
2004-07-06 09:42:12 +00:00
|
|
|
end
|
2004-07-15 01:18:57 +00:00
|
|
|
|
|
|
|
def self.not_available
|
2004-10-11 04:51:21 +00:00
|
|
|
fail RuntimeError, "'tkextlib/tcllib/autoscroll' extension is not available on your current environment."
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.autoscroll(win)
|
2004-10-11 04:51:21 +00:00
|
|
|
Tk::Tcllib::Autoscroll.not_available
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.unautoscroll(win)
|
2004-10-11 04:51:21 +00:00
|
|
|
Tk::Tcllib::Autoscroll.not_available
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
2004-07-06 09:42:12 +00:00
|
|
|
end
|
|
|
|
end
|
2004-07-09 19:29:29 +00:00
|
|
|
end
|
2004-07-06 09:42:12 +00:00
|
|
|
|
2004-07-09 19:29:29 +00:00
|
|
|
module Tk
|
2004-07-01 09:38:48 +00:00
|
|
|
module Scrollable
|
|
|
|
def autoscroll(mode = nil)
|
|
|
|
case mode
|
|
|
|
when :x, 'x'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @xscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
when :y, 'y'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @yscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
when nil, :both, 'both'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @xscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar)
|
|
|
|
end
|
|
|
|
if @yscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
else
|
2004-10-11 04:51:21 +00:00
|
|
|
fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected"
|
2004-07-01 09:38:48 +00:00
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def unautoscroll(mode = nil)
|
|
|
|
case mode
|
|
|
|
when :x, 'x'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @xscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
when :y, 'y'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @yscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
when nil, :both, 'both'
|
2004-10-11 04:51:21 +00:00
|
|
|
if @xscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar)
|
|
|
|
end
|
|
|
|
if @yscrollbar
|
|
|
|
Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar)
|
|
|
|
end
|
2004-07-01 09:38:48 +00:00
|
|
|
else
|
2004-10-11 04:51:21 +00:00
|
|
|
fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected"
|
2004-07-01 09:38:48 +00:00
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
* ext/tk/lib/tk.rb, ext/tk/lib/*: make default widget set
switchable between Tk (standard Tcl/Tk widget set) and
Ttk (Tile). Initial default widget set is Tk. Now, toplevel
widget classes are removed and defined as aliases.
For example, "TkButton" is an alias of the "Tk::Button" class.
Those aliases are replaced when switching default widget set.
"Tk.default_widget_set=" is the method for switching default
widget set. "Tk.default_widget_set = :Ttk" defines Ttk (Tile)
widget set as default. It means that "TkButton" denotes
"Tk::Tile::Button" class. And then, "TkButton.new" creates
a Tk::Tile::Button widget. Of course, you can back to use
standard Tk widgets as the default widget set by calling
"Tk.default_widget_set = :Tk", whenever you want. Based on
thie feature, you can use Ttk widget styling engine on your
old Ruby/Tk application without modifying its source, if you
don'tuse widget options unsupported on Ttk widgets (At first,
call "Tk.default_widget_set = :Ttk", and next load and run
your application).
This is one step for supporting Tcl/Tk8.5 features.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-27 18:44:31 +00:00
|
|
|
class Tk::Scrollbar
|
2004-07-01 09:38:48 +00:00
|
|
|
def autoscroll
|
2009-03-06 03:56:38 +00:00
|
|
|
# Arranges for the already existing scrollbar to be mapped
|
2004-07-01 09:38:48 +00:00
|
|
|
# and unmapped as needed.
|
2004-07-15 01:18:57 +00:00
|
|
|
#tk_call_without_enc('::autoscroll::autoscroll', @path)
|
|
|
|
Tk::Tcllib::Autoscroll.autoscroll(self)
|
2004-07-01 09:38:48 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
def unautoscroll
|
2009-03-06 03:56:38 +00:00
|
|
|
# Returns the scrollbar to its original static state.
|
2004-07-15 01:18:57 +00:00
|
|
|
#tk_call_without_enc('::autoscroll::unautoscroll', @path)
|
|
|
|
Tk::Tcllib::Autoscroll.unautoscroll(self)
|
2004-07-01 09:38:48 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
2004-07-15 01:18:57 +00:00
|
|
|
|
|
|
|
# TkPackage.require('autoscroll', '1.0')
|
* ext/tk/extconf.rb: improbe messages [ruby-core:06325].
* ext/tk/lib/tk.rb, ext/tk/lib/tk/canvas.rb, ext/tk/lib/tk/entry.rb,
ext/tk/lib/tk/frame.rb, ext/tk/lib/tk/image.rb,
ext/tk/lib/tk/itemconfig.rb, ext/tk/lib/tk/labelframe.rb,
ext/tk/lib/tk/listbox.rb, ext/tk/lib/tk/menu.rb,
ext/tk/lib/tk/radiobutton.rb, ext/tk/lib/tk/scale.rb,
ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tk/text.rb,
ext/tk/lib/tk/toplevel.rb: improve conversion of option values.
* ext/tk/lib/tkextlib/*: ditto.
* ext/tk/lib/tkextlib/*: update to support ActiveTcl8.4.11.2.
* ext/tk/lib/tkextlib/trofs/*: support Trofs 0.4.3.
* ext/tk/lib/tkextlib/tile/*: support Tile 0.7.2.
* ext/tk/lib/tkextlib/vu/*: support vu 2.3.0.
* ext/tk/lib/tkextlib/tcllib/*: support Tcllib 1.8 (Tklib 0.3).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-10-22 22:17:08 +00:00
|
|
|
# TkPackage.require('autoscroll', '1.1')
|
2004-07-15 01:18:57 +00:00
|
|
|
TkPackage.require('autoscroll')
|
|
|
|
|
|
|
|
module Tk
|
|
|
|
module Tcllib
|
|
|
|
class << Autoscroll
|
|
|
|
undef not_available
|
|
|
|
end
|
|
|
|
|
|
|
|
module Autoscroll
|
2004-11-03 08:09:55 +00:00
|
|
|
extend TkCore
|
2004-07-15 01:18:57 +00:00
|
|
|
def self.autoscroll(win)
|
2004-10-11 04:51:21 +00:00
|
|
|
tk_call_without_enc('::autoscroll::autoscroll', win.path)
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.unautoscroll(win)
|
2004-10-11 04:51:21 +00:00
|
|
|
tk_call_without_enc('::autoscroll::unautoscroll', win.path)
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
* ext/tk/extconf.rb: improbe messages [ruby-core:06325].
* ext/tk/lib/tk.rb, ext/tk/lib/tk/canvas.rb, ext/tk/lib/tk/entry.rb,
ext/tk/lib/tk/frame.rb, ext/tk/lib/tk/image.rb,
ext/tk/lib/tk/itemconfig.rb, ext/tk/lib/tk/labelframe.rb,
ext/tk/lib/tk/listbox.rb, ext/tk/lib/tk/menu.rb,
ext/tk/lib/tk/radiobutton.rb, ext/tk/lib/tk/scale.rb,
ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tk/text.rb,
ext/tk/lib/tk/toplevel.rb: improve conversion of option values.
* ext/tk/lib/tkextlib/*: ditto.
* ext/tk/lib/tkextlib/*: update to support ActiveTcl8.4.11.2.
* ext/tk/lib/tkextlib/trofs/*: support Trofs 0.4.3.
* ext/tk/lib/tkextlib/tile/*: support Tile 0.7.2.
* ext/tk/lib/tkextlib/vu/*: support vu 2.3.0.
* ext/tk/lib/tkextlib/tcllib/*: support Tcllib 1.8 (Tklib 0.3).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-10-22 22:17:08 +00:00
|
|
|
|
|
|
|
def self.wrap
|
|
|
|
# v1.1
|
|
|
|
tk_call_without_enc('::autoscroll::wrap')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.unwrap
|
|
|
|
# v1.1
|
|
|
|
tk_call_without_enc('::autoscroll::unwrap')
|
|
|
|
end
|
2004-07-15 01:18:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|