newt 0.9.7 → 1.0.0.pre1

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 (81) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +24 -0
  3. data/examples/test-e.rb +108 -0
  4. data/examples/test-j.rb +50 -60
  5. data/examples/test_method/Button.rb +21 -0
  6. data/examples/test_method/Checkbox.rb +27 -0
  7. data/examples/test_method/CheckboxTree.rb +27 -0
  8. data/examples/test_method/CheckboxTreeMulti.rb +25 -0
  9. data/examples/test_method/CompactButton.rb +21 -0
  10. data/examples/test_method/Entry.rb +62 -0
  11. data/examples/test_method/Form.rb +23 -0
  12. data/examples/test_method/Form_ExitStruct.rb +35 -0
  13. data/examples/test_method/HelpCallback.rb +48 -0
  14. data/examples/test_method/Label.rb +26 -0
  15. data/examples/test_method/Listbox.rb +32 -0
  16. data/examples/test_method/Newt_FLAG_SCROLL.rb +3 -4
  17. data/examples/test_method/Newt_cursor.rb +30 -0
  18. data/examples/test_method/RadioButton.rb +23 -0
  19. data/examples/test_method/ReflowText.rb +8 -10
  20. data/examples/test_method/Scale.rb +27 -0
  21. data/examples/test_method/Screen_bell.rb +1 -1
  22. data/examples/test_method/Screen_cls.rb +1 -2
  23. data/examples/test_method/Screen_draw_roottext.rb +2 -3
  24. data/examples/test_method/Screen_init.rb +1 -2
  25. data/examples/test_method/Screen_pop_helpline.rb +2 -5
  26. data/examples/test_method/Screen_push_helpline.rb +2 -5
  27. data/examples/test_method/Screen_redraw_helpline.rb +2 -5
  28. data/examples/test_method/Screen_set_colors.rb +11 -13
  29. data/examples/test_method/Screen_size.rb +1 -1
  30. data/examples/test_method/Screen_win_menu.rb +3 -7
  31. data/examples/test_method/SuspendCallback.rb +33 -0
  32. data/examples/test_method/{Textbox_set_colors.rb → Textbox.rb} +8 -8
  33. data/examples/test_method/{TextboxReflowed_new.rb → TextboxReflowed.rb} +5 -8
  34. data/examples/test_method/Widget_callback.rb +76 -0
  35. data/examples/{memory.rb → test_method/memory.rb} +5 -5
  36. data/examples/testgrid-e.rb +80 -0
  37. data/examples/testgrid-j.rb +57 -62
  38. data/examples/testtree-e.rb +53 -0
  39. data/examples/testtree-j.rb +37 -39
  40. data/ext/ruby_newt/extconf.rb +3 -4
  41. data/ext/ruby_newt/ruby_newt.c +1001 -539
  42. data/lib/version.rb +1 -1
  43. metadata +31 -51
  44. data/examples/test.rb +0 -95
  45. data/examples/test_method/Button_new.rb +0 -22
  46. data/examples/test_method/Checkbox_get.rb +0 -25
  47. data/examples/test_method/Checkbox_new.rb +0 -22
  48. data/examples/test_method/Checkbox_set.rb +0 -28
  49. data/examples/test_method/Checkbox_set_flags.rb +0 -28
  50. data/examples/test_method/CompactButton_new.rb +0 -22
  51. data/examples/test_method/Entry_get.rb +0 -26
  52. data/examples/test_method/Entry_new.rb +0 -23
  53. data/examples/test_method/Entry_set.rb +0 -26
  54. data/examples/test_method/Entry_set_flags.rb +0 -31
  55. data/examples/test_method/Form_destroy.rb +0 -33
  56. data/examples/test_method/Form_set_background.rb +0 -23
  57. data/examples/test_method/Form_set_height.rb +0 -26
  58. data/examples/test_method/Form_set_width.rb +0 -26
  59. data/examples/test_method/Grid_new.rb +0 -26
  60. data/examples/test_method/Label_new.rb +0 -22
  61. data/examples/test_method/Label_setText.rb +0 -25
  62. data/examples/test_method/Label_set_colors.rb +0 -28
  63. data/examples/test_method/Listbox_clear.rb +0 -25
  64. data/examples/test_method/Listbox_current_bykey.rb +0 -29
  65. data/examples/test_method/Listbox_delete.rb +0 -27
  66. data/examples/test_method/Listbox_get_current.rb +0 -28
  67. data/examples/test_method/Listbox_get_current_string.rb +0 -28
  68. data/examples/test_method/Listbox_insert.rb +0 -24
  69. data/examples/test_method/Listbox_new.rb +0 -24
  70. data/examples/test_method/Listbox_select.rb +0 -27
  71. data/examples/test_method/Listbox_set.rb +0 -27
  72. data/examples/test_method/Listbox_set_current.rb +0 -26
  73. data/examples/test_method/Listbox_set_width.rb +0 -25
  74. data/examples/test_method/RadioButton_new.rb +0 -22
  75. data/examples/test_method/Scale_new.rb +0 -22
  76. data/examples/test_method/Scale_set.rb +0 -22
  77. data/examples/test_method/Textbox_get_num_lines.rb +0 -27
  78. data/examples/test_method/Textbox_new.rb +0 -22
  79. data/examples/test_method/Textbox_set_height.rb +0 -25
  80. data/examples/testgrid.rb +0 -84
  81. data/examples/testtree.rb +0 -54
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'newt'
5
+
6
+ Newt::Screen.new
7
+
8
+ checktree = Newt::CheckboxTreeMulti.new(-1, -1, 10, ' ab', Newt::FLAG_SCROLL)
9
+ checktree.add('Numbers', 2, 0, Newt::ARG_APPEND)
10
+ checktree.add('Really really long thing', 3, 0, Newt::ARG_APPEND)
11
+ checktree.add('number 5', 5, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
12
+ checktree.add('number 6', 6, 0, Newt::ARG_APPEND)
13
+ checktree.add('number 7', 7, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
14
+ checktree.add('number 8', 8, 0, Newt::ARG_APPEND)
15
+ checktree.add('number 9', 9, 0, Newt::ARG_APPEND)
16
+ checktree.add('number 10', 10, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
17
+ checktree.add('number 11', 11, 0, Newt::ARG_APPEND)
18
+ checktree.add('number 12', 12, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
19
+
20
+ checktree.add('Colors', 1, 0, 0)
21
+ checktree.add('Red', 100, 0, 0, Newt::ARG_APPEND)
22
+ checktree.add('White', 101, 0, 0, Newt::ARG_APPEND)
23
+ checktree.add('Blue', 102, 0, 0, Newt::ARG_APPEND)
24
+
25
+ checktree.add('number 4', 4, 0, 3)
26
+
27
+ checktree.add('Single digit', 200, 0, 1, Newt::ARG_APPEND)
28
+ checktree.add('One', 201, 0, 1, 0, Newt::ARG_APPEND)
29
+ checktree.add('Two', 202, 0, 1, 0, Newt::ARG_APPEND)
30
+ checktree.add('Three', 203, 0, 1, 0, Newt::ARG_APPEND)
31
+ checktree.add('Four', 204, 0, 1, 0, Newt::ARG_APPEND)
32
+
33
+ checktree.add('Double digit', 300, 0, 1, Newt::ARG_APPEND)
34
+ checktree.add('Ten', 210, 0, 1, 1, Newt::ARG_APPEND)
35
+ checktree.add('Eleven', 211, 0, 1, 1, Newt::ARG_APPEND)
36
+ checktree.add('Twelve', 212, 0, 1, 1, Newt::ARG_APPEND)
37
+ checktree.add('Thirteen', 213, 0, 1, 1, Newt::ARG_APPEND)
38
+
39
+ button = Newt::Button.new(-1, -1, 'Exit')
40
+
41
+ grid = Newt::Grid.new(1, 2)
42
+ grid.set_field(0, 0, Newt::GRID_COMPONENT, checktree, 0, 0, 0, 1,
43
+ Newt::ANCHOR_RIGHT, 0)
44
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, button, 0, 0, 0, 0, 0, 0)
45
+
46
+ grid.wrapped_window('Checkbox Tree Test')
47
+
48
+ form = Newt::Form.new
49
+ form.add(checktree, button)
50
+
51
+ form.run
52
+
53
+ Newt::Screen.finish
@@ -1,55 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require "newt"
4
+ require 'newt'
5
5
 
6
6
  Newt::Screen.new
7
7
 
8
- checktree = Newt::CheckboxTreeMulti.new(-1, -1, 10, " ab", Newt::FLAG_SCROLL)
9
- checktree.add("¥Ê¥ó¥Ð¡¼", 2, 0, Newt::ARG_APPEND)
10
- checktree.add("ËÜÅö¤ËËÜÅö¤ËŤ¤¥â¥Î", 3, 0, Newt::ARG_APPEND)
11
- checktree.add("¥Ê¥ó¥Ð¡¼£µ", 5, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
12
- checktree.add("¥Ê¥ó¥Ð¡¼£¶", 6, 0, Newt::ARG_APPEND)
13
- checktree.add("¥Ê¥ó¥Ð¡¼£·", 7, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
14
- checktree.add("¥Ê¥ó¥Ð¡¼£¸", 8, 0, Newt::ARG_APPEND)
15
- checktree.add("¥Ê¥ó¥Ð¡¼£¹", 9, 0, Newt::ARG_APPEND)
16
- checktree.add("¥Ê¥ó¥Ð¡¼£±£°", 10, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
17
- checktree.add("¥Ê¥ó¥Ð¡¼£±£±", 11, 0, Newt::ARG_APPEND)
18
- checktree.add("¥Ê¥ó¥Ð¡¼£±£²", 12, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
19
-
20
- checktree.add("¥«¥é¡¼", 1, 0, 0)
21
- checktree.add("ÀÖ¿§", 100, 0, 0, Newt::ARG_APPEND)
22
- checktree.add("Çò¿§", 101, 0, 0, Newt::ARG_APPEND)
23
- checktree.add("ÀÄ¿§", 102, 0, 0, Newt::ARG_APPEND)
24
-
25
- checktree.add("¥Ê¥ó¥Ð¡¼£´", 4, 0, 3)
26
-
27
- checktree.add("°ì·å¤Î¿ô»ú", 200, 0, 1, Newt::ARG_APPEND)
28
- checktree.add("°ì", 201, 0, 1, 0, Newt::ARG_APPEND)
29
- checktree.add("Æó", 202, 0, 1, 0, Newt::ARG_APPEND)
30
- checktree.add("»°", 203, 0, 1, 0, Newt::ARG_APPEND)
31
- checktree.add("»Í", 204, 0, 1, 0, Newt::ARG_APPEND)
32
-
33
- checktree.add("Æó·å¤Î¿ô»ú", 300, 0, 1, Newt::ARG_APPEND)
34
- checktree.add("½½", 210, 0, 1, 1, Newt::ARG_APPEND)
35
- checktree.add("½½°ì", 211, 0, 1, 1, Newt::ARG_APPEND)
36
- checktree.add("½½Æó", 212, 0, 1, 1, Newt::ARG_APPEND)
37
- checktree.add("½½»°", 213, 0, 1, 1, Newt::ARG_APPEND)
38
-
39
- button = Newt::Button.new(-1, -1, "½ªÎ»")
8
+ checktree = Newt::CheckboxTreeMulti.new(-1, -1, 10, ' ab', Newt::FLAG_SCROLL)
9
+ checktree.add('¥Ê¥ó¥Ð¡¼', 2, 0, Newt::ARG_APPEND)
10
+ checktree.add('ËÜÅö¤ËËÜÅö¤ËŤ¤¥â¥Î', 3, 0, Newt::ARG_APPEND)
11
+ checktree.add('¥Ê¥ó¥Ð¡¼£µ', 5, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
12
+ checktree.add('¥Ê¥ó¥Ð¡¼£¶', 6, 0, Newt::ARG_APPEND)
13
+ checktree.add('¥Ê¥ó¥Ð¡¼£·', 7, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
14
+ checktree.add('¥Ê¥ó¥Ð¡¼£¸', 8, 0, Newt::ARG_APPEND)
15
+ checktree.add('¥Ê¥ó¥Ð¡¼£¹', 9, 0, Newt::ARG_APPEND)
16
+ checktree.add('¥Ê¥ó¥Ð¡¼£±£°', 10, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
17
+ checktree.add('¥Ê¥ó¥Ð¡¼£±£±', 11, 0, Newt::ARG_APPEND)
18
+ checktree.add('¥Ê¥ó¥Ð¡¼£±£²', 12, Newt::FLAG_SELECTED, Newt::ARG_APPEND)
19
+
20
+ checktree.add('¥«¥é¡¼', 1, 0, 0)
21
+ checktree.add('ÀÖ¿§', 100, 0, 0, Newt::ARG_APPEND)
22
+ checktree.add('Çò¿§', 101, 0, 0, Newt::ARG_APPEND)
23
+ checktree.add('ÀÄ¿§', 102, 0, 0, Newt::ARG_APPEND)
24
+
25
+ checktree.add('¥Ê¥ó¥Ð¡¼£´', 4, 0, 3)
26
+
27
+ checktree.add('°ì·å¤Î¿ô»ú', 200, 0, 1, Newt::ARG_APPEND)
28
+ checktree.add('°ì', 201, 0, 1, 0, Newt::ARG_APPEND)
29
+ checktree.add('Æó', 202, 0, 1, 0, Newt::ARG_APPEND)
30
+ checktree.add('»°', 203, 0, 1, 0, Newt::ARG_APPEND)
31
+ checktree.add('»Í', 204, 0, 1, 0, Newt::ARG_APPEND)
32
+
33
+ checktree.add('Æó·å¤Î¿ô»ú', 300, 0, 1, Newt::ARG_APPEND)
34
+ checktree.add('½½', 210, 0, 1, 1, Newt::ARG_APPEND)
35
+ checktree.add('½½°ì', 211, 0, 1, 1, Newt::ARG_APPEND)
36
+ checktree.add('½½Æó', 212, 0, 1, 1, Newt::ARG_APPEND)
37
+ checktree.add('½½»°', 213, 0, 1, 1, Newt::ARG_APPEND)
38
+
39
+ button = Newt::Button.new(-1, -1, '½ªÎ»')
40
40
 
41
41
  grid = Newt::Grid.new(1, 2)
42
42
  grid.set_field(0, 0, Newt::GRID_COMPONENT, checktree, 0, 0, 0, 1,
43
- Newt::ANCHOR_RIGHT, 0)
44
- grid.set_field(0, 1, Newt::GRID_COMPONENT, button, 0, 0, 0, 0,
45
- 0, 0)
43
+ Newt::ANCHOR_RIGHT, 0)
44
+ grid.set_field(0, 1, Newt::GRID_COMPONENT, button, 0, 0, 0, 0, 0, 0)
46
45
 
47
- grid.wrapped_window("¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥Ä¥ê¡¼¥Æ¥¹¥È")
46
+ grid.wrapped_window('¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥Ä¥ê¡¼¥Æ¥¹¥È')
48
47
 
49
48
  form = Newt::Form.new
50
49
  form.add(checktree, button)
51
50
 
52
- answer = form.run()
51
+ form.run
53
52
 
54
53
  Newt::Screen.finish
55
-
@@ -1,10 +1,9 @@
1
1
  require 'mkmf'
2
2
 
3
- # TODO is slang really needed?
4
3
  dir_config('slang')
5
4
  dir_config('newt')
6
5
 
7
- have_library("slang", "SLsmg_refresh")
8
- have_library("newt", "newtInit")
6
+ have_library('slang', 'SLsmg_refresh')
7
+ have_library('newt', 'newtInit')
9
8
 
10
- create_makefile("ruby_newt/ruby_newt")
9
+ create_makefile('ruby_newt/ruby_newt')
@@ -2,16 +2,15 @@
2
2
  * Published under MIT license, see README.
3
3
  */
4
4
 
5
+ #include <stdbool.h>
5
6
  #include <ruby.h>
6
- #include <rubyio.h>
7
7
  #include <newt.h>
8
8
 
9
- #define SYMBOL(str) (ID2SYM(rb_intern(str)))
10
-
11
9
  static VALUE mNewt;
12
10
  static VALUE mScreen;
13
11
  static VALUE cWidget;
14
12
  static VALUE cForm;
13
+ static VALUE cExitStruct;
15
14
  static VALUE cLabel;
16
15
  static VALUE cCompactButton;
17
16
  static VALUE cButton;
@@ -27,38 +26,134 @@ static VALUE cEntry;
27
26
  static VALUE cScale;
28
27
  static VALUE cGrid;
29
28
 
30
- static ID rb_call_id;
31
- static VALUE rb_ext_Widget_CALLBACK_HASH;
29
+ static VALUE rb_ext_sCallback;
32
30
  static struct newtColors newtColors;
33
31
 
34
- typedef struct snackWidget_s snackWidget;
35
-
36
- struct callbackStruct {
37
- VALUE *cb, *data;
32
+ #define SYMBOL(str) (ID2SYM(rb_intern(str)))
33
+ #define PROC_CALL (rb_intern("call"))
34
+ #define RECEIVER(context) (rb_funcall((context), rb_intern("receiver"), 0))
35
+ #define IVAR_DATA (rb_intern("newt_ivar_data"))
36
+ #define IVAR_COLS (rb_intern("newt_ivar_cols"))
37
+ #define IVAR_ROWS (rb_intern("newt_ivar_rows"))
38
+ #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
+ #define IVAR_WIDGET_CALLBACK (rb_intern("newt_ivar_widget_callback"))
42
+
43
+ #define ARG_ERROR(given, expected) \
44
+ rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected %s)", \
45
+ (given), (expected))
46
+
47
+ #define FLAG_GC_FREE (1 << 0)
48
+ #define FLAG_ADDED_TO_FORM (1 << 1)
49
+
50
+ typedef struct Widget_data_s Widget_data;
51
+ struct Widget_data_s {
52
+ VALUE self;
53
+ VALUE components;
54
+ newtComponent co;
55
+ int flags;
38
56
  };
39
57
 
40
- struct snackWidget_s {
41
- newtComponent co;
42
- char achar;
43
- void * apointer;
44
- int anint;
45
- struct callbackStruct scs;
58
+ static void free_widget(void *ptr);
59
+ static void form_destroy(Widget_data *form);
60
+
61
+ static const rb_data_type_t Widget_type = {
62
+ "newtComponent",
63
+ { NULL, free_widget, NULL },
64
+ NULL, NULL,
65
+ RUBY_TYPED_FREE_IMMEDIATELY
46
66
  };
47
67
 
68
+ #define Make_Widget(klass, component) \
69
+ (widget_data_make((klass), (component), true))
70
+
71
+ #define Make_Widget_Ref(klass, component) \
72
+ (widget_data_make((klass), (component), false));
73
+
74
+ #define Get_Widget_Data(self, data) \
75
+ ((data) = widget_data_get((self)))
76
+
77
+ #define Get_newtComponent(self, component) do { \
78
+ Widget_data *data; \
79
+ Get_Widget_Data((self), data); \
80
+ (component) = data->co; \
81
+ } while (0)
82
+
83
+ static inline VALUE widget_data_make(VALUE klass, newtComponent co, bool gc_free)
84
+ {
85
+ Widget_data *data;
86
+ VALUE self = TypedData_Make_Struct(klass, Widget_data, &Widget_type, data);
87
+ data->self = self;
88
+ data->co = co;
89
+ data->flags |= gc_free;
90
+ return self;
91
+ }
92
+
93
+ static inline Widget_data *widget_data_get(VALUE self)
94
+ {
95
+ VALUE str;
96
+ Widget_data *data;
97
+
98
+ TypedData_Get_Struct(self, Widget_data, &Widget_type, data);
99
+ if (data == NULL) {
100
+ str = rb_inspect(self);
101
+ rb_raise(rb_eRuntimeError, "%s has already been destroyed",
102
+ StringValuePtr(str));
103
+ }
104
+ return data;
105
+ }
106
+
107
+ static void free_widget(void *ptr)
108
+ {
109
+ Widget_data *data = (Widget_data *) ptr;
110
+
111
+ if (rb_obj_is_kind_of(data->self, cForm)) {
112
+ form_destroy(data);
113
+ } else if (data->flags & FLAG_GC_FREE) {
114
+ newtComponentDestroy(data->co);
115
+ }
116
+ free(data);
117
+ }
118
+
119
+ static void form_destroy(Widget_data *form)
120
+ {
121
+ if (form->flags & FLAG_GC_FREE) newtFormDestroy(form->co);
122
+ rb_gc_unregister_address(&form->components);
123
+ }
124
+
125
+ #define Data_Attach(self, data) do { \
126
+ VALUE ivar = get_newt_ivar((self)); \
127
+ rb_ary_push(ivar, (data)); \
128
+ } while (0)
129
+
130
+ static inline VALUE get_newt_ivar(VALUE self) {
131
+ VALUE ivar_data;
132
+
133
+ if (rb_ivar_defined(self, IVAR_DATA)) {
134
+ ivar_data = rb_ivar_get(self, IVAR_DATA);
135
+ } else {
136
+ ivar_data = rb_ary_new();
137
+ rb_ivar_set(self, IVAR_DATA, ivar_data);
138
+ }
139
+ return ivar_data;
140
+ }
141
+
142
+ static VALUE rb_ext_Delay(VALUE self, VALUE usecs)
143
+ {
144
+ newtDelay(NUM2UINT(usecs));
145
+ return Qnil;
146
+ }
48
147
 
49
148
  static VALUE rb_ext_ReflowText(VALUE self, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp)
50
149
  {
51
- int actualWidth, actualHeight;
52
150
  char *p;
53
- VALUE ary = rb_ary_new2(3);
151
+ int actualWidth, actualHeight;
54
152
 
55
- p = newtReflowText(StringValuePtr(text), NUM2INT(width), NUM2INT(flexDown), NUM2INT(flexUp),
56
- &actualWidth, &actualHeight);
153
+ p = newtReflowText(StringValuePtr(text), NUM2INT(width), NUM2INT(flexDown),
154
+ NUM2INT(flexUp), &actualWidth, &actualHeight);
57
155
 
58
- rb_ary_push(ary, rb_str_new2(p));
59
- rb_ary_push(ary, INT2NUM(actualWidth));
60
- rb_ary_push(ary, INT2NUM(actualHeight));
61
- return ary;
156
+ return rb_ary_new_from_args(3, rb_str_new2(p), INT2NUM(actualWidth), INT2NUM(actualHeight));
62
157
  }
63
158
 
64
159
  static VALUE rb_ext_ColorSetCustom(VALUE self, VALUE id)
@@ -71,7 +166,6 @@ static VALUE rb_ext_Screen_new()
71
166
  newtInit();
72
167
  newtCls();
73
168
  memcpy(&newtColors, &newtDefaultColorPalette, sizeof(struct newtColors));
74
-
75
169
  return Qnil;
76
170
  }
77
171
 
@@ -91,29 +185,26 @@ static VALUE rb_ext_Screen_Cls()
91
185
  static VALUE rb_ext_Screen_Finished()
92
186
  {
93
187
  newtFinished();
94
-
95
188
  return Qnil;
96
189
  }
97
190
 
98
191
  static VALUE rb_ext_Screen_WaitForKey()
99
192
  {
100
193
  newtWaitForKey();
101
-
102
194
  return Qnil;
103
195
  }
104
196
 
105
197
  static VALUE rb_ext_Screen_ClearKeyBuffer()
106
198
  {
107
199
  newtClearKeyBuffer();
108
-
109
200
  return Qnil;
110
201
  }
111
202
 
112
203
  static VALUE rb_ext_Screen_OpenWindow(VALUE self, VALUE left, VALUE top,
113
204
  VALUE width, VALUE height, VALUE title)
114
205
  {
115
- return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top),
116
- NUM2INT(width), NUM2INT(height), StringValuePtr(title)));
206
+ return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top), NUM2INT(width),
207
+ NUM2INT(height), StringValuePtr(title)));
117
208
  }
