Class: Glimmer::SWT::ShellProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::ShellProxy
- Defined in:
- lib/glimmer/swt/shell_proxy.rb
Overview
Proxy for org.eclipse.swt.widgets.Shell
Follows the Proxy Design Pattern
Constant Summary collapse
- WIDTH_MIN =
190
- HEIGHT_MIN =
0
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::DEFAULT_STYLES, WidgetProxy::KEYWORD_ALIASES
Instance Attribute Summary collapse
-
#last_shell_closing ⇒ Object
(also: #last_shell_closing?)
readonly
Returns the value of attribute last_shell_closing.
-
#opened_before ⇒ Object
(also: #opened_before?)
readonly
Returns the value of attribute opened_before.
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
- #add_observer(observer, property_name) ⇒ Object
-
#center_within_display ⇒ Object
(also: #center_in_display)
Centers shell within monitor it is in.
-
#close ⇒ Object
Closes shell.
- #content(&block) ⇒ Object
- #disposed? ⇒ Boolean (also: #disposed)
-
#hide ⇒ Object
Hides shell.
- #include_focus_control? ⇒ Boolean
-
#initialize(*args, swt_widget: nil) ⇒ ShellProxy
constructor
Instantiates ShellProxy with same arguments expected by SWT Shell if swt_widget keyword arg was passed, then it is assumed the shell has already been instantiated and the proxy wraps it instead of creating a new one.
- #nested? ⇒ Boolean (also: #nested)
-
#open ⇒ Object
(also: #show)
Opens shell and starts SWT’s UI thread event loop.
-
#open_only ⇒ Object
Opens without starting the event loop.
- #pack_same_size ⇒ Object
-
#start_event_loop ⇒ Object
(happens as part of ‘#open`) Starts SWT Event Loop.
-
#visible=(visibility) ⇒ Object
Setting to true opens/shows shell.
- #visible? ⇒ Boolean (also: #visible)
Methods inherited from WidgetProxy
#async_exec, #auto_exec, #can_add_observer?, #can_handle_drag_observation_request?, #can_handle_drop_observation_request?, #can_handle_observation_request?, create, #dispose, #ensure_drag_source_proxy, #ensure_drop_target_proxy, #extract_args, #finish_add_content!, flyweight_swt_widget_classes, #get_attribute, #handle_observation_request, #has_attribute?, #has_style?, #height, #method_missing, #post_add_content, #post_initialize_child, #print, #proxy_source_object, #remove_observer, #respond_to?, #set_attribute, #shell_proxy, 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, #width, #x, #y
Methods included from Custom::Drawable
#add_shape, #clear_shapes, #deregister_shape_painting, #drop_shapes, #expanded_shapes, #image_buffered_shapes, #paint_pixel_by_pixel, #setup_shape_painting, #shape_at_location, #shapes, #swt_drawable
Methods included from ProxyProperties
#get_attribute, #has_attribute?, #has_attribute_getter?, #has_attribute_setter?, #method_missing, #proxy_source_object, #respond_to?, #set_attribute
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(*args, swt_widget: nil) ⇒ ShellProxy
Instantiates ShellProxy with same arguments expected by SWT Shell if swt_widget keyword arg was passed, then it is assumed the shell has already been instantiated and the proxy wraps it instead of creating a new one.
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/shell_proxy.rb', line 45 def initialize(*args, swt_widget: nil) auto_exec do if @swt_widget = else if args.first.respond_to?(:swt_widget) && args.first..is_a?(Shell) @parent_proxy = args[0] args[0] = args[0]. end style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}.map(&:to_sym) fill_screen = nil if style_args.include?(:fill_screen) args.delete(:fill_screen) style_args.delete(:fill_screen) fill_screen = true end if style_args.any? style_arg_start_index = args.index(style_args.first) style_arg_last_index = args.index(style_args.last) args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args] end if args.first.nil? || (!args.first.is_a?(Display) && !args.first.is_a?(Shell)) @display = DisplayProxy.instance.swt_display args = [@display] + args end args = args.compact @swt_widget = Shell.new(*args) @swt_widget.set_data('proxy', self) @swt_widget.setLayout(FillLayout.new) @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN) # TODO make this an option not the default shell_swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display on_swt_show do if @filled_screen.nil? && fill_screen # only the first time @swt_widget.set_size(@display.bounds.width, @display.bounds.height) end Thread.new do sleep(0.25) shell_swt_display.async_exec do @swt_widget.setActive unless @swt_widget.isDisposed end end end end do @last_shell_closing = true if @display.shells.count == 1 && @display.shells.first == @swt_widget clear_shapes unless @last_shell_closing end @display ||= @swt_widget.getDisplay end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#last_shell_closing ⇒ Object (readonly) Also known as: last_shell_closing?
Returns the value of attribute last_shell_closing.
38 39 40 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 38 def last_shell_closing @last_shell_closing end |
#opened_before ⇒ Object (readonly) Also known as: opened_before?
Returns the value of attribute opened_before.
38 39 40 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 38 def opened_before @opened_before end |
Instance Method Details
#add_observer(observer, property_name) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 215 def add_observer(observer, property_name) case property_name.to_s when 'visible?' #TODO see if you must handle non-? version and/or move elsewhere visibility_notifier = proc do observer.call(visible?) end on_swt_show(&visibility_notifier) on_swt_hide(&visibility_notifier) on_swt_close(&visibility_notifier) else super end end |
#center_within_display ⇒ Object Also known as: center_in_display
Centers shell within monitor it is in
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 98 def center_within_display auto_exec do primary_monitor = @display.getPrimaryMonitor() monitor_bounds = primary_monitor.getBounds() shell_bounds = @swt_widget.getBounds() location_x = monitor_bounds.x + (monitor_bounds.width - shell_bounds.width) / 2 location_y = monitor_bounds.y + (monitor_bounds.height - shell_bounds.height) / 2 @swt_widget.setLocation(location_x, location_y) end end |
#close ⇒ Object
Closes shell. Automatically checks if widget is disposed to avoid crashing.
151 152 153 154 155 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 151 def close auto_exec do @swt_widget.close unless @swt_widget.isDisposed end end |
#content(&block) ⇒ Object
193 194 195 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 193 def content(&block) Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::ShellExpression.new, 'shell', &block) end |
#disposed? ⇒ Boolean Also known as: disposed
138 139 140 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 138 def disposed? .isDisposed end |
#hide ⇒ Object
Hides shell. Automatically checks if widget is disposed to avoid crashing.
144 145 146 147 148 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 144 def hide auto_exec do @swt_widget.setVisible(false) unless @swt_widget.isDisposed end end |
#include_focus_control? ⇒ Boolean
169 170 171 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 169 def include_focus_control? DisplayProxy.instance.focus_control&.shell == end |
#nested? ⇒ Boolean Also known as: nested
131 132 133 134 135 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 131 def nested? auto_exec do !&.parent.nil? end end |
#open ⇒ Object Also known as: show
Opens shell and starts SWT’s UI thread event loop
111 112 113 114 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 111 def open open_only start_event_loop unless nested? end |
#open_only ⇒ Object
Opens without starting the event loop.
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 118 def open_only auto_exec do if @opened_before @swt_widget.setVisible(true) else @opened_before = true @swt_widget.pack center_within_display @swt_widget.open end end end |
#pack_same_size ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 173 def pack_same_size auto_exec do bounds = @swt_widget.getBounds if OS.mac? @swt_widget.pack @swt_widget.setBounds(bounds) elsif OS.windows? || OS::Underlying.windows? minimum_size = @swt_widget.getMinimumSize @swt_widget.setMinimumSize(bounds.width, bounds.height) listener = on_control_resized { @swt_widget.setBounds(bounds) } @swt_widget.layout(true, true) @swt_widget.removeControlListener(listener.swt_listener) @swt_widget.setMinimumSize(minimum_size) elsif OS.linux? @swt_widget.layout(true, true) @swt_widget.setBounds(bounds) end end end |
#start_event_loop ⇒ Object
(happens as part of ‘#open`) Starts SWT Event Loop.
You may learn more about the SWT Event Loop here: help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Display.html This method is not needed except in rare circumstances where there is a need to start the SWT Event Loop before opening the shell.
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 203 def start_event_loop auto_exec do until @swt_widget.isDisposed begin @display.sleep unless @display.readAndDispatch rescue => e Glimmer::Config.logger.info {e.} end end end end |
#visible=(visibility) ⇒ Object
Setting to true opens/shows shell. Setting to false hides the shell.
165 166 167 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 165 def visible=(visibility) visibility ? show : hide end |
#visible? ⇒ Boolean Also known as: visible
157 158 159 160 161 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 157 def visible? auto_exec do @swt_widget.isDisposed ? false : @swt_widget.isVisible end end |