Changeset 28950
- Timestamp:
- 01/24/09 12:30:58 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 2 modified
-
lib/ruwin/edit_field/rich.rb (modified) (2 diffs)
-
test/ruwin/edit_field/test_rich.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb
r28946 r28950 7 7 sendMessage EM_GETSELTEXT, 0, result 8 8 result 9 end 10 end 11 12 class Format 13 include Ruwin 14 include Const::EditField 15 16 def initialize control, extent_flag 17 @control = control 18 @extent_flag = extent_flag 19 end 20 21 { 22 :bold => %w{CFM_BOLD CFE_BOLD}, 23 :italic => %w{CFM_ITALIC CFE_ITALIC}, 24 :underline => %w{CFM_UNDERLINE CFE_UNDERLINE}, 25 :strikeout => %w{CFM_STRIKEOUT CFE_STRIKEOUT}, 26 :protected => %w{CFM_PROTECTED CFE_PROTECTED}, 27 }.each do |option, (mask, effect)| 28 class_eval <<-"END" 29 def #{option}= enable 30 set_char_format(#{mask}, :effects => (enable ? #{effect} : 0)) 31 end 32 END 33 end 34 35 { 36 :height => %w{CFM_SIZE}, 37 :offset => %w{CFM_OFFSET}, 38 }.each do |option, mask| 39 class_eval <<-"END" 40 def #{option}= twip 41 set_char_format(#{mask}, :#{option} => twip) 42 end 43 END 44 end 45 46 47 private 48 def set_char_format mask, options 49 @control.sendMessage EM_SETCHARFORMAT, @extent_flag, char_format(mask, options) 50 end 51 52 def char_format mask, options 53 [ 54 60, 55 mask, 56 options[:effects] || 0, 57 options[:height] || 0, 58 options[:offset] || 0, 59 0, 60 0, 61 0, 62 0, 63 ].pack("LLLLLLCCU") 9 64 end 10 65 end … … 20 75 21 76 property_accessor :background_color => nil 77 attr_reader :default 22 78 23 79 def initialize 24 80 super 25 81 self.background_color = @proparty[:background_color] if @proparty[:background_color] 82 @default = Format.new self, SCF_DEFAULT 26 83 end 27 84 -
lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb
r28946 r28950 23 23 assert_equal [[EM_SETBKGNDCOLOR, 1, 0]], @control.message_log 24 24 end 25 26 27 def test_default_format 28 assert_kind_of Ruwin::EditField::Rich::Format, @control.default 29 assert_same @control, @control.default.instance_variable_get(:@control) 30 end 31 25 32 26 33 … … 83 90 end 84 91 92 class TestRuwinEditFieldRichFormatDefault < Test::Unit::TestCase 93 include Ruwin::Const::EditField 94 95 def setup 96 @control = Ruwin::EditField::Rich.new(HiddenWindow.new) 97 @format = @control.default 98 end 99 100 { 101 :bold => %w{CFM_BOLD CFE_BOLD}, 102 :italic => %w{CFM_ITALIC CFE_ITALIC}, 103 :underline => %w{CFM_UNDERLINE CFE_UNDERLINE}, 104 :strikeout => %w{CFM_STRIKEOUT CFE_STRIKEOUT}, 105 :protected => %w{CFM_PROTECTED CFE_PROTECTED}, 106 }.each do |option, (mask, effect)| 107 { 108 :on => true, 109 :off => false, 110 }.each do |name, enable| 111 effect = "0" if name == :off 112 113 class_eval <<-"END" 114 def test_effects_#{option}_#{name} 115 @format.#{option} = #{enable} 116 117 assert_equal 1, @control.message_log.size 118 assert_setcharformat @control.message_log.last, 1 => #{mask}, 2 => #{effect} 119 end 120 END 121 end 122 end 123 124 { 125 :height => %w{CFM_SIZE 3}, 126 :offset => %w{CFM_OFFSET 4}, 127 }.each do |option, (mask, index)| 128 %w{20 -20}.each do |value| 129 class_eval <<-"END" 130 def test_#{option}_#{value.gsub "-", "minus"} 131 @format.#{option} = #{value} 132 133 assert_equal 1, @control.message_log.size 134 assert_setcharformat @control.message_log.last, 1 => #{mask}, #{index} => #{value} 135 end 136 END 137 end 138 end 139 140 141 def assert_setcharformat expected, options 142 assert_equal EM_SETCHARFORMAT, expected[0] 143 assert_equal SCF_DEFAULT, expected[1] 144 145 charformat = @control.message_log.last[2].unpack("LLLLLLCCU") 146 options.each do |index, value| 147 assert_equal value, Ruwin::SIGNEDLONG(charformat[index]) 148 end 149 end 150 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)