⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlres.cpp

📁 linux下的电骡下载程序源码 包含emule协议的应用。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    wxXmlNode *node;    // first search for match at the top-level nodes (as this is    // where the resource is most commonly looked for):    for (node = parent->GetChildren(); node; node = node->GetNext())    {        if ( node->GetType() == wxXML_ELEMENT_NODE &&                 (node->GetName() == wxT("object") ||                  node->GetName() == wxT("object_ref")) &&             node->GetPropVal(wxT("name"), &dummy) && dummy == name )        {            wxString cls(node->GetPropVal(wxT("class"), wxEmptyString));            if (!classname || cls == classname)                return node;            // object_ref may not have 'class' property:            if (cls.empty() && node->GetName() == wxT("object_ref"))            {                wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);                if (refName.empty())                    continue;                wxXmlNode* refNode = FindResource(refName, wxEmptyString, TRUE);                if (refNode &&                    refNode->GetPropVal(wxT("class"), wxEmptyString) == classname)                {                    return node;                }            }        }    }    if ( recursive )        for (node = parent->GetChildren(); node; node = node->GetNext())        {            if ( node->GetType() == wxXML_ELEMENT_NODE &&                 (node->GetName() == wxT("object") ||                  node->GetName() == wxT("object_ref")) )            {                wxXmlNode* found = DoFindResource(node, name, classname, TRUE);                if ( found )                    return found;            }        }   return NULL;}wxXmlNode *wxXmlResource::FindResource(const wxString& name,                                       const wxString& classname,                                       bool recursive){    UpdateResources(); //ensure everything is up-to-date    wxString dummy;    for (size_t f = 0; f < m_data.size(); f++)    {        if ( m_data[f]->Doc == NULL || m_data[f]->Doc->GetRoot() == NULL )            continue;        wxXmlNode* found = DoFindResource(m_data[f]->Doc->GetRoot(),                                          name, classname, recursive);        if ( found )        {#if wxUSE_FILESYSTEM            m_curFileSystem.ChangePathTo(m_data[f]->File);#endif            return found;        }    }    wxLogError(_("XRC resource '%s' (class '%s') not found!"),               name.c_str(), classname.c_str());    return NULL;}static void MergeNodes(wxXmlNode& dest, wxXmlNode& with){    // Merge properties:    for (wxXmlProperty *prop = with.GetProperties(); prop; prop = prop->GetNext())    {        wxXmlProperty *dprop;        for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext())        {            if ( dprop->GetName() == prop->GetName() )            {                dprop->SetValue(prop->GetValue());                break;            }        }        if ( !dprop )            dest.AddProperty(prop->GetName(), prop->GetValue());   }    // Merge child nodes:    for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext())    {        wxString name = node->GetPropVal(wxT("name"), wxEmptyString);        wxXmlNode *dnode;        for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() )        {            if ( dnode->GetName() == node->GetName() &&                 dnode->GetPropVal(wxT("name"), wxEmptyString) == name &&                 dnode->GetType() == node->GetType() )            {                MergeNodes(*dnode, *node);                break;            }        }        if ( !dnode )            dest.AddChild(new wxXmlNode(*node));    }    if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().Length() )         dest.SetContent(with.GetContent());}wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,                                           wxObject *instance){    return CreateResFromNode2(node, parent, instance);}wxObject *wxXmlResource::CreateResFromNode2(wxXmlNode *node, wxObject *parent,                                            wxObject *instance,                                            wxXmlResourceHandler *handlerToUse){    if (node == NULL) return NULL;    // handling of referenced resource    if ( node->GetName() == wxT("object_ref") )    {        wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);        wxXmlNode* refNode = FindResource(refName, wxEmptyString, TRUE);        if ( !refNode )        {            wxLogError(_("Referenced object node with ref=\"%s\" not found!"),                       refName.c_str());            return NULL;        }        wxXmlNode copy(*refNode);        MergeNodes(copy, *node);        return CreateResFromNode(&copy, parent, instance);    }    wxXmlResourceHandler* handler;    if (handlerToUse)    {                if (handlerToUse->CanHandle(node))        {            return handlerToUse->CreateResource(node, parent, instance);        }    }    else if (node->GetName() == wxT("object"))    {            std::list<wxXmlResourceHandler *>::const_iterator it;        for (it = m_handlers.begin(); it != m_handlers.end(); ++it)        {            handler = *it;            if (handler->CanHandle(node))            {                return handler->CreateResource(node, parent, instance);            }        }    }    wxLogError(_("No handler found for XML node '%s', class '%s'!"),               node->GetName().c_str(),               node->GetPropVal(wxT("class"), wxEmptyString).c_str());    return NULL;}wxXmlSubclassFactoriesList *wxXmlResource::ms_subclassFactories = NULL;/*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory){    if (!ms_subclassFactories)    {        ms_subclassFactories = new wxXmlSubclassFactoriesList;//        ms_subclassFactories->DeleteContents(TRUE);    }    ms_subclassFactories->push_back(factory);}class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory{public:    ~wxXmlSubclassFactoryCXX() {}    wxObject *Create(const wxString& className)    {        wxClassInfo* classInfo = wxClassInfo::FindClass(className);        if (classInfo)            return classInfo->CreateObject();        else            return NULL;    }};wxXmlResourceHandler::wxXmlResourceHandler()        : m_node(NULL), m_parent(NULL), m_instance(NULL),          m_parentAsWindow(NULL), m_instanceAsWindow(NULL){}wxXmlResourceHandler::~wxXmlResourceHandler(){}wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance){    wxXmlNode *myNode = m_node;    wxString myClass = m_class;    wxObject *myParent = m_parent, *myInstance = m_instance;    wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow;    m_instance = instance;    if (!m_instance && node->HasProp(wxT("subclass")) &&        !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))    {        wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);        if (!subclass.empty())        {            std::list<wxXmlSubclassFactory *>::iterator it;            for (it = wxXmlResource::ms_subclassFactories->begin(); it != wxXmlResource::ms_subclassFactories->end(); ++it)            {                m_instance = (*it)->Create(subclass);                if (m_instance)                {                    break;                }            }            if (!m_instance)            {                wxString name = node->GetPropVal(wxT("name"), wxEmptyString);                wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),                           subclass.c_str(), name.c_str());            }        }    }    m_node = node;    m_class = node->GetPropVal(wxT("class"), wxEmptyString);    m_parent = parent;    m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);    m_instanceAsWindow = wxDynamicCast(m_instance, wxWindow);    wxObject *returned = DoCreateResource();    m_node = myNode;    m_class = myClass;    m_parent = myParent; m_parentAsWindow = myParentAW;    m_instance = myInstance; m_instanceAsWindow = myInstanceAW;    return returned;}void wxXmlResourceHandler::AddStyle(const wxString& name, int value){    m_styleNames.Add(name);    m_styleValues.Add(value);}void wxXmlResourceHandler::AddWindowStyles(){    XRC_ADD_STYLE(wxSIMPLE_BORDER);    XRC_ADD_STYLE(wxSUNKEN_BORDER);    XRC_ADD_STYLE(wxDOUBLE_BORDER);    XRC_ADD_STYLE(wxRAISED_BORDER);    XRC_ADD_STYLE(wxSTATIC_BORDER);    XRC_ADD_STYLE(wxNO_BORDER);    XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);    XRC_ADD_STYLE(wxWANTS_CHARS);    XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);}bool wxXmlResourceHandler::HasParam(const wxString& param){    return (GetParamNode(param) != NULL);}int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults){    wxString s = GetParamValue(param);    if (!s) return defaults;    wxStringTokenizer tkn(s, wxT("| \t\n"), wxTOKEN_STRTOK);    int style = 0;    int index;    wxString fl;    while (tkn.HasMoreTokens())    {        fl = tkn.GetNextToken();        index = m_styleNames.Index(fl);        if (index != wxNOT_FOUND)            style |= m_styleValues[index];        else            wxLogError(_("Unknown style flag ") + fl);    }    return style;}wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate){    wxString str1(GetParamValue(param));    wxString str2;    const wxChar *dt;    wxChar amp_char;    // VS: First version of XRC resources used $ instead of & (which is    //     illegal in XML), but later I realized that '_' fits this purpose    //     much better (because &File means "File with F underlined").    if (m_resource->CompareVersion(2,3,0,1) < 0)        amp_char = wxT('$');    else        amp_char = wxT('_');    for (dt = str1.c_str(); *dt; dt++)    {        // Remap amp_char to &, map double amp_char to amp_char (for things        // like "&File..." -- this is illegal in XML, so we use "_File..."):        if (*dt == amp_char)        {            if ( *(++dt) == amp_char )                str2 << amp_char;            else                str2 << wxT('&') << *dt;        }        // Remap \n to CR, \r to LF, \t to TAB:        else if (*dt == wxT('\\'))            switch (*(++dt))            {                case wxT('n') : str2 << wxT('\n'); break;                case wxT('t') : str2 << wxT('\t'); break;                case wxT('r') : str2 << wxT('\r'); break;                default       : str2 << wxT('\\') << *dt; break;            }        else str2 << *dt;    }    if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)        return wxGetTranslation(str2);    else        return str2;}long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv){    long value;    wxString str1 = GetParamValue(param);    if (!str1.ToLong(&value))        value = defaultv;    return value;}int wxXmlResourceHandler::GetID(){    return wxXmlResource::GetXRCID(GetName());}wxString wxXmlResourceHandler::GetName(){    return m_node->GetPropVal(wxT("name"), wxT("-1"));}bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv){    wxString v = GetParamValue(param);    v.MakeLower();    if (!v) return defaultv;    else return (v == wxT("1"));}wxColour wxXmlResourceHandler::GetColour(const wxString& param){    wxString v = GetParamValue(param);    unsigned long tmp = 0;    if (v.Length() != 7 || v[0u] != wxT('#') ||        wxSscanf(v.c_str(), wxT("#%lX"), &tmp) != 1)    {        wxLogError(_("XRC resource: Incorrect colour specification '%s' for property '%s'."),                   v.c_str(), param.c_str());        return wxNullColour;    }    return wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,                    (unsigned char) ((tmp & 0x00FF00) >> 8),                    (unsigned char) ((tmp & 0x0000FF)));}wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,                                         const wxArtClient& defaultArtClient,                                         wxSize size){    /* If the bitmap is specified as stock item, query wxArtProvider for it: */    wxXmlNode *bmpNode = GetParamNode(param);    if ( bmpNode )    {        wxString sid = bmpNode->GetPropVal(wxT("stock_id"), wxEmptyString);        if ( !sid.empty() )        {            wxString scl = bmpNode->GetPropVal(wxT("stock_client"), defaultArtClient);            wxBitmap stockArt =                wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -