summaryrefslogtreecommitdiff
path: root/trunk/ext/tk/sample/demos-jp/toolbar.rb
blob: 1bb265d1f8cff43e16af256edc4b3d8cbfbf5141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: euc-jp -*-
#
# toolbar.rb --
#
# This demonstration script creates a toolbar that can be torn off.
#
# based on "Id: toolbar.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"

if defined?($toolbar_demo) && $toolbar_demo
  $toolbar_demo.destroy 
  $toolbar_demo = nil
end

$toolbar_demo = TkToplevel.new {|w|
  title("Ttk Menu Buttons")
  iconname("toolbar")
  positionWindow(w)
}

base_frame = Ttk::Frame.new($toolbar_demo).pack(:fill=>:both, :expand=>true)

if Tk.windowingsystem != 'aqua'
  msg = Ttk::Label.new(base_frame, :wraplength=>'4i', :text=><<EOL)
¤³¤Î¥Ç¥â¤Ç¤Ï¡¤¥Ä¡¼¥ë¥Ð¡¼¤ò¤É¤Î¤è¤¦¤Ë¤·¤ÆŬÀڤ˥ơ¼¥ÞÂбþ¤µ¤»¤ë¤«¡¤\
¤Þ¤¿¡¤¤É¤Î¤è¤¦¤Ë¤·¤ÆÀÚ¤êÎ¥¤·²Äǽ¤Ë¤¹¤ë¤«¤ò¼¨¤·¤Æ¤¤¤Þ¤¹\
¡Ê¤¿¤À¤·¡¤¥Ä¡¼¥ë¥Ð¡¼¤ÎÀÚ¤êÎ¥¤·¤Ë¤ÏTcl/Tk8.5°Ê¾å¤Îµ¡Ç½¤¬É¬ÍפǤ¹¡Ë¡¥\
¥Ä¡¼¥ë¥Ð¡¼¤Î¥Ü¥¿¥ó¤Ï¡¤'Toolbutton'¥¹¥¿¥¤¥ë¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÌÀ¼¨¤¹¤ë¤³¤È¤Ç¡¤\
"toolbar style"¥Ü¥¿¥ó¤È¤Ê¤ë¤è¤¦¤Ë°À­ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡¥\
¥Ä¡¼¥ë¥Ð¡¼¤Îº¸Ã¼¤Ë¤Ï´Êñ¤Ê¥Þ¡¼¥«¡¼¤¬ÃÖ¤«¤ì¤Æ¤¤¤Þ¤¹¡¥\
¥Þ¡¼¥«¡¼¾å¤Ë¥Þ¥¦¥¹¥«¡¼¥½¥ë¤¬Íè¤ë¤È°ÜÆ°¥¢¥¤¥³¥ó¤Ë¥«¡¼¥½¥ë¤¬ÊѲ½¤·¤Þ¤¹¡¥\
¤½¤³¤Ç¥Ä¡¼¥ë¥Ð¡¼¤òÆ°¤«¤¹¤è¤¦¤Ë¥É¥é¥Ã¥°¤¹¤ë¤È¡¤\
¥Ä¡¼¥ë¥Ð¡¼Á´ÂΤòÀÚ¤êÎ¥¤·¤ÆÆÈΩ¤·¤¿¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥È¤Ë\
¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\
ÀÚ¤êÎ¥¤·¤¿¥Ä¡¼¥ë¥Ð¡¼¤¬ÉÔÍפȤʤä¿»þ¤Ë¤Ï¡¤\
°ìÈÌŪ¤Ê¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥È¤ÈƱÍͤËñ½ã¤ËÊĤ¸¤ë¤³¤È¤Ç¡¤
ºÆ¤Ó¸µ¤Î¥¦¥£¥ó¥É¥¦¤ËÄ¥¤êÉÕ¤±¤é¤ì¤ë¤Ç¤·¤ç¤¦¡¥
EOL
else
  msg = Ttk::Label.new(base_frame, :wraplength=>'4i', :text=><<EOL)
¤³¤Î¥Ç¥â¤Ç¤Ï¡¤¥Ä¡¼¥ë¥Ð¡¼¤ò¤É¤Î¤è¤¦¤Ë¤·¤ÆŬÀڤ˥ơ¼¥ÞÂбþ¤µ¤»¤ë¤«¤ò\
¼¨¤·¤Æ¤¤¤Þ¤¹¡¥\
¥Ä¡¼¥ë¥Ð¡¼¤Î¥Ü¥¿¥ó¤Ï¡¤'Toolbutton'¥¹¥¿¥¤¥ë¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÌÀ¼¨¤¹¤ë¤³¤È¤Ç¡¤\
"toolbar style"¥Ü¥¿¥ó¤È¤Ê¤ë¤è¤¦¤Ë°À­ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡¥
EOL
end

