glimmer-dsl-swt 4.17.4.1 → 4.17.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -3
  3. data/README.md +267 -107
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +24 -5
  6. data/lib/glimmer/data_binding/tree_items_binding.rb +20 -2
  7. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -0
  8. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +2 -0
  9. data/lib/glimmer/dsl/swt/dialog_expression.rb +1 -0
  10. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -0
  11. data/lib/glimmer/dsl/swt/dsl.rb +2 -0
  12. data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -0
  13. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -0
  14. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +61 -0
  15. data/lib/glimmer/dsl/swt/shell_expression.rb +4 -4
  16. data/lib/glimmer/dsl/swt/widget_expression.rb +9 -8
  17. data/lib/glimmer/swt/custom/checkbox_group.rb +160 -0
  18. data/lib/glimmer/swt/custom/code_text.rb +25 -18
  19. data/lib/glimmer/swt/custom/radio_group.rb +155 -0
  20. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -0
  21. data/lib/glimmer/swt/expand_item_proxy.rb +97 -0
  22. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -0
  23. data/lib/glimmer/swt/image_proxy.rb +5 -0
  24. data/lib/glimmer/swt/menu_proxy.rb +5 -5
  25. data/lib/glimmer/swt/sash_form_proxy.rb +1 -1
  26. data/lib/glimmer/swt/shell_proxy.rb +6 -6
  27. data/lib/glimmer/swt/styled_text_proxy.rb +43 -0
  28. data/lib/glimmer/swt/tab_item_proxy.rb +1 -1
  29. data/lib/glimmer/swt/widget_proxy.rb +86 -82
  30. data/lib/glimmer/ui/custom_shell.rb +4 -4
  31. data/lib/glimmer/ui/custom_widget.rb +3 -0
  32. data/samples/elaborate/meta_sample.rb +36 -31
  33. data/samples/hello/hello_checkbox.rb +85 -0
  34. data/samples/hello/hello_checkbox_group.rb +68 -0
  35. data/samples/hello/hello_combo.rb +12 -12
  36. data/samples/hello/hello_directory_dialog.rb +60 -0
  37. data/samples/hello/hello_expand_bar.rb +110 -0
  38. data/samples/hello/hello_file_dialog.rb +60 -0
  39. data/samples/hello/hello_list_multi_selection.rb +23 -23
  40. data/samples/hello/hello_list_single_selection.rb +18 -17
  41. data/samples/hello/hello_radio.rb +108 -0
  42. data/samples/hello/hello_radio_group.rb +84 -0
  43. data/samples/hello/hello_styled_text.rb +138 -0
  44. data/samples/hello/hello_world.rb +4 -4
  45. metadata +23 -4
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2007-2020 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/swt_proxy'
23
+ require 'glimmer/swt/widget_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+
26
+ module Glimmer
27
+ module SWT
28
+ # Proxy for org.eclipse.swt.widgets.DirectoryDialog
29
+ #
30
+ # Automatically uses the current shell if one is open.
31
+ # Otherwise, it instantiates a new shell parent
32
+ #
33
+ # Optionally takes a shell as an argument
34
+ #
35
+ # Follows the Proxy Design Pattern
36
+ class DirectoryDialogProxy < WidgetProxy
37
+ # TODO write rspec tests
38
+ include_package 'org.eclipse.swt.widgets'
39
+
40
+ def initialize(*args, swt_widget: nil)
41
+ if swt_widget
42
+ @swt_widget = swt_widget
43
+ else
44
+ style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
45
+ if style_args.any?
46
+ style_arg_start_index = args.index(style_args.first)
47
+ style_arg_last_index = args.index(style_args.last)
48
+ args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
49
+ end
50
+ if !args.first.is_a?(Shell)
51
+ current_shell = DisplayProxy.instance.swt_display.shells.first
52
+ args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
53
+ end
54
+ if args.first.is_a?(ShellProxy)
55
+ args[0] = args[0].swt_widget
56
+ end
57
+ parent = args[0]
58
+ @parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
59
+ @swt_widget = DirectoryDialog.new(*args)
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,97 @@
1
+ # Copyright (c) 2007-2020 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/widget_proxy'
23
+ require 'glimmer/swt/swt_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ # Proxy for org.eclipse.swt.widgets.ExpandItem
28
+ #
29
+ # Functions differently from other widget proxies.
30
+ #
31
+ # Glimmer instantiates an SWT Composite alongside the SWT ExpandItem
32
+ # and returns it for `#swt_widget` to allow adding widgets into it.
33
+ #
34
+ # In order to get the SWT ExpandItem object, one must call `#swt_expand_item`.
35
+ #
36
+ # Behind the scenes, this creates a tab item widget proxy separately from a composite that
37
+ # is set as the control of the tab item and `#swt_widget`.
38
+ #
39
+ # In order to retrieve the tab item widget proxy, one must call `#widget_proxy`
40
+ #
41
+ # Follows the Proxy Design Pattern
42
+ class ExpandItemProxy < WidgetProxy
43
+ ATTRIBUTES = ['text', 'height', 'expanded']
44
+
45
+ include_package 'org.eclipse.swt.widgets'
46
+
47
+ attr_reader :widget_proxy, :swt_expand_item
48
+
49
+ def initialize(parent, style, &contents)
50
+ super("composite", parent, style, &contents)
51
+ layout = FillLayout.new(SWTProxy[:vertical])
52
+ layout.marginWidth = 0
53
+ layout.marginHeight = 0
54
+ layout.spacing = 0
55
+ swt_widget.layout = layout
56
+ @widget_proxy = SWT::WidgetProxy.new('expand_item', parent, style)
57
+ @swt_expand_item = @widget_proxy.swt_widget
58
+ @swt_expand_item.control = swt_widget
59
+ @swt_expand_item.expanded = true
60
+ end
61
+
62
+ def post_add_content
63
+ @swt_expand_item.setHeight(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]).y) unless @swt_expand_item.getHeight > 0
64
+ end
65
+
66
+ def has_attribute?(attribute_name, *args)
67
+ if ATTRIBUTES.include?(attribute_name.to_s)
68
+ true
69
+ else
70
+ super(attribute_name, *args)
71
+ end
72
+ end
73
+
74
+ def set_attribute(attribute_name, *args)
75
+ if ATTRIBUTES.include?(attribute_name.to_s)
76
+ @widget_proxy.set_attribute(attribute_name, *args)
77
+ else
78
+ super(attribute_name, *args)
79
+ end
80
+ end
81
+
82
+ def get_attribute(attribute_name)
83
+ if ATTRIBUTES.include?(attribute_name.to_s)
84
+ @widget_proxy.get_attribute(attribute_name)
85
+ else
86
+ super(attribute_name)
87
+ end
88
+ end
89
+
90
+ def dispose
91
+ swt_expand_item.setControl(nil)
92
+ swt_widget.dispose
93
+ swt_expand_item.dispose
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2007-2020 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/swt_proxy'
23
+ require 'glimmer/swt/widget_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+
26
+ module Glimmer
27
+ module SWT
28
+ # Proxy for org.eclipse.swt.widgets.FileDialog
29
+ #
30
+ # Automatically uses the current shell if one is open.
31
+ # Otherwise, it instantiates a new shell parent
32
+ #
33
+ # Optionally takes a shell as an argument
34
+ #
35
+ # Follows the Proxy Design Pattern
36
+ class FileDialogProxy < WidgetProxy
37
+ # TODO write rspec tests
38
+ # TODO consider refactoring and sharing code with DirectoryDialogProxy (and do the same with their expressions)
39
+ include_package 'org.eclipse.swt.widgets'
40
+
41
+ def initialize(*args, swt_widget: nil)
42
+ if swt_widget
43
+ @swt_widget = swt_widget
44
+ else
45
+ style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
46
+ if style_args.any?
47
+ style_arg_start_index = args.index(style_args.first)
48
+ style_arg_last_index = args.index(style_args.last)
49
+ args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
50
+ end
51
+ if !args.first.is_a?(Shell)
52
+ current_shell = DisplayProxy.instance.swt_display.shells.first
53
+ args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
54
+ end
55
+ if args.first.is_a?(ShellProxy)
56
+ args[0] = args[0].swt_widget
57
+ end
58
+ parent = args[0]
59
+ @parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
60
+ @swt_widget = FileDialog.new(*args)
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -58,6 +58,11 @@ module Glimmer
58
58
  elsif @file_path
