/*!
 * \brief Process a left mouse button click on our icon.
 *
 * Boolean values will be inverted.
 *
 * \param treeCtrl The tree control that received the click.
 */
void CConfigItem::OnIconLeftDown(CConfigTree & WXUNUSED(treeCtrl))
{
    if (GetConfigType() != nutOption)
        return;

    switch (GetOptionFlavor()) {
    case nutFlavorBool:
    case nutFlavorBoolData:
        if (IsEnabled()) {
            CNutConfDoc *pDoc = wxGetApp().GetNutConfDoc();

            if (m_option && m_option->nco_exclusivity) {
                if(!IsActive()) {
                    pDoc->DeactivateOptionList(m_option->nco_exclusivity);
                    pDoc->SetActive(*this, true);
                }
            }
            else {
                pDoc->SetActive(*this, !IsActive());
            }
        }
    default:
        break;
    }
}
/*!
 * \brief Refresh a CConfigItem entry in a specified CConfigTree.
 */
bool CConfigItem::UpdateTreeItem(CConfigTree & treeCtrl)
{
    treeCtrl.SetItemText(m_itemId, GetBriefDescription());

    static wxColour normalColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
    static wxColour disabledColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);

    treeCtrl.SetItemTextColour(m_itemId, normalColour);

    int iconState = 0;
    wxString iconName;

    switch (GetConfigType()) {
    case nutFolder:
        iconName = wxT("Folder");
        break;
    case nutLibrary:
        iconName = wxT("Library");
        break;
    case nutModule:
        iconName = wxT("Module");
        break;
    case nutOption:
        if (GetOptionFlavor() == nutFlavorData) {
            switch (GetOptionType()) {
            case nutInteger:
                iconName = wxT("Integer");
                break;
            case nutEnumerated:
                iconName = wxT("Enumerated");
                break;
            case nutString:
                iconName = wxT("Text");
                break;
            case nutBool:
                if (GetUIHint() == nutHintRadio)
                    iconName = wxT("Radiobox");
                else
                    iconName = wxT("Checkbox");
                iconState = (m_value.GetBool()? 0 : 1);
                break;
            }
        }
        if (GetOptionFlavor() == nutFlavorBoolData || GetOptionFlavor() == nutFlavorBool) {
            if (GetUIHint() == nutHintRadio)
                iconName = wxT("Radiobox");
            else
                iconName = wxT("Checkbox");
            iconState = (IsActive()? 0 : 1);
        }
        break;
    }

    if (!iconName.IsEmpty()) {
        int iconId = treeCtrl.GetIconDB().GetIconId(iconName, iconState, IsEnabled());
        treeCtrl.SetItemImage(m_itemId, iconId, wxTreeItemIcon_Normal);
        treeCtrl.SetItemImage(m_itemId, iconId, wxTreeItemIcon_Selected);
    }
    return true;
}
bool CConfigItem::CanEdit() const
{
    if (!IsEnabled())
        return false;

    if (GetConfigType() != nutOption)
        return false;

    if (GetOptionFlavor() != nutFlavorData && GetOptionFlavor() != nutFlavorBoolData)
        return false;

    return true;
}
Esempio n. 4
0
// Can we start editing this item?
bool ecConfigItem::CanEdit() const
{
    if (!GetModifiable())
        return FALSE;

    if (GetConfigType() != ecOption)
        return FALSE;

    if (GetOptionFlavor() != ecFlavorData && GetOptionFlavor() != ecFlavorBoolData)
        return FALSE;

    // TODO: other criteria for editability
    return TRUE;
}
Esempio n. 5
0
// 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();
                str.Replace("\n", "\\n"); // escape any newline chars (eg CYGDAT_UITRON_TASK_INITIALIZERS)
        }
        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
}
Esempio n. 6
0
// Handle a left click on the icon: e.g. (un)check the option
// In the old MFC tool, this was handled by CControlView::Bump
void ecConfigItem::OnIconLeftDown(ecConfigTreeCtrl& treeCtrl)
{
    if (GetConfigType() != ecOption)
        return;

    switch (GetOptionFlavor())
    {
    case ecFlavorBool:
    case ecFlavorBoolData:
        {
            if (GetModifiable())
            {
                wxGetApp().GetConfigToolDoc()->SetEnabled(*this, !m_enabled);
            }
            break;
        }
    case ecFlavorData:
        {
            if (GetModifiable())
            {
                switch (GetOptionType())
                {
                case ecLong:
                    {
                        int nInc = 1;

                        long nOldValue = Value();
                        if(nInc==1 && nOldValue == long(-1))
                        {
                            nOldValue=0;
                        } else if(nInc==-1 && nOldValue==0){
                            nOldValue = long(-1);
                        } else {
                            nOldValue+=nInc;
                        }
                        wxGetApp().GetConfigToolDoc()->SetValue(*this, nOldValue);
                        break;
                    }
                case ecEnumerated:
                    {
                        int nInc = 1;

                        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;
        }
    }

}
Esempio n. 7
0
// Sets the text and icon for this item
bool ecConfigItem::UpdateTreeItem(ecConfigTreeCtrl& treeCtrl)
{
    treeCtrl.SetItemText(m_treeItem, GetItemNameOrMacro());

#if wxCHECK_VERSION(2, 6, 0)
    static wxColour normalColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
    static wxColour disabledColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
#else
    static wxColour normalColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
    static wxColour disabledColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT);
#endif

    treeCtrl.SetItemTextColour(m_treeItem, GetActive() ? normalColour : disabledColour);
    

    // Find which icon state we're in so we can get the appropriate icon id
    int iconState = 0;
    wxString iconName;

    switch (GetConfigType())
    {
        case ecContainer:
            {
                iconName = _("Container");
                iconState = 0;
                break;
            }
        case ecPackage:
            {
                iconName = _("Package");
                iconState = 0;
                break;
            }
        case ecComponent:
            {
                iconName = _("??");
                iconState = 0;
                break;
            }
        case ecOption:
            {
                if (GetOptionFlavor() == ecFlavorData)
                {
                    switch (GetOptionType())
                    {
                    case ecDouble:
                    case ecLong:
                        {
                            iconName = _("Integer");
                            iconState = 0;
                            break;
                        }
                    case ecEnumerated:
                        {
                            iconName = _("Enumerated");
                            iconState = 0;
                            break;
                        }
                    case ecString:
                        {
                            iconName = _("Text");
                            iconState = 0;
                            break;
                        }
                    // ??? Actually I don't think there's such a think as ecBool type, only enabled/disabled
                    case ecBool:
                        {
                            if (GetUIHint() == ecHintCheck)
                                iconName = _("Checkbox");
                            else
                                iconName = _("Radiobox");
                            iconState = (m_value.GetBool() ? 0 : 1);
                            break;
                        }
                    default:
                        {
                            break;
                        }
                    }
                }
                if (GetOptionFlavor() == ecFlavorBoolData || GetOptionFlavor() == ecFlavorBool)
                {
                    if (GetUIHint() == ecHintCheck)
                        iconName = _("Checkbox");
                    else
                        iconName = _("Radiobox");
                    iconState = (m_enabled ? 0 : 1);
                }
                break;
            }
        default:
            {
                break;
            }
    }

    if (!iconName.IsEmpty())
    {
        int iconId = treeCtrl.GetIconDB().GetIconId(iconName, iconState, GetModifiable());
        treeCtrl.SetItemImage(m_treeItem, iconId, wxTreeItemIcon_Normal);
        treeCtrl.SetItemImage(m_treeItem, iconId, wxTreeItemIcon_Selected);
    }

    return TRUE;
}