Beispiel #1
0
void wxFbPalette::PopulateToolbar( PObjectPackage pkg, wxToolBar *toolbar )
#endif
{
	unsigned int j = 0;
	while ( j < pkg->GetObjectCount() )
	{
		PObjectInfo info = pkg->GetObjectInfo( j );
		if ( info->IsStartOfGroup() )
		{
			toolbar->AddSeparator();
		}
		if ( NULL == info->GetComponent() )
		{
#if wxVERSION_NUMBER < 2900
			LogDebug( _( "Missing Component for Class \"%s\" of Package \"%s\"." ), info->GetClassName().c_str(), pkg->GetPackageName().c_str() );
#else
			LogDebug(_("Missing Component for Class \"" + info->GetClassName() + "\" of Package \"" + pkg->GetPackageName() + "\".") );
#endif
		}
		else
		{
			wxString widget( info->GetClassName() );

			wxBitmap icon = info->GetIconFile();

			#ifdef __WXMAC__
				wxBitmapButton* button = new wxBitmapButton( toolbar, nextId++, icon );
				button->SetToolTip( widget );
				toolbar->AddControl( button );
			#else
				toolbar->AddTool(nextId++, widget, icon, widget);
			#endif

			toolbar->Realize();
		}
		j++;
	}
}
Beispiel #2
0
PObjectBase XrcLoader::GetObject( ticpp::Element *xrcObj, PObjectBase parent )
{
	// First, create the object by the name, the modify the properties

	std::string className = xrcObj->GetAttribute( "class" );
	if ( parent->GetObjectTypeName() == wxT( "project" ) )
	{
		if ( className == "wxBitmap" )
		{
			PProperty bitmapsProp = parent->GetProperty( _( "bitmaps" ) );
			if ( bitmapsProp )
			{
				wxString value = bitmapsProp->GetValue();
				wxString text = _WXSTR( xrcObj->GetText() );
				text.Replace( wxT( "\'" ), wxT( "\'\'" ), true );
				value << wxT( "\'" ) << text << wxT( "\' " );
				bitmapsProp->SetValue( value );
				return PObjectBase();
			}
		}
		if ( className == "wxIcon" )
		{
			PProperty iconsProp = parent->GetProperty( _( "icons" ) );
			if ( iconsProp )
			{
				wxString value = iconsProp->GetValue();
				wxString text = _WXSTR( xrcObj->GetText() );
				text.Replace( wxT( "\'" ), wxT( "\'\'" ), true );
				value << wxT( "\'" ) << text << wxT( "\' " );
				iconsProp->SetValue( value );
				return PObjectBase();
			}
		}

		// Forms wxPanel, wxFrame, wxDialog are stored internally as Panel, Frame, and Dialog
		// to prevent conflicts with wxPanel as a container
		className = className.substr( 2, className.size() - 2 );
	}

	// Well, this is not nice. wxMenu class name is ambiguous, so we'll get the
	// correct class by the context. If the parent of a wxMenu is another wxMenu
	// then the class name will be "submenu"
	else if ( className == "wxMenu" && ( parent->GetClassName() == wxT( "wxMenu" ) || parent->GetClassName() == wxT( "submenu" ) ) )
	{
		className = "submenu";
	}

	// "separator" is also ambiguous - could be a toolbar separator or a menu separator
	else if ( className == "separator" )
	{
		if ( parent->GetClassName() == wxT( "wxToolBar" ) )
		{
			className = "toolSeparator";
		}
	}

	// replace "spacer" with "sizeritem" so it will be imported as a "sizeritem"
	// "sizeritem" is ambiguous - could also be a grid bag sizeritem
	else if ( className == "spacer" || className == "sizeritem" )
	{
		if ( parent->GetClassName() == wxT( "wxGridBagSizer" ) )
		{
			className = "gbsizeritem";
		}
		else
		{
			className = "sizeritem";
		}
	}

	PObjectBase object;
	PObjectInfo objInfo = m_objDb->GetObjectInfo( _WXSTR( className ) );
	if ( objInfo )
	{
		IComponent *comp = objInfo->GetComponent();
		if ( !comp )
		{
			wxLogError( _("No component found for class \"%s\", found on line %i."), _WXSTR( className ).c_str(), xrcObj->Row() );
		}
		else
		{
			ticpp::Element *fbObj = comp->ImportFromXrc( xrcObj );
			if ( !fbObj )
			{
				wxLogError( _("ImportFromXrc returned NULL for class \"%s\", found on line %i."), _WXSTR( className ).c_str(), xrcObj->Row() );
			}
			else
			{
				object = m_objDb->CreateObject( fbObj, parent );
				if ( !object )
				{
					// Unable to create the object and add it to the parent - probably needs a sizer
					PObjectBase newsizer = m_objDb->CreateObject( "wxBoxSizer", parent );
					if ( newsizer )
					{
						// It is possible the CreateObject returns an "item" containing the object, e.g. SizerItem or SplitterItem
						// If that is the case, reassign "object" to the actual object
						PObjectBase sizer = newsizer;
						if ( sizer->GetChildCount() > 0 )
						{
							sizer = sizer->GetChild( 0 );
						}

						if ( sizer )
						{
							object = m_objDb->CreateObject( fbObj, sizer );
							if ( object )
							{
								parent->AddChild( newsizer );
								newsizer->SetParent( parent );
							}
						}
					}
				}

				if ( !object )
				{
					wxLogError( wxT( "CreateObject failed for class \"%s\", with parent \"%s\", found on line %i" ), _WXSTR( className ).c_str(), parent->GetClassName().c_str(), xrcObj->Row() );
				}
				else
				{
					// It is possible the CreateObject returns an "item" containing the object, e.g. SizerItem or SplitterItem
					// If that is the case, reassign "object" to the actual object
					if ( object && object->GetChildCount() > 0 )
						object = object->GetChild( 0 );

					if ( object )
					{
						// Recursively import the children
						ticpp::Element *element = xrcObj->FirstChildElement( "object", false );
						while ( element )
						{
							GetObject( element, object );
							element = element->NextSiblingElement( "object", false );
						}
					}
				}
			}
		}
	}
	else
	{
		// Create a wxPanel to represent unknown classes
		object = m_objDb->CreateObject( "wxPanel", parent );
		if ( object )
		{
			parent->AddChild( object );
			object->SetParent( parent );
			wxLogError( wxT( "Unknown class \"%s\" found on line %i, replaced with a wxPanel" ), _WXSTR( className ).c_str(), xrcObj->Row() );
		}
		else
		{
			wxString msg( wxString::Format(
			                  wxT( "Unknown class \"%s\" found on line %i, and could not replace with a wxPanel as child of \"%s:%s\"" ),
			                  _WXSTR( className ).c_str(), xrcObj->Row(), parent->GetPropertyAsString( wxT( "name" ) ).c_str(), parent->GetClassName().c_str() ) );

			wxLogError( msg );
		}
	}

	return object;
}