win32-clipboard 0.4.3 → 0.4.4
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.
- data/CHANGES +7 -0
- data/MANIFEST +1 -1
- data/README +7 -7
- data/Rakefile +1 -2
- data/lib/win32/clipboard.rb +54 -35
- data/test/{tc_clipboard.rb → test_clipboard.rb} +7 -10
- data/win32-clipboard.gemspec +6 -7
- metadata +54 -45
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.4.4 - 26-Aug-2008
|
2
|
+
* Some internal refactoring to ensure that the clipboard is closed on failure
|
3
|
+
in a more robust fashion.
|
4
|
+
* Renamed the test file.
|
5
|
+
* Eliminated the custom memcpy function, since windows-pr now does the right
|
6
|
+
thing. This necessitated bumping the minimum required windows-pr version.
|
7
|
+
|
1
8
|
== 0.4.3 - 25-Jul-2007
|
2
9
|
* Changed ClipboardError to Clipboard::Error
|
3
10
|
* Added a Rakefile with tasks for testing and installation.
|
data/MANIFEST
CHANGED
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
== Description
|
2
|
-
win32-clipboard - a Ruby
|
2
|
+
win32-clipboard - a Ruby library for interacting with the Win32 clipboard.
|
3
3
|
|
4
4
|
== Installation
|
5
5
|
rake test (optional)
|
@@ -26,6 +26,8 @@ Clipboard.data(format=nil)
|
|
26
26
|
specified, it will attempt to retrieve the data in that format. The
|
27
27
|
default is Clipboard::TEXT. See the 'Constants' section for
|
28
28
|
the supported formats.
|
29
|
+
|
30
|
+
If there is no data in the clipboard, then an empty string is returned.
|
29
31
|
|
30
32
|
Note that this method does implicit conversions on formats with regards
|
31
33
|
to text data. See the MSDN documentation for more details.
|
@@ -93,8 +95,7 @@ Clipboard::TEXT
|
|
93
95
|
|
94
96
|
Clipboard::UNICODETEXT
|
95
97
|
Unicode text format. Each line ends with a carriage return/linefeed
|
96
|
-
(CR-LF) combination. A null character signals the end of the data.
|
97
|
-
format is only supported on NT/2000/XP.
|
98
|
+
(CR-LF) combination. A null character signals the end of the data.
|
98
99
|
|
99
100
|
== Future Plans
|
100
101
|
Add more formatting option contants and related methods.
|
@@ -103,10 +104,9 @@ Clipboard::UNICODETEXT
|
|
103
104
|
Ruby's
|
104
105
|
|
105
106
|
== Copyright
|
106
|
-
(C) 2003-
|
107
|
+
(C) 2003-2008 Daniel J. Berger
|
107
108
|
All Rights Reserved
|
108
109
|
|
109
|
-
==
|
110
|
+
== Authors
|
110
111
|
Daniel J. Berger
|
111
|
-
|
112
|
-
imperator on IRC (irc.freenode.org)
|
112
|
+
Park Heesob
|
data/Rakefile
CHANGED
data/lib/win32/clipboard.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'windows/clipboard'
|
2
2
|
require 'windows/memory'
|
3
3
|
require 'windows/error'
|
4
|
+
require 'windows/msvcrt/buffer'
|
4
5
|
|
5
6
|
module Win32
|
6
7
|
class Clipboard
|
@@ -9,21 +10,20 @@ module Win32
|
|
9
10
|
include Windows::Clipboard
|
10
11
|
include Windows::Memory
|
11
12
|
include Windows::Error
|
13
|
+
include Windows::MSVCRT::Buffer
|
14
|
+
|
12
15
|
extend Windows::Clipboard
|
13
16
|
extend Windows::Memory
|
14
17
|
extend Windows::Error
|
18
|
+
extend Windows::MSVCRT::Buffer
|
15
19
|
|
16
|
-
VERSION = '0.4.
|
20
|
+
VERSION = '0.4.4'
|
17
21
|
|
18
22
|
# Clipboard data types
|
19
23
|
TEXT = CF_TEXT
|
20
24
|
OEMTEXT = CF_OEMTEXT
|
21
25
|
UNICODETEXT = CF_UNICODETEXT
|
22
26
|
|
23
|
-
# We'll use a custom definition of memcpy since this is different than
|
24
|
-
# what's in the Windows::MSVCRT::Buffer module.
|
25
|
-
@@Memcpy = Win32API.new('msvcrt', 'memcpy', 'IPI', 'I')
|
26
|
-
|
27
27
|
# Sets the clipboard contents to the data that you specify. You may
|
28
28
|
# optionally specify a clipboard format. The default is Clipboard::TEXT.
|
29
29
|
#
|
@@ -40,34 +40,35 @@ module Win32
|
|
40
40
|
# Global Allocate a movable piece of memory.
|
41
41
|
hmem = GlobalAlloc(GHND, clip_data.length + 4)
|
42
42
|
mem = GlobalLock(hmem)
|
43
|
-
|
43
|
+
memcpy(mem, clip_data, clip_data.length)
|
44
44
|
|
45
45
|
# Set the new data
|
46
|
-
|
47
|
-
|
46
|
+
begin
|
47
|
+
if SetClipboardData(format, hmem) == 0
|
48
|
+
raise Error, "SetClipboardData() failed: " + get_last_error
|
49
|
+
end
|
50
|
+
ensure
|
48
51
|
GlobalFree(hmem)
|
49
52
|
self.close
|
50
|
-
raise Error, "SetClipboardData() failed: #{error}"
|
51
53
|
end
|
52
54
|
|
53
|
-
GlobalFree(hmem)
|
54
|
-
self.close
|
55
55
|
self
|
56
56
|
end
|
57
57
|
|
58
|
-
# Returns the data currently in the clipboard.
|
58
|
+
# Returns the data currently in the clipboard. If +format+ is
|
59
59
|
# specified, it will attempt to retrieve the data in that format. The
|
60
60
|
# default is Clipboard::TEXT.
|
61
|
+
#
|
62
|
+
# If there is no data in the clipboard then an empty string is returned.
|
61
63
|
#
|
62
64
|
def self.data(format = TEXT)
|
63
|
-
clipdata = ""
|
64
|
-
self.open
|
65
65
|
begin
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
self.open
|
67
|
+
clipdata = GetClipboardData(format) || ""
|
68
|
+
ensure
|
69
|
+
self.close
|
69
70
|
end
|
70
|
-
|
71
|
+
|
71
72
|
clipdata
|
72
73
|
end
|
73
74
|
|
@@ -80,9 +81,13 @@ module Win32
|
|
80
81
|
# Empties the contents of the clipboard.
|
81
82
|
#
|
82
83
|
def self.empty
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
begin
|
85
|
+
self.open
|
86
|
+
EmptyClipboard()
|
87
|
+
ensure
|
88
|
+
self.close
|
89
|
+
end
|
90
|
+
|
86
91
|
self
|
87
92
|
end
|
88
93
|
|
@@ -91,9 +96,14 @@ module Win32
|
|
91
96
|
#
|
92
97
|
def self.num_formats
|
93
98
|
count = 0
|
94
|
-
|
95
|
-
|
96
|
-
|
99
|
+
|
100
|
+
begin
|
101
|
+
self.open
|
102
|
+
count = CountClipboardFormats()
|
103
|
+
ensure
|
104
|
+
self.close
|
105
|
+
end
|
106
|
+
|
97
107
|
count
|
98
108
|
end
|
99
109
|
|
@@ -104,17 +114,22 @@ module Win32
|
|
104
114
|
end
|
105
115
|
|
106
116
|
# Returns the corresponding name for the given +format_num+, or nil
|
107
|
-
# if it does not exist.
|
117
|
+
# if it does not exist. You cannot specify any of the predefined
|
108
118
|
# clipboard formats (or nil is returned), only registered formats.
|
109
119
|
#
|
110
120
|
def self.format_name(format_num)
|
111
121
|
val = nil
|
112
122
|
buf = 0.chr * 80
|
113
|
-
|
114
|
-
|
115
|
-
|
123
|
+
|
124
|
+
begin
|
125
|
+
self.open
|
126
|
+
if GetClipboardFormatName(format_num, buf, buf.length) != 0
|
127
|
+
val = buf
|
128
|
+
end
|
129
|
+
ensure
|
130
|
+
self.close
|
116
131
|
end
|
117
|
-
|
132
|
+
|
118
133
|
val.split(0.chr).first rescue nil
|
119
134
|
end
|
120
135
|
|
@@ -125,13 +140,17 @@ module Win32
|
|
125
140
|
formats = {}
|
126
141
|
format = 0
|
127
142
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
143
|
+
begin
|
144
|
+
self.open
|
145
|
+
while 0 != (format = EnumClipboardFormats(format))
|
146
|
+
buf = 0.chr * 80
|
147
|
+
GetClipboardFormatName(format, buf, buf.length)
|
148
|
+
formats[format] = buf.split(0.chr).first
|
149
|
+
end
|
150
|
+
ensure
|
151
|
+
self.close
|
133
152
|
end
|
134
|
-
|
153
|
+
|
135
154
|
formats
|
136
155
|
end
|
137
156
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
###########################################################################
|
2
|
-
#
|
2
|
+
# test_clipboard.rb
|
3
3
|
#
|
4
|
-
# Test suite for the win32-clipboard
|
5
|
-
# data from your clipboard.
|
4
|
+
# Test suite for the win32-clipboard library. This will copy and remove
|
5
|
+
# data from your clipboard. If your current clipboard data is crucial to
|
6
6
|
# you, please save it first.
|
7
7
|
#
|
8
8
|
# You should run this test case via the 'rake test' task.
|
@@ -11,9 +11,9 @@ require 'win32/clipboard'
|
|
11
11
|
require 'test/unit'
|
12
12
|
include Win32
|
13
13
|
|
14
|
-
class
|
14
|
+
class TC_Win32_ClipBoard < Test::Unit::TestCase
|
15
15
|
def test_version
|
16
|
-
assert_equal('0.4.
|
16
|
+
assert_equal('0.4.4', Clipboard::VERSION)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_data
|
@@ -23,12 +23,9 @@ class TC_Win32ClipBoard < Test::Unit::TestCase
|
|
23
23
|
assert_raises(NameError){ Clipboard.data(CF_FOO) }
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
def test_get_data
|
26
|
+
def test_get_data_alias
|
28
27
|
assert_respond_to(Clipboard, :get_data)
|
29
|
-
|
30
|
-
assert_kind_of(String, Clipboard.get_data, 'bad data type')
|
31
|
-
assert_raises(NameError){ Clipboard.get_data(CF_FOO) }
|
28
|
+
assert_equal(true, Clipboard.method(:data) == Clipboard.method(:get_data))
|
32
29
|
end
|
33
30
|
|
34
31
|
def test_set_data
|
data/win32-clipboard.gemspec
CHANGED
@@ -2,19 +2,18 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "win32-clipboard"
|
5
|
-
gem.version = "0.4.
|
6
|
-
gem.
|
5
|
+
gem.version = "0.4.4"
|
6
|
+
gem.authors = ["Daniel J. Berger", "Park Heesob"]
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
9
9
|
gem.platform = Gem::Platform::RUBY
|
10
|
-
gem.summary = "A
|
11
|
-
gem.description = "A
|
12
|
-
gem.test_file = "test/
|
10
|
+
gem.summary = "A library for interacting with the Windows clipboard"
|
11
|
+
gem.description = "A library for interacting with the Windows clipboard"
|
12
|
+
gem.test_file = "test/test_clipboard.rb"
|
13
13
|
gem.has_rdoc = true
|
14
|
-
gem.require_path = "lib"
|
15
14
|
gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
|
16
15
|
gem.rubyforge_project = "win32utils"
|
17
|
-
gem.add_dependency("windows-pr", ">= 0.
|
16
|
+
gem.add_dependency("windows-pr", ">= 0.8.1")
|
18
17
|
|
19
18
|
files = Dir["doc/*"] + Dir["examples/*"] + Dir["lib/win32/*"]
|
20
19
|
files += Dir["test/*"] + Dir["[A-Z]*"]
|
metadata
CHANGED
@@ -1,37 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: win32-clipboard
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2007-07-25 00:00:00 -06:00
|
8
|
-
summary: A package for interacting with the Windows clipboard
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/win32utils
|
13
|
-
rubyforge_project: win32utils
|
14
|
-
description: A package for interacting with the Windows clipboard
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.4.4
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
- Park Heesob
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-08-26 00:00:00 -06:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: windows-pr
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.8.1
|
25
|
+
version:
|
26
|
+
description: A library for interacting with the Windows clipboard
|
27
|
+
email: djberg96@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- CHANGES
|
34
|
+
- README
|
35
|
+
- MANIFEST
|
31
36
|
files:
|
32
37
|
- examples/clipboard_test.rb
|
33
38
|
- lib/win32/clipboard.rb
|
34
|
-
- test/
|
39
|
+
- test/test_clipboard.rb
|
35
40
|
- CHANGES
|
36
41
|
- examples
|
37
42
|
- lib
|
@@ -40,27 +45,31 @@ files:
|
|
40
45
|
- README
|
41
46
|
- test
|
42
47
|
- win32-clipboard.gemspec
|
43
|
-
|
44
|
-
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://www.rubyforge.org/projects/win32utils
|
50
|
+
post_install_message:
|
45
51
|
rdoc_options: []
|
46
52
|
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
55
67
|
requirements: []
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: 0.4.1
|
66
|
-
version:
|
69
|
+
rubyforge_project: win32utils
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: A library for interacting with the Windows clipboard
|
74
|
+
test_files:
|
75
|
+
- test/test_clipboard.rb
|