Changeset 28996

Show
Ignore:
Timestamp:
01/25/09 12:16:07 (4 years ago)
Author:
isaisstillalive
Message:
  • 段落フォーマットと区別するため、Rich::FormatをRich::Format::Charに変更。
Location:
lang/ruby/ruwin
Files:
2 modified

Legend:

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

    r28993 r28996  
    77        def initialize *args 
    88          super 
    9           @format = Format.new self, SCF_SELECTION 
     9          @format = Format::Char.new self, SCF_SELECTION 
    1010        end 
    1111         
     
    1717      end 
    1818       
    19       class Format 
    20         include Ruwin 
    21         include Const::EditField 
    22          
    23         def initialize control, extent_flag 
    24           @control = control 
    25           @extent_flag = extent_flag 
    26         end 
    27          
    28         { 
    29           :bold       => %w{CFM_BOLD      CFE_BOLD}, 
    30           :italic     => %w{CFM_ITALIC    CFE_ITALIC}, 
    31           :underline  => %w{CFM_UNDERLINE CFE_UNDERLINE}, 
    32           :strikeout  => %w{CFM_STRIKEOUT CFE_STRIKEOUT}, 
    33           :protected  => %w{CFM_PROTECTED CFE_PROTECTED}, 
    34         }.each do |option, (mask, effect)| 
    35           class_eval <<-"END" 
    36             def #{option}= enable 
    37               set_char_format(#{mask}, :effects => (enable ? #{effect} : 0)) 
    38             end 
    39              
    40             def #{option} 
    41               get_char_format(#{mask})[2]&#{effect} == #{effect} 
    42             end 
    43           END 
    44         end 
    45          
    46         { 
    47           :height     => %w{CFM_SIZE    twip}, 
    48           :offset     => %w{CFM_OFFSET  twip}, 
    49           :color      => %w{CFM_COLOR   color}, 
    50         }.each do |option, (mask, variable)| 
    51           class_eval <<-"END" 
    52             def #{option}= #{variable} 
    53               set_char_format(#{mask}, :#{option} => #{variable}) 
    54             end 
    55           END 
    56         end 
    57          
    58         def height 
    59           SIGNEDLONG(get_char_format(CFM_SIZE)[3]) 
    60         end 
    61          
    62         def offset 
    63           SIGNEDLONG(get_char_format(CFM_OFFSET)[4]) 
    64         end 
    65          
    66         def color 
    67           get_char_format(CFM_OFFSET)[5] 
    68         end 
    69          
    70          
    71         private 
    72         CHARFORMAT = "LLLLLLCCU" 
    73          
    74         def set_char_format mask, options 
    75           @control.sendMessage EM_SETCHARFORMAT, @extent_flag, char_format(mask, options) 
    76         end 
    77          
    78         def get_char_format mask 
    79           charformat = char_format mask 
    80           @control.sendMessage EM_GETCHARFORMAT, @extent_flag, charformat 
    81           charformat.unpack CHARFORMAT 
    82         end 
    83          
    84         def char_format mask, options = {} 
    85           [ 
    86             60, 
    87             mask, 
    88             options[:effects] || 0, 
    89             options[:height]  || 0, 
    90             options[:offset]  || 0, 
    91             options[:color]   || 0, 
    92             0, 
    93             0, 
    94             0, 
    95           ].pack CHARFORMAT 
     19      module Format 
     20        class Char 
     21          include Ruwin 
     22          include Const::EditField 
     23           
     24          def initialize control, extent_flag 
     25            @control = control 
     26            @extent_flag = extent_flag 
     27          end 
     28           
     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}= enable 
     38                set_char_format(#{mask}, :effects => (enable ? #{effect} : 0)) 
     39              end 
     40               
     41              def #{option} 
     42                get_char_format(#{mask})[2]&#{effect} == #{effect} 
     43              end 
     44            END 
     45          end 
     46           
     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              end 
     56            END 
     57          end 
     58           
     59          def height 
     60            SIGNEDLONG(get_char_format(CFM_SIZE)[3]) 
     61          end 
     62           
     63          def offset 
     64            SIGNEDLONG(get_char_format(CFM_OFFSET)[4]) 
     65          end 
     66           
     67          def color 
     68            get_char_format(CFM_OFFSET)[5] 
     69          end 
     70           
     71           
     72          private 
     73          CHARFORMAT = "LLLLLLCCU" 
     74           
     75          def set_char_format mask, options 
     76            @control.sendMessage EM_SETCHARFORMAT, @extent_flag, char_format(mask, options) 
     77          end 
     78           
     79          def get_char_format mask 
     80            charformat = char_format mask 
     81            @control.sendMessage EM_GETCHARFORMAT, @extent_flag, charformat 
     82            charformat.unpack CHARFORMAT 
     83          end 
     84           
     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 CHARFORMAT 
     97          end 
    9698        end 
    9799      end 
     
    114116        self.background_color = @proparty[:background_color] if @proparty[:background_color] 
    115117         
    116         @default = Format.new self, SCF_DEFAULT 
     118        @default = Format::Char.new self, SCF_DEFAULT 
    117119        @default.color = @proparty[:color] if @proparty[:color] 
    118120      end 
  • lang/ruby/ruwin/test/ruwin/edit_field/test_rich.rb

    r28993 r28996  
    2626   
    2727  def test_default_format 
    28     assert_kind_of Ruwin::EditField::Rich::Format, @control.default 
     28    assert_kind_of Ruwin::EditField::Rich::Format::Char, @control.default 
    2929    assert_same @control, @control.default.instance_variable_get(:@control) 
    3030  end 
     
    122122end 
    123123 
    124 class TestRuwinEditFieldRichFormatDefault < Test::Unit::TestCase 
     124class TestRuwinEditFieldRichCharFormat < Test::Unit::TestCase 
    125125  include Ruwin::Const::EditField 
    126126