118
209
 
119
210
  static VALUE rb_ext_Screen_CenteredWindow(VALUE self, VALUE width, VALUE height, VALUE title)
@@ -283,21 +374,18 @@ static VALUE rb_ext_Screen_SetColor(VALUE self, VALUE colorset, VALUE fg, VALUE
283
374
  static VALUE rb_ext_Screen_Resume()
284
375
  {
285
376
  newtResume();
286
-
287
377
  return Qnil;
288
378
  }
289
379
 
290
380
  static VALUE rb_ext_Screen_Suspend()
291
381
  {
292
382
  newtSuspend();
293
-
294
383
  return Qnil;
295
384
  }
296
385
 
297
386
  static VALUE rb_ext_Screen_Refresh()
298
387
  {
299
388
  newtRefresh();
300
-
301
389
  return Qnil;
302
390
  }
303
391
 
@@ -318,251 +406,390 @@ static VALUE rb_ext_Screen_PushHelpLine(VALUE self, VALUE text)
318
406
  static VALUE rb_ext_Screen_RedrawHelpLine(VALUE self)
319
407
  {
320
408
  newtRedrawHelpLine();
321
-
322
409
  return Qnil;
323
410
  }
324
411
 
325
412
  static VALUE rb_ext_Screen_PopHelpLine(VALUE self)
326
413
  {
327
414
  newtPopHelpLine();
328
-
329
415
  return Qnil;
330
416
  }
331
417
 
332
418
  static VALUE rb_ext_Screen_Bell(VALUE self)
333
419
  {
334
420
  newtBell();
421
+ return Qnil;
422
+ }
423
+
424
+ static VALUE rb_ext_Screen_CursorOff(VALUE self)
425
+ {
426
+ newtCursorOff();
427
+ return Qnil;
428
+ }
335
429
 
430
+ static VALUE rb_ext_Screen_CursorOn(VALUE self)
431
+ {
432
+ newtCursorOn();
336
433
  return Qnil;
337
434
  }
338
435
 
339
436
  static VALUE rb_ext_Screen_Size(VALUE self)
340
437
  {
341
438
  int cols, rows;
342
- VALUE ary = rb_ary_new2(2);
343
439
 
344
440
  newtGetScreenSize(&cols, &rows);
345
- rb_ary_push(ary, INT2NUM(cols));
346
- rb_ary_push(ary, INT2NUM(rows));
347
-
348
- return ary;
441
+ return rb_ary_new_from_args(2, INT2NUM(cols), INT2NUM(rows));
349
442
  }
350
443
 
351
- static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE args)
444
+ static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE title, VALUE button, VALUE text)
352
445
  {
353
- if (RARRAY_LEN(args) < 3) {
354
- rb_raise(rb_eArgError, "3 arguments required");
355
- } else {
356
-
357
- newtWinMessage(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]), StringValuePtr(RARRAY_PTR(args)[2]));
358
- }
359
-
446
+ newtWinMessage(StringValuePtr(title), StringValuePtr(button), StringValuePtr(text));
360
447
  return Qnil;
361
448
  }
362
449
 
363
- static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE args)
450
+ static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE title, VALUE button1, VALUE button2, VALUE text)
364
451
  {
365
- int result = 0;
366
-
367
- if (RARRAY_LEN(args) < 4) {
368
- rb_raise(rb_eArgError, "4 arguments required");
369
- } else {
370
- result = newtWinChoice(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
371
- StringValuePtr(RARRAY_PTR(args)[2]), StringValuePtr(RARRAY_PTR(args)[3]));
372
- }
373
-
452
+ int result;
453
+ result = newtWinChoice(StringValuePtr(title), StringValuePtr(button1),
454
+ StringValuePtr(button2), StringValuePtr(text));
374
455
  return INT2NUM(result);
375
456
  }
376
457
 
377
458
  static VALUE rb_ext_Screen_WinMenu(VALUE self, VALUE args)
