glimmer-dsl-swt 4.18.4.8 → 4.18.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/README.md +24 -11
  4. data/VERSION +1 -1
  5. data/bin/glimmer +3 -3
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +353 -145
  8. data/docs/reference/GLIMMER_SAMPLES.md +207 -41
  9. data/glimmer-dsl-swt.gemspec +33 -15
  10. data/lib/ext/glimmer/config.rb +3 -7
  11. data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
  12. data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
  13. data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
  14. data/lib/glimmer/data_binding/widget_binding.rb +13 -15
  15. data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
  16. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
  17. data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
  18. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
  19. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
  20. data/lib/glimmer/dsl/swt/data_binding_expression.rb +2 -2
  21. data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
  22. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  23. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  24. data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
  25. data/lib/glimmer/dsl/swt/image_expression.rb +18 -3
  26. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
  27. data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
  28. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +9 -5
  29. data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
  30. data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
  31. data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
  32. data/lib/glimmer/launcher.rb +3 -0
  33. data/lib/glimmer/rake_task/scaffold.rb +3 -0
  34. data/lib/glimmer/swt/color_proxy.rb +1 -1
  35. data/lib/glimmer/swt/custom/code_text.rb +33 -11
  36. data/lib/glimmer/swt/custom/drawable.rb +50 -2
  37. data/lib/glimmer/swt/custom/radio_group.rb +2 -1
  38. data/lib/glimmer/swt/custom/shape.rb +166 -34
  39. data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/arc.rb} +15 -20
  40. data/lib/glimmer/swt/custom/shape/focus.rb +43 -0
  41. data/lib/glimmer/swt/custom/shape/image.rb +86 -0
  42. data/lib/glimmer/swt/custom/shape/line.rb +58 -0
  43. data/lib/glimmer/swt/custom/shape/oval.rb +43 -0
  44. data/lib/glimmer/swt/custom/shape/point.rb +52 -0
  45. data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
  46. data/lib/glimmer/swt/custom/shape/polyline.rb +73 -0
  47. data/lib/glimmer/swt/custom/shape/rectangle.rb +87 -0
  48. data/lib/glimmer/swt/custom/shape/text.rb +73 -0
  49. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  50. data/lib/glimmer/swt/dialog_proxy.rb +92 -0
  51. data/lib/glimmer/swt/display_proxy.rb +62 -2
  52. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  53. data/lib/glimmer/swt/font_proxy.rb +13 -7
  54. data/lib/glimmer/swt/image_proxy.rb +16 -5
  55. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  56. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  57. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  58. data/lib/glimmer/swt/message_box_proxy.rb +21 -7
  59. data/lib/glimmer/swt/properties.rb +3 -0
  60. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  61. data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -7
  62. data/lib/glimmer/swt/shell_proxy.rb +96 -80
  63. data/lib/glimmer/swt/swt_proxy.rb +17 -0
  64. data/lib/glimmer/swt/tab_item_proxy.rb +6 -3
  65. data/lib/glimmer/swt/table_proxy.rb +32 -11
  66. data/lib/glimmer/swt/transform_proxy.rb +26 -38
  67. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  68. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  69. data/lib/glimmer/swt/widget_proxy.rb +194 -137
  70. data/lib/glimmer/ui.rb +5 -0
  71. data/lib/glimmer/ui/custom_shell.rb +13 -7
  72. data/lib/glimmer/ui/custom_widget.rb +4 -5
  73. data/samples/elaborate/contact_manager.rb +7 -7
  74. data/samples/elaborate/login.rb +25 -21
  75. data/samples/elaborate/mandelbrot_fractal.rb +346 -39
  76. data/samples/elaborate/meta_sample.rb +1 -1
  77. data/samples/elaborate/tetris.rb +1 -0
  78. data/samples/elaborate/tic_tac_toe.rb +16 -14
  79. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  80. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  81. data/samples/hello/hello_button.rb +7 -7
  82. data/samples/hello/hello_canvas.rb +145 -41
  83. data/samples/hello/hello_checkbox.rb +16 -14
  84. data/samples/hello/hello_checkbox_group.rb +11 -9
  85. data/samples/hello/hello_color_dialog.rb +66 -0
  86. data/samples/hello/hello_combo.rb +14 -12
  87. data/samples/hello/hello_computed.rb +7 -7
  88. data/samples/hello/hello_cursor.rb +58 -0
  89. data/samples/hello/hello_custom_shell.rb +17 -21
  90. data/samples/hello/hello_custom_widget.rb +4 -6
  91. data/samples/hello/hello_date_time.rb +14 -12
  92. data/samples/hello/hello_directory_dialog.rb +7 -7
  93. data/samples/hello/hello_expand_bar.rb +8 -8
  94. data/samples/hello/hello_file_dialog.rb +7 -7
  95. data/samples/hello/hello_font_dialog.rb +82 -0
  96. data/samples/hello/hello_group.rb +18 -16
  97. data/samples/hello/hello_list_multi_selection.rb +13 -11
  98. data/samples/hello/hello_list_single_selection.rb +13 -11
  99. data/samples/hello/hello_progress_bar.rb +125 -0
  100. data/samples/hello/hello_radio.rb +18 -16
  101. data/samples/hello/hello_radio_group.rb +14 -12
  102. data/samples/hello/hello_spinner.rb +7 -7
  103. data/samples/hello/hello_tab.rb +5 -5
  104. data/samples/hello/hello_table.rb +10 -5
  105. data/samples/hello/hello_tree.rb +485 -0
  106. metadata +30 -23
  107. data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
  108. data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -34,13 +34,24 @@ module Glimmer
