Changeset 29145

Show
Ignore:
Timestamp:
01/28/09 01:55:43 (4 years ago)
Author:
isaisstillalive
Message:
  • selection系の動作をEditFieldとRichで合わせた。
Location:
lang/ruby/ruwin
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/ruwin/lib/ruwin/edit_field.rb

    r29128 r29145  
    3737       
    3838      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 
    3949        ranges = sendMessage EM_GETSEL, 0, 0 
    4050        return LOWORD(ranges), HIWORD(ranges) 
    4151      end 
    42        
    43        
    44        
    45        
    46        
    47        
    48        
    49        
    50        
    51        
    52        
    53        
     52      private :getsel 
    5453       
    5554       
     
    147146      STYLE = Control::STYLE | ES_MULTILINE | ES_AUTOVSCROLL 
    148147      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 
    149188    end 
    150189  end 
  • lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb

    r29128 r29145  
    3939        @default = Format::Char.new self, SCF_DEFAULT 
    4040        @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") 
    4149      end 
    4250       
  • lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb

    r29128 r29145  
    139139    assert_equal "RICHEDIT20A", @control.classname 
    140140  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 
    141157end 
  • lang/ruby/ruwin/test/ruwin/test_edit_field.rb

    r28963 r29145  
    1414  include Ruwin::Const::EditField 
    1515  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 
    1632end 
  • lang/ruby/ruwin/test/ruwin/testm_edit_field.rb

    r29128 r29145  
    4242    @control.string = "caption" 
    4343    @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) 
    4547  end 
    4648   
     
    5052    assert_equal [1, 4], @control.get_selection 
    5153  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   
    5263   
    5364   
     
    274285    assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.string 
    275286  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 
    276294end