59
59
  @image_data = ImageData.new(input_stream || @file_path)
60
60
  @swt_image = Image.new(DisplayProxy.instance.swt_display, @image_data)
61
+ width = options[:width]
62
+ height = options[:height]
63
+ height = (@image_data.height.to_f / @image_data.width.to_f)*width.to_f if !width.nil? && height.nil?
64
+ width = (@image_data.width.to_f / @image_data.height.to_f)*height.to_f if !height.nil? && width.nil?
65
+ scale_to(width, height) unless width.nil? || height.nil?
61
66
  else
62
67
  @swt_image = Image.new(*@args)
63
68
  @image_data = @swt_image.image_data
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 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
@@ -116,7 +116,7 @@ module Glimmer
116
116
  else
117
117
  menu_item_proxy.handle_observation_request(observation_request, &block)
118
118
  end
119
- end
119
+ end
120
120
  end
121
121
  end
122
- end
122
+ end
@@ -32,7 +32,7 @@ module Glimmer
32
32
  end
33
33
 
34
34
  def set_attribute(attribute_name, *args)
35
- if attribute_name.to_s == "weights"
35
+ if attribute_name.to_s == 'weights'
36
36
  @weights = args
37
37
  @weights = @weights.first if @weights.first.is_a?(Array)
38
38
  else
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 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
@@ -65,7 +65,7 @@ module Glimmer
65
65
  @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