## Set up the toolbar hull
tbar_base = Tk::Frame.new(base_frame,  # Tk ɸ½à¤Î frame ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥
                          :widgetname=>'toolbar') # ¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ëʸ»úÎó¤È¤¹¤ë¤¿¤á¤Ë¡¤¥¦¥£¥¸¥§¥Ã¥È̾¤òÌÀ¼¨¤·¤Æ¤¤¤Þ¤¹¡¥
sep = Ttk::Separator.new(base_frame)
to_base = Ttk::Frame.new(tbar_base, :cursor=>'fleur')
if Tk.windowingsystem != 'aqua'
  to  = Ttk::Separator.new(to_base, :orient=>:vertical)
  to2 = Ttk::Separator.new(to_base, :orient=>:vertical)
  to.pack(:fill=>:y, :expand=>true, :padx=>2, :side=>:left)
  to2.pack(:fill=>:y, :expand=>true, :side=>:left)
end

contents = Ttk::Frame.new(tbar_base)
Tk.grid(to_base, contents, :sticky=>'nsew')
tbar_base.grid_columnconfigure(contents, :weight=>1)
contents.grid_columnconfigure(1000, :weight=>1)

if Tk.windowingsystem != 'aqua'
  ## Bindings so that the toolbar can be torn off and reattached
  to_base.bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
  to.     bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
  to2.    bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)}
  def tbar_base.tearoff(w, x, y)
    on_win = TkWinfo.containing(x, y)
    return unless (on_win && on_win.path =~ /^#{@path}(\.|$)/)
    self.grid_remove
    w.grid_remove
    self.wm_manage
    # self.wm_title('Toolbar') # ¤â¤·¥¦¥£¥¸¥§¥Ã¥È̾¤ò¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ë¤Ë¤·¤¿¤¯¤Ê¤¤¤Ê¤é¡¤¤³¤³¤ÇÀßÄꤷ¤Æ¤¯¤À¤µ¤¤
    self.wm_protocol('WM_DELETE_WINDOW'){ self.untearoff(w) }
  end
  def tbar_base.untearoff(w)
    self.wm_forget
    w.grid
    self.grid
  end
end

## Some content for the rest of the toplevel
text = TkText.new(base_frame, :width=>40, :height=>10)

## Toolbar contents
tb_btn = Ttk::Button.new(tbar_base, :text=>'¥Ü¥¿¥ó', :style=>'Toolbutton', 
                         :command=>proc{
                           text.insert(:end, "¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤Þ¤·¤¿¡¥\n")
                         })
tb_chk = Ttk::Checkbutton.new(tbar_base, :text=>'¥Á¥§¥Ã¥¯¥Ü¥¿¥ó', 
                              :style=>'Toolbutton', 
                              :variable=>(check = TkVariable.new), 
                              :command=>proc{
                                text.insert(:end, "¥Á¥§¥Ã¥¯¥Ü¥¿¥ó¤ÎÃͤÏ#{check.value}¤Ç¤¹¡¥\n")
                              })
tb_mbtn = Ttk::Menubutton.new(tbar_base, :text=>'¥á¥Ë¥å¡¼')
tb_combo = Ttk::Combobox.new(tbar_base, :value=>TkFont.families, 
                             :state=>:readonly)
tb_mbtn.menu(menu = Tk::Menu.new(tb_mbtn))
menu.add(:command, :label=>'Just', :command=>proc{text.insert(:end, "Just\n")})
menu.add(:command, :label=>'An', :command=>proc{text.insert(:end, "An\n")})
menu.add(:command, :label=>'Example', 
         :command=>proc{text.insert(:end, "Example\n")})
tb_combo.bind('<ComboboxSelected>'){ text.font.family = tb_combo.get }

## Arrange contents
Tk.grid(tb_btn, tb_chk, tb_mbtn, tb_combo, 
        :in=>contents, :padx=>2, :sticky=>'ns')
Tk.grid(tbar_base, :sticky=>'ew')
Tk.grid(sep, :sticky=>'ew')
Tk.grid(msg, :sticky=>'ew')
Tk.grid(text, :sticky=>'nsew')
base_frame.grid_rowconfigure(text, :weight=>1)
base_frame.grid_columnconfigure(text, :weight=>1)

## See Code / Dismiss buttons
Ttk::Frame.new(base_frame) {|frame|
  sep = Ttk::Separator.new(frame)
  Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
  TkGrid('x', 
         Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', 
                         :image=>$image['view'], :compound=>:left, 
                         :command=>proc{showCode 'toolbar'}), 
         Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', 
                         :image=>$image['delete'], :compound=>:left, 
                         :command=>proc{
                           $toolbar_demo.destroy
                           $toolbar_demo = nil
                         }), 
         :padx=>4, :pady=>4)
  grid_columnconfigure(0, :weight=>1)
  Tk.grid(frame, :sticky=>'ew')
}