Changeset 29128
- Timestamp:
- 01/27/09 21:39:39 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 4 modified
-
lib/ruwin/edit_field.rb (modified) (5 diffs)
-
lib/ruwin/edit_field/rich.rb (modified) (1 diff)
-
test/ruwin/edit_field/test_rich.rb (modified) (1 diff)
-
test/ruwin/testm_edit_field.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin/edit_field.rb
r29123 r29128 6 6 module Base 7 7 include Const::EditField 8 STRING_CONVERTER = Proc.new{|string| string } 8 9 9 10 attr_reader :selection … … 15 16 self.writable = @proparty[:writable] 16 17 end 18 19 20 def string 21 self.class::STRING_CONVERTER.call(caption.kconv(Kconv::UTF8, Kconv::SJIS)) || "" 22 end 23 alias to_s string 24 25 def string= string 26 self.caption = self.class::STRING_CONVERTER.call(string).kconv(Kconv::SJIS, Kconv::UTF8) 27 end 28 29 def string_converter string 30 string 31 end 32 private :string_converter 33 34 def set_selection first, last 35 sendMessage EM_SETSEL, first, last 36 end 37 38 def get_selection 39 ranges = sendMessage EM_GETSEL, 0, 0 40 return LOWORD(ranges), HIWORD(ranges) 41 end 42 43 44 45 46 47 48 49 50 51 52 53 17 54 18 55 … … 28 65 def head 29 66 self[0, 0] 30 end31 32 def string33 caption.kconv(Kconv::UTF8, Kconv::SJIS).gsub(/\r\n|\r|\n/m, self.class::RETURN_CODE)34 end35 alias to_s string36 37 def string= string38 self.caption = string.gsub(/\r\n|\r|\n/m, self.class::RETURN_CODE).kconv(Kconv::SJIS, Kconv::UTF8)39 67 end 40 68 … … 100 128 STYLE = Control::STYLE | ES_AUTOHSCROLL 101 129 EXSTYLE = WS_EX_CLIENTEDGE 102 RETURN_CODE = ""130 STRING_CONVERTER = Proc.new{|string| string.split(/\r\n|\r|\n/, 2)[0] } 103 131 104 132 property_accessor :writable => true 133 105 134 private :caption, :caption= 135 106 136 107 137 def wm_lbuttondown 108 138 p :wm_lbuttondown 109 139 end 140 110 141 111 142 def self.read_only … … 115 146 class Multiline < EditField 116 147 STYLE = Control::STYLE | ES_MULTILINE | ES_AUTOVSCROLL 117 RETURN_CODE = "\r\n"148 STRING_CONVERTER = Proc.new{|string| string.gsub(/\r\n|\r|\n/u, "\r\n") } 118 149 end 119 150 end -
lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb
r29123 r29128 25 25 CLASS_NAME = "RICHEDIT" 26 26 end 27 STRING_CONVERTER = Proc.new{|string| string } 27 28 28 29 property_accessor :background_color => nil, :color => nil -
lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb
r29125 r29128 128 128 assert_equal "RICHEDIT20A", @control.classname 129 129 end 130 131 # 改行をそもそも含めることができない。ここのテスト手法は要検討132 undef test_string_getter_should_deny_return133 130 end 134 131 -
lang/ruby/ruwin/test/ruwin/testm_edit_field.rb
r29125 r29128 13 13 14 14 15 def test_string_setter_should_encode_utf8_to_sjis 16 @control.string = "あいう" 17 assert_equal "あいう".tosjis, @control.__send__(:caption) 18 end 19 20 def test_string_getter_should_encode_sjis_to_utf8 21 @control.__send__ :caption=, "あいう".tosjis 22 assert_equal "あいう", @control.string 23 end 24 25 def test_string_setter 26 @control.string = "caption" 27 assert_equal "caption", @control.__send__(:caption) 28 end 29 30 def test_string_getter_empty 31 @control.__send__ :caption=, "" 32 assert_equal "", @control.string 33 end 34 35 def test_string_getter 36 @control.__send__ :caption=, "caption" 37 assert_equal "caption", @control.string 38 end 39 40 41 def test_set_selection 42 @control.string = "caption" 43 @control.set_selection 1, 4 44 assert_equal 1|4<<16, @control.sendMessage(EM_GETSEL, 0, 0) 45 end 46 47 def test_get_selection 48 @control.string = "caption" 49 @control.sendMessage(EM_SETSEL, 1, 4) 50 assert_equal [1, 4], @control.get_selection 51 end 52 53 15 54 def test_undo_q_unbuffered 16 55 assert_equal false, @control.undo? … … 18 57 19 58 def test_undo_q_buffered 20 @control.se lection.string ="test"59 @control.sendMessage EM_REPLACESEL, 1, "test" 21 60 assert_equal true, @control.undo? 22 61 end … … 29 68 30 69 def test_undo_buffered 31 @control.se lection.string ="test"70 @control.sendMessage EM_REPLACESEL, 1, "test" 32 71 assert_equal true, @control.undo 33 72 assert_equal "", @control.string … … 94 133 end 95 134 96 97 def test_string98 @control.string = "caption"99 assert_equal "caption", @control.string100 end101 135 102 136 def test_clear … … 188 222 assert_equal :updated, @control.wm_command(msg, nil, EN_UPDATE, nil) 189 223 end 190 191 def test_string_setter_should_encode_utf8_to_sjis192 klass = Class.new(self.class::TARGET_CLASS)193 control = klass.new(@window)194 control.string = "あいう"195 assert_equal "あいう".tosjis, control.__send__(:caption)196 end197 198 def test_string_getter_should_encode_sjis_to_utf8199 klass = Class.new(self.class::TARGET_CLASS)200 control = klass.new(@window)201 control.__send__ :caption=, "あいう".tosjis202 assert_equal "あいう", control.string203 end204 224 end 225 205 226 206 227 module TestModuleEditFieldSingle … … 217 238 control = klass.new(@window) 218 239 control.string = "caption\r\ncaption\rcaption\ncaption" 219 assert_equal "caption captioncaptioncaption", control.__send__(:caption)240 assert_equal "caption", control.__send__(:caption) 220 241 end 221 242 … … 224 245 control = klass.new(@window) 225 246 control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 226 assert_equal "caption captioncaptioncaption", control.string247 assert_equal "caption", control.string 227 248 end 228 249 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)