Class
Llistbox
Home
In: locana/l_listbox.rb
Parent: Lframe

This class draws a listbox. It is based on the Lframe class so scrollbars are supported. This class also supports the following additional attributes:

Methods

active_item, active_item=, add_item, clear, default_border, del_item, deselect, each_index, each_index_reverse, each_item, each_item_reverse, get_item, hscroll_position=, include_objects, ipadx, is_selected?, item_count, nearest, nitems, on_down_key, on_end_key, on_home_key, on_key_release, on_left_key, on_mouse_ldn, on_mouse_rdn, on_pagedown_key, on_pageup_key, on_right_key, on_scroll, on_up_key, otype, paint_focus, paint_focus?, paint_focus_remove, paint_normal, pixel_height, pixel_height_total, pixel_width, pixel_width_total, scroll_distance, scroll_distance_alignment, see, select, set_focus, text=, update_item, valid_attribute?, value, value=, vertical_spacing, vertical_spacing=, vscroll_position=,
Public Instance methods
valid_attribute?(attribute, lvalue=nil) src

Supports the :otype, :vertical_spacing, :value, and :text attributes.

include_objects() src

Defines any needed instance variables.

set_focus() src

Calls the Lobject version of the set_focus rather than the Lframe version of set_focus.

default_border() src

Returns the symbol to use as the default border for this object. Returns :sunken as the default.

paint_focus?() src

Returns true because listboxes gets a focus, this is needed because the Lframe class does not paint a focus by default.

paint_focus() src

Paints the focus indicator. The focus for the listbox object underlines the current or active item in the listbox.

paint_focus_remove() src

This should undo or remove the focus painted by paint_focus.

paint_normal() src

Draws the listbox using the font and color of the listbox. Selected items (in the :value attribute) are drawn using the fg_highlight and bg_highlight colors.

scroll_distance_alignment(is_horizontal) src

The scrollbars use this value for determining the alignment when dragging the scroller button. The default is the height of a single line of text for vertical scrollbars and super for horizontal scrollbars. It keeps the top line fully visible at all times.

scroll_distance(is_horizontal) src

The scrollbars use this value for determining the scrolling distance when pushing one of the buttons in the scrollbar. The default is the height of a single line of text for vertical scrollbars and super for horizontal scrollbars.

hscroll_position=(new_value) src

Sets the horizontal scroll position. Scrolls the text in the listbox. Allows you to scroll the text in the listbox left or right. The on_scroll event automatically calls this as the horizontal scroller button is moved. This repaints the listbox to reflect the change.

vscroll_position=(new_value) src

Sets the vertical scroll position. Scrolls the text in the listbox. Allows you to scroll the text in the listbox up or down. The on_scroll event automatically calls this as the vertical scroller button is moved. This repaints the listbox to reflect the change.

on_scroll(levent=nil, &block) src

Triggered whenever the scroller is moved in one of the scrollbars. Repaints the listbox to reflect the new position when needed.

on_mouse_ldn(levent=nil, &block) src

Selects the item in the list closed to the mouse when the left button is clicked.

on_mouse_rdn(levent=nil, &block) src

Remembers the item closest to the mouse when the right mouse button is clicked so it can be used by any popup menus.

on_home_key(levent=nil, &block) src

Makes sure the first item in the list is visible and is the active item. Calls see(0) and sets the active_item to 0.

on_end_key(levent=nil, &block) src

Makes sure the last item in the list is visible and is the active item. Calls see(-1) and sets the active_item to -1.

on_left_key(levent=nil, &block) src

Scrolls the listbox to the left scroll_distance pixels, ctrl-left scrolls to first character. Ignored if there is no horizontal scrollbar.

on_right_key(levent=nil, &block) src

Scroll the list to the right scroll_distance pixels, ctrl-right scrolls so that the last character is visible. Ignored if there is no horizontal scrollbar.

on_up_key(levent=nil, &block) src

Up moves the active item or focus indicator up one line, shift-up scrolls up one page and moves the focus indicator, ctrl-up scrolls up to and moves the focus indicator to the first item in the list.

on_down_key(levent=nil, &block) src

