class Newt::Form

Public Class Methods

new(*args) click to toggle source
static VALUE rb_ext_Form_new(int argc, VALUE *argv, VALUE self)
{
  newtComponent co;
  VALUE helpTag;
  int flags = 0;

  if (argc > 3)
    ARG_ERROR(argc, "0..3");

  INIT_GUARD();
  helpTag = (argc >= 2) ? argv[1] : Qnil;
  flags = (argc == 3) ? NUM2INT(argv[2]) : 0;

  /* Can't determine how Form scrollbars work, so just pass NULL. */
  co = newtForm(NULL, (void *) helpTag, flags);
  return Make_Widget(self, co);
}

Public Instance Methods

add(*args) click to toggle source
static VALUE rb_ext_Form_AddComponents(VALUE self, VALUE components)
{
  Widget_data *form, *co;
  VALUE str;
  int i;

  INIT_GUARD();
  Get_Widget_Data(self, form);
  if (RARRAY_LEN(components) > 0 && form->components == Qnil) {
    form->components = rb_hash_new();
    rb_gc_register_address(&form->components);
  }

  for (i = 0; i < RARRAY_LEN(components); i++) {
    Get_Widget_Data(RARRAY_PTR(components)[i], co);
    if (co->flags & FLAG_ADDED_TO_FORM) {
      str = rb_inspect(RARRAY_PTR(components)[i]);
      rb_raise(rb_eRuntimeError, "%s is already added to a Form",
               StringValuePtr(str));
    }

    co->flags ^= FLAG_GC_FREE;
    co->flags |= FLAG_ADDED_TO_FORM;
    rb_hash_aset(form->components, PTR2NUM(co->co), RARRAY_PTR(components)[i]);
    newtFormAddComponent(form->co, co->co);
  }
  return Qnil;
}
add_hotkey(p1) click to toggle source
static VALUE rb_ext_Form_AddHotKey(VALUE self, VALUE key)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormAddHotKey(form, NUM2INT(key));
  return Qnil;
}
draw() click to toggle source
static VALUE rb_ext_Form_DrawForm(VALUE self)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtDrawForm(form);
  return Qnil;
}
get_current() click to toggle source
static VALUE rb_ext_Form_GetCurrent(VALUE self)
{
  newtComponent form, co;

  Get_newtComponent(self, form);
  co = newtFormGetCurrent(form);
  return Make_Widget_Ref(cWidget, co);
}
run() click to toggle source
static VALUE rb_ext_Form_Run(VALUE self)
{
  Widget_data *data;
  rb_newt_ExitStruct *rb_es;

  INIT_GUARD();
  Get_Widget_Data(self, data);
  rb_es = ALLOC(rb_newt_ExitStruct);
  newtFormRun(data->co, &rb_es->es);
  rb_es->components = data->components;
  rb_gc_register_address(&rb_es->components);
  return Data_Wrap_Struct(cExitStruct, 0, rb_newt_es_free, rb_es);
}
set_background(p1) click to toggle source
static VALUE rb_ext_Form_SetBackground(VALUE self, VALUE color)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormSetBackground(form, NUM2INT(color));
  return Qnil;
}
set_current(p1) click to toggle source
static VALUE rb_ext_Form_SetCurrent(VALUE self, VALUE obj)
{
  newtComponent form, co;

  Get_newtComponent(self, form);
  Get_newtComponent(obj, co);
  newtFormSetCurrent(form, co);
  return Qnil;
}
set_height(p1) click to toggle source
static VALUE rb_ext_Form_SetHeight(VALUE self, VALUE height)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormSetHeight(form, NUM2INT(height));
  return Qnil;
}
set_size() click to toggle source
static VALUE rb_ext_Form_SetSize(VALUE self)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormSetSize(form);
  return Qnil;
}
set_timer(p1) click to toggle source
static VALUE rb_ext_Form_SetTimer(VALUE self, VALUE millisecs)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormSetTimer(form, NUM2INT(millisecs));
  return Qnil;
}
set_width(p1) click to toggle source
static VALUE rb_ext_Form_SetWidth(VALUE self, VALUE width)
{
  newtComponent form;

  Get_newtComponent(self, form);
  newtFormSetWidth(form, NUM2INT(width));
  return Qnil;
}
watch_fd(p1, p2) click to toggle source
static VALUE rb_ext_Form_WatchFd(VALUE self, VALUE io, VALUE flags)
{
  newtComponent form;
  int fd;

  if (!rb_obj_is_kind_of(io, rb_cIO) && TYPE(io) != T_FIXNUM)
    rb_raise(rb_eTypeError, "neither IO nor file descriptor");

  Get_newtComponent(self, form);
  fd = NUM2INT(rb_funcall(io, rb_intern("fileno"), 0));
  newtFormWatchFd(form, fd, NUM2INT(flags));
  return Qnil;
}