34
34
  include Properties
35
35
 
36
36
  class << self
37
- def create(*args)
37
+ include_package 'org.eclipse.swt.graphics'
38
+
39
+ def create(*args, &content)
38
40
  if args.size == 1 && args.first.is_a?(ImageProxy)
39
41
  args.first
40
42
  else
41
- new(*args)
43
+ new(*args, &content)
42
44
  end
43
45
  end
46
+
47
+ def create_pixel_by_pixel(*args, &each_pixel_color)
48
+ image_proxy = create(*args)
49
+ options = args.last.is_a?(Hash) ? args.pop : {}
50
+ height = args[-1]
51
+ width = args[-2]
52
+ image_proxy.paint_pixel_by_pixel(width, height, &each_pixel_color)
53
+ image_proxy
54
+ end
44
55
  end
45
56
 
46
57
  include_package 'org.eclipse.swt.widgets'
@@ -88,7 +99,7 @@ module Glimmer
88
99
  # TODO consider adding a get_data/set_data method to conform with other SWT widgets
89
100
  @swt_image.singleton_class.define_method(:dispose) do
90
101
  proxy.clear_shapes
91
- super
102
+ super()
92
103
  end
93
104
  post_add_content if content.nil?
94
105
  end
@@ -97,7 +108,7 @@ module Glimmer
97
108
  if shapes.any?
98
109
  setup_shape_painting
99
110
  end
100
- if @parent.respond_to?('image=')
111
+ if @parent.respond_to?('image=') && !@parent.is_disposed
101
112
  @parent&.image = swt_image
102
113
  end
103
114
  end
@@ -121,7 +132,7 @@ module Glimmer
121
132
  end
122
133
 
123
134
  def scale_to(width, height)
124
- return if @image_data.width == width && @image_data.height == height
135
+ return self if @image_data.width == width && @image_data.height == height
125
136
  scaled_image_data = @original_image_data.scaledTo(width, height)
126
137
  device = swt_image.device
127
138
  swt_image.dispose
@@ -47,15 +47,17 @@ module Glimmer
47
47
 
48
48
  # Inititalizes with owning widget proxy and layout data arguments
49
49
  def initialize(widget_proxy, args)
50
- @widget_proxy = widget_proxy
51
- args = SWTProxy.constantify_args(args)
52
- begin
53
- @swt_layout_data = swt_layout_data_class.new(*args)
54
- rescue => e
55
- Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
56
- @swt_layout_data = args.first if args.count == 1
50
+ DisplayProxy.instance.auto_exec do
51
+ @widget_proxy = widget_proxy
52
+ args = SWTProxy.constantify_args(args)
53
+ begin
54
+ @swt_layout_data = swt_layout_data_class.new(*args)
55
+ rescue => e
56
+ Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
57
+ @swt_layout_data = args.first if args.count == 1
58
+ end
59
+ @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
57
60
  end
58
- @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
59
61
  end
60
62
 
61
63
  # This figures out the right SWT layout data class name
@@ -72,9 +74,11 @@ module Glimmer
72
74
  # - org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
73
75
  #
74
76
  def swt_layout_data_class
