Class
Leditbox
Home
In: locana/l_editbox.rb
Parent: Lframe

This is a multi-line editbox or input box with scrollbars allowing you to enter data. Some interesting notes regarding the on_enter_key and on_tab_key events:

Based on the Lframe class so scrollbars are supported. Here are the attributes that are created specifically for the editbox object:

The speed of the blinking cursor is determined by the constant CURSOR_BLINK_TIME and defaults to 600 millisecs.

Methods

auto_select, auto_select=, char_count, clear, cursor_blinking, cursor_position, cursor_position=, default_bg, default_border, default_mouse_cursor, get_char, get_line, highlighted?, hscroll, hscroll_position=, include_objects, inherit_color_from_parent?, inherits_attribute?, insert_mode, insert_mode=, ipadx, ipady, is_byte_a_word_boundary?, line_count, max_line, max_size, max_size=, nearest, on_backspace_key, on_before_update, on_change, on_copy, on_cut, on_delete_key, on_down_key, on_end_key, on_enter_key, on_exit, on_home_key, on_insert_key, on_key_press, on_key_release, on_left_key, on_mouse_ldn, on_mouse_lup, on_mouse_move, on_next_word, on_pagedown_key, on_pageup_key, on_paste, on_prev_word, on_resize, on_right_key, on_scroll, on_tab_key, on_up_key, paint_focus, paint_focus?, paint_focus_remove, paint_normal, pixel_height, pixel_height_total, pixel_width, pixel_width_total, prepare, scroll_distance, scroll_distance_alignment, select_text, set_focus, skip_object_theme, tab_size, valid_attribute?, value, value=, visible_line_count, vscroll_position=, word_wrap, word_wrap=,
Public Instance methods
valid_attribute?(attribute, lvalue=nil) src

Supports several attributes specific to the editbox.

default_bg() src

Returns :sys_textbox_bg.

default_mouse_cursor() src

Returns :ibeam.

default_border() src

Returns :sunken.

inherits_attribute?(attr) src

Textbox and editbox objects don’t inherit the background color from the parent object.

inherit_color_from_parent?() src

Returns false because editbox objects don’t inherit color from parent objects.

skip_object_theme() src

Returns true because the editbox does not pull attributes from the :object attribute of any style.

tab_size() src

The default is 3. Pressing the ctrl-tab key (on_tab_key event) inserts spaces into the editbox such that the current cursor position is moved to this boundary point. For example, when at cursor position 1, pressing the tab key inserts two spaces.

ipadx() src

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

ipady() src

The default is 2 so the text does not hug the top and bottom border.

paint_focus?() src

Returns true. Leditbox object get a focus. Needed since this is based on the Lframe class and the Lframe class does not paint a focus by default.

hscroll() src

If word wrapping (:word_wrap attribute) is on, returns false because the horizontal scrollbar is disabled when word wrapping is on.

word_wrap() src

Returns the current state of word wrapping. True, false or nil. The default is false, word wrapping is off by default.

word_wrap=(new_value) src

Turn word wrapping on or off.

prepare(parent=nil, move_obj=nil) src

Positions the cursor after the object is prepared.

include_objects() src

Defines several instance variables and creates a timer for blinking the cursor.

set_focus() src

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

value() src

Returns the self[:value] attribute as a string. The :value attribute is stored as an Array of strings for performance reasons.

value=(new_value) src

Clears the selection or highlight, resets the cursor position, and converts new_value to an Array.

insert_mode() src

Returns the current state of insert_mode. The default is true.

insert_mode=(new_value) src

Sets insert mode on or off.

auto_select() src

The default is false. When true, the entire content of the editbox is highlighted every time the cursor enters the editbox.

clear(include_children=nil) src

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

auto_select=(new_value) src

Sets the :auto_select attribute on or off.

max_size() src

Returns the maximum number of characters that can be entered into this editbox. The default is unlimited (limited by memory and/or the size of a Ruby String).

max_size=(new_value) src

Sets the maximum number of characters that can be entered into this editbox.

select_text(start_line=0, start_col=0, end_line=-1, end_col=-1) src

Selects or highlights the text between start and end. Use (0,0, -1,-1) to select all text. Use (0,0, 0,0) to clear the selection.

nearest(lx, ly) src

Returns the character index (as a Leditbox_position) closest to lx, ly (the screen relative mouse position, levent[:x], levent[:y]).

cursor_position() src

Returns the current position of the cursor (as Leditbox_position) in self[:value].

cursor_position=(new_pos) src

Sets the position of the cursor to new_pos. Calls cursor_position_set(). If the text at the new cursor position is not visible, the text is automatically scrolled so the cursor is visible.

on_resize(levent=nil, &block) src

If word wrapping is turned on then rewrap the text in the editbox.

on_change(levent=nil, &block) src

This is a little different than the normal on_change event for performance reasons. This occurs after the change has been applied to the object, thus, editbox[:value] equals levent[:value] and is the content of the editbox as an array or strings (or lines) and editbox.value is the content of the editbox as a string. Here are some distinctions on the content of levent:

on_exit(levent=nil, &block) src

Automatically un-selects or de-highlighted any highlighted text.

on_before_update(levent=nil, &block) src

The editbox needs to use dup rather than clone to make a copy of the :value attribute because the :value attribute is an Array. The copy of the :value attribute is used by the :undo event.

on_paste(levent=nil, &block) src

Inserts the content of the clipboard into the editbox at cursor_position. If there is selected or highlighted text, triggers the on_cut event to remove the highlighted text. Also triggers the on_change event just after the new text is pasted into the editbox.

on_cut(levent=nil, &block) src

Cuts the selected or highlighted text from the editbox and places it in the clipboard. Triggers the on_change event just after the highlighted text is cut from the editbox.

on_copy(levent=nil, &block) src

Copies the highlighted text from the editbox to the clipboard.

on_tab_key(levent=nil, &block) src

The tab key and shift tab moves the focus to the next or previous object. The ctrl tab key is converted to spaces and inserted into the editbox. Spaces are inserted spaces into the editbox such that the current cursor position is moved to the tab_size boundary. For example, when at cursor position 1, pressing the tab key inserts two spaces. Use ctrl-tab to move to the next object and ctrl-shift-tab to move to the previous object.

on_backspace_key(levent=nil, &block) src

Eliminates any selected or highlighted text and the character before the cursor.

on_delete_key(levent=nil, &block) src

If any text is selected or highlighted, it is removed unless the Alt, Ctrl, or Shift keys are pressed with the delete key. If there is no selected or highlighted text the character after the cursor is deleted as long as the Alt, Ctrl, or Shift keys are not pressed.

on_enter_key(levent=nil, &block) src

Inserts a line feed/carriage return in the editbox. Also removes any selected or highlighted text from the editbox.

on_insert_key(levent=nil, &block) src

Toggles insert mode on and off.

on_key_release(levent=nil, &block) src

Ctrl-w toggles word wrap on and off.

on_key_press(levent=nil, &block) src

Inserts the character associated with the on_key_press event into the editbox and triggers the on_change event. Also removes any selected or highlighted text from the editbox.

on_home_key(levent=nil, &block) src

Ctrl-home key move to the first line in the editbox. Otherwise, the first home key press moves the cursor to the first non-space character in the line and the second home key press moves the cursor to the first character on the line.

on_end_key(levent=nil, &block) src

Ctrl-end key move to the last line in the editbox. Otherwise, moves the cursor to the last character on the current line.

on_pageup_key(levent=nil, &block) src

Scrolls up one page.

on_pagedown_key(levent=nil, &block) src

Scrolls down one page.

is_byte_a_word_boundary?(byte) src

This is called by on_next_word() and on_prev_word() to determine the start of the next or previous word. Returns false if byte matches any of these characters: ‘0,1,2,3,4,5,6,7,8,9,0,_,:,?,@,A,B,…,Y,Z,_,`,a,b,…,y,z’ except ’,’ and ’…’ which represents rest of the alphabet.

on_next_word(levent=nil, &block) src

Moves the cursor to the next word in the editbox. Holding the shift key will select or highlight to the next word. Called when the user does a ctrl-right_key to move to the next word. The method is_byte_a_word_boundary?() is used to determine what the first character of a word is.

on_prev_word(levent=nil, &block) src

Moves the cursor to the previous word in the editbox. Holding the shift key will highlight to the previous word. Called when the user does a ctrl-left_key to move to the previous word. The method is_byte_a_word_boundary?() is used to determine what the first character of a word is.

on_up_key(levent=nil, &block) src

The moves the cursor up one line. Holding the shift key highlights characters.

on_down_key(levent=nil, &block) src

The moves the cursor down one line. Holding the shift key highlights characters.

on_left_key(levent=nil, &block) src

The moves the cursor one character to the left. Holding the ctrl key triggers the on_prev_word event. Holding the shift key highlights the previous character.

on_right_key(levent=nil, &block) src

The moves the cursor one character to the right. Holding the ctrl key trigger the on_next_word event. Holding the shift key will highlight the next character.

on_mouse_ldn(levent=nil, &block) src

Repositions the cursor and clears any selected or highlighted text. Also prepares for dragging the highlight as the mouse is moved.

on_mouse_lup(levent=nil, &block) src

Clears any preparation for dragging the highlight as the mouse is moved. Sets the current cursor position to character nearest the mouse.

on_mouse_move(levent=nil, &block) src

Drags or expands the highlight when left mouse button is pressed.

paint_normal() src

Paints the content of the editbox and takes into consideration any highlighted or selected text, font, and 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. This scrolls the text in the editbox. The editbox automatically uses this to scroll horizontally when you type in more characters than you can see. This is used to make sure you can always see what you are typing.

vscroll_position=(new_value) src

Sets the vertical scroll position. This scrolls the text in the editbox. The editbox automatically uses this to scroll vertically when you type in more characters that you can see. This is used to make sure you can always see what you are typing.

on_scroll(levent=nil, &block) src

Triggered whenever the scroller is moved. Repaints the editbox to reflect the new position when needed.

highlighted?(line, col) src

Returns true if the character at line, col is highlighted.

char_count() src

Returns the number of characters in the editbox. Includes the line feed character at the end of each line.

visible_line_count() src

This returns the number of lines of text visible in the editbox.

line_count() src

Returns the number of lines in the editbox.

max_line() src

Returns the line number of the last line in the editbox. 0 relative.

get_line(line=nil) src

Returns the text or string at line where line is the row you want. If line == nil, the line at the current cursor position is returned.

get_char(line=nil, col=nil) src

Returns the character at line, col. If line == nil or col == nil, then the current cursor position line and col are used.

cursor_blinking(show_cursor, start_timer=true) src

Draws the cursor (focus indicator), removes the cursor, and causes the cursor to blink. Leditbox::CURSOR_BLINK_TIME determines the rate of blinking.

paint_focus() src

Calls cursor_blinking() to draw the cursor, remove the cursor, and blink the cursor.

paint_focus_remove() src

Calls cursor_blinking() to draw the cursor, remove the cursor, and blink the cursor.

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 it’s 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 it’s parents. This is used to calculate height of the object when needed. The default is to return the greater of the height of the :value attribute or height of two lines of text.

pixel_width_total() src

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

pixel_height_total() src

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


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