378
459
  {
379
- long len;
380
- int i, listItem;
381
460
  char **cptr;
461
+ char *title, *text, *button1, *button2;
382
462
 
383
- len = RARRAY_LEN(args);
384
- if (len == 8) {
385
- Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
463
+ int len, i, listItem;
464
+ int width, flexDown, flexUp, maxHeight;
386
465
 
387
- len = RARRAY_LEN(RARRAY_PTR(args)[6]);
388
- cptr = ALLOCA_N(char*, len + 1);
389
- for (i = 0; i < len; i++) {
390
- Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
391
- cptr[i] = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
392
- }
393
- cptr[len] = NULL;
394
-
395
- newtWinMenu(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
396
- NUM2INT(RARRAY_PTR(args)[2]),
397
- NUM2INT(RARRAY_PTR(args)[3]), NUM2INT(RARRAY_PTR(args)[4]),
398
- NUM2INT(RARRAY_PTR(args)[5]),
399
- cptr, &listItem, StringValuePtr(RARRAY_PTR(args)[7]), NULL);
400
- return INT2NUM(listItem);
401
- } else if (len == 9) {
402
- Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
403
-
404
- len = RARRAY_LEN(RARRAY_PTR(args)[6]);
405
- cptr = ALLOCA_N(char*, len + 1);
406
- for (i = 0; i < len; i++) {
407
- Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
408
- cptr[i] = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
409
- }
410
- cptr[len] = NULL;
411
-
412
- newtWinMenu(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
413
- NUM2INT(RARRAY_PTR(args)[2]),
414
- NUM2INT(RARRAY_PTR(args)[3]), NUM2INT(RARRAY_PTR(args)[4]),
415
- NUM2INT(RARRAY_PTR(args)[5]),
416
- cptr, &listItem, StringValuePtr(RARRAY_PTR(args)[7]), StringValuePtr(RARRAY_PTR(args)[8]), NULL);
417
- return INT2NUM(listItem);
418
- } else {
419
- rb_raise(rb_eArgError, "8 or 9 arguments required");
466
+ len = RARRAY_LENINT(args);
467
+ if (len < 8 || len > 9)
468
+ ARG_ERROR(len, "8..9");
469
+
470
+ title = StringValuePtr(RARRAY_PTR(args)[0]);
471
+ text = StringValuePtr(RARRAY_PTR(args)[1]);
472
+ width = NUM2INT(RARRAY_PTR(args)[2]);
473
+ flexDown = NUM2INT(RARRAY_PTR(args)[3]);
474
+ flexUp = NUM2INT(RARRAY_PTR(args)[4]);
475
+ maxHeight = NUM2INT(RARRAY_PTR(args)[5]);
476
+
477
+ Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
478
+
479
+ len = RARRAY_LENINT(RARRAY_PTR(args)[6]);
480
+ cptr = ALLOCA_N(char*, len + 1);
481
+ for (i = 0; i < len; i++) {
482
+ Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
483
+ cptr[i] = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
420
484
  }
485
+ cptr[len] = NULL;
421
486
 
422
- return Qnil;
487
+ button1 = StringValuePtr(RARRAY_PTR(args)[7]);
488
+ button2 = (len == 9) ? StringValuePtr(RARRAY_PTR(args)[8]) : NULL;
489
+
490
+ newtWinMenu(title, text, width, flexDown, flexUp, maxHeight, cptr, &listItem, button1, button2, NULL);
491
+ return INT2NUM(listItem);
423
492
  }
424
493
 
425
494
  static VALUE rb_ext_Screen_WinEntries(VALUE self, VALUE args)
426
495
  {
427
- long len;
428
- int i;
429
- struct newtWinEntry *items;
430
- char * entries[10];
431
496
  VALUE ary;
432
-
497
+ struct newtWinEntry *items;
498
+ char *title, *text, *button1, *button2;
499
+ int len, i;
500
+ int width, flexDown, flexUp, dataWidth;
501
+ char *entries[10];
502
+
503
+ len = RARRAY_LENINT(args);
504
+ if (len < 8 || len > 9)
505
+ ARG_ERROR(len, "8..9");
506
+
507
+ title = StringValuePtr(RARRAY_PTR(args)[0]);
508
+ text = StringValuePtr(RARRAY_PTR(args)[1]);
509
+ width = NUM2INT(RARRAY_PTR(args)[2]);
510
+ flexDown = NUM2INT(RARRAY_PTR(args)[3]);
511
+ flexUp = NUM2INT(RARRAY_PTR(args)[4]);
512
+ dataWidth = NUM2INT(RARRAY_PTR(args)[5]);
513
+ button1 = StringValuePtr(RARRAY_PTR(args)[7]);
514
+ button2 = (len == 9) ? StringValuePtr(RARRAY_PTR(args)[8]) : NULL;
515
+
516
+ Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
517
+ len = RARRAY_LENINT(RARRAY_PTR(args)[6]);
518
+ if (len > 8) ARG_ERROR(len, "8 or less");
433
519
  memset(entries, 0, sizeof(entries));
520
+ items = ALLOCA_N(struct newtWinEntry, len + 1);
521
+ for (i = 0; i < len; i++) {
522
+ Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
523
+ items[i].text = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
524
+ items[i].value = entries + i;
525
+ items[i].flags = 0;
526
+ }
527
+ items[len].text = NULL;
528
+ items[len].value = NULL;
529
+ items[len].flags = 0;
530
+
434
531
  ary = rb_ary_new();
532
+ newtWinEntries(title, text, width, flexDown, flexUp, dataWidth, items, button1, button2, NULL);
533
+ for (i = 0; i < len; i++) { rb_ary_push(ary, rb_str_new2(entries[i])); }
534
+ return ary;
535
+ }
435
536
 
436
- len = RARRAY_LEN(args);
437
- if (len == 8) {
438
- Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
439
-
440
- len = RARRAY_LEN(RARRAY_PTR(args)[6]);
441
- if (len > 8) rb_raise(rb_eArgError, "8 or less arguments required");
442
- items = ALLOCA_N(struct newtWinEntry, len + 1);
443
- for (i = 0; i < len; i++) {
444
- Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
445
- items[i].text = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
446
- items[i].value = entries + i;
447
- items[i].flags = 0;
448
- }
449
- items[len].text = NULL;
450
- items[len].value = NULL;
451
- items[len].flags = 0;
452
-
453
- newtWinEntries(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
454
- NUM2INT(RARRAY_PTR(args)[2]),
455
- NUM2INT(RARRAY_PTR(args)[3]), NUM2INT(RARRAY_PTR(args)[4]),
456
- NUM2INT(RARRAY_PTR(args)[5]),
457
- items, StringValuePtr(RARRAY_PTR(args)[7]), NULL);
458
- for (i = 0; i < len; i++) {
459
- rb_ary_push(ary, rb_str_new2(entries[i]));
460
- }
461
- return ary;
462
- } else if (len == 9) {
463
- Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
464
-
465
- len = RARRAY_LEN(RARRAY_PTR(args)[6]);
466
- if (len > 8) rb_raise(rb_eArgError, "8 or less arguments required");
467
- items = ALLOCA_N(struct newtWinEntry, len + 1);
468
- for (i = 0; i < len; i++) {
469
- Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
470
- items[i].text = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
471
- items[i].value = entries + i;
472
- items[i].flags = 0;
473
- }
474
- items[len].text = NULL;
475
- items[len].value = NULL;
476
- items[len].flags = 0;
477
-
478
- newtWinEntries(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
479
- NUM2INT(RARRAY_PTR(args)[2]),
480
- NUM2INT(RARRAY_PTR(args)[3]), NUM2INT(RARRAY_PTR(args)[4]),
481
- NUM2INT(RARRAY_PTR(args)[5]),
482
- items, StringValuePtr(RARRAY_PTR(args)[7]), StringValuePtr(RARRAY_PTR(args)[8]), NULL);
483
- for (i = 0; i < len; i++) {
484
- rb_ary_push(ary, rb_str_new2(entries[i]));
485
- }
486
- return ary;
537
+ void rb_ext_Screen_suspend_callback_function(void *cb)
538
+ {
539
+ VALUE context, callback, data;
540
+
541
+ context = RSTRUCT_GET((VALUE) cb, 1);
542
+ callback = RSTRUCT_GET((VALUE) cb, 2);
543
+ data = RSTRUCT_GET((VALUE) cb, 3);
544
+
545
+ if (SYMBOL_P(callback)) {
546
+ rb_funcall(RECEIVER(context), SYM2ID(callback), 1, data);
487
547
  } else {
488
- rb_raise(rb_eArgError, "8 or 9 arguments required");
548
+ rb_funcall(callback, PROC_CALL, 1, data);
489
549
  }
550
+ }
490
551
 
491
- return Qnil;
552
+ void rb_ext_Screen_help_callback_function(newtComponent co, void *data)
553
+ {
554
+ VALUE widget, cb;
555
+ VALUE context, callback;
556
+
557
+ widget = Make_Widget_Ref(cForm, co);
558
+ cb = rb_ivar_get(mScreen, IVAR_HELP_CALLBACK);
559
+ context = RSTRUCT_GET((VALUE) cb, 1);
560
+ callback = RSTRUCT_GET((VALUE) cb, 2);
561
+
562
+ if (SYMBOL_P(callback)) {
563
+ rb_funcall(RECEIVER(context), SYM2ID(callback), 2, widget, (VALUE) data);
564
+ } else {
565
+ rb_funcall(callback, PROC_CALL, 2, widget, (VALUE) data);
566
+ }
492
567
  }
493
568
 
494
- void
495
- rb_ext_Widget_callback_function(newtComponent co, void *proc)
569
+ void rb_ext_Widget_callback_function(newtComponent co, void *cb)
496
570
  {
497
- VALUE widget;
571
+ VALUE widget, context, callback, data;
498
572
 
499
- widget = Data_Wrap_Struct(cWidget, 0, 0, co);
500
- if(SYMBOL_P(proc)){
501
- rb_funcall(rb_mKernel, SYM2ID((VALUE)proc), 1, widget);
573
+ widget = RSTRUCT_GET((VALUE) cb, 0);
574
+ context = RSTRUCT_GET((VALUE) cb, 1);
575
+ callback = RSTRUCT_GET((VALUE) cb, 2);
576
+ data = RSTRUCT_GET((VALUE) cb, 3);
577
+
578
+ if (SYMBOL_P(callback)) {
579
+ rb_funcall(RECEIVER(context), SYM2ID(callback), 2, widget, data);
580
+ } else {
581
+ rb_funcall(callback, PROC_CALL, 2, widget, data);
502
582
  }
503
- else{
504
- rb_funcall((VALUE)proc, rb_call_id, 1, widget);
505
- };
506
- };
583
+ }
584
+
585
+ int rb_ext_Entry_filter_function(newtComponent co, void *cb, int ch, int cursor)
586
+ {
587
+ VALUE widget, context, callback, data;
588
+ VALUE vch, vcursor;
589
+ VALUE rv;
590
+
591
+ widget = RSTRUCT_GET((VALUE) cb, 0);
592
+ context = RSTRUCT_GET((VALUE) cb, 1);
593
+ callback = RSTRUCT_GET((VALUE) cb, 2);
594
+ data = RSTRUCT_GET((VALUE) cb, 3);
595
+ vch = INT2NUM(ch);
596
+ vcursor = INT2NUM(cursor);
597
+
598
+ if (SYMBOL_P(callback)) {
599
+ rv = rb_funcall(RECEIVER(context), SYM2ID(callback), 4, widget, data, vch, vcursor);
600
+ } else {
601
+ rv = rb_funcall(callback, PROC_CALL, 4, widget, data, vch, vcursor);
602
+ }
603
+ return (NIL_P(rv) || !RB_TYPE_P(rv, T_FIXNUM)) ? 0 : NUM2INT(rv);
604
+ }
507
605
 
508
- static VALUE rb_ext_Widget_callback(int argc, VALUE argv[], VALUE self)
606
+ static VALUE rb_ext_Screen_SuspendCallback(int argc, VALUE *argv, VALUE self)
607
+ {
608
+ VALUE cb, data = Qnil;
609
+
610
+ if (argc < 1 || argc > 2)
611
+ ARG_ERROR(argc, "1 or 2");
612
+
613
+ if (argc == 2)
614
+ data = argv[1];
615
+
616
+ cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
617
+ rb_ivar_set(self, IVAR_SUSPEND_CALLBACK, cb);
618
+ newtSetSuspendCallback(rb_ext_Screen_suspend_callback_function, (void *) cb);
619
+ return Qnil;
620
+ }
621
+
622
+ static VALUE rb_ext_Screen_HelpCallback(VALUE self, VALUE cb)
623
+ {
624
+ cb = rb_struct_new(rb_ext_sCallback, Qnil, rb_binding_new(), cb, Qnil, NULL);
625
+ rb_ivar_set(self, IVAR_HELP_CALLBACK, cb);
626
+ newtSetHelpCallback(rb_ext_Screen_help_callback_function);
627
+ return Qnil;
628
+ }
629
+
630
+ static VALUE rb_ext_Widget_callback(int argc, VALUE *argv, VALUE self)
509
631
  {
510
632
  newtComponent co;
511
- VALUE arg1, value;
633
+ VALUE cb, data = Qnil;
512
634
 
513
- Data_Get_Struct(self, struct newtComponent_struct, co);
514
- switch(rb_scan_args(argc, argv, "01", &arg1)){
515
- case 0:
516
- value = rb_hash_aref(rb_ext_Widget_CALLBACK_HASH, self);
517
- break;
518
- case 1:
519
- rb_hash_aset(rb_ext_Widget_CALLBACK_HASH, self, arg1);
520
- newtComponentAddCallback(co, rb_ext_Widget_callback_function, (void*)arg1);
521
- value = Qnil;
522
- break;
523
- default:
524
- rb_bug("rb_ext_Widget_callback");
525
- };
635
+ if (argc < 1 || argc > 2)
636
+ ARG_ERROR(argc, "1 or 2");
526
637
 
527
- return value;
638
+ if (argc == 2)
639
+ data = argv[1];
640
+
641
+ Get_newtComponent(self, co);
642
+ cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
643
+ rb_ivar_set(self, IVAR_WIDGET_CALLBACK, cb);
644
+ newtComponentAddCallback(co, rb_ext_Widget_callback_function, (void *) cb);
645
+ return Qnil;
528
646
  }
529
647
 
530
648
  static VALUE rb_ext_Widget_takesFocus(VALUE self, VALUE index)
531
649
  {
532
- newtComponent form;
650
+ newtComponent co;
533
651
 
534
- Data_Get_Struct(self, struct newtComponent_struct, form);
535
- newtComponentTakesFocus(form, NUM2INT(index));
652
+ Get_newtComponent(self, co);
653
+ newtComponentTakesFocus(co, NUM2INT(index));
536
654
  return Qnil;
537
655
  }
538
656
 
539
- static VALUE rb_ext_Widget_equal(VALUE self, VALUE widget)
657
+ static VALUE rb_ext_Widget_GetPosition(VALUE self)
540
658
  {
541
- newtComponent co, co2;
659
+ newtComponent co;
660
+ int left, top;
542
661
 
543
- if (NIL_P(widget)) return Qfalse;
544
- if (self == widget) return Qtrue;
662
+ Get_newtComponent(self, co);
663
+ newtComponentGetPosition(co, &left, &top);
664
+ return rb_ary_new_from_args(2, INT2NUM(left), INT2NUM(top));
665
+ }
545
666
 
546
- Data_Get_Struct(self, struct newtComponent_struct, co);
547
- Data_Get_Struct(widget, struct newtComponent_struct, co2);
548
- if (co == co2) return Qtrue;
667
+ static VALUE rb_ext_Widget_GetSize(VALUE self)
668
+ {
669
+ newtComponent co;
670
+ int width, height;
671
+
672
+ Get_newtComponent(self, co);
673
+ newtComponentGetSize(co, &width, &height);
674
+ return rb_ary_new_from_args(2, INT2NUM(width), INT2NUM(height));
675
+ }
676
+
677
+ static VALUE rb_ext_Widget_equal(VALUE self, VALUE obj)
678
+ {
679
+ newtComponent co, cco;
680
+ void *data;
681
+
682
+ if (NIL_P(obj)) return Qfalse;
683
+ if (self == obj) return Qtrue;
684
+
685
+ if (rb_obj_is_kind_of(obj, cWidget) || rb_obj_is_kind_of(obj, cExitStruct)) {
686
+ Get_newtComponent(self, co);
687
+ if (rb_obj_is_kind_of(obj, cExitStruct)) {
688
+ Data_Get_Struct(obj, struct newtExitStruct, data);
689
+ if (co == ((struct newtExitStruct *) data)->u.co)
690
+ return Qtrue;
691
+ } else {
692
+ Get_newtComponent(obj, cco);
693
+ if (co == cco) return Qtrue;
694
+ }
695
+ }
549
696
  return Qfalse;
550
697
  }
551
698
 
699
+ static VALUE rb_ext_ExitStruct_reason(VALUE self)
700
+ {
701
+ struct newtExitStruct *es;
702
+
703
+ Data_Get_Struct(self, struct newtExitStruct, es);
704
+ return INT2NUM(es->reason);
705
+ }
706
+
707
+ static VALUE rb_ext_ExitStruct_watch(VALUE self)
708
+ {
709
+ struct newtExitStruct *es;
710
+
711
+ Data_Get_Struct(self, struct newtExitStruct, es);
712
+ if (es->reason == NEWT_EXIT_FDREADY)
713
+ return INT2NUM(es->u.watch);
714
+ else
715
+ return Qnil;
716
+ }
717
+
718
+ static VALUE rb_ext_ExitStruct_key(VALUE self)
719
+ {
720
+ struct newtExitStruct *es;
721
+
722
+ Data_Get_Struct(self, struct newtExitStruct, es);
723
+ if (es->reason == NEWT_EXIT_HOTKEY)
724
+ return INT2NUM(es->u.key);
725
+ else
726
+ return Qnil;
727
+ }
728
+
729
+ static VALUE rb_ext_ExitStruct_component(VALUE self)
730
+ {
731
+ struct newtExitStruct *es;
732
+
733
+ Data_Get_Struct(self, struct newtExitStruct, es);
734
+ if (es->reason == NEWT_EXIT_COMPONENT)
735
+ return Make_Widget(cWidget, es->u.co);
736
+ else
737
+ return Qnil;
738
+ }
739
+
740
+ static VALUE rb_ext_ExitStruct_equal(VALUE self, VALUE obj)
741
+ {
742
+ struct newtExitStruct *es;
743
+ newtComponent co;
744
+
745
+ if (NIL_P(obj)) return Qfalse;
746
+ if (self == obj) return Qtrue;
747
+
748
+ /* Compare components for backwards compatibility with newtRunForm(). */
749
+ if (rb_obj_is_kind_of(obj, cWidget)) {
750
+ Data_Get_Struct(self, struct newtExitStruct, es);
751
+ Get_newtComponent(obj, co);
752
+ if (es->reason == NEWT_EXIT_COMPONENT && es->u.co == co) return Qtrue;
753
+ }
754
+ return Qfalse;
755
+ }
756
+
757
+ static VALUE rb_ext_ExitStruct_inspect(VALUE self)
758
+ {
759
+ struct newtExitStruct *es;
760
+ VALUE classname = rb_class_name(rb_obj_class(self));
761
+ char *class = StringValuePtr(classname);
762
+
763
+ Data_Get_Struct(self, struct newtExitStruct, es);
764
+ switch(es->reason) {
765
+ case NEWT_EXIT_HOTKEY:
766
+ return rb_sprintf("#<%s reason=%d, key=%d>", class, es->reason, es->u.key);
767
+ case NEWT_EXIT_COMPONENT:
768
+ return rb_sprintf("#<%s reason=%d, component=%p>", class, es->reason, es->u.co);
769
+ case NEWT_EXIT_FDREADY:
770
+ return rb_sprintf("#<%s reason=%d, watch=%d>", class, es->reason, es->u.watch);
771
+ case NEWT_EXIT_TIMER:
772
+ case NEWT_EXIT_ERROR:
773
+ return rb_sprintf("#<%s reason=%d>", class, es->reason);
774
+ default:
775
+ return rb_call_super(0, NULL);
776
+ }
777
+ }
778
+
552
779
  static VALUE rb_ext_Label_new(VALUE self, VALUE left, VALUE top, VALUE text)
553
780
  {
554
781
  newtComponent co;
555
782
 
556
783
  co = newtLabel(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
557
- return Data_Wrap_Struct(self, 0, 0, co);
784
+ return Make_Widget(self, co);
558
785
  }
559
786
 
560
787
  static VALUE rb_ext_Label_SetText(VALUE self, VALUE text)
561
788
  {
562
- newtComponent co;
789
+ Widget_data *data;
563
790
 
564
- Data_Get_Struct(self, struct newtComponent_struct, co);
565
- newtLabelSetText(co, StringValuePtr(text));
791
+ Get_Widget_Data(self, data);
792
+ newtLabelSetText(data->co, StringValuePtr(text));
566
793
  return Qnil;
567
794
  }
568
795
 
@@ -570,7 +797,7 @@ static VALUE rb_ext_Label_SetColors(VALUE self, VALUE colorset)
570
797
  {
571
798
  newtComponent co;
572
799
 
573
- Data_Get_Struct(self, struct newtComponent_struct, co);
800
+ Get_newtComponent(self, co);
574
801
  newtLabelSetColors(co, NUM2INT(colorset));
575
802
  return Qnil;
576
803
  }
@@ -580,7 +807,7 @@ static VALUE rb_ext_CompactButton_new(VALUE self, VALUE left, VALUE top, VALUE t
580
807
  newtComponent co;
581
808
 
582
809
  co = newtCompactButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
583
- return Data_Wrap_Struct(self, 0, 0, co);
810
+ return Make_Widget(self, co);
584
811
  }
585
812
 
586
813
  static VALUE rb_ext_Button_new(VALUE self, VALUE left, VALUE top, VALUE text)
@@ -588,30 +815,34 @@ static VALUE rb_ext_Button_new(VALUE self, VALUE left, VALUE top, VALUE text)
588
815
  newtComponent co;
589
816
 
590
817
  co = newtButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text));
591
- return Data_Wrap_Struct(self, 0, 0, co);
818
+ return Make_Widget(self, co);
592
819
  }