75
- parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
76
- layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
77
- eval(layout_data_class_name)
77
+ DisplayProxy.instance.auto_exec do
78
+ parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
79
+ layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
80
+ eval(layout_data_class_name)
81
+ end
78
82
  end
79
83
 
80
84
  def has_attribute?(attribute_name, *args)
@@ -82,10 +86,12 @@ module Glimmer
82
86
  end
83
87
 
84
88
  def set_attribute(attribute_name, *args)
85
- args = SWTProxy.constantify_args(args)
86
- if args.first != @swt_layout_data.send(attribute_getter(attribute_name))
87
- @swt_layout_data.send(attribute_setter(attribute_name), *args)
88
- @widget_proxy.swt_widget.getShell.pack
89
+ DisplayProxy.instance.auto_exec do
90
+ args = SWTProxy.constantify_args(args)
91
+ if args.first != @swt_layout_data.send(attribute_getter(attribute_name))
92
+ @swt_layout_data.send(attribute_setter(attribute_name), *args)
93
+ @widget_proxy.swt_widget.getShell.pack
94
+ end
89
95
  end
90
96
  end
91
97
 
@@ -62,19 +62,21 @@ module Glimmer
62
62
  end
63
63
 
64
64
  def initialize(underscored_layout_name, widget_proxy, args)
65
- @underscored_layout_name = underscored_layout_name
66
- @widget_proxy = widget_proxy
67
- args = SWTProxy.constantify_args(args)
68
- @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
69
- @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth)
70
- @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight)
71
- @swt_layout.marginTop = 0 if @swt_layout.respond_to?(:marginTop)
72
- @swt_layout.marginRight = 0 if @swt_layout.respond_to?(:marginRight)
73
- @swt_layout.marginBottom = 0 if @swt_layout.respond_to?(:marginBottom)
74
- @swt_layout.marginLeft = 0 if @swt_layout.respond_to?(:marginLeft)
75
- old_layout = @widget_proxy.swt_widget.getLayout
76
- @widget_proxy.swt_widget.setLayout(@swt_layout)
77
- @widget_proxy.swt_widget.layout if old_layout
65
+ DisplayProxy.instance.auto_exec do
66
+ @underscored_layout_name = underscored_layout_name
67
+ @widget_proxy = widget_proxy
68
+ args = SWTProxy.constantify_args(args)
69
+ @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
70
+ @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth)
71
+ @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight)
72
+ @swt_layout.marginTop = 0 if @swt_layout.respond_to?(:marginTop)
73
+ @swt_layout.marginRight = 0 if @swt_layout.respond_to?(:marginRight)
74
+ @swt_layout.marginBottom = 0 if @swt_layout.respond_to?(:marginBottom)
75
+ @swt_layout.marginLeft = 0 if @swt_layout.respond_to?(:marginLeft)
76
+ old_layout = @widget_proxy.swt_widget.getLayout
77
+ @widget_proxy.swt_widget.setLayout(@swt_layout)
78
+ @widget_proxy.swt_widget.layout if old_layout
79
+ end
78
80
  end
79
81
 
80
82
  def has_attribute?(attribute_name, *args)
@@ -82,11 +84,13 @@ module Glimmer
82
84
  end
83
85
 
84
86
  def set_attribute(attribute_name, *args)
85
- apply_property_type_converters(attribute_name, args)
86
- if args.first != @swt_layout.send(attribute_getter(attribute_name))
87
+ DisplayProxy.instance.auto_exec do
88
+ apply_property_type_converters(attribute_name, args)
89
+ if args.first != @swt_layout.send(attribute_getter(attribute_name))
87
90
  @swt_layout.send(attribute_setter(attribute_name), *args)
88
91
  @widget_proxy.swt_widget.layout
89
92
  @widget_proxy.swt_widget.getShell.layout
93
+ end
90
94
  end
91
95
  end
92
96
 
@@ -68,9 +68,9 @@ module Glimmer
68
68
  end
69
69
 
70
70
  if styles.include?(:bar)
71
- parent.swt_widget.setMenuBar(swt_widget)
71
+ DisplayProxy.instance.auto_exec { parent.swt_widget.setMenuBar(swt_widget) }
72
72
  elsif styles.include?(:pop_up)
73
- parent.swt_widget.setMenu(swt_widget)
73
+ DisplayProxy.instance.auto_exec { parent.swt_widget.setMenu(swt_widget) }
74
74
  end
75
75
  end
76
76
 
@@ -35,6 +35,7 @@ module Glimmer
35
35
  attr_reader :swt_widget
36
36
 
37
37
  def initialize(parent, style)
38
+ # TODO consider consolidating with DialogProxy if it makes sense
38
39
  if parent.nil?
39
40
  @temporary_parent = parent = Glimmer::SWT::ShellProxy.new.swt_widget
40
41
  end
@@ -42,8 +43,10 @@ module Glimmer
42
43
  end
43
44
 
44
45
  def open
45
- @swt_widget.open.tap do |result|
46
- @temporary_parent&.dispose
46
+ DisplayProxy.instance.auto_exec do
47
+ @swt_widget.open.tap do |result|
48
+ @temporary_parent&.dispose
49
+ end
47
50
  end
48
51
  end
49
52
 
@@ -66,18 +69,29 @@ module Glimmer
66
69
  end
67
70
 
68
71
  def set_attribute(attribute_name, *args)
69
- @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
72
+ DisplayProxy.instance.auto_exec do
73
+ @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
74
+ end
70
75
  end
71
76
 
72
77
  def get_attribute(attribute_name)
73
- @swt_widget.send(attribute_getter(attribute_name))
78
+ DisplayProxy.instance.auto_exec do
79
+ @swt_widget.send(attribute_getter(attribute_name))
80
+ end
74
81
  end
75
82
 
76
83
  def method_missing(method, *args, &block)
77
- swt_widget.send(method, *args, &block)
84
+ DisplayProxy.instance.auto_exec do
85
+ swt_widget.send(method, *args, &block)
86
+ end
78
87
  rescue => e
