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

📄 configitem.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    default:        wxASSERT(FALSE);        break;    }    return str;}    int ecConfigItem::EvalEnumStrings (wxArrayString &arEnumStrings) const{    const CdlValuable valuable = GetCdlValuable();    wxASSERT (valuable);    /*    if (m_Type == Boolean)    {    arEnumStrings.SetSize (2);    arEnumStrings.SetAt (0, wxT("True"));    arEnumStrings.SetAt (1, wxT("False"));    }    else    */    {        wxASSERT (m_optionType == ecEnumerated);        CdlListValue list_value;        CdlEvalContext context (NULL, m_CdlItem, m_CdlItem->get_property (CdlPropertyId_LegalValues));        valuable->get_legal_values ()->eval (context, list_value);        const std::vector<CdlSimpleValue> & table = list_value.get_table ();                // add legal values to the list        for (unsigned int nValue = 0; nValue < table.size (); nValue++)        {            arEnumStrings.Add (table [nValue].get_value ().c_str ());        }    }    return arEnumStrings.GetCount();}static const wxChar* gs_whereTypes[] = {        _("Macro names"),         _("Item names"),         _("Short descriptions"),         _("Current Values"),         _("Default Values")};// Convert a string representation of 'where' (e.g. "Macro names") to// ecWhereTypeecWhereType ecConfigItem::WhereStringToType(const wxString& whereString){    int sz = 5;    int i;    for (i = 0; i < sz; i++)        if (whereString == gs_whereTypes[i])            return (ecWhereType) i;    wxASSERT( FALSE );    return (ecWhereType) 0;}// Convert a type representation of 'where' to a stringwxString ecConfigItem::WhereTypeToString(ecWhereType whereType){    return gs_whereTypes[(size_t) whereType] ;}// Bump by specified amount, or toggle if a boolean valuebool ecConfigItem::BumpItem(int nInc){    bool rc = FALSE;        // Take an action for clicking on the icon    ecConfigToolDoc* pDoc = wxGetApp().GetConfigToolDoc();        // do not modify the option value if it is inactive or not modifiable    const CdlValuable valuable = GetCdlValuable();    if (!valuable || (valuable->is_modifiable () && valuable->is_active ()))    {        if (0 == nInc) // if a toggle request        {            if (HasBool () && ! (HasRadio () && IsEnabled ())) { // only enable (not disable) a radio button                rc = pDoc->SetEnabled (*this, ! this->IsEnabled ()); // toggle enabled/disabled state            }        } else if (IsEnabled ()) { // the item is enabled...            switch(GetOptionType())            {            case ecOptionTypeNone:            case ecString:            case ecDouble:                break;            case ecEnumerated:                {                    wxArrayString arEnum;                    EvalEnumStrings (arEnum); // calculate legal values just in time                    if (0==arEnum.Count()) // if no legal values...                        break;           // ...do nothing                    int nIndex = -1;                    const wxString strCurrent = StringValue ();                    int nEnum;                    for (nEnum = 0; (nEnum < arEnum.Count()) && (nIndex == -1); nEnum++)                        if (strCurrent == arEnum[nEnum])                            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.Count()-1; // make it positive                                                rc=pDoc->SetValue (*this, arEnum[nIndex % arEnum.Count()]);                }                break;            case ecLong:                {                    // TODO: if we're editing, we should get the value in the edit item                    // and not the ecConfigItem.                    long nOldValue = Value();                    if(nInc==1 && nOldValue==-1){                        nOldValue=0;                    } else if(nInc==-1 && nOldValue==0){                        nOldValue=-1;                    } else {                        nOldValue+=nInc;                    }                    rc=pDoc->SetValue(*this, nOldValue);                    break;                }                                break;                /*                case CConfigItem::Boolean:                                  {                  ItemIntegerType nOldValue=Value(h);                  pDoc->SetValue(ti,nOldValue^1);                  }                  break;                  case CConfigItem::Radio:                                      if(0==Value(h)){                    pDoc->SetValue(ti, (ItemIntegerType) 1);                    }                    break;                */            default:                break;            }        }    }    return rc;}#if 0/* Presumably we don't need this since we use the m_parent member insteadecConfigItem *ecConfigItem::Parent() const {     CTreeCtrl &tree=CConfigTool::GetControlView()->GetTreeCtrl();    HTREEITEM hParent=tree.GetParentItem(HItem());    return (NULL==hParent||TVI_ROOT==hParent)?NULL:(ecConfigItem *)tree.GetItemData(hParent);}*/#endif/* * ecTextEditorCtrl * A specialised wxTextCtrl, for editing config values */BEGIN_EVENT_TABLE(ecTextEditorCtrl, wxTextCtrl)    EVT_TEXT_ENTER(-1, ecTextEditorCtrl::OnEnter)    EVT_KILL_FOCUS(ecTextEditorCtrl::OnKillFocus)    EVT_LEFT_DCLICK(ecTextEditorCtrl::OnLeftDClick)END_EVENT_TABLE()IMPLEMENT_CLASS(ecTextEditorCtrl, wxTextCtrl)ecTextEditorCtrl::ecTextEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,                                   long style):    wxTextCtrl(parent, id, wxEmptyString, pos, size, style){}void ecTextEditorCtrl::OnEnter(wxCommandEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}void ecTextEditorCtrl::OnKillFocus(wxFocusEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}// Edit the string in a separate dialog, for conveniencevoid ecTextEditorCtrl::OnLeftDClick(wxMouseEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    ecConfigItem* item = parent->GetCurrentConfigItem();    ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();        wxString initialValue(GetValue());        ecEditStringDialog dialog(initialValue, wxGetApp().GetTopWindow(), ecID_EDIT_STRING_DIALOG);    if (dialog.ShowModal() == wxID_OK)    {        wxString val = dialog.GetValue() ;        // This control will have been deleted at this point, due to losing the focus.        // So update the item, not the control.        // wxTextCtrl::SetValue(val);        doc->SetValue(*item, val);    }   }/* * ecDoubleEditorCtrl * A specialised wxTextCtrl, for editing double config values */BEGIN_EVENT_TABLE(ecDoubleEditorCtrl, wxTextCtrl)    EVT_TEXT_ENTER(-1, ecDoubleEditorCtrl::OnEnter)    EVT_KILL_FOCUS(ecDoubleEditorCtrl::OnKillFocus)END_EVENT_TABLE()IMPLEMENT_CLASS(ecDoubleEditorCtrl, wxTextCtrl)ecDoubleEditorCtrl::ecDoubleEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,                                   long style):    wxTextCtrl(parent, id, wxEmptyString, pos, size, style){}void ecDoubleEditorCtrl::OnEnter(wxCommandEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}void ecDoubleEditorCtrl::OnKillFocus(wxFocusEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}/* * ecIntegerEditorCtrl * A specialised wxTextCtrl, for editing double config values */BEGIN_EVENT_TABLE(ecIntegerEditorCtrl, wxSpinCtrl)    EVT_TEXT_ENTER(-1, ecIntegerEditorCtrl::OnEnter)    EVT_KILL_FOCUS(ecIntegerEditorCtrl::OnKillFocus)END_EVENT_TABLE()IMPLEMENT_CLASS(ecIntegerEditorCtrl, wxSpinCtrl)ecIntegerEditorCtrl::ecIntegerEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,                                   long style):    wxSpinCtrl(parent, id, wxEmptyString, pos, size, style, -32000, 32000, 0){}void ecIntegerEditorCtrl::OnEnter(wxCommandEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}void ecIntegerEditorCtrl::OnKillFocus(wxFocusEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}/* * ecEnumEditorCtrl * A specialised wxChoice, for editing enumerated config values */BEGIN_EVENT_TABLE(ecEnumEditorCtrl, wxChoice)    EVT_CHAR(ecEnumEditorCtrl::OnChar)    EVT_KILL_FOCUS(ecEnumEditorCtrl::OnKillFocus)END_EVENT_TABLE()IMPLEMENT_CLASS(ecEnumEditorCtrl, wxChoice)ecEnumEditorCtrl::ecEnumEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,                                   long style):    wxChoice(parent, id, pos, size, 0, 0, style){}void ecEnumEditorCtrl::OnChar(wxKeyEvent& event){    if (event.GetKeyCode() == WXK_RETURN)    {        ecValueWindow* parent = (ecValueWindow*) GetParent();        parent->EndEditing();    }    else        event.Skip();}void ecEnumEditorCtrl::OnKillFocus(wxFocusEvent& event){    ecValueWindow* parent = (ecValueWindow*) GetParent();    parent->EndEditing();}/* * ecEditStringDialog * Pops up to make it easier to edit large string values */BEGIN_EVENT_TABLE(ecEditStringDialog, ecDialog)    EVT_BUTTON(wxID_OK, ecEditStringDialog::OnOK)END_EVENT_TABLE()ecEditStringDialog::ecEditStringDialog(const wxString& initialValue, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,        long style){    m_value = initialValue;    //SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);    ecDialog::Create(parent, id, _("String Edit"),        wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);    CreateControls(this);        TransferDataToWindow();    Centre(wxBOTH);}ecEditStringDialog::~ecEditStringDialog(){}//// Event handlersvoid ecEditStringDialog::OnOK(wxCommandEvent& event){    wxDialog::OnOK(event);}//// Operationsvoid ecEditStringDialog::CreateControls(wxWindow* parent){    wxSizer *item0 = new wxBoxSizer( wxVERTICAL );    wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );    item1->Add( 20, 20, 10, wxALIGN_CENTRE|wxALL, 5 );    wxButton *item2 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );    item2->SetDefault();    item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );    wxButton *item3 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );    item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );    item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );    wxTextCtrl *item4 = new wxTextCtrl( parent, ecID_STRING_EDIT_TEXTCTRL, _(""), wxDefaultPosition, wxSize(420,250), wxTE_MULTILINE );    item0->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );    parent->SetAutoLayout( TRUE );    parent->SetSizer( item0 );    parent->Layout();    item0->Fit( parent );    item0->SetSizeHints( parent );    FindWindow(ecID_STRING_EDIT_TEXTCTRL)->SetValidator(wxGenericValidator(& m_value));    FindWindow(ecID_STRING_EDIT_TEXTCTRL)->SetFocus();}

⌨️ 快捷键说明

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