Ejemplo n.º 1
0
/*
 * call-seq:
 *   call(type[, id]) {|evt| } -> bool
 *
 * create an event for the given event type.
 * ===Arguments
 * * type Symbol/Integer
 * * id Symbol/Integer
 * ===Return value
 * bool
*/
DLL_LOCAL VALUE _call(int argc,VALUE *argv,VALUE self)
{
	VALUE type,id;
	rb_scan_args(argc, argv, "11",&type,&id);

	wxEvent *evt;
	wxEventType etype = unwrapEventType(type);

	evttypeclassholdertype::iterator it = evttypeclassholder.find(etype);
	if(it != evttypeclassholder.end())
		evt = wxDynamicCast(it->second->CreateObject(),wxEvent);
	else
#if wxUSE_GUI
		evt = new wxCommandEvent;
#else
		evt = new RubyEvent;
#endif

	evt->SetEventType(etype);
	if(!NIL_P(id))
		evt->SetId(unwrapID(id));
	else
	{
		if(rb_respond_to(self,rwx_IDid))
			evt->SetId(unwrapID(rb_funcall(self,rwx_IDid,0)));
	}
	evt->SetEventObject(_self);

	if(rb_block_given_p())
		rb_yield(wrap(evt));

	return wrap(_self->ProcessEvent(*evt));

}
Ejemplo n.º 2
0
/*
 * call-seq:
 *   bind(type[, id[, last]]) {|evt| } -> self
 *
 * bind the block to the given event type. id and id-range are optional.
 * ===Arguments
 * * type Symbol/Integer
 * * id Symbol/Integer
 * * last Symbol/Integer
 * ===Return value
 * self
 * === Exceptions
 * [ArgumentError]
 * * when the evthander prevent the binding of the given type.
*/
DLL_LOCAL VALUE _bind(int argc,VALUE *argv,VALUE self)
{
	VALUE type,id,last,proc;
	rb_scan_args(argc, argv, "12&",&type,&id,&last,&proc);

	wxEventType ctype = unwrapEventType(type);

#if wxUSE_TEXTCTRL
	if(ctype == wxEVT_TEXT_ENTER && rb_obj_is_kind_of(self, rb_cWXTextCtrl))
	{
		wxTextCtrl* textctrl = unwrap<wxTextCtrl*>(self);
		if(!textctrl->HasFlag(wxTE_PROCESS_ENTER)) {
			rb_raise(rb_eArgError,
				"'%" PRIsVALUE "' for '%" PRIsVALUE "' needs 'process_enter' option.",
				RB_OBJ_STRING(type), RB_OBJ_STRING(self)
			);
		}
	}
#endif

	if(NIL_P(proc))
		proc = rb_block_proc();

	_self->Bind(wxEventTypeTag<wxEvent>(ctype),RubyFunctor(proc),unwrapID(id),unwrapID(last));

	return self;
}
Ejemplo n.º 3
0
VALUE _appendNormalItem(int argc,VALUE *argv,VALUE self)
{
	VALUE id,text,help,temp;

	rb_scan_args(argc, argv, "1*",&id,&temp);

	if(rb_obj_is_kind_of(id,rb_cString) && rb_block_given_p()){
		rb_scan_args(argc, argv, "11",&text,&help);
		wxMenu *m = new wxMenu;
		rb_yield(wrap(m));
		return wrap(_self->AppendSubMenu(m,wrap<wxString>(text),wrap<wxString>(help)));
	}else{
		rb_scan_args(argc, argv, "12",&id,&text,&help);
		wxWindowID wid = unwrapID(id);
		if(!wxIsStockID(wid) && NIL_P(text))
			rb_raise(rb_eArgError,"id %d needs an text",wid);
		wxMenuItem *item = _self->Append(wid,wrap<wxString>(text),wrap<wxString>(help));
		if(rb_block_given_p()){
			VALUE proc = rb_block_proc();
#ifdef wxHAS_EVENT_BIND
			_self->Bind(wxEVT_COMMAND_MENU_SELECTED,RubyFunctor(proc),item->GetId());
#else
			_self->Connect(item->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(RubyFunctor::operator()),NULL,new RubyFunctor(proc));
#endif
		}
		return wrap(item);
	}
}
Ejemplo n.º 4
0
VALUE _appendShift(VALUE self,VALUE val)
{
	wxWindowID id = unwrapID(val);
	if(!wxIsStockID(id))
		rb_raise(rb_eArgError,"id \"%s\" cant be fast added",wrap<char*>(val));
	_self->Append(id);
	return self;
}
Ejemplo n.º 5
0
VALUE _appendCheckItem(int argc,VALUE *argv,VALUE self)
{
	VALUE id,text,help;
	rb_scan_args(argc, argv, "12",&id,&text,&help);
	wxMenuItem *item = _self->AppendCheckItem(unwrapID(id),wrap<wxString>(text),wrap<wxString>(help));
	if(rb_block_given_p()){
		VALUE proc = rb_block_proc();
#ifdef wxHAS_EVENT_BIND
		_self->Bind(wxEVT_COMMAND_MENU_SELECTED,RubyFunctor(proc),item->GetId());
#else
		_self->Connect(item->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(RubyFunctor::operator()),NULL,new RubyFunctor(proc));
#endif
	}
	return wrap(item);
}