79
- Glimmer::Config.logger.debug {"Neither MessageBoxProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
80
- super
88
+ begin
89
+ super
90
+ rescue Exception => inner_error
91
+ Glimmer::Config.logger.error {"Neither MessageBoxProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
92
+ Glimmer::Config.logger.error {e.full_message}
93
+ raise inner_error
94
+ end
81
95
  end
82
96
 
83
97
  def respond_to?(method, *args, &block)
@@ -69,6 +69,9 @@ module Glimmer
69
69
  Glimmer::SWT::Properties.normalized_attribute(attribute_name)
70
70
  end
71
71
  alias ruby_attribute_getter normalized_attribute
72
+
72
73
  end
74
+
73
75
  end
76
+
74
77
  end
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ # Provides a default implementation for proxy properties, that is
27
+ # properties that come from a proxy object source such as swt_widget
28
+ # having Java camelcase format
29
+ module ProxyProperties
30
+ include Properties
31
+
32
+ # Subclasses must override to privde a proxy source if they want to take advantage of
33
+ # default implementation of attribute setters/getters
34
+ # It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
35
+ def proxy_source_object
36
+ if respond_to?(:swt_widget)
37
+ swt_widget
38
+ elsif respond_to?(:swt_display)
39
+ swt_display
40
+ elsif respond_to?(:swt_image)
41
+ swt_image
42
+ elsif respond_to?(:swt_dialog)
43
+ swt_dialog
44
+ elsif respond_to?(:swt_transform)
45
+ swt_transform
46
+ end
47
+ end
48
+
49
+ def has_attribute_getter?(attribute_getter_name, *args)
50
+ attribute_getter_name = attribute_getter_name.to_s.underscore
51
+ return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
52
+ args.empty? && proxy_source_object&.respond_to?(attribute_getter_name)
53
+ end
54
+
55
+ def has_attribute_setter?(attribute_setter_name, *args)
56
+ attribute_setter_name = attribute_setter_name.to_s
57
+ underscored_attribute_setter_name = attribute_setter_name.underscore
58
+ return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
59
+ attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
60
+ has_attribute?(attribute_name, *args)
61
+ end
62
+
63
+ def has_attribute?(attribute_name, *args)
64
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
65
+ proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) ||
66
+ respond_to?(ruby_attribute_setter(attribute_name), args)
67
+ end
68
+ end
69
+
70
+ def set_attribute(attribute_name, *args)
71
+ swt_widget_operation = false
72
+ result = nil
73
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
74
+ result = if proxy_source_object&.respond_to?(attribute_setter(attribute_name))
75
+ swt_widget_operation = true
76
+ proxy_source_object&.send(attribute_setter(attribute_name), *args) unless proxy_source_object&.send(attribute_getter(attribute_name)) == args.first
77
+ elsif proxy_source_object&.respond_to?(ruby_attribute_setter(attribute_name))
78
+ swt_widget_operation = true
79
+ proxy_source_object&.send(ruby_attribute_setter(attribute_name), args)
80
+ end
81
+ end
82
+ unless swt_widget_operation
83
+ result = send(ruby_attribute_setter(attribute_name), args)
84
+ end
85
+ result
86
+ end
87
+
88
+ def get_attribute(attribute_name)
89
+ swt_widget_operation = false
90
+ result = nil
91
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
92
+ result = if proxy_source_object&.respond_to?(attribute_getter(attribute_name))
93
+ swt_widget_operation = true
94
+ proxy_source_object&.send(attribute_getter(attribute_name))
95
+ elsif proxy_source_object&.respond_to?(ruby_attribute_getter(attribute_name))
96
+ swt_widget_operation = true
97
+ proxy_source_object&.send(ruby_attribute_getter(attribute_name))
98
+ elsif proxy_source_object&.respond_to?(attribute_name)
99
+ swt_widget_operation = true
100
+ proxy_source_object&.send(attribute_name)
101
+ end
102
+ end
103
+ unless swt_widget_operation
104
+ result = if respond_to?(ruby_attribute_getter(attribute_name))
105
+ send(ruby_attribute_getter(attribute_name))
106
+ else
107
+ send(attribute_name)
108
+ end
109
+ end
110
+ result
111
+ end
112
+
113
+ def method_missing(method, *args, &block)
114
+ if has_attribute_setter?(method, *args)
115
+ set_attribute(method, *args)
116
+ elsif has_attribute_getter?(method, *args)
117
+ get_attribute(method, *args)
118
+ else
119
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
120
+ proxy_source_object&.send(method, *args, &block)
121
+ end
122
+ end
123
+ rescue => e
124
+ begin
125
+ super
126
+ rescue Exception => inner_error
127
+ Glimmer::Config.logger.error { "Neither self.class.name nor #{proxy_source_object&.class.name} can handle the method ##{method}" }
128
+ Glimmer::Config.logger.error { e.full_message }
129
+ raise inner_error
130
+ end
131
+ end
132
+
133
+ def respond_to?(method, *args, &block)
134
+ result = super
135
+ return true if result
136
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
137
+ proxy_source_object&.respond_to?(method, *args, &block)
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -24,14 +24,27 @@ require 'glimmer/swt/swt_proxy'
24
24
 
25
25
  module Glimmer
26
26
  module SWT
27
- class ScrolledCompositeProxy < Glimmer::SWT::WidgetProxy
27
+ class ScrolledCompositeProxy < Glimmer::SWT::WidgetProxy
28
28
  def post_initialize_child(child)
29
- swt_widget.content = child.swt_widget
29
+ auto_exec do
30
+ swt_widget.content = child.swt_widget
31
+ end
32
+ # TODO consider triggering this method in the future upon resizing of content with a listener (on_control_resized)
33
+ # child.on_control_resized do
34
+ # swt_widget.set_min_size(swt_widget.computeSize(child.bounds.width, child.bounds.height))
35
+ # end
30
36
  end
31
37
 
32
38
  def post_add_content
33
- swt_widget.set_min_size(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]))
34
- end
39
+ calculate_min_size
40
+ end
41
+
42
+ def calculate_min_size
43
+ auto_exec do
44
+ swt_widget.set_min_size(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]))
45
+ end
46
+ end
47
+ alias recalculate_min_size calculate_min_size
35
48
  end
36
49
  end
37
50
  end
@@ -42,60 +42,64 @@ module Glimmer
42
42
  # if swt_widget keyword arg was passed, then it is assumed the shell has already been instantiated
43
43
  # and the proxy wraps it instead of creating a new one.
44
44
  def initialize(*args, swt_widget: nil)
