Class: Glimmer::SWT::TextProxy

Inherits:
WidgetProxy show all
Defined in:
lib/glimmer/swt/text_proxy.rb

Direct Known Subclasses

StyledTextProxy

Constant Summary

Constants inherited from WidgetProxy

WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP

Instance Attribute Summary collapse

Attributes inherited from WidgetProxy

#args, #background, #children, #cursor, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #menu_x, #menu_y, #parent, #path, #rendered

Instance Method Summary collapse

Methods inherited from WidgetProxy

#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #attach, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, #listeners, #listeners_for, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #parent_dom_element, #parent_path, #parents, #post_add_content, #post_dispose_child, #post_initialize_child, #print, #property_type_converters, #reattach, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #resume_event_handling, #selector, #set_attribute, #set_data, #set_focus, #shell, #skip_content_on_render_blocks?, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(parent, args, block) ⇒ TextProxy

Returns a new instance of TextProxy.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/glimmer/swt/text_proxy.rb', line 15

def initialize(parent, args, block)
  args << :border if args.empty?
  @border = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:border] }
  @left = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:left] }
  @center = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:center] }
  @right = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:right] }
  @read_only = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:read_only] }
  @wrap = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:wrap] }
  @multi = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:multi] }
  super(parent, args, block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy

Instance Attribute Details

#borderObject (readonly) Also known as: border?

Returns the value of attribute border.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def border
  @border
end

#centerObject (readonly) Also known as: center?

Returns the value of attribute center.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def center
  @center
end

#leftObject (readonly) Also known as: left?

Returns the value of attribute left.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def left
  @left
end

#multiObject (readonly) Also known as: multi?

Returns the value of attribute multi.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def multi
  @multi
end

#read_onlyObject (readonly) Also known as: read_only?

Returns the value of attribute read_only.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def read_only
  @read_only
end

#rightObject (readonly) Also known as: right?

Returns the value of attribute right.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def right
  @right
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def text
  @text
end

#wrapObject (readonly) Also known as: wrap?

Returns the value of attribute wrap.



6
7
8
# File 'lib/glimmer/swt/text_proxy.rb', line 6

def wrap
  @wrap
end

Instance Method Details

#domObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/glimmer/swt/text_proxy.rb', line 97

def dom
  text_text = @text
  text_id = id
  text_style = 'min-width: 27px; '
  text_style += 'border: none; ' if !@border
  text_style += 'text-align: left; ' if @left
  text_style += 'text-align: center; ' if @center
  text_style += 'text-align: right; ' if @right
  text_class = name
  options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text}
  options = options.merge('disabled': 'disabled') unless @enabled
  options = options.merge('readonly': 'readonly') if @read_only
  options = options.merge('contenteditable': 'true')
  options = options.merge(type: 'password') if has_style?(:password)
  @dom ||= html {
    send(element, options)
  }.to_s
end

#elementObject



32
33
34
# File 'lib/glimmer/swt/text_proxy.rb', line 32

def element
  @wrap || @multi ? 'textarea' : 'input'
end

#observation_request_to_event_mappingObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/glimmer/swt/text_proxy.rb', line 36

def observation_request_to_event_mapping
  myself = self
  {
    'on_verify_text' => [
      {
        event: 'beforeinput',
        event_handler: -> (event_listener) {
          -> (event) {
            event.define_singleton_method(:widget) {myself}
            event.define_singleton_method(:text) {`#{event.to_n}.originalEvent.data` || ''}
            selection_start = `#{event.target}[0].selectionStart`
            selection_end = `#{event.target}[0].selectionEnd`
            if `#{event.to_n}.originalEvent.inputType` == 'deleteContentBackward' && selection_start == selection_end
              selection_start -= 1
              selection_start = 0 if selection_start < 0
            end
            event.define_singleton_method(:start) do
              selection_start
            end
            event.define_singleton_method(:end) {selection_end}
            doit = true
            event.define_singleton_method(:doit=) do |value|
              doit = value
            end
            event.define_singleton_method(:doit) { doit }
            event_listener.call(event)
            
            if !doit
              `#{event.to_n}.originalEvent.returnValue = false`
            end
            
            doit
          }
        }
      },
      {
        event: 'input',
        event_handler: -> (event_listener) {
          -> (event) {
            event.define_singleton_method(:widget) {myself}
            @text = event.target.value
          }
        }
      }
    ],
    'on_modify_text' => [
      {
        event: 'input',
        event_handler: -> (event_listener) {
          -> (event) {
            # TODO add all attributes for on_modify_text modify event
            event.define_singleton_method(:widget) {myself}
            @text = event.target.value
            event_listener.call(event)
          }
        }
      }
    ],
  }
end