| 1 | module Ruwin
|
|---|
| 2 | class Component < SWin::Window
|
|---|
| 3 | include Ruwin
|
|---|
| 4 | include Ruwin::Const::Window
|
|---|
| 5 |
|
|---|
| 6 | CLASS_NAME = nil
|
|---|
| 7 | STYLE = nil
|
|---|
| 8 | EXSTYLE = nil
|
|---|
| 9 |
|
|---|
| 10 | def initialize &block
|
|---|
| 11 | @proparty = self.class.copy_proparty
|
|---|
| 12 |
|
|---|
| 13 | self.classname = self.class::CLASS_NAME if self.class::CLASS_NAME
|
|---|
| 14 | self.style = self.class::STYLE | @proparty[:style] if self.class::STYLE
|
|---|
| 15 | self.exstyle = self.class::EXSTYLE | @proparty[:exstyle] if self.class::EXSTYLE
|
|---|
| 16 | self.caption = @proparty[:caption].tosjis
|
|---|
| 17 |
|
|---|
| 18 | instance_eval &block if block
|
|---|
| 19 |
|
|---|
| 20 | create
|
|---|
| 21 | end
|
|---|
| 22 |
|
|---|
| 23 | class << self
|
|---|
| 24 | def new parent = nil, &block
|
|---|
| 25 | Factory.newwindow(parent, self, &block)
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 | def inherited klass
|
|---|
| 29 | klass.instance_variable_set :@proparty, copy_proparty
|
|---|
| 30 | end
|
|---|
| 31 |
|
|---|
| 32 | def copy_proparty
|
|---|
| 33 | proparty = {}
|
|---|
| 34 | @proparty.each do |key, value|
|
|---|
| 35 | proparty[key] = value.dup rescue value
|
|---|
| 36 | end
|
|---|
| 37 | proparty
|
|---|
| 38 | end
|
|---|
| 39 |
|
|---|
| 40 | private
|
|---|
| 41 | def property_accessor proparties
|
|---|
| 42 | @proparty.merge! proparties
|
|---|
| 43 |
|
|---|
| 44 | define_instance_methods = ""
|
|---|
| 45 | define_class_methods = ""
|
|---|
| 46 |
|
|---|
| 47 | proparties.each do |name, default|
|
|---|
| 48 | unless method_defined? name
|
|---|
| 49 | define_instance_methods << <<-"END"
|
|---|
| 50 | def #{name}
|
|---|
| 51 | @proparty[:#{name}]
|
|---|
| 52 | end
|
|---|
| 53 | END
|
|---|
| 54 | end
|
|---|
| 55 | unless method_defined? :"#{name}="
|
|---|
| 56 | define_instance_methods << <<-"END"
|
|---|
| 57 | def #{name}= value
|
|---|
| 58 | @proparty[:#{name}] = value
|
|---|
| 59 | end
|
|---|
| 60 | END
|
|---|
| 61 | end
|
|---|
| 62 | define_class_methods << <<-"END"
|
|---|
| 63 | def #{name} *args
|
|---|
| 64 | return @proparty[:#{name}] if args.empty?
|
|---|
| 65 | @proparty[:#{name}] = args.first
|
|---|
| 66 | end
|
|---|
| 67 | END
|
|---|
| 68 | end
|
|---|
| 69 |
|
|---|
| 70 | self.class_eval define_instance_methods
|
|---|
| 71 | (class << self; self; end).class_eval define_class_methods
|
|---|
| 72 | end
|
|---|
| 73 | end
|
|---|
| 74 |
|
|---|
| 75 | @proparty = {}
|
|---|
| 76 | property_accessor \
|
|---|
| 77 | :caption => "",
|
|---|
| 78 | :style => 0,
|
|---|
| 79 | :exstyle => 0
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | private
|
|---|
| 83 | def send_message_with_error_code message, wparam, lparam, error_code = self.class::ERR, &alternate
|
|---|
| 84 | result = sendMessage message, wparam, lparam
|
|---|
| 85 | if result == error_code
|
|---|
| 86 | return alternate ? alternate.call : nil
|
|---|
| 87 | end
|
|---|
| 88 | result
|
|---|
| 89 | end
|
|---|
| 90 |
|
|---|
| 91 | def draw_bundling &block
|
|---|
| 92 | sendMessage WM_SETREDRAW, 0, 0
|
|---|
| 93 | block.call
|
|---|
| 94 | sendMessage WM_SETREDRAW, 1, 0
|
|---|
| 95 | end
|
|---|
| 96 | end
|
|---|
| 97 | end
|
|---|