Class: Fzeet::Button

Inherits:
Control show all
Includes:
ButtonMethods
Defined in:
lib/fzeet/windows/user/Control/Button.rb

Constant Summary collapse

Prefix =
{
	xstyle: [:ws_ex_],
	style: [:bs_, :ws_],
	message: [:bm_, :bcm_, :ccm_, :wm_],
	notification: [:bn_, :bcn_, :nm_]
}

Constants included from WindowMethods

WindowMethods::EnumChildProc

Instance Attribute Summary

Attributes inherited from Control

#id, #parent

Instance Method Summary collapse

Methods included from ButtonMethods

#checked=, #checked?, #image=, #indeterminate=, #indeterminate?, #note=, #pushed=, #pushed?

Methods inherited from Control

crackNotification, #dispose

Methods included from WindowMethods

#[], #capture=, #capture?, #dialog=, #dialog?, #dlgmsg?, #drawMenuBar, #eachChild, #enabled=, #enabled?, #focus=, #focus?, #invalidate, #location, #location=, #long, #menu, #menu=, #message, #paint, #position, #position=, #postmsg, #question, #rect, #reframe, #sendmsg, #show, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?

Methods included from Toggle

#toggle

Constructor Details

#initialize(parent, id, opts = {}, &block) ⇒ Button

Returns a new instance of Button.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fzeet/windows/user/Control/Button.rb', line 88

def initialize(parent, id, opts = {}, &block)
	super('Button', parent, id, opts)

	width, height = 0, 0

	using(ScreenDC.new) { |dc| dc.select(Font) {
		minw = dc.textExtent('W' * 8).to_a[0]
		width, height = dc.textExtent("W#{text}W").to_a

		width = minw if width < minw; height = (height * 1.8).ceil
	}}

	self.location = 10, 10 if location.client!(parent).to_a == [0, 0]
	self.size = width, height if size.to_a == [0, 0]

	@parent.on(:command, @id, &block) if block
end

Instance Method Details

#on(notification, &block) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/fzeet/windows/user/Control/Button.rb', line 106

def on(notification, &block)
	if (notification = Fzeet.constant(notification, *self.class::Prefix[:notification])) < Windows::BCN_LAST
		@parent.on(:command, @id, notification, &block)
	else
		@parent.on(:notify, @id, notification, &block)
	end

	self
end