glimmer-dsl-opal 0.26.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Point < Shape
33
+
34
+ def element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: 1, height: 1)
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polygon < Shape
33
+
34
+ def element
35
+ 'polygon'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polygon(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polyline < Shape
33
+
34
+ def element
35
+ 'polyline'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polyline(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Rectangle < Shape
33
+
34
+ def element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: @args[2], height: @args[3], rx: @args[4], ry: @args[5])
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2020-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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Text < Shape
33
+
34
+ def background=(value)
35
+ # TODO override background= to fill a rectangle containing text, matching its size
36
+ # For now, disable background when foreground is not set
37
+ super(value) unless foreground.nil?
38
+ end
39
+
40
+ def foreground=(value)
41
+ super(value)
42
+ self.background = value
43
+ end
44
+
45
+ def element
46
+ 'text'
47
+ end
48
+
49
+ def dom
50
+ shape_id = id
51
+ shape_class = name
52
+ @dom ||= xml {
53
+ tag(:_name => 'text', id: shape_id, class: shape_class, x: @args[1], y: @args[2]) {
54
+ @args[0]
55
+ }
56
+ }.to_s
57
+ end
58
+
59
+ end
60
+ String = Text
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,109 @@
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/property_owner'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ require 'glimmer/swt/font_proxy'
27
+ # require 'glimmer/swt/transform_proxy'
28
+ require 'glimmer/swt/point'
29
+ require 'glimmer/swt/rectangle'
30
+
31
+ module Glimmer
32
+ module SWT
33
+ module Custom
34
+ # Represents a shape (graphics) to be drawn on a control/widget/canvas/display
35
+ # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
36
+ class Shape < WidgetProxy
37
+ include PropertyOwner
38
+
39
+ class << self
40
+ def create(parent, keyword, args, &property_block)
41
+ potential_shape_class_name = keyword.to_s.camelcase(:upper).to_sym
42
+ if constants.include?(potential_shape_class_name)
43
+ const_get(potential_shape_class_name).new(parent, args, &property_block)
44
+ else
45
+ new(parent, args, &property_block)
46
+ end
47
+ end
48
+
49
+ def valid?(parent, keyword, args, &block)
50
+ return true if keyword.to_s == 'shape'
51
+ keywords.include?(keyword.to_s)
52
+ end
53
+
54
+ def keywords
55
+ constants.select do |constant|
56
+ constant_value = const_get(constant)
57
+ constant_value.respond_to?(:ancestors) && constant_value.ancestors.include?(Glimmer::SWT::Custom::Shape)
58
+ end.map {|constant| constant.to_s.underscore}
59
+ end
60
+
61
+ end
62
+
63
+ def background=(value)
64
+ value = ColorProxy.new(value) if value.is_a?(String)
65
+ @background = value
66
+ dom_element.css('fill', background.to_css) unless background.nil?
67
+ end
68
+
69
+ def foreground=(value)
70
+ value = ColorProxy.new(value) if value.is_a?(String)
71
+ @foreground = value
72
+ dom_element.css('stroke', foreground.to_css) unless foreground.nil?
73
+ dom_element.css('fill', 'transparent') if background.nil?
74
+ end
75
+
76
+ def attach(the_parent_dom_element)
77
+ the_parent_dom_element.html("#{the_parent_dom_element.html()}\n#{@dom}")
78
+ end
79
+
80
+ def element
81
+ 'g'
82
+ end
83
+
84
+ def dom
85
+ shape_id = id
86
+ shape_class = name
87
+ @dom ||= xml {
88
+ g(id: shape_id, class: shape_class) {
89
+ }
90
+ }.to_s
91
+ end
92
+
93
+ # TODO implement shape_at_location potentially with document.elementFromPoint(x, y);
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ require 'glimmer/swt/custom/shape/line'
104
+ require 'glimmer/swt/custom/shape/oval'
105
+ require 'glimmer/swt/custom/shape/point'
106
+ require 'glimmer/swt/custom/shape/polygon'
107
+ require 'glimmer/swt/custom/shape/polyline'
108
+ require 'glimmer/swt/custom/shape/rectangle'
109
+ require 'glimmer/swt/custom/shape/text'
@@ -136,43 +136,6 @@ module Glimmer
136
136
  }
137
137
  },
138
138
  ],