45
- if swt_widget
46
- @swt_widget = swt_widget
47
- else
48
- if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
49
- @parent_proxy = args[0]
50
- args[0] = args[0].swt_widget
51
- end
52
- style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}.map(&:to_sym)
53
- fill_screen = nil
54
- if style_args.include?(:fill_screen)
55
- args.delete(:fill_screen)
56
- style_args.delete(:fill_screen)
57
- fill_screen = true
58
- end
59
- if style_args.any?
60
- style_arg_start_index = args.index(style_args.first)
61
- style_arg_last_index = args.index(style_args.last)
62
- args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
63
- end
64
- if args.first.nil? || (!args.first.is_a?(Display) && !args.first.is_a?(Shell))
65
- @display = DisplayProxy.instance.swt_display
66
- args = [@display] + args
67
- end
68
- args = args.compact
69
- @swt_widget = Shell.new(*args)
70
- @swt_widget.set_data('proxy', self)
71
- @swt_widget.setLayout(FillLayout.new)
72
- @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
73
- # TODO make this an option not the default
74
- shell_swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display
75
- on_swt_show do
76
- @swt_widget.set_size(@display.bounds.width, @display.bounds.height) if fill_screen
77
- Thread.new do
78
- sleep(0.25)
79
- shell_swt_display.async_exec do
80
- @swt_widget.setActive unless @swt_widget.isDisposed
45
+ auto_exec do
46
+ if swt_widget
47
+ @swt_widget = swt_widget
48
+ else
49
+ if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
50
+ @parent_proxy = args[0]
51
+ args[0] = args[0].swt_widget
52
+ end
53
+ style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}.map(&:to_sym)
54
+ fill_screen = nil
55
+ if style_args.include?(:fill_screen)
56
+ args.delete(:fill_screen)
57
+ style_args.delete(:fill_screen)
58
+ fill_screen = true
59
+ end
60
+ if style_args.any?
61
+ style_arg_start_index = args.index(style_args.first)
62
+ style_arg_last_index = args.index(style_args.last)
63
+ args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
64
+ end
65
+ if args.first.nil? || (!args.first.is_a?(Display) && !args.first.is_a?(Shell))
66
+ @display = DisplayProxy.instance.swt_display
67
+ args = [@display] + args
68
+ end
69
+ args = args.compact
70
+ @swt_widget = Shell.new(*args)
71
+ @swt_widget.set_data('proxy', self)
72
+ @swt_widget.setLayout(FillLayout.new)
73
+ @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
74
+ # TODO make this an option not the default
75
+ shell_swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display
76
+ on_swt_show do
77
+ @swt_widget.set_size(@display.bounds.width, @display.bounds.height) if fill_screen
78
+ Thread.new do
79
+ sleep(0.25)
80
+ shell_swt_display.async_exec do
81
+ @swt_widget.setActive unless @swt_widget.isDisposed
82
+ end
81
83
  end
82
84
  end
83
85
  end
86
+ on_widget_disposed {
87
+ clear_shapes
88
+ }
89
+ @display ||= @swt_widget.getDisplay
84
90
  end
85
- on_widget_disposed {
86
- clear_shapes
87
- }
88
- @display ||= @swt_widget.getDisplay
89
91
  end
90
92
 
91
93
  # Centers shell within monitor it is in
92
94
  def center_within_display
93
- primary_monitor = @display.getPrimaryMonitor()
94
- monitor_bounds = primary_monitor.getBounds()
95
- shell_bounds = @swt_widget.getBounds()
96
- location_x = monitor_bounds.x + (monitor_bounds.width - shell_bounds.width) / 2
97
- location_y = monitor_bounds.y + (monitor_bounds.height - shell_bounds.height) / 2
98
- @swt_widget.setLocation(location_x, location_y)
95
+ auto_exec do
96
+ primary_monitor = @display.getPrimaryMonitor()
97
+ monitor_bounds = primary_monitor.getBounds()
98
+ shell_bounds = @swt_widget.getBounds()
99
+ location_x = monitor_bounds.x + (monitor_bounds.width - shell_bounds.width) / 2
100
+ location_y = monitor_bounds.y + (monitor_bounds.height - shell_bounds.height) / 2
101
+ @swt_widget.setLocation(location_x, location_y)
102
+ end
99
103
  end
100
104
 
101
105
  # Opens shell and starts SWT's UI thread event loop
@@ -107,18 +111,22 @@ module Glimmer
107
111
 
108
112
  # Opens without starting the event loop.
109
113
  def open_only
