📄 configitem.cpp
字号:
//####COPYRIGHTBEGIN####//// ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 of the License, or (at your option)// any later version.//// This program is distributed in the hope that it will be useful, but WITHOUT// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for// more details.//// You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------////####COPYRIGHTEND####// configitem.cpp :////===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): julians// Contact(s): julians// Date: 2000/09/01// Version: $Id: configitem.cpp,v 1.10 2001/04/30 17:12:32 julians Exp $// Purpose:// Description: Implementation file for the ConfigTool application class// Requires:// Provides:// See also:// Known bugs:// Usage:////####DESCRIPTIONEND####////===========================================================================// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifdef __GNUG__ #pragma implementation "configitem.h"#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__ #pragma hdrstop#endif#include "wx/settings.h"#include "wx/valgen.h"#include "configitem.h"#include "configtree.h"#include "configtooldoc.h"#include "configtoolview.h"#include "ecutils.h"IMPLEMENT_CLASS(ecConfigItem, wxObject)/* * ecConfigItem * Represents a node in the configuration hierarchy. * For every ecConfigItem, there is also an ecTreeItemData * that points to it. */ecConfigItem::ecConfigItem(ecConfigItem* parent, const wxString& name, ecConfigType ctype, ecOptionFlavor flavor, ecOptionType otype, bool active, bool enabled, ecUIHint hint){ m_CdlItem = NULL; m_name = name; m_configType = ctype; m_optionType = otype; m_optionFlavor = flavor; m_enabled = enabled; m_active = active; m_parent = parent; m_hint = hint; m_treeItem = wxTreeItemId(); switch (otype) { case ecDouble: { m_value = 0.0; break; } case ecString: case ecEnumerated: { m_value = wxT(""); break; } case ecLong: { m_value = (long) 0; break; } case ecBool: { m_value = (bool) FALSE; break; } default: { break; } }}ecConfigItem::ecConfigItem(ecConfigItem* parent, CdlUserVisible vitem){ m_name = wxT("UNNAMED"); m_configType = ecConfigTypeNone; m_optionType = ecOptionTypeNone; m_optionFlavor = ecFlavorNone; m_enabled = FALSE; m_active = FALSE; m_parent = parent; m_CdlItem = vitem; m_hint = ecHintNone; m_treeItem = wxTreeItemId(); ecConfigTreeCtrl* treeCtrl = wxGetApp().GetTreeCtrl(); m_treeItem = treeCtrl->AppendItem(parent->GetTreeItem(), m_name, -1, -1, new ecTreeItemData(this)); ConvertFromCdl(); UpdateTreeItem(* treeCtrl);}ecConfigItem::~ecConfigItem(){ // Make sure that the tree item no longer references this object ecConfigTreeCtrl* treeCtrl = wxGetApp().GetTreeCtrl(); if (m_treeItem && treeCtrl) { ecTreeItemData* data = (ecTreeItemData*) treeCtrl->GetItemData(m_treeItem); data->SetConfigItem(NULL); } ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); if (doc) { doc->GetItems().DeleteObject(this); }}// Convert from Cdl to internal representationbool ecConfigItem::ConvertFromCdl(){ if (!GetCdlItem()) return FALSE; m_name = GetCdlItem()->get_display ().c_str (); m_macro = GetCdlItem()->get_name().c_str(); m_strDescr = ecUtils::StripExtraWhitespace (wxString (GetCdlItem()->get_description ().c_str ())); // FIXME: re-implement using CdlValuableBody::get_widget_hint() // (comment from original MFC configtool) if (IsPackage()) { // If a package item, display the package version string m_optionType = ecString; m_configType = ecPackage; m_optionFlavor = ecFlavorNone; } else { const CdlValuable valuable = dynamic_cast<CdlValuable> (GetCdlItem()); switch (valuable->get_flavor ()){ case CdlValueFlavor_None: m_optionFlavor = ecFlavorNone; m_optionType=ecOptionTypeNone; //??? Shouldn't it be ecBool for CdlValueFlavor_Bool? m_configType = ecContainer; break; case CdlValueFlavor_Bool: m_optionFlavor = ecFlavorBool; m_optionType=ecOptionTypeNone; //??? Shouldn't it be ecBool for CdlValueFlavor_Bool? m_configType = ecOption; m_hint = (HasRadio() ? ecHintRadio : ecHintCheck); break; case CdlValueFlavor_Data: case CdlValueFlavor_BoolData: m_optionFlavor = (valuable->get_flavor() == CdlValueFlavor_Data ? ecFlavorData : ecFlavorBoolData); m_configType = ecOption; m_hint = (HasRadio() ? ecHintRadio : ecHintCheck); if (! valuable->has_legal_values ()) { m_optionType=ecString; } else if (0 == valuable->get_legal_values ()->ranges.size ()) { m_optionType=ecEnumerated; } else { CdlListValue list_value; CdlEvalContext context (NULL, valuable, valuable->get_property (CdlPropertyId_LegalValues)); valuable->get_legal_values ()->eval (context, list_value); m_optionType=list_value.get_double_ranges ().size () ? ecDouble : ecLong; } break; default: wxASSERT (0); // specified flavor not supported break; } } m_active = IsActive(); m_enabled = IsEnabled(); return TRUE;}wxString ecConfigItem::GetItemNameOrMacro() const{ return (wxGetApp().GetSettings().m_showMacroNames && !GetMacro().IsEmpty() ? GetMacro() : GetName());}// Sets the text and icon for this itembool ecConfigItem::UpdateTreeItem(ecConfigTreeCtrl& treeCtrl){ treeCtrl.SetItemText(m_treeItem, m_name); static wxColour normalColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); static wxColour disabledColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT); 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, GetActive()); treeCtrl.SetItemImage(m_treeItem, iconId, wxTreeItemIcon_Normal); treeCtrl.SetItemImage(m_treeItem, iconId, wxTreeItemIcon_Selected); } return TRUE;}// Handle a left click on the icon: e.g. (un)check the option// In the old MFC tool, this was handled by CControlView::Bumpvoid ecConfigItem::OnIconLeftDown(ecConfigTreeCtrl& treeCtrl){ if (GetConfigType() != ecOption) return; switch (GetOptionFlavor()) { case ecFlavorBool: case ecFlavorBoolData: { if (GetActive()) { wxGetApp().GetConfigToolDoc()->SetEnabled(*this, !m_enabled); } break; } case ecFlavorData: { if (GetActive()) { 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -