win32-clipboard 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.4.1 - 30-Jul-2006
2
+ * Now uses the windows-pr package. No API changes.
3
+ * Made Clipboard.get_data a true alias (instead of a facade).
4
+
1
5
  == 0.4.0 - 24-Feb-2006
2
6
  * Removed the C version entirely and replaced it with a pure Ruby version
3
7
  that uses the Win32API package.
data/MANIFEST CHANGED
@@ -1,8 +1,8 @@
1
1
  MANIFEST
2
2
  CHANGES
3
3
  README
4
-
5
- doc/clipboard.txt
4
+ install.rb
5
+ win32-clipboard.gemspec
6
6
 
7
7
  examples/clipboard_test.rb
8
8
 
data/README CHANGED
@@ -9,7 +9,7 @@
9
9
  puts "Number of available formats: " + Clipboard.num_formats
10
10
 
11
11
  puts "Setting data to 'foobar'"
12
- Clipboard.data = "foobar"
12
+ Clipboard.set_data("foobar")
13
13
 
14
14
  puts "Clipboard now contains: " + Clipboard.data
15
15
 
@@ -27,12 +27,6 @@ Clipboard.get_data(format=nil)
27
27
  Note that this method does implicit conversions on formats with regards
28
28
  to text data. See the MSDN documentation for more details.
29
29
 
30
- Clipboard.set_data(data, format=nil)
31
- Sets the clipboard contents to the data that you specify. You may
32
- optionally specify a clipboard format. The default is Clipboard::TEXT.
33
-
34
- See the 'Constants' section for a list of the supported formats.
35
-
36
30
  Clipboard.empty
37
31
  Empty the contents of the clipboard
38
32
 
@@ -64,6 +58,12 @@ Clipboard.register_format(format)
64
58
  Registered clipboard formats are identified by values in the range 0xC000
65
59
  through 0xFFFF.
66
60
 
61
+ Clipboard.set_data(data, format=nil)
62
+ Sets the clipboard contents to the data that you specify. You may
63
+ optionally specify a clipboard format. The default is Clipboard::TEXT.
64
+
65
+ See the 'Constants' section for a list of the supported formats.
66
+
67
67
  == Error Classes
68
68
  ClipboardError
69
69
  Typically only raised if the clipboard fails to open or if you attempt to
@@ -1,58 +1,34 @@
1
- require "Win32API"
1
+ require 'windows/clipboard'
2
+ require 'windows/memory'
3
+ require 'windows/error'
2
4
 
3
5
  module Win32
4
6
  class ClipboardError < StandardError; end
5
7
  class Clipboard
6
- VERSION = '0.4.0'
8
+ include Windows::Clipboard
9
+ include Windows::Memory
10
+ include Windows::Error
11
+ extend Windows::Clipboard
12
+ extend Windows::Memory
13
+ extend Windows::Error
14
+
15
+ VERSION = '0.4.1'
7
16
 
8
17
  # Clipboard data types
9
- TEXT = 1
10
- OEMTEXT = 7
11
- UNICODETEXT = 13
12
-
13
- # Alloc constants
14
- GMEM_MOVEABLE = 0x0002
15
- GMEM_ZEROINIT = 0x0040
16
- GHND = 0x0042
17
-
18
- # Clipboard specific functions
19
- @@OpenClipboard = Win32API.new('user32', 'OpenClipboard', 'L', 'I')
20
- @@CloseClipboard = Win32API.new('user32', 'CloseClipboard', 'V', 'I')
21
- @@GetClipboardData = Win32API.new('user32', 'GetClipboardData', 'I', 'P')
22
- @@SetClipboardData = Win32API.new('user32', 'SetClipboardData', 'II', 'I')
23
- @@EmptyClipboard = Win32API.new('user32', 'EmptyClipboard', 'V', 'I')
18
+ TEXT = CF_TEXT
19
+ OEMTEXT = CF_OEMTEXT
20
+ UNICODETEXT = CF_UNICODETEXT
24
21
 
