summaryrefslogtreecommitdiffstats
path: root/perl-install/Newt/Newt.xs
blob: e3e71be6848fd25c5a04298a32b9772fc9762244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <newt.h>

static void suspend() {
  newtSuspend();
  raise(SIGTSTP);
  newtResume();
}

typedef newtComponent Newt__Component;
typedef newtGrid Newt__Grid;


MODULE = Newt		PACKAGE = Newt 	PREFIX = newt

void
DESTROY()
	CODE:
	{
		newtFinished();
	}

void 
changeColors()
  CODE:
{
const struct newtColors colors = {
	"cyan", "black", 			/* root fg, bg */
	"black", "blue",			/* border fg, bg */
	"white", "blue",			/* window fg, bg */
	"white", "black",			/* shadow fg, bg */
	"white", "blue",			/* title fg, bg */
	"yellow", "cyan",			/* button fg, bg */
	"white", "cyan",			/* active button fg, bg */
	"yellow", "blue",			/* checkbox fg, bg */
	"blue", "brown",			/* active checkbox fg, bg */
	"yellow", "blue",			/* entry box fg, bg */
	"white", "blue",			/* label fg, bg */
	"black", "cyan",			/* listbox fg, bg */
	"yellow", "cyan",			/* active listbox fg, bg */
	"white", "blue",			/* textbox fg, bg */
	"cyan", "black",			/* active textbox fg, bg */
	"white", "blue",			/* help line */
	"yellow", "blue",			/* root text */
	"blue",					/* scale full */
	"red",					/* scale empty */
	"blue", "cyan",				/* disabled entry fg, bg */
	"white", "blue",			/* compact button fg, bg */
	"yellow", "red",			/* active & sel listbox */
	"black", "brown"			/* selected listbox */
};
  newtSetColors(colors);
}

int
newtInit()

int
newtFinished()

void
newtCls()

#void
#newtSuspend()

int
newtCenteredWindow(width,height,title)
	int width;
	int height;
	const char * title;

void
newtPopWindow()

void
newtRefresh()

void
newtPushHelpLine(text)
	const char * text;

void
newtDrawRootText(row,col,text)
	int row;
	int col;
	const char * text;

void
newtGetScreenSize()
  PPCODE:
{
  int cols, rows;
  newtGetScreenSize(&cols, &rows);
  PUSHs(sv_2mortal(newSViv(cols)));
  PUSHs(sv_2mortal(newSViv(rows)));
}

void
newtSetSuspendCallback()
	CODE:
	{
	  newtSetSuspendCallback(suspend, NULL);
	}


void
newtWinMessage(title,buttonText,text)
	char * title;
	char * buttonText;
	char * text;

int
newtWinChoice(title,button1,button2,text)
	char * title;
	char * button1;
	char * button2;
	char * text;

int
newtWinTernary(title,button1,button2,button3,message)
	char * title;
	char * button1;
	char * button2;
	char * button3;
	char * message;

void
newtWinMenu(title,text,suggestedWidth,flexDown,flexUp,maxListHeight,list,def,buttons, ...)
	char * title;
	char * text;
	int suggestedWidth;
	int flexDown;
	int flexUp;
	int maxListHeight;
	char **list;
	int def;
	char *buttons;
        PPCODE:
	{
	  int button;
#define nb 8
#define a(i) SvPV(ST(i + nb),PL_na)
	  button = newtWinMenu(title, text, suggestedWidth, flexDown, flexUp, maxListHeight, list, &def,
			       items > nb +  0 ? a( 0) : NULL,
			       items > nb +  1 ? a( 1) : NULL,
			       items > nb +  2 ? a( 2) : NULL,
			       items > nb +  3 ? a( 3) : NULL,
			       items > nb +  4 ? a( 4) : NULL,
			       items > nb +  5 ? a( 5) : NULL,
			       items > nb +  6 ? a( 6) : NULL,
			       items > nb +  7 ? a( 7) : NULL,
			       items > nb +  8 ? a( 8) : NULL,
			       items > nb +  9 ? a( 9) : NULL,
			       items > nb + 10 ? a(10) : NULL, 
			       NULL);
#undef a
	  EXTEND(SP, 2);
 	  PUSHs(sv_2mortal(newSViv(button)));
 	  PUSHs(sv_2mortal(newSViv(def)));
	}

MODULE = Newt		PACKAGE = Newt::Component 	PREFIX = newt

Newt::Component
newtCompactButton(left,top,text)
	int left;
	int top;
	const char * text;

Newt::Component
newtButton(left,top,text)
	int left;
	int top;
	const char * text;

