| 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 |