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

📄 configitem.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                        wxArrayString arEnum;                        EvalEnumStrings (arEnum); // calculate legal values just in time                        if (0 == arEnum.GetCount()) // if no legal values...                            break;           // ...do nothing                        int nIndex = -1;                        const wxString strCurrent = StringValue ();                        int nEnum;                        for (nEnum = 0; (nEnum < arEnum.GetCount()) && (nIndex == -1); nEnum++)                            if (0 == arEnum[nEnum].CompareTo (strCurrent))                                nIndex = nEnum; // the index of the current value                                                        if (nIndex != -1) // if the current value is still legal                                nIndex += (nInc < 0 ? -1 : 1); // increment/decrement the index                            else                                nIndex = 0; // otherwise select the first enum                                                        if (nIndex < 0) // if the new index is negative                                nIndex = arEnum.GetCount()-1; // make it positive                            wxGetApp().GetConfigToolDoc()->SetValue(*this, arEnum[nIndex % arEnum.GetCount()]);                            break;                    }                default:                    {                        break;                    }                }            }            break;           }    default:        {            break;        }    }}// Gets the value to display (often an empty string)wxString ecConfigItem::GetDisplayValue() const{    wxString str;    switch(GetOptionType())    {    case ecEnumerated:    case ecLong:    case ecDouble:    case ecString:        {            if (GetCdlValuable())                str = StringValue();        }        break;    default:        break;    }    return str;#if 0    switch (GetConfigType())    {        case ecComponent:        case ecContainer:            {                return wxEmptyString;                break;            }        case ecPackage:            {                return m_value.GetString();                break;            }        case ecOption:            {                switch (GetOptionType())                {                    case ecDouble:                        {                            wxString val;                            val.Printf("%.4lf", (double) m_value.GetDouble());                            return val;                        }                    case ecLong:                        {                            wxString val;                            val.Printf("%.ld", (long) m_value.GetLong());                            return val;                            break;                        }                    case ecEnumerated:                    case ecString:                        {                            return m_value.GetString();                            break;                        }                    case ecBool:                        {                            return wxEmptyString;                            break;                        }                    default:                        {                            break;                        }                }                break;            }        default:            {                break;            }    }    return wxEmptyString;#endif}// Can we start editing this item?bool ecConfigItem::CanEdit() const{    if (!GetActive())        return FALSE;    if (GetConfigType() != ecOption)        return FALSE;    if (GetOptionFlavor() != ecFlavorData && GetOptionFlavor() != ecFlavorBoolData)        return FALSE;    // TODO: other criteria for editability    return TRUE;}// Creates an edit window. It will be positioned by the caller.wxWindow* ecConfigItem::CreateEditWindow(wxWindow* parent){    wxWindow* window = NULL;    switch(GetOptionType())    {    case ecEnumerated:        {            window = new ecEnumEditorCtrl(parent, ecID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize,                /* wxNO_BORDER */ 0);            wxArrayString arEnumStrings;            EvalEnumStrings(arEnumStrings);            int i;            for (i = 0; i < arEnumStrings.GetCount(); i++)            {                ((ecEnumEditorCtrl*) window)->Append(arEnumStrings[i]);            }            break;        }    case ecLong:        {            window = new ecIntegerEditorCtrl(parent, ecID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize,                /* wxNO_BORDER | */ wxSP_ARROW_KEYS);            break;        }    case ecDouble:        {            window = new ecDoubleEditorCtrl(parent, ecID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize,                /* wxNO_BORDER|*/ wxTE_PROCESS_ENTER);            break;        }    case ecString:        {            window = new ecTextEditorCtrl(parent, ecID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize,                /* wxNO_BORDER|*/ wxTE_PROCESS_ENTER);            break;        }    default:        break;    }    wxASSERT (window != NULL) ;        return window;}    // Transfers data between item and windowbool ecConfigItem::TransferDataToWindow(wxWindow* window){    if (window->IsKindOf(CLASSINFO(ecTextEditorCtrl)))    {        ecTextEditorCtrl* win = (ecTextEditorCtrl*) window;        win->SetValue(GetDisplayValue());    }    else if (window->IsKindOf(CLASSINFO(ecDoubleEditorCtrl)))    {        ecDoubleEditorCtrl* win = (ecDoubleEditorCtrl*) window;        win->SetValue(GetDisplayValue());    }    else if (window->IsKindOf(CLASSINFO(ecEnumEditorCtrl)))    {        ecEnumEditorCtrl* win = (ecEnumEditorCtrl*) window;        win->SetStringSelection(GetDisplayValue());    }    else if (window->IsKindOf(CLASSINFO(ecIntegerEditorCtrl)))    {        ecIntegerEditorCtrl* win = (ecIntegerEditorCtrl*) window;        long i;        ecUtils::StrToItemIntegerType(StringValue(), i);        wxString val;        val.Printf(wxT("%ld"), i);        win->SetValue(val);    }    return TRUE;}bool ecConfigItem::TransferDataFromWindow(wxWindow* window){    ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();    wxASSERT (doc != NULL);    if (!doc)        return FALSE;    if (window->IsKindOf(CLASSINFO(ecTextEditorCtrl)))    {        ecTextEditorCtrl* win = (ecTextEditorCtrl*) window;        wxASSERT ( GetOptionType() == ecString );        // TODO: do checking        doc->SetValue(*this, win->GetValue());    }    else if (window->IsKindOf(CLASSINFO(ecDoubleEditorCtrl)))    {        ecDoubleEditorCtrl* win = (ecDoubleEditorCtrl*) window;        wxASSERT ( GetOptionType() == ecString );        // TODO: do checking        doc->SetValue(*this, atof(win->GetValue()));    }    else if (window->IsKindOf(CLASSINFO(ecEnumEditorCtrl)))    {        ecEnumEditorCtrl* win = (ecEnumEditorCtrl*) window;        wxASSERT ( GetOptionType() == ecEnumerated );        // TODO: do checking        doc->SetValue(*this, win->GetStringSelection());    }    else if (window->IsKindOf(CLASSINFO(ecIntegerEditorCtrl)))    {        ecIntegerEditorCtrl* win = (ecIntegerEditorCtrl*) window;        wxASSERT ( GetOptionType() == ecLong );        // TODO: do checking        doc->SetValue(*this, (long) win->GetValue());    }    return TRUE;}//// Taken from MFC versionconst ecFileName ecConfigItem::GetFilename() const{    wxString sep(wxFILE_SEP_PATH);    ecFileName strFile;    const CdlNode node = dynamic_cast<CdlNode> (m_CdlItem);    if (node){        // get the package which owns the configuration item        const CdlPackage package = GetOwnerPackage();        if (package){                        // return the filename of the config header            wxString pkg(wxT("include"));            pkg += sep;            pkg += wxT("pkgconf");            strFile=ecFileName(wxGetApp().GetConfigToolDoc()->GetInstallTree()+sep+pkg) + package->get_config_header ().c_str ();        }    }    return strFile;}// Change version (of a package)bool ecConfigItem::ChangeVersion(const wxString &strVersion){    bool rc=FALSE;    CdlPackage package=dynamic_cast<CdlPackage>(GetCdlItem());    wxASSERT(package != 0);    const CdlValuable valuable = GetCdlValuable();    wxASSERT (valuable != 0);    const wxString strMacroName(GetMacro());    if (strVersion != valuable->get_value ().c_str ()) { // if the wrong version is loaded        // TRACE (wxT("Changing package %s to version '%s'\n"), strMacroName, strVersion);        try {            wxGetApp().GetConfigToolDoc()->GetCdlConfig()->change_package_version (package, ecUtils::UnicodeToStdStr (strVersion), ecConfigToolDoc::CdlParseErrorHandler, ecConfigToolDoc::CdlParseWarningHandler);            rc=TRUE;        }        catch (CdlStringException exception) {            wxString msg;            msg.Printf(wxT("Error changing package %s to version '%s':\n\n%s"), (const wxChar*) strMacroName, (const wxChar*) strVersion, (const wxChar*) wxString (exception.get_message ().c_str ())) ;            wxMessageBox(msg);        }        catch (...) {            wxString msg;            msg.Printf(wxT("Error changing package %s to version '%s'"), (const wxChar*) strMacroName, (const wxChar*) strVersion) ;            wxMessageBox(msg);        }    }    return rc;}// Unload (a package)bool ecConfigItem::Unload(){    bool rc=FALSE;    CdlPackage package=dynamic_cast<CdlPackage>(GetCdlItem());    wxASSERT(package);    ecConfigToolDoc* pDoc=wxGetApp().GetConfigToolDoc();    // Remove its objects from the view to prevent any painting problems    ecTreeItemData* data = (ecTreeItemData*) wxGetApp().GetTreeCtrl()->GetItemData(GetTreeItem());    wxASSERT(data);    // I _think_ we should do this to stop 'this' from being deleted when we delete the item.    // But, in that case, where do we delete this item?    // Perhaps should store them in an array in the document, as per the MFC tool.    data->SetConfigItem(NULL);    wxGetApp().GetTreeCtrl()->Delete(GetTreeItem());    wxNode* node = pDoc->GetItems().First();    while (node)    {        ecConfigItem* item = wxDynamicCast(node->Data(), ecConfigItem);        if (package == item->GetOwnerPackage())        {            item->SetTreeItem(wxTreeItemId()); // Make sure we can't attempt to paint it            item->SetCdlItem(NULL); // Make sure we can't access stale data        }        node = node->Next();    }    const wxString strMacroName(GetMacro());    //TRACE (wxT("Unloading package %s\n"), strMacroName);    try {        pDoc->GetCdlConfig()->unload_package (package);        rc=TRUE;    }    catch (CdlStringException exception) {        wxString msg;        wxString exceptionMsg(exception.get_message ().c_str ());        msg.Printf(wxT("Error unloading package %s:\n\n%s"), (const wxChar*) strMacroName, (const wxChar*) exceptionMsg );        wxMessageBox(msg);    }    catch (...) {        wxString msg;        msg.Printf(wxT("Error unloading package %s"), (const wxChar*) strMacroName);        wxMessageBox(msg);    }    m_treeItem=wxTreeItemId();   // Make sure we can't attempt to paint it    m_CdlItem=NULL; // Make sure we can't access stale data    return rc;}wxString ecConfigItem::GetURL() const{    for(const ecConfigItem *pItem=this;pItem;pItem=pItem->GetParent()){        if(pItem->GetCdlItem()){            wxString strURL;            strURL=pItem->GetCdlItem()->get_doc_url().c_str();            if(strURL.Len()){                return strURL;            }            strURL=pItem->GetCdlItem()->get_doc().c_str();            if(strURL.Len()){                return strURL;            }        }    }

⌨️ 快捷键说明

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