Newt::Component
newtCheckbox(left,top,text,defValue,seq,result)
	int left;
	int top;
	const char * text;
	char *defValue;
	const char * seq;
        int *result;
  CODE: 
  RETVAL = newtCheckbox(left, top, text, defValue[0], seq, (char*)result);
  OUTPUT:
  RETVAL

int
newtCheckboxGetValue(co)
	Newt::Component co;

void
newtCheckboxSetValue(co, value)
	Newt::Component co;
	char *value;
  CODE: 
  newtCheckboxSetValue(co, value[0]);

Newt::Component
newtLabel(left,top,text)
	int left;
	int top;
	const char * text;

void
newtLabelSetText(co,text)
	Newt::Component co;
	const char * text;

Newt::Component
newtVerticalScrollbar(left,top,height,normalColorset,thumbColorset)
	int left;
	int top;
	int height;
	int normalColorset;
	int thumbColorset;

void
newtScrollbarSet(co,where,total)
	Newt::Component co;
	int where;
	int total;

Newt::Component
newtListbox(left,top,height,flags)
	int left;
	int top;
	int height;
	int flags;

void *
newtListboxGetCurrent(co)
	Newt::Component co;

void
newtListboxSetCurrent(co,num)
	Newt::Component co;
	int num;

void
newtListboxSetCurrentByKey(co,key)
	Newt::Component co;
	void * key;

void
newtListboxSetText(co,num,text)
	Newt::Component co;
	int num;
	const char * text;

void
newtListboxSetEntry(co,num,text)
	Newt::Component co;
	int num;
	const char * text;

void
newtListboxSetWidth(co,width)
	Newt::Component co;
	int width;

# return the data passed to AddEntry 
void
newtListboxSetData(co,num,data)
	Newt::Component co;
	int num;
	void * data;

int
newtListboxAddEntry(co,text,data)
	Newt::Component co;
	const char * text;
	const void * data;

# Send the key to insert after, or NULL to insert at the top 
int
newtListboxInsertEntry(co,text,data,key)
	Newt::Component co;
	const char * text;
	const void * data;
	void * key;

int
newtListboxDeleteEntry(co,data)
	Newt::Component co;
	void * data;

# removes all entries from listbox
void
newtListboxClear(co)
	Newt::Component co;

void
newtListboxGetEntry(co,num,text,data)
	Newt::Component co;
	int num;
	char * text;
	void * data;
	PPCODE:
	{
		newtListboxGetEntry(co, num, &text, data);
	}

# Returns an array of data pointers from items, last element is NULL 
void *
newtListboxGetSelection(co,numitems)
	Newt::Component co;
	int *numitems;

void
newtListboxClearSelection(co)
	Newt::Component co;

void
newtListboxSelectItem(co,key,sense)
	Newt::Component co;
        void *key
	enum newtFlagsSense sense;

Newt::Component
newtTextboxReflowed(left,top,text,width,flexDown,flexUp,flags)
	int left;
	int top;
	char * text;
	int width;
	int flexDown;
	int flexUp;
	int flags;

Newt::Component
newtTextbox(left,top,width,height,flags)
	int left;
	int top;
	int width;
	int height;
	int flags;

void
newtTextboxSetText(co,text)
	Newt::Component co;
	const char * text;

void
newtTextboxSetHeight(co,height)
	Newt::Component co;
	int height;

int
newtTextboxGetNumLines(co)
	Newt::Component co;

char *
newtReflowText(text,width,flexDown,flexUp,actualWidth,actualHeight)
	char * text;
	int width;
	int flexDown;
	int flexUp;
	int * actualWidth;
	int * actualHeight;

Newt::Component
newtForm(vertBar,help,flags)
	Newt::Component vertBar;
	const char * help;
	int flags;

void
newtFormSetSize(co)
	Newt::Component co;

Newt::Component
newtFormGetCurrent(co)
	Newt::Component co;

void
newtFormSetBackground(co,color)
	Newt::Component co;
	int color;

void
newtFormSetCurrent(co,subco)
	Newt::Component co;
	Newt::Component subco;

void
newtFormAddComponent(form,co)
	Newt::Component form;
	Newt::Component co;

void
newtFormSetHeight(co,height)
	Newt::Component co;
	int height;

void
newtFormSetWidth(co,width)
	Newt::Component co;
	int width;

Newt::Component
newtRunForm(form)
	Newt::Component form;

void
newtDrawForm(form)
	Newt::Component form;

Newt::Component
newtEntry(left,top,initialValue,width,flag)
	int left;
	int top;
	const char * initialValue;
	int width;
        int flag;
	CODE:
	{
		char *result;
		RETVAL = newtEntry(left,top,initialValue,width,&result,flag);
	}
	OUTPUT:
	RETVAL

