示例#1
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();	
		}
	}
}
示例#2
0
void wxGISAcceleratorTable::Store(void)
{
	wxXmlNode* pAcceleratorsNodeCU = m_pConf->GetConfigNode(enumGISHKCU, wxString(wxT("accelerators")));
	if(pAcceleratorsNodeCU)
		wxGISConfig::DeleteNodeChildren(pAcceleratorsNodeCU);
	else
		pAcceleratorsNodeCU = m_pConf->CreateConfigNode(enumGISHKCU, wxString(wxT("accelerators")), true);
	for(size_t i = 0; i < m_AccelEntryArray.size(); i++)
	{
		ICommand* pCmd = m_pApp->GetCommand(m_AccelEntryArray[i].GetCommand());
		wxObject* pObj = dynamic_cast<wxObject*>(pCmd);
		if(pObj)
		{
			wxClassInfo* pInfo = pObj->GetClassInfo();
			wxString sClassName = pInfo->GetClassName();
			unsigned char nSubType = pCmd->GetSubType();
			int nKeyCode = m_AccelEntryArray[i].GetKeyCode();
			int nFlags = m_AccelEntryArray[i].GetFlags();
			wxString sFlags;

			if(nFlags & wxMOD_ALT)
				sFlags += wxT("ALT|");
			if(nFlags & wxMOD_CONTROL)
				sFlags += wxT("CTRL|");
			if(nFlags & wxMOD_SHIFT)
				sFlags += wxT("SHIFT|");
			if(nFlags == 0)
				sFlags += wxT("NORMAL");

			wxString sKeyCode;
			if(nKeyCode >= WXK_F1 && nKeyCode <= WXK_F12)
			{
				sKeyCode += wxString::Format(wxT("WXK_F%d"), nKeyCode - WXK_DIVIDE );
			}
			else if((nKeyCode >= (int)'A' && nKeyCode <= (int)'Z') || (nKeyCode >= (int)'0' && nKeyCode <= (int)'9') || (nKeyCode >= WXK_NUMPAD0 && nKeyCode <= WXK_NUMPAD9))
			{
				sKeyCode += wxString(wxChar(nKeyCode));
			}
			else if(nKeyCode == WXK_DELETE )
			{
				sKeyCode += wxString(wxT("WXK_DELETE"));
			}	
			else if(nKeyCode == WXK_NUMPAD_DELETE)
			{
				sKeyCode += wxString(wxT("WXK_NUMPAD_DELETE"));
			}
			else if(nKeyCode == WXK_ESCAPE)
			{
				sKeyCode += wxString(wxT("WXK_ESCAPE"));
			}
			else if(nKeyCode == WXK_SPACE)
			{
				sKeyCode += wxString(wxT("WXK_SPACE"));
			}
			else if(nKeyCode == WXK_NUMPAD_SPACE)
			{
				sKeyCode += wxString(wxT("WXK_NUMPAD_SPACE"));
			}
			else if(nKeyCode == WXK_RETURN)
			{
				sKeyCode += wxString(wxT("WXK_RETURN"));
			}
			else if(nKeyCode == WXK_EXECUTE)
			{
				sKeyCode += wxString(wxT("WXK_EXECUTE"));
			}
			else if(nKeyCode == WXK_PAUSE)
			{
				sKeyCode += wxString(wxT("WXK_PAUSE"));
			}
			else if(nKeyCode == WXK_END)
			{
				sKeyCode += wxString(wxT("WXK_END"));
			}
			else if(nKeyCode == WXK_NUMPAD_END)
			{
				sKeyCode += wxString(wxT("WXK_NUMPAD_END"));
			}
			else if(nKeyCode == WXK_HOME)
			{
				sKeyCode += wxString(wxT("WXK_HOME"));
			}
			else if(nKeyCode == WXK_NUMPAD_HOME)
			{
				sKeyCode += wxString(wxT("WXK_NUMPAD_HOME"));
			}
			else if(nKeyCode == WXK_INSERT)
			{
				sKeyCode += wxString(wxT("WXK_INSERT"));
			}
			else if(nKeyCode == WXK_NUMPAD_INSERT)
			{
				sKeyCode += wxString(wxT("WXK_NUMPAD_INSERT"));
			}

			wxXmlNode* pNewNode = new wxXmlNode(pAcceleratorsNodeCU, wxXML_ELEMENT_NODE, wxString(wxT("Entry")));
			pNewNode->AddProperty(wxT("cmd_name"), sClassName);
			pNewNode->AddProperty(wxT("subtype"), wxString::Format(wxT("%u"), nSubType));
			pNewNode->AddProperty(wxT("flags"), sFlags);
			pNewNode->AddProperty(wxT("keycode"), sKeyCode);
		}
	}
}