139
- 'on_key_pressed' => {
140
- event: 'keydown',
141
- event_handler: -> (event_listener) {
142
- -> (event) {
143
- # TODO generalize this solution to all widgets that support key presses
144
- # TODO support event.location once DOM3 is supported by opal-jquery
145
- event.define_singleton_method(:keyCode) {event.which}
146
- event.define_singleton_method(:key_code, &event.method(:keyCode))
147
- event.define_singleton_method(:character) {event.which.chr}
148
- event.define_singleton_method(:stateMask) do
149
- state_mask = 0
150
- state_mask |= SWTProxy[:alt] if event.alt_key
151
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
152
- state_mask |= SWTProxy[:shift] if event.shift_key
153
- state_mask |= SWTProxy[:command] if event.meta_key
154
- state_mask
155
- end
156
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
157
- doit = true
158
- event.define_singleton_method(:doit=) do |value|
159
- doit = value
160
- end
161
- event.define_singleton_method(:doit) { doit }
162
- event_listener.call(event)
163
-
164
- # TODO Fix doit false, it's not stopping input
165
- unless doit
166
- event.prevent
167
- event.prevent_default
168
- event.stop_propagation
169
- event.stop_immediate_propagation
170
- end
171
-
172
- doit
173
- }
174
- }
175
- },
176
139
  }
177
140
  end
178
141
 
@@ -4,16 +4,6 @@ require 'glimmer/swt/swt_proxy'
4
4
  module Glimmer
5
5
  module SWT
6
6
  class DisplayProxy < WidgetProxy
7
- JS_KEY_CODE_TO_SWT_KEY_CODE_MAP = {
8
- 16 => SWTProxy[:shift],
9
- 17 => SWTProxy[:ctrl],
10
- 18 => SWTProxy[:alt],
11
- 37 => SWTProxy[:arrow_left],
12
- 38 => SWTProxy[:arrow_up],
13
- 39 => SWTProxy[:arrow_right],
14
- 40 => SWTProxy[:arrow_down],
15
- }
16
-
17
7
  class << self
18
8
  def instance
19
9
  @instance ||= new
@@ -96,93 +86,6 @@ module Glimmer
96
86
  # sync_exec kept for API compatibility reasons
97
87
  alias sync_exec async_exec
98
88
 
99
- def observation_request_to_event_mapping
100
- {
101
- 'on_swt_keydown' => [
102
- {
103
- event: 'keypress',
104
- event_handler: -> (event_listener) {
105
- -> (event) {
106
- event.singleton_class.define_method(:character) do
107
- which || key_code
108
- end
109
- event.define_singleton_method(:keyCode) {
110
- JS_KEY_CODE_TO_SWT_KEY_CODE_MAP[event.which] || event.which
111
- }
112
- event.define_singleton_method(:key_code, &event.method(:keyCode))
113
- event.define_singleton_method(:character) {event.which.chr}
114
- event.define_singleton_method(:stateMask) do
115
- state_mask = 0
116
- state_mask |= SWTProxy[:alt] if event.alt_key
117
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
118
- state_mask |= SWTProxy[:shift] if event.shift_key
119
- state_mask |= SWTProxy[:command] if event.meta_key
120
- state_mask
121
- end
122
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
123
- doit = true
124
- event.define_singleton_method(:doit=) do |value|
125
- doit = value
126
- end
127
- event.define_singleton_method(:doit) { doit }
128
- event_listener.call(event)
129
-
130
- # TODO Fix doit false, it's not stopping input
131
- unless doit
132
- event.prevent
133
- event.prevent_default
134
- event.stop_propagation
135
- event.stop_immediate_propagation
136
- end
137
-
138
- doit
139
- }
140
- }
141
- },
142
- {
143
- event: 'keydown',
144
- event_handler: -> (event_listener) {
145
- -> (event) {
146
- event.singleton_class.define_method(:character) do
147
- which || key_code
148
- end
149
- event.define_singleton_method(:keyCode) {
150
- JS_KEY_CODE_TO_SWT_KEY_CODE_MAP[event.which] || event.which
151
- }
152
- event.define_singleton_method(:key_code, &event.method(:keyCode))
153
- event.define_singleton_method(:character) {event.which.chr}
154
- event.define_singleton_method(:stateMask) do
155
- state_mask = 0
156
- state_mask |= SWTProxy[:alt] if event.alt_key
157
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
158
- state_mask |= SWTProxy[:shift] if event.shift_key
159
- state_mask |= SWTProxy[:command] if event.meta_key
160
- state_mask
161
- end
162
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
163
- doit = true
164
- event.define_singleton_method(:doit=) do |value|
165
- doit = value
166
- end
167
- event.define_singleton_method(:doit) { doit }
168
- event_listener.call(event) if event.which != 13 && (event.which == 127 || event.which <= 40)
169
-
170
- # TODO Fix doit false, it's not stopping input
171
- unless doit
172
- event.prevent
173
- event.prevent_default
174
- event.stop_propagation
175
- event.stop_immediate_propagation
176
- end
177
-
178
- doit
179
- }
180
- }
181
- }
182
- ]
183
- }
184
- end
185
-
186
89
  private
187
90
 
188
91
  def async_exec_queues