Changeset 29145
- Timestamp:
- 01/28/09 01:55:43 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 5 modified
-
lib/ruwin/edit_field.rb (modified) (2 diffs)
-
lib/ruwin/edit_field/rich.rb (modified) (1 diff)
-
test/ruwin/edit_field/test_rich.rb (modified) (1 diff)
-
test/ruwin/test_edit_field.rb (modified) (1 diff)
-
test/ruwin/testm_edit_field.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin/edit_field.rb
r29128 r29145 37 37 38 38 def get_selection 39 return getsel 40 end 41 42 43 def selection_string 44 first, last = getsel 45 string[first...last] 46 end 47 48 def getsel 39 49 ranges = sendMessage EM_GETSEL, 0, 0 40 50 return LOWORD(ranges), HIWORD(ranges) 41 51 end 42 43 44 45 46 47 48 49 50 51 52 53 52 private :getsel 54 53 55 54 … … 147 146 STYLE = Control::STYLE | ES_MULTILINE | ES_AUTOVSCROLL 148 147 STRING_CONVERTER = Proc.new{|string| string.gsub(/\r\n|\r|\n/u, "\r\n") } 148 149 def set_selection logical_first, logical_last 150 logical_length = logical_last-logical_first 151 152 physical_first = physical_add(0, logical_first) 153 physical_last = physical_add(physical_first, logical_length) 154 155 super physical_first, physical_last 156 end 157 158 def get_selection 159 physical_first, physical_last = super 160 161 physical_length = physical_last-physical_first 162 163 logical_length = logical_length(physical_first, physical_length) 164 logical_first = logical_length(0, physical_first) 165 166 return logical_first, logical_first+logical_length 167 end 168 169 private 170 def return_count physical_first, physical_length 171 string[physical_first, physical_length].split("\r\n").size-1 172 end 173 174 def physical_add physical_first, logical_length 175 pos = physical_first 176 len = logical_length 177 until len == 0 178 return_count = return_count(pos, len) 179 pos += len 180 len = return_count 181 end 182 pos 183 end 184 185 def logical_length physical_first, physical_length 186 physical_length - return_count(physical_first, physical_length) 187 end 149 188 end 150 189 end -
lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb
r29128 r29145 39 39 @default = Format::Char.new self, SCF_DEFAULT 40 40 @default.color = @proparty[:color] if @proparty[:color] 41 end 42 43 44 def selection_string 45 range = getsel 46 result = "\0"*(range.last-range.first) 47 sendMessage EM_GETSELTEXT, 0, result 48 result.gsub("\r", "\r\n") 41 49 end 42 50 -
lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb
r29128 r29145 139 139 assert_equal "RICHEDIT20A", @control.classname 140 140 end 141 142 143 def test_set_selection_should_counting_return_code_1_char 144 @control.string = "caption\r\ncaption\r\ncaption" 145 @control.set_selection 12, 19 146 147 sel = @control.sendMessage(EM_GETSEL, 0, 0) 148 assert_equal 12, Ruwin::LOWORD(sel) 149 assert_equal 19, Ruwin::HIWORD(sel) 150 end 151 152 def test_get_selection_should_counting_return_code_1_char 153 @control.string = "caption\r\ncaption\r\ncaption" 154 @control.sendMessage(EM_SETSEL, 12, 19) 155 assert_equal [12, 19], @control.get_selection 156 end 141 157 end -
lang/ruby/ruwin/test/ruwin/test_edit_field.rb
r28963 r29145 14 14 include Ruwin::Const::EditField 15 15 TARGET_CLASS = Ruwin::EditField::Multiline 16 17 18 def test_set_selection_should_counting_return_code_1_char 19 @control.string = "caption\r\ncaption\r\ncaption" 20 @control.set_selection 12, 19 21 22 sel = @control.sendMessage(EM_GETSEL, 0, 0) 23 assert_equal 13, Ruwin::LOWORD(sel) 24 assert_equal 21, Ruwin::HIWORD(sel) 25 end 26 27 def test_get_selection_should_counting_return_code_1_char 28 @control.string = "caption\r\ncaption\r\ncaption" 29 @control.sendMessage(EM_SETSEL, 13, 21) 30 assert_equal [12, 19], @control.get_selection 31 end 16 32 end -
lang/ruby/ruwin/test/ruwin/testm_edit_field.rb
r29128 r29145 42 42 @control.string = "caption" 43 43 @control.set_selection 1, 4 44 assert_equal 1|4<<16, @control.sendMessage(EM_GETSEL, 0, 0) 44 sel = @control.sendMessage(EM_GETSEL, 0, 0) 45 assert_equal 1, Ruwin::LOWORD(sel) 46 assert_equal 4, Ruwin::HIWORD(sel) 45 47 end 46 48 … … 50 52 assert_equal [1, 4], @control.get_selection 51 53 end 54 55 56 def test_selection_string_getter 57 @control.string = "caption" 58 @control.set_selection 1, 4 59 assert_equal "apt", @control.selection_string 60 end 61 62 52 63 53 64 … … 274 285 assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.string 275 286 end 287 288 289 def test_selection_string_getter_multiline 290 @control.string = "caption\r\ncaption" 291 @control.set_selection 4, 11 292 assert_equal "ion\r\ncap", @control.selection_string 293 end 276 294 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)