Class: Glimmer::SWT::MenuProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::MenuProxy
- Defined in:
- lib/glimmer/swt/menu_proxy.rb
Overview
Proxy for org.eclipse.swt.widgets.Menu
Functions differently from other widget proxies.
Glimmer automatically detects if this is a drop down menu or pop up menu from its parent if no SWT style is passed in.
There are 3 possibilities:
-
SWT :bar style is passed in: Menu Bar
-
Parent is ShellProxy: Pop Up Menu (having style :pop_up)
-
Parent is another Menu: Drop Down Menu (having style :drop_down)
In order to get the SWT Menu object, one must call ‘#swt_widget`.
In the case of a Drop Down menu, this automatically creates an SWT MenuItem object with style :cascade
In order to retrieve the menu item widget proxy, one must call ‘#menu_item_proxy`
Follows the Proxy Design Pattern
Constant Summary
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::DEFAULT_STYLES, WidgetProxy::KEYWORD_ALIASES
Instance Attribute Summary collapse
-
#menu_item_proxy ⇒ Object
readonly
Returns the value of attribute menu_item_proxy.
-
#menu_parent ⇒ Object
readonly
Returns the value of attribute menu_parent.
-
#swt_menu_item ⇒ Object
readonly
Returns the value of attribute swt_menu_item.
Attributes inherited from WidgetProxy
#drag_source_proxy, #drag_source_style, #drag_source_transfer, #drop_target_proxy, #drop_target_transfer, #finished_add_content, #parent_proxy, #swt_widget
Attributes included from Custom::Drawable
#image_double_buffered, #requires_shape_disposal
Instance Method Summary collapse
- #can_handle_observation_request?(observation_request, super_only: false) ⇒ Boolean
- #get_attribute(attribute_name) ⇒ Object
- #handle_observation_request(observation_request, &block) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
-
#initialize(parent, args) ⇒ MenuProxy
constructor
A new instance of MenuProxy.
- #set_attribute(attribute_name, *args) ⇒ Object
Methods inherited from WidgetProxy
#add_observer, #async_exec, #can_add_observer?, #can_handle_drag_observation_request?, #can_handle_drop_observation_request?, #content, create, #dispose, #disposed?, #ensure_drag_source_proxy, #ensure_drop_target_proxy, #extract_args, #finish_add_content!, flyweight_swt_widget_classes, #has_attribute_getter?, #has_attribute_setter?, #has_style?, #method_missing, #pack_same_size, #post_add_content, #post_initialize_child, #remove_observer, #respond_to?, swt_widget_class_for, swt_widget_class_manual_entries, #sync_exec, #timer_exec, underscored_widget_name, widget_exists?, #widget_property_listener_installers, widget_proxy_class
Methods included from Custom::Drawable
#add_shape, #clear_shapes, #deregister_shape_painting, #image_buffered_shapes, #setup_shape_painting, #shapes
Methods included from Properties
attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter
Methods included from Packages
Constructor Details
#initialize(parent, args) ⇒ MenuProxy
Returns a new instance of MenuProxy.
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 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 51 def initialize(parent, args) index = args.delete(args.last) if args.last.is_a?(Numeric) styles = args.map(&:to_sym) if !styles.include?(:bar) && !parent..is_a?(Menu) styles = styles.unshift(:pop_up) end = self.class.('menu') if parent..is_a?(Menu) @menu_item_proxy = SWT::WidgetProxy.new('menu_item', parent, [:cascade] + [index].compact) @swt_menu_item = @menu_item_proxy. @swt_widget = .new(@menu_item_proxy.) @swt_menu_item.setMenu() elsif parent..is_a?(Shell) @swt_widget = .new(parent., style('menu', styles)) else @swt_widget = .new(parent.) end if styles.include?(:bar) parent..setMenuBar() elsif styles.include?(:pop_up) parent..setMenu() end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#menu_item_proxy ⇒ Object (readonly)
Returns the value of attribute menu_item_proxy.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @menu_item_proxy end |
#menu_parent ⇒ Object (readonly)
Returns the value of attribute menu_parent.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @menu_parent end |
#swt_menu_item ⇒ Object (readonly)
Returns the value of attribute swt_menu_item.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @swt_menu_item end |
Instance Method Details
#can_handle_observation_request?(observation_request, super_only: false) ⇒ Boolean
107 108 109 110 111 112 113 114 115 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 107 def can_handle_observation_request?(observation_request, super_only: false) observation_request = observation_request.to_s super_result = super(observation_request) if observation_request.start_with?('on_') && !super_result && !super_only return .can_handle_observation_request?(observation_request) else super_result end end |
#get_attribute(attribute_name) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 97 def get_attribute(attribute_name) if normalized_attribute(attribute_name) == 'text' @swt_menu_item.getText elsif normalized_attribute(attribute_name) == 'enabled' @swt_menu_item.getEnabled else super(attribute_name) end end |
#handle_observation_request(observation_request, &block) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 117 def handle_observation_request(observation_request, &block) if can_handle_observation_request?(observation_request, super_only: true) super else .handle_observation_request(observation_request, &block) end end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
77 78 79 80 81 82 83 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 77 def has_attribute?(attribute_name, *args) if ['text', 'enabled'].include?(attribute_name.to_s) true else super(attribute_name, *args) end end |
#set_attribute(attribute_name, *args) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 85 def set_attribute(attribute_name, *args) if normalized_attribute(attribute_name) == 'text' text_value = args[0] @swt_menu_item.setText text_value elsif normalized_attribute(attribute_name) == 'enabled' value = args[0] @swt_menu_item.setEnabled value else super(attribute_name, *args) end end |