Class: Fzeet::Windows::HTMLElement

Inherits:
Object
  • Object
show all
Defined in:
lib/fzeet/windows/mshtml/Common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



708
709
710
# File 'lib/fzeet/windows/mshtml/Common.rb', line 708

def handlers
  @handlers
end

Instance Method Details

#attr(*args) ⇒ Object



776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
# File 'lib/fzeet/windows/mshtml/Common.rb', line 776

def attr(*args)
	case args.length
	when 1
		getAttribute(bstr = Windows.SysAllocString("#{args[0]}\0".encode('utf-16le')), 0, v = VARIANT.new)

		case v[:vt]
		when VT_BSTR; (v[:bstrVal].null?) ? nil : Windows.WCSTOMBS(v[:bstrVal])
		when VT_I4; v[:lVal]
		when VT_BOOL; v[:boolVal] == -1
		else raise
		end
	when 2
		v = VARIANT.new

		case args[1]
		when String; v[:vt] = VT_BSTR; v[:bstrVal] = bstrv = Windows.SysAllocString("#{args[0]}\0".encode('utf-16le'))
		when Integer; v[:vt] = VT_I4; v[:lVal] = args[1]
		when TrueClass; v[:vt] = VT_BOOL; v[:boolVal] = -1
		when FalseClass, NilClass; v[:vt] = VT_BOOL; v[:boolVal] = 0
		else raise ArgumentError
		end

		setAttribute(bstr = Windows.SysAllocString("#{args[0]}\0".encode('utf-16le')), v, 0)

		self
	else raise ArgumentError
	end
ensure
	Windows.SysFreeString(bstr) if bstr
	Windows.SysFreeString(bstrv) if bstrv
end

#css(hash) ⇒ Object



818
# File 'lib/fzeet/windows/mshtml/Common.rb', line 818

def css(hash) s = style; hash.each { |k, v| s.send("#{k}=", v) }; self end

#nodeObject



808
# File 'lib/fzeet/windows/mshtml/Common.rb', line 808

def node; QueryInstance(HTMLDOMNode) end

#on(event, &block) ⇒ Object



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/fzeet/windows/mshtml/Common.rb', line 710

def on(event, &block)
	((@handlers ||= {})[event] ||= []) << block
	@dcallbacks ||= []

	send("put_on#{event}", VARIANT.new.tap { |v|
		v[:vt] = VT_DISPATCH

		v[:pdispVal] = @dcallbacks.push(DCallback.new.tap { |dcb|
			dcb.instance_variable_set(:@element, self)
			dcb.instance_variable_set(:@event, event)

			def dcb.Invoke(*args)
				@element.handlers[@event].each { |handler|
					(handler.arity == 0) ? handler.call : handler.call(*args)
				}

				S_OK
			end
		}).last
	}) unless @handlers[event].length > 1

	self
end

#styleObject



810
811
812
813
814
815
816
# File 'lib/fzeet/windows/mshtml/Common.rb', line 810

def style
	FFI::MemoryPointer.new(:pointer) { |pstyle|
		get_style(pstyle)

		return HTMLStyle.new(pstyle.read_pointer)
	}
end