25
- @@CountClipboardFormats = Win32API.new(
26
- 'user32', 'CountClipboardFormats', 'V', 'I'
27
- )
28
-
29
- @@IsClipboardFormatAvailable = Win32API.new(
30
- 'user32', 'IsClipboardFormatAvailable', 'I', 'I'
31
- )
32
-
33
- @@GetClipboardFormatName = Win32API.new(
34
- 'user32', 'GetClipboardFormatName', 'IPI', 'I'
35
- )
36
-
37
- @@EnumClipboardFormats = Win32API.new(
38
- 'user32', 'EnumClipboardFormats', 'I', 'I'
39
- )
40
-
41
- @@RegisterClipboardFormat = Win32API.new(
42
- 'user32', 'RegisterClipboardFormat', 'P', 'I'
43
- )
44
-
45
- # Generic Win32 functions
46
- @@GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'II' ,'I')
47
- @@GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'I' ,'I')
48
- @@GlobalFree = Win32API.new('kernel32', 'GlobalFree', 'I' ,'I')
49
- @@Memcpy = Win32API.new('msvcrt', 'memcpy', 'IPI', 'I')
22
+ # We'll use a custom definition of memcpy since this is different than
23
+ # what's in the Windows::MSVCRT::Buffer module.
24
+ @@Memcpy = Win32API.new('msvcrt', 'memcpy', 'IPI', 'I')
50
25
 
51
26
  # Sets the clipboard contents to the data that you specify. You may
52
27
  # optionally specify a clipboard format. The default is Clipboard::TEXT.
28
+ #
53
29
  def self.set_data(clip_data, format = TEXT)
54
30
  self.open
55
- @@EmptyClipboard.call
31
+ EmptyClipboard()
56
32
 
57
33
  # NULL terminate text
58
34
  case format
@@ -61,73 +37,80 @@ module Win32
61
37
  end
62
38
 
63
39
  # Global Allocate a movable piece of memory.
64
- hmem = @@GlobalAlloc.call(GHND, clip_data.length + 4)
65
- mem = @@GlobalLock.call(hmem)
40
+ hmem = GlobalAlloc(GHND, clip_data.length + 4)
41
+ mem = GlobalLock(hmem)
66
42
  @@Memcpy.call(mem, clip_data, clip_data.length)
67
43
 
68
44
  # Set the new data
69
- if @@SetClipboardData.call(format, hmem) == 0
70
- @@GlobalFree.call(hmem)
45
+ if SetClipboardData(format, hmem) == 0
46
+ error = get_last_error
47
+ GlobalFree(hmem)
71
48
  self.close
72
- raise ClipboardError, "SetClipboardData() failed"
49
+ raise ClipboardError, "SetClipboardData() failed: #{error}"
73
50
  end
74
51
 
75
- @@GlobalFree.call(hmem)
52
+ GlobalFree(hmem)
76
53
  self.close
77
54
  self
78
55
  end
79
56
 
80
- # Returns the data currently in the clipboard. If 'format' is
57
+ # Returns the data currently in the clipboard. If +format+ is
81
58
  # specified, it will attempt to retrieve the data in that format. The
82
- # default is Clipboard::TEXT.
59
+ # default is Clipboard::TEXT.
60
+ #
83
61
  def self.data(format = TEXT)
84
62
  clipdata = ""
85
63
  self.open
86
64
  begin
87
- clipdata = @@GetClipboardData.call(format)
65
+ clipdata = GetClipboardData(format)
88
66
  rescue ArgumentError
89
67
  # Assume failure is caused by no data in clipboard
90
68
  end
91
69
  self.close
92
70
  clipdata
93
71
  end
94
-
95
- # An alias for Clipboard.data.
96
- def self.get_data(format = TEXT)
97
- self.data(format)
72
+
73
+ # Singleton aliases
74
+ #
75
+ class << self
76
+ alias :get_data :data
98
77
  end
99
78
 
100
79
  # Empties the contents of the clipboard.
80
+ #
101
81
  def self.empty
102
82
  self.open
103
- @@EmptyClipboard.call
83
+ EmptyClipboard()
104
84
  self.close
105
85
  self
106
86
  end
107
87
 
108
88
  # Returns the number of different data formats currently on the
109
89
  # clipboard.
90
+ #
110
91
  def self.num_formats
111
92
  count = 0
112
93
  self.open
113
- count = @@CountClipboardFormats.call
94
+ count = CountClipboardFormats()
114
95
  self.close
115
96
  count
116
97
  end
117
98
 
118
99
  # Returns whether or not +format+ (an int) is currently available.
100
+ #
119
101
  def self.format_available?(format)
120
- @@IsClipboardFormatAvailable.call(format) == 0 ? false : true
102
+ IsClipboardFormatAvailable(format)
121
103
  end
122
104
 
123
- # Returns the corresponding name for the given 'format_number', or nil
105
+ # Returns the corresponding name for the given +format_num+, or nil
124
106
  # if it does not exist. You cannot specify any of the predefined