66
66
  # TODO make this an option not the default
67
67
  on_swt_show do
68
- Thread.new do
68
+ Thread.new do
69
69
  sleep(0.25)
70
70
  async_exec do
71
71
  @swt_widget.setActive unless @swt_widget.isDisposed
@@ -130,7 +130,7 @@ module Glimmer
130
130
  @swt_widget.pack
131
131
  @swt_widget.removeControlListener(listener.swt_listener)
132
132
  @swt_widget.setMinimumSize(minimum_size)
133
- elsif OS.linux?
133
+ elsif OS.linux?
134
134
  @swt_widget.layout(true, true)
135
135
  @swt_widget.setBounds(bounds)
136
136
  end
@@ -171,4 +171,4 @@ module Glimmer
171
171
  end
172
172
  end
173
173
  end
174
- end
174
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2007-2020 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/widget_proxy'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ # Proxy for org.eclipse.swt.custom.StyledText
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class StyledTextProxy < WidgetProxy
30
+ def set_attribute(attribute_name, *args)
31
+ if attribute_name.to_s == 'selection'
32
+ if args.first
33
+ async_exec { @swt_widget.setCaretOffset(args.first.x) }
34
+ async_exec { @swt_widget.setSelection(args.first) }
35
+ end
36
+ else
37
+ super(attribute_name, *args)
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -47,7 +47,7 @@ module Glimmer
47
47
  super("composite", parent, style, &contents)
48
48
  @widget_proxy = SWT::WidgetProxy.new('tab_item', parent, style)
49
49
  @swt_tab_item = @widget_proxy.swt_widget
50
- @widget_proxy.swt_widget.control = self.swt_widget
50
+ @swt_tab_item.control = swt_widget
51
51
  end
52
52
 
53
53
  def has_attribute?(attribute_name, *args)
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 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
@@ -44,26 +44,29 @@ module Glimmer
44
44
  include Packages
45
45
 
46
46
  DEFAULT_STYLES = {
47
- "arrow" => [:arrow],
48
- "button" => [:push],
49
- "checkbox" => [:check],
50
- "check" => [:check],
51
- "drag_source" => [:drop_copy],
52
- "drop_target" => [:drop_copy],
53
- "list" => [:border, :v_scroll],
54
- "menu_item" => [:push],
55
- "radio" => [:radio],
56
- "scrolled_composite" => [:border, :h_scroll, :v_scroll],
57
- "spinner" => [:border],
58
- "styled_text" => [:border, :multi, :v_scroll, :h_scroll],
59
- "table" => [:virtual, :border, :full_selection],
60
- "text" => [:border],
61
- "toggle" => [:toggle],
62
- "tree" => [:virtual, :border, :h_scroll, :v_scroll],
47
+ 'arrow' => [:arrow],
48
+ 'button' => [:push],
49
+ 'checkbox' => [:check],
50
+ 'check' => [:check],
51
+ 'drag_source' => [:drop_copy],
52
+ 'drop_target' => [:drop_copy],
53
+ 'expand_bar' => [:v_scroll],
54
+ 'list' => [:border, :v_scroll],
55
+ 'menu_item' => [:push],
56
+ 'radio' => [:radio],
57
+ 'scrolled_composite' => [:border, :h_scroll, :v_scroll],
58
+ 'spinner' => [:border],
59
+ 'styled_text' => [:border, :multi, :v_scroll, :h_scroll],
60
+ 'table' => [:virtual, :border, :full_selection],
61
+ 'text' => [:border],
62
+ 'toggle' => [:toggle],
63
+ 'tool_bar' => [:push],
64
+ 'tool_item' => [:push],
65
+ 'tree' => [:virtual, :border, :h_scroll, :v_scroll],
63
66
  }
64
67
 
65
68
  DEFAULT_INITIALIZERS = {
66
- "composite" => lambda do |composite|
69
+ 'composite' => lambda do |composite|
67
70
  if composite.get_layout.nil?
68
71
  layout = GridLayout.new
69
72
  layout.marginWidth = 15
@@ -71,28 +74,28 @@ module Glimmer
71
74
  composite.layout = layout
72
75
  end
73
76
  end,
74
- "scrolled_composite" => lambda do |scrolled_composite|
77
+ 'scrolled_composite' => lambda do |scrolled_composite|
75
78
  scrolled_composite.expand_horizontal = true
76
79
  scrolled_composite.expand_vertical = true
77
80
  end,
78
- "table" => lambda do |table|
81
+ 'table' => lambda do |table|
79
82
  table.setHeaderVisible(true)
80
83
  table.setLinesVisible(true)
81
84
  end,
82
- "table_column" => lambda do |table_column|
85
+ 'table_column' => lambda do |table_column|
83
86
  table_column.setWidth(80)
84
87
  end,
85
- "group" => lambda do |group|
88
+ 'group' => lambda do |group|
86
89
  group.layout = GridLayout.new if group.get_layout.nil?
87
90
  end,
88
91
  }
89
92
 
90
93
  KEYWORD_ALIASES = {
91
- 'radio' => 'button',
94
+ 'arrow' => 'button',
92
95
  'checkbox' => 'button',
93
96
  'check' => 'button',
97
+ 'radio' => 'button',
94
98
  'toggle' => 'button',
95
- 'arrow' => 'button',
96
99
  }
97
100
 
98
101
  class << self
@@ -105,7 +108,7 @@ module Glimmer
105
108
  if init_args.empty?
106
109
  selected_widget_proxy_class.new(swt_widget: swt_widget)
107
110
  else
108
- selected_widget_proxy_class.new(*init_args)
111
+ selected_widget_proxy_class.new(*init_args)
109
112
  end
110
113
  end
111
114
 
@@ -116,11 +119,11 @@ module Glimmer
116
119
  Glimmer::SWT.const_get(class_name)
117
120
  rescue
118
121
  Glimmer::SWT::WidgetProxy
119
- end
122
+ end
120
123
  end
121
124
 
122
125
  def underscored_widget_name(swt_widget)
123
- swt_widget.class.name.split(/::|\./).last.underscore
126
+ swt_widget.class.name.split(/::|\./).last.underscore
124
127
  end
125
128
  end
126
129
 
@@ -128,7 +131,7 @@ module Glimmer
128
131
 
129
132
  # Initializes a new SWT Widget
130
133
  #
131
- # It is preferred to use `::create` method instead since it instantiates the
134
+ # It is preferred to use `::create` method instead since it instantiates the
132
135
  # right subclass per widget keyword
133
136
  #
134
137
  # keyword, parent, swt_widget_args (including styles)
@@ -149,7 +152,7 @@ module Glimmer
149
152
  @parent_proxy = parent.get_data('proxy') || parent_proxy_class.new(swt_widget: parent)
150
153
  end
151
154
  if @swt_widget&.get_data('proxy').nil?
152
- @swt_widget.set_data('proxy', self)
155
+ @swt_widget.set_data('proxy', self)
153
156
  DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
154
157
  @parent_proxy.post_initialize_child(self)
155
158
  end
@@ -216,7 +219,11 @@ module Glimmer
216
219
  def get_attribute(attribute_name)
217
220
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
218
221
  if widget_custom_attribute
219
- @swt_widget.send(widget_custom_attribute[:getter][:name])
222
+ if widget_custom_attribute[:getter][:invoker]
223
+ widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
224
+ else
225
+ @swt_widget.send(widget_custom_attribute[:getter][:name])
226
+ end
220
227
  else
221
228
  @swt_widget.send(attribute_getter(attribute_name))
222
229
  end
@@ -330,43 +337,33 @@ module Glimmer
330
337
  }
331
338
  end,
332
339
  :caret_position => lambda do |observer|
333
- on_swt_keydown { |event|
334
- observer.call(@swt_widget.getCaretPosition)
335
- }
336
340
  on_swt_keyup { |event|
337
- observer.call(@swt_widget.getCaretPosition)
341
+ observer.call(@swt_widget.getCaretOffset)
338
342
  }
