ext/ruby_newt/ruby_newt.c in newt-0.9.0 vs ext/ruby_newt/ruby_newt.c in newt-0.9.1

- old
+ new

@@ -2,11 +2,12 @@ * * by Noritsugu Nakamura * from 2001.04.20 * * modified by Eric Sperano - * 2012.02.27 + * from 2012.02.27 + * */ #include <ruby.h> #include <rubyio.h> #include <newt.h> @@ -46,10 +47,14 @@ int anint; struct callbackStruct scs; }; +/* + * ReflowText + * + */ static VALUE rb_ext_ReflowText(VALUE self, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp) { int actualWidth, actualHeight; char *p; @@ -62,143 +67,215 @@ rb_ary_push(ary, INT2NUM(actualWidth)); rb_ary_push(ary, INT2NUM(actualHeight)); return ary; } +/* + * Screen_new + * + */ static VALUE rb_ext_Screen_new() { newtInit(); newtCls(); return Qnil; } +/* + * Screen_Init + * + */ static VALUE rb_ext_Screen_Init() { newtInit(); return Qnil; } +/* + * Screen_Cls + * + */ static VALUE rb_ext_Screen_Cls() { newtCls(); return Qnil; } +/* + * Screen_Finished + * + */ static VALUE rb_ext_Screen_Finished() { newtFinished(); return Qnil; } +/* + * Screen_WaitForKey + * + */ static VALUE rb_ext_Screen_WaitForKey() { newtWaitForKey(); return Qnil; } +/* + * Screen_ClearKeyBuffer + * + */ static VALUE rb_ext_Screen_ClearKeyBuffer() { newtClearKeyBuffer(); return Qnil; } +/* + * Screen_OpenWindow + * + */ static VALUE rb_ext_Screen_OpenWindow(VALUE self, VALUE left, VALUE top, VALUE width, VALUE height, VALUE title) { return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(height), StringValuePtr(title))); } +/* + * Screen_CenteredWindow + * + */ static VALUE rb_ext_Screen_CenteredWindow(VALUE self, VALUE width, VALUE height, VALUE title) { return INT2NUM(newtCenteredWindow(NUM2INT(width), NUM2INT(height), StringValuePtr(title))); } +/* + * Screen_PopWindow + * + */ static VALUE rb_ext_Screen_PopWindow(VALUE self) { newtPopWindow(); return Qnil; } +/* + * Screen_Resume + * + */ static VALUE rb_ext_Screen_Resume() { newtResume(); return Qnil; } +/* + * Screen_Suspend + * + */ static VALUE rb_ext_Screen_Suspend() { newtSuspend(); return Qnil; } +/* + * Screen_Refresh + * + */ static VALUE rb_ext_Screen_Refresh() { newtRefresh(); return Qnil; } +/* + * Screen_DrawRootText + * + */ static VALUE rb_ext_Screen_DrawRootText(VALUE self, VALUE col, VALUE row, VALUE text) { newtDrawRootText(NUM2INT(col), NUM2INT(row), StringValuePtr(text)); return Qnil; } +/* + * Screen_PushHelpLine + * + */ static VALUE rb_ext_Screen_PushHelpLine(VALUE self, VALUE text) { newtPushHelpLine(StringValuePtr(text)); return Qnil; } +/* + * Screen_RedrawHelpLine + * + */ static VALUE rb_ext_Screen_RedrawHelpLine(VALUE self) { newtRedrawHelpLine(); return Qnil; } +/* + * Screen_PopHelpLine + * + */ static VALUE rb_ext_Screen_PopHelpLine(VALUE self) { newtPopHelpLine(); return Qnil; } +/* + * Screen_Bell + * + */ static VALUE rb_ext_Screen_Bell(VALUE self) { newtBell(); return Qnil; } +/* + * Screen_Size + * + */ static VALUE rb_ext_Screen_Size(VALUE self) { int cols, rows; VALUE ary = rb_ary_new2(2); @@ -208,10 +285,14 @@ rb_ary_push(ary, INT2NUM(rows)); return ary; } +/* + * Screen_WinMessage + * + */ static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE args) { if (RARRAY_LEN(args) < 3) { rb_raise(rb_eArgError, "3 arguments required"); @@ -221,10 +302,14 @@ } return Qnil; } +/* + * Screen_WinChoice + * + */ static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE args) { if (RARRAY_LEN(args) < 4) { rb_raise(rb_eArgError, "4 arguments required"); @@ -235,10 +320,14 @@ } return Qnil; } +/* + * Screen_WinMenu + * + */ static VALUE rb_ext_Screen_WinMenu(VALUE self, VALUE args) { long len; int i, listItem; @@ -284,10 +373,14 @@ } return Qnil; } +/* + * Screen_WinEntries + * + */ static VALUE rb_ext_Screen_WinEntries(VALUE self, VALUE args) { long len; int i; @@ -354,10 +447,14 @@ } return Qnil; } +/* + * Widget_callback_function + * + */ void rb_ext_Widget_callback_function(newtComponent co, void *proc) { VALUE widget; @@ -368,10 +465,14 @@ else{ rb_funcall((VALUE)proc, rb_call_id, 1, widget); }; }; +/* + * Widget_callback + * + */ static VALUE rb_ext_Widget_callback(int argc, VALUE argv[], VALUE self) { newtComponent co; VALUE arg1, value; @@ -391,10 +492,14 @@ }; return value; } +/* + * Widget_equal + * + */ static VALUE rb_ext_Widget_equal(VALUE self, VALUE widget) { newtComponent co, co2; @@ -406,47 +511,67 @@ /*fprintf(stderr, "* %p %p", co, co2);*/ if (co == co2) return Qtrue; return Qfalse; } +/* + * Label_new + * + */ static VALUE rb_ext_Label_new(VALUE self, VALUE left, VALUE top, VALUE text) { newtComponent co; co = newtLabel(NUM2INT(left), NUM2INT(top), StringValuePtr(text)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Label_SetText + * + */ static VALUE rb_ext_Label_SetText(VALUE self, VALUE text) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtLabelSetText(co, StringValuePtr(text)); return Qnil; } +/* + * CompactButton_new + * + */ static VALUE rb_ext_CompactButton_new(VALUE self, VALUE left, VALUE top, VALUE text) { newtComponent co; co = newtCompactButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Button_new + * + */ static VALUE rb_ext_Button_new(VALUE self, VALUE left, VALUE top, VALUE text) { newtComponent co; co = newtButton(NUM2INT(left), NUM2INT(top), StringValuePtr(text)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Checkbox_new + * + */ static VALUE rb_ext_Checkbox_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE defValue, VALUE seq) { newtComponent co; @@ -459,10 +584,14 @@ StringValuePtr(defValue)[0], StringValuePtr(seq), NULL); } return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Checkbox_GetValue + * + */ static VALUE rb_ext_Checkbox_GetValue(VALUE self) { newtComponent co; char value[10]; @@ -471,10 +600,14 @@ value[0] = newtCheckboxGetValue(co); value[1] = '\0'; return rb_str_new2(value); } +/* + * Checkbox_SetValue + * + */ static VALUE rb_ext_Checkbox_SetValue(VALUE self, VALUE value) { newtComponent co; @@ -483,10 +616,14 @@ newtCheckboxSetValue(co, StringValuePtr(value)[0]); } return Qnil; } +/* + * Checkbox_SetFlags + * + */ static VALUE rb_ext_Checkbox_SetFlags(VALUE self, VALUE args) { newtComponent co; long len; @@ -503,10 +640,14 @@ } return Qnil; } +/* + * RadioButton_new + * + */ static VALUE rb_ext_RadioButton_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE isDefault, VALUE prevButton) { newtComponent co, cco; @@ -520,19 +661,27 @@ NUM2INT(isDefault), cco); } return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Listbox_new + * + */ static VALUE rb_ext_Listbox_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags) { newtComponent co; co = newtListbox(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Listbox_GetCurrent + * + */ static VALUE rb_ext_Listbox_GetCurrent(VALUE self) { newtComponent co; int i = 0; @@ -546,20 +695,28 @@ ip = (int *)newtListboxGetCurrent(co); /*return rb_str_new2(p);*/ return INT2NUM(i); } +/* + * Listbox_SetCurrent + * + */ static VALUE rb_ext_Listbox_SetCurrent(VALUE self, VALUE num) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtListboxSetCurrent(co, NUM2INT(num)); return Qnil; } +/* + * Listbox_SetCurrentByKey + * + */ static VALUE rb_ext_Listbox_SetCurrentByKey(VALUE self, VALUE key) { newtComponent co; @@ -577,30 +734,42 @@ break; } return Qnil; } +/* + * Listbox_SetEntry + * + */ static VALUE rb_ext_Listbox_SetEntry(VALUE self, VALUE num, VALUE text) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtListboxSetEntry(co, NUM2INT(num), StringValuePtr(text)); return Qnil; } +/* + * Listbox_SetWidth + * + */ static VALUE rb_ext_Listbox_SetWidth(VALUE self, VALUE width) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtListboxSetWidth(co, NUM2INT(width)); return Qnil; } +/* + * Listbox_SetData + * + */ static VALUE rb_ext_Listbox_SetData(VALUE self, VALUE num, VALUE data) { newtComponent co; @@ -618,10 +787,14 @@ break; } return Qnil; } +/* + * Listbox_AppendEntry + * + */ static VALUE rb_ext_Listbox_AppendEntry(VALUE self, VALUE text, VALUE data) { newtComponent co; @@ -639,10 +812,14 @@ break; } return Qnil; } +/* + * Listbox_InsertEntry + * + */ static VALUE rb_ext_Listbox_InsertEntry(VALUE self, VALUE text, VALUE data, VALUE key) { newtComponent co; @@ -679,10 +856,14 @@ break; } return Qnil; } +/* + * Listbox_DeleteEntry + * + */ static VALUE rb_ext_Listbox_DeleteEntry(VALUE self, VALUE data) { newtComponent co; @@ -700,10 +881,14 @@ break; } return Qnil; } +/* + * Listbox_Clear + * + */ static VALUE rb_ext_Listbox_Clear(VALUE self) { newtComponent co; @@ -711,10 +896,14 @@ newtListboxClear(co); return Qnil; } +/* + * Listbox_ClearSelection + * + */ static VALUE rb_ext_Listbox_ClearSelection(VALUE self) { newtComponent co; @@ -722,10 +911,14 @@ newtListboxClearSelection(co); return Qnil; } +/* + * Listbox_SelectItem + * + */ static VALUE rb_ext_Listbox_SelectItem(VALUE self, VALUE key, VALUE sense) { newtComponent co; @@ -743,19 +936,27 @@ break; } return Qnil; } +/* + * CheckboxTree_new + * + */ static VALUE rb_ext_CheckboxTree_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE flags) { newtComponent co; co = newtCheckboxTree(NUM2INT(left), NUM2INT(top), NUM2INT(height), NUM2INT(flags)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * CheckboxTree_AddItem + * + */ static VALUE rb_ext_CheckboxTree_AddItem(VALUE self, VALUE args) /*rb_ext_CheckboxTree_AddItem(VALUE self, VALUE text, VALUE data, VALUE flags)*/ /*, VALUE index)*/ { @@ -807,10 +1008,14 @@ } return Qnil; #endif } +/* + * CheckboxTreeMulti_new + * + */ static VALUE rb_ext_CheckboxTreeMulti_new(VALUE self, VALUE left, VALUE top, VALUE height, VALUE seq, VALUE flags) { newtComponent co; @@ -820,58 +1025,82 @@ co = newtCheckboxTreeMulti(NUM2INT(left), NUM2INT(top), NUM2INT(height), StringValuePtr(seq), NUM2INT(flags)); } return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Textbox_new + * + */ static VALUE rb_ext_Textbox_new(VALUE self, VALUE left, VALUE top, VALUE width, VALUE height, VALUE flags) { newtComponent co; co = newtTextbox(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(height), NUM2INT(flags)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Textbox_SetText + * + */ static VALUE rb_ext_Textbox_SetText(VALUE self, VALUE text) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtTextboxSetText(co, StringValuePtr(text)); return Qnil; } +/* + * Textbox_SetHeight + * + */ static VALUE rb_ext_Textbox_SetHeight(VALUE self, VALUE height) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtTextboxSetHeight(co, NUM2INT(height)); return Qnil; } +/* + * Textbox_GetNumLines + * + */ static VALUE rb_ext_Textbox_GetNumLines(VALUE self) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); return INT2NUM(newtTextboxGetNumLines(co)); } +/* + * TextboxReflowed_new + * + */ static VALUE rb_ext_TextboxReflowed_new(VALUE self, VALUE left, VALUE top, VALUE text, VALUE width, VALUE flexDown, VALUE flexUp, VALUE flags) { newtComponent co; co = newtTextboxReflowed(NUM2INT(left), NUM2INT(top), StringValuePtr(text), NUM2INT(width), NUM2INT(flexDown), NUM2INT(flexUp), NUM2INT(flags)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Form_Destroy + * + */ static void rb_ext_Form_Destroy(VALUE self) { newtComponent form; @@ -879,19 +1108,27 @@ Data_Get_Struct(cForm, struct newtComponent_struct, form); newtFormDestroy(form); } } +/* + * Form_new + * + */ static VALUE rb_ext_Form_new(VALUE self, VALUE left, VALUE top, VALUE text) { newtComponent co; co = newtForm(NULL, NULL, 0); return Data_Wrap_Struct(self, 0, rb_ext_Form_Destroy, co); } +/* + * Form_SetBackground + * + */ static VALUE rb_ext_Form_SetBackground(VALUE self, VALUE color) { newtComponent form; @@ -911,10 +1148,14 @@ newtFormAddComponent(form, cco); return Qnil; } #endif +/* + * Form_AddComponents + * + */ static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE co) { int i; newtComponent form, cco; @@ -926,70 +1167,98 @@ newtFormAddComponent(form, cco); } return Qnil; } +/* + * Form_SetHeight + * + */ static VALUE rb_ext_Form_SetHeight(VALUE self, VALUE height) { newtComponent form; Data_Get_Struct(self, struct newtComponent_struct, form); newtFormSetHeight(form, NUM2INT(height)); return Qnil; } +/* + * Form_SetWidth + * + */ static VALUE rb_ext_Form_SetWidth(VALUE self, VALUE width) { newtComponent form; Data_Get_Struct(self, struct newtComponent_struct, form); newtFormSetWidth(form, NUM2INT(width)); return Qnil; } +/* + * Run_Form + * + */ static VALUE rb_ext_Run_Form(VALUE self) { newtComponent form, co; Data_Get_Struct(self, struct newtComponent_struct, form); co = newtRunForm(form); return Data_Wrap_Struct(cWidget, 0, 0, co); } +/* + * Form_DrawForm + * + */ static VALUE rb_ext_Form_DrawForm(VALUE self) { newtComponent form; Data_Get_Struct(self, struct newtComponent_struct, form); newtDrawForm(form); return Qnil; } +/* + * Form_AddHotKey + * + */ static VALUE rb_ext_Form_AddHotKey(VALUE self, VALUE key) { newtComponent form; Data_Get_Struct(self, struct newtComponent_struct, form); newtFormAddHotKey(form, NUM2INT(key)); return Qnil; } +/* + * Entry_new + * + */ static VALUE rb_ext_Entry_new(VALUE self, VALUE left, VALUE top, VALUE initialValue, VALUE width, VALUE flags) { newtComponent co; co = newtEntry(NUM2INT(left), NUM2INT(top), StringValuePtr(initialValue), NUM2INT(width), NULL, NUM2INT(flags)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Entry_Set + * + */ static VALUE rb_ext_Entry_Set(VALUE self, VALUE value, VALUE cursorAtEnd) { newtComponent co; @@ -1010,19 +1279,27 @@ } return Qnil; } +/* + * Entry_GetValue + * + */ static VALUE rb_ext_Entry_GetValue(VALUE self) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); return rb_str_new2(newtEntryGetValue(co)); } +/* + * Entry_SetFlags + * + */ static VALUE rb_ext_Entry_SetFlags(VALUE self, VALUE args) { newtComponent co; long len; @@ -1038,29 +1315,41 @@ rb_raise(rb_eArgError, "1 argument or 2 arguments required"); } return Qnil; } +/* + * Scale_new + * + */ static VALUE rb_ext_Scale_new(VALUE self, VALUE left, VALUE top, VALUE width, VALUE fullValue) { newtComponent co; co = newtScale(NUM2INT(left), NUM2INT(top), NUM2INT(width), NUM2INT(fullValue)); return Data_Wrap_Struct(self, 0, 0, co); } +/* + * Scale_Set + * + */ static VALUE rb_ext_Scale_Set(VALUE self, VALUE amount) { newtComponent co; Data_Get_Struct(self, struct newtComponent_struct, co); newtScaleSet(co, NUM2INT(amount)); return Qnil; } +/* + * Grid_free + * + */ static void rb_ext_Grid_free(VALUE self) { newtGrid grid; @@ -1068,20 +1357,28 @@ Data_Get_Struct(cGrid, struct grid_s, grid); newtGridFree(grid, 1); } } +/* + * Grid_new + * + */ static VALUE rb_ext_Grid_new(VALUE self, VALUE cols, VALUE rows) { newtGrid grid; grid = newtCreateGrid(NUM2INT(cols), NUM2INT(rows)); /*return Data_Wrap_Struct(self, 0, 0, grid);*/ return Data_Wrap_Struct(self, 0, rb_ext_Grid_free, grid); } +/* + * Grid_SetField + * + */ static VALUE rb_ext_Grid_SetField(VALUE self, VALUE col, VALUE row, VALUE type, VALUE val, VALUE padLeft, VALUE padTop, VALUE padRight, VALUE padBottom, VALUE anchor, VALUE flags) { @@ -1094,10 +1391,14 @@ NUM2INT(padLeft), NUM2INT(padTop), NUM2INT(padRight), NUM2INT(padBottom), NUM2INT(anchor), NUM2INT(flags)); return Qnil; } +/* + * Grid_WrappedWindow + * + */ static VALUE rb_ext_Grid_WrappedWindow(VALUE self, VALUE args) { newtGrid grid; long len; @@ -1115,10 +1416,14 @@ } return Qnil; } +/* + * Grid_GetSize + * + */ static VALUE rb_ext_Grid_GetSize(VALUE self) { int width, height; newtGrid grid; @@ -1130,11 +1435,14 @@ rb_ary_push(ary, INT2NUM(height)); return ary; } - +/* + * Init_ruby_newt + * + */ void Init_ruby_newt(){ mNewt = rb_define_module("Newt"); rb_define_module_function(mNewt, "reflow_text", rb_ext_ReflowText, 4); @@ -1327,7 +1635,6 @@ rb_define_const(mNewt, "KEY_F8", INT2FIX(NEWT_KEY_F8)); rb_define_const(mNewt, "KEY_F9", INT2FIX(NEWT_KEY_F9)); rb_define_const(mNewt, "KEY_F10", INT2FIX(NEWT_KEY_F10)); rb_define_const(mNewt, "KEY_F11", INT2FIX(NEWT_KEY_F11)); rb_define_const(mNewt, "KEY_F12", INT2FIX(NEWT_KEY_F12)); - }