Example #1
0
void wxGISToolBar::Serialize(IApplication* pApp, wxXmlNode* pNode, bool bStore)
{
	if(bStore)
	{
		pNode->AddProperty(wxT("size"), wxString::Format(wxT("%u"), GetToolBitmapSize().GetWidth()));
		pNode->AddProperty(wxT("LeftDockable"), m_bLDock == true ? wxT("t") : wxT("f"));
		pNode->AddProperty(wxT("RightDockable"), m_bRDock == true ? wxT("t") : wxT("f"));
		wxGISCommandBar::Serialize(pApp, pNode, bStore);
	}
	else
	{
		m_bLDock = pNode->GetPropVal(wxT("LeftDockable"), wxT("f")) == wxT("f") ? false : true;
		m_bRDock = pNode->GetPropVal(wxT("RightDockable"), wxT("f")) == wxT("f") ? false : true;
		short iSize = wxAtoi(pNode->GetPropVal(wxT("size"), wxT("16")));
		SetToolBitmapSize(wxSize(iSize,iSize));

		wxAuiToolBarItemArray prepend_items;
		wxAuiToolBarItemArray append_items;
		ICommand* pCmd = pApp->GetCommand(wxT("wxGISCommonCmd"), 2);
		if(pCmd)
		{				
			wxAuiToolBarItem item;
			item.SetKind(wxITEM_SEPARATOR);
			append_items.Add(item);
			item.SetKind(pCmd->GetKind());
			item.SetId(pCmd->GetID());
			item.SetLabel(pCmd->GetCaption());
			append_items.Add(item);
		}
		SetCustomOverflowItems(prepend_items, append_items);
		wxGISCommandBar::Serialize(pApp, pNode, bStore);
		Realize();
	}
}
Example #2
0
void wxGISCommandBar::Serialize(IApplication* pApp, wxXmlNode* pNode, bool bStore)
{
	if(bStore)
	{
		pNode->AddProperty(wxT("name"), m_sName);
		pNode->AddProperty(wxT("caption"), m_sCaption);
		for(size_t i = m_CommandArray.size(); i > 0; i--)
		{
			ICommand* pCmd = m_CommandArray[i - 1];
			if(pCmd)
			{
				wxXmlNode* pNewNode = new wxXmlNode(pNode, wxXML_ELEMENT_NODE, wxString(wxT("Item")));
				wxGISEnumCommandKind Kind = pCmd->GetKind();
				switch(Kind)
				{
				case enumGISCommandSeparator:
					pNewNode->AddProperty(wxT("type"), wxT("sep"));
					break;
				case enumGISCommandCheck:
				case enumGISCommandRadio:
				case enumGISCommandNormal:
				case enumGISCommandControl:
				{
					pNewNode->AddProperty(wxT("type"), wxT("cmd"));
					wxObject* pObj = dynamic_cast<wxObject*>(pCmd);
					if(pObj)
					{
						wxClassInfo* pInfo = pObj->GetClassInfo();
						wxString sClassName = pInfo->GetClassName();
						pNewNode->AddProperty(wxT("cmd_name"), sClassName);
						pNewNode->AddProperty(wxT("subtype"), wxString::Format(wxT("%u"), pCmd->GetSubType()));
						pNewNode->AddProperty(wxT("name"), pCmd->GetCaption());
					}
					break;
				}
				case enumGISCommandMenu:
				{
					pNewNode->AddProperty(wxT("type"), wxT("menu"));
					IGISCommandBar* pCB = dynamic_cast<IGISCommandBar*>(pCmd);
					if(pCB)
					{
						pNewNode->AddProperty(wxT("cmd_name"), pCB->GetName());
						pNewNode->AddProperty(wxT("name"), pCmd->GetCaption());
					}
					break;
				}
				default:
					break;
				}
			}
		}
	}
	else
	{
		//m_sName = pNode->GetPropVal(wxT("name"), m_sName);
		//m_sCaption = pNode->GetPropVal(wxT("caption"), m_sCaption);
		wxXmlNode *subchild = pNode->GetChildren();
		while(subchild)
		{
			wxString sType = subchild->GetPropVal(wxT("type"), wxT("sep"));
			if(sType == wxT("cmd"))
			{
				wxString sCmdName = subchild->GetPropVal(wxT("cmd_name"), wxT("None"));
				unsigned char nSubtype = wxAtoi(subchild->GetPropVal(wxT("subtype"), wxT("0")));
				//wxString sName = subchild->GetPropVal(wxT("name"), NONAME);
				ICommand* pSubCmd = pApp->GetCommand(sCmdName, nSubtype);
				if(pSubCmd)
					AddCommand(pSubCmd);
			}
			else if(sType == wxT("menu"))
			{
				//the menu description must be exist in xml before using submenu
				wxString sCmdName = subchild->GetPropVal(wxT("cmd_name"), ERR);
				IGISCommandBar* pGISCommandBar = pApp->GetCommandBar(sCmdName);
				if(pGISCommandBar)
				{
					ICommand* pSubCmd = dynamic_cast<ICommand*>(pGISCommandBar);
					if(pSubCmd)
						AddCommand(pSubCmd);
					else
						AddMenu(dynamic_cast<wxMenu*>(pGISCommandBar), pGISCommandBar->GetCaption());
				}
			}
			else
			{
				ICommand* pSubCmd = pApp->GetCommand(wxT("wxGISCommonCmd"), 3);
				if(pSubCmd)
					AddCommand(pSubCmd);
			}			
			subchild = subchild->GetNext();	
		}
	}
}