Changeset 29123

Show
Ignore:
Timestamp:
01/27/09 19:06:04 (4 years ago)
Author:
isaisstillalive
Message:
  • 文字コードと改行を自動変換するように変更。
  • コントロールの文字コードはSJISだが、stringメソッドで取得する際にUTF8に変換する。
  • 改行は、単一行EditFieldの場合は空に。複数行EditFieldの場合はCRLFに統一。
Location:
lang/ruby/ruwin
Files:
4 modified

Legend:

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

    r29107 r29123  
    3030      end 
    3131       
    32        
    3332      def string 
    34         caption 
     33        caption.kconv(Kconv::UTF8, Kconv::SJIS).gsub(/\r\n|\r|\n/m, self.class::RETURN_CODE) 
    3534      end 
    3635      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) 
     39      end 
    3740       
    3841      def clear 
     
    7679       
    7780      def upcase 
    78         caption.upcase 
     81        string.upcase 
    7982      end 
    8083       
    8184      def upcase! 
    82         self.caption = upcase 
     85        self.string = upcase 
    8386      end 
    8487       
     
    97100    STYLE = Control::STYLE | ES_AUTOHSCROLL 
    98101    EXSTYLE = WS_EX_CLIENTEDGE 
     102    RETURN_CODE = "" 
    99103     
    100104    property_accessor :writable => true 
     105    private :caption, :caption= 
     106     
     107    def wm_lbuttondown 
     108      p :wm_lbuttondown 
     109    end 
    101110     
    102111    def self.read_only 
     
    104113    end 
    105114     
    106     private :caption= 
    107     def string= string 
    108       self.caption = string.gsub(/\r\n|\r|\n/m, "") 
    109     end 
    110          
    111115    class Multiline < EditField 
    112116      STYLE = Control::STYLE | ES_MULTILINE | ES_AUTOVSCROLL 
    113        
    114       def string= string 
    115         self.caption = string.gsub(/\r\n|\r|\n/m, "\r\n") 
    116       end 
     117      RETURN_CODE = "\r\n" 
    117118    end 
    118119  end 
  • lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb

    r29107 r29123  
    9797      class Multiline < Rich 
    9898        STYLE = EditField::Multiline::STYLE 
    99          
    100         def string= string 
    101           self.caption = string.gsub(/\r\n|\r|\n/m, "\r\n") 
    102         end 
     99        RETURN_CODE = "\r\n" 
    103100      end 
    104101    end 
  • lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb

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

    r29107 r29123  
    2525    # assert_equal false, @control.undo # 単一行の際に正しく戻らない 
    2626    @control.undo 
    27     assert_equal "", @control.caption 
     27    assert_equal "", @control.string 
    2828  end 
    2929   
     
    3131    @control.selection.string = "test" 
    3232    assert_equal true, @control.undo 
    33     assert_equal "", @control.caption 
     33    assert_equal "", @control.string 
    3434  end 
    3535   
     
    174174    @control.string = "caption" 
    175175    assert_equal "CAPTION", @control.upcase 
    176     assert_equal "caption", @control.caption 
     176    assert_equal "caption", @control.string 
    177177  end 
    178178   
     
    180180    @control.string = "caption" 
    181181    assert_equal "CAPTION", @control.upcase! 
    182     assert_equal "CAPTION", @control.caption 
     182    assert_equal "CAPTION", @control.string 
    183183  end 
    184184   
     
    187187    msg = DummyMSG.new nil, nil, nil 
    188188    assert_equal :updated, @control.wm_command(msg, nil, EN_UPDATE, nil) 
     189  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 
    189203  end 
    190204end 
     
    199213   
    200214   
    201   def test_string_should_deny_return 
     215  def test_string_setter_should_deny_return 
    202216    klass = Class.new(self.class::TARGET_CLASS) 
    203217    control = klass.new(@window) 
    204218    control.string = "caption\r\ncaption\rcaption\ncaption" 
    205     assert_equal "captioncaptioncaptioncaption", control.caption 
     219    assert_equal "captioncaptioncaptioncaption", control.__send__(:caption) 
     220  end 
     221   
     222  def test_string_getter_should_deny_return 
     223    klass = Class.new(self.class::TARGET_CLASS) 
     224    control = klass.new(@window) 
     225    control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 
     226    assert_equal "captioncaptioncaptioncaption", control.string 
    206227  end 
    207228end 
     
    219240   
    220241   
    221   def test_string_should_allow_return 
     242  def test_string_setter_should_allow_return_and_convert_to_crlf 
    222243    klass = Class.new(self.class::TARGET_CLASS) 
    223244    control = klass.new(@window) 
    224245    control.string = "caption\r\ncaption\rcaption\ncaption" 
    225     assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.caption 
     246    assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.__send__(:caption) 
     247  end 
     248   
     249  def test_string_getter_should_allow_return_and_convert_to_crlf 
     250    klass = Class.new(self.class::TARGET_CLASS) 
     251    control = klass.new(@window) 
     252    control.__send__ :caption=, "caption\r\ncaption\rcaption\ncaption" 
     253    assert_equal "caption\r\ncaption\r\ncaption\r\ncaption", control.string 
    226254  end 
    227255end 
     
    353381    @selection.change 3, 6 
    354382    @selection.string = "ricor" 
    355     assert_equal "capricorn", @control.caption 
     383    assert_equal "capricorn", @control.string 
    356384  end 
    357385   
     
    360388    @selection_without_reflection.change 3, 6 
    361389    @selection_without_reflection.string = "ricor" 
    362     assert_equal "capricorn", @control.caption 
     390    assert_equal "capricorn", @control.string 
    363391    assert_equal 0...0, @selection.range 
    364392  end