| 1 | module Ruwin
|
|---|
| 2 | class EditField
|
|---|
| 3 | class Rich < EditField
|
|---|
| 4 | autoload :Format, "ruwin/edit_field/rich/format"
|
|---|
| 5 |
|
|---|
| 6 | class Selection < EditField::Selection
|
|---|
| 7 | attr_reader :format
|
|---|
| 8 |
|
|---|
| 9 | def initialize *args
|
|---|
| 10 | super
|
|---|
| 11 | @format = Format::Char.new self, SCF_SELECTION
|
|---|
| 12 | end
|
|---|
| 13 |
|
|---|
| 14 | def string
|
|---|
| 15 | result = "\0"*length
|
|---|
| 16 | sendMessage EM_GETSELTEXT, 0, result
|
|---|
| 17 | result
|
|---|
| 18 | end
|
|---|
| 19 | end
|
|---|
| 20 |
|
|---|
| 21 | SELECTION_CLASS = Selection
|
|---|
| 22 |
|
|---|
| 23 | LoadLibrary = Win32API.new("kernel32","LoadLibrary",["P"],"I")
|
|---|
| 24 | if LoadLibrary.call("riched20") != 0
|
|---|
| 25 | CLASS_NAME = "RICHEDIT20A"
|
|---|
| 26 | elsif LoadLibrary.call("riched32") != 0
|
|---|
| 27 | CLASS_NAME = "RICHEDIT"
|
|---|
| 28 | end
|
|---|
| 29 |
|
|---|
| 30 | property_accessor :background_color => nil, :color => nil
|
|---|
| 31 | attr_reader :default
|
|---|
| 32 |
|
|---|
| 33 | def initialize
|
|---|
| 34 | super
|
|---|
| 35 |
|
|---|
| 36 | sendMessage EM_SETEVENTMASK, 0, ENM_KEYEVENTS|ENM_LINK
|
|---|
| 37 |
|
|---|
| 38 | self.background_color = @proparty[:background_color] if @proparty[:background_color]
|
|---|
| 39 |
|
|---|
| 40 | @default = Format::Char.new self, SCF_DEFAULT
|
|---|
| 41 | @default.color = @proparty[:color] if @proparty[:color]
|
|---|
| 42 | end
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | def background_color= color
|
|---|
| 46 | if color
|
|---|
| 47 | sendMessage EM_SETBKGNDCOLOR, 0, color
|
|---|
| 48 | else
|
|---|
| 49 | sendMessage EM_SETBKGNDCOLOR, 1, 0
|
|---|
| 50 | end
|
|---|
| 51 | end
|
|---|
| 52 |
|
|---|
| 53 | def auto_url_detect= enable
|
|---|
| 54 | if enable
|
|---|
| 55 | sendMessage EM_AUTOURLDETECT, 1, 0
|
|---|
| 56 | else
|
|---|
| 57 | sendMessage EM_AUTOURLDETECT, 0, 0
|
|---|
| 58 | end
|
|---|
| 59 | end
|
|---|
| 60 |
|
|---|
| 61 | notifies = {
|
|---|
| 62 | :EN_MSGFILTER => :en_msgfilter,
|
|---|
| 63 | :EN_LINK => :en_link,
|
|---|
| 64 | }.map{|command, event| "when #{command}; #{event} msg;" }.join
|
|---|
| 65 | class_eval <<-"END"
|
|---|
| 66 | def wm_notify msg, hwndFrom, idFrom, code
|
|---|
| 67 | case code
|
|---|
| 68 | #{notifies}
|
|---|
| 69 | else
|
|---|
| 70 | super
|
|---|
| 71 | end
|
|---|
| 72 | end
|
|---|
| 73 | END
|
|---|
| 74 |
|
|---|
| 75 | def en_msgfilter msg
|
|---|
| 76 | nmhdr1, nmhdr2, nmhdr2, msg, wParam, lParam = *SWin::Application.cstruct2array(msg.lParam, "UUUUUU")
|
|---|
| 77 | case msg
|
|---|
| 78 | when WM_KEYDOWN
|
|---|
| 79 | [:keydown, wParam]
|
|---|
| 80 | end
|
|---|
| 81 | end
|
|---|
| 82 |
|
|---|
| 83 | def en_link msg
|
|---|
| 84 | nmhdr1, nmhdr2, nmhdr2, msg, wParam, lParam, first, last = *SWin::Application.cstruct2array(msg.lParam, "UUUUUUUU")
|
|---|
| 85 | case msg
|
|---|
| 86 | when WM_LBUTTONDOWN
|
|---|
| 87 | [:link_lmousedown, first, last]
|
|---|
| 88 | end
|
|---|
| 89 | end
|
|---|
| 90 |
|
|---|
| 91 | class Multiline < Rich
|
|---|
| 92 | STYLE = EditField::Multiline::STYLE
|
|---|
| 93 | end
|
|---|
| 94 | end
|
|---|
| 95 | end
|
|---|
| 96 | end
|
|---|