Module: Fzeet::ListBoxMethods
- Included in:
- ComboBoxMethods, ListBox
- Defined in:
- lib/fzeet/Control/ListBox.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #append(item) ⇒ Object
- #clear ⇒ Object
- #each ⇒ Object
- #length ⇒ Object
- #selected=(i) ⇒ Object
- #textlen(i) ⇒ Object
Instance Method Details
#[](i) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fzeet/Control/ListBox.rb', line 7 def [](i) i = sendmsg(:getcursel) if i == :selected return '' if i == -1 || (len = textlen(i) + 1) == 1 ''.tap { |item| FFI::MemoryPointer.new(:char, len) { |buf| raise "GETTEXT failed." if sendmsg(:gettext, i, buf) == -1 item << buf.read_string } } end |
#append(item) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/fzeet/Control/ListBox.rb', line 23 def append(item) [*item].each { |item| p = FFI::MemoryPointer.from_string(item.to_s) raise 'ADDSTRING failed.' if [-1, -2].include?(sendmsg(:addstring, 0, p).tap { p.free }) } self end |
#clear ⇒ Object
21 |
# File 'lib/fzeet/Control/ListBox.rb', line 21 def clear; sendmsg(:resetcontent); self end |
#each ⇒ Object
47 |
# File 'lib/fzeet/Control/ListBox.rb', line 47 def each; length.times { |i| yield self[i] }; self end |
#length ⇒ Object
46 |
# File 'lib/fzeet/Control/ListBox.rb', line 46 def length; raise 'GETCOUNT failed.' if (len = sendmsg(:getcount)) == -1; len end |
#selected=(i) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fzeet/Control/ListBox.rb', line 33 def selected=(i) i = case i when -1; 0xffffffff when :first; 0 when :last; length - 1 else i end raise 'SETCURSEL failed.' if sendmsg(:setcursel, i) == -1 && i != 0xffffffff self end |
#textlen(i) ⇒ Object
5 |
# File 'lib/fzeet/Control/ListBox.rb', line 5 def textlen(i) raise "GETTEXTLEN failed." if (len = sendmsg(:gettextlen, i)) == -1; len end |