Changeset 29212
- Timestamp:
- 01/29/09 11:19:47 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 3 modified
-
lib/ruwin/edit_field.rb (modified) (7 diffs)
-
lib/ruwin/edit_field/rich.rb (modified) (2 diffs)
-
test/ruwin/testm_edit_field.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin/edit_field.rb
r29149 r29212 6 6 module Base 7 7 include Const::EditField 8 STRING_CONVERTER = Proc.new{|string| string }8 ENABLE_MULTILINE = false 9 9 10 10 attr_reader :selection … … 19 19 20 20 def string 21 self.class::STRING_CONVERTER.call(caption.kconv(Kconv::UTF8, Kconv::SJIS)) || "" 22 end 23 alias to_s string 21 physical_string 22 end 24 23 25 24 def string= string 26 self.caption = self.class::STRING_CONVERTER.call(string).kconv(Kconv::SJIS, Kconv::UTF8) 27 end 25 self.caption = convert_string(string, "\r\n").kconv(Kconv::SJIS, Kconv::UTF8) 26 end 27 28 def length 29 physical_length 30 end 31 32 33 def physical_string 34 return "" if caption.empty? 35 convert_string(caption.kconv(Kconv::UTF8, Kconv::SJIS)) 36 end 37 38 def logical_string 39 return "" if caption.empty? 40 convert_string(caption.kconv(Kconv::UTF8, Kconv::SJIS), "\r") 41 end 42 43 def convert_string string, rs = "\r\n" 44 if self.class::ENABLE_MULTILINE 45 string.gsub(/\r\n|\r|\n/u, rs) 46 else 47 string.split(/\r\n|\r|\n/, 2)[0] 48 end 49 end 50 51 def physical_length 52 physical_string.length 53 end 54 55 def logical_length 56 logical_string.length 57 end 58 28 59 29 60 def substring logical_first, logical_last 30 to_physical_string( to_logical_string(physical_string).split(//u)[logical_first...logical_last].join(""))61 to_physical_string(logical_string.split(//u)[logical_first...logical_last].join("")) 31 62 end 32 63 … … 44 75 physical_string[first...last] 45 76 end 46 47 48 alias physical_string string49 private :physical_string50 77 51 78 def to_logical_string physical_string … … 151 178 STYLE = Control::STYLE | ES_AUTOHSCROLL 152 179 EXSTYLE = WS_EX_CLIENTEDGE 153 STRING_CONVERTER = Proc.new{|string| string.split(/\r\n|\r|\n/, 2)[0] }154 180 155 181 property_accessor :writable => true … … 169 195 class Multiline < EditField 170 196 STYLE = Control::STYLE | ES_MULTILINE | ES_AUTOVSCROLL 171 STRING_CONVERTER = Proc.new{|string| string.gsub(/\r\n|\r|\n/u, "\r\n") }197 ENABLE_MULTILINE = true 172 198 173 199 private 174 def return_countphysical_first, physical_length200 def count_rs physical_first, physical_length 175 201 string[physical_first, physical_length].split("\r\n").size-1 176 202 end … … 180 206 len = logical_length 181 207 until len == 0 182 return_count = return_count(pos, len)208 count_rs = count_rs(pos, len) 183 209 pos += len 184 len = return_count210 len = count_rs 185 211 end 186 212 pos 187 213 end 188 214 189 def logical_ lengthphysical_first, physical_length190 physical_length - return_count(physical_first, physical_length)215 def logical_diff physical_first, physical_length 216 physical_length - count_rs(physical_first, physical_length) 191 217 end 192 218 … … 203 229 physical_length = physical_last-physical_first 204 230 205 logical_length = logical_ length(physical_first, physical_length)206 logical_first = logical_ length(0, physical_first)231 logical_length = logical_diff(physical_first, physical_length) 232 logical_first = logical_diff(0, physical_first) 207 233 208 234 return logical_first, logical_first+logical_length -
lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb
r29150 r29212 25 25 CLASS_NAME = "RICHEDIT" 26 26 end 27 STRING_CONVERTER = Proc.new{|string| string }28 27 29 28 property_accessor :background_color => nil, :color => nil … … 108 107 class Multiline < Rich 109 108 STYLE = EditField::Multiline::STYLE 110 RETURN_CODE = "\r\n"109 ENABLE_MULTILINE = true 111 110 end 112 111 end -
lang/ruby/ruwin/test/ruwin/testm_edit_field.rb
r29149 r29212 13 13 14 14 15 def test_string_setter 16 @control.string = "caption" 17 assert_equal "caption", @control.__send__(:caption) 18 end 19 15 20 def test_string_setter_should_encode_utf8_to_sjis 16 21 @control.string = "あいう" … … 18 23 end 19 24 25 def test_string_getter_empty 26 @control.__send__ :caption=, "" 27 assert_equal "", @control.string 28 end 29 30 def test_string_getter 31 @control.__send__ :caption=, "caption" 32 assert_equal "caption", @control.string 33 end 34 20 35 def test_string_getter_should_encode_sjis_to_utf8 21 36 @control.__send__ :caption=, "あいう".tosjis … … 23 38 end 24 39 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 40 41 def test_logical_string 42 @control.__send__ :caption=, "caption" 43 assert_equal "caption", @control.logical_string 44 end 45 46 def test_physical_string 47 @control.__send__ :caption=, "caption" 48 assert_equal "caption", @control.physical_string 49 end 50 51 52 def test_length 53 @control.__send__ :caption=, "caption" 54 assert_equal 7, @control.length 55 end 56 57 def test_logical_length 58 @control.__send__ :caption=, "caption" 59 assert_equal 7, @control.logical_length 60 end 61 62 def test_physical_length 63 @control.__send__ :caption=, "caption" 64 assert_equal 7, @control.physical_length 38 65 end 39 66 … … 257 284 258 285 def test_string_setter_should_deny_return 259 klass = Class.new(self.class::TARGET_CLASS) 260 control = klass.new(@window) 261 control.string = "caption\r\ncaption\rcaption\ncaption" 262 assert_equal "caption", control.__send__(:caption) 286 @control.string = "caption\r\ncaption\rcaption\ncaption" 287 assert_equal "caption", @control.__send__(:caption) 263 288 end 264 289 265 290 def test_string_getter_should_deny_return 266 klass = Class.new(self.class::TARGET_CLASS) 267 control = klass.new(@window) 268 control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 269 assert_equal "caption", control.string 291 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 292 assert_equal "caption", @control.string 270 293 end 271 294 end … … 284 307 285 308 def test_string_setter_should_allow_return_and_convert_to_crlf 286 klass = Class.new(self.class::TARGET_CLASS) 287 control = klass.new(@window) 288 control.string = "caption\r\ncaption\rcaption\ncaption" 289 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.__send__(:caption) 309 @control.string = "caption\r\ncaption\rcaption\ncaption" 310 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", @control.__send__(:caption) 290 311 end 291 312 292 313 def test_string_getter_should_allow_return_and_convert_to_crlf 293 klass = Class.new(self.class::TARGET_CLASS) 294 control = klass.new(@window) 295 control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 296 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.string 314 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 315 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", @control.string 316 end 317 318 319 def test_logical_string 320 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 321 assert_equal "caption\rcaption\rcaption\rcaption", @control.logical_string 322 end 323 324 def test_physical_string 325 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 326 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", @control.physical_string 327 end 328 329 330 def test_length 331 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 332 assert_equal 28+6, @control.length 333 end 334 335 def test_logical_length 336 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 337 assert_equal 28+3, @control.logical_length 338 end 339 340 def test_physical_length 341 @control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 342 assert_equal 28+6, @control.physical_length 343 end 344 345 346 def test_substring_multiline 347 @control.string = "caption\r\ncaption\rcaption\ncaption" 348 assert_equal "ion\r\ncap", @control.substring(4, 11) 297 349 end 298 350 … … 303 355 assert_equal "ion\r\ncap", @control.selection_string 304 356 end 305 306 def test_substring_multiline307 @control.string = "caption\r\ncaption\rcaption\ncaption"308 assert_equal "ion\r\ncap", @control.substring(4, 11)309 end310 357 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)