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,150 @@
1
+ ###################################
2
+ #
3
+ # vrtimer.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 1999-2001 Nishikawa,Yasuhiro
6
+ #
7
+ # More information at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
8
+ # (in Japanese)
9
+ #
10
+ #
11
+ #
12
+ ###################################
13
+
14
+ VR_DIR="vr/" unless defined?(::VR_DIR)
15
+ require VR_DIR+'vruby'
16
+ require "Win32API"
17
+
18
+ =begin
19
+ = VisualuRuby(tmp) Module(s) for Timer
20
+ <<<handlers.rd
21
+ =end
22
+
23
+
24
+
25
+ module VRTimerFeasible
26
+ =begin
27
+ == VRTimerFeasible
28
+ Interval Timers.
29
+ This module prepares create/delete interval timers.
30
+
31
+ === Methods
32
+ --- addTimer(interval=1000,timername="self")
33
+ Creates an interval timer whose name is defined by ((|timername|)).
34
+ Interval timers invoke ((|timername|))_timer method every interval times
35
+ in millisecond.
36
+
37
+ --- deleteTimer(timername="self")
38
+ Deletes an interval timer whose name is ((|timername|))
39
+
40
+ --- timeralive?(timername="self")
41
+ Returns boolean whether timer is alive or not.
42
+
43
+ === Event handler
44
+ --- ????_timer
45
+ Fired every interval times by the interval timer.
46
+ =end
47
+
48
+
49
+ include VRMessageHandler
50
+
51
+ SetTimer = Win32API.new("USER32", "SetTimer",['L', 'I', 'I', 'L'], 'I')
52
+ KillTimer = Win32API.new("USER32", "KillTimer",['L', 'L'], 'I')
53
+ WM_TIMER = 275
54
+
55
+ private
56
+
57
+ def newtimerid
58
+ @_vr_timernextid=0 unless defined? @_vr_timernextid
59
+ @_vr_timernextid+=1
60
+ end
61
+
62
+ public
63
+
64
+ def self_vrtimer(id) # WM_TIMER handler
65
+ name=@_vr_timers[id][0].dup
66
+ class << name
67
+ def name; self; end
68
+ end
69
+ # name += "_"+"timer"
70
+ # selfmsg_dispatching(name)
71
+ controlmsg_dispatching(name,"timer")
72
+ #
73
+ send(name) if respond_to?(name)
74
+ end
75
+
76
+ def vrinit
77
+ super
78
+ timerfeasibleinit
79
+ end
80
+
81
+ def timerfeasibleinit
82
+ @_vr_timerinterval=1000
83
+ addHandler WM_TIMER, "vrtimer", MSGTYPE::ARGWINT,nil #check
84
+ addEvent WM_TIMER
85
+ addNoRelayMessages [WM_TIMER]
86
+ end
87
+
88
+ def addTimer(interval=1000,timername="self")
89
+ id=newtimerid
90
+ SetTimer.call(self.hWnd,id,interval,0)
91
+ @_vr_timers=[] unless defined? @_vr_timers
92
+ @_vr_timers[id] = [timername,interval]
93
+ id
94
+ end
95
+
96
+ def deleteTimer(timername="self")
97
+ id=timerid(timername)
98
+
99
+ if id then
100
+ KillTimer.call(self.hWnd,id)
101
+ @_vr_timers[id]=nil
102
+ else
103
+ raise RuntimeError,"No such Timer"
104
+ end
105
+ end
106
+
107
+ def timerid(timername="self")
108
+ return nil unless @_vr_timers
109
+ r=nil
110
+ 1.upto(@_vr_timers.size-1) do |i|
111
+ if @_vr_timers[i] and @_vr_timers[i][0]==timername then
112
+ r=i
113
+ end
114
+ end
115
+ r
116
+ end
117
+
118
+ def timeralive?(tname="self")
119
+ timerid(tname).is_a?(Integer)
120
+ end
121
+ end
122
+
123
+ =begin sample
124
+ require 'vrcontrol'
125
+ module Test
126
+ include VRTimerFeasible
127
+
128
+ def construct
129
+ self.caption="test"
130
+ go=addControl VRButton,"delete","delete",10,10,100,20
131
+ addTimer 1000,"t1"
132
+ addTimer 1200,"t2"
133
+ end
134
+
135
+ def t1_timer
136
+ p "t1"
137
+ end
138
+ def t2_timer
139
+ print timeralive?("t1") ,":", timeralive?("t2"),"\n"
140
+ end
141
+
142
+ def delete_clicked
143
+ deleteTimer "t1"
144
+ end
145
+
146
+ end
147
+
148
+ VRLocalScreen.showForm(Test)
149
+ VRLocalScreen.messageloop
150
+ =end
@@ -0,0 +1,274 @@
1
+ ###################################
2
+ #
3
+ # vrtooltip.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 2001- 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+'vruby'
14
+
15
+ module WMsg
16
+ TTM_ACTIVATE = WM_USER + 1
17
+ TTM_SETDELAYTIME = WM_USER + 3
18
+ TTM_ADDTOOL = WM_USER + 4
19
+ TTM_DELTOOL = WM_USER + 5
20
+ TTM_RELAYEVENT = WM_USER + 7
21
+ TTM_GETTOOLINFO = WM_USER + 8
22
+ TTM_SETTOOLINFO = WM_USER + 9
23
+ TTM_GETTEXT = WM_USER + 11
24
+ TTM_GETTOOLCOUNT = WM_USER + 13
25
+ TTM_TRACKACTIVATE = WM_USER + 17
26
+ TTM_TRACKPOSITION = WM_USER + 18
27
+ TTM_SETTIPBKCOLOR = WM_USER + 19
28
+ TTM_SETTIPTEXTCOLOR= WM_USER + 20
29
+ TTM_GETDELAYTIME = WM_USER + 21
30
+ TTM_GETTIPBKCOLOR = WM_USER + 22
31
+ TTM_GETTIPTEXTCOLOR= WM_USER + 23
32
+ TTM_SETMAXTIPWIDTH = WM_USER + 24
33
+ TTM_GETMAXTIPWIDTH = WM_USER + 25
34
+
35
+ TTN_NEEDTEXT = 0x100000000-520
36
+ TTN_SHOW = 0x100000000-521
37
+ TTN_POP = 0x100000000-522
38
+ end
39
+
40
+ module WConst
41
+ TTF_IDISHWND = 1
42
+ TTF_CENTERTIP = 2
43
+ TTF_SUBCLASS = 16
44
+ end
45
+
46
+ module WStruct
47
+ TOOLINFO = "IILLllllLp"
48
+ end
49
+
50
+ class VRTooltip < SWin::Window
51
+ =begin
52
+ == VRTooltip
53
+ This is a class for Tooltip window.
54
+ Tooltip windows are created by VRScreen.createTooltip()
55
+
56
+ === Methods
57
+ --- addTool(cntl,text)
58
+ Assigns a tooltip text for ((|cntl|)).
59
+ Returns a tooltip identifier.
60
+ --- addToolArea([sx,sy,ex,ey],text,wnd=self)
61
+ Assigns a tooltip text for the area in the parent window.
62
+ ((|sx|)) and ((|sy|)) indicate left-top corner,
63
+ and ((|ex|)) and ((|ey|)) indicate right-bottom corner.
64
+ Returns a tooltip identifier.
65
+ --- delTool(idf)
66
+ Deletes a tool identified by ((|idf|)) returned by addTool or addToolArea
67
+ --- enumTool
68
+ Yields all tool identifiers.
69
+ --- maxtipwidth
70
+ --- maxtipwidth=(mw)
71
+ About the tooltip width.
72
+ If you are to use multiline tooltip, set this parameter.
73
+ --- autopopTime
74
+ --- autopopTime=
75
+ Sets/Gets time length that tooltip remains visible.
76
+ --- initialTime
77
+ --- initialTime=
78
+ Sets/Gets time length that the pointer must remain stationary.
79
+ --- reshowTime
80
+ --- reshowTime=
81
+ Sets/Gets time length to reshow another tool's tooltip.
82
+
83
+ --- bkColor
84
+ --- bkColor=
85
+ Sets/Gets background color of tooltip window
86
+
87
+ --- textColor
88
+ --- textColor=
89
+ Sets/Gets text color of tooltip window
90
+
91
+ --- activate=(f)
92
+ ((|f|)) is boolean. This activates/deactivates the tooltip.
93
+ =end
94
+
95
+ class VRTooltipTool
96
+ attr :hwnd
97
+ attr :uid
98
+ attr :tool
99
+ def initialize(hwnd,uid,tool)
100
+ @hwnd,@uid,@tool = hwnd,uid,tool
101
+ end
102
+ end
103
+
104
+ private
105
+ def initialize
106
+ self.classname = "tooltips_class32"
107
+ self.style=1
108
+ self.exstyle= WExStyle::WS_EX_TOPMOST | WExStyle::WS_EX_TOOLWINDOW
109
+ @_vr_tools={}
110
+ end
111
+
112
+ def classcheck(cls,obj)
113
+ (eval("defined?(#{cls})") and obj.is_a?(eval(cls)))
114
+ end
115
+
116
+ def createTIPTOOLCore(wnd=@parent)
117
+ size=4*10
118
+ flag=WConst::TTF_SUBCLASS
119
+ hwnd=wnd.hWnd
120
+ uid= sx= sy= ex= ey= 0
121
+ hinst=@screen.application.hInstance
122
+ text=""
123
+ [size,flag,hwnd,uid,sx,sy,ex,ey,hinst,text]
124
+ end
125
+
126
+ def addToolCore(ti)
127
+ tis=ti.pack(WStruct::TOOLINFO)
128
+ sendMessage WMsg::TTM_ADDTOOL,0,tis
129
+ end
130
+
131
+ def getTOOLINFOCore(hwnd,uid)
132
+ ti=createTIPTOOLCore
133
+ ti[2]=hwnd
134
+ ti[3]=uid
135
+ ti[9] = "\0\0\0\0" * (1024/4+1) # /* Thanks, Wayne Vucenic */
136
+ tis = ti.pack(WStruct::TOOLINFO)
137
+ sendMessage WMsg::TTM_GETTOOLINFO,0,tis
138
+ tis.unpack(WStruct::TOOLINFO)
139
+ end
140
+
141
+ public
142
+
143
+ def setparam(parent,screen)
144
+ @parent,@screen = parent,screen unless defined? @screen
145
+ end
146
+
147
+ def activate=(f)
148
+ i = if f then 1 else 0 end
149
+ sendMessage WMsg::TTM_ACTIVATE,i,0
150
+ end
151
+
152
+ def maxtipwidth=(w)
153
+ s=[w].pack("L")
154
+ sendMessage WMsg::TTM_SETMAXTIPWIDTH,0,s
155
+ end
156
+
157
+ def maxtipwidth
158
+ sendMessage WMsg::TTM_GETMAXTIPWIDTH,0,0
159
+ end
160
+
161
+ def autopopTime
162
+ sendMessage WMsg::TTM_GETDELAYTIME,2,0
163
+ end
164
+ def initialTime
165
+ sendMessage WMsg::TTM_GETDELAYTIME,3,0
166
+ end
167
+ def reshowTime
168
+ sendMessage WMsg::TTM_GETDELAYTIME,1,0
169
+ end
170
+ def autopopTime=(msec)
171
+ sendMessage WMsg::TTM_SETDELAYTIME,2,MAKELPARAM(msec,0)
172
+ end
173
+ def initialTime=(msec)
174
+ sendMessage WMsg::TTM_SETDELAYTIME,3,MAKELPARAM(msec,0)
175
+ end
176
+ def reshowTime=(msec)
177
+ sendMessage WMsg::TTM_SETDELAYTIME,1,MAKELPARAM(msec,0)
178
+ end
179
+
180
+ def bkColor
181
+ sendMessage WMsg::TTM_GETTIPBKCOLOR,0,0
182
+ end
183
+ def bkColor=(c)
184
+ sendMessage WMsg::TTM_SETTIPBKCOLOR,c.to_i,0
185
+ end
186
+ def textColor
187
+ sendMessage WMsg::TTM_GETTIPTEXTCOLOR,0,0
188
+ end
189
+ def textColor=(c)
190
+ sendMessage WMsg::TTM_SETTIPTEXTCOLOR,c.to_i,0
191
+ end
192
+
193
+ def addTool(cnt,text)
194
+ if classcheck("VRStatic",cnt) then
195
+ sx=cnt.x; sy=cnt.y; ex=sx+cnt.w; ey=sy+cnt.h
196
+ rect = [sx,sy,ex,ey]
197
+ return addToolArea(rect,text)
198
+ end
199
+ if classcheck("VRToolbar::VRToolbarButton",cnt) then
200
+ rect = [0,0,0,0].pack("LLLL")
201
+ cnt.toolbar.sendMessage WMsg::TB_GETITEMRECT,cnt.index,rect
202
+ return addToolArea(rect.unpack("LLLL"),text,cnt.toolbar)
203
+ end
204
+
205
+ ti = createTIPTOOLCore
206
+ ti[1] |= WConst::TTF_IDISHWND
207
+ ti[3] = cnt.hWnd
208
+ ti[9] =text
209
+ addToolCore(ti)
210
+ @_vr_tools[ ti[2,2] ] = VRTooltipTool.new(@parent.hWnd,cnt.hWnd,cnt)
211
+ end
212
+
213
+ def addToolArea(rect,text,wnd=@parent)
214
+ sx,sy,ex,ey = *rect
215
+ ti = createTIPTOOLCore wnd
216
+ ti[3] = @parent.newControlID
217
+ ti[4]=sx ; ti[5]=sy; ti[6]=ex ; ti[7]=ey
218
+ ti[9] =text
219
+ addToolCore(ti)
220
+ @_vr_tools[ ti[2,2] ] = VRTooltipTool.new(@parent.hWnd,ti[3],rect)
221
+ end
222
+
223
+ def delTool(ttt)
224
+ raise "Requires VRTooltipTool (#{ttt.class})" unless ttt.is_a?(VRTooltipTool)
225
+ ti=createTIPTOOLCore
226
+ ti[2] = ttt.hwnd
227
+ ti[3] = ttt.uid
228
+ tts = ti.pack(WStruct::TOOLINFO)
229
+ @_vr_tools.delete(ti[2,2])
230
+ sendMessage WMsg::TTM_DELTOOL,0,tts
231
+ end
232
+
233
+ def enumTool
234
+ r = sendMessage WMsg::TTM_GETTOOLCOUNT,0,0
235
+ raise "Unknown error" if r!=@_vr_tools.size
236
+ @_vr_tools.each do |key,val|
237
+ yield val
238
+ end
239
+ end
240
+
241
+ def getTextOf(ttt,maxlength=1024) # there is no way to determine the length
242
+ ti = createTIPTOOLCore
243
+ buffer = "\0\0\0\0" * (maxlength/4+1)
244
+ ti[2] = ttt.hwnd
245
+ ti[3] = ttt.uid
246
+ ti[9] = buffer
247
+ tis = ti.pack(WStruct::TOOLINFO)
248
+ sendMessage WMsg::TTM_GETTEXT,0,tis
249
+ buffer.gsub!(/\0.*/,'')
250
+ buffer
251
+ end
252
+
253
+ def setTextOf(ttt,text)
254
+ ti = getTOOLINFOCore(ttt.hwnd,ttt.uid)
255
+ ti[9] = text
256
+ tis = ti.pack(WStruct::TOOLINFO)
257
+ sendMessage WMsg::TTM_SETTOOLINFO,0,tis
258
+ end
259
+
260
+ end
261
+
262
+
263
+ class VRForm
264
+ attr :tooltip
265
+ def createTooltip
266
+ return tooltip if defined?(@tooltip) && @tooltip
267
+ @tooltip = @screen.factory.newwindow(self,VRTooltip)
268
+ @tooltip.setparam self,@screen
269
+ @tooltip.create
270
+ @tooltip.etc = newControlID # error occurs if this line is before creation
271
+ @tooltip.top(-1)
272
+ end
273
+ end
274
+
@@ -0,0 +1,144 @@
1
+ ###################################
2
+ #
3
+ # vrtray.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 2002,2003 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+'vruby'
14
+
15
+ module VRTrayiconFeasible
16
+ =begin
17
+ == VRTrayiconFeasible
18
+ This modules is included to create/delete/modify tray icons.
19
+
20
+ === Methods
21
+ --- create_trayicon(icon=DEFAULTICON,tiptext="",icon_id=0)
22
+ Creates new trayicon in the tasktray.((|icon|)) is hIcon of the trayicon and
23
+ the trayicon has tooltip text ((|tiptext|)).
24
+ When argument ((|icon|)) is nil, icon will set as DEFAULTICON.
25
+ To distinguish multiple trayicon, ((|icon_id|)) information is added to it.
26
+ --- delete_trayicon(icon_id=0)
27
+ Deletes the trayicon specified by ((|icon_id|))
28
+ --- modify_trayicon(hicon,tiptext,iconid=0)
29
+ Modifies the trayicon's icon/tiptext.
30
+
31
+ === Event Handlers
32
+ --- self_traymousemove(icon_id)
33
+ Fired when mouse cursor is moved over the trayicon.
34
+ --- self_traylbuttondown(icon_id)
35
+ Fired when mouse left-button down on the trayicon.
36
+ --- self_traylbuttonup(icon_id)
37
+ Fired when mouse left-button up on the trayicon.
38
+ --- self_trayrbuttondown(icon_id)
39
+ Fired when mouse right-button down on the trayicon.
40
+ --- self_trayrbuttonup(icon_id)
41
+ Fired when mouse right-button up on the trayicon.
42
+ =end
43
+
44
+
45
+ include VRUserMessageUseable
46
+
47
+ Shell_NotifyIcon=Win32API.new("shell32","Shell_NotifyIcon","IP","I")
48
+
49
+ NOTIFYICONDATA_a = "IIIIII"
50
+ DEFAULTICON = Win32API.new("user32","LoadIcon","II","I").call(0,32512)
51
+
52
+ NIF_MESSAGE = 1
53
+ NIF_ICON = 2
54
+ NIF_TIP = 4
55
+ NIM_ADD = 0
56
+ NIM_MODIFY = 1
57
+ NIM_DELETE = 2
58
+
59
+ def vrinit
60
+ super
61
+ trayiconfeasibleinit
62
+ end
63
+
64
+ def trayiconfeasibleinit
65
+ @_vr_traynotify_msg = registerUserMessage(ReservedMsg::WM_VR_TRAYNOTIFY,"_vr_traynotify")
66
+ end
67
+
68
+ def create_trayicon(icon=DEFAULTICON,tiptext="",iconid=0)
69
+ icon = DEFAULTICON unless icon
70
+ tip = tiptext.to_s
71
+ s = [4*6+64,
72
+ self.hWnd,iconid,NIF_MESSAGE|NIF_ICON|NIF_TIP,
73
+ @_vr_traynotify_msg,icon ].pack(NOTIFYICONDATA_a) <<
74
+ tip << "\0"*(64-tip.length)
75
+ Shell_NotifyIcon.call(NIM_ADD,s)
76
+ end
77
+
78
+ def delete_trayicon(iconid=0)
79
+ s = [4*6+64,
80
+ self.hWnd,iconid,0,0,0].pack(NOTIFYICONDATA_a) << "\0"*64
81
+ Shell_NotifyIcon.call(NIM_DELETE,s)
82
+ end
83
+
84
+ def modify_trayicon(hicon,tiptext,iconid=0)
85
+ flag=0
86
+ if hicon then
87
+ flag |= NIF_ICON
88
+ end
89
+ if tiptext then
90
+ flag |= NIF_TIP
91
+ end
92
+ tip = tiptext.to_s
93
+ s = [4*6+64, self.hWnd,iconid,flag,0,hicon.to_i].pack(NOTIFYICONDATA_a) <<
94
+ tip << "\0"*(64-tip.length)
95
+ Shell_NotifyIcon.call(NIM_MODIFY,s)
96
+ end
97
+
98
+ def self__vr_traynotify(wparam,lparam)
99
+ case lparam
100
+ when WMsg::WM_MOUSEMOVE
101
+ selfmsg_dispatching("traymousemove",wparam)
102
+ when WMsg::WM_LBUTTONDOWN
103
+ selfmsg_dispatching("traylbuttondown",wparam)
104
+ when WMsg::WM_LBUTTONUP
105
+ selfmsg_dispatching("traylbuttonup",wparam)
106
+ when WMsg::WM_RBUTTONDOWN
107
+ selfmsg_dispatching("trayrbuttondown",wparam)
108
+ when WMsg::WM_RBUTTONUP
109
+ selfmsg_dispatching("trayrbuttonup",wparam)
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ module VRTasktraySensitive
116
+ =begin
117
+ == VRTasktraySensitive
118
+ This modules enables to sense the tasktray creation on restarting explorer.
119
+ The deleted tasktray icons can be created again using this module and writing
120
+ in its event handler how to do it.
121
+
122
+ === Event Handlers
123
+ --- self_taskbarcreated
124
+ Fired when the explorer restarts and creates its tasktray.
125
+ =end
126
+
127
+ RegisterWindowMessage = Win32API.new("user32","RegisterWindowMessage","P","L")
128
+
129
+ def vrinit
130
+ super
131
+ tasktraysensitive
132
+ end
133
+
134
+ def tasktraysensitive # coded by Katonbo-san
135
+ # get message ID of 'TaskbarCreated' message
136
+ id_taskbar_created = RegisterWindowMessage.call('TaskbarCreated')
137
+
138
+ # prepare 'TaskbarCreated' message handler
139
+ addHandler(id_taskbar_created, 'taskbarcreated', MSGTYPE::ARGNONE, nil)
140
+ addEvent(id_taskbar_created)
141
+ end
142
+ end
143
+
144
+