125
107
  # clipboard formats (or nil is returned), only registered formats.
126
- def self.format_name(format)
108
+ #
109
+ def self.format_name(format_num)
127
110
  val = nil
128
111
  buf = 0.chr * 80
129
112
  self.open
130
- if @@GetClipboardFormatName.call(format, buf, buf.length) != 0
113
+ if GetClipboardFormatName(format_num, buf, buf.length) != 0
131
114
  val = buf
132
115
  end
133
116
  self.close
@@ -136,21 +119,22 @@ module Win32
136
119
 
137
120
  # Returns a hash of all the current formats, with the format number as
138
121
  # the key and the format name as the value for that key.
122
+ #
139
123
  def self.formats
140
124
  formats = {}
141
125
  format = 0
142
126
 
143
127
  self.open
144
- while 0 != (format = @@EnumClipboardFormats.call(format))
128
+ while 0 != (format = EnumClipboardFormats(format))
145
129
  buf = 0.chr * 80
146
- @@GetClipboardFormatName.call(format, buf, buf.length)
130
+ GetClipboardFormatName(format, buf, buf.length)
147
131
  formats[format] = buf.split(0.chr).first
148
132
  end
149
133
  self.close
150
134
  formats
151
135
  end
152
136
 
153
- # Registers the given 'format' (a String) as a clipboard format, which
137
+ # Registers the given +format+ (a String) as a clipboard format, which
154
138
  # can then be used as a valid clipboard format.
155
139
  #
156
140
  # If a registered format with the specified name already exists, a new
@@ -161,22 +145,24 @@ module Win32
161
145
  #
162
146
  # Registered clipboard formats are identified by values in the range 0xC000
163
147
  # through 0xFFFF.
148
+ #
164
149
  def self.register_format(format)
165
- if @@RegisterClipboardFormat.call(format) == 0
166
- raise ClipboardError, "RegisterClipboardFormat() call failed"
150
+ if RegisterClipboardFormat(format) == 0
151
+ error = "RegisterClipboardFormat() call failed: " + get_last_error
152
+ raise ClipboardError, error
167
153
  end
168
154
  end
169
155
 
170
156
  private
171
157
 
172
158
  def self.open
173
- if 0 == @@OpenClipboard.call(0)
174
- raise ClipboardError, "OpenClipboard() failed"
159
+ if 0 == OpenClipboard(0)
160
+ raise ClipboardError, "OpenClipboard() failed: " + get_last_error
175
161
  end
176
162
  end
177
163
 
178
164
  def self.close
179
- @@CloseClipboard.call
165
+ CloseClipboard()
180
166
  end
181
167
  end
182
168
  end
data/test/tc_clipboard.rb CHANGED
@@ -18,7 +18,7 @@ include Win32
18
18
 
19
19
  class TC_Win32ClipBoard < Test::Unit::TestCase
20
20
  def test_version
21
- assert_equal('0.4.0', Clipboard::VERSION)
21
+ assert_equal('0.4.1', Clipboard::VERSION)
22
22
  end
23
23
 
24
24
  def test_data
@@ -28,6 +28,14 @@ class TC_Win32ClipBoard < Test::Unit::TestCase
28
28
  assert_raises(NameError){ Clipboard.data(CF_FOO) }
29
29
  end
30
30
 
31
+ # Alias
32
+ def test_get_data
33
+ assert_respond_to(Clipboard, :get_data)
34
+ assert_nothing_raised{ Clipboard.get_data }
35
+ assert_kind_of(String, Clipboard.get_data, 'bad data type')
36
+ assert_raises(NameError){ Clipboard.get_data(CF_FOO) }
37
+ end
38
+
31
39
  def test_set_data
32
40
  assert_respond_to(Clipboard, :set_data)
33
41
  assert_nothing_raised{ Clipboard.set_data("foo") }
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: win32-clipboard
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2006-02-24 00:00:00 -07:00
6
+ version: 0.4.1
7
+ date: 2006-07-30 00:00:00 -06:00
8
8
  summary: A package for interacting with the Windows clipboard
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Daniel J. Berger
30
31
  files:
@@ -47,5 +48,13 @@ extensions: []
47
48
 
48
49
  requirements: []
49
50
 
50
- dependencies: []
51
-
51
+ dependencies:
52
+ - !ruby/object:Gem::Dependency
53
+ name: windows-pr
54
+ version_requirement:
55
+ version_requirements: !ruby/object:Gem::Version::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.4.1
60
+ version: