vruby 2004.08.07

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ ###################################
2
+ #
3
+ # clipboard.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 2000-2002 Nishikawa,Yasuhiro
6
+ #
7
+ # More information at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
8
+ # (in Japanese)
9
+ #
10
+ ###################################
11
+
12
+ VR_DIR="vr/" unless defined?(::VR_DIR)
13
+ require VR_DIR+'sysmod'
14
+ require 'Win32API'
15
+
16
+ class Clipboard
17
+ =begin
18
+ == Clipboard
19
+ A class for handling clipboard.
20
+
21
+ === Class Method
22
+ --- open(hwnd)
23
+ opens the clipboard and returns the instance.
24
+ When it is used in iterator style, clipboard is automatically closed
25
+ and returns whether it succeed to close clipboard or not.
26
+
27
+ === Methods
28
+ --- close
29
+ Closes clipboard.
30
+ --- enum_formats
31
+ Enums the clipboard formats to get from clipboard.
32
+ --- getData(format)
33
+ Gets data in the ((|format|)) from clipboard.
34
+ --- setData(format,data)
35
+ Sets data into the clipboard. (clipboard is cleared before set)
36
+ --- getText
37
+ same as getData(VR_CF_TEXT)
38
+ --- setText(string)
39
+ same as setData(VR_CF_TEXT, ((|string|)) )
40
+ =end
41
+
42
+ include ClipboardFormat
43
+ GetClipboardData = Win32API.new('user32','GetClipboardData','I','L')
44
+ SetClipboardData = Win32API.new('user32','SetClipboardData','IL','L')
45
+ EnumClipboardFormats = Win32API.new('user32','EnumClipboardFormats','I','I')
46
+ OpenClipboard = Win32API.new('user32','OpenClipboard','L','I')
47
+ CloseClipboard = Win32API.new('user32','CloseClipboard','V','I')
48
+ EmptyClipboard = Win32API.new('user32','EmptyClipboard','V','I')
49
+
50
+ #
51
+ VR_CF_TEXT = CF_OEMTEXT # modify if you like to use CF_TEXT than CF_OEMTEXT
52
+
53
+ def self.open(*args)
54
+ r = self.new(*args)
55
+ if iterator?
56
+ yield r
57
+ r.close
58
+ else
59
+ return r
60
+ end
61
+ end
62
+
63
+ def initialize(hwnd)
64
+ @hwnd = hwnd
65
+ @opened = (OpenClipboard.call(hwnd)!=0)
66
+ raise "fail to open clipboard" unless defined?(@opened)
67
+ end
68
+
69
+ def close
70
+ @opened = (CloseClipboard.call() == 0)
71
+ end
72
+
73
+ def getData(uformat)
74
+ raise "Clipboard not opened" unless defined?(@opened)
75
+ gmem = GetClipboardData.call(uformat.to_i)
76
+ raise "GetData failed" if gmem==0
77
+ GMEM::Get(gmem) if gmem!=0
78
+ end
79
+
80
+ def setData(uformat,data)
81
+ raise "Clipboard not opened" unless defined? @opened
82
+ EmptyClipboard.call
83
+ gmem = GMEM::AllocStr(66,data)
84
+ SetClipboardData.call(uformat,gmem)
85
+ # GMEM::Free(gmem)
86
+ end
87
+
88
+ def getText
89
+ r=getData(VR_CF_TEXT)
90
+ r.split(/\0/,0)[0]
91
+ end
92
+
93
+ def setText(str)
94
+ setData VR_CF_TEXT,str.to_s
95
+ end
96
+
97
+ def enum_formats
98
+ r=0
99
+ while true do
100
+ r=EnumClipboardFormats.call(r)
101
+ break if r==0
102
+ yield r
103
+ end
104
+ end
105
+ end
106
+
107
+
@@ -0,0 +1,18 @@
1
+ require 'Win32API'
2
+
3
+ if RUBY_VERSION < "1.6" # for 1.5 or 1.4
4
+ def Win32API.new(dll,func,args,retval)
5
+ args = args.split(//) if args.is_a?(String)
6
+ super dll,func,args,retval
7
+ end
8
+ class Object
9
+ alias class :type
10
+ end
11
+
12
+ elsif RUBY_VERSION < "1.7" # for 1.6
13
+
14
+
15
+ #elsif RUBY_VERSION < "1.8" # for 1.7
16
+
17
+ end
18
+
@@ -0,0 +1,12 @@
1
+ class VRUpdown < VRNotifyControl
2
+ alias vrinitnew vrinit
3
+ undef vrinitnew
4
+ def vrinit
5
+ super
6
+ addNotifyHandler(WMsg::UDN_DELTAPOS,"deltapos",
7
+ MSGTYPE::ARGSTRUCT,WStruct::NM_UPDOWN)
8
+ addNotifyHandler(WMsg::UDN_DELTAPOS,"changed",
9
+ MSGTYPE::ARGSTRUCT,WStruct::NM_UPDOWN)
10
+ addFilterArg WMsg::UDN_DELTAPOS,"TF"
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ unless defined?(VREdit) then
2
+ raise "compatibility file must be loaded after its original one."
3
+ end
4
+
5
+ class VREdit
6
+ alias vrinitnew vrinit
7
+ undef vrinitnew
8
+ def vrinit
9
+ super
10
+ addCommandHandler(0x300,"change",MSGTYPE::ARGNONE,nil)
11
+ addCommandHandler(0x300,"changed",MSGTYPE::ARGNONE,nil)
12
+ end
13
+ end
14
+
15
+ class VRListbox
16
+ alias vrinitnew vrinit
17
+ undef vrinitnew
18
+ def vrinit
19
+ super
20
+ addCommandHandler(WMsg::LBN_SELCHANGE, "selchange",MSGTYPE::ARGNONE,nil)
21
+ addCommandHandler(WMsg::LBN_SELCHANGE, "selchanged",MSGTYPE::ARGNONE,nil)
22
+ set_liststrings
23
+ end
24
+
25
+ alias getCount :countStrings
26
+ alias selectedIndex :selectedString
27
+ alias getString :getTextOf
28
+ alias itemString :getTextOf
29
+ alias setItemData :setDataOf
30
+ alias getItemData :getDataOf
31
+ end
32
+
33
+ class VRCombobox
34
+ alias vrinitnew vrinit
35
+ undef vrinitnew
36
+ def vrinit
37
+ super
38
+ set_liststrings
39
+ addCommandHandler(WMsg::CBN_SELCHANGE, "selchange",MSGTYPE::ARGNONE,nil)
40
+ addCommandHandler(WMsg::CBN_SELCHANGE, "selchanged",MSGTYPE::ARGNONE,nil)
41
+ end
42
+
43
+ alias getCount :countStrings
44
+ alias selectedIndex :selectedString
45
+ alias getString :getTextOf
46
+ alias itemString :getTextOf
47
+ alias setItemData :setDataOf
48
+ alias getItemData :getDataOf
49
+
50
+ end
@@ -0,0 +1,24 @@
1
+ unless defined?(VREdit) then
2
+ raise "compatibility file must be loaded after its original one."
3
+ end
4
+
5
+
6
+ class VRMediaView
7
+ def vr_e_compatibility
8
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYMODE,"modechange",MSGTYPE::ARGINT,nil)
9
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYSIZE, "sizechange",MSGTYPE::ARGNONE,nil)
10
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYMEDIA,"mediachange",MSGTYPE::ARGSTRING,nil)
11
+ end
12
+
13
+ alias vrinitnew vrinit
14
+ undef vrinitnew
15
+ def vrinit
16
+ super
17
+ vr_e_compatibility
18
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYERROR,"onerror",MSGTYPE::ARGINT,nil)
19
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYMODE,"modechanged",MSGTYPE::ARGINT,nil)
20
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYSIZE, "sizechanged",MSGTYPE::ARGNONE,nil)
21
+ addMMHandler(VRMediaView::MCIWNDM_NOTIFYMEDIA,"mediachanged",MSGTYPE::ARGSTRING,nil)
22
+ end
23
+ end
24
+
@@ -0,0 +1,111 @@
1
+ ###############################
2
+ #
3
+ # contrib/inifile.rb
4
+ #
5
+ # These modules/classes are contributed by Yukimi_Sake-san.
6
+ # Distributed at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
7
+ #
8
+ ###############################
9
+
10
+
11
+ class Inifile < Hash
12
+ =begin
13
+ ===Inifile
14
+ It makes inifile like Window's in working directory
15
+ [section]
16
+ key=value
17
+ ...
18
+
19
+ ===Methods
20
+ ---deletekey(section,key)
21
+ Delete ((|key|)) and associated value in ((|section|)).
22
+ ---erasesection(section)
23
+ Erase ((|section|)) and associated keys and values.
24
+ ---read( section, key, [default=""])
25
+ Read value associated ((|key|)) in ((|section|)).
26
+ If ((|section|)) or ((|key|)) not exists ,value uses ((|default|)).
27
+ ---write( section, key, value)
28
+ Write ((|value|)) in assiciated ((|key|)) and ((|section|)).
29
+ If ((|section|)) or ((|key|)) not exists , make them.
30
+ ---frash
31
+ Write into ((|inifilename|)) of instance.
32
+ =end
33
+ def initialize(iniFilename) #privatemethod. Use "new(inFilename)" instead.
34
+ sec={}
35
+ section=""
36
+ @fn = Dir.getwd + "/" + iniFilename
37
+ if File.exist?(@fn) then
38
+ f=open @fn
39
+ f.each do |t|
40
+ if t =~ /\[.+\]/ then
41
+ section= t.sub(/\[(.+)\]/,'\1').strip
42
+ sec={section=>{}}
43
+ self.update sec
44
+ elsif t =~/.+=/ then
45
+ a=t.split(/=/)
46
+ val={a[0].strip=>a[1].strip}
47
+ self[section].update(val)
48
+ end
49
+ end
50
+ f.close
51
+ end
52
+ end
53
+
54
+ def deletekey(section,key)
55
+ self[section.strip].delete(key)
56
+ end
57
+
58
+ def erasesection(section)
59
+ self.delete(section)
60
+ end
61
+
62
+ def read( section, key, default="")
63
+ if self[section] && r=self[section][key] then r else default end
64
+ end
65
+
66
+ def write( section, key, value)
67
+ self.update({section.strip=>{}}) if self[section.strip] == nil
68
+ self[section.strip].update({key.strip => (value.to_s).strip})
69
+ end
70
+
71
+ def flash
72
+ f=open @fn,"w"
73
+ self.each do |k,v|
74
+ f.write'['+k+']' +"\n"
75
+ v.each do |k1,v1|
76
+ f.write k1+"="+v1.to_s+"\n"
77
+ end
78
+ end
79
+ f.close
80
+ end
81
+
82
+ end
83
+
84
+ =begin sample
85
+ require 'inifile'
86
+
87
+ ini = Inifile.new ("test.ini") # generate instance and read if
88
+ # targetfile exists
89
+
90
+ p "writing as method"
91
+ ini.write "section1","key11",11
92
+ ini.write "section1","key12",12
93
+ ini.write "section2","key21",21
94
+ ini.write "section2","key22",22
95
+ ini.write "section3","key31",31
96
+ ini.write "section3","key32",32
97
+ p ini.read "section1","key11",101
98
+ p ini.read("section1","key13",103)
99
+ p ini.read("section2","key22",202)
100
+ p ini.read("section2","key23",203)
101
+ p ini.read("section3","key32",302)
102
+ p ini.read("section3","key33",303)
103
+ p "writing as Hash"
104
+ p ini["section1"]["key11"]
105
+ p ini["section2"]
106
+ #ini.deletekey("section1","key12")
107
+ #ini.erasesection("section1")
108
+
109
+ ini.flash # now update inifile
110
+
111
+ =end
@@ -0,0 +1,55 @@
1
+ ###############################
2
+ #
3
+ # contrib/msgboxconst.rb
4
+ #
5
+ # These modules/classes are contributed by Yuya-san.
6
+ # Modified by nyasu <nyasu@osk.3web.ne.jp>
7
+ # Distributed at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
8
+ #
9
+ ###############################
10
+
11
+ #====================================================================#
12
+ # WConst Module
13
+ module WConst
14
+
15
+ MB_USERICON = 128
16
+ MB_ICONASTERISK = 64
17
+ MB_ICONEXCLAMATION = 0x30
18
+ MB_ICONWARNING = 0x30
19
+ MB_ICONERROR = 16
20
+ MB_ICONHAND = 16
21
+ MB_ICONQUESTION = 32
22
+ MB_OK = 0
23
+ MB_ABORTRETRYIGNORE = 2
24
+ MB_APPLMODAL = 0
25
+ MB_DEFAULT_DESKTOP_ONLY = 0x20000
26
+ MB_HELP = 0x4000
27
+ MB_RIGHT = 0x80000
28
+ MB_RTLREADING = 0x100000
29
+ MB_TOPMOST = 0x40000
30
+ MB_DEFBUTTON1 = 0
31
+ MB_DEFBUTTON2 = 256
32
+ MB_DEFBUTTON3 = 512
33
+ MB_DEFBUTTON4 = 0x300
34
+ MB_ICONINFORMATION = 64
35
+ MB_ICONSTOP = 16
36
+ MB_OKCANCEL = 1
37
+ MB_RETRYCANCEL = 5
38
+ MB_SERVICE_NOTIFICATION = 0x40000
39
+ MB_SETFOREGROUND = 0x10000
40
+ MB_SYSTEMMODAL = 4096
41
+ MB_TASKMODAL = 0x2000
42
+ MB_YESNO = 4
43
+ MB_YESNOCANCEL = 3
44
+ MB_ICONMASK = 240
45
+ MB_DEFMASK = 3840
46
+ MB_MODEMASK = 0x00003000
47
+ MB_MISCMASK = 0x0000c000
48
+ MB_NOFOCUS = 0x00008000
49
+ MB_TYPEMASK = 15
50
+
51
+ end
52
+
53
+ #====================================================================#
54
+ # End of source.
55
+ #====================================================================#
@@ -0,0 +1,378 @@
1
+ ###############################
2
+ #
3
+ # contrib/toolbar.rb
4
+ #
5
+ # These modules/classes are contributed by Yukimi_Sake-san.
6
+ # Modified by nyasu <nyasu@osk.3web.ne.jp>
7
+ # Distributed at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
8
+ #
9
+ ###############################
10
+
11
+ module WMsg
12
+ # WM_USER = 0x400
13
+ TB_ENABLEBUTTON = WM_USER + 1
14
+ TB_CHECKBUTTON = WM_USER + 2
15
+ TB_PRESSBUTTON = WM_USER + 3
16
+ TB_HIDEBUTTON = WM_USER + 4
17
+ TB_INDETERMINATE = WM_USER + 5
18
+ TB_ISBUTTONENABLED = WM_USER + 9
19
+ TB_ISBUTTONCHECKED = WM_USER + 10
20
+ TB_ISBUTTONPRESSED = WM_USER + 11
21
+ TB_ISBUTTONHIDDEN = WM_USER + 12
22
+ TB_ISBUTTONINDETERMINATE = WM_USER + 13
23
+ TB_SETSTATE = WM_USER + 17
24
+ TB_GETSTATE = WM_USER + 18
25
+ TB_ADDBITMAP = WM_USER + 19
26
+ TB_ADDBUTTONS = WM_USER + 20
27
+ TB_INSERTBUTTON = WM_USER + 21
28
+ TB_DELETEBUTTON = WM_USER + 22
29
+ TB_GETBUTTON = WM_USER + 23
30
+ TB_BUTTONCOUNT = WM_USER + 24
31
+ TB_COMMANDTOINDEX = WM_USER + 25
32
+ TB_SAVERESTOREA = WM_USER + 26
33
+ TB_SAVERESTOREW = WM_USER + 76
34
+ TB_CUSTOMIZE = WM_USER + 27
35
+ TB_ADDSTRINGA = WM_USER + 28
36
+ TB_GETITEMRECT = WM_USER + 29
37
+ TB_BUTTONSTRUCTSIZE = WM_USER + 30
38
+ TB_SETBUTTONSIZE = WM_USER + 31
39
+ TB_SETBITMAPSIZE = WM_USER + 32
40
+ TB_AUTOSIZE = WM_USER + 33
41
+ TB_GETTOOLTIPS = WM_USER + 35
42
+ TB_SETTOOLTIPS = WM_USER + 36
43
+ TB_SETPARENT = WM_USER + 37
44
+ TB_SETROWS = WM_USER + 39
45
+ TB_GETROWS = WM_USER + 40
46
+ TB_GETBITMAPFLAGS = WM_USER + 41
47
+ TB_SETCMDID = WM_USER + 42
48
+ TB_CHANGEBITMAP = WM_USER + 43
49
+ TB_GETBITMAP = WM_USER + 44
50
+ TB_GETBUTTONTEXTA = WM_USER + 45
51
+ TB_REPLACEBITMAP = WM_USER + 46
52
+ TB_SETINDENT = WM_USER + 47
53
+ TB_SETIMAGELIST = WM_USER + 48
54
+ TB_GETIMAGELIST = WM_USER + 49
55
+ TB_LOADIMAGES = WM_USER + 50
56
+ TB_GETRECT = WM_USER + 51 # wParam is the Cmd instead of index
57
+ TB_SETHOTIMAGELIST = WM_USER + 52
58
+ TB_GETHOTIMAGELIST = WM_USER + 53
59
+ TB_SETDISABLEDIMAGELIST = WM_USER + 54
60
+ TB_GETDISABLEDIMAGELIST = WM_USER + 55
61
+ TB_SETSTYLE = WM_USER + 56
62
+ TB_GETSTYLE = WM_USER + 57
63
+ TB_GETBUTTONSIZE = WM_USER + 58
64
+ TB_SETBUTTONWIDTH = WM_USER + 59
65
+ TB_SETMAXTEXTROWS = WM_USER + 60
66
+ TB_GETTEXTROWS = WM_USER + 61
67
+ TB_GETBUTTONTEXTW = WM_USER + 75
68
+ TB_ADDSTRINGW = WM_USER + 77
69
+
70
+ TBBF_LARGE = 1
71
+
72
+ TB_GETBUTTONINFO = WM_USER + 65
73
+ TB_SETBUTTONINFO = WM_USER + 66
74
+
75
+
76
+ TBN_FIRST = -700
77
+ TBN_GETBUTTONINFO = TBN_FIRST-0
78
+ TBN_BEGINDRAG = TBN_FIRST-1
79
+ TBN_ENDDRAG = TBN_FIRST-2
80
+ TBN_BEGINADJUST = TBN_FIRST-3
81
+ TBN_ENDADJUST = TBN_FIRST-4
82
+ TBN_RESET = TBN_FIRST-5
83
+ TBN_QUERYINSERT = TBN_FIRST-6
84
+ TBN_QUERYDELETE = TBN_FIRST-7
85
+ TBN_TOOLBARCHANGE = TBN_FIRST-8
86
+ TBN_CUSTHELP = TBN_FIRST-9
87
+ TBN_GETBUTTONINFOW = TBN_FIRST-20
88
+ end
89
+
90
+ module WConst
91
+ TBSTATE_CHECKED = 1
92
+ TBSTATE_PRESSED = 2
93
+ TBSTATE_ENABLED = 4
94
+ TBSTATE_HIDDEN = 8
95
+ TBSTATE_INDETERMINATE = 16
96
+ TBSTATE_WRAP = 32
97
+
98
+ TBSTYLE_BUTTON = 0
99
+ TBSTYLE_SEP = 1
100
+ TBSTYLE_CHECK = 2
101
+ TBSTYLE_GROUP = 4
102
+ TBSTYLE_CHECKGROUP = (TBSTYLE_GROUP|TBSTYLE_CHECK)
103
+ TBSTYLE_TOOLTIPS = 256
104
+ TBSTYLE_WRAPABLE = 512
105
+ TBSTYLE_ALTDRAG = 1024
106
+ TBSTYLE_FLAT = 2048
107
+
108
+
109
+ TBIF_IMAGE = 0x00000001
110
+ TBIF_TEXT = 0x00000002
111
+ TBIF_STATE = 0x00000004
112
+ TBIF_STYLE = 0x00000008
113
+ TBIF_LPARAM = 0x00000010
114
+ TBIF_COMMAND = 0x00000020
115
+ TBIF_SIZE = 0x00000040
116
+ end
117
+
118
+ module WStruct
119
+ TB_BUTTON = "IICCCCLI"
120
+ # int iBitmap;int idCommand; BYTE fsState; BYTE fsStyle;
121
+ # BYTE[2] fsReserved; DWORD dwData;int iString;
122
+ TBNOTIFY = NMHDR+"I"+TB_BUTTON+"IP"
123
+ # NMHDR hdr; int iItem; TBBUTTON tbButton;
124
+ # int cchText; LPTSTR pszText;
125
+ TBADDBITMAP="UU"
126
+ #HINSTANCE hInst; UINT nID;
127
+
128
+ end
129
+
130
+ module VRToolbarUseable
131
+ =begin
132
+ == VRToolbarUseable
133
+ If you include this module in parent, you can solve the fault of a notify
134
+ events at the time of including a VRComCtlContainer, since toolbar buttons
135
+ are set to _vr_toolbar_buttons which is an original variable.
136
+ When not including this module , toolbar buttons are set to _vr_contorols
137
+ for back compatibility.
138
+ =end
139
+ require 'vr/vrcontrol'
140
+ include VRStdControlContainer
141
+ attr :_vr_toolbar_buttons
142
+ alias self_wmcommand_org self_wmcommand
143
+
144
+ def self_wmcommand(msg)
145
+ if @_vr_toolbar_buttons then
146
+ tbbid=LOWORD(msg.wParam)
147
+ tbbmid=HIWORD(msg.wParam)
148
+ c = @_vr_toolbar_buttons[tbbid]
149
+ if c then
150
+ c._vr_cmdhandlers[tbbmid].each{|shandler|
151
+ args=msgarg2handlerarg(shandler[1],msg,shandler[2])
152
+ c.send(shandler[0],*args) if c.respond_to?(shandler[0])
153
+ msg.retval = controlmsg_dispatching(c,shandler[0],*args)
154
+ } if c._vr_cmdhandlers and c._vr_cmdhandlers[tbbmid]
155
+ end
156
+ end
157
+ self_wmcommand_org(msg)
158
+ end
159
+
160
+ def registerToolbarButton(c,name,id)
161
+ @_vr_toolbar_buttons = {} unless @_vr_toolbar_buttons
162
+ c.etc= id
163
+ c.name=name
164
+ @_vr_toolbar_buttons[id]=c
165
+ end
166
+
167
+ end
168
+
169
+ class VRToolbar < VRNotifyControl
170
+ =begin
171
+ == VRToolbar
172
+ This class represents Toolbar.
173
+
174
+ === Methods
175
+ --- insertButton(i,name,style=TBSTYLE_BUTTON)
176
+ Inserts a button as ((|i|))-th button. ((|style|)) can be
177
+ a constant in WConst such as TBSTYLE_BUTTON (default),
178
+ TBSTYLE_SEP (separator), TBSTYLE_CHECK,...
179
+ --- addButton(style)
180
+ Adds a button at last of the buttons.
181
+ --- deleteButton(i)
182
+ Deletes a button at ((|i|))-th.
183
+ --- clearButtons
184
+ Deletes all buttons.
185
+ --- countButtons
186
+ Counts buttons.
187
+ --- setImagelist(imglist)
188
+ Sets the imagelist for the toolbar. ((|imglist|)) must be an instance of
189
+ SWin::Imagelist.
190
+ --- setParent(hwnd)
191
+ Sets the window to nofify command messages.
192
+ --- autoSize
193
+ Resizes toolbar.
194
+ --- indeterminateOf(i,bool=true)
195
+ Sets the indeterminate state of the ((|i|))-th button.
196
+ --- commandToIndex(id)
197
+ Retrieves the index number for the button whose id is ((|id|)).
198
+ This id is used in WM_COMMAND messages.
199
+ --- enableButton(i,bool=true)
200
+ Enables or disables the ((|i|))-th button.
201
+ --- getButtonStateOf(id)
202
+ Gets the state of the button whose id is ((|id|)).
203
+ --- setButtonStateOf(i,state)
204
+ Sets the state of the button whose id is ((|id|)).
205
+ --- setButtons(buttons)
206
+ Sets the array of ((|button|)) to a tool bar at once.
207
+ ((|button|)) must be an array of ((|[name,style]|))
208
+ --- enumButtons
209
+ Yields all toolbar buttons which are instance of
210
+ VRToolbar::VRToolbarButton.
211
+ === Event Handler
212
+ --- ????_clicked
213
+ Fired when the button clicked.
214
+
215
+ == VRToolbar::VRToolbarButton
216
+ This class is for each toolbar buttons. This resemble menus in using it.
217
+
218
+ === Methods
219
+ --- state
220
+ Returns the state of the button.
221
+ --- checked?
222
+ Returns true if the button is checked/pushed.
223
+ =end
224
+
225
+ include WConst
226
+
227
+ class VRToolbarButton
228
+ attr :name,1
229
+ attr :etc,1
230
+ attr :index
231
+ attr :toolbar
232
+
233
+ def _vr_cmdhandlers
234
+ {0=>[["clicked",MSGTYPE::ARGNONE,nil]]}
235
+ end
236
+
237
+ def initialize(i,toolbar)
238
+ @index,@toolbar = i,toolbar
239
+ end
240
+
241
+ def state
242
+ @toolbar.getButtonStateOf(@etc)
243
+ end
244
+
245
+ def checked?
246
+ (state&1)==1
247
+ end
248
+
249
+ end
250
+
251
+ def VRToolbar.Controltype() ["ToolbarWindow32",0] end
252
+
253
+ def vrinit
254
+ super
255
+ sendMessage WMsg::TB_BUTTONSTRUCTSIZE ,20,0
256
+ if defined?(VRTooltip) and defined?(@parent.tooltip) and @parent.tooltip then
257
+ sendMessage WMsg::TB_SETTOOLTIPS,@parent.tooltip.hWnd,0
258
+ end
259
+ end
260
+
261
+ def setButtonText(i,text)
262
+ if text.length>0 then
263
+ iid = indexToCommand(i)
264
+ tbi = [4*8,WConst::TBIF_TEXT,iid,0,0,0,text,text.length].pack("llllilpl")
265
+ sendMessage WMsg::TB_SETBUTTONINFO,i,tbi
266
+ end
267
+ end
268
+
269
+ def insertButton(i,name,tbStyle=TBSTYLE_BUTTON)
270
+ @_vr_tbbuttons = -1 unless defined?(@_vr_tbbuttons)
271
+ @_vr_tbbuttons += 1 unless tbStyle == TBSTYLE_SEP
272
+ id = @parent.newControlID
273
+ tbb=@screen.application.arg2cstructStr(WStruct::TB_BUTTON,
274
+ @_vr_tbbuttons,id,
275
+ ((tbStyle == TBSTYLE_SEP)? 0 : 4),tbStyle,0,0,0,0)
276
+ sendMessage WMsg::TB_INSERTBUTTON,i,tbb
277
+ i = commandToIndex(id)
278
+ r=VRToolbarButton.new(i,self)
279
+ if @parent.respond_to?(:registerToolbarButton) then
280
+ @parent.registerToolbarButton(r,name,id)
281
+ else
282
+ @parent.registerControl(r,name,id)
283
+ end
284
+ r
285
+ end
286
+
287
+ def addButton(name,tbStyle=TBSTYLE_BUTTON)
288
+ insertButton(0xffff,name,tbStyle)
289
+ end
290
+
291
+ def deleteButton(i)
292
+ sendMessage WMsg::TB_DELETEBUTTON,i,0
293
+ end
294
+
295
+ def countButtons
296
+ r=sendMessage WMsg::TB_BUTTONCOUNT,0,0
297
+ end
298
+
299
+ def clearButtons
300
+ (countButtons-1).downto(0) do |i|
301
+ deleteButton(i)
302
+ refresh
303
+ end
304
+ end
305
+
306
+ def setParent(win)
307
+ hwnd = if win.is_a?(SWin::Window) then win.hwnd else win end
308
+ sendMessage WMsg::TB_SETPARENT,hwnd,0
309
+ end
310
+
311
+ def autoSize
312
+ sendMessage WMsg::TB_AUTOSIZE ,0,0
313
+ refresh
314
+ end
315
+
316
+ def indeterminateOf(i,bool=true)
317
+ sendMessage WMsg::TB_INDETERMINATE,i,(if bool then -1 else 0 end)
318
+ end
319
+
320
+ def setImagelist(imagelist)
321
+ raise "not Imagelist" unless imagelist.is_a?(SWin::Imagelist)
322
+ self.properties["imagelist"]=imagelist
323
+ sendMessage WMsg::TB_SETIMAGELIST,0,imagelist.himagelist
324
+ refresh
325
+ end
326
+
327
+ def setDisabledImagelist(imagelist)
328
+ raise "not Imagelist" unless imagelist.is_a?(SWin::Imagelist)
329
+ self.properties["disabled_imagelist"]=imagelist
330
+ sendMessage WMsg::TB_SETDISABLEDIMAGELIST,0,imagelist.himagelist
331
+ refresh
332
+ end
333
+
334
+ def commandToIndex(id)
335
+ sendMessage WMsg::TB_COMMANDTOINDEX,id,0
336
+ end
337
+
338
+ def indexToCommand(i)
339
+ getButton(i)[1]
340
+ end
341
+
342
+ def checked?(i)
343
+ (getButtonStateOf(i) & 1)==1
344
+ end
345
+
346
+ def setButtonStateOf(id,state)
347
+ sendMessage WMsg::TB_SETSTATE,id,state
348
+ end
349
+
350
+ def getButtonStateOf(id)
351
+ sendMessage WMsg::TB_GETSTATE,id,0
352
+ end
353
+
354
+ def enableButton(id,bool=true)
355
+ sendMessage WMsg::TB_ENABLEBUTTON,id,(if bool then 1 else 0 end)
356
+ end
357
+
358
+ def getButton(i)
359
+ tbb=@screen.application.arg2cstructStr(WStruct::TB_BUTTON,
360
+ 0,0,0,0,0,0,0,0)
361
+ sendMessage WMsg::TB_GETBUTTON ,i ,tbb
362
+ @screen.application.unpack(tbb,WStruct::TB_BUTTON)
363
+ end
364
+
365
+ def setButtons(a)
366
+ a.each{|i| addButton(i[0], (i[1] ? i[1] : TBSTYLE_BUTTON))}
367
+ end
368
+
369
+ def enumButtons
370
+ raise "Use VRToolbarUseable" unless parent.respond_to? :_vr_toolbar_buttons
371
+ n = countButtons
372
+ raise "unknown error" unless n == parent._vr_toolbar_buttons.size
373
+ parent._vr_toolbar_buttons.each{|key,val|
374
+ yield val
375
+ }
376
+ end
377
+
378
+ end