339
- on_swt_mousedown { |event|
340
- observer.call(@swt_widget.getCaretPosition)
343
+ on_swt_mouseup { |event|
344
+ observer.call(@swt_widget.getCaretOffset)
345
+ }
346
+ end,
347
+ :caret_offset => lambda do |observer|
348
+ on_swt_keyup { |event|
349
+ observer.call(@swt_widget.getCaretOffset)
341
350
  }
342
351
  on_swt_mouseup { |event|
343
- observer.call(@swt_widget.getCaretPosition)
352
+ observer.call(@swt_widget.getCaretOffset)
344
353
  }
345
354
  end,
346
355
  :selection => lambda do |observer|
347
- on_swt_keydown { |event|
348
- observer.call(@swt_widget.getSelection)
349
- }
350
356
  on_swt_keyup { |event|
351
- observer.call(@swt_widget.getSelection)
352
- }
353
- on_swt_mousedown { |event|
354
- observer.call(@swt_widget.getSelection)
357
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
355
358
  }
356
359
  on_swt_mouseup { |event|
357
- observer.call(@swt_widget.getSelection)
360
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
358
361
  }
359
362
  end,
360
363
  :selection_count => lambda do |observer|
361
- on_swt_keydown { |event|
362
- observer.call(@swt_widget.getSelectionCount)
363
- }
364
364
  on_swt_keyup { |event|
365
365
  observer.call(@swt_widget.getSelectionCount)
366
366
  }
367
- on_swt_mousedown { |event|
368
- observer.call(@swt_widget.getSelectionCount)
369
- }
370
367
  on_swt_mouseup { |event|
371
368
  observer.call(@swt_widget.getSelectionCount)
372
369
  }
@@ -379,7 +376,16 @@ module Glimmer
379
376
  observer.call(@last_top_index)
380
377
  end
381
378
  }
382
- end,
379
+ end,
380
+ :top_pixel => lambda do |observer|
381
+ @last_top_pixel = @swt_widget.getTopPixel
382
+ on_paint_control { |event|
383
+ if @swt_widget.getTopPixel != @last_top_pixel
384
+ @last_top_pixel = @swt_widget.getTopPixel
385
+ observer.call(@last_top_pixel)
386
+ end
387
+ }
388
+ end,
383
389
  },
384
390
  Java::OrgEclipseSwtWidgets::Button => {
385
391
  :selection => lambda do |observer|
@@ -474,13 +480,13 @@ module Glimmer
474
480
  proxy.set_attribute(:transfer, :text)
475
481
  proxy.on_drag_enter { |event|
476
482
  event.detail = DNDProxy[:drop_copy]
477
- }
483
+ }
478
484
  end
479
485
  end
480
486
 
481
487
  # TODO eliminate duplication in the following methods perhaps by relying on exceptions
482
488
 
483
- def can_handle_observation_request?(observation_request)
489
+ def can_handle_observation_request?(observation_request)
484
490
  observation_request = observation_request.to_s
485
491
  if observation_request.start_with?('on_swt_')
486
492
  constant_name = observation_request.sub(/^on_swt_/, '')
@@ -503,7 +509,7 @@ module Glimmer
503
509
  end
504
510
  rescue => e
505
511
  Glimmer::Config.logger.debug {e.full_message}
506
- false
512
+ false
507
513
  end
508
514
 
509
515
  def can_handle_drop_observation_request?(observation_request)
@@ -541,7 +547,7 @@ module Glimmer
541
547
  end
542
548
 
543
549
  def method_missing(method, *args, &block)
544
- if can_handle_observation_request?(method)
550
+ if can_handle_observation_request?(method)
545
551
  handle_observation_request(method, &block)
546
552
  else
547
553
  swt_widget.send(method, *args, &block)
@@ -553,7 +559,7 @@ module Glimmer
553
559
  end
554
560
 
555
561
  def respond_to?(method, *args, &block)
556
- super ||
562
+ super ||
557
563
  can_handle_observation_request?(method) ||
558
564
  swt_widget.respond_to?(method, *args, &block)
559
565
  end
@@ -561,7 +567,7 @@ module Glimmer
561
567
  private
562
568
 
563
569
  def style(underscored_widget_name, styles)
564
- styles = [styles].flatten.compact
570
+ styles = [styles].flatten.compact
565
571
  styles = default_style(underscored_widget_name) if styles.empty?
566
572
  interpret_style(*styles)
567
573
  end
@@ -597,9 +603,9 @@ module Glimmer
597
603
  end
598
604
 