Down moves the active item or focus indicator down one line, shift-up scrolls down one page and moves the focus indicator, ctrl-up scrolls down such that the last item in the list is visible and moves the focus indicator to the last item in the listbox.

on_pageup_key(levent=nil, &block) src

Scrolls up one page.

on_pagedown_key(levent=nil, &block) src

Scrolls down one page.

on_key_release(levent=nil, &block) src

The spacebar toggles selecting/deselecting the active item or focus indicator (where the cursor is).

text=(new_value) src

Changes the text in the listbox. This updates the scrollbars and clears selected items (:value attribute). Also repaints the listbox.

otype() src

Returns the :otype attribute. The default is :single if the :otype attribute has not been specified.

each_item(reverse_order=nil) {|get_item(idx, idx)| ...} src

Yields each selected item in the listbox. Calls yield(item, idx).

each_item_reverse() src

Yields each selected item in reverse order. See each_item for more details.

each_index(reverse_order=nil) {|idx| ...} src

Iterates over each selected value. Yields the index of each selected value (indexes in the :value attribute) in the listbox.

each_index_reverse() src

Iterates over each selected value in reverse order. Yields the index of each selected value (indexes in the :value attribute) in the listbox.

value() src

Returns the :value attribute. When otype == :single, this returns a single Fixnum of the selected item. When otype == :multiple or :extended, this returns an array of Fixnums. Returns nil if there are no selected items.

value=(new_value) src

Sets the value attribute, highlights the values.

clear(include_children=nil) src

Calls the Lobject version of clear rather than the Lframe version of clear.

add_item(index, text, dont_paint=nil) src

Adds text to the listbox at index.

del_item(index, dont_paint=nil) src

Deletes the item at index from the listbox.

update_item(index, text, dont_paint=nil) src

Changes the text associated with the item in the listbox at index.

active_item=(new_index) src

Sets the active, current item, or focus indicator. This item will always be visible because is shows when the listbox has the focus by drawing a line under the item. If the item at new_index is not visible, the listbox is automatically scrolled and repainted so you can see the item.

active_item() src

Returns the index of the currently selected or active item in the listbox.

get_item(index=nil, dont_return_active_item=nil) src

Returns the item (the text from the :text Array) at index from the list. If index is nil, then returns the selected item(s) from the :value attribute, if there are no selected items and the otype==:single, then the active_item (item under the cursor) is returned.

nearest(ly=screenY) src

Returns the index of the item nearest the ly pixel position where ly is a screen relative pixel position (the :y element of the Levent object, i.e. levent[:y]).

see(index, force_repaint=nil) src

Makes sure the item at index is visible. If the item at index is not visible, the listbox is scrolled and repainted such that the item at index is visible.

is_selected?(index) src

Returns true if index is selected or highlighted.

select(index, levent=nil, dont_paint=nil) src

Selects or highlight the item at index.

deselect(index, dont_paint=nil) src

Unselects or un-highlights the item at index.

from the :value attribute.

vertical_spacing() src

This is the vertical spacing in pixels between each item in the list. The default is 0.

vertical_spacing=(new_value) src

Sets the vertical spacing in pixels between each item in the list. This will repaints the listbox using the new value.

ipadx() src

The default is 3 so the text does not hug the left and right border.

pixel_width() src

Returns the pixel width of the text in the object. This should take into consideration the font, size, and style of the object and its parents. This is used to calculate width of the object when needed.

pixel_height() src

Returns the pixel height of the text in the object. This should take into consideration the font, size, and style of the object and its parents. This is used to calculate height of the object when needed.

pixel_width_total() src

Returns the total pixel width needed by the text currently in the listbox.

pixel_height_total() src

Returns the total pixel height needed by the text currently in the listbox.

item_count() src

Returns the number of items (Strings or Symbols) currently in the listbox (in the :text Array).

nitems()

Alias for item_count


Seva Software


Thank you for taking the time to visit this web page. I trust you found the information contained in this page useful.
Please email any questions, concerns, or issues with this web site to webmaster@sevasoftware.com.
Please remember Seva Software when your company would benefit from an experienced database architect and software engineer.

http://www.arunadb.org http://www.locana.org http://www.ruby-lang.org http://www.coolwell.org http://www.sevasoftware.com