Changeset 28997
- Timestamp:
- 01/25/09 12:23:35 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 2 added
- 2 modified
- 2 copied
-
lib/ruwin/edit_field/rich (added)
-
lib/ruwin/edit_field/rich.rb (modified) (2 diffs)
-
lib/ruwin/edit_field/rich/format.rb (copied) (copied from lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb) (2 diffs, 1 prop)
-
test/ruwin/edit_field/rich (added)
-
test/ruwin/edit_field/rich/test_format.rb (copied) (copied from lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb) (1 diff, 1 prop)
-
test/ruwin/edit_field/test_rich.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin/edit_field/rich.rb
r28996 r28997 2 2 class EditField 3 3 class Rich < EditField 4 autoload :Format, "ruwin/edit_field/rich/format" 5 4 6 class Selection < EditField::Selection 5 7 attr_reader :format … … 14 16 sendMessage EM_GETSELTEXT, 0, result 15 17 result 16 end17 end18 19 module Format20 class Char21 include Ruwin22 include Const::EditField23 24 def initialize control, extent_flag25 @control = control26 @extent_flag = extent_flag27 end28 29 {30 :bold => %w{CFM_BOLD CFE_BOLD},31 :italic => %w{CFM_ITALIC CFE_ITALIC},32 :underline => %w{CFM_UNDERLINE CFE_UNDERLINE},33 :strikeout => %w{CFM_STRIKEOUT CFE_STRIKEOUT},34 :protected => %w{CFM_PROTECTED CFE_PROTECTED},35 }.each do |option, (mask, effect)|36 class_eval <<-"END"37 def #{option}= enable38 set_char_format(#{mask}, :effects => (enable ? #{effect} : 0))39 end40 41 def #{option}42 get_char_format(#{mask})[2]&#{effect} == #{effect}43 end44 END45 end46 47 {48 :height => %w{CFM_SIZE twip},49 :offset => %w{CFM_OFFSET twip},50 :color => %w{CFM_COLOR color},51 }.each do |option, (mask, variable)|52 class_eval <<-"END"53 def #{option}= #{variable}54 set_char_format(#{mask}, :#{option} => #{variable})55 end56 END57 end58 59 def height60 SIGNEDLONG(get_char_format(CFM_SIZE)[3])61 end62 63 def offset64 SIGNEDLONG(get_char_format(CFM_OFFSET)[4])65 end66 67 def color68 get_char_format(CFM_OFFSET)[5]69 end70 71 72 private73 CHARFORMAT = "LLLLLLCCU"74 75 def set_char_format mask, options76 @control.sendMessage EM_SETCHARFORMAT, @extent_flag, char_format(mask, options)77 end78 79 def get_char_format mask80 charformat = char_format mask81 @control.sendMessage EM_GETCHARFORMAT, @extent_flag, charformat82 charformat.unpack CHARFORMAT83 end84 85 def char_format mask, options = {}86 [87 60,88 mask,89 options[:effects] || 0,90 options[:height] || 0,91 options[:offset] || 0,92 options[:color] || 0,93 0,94 0,95 0,96 ].pack CHARFORMAT97 end98 18 end 99 19 end -
lang/ruby/ruwin/lib/ruwin/edit_field/rich/format.rb
r28996 r28997 1 1 module Ruwin 2 2 class EditField 3 class Rich < EditField 4 class Selection < EditField::Selection 5 attr_reader :format 6 7 def initialize *args 8 super 9 @format = Format::Char.new self, SCF_SELECTION 10 end 11 12 def string 13 result = "\0"*length 14 sendMessage EM_GETSELTEXT, 0, result 15 result 16 end 17 end 18 3 class Rich 19 4 module Format 20 5 class Char … … 98 83 end 99 84 end 100 101 SELECTION_CLASS = Selection102 103 LoadLibrary = Win32API.new("kernel32","LoadLibrary",["P"],"I")104 if LoadLibrary.call("riched20") != 0105 CLASS_NAME = "RICHEDIT20A"106 elsif LoadLibrary.call("riched32") != 0107 CLASS_NAME = "RICHEDIT"108 end109 110 property_accessor :background_color => nil, :color => nil111 attr_reader :default112 113 def initialize114 super115 116 self.background_color = @proparty[:background_color] if @proparty[:background_color]117 118 @default = Format::Char.new self, SCF_DEFAULT119 @default.color = @proparty[:color] if @proparty[:color]120 end121 122 123 def background_color= color124 if color125 sendMessage EM_SETBKGNDCOLOR, 0, color126 else127 sendMessage EM_SETBKGNDCOLOR, 1, 0128 end129 end130 131 132 def wm_notify msg133 hwndFrom, idFrom, code = *SWin::Application.cstruct2array(msg.lParam, "UUU")134 case code135 when EN_MSGFILTER136 en_msgfilter msg137 end138 end139 140 def en_msgfilter msg141 nmhdr1, nmhdr2, nmhdr2, msg, wParam, lParam = *SWin::Application.cstruct2array(msg.lParam, "UUUUUU")142 case msg143 when WM_KEYDOWN144 [:keydown, wParam]145 end146 end147 148 class Multiline < Rich149 STYLE = EditField::Multiline::STYLE150 end151 85 end 152 86 end -
lang/ruby/ruwin/test/ruwin/edit_field/rich/test_format.rb
r28996 r28997 1 require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", " helper"))1 require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "helper")) 2 2 require "ruwin" 3 3 require "ruwin/edit_field" 4 require File.expand_path(File.join(File.dirname(__FILE__), "..", "testm_edit_field"))5 6 module TestModuleEditFieldRich7 include Ruwin::Const::EditField8 9 def test_background_color_property10 klass = Class.new(self.class::TARGET_CLASS)11 klass.class_eval "background_color 0x010203"12 control = klass.new(@window)13 assert control.message_log.include?([EM_SETBKGNDCOLOR, 0, 0x010203])14 end15 16 def test_background_color_setter17 @control.background_color = 0x01020318 assert_equal [[EM_SETBKGNDCOLOR, 0, 0x010203]], @control.message_log19 end20 21 def test_background_color_setter_nil22 @control.background_color = nil23 assert_equal [[EM_SETBKGNDCOLOR, 1, 0]], @control.message_log24 end25 26 27 def test_default_format28 assert_kind_of Ruwin::EditField::Rich::Format::Char, @control.default29 assert_same @control, @control.default.instance_variable_get(:@control)30 end31 32 33 34 def test_color_property35 klass = Class.new(self.class::TARGET_CLASS)36 klass.class_eval "color 0x010203"37 control = klass.new(@window)38 39 expected = control.message_log.find{|v| v[0] == EM_SETCHARFORMAT}40 assert_equal EM_SETCHARFORMAT, expected[0]41 assert_equal SCF_DEFAULT, expected[1]42 43 charformat = expected[2].unpack("LLLLLLCCU")44 assert_equal 0x010203, charformat[5]45 end46 47 48 49 DummyMSG = Struct.new(:hWnd, :msg, :wParam, :lParam)50 51 def test_wm_notify52 klass = Class.new(Ruwin::EditField::Rich)53 klass.class_eval <<-'END'54 attr_reader :en_msgfilter_msg55 def en_msgfilter msg56 @en_msgfilter_msg = msg57 end58 END59 instance = klass.new(HiddenWindow.new)60 61 lParam = SWin::Application.arg2cstructStr("UUU", 0, 0, EN_MSGFILTER)62 lParam_ptr = [lParam].pack("P").unpack("L")[0]63 msg = DummyMSG.new nil, nil, nil, lParam_ptr64 instance.wm_notify msg65 assert_equal msg, instance.en_msgfilter_msg66 end67 68 def test_en_msgfilter69 klass = Class.new(Ruwin::EditField::Rich)70 instance = klass.new(HiddenWindow.new)71 72 lParam = SWin::Application.arg2cstructStr("UUUUUU", 0, 0, 0, Ruwin::Const::Window::WM_KEYDOWN, 1, 0)73 lParam_ptr = [lParam].pack("P").unpack("L")[0]74 msg = DummyMSG.new nil, nil, nil, lParam_ptr75 assert_equal [:keydown, 1], instance.en_msgfilter(msg)76 end77 end78 79 class TestRuwinEditFieldRich < Test::Unit::TestCase80 include TestModuleEditFieldSingle81 include TestModuleEditFieldRich82 include Ruwin::Const::EditField83 TARGET_CLASS = Ruwin::EditField::Rich84 85 def test_classname86 assert_equal "RICHEDIT20A", @control.classname87 end88 end89 90 class TestRuwinEditFieldRichMultiline < Test::Unit::TestCase91 include TestModuleEditFieldMultiline92 include TestModuleEditFieldRich93 include Ruwin::Const::EditField94 TARGET_CLASS = Ruwin::EditField::Rich::Multiline95 96 def test_classname97 assert_equal "RICHEDIT20A", @control.classname98 end99 end100 101 class TestRuwinEditFieldRichSelection < Test::Unit::TestCase102 include TestModuleEditFieldSelection103 include Ruwin::Const::EditField104 TARGET_CLASS = Ruwin::EditField::Rich105 106 def test_format_bold107 @selection.format.bold = true108 109 assert_equal 1, @control.message_log.size110 assert_equal EM_SETCHARFORMAT, @control.message_log[0][0]111 end112 113 def test_format_bold_without_reflection114 @selection_without_reflection.format.bold = true115 116 assert_equal 4, @control.message_log.size117 assert_equal EM_GETSEL, @control.message_log[0][0]118 assert_equal EM_SETSEL, @control.message_log[1][0]119 assert_equal EM_SETCHARFORMAT, @control.message_log[2][0]120 assert_equal EM_SETSEL, @control.message_log[3][0]121 end122 end123 4 124 5 class TestRuwinEditFieldRichCharFormat < Test::Unit::TestCase -
lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb
r28996 r28997 121 121 end 122 122 end 123 124 class TestRuwinEditFieldRichCharFormat < Test::Unit::TestCase125 include Ruwin::Const::EditField126 127 def setup128 @control = Ruwin::EditField::Rich.new(HiddenWindow.new)129 @format = @control.default130 @control.message_log.clear131 end132 133 {134 :bold => %w{CFM_BOLD CFE_BOLD},135 :italic => %w{CFM_ITALIC CFE_ITALIC},136 :underline => %w{CFM_UNDERLINE CFE_UNDERLINE},137 :strikeout => %w{CFM_STRIKEOUT CFE_STRIKEOUT},138 :protected => %w{CFM_PROTECTED CFE_PROTECTED},139 }.each do |option, (mask, effect)|140 {141 :on => true,142 :off => false,143 }.each do |name, enable|144 class_eval <<-"END"145 def test_effects_#{option}_setter_#{name}146 @format.#{option} = #{enable}147 148 assert_equal 1, @control.message_log.size149 assert_setcharformat @control.message_log.last, 1 => #{mask}, 2 => #{name == :on ? effect : 0}150 end151 152 def test_effects_#{option}_getter_#{name}153 @format.#{option} = #{enable}154 155 assert_equal #{enable}, @format.#{option}156 end157 END158 end159 end160 161 {162 :height => %w{CFM_SIZE 3},163 :offset => %w{CFM_OFFSET 4},164 }.each do |option, (mask, index)|165 %w{20 -20}.each do |value|166 class_eval <<-"END"167 def test_#{option}_setter_#{value.gsub "-", "minus"}168 @format.#{option} = #{value}169 170 assert_equal 1, @control.message_log.size171 assert_setcharformat @control.message_log.last, 1 => #{mask}, #{index} => #{value}172 end173 174 def test_#{option}_getter_#{value.gsub "-", "minus"}175 @format.#{option} = #{value}176 177 assert_equal #{value}, @format.#{option}178 end179 END180 end181 end182 183 def test_color184 @format.color = 0xFF9933185 186 assert_equal 1, @control.message_log.size187 assert_setcharformat @control.message_log.last, 1 => CFM_COLOR, 5 => 0xFF9933188 end189 190 191 def assert_setcharformat expected, options192 assert_equal EM_SETCHARFORMAT, expected[0]193 assert_equal SCF_DEFAULT, expected[1]194 195 charformat = expected[2].unpack("LLLLLLCCU")196 options.each do |index, value|197 assert_equal value, Ruwin::SIGNEDLONG(charformat[index])198 end199 end200 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)