593
820
 
594
- static VALUE rb_ext_Checkbox_new(VALUE self, VALUE left, VALUE top, VALUE text,
595
- VALUE defValue, VALUE seq)
821
+ static VALUE rb_ext_Checkbox_new(int argc, VALUE *argv, VALUE self)
596
822
  {
597
823
  newtComponent co;
824
+ const char *seq = NULL;
825
+ char defValue = 0;
598
826
 
599
- if (NIL_P(seq)) {
600
- co = newtCheckbox(NUM2INT(left), NUM2INT(top), StringValuePtr(text),
601
- StringValuePtr(defValue)[0], NULL, NULL);
602
- } else {
603
- co = newtCheckbox(NUM2INT(left), NUM2INT(top), StringValuePtr(text),
604
- StringValuePtr(defValue)[0], StringValuePtr(seq), NULL);
605
- }
606
- return Data_Wrap_Struct(self, 0, 0, co);
827
+ if (argc < 3 || argc > 5)
828
+ ARG_ERROR(argc, "3..5");
829
+
830
+ if (argc > 3 && !NIL_P(argv[3]))
831
+ defValue = StringValuePtr(argv[3])[0];
832
+
833
+ if (argc == 5 && !NIL_P(argv[4]) && RSTRING_LEN(argv[4]) > 0)
834
+ seq = StringValuePtr(argv[4]);
835
+
836
+ co = newtCheckbox(NUM2INT(argv[0]), NUM2INT(argv[1]), StringValuePtr(argv[2]), defValue, seq, NULL);
837
+ return Make_Widget(self, co);
607
838
  }
608
839
 
609
840
  static VALUE rb_ext_Checkbox_GetValue(VALUE self)
610
841
  {
611
842
  newtComponent co;
612
- char value[10];
843
+ char value[2];
613
844
 
614
- Data_Get_Struct(self, struct newtComponent_struct, co);
845
+ Get_newtComponent(self, co);
615
846
  value[0] = newtCheckboxGetValue(co);
616
847
  value[1] = '\0';
617
848
  return rb_str_new2(value);
@@ -621,77 +852,91 @@ static VALUE rb_ext_Checkbox_SetValue(VALUE self, VALUE value)
621
852
  {
622
853
  newtComponent co;
623
854
 
624
- Data_Get_Struct(self, struct newtComponent_struct, co);
855
+ Get_newtComponent(self, co);
625
856
  if (RSTRING_LEN(value) > 0) {
626
857
  newtCheckboxSetValue(co, StringValuePtr(value)[0]);
627
858
  }
628
859
  return Qnil;
629
860
  }
630
861
 
631
- static VALUE rb_ext_Checkbox_SetFlags(VALUE self, VALUE args)
862
+ static VALUE rb_ext_Checkbox_SetFlags(int argc, VALUE *argv, VALUE self)
632
863
  {
633
864
  newtComponent co;
634
- long len;
635
-
636
- len = RARRAY_LEN(args);
637
- if (len == 1) {
638
- Data_Get_Struct(self, struct newtComponent_struct, co);
639
- newtCheckboxSetFlags(co, NUM2INT(RARRAY_PTR(args)[0]), NEWT_FLAGS_SET);
640
- } else if (len == 2) {
641
- Data_Get_Struct(self, struct newtComponent_struct, co);
642
- newtCheckboxSetFlags(co, NUM2INT(RARRAY_PTR(args)[0]), NUM2INT(RARRAY_PTR(args)[1]));
643
- } else {
644
- rb_raise(rb_eArgError, "1 argument or 2 arguments required");
645
- }
865
+ int sense = NEWT_FLAGS_SET;
866
+
867
+ if (argc < 1 || argc > 2)
868
+ ARG_ERROR(argc, "1..2");
869
+
870
+ if (argc == 2)
871
+ sense = NUM2INT(argv[1]);
646
872
 
873
+ Get_newtComponent(self, co);
874
+ newtCheckboxSetFlags(co, NUM2INT(argv[0]), sense);
647
875
  return Qnil;
648
876
  }
649
877
 
650
- static VALUE rb_ext_RadioButton_new(VALUE self, VALUE left, VALUE top, VALUE text,
651
- VALUE isDefault, VALUE prevButton)
878
+ static VALUE rb_ext_RadioButton_new(int argc, VALUE *argv, VALUE self)
879
+ {
880
+ newtComponent co, cco = NULL;
881
+ int is_default = 0;
882
+
883
+ if (argc < 3 || argc > 5)
884
+ ARG_ERROR(argc, "3..5");
885
+
886
+ if (argc >= 4)
887
+ is_default = NUM2INT(argv[3]);
888
+
889
+ if (argc == 5 && argv[4] != Qnil)
890
+ Get_newtComponent(argv[4], cco);
891
+
892
+ co = newtRadiobutton(NUM2INT(argv[0]), NUM2INT(argv[1]), StringValuePtr(argv[2]), is_default, cco);
893
+ return Make_Widget(self, co);
894
+ }
895
+
896
+ static VALUE rb_ext_RadioButton_GetCurrent(VALUE self)
652
897
  {
653
898
  newtComponent co, cco;
654
899
 
655
- if (NIL_P(prevButton)) {
656
- co = newtRadiobutton(NUM2INT(left), NUM2INT(top), StringValuePtr(text),
657
- NUM2INT(isDefault), NULL);
658
- } else {
659
- Data_Get_Struct(prevButton, struct newtComponent_struct, cco);
660
- co = newtRadiobutton(NUM2INT(left), NUM2INT(top), StringValuePtr(text),
661
- NUM2INT(isDefault), cco);
662
- }
663
- return Data_Wrap_Struct(self, 0, 0, co);
900
+ Get_newtComponent(self, co);
901
+ cco = newtRadioGetCurrent(co);
902
+ return Make_Widget_Ref(cRadioButton, cco);
664
903
  }
665
904
 
666
- static VALUE rb_ext_Listbox_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags)
905
+ static VALUE rb_ext_RadioButton_SetCurrent(VALUE self)
667
906
  {
668
907
  newtComponent co;
669
908
 
670
- co = newtListbox(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags));
671
- return Data_Wrap_Struct(self, 0, 0, co);
909
+ Get_newtComponent(self, co);
910
+ newtRadioSetCurrent(co);
911
+ return Qnil;
672
912
  }
673
913
 
674
- static VALUE rb_ext_Listbox_GetCurrentAsNumber(VALUE self)
914
+ static VALUE rb_ext_Listbox_new(int argc, VALUE *argv, VALUE self)
675
915
  {
676
916
  newtComponent co;
917
+ int flags;
677
918
 
678
- Data_Get_Struct(self, struct newtComponent_struct, co);
679
- return INT2NUM((int *) newtListboxGetCurrent(co));
919
+ if (argc < 3 || argc > 4)
920
+ ARG_ERROR(argc, "3..4");
921
+
922
+ flags = (argc == 4) ? NUM2INT(argv[3]) : 0;
923
+ co = newtListbox(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), flags);
924
+ return Make_Widget(self, co);
680
925
  }
681
926
 
682
- static VALUE rb_ext_Listbox_GetCurrentAsString(VALUE self)
927
+ static VALUE rb_ext_Listbox_GetCurrent(VALUE self)
683
928
  {
684
929
  newtComponent co;
685
930
 
686
- Data_Get_Struct(self, struct newtComponent_struct, co);
687
- return rb_str_new2((char *) newtListboxGetCurrent(co));
931
+ Get_newtComponent(self, co);
932
+ return (VALUE) newtListboxGetCurrent(co);
688
933
  }
689
934
 
690
935
  static VALUE rb_ext_Listbox_SetCurrent(VALUE self, VALUE num)
691
936
  {
692
937
  newtComponent co;
693
938
 
694
- Data_Get_Struct(self, struct newtComponent_struct, co);
939
+ Get_newtComponent(self, co);
695
940
  newtListboxSetCurrent(co, NUM2INT(num));
696
941
  return Qnil;
697
942
  }
@@ -700,27 +945,26 @@ static VALUE rb_ext_Listbox_SetCurrentByKey(VALUE self, VALUE key)
700
945
  {
701
946
  newtComponent co;
702
947
 
703
- Data_Get_Struct(self, struct newtComponent_struct, co);
704
-
705
- switch(TYPE(key)) {
706
- case T_STRING:
707
- newtListboxSetCurrentByKey(co, (void *)StringValuePtr(key));
708
- break;
709
- case T_FIXNUM:
710
- newtListboxSetCurrentByKey(co, (void *)NUM2INT(key));
711
- break;
712
- default:
713
- rb_raise(rb_eTypeError, "String or Fixnum expected");
714
- break;
715
- }
948
+ Get_newtComponent(self, co);
949
+ newtListboxSetCurrentByKey(co, (void *) key);
716
950
  return Qnil;
717
951
  }
718
952
 
953
+ static VALUE rb_ext_Listbox_GetEntry(VALUE self, VALUE num)
954
+ {
955
+ char *text; void *data;
956
+ newtComponent co;
957
+
958
+ Get_newtComponent(self, co);
959
+ newtListboxGetEntry(co, NUM2INT(num), &text, &data);
960
+ return rb_ary_new_from_args(2, rb_str_new2(text), (VALUE *) data);
961
+ }
962
+
719
963
  static VALUE rb_ext_Listbox_SetEntry(VALUE self, VALUE num, VALUE text)
720
964
  {
721
965
  newtComponent co;
722
966
 
723
- Data_Get_Struct(self, struct newtComponent_struct, co);
967
+ Get_newtComponent(self, co);
724
968
  newtListboxSetEntry(co, NUM2INT(num), StringValuePtr(text));
725
969
  return Qnil;
726
970
  }
@@ -729,7 +973,7 @@ static VALUE rb_ext_Listbox_SetWidth(VALUE self, VALUE width)
729
973
  {
730
974
  newtComponent co;
731
975
 
732
- Data_Get_Struct(self, struct newtComponent_struct, co);
976
+ Get_newtComponent(self, co);
733
977
  newtListboxSetWidth(co, NUM2INT(width));
734
978
  return Qnil;
735
979
  }
@@ -738,19 +982,9 @@ static VALUE rb_ext_Listbox_SetData(VALUE self, VALUE num, VALUE data)
738
982
  {
739
983
  newtComponent co;
740
984
 
741
- Data_Get_Struct(self, struct newtComponent_struct, co);
742
-
743
- switch(TYPE(data)) {
744
- case T_STRING:
745
- newtListboxSetData(co, NUM2INT(num), (void *)StringValuePtr(data));
746
- break;
747
- case T_FIXNUM:
748
- newtListboxSetData(co, NUM2INT(num), (void *)NUM2INT(data));
749
- break;
750
- default:
751
- rb_raise(rb_eTypeError, "String or Fixnum expected");
752
- break;
753
- }
985
+ Get_newtComponent(self, co);
986
+ Data_Attach(self, data);
987
+ newtListboxSetData(co, NUM2INT(num), (void *) data);
754
988
  return Qnil;
755
989
  }
756
990
 
@@ -758,19 +992,9 @@ static VALUE rb_ext_Listbox_AppendEntry(VALUE self, VALUE text, VALUE data)
758
992
  {
759
993
  newtComponent co;
760
994
 
761
- Data_Get_Struct(self, struct newtComponent_struct, co);
762
-
763
- switch(TYPE(data)) {
764
- case T_STRING:
765
- newtListboxAppendEntry(co, StringValuePtr(text), (void *)StringValuePtr(data));
766
- break;
767
- case T_FIXNUM:
768
- newtListboxAppendEntry(co, StringValuePtr(text), (void *)NUM2INT(data));
769
- break;
770
- default:
771
- rb_raise(rb_eTypeError, "String or Fixnum expected");
772
- break;
773
- }
995
+ Get_newtComponent(self, co);
996
+ Data_Attach(self, data);
997
+ newtListboxAppendEntry(co, StringValuePtr(text), (void *) data);
774
998
  return Qnil;
775
999
  }
776
1000
 
@@ -778,38 +1002,9 @@ static VALUE rb_ext_Listbox_InsertEntry(VALUE self, VALUE text, VALUE data, VALU
778
1002
  {
779
1003
  newtComponent co;
780
1004
 
781
- Data_Get_Struct(self, struct newtComponent_struct, co);
782
-
783
- switch(TYPE(data)) {
784
- case T_STRING:
785
- switch(TYPE(key)) {
786
- case T_STRING:
787
- newtListboxInsertEntry(co, StringValuePtr(text), (void *)StringValuePtr(data), (void *)StringValuePtr(key));
788
- break;
789
- case T_FIXNUM:
790
- newtListboxInsertEntry(co, StringValuePtr(text), (void *)StringValuePtr(data), (void *)NUM2INT(key));
791
- break;
792
- default:
793
- rb_raise(rb_eTypeError, "String or Fixnum expected");
794
- break;
795
- }
796
- case T_FIXNUM:
797
- switch(TYPE(key)) {
798
- case T_STRING:
799
- newtListboxInsertEntry(co, StringValuePtr(text), (void *)NUM2INT(data), (void *)StringValuePtr(key));
800
- break;
801
- case T_FIXNUM:
802
- newtListboxInsertEntry(co, StringValuePtr(text), (void *)NUM2INT(data), (void *)NUM2INT(key));
803
- break;
804
- default:
805
- rb_raise(rb_eTypeError, "String or Fixnum expected");
806
- break;
807
- }
808
- break;
809
- default:
810
- rb_raise(rb_eTypeError, "String or Fixnum expected");
811
- break;
812
- }
1005
+ Get_newtComponent(self, co);
1006
+ Data_Attach(self, data);
1007
+ newtListboxInsertEntry(co, StringValuePtr(text), (void *) data, (void *) key);
813
1008
  return Qnil;
814
1009
  }
815
1010
 
@@ -817,19 +1012,8 @@ static VALUE rb_ext_Listbox_DeleteEntry(VALUE self, VALUE data)
817
1012
  {
818
1013
  newtComponent co;
819
1014
 
820
- Data_Get_Struct(self, struct newtComponent_struct, co);
821
-
822
- switch(TYPE(data)) {
823
- case T_STRING:
824
- newtListboxDeleteEntry(co, (void *)StringValuePtr(data));
825
- break;
826
- case T_FIXNUM:
827
- newtListboxDeleteEntry(co, (void *)NUM2INT(data));
828
- break;
829
- default:
830
- rb_raise(rb_eTypeError, "String or Fixnum expected");
831
- break;
832
- }
1015
+ Get_newtComponent(self, co);
1016
+ newtListboxDeleteEntry(co, (void *) data);
833
1017
  return Qnil;
834
1018
  }
835
1019
 
@@ -837,18 +1021,33 @@ static VALUE rb_ext_Listbox_Clear(VALUE self)
837
1021
  {
838
1022
  newtComponent co;
839
1023
 
840
- Data_Get_Struct(self, struct newtComponent_struct, co);
841
-
1024
+ Get_newtComponent(self, co);
842
1025
  newtListboxClear(co);
843
1026
  return Qnil;
844
1027
  }
845
1028
 
846
- static VALUE rb_ext_Listbox_ClearSelection(VALUE self)
1029
+ static VALUE rb_ext_Listbox_GetSelection(VALUE self)
847
1030
  {
848
1031
  newtComponent co;
1032
+ VALUE ary, item;
1033
+ void **items;
1034
+ int i, numitems = 0;
849
1035
 
850
- Data_Get_Struct(self, struct newtComponent_struct, co);
1036
+ Get_newtComponent(self, co);
1037
+ items = newtListboxGetSelection(co, &numitems);
1038
+ ary = rb_ary_new();
1039
+ for (i = 0; i < numitems; i++) {
1040
+ item = (VALUE) items[i];
1041
+ rb_ary_push(ary, item);
1042
+ }
1043
+ return ary;
1044
+ }
1045
+
1046
+ static VALUE rb_ext_Listbox_ClearSelection(VALUE self)
1047
+ {
1048
+ newtComponent co;
851
1049
 
1050
+ Get_newtComponent(self, co);
852
1051
  newtListboxClearSelection(co);
853
1052
  return Qnil;
854
1053
  }
@@ -857,109 +1056,201 @@ static VALUE rb_ext_Listbox_SelectItem(VALUE self, VALUE key, VALUE sense)
857
1056
  {
858
1057
  newtComponent co;
859
1058
 
860
- Data_Get_Struct(self, struct newtComponent_struct, co);
1059
+ Get_newtComponent(self, co);
1060
+ newtListboxSelectItem(co, (void *) key, NUM2INT(sense));
1061
+ return Qnil;
1062
+ }
861
1063
 
862
- switch(TYPE(key)) {
863
- case T_STRING:
864
- newtListboxSelectItem(co, (void *)StringValuePtr(key), NUM2INT(sense));
865
- break;
866
- case T_FIXNUM:
867
- newtListboxSelectItem(co, (void *)NUM2INT(key), NUM2INT(sense));
868
- break;
869
- default:
870
- rb_raise(rb_eTypeError, "String or Fixnum expected");
871
- break;
1064
+ static VALUE rb_ext_Listbox_ItemCount(VALUE self)
1065
+ {
1066
+ newtComponent co;
1067
+
1068
+ Get_newtComponent(self, co);
1069
+ return INT2NUM(newtListboxItemCount(co));
1070
+ }
1071
+
1072
+ static VALUE checkboxtree_collect_selection(int numitems, VALUE *data)
1073
+ {
1074
+ VALUE ary;
1075
+ int i;
1076
+
1077
+ ary = Qnil;
1078
+ if (numitems > 0) {
1079
+ ary = rb_ary_new();
1080
+ for (i = 0; i < numitems; i++)
1081
+ rb_ary_push(ary, data[i]);
872
1082
  }
873
- return Qnil;
1083
+ return ary;
874
1084
  }
875
1085
 
876
- static VALUE rb_ext_CheckboxTree_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags)
1086
+ static VALUE rb_ext_CheckboxTree_new(int argc, VALUE *argv, VALUE self)
877
1087
  {
878
1088
  newtComponent co;
1089
+ int flags;
1090
+
1091
+ if (argc < 3 || argc > 4)
1092
+ ARG_ERROR(argc, "3..4");
879
1093
 
880
- co = newtCheckboxTree(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags));
881
- return Data_Wrap_Struct(self, 0, 0, co);
1094
+ flags = (argc == 4) ? NUM2INT(argv[3]) : 0;
1095
+ co = newtCheckboxTree(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), flags);
1096
+ return Make_Widget(self, co);
882
1097
  }
883
1098
 
884
1099
  static VALUE rb_ext_CheckboxTree_AddItem(VALUE self, VALUE args)
885
- /*rb_ext_CheckboxTree_AddItem(VALUE self, VALUE text, VALUE data, VALUE flags)*/
886
- /*, VALUE index)*/
887
1100
  {
888
1101
  newtComponent co;
889
- #if 1
890
- int i, len;
891
1102
  int *indexes;
1103
+ char *text; VALUE data;
1104
+ int i, len, flags;
1105
+
1106
+ len = RARRAY_LENINT(args);
1107
+ if (len < 4)
1108
+ ARG_ERROR(len, "4+");
1109
+
1110
+ Get_newtComponent(self, co);
1111
+ indexes = ALLOCA_N(int, (len - 4) + 2);
1112
+ for (i = 0; i < (len - 4) + 1; i++)
1113
+ indexes[i] = NUM2INT(RARRAY_PTR(args)[i+3]);
1114
+ indexes[(len - 4) + 1] = NEWT_ARG_LAST;
1115
+
1116
+ text = StringValuePtr(RARRAY_PTR(args)[0]);
1117
+ data = RARRAY_PTR(args)[1];
1118
+ flags = NUM2INT(RARRAY_PTR(args)[2]);
1119
+ Data_Attach(self, data);
1120
+ newtCheckboxTreeAddArray(co, text, (void *) data, flags, indexes);
1121
+ return Qnil;
1122
+ }
892
1123
 
893
- len = RARRAY_LEN(args);
894
- if (len < 4) {
895
- rb_raise(rb_eArgError, "4 arguments required");
896
- } else {
897
- Data_Get_Struct(self, struct newtComponent_struct, co);
1124
+ static VALUE rb_ext_CheckboxTree_GetSelection(VALUE self)
1125
+ {
1126
+ newtComponent co;
1127
+ VALUE *data;
1128
+ int numitems;
898
1129
 
899
- indexes = ALLOCA_N(int, (len - 4) + 2);
900
- for (i = 0; i < (len - 4) + 1; i++) {
901
- indexes[i] = NUM2INT(RARRAY_PTR(args)[i+3]);
902
- }
903
- indexes[(len - 4) + 1] = NEWT_ARG_LAST;
904
-
905
- switch(TYPE(RARRAY_PTR(args)[1])) {
906
- case T_STRING:
907
- newtCheckboxTreeAddArray(co, StringValuePtr(RARRAY_PTR(args)[0]), (void *)StringValuePtr(RARRAY_PTR(args)[1]),
908
- NUM2INT(RARRAY_PTR(args)[2]), indexes);
909
- break;
910
- case T_FIXNUM:
911
- newtCheckboxTreeAddArray(co, StringValuePtr(RARRAY_PTR(args)[0]), (void *)NUM2INT(RARRAY_PTR(args)[1]),
912
- NUM2INT(RARRAY_PTR(args)[2]), indexes);
913
- break;
914
- default:
915
- rb_raise(rb_eTypeError, "String or Fixnum expected");
916
- break;
917
- }
918
- return Qnil;
919
- }
920
- #else
921
- Data_Get_Struct(self, struct newtComponent_struct, co);
1130
+ Get_newtComponent(self, co);
1131
+ data = (VALUE *) newtCheckboxTreeGetSelection(co, &numitems);
1132
+ return checkboxtree_collect_selection(numitems, data);
1133
+ }
922
1134
 
923
- switch(TYPE(data)) {
924
- case T_STRING:
925
- newtCheckboxTreeAddItem(co, StringValuePtr(text), (void *)StringValuePtr(data), NUM2INT(flags), NEWT_ARG_APPEND, NEWT_ARG_LAST);
926
- break;
927
- case T_FIXNUM:
928
- newtCheckboxTreeAddItem(co, StringValuePtr(text), (void *)NUM2INT(data), NUM2INT(flags), NEWT_ARG_APPEND, NEWT_ARG_LAST);
929
- break;
930
- default:
931
- rb_raise(rb_eTypeError, "String or Fixnum expected");
932
- break;
933
- }
1135
+ static VALUE rb_ext_CheckboxTree_GetCurrent(VALUE self)
1136
+ {
1137
+ newtComponent co;
1138
+
1139
+ Get_newtComponent(self, co);
1140
+ return (VALUE) newtCheckboxTreeGetCurrent(co);
1141
+ }
1142
+
1143
+ static VALUE rb_ext_CheckboxTree_SetCurrent(VALUE self, VALUE data)
1144
+ {
1145
+ newtComponent co;
1146
+
1147
+ Get_newtComponent(self, co);
1148
+ newtCheckboxTreeSetCurrent(co, (void *) data);
934
1149
  return Qnil;
935
- #endif
936
1150
  }
937
1151
 
938
- static VALUE rb_ext_CheckboxTreeMulti_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE seq, VALUE flags)
1152
+ static VALUE rb_ext_CheckboxTree_FindItem(VALUE self, VALUE data)
939
1153
  {
940
1154
  newtComponent co;
1155
+ int *path;
1156
+ VALUE ary;
1157
+ int i;
941
1158
 
942
- if (NIL_P(seq)) {
943
- co = newtCheckboxTreeMulti(NUM2INT(left), NUM2INT(top), NUM2INT(height), NULL, NUM2INT(flags));
944
- } else {
945
- co = newtCheckboxTreeMulti(NUM2INT(left), NUM2INT(top), NUM2INT(height), StringValuePtr(seq), NUM2INT(flags));
1159
+ ary = Qnil;
1160
+ Get_newtComponent(self, co);
1161
+ path = newtCheckboxTreeFindItem(co, (void *) data);
1162
+ if (path != NULL) {
1163
+ ary = rb_ary_new();
1164
+ for (i = 0; path[i] != NEWT_ARG_LAST; i++)
1165
+ rb_ary_push(ary, INT2NUM(path[i]));
946
1166
  }
947
- return Data_Wrap_Struct(self, 0, 0, co);
1167
+ return ary;
1168
+ }
1169
+
1170
+ static VALUE rb_ext_CheckboxTree_SetEntry(VALUE self, VALUE data, VALUE text)
1171
+ {
1172
+ newtComponent co;
1173
+
1174
+ Get_newtComponent(self, co);
1175
+ newtCheckboxTreeSetEntry(co, (void *) data, StringValuePtr(text));
1176
+ return Qnil;
1177
+ }
1178
+
1179
+ static VALUE rb_ext_CheckboxTree_SetWidth(VALUE self, VALUE width)
1180
+ {
1181
+ newtComponent co;
1182
+
1183
+ Get_newtComponent(self, co);
1184
+ newtCheckboxTreeSetWidth(co, NUM2INT(width));
1185
+ return Qnil;
1186
+ }
1187
+
1188
+ static VALUE rb_ext_CheckboxTree_GetEntryValue(VALUE self, VALUE data)
1189
+ {
1190
+ newtComponent co;
1191
+ char value[2];
1192
+
1193
+ Get_newtComponent(self, co);
1194
+ value[0] = newtCheckboxTreeGetEntryValue(co, (void *) data);
1195
+ value[1] = '\0';
1196
+ return (value[0] == -1) ? Qnil : rb_str_new_cstr(value);
948
1197
  }
949
1198
 
950
- static VALUE rb_ext_Textbox_new(VALUE self, VALUE left, VALUE top, VALUE width, VALUE height, VALUE flags)
1199
+ static VALUE rb_ext_CheckboxTree_SetEntryValue(VALUE self, VALUE data, VALUE value) {
1200
+ newtComponent co;
1201
+
1202
+ Get_newtComponent(self, co);
1203
+ newtCheckboxTreeSetEntryValue(co, (void *) data, StringValueCStr(value)[0]);
1204
+ return Qnil;
1205
+ }
1206
+
1207
+ static VALUE rb_ext_CheckboxTreeMulti_new(int argc, VALUE *argv, VALUE self)
951
1208
  {
952
1209
  newtComponent co;
1210
+ char *seq;
1211
+ int flags;
1212
+
1213
+ if (argc < 3 || argc > 5)
1214
+ ARG_ERROR(argc, "3..5");
1215
+
1216
+ seq = NULL;
1217
+ if (argc >= 4 && !NIL_P(argv[3]) && RSTRING_LEN(argv[3]))
1218
+ seq = StringValuePtr(argv[3]);
953
1219
 
954
- co = newtTextbox(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(height), NUM2INT(flags));
955
- return Data_Wrap_Struct(self, 0, 0, co);
1220
+ flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
1221
+ co = newtCheckboxTreeMulti(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), seq, flags);
1222
+ return Make_Widget(self, co);
1223
+ }
1224
+
1225
+ static VALUE rb_ext_CheckboxTreeMulti_GetSelection(VALUE self, VALUE seqnum)
1226
+ {
1227
+ newtComponent co;
1228
+ VALUE *data;
1229
+ int numitems;
1230
+
1231
+ Get_newtComponent(self, co);
1232
+ data = (VALUE *) newtCheckboxTreeGetMultiSelection(co, &numitems, StringValuePtr(seqnum)[0]);
1233
+ return checkboxtree_collect_selection(numitems, data);
1234
+ }
1235
+
1236
+ static VALUE rb_ext_Textbox_new(int argc, VALUE *argv, VALUE self)
1237
+ {
1238
+ newtComponent co;
1239
+ int flags;
1240
+
1241
+ if (argc < 4 || argc > 5)
1242
+ ARG_ERROR(argc, "4..5");
1243
+
1244
+ flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
1245
+ co = newtTextbox(NUM2INT(argv[0]), NUM2INT(argv[1]), NUM2INT(argv[2]), NUM2INT(argv[3]), flags);
1246
+ return Make_Widget(self, co);
956
1247
  }
957
1248
 
958
1249
  static VALUE rb_ext_Textbox_SetText(VALUE self, VALUE text)
959
1250
  {
960
1251
  newtComponent co;
961
1252
 
962
- Data_Get_Struct(self, struct newtComponent_struct, co);
1253
+ Get_newtComponent(self, co);
963
1254
  newtTextboxSetText(co, StringValuePtr(text));
964
1255
  return Qnil;
965
1256
  }
@@ -968,7 +1259,7 @@ static VALUE rb_ext_Textbox_SetHeight(VALUE self, VALUE height)
968
1259
  {
969
1260
  newtComponent co;
970
1261
 
971
- Data_Get_Struct(self, struct newtComponent_struct, co);
1262
+ Get_newtComponent(self, co);
972
1263
  newtTextboxSetHeight(co, NUM2INT(height));
973
1264
  return Qnil;
974
1265
  }
@@ -977,7 +1268,7 @@ static VALUE rb_ext_Textbox_GetNumLines(VALUE self)
977
1268
  {
978
1269
  newtComponent co;
979
1270
 
980
- Data_Get_Struct(self, struct newtComponent_struct, co);
1271
+ Get_newtComponent(self, co);
981
1272
  return INT2NUM(newtTextboxGetNumLines(co));
982
1273
  }
983
1274
 
@@ -985,79 +1276,114 @@ static VALUE rb_ext_Textbox_SetColors(VALUE self, VALUE normal, VALUE active)
985
1276
  {
986
1277
  newtComponent co;
987
1278
 
988
- Data_Get_Struct(self, struct newtComponent_struct, co);
1279
+ Get_newtComponent(self, co);
989
1280
  newtTextboxSetColors(co, NUM2INT(normal), NUM2INT(active));
990
1281
  return Qnil;
991
1282
  }
992
1283
 
993
- static VALUE rb_ext_TextboxReflowed_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp, VALUE flags)
1284
+ static VALUE rb_ext_TextboxReflowed_new(int argc, VALUE *argv, VALUE self)
994
1285
  {
995
1286
  newtComponent co;
1287
+ int flags;
996
1288
 
997
- co = newtTextboxReflowed(NUM2INT(left), NUM2INT(top), StringValuePtr(text), NUM2INT(width),
998
- NUM2INT(flexDown), NUM2INT(flexUp), NUM2INT(flags));
999
- return Data_Wrap_Struct(self, 0, 0, co);
1000
- }
1289
+ if (argc < 6 || argc > 7)
1290
+ ARG_ERROR(argc, "6..7");
1001
1291
 
1002
- static void rb_ext_Form_Destroy(VALUE self)
1003
- {
1004
- newtComponent form;
1292
+ flags = (argc == 7) ? NUM2INT(argv[6]) : 0;
1293
+ co = newtTextboxReflowed(NUM2INT(argv[0]), NUM2INT(argv[1]),
1294
+ StringValuePtr(argv[2]), NUM2INT(argv[3]),
1295
+ NUM2INT(argv[4]), NUM2INT(argv[5]), flags);
1005
1296
 
1006
- if (self) {
1007
- Data_Get_Struct(self, struct newtComponent_struct, form);
1008
- newtFormDestroy(form);
1009
- }
1297
+ return Make_Widget(self, co);
1010
1298
  }
1011
1299
 
1012
- static VALUE rb_ext_Form_new(VALUE self, VALUE left, VALUE top, VALUE text)
1300
+ static VALUE rb_ext_Form_new(int argc, VALUE *argv, VALUE self)
1013
1301
  {
1014
1302
  newtComponent co;
1303
+ VALUE helpTag;
1304
+ int flags = 0;
1305
+
1306
+ if (argc > 3)
1307
+ ARG_ERROR(argc, "0..3");
1015
1308
 
1016
- co = newtForm(NULL, NULL, 0);
1017
- return Data_Wrap_Struct(self, 0, 0, co);
1018
- //return Data_Wrap_Struct(self, 0, rb_ext_Form_Destroy, co);
1309
+ helpTag = (argc >= 2) ? argv[1] : Qnil;
1310
+ flags = (argc == 3) ? NUM2INT(argv[2]) : 0;
1311
+
1312
+ /* Can't determine how Form scrollbars work, so just pass NULL. */
1313
+ co = newtForm(NULL, (void *) helpTag, flags);
1314
+ return Make_Widget(self, co);
1019
1315
  }
1020
1316
 
1021
1317
  static VALUE rb_ext_Form_SetBackground(VALUE self, VALUE color)
1022
1318
  {
1023
1319
  newtComponent form;
1024
1320
 
1025
- Data_Get_Struct(self, struct newtComponent_struct, form);
1321
+ Get_newtComponent(self, form);
1026
1322
  newtFormSetBackground(form, NUM2INT(color));
1027
1323
  return Qnil;
1028
1324
  }
1029
1325
 
1030
- #if 0
1031
- static VALUE rb_ext_Form_AddComponent(VALUE self, VALUE co)
1326
+ static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE components)
1032
1327
  {
1033
- newtComponent form, cco;
1328
+ Widget_data *form, *co;
1329
+ VALUE str;
1330
+ int i;
1331
+
1332
+ Get_Widget_Data(self, form);
1333
+ if (RARRAY_LEN(components) > 0 && (void *) form->components == NULL) {
1334
+ form->components = rb_ary_new();
1335
+ rb_gc_register_address(&form->components);
1336
+ }
1337
+
1338
+ for (i = 0; i < RARRAY_LEN(components); i++) {
1339
+ Get_Widget_Data(RARRAY_PTR(components)[i], co);
1340
+ if (co->flags & FLAG_ADDED_TO_FORM) {
1341
+ str = rb_inspect(RARRAY_PTR(components)[i]);
1342
+ rb_raise(rb_eRuntimeError, "%s is already added to a Form",
1343
+ StringValuePtr(str));
1344
+ }
1034
1345
 
1035
- Data_Get_Struct(self, struct newtComponent_struct, form);
1036
- Data_Get_Struct(co, struct newtComponent_struct, cco);
1037
- newtFormAddComponent(form, cco);
1346
+ co->flags ^= FLAG_GC_FREE;
1347
+ co->flags |= FLAG_ADDED_TO_FORM;
1348
+ rb_ary_push(form->components, RARRAY_PTR(components)[i]);
1349
+ newtFormAddComponent(form->co, co->co);
1350
+ }
1038
1351
  return Qnil;
1039
1352
  }
1040
- #endif
1041
1353
 
1042
- static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE co)
1354
+ static VALUE rb_ext_Form_SetSize(VALUE self)
1043
1355
  {
1044
- int i;
1045
- newtComponent form, cco;
1356
+ newtComponent form;
1046
1357
 
1047
- Data_Get_Struct(self, struct newtComponent_struct, form);
1358
+ Get_newtComponent(self, form);
1359
+ newtFormSetSize(form);
1360
+ return Qnil;
1361
+ }
1048
1362
 
1049
- for (i = 0; i < RARRAY_LEN(co); i++) {
1050
- Data_Get_Struct(RARRAY_PTR(co)[i], struct newtComponent_struct, cco);
1051
- newtFormAddComponent(form, cco);
1052
- }
1363
+ static VALUE rb_ext_Form_SetCurrent(VALUE self, VALUE obj)
1364
+ {
1365
+ newtComponent form, co;
1366
+
1367
+ Get_newtComponent(self, form);
1368
+ Get_newtComponent(obj, co);
1369
+ newtFormSetCurrent(form, co);
1053
1370
  return Qnil;
1054
1371
  }
1055
1372
 
1373
+ static VALUE rb_ext_Form_GetCurrent(VALUE self)
1374
+ {
1375
+ newtComponent form, co;
1376
+
1377
+ Get_newtComponent(self, form);
1378
+ co = newtFormGetCurrent(form);
1379
+ return Make_Widget_Ref(cWidget, co);
1380
+ }
1381
+
1056
1382
  static VALUE rb_ext_Form_SetHeight(VALUE self, VALUE height)
1057
1383
  {
1058
1384
  newtComponent form;
1059
1385
 
1060
- Data_Get_Struct(self, struct newtComponent_struct, form);
1386
+ Get_newtComponent(self, form);
1061
1387
  newtFormSetHeight(form, NUM2INT(height));
1062
1388
  return Qnil;
1063
1389
  }
@@ -1066,25 +1392,27 @@ static VALUE rb_ext_Form_SetWidth(VALUE self, VALUE width)
1066
1392
  {
1067
1393
  newtComponent form;
1068
1394
 
1069
- Data_Get_Struct(self, struct newtComponent_struct, form);
1395
+ Get_newtComponent(self, form);
1070
1396
  newtFormSetWidth(form, NUM2INT(width));
1071
1397
  return Qnil;
1072
1398
  }
1073
1399
 
1074
- static VALUE rb_ext_Run_Form(VALUE self)
1400
+ static VALUE rb_ext_Form_Run(VALUE self)
1075
1401
  {
1076
- newtComponent form, co;
1402
+ newtComponent form;
1403
+ struct newtExitStruct *es;
1077
1404
 
1078
- Data_Get_Struct(self, struct newtComponent_struct, form);
1079
- co = newtRunForm(form);
1080
- return Data_Wrap_Struct(cWidget, 0, 0, co);
1405
+ Get_newtComponent(self, form);
1406
+ es = ALLOC(struct newtExitStruct);
1407
+ newtFormRun(form, es);
1408
+ return Data_Wrap_Struct(cExitStruct, 0, xfree, es);
1081
1409
  }
1082
1410
 
1083
1411
  static VALUE rb_ext_Form_DrawForm(VALUE self)
1084
1412
  {
1085
1413
  newtComponent form;
1086
1414
 
1087
- Data_Get_Struct(self, struct newtComponent_struct, form);
1415
+ Get_newtComponent(self, form);
1088
1416
  newtDrawForm(form);
1089
1417
  return Qnil;
1090
1418
  }
@@ -1093,25 +1421,54 @@ static VALUE rb_ext_Form_AddHotKey(VALUE self, VALUE key)
1093
1421
  {
1094
1422
  newtComponent form;
1095
1423
 
1096
- Data_Get_Struct(self, struct newtComponent_struct, form);
1424
+ Get_newtComponent(self, form);
1097
1425
  newtFormAddHotKey(form, NUM2INT(key));
1098
1426
  return Qnil;
1099
1427
  }
1100
1428
 
1101
- static VALUE rb_ext_Entry_new(VALUE self, VALUE left, VALUE top, VALUE initialValue, VALUE width, VALUE flags)
1429
+ static VALUE rb_ext_Form_SetTimer(VALUE self, VALUE millisecs)
1430
+ {
1431
+ newtComponent form;
1432
+
1433
+ Get_newtComponent(self, form);
1434
+ newtFormSetTimer(form, NUM2INT(millisecs));
1435
+ return Qnil;
1436
+ }
1437
+
1438
+ static VALUE rb_ext_Form_WatchFd(VALUE self, VALUE io, VALUE flags)
1439
+ {
1440
+ newtComponent form;
1441
+ int fd;
1442
+
1443
+ if (!rb_obj_is_kind_of(io, rb_cIO) && TYPE(io) != T_FIXNUM)
1444
+ rb_raise(rb_eTypeError, "neither IO nor file descriptor");
1445
+
1446
+ Get_newtComponent(self, form);
1447
+ fd = NUM2INT(rb_funcall(io, rb_intern("fileno"), 0));
1448
+ newtFormWatchFd(form, fd, NUM2INT(flags));
1449
+ return Qnil;
1450
+ }
1451
+
1452
+ static VALUE rb_ext_Entry_new(int argc, VALUE *argv, VALUE self)
1102
1453
  {
1103
1454
  newtComponent co;
1455
+ int flags;
1456
+
1457
+ if (argc < 4 || argc > 5)
1458
+ ARG_ERROR(argc, "4..5");
1104
1459
 
1105
- co = newtEntry(NUM2INT(left), NUM2INT(top), StringValuePtr(initialValue), NUM2INT(width),
1106
- NULL, NUM2INT(flags));
1107
- return Data_Wrap_Struct(self, 0, 0, co);
1460
+ flags = (argc == 5) ? NUM2INT(argv[4]) : 0;
1461
+ co = newtEntry(NUM2INT(argv[0]), NUM2INT(argv[1]), StringValuePtr(argv[2]),
1462
+ NUM2INT(argv[3]), NULL, flags);
1463
+
1464
+ return Make_Widget(self, co);
1108
1465
  }
1109
1466
 
1110
1467
  static VALUE rb_ext_Entry_Set(VALUE self, VALUE value, VALUE cursorAtEnd)
1111
1468
  {
1112
1469
  newtComponent co;
1113
1470
 
1114
- Data_Get_Struct(self, struct newtComponent_struct, co);
1471
+ Get_newtComponent(self, co);
1115
1472
  switch(TYPE(cursorAtEnd)) {
1116
1473
  case T_TRUE:
1117
1474
  newtEntrySet(co, StringValuePtr(value), 1);
@@ -1126,7 +1483,6 @@ static VALUE rb_ext_Entry_Set(VALUE self, VALUE value, VALUE cursorAtEnd)
1126
1483
  rb_raise(rb_eTypeError, "Boolean or Fixnum expected");
1127
1484
  break;
1128
1485
  }
1129
-
1130
1486
  return Qnil;
1131
1487
  }
1132
1488
 
@@ -1134,25 +1490,67 @@ static VALUE rb_ext_Entry_GetValue(VALUE self)
1134
1490
  {
1135
1491
  newtComponent co;
1136
1492
 
1137
- Data_Get_Struct(self, struct newtComponent_struct, co);
1493
+ Get_newtComponent(self, co);
1138
1494
  return rb_str_new2(newtEntryGetValue(co));
1139
1495
  }
1140
1496
 
1141
- static VALUE rb_ext_Entry_SetFlags(VALUE self, VALUE args)
1497
+ static VALUE rb_ext_Entry_SetFilter(int argc, VALUE *argv, VALUE self)
1142
1498
  {
1143
1499
  newtComponent co;
1144
- long len;
1145
-
1146
- len = RARRAY_LEN(args);
1147
- if (len == 1) {
1148
- Data_Get_Struct(self, struct newtComponent_struct, co);
1149
- newtEntrySetFlags(co, NUM2INT(RARRAY_PTR(args)[0]), NEWT_FLAGS_SET);
1150
- } else if (len == 2) {
1151
- Data_Get_Struct(self, struct newtComponent_struct, co);
1152
- newtEntrySetFlags(co, NUM2INT(RARRAY_PTR(args)[0]), NUM2INT(RARRAY_PTR(args)[1]));
1153
- } else {
1154
- rb_raise(rb_eArgError, "1 argument or 2 arguments required");
1155
- }
1500
+ VALUE cb, data = Qnil;
1501
+
1502
+ if (argc < 1 || argc > 2)
1503
+ ARG_ERROR(argc, "1 or 2");
1504
+
1505
+ if (argc == 2)
1506
+ data = argv[1];
1507
+
1508
+ Get_newtComponent(self, co);
1509
+ cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
1510
+ rb_ivar_set(self, IVAR_FILTER_CALLBACK, cb);
1511
+ newtEntrySetFilter(co, rb_ext_Entry_filter_function, (void *) cb);
1512
+ return Qnil;
1513
+ }
1514
+
1515
+ static VALUE rb_ext_Entry_SetFlags(int argc, VALUE *argv, VALUE self)
1516
+ {
1517
+ newtComponent co;
1518
+ int sense = NEWT_FLAGS_SET;
1519
+
1520
+ if (argc < 1 || argc > 2)
1521
+ ARG_ERROR(argc, "1..2");
1522
+
1523
+ if (argc == 2)
1524
+ sense = NUM2INT(argv[1]);
1525
+
1526
+ Get_newtComponent(self, co);
1527
+ newtEntrySetFlags(co, NUM2INT(argv[0]), sense);
1528
+ return Qnil;
1529
+ }
1530
+
1531
+ static VALUE rb_ext_Entry_SetColors(VALUE self, VALUE normal, VALUE disabled)
1532
+ {
1533
+ newtComponent co;
1534
+
1535
+ Get_newtComponent(self, co);
1536
+ newtEntrySetColors(co, NUM2INT(normal), NUM2INT(disabled));
1537
+ return Qnil;
1538
+ }
1539
+
1540
+ static VALUE rb_ext_Entry_GetCursorPosition(VALUE self)
1541
+ {
1542
+ newtComponent co;
1543
+
1544
+ Get_newtComponent(self, co);
1545
+ return INT2NUM(newtEntryGetCursorPosition(co));
1546
+ }
1547
+
1548
+ static VALUE rb_ext_Entry_SetCursorPosition(VALUE self, VALUE position)
1549
+ {
1550
+ newtComponent co;
1551
+
1552
+ Get_newtComponent(self, co);
1553
+ newtEntrySetCursorPosition(co, NUM2INT(position));
1156
1554
  return Qnil;
1157
1555
  }
1158
1556
 
@@ -1161,88 +1559,106 @@ static VALUE rb_ext_Scale_new(VALUE self, VALUE left, VALUE top, VALUE width, VA
1161
1559
  newtComponent co;
1162
1560
 
1163
1561
  co = newtScale(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(fullValue));
1164
- return Data_Wrap_Struct(self, 0, 0, co);
1562
+ return Make_Widget(self, co);
1165
1563
  }
1166
1564
 
1167
1565
  static VALUE rb_ext_Scale_Set(VALUE self, VALUE amount)
1168
1566
  {
1169
1567
  newtComponent co;
1170
1568
 
1171
- Data_Get_Struct(self, struct newtComponent_struct, co);
1569
+ Get_newtComponent(self, co);
1172
1570
  newtScaleSet(co, NUM2INT(amount));
1173
1571
  return Qnil;
1174
1572
  }
1175
1573
 
1176
- static void rb_ext_Grid_Destroy(VALUE self)
1574
+ static VALUE rb_ext_Scale_SetColors(VALUE self, VALUE empty, VALUE full)
1177
1575
  {
1178
- newtGrid grid;
1576
+ newtComponent co;
1179
1577
 
1180
- if (self) {
1181
- Data_Get_Struct(cGrid, struct grid_s, grid);
1182
- newtGridFree(grid, 1);
1183
- }
1578
+ Get_newtComponent(self, co);
1579
+ newtScaleSetColors(co, NUM2INT(empty), NUM2INT(full));
1580
+ return Qnil;
1184
1581
  }
1185
1582
 
1186
1583
  static VALUE rb_ext_Grid_new(VALUE self, VALUE cols, VALUE rows)
1187
1584
  {
1188
1585
  newtGrid grid;
1586
+ VALUE widget;
1587
+ int num_cols, num_rows;
1588
+
1589
+ num_cols = NUM2INT(cols);
1590
+ num_rows = NUM2INT(rows);
1591
+
1592
+ if (num_cols <= 0 || num_rows <= 0)
1593
+ rb_raise(rb_eRuntimeError, "specified number of columns or rows should be greater than 0");
1189
1594
 
1190
- grid = newtCreateGrid(NUM2INT(cols), NUM2INT(rows));
1191
- return Data_Wrap_Struct(self, 0, 0, grid);
1192
- //return Data_Wrap_Struct(self, 0, rb_ext_Grid_Destroy, grid);
1595
+ grid = newtCreateGrid(num_cols, num_rows);
1596
+ widget = Data_Wrap_Struct(self, 0, 0, grid);
1597
+ rb_ivar_set(widget, IVAR_COLS, cols);
1598
+ rb_ivar_set(widget, IVAR_ROWS, rows);
1599
+ return widget;
1193
1600
  }
1194
1601
 
1195
1602
  static VALUE rb_ext_Grid_SetField(VALUE self, VALUE col, VALUE row, VALUE type, VALUE val,
1196
- VALUE padLeft, VALUE padTop, VALUE padRight, VALUE padBottom,
1197
- VALUE anchor, VALUE flags)
1603
+ VALUE padLeft, VALUE padTop, VALUE padRight, VALUE padBottom, VALUE anchor, VALUE flags)
1198
1604
  {
1199
1605
  newtGrid grid;
1200
- newtComponent co;
1606
+ void *co;
1607
+ int icol, irow, itype, cols, rows;
1608
+
1609
+ icol = NUM2INT(col);
1610
+ irow = NUM2INT(row);
1611
+ itype = NUM2INT(type);
1612
+
1613
+ cols = NUM2INT(rb_ivar_get(self, IVAR_COLS));
1614
+ rows = NUM2INT(rb_ivar_get(self, IVAR_ROWS));
1615
+ if (icol >= cols || irow >= rows)
1616
+ rb_raise(rb_eRuntimeError, "attempting to set a field at an invalid position (%d, %d)", icol, irow);
1617
+
1618
+ if (itype == NEWT_GRID_SUBGRID)
1619
+ Data_Get_Struct(val, struct grid_s, co);
1620
+ else
1621
+ Get_newtComponent(val, co);
1201
1622
 
1202
1623
  Data_Get_Struct(self, struct grid_s, grid);
1203
- Data_Get_Struct(val, struct newtComponent_struct, co);
1204
- newtGridSetField(grid, NUM2INT(col), NUM2INT(row), NUM2INT(type), co,
1205
- NUM2INT(padLeft), NUM2INT(padTop), NUM2INT(padRight), NUM2INT(padBottom),
1206
- NUM2INT(anchor), NUM2INT(flags));
1624
+ newtGridSetField(grid, icol, irow, itype, co, NUM2INT(padLeft),
1625
+ NUM2INT(padTop), NUM2INT(padRight), NUM2INT(padBottom),
1626
+ NUM2INT(anchor), NUM2INT(flags));
1627
+
1207
1628
  return Qnil;
1208
1629
  }
1209
1630
 
1210
- static VALUE rb_ext_Grid_WrappedWindow(VALUE self, VALUE args)
1631
+ static VALUE rb_ext_Grid_WrappedWindow(int argc, VALUE *argv, VALUE self)
1211
1632
  {
1212
1633
  newtGrid grid;
1213
- long len;
1214
-
1215
- len = RARRAY_LEN(args);
1216
- if (len == 1) {
1217
- Data_Get_Struct(self, struct grid_s, grid);
1218
- newtGridWrappedWindow(grid, StringValuePtr(RARRAY_PTR(args)[0]));
1219
- } else if (len == 3) {
1220
- Data_Get_Struct(self, struct grid_s, grid);
1221
- newtGridWrappedWindowAt(grid, StringValuePtr(RARRAY_PTR(args)[0]),
1222
- NUM2INT(StringValuePtr(RARRAY_PTR(args)[1])), NUM2INT(StringValuePtr(RARRAY_PTR(args)[2])));
1223
- } else {
1224
- rb_raise(rb_eArgError, "1 argument or 3 arguments required");
1225
- }
1634
+ char *title;
1635
+
1636
+ if (argc != 1 && argc != 3)
1637
+ ARG_ERROR(argc, "1 or 3");
1226
1638
 
1639
+ title = StringValuePtr(argv[0]);
1640
+ Data_Get_Struct(self, struct grid_s, grid);
1641
+ if (argc == 1) {
1642
+ newtGridWrappedWindow(grid, title);
1643
+ } else if (argc == 3) {
1644
+ newtGridWrappedWindowAt(grid, title, NUM2INT(argv[1]), NUM2INT(argv[2]));
1645
+ }
1227
1646
  return Qnil;
1228
1647
  }
1229
1648
 
1230
1649
  static VALUE rb_ext_Grid_GetSize(VALUE self)
1231
1650
  {
1232
- int width, height;
1233
1651
  newtGrid grid;
1234
- VALUE ary = rb_ary_new2(2);
1652
+ int width, height;
1235
1653
 
1236
1654
  Data_Get_Struct(self, struct grid_s, grid);
1237
1655
  newtGridGetSize(grid, &width, &height);
1238
- rb_ary_push(ary, INT2NUM(width));
1239
- rb_ary_push(ary, INT2NUM(height));
1240
-
1241
- return ary;
1656
+ return rb_ary_new_from_args(2, INT2NUM(width), INT2NUM(height));
1242
1657
  }
1243
1658
 
