示例#1
0
VisualSizer::VisualSizer(shared_ptr<ObjectBase> obj,wxWindow *parent)
: VisualObject(obj)
{
	IComponent *comp = obj->GetObjectInfo()->GetComponent();
	if (comp)
	{

		/*  wxObject* yo = parent;
		IObject *objer =  obj.get();
		wxStaticBox* box = new wxStaticBox( (wxWindow*)yo, -1,
		objer->GetPropertyAsString(wxT("label")));

		wxStaticBoxSizer* sizer = new wxStaticBoxSizer(box,
		objer->GetPropertyAsInteger(wxT("orient")));

		SetSizer( sizer );*/

		SetSizer((wxSizer *)(comp->Create(obj.get(),parent)));
	}
	else
	{
		// para que no pete ponemos un sizer por defecto, aunque deberá mostrar algun
		// mensaje de advertencia
		SetSizer(new wxBoxSizer(wxVERTICAL));
	}

	shared_ptr<Property> pminsize  = obj->GetProperty( wxT("minimum_size") );
	if (pminsize)
	{
		wxSize minsize = StringToSize(pminsize->GetValue());
		m_sizer->SetMinSize( minsize );
		m_sizer->Layout();
	}
}
示例#2
0
VisualWindow::VisualWindow(shared_ptr<ObjectBase> obj, wxWindow *parent)
: VisualObject(obj)
{
	IComponent *comp = obj->GetObjectInfo()->GetComponent();

	if (comp)
		SetWindow((wxWindow *)(comp->Create(obj.get(),parent)));

	else
		SetWindow(new GenericWindow(parent));

	SetupWindow();
}
示例#3
0
/**
* Generates wxObjects from ObjectBase
*
* @param obj ObjectBase to generate.
* @param parent wxWindow parent, necessary to instantiate a widget.
* @param parentObject ObjectBase parent - not always the same as the wxparent (e.g. an abstract component).
*/
void VisualEditor::Generate( PObjectBase obj, wxWindow* wxparent, wxObject* parentObject )
{
	// Get Component
	PObjectInfo obj_info = obj->GetObjectInfo();
	IComponent* comp = obj_info->GetComponent();

	if ( NULL == comp )
	{
		THROW_WXFBEX( wxString::Format( wxT("Component for %s not found!"), obj->GetClassName().c_str() ) );
	}

	// Create Object
	wxObject* createdObject = comp->Create( obj.get(), wxparent );
	wxWindow* createdWindow = NULL;
	wxSizer*  createdSizer  = NULL;
	switch ( comp->GetComponentType() )
	{
		case COMPONENT_TYPE_WINDOW:
			createdWindow = wxDynamicCast( createdObject, wxWindow );
			if ( NULL == createdWindow )
			{
				THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a window component, but this is not a wxWindow!"), obj->GetClassName().c_str() ) );
			}
			SetupWindow( obj, createdWindow );

			// Push event handler in order to respond to Paint and Mouse events
			createdWindow->PushEventHandler( new VObjEvtHandler( createdWindow, obj ) );
			break;

		case COMPONENT_TYPE_SIZER:
			createdSizer = wxDynamicCast( createdObject, wxSizer );
			if ( NULL == createdSizer )
			{
				THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a sizer component, but this is not a wxSizer!"), obj->GetClassName().c_str() ) );
			}
			SetupSizer( obj, createdSizer );
			break;

		default:
			break;
	}

	// Associate the wxObject* with the PObjectBase
	m_wxobjects.insert( wxObjectMap::value_type( createdObject, obj ) );
	m_baseobjects.insert( ObjectBaseMap::value_type( obj.get(), createdObject ) );

	// New wxparent for the window's children
	wxWindow* new_wxparent = ( createdWindow ? createdWindow : wxparent );

	// Recursively generate the children
	for ( unsigned int i = 0; i < obj->GetChildCount(); i++ )
	{
		Generate( obj->GetChild( i ), new_wxparent, createdObject );
	}

	comp->OnCreated( createdObject, new_wxparent );

	// If the created object is a sizer and the parent object is a window, set the sizer to the window
	if (
			( createdSizer != NULL && NULL != wxDynamicCast( parentObject, wxWindow ) )
			||
			( NULL == parentObject && createdSizer != NULL )
		)
	{
		wxparent->SetSizer( createdSizer );
		if ( parentObject )
			createdSizer->SetSizeHints( wxparent );

		wxparent->SetAutoLayout(true);
		wxparent->Layout();
	}
}