newt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1331 @@
1
+ /*
2
+ *
3
+ * by Noritsugu Nakamura
4
+ * from 2001.04.20
5
+ *
6
+ * modified by Eric Sperano
7
+ * 2012.02.27
8
+ */
9
+
10
+ #include <ruby.h>
11
+ #include <rubyio.h>
12
+ #include <newt.h>
13
+
14
+ static VALUE mNewt;
15
+ static VALUE mScreen;
16
+ static VALUE cWidget;
17
+ static VALUE cForm;
18
+ static VALUE cLabel;
19
+ static VALUE cCompactButton;
20
+ static VALUE cButton;
21
+ static VALUE cCheckbox;
22
+ static VALUE cRadioButton;
23
+
24
+ static VALUE cListbox;
25
+ static VALUE cCheckboxTree;
26
+ static VALUE cCheckboxTreeMulti;
27
+ static VALUE cTextbox;
28
+ static VALUE cTextboxReflowed;
29
+ static VALUE cEntry;
30
+ static VALUE cScale;
31
+ static VALUE cGrid;
32
+
33
+ static ID rb_call_id;
34
+ static VALUE rb_ext_Widget_CALLBACK_HASH;
35
+
36
+ typedef struct snackWidget_s snackWidget;
37
+
38
+ struct callbackStruct {
39
+ VALUE *cb, *data;
40
+ };
41
+
42
+ struct snackWidget_s {
43
+ newtComponent co;
44
+ char achar;
45
+ void * apointer;
46
+ int anint;
47
+ struct callbackStruct scs;
48
+ };
49
+
50
+
51
+ static VALUE
52
+ rb_ext_ReflowText(VALUE self, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp)
53
+ {
54
+ int actualWidth, actualHeight;
55
+ char *p;
56
+ VALUE ary = rb_ary_new2(3);
57
+
58
+ p = newtReflowText(STR2CSTR(text), NUM2INT(width), NUM2INT(flexDown), NUM2INT(flexUp),
59
+ &actualWidth, &actualHeight);
60
+
61
+ rb_ary_push(ary, rb_str_new2(p));
62
+ rb_ary_push(ary, INT2NUM(actualWidth));
63
+ rb_ary_push(ary, INT2NUM(actualHeight));
64
+ return ary;
65
+ }
66
+
67
+ static VALUE
68
+ rb_ext_Screen_new()
69
+ {
70
+ newtInit();
71
+ newtCls();
72
+
73
+ return Qnil;
74
+ }
75
+
76
+ static VALUE
77
+ rb_ext_Screen_Init()
78
+ {
79
+ newtInit();
80
+ return Qnil;
81
+ }
82
+
83
+ static VALUE
84
+ rb_ext_Screen_Cls()
85
+ {
86
+ newtCls();
87
+ return Qnil;
88
+ }
89
+
90
+ static VALUE
91
+ rb_ext_Screen_Finished()
92
+ {
93
+ newtFinished();
94
+
95
+ return Qnil;
96
+ }
97
+
98
+ static VALUE
99
+ rb_ext_Screen_WaitForKey()
100
+ {
101
+ newtWaitForKey();
102
+
103
+ return Qnil;
104
+ }
105
+
106
+ static VALUE
107
+ rb_ext_Screen_ClearKeyBuffer()
108
+ {
109
+ newtClearKeyBuffer();
110
+
111
+ return Qnil;
112
+ }
113
+
114
+ static VALUE
115
+ rb_ext_Screen_OpenWindow(VALUE self, VALUE left, VALUE top,
116
+ VALUE width, VALUE height, VALUE title)
117
+ {
118
+ return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top),
119
+ NUM2INT(width), NUM2INT(height), STR2CSTR(title)));
120
+ }
121
+
122
+ static VALUE
123
+ rb_ext_Screen_CenteredWindow(VALUE self, VALUE width, VALUE height, VALUE title)
124
+ {
125
+ return INT2NUM(newtCenteredWindow(NUM2INT(width), NUM2INT(height), STR2CSTR(title)));
126
+ }
127
+
128
+ static VALUE
129
+ rb_ext_Screen_PopWindow(VALUE self)
130
+ {
131
+ newtPopWindow();
132
+ return Qnil;
133
+ }
134
+
135
+
136
+ static VALUE
137
+ rb_ext_Screen_Resume()
138
+ {
139
+ newtResume();
140
+
141
+ return Qnil;
142
+ }
143
+
144
+ static VALUE
145
+ rb_ext_Screen_Suspend()
146
+ {
147
+ newtSuspend();
148
+
149
+ return Qnil;
150
+ }
151
+
152
+ static VALUE
153
+ rb_ext_Screen_Refresh()
154
+ {
155
+ newtRefresh();
156
+
157
+ return Qnil;
158
+ }
159
+
160
+ static VALUE
161
+ rb_ext_Screen_DrawRootText(VALUE self, VALUE col, VALUE row, VALUE text)
162
+ {
163
+
164
+ newtDrawRootText(NUM2INT(col), NUM2INT(row), STR2CSTR(text));
165
+ return Qnil;
166
+ }
167
+
168
+ static VALUE
169
+ rb_ext_Screen_PushHelpLine(VALUE self, VALUE text)
170
+ {
171
+ newtPushHelpLine(STR2CSTR(text));
172
+
173
+ return Qnil;
174
+ }
175
+
176
+ static VALUE
177
+ rb_ext_Screen_RedrawHelpLine(VALUE self)
178
+ {
179
+ newtRedrawHelpLine();
180
+
181
+ return Qnil;
182
+ }
183
+
184
+ static VALUE
185
+ rb_ext_Screen_PopHelpLine(VALUE self)
186
+ {
187
+ newtPopHelpLine();
188
+
189
+ return Qnil;
190
+ }
191
+
192
+ static VALUE
193
+ rb_ext_Screen_Bell(VALUE self)
194
+ {
195
+ newtBell();
196
+
197
+ return Qnil;
198
+ }
199
+
200
+ static VALUE
201
+ rb_ext_Screen_Size(VALUE self)
202
+ {
203
+ int cols, rows;
204
+ VALUE ary = rb_ary_new2(2);
205
+
206
+ newtGetScreenSize(&cols, &rows);
207
+ rb_ary_push(ary, INT2NUM(cols));
208
+ rb_ary_push(ary, INT2NUM(rows));
209
+
210
+ return ary;
211
+ }
212
+
213
+ static VALUE
214
+ rb_ext_Screen_WinMessage(VALUE self, VALUE args)
215
+ {
216
+ if (RARRAY(args)->len < 3) {
217
+ rb_raise(rb_eArgError, "3 arguments required");
218
+ } else {
219
+
220
+ newtWinMessage(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]), STR2CSTR(RARRAY(args)->ptr[2]));
221
+ }
222
+
223
+ return Qnil;
224
+ }
225
+
226
+ static VALUE
227
+ rb_ext_Screen_WinChoice(VALUE self, VALUE args)
228
+ {
229
+ if (RARRAY(args)->len < 4) {
230
+ rb_raise(rb_eArgError, "4 arguments required");
231
+ } else {
232
+
233
+ newtWinChoice(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]),
234
+ STR2CSTR(RARRAY(args)->ptr[2]), STR2CSTR(RARRAY(args)->ptr[3]));
235
+ }
236
+
237
+ return Qnil;
238
+ }
239
+
240
+ static VALUE
241
+ rb_ext_Screen_WinMenu(VALUE self, VALUE args)
242
+ {
243
+ int len, i, listItem;
244
+ char **cptr;
245
+
246
+ len = RARRAY(args)->len;
247
+ if (len == 8) {
248
+ Check_Type(RARRAY(args)->ptr[6], T_ARRAY);
249
+
250
+ len = RARRAY(RARRAY(args)->ptr[6])->len;
251
+ cptr = ALLOCA_N(char*, len + 1);
252
+ for (i = 0; i < len; i++) {
253
+ Check_Type(RARRAY(RARRAY(args)->ptr[6])->ptr[i], T_STRING);
254
+ cptr[i] = STR2CSTR(RARRAY(RARRAY(args)->ptr[6])->ptr[i]);
255
+ }
256
+ cptr[len] = NULL;
257
+
258
+ newtWinMenu(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]),
259
+ NUM2INT(RARRAY(args)->ptr[2]),
260
+ NUM2INT(RARRAY(args)->ptr[3]), NUM2INT(RARRAY(args)->ptr[4]),
261
+ NUM2INT(RARRAY(args)->ptr[5]),
262
+ cptr, &listItem, STR2CSTR(RARRAY(args)->ptr[7]), NULL);
263
+ return INT2NUM(listItem);
264
+ } else if (len == 9) {
265
+ Check_Type(RARRAY(args)->ptr[6], T_ARRAY);
266
+
267
+ len = RARRAY(RARRAY(args)->ptr[6])->len;
268
+ cptr = ALLOCA_N(char*, len + 1);
269
+ for (i = 0; i < len; i++) {
270
+ Check_Type(RARRAY(RARRAY(args)->ptr[6])->ptr[i], T_STRING);
271
+ cptr[i] = STR2CSTR(RARRAY(RARRAY(args)->ptr[6])->ptr[i]);
272
+ }
273
+ cptr[len] = NULL;
274
+
275
+ newtWinMenu(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]),
276
+ NUM2INT(RARRAY(args)->ptr[2]),
277
+ NUM2INT(RARRAY(args)->ptr[3]), NUM2INT(RARRAY(args)->ptr[4]),
278
+ NUM2INT(RARRAY(args)->ptr[5]),
279
+ cptr, &listItem, STR2CSTR(RARRAY(args)->ptr[7]), STR2CSTR(RARRAY(args)->ptr[8]), NULL);
280
+ return INT2NUM(listItem);
281
+ } else {
282
+ rb_raise(rb_eArgError, "8 or 9 arguments required");
283
+ }
284
+
285
+ return Qnil;
286
+ }
287
+
288
+ static VALUE
289
+ rb_ext_Screen_WinEntries(VALUE self, VALUE args)
290
+ {
291
+ int len, i;
292
+ struct newtWinEntry *items;
293
+ char * entries[10];
294
+ VALUE ary;
295
+
296
+ memset(entries, 0, sizeof(entries));
297
+ ary = rb_ary_new();
298
+
299
+ len = RARRAY(args)->len;
300
+ if (len == 8) {
301
+ Check_Type(RARRAY(args)->ptr[6], T_ARRAY);
302
+
303
+ len = RARRAY(RARRAY(args)->ptr[6])->len;
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(RARRAY(args)->ptr[6])->ptr[i], T_STRING);
308
+ items[i].text = STR2CSTR(RARRAY(RARRAY(args)->ptr[6])->ptr[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(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]),
317
+ NUM2INT(RARRAY(args)->ptr[2]),
318
+ NUM2INT(RARRAY(args)->ptr[3]), NUM2INT(RARRAY(args)->ptr[4]),
319
+ NUM2INT(RARRAY(args)->ptr[5]),
320
+ items, STR2CSTR(RARRAY(args)->ptr[7]), NULL);
321
+ for (i = 0; i < len; i++) {
322
+ rb_ary_push(ary, rb_str_new2(entries[i]));
323
+ }
324
+ return ary;
325
+ } else if (len == 9) {
326
+ Check_Type(RARRAY(args)->ptr[6], T_ARRAY);
327
+
328
+ len = RARRAY(RARRAY(args)->ptr[6])->len;
329
+ if (len > 8) rb_raise(rb_eArgError, "8 or less arguments required");
330
+ items = ALLOCA_N(struct newtWinEntry, len + 1);
331
+ for (i = 0; i < len; i++) {
332
+ Check_Type(RARRAY(RARRAY(args)->ptr[6])->ptr[i], T_STRING);
333
+ items[i].text = STR2CSTR(RARRAY(RARRAY(args)->ptr[6])->ptr[i]);
334
+ items[i].value = entries + i;
335
+ items[i].flags = 0;
336
+ }
337
+ items[len].text = NULL;
338
+ items[len].value = NULL;
339
+ items[len].flags = 0;
340
+
341
+ newtWinEntries(STR2CSTR(RARRAY(args)->ptr[0]), STR2CSTR(RARRAY(args)->ptr[1]),
342
+ NUM2INT(RARRAY(args)->ptr[2]),
343
+ NUM2INT(RARRAY(args)->ptr[3]), NUM2INT(RARRAY(args)->ptr[4]),
344
+ NUM2INT(RARRAY(args)->ptr[5]),
345
+ items, STR2CSTR(RARRAY(args)->ptr[7]), STR2CSTR(RARRAY(args)->ptr[8]), NULL);
346
+ for (i = 0; i < len; i++) {
347
+ rb_ary_push(ary, rb_str_new2(entries[i]));
348
+ }
349
+ return ary;
350
+ } else {
351
+ rb_raise(rb_eArgError, "8 or 9 arguments required");
352
+ }
353
+
354
+ return Qnil;
355
+ }
356
+
357
+ void
358
+ rb_ext_Widget_callback_function(newtComponent co, void *proc)
359
+ {
360
+ VALUE widget;
361
+
362
+ widget = Data_Wrap_Struct(cWidget, 0, 0, co);
363
+ if(SYMBOL_P(proc)){
364
+ rb_funcall(rb_mKernel, SYM2ID((VALUE)proc), 1, widget);
365
+ }
366
+ else{
367
+ rb_funcall((VALUE)proc, rb_call_id, 1, widget);
368
+ };
369
+ };
370
+
371
+ static VALUE
372
+ rb_ext_Widget_callback(int argc, VALUE argv[], VALUE self)
373
+ {
374
+ newtComponent co;
375
+ VALUE arg1, value;
376
+
377
+ Data_Get_Struct(self, struct newtComponent_struct, co);
378
+ switch(rb_scan_args(argc, argv, "01", &arg1)){
379
+ case 0:
380
+ value = rb_hash_aref(rb_ext_Widget_CALLBACK_HASH, self);
381
+ break;
382
+ case 1:
383
+ rb_hash_aset(rb_ext_Widget_CALLBACK_HASH, self, arg1);
384
+ newtComponentAddCallback(co, rb_ext_Widget_callback_function, (void*)arg1);
385
+ value = Qnil;
386
+ break;
387
+ default:
388
+ rb_bug("rb_ext_Widget_callback");
389
+ };
390
+
391
+ return value;
392
+ }
393
+
394
+ static VALUE
395
+ rb_ext_Widget_equal(VALUE self, VALUE widget)
396
+ {
397
+ newtComponent co, co2;
398
+
399
+ if (NIL_P(widget)) return Qfalse;
400
+ if (self == widget) return Qtrue;
401
+
402
+ Data_Get_Struct(self, struct newtComponent_struct, co);
403
+ Data_Get_Struct(widget, struct newtComponent_struct, co2);
404
+ /*fprintf(stderr, "* %p %p", co, co2);*/
405
+ if (co == co2) return Qtrue;
406
+ return Qfalse;
407
+ }
408
+
409
+ static VALUE
410
+ rb_ext_Label_new(VALUE self, VALUE left, VALUE top, VALUE text)
411
+ {
412
+ newtComponent co;
413
+
414
+ co = newtLabel(NUM2INT(left), NUM2INT(top), STR2CSTR(text));
415
+ return Data_Wrap_Struct(self, 0, 0, co);
416
+ }
417
+
418
+ static VALUE
419
+ rb_ext_Label_SetText(VALUE self, VALUE text)
420
+ {
421
+ newtComponent co;
422
+
423
+ Data_Get_Struct(self, struct newtComponent_struct, co);
424
+ newtLabelSetText(co, STR2CSTR(text));
425
+ return Qnil;
426
+ }
427
+
428
+ static VALUE
429
+ rb_ext_CompactButton_new(VALUE self, VALUE left, VALUE top, VALUE text)
430
+ {
431
+ newtComponent co;
432
+
433
+ co = newtCompactButton(NUM2INT(left), NUM2INT(top), STR2CSTR(text));
434
+ return Data_Wrap_Struct(self, 0, 0, co);
435
+ }
436
+
437
+ static VALUE
438
+ rb_ext_Button_new(VALUE self, VALUE left, VALUE top, VALUE text)
439
+ {
440
+ newtComponent co;
441
+
442
+ co = newtButton(NUM2INT(left), NUM2INT(top), STR2CSTR(text));
443
+ return Data_Wrap_Struct(self, 0, 0, co);
444
+ }
445
+
446
+ static VALUE
447
+ rb_ext_Checkbox_new(VALUE self, VALUE left, VALUE top, VALUE text,
448
+ VALUE defValue, VALUE seq)
449
+ {
450
+ newtComponent co;
451
+
452
+ if (NIL_P(seq)) {
453
+ co = newtCheckbox(NUM2INT(left), NUM2INT(top), STR2CSTR(text),
454
+ STR2CSTR(defValue)[0], NULL, NULL);
455
+ } else {
456
+ co = newtCheckbox(NUM2INT(left), NUM2INT(top), STR2CSTR(text),
457
+ STR2CSTR(defValue)[0], STR2CSTR(seq), NULL);
458
+ }
459
+ return Data_Wrap_Struct(self, 0, 0, co);
460
+ }
461
+
462
+ static VALUE
463
+ rb_ext_Checkbox_GetValue(VALUE self)
464
+ {
465
+ newtComponent co;
466
+ char value[10];
467
+
468
+ Data_Get_Struct(self, struct newtComponent_struct, co);
469
+ value[0] = newtCheckboxGetValue(co);
470
+ value[1] = '\0';
471
+ return rb_str_new2(value);
472
+ }
473
+
474
+ static VALUE
475
+ rb_ext_Checkbox_SetValue(VALUE self, VALUE value)
476
+ {
477
+ newtComponent co;
478
+
479
+ Data_Get_Struct(self, struct newtComponent_struct, co);
480
+ if (RSTRING(value)->len > 0) {
481
+ newtCheckboxSetValue(co, STR2CSTR(value)[0]);
482
+ }
483
+ return Qnil;
484
+ }
485
+
486
+ static VALUE
487
+ rb_ext_Checkbox_SetFlags(VALUE self, VALUE args)
488
+ {
489
+ newtComponent co;
490
+ int len;
491
+
492
+ len = RARRAY(args)->len;
493
+ if (len == 1) {
494
+ Data_Get_Struct(self, struct newtComponent_struct, co);
495
+ newtCheckboxSetFlags(co, NUM2INT(RARRAY(args)->ptr[0]), NEWT_FLAGS_SET);
496
+ } else if (len == 2) {
497
+ Data_Get_Struct(self, struct newtComponent_struct, co);
498
+ newtCheckboxSetFlags(co, NUM2INT(RARRAY(args)->ptr[0]), NUM2INT(RARRAY(args)->ptr[1]));
499
+ } else {
500
+ rb_raise(rb_eArgError, "1 argument or 2 arguments required");
501
+ }
502
+
503
+ return Qnil;
504
+ }
505
+
506
+ static VALUE
507
+ rb_ext_RadioButton_new(VALUE self, VALUE left, VALUE top, VALUE text,
508
+ VALUE isDefault, VALUE prevButton)
509
+ {
510
+ newtComponent co, cco;
511
+
512
+ if (NIL_P(prevButton)) {
513
+ co = newtRadiobutton(NUM2INT(left), NUM2INT(top), STR2CSTR(text),
514
+ NUM2INT(isDefault), NULL);
515
+ } else {
516
+ Data_Get_Struct(prevButton, struct newtComponent_struct, cco);
517
+ co = newtRadiobutton(NUM2INT(left), NUM2INT(top), STR2CSTR(text),
518
+ NUM2INT(isDefault), cco);
519
+ }
520
+ return Data_Wrap_Struct(self, 0, 0, co);
521
+ }
522
+
523
+ static VALUE
524
+ rb_ext_Listbox_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags)
525
+ {
526
+ newtComponent co;
527
+
528
+ co = newtListbox(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags));
529
+ return Data_Wrap_Struct(self, 0, 0, co);
530
+ }
531
+
532
+ static VALUE
533
+ rb_ext_Listbox_GetCurrent(VALUE self)
534
+ {
535
+ newtComponent co;
536
+ int i;
537
+ int *ip;
538
+ char *p;
539
+
540
+ ip = &i;
541
+
542
+ Data_Get_Struct(self, struct newtComponent_struct, co);
543
+ /*p = (char *)newtListboxGetCurrent(co);*/
544
+ ip = (int *)newtListboxGetCurrent(co);
545
+ /*return rb_str_new2(p);*/
546
+ return INT2NUM(i);
547
+ }
548
+
549
+ static VALUE
550
+ rb_ext_Listbox_SetCurrent(VALUE self, VALUE num)
551
+ {
552
+ newtComponent co;
553
+
554
+ Data_Get_Struct(self, struct newtComponent_struct, co);
555
+ newtListboxSetCurrent(co, NUM2INT(num));
556
+ return Qnil;
557
+ }
558
+
559
+ static VALUE
560
+ rb_ext_Listbox_SetCurrentByKey(VALUE self, VALUE key)
561
+ {
562
+ newtComponent co;
563
+
564
+ Data_Get_Struct(self, struct newtComponent_struct, co);
565
+
566
+ switch(TYPE(key)) {
567
+ case T_STRING:
568
+ newtListboxSetCurrentByKey(co, (void *)STR2CSTR(key));
569
+ break;
570
+ case T_FIXNUM:
571
+ newtListboxSetCurrentByKey(co, (void *)NUM2INT(key));
572
+ break;
573
+ default:
574
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
575
+ break;
576
+ }
577
+ return Qnil;
578
+ }
579
+
580
+ static VALUE
581
+ rb_ext_Listbox_SetEntry(VALUE self, VALUE num, VALUE text)
582
+ {
583
+ newtComponent co;
584
+
585
+ Data_Get_Struct(self, struct newtComponent_struct, co);
586
+ newtListboxSetEntry(co, NUM2INT(num), STR2CSTR(text));
587
+ return Qnil;
588
+ }
589
+
590
+ static VALUE
591
+ rb_ext_Listbox_SetWidth(VALUE self, VALUE width)
592
+ {
593
+ newtComponent co;
594
+
595
+ Data_Get_Struct(self, struct newtComponent_struct, co);
596
+ newtListboxSetWidth(co, NUM2INT(width));
597
+ return Qnil;
598
+ }
599
+
600
+ static VALUE
601
+ rb_ext_Listbox_SetData(VALUE self, VALUE num, VALUE data)
602
+ {
603
+ newtComponent co;
604
+
605
+ Data_Get_Struct(self, struct newtComponent_struct, co);
606
+
607
+ switch(TYPE(data)) {
608
+ case T_STRING:
609
+ newtListboxSetData(co, NUM2INT(num), (void *)STR2CSTR(data));
610
+ break;
611
+ case T_FIXNUM:
612
+ newtListboxSetData(co, NUM2INT(num), (void *)NUM2INT(data));
613
+ break;
614
+ default:
615
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
616
+ break;
617
+ }
618
+ return Qnil;
619
+ }
620
+
621
+ static VALUE
622
+ rb_ext_Listbox_AppendEntry(VALUE self, VALUE text, VALUE data)
623
+ {
624
+ newtComponent co;
625
+
626
+ Data_Get_Struct(self, struct newtComponent_struct, co);
627
+
628
+ switch(TYPE(data)) {
629
+ case T_STRING:
630
+ newtListboxAppendEntry(co, STR2CSTR(text), (void *)STR2CSTR(data));
631
+ break;
632
+ case T_FIXNUM:
633
+ newtListboxAppendEntry(co, STR2CSTR(text), (void *)NUM2INT(data));
634
+ break;
635
+ default:
636
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
637
+ break;
638
+ }
639
+ return Qnil;
640
+ }
641
+
642
+ static VALUE
643
+ rb_ext_Listbox_InsertEntry(VALUE self, VALUE text, VALUE data, VALUE key)
644
+ {
645
+ newtComponent co;
646
+
647
+ Data_Get_Struct(self, struct newtComponent_struct, co);
648
+
649
+ switch(TYPE(data)) {
650
+ case T_STRING:
651
+ switch(TYPE(key)) {
652
+ case T_STRING:
653
+ newtListboxInsertEntry(co, STR2CSTR(text), (void *)STR2CSTR(data), (void *)STR2CSTR(key));
654
+ break;
655
+ case T_FIXNUM:
656
+ newtListboxInsertEntry(co, STR2CSTR(text), (void *)STR2CSTR(data), (void *)NUM2INT(key));
657
+ break;
658
+ default:
659
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
660
+ break;
661
+ }
662
+ case T_FIXNUM:
663
+ switch(TYPE(key)) {
664
+ case T_STRING:
665
+ newtListboxInsertEntry(co, STR2CSTR(text), (void *)NUM2INT(data), (void *)STR2CSTR(key));
666
+ break;
667
+ case T_FIXNUM:
668
+ newtListboxInsertEntry(co, STR2CSTR(text), (void *)NUM2INT(data), (void *)NUM2INT(key));
669
+ break;
670
+ default:
671
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
672
+ break;
673
+ }
674
+ break;
675
+ default:
676
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
677
+ break;
678
+ }
679
+ return Qnil;
680
+ }
681
+
682
+ static VALUE
683
+ rb_ext_Listbox_DeleteEntry(VALUE self, VALUE data)
684
+ {
685
+ newtComponent co;
686
+
687
+ Data_Get_Struct(self, struct newtComponent_struct, co);
688
+
689
+ switch(TYPE(data)) {
690
+ case T_STRING:
691
+ newtListboxDeleteEntry(co, (void *)STR2CSTR(data));
692
+ break;
693
+ case T_FIXNUM:
694
+ newtListboxDeleteEntry(co, (void *)NUM2INT(data));
695
+ break;
696
+ default:
697
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
698
+ break;
699
+ }
700
+ return Qnil;
701
+ }
702
+
703
+ static VALUE
704
+ rb_ext_Listbox_Clear(VALUE self)
705
+ {
706
+ newtComponent co;
707
+
708
+ Data_Get_Struct(self, struct newtComponent_struct, co);
709
+
710
+ newtListboxClear(co);
711
+ return Qnil;
712
+ }
713
+
714
+ static VALUE
715
+ rb_ext_Listbox_ClearSelection(VALUE self)
716
+ {
717
+ newtComponent co;
718
+
719
+ Data_Get_Struct(self, struct newtComponent_struct, co);
720
+
721
+ newtListboxClearSelection(co);
722
+ return Qnil;
723
+ }
724
+
725
+ static VALUE
726
+ rb_ext_Listbox_SelectItem(VALUE self, VALUE key, VALUE sense)
727
+ {
728
+ newtComponent co;
729
+
730
+ Data_Get_Struct(self, struct newtComponent_struct, co);
731
+
732
+ switch(TYPE(key)) {
733
+ case T_STRING:
734
+ newtListboxSelectItem(co, (void *)STR2CSTR(key), NUM2INT(sense));
735
+ break;
736
+ case T_FIXNUM:
737
+ newtListboxSelectItem(co, (void *)NUM2INT(key), NUM2INT(sense));
738
+ break;
739
+ default:
740
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
741
+ break;
742
+ }
743
+ return Qnil;
744
+ }
745
+
746
+ static VALUE
747
+ rb_ext_CheckboxTree_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags)
748
+ {
749
+ newtComponent co;
750
+
751
+ co = newtCheckboxTree(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags));
752
+ return Data_Wrap_Struct(self, 0, 0, co);
753
+ }
754
+
755
+ static VALUE
756
+ rb_ext_CheckboxTree_AddItem(VALUE self, VALUE args)
757
+ /*rb_ext_CheckboxTree_AddItem(VALUE self, VALUE text, VALUE data, VALUE flags)*/
758
+ /*, VALUE index)*/
759
+ {
760
+ newtComponent co;
761
+ #if 1
762
+ int i, len;
763
+ int *indexes;
764
+
765
+ len = RARRAY(args)->len;
766
+ if (len < 4) {
767
+ rb_raise(rb_eArgError, "4 arguments required");
768
+ } else {
769
+ Data_Get_Struct(self, struct newtComponent_struct, co);
770
+
771
+ indexes = ALLOCA_N(int, (len - 4) + 2);
772
+ for (i = 0; i < (len - 4) + 1; i++) {
773
+ indexes[i] = NUM2INT(RARRAY(args)->ptr[i+3]);
774
+ }
775
+ indexes[(len - 4) + 1] = NEWT_ARG_LAST;
776
+
777
+ switch(TYPE(RARRAY(args)->ptr[1])) {
778
+ case T_STRING:
779
+ newtCheckboxTreeAddArray(co, STR2CSTR(RARRAY(args)->ptr[0]), (void *)STR2CSTR(RARRAY(args)->ptr[1]),
780
+ NUM2INT(RARRAY(args)->ptr[2]), indexes);
781
+ break;
782
+ case T_FIXNUM:
783
+ newtCheckboxTreeAddArray(co, STR2CSTR(RARRAY(args)->ptr[0]), (void *)NUM2INT(RARRAY(args)->ptr[1]),
784
+ NUM2INT(RARRAY(args)->ptr[2]), indexes);
785
+ break;
786
+ default:
787
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
788
+ break;
789
+ }
790
+ return Qnil;
791
+ }
792
+ #else
793
+ Data_Get_Struct(self, struct newtComponent_struct, co);
794
+
795
+ switch(TYPE(data)) {
796
+ case T_STRING:
797
+ newtCheckboxTreeAddItem(co, STR2CSTR(text), (void *)STR2CSTR(data), NUM2INT(flags), NEWT_ARG_APPEND, NEWT_ARG_LAST);
798
+ break;
799
+ case T_FIXNUM:
800
+ newtCheckboxTreeAddItem(co, STR2CSTR(text), (void *)NUM2INT(data), NUM2INT(flags), NEWT_ARG_APPEND, NEWT_ARG_LAST);
801
+ break;
802
+ default:
803
+ rb_raise(rb_eTypeError, "String or Fixnum expected");
804
+ break;
805
+ }
806
+ return Qnil;
807
+ #endif
808
+ }
809
+
810
+ static VALUE
811
+ rb_ext_CheckboxTreeMulti_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE seq, VALUE flags)
812
+ {
813
+ newtComponent co;
814
+
815
+ if (NIL_P(seq)) {
816
+ co = newtCheckboxTreeMulti(NUM2INT(left), NUM2INT(top), NUM2INT(height), NULL, NUM2INT(flags));
817
+ } else {
818
+ co = newtCheckboxTreeMulti(NUM2INT(left), NUM2INT(top), NUM2INT(height), STR2CSTR(seq), NUM2INT(flags));
819
+ }
820
+ return Data_Wrap_Struct(self, 0, 0, co);
821
+ }
822
+
823
+ static VALUE
824
+ rb_ext_Textbox_new(VALUE self, VALUE left, VALUE top, VALUE width, VALUE height, VALUE flags)
825
+ {
826
+ newtComponent co;
827
+
828
+ co = newtTextbox(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(height), NUM2INT(flags));
829
+ return Data_Wrap_Struct(self, 0, 0, co);
830
+ }
831
+
832
+ static VALUE
833
+ rb_ext_Textbox_SetText(VALUE self, VALUE text)
834
+ {
835
+ newtComponent co;
836
+
837
+ Data_Get_Struct(self, struct newtComponent_struct, co);
838
+ newtTextboxSetText(co, STR2CSTR(text));
839
+ return Qnil;
840
+ }
841
+
842
+ static VALUE
843
+ rb_ext_Textbox_SetHeight(VALUE self, VALUE height)
844
+ {
845
+ newtComponent co;
846
+
847
+ Data_Get_Struct(self, struct newtComponent_struct, co);
848
+ newtTextboxSetHeight(co, NUM2INT(height));
849
+ return Qnil;
850
+ }
851
+
852
+ static VALUE
853
+ rb_ext_Textbox_GetNumLines(VALUE self)
854
+ {
855
+ newtComponent co;
856
+
857
+ Data_Get_Struct(self, struct newtComponent_struct, co);
858
+ return INT2NUM(newtTextboxGetNumLines(co));
859
+ }
860
+
861
+ static VALUE
862
+ rb_ext_TextboxReflowed_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp, VALUE flags)
863
+ {
864
+ newtComponent co;
865
+
866
+ co = newtTextboxReflowed(NUM2INT(left), NUM2INT(top), STR2CSTR(text), NUM2INT(width),
867
+ NUM2INT(flexDown), NUM2INT(flexUp), NUM2INT(flags));
868
+ return Data_Wrap_Struct(self, 0, 0, co);
869
+ }
870
+
871
+ static void
872
+ rb_ext_Form_Destroy(VALUE self)
873
+ {
874
+ newtComponent form;
875
+
876
+ if (self) {
877
+ Data_Get_Struct(cForm, struct newtComponent_struct, form);
878
+ newtFormDestroy(form);
879
+ }
880
+ }
881
+
882
+ static VALUE
883
+ rb_ext_Form_new(VALUE self, VALUE left, VALUE top, VALUE text)
884
+ {
885
+ newtComponent co;
886
+
887
+ co = newtForm(NULL, NULL, 0);
888
+ return Data_Wrap_Struct(self, 0, rb_ext_Form_Destroy, co);
889
+ }
890
+
891
+ static VALUE
892
+ rb_ext_Form_SetBackground(VALUE self, VALUE color)
893
+ {
894
+ newtComponent form;
895
+
896
+ Data_Get_Struct(self, struct newtComponent_struct, form);
897
+ newtFormSetBackground(form, NUM2INT(color));
898
+ return Qnil;
899
+ }
900
+
901
+ #if 0
902
+ static VALUE
903
+ rb_ext_Form_AddComponent(VALUE self, VALUE co)
904
+ {
905
+ newtComponent form, cco;
906
+
907
+ Data_Get_Struct(self, struct newtComponent_struct, form);
908
+ Data_Get_Struct(co, struct newtComponent_struct, cco);
909
+ newtFormAddComponent(form, cco);
910
+ return Qnil;
911
+ }
912
+ #endif
913
+
914
+ static VALUE
915
+ rb_ext_Form_AddComponents(VALUE self, VALUE co)
916
+ {
917
+ int i;
918
+ newtComponent form, cco;
919
+
920
+ Data_Get_Struct(self, struct newtComponent_struct, form);
921
+
922
+ for (i = 0; i < RARRAY(co)->len; i++) {
923
+ Data_Get_Struct(RARRAY(co)->ptr[i], struct newtComponent_struct, cco);
924
+ newtFormAddComponent(form, cco);
925
+ }
926
+ return Qnil;
927
+ }
928
+
929
+ static VALUE
930
+ rb_ext_Form_SetHeight(VALUE self, VALUE height)
931
+ {
932
+ newtComponent form;
933
+
934
+ Data_Get_Struct(self, struct newtComponent_struct, form);
935
+ newtFormSetHeight(form, NUM2INT(height));
936
+ return Qnil;
937
+ }
938
+
939
+ static VALUE
940
+ rb_ext_Form_SetWidth(VALUE self, VALUE width)
941
+ {
942
+ newtComponent form;
943
+
944
+ Data_Get_Struct(self, struct newtComponent_struct, form);
945
+ newtFormSetWidth(form, NUM2INT(width));
946
+ return Qnil;
947
+ }
948
+
949
+ static VALUE
950
+ rb_ext_Run_Form(VALUE self)
951
+ {
952
+ newtComponent form, co;
953
+
954
+ Data_Get_Struct(self, struct newtComponent_struct, form);
955
+ co = newtRunForm(form);
956
+ return Data_Wrap_Struct(cWidget, 0, 0, co);
957
+ }
958
+
959
+ static VALUE
960
+ rb_ext_Form_DrawForm(VALUE self)
961
+ {
962
+ newtComponent form;
963
+
964
+ Data_Get_Struct(self, struct newtComponent_struct, form);
965
+ newtDrawForm(form);
966
+ return Qnil;
967
+ }
968
+
969
+ static VALUE
970
+ rb_ext_Form_AddHotKey(VALUE self, VALUE key)
971
+ {
972
+ newtComponent form;
973
+
974
+ Data_Get_Struct(self, struct newtComponent_struct, form);
975
+ newtFormAddHotKey(form, NUM2INT(key));
976
+ return Qnil;
977
+ }
978
+
979
+ static VALUE
980
+ rb_ext_Entry_new(VALUE self, VALUE left, VALUE top, VALUE initialValue, VALUE width, VALUE flags)
981
+ {
982
+ newtComponent co;
983
+
984
+ co = newtEntry(NUM2INT(left), NUM2INT(top), STR2CSTR(initialValue), NUM2INT(width),
985
+ NULL, NUM2INT(flags));
986
+ return Data_Wrap_Struct(self, 0, 0, co);
987
+ }
988
+
989
+ static VALUE
990
+ rb_ext_Entry_Set(VALUE self, VALUE value, VALUE cursorAtEnd)
991
+ {
992
+ newtComponent co;
993
+
994
+ Data_Get_Struct(self, struct newtComponent_struct, co);
995
+ switch(TYPE(cursorAtEnd)) {
996
+ case T_TRUE:
997
+ newtEntrySet(co, STR2CSTR(value), 1);
998
+ break;
999
+ case T_FALSE:
1000
+ newtEntrySet(co, STR2CSTR(value), 0);
1001
+ break;
1002
+ case T_FIXNUM:
1003
+ newtEntrySet(co, STR2CSTR(value), NUM2INT(cursorAtEnd));
1004
+ break;
1005
+ default:
1006
+ rb_raise(rb_eTypeError, "Boolean or Fixnum expected");
1007
+ break;
1008
+ }
1009
+
1010
+ return Qnil;
1011
+ }
1012
+
1013
+ static VALUE
1014
+ rb_ext_Entry_GetValue(VALUE self)
1015
+ {
1016
+ newtComponent co;
1017
+
1018
+ Data_Get_Struct(self, struct newtComponent_struct, co);
1019
+ return rb_str_new2(newtEntryGetValue(co));
1020
+ }
1021
+
1022
+ static VALUE
1023
+ rb_ext_Entry_SetFlags(VALUE self, VALUE args)
1024
+ {
1025
+ newtComponent co;
1026
+ int len;
1027
+
1028
+ len = RARRAY(args)->len;
1029
+ if (len == 1) {
1030
+ Data_Get_Struct(self, struct newtComponent_struct, co);
1031
+ newtEntrySetFlags(co, NUM2INT(RARRAY(args)->ptr[0]), NEWT_FLAGS_SET);
1032
+ } else if (len == 2) {
1033
+ Data_Get_Struct(self, struct newtComponent_struct, co);
1034
+ newtEntrySetFlags(co, NUM2INT(RARRAY(args)->ptr[0]), NUM2INT(RARRAY(args)->ptr[1]));
1035
+ } else {
1036
+ rb_raise(rb_eArgError, "1 argument or 2 arguments required");
1037
+ }
1038
+ return Qnil;
1039
+ }
1040
+
1041
+ static VALUE
1042
+ rb_ext_Scale_new(VALUE self, VALUE left, VALUE top, VALUE width, VALUE fullValue)
1043
+ {
1044
+ newtComponent co;
1045
+
1046
+ co = newtScale(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(fullValue));
1047
+ return Data_Wrap_Struct(self, 0, 0, co);
1048
+ }
1049
+
1050
+ static VALUE
1051
+ rb_ext_Scale_Set(VALUE self, VALUE amount)
1052
+ {
1053
+ newtComponent co;
1054
+
1055
+ Data_Get_Struct(self, struct newtComponent_struct, co);
1056
+ newtScaleSet(co, NUM2INT(amount));
1057
+ return Qnil;
1058
+ }
1059
+
1060
+ static void
1061
+ rb_ext_Grid_free(VALUE self)
1062
+ {
1063
+ newtGrid grid;
1064
+
1065
+ if (self) {
1066
+ Data_Get_Struct(cGrid, struct grid_s, grid);
1067
+ newtGridFree(grid, 1);
1068
+ }
1069
+ }
1070
+
1071
+ static VALUE
1072
+ rb_ext_Grid_new(VALUE self, VALUE cols, VALUE rows)
1073
+ {
1074
+ newtGrid grid;
1075
+
1076
+ grid = newtCreateGrid(NUM2INT(cols), NUM2INT(rows));
1077
+ /*return Data_Wrap_Struct(self, 0, 0, grid);*/
1078
+ return Data_Wrap_Struct(self, 0, rb_ext_Grid_free, grid);
1079
+ }
1080
+
1081
+ static VALUE
1082
+ rb_ext_Grid_SetField(VALUE self, VALUE col, VALUE row, VALUE type, VALUE val,
1083
+ VALUE padLeft, VALUE padTop, VALUE padRight, VALUE padBottom,
1084
+ VALUE anchor, VALUE flags)
1085
+ {
1086
+ newtGrid grid;
1087
+ newtComponent co;
1088
+
1089
+ Data_Get_Struct(self, struct grid_s, grid);
1090
+ Data_Get_Struct(val, struct newtComponent_struct, co);
1091
+ newtGridSetField(grid, NUM2INT(col), NUM2INT(row), NUM2INT(type), co,
1092
+ NUM2INT(padLeft), NUM2INT(padTop), NUM2INT(padRight), NUM2INT(padBottom),
1093
+ NUM2INT(anchor), NUM2INT(flags));
1094
+ return Qnil;
1095
+ }
1096
+
1097
+ static VALUE
1098
+ rb_ext_Grid_WrappedWindow(VALUE self, VALUE args)
1099
+ {
1100
+ newtGrid grid;
1101
+ int len;
1102
+
1103
+ len = RARRAY(args)->len;
1104
+ if (len == 1) {
1105
+ Data_Get_Struct(self, struct grid_s, grid);
1106
+ newtGridWrappedWindow(grid, STR2CSTR(RARRAY(args)->ptr[0]));
1107
+ } else if (len == 3) {
1108
+ Data_Get_Struct(self, struct grid_s, grid);
1109
+ newtGridWrappedWindowAt(grid, STR2CSTR(RARRAY(args)->ptr[0]),
1110
+ NUM2INT(STR2CSTR(RARRAY(args)->ptr[1])), NUM2INT(STR2CSTR(RARRAY(args)->ptr[2])));
1111
+ } else {
1112
+ rb_raise(rb_eArgError, "1 argument or 3 arguments required");
1113
+ }
1114
+
1115
+ return Qnil;
1116
+ }
1117
+
1118
+ static VALUE
1119
+ rb_ext_Grid_GetSize(VALUE self)
1120
+ {
1121
+ int width, height;
1122
+ newtGrid grid;
1123
+ VALUE ary = rb_ary_new2(2);
1124
+
1125
+ Data_Get_Struct(self, struct grid_s, grid);
1126
+ newtGridGetSize(grid, &width, &height);
1127
+ rb_ary_push(ary, INT2NUM(width));
1128
+ rb_ary_push(ary, INT2NUM(height));
1129
+
1130
+ return ary;
1131
+ }
1132
+
1133
+
1134
+ void
1135
+ Init_ruby_newt(){
1136
+ mNewt = rb_define_module("Newt");
1137
+ rb_define_module_function(mNewt, "reflow_text", rb_ext_ReflowText, 4);
1138
+
1139
+ mScreen = rb_define_class_under(mNewt, "Screen", rb_cObject);
1140
+ rb_define_module_function(mScreen, "new", rb_ext_Screen_new, 0);
1141
+ rb_define_module_function(mScreen, "init", rb_ext_Screen_Init, 0);
1142
+ rb_define_module_function(mScreen, "cls", rb_ext_Screen_Cls, 0);
1143
+ rb_define_module_function(mScreen, "finish", rb_ext_Screen_Finished, 0);
1144
+ rb_define_module_function(mScreen, "wait_for_key", rb_ext_Screen_WaitForKey, 0);
1145
+ rb_define_module_function(mScreen, "clear_keybuffer", rb_ext_Screen_ClearKeyBuffer, 0);
1146
+ rb_define_module_function(mScreen, "open_window", rb_ext_Screen_OpenWindow, 5);
1147
+ rb_define_module_function(mScreen, "centered_window", rb_ext_Screen_CenteredWindow, 3);
1148
+ rb_define_module_function(mScreen, "pop_window", rb_ext_Screen_PopWindow, 0);
1149
+ rb_define_module_function(mScreen, "refresh", rb_ext_Screen_Refresh, 0);
1150
+ rb_define_module_function(mScreen, "suspend", rb_ext_Screen_Suspend, 0);
1151
+ rb_define_module_function(mScreen, "resume", rb_ext_Screen_Resume, 0);
1152
+ rb_define_module_function(mScreen, "push_helpline", rb_ext_Screen_PushHelpLine, 1);
1153
+ rb_define_module_function(mScreen, "redraw_helpline", rb_ext_Screen_RedrawHelpLine, 0);
1154
+ rb_define_module_function(mScreen, "pop_helpline", rb_ext_Screen_PopHelpLine, 0);
1155
+ rb_define_module_function(mScreen, "draw_roottext", rb_ext_Screen_DrawRootText, 3);
1156
+ rb_define_module_function(mScreen, "bell", rb_ext_Screen_Bell, 0);
1157
+ rb_define_module_function(mScreen, "size", rb_ext_Screen_Size, 0);
1158
+ rb_define_module_function(mScreen, "win_message", rb_ext_Screen_WinMessage, -2);
1159
+ rb_define_module_function(mScreen, "win_choice", rb_ext_Screen_WinChoice, -2);
1160
+ rb_define_module_function(mScreen, "win_menu", rb_ext_Screen_WinMenu, -2);
1161
+ rb_define_module_function(mScreen, "win_entries", rb_ext_Screen_WinEntries, -2);
1162
+
1163
+ rb_ext_Widget_CALLBACK_HASH = rb_hash_new();
1164
+ rb_define_const(mNewt, "CALLBACK_HASH", rb_ext_Widget_CALLBACK_HASH);
1165
+ rb_call_id = rb_intern("call");
1166
+
1167
+ cWidget = rb_define_class_under(mNewt, "Widget", rb_cObject);
1168
+ rb_define_method(cWidget, "callback", rb_ext_Widget_callback, -1);
1169
+ rb_define_method(cWidget, "==", rb_ext_Widget_equal, 1);
1170
+
1171
+ cCompactButton = rb_define_class_under(mNewt, "CompactButton", cWidget);
1172
+ rb_define_singleton_method(cCompactButton, "new", rb_ext_CompactButton_new, 3);
1173
+
1174
+ cButton = rb_define_class_under(mNewt, "Button", cWidget);
1175
+ rb_define_singleton_method(cButton, "new", rb_ext_Button_new, 3);
1176
+
1177
+ cCheckbox = rb_define_class_under(mNewt, "Checkbox", cWidget);
1178
+ rb_define_singleton_method(cCheckbox, "new", rb_ext_Checkbox_new, 5);
1179
+ rb_define_method(cCheckbox, "get", rb_ext_Checkbox_GetValue, 0);
1180
+ rb_define_method(cCheckbox, "set", rb_ext_Checkbox_SetValue, 1);
1181
+ rb_define_method(cCheckbox, "set_flags", rb_ext_Checkbox_SetFlags, -2);
1182
+
1183
+ cRadioButton = rb_define_class_under(mNewt, "RadioButton", cWidget);
1184
+ rb_define_singleton_method(cRadioButton, "new", rb_ext_RadioButton_new, 5);
1185
+
1186
+ cLabel = rb_define_class_under(mNewt, "Label", cWidget);
1187
+ rb_define_singleton_method(cLabel, "new", rb_ext_Label_new, 3);
1188
+ rb_define_method(cLabel, "set_text", rb_ext_Label_SetText, 1);
1189
+
1190
+ cListbox = rb_define_class_under(mNewt, "Listbox", cWidget);
1191
+ rb_define_singleton_method(cListbox, "new", rb_ext_Listbox_new, 4);
1192
+ rb_define_method(cListbox, "get_current", rb_ext_Listbox_GetCurrent, 0);
1193
+ rb_define_method(cListbox, "set_current", rb_ext_Listbox_SetCurrent, 1);
1194
+ rb_define_method(cListbox, "setCurrentByKey", rb_ext_Listbox_SetCurrentByKey, 1);
1195
+ rb_define_method(cListbox, "set_width", rb_ext_Listbox_SetWidth, 1);
1196
+ rb_define_method(cListbox, "setData", rb_ext_Listbox_SetData, 2);
1197
+ rb_define_method(cListbox, "append", rb_ext_Listbox_AppendEntry, 2);
1198
+ rb_define_method(cListbox, "insert", rb_ext_Listbox_InsertEntry, 3);
1199
+ rb_define_method(cListbox, "set", rb_ext_Listbox_SetEntry, 2);
1200
+ rb_define_method(cListbox, "delete", rb_ext_Listbox_DeleteEntry, 1);
1201
+ rb_define_method(cListbox, "clear", rb_ext_Listbox_Clear, 0);
1202
+ rb_define_method(cListbox, "clearSelection", rb_ext_Listbox_ClearSelection, 0);
1203
+ rb_define_method(cListbox, "select", rb_ext_Listbox_SelectItem, 2);
1204
+
1205
+ cCheckboxTree = rb_define_class_under(mNewt, "CheckboxTree", cWidget);
1206
+ rb_define_singleton_method(cCheckboxTree, "new", rb_ext_CheckboxTree_new, 4);
1207
+ /*rb_define_method(cCheckboxTree, "addItem", rb_ext_CheckboxTree_AddItem, 3);*/
1208
+ rb_define_method(cCheckboxTree, "add", rb_ext_CheckboxTree_AddItem, -2);
1209
+
1210
+ cCheckboxTreeMulti = rb_define_class_under(mNewt, "CheckboxTreeMulti", cCheckboxTree);
1211
+ rb_define_singleton_method(cCheckboxTreeMulti, "new", rb_ext_CheckboxTreeMulti_new, 5);
1212
+
1213
+ cTextbox = rb_define_class_under(mNewt, "Textbox", cWidget);
1214
+ rb_define_singleton_method(cTextbox, "new", rb_ext_Textbox_new, 5);
1215
+ rb_define_method(cTextbox, "set_text", rb_ext_Textbox_SetText, 1);
1216
+ rb_define_method(cTextbox, "set_height", rb_ext_Textbox_SetHeight, 1);
1217
+ rb_define_method(cTextbox, "get_num_lines", rb_ext_Textbox_GetNumLines, 0);
1218
+
1219
+ cTextboxReflowed = rb_define_class_under(mNewt, "TextboxReflowed", cWidget);
1220
+ rb_define_singleton_method(cTextboxReflowed, "new", rb_ext_TextboxReflowed_new, 7);
1221
+
1222
+ cForm = rb_define_class_under(mNewt, "Form", cWidget);
1223
+ rb_define_singleton_method(cForm, "new", rb_ext_Form_new, 0);
1224
+ /*rb_define_method(cForm, "setSize", rb_ext_Form_SetSize, 0);*/
1225
+ /*rb_define_method(cForm, "destroy", rb_ext_Form_Destroy, 0);*/
1226
+ rb_define_method(cForm, "set_background", rb_ext_Form_SetBackground, 1);
1227
+ /*rb_define_method(cForm, "addComponent", rb_ext_Form_AddComponent, 1);*/
1228
+ rb_define_method(cForm, "add", rb_ext_Form_AddComponents, -2);
1229
+ rb_define_method(cForm, "set_height", rb_ext_Form_SetHeight, 1);
1230
+ rb_define_method(cForm, "set_width", rb_ext_Form_SetWidth, 1);
1231
+ rb_define_method(cForm, "run", rb_ext_Run_Form, 0);
1232
+ rb_define_method(cForm, "draw", rb_ext_Form_DrawForm, 0);
1233
+ rb_define_method(cForm, "add_hotkey", rb_ext_Form_AddHotKey, 1);
1234
+
1235
+ cEntry = rb_define_class_under(mNewt, "Entry", cWidget);
1236
+ rb_define_singleton_method(cEntry, "new", rb_ext_Entry_new, 5);
1237
+ rb_define_method(cEntry, "set", rb_ext_Entry_Set, 2);
1238
+ rb_define_method(cEntry, "get", rb_ext_Entry_GetValue, 0);
1239
+ rb_define_method(cEntry, "set_flags", rb_ext_Entry_SetFlags, -2);
1240
+
1241
+ cScale = rb_define_class_under(mNewt, "Scale", cWidget);
1242
+ rb_define_singleton_method(cScale, "new", rb_ext_Scale_new, 4);
1243
+ rb_define_method(cScale, "set", rb_ext_Scale_Set, 1);
1244
+
1245
+
1246
+ cGrid = rb_define_class_under(mNewt, "Grid", cWidget);
1247
+ rb_define_singleton_method(cGrid, "new", rb_ext_Grid_new, 2);
1248
+ /*rb_define_method(cGrid, "destroy", rb_ext_Grid_free, 0);*/
1249
+ rb_define_method(cGrid, "set_field", rb_ext_Grid_SetField, 10);
1250
+ rb_define_method(cGrid, "wrapped_window", rb_ext_Grid_WrappedWindow, -2);
1251
+ rb_define_method(cGrid, "get_size", rb_ext_Grid_GetSize, 0);
1252
+
1253
+ rb_define_const(mNewt, "COLORSET_ROOT", INT2FIX(NEWT_COLORSET_ROOT));
1254
+ rb_define_const(mNewt, "COLORSET_BORDER", INT2FIX(NEWT_COLORSET_BORDER));
1255
+ rb_define_const(mNewt, "COLORSET_WINDOW", INT2FIX(NEWT_COLORSET_WINDOW));
1256
+ rb_define_const(mNewt, "COLORSET_SHADOW", INT2FIX(NEWT_COLORSET_SHADOW));
1257
+ rb_define_const(mNewt, "COLORSET_TITLE", INT2FIX(NEWT_COLORSET_TITLE));
1258
+ rb_define_const(mNewt, "COLORSET_BUTTON", INT2FIX(NEWT_COLORSET_BUTTON));
1259
+ rb_define_const(mNewt, "COLORSET_ACTBUTTON", INT2FIX(NEWT_COLORSET_ACTBUTTON));
1260
+ rb_define_const(mNewt, "COLORSET_CHECKBOX", INT2FIX(NEWT_COLORSET_CHECKBOX));
1261
+ rb_define_const(mNewt, "COLORSET_ACTCHECKBOX", INT2FIX(NEWT_COLORSET_ACTCHECKBOX));
1262
+ rb_define_const(mNewt, "COLORSET_ENTRY", INT2FIX(NEWT_COLORSET_ENTRY));
1263
+ rb_define_const(mNewt, "COLORSET_LABEL", INT2FIX(NEWT_COLORSET_LABEL));
1264
+ rb_define_const(mNewt, "COLORSET_LISTBOX", INT2FIX(NEWT_COLORSET_LISTBOX));
1265
+ rb_define_const(mNewt, "COLORSET_ACTLISTBOX", INT2FIX(NEWT_COLORSET_ACTLISTBOX));
1266
+ rb_define_const(mNewt, "COLORSET_TEXTBOX", INT2FIX(NEWT_COLORSET_TEXTBOX));
1267
+ rb_define_const(mNewt, "COLORSET_ACTTEXTBOX", INT2FIX(NEWT_COLORSET_ACTTEXTBOX));
1268
+ rb_define_const(mNewt, "COLORSET_HELPLINE", INT2FIX(NEWT_COLORSET_HELPLINE));
1269
+ rb_define_const(mNewt, "COLORSET_ROOTTEXT", INT2FIX(NEWT_COLORSET_ROOTTEXT));
1270
+ rb_define_const(mNewt, "COLORSET_EMPTYSCALE", INT2FIX(NEWT_COLORSET_EMPTYSCALE));
1271
+ rb_define_const(mNewt, "COLORSET_FULLSCALE", INT2FIX(NEWT_COLORSET_FULLSCALE));
1272
+ rb_define_const(mNewt, "COLORSET_DISENTRY", INT2FIX(NEWT_COLORSET_DISENTRY));
1273
+ rb_define_const(mNewt, "COLORSET_COMPACTBUTTON", INT2FIX(NEWT_COLORSET_COMPACTBUTTON));
1274
+ rb_define_const(mNewt, "COLORSET_ACTSELLISTBOX", INT2FIX(NEWT_COLORSET_ACTSELLISTBOX));
1275
+ rb_define_const(mNewt, "COLORSET_SELLISTBOX", INT2FIX(NEWT_COLORSET_SELLISTBOX));
1276
+
1277
+ rb_define_const(mNewt, "ARG_APPEND", INT2FIX(NEWT_ARG_APPEND));
1278
+
1279
+ rb_define_const(mNewt, "FLAGS_SET", INT2FIX(NEWT_FLAGS_SET));
1280
+ rb_define_const(mNewt, "FLAGS_RESET", INT2FIX(NEWT_FLAGS_RESET));
1281
+ rb_define_const(mNewt, "FLAGS_TOGGLE", INT2FIX(NEWT_FLAGS_TOGGLE));
1282
+
1283
+ rb_define_const(mNewt, "FLAG_RETURNEXIT", INT2FIX(NEWT_FLAG_RETURNEXIT));
1284
+ rb_define_const(mNewt, "FLAG_HIDDEN", INT2FIX(NEWT_FLAG_HIDDEN));
1285
+ rb_define_const(mNewt, "FLAG_SCROLL", INT2FIX(NEWT_FLAG_SCROLL));
1286
+ rb_define_const(mNewt, "FLAG_DISABLED", INT2FIX(NEWT_FLAG_DISABLED));
1287
+ rb_define_const(mNewt, "FLAG_BORDER", INT2FIX(NEWT_FLAG_BORDER));
1288
+ rb_define_const(mNewt, "FLAG_WRAP", INT2FIX(NEWT_FLAG_WRAP));
1289
+ rb_define_const(mNewt, "FLAG_NOF12", INT2FIX(NEWT_FLAG_NOF12));
1290
+ rb_define_const(mNewt, "FLAG_MULTIPLE", INT2FIX(NEWT_FLAG_MULTIPLE));
1291
+ rb_define_const(mNewt, "FLAG_SELECTED", INT2FIX(NEWT_FLAG_SELECTED));
1292
+ rb_define_const(mNewt, "FLAG_CHECKBOX", INT2FIX(NEWT_FLAG_CHECKBOX));
1293
+
1294
+ rb_define_const(mNewt, "ANCHOR_LEFT", INT2FIX(NEWT_ANCHOR_LEFT));
1295
+ rb_define_const(mNewt, "ANCHOR_RIGHT", INT2FIX(NEWT_ANCHOR_RIGHT));
1296
+ rb_define_const(mNewt, "ANCHOR_TOP", INT2FIX(NEWT_ANCHOR_TOP));
1297
+ rb_define_const(mNewt, "ANCHOR_BOTTOM", INT2FIX(NEWT_ANCHOR_BOTTOM));
1298
+
1299
+ rb_define_const(mNewt, "GRID_FLAG_GROWX", INT2FIX(NEWT_GRID_FLAG_GROWX));
1300
+ rb_define_const(mNewt, "GRID_FLAG_GROWY", INT2FIX(NEWT_GRID_FLAG_GROWY));
1301
+ rb_define_const(mNewt, "GRID_EMPTY", INT2FIX(NEWT_GRID_EMPTY));
1302
+ rb_define_const(mNewt, "GRID_COMPONENT", INT2FIX(NEWT_GRID_COMPONENT));
1303
+ rb_define_const(mNewt, "GRID_SUBGRID", INT2FIX(NEWT_GRID_SUBGRID));
1304
+
1305
+ rb_define_const(mNewt, "KEY_UP", INT2FIX(NEWT_KEY_UP));
1306
+ rb_define_const(mNewt, "KEY_DOWN", INT2FIX(NEWT_KEY_DOWN));
1307
+ rb_define_const(mNewt, "KEY_LEFT", INT2FIX(NEWT_KEY_LEFT));
1308
+ rb_define_const(mNewt, "KEY_RIGHT", INT2FIX(NEWT_KEY_RIGHT));
1309
+ rb_define_const(mNewt, "KEY_BKSPC", INT2FIX(NEWT_KEY_BKSPC));
1310
+ rb_define_const(mNewt, "KEY_DELETE", INT2FIX(NEWT_KEY_DELETE));
1311
+ rb_define_const(mNewt, "KEY_HOME", INT2FIX(NEWT_KEY_HOME));
1312
+ rb_define_const(mNewt, "KEY_END", INT2FIX(NEWT_KEY_END));
1313
+ rb_define_const(mNewt, "KEY_UNTAB", INT2FIX(NEWT_KEY_UNTAB));
1314
+ rb_define_const(mNewt, "KEY_PGUP", INT2FIX(NEWT_KEY_PGUP));
1315
+ rb_define_const(mNewt, "KEY_PGDN", INT2FIX(NEWT_KEY_PGDN));
1316
+ rb_define_const(mNewt, "KEY_INSERT", INT2FIX(NEWT_KEY_INSERT));
1317
+
1318
+ rb_define_const(mNewt, "KEY_F1", INT2FIX(NEWT_KEY_F1));
1319
+ rb_define_const(mNewt, "KEY_F2", INT2FIX(NEWT_KEY_F2));
1320
+ rb_define_const(mNewt, "KEY_F3", INT2FIX(NEWT_KEY_F3));
1321
+ rb_define_const(mNewt, "KEY_F4", INT2FIX(NEWT_KEY_F4));
1322
+ rb_define_const(mNewt, "KEY_F5", INT2FIX(NEWT_KEY_F5));
1323
+ rb_define_const(mNewt, "KEY_F6", INT2FIX(NEWT_KEY_F6));
1324
+ rb_define_const(mNewt, "KEY_F7", INT2FIX(NEWT_KEY_F7));
1325
+ rb_define_const(mNewt, "KEY_F8", INT2FIX(NEWT_KEY_F8));
1326
+ rb_define_const(mNewt, "KEY_F9", INT2FIX(NEWT_KEY_F9));
1327
+ rb_define_const(mNewt, "KEY_F10", INT2FIX(NEWT_KEY_F10));
1328
+ rb_define_const(mNewt, "KEY_F11", INT2FIX(NEWT_KEY_F11));
1329
+ rb_define_const(mNewt, "KEY_F12", INT2FIX(NEWT_KEY_F12));
1330
+
1331
+ }