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

📄 configitem.cpp

📁 eCos1.31版
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//####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####////===========================================================================//===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): 	sdf// Contact(s):	sdf// Date:		1998/08/11// Version:		0.01// Purpose:	// Description:	This is the implementation of the configuration item class// Requires:	// Provides:	// See also:    // Known bugs:	// Usage:	////####DESCRIPTIONEND####////===========================================================================#include "stdafx.h"#include "ConfigItem.h"#include "ControlView.h"#include "CTUtils.h"#ifdef PLUGIN  #define INCLUDEFILE "ide.common.h" // for setEditLocation  #include "IncludeSTL.h"  #include "common/CodeCoordinate.h"#endif#include "ConfigToolDoc.h"#include "ConfigTool.h"LPCTSTR CConfigItem::TreeItemTypeImage[MaxTreeItemType + 1]={  _T("None"), _T("Integer"), _T("Enumeration"), _T("String"), _T("Double"), 0}; // Internationalization OKconst CFileName CConfigItem::FileName() const{  CFileName 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      strFile=CFileName(CConfigTool::GetConfigToolDoc()->InstallTree()+_T("include\\pkgconf"))+package->get_config_header ().c_str ();    }  }  return strFile;}CConfigItem::CConfigItem(CConfigItem *pParent, CdlUserVisible CdlItem):  m_CdlItem(CdlItem){  CTreeCtrl &tree=CConfigTool::GetControlView()->GetTreeCtrl();  HTREEITEM hParent;  if(NULL==CdlItem){    // This is the root item    hParent=TVI_ROOT;    m_Type=None;  } else {    hParent=pParent->HItem();      // FIXME: re-implement using CdlValuableBody::get_widget_hint()    if (IsPackage()) {      // If a package item, display the package version string      m_Type=String;     } else {      const CdlValuable valuable = dynamic_cast<CdlValuable> (CdlItem);      switch (valuable->get_flavor ()){        case CdlValueFlavor_None:        case CdlValueFlavor_Bool:          m_Type=None;          break;        case CdlValueFlavor_Data:        case CdlValueFlavor_BoolData:          if (! valuable->has_legal_values ()) {            m_Type=String;          } else if (0 == valuable->get_legal_values ()->ranges.size ()) {            m_Type=Enum;          } else {            CdlListValue list_value;            CdlEvalContext context (NULL, valuable, valuable->get_property (CdlPropertyId_LegalValues));            valuable->get_legal_values ()->eval (context, list_value);            m_Type=list_value.get_double_ranges ().size () ? Double : Integer;          }          break;        default:          ASSERT (0); // specified flavor not supported          break;      }    }    }  m_hItem=tree.InsertItem(ItemNameOrMacro(),hParent);  tree.SetItemData(m_hItem,(DWORD)this);  CConfigTool::GetControlView()->AdjustItemImage(m_hItem);}CConfigItem::~CConfigItem(){}CString CConfigItem::GetURL() const{  for(const CConfigItem *pItem=this;pItem;pItem=pItem->Parent()){    if(pItem->GetCdlItem()){      CString strURL;      strURL=pItem->GetCdlItem()->get_doc_url().c_str();      if(strURL.GetLength()){        return strURL;      }      strURL=pItem->GetCdlItem()->get_doc().c_str();      if(strURL.GetLength()){        return strURL;      }    }  }  return _T("ref/ecos-ref.html"); // the default URL}bool CConfigItem::SetValue(LPCTSTR pszValue, CdlTransaction transaction/*=NULL*/){  ASSERT ((m_Type == String) || (m_Type == Enum));  const CdlValuable valuable = GetCdlValuable();  ASSERT (valuable);  const std::string str=CUtils::UnicodeToStdStr (pszValue);  if(transaction){    if (CdlValueFlavor_BoolData == valuable->get_flavor ()){      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (transaction, valuable->is_enabled (), str, CdlValueSource_User);    } else {// CdlValueFlavor_Data      valuable->set_value (transaction, str, CdlValueSource_User);    }  } else {    if (CdlValueFlavor_BoolData == valuable->get_flavor ()){      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (valuable->is_enabled (), str, CdlValueSource_User);    } else {// CdlValueFlavor_Data      valuable->set_value (str, CdlValueSource_User);    }  }    return true;}bool CConfigItem::SetValue (double dValue, CdlTransaction transaction/*=NULL*/){  ASSERT (m_Type == Double);  const CdlValuable valuable = GetCdlValuable();  ASSERT (valuable);    if(transaction) {    if (CdlValueFlavor_BoolData == valuable->get_flavor ()) {      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (transaction, valuable->is_enabled (), dValue, CdlValueSource_User);    } else {// CdlValueFlavor_Data      valuable->set_double_value (transaction, dValue, CdlValueSource_User);    }  } else {    if (CdlValueFlavor_BoolData == valuable->get_flavor ()) {      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (valuable->is_enabled (), dValue, CdlValueSource_User);    } else {// CdlValueFlavor_Data      valuable->set_double_value (dValue, CdlValueSource_User);    }  }    return true;}CConfigItem *CConfigItem::FirstRadio() const{  ASSERT(HasRadio ());    for(CConfigItem *h=Parent()->FirstChild();h;h=h->NextSibling()){    if(h->HasRadio ()){      return h;    }  }  // No radio buttons found  ASSERT(false);  return false;}bool CConfigItem::IsEnabled() const{  const CdlValuable valuable = GetCdlValuable();  return NULL==valuable ||valuable->is_enabled();}bool CConfigItem::SetValue (ItemIntegerType nValue, CdlTransaction transaction/*=NULL*/){  ASSERT (m_Type == Integer);  const CdlValuable valuable = GetCdlValuable();  ASSERT (valuable);  if(transaction) {    if (CdlValueFlavor_BoolData == valuable->get_flavor ()) {      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (transaction, valuable->is_enabled (), (cdl_int) nValue, CdlValueSource_User);    } else { // CdlValueFlavor_Data      valuable->set_integer_value (transaction, nValue, CdlValueSource_User);    }  } else {    if (CdlValueFlavor_BoolData == valuable->get_flavor ()) {      // set the user bool to the current bool when changing a booldata      // value to avoid a possible change in the current bool      valuable->set_enabled_and_value (valuable->is_enabled (), (cdl_int) nValue, CdlValueSource_User);    } else { // CdlValueFlavor_Data      valuable->set_integer_value (nValue, CdlValueSource_User);    }  }    return true;}bool CConfigItem::HasModifiedChildren() const{  for(CConfigItem *pItem=FirstChild();pItem;pItem=pItem->NextSibling()){    if(pItem->Modified()||pItem->HasModifiedChildren()){      return true;    }  }  return false;}ItemIntegerType CConfigItem::Value () const{  ASSERT (!IsPackage()); // not a package item  const CdlValuable valuable = GetCdlValuable();  ASSERT (valuable);  ItemIntegerType nValue (0);    switch (valuable->get_flavor ())  {    //	case CdlValueFlavor_Bool:    //		nValue = valuable->is_enabled (CdlValueSource_Current) ? 1 : 0;    //		break;      case CdlValueFlavor_BoolData:  case CdlValueFlavor_Data:    nValue = (ItemIntegerType) valuable->get_integer_value (CdlValueSource_Current);    break;      default:    ASSERT (0); // specified flavor not supported  }    return nValue;}const double CConfigItem::DoubleValue (CdlValueSource source /* = CdlValueSource_Current */ ) const{  ASSERT (!IsPackage()); // not a package item  const CdlValuable valuable = GetCdlValuable();  ASSERT (valuable);  ASSERT (valuable->has_double_value (source));  return valuable->get_double_value (source);}ItemIntegerType CConfigItem::DefaultValue () const{  ItemIntegerType nValue;  return CUtils::StrToItemIntegerType (StringValue (CdlValueSource_Default), nValue) ? nValue : 0;}

⌨️ 快捷键说明

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