newt 0.9.6 → 1.0.0

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