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,110 @@
1
+ ###############################
2
+ #
3
+ # contrib/vrctlcolor.rb
4
+ #
5
+ # These modules/classes are contributed by Shigitani-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
+ =begin
12
+ === VRCtlColor
13
+ VisualuRuby �ɂ����āAWM_CTLCOLOR ���������郂�W���[���B
14
+
15
+ === Methods
16
+ --- addCtlColor(ctl)
17
+ WM_CTLCOLOR ���󂯎�����Ƃ��ɏ�������Ώۂ̃R���g���[����o�^����B
18
+ �Ȃ��A�o�^����Ƃ��� ctl �ɂ� setTextColor, setBkColor �� 2 �‚̓��ك��\�b�h
19
+ ���lj�����܂��B
20
+
21
+ --- setTextColor(ctl, textcolor)
22
+ --- setBkColor(ctl, bkcolor)
23
+ �o�^�����R���g���[���̃e�L�X�g�F�A�w�i�F��ݒ肷��B�o�^����Ă��Ȃ��R���g
24
+ ���[�����w�肵���ꍇ�͉������Ȃ��B
25
+
26
+ --- ctl.setTextColor(textcolor)
27
+ --- ctl.setBkColor(bkcolor)
28
+ addCtlColor �Œlj����ꂽ���ك��\�b�h�B�R���g���[���̃e�L�X�g�F�A�w�i�F��ݒ�
29
+ ����B
30
+ =end
31
+
32
+ module WMsg
33
+ WM_CTLCOLORMSGBOX = 0x0132
34
+ WM_CTLCOLOREDIT = 0x0133
35
+ WM_CTLCOLORLISTBOX = 0x0134
36
+ WM_CTLCOLORBTN = 0x0135
37
+ WM_CTLCOLORDLG = 0x0136
38
+ WM_CTLCOLORSCROLLBAR = 0x0137
39
+ WM_CTLCOLORSTATIC = 0x0138
40
+ end
41
+
42
+ module VRCtlColor
43
+
44
+ include VRMessageHandler
45
+
46
+ def vrctlcolorinit
47
+ @win32_getBkColor = Win32API.new('gdi32.dll', 'GetBkColor', 'I', 'I')
48
+ @win32_setBkColor = Win32API.new('gdi32.dll', 'SetBkColor', 'II', 'I')
49
+ @win32_setTextColor = Win32API.new('gdi32.dll', 'SetTextColor', 'II', 'I')
50
+ @win32_createSolidBrush = Win32API.new('gdi32.dll', 'CreateSolidBrush', 'I', 'I')
51
+ @win32_deleteObject = Win32API.new('gdi32.dll', 'DeleteObject', 'I', 'I')
52
+
53
+ @_vrctlcolor = Hash.new
54
+ @_vrctlcolor_brush = Hash.new
55
+
56
+ msgs = [ WMsg::WM_CTLCOLORMSGBOX, WMsg::WM_CTLCOLOREDIT, WMsg::WM_CTLCOLORLISTBOX,
57
+ WMsg::WM_CTLCOLORBTN, WMsg::WM_CTLCOLORDLG, WMsg::WM_CTLCOLORSCROLLBAR,
58
+ WMsg::WM_CTLCOLORSTATIC ]
59
+ msgs.each {|msg| addHandler(msg, 'ctlcolor', MSGTYPE::ARGINTINT, nil) }
60
+ acceptEvents(msgs)
61
+ addHandler WMsg::WM_DESTROY,"_vrdestroy",MSGTYPE::ARGNONE,nil
62
+ acceptEvents [WMsg::WM_DESTROY]
63
+ end
64
+
65
+ def vrinit
66
+ super
67
+ vrctlcolorinit
68
+ end
69
+
70
+ def addCtlColor(ctl)
71
+ @_vrctlcolor[ctl.hWnd] = [nil, nil]
72
+ def ctl.setTextColor(textcolor)
73
+ parent.setTextColor(self, textcolor)
74
+ end
75
+ def ctl.setBkColor(bkcolor)
76
+ parent.setBkColor(self, bkcolor)
77
+ end
78
+ end
79
+
80
+ def setTextColor(ctl, textcolor)
81
+ return unless @_vrctlcolor.has_key?(ctl.hWnd)
82
+ @_vrctlcolor[ctl.hWnd][0] = textcolor
83
+ end
84
+
85
+ def setBkColor(ctl, bkcolor)
86
+ return unless @_vrctlcolor.has_key?(ctl.hWnd)
87
+ @_vrctlcolor[ctl.hWnd][1] = bkcolor
88
+ end
89
+
90
+ def self_ctlcolor(hDC, hWnd)
91
+ return nil unless @_vrctlcolor.has_key?(hWnd)
92
+ textcolor, bkcolor = @_vrctlcolor[hWnd]
93
+ @win32_setTextColor.call(hDC, textcolor) unless textcolor.nil?
94
+ bkcolor = @win32_getBkColor.call(hDC) if bkcolor.nil?
95
+ @win32_setBkColor.call(hDC, bkcolor)
96
+ SKIP_DEFAULTHANDLER[get_brush(bkcolor)]
97
+ end
98
+
99
+ def get_brush(bkcolor)
100
+ unless @_vrctlcolor_brush.has_key?(bkcolor) then
101
+ @_vrctlcolor_brush[bkcolor] = @win32_createSolidBrush.call(bkcolor)
102
+ end
103
+ @_vrctlcolor_brush[bkcolor]
104
+ end
105
+
106
+ def self__vrdestroy
107
+ @_vrctlcolor_brush.values.each {|brush| @win32_deleteObject.call(brush) }
108
+ end
109
+
110
+ end
@@ -0,0 +1,35 @@
1
+ ###############################
2
+ #
3
+ # contrib/vrhotkey.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
+ #====================================================================#
13
+ # WConst Module
14
+ module WConst
15
+ WM_HOTKEY = 786
16
+ end
17
+
18
+ #====================================================================#
19
+ # VRHotKey Module
20
+ module VRHotKey
21
+
22
+ #==================================================================#
23
+ # Instance Methods
24
+
25
+ def vrinit
26
+ super
27
+ self.addHandler(WConst::WM_HOTKEY, 'hotkey', MSGTYPE::ARGWINT, nil)
28
+ self.addEvent(WConst::WM_HOTKEY)
29
+ end
30
+
31
+ end
32
+
33
+ #====================================================================#
34
+ # End of source.
35
+ #====================================================================#
@@ -0,0 +1,71 @@
1
+ ###############################
2
+ #
3
+ # contrib/vrlistviewex.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
+ # VRListview Class
13
+ class VRListview
14
+
15
+ #==================================================================#
16
+ # Private Instance Methods
17
+
18
+ def exstyle_getter(style)
19
+ return (self.lvexstyle & style) == style
20
+ end
21
+ private :exstyle_getter
22
+
23
+ def exstyle_setter(style, bool)
24
+ if bool
25
+ self.lvexstyle |= style
26
+ else
27
+ self.lvexstyle &= 0xFFFFFFFF - style
28
+ end
29
+ end
30
+ private :exstyle_setter
31
+
32
+ #==================================================================#
33
+ # Instance Methods
34
+
35
+ def row_select
36
+ return exstyle_getter(WExStyle::LVS_EX_FULLROWSELECT)
37
+ end
38
+
39
+ def row_select=(bool)
40
+ exstyle_setter(WExStyle::LVS_EX_FULLROWSELECT, bool)
41
+ end
42
+
43
+ def grid_lines
44
+ return exstyle_getter(WExStyle::LVS_EX_GRIDLINES)
45
+ end
46
+
47
+ def grid_lines=(bool)
48
+ exstyle_setter(WExStyle::LVS_EX_GRIDLINES, bool)
49
+ end
50
+
51
+ def hide_selection
52
+ return !self.winstyle.getter(WStyle::LVS_SHOWSELALWAYS)
53
+ end
54
+
55
+ def hide_selection=(bool)
56
+ self.winstyle.setter(WStyle::LVS_SHOWSELALWAYS, !bool)
57
+ end
58
+
59
+ def extended_select
60
+ return !self.winstyle.getter(WStyle::LVS_SINGLESEL)
61
+ end
62
+
63
+ def extended_select=(bool)
64
+ self.winstyle.setter(WStyle::LVS_SINGLESEL, !bool)
65
+ end
66
+
67
+ end
68
+
69
+ #====================================================================#
70
+ # End of source.
71
+ #====================================================================#
@@ -0,0 +1,54 @@
1
+ ###############################
2
+ #
3
+ # contrib/vrwincomponent.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
+ # VRWinComponent Class
13
+ class VRWinComponent
14
+
15
+ #==================================================================#
16
+ # Instance Methods
17
+
18
+ def maximizebox
19
+ return self.winstyle.getter(WStyle::WS_MAXIMIZEBOX)
20
+ end
21
+
22
+ def maximizebox=(bool)
23
+ self.winstyle.setter(WStyle::WS_MAXIMIZEBOX, bool)
24
+ end
25
+
26
+ def minimizebox
27
+ return self.winstyle.getter(WStyle::WS_MINIMIZEBOX)
28
+ end
29
+
30
+ def minimizebox=(bool)
31
+ self.winstyle.setter(WStyle::WS_MINIMIZEBOX, bool)
32
+ end
33
+
34
+ def sizebox
35
+ return self.winstyle.getter(WStyle::WS_SIZEBOX)
36
+ end
37
+
38
+ def sizebox=(bool)
39
+ self.winstyle.setter(WStyle::WS_SIZEBOX, bool)
40
+ end
41
+
42
+ def tabstop
43
+ return self.winstyle.getter(WStyle::WS_TABSTOP)
44
+ end
45
+
46
+ def tabstop=(bool)
47
+ self.winstyle.setter(WStyle::WS_TABSTOP, bool)
48
+ end
49
+
50
+ end
51
+
52
+ #====================================================================#
53
+ # End of source.
54
+ #====================================================================#
@@ -0,0 +1,210 @@
1
+ ###################################
2
+ #
3
+ # dragdropformat.rb
4
+ # Programmed by nyasu <nyasu@osk.3web.ne.jp>
5
+ # Copyright 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
+ module ClipboardFormat
17
+ RegisterClipboardFormat =
18
+ Win32API.new("user32","RegisterClipboardFormat","P","I")
19
+
20
+ CF_URL = RegisterClipboardFormat.call("UniformResourceLocator")
21
+
22
+ end
23
+
24
+ class DragDropObject
25
+ =begin
26
+ == DragDropObject
27
+ A capsule for OLE Drag and Drop
28
+ This is just a base class. Don't use this directly.
29
+
30
+ === Methods
31
+ --- handle
32
+ Returns a global heap handle containing the file pathes.
33
+ --- free_handle
34
+ Tries to free the handle.
35
+ Please check you really need to free it, because sometimes your OS will
36
+ free it automatically at the appropriate timing.
37
+ =end
38
+
39
+ def initialize
40
+ @__binarydata=""
41
+ end
42
+ def handle
43
+ @handle=GMEM::AllocStr(0x2000,@__binarydata)
44
+ end
45
+ def free_handle
46
+ GMEM::Free(@handle)
47
+ @handle=0
48
+ end
49
+
50
+ def objectformat
51
+ self.class::FormatId
52
+ end
53
+
54
+ end
55
+
56
+ class DragDropText < DragDropObject
57
+ =begin
58
+ == DragDropText
59
+ This class deals the structure for drag-and-drop files.
60
+
61
+ === Class Methods
62
+ --- set(files)
63
+ Creates object and sets the file pathes in ((|files|)) to the object.
64
+ --- get(handle)
65
+ Create object and sets the file pathes containing in ((|handle|)).
66
+ The ((|handle|)) is a global heap handle.
67
+ === Methods
68
+ --- text
69
+ Returns the text.
70
+ =end
71
+
72
+ FormatName="CF_TEXT"
73
+ FormatId=ClipboardFormat::CF_TEXT
74
+
75
+ def initialize(text,handle=0)
76
+ @__binarydata = @__texts = text.to_str.dup
77
+ @handle=handle
78
+ end
79
+
80
+ def self.set(texts)
81
+ self.new(texts)
82
+ end
83
+
84
+ def self.get(handle)
85
+ self.new(GMEM::Get(handle),handle)
86
+ end
87
+
88
+ def text
89
+ @__texts.dup
90
+ end
91
+ end
92
+
93
+ class DragDropFiles < DragDropObject
94
+ =begin
95
+ == DragDropFiles
96
+ This class deals the structure for drag-and-drop files.
97
+
98
+ === Class Methods
99
+ --- set(files)
100
+ Creates object and sets the file pathes in ((|files|)) to the object.
101
+ --- get(handle)
102
+ Create object and sets the file pathes containing in ((|handle|)).
103
+ The ((|handle|)) is a global heap handle.
104
+ === Methods
105
+ --- files
106
+ Returns the file pathes.
107
+ =end
108
+
109
+ FormatName = "CF_HDROP"
110
+ FormatId = ClipboardFormat::CF_HDROP
111
+
112
+ DragQueryFile = Win32API.new("shell32","DragQueryFile", ["I","I","P","I"],"I")
113
+
114
+ def initialize(files,handle=0)
115
+ @__files = files.dup
116
+ @handle=handle
117
+ @__binarydata="\0"*0x14+@__files.join("\0")+"\0"
118
+ @__binarydata[0]=0x14
119
+ end
120
+
121
+ def self.set(files)
122
+ self.new(files)
123
+ end
124
+
125
+ def self.get(handle)
126
+ __fnbuffer = " "*16 #256bytes
127
+ n=DragQueryFile.call(handle,-1,__fnbuffer,__fnbuffer.size)
128
+ r=[]
129
+ 0.upto(n-1) do |i|
130
+ s=DragQueryFile.call(handle,i,__fnbuffer,__fnbuffer.size)
131
+ r.push __fnbuffer[0,s]
132
+ end
133
+ self.new(r,handle)
134
+ end
135
+
136
+ def files
137
+ @__files.dup
138
+ end
139
+ end
140
+
141
+
142
+ module DragDropRubyObjectFactory
143
+ =begin
144
+ == DragDropRubyObjectFactory
145
+ This class' feature is to register new clipboard format into your system for
146
+ drag&drop ruby object.
147
+
148
+ === Class Methods
149
+ --- declare_dndclass(classname,registername)
150
+ Registers new format and create new wrapper class for ruby.
151
+ The format is registered as ((|registername|)) and
152
+ the wrapper class is declared as DragDropRubyObjectFactory::((|classname|)).
153
+ This methods returns the wrapper class.
154
+ =end
155
+
156
+
157
+ class DragDropRubyObject < DragDropObject
158
+ =begin
159
+ == DragDropRubyObjectFactory::DragDropRubyObject
160
+ This is a base class of wrapper classes created by
161
+ DragDropRubyObjectFactory.declare_dndclass()
162
+
163
+ === Class Methods
164
+ --- new(binstr,handle=0)
165
+ No need to use this. (maybe)
166
+ --- set(obj)
167
+ Returns new wrapper object of ((|obj|)) for drag&drop.
168
+ --- get(handle)
169
+ Returns wrapper object using global heap of ((|handle|)).
170
+ === Method
171
+ --- object
172
+ returns the wrapped object.
173
+ =end
174
+
175
+ include ClipboardFormat
176
+ FormatName = "DumpedRubyObjectForDnD"
177
+ FormatId = RegisterClipboardFormat.call(FormatName)
178
+
179
+ def initialize(bin,handle=0)
180
+ @objectformat = ClipboardFormat::CF_TEXT # only for base class
181
+ @__binarydata = bin
182
+ @handle=handle
183
+ end
184
+
185
+ def self.set(obj)
186
+ self.new(Marshal.dump(obj))
187
+ end
188
+
189
+ def self.get(handle)
190
+ bin = GMEM::Get(handle)
191
+ self.new(bin,handle)
192
+ end
193
+
194
+ def object
195
+ Marshal.load(@__binarydata)
196
+ end
197
+ end
198
+
199
+ def self.declare_dndclass(classname,registername)
200
+ str = <<"EEOOFF"
201
+ class #{classname} < DragDropRubyObject
202
+ FormatName = '#{registername}'
203
+ FormatId = RegisterClipboardFormat.call(FormatName)
204
+ end
205
+ EEOOFF
206
+ eval(str)
207
+ eval("#{classname} ")
208
+ end
209
+
210
+ end