599
605
  def add_listener(underscored_listener_name, &block)
600
- widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
606
+ widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
601
607
  widget_listener_proxy = nil
602
- safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
608
+ safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
603
609
  listener = listener_class.new(listener_method => safe_block)
604
610
  @swt_widget.send(widget_add_listener_method, listener)
605
611
  widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
@@ -641,7 +647,7 @@ module Glimmer
641
647
  listener_class.define_method('initialize') do |event_method_block_mapping|
642
648
  @event_method_block_mapping = event_method_block_mapping
643
649
  end
644
- listener_type.getMethods.each do |event_method|
650
+ listener_type.getMethods.each do |event_method|
645
651
  listener_class.define_method(event_method.getName) do |*args|
646
652
  @event_method_block_mapping[event_method.getName]&.call(*args)
647
653
  end
@@ -660,21 +666,21 @@ module Glimmer
660
666
  end
661
667
 
662
668
  def widget_custom_attribute_mapping
669
+ # TODO scope per widget class type just like other mappings
663
670
  @swt_widget_custom_attribute_mapping ||= {
664
671
  'focus' => {
665
672
  getter: {name: 'isFocusControl'},
666
673
  setter: {name: 'setFocus', invoker: lambda { |widget, args| @swt_widget.setFocus if args.first }},
667
674
  },
668
675
  'caret_position' => {
669
- getter: {name: 'getCaretPosition'},
676
+ getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset}},
670
677
  setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first) if args.first }},
671
678
  },
672
679
  'selection_count' => {
673
680
  getter: {name: 'getSelectionCount'},
674
- setter: {name: 'setSelection', invoker: lambda { |widget, args|
675
- # TODO consider the idea of aliasing getCaretPosition in StyledText
676
- caret_position = @swt_widget.getCaretPosition rescue @swt_widget.getCaretOffset
677
- @swt_widget.setSelection(caret_position, caret_position + args.first) if args.first
681
+ setter: {name: 'setSelection', invoker: lambda { |widget, args|
682
+ caret_position = @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset
683
+ @swt_widget.setSelection(caret_position, caret_position + args.first) if args.first
678
684
  }},
679
685
  },
680
686
  }
@@ -713,11 +719,9 @@ module Glimmer
713
719
  end
714
720
 
715
721
  def apply_property_type_converters(attribute_name, args)
716
- if args.count == 1
717
- value = args.first
718
- converter = property_type_converters[attribute_name.to_sym]
719
- args[0] = converter.call(value) if converter
720
- end
722
+ value = args
723
+ converter = property_type_converters[attribute_name.to_sym]
724
+ args[0..-1] = [converter.call(*value)] if converter
721
725
  if args.count == 1 && args.first.is_a?(ColorProxy)
722
726
  g_color = args.first
723
727
  args[0] = g_color.swt_color
@@ -738,8 +742,8 @@ module Glimmer
738
742
  SWTProxy[*value]
739
743
  },
740
744
  :background => color_converter,
741
- :background_image => lambda do |value|
742
- image_proxy = ImageProxy.create(value)
745
+ :background_image => lambda do |*value|
746
+ image_proxy = ImageProxy.create(*value)
743
747
 
744
748
  if image_proxy&.file_path&.end_with?('.gif')
745
749
  image = image_proxy.swt_image
@@ -769,13 +773,13 @@ module Glimmer
769
773
  sleep(delayTime)
770
774
  end
771
775
  };
772
- image_proxy = nil
776
+ image_proxy = nil
773
777
  else
774
778
  on_swt_Resize do |resize_event|
775
779
  image_proxy.scale_to(@swt_widget.getSize.x, @swt_widget.getSize.y)
776
- @swt_widget.setBackgroundImage(image_proxy.swt_image)
777
- end
778
- end
780
+ @swt_widget.setBackgroundImage(image_proxy.swt_image)
781
+ end
782
+ end
779
783
 
780
784
  image_proxy&.swt_image
781
785
  end,
@@ -797,8 +801,8 @@ module Glimmer
797
801
  value
798
802
  end
799
803
  end,
800
- :image => lambda do |value|
801
- ImageProxy.create(value).swt_image
804
+ :image => lambda do |*value|
805
+ ImageProxy.create(*value).swt_image
802
806
  end,
803
807
  :images => lambda do |array|
804
808
  array.to_a.map do |value|
@@ -837,4 +841,4 @@ module Glimmer
837
841
  end
838
842
  end
839
843
  end
840
- end
844
+ end