110
- if @opened_before
111
- @swt_widget.setVisible(true)
112
- else
113
- @opened_before = true
114
- @swt_widget.pack
115
- center_within_display
116
- @swt_widget.open
114
+ auto_exec do
115
+ if @opened_before
116
+ @swt_widget.setVisible(true)
117
+ else
118
+ @opened_before = true
119
+ @swt_widget.pack
120
+ center_within_display
121
+ @swt_widget.open
122
+ end
117
123
  end
118
124
  end
119
125
 
120
126
  def nested?
121
- !swt_widget&.parent.nil?
127
+ auto_exec do
128
+ !swt_widget&.parent.nil?
129
+ end
122
130
  end
123
131
  alias nested nested?
124
132
 
@@ -129,16 +137,22 @@ module Glimmer
129
137
 
130
138
  # Hides shell. Automatically checks if widget is disposed to avoid crashing.
131
139
  def hide
132
- @swt_widget.setVisible(false) unless @swt_widget.isDisposed
140
+ auto_exec do
141
+ @swt_widget.setVisible(false) unless @swt_widget.isDisposed
142
+ end
133
143
  end
134
144
 
135
145
  # Closes shell. Automatically checks if widget is disposed to avoid crashing.
136
146
  def close
137
- @swt_widget.close unless @swt_widget.isDisposed
147
+ auto_exec do
148
+ @swt_widget.close unless @swt_widget.isDisposed
149
+ end
138
150
  end
139
151
 
140
152
  def visible?
141
- @swt_widget.isDisposed ? false : @swt_widget.isVisible
153
+ auto_exec do
154
+ @swt_widget.isDisposed ? false : @swt_widget.isVisible
155
+ end
142
156
  end
143
157
  alias visible visible?
144
158
 
@@ -151,25 +165,23 @@ module Glimmer
151
165
  DisplayProxy.instance.focus_control&.shell == swt_widget
152
166
  end
153
167
 
154
- def pack
155
- @swt_widget.pack
156
- end
157
-
158
168
  def pack_same_size
159
- bounds = @swt_widget.getBounds
160
- if OS.mac?
161
- @swt_widget.pack
162
- @swt_widget.setBounds(bounds)
163
- elsif OS.windows? || OS::Underlying.windows?
164
- minimum_size = @swt_widget.getMinimumSize
165
- @swt_widget.setMinimumSize(bounds.width, bounds.height)
166
- listener = on_control_resized { @swt_widget.setBounds(bounds) }
167
- @swt_widget.layout(true, true)
168
- @swt_widget.removeControlListener(listener.swt_listener)
169
- @swt_widget.setMinimumSize(minimum_size)
170
- elsif OS.linux?
171
- @swt_widget.layout(true, true)
172
- @swt_widget.setBounds(bounds)
169
+ auto_exec do
170
+ bounds = @swt_widget.getBounds
171
+ if OS.mac?
172
+ @swt_widget.pack
173
+ @swt_widget.setBounds(bounds)
174
+ elsif OS.windows? || OS::Underlying.windows?
175
+ minimum_size = @swt_widget.getMinimumSize
176
+ @swt_widget.setMinimumSize(bounds.width, bounds.height)
177
+ listener = on_control_resized { @swt_widget.setBounds(bounds) }
178
+ @swt_widget.layout(true, true)
179
+ @swt_widget.removeControlListener(listener.swt_listener)
180
+ @swt_widget.setMinimumSize(minimum_size)
181
+ elsif OS.linux?
182
+ @swt_widget.layout(true, true)
183
+ @swt_widget.setBounds(bounds)
184
+ end
173
185
  end
174
186
  end
175
187
 
@@ -184,11 +196,13 @@ module Glimmer
184
196
  # https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Display.html
185
197
  # This method is not needed except in rare circumstances where there is a need to start the SWT Event Loop before opening the shell.
186
198
  def start_event_loop
187
- until @swt_widget.isDisposed
188
- begin
189
- @display.sleep unless @display.readAndDispatch
190
- rescue => e
191
- Glimmer::Config.logger.info {e.full_message}
199
+ auto_exec do
200
+ until @swt_widget.isDisposed
201
+ begin
202
+ @display.sleep unless @display.readAndDispatch
203
+ rescue => e
204
+ Glimmer::Config.logger.info {e.full_message}
205
+ end
192
206
  end
193
207
  end
194
208
  end
@@ -209,6 +223,8 @@ module Glimmer
209
223
 
210
224
  end
211
225
 
226
+ WindowProxy = ShellProxy
227
+
212
228
  end
213
229
 
214
230
  end