exerb 6.0.1

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.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/ChangeLog.ja.rd +305 -0
  4. data/README.en.txt +12 -0
  5. data/README.ja.html +143 -0
  6. data/README.ja.txt +6 -0
  7. data/README.md +50 -0
  8. data/Rakefile +205 -0
  9. data/bin/exerb +185 -0
  10. data/bin/mkexy +47 -0
  11. data/doc/LGPL +513 -0
  12. data/doc/class.ja.html +92 -0
  13. data/doc/command.ja.html +109 -0
  14. data/doc/core.ja.html +72 -0
  15. data/doc/example.ja.html +89 -0
  16. data/doc/faq.ja.html +59 -0
  17. data/doc/inside.ja.rd +404 -0
  18. data/doc/license.ja.html +62 -0
  19. data/doc/logo.gif +0 -0
  20. data/doc/misc.ja.html +72 -0
  21. data/doc/navi.gif +0 -0
  22. data/doc/recipe.ja.html +317 -0
  23. data/doc/style.css +187 -0
  24. data/doc/tutorial.ja.html +182 -0
  25. data/example/Makefile +54 -0
  26. data/example/cat_n.rb +14 -0
  27. data/example/exception.rb +9 -0
  28. data/example/ext/Win32API.so +0 -0
  29. data/example/ext/swin.so +0 -0
  30. data/example/msgbox.rb +14 -0
  31. data/example/rubytk.rb +22 -0
  32. data/example/runtime.ico +0 -0
  33. data/example/runtime.rb +19 -0
  34. data/example/vr/clipboard.rb +106 -0
  35. data/example/vr/compat/rubycompat.rb +18 -0
  36. data/example/vr/compat/vrcomctl.rb +12 -0
  37. data/example/vr/compat/vrcontrol.rb +50 -0
  38. data/example/vr/compat/vrmmedia.rb +24 -0
  39. data/example/vr/contrib/inifile.rb +116 -0
  40. data/example/vr/contrib/msgboxconst.rb +55 -0
  41. data/example/vr/contrib/toolbar.rb +371 -0
  42. data/example/vr/contrib/vrctlcolor.rb +110 -0
  43. data/example/vr/contrib/vrhotkey.rb +35 -0
  44. data/example/vr/contrib/vrlistviewex.rb +71 -0
  45. data/example/vr/contrib/vrstdscrollbar.rb +414 -0
  46. data/example/vr/contrib/vrwincomponent.rb +54 -0
  47. data/example/vr/dragdropformat.rb +209 -0
  48. data/example/vr/rscutil.rb +168 -0
  49. data/example/vr/sysmod.rb +249 -0
  50. data/example/vr/vractivex.rb +56 -0
  51. data/example/vr/vrclipboard.rb +53 -0
  52. data/example/vr/vrcomctl.rb +1819 -0
  53. data/example/vr/vrcontrol.rb +1374 -0
  54. data/example/vr/vrdde.rb +623 -0
  55. data/example/vr/vrddrop.rb +190 -0
  56. data/example/vr/vrdialog.rb +406 -0
  57. data/example/vr/vrhandler.rb +195 -0
  58. data/example/vr/vrlayout.old.rb +209 -0
  59. data/example/vr/vrlayout.rb +173 -0
  60. data/example/vr/vrlayout2.rb +340 -0
  61. data/example/vr/vrmargin.rb +141 -0
  62. data/example/vr/vrmgdlayout.rb +381 -0
  63. data/example/vr/vrmmedia.rb +287 -0
  64. data/example/vr/vrolednd.rb +192 -0
  65. data/example/vr/vrowndraw.rb +108 -0
  66. data/example/vr/vrrichedit.rb +366 -0
  67. data/example/vr/vrtimer.rb +148 -0
  68. data/example/vr/vrtooltip.rb +273 -0
  69. data/example/vr/vrtray.rb +143 -0
  70. data/example/vr/vrtvitem.rb +118 -0
  71. data/example/vr/vrtwopane.rb +223 -0
  72. data/example/vr/vruby.rb +1051 -0
  73. data/example/vr/winconst.rb +158 -0
  74. data/example/vruby.rb +38 -0
  75. data/exerb.gemspec +26 -0
  76. data/extconf.rb +7 -0
  77. data/lib/exerb/archive.rb +143 -0
  78. data/lib/exerb/config.rb +51 -0
  79. data/lib/exerb/error.rb +15 -0
  80. data/lib/exerb/executable.rb +68 -0
  81. data/lib/exerb/file_table.rb +189 -0
  82. data/lib/exerb/mkexy.rb +81 -0
  83. data/lib/exerb/name_table.rb +120 -0
  84. data/lib/exerb/recipe.rb +465 -0
  85. data/lib/exerb/resource.rb +190 -0
  86. data/lib/exerb/resource/base.rb +29 -0
  87. data/lib/exerb/resource/binary.rb +31 -0
  88. data/lib/exerb/resource/dialog.rb +30 -0
  89. data/lib/exerb/resource/group_icon.rb +85 -0
  90. data/lib/exerb/resource/icon.rb +52 -0
  91. data/lib/exerb/resource/version_info.rb +155 -0
  92. data/lib/exerb/resource_library.rb +120 -0
  93. data/lib/exerb/utility.rb +95 -0
  94. data/lib/exerb/utility2.rb +122 -0
  95. data/lib/exerb/version.rb +13 -0
  96. data/lib/exerb/win32/const/resource.rb +51 -0
  97. data/lib/exerb/win32/icon_file.rb +78 -0
  98. data/lib/exerb/win32/pe_file.rb +59 -0
  99. data/lib/exerb/win32/resource_directory.rb +105 -0
  100. data/lib/exerb/win32/resource_directory_root.rb +67 -0
  101. data/lib/exerb/win32/resource_entry.rb +98 -0
  102. data/lib/exerb/win32/struct/base.rb +43 -0
  103. data/lib/exerb/win32/struct/icon_dir_entry.rb +83 -0
  104. data/lib/exerb/win32/struct/icon_header.rb +43 -0
  105. data/lib/exerb/win32/struct/icon_res_entry.rb +48 -0
  106. data/lib/exerb/win32/struct/image_dos_header.rb +73 -0
  107. data/lib/exerb/win32/struct/image_file_header.rb +47 -0
  108. data/lib/exerb/win32/struct/image_nt_headers32.rb +53 -0
  109. data/lib/exerb/win32/struct/image_optional_header32.rb +107 -0
  110. data/lib/exerb/win32/struct/image_resource_data_entry.rb +45 -0
  111. data/lib/exerb/win32/struct/image_resource_directory.rb +47 -0
  112. data/lib/exerb/win32/struct/image_resource_directory_entry.rb +72 -0
  113. data/lib/exerb/win32/struct/image_section_header.rb +53 -0
  114. data/lib/exerb/win32/struct/version_info_block.rb +75 -0
  115. data/lib/exerb/win32/struct/vs_fixed_file_info.rb +62 -0
  116. data/src/exerb/cui.c +48 -0
  117. data/src/exerb/default.rb +1 -0
  118. data/src/exerb/exerb.c +877 -0
  119. data/src/exerb/exerb.h +92 -0
  120. data/src/exerb/gui.c +176 -0
  121. data/src/exerb/module.c +138 -0
  122. data/src/exerb/module.h +7 -0
  123. data/src/exerb/patch.c +27 -0
  124. data/src/exerb/resource.h +22 -0
  125. data/src/exerb/resource.rc +121 -0
  126. data/src/exerb/ruby.ico +0 -0
  127. data/src/exerb/utility.c +263 -0
  128. data/src/exerb/utility.h +33 -0
  129. data/test/alltests.rb +16 -0
  130. data/test/test-argv.rb +26 -0
  131. data/test/test-argv/test-argv.rb +9 -0
  132. data/test/test-argv/test-argv.ret +1 -0
  133. data/test/test-dollarzero.rb +26 -0
  134. data/test/test-dollarzero/test-dollarzero.rb +10 -0
  135. data/test/test-dollarzero/test-dollarzero.ret +2 -0
  136. data/test/test-dot.rb +26 -0
  137. data/test/test-dot/dot.dot.dot.rb +9 -0
  138. data/test/test-dot/dot.dot.rb +9 -0
  139. data/test/test-dot/test-dot.rb +13 -0
  140. data/test/test-dot/test-dot.ret +5 -0
  141. data/test/test-exitcode.rb +28 -0
  142. data/test/test-exitcode/test-exitcode.rb +9 -0
  143. data/test/test-kcode.rb +43 -0
  144. data/test/test-kcode/euc.rb +10 -0
  145. data/test/test-kcode/euc.ret +2 -0
  146. data/test/test-kcode/none.rb +10 -0
  147. data/test/test-kcode/none.ret +2 -0
  148. data/test/test-kcode/sjis.rb +10 -0
  149. data/test/test-kcode/sjis.ret +2 -0
  150. data/test/test-kcode/utf8.rb +10 -0
  151. data/test/test-kcode/utf8.ret +2 -0
  152. data/test/test-loadpath.rb +24 -0
  153. data/test/test-loadpath/test-loadpath.rb +9 -0
  154. data/test/test-nest.rb +18 -0
  155. data/test/test-nest/foo.rb +1 -0
  156. data/test/test-nest/foo/bar.rb +2 -0
  157. data/test/test-nest/foo/foo.rb +1 -0
  158. data/test/test-nest/test-nest.rb +1 -0
  159. data/test/test-nest/test-nest.ret +1 -0
  160. data/test/test-preload.rb +24 -0
  161. data/test/test-preload/test-preload.rb +9 -0
  162. data/test/test-regexp.rb +26 -0
  163. data/test/test-regexp/test-regexp.rb +23 -0
  164. data/test/test-regexp/test-regexp.ret +13 -0
  165. data/test/test-require1.rb +26 -0
  166. data/test/test-require1/require1.rb +9 -0
  167. data/test/test-require1/require2.rb +9 -0
  168. data/test/test-require1/require3.rb +9 -0
  169. data/test/test-require1/require4.rb +9 -0
  170. data/test/test-require1/require5.rb +9 -0
  171. data/test/test-require1/require6.rb +9 -0
  172. data/test/test-require1/test-require1.rb +41 -0
  173. data/test/test-require1/test-require1.ret +27 -0
  174. data/test/test-socket.rb +26 -0
  175. data/test/test-socket/test-socket.rb +7 -0
  176. data/test/test-socket/test-socket.ret +1 -0
  177. data/test/testcase.rb +66 -0
  178. data/vendor/mkexports.rb +167 -0
  179. metadata +352 -0
