Changeset 29128

Show
Ignore:
Timestamp:
01/27/09 21:39:39 (4 years ago)
Author:
isaisstillalive
Message:
  • string,string=の動作を、EditFieldとRichで統一した。
Location:
lang/ruby/ruwin
Files:
4 modified

Legend:

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

    r29123 r29128  
    66    module Base 
    77      include Const::EditField 
     8      STRING_CONVERTER = Proc.new{|string| string } 
    89       
    910      attr_reader :selection 
     
    1516        self.writable = @proparty[:writable] 
    1617      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       
    1754       
    1855       
     
    2865      def head 
    2966        self[0, 0] 
    30       end 
    31        
    32       def string 
    33         caption.kconv(Kconv::UTF8, Kconv::SJIS).gsub(/\r\n|\r|\n/m, self.class::RETURN_CODE) 
    34       end 
    35       alias to_s string 
    36        
    37       def string= string 
    38         self.caption = string.gsub(/\r\n|\r|\n/m, self.class::RETURN_CODE).kconv(Kconv::SJIS, Kconv::UTF8) 
    3967      end 
    4068       
     
    100128    STYLE = Control::STYLE | ES_AUTOHSCROLL 
    101129    EXSTYLE = WS_EX_CLIENTEDGE 
    102     RETURN_CODE = "" 
     130    STRING_CONVERTER = Proc.new{|string| string.split(/\r\n|\r|\n/, 2)[0] } 
    103131     
    104132    property_accessor :writable => true 
     133     
    105134    private :caption, :caption= 
     135     
    106136     
    107137    def wm_lbuttondown 
    108138      p :wm_lbuttondown 
    109139    end 
     140     
    110141     
    111142    def self.read_only 
     
    115146    class Multiline < EditField 
    116147      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") } 
    118149    end 
    119150  end 
  • lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb

    r29123 r29128  
    2525        CLASS_NAME = "RICHEDIT" 
    2626      end 
     27      STRING_CONVERTER = Proc.new{|string| string } 
    2728       
    2829      property_accessor :background_color => nil, :color => nil 
  • lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb

    r29125 r29128  
    128128    assert_equal "RICHEDIT20A", @control.classname 
    129129  end 
    130    
    131   # 改行をそもそも含めることができない。ここのテスト手法は要検討 
    132   undef test_string_getter_should_deny_return 
    133130end 
    134131 
  • lang/ruby/ruwin/test/ruwin/testm_edit_field.rb

    r29125 r29128  
    1313   
    1414   
     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   
    1554  def test_undo_q_unbuffered 
    1655    assert_equal false, @control.undo? 
     
    1857   
    1958  def test_undo_q_buffered 
    20     @control.selection.string = "test" 
     59    @control.sendMessage EM_REPLACESEL, 1, "test" 
    2160    assert_equal true, @control.undo? 
    2261  end 
     
    2968   
    3069  def test_undo_buffered 
    31     @control.selection.string = "test" 
     70    @control.sendMessage EM_REPLACESEL, 1, "test" 
    3271    assert_equal true, @control.undo 
    3372    assert_equal "", @control.string 
     
    94133  end 
    95134   
    96    
    97   def test_string 
    98     @control.string = "caption" 
    99     assert_equal "caption", @control.string 
    100   end 
    101135   
    102136  def test_clear 
     
    188222    assert_equal :updated, @control.wm_command(msg, nil, EN_UPDATE, nil) 
    189223  end 
    190    
    191   def test_string_setter_should_encode_utf8_to_sjis 
    192     klass = Class.new(self.class::TARGET_CLASS) 
    193     control = klass.new(@window) 
    194     control.string = "あいう" 
    195     assert_equal "あいう".tosjis, control.__send__(:caption) 
    196   end 
    197    
    198   def test_string_getter_should_encode_sjis_to_utf8 
    199     klass = Class.new(self.class::TARGET_CLASS) 
    200     control = klass.new(@window) 
    201     control.__send__ :caption=, "あいう".tosjis 
    202     assert_equal "あいう", control.string 
    203   end 
    204224end 
     225 
    205226 
    206227module TestModuleEditFieldSingle 
     
    217238    control = klass.new(@window) 
    218239    control.string = "caption\r\ncaption\rcaption\ncaption" 
    219     assert_equal "captioncaptioncaptioncaption", control.__send__(:caption) 
     240    assert_equal "caption", control.__send__(:caption) 
    220241  end 
    221242   
     
    224245    control = klass.new(@window) 
    225246    control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 
    226     assert_equal "captioncaptioncaptioncaption", control.string 
     247    assert_equal "caption", control.string 
    227248  end 
    228249end