newt 1.0.0.pre1 → 1.0.1
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/README.rdoc +6 -1
- data/examples/test-e.rb +9 -5
- data/examples/test-j.rb +9 -5
- data/examples/test_method/Checkbox.rb +7 -1
- data/examples/test_method/CheckboxTree.rb +2 -1
- data/examples/test_method/CheckboxTreeMulti.rb +2 -1
- data/examples/test_method/Entry.rb +5 -1
- data/examples/test_method/Form_ExitStruct.rb +2 -1
- data/examples/test_method/Listbox.rb +2 -1
- data/examples/test_method/RadioButton.rb +3 -1
- data/examples/test_method/ReflowText.rb +6 -16
- data/examples/testgrid-e.rb +0 -2
- data/ext/ruby_newt/extconf.rb +4 -4
- data/ext/ruby_newt/ruby_newt.c +183 -60
- data/lib/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5359a4863477fd0ef9301a39de7f52eec456a006e55c12fe8dbab231f0e46eb4
|
|
4
|
+
data.tar.gz: 563df08ba0b46e638a855a6ce62f17360e054125bd886086294d0ceb05e2f4b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bab12bfb6e2bfd73116c94fe7489bee4063351092f900e91648fbb3ec85d128ba67b137d0fc143a725ca2b77633fe25b16918392bd08cab9edee2118c362c8b4
|
|
7
|
+
data.tar.gz: 5950e44aa2201eaff12e0d3725f0ff9f573cd2f3bf829068c660e304544052f17f55695efb731d6d042a63ad99d297f573ac7081d41089819fde4b539a5611d9
|
data/README.rdoc
CHANGED
|
@@ -21,6 +21,7 @@ See http://github.com/theforeman/ruby-newt/tree/master/examples for usage exampl
|
|
|
21
21
|
|
|
22
22
|
=== From source
|
|
23
23
|
|
|
24
|
+
$ gem install rake rake-compiler
|
|
24
25
|
$ git clone git://github.com/theforeman/ruby-newt
|
|
25
26
|
$ cd ruby-newt
|
|
26
27
|
$ gem build newt.gemspec
|
|
@@ -28,7 +29,9 @@ See http://github.com/theforeman/ruby-newt/tree/master/examples for usage exampl
|
|
|
28
29
|
|
|
29
30
|
=== Development
|
|
30
31
|
|
|
31
|
-
$
|
|
32
|
+
$ bundle install
|
|
33
|
+
$ bundle exec rake compile
|
|
34
|
+
$ bundle exec rake test
|
|
32
35
|
|
|
33
36
|
== REQUIREMENTS
|
|
34
37
|
|
|
@@ -77,6 +80,8 @@ programs using the ruby-newt library may need to be changed.
|
|
|
77
80
|
modify this hash directly will break.
|
|
78
81
|
* The various _add_callback_ methods no longer return the previously set
|
|
79
82
|
callback when called with no parameters.
|
|
83
|
+
* Use +get_current+ instead of +get+ for radiobuttons.
|
|
84
|
+
* Use +set_current+ instead of +set+ for radiobuttons.
|
|
80
85
|
|
|
81
86
|
== AUTHORS
|
|
82
87
|
|
data/examples/test-e.rb
CHANGED
|
@@ -49,7 +49,7 @@ e1 = Newt::Entry.new(12, 6, '', 20, 0)
|
|
|
49
49
|
e2 = Newt::Entry.new(12, 7, 'Default', 20, Newt::FLAG_SCROLL)
|
|
50
50
|
e3 = Newt::Entry.new(12, 8, '', 20, Newt::FLAG_HIDDEN)
|
|
51
51
|
|
|
52
|
-
cs[0].callback( proc {
|
|
52
|
+
cs[0].callback( proc { disable_callback(cs[0], e1) } )
|
|
53
53
|
scale = Newt::Scale.new(3, 14, 32, 100)
|
|
54
54
|
|
|
55
55
|
chklist.set_height(3)
|
|
@@ -93,13 +93,17 @@ end
|
|
|
93
93
|
Newt::Screen.pop_window
|
|
94
94
|
Newt::Screen.pop_window
|
|
95
95
|
|
|
96
|
+
e1 = e1.get
|
|
97
|
+
e2 = e2.get
|
|
98
|
+
e3 = e3.get
|
|
99
|
+
selected_list = lb.get_selection
|
|
100
|
+
|
|
96
101
|
Newt::Screen.finish
|
|
97
102
|
|
|
98
|
-
printf "got string 1: %s\n", e1
|
|
99
|
-
printf "got string 2: %s\n", e2
|
|
100
|
-
printf "got string 3: %s\n", e3
|
|
103
|
+
printf "got string 1: %s\n", e1
|
|
104
|
+
printf "got string 2: %s\n", e2
|
|
105
|
+
printf "got string 3: %s\n", e3
|
|
101
106
|
|
|
102
|
-
selected_list = lb.get_selection
|
|
103
107
|
if selected_list.count > 0
|
|
104
108
|
print "\nSelected listbox items:\n"
|
|
105
109
|
selected_list.each do |item|
|
data/examples/test-j.rb
CHANGED
|
@@ -49,7 +49,7 @@ e1 = Newt::Entry.new(12, 6, '', 20, 0)
|
|
|
49
49
|
e2 = Newt::Entry.new(12, 7, 'ɸ½à', 20, Newt::FLAG_SCROLL)
|
|
50
50
|
e3 = Newt::Entry.new(12, 8, '', 20, Newt::FLAG_HIDDEN)
|
|
51
51
|
|
|
52
|
-
cs[0].callback( proc {
|
|
52
|
+
cs[0].callback( proc { disable_callback(cs[0], e1) } )
|
|
53
53
|
scale = Newt::Scale.new(3, 14, 32, 100)
|
|
54
54
|
|
|
55
55
|
chklist.set_height(3)
|
|
@@ -93,13 +93,17 @@ end
|
|
|
93
93
|
Newt::Screen.pop_window
|
|
94
94
|
Newt::Screen.pop_window
|
|
95
95
|
|
|
96
|
+
e1 = e1.get
|
|
97
|
+
e2 = e2.get
|
|
98
|
+
e3 = e3.get
|
|
99
|
+
selected_list = lb.get_selection
|
|
100
|
+
|
|
96
101
|
Newt::Screen.finish
|
|
97
102
|
|
|
98
|
-
printf "got string 1: %s\n", e1
|
|
99
|
-
printf "got string 2: %s\n", e2
|
|
100
|
-
printf "got string 3: %s\n", e3
|
|
103
|
+
printf "got string 1: %s\n", e1
|
|
104
|
+
printf "got string 2: %s\n", e2
|
|
105
|
+
printf "got string 3: %s\n", e3
|
|
101
106
|
|
|
102
|
-
selected_list = lb.get_selection
|
|
103
107
|
if selected_list.count > 0
|
|
104
108
|
print "\nSelected listbox items:\n"
|
|
105
109
|
selected_list.each do |item|
|
|
@@ -20,8 +20,14 @@ begin
|
|
|
20
20
|
f.add(cb1, cb2, cb3, cb4, cb5, b)
|
|
21
21
|
|
|
22
22
|
f.run
|
|
23
|
+
|
|
24
|
+
cb1 = cb1.get
|
|
25
|
+
cb2 = cb2.get
|
|
26
|
+
cb3 = cb3.get
|
|
27
|
+
cb4 = cb4.get
|
|
28
|
+
cb5 = cb5.get
|
|
23
29
|
ensure
|
|
24
30
|
Newt::Screen.finish
|
|
25
31
|
end
|
|
26
32
|
|
|
27
|
-
p cb1
|
|
33
|
+
p cb1, cb2, cb3, cb4, cb5
|
|
@@ -49,11 +49,15 @@ begin
|
|
|
49
49
|
f.add(e1, e2, e3, b)
|
|
50
50
|
|
|
51
51
|
f.run
|
|
52
|
+
|
|
53
|
+
e1 = e1.get
|
|
54
|
+
e2 = e2.get
|
|
55
|
+
e3 = e3.get
|
|
52
56
|
ensure
|
|
53
57
|
Newt::Screen.finish
|
|
54
58
|
end
|
|
55
59
|
|
|
56
|
-
p e1
|
|
60
|
+
p e1, e2, e3
|
|
57
61
|
puts
|
|
58
62
|
puts "$widget = #{$widget}"
|
|
59
63
|
puts "$data = #{$data}"
|
|
@@ -21,6 +21,7 @@ begin
|
|
|
21
21
|
f.add(b1, b2, b)
|
|
22
22
|
|
|
23
23
|
rv = f.run
|
|
24
|
+
current = f.get_current
|
|
24
25
|
ensure
|
|
25
26
|
Newt::Screen.finish
|
|
26
27
|
end
|
|
@@ -29,7 +30,7 @@ puts rv.inspect
|
|
|
29
30
|
puts 'Button1' if rv == b1
|
|
30
31
|
puts 'Button2' if b2 == rv
|
|
31
32
|
puts 'Exit' if rv == b
|
|
32
|
-
puts 'Exit button is current button' if b ==
|
|
33
|
+
puts 'Exit button is current button' if b == current
|
|
33
34
|
puts 'Escape' if rv.reason == Newt::EXIT_HOTKEY && rv.key == ?\e.ord
|
|
34
35
|
puts 'Timeout' if rv.reason == Newt::EXIT_TIMER
|
|
35
36
|
puts 'FD Watch' if rv.reason == Newt::EXIT_FDREADY
|
|
@@ -3,22 +3,12 @@
|
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'newt'
|
|
5
5
|
|
|
6
|
-
text = ''
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
text, width, height = Newt.reflow_text('This is a quite a bit of text. It is 40 ' \
|
|
14
|
-
'columns long, so some wrapping should be ' \
|
|
15
|
-
'done. Did you know that the quick, brown ' \
|
|
16
|
-
"fox jumped over the lazy dog?\n\n" \
|
|
17
|
-
"In other news, it's pretty important that we " \
|
|
18
|
-
'can properly force a line break.', 40, 5, 5)
|
|
19
|
-
ensure
|
|
20
|
-
Newt::Screen.finish
|
|
21
|
-
end
|
|
6
|
+
text, width, height = Newt.reflow_text('This is a quite a bit of text. It is 40 ' \
|
|
7
|
+
'columns long, so some wrapping should be ' \
|
|
8
|
+
'done. Did you know that the quick, brown ' \
|
|
9
|
+
"fox jumped over the lazy dog?\n\n" \
|
|
10
|
+
"In other news, it's pretty important that we " \
|
|
11
|
+
'can properly force a line break.', 40, 5, 5)
|
|
22
12
|
|
|
23
13
|
p text
|
|
24
14
|
p width
|
data/examples/testgrid-e.rb
CHANGED
|
@@ -26,7 +26,6 @@ f.add(b1, b2, b3, b4)
|
|
|
26
26
|
grid.wrapped_window('first window')
|
|
27
27
|
f.run
|
|
28
28
|
|
|
29
|
-
# f.destroy
|
|
30
29
|
Newt::Screen.pop_window
|
|
31
30
|
|
|
32
31
|
flowed_text, text_width, text_height = Newt.reflow_text('This is a quite a bit of text. It is 40 ' \
|
|
@@ -58,7 +57,6 @@ f.add(b1, t, b2)
|
|
|
58
57
|
f.run
|
|
59
58
|
|
|
60
59
|
Newt::Screen.pop_window
|
|
61
|
-
# f.destroy
|
|
62
60
|
|
|
63
61
|
Newt::Screen.win_message('Simple', 'Ok', 'This is a simple message window')
|
|
64
62
|
result = Newt::Screen.win_choice('Simple', 'Ok', 'Cancel', 'This is a simple choice window')
|
data/ext/ruby_newt/extconf.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'mkmf'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
pkg_config('slang')
|
|
4
|
+
pkg_config('libnewt')
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
append_cflags(ENV['CFLAGS'])
|
|
7
|
+
append_ldflags(ENV['LDFLAGS'])
|
|
8
8
|
|
|
9
9
|
create_makefile('ruby_newt/ruby_newt')
|
data/ext/ruby_newt/ruby_newt.c
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#include <ruby.h>
|
|
7
7
|
#include <newt.h>
|
|
8
8
|
|
|
9
|
+
static VALUE initialized = Qfalse;
|
|
10
|
+
|
|
9
11
|
static VALUE mNewt;
|
|
10
12
|
static VALUE mScreen;
|
|
11
13
|
static VALUE cWidget;
|
|
@@ -29,21 +31,28 @@ static VALUE cGrid;
|
|
|
29
31
|
static VALUE rb_ext_sCallback;
|
|
30
32
|
static struct newtColors newtColors;
|
|
31
33
|
|
|
34
|
+
#define PTR2NUM(ptr) (SIZET2NUM((size_t)(ptr)))
|
|
32
35
|
#define SYMBOL(str) (ID2SYM(rb_intern(str)))
|
|
33
36
|
#define PROC_CALL (rb_intern("call"))
|
|
34
37
|
#define RECEIVER(context) (rb_funcall((context), rb_intern("receiver"), 0))
|
|
35
38
|
#define IVAR_DATA (rb_intern("newt_ivar_data"))
|
|
36
39
|
#define IVAR_COLS (rb_intern("newt_ivar_cols"))
|
|
37
40
|
#define IVAR_ROWS (rb_intern("newt_ivar_rows"))
|
|
41
|
+
#define CVAR_SUSPEND_CALLBACK (rb_intern("newt_cvar_suspend_callback"))
|
|
42
|
+
#define CVAR_HELP_CALLBACK (rb_intern("newt_cvar_help_callback"))
|
|
38
43
|
#define IVAR_FILTER_CALLBACK (rb_intern("newt_ivar_filter_callback"))
|
|
39
|
-
#define IVAR_SUSPEND_CALLBACK (rb_intern("newt_ivar_suspend_callback"))
|
|
40
|
-
#define IVAR_HELP_CALLBACK (rb_intern("newt_ivar_help_callback"))
|
|
41
44
|
#define IVAR_WIDGET_CALLBACK (rb_intern("newt_ivar_widget_callback"))
|
|
42
45
|
|
|
43
46
|
#define ARG_ERROR(given, expected) \
|
|
44
47
|
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected %s)", \
|
|
45
48
|
(given), (expected))
|
|
46
49
|
|
|
50
|
+
#define INIT_GUARD() do { \
|
|
51
|
+
if (initialized == Qfalse) { \
|
|
52
|
+
rb_raise(rb_eRuntimeError, "libnewt is not initialized"); \
|
|
53
|
+
} \
|
|
54
|
+
} while (0)
|
|
55
|
+
|
|
47
56
|
#define FLAG_GC_FREE (1 << 0)
|
|
48
57
|
#define FLAG_ADDED_TO_FORM (1 << 1)
|
|
49
58
|
|
|
@@ -55,6 +64,12 @@ struct Widget_data_s {
|
|
|
55
64
|
int flags;
|
|
56
65
|
};
|
|
57
66
|
|
|
67
|
+
typedef struct rb_newt_ExitStruct_s rb_newt_ExitStruct;
|
|
68
|
+
struct rb_newt_ExitStruct_s {
|
|
69
|
+
struct newtExitStruct es;
|
|
70
|
+
VALUE components;
|
|
71
|
+
};
|
|
72
|
+
|
|
58
73
|
static void free_widget(void *ptr);
|
|
59
74
|
static void form_destroy(Widget_data *form);
|
|
60
75
|
|
|
@@ -76,6 +91,7 @@ static const rb_data_type_t Widget_type = {
|
|
|
76
91
|
|
|
77
92
|
#define Get_newtComponent(self, component) do { \
|
|
78
93
|
Widget_data *data; \
|
|
94
|
+
INIT_GUARD(); \
|
|
79
95
|
Get_Widget_Data((self), data); \
|
|
80
96
|
(component) = data->co; \
|
|
81
97
|
} while (0)
|
|
@@ -85,6 +101,7 @@ static inline VALUE widget_data_make(VALUE klass, newtComponent co, bool gc_free
|
|
|
85
101
|
Widget_data *data;
|
|
86
102
|
VALUE self = TypedData_Make_Struct(klass, Widget_data, &Widget_type, data);
|
|
87
103
|
data->self = self;
|
|
104
|
+
data->components = Qnil;
|
|
88
105
|
data->co = co;
|
|
89
106
|
data->flags |= gc_free;
|
|
90
107
|
return self;
|
|
@@ -104,6 +121,13 @@ static inline Widget_data *widget_data_get(VALUE self)
|
|
|
104
121
|
return data;
|
|
105
122
|
}
|
|
106
123
|
|
|
124
|
+
NORETURN(static VALUE newt_s_alloc(VALUE klass));
|
|
125
|
+
static VALUE newt_s_alloc(VALUE klass)
|
|
126
|
+
{
|
|
127
|
+
rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE, klass);
|
|
128
|
+
UNREACHABLE_RETURN(Qnil);
|
|
129
|
+
}
|
|
130
|
+
|
|
107
131
|
static void free_widget(void *ptr)
|
|
108
132
|
{
|
|
109
133
|
Widget_data *data = (Widget_data *) ptr;
|
|
@@ -122,6 +146,12 @@ static void form_destroy(Widget_data *form)
|
|
|
122
146
|
rb_gc_unregister_address(&form->components);
|
|
123
147
|
}
|
|
124
148
|
|
|
149
|
+
static void rb_newt_es_free(rb_newt_ExitStruct *rb_es)
|
|
150
|
+
{
|
|
151
|
+
rb_gc_unregister_address(&rb_es->components);
|
|
152
|
+
xfree(rb_es);
|
|
153
|
+
}
|
|
154
|
+
|
|
125
155
|
#define Data_Attach(self, data) do { \
|
|
126
156
|
VALUE ivar = get_newt_ivar((self)); \
|
|
127
157
|
rb_ary_push(ivar, (data)); \
|
|
@@ -161,23 +191,27 @@ static VALUE rb_ext_ColorSetCustom(VALUE self, VALUE id)
|
|
|
161
191
|
return INT2NUM(NEWT_COLORSET_CUSTOM(NUM2INT(id)));
|
|
162
192
|
}
|
|
163
193
|
|
|
164
|
-
static VALUE
|
|
194
|
+
static VALUE rb_ext_Screen_Init()
|
|
165
195
|
{
|
|
196
|
+
if (initialized == Qtrue)
|
|
197
|
+
return Qnil;
|
|
198
|
+
|
|
166
199
|
newtInit();
|
|
167
|
-
newtCls();
|
|
168
200
|
memcpy(&newtColors, &newtDefaultColorPalette, sizeof(struct newtColors));
|
|
201
|
+
initialized = Qtrue;
|
|
169
202
|
return Qnil;
|
|
170
203
|
}
|
|
171
204
|
|
|
172
|
-
static VALUE
|
|
205
|
+
static VALUE rb_ext_Screen_new()
|
|
173
206
|
{
|
|
174
|
-
|
|
175
|
-
|
|
207
|
+
rb_ext_Screen_Init();
|
|
208
|
+
newtCls();
|
|
176
209
|
return Qnil;
|
|
177
210
|
}
|
|
178
211
|
|
|
179
212
|
static VALUE rb_ext_Screen_Cls()
|
|
180
213
|
{
|
|
214
|
+
INIT_GUARD();
|
|
181
215
|
newtCls();
|
|
182
216
|
return Qnil;
|
|
183
217
|
}
|
|
@@ -185,17 +219,20 @@ static VALUE rb_ext_Screen_Cls()
|
|
|
185
219
|
static VALUE rb_ext_Screen_Finished()
|
|
186
220
|
{
|
|
187
221
|
newtFinished();
|
|
222
|
+
initialized = Qfalse;
|
|
188
223
|
return Qnil;
|
|
189
224
|
}
|
|
190
225
|
|
|
191
226
|
static VALUE rb_ext_Screen_WaitForKey()
|
|
192
227
|
{
|
|
228
|
+
INIT_GUARD();
|
|
193
229
|
newtWaitForKey();
|
|
194
230
|
return Qnil;
|
|
195
231
|
}
|
|
196
232
|
|
|
197
233
|
static VALUE rb_ext_Screen_ClearKeyBuffer()
|
|
198
234
|
{
|
|
235
|
+
INIT_GUARD();
|
|
199
236
|
newtClearKeyBuffer();
|
|
200
237
|
return Qnil;
|
|
201
238
|
}
|
|
@@ -203,17 +240,20 @@ static VALUE rb_ext_Screen_ClearKeyBuffer()
|
|
|
203
240
|
static VALUE rb_ext_Screen_OpenWindow(VALUE self, VALUE left, VALUE top,
|
|
204
241
|
VALUE width, VALUE height, VALUE title)
|
|
205
242
|
{
|
|
243
|
+
INIT_GUARD();
|
|
206
244
|
return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top), NUM2INT(width),
|
|
207
245
|
NUM2INT(height), StringValuePtr(title)));
|
|
208
246
|
}
|
|
209
247
|
|
|
210
248
|
static VALUE rb_ext_Screen_CenteredWindow(VALUE self, VALUE width, VALUE height, VALUE title)
|
|
211
249
|
{
|
|
250
|
+
INIT_GUARD();
|
|
212
251
|
return INT2NUM(newtCenteredWindow(NUM2INT(width), NUM2INT(height), StringValuePtr(title)));
|
|
213
252
|
}
|
|
214
253
|
|
|
215
254
|
static VALUE rb_ext_Screen_PopWindow(VALUE self)
|
|
216
255
|
{
|
|
256
|
+
INIT_GUARD();
|
|
217
257
|
newtPopWindow();
|
|
218
258
|
return Qnil;
|
|
219
259
|
}
|
|
@@ -361,43 +401,50 @@ static VALUE rb_ext_Screen_SetColors(VALUE self, VALUE colors)
|
|
|
361
401
|
{
|
|
362
402
|
Check_Type(colors, T_HASH);
|
|
363
403
|
rb_hash_foreach(colors, rb_ext_Colors_callback_function, (VALUE) &newtColors);
|
|
404
|
+
|
|
405
|
+
INIT_GUARD();
|
|
364
406
|
newtSetColors(newtColors);
|
|
365
407
|
return Qnil;
|
|
366
408
|
}
|
|
367
409
|
|
|
368
410
|
static VALUE rb_ext_Screen_SetColor(VALUE self, VALUE colorset, VALUE fg, VALUE bg)
|
|
369
411
|
{
|
|
412
|
+
INIT_GUARD();
|
|
370
413
|
newtSetColor(NUM2INT(colorset), StringValuePtr(fg), StringValuePtr(bg));
|
|
371
414
|
return Qnil;
|
|
372
415
|
}
|
|
373
416
|
|
|
374
417
|
static VALUE rb_ext_Screen_Resume()
|
|
375
418
|
{
|
|
419
|
+
INIT_GUARD();
|
|
376
420
|
newtResume();
|
|
377
421
|
return Qnil;
|
|
378
422
|
}
|
|
379
423
|
|
|
380
424
|
static VALUE rb_ext_Screen_Suspend()
|
|
381
425
|
{
|
|
426
|
+
INIT_GUARD();
|
|
382
427
|
newtSuspend();
|
|
383
428
|
return Qnil;
|
|
384
429
|
}
|
|
385
430
|
|
|
386
431
|
static VALUE rb_ext_Screen_Refresh()
|
|
387
432
|
{
|
|
433
|
+
INIT_GUARD();
|
|
388
434
|
newtRefresh();
|
|
389
435
|
return Qnil;
|
|
390
436
|
}
|
|
391
437
|
|
|
392
438
|
static VALUE rb_ext_Screen_DrawRootText(VALUE self, VALUE col, VALUE row, VALUE text)
|
|
393
439
|
{
|
|
394
|
-
|
|
440
|
+
INIT_GUARD();
|
|
395
441
|
newtDrawRootText(NUM2INT(col), NUM2INT(row), StringValuePtr(text));
|
|
396
442
|
return Qnil;
|
|
397
443
|
}
|
|
398
444
|
|
|
399
445
|
static VALUE rb_ext_Screen_PushHelpLine(VALUE self, VALUE text)
|
|
400
446
|
{
|
|
447
|
+
INIT_GUARD();
|
|
401
448
|
newtPushHelpLine(StringValuePtr(text));
|
|
402
449
|
|
|
403
450
|
return Qnil;
|
|
@@ -405,30 +452,35 @@ static VALUE rb_ext_Screen_PushHelpLine(VALUE self, VALUE text)
|
|
|
405
452
|
|
|
406
453
|
static VALUE rb_ext_Screen_RedrawHelpLine(VALUE self)
|
|
407
454
|
{
|
|
455
|
+
INIT_GUARD();
|
|
408
456
|
newtRedrawHelpLine();
|
|
409
457
|
return Qnil;
|
|
410
458
|
}
|
|
411
459
|
|
|
412
460
|
static VALUE rb_ext_Screen_PopHelpLine(VALUE self)
|
|
413
461
|
{
|
|
462
|
+
INIT_GUARD();
|
|
414
463
|
newtPopHelpLine();
|
|
415
464
|
return Qnil;
|
|
416
465
|
}
|
|
417
466
|
|
|
418
467
|
static VALUE rb_ext_Screen_Bell(VALUE self)
|
|
419
468
|
{
|
|
469
|
+
INIT_GUARD();
|
|
420
470
|
newtBell();
|
|
421
471
|
return Qnil;
|
|
422
472
|
}
|
|
423
473
|
|
|
424
474
|
static VALUE rb_ext_Screen_CursorOff(VALUE self)
|
|
425
475
|
{
|
|
476
|
+
INIT_GUARD();
|
|
426
477
|
newtCursorOff();
|
|
427
478
|
return Qnil;
|
|
428
479
|
}
|
|
429
480
|
|
|
430
481
|
static VALUE rb_ext_Screen_CursorOn(VALUE self)
|
|
431
482
|
{
|
|
483
|
+
INIT_GUARD();
|
|
432
484
|
newtCursorOn();
|
|
433
485
|
return Qnil;
|
|
434
486
|
}
|
|
@@ -437,12 +489,14 @@ static VALUE rb_ext_Screen_Size(VALUE self)
|
|
|
437
489
|
{
|
|
438
490
|
int cols, rows;
|
|
439
491
|
|
|
492
|
+
INIT_GUARD();
|
|
440
493
|
newtGetScreenSize(&cols, &rows);
|
|
441
494
|
return rb_ary_new_from_args(2, INT2NUM(cols), INT2NUM(rows));
|
|
442
495
|
}
|
|
443
496
|
|
|
444
497
|
static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE title, VALUE button, VALUE text)
|
|
445
498
|
{
|
|
499
|
+
INIT_GUARD();
|
|
446
500
|
newtWinMessage(StringValuePtr(title), StringValuePtr(button), StringValuePtr(text));
|
|
447
501
|
return Qnil;
|
|
448
502
|
}
|
|
@@ -450,6 +504,8 @@ static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE title, VALUE button, VAL
|
|
|
450
504
|
static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE title, VALUE button1, VALUE button2, VALUE text)
|
|
451
505
|
{
|
|
452
506
|
int result;
|
|
507
|
+
|
|
508
|
+
INIT_GUARD();
|
|
453
509
|
result = newtWinChoice(StringValuePtr(title), StringValuePtr(button1),
|
|
454
510
|
StringValuePtr(button2), StringValuePtr(text));
|
|
455
511
|
return INT2NUM(result);
|
|
@@ -467,6 +523,7 @@ static VALUE rb_ext_Screen_WinMenu(VALUE self, VALUE args)
|
|
|
467
523
|
if (len < 8 || len > 9)
|
|
468
524
|
ARG_ERROR(len, "8..9");
|
|
469
525
|
|
|
526
|
+
INIT_GUARD();
|
|
470
527
|
title = StringValuePtr(RARRAY_PTR(args)[0]);
|
|
471
528
|
text = StringValuePtr(RARRAY_PTR(args)[1]);
|
|
472
529
|
width = NUM2INT(RARRAY_PTR(args)[2]);
|
|
@@ -504,6 +561,7 @@ static VALUE rb_ext_Screen_WinEntries(VALUE self, VALUE args)
|
|
|
504
561
|
if (len < 8 || len > 9)
|
|
505
562
|
ARG_ERROR(len, "8..9");
|
|
506
563
|
|
|
564
|
+
INIT_GUARD();
|
|
507
565
|
title = StringValuePtr(RARRAY_PTR(args)[0]);
|
|
508
566
|
text = StringValuePtr(RARRAY_PTR(args)[1]);
|
|
509
567
|
width = NUM2INT(RARRAY_PTR(args)[2]);
|
|
@@ -555,7 +613,7 @@ void rb_ext_Screen_help_callback_function(newtComponent co, void *data)
|
|
|
555
613
|
VALUE context, callback;
|
|
556
614
|
|
|
557
615
|
widget = Make_Widget_Ref(cForm, co);
|
|
558
|
-
cb =
|
|
616
|
+
cb = rb_cvar_get(mScreen, CVAR_HELP_CALLBACK);
|
|
559
617
|
context = RSTRUCT_GET((VALUE) cb, 1);
|
|
560
618
|
callback = RSTRUCT_GET((VALUE) cb, 2);
|
|
561
619
|
|
|
@@ -610,19 +668,23 @@ static VALUE rb_ext_Screen_SuspendCallback(int argc, VALUE *argv, VALUE self)
|
|
|
610
668
|
if (argc < 1 || argc > 2)
|
|
611
669
|
ARG_ERROR(argc, "1 or 2");
|
|
612
670
|
|
|
671
|
+
INIT_GUARD();
|
|
613
672
|
if (argc == 2)
|
|
614
673
|
data = argv[1];
|
|
615
674
|
|
|
616
675
|
cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
|
|
617
|
-
|
|
676
|
+
rb_obj_freeze(cb);
|
|
677
|
+
rb_cvar_set(self, CVAR_SUSPEND_CALLBACK, cb);
|
|
618
678
|
newtSetSuspendCallback(rb_ext_Screen_suspend_callback_function, (void *) cb);
|
|
619
679
|
return Qnil;
|
|
620
680
|
}
|
|
621
681
|
|
|
622
682
|
static VALUE rb_ext_Screen_HelpCallback(VALUE self, VALUE cb)
|
|
623
683
|
{
|
|
684
|
+
INIT_GUARD();
|
|
624
685
|
cb = rb_struct_new(rb_ext_sCallback, Qnil, rb_binding_new(), cb, Qnil, NULL);
|
|
625
|
-
|
|
686
|
+
rb_obj_freeze(cb);
|
|
687
|
+
rb_cvar_set(self, CVAR_HELP_CALLBACK, cb);
|
|
626
688
|
newtSetHelpCallback(rb_ext_Screen_help_callback_function);
|
|
627
689
|
return Qnil;
|
|
628
690
|
}
|
|
@@ -635,11 +697,13 @@ static VALUE rb_ext_Widget_callback(int argc, VALUE *argv, VALUE self)
|
|
|
635
697
|
if (argc < 1 || argc > 2)
|
|
636
698
|
ARG_ERROR(argc, "1 or 2");
|
|
637
699
|
|
|
700
|
+
INIT_GUARD();
|
|
638
701
|
if (argc == 2)
|
|
639
702
|
data = argv[1];
|
|
640
703
|
|
|
641
704
|
Get_newtComponent(self, co);
|
|
642
705
|
cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
|
|
706
|
+
rb_obj_freeze(cb);
|
|
643
707
|
rb_ivar_set(self, IVAR_WIDGET_CALLBACK, cb);
|
|
644
708
|
newtComponentAddCallback(co, rb_ext_Widget_callback_function, (void *) cb);
|
|
645
709
|
return Qnil;
|
|
@@ -683,94 +747,117 @@ static VALUE rb_ext_Widget_equal(VALUE self, VALUE obj)
|
|
|
683
747
|
if (self == obj) return Qtrue;
|
|
684
748
|
|
|
685
749
|
if (rb_obj_is_kind_of(obj, cWidget) || rb_obj_is_kind_of(obj, cExitStruct)) {
|
|
686
|
-
|
|
750
|
+
Get_Widget_Data(self, data);
|
|
751
|
+
co = ((Widget_data *) data)->co;
|
|
687
752
|
if (rb_obj_is_kind_of(obj, cExitStruct)) {
|
|
688
|
-
Data_Get_Struct(obj,
|
|
689
|
-
if (co == ((
|
|
753
|
+
Data_Get_Struct(obj, rb_newt_ExitStruct, data);
|
|
754
|
+
if (co == (((rb_newt_ExitStruct *) data)->es.u.co))
|
|
690
755
|
return Qtrue;
|
|
691
756
|
} else {
|
|
692
|
-
|
|
757
|
+
Get_Widget_Data(obj, data);
|
|
758
|
+
cco = ((Widget_data *) data)->co;
|
|
693
759
|
if (co == cco) return Qtrue;
|
|
694
760
|
}
|
|
695
761
|
}
|
|
696
762
|
return Qfalse;
|
|
697
763
|
}
|
|
698
764
|
|
|
765
|
+
static VALUE rb_ext_Widget_inspect(VALUE self)
|
|
766
|
+
{
|
|
767
|
+
newtComponent co;
|
|
768
|
+
void *data;
|
|
769
|
+
|
|
770
|
+
VALUE classname = rb_class_name(rb_obj_class(self));
|
|
771
|
+
char *class = StringValuePtr(classname);
|
|
772
|
+
|
|
773
|
+
Get_Widget_Data(self, data);
|
|
774
|
+
co = ((Widget_data *) data)->co;
|
|
775
|
+
return rb_sprintf("#<%s:%p component=%p>", class, (void *) self, co);
|
|
776
|
+
}
|
|
777
|
+
|
|
699
778
|
static VALUE rb_ext_ExitStruct_reason(VALUE self)
|
|
700
779
|
{
|
|
701
|
-
|
|
780
|
+
rb_newt_ExitStruct *rb_es;
|
|
702
781
|
|
|
703
|
-
Data_Get_Struct(self,
|
|
704
|
-
return INT2NUM(es
|
|
782
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
783
|
+
return INT2NUM(rb_es->es.reason);
|
|
705
784
|
}
|
|
706
785
|
|
|
707
786
|
static VALUE rb_ext_ExitStruct_watch(VALUE self)
|
|
708
787
|
{
|
|
709
|
-
|
|
788
|
+
rb_newt_ExitStruct *rb_es;
|
|
710
789
|
|
|
711
|
-
Data_Get_Struct(self,
|
|
712
|
-
if (es
|
|
713
|
-
return INT2NUM(es
|
|
790
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
791
|
+
if (rb_es->es.reason == NEWT_EXIT_FDREADY)
|
|
792
|
+
return INT2NUM(rb_es->es.u.watch);
|
|
714
793
|
else
|
|
715
794
|
return Qnil;
|
|
716
795
|
}
|
|
717
796
|
|
|
718
797
|
static VALUE rb_ext_ExitStruct_key(VALUE self)
|
|
719
798
|
{
|
|
720
|
-
|
|
799
|
+
rb_newt_ExitStruct *rb_es;
|
|
721
800
|
|
|
722
|
-
Data_Get_Struct(self,
|
|
723
|
-
if (es
|
|
724
|
-
return INT2NUM(es
|
|
801
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
802
|
+
if (rb_es->es.reason == NEWT_EXIT_HOTKEY)
|
|
803
|
+
return INT2NUM(rb_es->es.u.key);
|
|
725
804
|
else
|
|
726
805
|
return Qnil;
|
|
727
806
|
}
|
|
728
807
|
|
|
729
808
|
static VALUE rb_ext_ExitStruct_component(VALUE self)
|
|
730
809
|
{
|
|
731
|
-
|
|
810
|
+
rb_newt_ExitStruct *rb_es;
|
|
732
811
|
|
|
733
|
-
Data_Get_Struct(self,
|
|
734
|
-
if (es
|
|
735
|
-
|
|
736
|
-
else
|
|
737
|
-
|
|
812
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
813
|
+
if (rb_es->es.reason == NEWT_EXIT_COMPONENT) {
|
|
814
|
+
return rb_hash_aref(rb_es->components, PTR2NUM(rb_es->es.u.co));
|
|
815
|
+
} else {
|
|
816
|
+
return Qnil;
|
|
817
|
+
}
|
|
738
818
|
}
|
|
739
819
|
|
|
740
820
|
static VALUE rb_ext_ExitStruct_equal(VALUE self, VALUE obj)
|
|
741
821
|
{
|
|
742
|
-
|
|
822
|
+
rb_newt_ExitStruct *rb_es;
|
|
743
823
|
newtComponent co;
|
|
824
|
+
void *data;
|
|
744
825
|
|
|
745
826
|
if (NIL_P(obj)) return Qfalse;
|
|
746
827
|
if (self == obj) return Qtrue;
|
|
747
828
|
|
|
748
829
|
/* Compare components for backwards compatibility with newtRunForm(). */
|
|
749
830
|
if (rb_obj_is_kind_of(obj, cWidget)) {
|
|
750
|
-
Data_Get_Struct(self,
|
|
751
|
-
|
|
752
|
-
|
|
831
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
832
|
+
Get_Widget_Data(obj, data);
|
|
833
|
+
co = ((Widget_data *) data)->co;
|
|
834
|
+
if (rb_es->es.reason == NEWT_EXIT_COMPONENT
|
|
835
|
+
&& rb_es->es.u.co == co) return Qtrue;
|
|
753
836
|
}
|
|
754
837
|
return Qfalse;
|
|
755
838
|
}
|
|
756
839
|
|
|
757
840
|
static VALUE rb_ext_ExitStruct_inspect(VALUE self)
|
|
758
841
|
{
|
|
759
|
-
|
|
842
|
+
rb_newt_ExitStruct *rb_es;
|
|
760
843
|
VALUE classname = rb_class_name(rb_obj_class(self));
|
|
761
844
|
char *class = StringValuePtr(classname);
|
|
762
845
|
|
|
763
|
-
Data_Get_Struct(self,
|
|
764
|
-
switch(es
|
|
846
|
+
Data_Get_Struct(self, rb_newt_ExitStruct, rb_es);
|
|
847
|
+
switch(rb_es->es.reason) {
|
|
765
848
|
case NEWT_EXIT_HOTKEY:
|
|
766
|
-
return rb_sprintf("#<%s reason=%d, key=%d>", class,
|
|
849
|
+
return rb_sprintf("#<%s:%p reason=%d, key=%d>", class, (void *) self,
|
|
850
|
+
rb_es->es.reason, rb_es->es.u.key);
|
|
767
851
|
case NEWT_EXIT_COMPONENT:
|
|
768
|
-
return rb_sprintf("#<%s reason=%d, component=%p>", class,
|
|
852
|
+
return rb_sprintf("#<%s:%p reason=%d, component=%p>", class, (void *) self,
|
|
853
|
+
rb_es->es.reason, rb_es->es.u.co);
|
|
769
854
|
case NEWT_EXIT_FDREADY:
|
|
770
|
-
return rb_sprintf("#<%s reason=%d, watch=%d>", class,
|
|
855
|
+
return rb_sprintf("#<%s:%p reason=%d, watch=%d>", class, (void *) self,
|
|
856
|
+
rb_es->es.reason, rb_es->es.u.watch);
|
|
771
857
|
case NEWT_EXIT_TIMER:
|
|
772
858
|
case NEWT_EXIT_ERROR:
|
|
773
|
-
return rb_sprintf("#<%s reason=%d>", class,
|
|
859
|
+
return rb_sprintf("#<%s:%p reason=%d>", class, (void *) self,
|
|
860
|
+
rb_es->es.reason);
|
|
774
861
|
default:
|
|
775
862
|
return rb_call_super(0, NULL);
|
|
776
863
|
}
|
|
@@ -780,16 +867,17 @@ static VALUE rb_ext_Label_new(VALUE self, VALUE left, VALUE top, VALUE text)
|
|
|
780
867
|
{
|
|
781
868
|
newtComponent co;
|
|
782
869
|
|
|
870
|
+
INIT_GUARD();
|
|
783
871
|
co = newtLabel(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
|
|
784
872
|
return Make_Widget(self, co);
|
|
785
873
|
}
|
|
786
874
|
|
|
787
875
|
static VALUE rb_ext_Label_SetText(VALUE self, VALUE text)
|
|
788
876
|
{
|
|
789
|
-
|
|
877
|
+
newtComponent co;
|
|
790
878
|
|
|
791
|
-
|
|
792
|
-
newtLabelSetText(
|
|
879
|
+
Get_newtComponent(self, co);
|
|
880
|
+
newtLabelSetText(co, StringValuePtr(text));
|
|
793
881
|
return Qnil;
|
|
794
882
|
}
|
|
795
883
|
|
|
@@ -806,6 +894,7 @@ static VALUE rb_ext_CompactButton_new(VALUE self, VALUE left, VALUE top, VALUE t
|
|
|
806
894
|
{
|
|
807
895
|
newtComponent co;
|
|
808
896
|
|
|
897
|
+
INIT_GUARD();
|
|
809
898
|
co = newtCompactButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
|
|
810
899
|
return Make_Widget(self, co);
|
|
811
900
|
}
|
|
@@ -814,6 +903,7 @@ static VALUE rb_ext_Button_new(VALUE self, VALUE left, VALUE top, VALUE text)
|
|
|
814
903
|
{
|
|
815
904
|
newtComponent co;
|
|
816
905
|
|
|
906
|
+
INIT_GUARD();
|
|
817
907
|
co = newtButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
|
|
818
908
|
return Make_Widget(self, co);
|
|
819
909
|
}
|
|
@@ -827,6 +917,7 @@ static VALUE rb_ext_Checkbox_new(int argc, VALUE *argv, VALUE self)
|
|
|
827
917
|
if (argc < 3 || argc > 5)
|
|
828
918
|
ARG_ERROR(argc, "3..5");
|
|
829
919
|
|
|
920
|
+
INIT_GUARD();
|
|
830
921
|
if (argc > 3 && !NIL_P(argv[3]))
|
|
831
922
|
defValue = StringValuePtr(argv[3])[0];
|
|
832
923
|
|
|
@@ -883,6 +974,7 @@ static VALUE rb_ext_RadioButton_new(int argc, VALUE *argv, VALUE self)
|
|
|
883
974
|
if (argc < 3 || argc > 5)
|
|
884
975
|
ARG_ERROR(argc, "3..5");
|
|
885
976
|
|
|
977
|
+
INIT_GUARD();
|
|
886
978
|
if (argc >= 4)
|
|
887
979
|
is_default = NUM2INT(argv[3]);
|
|
888
980
|
|
|
@@ -919,7 +1011,9 @@ static VALUE rb_ext_Listbox_new(int argc, VALUE *argv, VALUE self)
|
|
|
919
1011
|
if (argc < 3 || argc > 4)
|
|
920
1012
|
ARG_ERROR(argc, "3..4");
|
|
921
1013
|
|
|
1014
|
+
INIT_GUARD();
|
|
922
1015
|
flags = (argc == 4) ? NUM2INT(argv[3]) : 0;
|
|
1016
|
+
|
|
923
1017
|
co = newtListbox(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), flags);
|
|
924
1018
|
return Make_Widget(self, co);
|
|
925
1019
|
}
|
|
@@ -1091,7 +1185,9 @@ static VALUE rb_ext_CheckboxTree_new(int argc, VALUE *argv, VALUE self)
|
|
|
1091
1185
|
if (argc < 3 || argc > 4)
|
|
1092
1186
|
ARG_ERROR(argc, "3..4");
|
|
1093
1187
|
|
|
1188
|
+
INIT_GUARD();
|
|
1094
1189
|
flags = (argc == 4) ? NUM2INT(argv[3]) : 0;
|
|
1190
|
+
|
|
1095
1191
|
co = newtCheckboxTree(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), flags);
|
|
1096
1192
|
return Make_Widget(self, co);
|
|
1097
1193
|
}
|
|
@@ -1213,11 +1309,13 @@ static VALUE rb_ext_CheckboxTreeMulti_new(int argc, VALUE *argv, VALUE self)
|
|
|
1213
1309
|
if (argc < 3 || argc > 5)
|
|
1214
1310
|
ARG_ERROR(argc, "3..5");
|
|
1215
1311
|
|
|
1312
|
+
INIT_GUARD();
|
|
1216
1313
|
seq = NULL;
|
|
1217
1314
|
if (argc >= 4 && !NIL_P(argv[3]) && RSTRING_LEN(argv[3]))
|
|
1218
1315
|
seq = StringValuePtr(argv[3]);
|
|
1219
1316
|
|
|
1220
1317
|
flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
|
|
1318
|
+
|
|
1221
1319
|
co = newtCheckboxTreeMulti(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), seq, flags);
|
|
1222
1320
|
return Make_Widget(self, co);
|
|
1223
1321
|
}
|
|
@@ -1241,7 +1339,9 @@ static VALUE rb_ext_Textbox_new(int argc, VALUE *argv, VALUE self)
|
|
|
1241
1339
|
if (argc < 4 || argc > 5)
|
|
1242
1340
|
ARG_ERROR(argc, "4..5");
|
|
1243
1341
|
|
|
1342
|
+
INIT_GUARD();
|
|
1244
1343
|
flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
|
|
1344
|
+
|
|
1245
1345
|
co = newtTextbox(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), NUM2INT(argv[3]), flags);
|
|
1246
1346
|
return Make_Widget(self, co);
|
|
1247
1347
|
}
|
|
@@ -1289,7 +1389,9 @@ static VALUE rb_ext_TextboxReflowed_new(int argc, VALUE *argv, VALUE self)
|
|
|
1289
1389
|
if (argc < 6 || argc > 7)
|
|
1290
1390
|
ARG_ERROR(argc, "6..7");
|
|
1291
1391
|
|
|
1392
|
+
INIT_GUARD();
|
|
1292
1393
|
flags = (argc == 7) ? NUM2INT(argv[6]) : 0;
|
|
1394
|
+
|
|
1293
1395
|
co = newtTextboxReflowed(NUM2INT(argv[0]), NUM2INT(argv[1]),
|
|
1294
1396
|
StringValuePtr(argv[2]), NUM2INT(argv[3]),
|
|
1295
1397
|
NUM2INT(argv[4]), NUM2INT(argv[5]), flags);
|
|
@@ -1306,6 +1408,7 @@ static VALUE rb_ext_Form_new(int argc, VALUE *argv, VALUE self)
|
|
|
1306
1408
|
if (argc > 3)
|
|
1307
1409
|
ARG_ERROR(argc, "0..3");
|
|
1308
1410
|
|
|
1411
|
+
INIT_GUARD();
|
|
1309
1412
|
helpTag = (argc >= 2) ? argv[1] : Qnil;
|
|
1310
1413
|
flags = (argc == 3) ? NUM2INT(argv[2]) : 0;
|
|
1311
1414
|
|
|
@@ -1329,9 +1432,10 @@ static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE components)
|
|
|
1329
1432
|
VALUE str;
|
|
1330
1433
|
int i;
|
|
1331
1434
|
|
|
1435
|
+
INIT_GUARD();
|
|
1332
1436
|
Get_Widget_Data(self, form);
|
|
1333
|
-
if (RARRAY_LEN(components) > 0 &&
|
|
1334
|
-
form->components =
|
|
1437
|
+
if (RARRAY_LEN(components) > 0 && form->components == Qnil) {
|
|
1438
|
+
form->components = rb_hash_new();
|
|
1335
1439
|
rb_gc_register_address(&form->components);
|
|
1336
1440
|
}
|
|
1337
1441
|
|
|
@@ -1345,7 +1449,7 @@ static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE components)
|
|
|
1345
1449
|
|
|
1346
1450
|
co->flags ^= FLAG_GC_FREE;
|
|
1347
1451
|
co->flags |= FLAG_ADDED_TO_FORM;
|
|
1348
|
-
|
|
1452
|
+
rb_hash_aset(form->components, PTR2NUM(co->co), RARRAY_PTR(components)[i]);
|
|
1349
1453
|
newtFormAddComponent(form->co, co->co);
|
|
1350
1454
|
}
|
|
1351
1455
|
return Qnil;
|
|
@@ -1399,13 +1503,16 @@ static VALUE rb_ext_Form_SetWidth(VALUE self, VALUE width)
|
|
|
1399
1503
|
|
|
1400
1504
|
static VALUE rb_ext_Form_Run(VALUE self)
|
|
1401
1505
|
{
|
|
1402
|
-
|
|
1403
|
-
|
|
1506
|
+
Widget_data *data;
|
|
1507
|
+
rb_newt_ExitStruct *rb_es;
|
|
1404
1508
|
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1509
|
+
INIT_GUARD();
|
|
1510
|
+
Get_Widget_Data(self, data);
|
|
1511
|
+
rb_es = ALLOC(rb_newt_ExitStruct);
|
|
1512
|
+
newtFormRun(data->co, &rb_es->es);
|
|
1513
|
+
rb_es->components = data->components;
|
|
1514
|
+
rb_gc_register_address(&rb_es->components);
|
|
1515
|
+
return Data_Wrap_Struct(cExitStruct, 0, rb_newt_es_free, rb_es);
|
|
1409
1516
|
}
|
|
1410
1517
|
|
|
1411
1518
|
static VALUE rb_ext_Form_DrawForm(VALUE self)
|
|
@@ -1457,7 +1564,9 @@ static VALUE rb_ext_Entry_new(int argc, VALUE *argv, VALUE self)
|
|
|
1457
1564
|
if (argc < 4 || argc > 5)
|
|
1458
1565
|
ARG_ERROR(argc, "4..5");
|
|
1459
1566
|
|
|
1567
|
+
INIT_GUARD();
|
|
1460
1568
|
flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
|
|
1569
|
+
|
|
1461
1570
|
co = newtEntry(NUM2INT(argv[0]), NUM2INT(argv[1]), StringValuePtr(argv[2]),
|
|
1462
1571
|
NUM2INT(argv[3]), NULL, flags);
|
|
1463
1572
|
|
|
@@ -1507,6 +1616,7 @@ static VALUE rb_ext_Entry_SetFilter(int argc, VALUE *argv, VALUE self)
|
|
|
1507
1616
|
|
|
1508
1617
|
Get_newtComponent(self, co);
|
|
1509
1618
|
cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
|
|
1619
|
+
rb_obj_freeze(cb);
|
|
1510
1620
|
rb_ivar_set(self, IVAR_FILTER_CALLBACK, cb);
|
|
1511
1621
|
newtEntrySetFilter(co, rb_ext_Entry_filter_function, (void *) cb);
|
|
1512
1622
|
return Qnil;
|
|
@@ -1558,6 +1668,7 @@ static VALUE rb_ext_Scale_new(VALUE self, VALUE left, VALUE top, VALUE width, VA
|
|
|
1558
1668
|
{
|
|
1559
1669
|
newtComponent co;
|
|
1560
1670
|
|
|
1671
|
+
INIT_GUARD();
|
|
1561
1672
|
co = newtScale(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(fullValue));
|
|
1562
1673
|
return Make_Widget(self, co);
|
|
1563
1674
|
}
|
|
@@ -1592,6 +1703,7 @@ static VALUE rb_ext_Grid_new(VALUE self, VALUE cols, VALUE rows)
|
|
|
1592
1703
|
if (num_cols <= 0 || num_rows <= 0)
|
|
1593
1704
|
rb_raise(rb_eRuntimeError, "specified number of columns or rows should be greater than 0");
|
|
1594
1705
|
|
|
1706
|
+
INIT_GUARD();
|
|
1595
1707
|
grid = newtCreateGrid(num_cols, num_rows);
|
|
1596
1708
|
widget = Data_Wrap_Struct(self, 0, 0, grid);
|
|
1597
1709
|
rb_ivar_set(widget, IVAR_COLS, cols);
|
|
@@ -1615,10 +1727,13 @@ static VALUE rb_ext_Grid_SetField(VALUE self, VALUE col, VALUE row, VALUE type,
|
|
|
1615
1727
|
if (icol >= cols || irow >= rows)
|
|
1616
1728
|
rb_raise(rb_eRuntimeError, "attempting to set a field at an invalid position (%d, %d)", icol, irow);
|
|
1617
1729
|
|
|
1618
|
-
|
|
1730
|
+
INIT_GUARD();
|
|
1731
|
+
if (itype == NEWT_GRID_SUBGRID) {
|
|
1619
1732
|
Data_Get_Struct(val, struct grid_s, co);
|
|
1620
|
-
else
|
|
1621
|
-
|
|
1733
|
+
} else {
|
|
1734
|
+
Get_Widget_Data(val, co);
|
|
1735
|
+
co = ((Widget_data *) co)->co;
|
|
1736
|
+
}
|
|
1622
1737
|
|
|
1623
1738
|
Data_Get_Struct(self, struct grid_s, grid);
|
|
1624
1739
|
newtGridSetField(grid, icol, irow, itype, co, NUM2INT(padLeft),
|
|
@@ -1636,6 +1751,7 @@ static VALUE rb_ext_Grid_WrappedWindow(int argc, VALUE *argv, VALUE self)
|
|
|
1636
1751
|
if (argc != 1 && argc != 3)
|
|
1637
1752
|
ARG_ERROR(argc, "1 or 3");
|
|
1638
1753
|
|
|
1754
|
+
INIT_GUARD();
|
|
1639
1755
|
title = StringValuePtr(argv[0]);
|
|
1640
1756
|
Data_Get_Struct(self, struct grid_s, grid);
|
|
1641
1757
|
if (argc == 1) {
|
|
@@ -1651,6 +1767,7 @@ static VALUE rb_ext_Grid_GetSize(VALUE self)
|
|
|
1651
1767
|
newtGrid grid;
|
|
1652
1768
|
int width, height;
|
|
1653
1769
|
|
|
1770
|
+
INIT_GUARD();
|
|
1654
1771
|
Data_Get_Struct(self, struct grid_s, grid);
|
|
1655
1772
|
newtGridGetSize(grid, &width, &height);
|
|
1656
1773
|
return rb_ary_new_from_args(2, INT2NUM(width), INT2NUM(height));
|
|
@@ -1658,12 +1775,15 @@ static VALUE rb_ext_Grid_GetSize(VALUE self)
|
|
|
1658
1775
|
|
|
1659
1776
|
void Init_ruby_newt(){
|
|
1660
1777
|
mNewt = rb_define_module("Newt");
|
|
1778
|
+
rb_define_module_function(mNewt, "init", rb_ext_Screen_Init, 0);
|
|
1779
|
+
rb_define_module_function(mNewt, "finish", rb_ext_Screen_Finished, 0);
|
|
1661
1780
|
rb_define_module_function(mNewt, "delay", rb_ext_Delay, 1);
|
|
1662
1781
|
rb_define_module_function(mNewt, "reflow_text", rb_ext_ReflowText, 4);
|
|
1663
1782
|
|
|
1664
1783
|
mScreen = rb_define_class_under(mNewt, "Screen", rb_cObject);
|
|
1665
|
-
|
|
1784
|
+
rb_define_alloc_func(mScreen, newt_s_alloc);
|
|
1666
1785
|
rb_define_module_function(mScreen, "init", rb_ext_Screen_Init, 0);
|
|
1786
|
+
rb_define_module_function(mScreen, "new", rb_ext_Screen_new, 0);
|
|
1667
1787
|
rb_define_module_function(mScreen, "cls", rb_ext_Screen_Cls, 0);
|
|
1668
1788
|
rb_define_module_function(mScreen, "finish", rb_ext_Screen_Finished, 0);
|
|
1669
1789
|
rb_define_module_function(mScreen, "wait_for_key", rb_ext_Screen_WaitForKey, 0);
|
|
@@ -1691,14 +1811,16 @@ void Init_ruby_newt(){
|
|
|
1691
1811
|
rb_define_module_function(mScreen, "win_menu", rb_ext_Screen_WinMenu, -2);
|
|
1692
1812
|
rb_define_module_function(mScreen, "win_entries", rb_ext_Screen_WinEntries, -2);
|
|
1693
1813
|
|
|
1694
|
-
rb_ext_sCallback = rb_struct_define(
|
|
1814
|
+
rb_ext_sCallback = rb_struct_define("NewtCallback", "widget", "context", "callback", "data", NULL);
|
|
1695
1815
|
|
|
1696
1816
|
cWidget = rb_define_class_under(mNewt, "Widget", rb_cObject);
|
|
1817
|
+
rb_define_alloc_func(cWidget, newt_s_alloc);
|
|
1697
1818
|
rb_define_method(cWidget, "callback", rb_ext_Widget_callback, -1);
|
|
1698
1819
|
rb_define_method(cWidget, "takes_focus", rb_ext_Widget_takesFocus, 1);
|
|
1699
1820
|
rb_define_method(cWidget, "get_position", rb_ext_Widget_GetPosition, 0);
|
|
1700
1821
|
rb_define_method(cWidget, "get_size", rb_ext_Widget_GetSize, 0);
|
|
1701
1822
|
rb_define_method(cWidget, "==", rb_ext_Widget_equal, 1);
|
|
1823
|
+
rb_define_method(cWidget, "inspect", rb_ext_Widget_inspect, 0);
|
|
1702
1824
|
|
|
1703
1825
|
cCompactButton = rb_define_class_under(mNewt, "CompactButton", cWidget);
|
|
1704
1826
|
rb_define_singleton_method(cCompactButton, "new", rb_ext_CompactButton_new, 3);
|
|
@@ -1782,6 +1904,7 @@ void Init_ruby_newt(){
|
|
|
1782
1904
|
rb_define_method(cForm, "watch_fd", rb_ext_Form_WatchFd, 2);
|
|
1783
1905
|
|
|
1784
1906
|
cExitStruct = rb_define_class_under(cForm, "ExitStruct", rb_cObject);
|
|
1907
|
+
rb_define_alloc_func(cExitStruct, newt_s_alloc);
|
|
1785
1908
|
rb_define_private_method(rb_singleton_class(cExitStruct), "new", NULL, 0);
|
|
1786
1909
|
rb_define_method(cExitStruct, "reason", rb_ext_ExitStruct_reason, 0);
|
|
1787
1910
|
rb_define_method(cExitStruct, "watch", rb_ext_ExitStruct_watch, 0);
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: newt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Noritsugu Nakamura
|
|
8
8
|
- Eric Sperano
|
|
9
9
|
- Lukas Zapletal
|
|
10
|
-
|
|
10
|
+
- Robert Gill
|
|
11
|
+
autorequire:
|
|
11
12
|
bindir: bin
|
|
12
13
|
cert_chain: []
|
|
13
|
-
date:
|
|
14
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
|
14
15
|
dependencies: []
|
|
15
16
|
description: Ruby bindings for newt TUI library
|
|
16
17
|
email: foreman-dev@googlegroups.com
|
|
@@ -66,7 +67,7 @@ homepage: https://github.com/theforeman/ruby-newt
|
|
|
66
67
|
licenses:
|
|
67
68
|
- MIT
|
|
68
69
|
metadata: {}
|
|
69
|
-
post_install_message:
|
|
70
|
+
post_install_message:
|
|
70
71
|
rdoc_options: []
|
|
71
72
|
require_paths:
|
|
72
73
|
- lib
|
|
@@ -78,13 +79,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
78
79
|
version: '0'
|
|
79
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
requirements:
|
|
81
|
-
- - "
|
|
82
|
+
- - ">="
|
|
82
83
|
- !ruby/object:Gem::Version
|
|
83
|
-
version:
|
|
84
|
+
version: '0'
|
|
84
85
|
requirements: []
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
signing_key:
|
|
86
|
+
rubygems_version: 3.5.9
|
|
87
|
+
signing_key:
|
|
88
88
|
specification_version: 4
|
|
89
89
|
summary: Ruby bindings for newt
|
|
90
90
|
test_files: []
|