@@ -0,0 +1,1374 @@
1
+ ###################################
2
+ #
3
+ # vrcontrol.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 1999-2005 Nishikawa,Yasuhiro
6
+ #
7
+ # More information at http://vruby.sourceforge.net/index.html
8
+ #
9
+ ###################################
10
+
11
+ VR_DIR="vr/" unless defined?(::VR_DIR)
12
+ require VR_DIR+'vruby'
13
+ require VR_DIR+'sysmod'
14
+ =begin
15
+ = VisualuRuby(tmp) Standard Controls
16
+ This file prepares classes of standard controls, panels and menu modules.
17
+
18
+ <<< handlers.rd
19
+
20
+ === Control Container
21
+ * ((<VRStdControlContainer>))
22
+
23
+ === Standard Controls
24
+ * ((<VRButton>))
25
+ * ((<VRGroupbox>))
26
+ * ((<VRCheckbox>))
27
+ * ((<VRRadiobutton>))
28
+ * ((<VRStatic>))
29
+ * ((<VREdit>))
30
+ * ((<VRText>))
31
+ * ((<VRListbox>))
32
+ * ((<VRCombobox>))
33
+
34
+ === Menu
35
+ * ((<VRMenu>))
36
+ * ((<VRMenuItem>))
37
+ * ((<VRMenuUseable>))
38
+
39
+ === Panels
40
+ * ((<VRPanel>))
41
+ * ((<VRBitmapPanel>))
42
+ * ((<VRCanvasPanel>))
43
+ =end
44
+
45
+ ###########################################
46
+ # Messages and Styles
47
+ #
48
+
49
+ module WMsg
50
+ BN_CLICKED = 0
51
+ BN_DBLCLICKED = 5
52
+ BM_GETCHECK = 0xf0
53
+ BM_SETCHECK = 0xf1
54
+
55
+ STN_CLICKED = 0
56
+ STN_DBLCLICKED = 1
57
+
58
+ LB_ADDSTRING = 0x0180
59
+ LB_INSERTSTRING = 0x0181
60
+ LB_DELETESTRING = 0x0182
61
+ LB_SETSEL = 0x0185
62
+ LB_SETCURSEL = 0x0186
63
+ LB_GETSEL = 0x0187
64
+ LB_GETCURSEL = 0x188
65
+ LB_GETTEXT = 0x189
66
+ LB_GETTEXTLEN = 0x18a
67
+ LB_GETCOUNT = 0x18b
68
+ LB_SELECTSTRING = 0x18c
69
+ LB_DIR = 0x18d
70
+ LB_FINDSTRING = 0x18f
71
+ LB_GETSELCOUNT = 0x190
72
+ LB_GETSELITEMS = 0x191
73
+ LB_GETITEMDATA = 0x199
74
+ LB_SETITEMDATA = 0x19a
75
+ LBN_SELCHANGE=1
76
+ LBN_DBLCLK=2
77
+
78
+ CB_ADDSTRING = 0x143
79
+ CB_DELETESTRING = 0x144
80
+ CB_DIR = 0x145
81
+ CB_GETCOUNT = 0x146
82
+ CB_GETCURSEL = 0x147
83
+ CB_GETLBTEXT = 0x148
84
+ CB_GETLBTEXTLEN = 0x149
85
+ CB_INSERTSTRING = 0x14a
86
+ CB_FINDSTRING = 0x14c
87
+ CB_SELECTSTRING = 0x14d
88
+ CB_SETCURSEL = 0x14e
89
+ CB_GETITEMDATA = 0x150
90
+ CB_SETITEMDATA = 0x151
91
+ CB_SETEXTENDEDUI =0x155
92
+ CBN_SELCHANGE = 1
93
+ end
94
+
95
+ module WStyle
96
+ BS_PUSHBUTTON = 0
97
+ BS_CHECKBOX = 2
98
+ BS_AUTOCHECKBOX = 3
99
+ BS_RADIOBUTTON = 4
100
+ BS_3STATE = 5
101
+ BS_GROUPBOX = 7
102
+ BS_USERBUTTON = 8
103
+ BS_AUTORADIOBUTTON= 9
104
+
105
+ ES_MULTILINE = 4
106
+ ES_PASSWORD = 0x20
107
+ ES_AUTOVSCROLL = 0x40
108
+ ES_AUTOHSCROLL = 0x80
109
+ ES_READONLY = 0x800
110
+ ES_WANTRETURN = 0x1000
111
+ LBS_STANDARD = 0x00a00000 | 1
112
+ LBS_MULTIPLESEL = 8
113
+
114
+ CBS_STANDARD = 0x00a00200 | 3
115
+ CBS_AUTOSCROLL = 0x40
116
+ end
117
+
118
+ ###############################################
119
+ # Standard Control
120
+ #
121
+
122
+ class VRStdControl < VRControl
123
+ def _vr_cmdhandlers
124
+ unless defined?(@_vr_cmdhandlers)
125
+ @_vr_cmdhandlers={}
126
+ else
127
+ @_vr_cmdhandlers
128
+ end
129
+ end
130
+
131
+ def addCommandHandler(msg,handlername,handlertype,argparsestr)
132
+ @_vr_cmdhandlers={} unless defined?(@_vr_cmdhandlers)
133
+ @_vr_cmdhandlers[msg]=[] unless _vr_cmdhandlers[msg]
134
+ @_vr_cmdhandlers[msg].push [handlername,handlertype,argparsestr]
135
+ end
136
+
137
+ def deleteCommandHandler(msg,handlername)
138
+ return false unless @_vr_cmdhandlers[msg]
139
+ @_vr_cmdhandlers.delete_if do |shandler|
140
+ shandler[0] != (PREHANDLERSTR+handlername).intern
141
+ end
142
+ end
143
+ end
144
+
145
+
146
+ ################################################
147
+ # Standard Control Container
148
+ #
149
+ module VRStdControlContainer
150
+ =begin
151
+ == VRStdControlContainer
152
+ This module provides a message handler for WM_COMMAND, which calls
153
+ the defined methods in a parent window.
154
+ VRForm includes this module automatically loading "vrcontrol.rb".
155
+ =end
156
+
157
+ include VRMessageHandler
158
+
159
+ def stdcontrolcontainerinit
160
+ addHandler(WMsg::WM_COMMAND,"wmcommand",MSGTYPE::ARGPASS,nil)
161
+ addEvent WMsg::WM_COMMAND
162
+ end
163
+
164
+ def vrinit
165
+ super
166
+ stdcontrolcontainerinit
167
+ addNoRelayMessages [WMsg::WM_COMMAND]
168
+ end
169
+
170
+ def self_wmcommand(msg)
171
+ id=LOWORD(msg.wParam)
172
+ ct=@controls[id] # Activated Control
173
+ if !ct then
174
+ if !@_vr_menu then return end
175
+ ct=@_vr_menus[id]
176
+ if !ct then
177
+ return # no handler
178
+ end
179
+ end
180
+
181
+ messageid=HIWORD(msg.wParam)
182
+ return unless ct._vr_cmdhandlers and ct._vr_cmdhandlers[messageid]
183
+
184
+ ct._vr_cmdhandlers[messageid].each do |shandler|
185
+ args=msgarg2handlerarg(shandler[1],msg,shandler[2])
186
+ ct.__send__(shandler[0],*args) if ct.respond_to?(shandler[0])
187
+ msg.retval = controlmsg_dispatching(ct,shandler[0],*args)
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ # add
194
+ module VRContainersSet
195
+ include VRStdControlContainer
196
+ INITIALIZERS.push :stdcontrolcontainerinit
197
+ end
198
+
199
+
200
+
201
+ ##########################################
202
+ # Standard Controls
203
+ #
204
+ #
205
+ # Minimum definition for a Standard Control is
206
+ #
207
+ #> class VRSampleControl <VRStdControl
208
+ #> WINCLASSINFO = ["ControlClass",additionalStyle,exStyle]
209
+ #> def vrinit()
210
+ #> super
211
+ #> addCommandHandler(message,eventname,type,argparsestr])
212
+ #> end
213
+ #> end
214
+ #
215
+ # @_vr_cmdhandlers such as {
216
+ ## message -> [eventname, argtype, unpackstr]
217
+ # WMsg::BN_CLICKED=>["clicked",MSGTYPE::ARGNONE,nil],
218
+ # WMsg::LBN_SELCHANGE=>["selchange",MSGTYPE::ARGNONE,nil]
219
+ #}
220
+ # ############################################################
221
+
222
+ class VRButton < VRStdControl
223
+ =begin
224
+ == VRButton
225
+ Button.
226
+ Button's caption can be set/got by caption/caption= method of SWin::Window.
227
+
228
+ === Event handlers
229
+ Buttons invoke the following method of parent window.
230
+ --- ????_clicked
231
+ This parent's method is fired when button is pushed.
232
+ --- ????_dblclicked
233
+ This parent's method is fired when button is double clicked.
234
+ =end
235
+
236
+ WINCLASSINFO = ["BUTTON",WStyle::BS_PUSHBUTTON]
237
+
238
+ def vrinit
239
+ super
240
+ addCommandHandler(WMsg::BN_CLICKED, "clicked", MSGTYPE::ARGNONE,nil)
241
+ addCommandHandler(WMsg::BN_DBLCLICKED, "dblclicked",MSGTYPE::ARGNONE,nil)
242
+ end
243
+ end
244
+
245
+ class VRGroupbox < VRStdControl
246
+ =begin
247
+ == VRGroupbox
248
+ Groupbox.
249
+
250
+ This control can be a container of other window.
251
+ You need to extend this class by Container modules, VRStdControlContainer for Standard Controls and VRCommonControlContainer for Common Controls.
252
+ =end
253
+
254
+ include VRParent
255
+ WINCLASSINFO = ["BUTTON",WStyle::BS_GROUPBOX]
256
+ end
257
+
258
+ class VRCheckbox < VRButton
259
+ =begin
260
+ == VRCheckbox
261
+ Check box.
262
+ Parent class is ((<VRButton>))
263
+
264
+ === Methods
265
+ Checkbox has the following methods.
266
+ --- checked?
267
+ Return boolean value whether checkbox is checked or not.
268
+ --- check(v)
269
+ Check checkbox as v(=true/false).
270
+ =end
271
+ WINCLASSINFO = ["BUTTON",WStyle::BS_AUTOCHECKBOX]
272
+ private
273
+
274
+ def to_check_state(v)
275
+ res=case v
276
+ when true
277
+ 1
278
+ when false,nil
279
+ 0
280
+ else
281
+ if v.respond_to?(:to_i)
282
+ v.to_i != 0 ? 1 : 0
283
+ else
284
+ v ? 1 : 0
285
+ end
286
+ end
287
+ return res
288
+ end
289
+
290
+ public
291
+
292
+ def checked?
293
+ c=sendMessage(WMsg::BM_GETCHECK,0,0) #getcheck
294
+ return c!=0
295
+ end
296
+
297
+ def check(v)
298
+ sendMessage WMsg::BM_SETCHECK, to_check_state(v),0
299
+ end
300
+
301
+ alias :checked= :check
302
+ end
303
+
304
+ class VRRadiobutton < VRCheckbox
305
+ =begin
306
+ == VRRadiobutton
307
+ Radio Button.
308
+
309
+ Parent class is ((<VRCheckbox>))
310
+ =end
311
+ WINCLASSINFO = ["BUTTON",WStyle::BS_AUTORADIOBUTTON]
312
+ end
313
+
314
+
315
+ class VRStatic < VRStdControl
316
+ =begin
317
+ == VRStatic
318
+ Static Control(text).
319
+
320
+ Text can be access as caption.
321
+
322
+ === Event handlers
323
+ --- ????_clicked
324
+ Fired when the control is clicked if the control has the style WMsg::STN_CLICKED
325
+ =end
326
+ WINCLASSINFO = ["STATIC",0]
327
+ def vrinit
328
+ addCommandHandler(WMsg::STN_CLICKED, "clicked",0,nil)
329
+ end
330
+ end
331
+
332
+ class VREdit < VRStdControl
333
+ =begin
334
+ == VREdit
335
+ Edit Control.
336
+
337
+ === Methods
338
+ --- text
339
+ Gets Text in the control. Line break(\r\n) is translated by this method.
340
+ --- text=(str)
341
+ Sets Text in the control. Line break is translated by this method.
342
+ --- getSel
343
+ Returns [start_pos,end_pos] of the selected area.
344
+ --- setSel(st,en,noscroll=0)
345
+ Sets the selected area specified by ((|st|)) as start point and ((|en|))
346
+ as end point and Scrolls to show the area. When ((|noscroll|)) is 1,
347
+ it doesn't scroll.
348
+ --- setCaret(r)
349
+ Sets cursor point at ((|r|))
350
+ --- replaceSel(newstr)
351
+ Replaces text in the selected area with ((|newstr|)).
352
+ --- readonly=(b)
353
+ Sets readonly flag as boolean ((|b|))
354
+ --- limit
355
+ Gets the length limit of this Editbox.
356
+ --- limit=(lmt)
357
+ Sets the length limit of this Editbox.
358
+ --- modified
359
+ Returns true if the editbox text is modified by user.
360
+ --- modified=(f)
361
+ Sets modified flag of the editbox.
362
+ --- cut
363
+ Cuts the selected area into clipboard.
364
+ --- copy
365
+ Copies the selected area into clipboard.
366
+ --- paste
367
+ Paste the clipboard text into the editbox.
368
+ --- clear
369
+ Clears selected area text.
370
+ Use ((<cut>)) method to set the text into clipboard.
371
+ --- undo
372
+ Undo the previous cut/copy/paste/clear action.
373
+ --- charFromPos(x,y)
374
+ retrieves information about the character closest to a specified point
375
+ in the client area.
376
+ ((x)) is the horizontal coordinate. ((y)) is the vertical coordinate.
377
+ the return value specifies character index by Fixnum.
378
+ the character index starts from zero
379
+ === Event handlers
380
+ Editboxes invoke the following method of parent window.
381
+ --- ????_changed
382
+ This parent's method is fired when editbox text is modified.
383
+ =end
384
+
385
+ WINCLASSINFO = ["EDIT",WStyle::ES_AUTOHSCROLL,WExStyle::WS_EX_CLIENTEDGE]
386
+
387
+ def vrinit
388
+ super
389
+ addCommandHandler(0x300,"changed",MSGTYPE::ARGNONE,nil)
390
+ end
391
+
392
+ def getSel
393
+ r=sendMessage(0xb0,0,0)
394
+ return LOWORD(r),HIWORD(r)
395
+ end
396
+
397
+ def setCaret(r)
398
+ setSel(r,r)
399
+ end
400
+
401
+ def setSel(st,en,noscroll=0)
402
+ sendMessage(0xb1,st,en)
403
+ end
404
+
405
+ def replaceSel(newstr)
406
+ sendMessage(0xc2,0,newstr.to_s)
407
+ end
408
+
409
+ def readonly=(b)
410
+ f= (b)? 1 : 0
411
+ sendMessage 0xcf,f,0
412
+ end
413
+
414
+ def limit=(lmt)
415
+ sendMessage 0xc5,lmt.to_i,0
416
+ end
417
+ def limit
418
+ sendMessage 0xd5,0,0
419
+ end
420
+
421
+ def modified
422
+ r=sendMessage 0xb8,0,0 #GETMODIFY
423
+ if r==0 then false else true end
424
+ end
425
+ alias modified? :modified
426
+ def modified=(f)
427
+ r= if f then 1 else 0 end
428
+ sendMessage 0xb9,r,0
429
+ end
430
+
431
+ # change linebreak code
432
+ # caption,caption= methods is raw methods
433
+
434
+ VR_REGEXPNEWLINE="\r\n"
435
+ def text() self.caption.gsub(/#{VR_REGEXPNEWLINE}/,$/); end
436
+ def text=(str)
437
+ self.caption = str.to_s.gsub(/#{VR_REGEXPNEWLINE}/,"\n").gsub(/\n/,VR_REGEXPNEWLINE)
438
+ end
439
+
440
+
441
+ # for clipboard and so on..
442
+ def cut
443
+ sendMessage 0x300,0,0 #CUT
444
+ end
445
+ def copy
446
+ sendMessage 0x301,0,0 #COPY
447
+ end
448
+ def paste
449
+ sendMessage 0x302,0,0 #PASTE
450
+ end
451
+ def clear
452
+ sendMessage 0x303,0,0 #CLEAR
453
+ end
454
+ def undo
455
+ sendMessage 0x304,0,0 #UNDO
456
+ end
457
+
458
+ def charFromPos(x,y)
459
+ r=sendMessage 0x00D7,0,(y << 16) | x #EM_CHARFROMPOS
460
+ return LOWORD(r)
461
+ end
462
+
463
+ end
464
+
465
+ class VRText < VREdit
466
+ =begin
467
+ == VRText
468
+ Mutiline Editbox.
469
+ Parent class is ((<VREdit>))
470
+
471
+ === Methods
472
+ --- scrollTo(line.col)
473
+ Scrolls ((|line|)) lines vertically and ((|col|)) columns horizontally.
474
+ --- visibleStartLine
475
+ Returns line number of the first visible line in the editbox.
476
+ --- countLines
477
+ Returns max line number.
478
+ --- getLineLengthOf(ln)
479
+ Returns length of the ((|ln|))-th line.
480
+ --- getLineTextOf(ln,maxlen)
481
+ Returns text of ((|ln|))-th line. If maxlen is specified, returned text is
482
+ limited in its length.
483
+ --- scrollup
484
+ Scrolls line up in the editbox.
485
+ --- scrolldown
486
+ Scrolls line down in the editbox.
487
+ --- scrollupPage
488
+ Scrolls page up in the editbox.
489
+ --- scrolldownPage
490
+ Scrolls page down in the editbox.
491
+ --- scrolltocaret
492
+ Scrolls the caret into view in the editbox.
493
+ --- char2line(ptr)
494
+ Returns the index of the line that contains the specified character index.
495
+ --- line2char(ln)
496
+ Returns the character index of a line.
497
+ --- getCurrentLine
498
+ Returns the current line index.
499
+ --- charLineFromPos(x,y)
500
+ retrieves information about the character closest to a specified point
501
+ in the client area.
502
+ ((x)) is the horizontal coordinate. ((y)) is the vertical coordinate.
503
+ the return value specifies character index and line index by Array.
504
+ first item means character index. second item means line index.
505
+ the character index and line index start from zero
506
+ =end
507
+
508
+ WINCLASSINFO = ["EDIT",
509
+ WStyle::ES_MULTILINE|WStyle::ES_AUTOVSCROLL,WExStyle::WS_EX_CLIENTEDGE
510
+ ]
511
+
512
+ private
513
+ def c_scroll(r)
514
+ sendMessage 0xb5,r.to_i,0
515
+ end
516
+
517
+ public
518
+
519
+ def countLines
520
+ sendMessage 0x00BA,0,0
521
+ end
522
+
523
+ def scrollTo(line,col)
524
+ sendMessage 0x00B6,0,MAKELPARAM(line,col) #LINESCROLL
525
+ end
526
+ def visibleStartLine()
527
+ sendMessage 0x00CE,0,0 #GETFIRSTVISIBLELINE
528
+ end
529
+
530
+ def getLineLengthOf(l)
531
+ sendMessage 0xc1,l.to_i,0 #GETLINELENGTH
532
+ end
533
+ def getLineTextOf(l,textsize=getLineLengthOf(l))
534
+ r=pack("Ia",textsize," "*textsize)
535
+ len=sendMessage 0xc4,l.to_i,r
536
+ r[0,len]
537
+ end
538
+
539
+ def scrollup() c_scroll 0; end
540
+ def scrolldown() c_scroll 1; end
541
+ def scrollupPage() c_scroll 2; end
542
+ def scrolldownPage() c_scroll 3; end
543
+
544
+ def scrolltocaret
545
+ sendMessage 0xb7,0,0 #SCROLLCARET
546
+ end
547
+
548
+ def char2line(ptr)
549
+ sendMessage 0xc9,ptr.to_i,0 #LINEFROMCHAR
550
+ end
551
+ def line2char(l)
552
+ sendMessage 0xbb,l.to_i,0 #LINEINDEX
553
+ end
554
+ def getCurrentLine
555
+ char2line(-1)
556
+ end
557
+
558
+ def charLineFromPos(x,y)
559
+ r=sendMessage 0x00D7,0,(y << 16) | x #EM_CHARFROMPOS
560
+ return [LOWORD(r),HIWORD(r)]
561
+ end
562
+
563
+ end
564
+
565
+
566
+ class VRListbox < VRStdControl
567
+ =begin
568
+ == VRListbox
569
+ Listbox.
570
+ Listbox has multi strings to select.
571
+
572
+ === Methods
573
+ --- addString(idx,str)
574
+ Adds ((|str|)) String at the ((|idx|)).
575
+ When ((|idx|)) is omitted, ((|str|)) is added at the bottom.
576
+ --- deleteString(idx)
577
+ Deletes string at ((|idx|))
578
+ --- countStrings
579
+ Returns the count of its strings.
580
+ --- clearStrings
581
+ Deletes all strings.
582
+ --- eachString
583
+ Yields each string.
584
+ --- setListStrings(strarray)
585
+ Sets array of string ( ((|strarray|)) ) as the listbox strings.
586
+ --- selectedString
587
+ Returns the selected index.
588
+ --- select(idx)
589
+ Selects ((|idx|))-th string.
590
+ --- getTextOf(idx)
591
+ Retrieves the text of ((|idx|))-th string.
592
+ --- setDir(fname,opt=0)
593
+ Sets the filenames specified by ((|fname|)) to the listbox.
594
+ ((|opt|)) specifies the attributes of the files to be added.
595
+ --- findString(findstr,start=0)
596
+ Finds ((|findstr|)) in the listbox strings and returns the its index.
597
+ ((|start|)) specifies the index to start finding.
598
+ --- getDataOf(idx)
599
+ Retrieves the 32bit value associated with the ((|idx|))-th string.
600
+ --- setDataOf(idx,data)
601
+ Associates the 32bit value with the ((|idx|))-th string.
602
+ === Event handlers
603
+ --- ????_selchanged
604
+ Fired when the selected string is changed.
605
+ =end
606
+
607
+ WINCLASSINFO = ["LISTBOX",WStyle::LBS_STANDARD,WExStyle::WS_EX_CLIENTEDGE]
608
+
609
+ def vrinit
610
+ super
611
+ addCommandHandler(WMsg::LBN_SELCHANGE, "selchange",MSGTYPE::ARGNONE,nil)
612
+ set_liststrings
613
+ end
614
+
615
+ private
616
+ def set_liststrings
617
+ clearStrings
618
+
619
+ return unless defined? @_vr_init_items
620
+ 0.upto(@_vr_init_items.size-1) do |idx|
621
+ addString idx,@_vr_init_items[idx]
622
+ end if @_vr_init_items
623
+ end
624
+
625
+ public
626
+ def addString(*arg)
627
+ if arg[0].is_a?(Integer) then
628
+ sendMessage WMsg::LB_INSERTSTRING,arg[0],arg[1].to_s
629
+ else
630
+ sendMessage WMsg::LB_ADDSTRING,0,arg[0].to_s
631
+ end
632
+ end
633
+
634
+ def deleteString(idx)
635
+ sendMessage WMsg::LB_DELETESTRING,idx.to_i,0
636
+ end
637
+ def countStrings
638
+ sendMessage WMsg::LB_GETCOUNT,0,0
639
+ end
640
+
641
+ def clearStrings
642
+ c=getCount
643
+ (1..c).each do |i|
644
+ deleteString 0 #delete #0 c-times
645
+ end
646
+ end
647
+
648
+ def eachString
649
+ c=getCount
650
+ 0.upto(c-1) do |i|
651
+ yield getString(i)
652
+ end
653
+ end
654
+
655
+ def setListStrings(sarray)
656
+ @_vr_init_items=sarray
657
+ if hWnd>0 then set_liststrings end
658
+ end
659
+
660
+ def selectedString
661
+ sendMessage(WMsg::LB_GETCURSEL,0,0)
662
+ end
663
+
664
+ def getTextOf(idx)
665
+ len = sendMessage(WMsg::LB_GETTEXTLEN,idx.to_i,0) #LB_gettextlen
666
+ raise "No such index(#{idx}) in the Listbox"if len<0
667
+ str=" " * len
668
+ sendMessage(WMsg::LB_GETTEXT,idx.to_i,str) #LB_getText
669
+ str
670
+ end
671
+
672
+ def select(idx)
673
+ sendMessage(WMsg::LB_SETCURSEL,idx.to_i,0)
674
+ end
675
+
676
+ def setDir(fname,opt=0)
677
+ sendMessage(WMsg::LB_DIR,opt.to_i,fname.to_s)
678
+ end
679
+
680
+ def findString(findstr,start=0)
681
+ sendMessage(WMsg::LB_FINDSTRING,start.to_i,findstr.to_s)
682
+ end
683
+
684
+ def getDataOf(idx)
685
+ sendMessage(WMsg::LB_GETITEMDATA,idx.to_i,0)
686
+ end
687
+ def setDataOf(idx,data)
688
+ sendMessage(WMsg::LB_SETITEMDATA,idx.to_i,data.to_i)
689
+ end
690
+
691
+ def eachSelected
692
+ count = sendMessage(WMsg::LB_GETSELCOUNT,0,0)
693
+
694
+ if count<1 then
695
+ yield selectedString
696
+ return
697
+ end
698
+
699
+ buffer = '\0\0\0\0' * count
700
+ sendMessage(WMsg::LB_GETSELITEMS,count,buffer)
701
+
702
+ buffer.unpack("I*")[0,count].each do |i|
703
+ yield i
704
+ end
705
+ end
706
+
707
+ end
708
+
709
+ class VRCombobox < VRStdControl
710
+ =begin
711
+ == VRCombobox
712
+ Combobox is like Listbox, but Only one string is selected.
713
+
714
+ === Methods
715
+ --- addString(idx,str)
716
+ Adds ((|str|)) String at the ((|idx|)).
717
+ When ((|idx|)) is omitted, ((|str|)) is added at the bottom.
718
+ --- deleteString(idx)
719
+ Deletes string at ((|idx|))
720
+ --- countStrings
721
+ Returns the count of its strings.
722
+ --- clearStrings
723
+ Deletes all strings.
724
+ --- eachString
725
+ Yields each string.
726
+ --- setListStrings(strarray)
727
+ Sets array of string ( ((|strarray|)) ) as the combobox strings.
728
+ --- selectedString
729
+ Returns the selected index.
730
+ --- select(idx)
731
+ Selects ((|idx|))-th string.
732
+ --- getTextOf(idx)
733
+ Retrieves the text of ((|idx|))-th string.
734
+ --- setDir(fname,opt=0)
735
+ Sets the filenames specified by ((|fname|)) to the combobox.
736
+ ((|opt|)) specifies the attributes of the files to be added.
737
+ --- findString(findstr,start=0)
738
+ Finds ((|findstr|)) in the combobox strings and returns the its index.
739
+ ((|start|)) specifies the index to start finding.
740
+ --- getDataOf(idx)
741
+ Retrieves the 32bit value associated with the ((|idx|))-th string.
742
+ --- setDataOf(idx,data)
743
+ Associates the 32bit value with the ((|idx|))-th string.
744
+ === Event handlers
745
+ --- ????_selchanged
746
+ Fired when the selected string is changed.
747
+ =end
748
+
749
+ WINCLASSINFO = ["COMBOBOX",WStyle::CBS_STANDARD]
750
+
751
+ def vrinit
752
+ super
753
+ set_liststrings
754
+ addCommandHandler(WMsg::CBN_SELCHANGE, "selchange",MSGTYPE::ARGNONE,nil)
755
+ end
756
+
757
+ private
758
+ def set_liststrings
759
+ clearStrings
760
+ return unless defined? @_vr_init_items
761
+ 0.upto(@_vr_init_items.size-1) do |idx|
762
+ addString idx,@_vr_init_items[idx]
763
+ end if @_vr_init_items
764
+ end
765
+
766
+ public
767
+ def addString(*arg)
768
+ if arg[0].is_a?(Integer) then
769
+ sendMessage WMsg::CB_INSERTSTRING,arg[0],arg[1].to_s
770
+ else
771
+ sendMessage WMsg::CB_ADDSTRING,0,arg[0].to_s
772
+ end
773
+ end
774
+
775
+
776
+ def deleteString(idx)
777
+ sendMessage WMsg::CB_DELETESTRING,idx,0
778
+ end
779
+ def countStrings
780
+ sendMessage WMsg::CB_GETCOUNT,0,0
781
+ end
782
+
783
+ def clearStrings
784
+ c=getCount
785
+ (1..c).each do |i|
786
+ deleteString 0 #delete #0 c-times
787
+ end
788
+ end
789
+
790
+ def eachString
791
+ c=getCount
792
+ 0.upto(c-1) do |i|
793
+ yield getString(i)
794
+ end
795
+ end
796
+
797
+ def setListStrings(sarray)
798
+ @_vr_init_items=sarray
799
+ if hWnd>0 then set_liststrings end
800
+ end
801
+
802
+ def selectedString
803
+ sendMessage(WMsg::CB_GETCURSEL,0,0)
804
+ end
805
+
806
+ def getTextOf(idx)
807
+ len = sendMessage(WMsg::CB_GETLBTEXTLEN,idx,0) #CB_gettextlen
808
+ raise "No such index(#{idx}) in the Combobox"if len<0
809
+ str=" " * len
810
+ sendMessage(WMsg::CB_GETLBTEXT,idx,str) #CB_getText
811
+ str
812
+ end
813
+
814
+ def select(idx)
815
+ sendMessage(WMsg::CB_SETCURSEL,idx,0)
816
+ end
817
+
818
+ def setDir(fname,opt=0)
819
+ sendMessage(WMsg::CB_DIR,opt.to_i,fname.to_s)
820
+ end
821
+
822
+ def findString(findstr,start=0)
823
+ sendMessage(WMsg::CB_FINDSTRING,start.to_i,findstr.to_s)
824
+ end
825
+
826
+ def getDataOf(idx)
827
+ sendMessage(WMsg::CB_GETITEMDATA,idx.to_i,0)
828
+ end
829
+ def setDataOf(idx,data)
830
+ sendMessage(WMsg::CB_SETITEMDATA,idx.to_i,data.to_i)
831
+ end
832
+ end
833
+
834
+ #####################################
835
+ # Editable Combobox
836
+ # programmed by USHIWATARI-san
837
+ module WMsg
838
+ CBN_EDITCHANGE = 5
839
+ end
840
+ module WStyle
841
+ CBS_DROPDOWN = 0x00a00200 | 2
842
+ end
843
+
844
+ class VREditCombobox < VRCombobox
845
+ =begin
846
+ == VREditCombobox
847
+ Editable Combobox.
848
+ This is a kind of Combobox where you can edit the text.
849
+
850
+ === Methods
851
+ This has also VRCombobox's methods.
852
+ --- text
853
+ Returns the current text.
854
+
855
+ === Event handlers
856
+ --- changed
857
+ Fired when the text is changed.
858
+ =end
859
+
860
+
861
+ WINCLASSINFO = ["COMBOBOX",WStyle::CBS_DROPDOWN | WStyle::CBS_AUTOSCROLL ]
862
+ def vrinit
863
+ super
864
+ addCommandHandler(WMsg::CBN_EDITCHANGE, "changed",MSGTYPE::ARGNONE,nil)
865
+ end
866
+
867
+ def text
868
+ self.caption
869
+ end
870
+ def text=(str)
871
+ self.caption = str.gsub(/([^\r])\n/,'\1'+VREdit::VR_REGEXPNEWLINE)
872
+ end
873
+
874
+ end
875
+
876
+
877
+
878
+ #####################################
879
+ # Menu
880
+ #
881
+ class VRMenu
882
+ =begin
883
+ == VRMenu
884
+ Menu.
885
+
886
+ === Methods
887
+ --- append(caption,state)
888
+ Adds a new menu item at the last with the caption of ((|caption|)) and
889
+ the state of ((|state|)). See ((<state=>)) about ((|state|)).
890
+ --- insert(ptr,caption,name,state)
891
+ Inserts new item at ((|ptr|)).
892
+ --- delete(id)
893
+ Deletes menu. ((|id|)) can be a instance of VRMenuItem or a menu-id integer.
894
+ --- count
895
+ Counts the menu items.
896
+ --- set(sarr)
897
+ Sets the menu according to the ((|sarr|)) which is a structured array
898
+ of strings such like
899
+ (({ [ ["&File", [["&Open","open"],["E&xit","exit"]], }))
900
+ (({ ["&Edit",["&Copy","copy]] }))
901
+ (({ ] ] }))
902
+ Caption : TEXT
903
+ Name : TEXT
904
+ Menu : [Caption, Name|Menu]
905
+
906
+ When a menu is clicked, ((|Name|))_clicked method is fired.
907
+
908
+ =end
909
+
910
+ attr :menu
911
+ attr :parent
912
+
913
+ SEPARATOR=["sep","_vrmenusep",0x800]
914
+
915
+ def initialize(menu,parent)
916
+ @menu=menu
917
+ @parent=parent
918
+ end
919
+
920
+ def append (*arg)
921
+ m=VRMenuItem.new(@menu)
922
+ id=@parent.newControlID
923
+ if arg[2] then
924
+ @menu.append arg[0],id,arg[2]
925
+ else
926
+ @menu.append arg[0],id
927
+ end
928
+ @parent.registerMenu(m,arg[1],id,arg[0])
929
+ m
930
+ end
931
+ def insert (ptr,*arg)
932
+ m=VRMenuItem.new(@menu)
933
+ id=@parent.newControlID
934
+ if arg.size>2 then
935
+ @menu.insert arg[0],id,ptr,arg[2]
936
+ else
937
+ @menu.insert arg[0],id,ptr
938
+ end
939
+ @parent.registerMenu(m,arg[1],id,arg[0])
940
+ m
941
+ end
942
+ def delete (id)
943
+ if id.is_a?(VRMenuItem) then
944
+ @menu.delete id.etc
945
+ else
946
+ @menu.delete id
947
+ end
948
+ end
949
+ def count (*arg)
950
+ @menu.count(*arg)
951
+ end
952
+
953
+ def set(sarr)
954
+ sarr.each do |item|
955
+ if item[1].is_a?(Array) then
956
+ m=@parent.newMenu(true)
957
+ m.set(item[1])
958
+ @menu.append item[0],m.menu,item[2]
959
+ elsif item[1].is_a?(VRMenu) then
960
+ @menu.append item[0],item[1].menu,item[2]
961
+ else
962
+ append(*item)
963
+ end
964
+ end
965
+ self
966
+ end
967
+ end
968
+
969
+ VRMenuTemplate = Struct.new("VRMenuTemplate",:caption,:item,:state)
970
+ =begin
971
+ == VRMenuTemplate
972
+ If you don't like using Array for VRMenu#set, this will help you.
973
+
974
+ === Methods
975
+ --- caption
976
+ --- caption=
977
+ Represents the caption of the menu.
978
+ --- item
979
+ --- item=
980
+ When ((|item|)) is String, ((|item|)) means the name of menu item.
981
+ This name is used for the event handler name like ((|item|))_clicked.
982
+ ((|item|)) can be also an instance of VRMenuTemplate. In this case ((|item|))
983
+ represents its submenu.
984
+ === example
985
+ a=VRMenuTemplate.new
986
+ a.caption,a.item = "Test1","test1"
987
+
988
+ b=VRMenuTemplate.new("Test2","test2")
989
+ c=VRMenuTemplate.new("Test3","test3",VRMenuItem::GRAYED)
990
+
991
+ d1=VRMenuTemplate.new("Test4-1","test41")
992
+ d2=VRMenuTemplate.new("Test4-2","test42")
993
+ d3=VRMenuTemplate.new("Test4-3","test43")
994
+
995
+ d = VRMenuTemplate.new
996
+ d.caption , d.item = "Test4" , [d1,d2,d3]
997
+ =end
998
+
999
+ class VRMenuItem
1000
+ =begin
1001
+ == VRMenuItem
1002
+ This is a wrapper of SWin::Menu
1003
+ === Methods
1004
+ --- new(menu)
1005
+ ((|menu|)) must be the instance of SWin::Menu.
1006
+ --- state
1007
+ Returns the state of the menu item.
1008
+ --- state=
1009
+ Sets the state of the menu item.
1010
+ state means
1011
+ * 0 MF_ENABLED
1012
+ * 1 MF_GRAYED
1013
+ * 2 MF_DISABLED
1014
+ * 8 MF_CHECKED
1015
+ --- checked?
1016
+ Returns true if the menu item is checked.
1017
+ --- checked=
1018
+ Sets true/false whether the menu item is checked or not.
1019
+ --- modify(text)
1020
+ Modifies the text of the menu item.
1021
+ =end
1022
+ attr :name,1
1023
+ attr :etc,1
1024
+
1025
+ GRAYED=1
1026
+ DISABLED=2
1027
+ CHECKED=8
1028
+
1029
+ def initialize(menu)
1030
+ @menu=menu
1031
+ end
1032
+ def _vr_cmdhandlers
1033
+ {0=>[["clicked",MSGTYPE::ARGNONE,nil]], # for menu
1034
+ 1=>[["clicked",MSGTYPE::ARGNONE,nil]]} # for key accelerator
1035
+ end
1036
+
1037
+ def state= (st)
1038
+ @menu.setState(@etc,st)
1039
+ end
1040
+ def state
1041
+ @menu.getState(@etc)
1042
+ end
1043
+ def checked=(f)
1044
+ @menu.setChecked(@etc,f)
1045
+ end
1046
+ def checked?
1047
+ (self.state&8)==8
1048
+ end
1049
+ def modify(text)
1050
+ @menu.modify @etc,text
1051
+ end
1052
+ end
1053
+
1054
+ module VRKeyAcceleratorUseable # Thanks to Yukimisake-san.
1055
+ def menuTransTable(hsh)
1056
+ tVirt = {"Ctrl" => 0x08,"Shift" => 0x04,"Alt" => 0x10}
1057
+ tVkey = {"F1"=>0x70,"F2"=>0x71,"F3"=>0x72,"F4"=>0x73,
1058
+ "F5"=>0x74,"F6"=>0x75,"F7"=>0x76,"F8"=>0x77,
1059
+ "F9"=>0x78,"F10"=>0x79,"F11"=>0x7a,"F12"=>0x7b,
1060
+ "Insert"=>0x2d,"Delete"=>0x2e,"PageUp"=>0x21,"PageDown"=>0x22,
1061
+ "End"=>0x23,"Home"=>0x24
1062
+ }
1063
+ r = []
1064
+ hsh.each{|k,v|
1065
+ fVirt = 1
1066
+ key = nil
1067
+ if txt = v[/\t.*/] then
1068
+ a = txt.strip!.split(/\+/)
1069
+ a[0,a.size-1].each{|ii|
1070
+ raise "Iregal Key" unless n = tVirt[ii]
1071
+ fVirt += n } if a.size > 1
1072
+ if (s = a[a.size-1]).size > 1 then
1073
+ unless key = tVkey[s] then raise "Iregal Key" end
1074
+ else
1075
+ key = (s.upcase)[0]
1076
+ end
1077
+ end
1078
+ if key then
1079
+ r << fVirt
1080
+ r << key
1081
+ r << k
1082
+ end
1083
+ }
1084
+ r
1085
+ end
1086
+ end
1087
+
1088
+ module VRMenuUseable
1089
+ =begin
1090
+ == VRMenuUseable
1091
+ Include this module to use menus.
1092
+
1093
+ === Methods
1094
+ --- newMenu(popup=false)
1095
+ Creates a new ((<VRMenu>)). If popup is true, the created menu is popup menu.
1096
+ --- newPopupMenu
1097
+ Same as newMenu(true)
1098
+ --- setMenu(menu)
1099
+ Sets the menu ((<VRMenu>)) to the window.
1100
+ --- showPopup(popupmenu)
1101
+ Shows ((|popupmenu|)) at the cursor position
1102
+ =end
1103
+
1104
+ include VRKeyAcceleratorUseable
1105
+
1106
+ SetForegroundWindow = Win32API.new("user32","SetForegroundWindow","I","I")
1107
+
1108
+ def registerMenu(m,name,id,mcaption="")
1109
+ m.etc= id
1110
+ instance_eval("@"+name+"=m")
1111
+ @_vr_menus= {} unless defined?(@_vr_menus)
1112
+ @_vr_menucaptions= {} unless defined?(@_vr_menucaptions)
1113
+ @_vr_menus[id]= m
1114
+ @_vr_menucaptions[id] = mcaption
1115
+ m.name = name
1116
+ m
1117
+ end
1118
+
1119
+ def newMenu(popup=false)
1120
+ if popup then
1121
+ menu=@screen.factory.newpopup
1122
+ else
1123
+ menu=@screen.factory.newmenu
1124
+ end
1125
+ VRMenu.new(menu,self)
1126
+ end
1127
+
1128
+ def newPopupMenu # contributed by Yuya-san
1129
+ return self.newMenu(true)
1130
+ end
1131
+
1132
+ def setMenu(menu,keyacc=false)
1133
+ SetForegroundWindow.call(self.hWnd)
1134
+ if menu.is_a?(SWin::Menu) then
1135
+ super menu
1136
+ return
1137
+ end
1138
+
1139
+ @_vr_menu=menu
1140
+ @menu=menu
1141
+ super menu.menu
1142
+ if keyacc then
1143
+ tb = menuTransTable(@_vr_menucaptions)
1144
+ SWin::Application.setAccel(self,tb)
1145
+ end
1146
+ end
1147
+
1148
+ def showPopup(menu)
1149
+ SetForegroundWindow.call(self.hWnd)
1150
+ if menu.is_a?(SWin::Menu) then
1151
+ m=menu
1152
+ else # asumes it is VRMenu
1153
+ m=menu.menu
1154
+ @_vr_menu = menu
1155
+ end
1156
+ popupMenu m,*Cursor.get_screenposition
1157
+ end
1158
+
1159
+ def setMenuByArray(arr)
1160
+ self.setMenu newMenu(arr)
1161
+ end
1162
+
1163
+ end
1164
+
1165
+
1166
+ ##############################
1167
+ # Other Controls
1168
+ #
1169
+
1170
+ module WStruct
1171
+ SCROLLINFO="lllllll"
1172
+ end
1173
+
1174
+ class VRScrollbar < VRControl
1175
+ WINCLASSINFO = ["SCROLLBAR",0]
1176
+ attr :smallstep,1
1177
+ attr :longstep,1
1178
+
1179
+ def vrinit
1180
+ setRange(0,100)
1181
+ self.pagesize=10
1182
+ self.position=50
1183
+ @smallstep, @longstep = 1,10
1184
+ end
1185
+
1186
+ def setRange(min,max)
1187
+ sendMessage 0xe6,min.to_i,max.to_i
1188
+ end
1189
+
1190
+ def position=(val)
1191
+ sendMessage 0xe0,val.to_i,1
1192
+ end
1193
+ def position
1194
+ sendMessage 0xe1,0,0
1195
+ end
1196
+
1197
+ def pagesize=(p)
1198
+ si=[4*7,2,0,0,p.to_i,0,0].pack WStruct::SCROLLINFO
1199
+ sendMessage 0xe9,1,si # SBM_SETSCROLLINFO
1200
+ end
1201
+ def pagesize
1202
+ si=[4*7,2,0,0,0,0,0].pack WStruct::SCROLLINFO
1203
+ sendMessage 0xea,1,si # SBM_GETSCROLLINFO
1204
+ si.unpack(WStruct::SCROLLINFO)[4]
1205
+ end
1206
+ end
1207
+
1208
+ class VRHScrollbar < VRScrollbar
1209
+ WINCLASSINFO = ["SCROLLBAR",0]
1210
+ end
1211
+ class VRVScrollbar < VRScrollbar
1212
+ WINCLASSINFO = ["SCROLLBAR",1]
1213
+ end
1214
+
1215
+ module WMsg
1216
+ WM_HSCROLL=276
1217
+ WM_VSCROLL=277
1218
+ end
1219
+
1220
+ module VRScrollbarContainer
1221
+ def scrollbarcontainerinit
1222
+ addHandler WMsg::WM_HSCROLL,"vrscroll",MSGTYPE::ARGINTINT,nil
1223
+ addHandler WMsg::WM_VSCROLL,"vrscroll",MSGTYPE::ARGINTINT,nil
1224
+ acceptEvents [ WMsg::WM_HSCROLL,WMsg::WM_VSCROLL]
1225
+ @_vr_scrollbars={}
1226
+ end
1227
+ def vrinit
1228
+ super
1229
+ scrollbarcontainerinit
1230
+ end
1231
+
1232
+ def searchscrollbar(hwnd)
1233
+ @_vr_scrollbars=Hash.new unless defined? @_vr_scrollbars
1234
+ srl = @_vr_scrollbars[hwnd] # false : to be ignored window, 0: form
1235
+ if srl==nil then
1236
+ @controls.each_value do |v|
1237
+ if v.is_a?(SWin::Window) and v.hWnd==hwnd then
1238
+ if v.is_a?(VRScrollbar) then
1239
+ @_vr_scrollbars[hwnd] = srl = v
1240
+ elsif defined?(VRTrackbar) and v.is_a?(VRTrackbar) then
1241
+ @_vr_scrollbars[hwnd] = srl = false
1242
+ elsif defined?(VRUpdown) and v.is_a?(VRUpdown) then
1243
+ @_vr_scrollbars[hwnd] = srl = false
1244
+ else
1245
+ @_vr_scrollbars[hwnd] = srl = 0
1246
+ end
1247
+ break
1248
+ end
1249
+ end # @controls.each_value
1250
+ end
1251
+
1252
+ case srl
1253
+ when 0
1254
+ self
1255
+ when false
1256
+ nil
1257
+ when nil
1258
+ nil
1259
+ else
1260
+ srl
1261
+ end
1262
+ end
1263
+
1264
+ def self_vrscroll(wparam,hwnd)
1265
+ srl = searchscrollbar(hwnd)
1266
+ return unless srl
1267
+
1268
+ code=LOWORD(wparam)
1269
+ if code==4 then
1270
+ pos=HIWORD(wparam)
1271
+ else
1272
+ pos = srl.position
1273
+ end
1274
+ case code
1275
+ when 0
1276
+ srl.sendMessage 224,pos-srl.smallstep,1
1277
+ when 1
1278
+ srl.sendMessage 224,pos+srl.smallstep,1
1279
+ when 2
1280
+ srl.sendMessage 224,pos-srl.longstep,1
1281
+ when 3
1282
+ srl.sendMessage 224,pos+srl.longstep,1
1283
+ when 4
1284
+ srl.sendMessage 224,pos,1
1285
+ end
1286
+ controlmsg_dispatching(srl,"changed")
1287
+ end
1288
+ end
1289
+
1290
+ # add
1291
+ module VRContainersSet
1292
+ include VRScrollbarContainer
1293
+ INITIALIZERS.push :scrollbarcontainerinit
1294
+ end
1295
+
1296
+
1297
+ ########################
1298
+ #
1299
+ # Control using VRPanel
1300
+ #
1301
+ class VRBitmapPanel < VRPanel
1302
+ =begin
1303
+ == VRBitmapPanel
1304
+ Bitmap panel that can display static bitmap.
1305
+
1306
+ === Methods
1307
+ --- loadFile(filename)
1308
+ Loads ((|filename|)) as bitmap file.
1309
+ --- createBitmap(info,bmp)
1310
+ Creates an bitmap from ((|info|)) and ((|bmp|)).
1311
+ --- bmp
1312
+ The instance of displaying SWin::Bitmap.
1313
+ =end
1314
+ attr :bmp,1
1315
+
1316
+ include VRDrawable
1317
+ def vrinit
1318
+ super
1319
+ @bmp=nil
1320
+ end
1321
+
1322
+ def loadFile(fname)
1323
+ @bmp=SWin::Bitmap.loadFile fname
1324
+ self.refresh
1325
+ end
1326
+
1327
+ def createBitmap(info,bmp)
1328
+ @bmp=SWin::Bitmap.createBitmap info,bmp
1329
+ self.refresh
1330
+ end
1331
+
1332
+ def self_paint
1333
+ drawBitmap @bmp if @bmp.is_a?(SWin::Bitmap)
1334
+ end
1335
+ end
1336
+
1337
+
1338
+ class VRCanvasPanel < VRPanel
1339
+ =begin
1340
+ == VRCanvasPanel
1341
+ Bitmap Canvas panel that can display drawable bitmap.
1342
+ === Methods
1343
+ --- createCanvas(w,h,color=0xffffff)
1344
+ Creates a new canvas dimensioned ( ((|w|)),((|h||)) ) and
1345
+ colored ((|color|)) on the background.
1346
+ --- canvas
1347
+ Returns the instance of SWin::Canvas to draw it.
1348
+ =end
1349
+
1350
+ attr :canvas
1351
+
1352
+ include VRDrawable
1353
+
1354
+ def createCanvas(w,h,color=0xffffff)
1355
+ @canvas=@screen.factory.newcanvas(w,h)
1356
+ @canvas.setBrush(color)
1357
+ @canvas.setPen(color)
1358
+ @canvas.fillRect(0,0,w,h)
1359
+ @canvas.setPen(0x0)
1360
+ end
1361
+
1362
+ def vrinit
1363
+ super
1364
+ @canvas=nil
1365
+ end
1366
+
1367
+ def self_paint
1368
+ bitblt @canvas if @canvas
1369
+ end
1370
+ end
1371
+
1372
+ if VR_COMPATIBILITY_LEVEL then
1373
+ require VR_DIR + 'compat/vrcontrol.rb'
1374
+ end