glimmer-dsl-swt 4.17.2.4 → 4.17.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +44 -0
- data/README.md +294 -467
- data/VERSION +1 -1
- data/glimmer-dsl-swt.gemspec +14 -6
- data/lib/glimmer-dsl-swt.rb +1 -0
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -0
- data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -0
- data/lib/glimmer/dsl/swt/widget_expression.rb +2 -0
- data/lib/glimmer/rake_task.rb +19 -21
- data/lib/glimmer/rake_task/package.rb +9 -2
- data/lib/glimmer/rake_task/scaffold.rb +138 -42
- data/lib/glimmer/swt/custom/code_text.rb +95 -0
- data/lib/glimmer/swt/expand_item_proxy.rb +98 -0
- data/lib/glimmer/swt/image_proxy.rb +5 -0
- data/lib/glimmer/swt/message_box_proxy.rb +1 -1
- data/lib/glimmer/swt/sash_form_proxy.rb +53 -0
- data/lib/glimmer/swt/styled_text_proxy.rb +43 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +1 -1
- data/lib/glimmer/swt/widget_proxy.rb +92 -33
- data/samples/elaborate/meta_sample.rb +166 -0
- data/samples/hello/hello_expand_bar.rb +108 -0
- data/samples/hello/hello_sash_form.rb +137 -0
- data/samples/hello/hello_styled_text.rb +138 -0
- metadata +16 -8
- data/lib/glimmer/rake_task/sample.rb +0 -115
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'glimmer/ui/custom_widget'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
module Custom
|
6
|
+
# CodeText is a customization of StyledText with support for Ruby Syntax Highlighting
|
7
|
+
class CodeText
|
8
|
+
include Glimmer::UI::CustomWidget
|
9
|
+
|
10
|
+
SYNTAX_COLOR_MAP = {
|
11
|
+
Builtin: [215,58,73],
|
12
|
+
Class: [3,47,98],
|
13
|
+
Constant: [0,92,197],
|
14
|
+
Double: [0,92,197],
|
15
|
+
Escape: [:red],
|
16
|
+
Function: [:blue],
|
17
|
+
Instance: [227,98,9],
|
18
|
+
Integer: [:blue],
|
19
|
+
Interpol: [:blue],
|
20
|
+
Keyword: [:blue],
|
21
|
+
Name: [111,66,193], #purple
|
22
|
+
Operator: [:red],
|
23
|
+
Pseudo: [:dark_red],
|
24
|
+
Punctuation: [:blue],
|
25
|
+
Single: [106,115,125], # Also, Comments
|
26
|
+
Symbol: [:dark_green],
|
27
|
+
Text: [75, 75, 75],
|
28
|
+
}
|
29
|
+
|
30
|
+
# TODO support `option :language`
|
31
|
+
# TODO support auto language detection
|
32
|
+
|
33
|
+
def text=(value)
|
34
|
+
swt_widget&.text = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def text
|
38
|
+
swt_widget&.text
|
39
|
+
end
|
40
|
+
|
41
|
+
def syntax_highlighting
|
42
|
+
return [] if text.to_s.strip.empty?
|
43
|
+
code = text
|
44
|
+
return @syntax_highlighting if @last_code == code
|
45
|
+
@last_code = code
|
46
|
+
@lexer ||= Rouge::Lexer.find_fancy('ruby', code)
|
47
|
+
lex = @lexer.lex(code).to_a
|
48
|
+
code_size = 0
|
49
|
+
lex_hashes = lex.map do |pair|
|
50
|
+
{token_type: pair.first, token_text: pair.last}
|
51
|
+
end.each do |hash|
|
52
|
+
hash[:token_index] = code_size
|
53
|
+
code_size += hash[:token_text].size
|
54
|
+
end
|
55
|
+
code_lines = code.split("\n")
|
56
|
+
line_index = 0
|
57
|
+
@syntax_highlighting = code_lines_map = code_lines.reduce({}) do |hash, line|
|
58
|
+
line_hashes = []
|
59
|
+
line_hashes << lex_hashes.shift while lex_hashes.any? && lex_hashes.first[:token_index].between?(line_index, line_index + line.size)
|
60
|
+
hash.merge(line_index => line_hashes).tap do
|
61
|
+
line_index += line.size + 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
before_body {
|
67
|
+
@swt_style = swt_style == 0 ? [:border, :multi, :v_scroll, :h_scroll] : swt_style
|
68
|
+
}
|
69
|
+
|
70
|
+
body {
|
71
|
+
styled_text(swt_style) {
|
72
|
+
font name: 'Consolas', height: 15
|
73
|
+
foreground rgb(75, 75, 75)
|
74
|
+
left_margin 5
|
75
|
+
top_margin 5
|
76
|
+
right_margin 5
|
77
|
+
bottom_margin 5
|
78
|
+
|
79
|
+
on_line_get_style { |line_style_event|
|
80
|
+
styles = []
|
81
|
+
syntax_highlighting[line_style_event.lineOffset].to_a.each do |token_hash|
|
82
|
+
start_index = token_hash[:token_index]
|
83
|
+
size = token_hash[:token_text].size
|
84
|
+
token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
|
85
|
+
token_color = color(*token_color).swt_color
|
86
|
+
styles << StyleRange.new(start_index, size, token_color, nil)
|
87
|
+
end
|
88
|
+
line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,98 @@
|
|
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
|
+
WidgetProxy.new('composite', self, []) # adding filler since it seems like the last child gets a bad style, so this gets it instead
|
65
|
+
end
|
66
|
+
|
67
|
+
def has_attribute?(attribute_name, *args)
|
68
|
+
if ATTRIBUTES.include?(attribute_name.to_s)
|
69
|
+
true
|
70
|
+
else
|
71
|
+
super(attribute_name, *args)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_attribute(attribute_name, *args)
|
76
|
+
if ATTRIBUTES.include?(attribute_name.to_s)
|
77
|
+
@widget_proxy.set_attribute(attribute_name, *args)
|
78
|
+
else
|
79
|
+
super(attribute_name, *args)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_attribute(attribute_name)
|
84
|
+
if ATTRIBUTES.include?(attribute_name.to_s)
|
85
|
+
@widget_proxy.get_attribute(attribute_name)
|
86
|
+
else
|
87
|
+
super(attribute_name)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def dispose
|
92
|
+
swt_expand_item.setControl(nil)
|
93
|
+
swt_widget.dispose
|
94
|
+
swt_expand_item.dispose
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
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
|
@@ -0,0 +1,53 @@
|
|
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.SashForm
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class SashFormProxy < WidgetProxy
|
30
|
+
def post_add_content
|
31
|
+
swt_widget.setWeights(@weights) unless @weights.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_attribute(attribute_name, *args)
|
35
|
+
if attribute_name.to_s == 'weights'
|
36
|
+
@weights = args
|
37
|
+
@weights = @weights.first if @weights.first.is_a?(Array)
|
38
|
+
else
|
39
|
+
super(attribute_name, *args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_attribute(attribute_name)
|
44
|
+
if attribute_name.to_s == "weights"
|
45
|
+
swt_widget.getWeights.to_a
|
46
|
+
else
|
47
|
+
super(attribute_name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
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
|
-
@
|
50
|
+
@swt_tab_item.control = swt_widget
|
51
51
|
end
|
52
52
|
|
53
53
|
def has_attribute?(attribute_name, *args)
|
@@ -44,26 +44,29 @@ module Glimmer
|
|
44
44
|
include Packages
|
45
45
|
|
46
46
|
DEFAULT_STYLES = {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
+
'tool_bar' => [:push],
|
63
|
+
'tool_item' => [:push],
|
64
|
+
'expand_bar' => [:v_scroll],
|
65
|
+
'tree' => [:virtual, :border, :h_scroll, :v_scroll],
|
63
66
|
}
|
64
67
|
|
65
68
|
DEFAULT_INITIALIZERS = {
|
66
|
-
|
69
|
+
'composite' => lambda do |composite|
|
67
70
|
if composite.get_layout.nil?
|
68
71
|
layout = GridLayout.new
|
69
72
|
layout.marginWidth = 15
|
@@ -71,18 +74,18 @@ module Glimmer
|
|
71
74
|
composite.layout = layout
|
72
75
|
end
|
73
76
|
end,
|
74
|
-
|
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
|
-
|
81
|
+
'table' => lambda do |table|
|
79
82
|
table.setHeaderVisible(true)
|
80
83
|
table.setLinesVisible(true)
|
81
84
|
end,
|
82
|
-
|
85
|
+
'table_column' => lambda do |table_column|
|
83
86
|
table_column.setWidth(80)
|
84
87
|
end,
|
85
|
-
|
88
|
+
'group' => lambda do |group|
|
86
89
|
group.layout = GridLayout.new if group.get_layout.nil?
|
87
90
|
end,
|
88
91
|
}
|
@@ -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
|
-
|
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
|
@@ -329,6 +336,56 @@ module Glimmer
|
|
329
336
|
observer.call(@swt_widget.getText)
|
330
337
|
}
|
331
338
|
end,
|
339
|
+
:caret_position => lambda do |observer|
|
340
|
+
on_swt_keyup { |event|
|
341
|
+
observer.call(@swt_widget.getCaretOffset)
|
342
|
+
}
|
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)
|
350
|
+
}
|
351
|
+
on_swt_mouseup { |event|
|
352
|
+
observer.call(@swt_widget.getCaretOffset)
|
353
|
+
}
|
354
|
+
end,
|
355
|
+
:selection => lambda do |observer|
|
356
|
+
on_swt_keyup { |event|
|
357
|
+
observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
|
358
|
+
}
|
359
|
+
on_swt_mouseup { |event|
|
360
|
+
observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
|
361
|
+
}
|
362
|
+
end,
|
363
|
+
:selection_count => lambda do |observer|
|
364
|
+
on_swt_keyup { |event|
|
365
|
+
observer.call(@swt_widget.getSelectionCount)
|
366
|
+
}
|
367
|
+
on_swt_mouseup { |event|
|
368
|
+
observer.call(@swt_widget.getSelectionCount)
|
369
|
+
}
|
370
|
+
end,
|
371
|
+
:top_index => lambda do |observer|
|
372
|
+
@last_top_index = @swt_widget.getTopIndex
|
373
|
+
on_paint_control { |event|
|
374
|
+
if @swt_widget.getTopIndex != @last_top_index
|
375
|
+
@last_top_index = @swt_widget.getTopIndex
|
376
|
+
observer.call(@last_top_index)
|
377
|
+
end
|
378
|
+
}
|
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,
|
332
389
|
},
|
333
390
|
Java::OrgEclipseSwtWidgets::Button => {
|
334
391
|
:selection => lambda do |observer|
|
@@ -609,18 +666,22 @@ module Glimmer
|
|
609
666
|
end
|
610
667
|
|
611
668
|
def widget_custom_attribute_mapping
|
669
|
+
# TODO scope per widget class type just like other mappings
|
612
670
|
@swt_widget_custom_attribute_mapping ||= {
|
613
671
|
'focus' => {
|
614
672
|
getter: {name: 'isFocusControl'},
|
615
673
|
setter: {name: 'setFocus', invoker: lambda { |widget, args| @swt_widget.setFocus if args.first }},
|
616
674
|
},
|
617
675
|
'caret_position' => {
|
618
|
-
getter: {name: 'getCaretPosition'},
|
676
|
+
getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset}},
|
619
677
|
setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first) if args.first }},
|
620
678
|
},
|
621
679
|
'selection_count' => {
|
622
680
|
getter: {name: 'getSelectionCount'},
|
623
|
-
setter: {name: 'setSelection', invoker: lambda { |widget, args|
|
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
|
684
|
+
}},
|
624
685
|
},
|
625
686
|
}
|
626
687
|
end
|
@@ -658,11 +719,9 @@ module Glimmer
|
|
658
719
|
end
|
659
720
|
|
660
721
|
def apply_property_type_converters(attribute_name, args)
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
args[0] = converter.call(value) if converter
|
665
|
-
end
|
722
|
+
value = args
|
723
|
+
converter = property_type_converters[attribute_name.to_sym]
|
724
|
+
args[0..-1] = [converter.call(*value)] if converter
|
666
725
|
if args.count == 1 && args.first.is_a?(ColorProxy)
|
667
726
|
g_color = args.first
|
668
727
|
args[0] = g_color.swt_color
|
@@ -683,8 +742,8 @@ module Glimmer
|
|
683
742
|
SWTProxy[*value]
|
684
743
|
},
|
685
744
|
:background => color_converter,
|
686
|
-
:background_image => lambda do
|
687
|
-
image_proxy = ImageProxy.create(value)
|
745
|
+
:background_image => lambda do |*value|
|
746
|
+
image_proxy = ImageProxy.create(*value)
|
688
747
|
|
689
748
|
if image_proxy&.file_path&.end_with?('.gif')
|
690
749
|
image = image_proxy.swt_image
|
@@ -742,8 +801,8 @@ module Glimmer
|
|
742
801
|
value
|
743
802
|
end
|
744
803
|
end,
|
745
|
-
:image => lambda do
|
746
|
-
ImageProxy.create(value).swt_image
|
804
|
+
:image => lambda do |*value|
|
805
|
+
ImageProxy.create(*value).swt_image
|
747
806
|
end,
|
748
807
|
:images => lambda do |array|
|
749
808
|
array.to_a.map do |value|
|