Class: Fzeet::Windows::MenuMethods::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/fzeet/windows/user/Menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(menu, id) ⇒ Item

Returns a new instance of Item.



119
# File 'lib/fzeet/windows/user/Menu.rb', line 119

def initialize(menu, id) @menu, @id = menu, Command[id] end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



121
122
123
# File 'lib/fzeet/windows/user/Menu.rb', line 121

def id
  @id
end

Returns the value of attribute menu.



121
122
123
# File 'lib/fzeet/windows/user/Menu.rb', line 121

def menu
  @menu
end

Instance Method Details

#checked=(checked) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/fzeet/windows/user/Menu.rb', line 143

def checked=(checked)
	Windows.DetonateLastError(-1, :CheckMenuItem,
		@menu.handle,
		@id,
		(checked) ? Windows::MF_CHECKED : Windows::MF_UNCHECKED
	)
end

#checked?Boolean

Returns:

  • (Boolean)


137
138
139
140
141
# File 'lib/fzeet/windows/user/Menu.rb', line 137

def checked?
	flags = Windows.DetonateLastError(-1, :GetMenuState, @menu.handle, @id, 0)

	(flags & Windows::MF_CHECKED) == Windows::MF_CHECKED
end

#enabled=(enabled) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/fzeet/windows/user/Menu.rb', line 129

def enabled=(enabled)
	Windows.DetonateLastError(-1, :EnableMenuItem,
		@menu.handle,
		@id,
		(enabled) ? Windows::MF_ENABLED : Windows::MF_GRAYED
	)
end

#enabled?Boolean

Returns:

  • (Boolean)


123
124
125
126
127
# File 'lib/fzeet/windows/user/Menu.rb', line 123

def enabled?
	flags = Windows.DetonateLastError(-1, :GetMenuState, @menu.handle, @id, 0)

	(flags & Windows::MF_GRAYED) != Windows::MF_GRAYED
end

#imageObject



182
# File 'lib/fzeet/windows/user/Menu.rb', line 182

def image; (Handle.instance?(handle = info(:bitmap)[:hbmpItem])) ? Handle.instance(handle) : nil end

#image=(image) ⇒ Object



184
185
186
187
188
189
# File 'lib/fzeet/windows/user/Menu.rb', line 184

def image=(image)
	self.info = Windows::MENUITEMINFO.new.tap { |mii|
		mii[:fMask] = Windows::MIIM_BITMAP
		mii[:hbmpItem] = image.handle
	}
end

#info(mask) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fzeet/windows/user/Menu.rb', line 159

def info(mask)
	Windows.DetonateLastError(0, :GetMenuItemInfo,
		@menu.handle,
		@id,
		0,
		info = Windows::MENUITEMINFO.new.tap { |mii|
			mii[:cbSize] = mii.size
			mii[:fMask] = Fzeet.constant(mask, :miim_)
		}
	)

	info
end

#info=(mii) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/fzeet/windows/user/Menu.rb', line 173

def info=(mii)
	Windows.DetonateLastError(0, :SetMenuItemInfo,
		@menu.handle,
		@id,
		0,
		mii.tap { mii[:cbSize] = mii.size }
	)
end

#select(first, last) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/fzeet/windows/user/Menu.rb', line 151

def select(first, last)
	Windows.DetonateLastError(0, :CheckMenuRadioItem,
		@menu.handle, Command[first], Command[last], @id, 0
	)

	self
end