~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/lib/tk/scrollbar.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# tk/scrollbar.rb : treat scrollbar widget
 
3
#
 
4
require 'tk'
 
5
 
 
6
class TkScrollbar<TkWindow
 
7
  TkCommandNames = ['scrollbar'.freeze].freeze
 
8
  WidgetClassName = 'Scrollbar'.freeze
 
9
  WidgetClassNames[WidgetClassName] = self
 
10
 
 
11
  def create_self(keys)
 
12
    @assigned = []
 
13
    @scroll_proc = proc{|*args| 
 
14
      if self.orient == 'horizontal'
 
15
        @assigned.each{|w| w.xview(*args)}
 
16
      else # 'vertical'
 
17
        @assigned.each{|w| w.yview(*args)}
 
18
      end
 
19
    }
 
20
 
 
21
    if keys and keys != None
 
22
      #tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true))
 
23
      tk_call_without_enc(self.class::TkCommandNames[0], @path, 
 
24
                          *hash_kv(keys, true))
 
25
    else
 
26
      #tk_call_without_enc('scrollbar', @path)
 
27
      tk_call_without_enc(self.class::TkCommandNames[0], @path)
 
28
    end
 
29
  end
 
30
  private :create_self
 
31
 
 
32
  def propagate_set(src_win, first, last)
 
33
    self.set(first, last)
 
34
    if self.orient == 'horizontal'
 
35
      @assigned.each{|w| w.xview('moveto', first) if w != src_win}
 
36
    else # 'vertical'
 
37
      @assigned.each{|w| w.yview('moveto', first) if w != src_win}
 
38
    end
 
39
  end
 
40
 
 
41
  def assign(*wins)
 
42
    begin
 
43
      self.command(@scroll_proc) if self.cget('command').cmd != @scroll_proc
 
44
    rescue Exception
 
45
      self.command(@scroll_proc)
 
46
    end
 
47
    orient = self.orient
 
48
    wins.each{|w|
 
49
      @assigned << w unless @assigned.index(w)
 
50
      if orient == 'horizontal'
 
51
        w.xscrollcommand proc{|first, last| self.propagate_set(w, first, last)}
 
52
      else # 'vertical'
 
53
        w.yscrollcommand proc{|first, last| self.propagate_set(w, first, last)}
 
54
      end
 
55
    }
 
56
    Tk.update  # avoid scrollbar trouble
 
57
    self
 
58
  end
 
59
 
 
60
  def assigned_list
 
61
    begin
 
62
      return @assigned.dup if self.cget('command').cmd == @scroll_proc
 
63
    rescue Exception
 
64
    end
 
65
    fail RuntimeError, "not depend on the assigned_list"
 
66
  end
 
67
 
 
68
  def configure(*args)
 
69
    ret = super(*args)
 
70
    # Tk.update  # avoid scrollbar trouble
 
71
    ret
 
72
  end
 
73
 
 
74
  #def delta(deltax=None, deltay=None)
 
75
  def delta(deltax, deltay)
 
76
    number(tk_send_without_enc('delta', deltax, deltay))
 
77
  end
 
78
 
 
79
  #def fraction(x=None, y=None)
 
80
  def fraction(x, y)
 
81
    number(tk_send_without_enc('fraction', x, y))
 
82
  end
 
83
 
 
84
  def identify(x, y)
 
85
    tk_send_without_enc('identify', x, y)
 
86
  end
 
87
 
 
88
  def get
 
89
    #ary1 = tk_send('get').split
 
90
    #ary2 = []
 
91
    #for i in ary1
 
92
    #  ary2.push number(i)
 
93
    #end
 
94
    #ary2
 
95
    list(tk_send_without_enc('get'))
 
96
  end
 
97
 
 
98
  def set(first, last)
 
99
    tk_send_without_enc('set', first, last)
 
100
    self
 
101
  end
 
102
 
 
103
  def activate(element=None)
 
104
    tk_send_without_enc('activate', element)
 
105
  end
 
106
end
 
107
 
 
108
class TkXScrollbar<TkScrollbar
 
109
  def create_self(keys)
 
110
    keys = {} unless keys
 
111
    keys['orient'] = 'horizontal'
 
112
    super(keys)
 
113
  end
 
114
  private :create_self
 
115
end
 
116
 
 
117
class TkYScrollbar<TkScrollbar
 
118
  def create_self(keys)
 
119
    keys = {} unless keys
 
120
    keys['orient'] = 'vertical'
 
121
    super(keys)
 
122
  end
 
123
  private :create_self
 
124
end