void
newtEntrySet(co,value,cursorAtEnd)
	Newt::Component co;
	const char * value;
	int cursorAtEnd;

char *
newtEntryGetValue(co)
	Newt::Component co;

void
newtFormDestroy(form)
	Newt::Component form;

MODULE = Newt		PACKAGE = Newt::Grid 	PREFIX = newt

Newt::Grid
newtCreateGrid(cols,rows)
	int cols;
	int rows;

Newt::Grid
HCloseStacked(first, ...)
	Newt::Component first;
     CODE:
	{
	  int i;
#define a(i) (newtComponent)SvIV((SV*)SvRV( ST(i) ))
          RETVAL =
	     newtGridHCloseStacked(
                           items >  0 ? 1 : 0, items >  0 ? a( 0) : NULL, 
			   items >  1 ? 1 : 0, items >  1 ? a( 1) : NULL, 
			   items >  2 ? 1 : 0, items >  2 ? a( 2) : NULL, 
			   items >  3 ? 1 : 0, items >  3 ? a( 3) : NULL, 
			   items >  4 ? 1 : 0, items >  4 ? a( 4) : NULL, 
			   items >  5 ? 1 : 0, items >  5 ? a( 5) : NULL, 
			   items >  6 ? 1 : 0, items >  6 ? a( 6) : NULL, 
			   items >  7 ? 1 : 0, items >  7 ? a( 7) : NULL, 
			   items >  8 ? 1 : 0, items >  8 ? a( 8) : NULL, 
			   items >  9 ? 1 : 0, items >  9 ? a( 9) : NULL, 
			   items > 10 ? 1 : 0, items > 10 ? a(10) : NULL,  
			   NULL);
#undef a
	}
OUTPUT:
RETVAL


Newt::Grid
newtGridBasicWindow(text,middle,buttons)
	Newt::Component text;
	Newt::Grid middle;
	Newt::Grid buttons;


Newt::Grid
newtGridSimpleWindow(text,middle,buttons)
	Newt::Component text;
	Newt::Component middle;
	Newt::Grid buttons;

void
newtGridSetField(grid,col,row,type,val,padLeft,padTop,padRight,padBottom,anchor,flags)
	Newt::Grid grid;
	int col;
	int row;
	enum newtGridElement type;
	void * val;
	int padLeft;
	int padTop;
	int padRight;
	int padBottom;
	int anchor;
	int flags;


void
newtGridFree(grid,recurse)
	Newt::Grid grid;
	int recurse;

void
newtGridGetSize(grid,width,height)
	Newt::Grid grid;
	int * width;
	int * height;

void
newtGridWrappedWindow(grid,title)
	Newt::Grid grid;
	char * title;
	
void
newtGridAddComponentsToForm(grid,form,recurse)
	Newt::Grid grid;
	Newt::Component form;
	int recurse;

Newt::Grid
newtButtonBar(button1, ...)
	char * button1;
 PPCODE:
	{
	  static newtComponent p[11];
	  int i;
	  EXTEND(SP, items + 1);
#define a(i) (char *)SvPV(ST(i),PL_na)
          PUSHs(sv_setref_pv(sv_newmortal(), "Newt::Grid", 
	     newtButtonBar(items >  0 ? a( 0) : NULL, items >  0 ? &p[ 0] : NULL, 
			   items >  1 ? a( 1) : NULL, items >  1 ? &p[ 1] : NULL, 
			   items >  2 ? a( 2) : NULL, items >  2 ? &p[ 2] : NULL, 
			   items >  3 ? a( 3) : NULL, items >  3 ? &p[ 3] : NULL, 
			   items >  4 ? a( 4) : NULL, items >  4 ? &p[ 4] : NULL, 
			   items >  5 ? a( 5) : NULL, items >  5 ? &p[ 5] : NULL, 
			   items >  6 ? a( 6) : NULL, items >  6 ? &p[ 6] : NULL, 
			   items >  7 ? a( 7) : NULL, items >  7 ? &p[ 7] : NULL, 
			   items >  8 ? a( 8) : NULL, items >  8 ? &p[ 8] : NULL, 
			   items >  9 ? a( 9) : NULL, items >  9 ? &p[ 9] : NULL, 
			   items > 10 ? a(10) : NULL, items > 10 ? &p[10] : NULL,  
			   NULL)));
#undef a
        for (i = 0; i < items; i++) PUSHs(sv_setref_pv(sv_newmortal(), "Newt::Component", p[i]));
	}