1244
1659
  void Init_ruby_newt(){
1245
1660
  mNewt = rb_define_module("Newt");
1661
+ rb_define_module_function(mNewt, "delay", rb_ext_Delay, 1);
1246
1662
  rb_define_module_function(mNewt, "reflow_text", rb_ext_ReflowText, 4);
1247
1663
 
1248
1664
  mScreen = rb_define_class_under(mNewt, "Screen", rb_cObject);
@@ -1260,24 +1676,28 @@ void Init_ruby_newt(){
1260
1676
  rb_define_module_function(mScreen, "refresh", rb_ext_Screen_Refresh, 0);
1261
1677
  rb_define_module_function(mScreen, "suspend", rb_ext_Screen_Suspend, 0);
1262
1678
  rb_define_module_function(mScreen, "resume", rb_ext_Screen_Resume, 0);
1679
+ rb_define_module_function(mScreen, "suspend_callback", rb_ext_Screen_SuspendCallback, -1);
1680
+ rb_define_module_function(mScreen, "help_callback", rb_ext_Screen_HelpCallback, 1);
1263
1681
  rb_define_module_function(mScreen, "push_helpline", rb_ext_Screen_PushHelpLine, 1);
1264
1682
  rb_define_module_function(mScreen, "redraw_helpline", rb_ext_Screen_RedrawHelpLine, 0);
1265
1683
  rb_define_module_function(mScreen, "pop_helpline", rb_ext_Screen_PopHelpLine, 0);
1266
1684
  rb_define_module_function(mScreen, "draw_roottext", rb_ext_Screen_DrawRootText, 3);
1267
1685
  rb_define_module_function(mScreen, "bell", rb_ext_Screen_Bell, 0);
1686
+ rb_define_module_function(mScreen, "cursor_off", rb_ext_Screen_CursorOff, 0);
1687
+ rb_define_module_function(mScreen, "cursor_on", rb_ext_Screen_CursorOn, 0);
1268
1688
  rb_define_module_function(mScreen, "size", rb_ext_Screen_Size, 0);
1269
- rb_define_module_function(mScreen, "win_message", rb_ext_Screen_WinMessage, -2);
1270
- rb_define_module_function(mScreen, "win_choice", rb_ext_Screen_WinChoice, -2);
1689
+ rb_define_module_function(mScreen, "win_message", rb_ext_Screen_WinMessage, 3);
1690
+ rb_define_module_function(mScreen, "win_choice", rb_ext_Screen_WinChoice, 4);
1271
1691
  rb_define_module_function(mScreen, "win_menu", rb_ext_Screen_WinMenu, -2);
1272
1692
  rb_define_module_function(mScreen, "win_entries", rb_ext_Screen_WinEntries, -2);
1273
1693
 
1274
- rb_ext_Widget_CALLBACK_HASH = rb_hash_new();
1275
- rb_define_const(mNewt, "CALLBACK_HASH", rb_ext_Widget_CALLBACK_HASH);
1276
- rb_call_id = rb_intern("call");
1694
+ rb_ext_sCallback = rb_struct_define(NULL, "widget", "context", "callback", "data", NULL);
1277
1695
 
1278
1696
  cWidget = rb_define_class_under(mNewt, "Widget", rb_cObject);
1279
1697
  rb_define_method(cWidget, "callback", rb_ext_Widget_callback, -1);
1280
- rb_define_method(cWidget, "takesFocus", rb_ext_Widget_takesFocus, 1);
1698
+ rb_define_method(cWidget, "takes_focus", rb_ext_Widget_takesFocus, 1);
1699
+ rb_define_method(cWidget, "get_position", rb_ext_Widget_GetPosition, 0);
1700
+ rb_define_method(cWidget, "get_size", rb_ext_Widget_GetSize, 0);
1281
1701
  rb_define_method(cWidget, "==", rb_ext_Widget_equal, 1);
1282
1702
 
1283
1703
  cCompactButton = rb_define_class_under(mNewt, "CompactButton", cWidget);
@@ -1287,15 +1707,15 @@ void Init_ruby_newt(){
1287
1707
  rb_define_singleton_method(cButton, "new", rb_ext_Button_new, 3);
1288
1708
 
1289
1709
  cCheckbox = rb_define_class_under(mNewt, "Checkbox", cWidget);
1290
- rb_define_singleton_method(cCheckbox, "new", rb_ext_Checkbox_new, 5);
1710
+ rb_define_singleton_method(cCheckbox, "new", rb_ext_Checkbox_new, -1);
1291
1711
  rb_define_method(cCheckbox, "get", rb_ext_Checkbox_GetValue, 0);
1292
1712
  rb_define_method(cCheckbox, "set", rb_ext_Checkbox_SetValue, 1);
1293
- rb_define_method(cCheckbox, "set_flags", rb_ext_Checkbox_SetFlags, -2);
1713
+ rb_define_method(cCheckbox, "set_flags", rb_ext_Checkbox_SetFlags, -1);
1294
1714
 
1295
1715
  cRadioButton = rb_define_class_under(mNewt, "RadioButton", cWidget);
1296
- rb_define_singleton_method(cRadioButton, "new", rb_ext_RadioButton_new, 5);
1297
- rb_define_method(cRadioButton, "get", rb_ext_Checkbox_GetValue, 0);
1298
- rb_define_method(cRadioButton, "set", rb_ext_Checkbox_SetValue, 1);
1716
+ rb_define_singleton_method(cRadioButton, "new", rb_ext_RadioButton_new, -1);
1717
+ rb_define_method(cRadioButton, "get_current", rb_ext_RadioButton_GetCurrent, 0);
1718
+ rb_define_method(cRadioButton, "set_current", rb_ext_RadioButton_SetCurrent, 0);
1299
1719
 
1300
1720
  cLabel = rb_define_class_under(mNewt, "Label", cWidget);
1301
1721
  rb_define_singleton_method(cLabel, "new", rb_ext_Label_new, 3);
@@ -1303,69 +1723,92 @@ void Init_ruby_newt(){
1303
1723
  rb_define_method(cLabel, "set_colors", rb_ext_Label_SetColors, 1);
1304
1724
 
1305
1725
  cListbox = rb_define_class_under(mNewt, "Listbox", cWidget);
1306
- rb_define_singleton_method(cListbox, "new", rb_ext_Listbox_new, 4);
1307
- rb_define_method(cListbox, "get_current", rb_ext_Listbox_GetCurrentAsNumber, 0);
1308
- rb_define_method(cListbox, "get_current_as_number", rb_ext_Listbox_GetCurrentAsNumber, 0);
1309
- rb_define_method(cListbox, "get_current_as_string", rb_ext_Listbox_GetCurrentAsString, 0);
1726
+ rb_define_singleton_method(cListbox, "new", rb_ext_Listbox_new, -1);
1727
+ rb_define_method(cListbox, "get_current", rb_ext_Listbox_GetCurrent, 0);
1310
1728
  rb_define_method(cListbox, "set_current", rb_ext_Listbox_SetCurrent, 1);
1311
- rb_define_method(cListbox, "setCurrentByKey", rb_ext_Listbox_SetCurrentByKey, 1);
1729
+ rb_define_method(cListbox, "set_current_by_key", rb_ext_Listbox_SetCurrentByKey, 1);
1312
1730
  rb_define_method(cListbox, "set_width", rb_ext_Listbox_SetWidth, 1);
1313
- rb_define_method(cListbox, "setData", rb_ext_Listbox_SetData, 2);
1731
+ rb_define_method(cListbox, "set_data", rb_ext_Listbox_SetData, 2);
1314
1732
  rb_define_method(cListbox, "append", rb_ext_Listbox_AppendEntry, 2);
1315
1733
  rb_define_method(cListbox, "insert", rb_ext_Listbox_InsertEntry, 3);
1734
+ rb_define_method(cListbox, "get", rb_ext_Listbox_GetEntry, 1);
1316
1735
  rb_define_method(cListbox, "set", rb_ext_Listbox_SetEntry, 2);
1317
1736
  rb_define_method(cListbox, "delete", rb_ext_Listbox_DeleteEntry, 1);
1318
1737
  rb_define_method(cListbox, "clear", rb_ext_Listbox_Clear, 0);
1319
- rb_define_method(cListbox, "clearSelection", rb_ext_Listbox_ClearSelection, 0);
1738
+ rb_define_method(cListbox, "get_selection", rb_ext_Listbox_GetSelection, 0);
1739
+ rb_define_method(cListbox, "clear_selection", rb_ext_Listbox_ClearSelection, 0);
1320
1740
  rb_define_method(cListbox, "select", rb_ext_Listbox_SelectItem, 2);
1741
+ rb_define_method(cListbox, "item_count", rb_ext_Listbox_ItemCount, 0);
1321
1742
 
1322
1743
  cCheckboxTree = rb_define_class_under(mNewt, "CheckboxTree", cWidget);
1323
- rb_define_singleton_method(cCheckboxTree, "new", rb_ext_CheckboxTree_new, 4);
1324
- /*rb_define_method(cCheckboxTree, "addItem", rb_ext_CheckboxTree_AddItem, 3);*/
1744
+ rb_define_singleton_method(cCheckboxTree, "new", rb_ext_CheckboxTree_new, -1);
1325
1745
  rb_define_method(cCheckboxTree, "add", rb_ext_CheckboxTree_AddItem, -2);
1746
+ rb_define_method(cCheckboxTree, "get_selection", rb_ext_CheckboxTree_GetSelection, 0);
1747
+ rb_define_method(cCheckboxTree, "get_current", rb_ext_CheckboxTree_GetCurrent, 0);
1748
+ rb_define_method(cCheckboxTree, "set_current", rb_ext_CheckboxTree_SetCurrent, 1);
1749
+ rb_define_method(cCheckboxTree, "find", rb_ext_CheckboxTree_FindItem, 1);
1750
+ rb_define_method(cCheckboxTree, "set_entry", rb_ext_CheckboxTree_SetEntry, 2);
1751
+ rb_define_method(cCheckboxTree, "set_width", rb_ext_CheckboxTree_SetWidth, 1);
1752
+ rb_define_method(cCheckboxTree, "get", rb_ext_CheckboxTree_GetEntryValue, 1);
1753
+ rb_define_method(cCheckboxTree, "set", rb_ext_CheckboxTree_SetEntryValue, 2);
1326
1754
 
1327
1755
  cCheckboxTreeMulti = rb_define_class_under(mNewt, "CheckboxTreeMulti", cCheckboxTree);
1328
- rb_define_singleton_method(cCheckboxTreeMulti, "new", rb_ext_CheckboxTreeMulti_new, 5);
1756
+ rb_define_singleton_method(cCheckboxTreeMulti, "new", rb_ext_CheckboxTreeMulti_new, -1);
1757
+ rb_define_method(cCheckboxTreeMulti, "get_selection", rb_ext_CheckboxTreeMulti_GetSelection, 1);
1329
1758
 
1330
1759
  cTextbox = rb_define_class_under(mNewt, "Textbox", cWidget);
1331
- rb_define_singleton_method(cTextbox, "new", rb_ext_Textbox_new, 5);
1760
+ rb_define_singleton_method(cTextbox, "new", rb_ext_Textbox_new, -1);
1332
1761
  rb_define_method(cTextbox, "set_text", rb_ext_Textbox_SetText, 1);
1333
1762
  rb_define_method(cTextbox, "set_height", rb_ext_Textbox_SetHeight, 1);
1334
1763
  rb_define_method(cTextbox, "get_num_lines", rb_ext_Textbox_GetNumLines, 0);
1335
1764
  rb_define_method(cTextbox, "set_colors", rb_ext_Textbox_SetColors, 2);
1336
1765
 
1337
- cTextboxReflowed = rb_define_class_under(mNewt, "TextboxReflowed", cWidget);
1338
- rb_define_singleton_method(cTextboxReflowed, "new", rb_ext_TextboxReflowed_new, 7);
1766
+ cTextboxReflowed = rb_define_class_under(mNewt, "TextboxReflowed", cTextbox);
1767
+ rb_define_singleton_method(cTextboxReflowed, "new", rb_ext_TextboxReflowed_new, -1);
1339
1768
 
1340
1769
  cForm = rb_define_class_under(mNewt, "Form", cWidget);
1341
- rb_define_singleton_method(cForm, "new", rb_ext_Form_new, 0);
1342
- /*rb_define_method(cForm, "setSize", rb_ext_Form_SetSize, 0);*/
1343
- /*rb_define_method(cForm, "destroy", rb_ext_Form_Destroy, 0);*/
1770
+ rb_define_singleton_method(cForm, "new", rb_ext_Form_new, -1);
1344
1771
  rb_define_method(cForm, "set_background", rb_ext_Form_SetBackground, 1);
1345
- /*rb_define_method(cForm, "addComponent", rb_ext_Form_AddComponent, 1);*/
1346
1772
  rb_define_method(cForm, "add", rb_ext_Form_AddComponents, -2);
1773
+ rb_define_method(cForm, "set_size", rb_ext_Form_SetSize, 0);
1774
+ rb_define_method(cForm, "get_current", rb_ext_Form_GetCurrent, 0);
1775
+ rb_define_method(cForm, "set_current", rb_ext_Form_SetCurrent, 1);
1347
1776
  rb_define_method(cForm, "set_height", rb_ext_Form_SetHeight, 1);
1348
1777
  rb_define_method(cForm, "set_width", rb_ext_Form_SetWidth, 1);
1349
- rb_define_method(cForm, "run", rb_ext_Run_Form, 0);
1778
+ rb_define_method(cForm, "run", rb_ext_Form_Run, 0);
1350
1779
  rb_define_method(cForm, "draw", rb_ext_Form_DrawForm, 0);
1351
1780
  rb_define_method(cForm, "add_hotkey", rb_ext_Form_AddHotKey, 1);
1781
+ rb_define_method(cForm, "set_timer", rb_ext_Form_SetTimer, 1);
1782
+ rb_define_method(cForm, "watch_fd", rb_ext_Form_WatchFd, 2);
1783
+
1784
+ cExitStruct = rb_define_class_under(cForm, "ExitStruct", rb_cObject);
1785
+ rb_define_private_method(rb_singleton_class(cExitStruct), "new", NULL, 0);
1786
+ rb_define_method(cExitStruct, "reason", rb_ext_ExitStruct_reason, 0);
1787
+ rb_define_method(cExitStruct, "watch", rb_ext_ExitStruct_watch, 0);
1788
+ rb_define_method(cExitStruct, "key", rb_ext_ExitStruct_key, 0);
1789
+ rb_define_method(cExitStruct, "component", rb_ext_ExitStruct_component, 0);
1790
+ rb_define_method(cExitStruct, "==", rb_ext_ExitStruct_equal, 1);
1791
+ rb_define_method(cExitStruct, "inspect", rb_ext_ExitStruct_inspect, 0);
1352
1792
 
1353
1793
  cEntry = rb_define_class_under(mNewt, "Entry", cWidget);
1354
- rb_define_singleton_method(cEntry, "new", rb_ext_Entry_new, 5);
1794
+ rb_define_singleton_method(cEntry, "new", rb_ext_Entry_new, -1);
1355
1795
  rb_define_method(cEntry, "set", rb_ext_Entry_Set, 2);
1356
1796
  rb_define_method(cEntry, "get", rb_ext_Entry_GetValue, 0);
1357
- rb_define_method(cEntry, "set_flags", rb_ext_Entry_SetFlags, -2);
1797
+ rb_define_method(cEntry, "set_filter", rb_ext_Entry_SetFilter, -1);
1798
+ rb_define_method(cEntry, "set_flags", rb_ext_Entry_SetFlags, -1);
1799
+ rb_define_method(cEntry, "set_colors", rb_ext_Entry_SetColors, 2);
1800
+ rb_define_method(cEntry, "get_cursor_position", rb_ext_Entry_GetCursorPosition, 0);
1801
+ rb_define_method(cEntry, "set_cursor_position", rb_ext_Entry_SetCursorPosition, 1);
1358
1802
 
1359
1803
  cScale = rb_define_class_under(mNewt, "Scale", cWidget);
1360
1804
  rb_define_singleton_method(cScale, "new", rb_ext_Scale_new, 4);
1361
1805
  rb_define_method(cScale, "set", rb_ext_Scale_Set, 1);
1362
-
1806
+ rb_define_method(cScale, "set_colors", rb_ext_Scale_SetColors, 2);
1363
1807
 
1364
1808
  cGrid = rb_define_class_under(mNewt, "Grid", cWidget);
1365
1809
  rb_define_singleton_method(cGrid, "new", rb_ext_Grid_new, 2);
1366
- /*rb_define_method(cGrid, "destroy", rb_ext_Grid_Destroy, 0);*/
1367
1810
  rb_define_method(cGrid, "set_field", rb_ext_Grid_SetField, 10);
1368
- rb_define_method(cGrid, "wrapped_window", rb_ext_Grid_WrappedWindow, -2);
1811
+ rb_define_method(cGrid, "wrapped_window", rb_ext_Grid_WrappedWindow, -1);
1369
1812
  rb_define_method(cGrid, "get_size", rb_ext_Grid_GetSize, 0);
1370
1813
 
1371
1814
  rb_define_const(mNewt, "COLORSET_ROOT", INT2FIX(NEWT_COLORSET_ROOT));
@@ -1412,6 +1855,10 @@ void Init_ruby_newt(){
1412
1855
  rb_define_const(mNewt, "FLAG_PASSWORD", INT2FIX(NEWT_FLAG_PASSWORD));
1413
1856
  rb_define_const(mNewt, "FLAG_SHOWCURSOR", INT2FIX(NEWT_FLAG_SHOWCURSOR));
1414
1857
 
1858
+ rb_define_const(mNewt, "FD_READ", INT2FIX(NEWT_FD_READ));
1859
+ rb_define_const(mNewt, "FD_WRITE", INT2FIX(NEWT_FD_WRITE));
1860
+ rb_define_const(mNewt, "FD_EXCEPT", INT2FIX(NEWT_FD_EXCEPT));
1861
+
1415
1862
  rb_define_const(mNewt, "ANCHOR_LEFT", INT2FIX(NEWT_ANCHOR_LEFT));
1416
1863
  rb_define_const(mNewt, "ANCHOR_RIGHT", INT2FIX(NEWT_ANCHOR_RIGHT));
1417
1864
  rb_define_const(mNewt, "ANCHOR_TOP", INT2FIX(NEWT_ANCHOR_TOP));
@@ -1423,6 +1870,12 @@ void Init_ruby_newt(){
1423
1870
  rb_define_const(mNewt, "GRID_COMPONENT", INT2FIX(NEWT_GRID_COMPONENT));
1424
1871
  rb_define_const(mNewt, "GRID_SUBGRID", INT2FIX(NEWT_GRID_SUBGRID));
1425
1872
 
1873
+ rb_define_const(mNewt, "KEY_TAB", INT2FIX(NEWT_KEY_TAB));
1874
+ rb_define_const(mNewt, "KEY_ENTER", INT2FIX(NEWT_KEY_ENTER));
1875
+ rb_define_const(mNewt, "KEY_SUSPEND", INT2FIX(NEWT_KEY_SUSPEND));
1876
+ rb_define_const(mNewt, "KEY_ESCAPE", INT2FIX(NEWT_KEY_ESCAPE));
1877
+ rb_define_const(mNewt, "KEY_RETURN", INT2FIX(NEWT_KEY_RETURN));
1878
+
1426
1879
  rb_define_const(mNewt, "KEY_UP", INT2FIX(NEWT_KEY_UP));
1427
1880
  rb_define_const(mNewt, "KEY_DOWN", INT2FIX(NEWT_KEY_DOWN));
1428
1881
  rb_define_const(mNewt, "KEY_LEFT", INT2FIX(NEWT_KEY_LEFT));
@@ -1448,4 +1901,13 @@ void Init_ruby_newt(){
1448
1901
  rb_define_const(mNewt, "KEY_F10", INT2FIX(NEWT_KEY_F10));
1449
1902
  rb_define_const(mNewt, "KEY_F11", INT2FIX(NEWT_KEY_F11));
1450
1903
  rb_define_const(mNewt, "KEY_F12", INT2FIX(NEWT_KEY_F12));
1904
+
1905
+ rb_define_const(mNewt, "KEY_RESIZE", INT2FIX(NEWT_KEY_RESIZE));
1906
+ rb_define_const(mNewt, "KEY_ERROR", INT2FIX(NEWT_KEY_ERROR));
1907
+
1908
+ rb_define_const(mNewt, "EXIT_HOTKEY", INT2FIX(NEWT_EXIT_HOTKEY));
1909
+ rb_define_const(mNewt, "EXIT_COMPONENT", INT2FIX(NEWT_EXIT_COMPONENT));
1910
+ rb_define_const(mNewt, "EXIT_FDREADY", INT2FIX(NEWT_EXIT_FDREADY));
1911
+ rb_define_const(mNewt, "EXIT_TIMER", INT2FIX(NEWT_EXIT_TIMER));
1912
+ rb_define_const(mNewt, "EXIT_ERROR", INT2FIX(NEWT_EXIT_ERROR));
1451
1913
  }