Class: Fzeet::MenuMethods::Item

Inherits:
Object
  • Object
show all
Includes:
Toggle
Defined in:
lib/fzeet/Menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Toggle

#toggle

Constructor Details

#initialize(menu, id) ⇒ Item

Returns a new instance of Item.



10
# File 'lib/fzeet/Menu.rb', line 10

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/fzeet/Menu.rb', line 12

def id
  @id
end

Returns the value of attribute menu.



12
13
14
# File 'lib/fzeet/Menu.rb', line 12

def menu
  @menu
end

Instance Method Details

#checked=(checked) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/fzeet/Menu.rb', line 34

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

#checked?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/fzeet/Menu.rb', line 28

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

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

#enabled=(enabled) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/fzeet/Menu.rb', line 20

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

#enabled?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/fzeet/Menu.rb', line 14

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

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

#imageObject



73
# File 'lib/fzeet/Menu.rb', line 73

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

#image=(image) ⇒ Object



75
76
77
78
79
80
# File 'lib/fzeet/Menu.rb', line 75

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

#info(mask) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fzeet/Menu.rb', line 50

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



64
65
66
67
68
69
70
71
# File 'lib/fzeet/Menu.rb', line 64

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

#select(first, last) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/fzeet/Menu.rb', line 42

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

	self
end