📄 configitem.cpp
字号:
/* ---------------------------------------------------------------------------- * Copyright (C) 2004-2005 by egnite Software GmbH * * 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. * * ---------------------------------------------------------------------------- * Parts are * * Copyright (C) 1998, 1999, 2000 Red Hat, Inc. * * 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. * * ---------------------------------------------------------------------------- *//* * $Log: configitem.cpp,v $ * Revision 1.6 2005/11/24 09:44:30 haraldkipp * wxWidget failed to built with unicode support, which results in a number * of compile errors. Fixed by Torben Mikael Hansen. * * Revision 1.5 2005/04/22 15:08:10 haraldkipp * Avoid compiler warnings. * Upgraded to wxWidgets 2.5.5. * * Revision 1.4 2004/09/07 19:16:12 haraldkipp * Activate boolean items only * * Revision 1.3 2004/08/18 13:34:20 haraldkipp * Now working on Linux * * Revision 1.2 2004/08/03 15:03:24 haraldkipp * Another change of everything * * Revision 1.1 2004/06/07 16:13:15 haraldkipp * Complete redesign based on eCos' configtool * */#include "ids.h"#include "utils.h"#include "nutconf.h"#include "configtree.h"#include "configitem.h"#include "enumeditctrl.h"#include "inteditctrl.h"#include "texteditctrl.h"#ifdef __WXMSW__#define strcasecmp stricmp#endifIMPLEMENT_CLASS(CConfigItem, wxObject);/*! * \brief Default constructor. */CConfigItem::CConfigItem(){ m_compo = NULL; m_option = NULL; m_name = wxEmptyString; m_configType = nutConfigTypeNone; m_optionType = nutOptionTypeNone; m_parent = NULL; m_hint = nutHintNone; m_itemId = wxTreeItemId();}/*! * \brief Creates a CConfigItem from a given NUTCOMPONENT. */CConfigItem::CConfigItem(CConfigItem * parent, NUTCOMPONENT * compo){ m_compo = compo; m_option = NULL; m_name = wxString(compo->nc_name,wxConvLocal); if (compo->nc_child) { m_configType = nutLibrary; } else { m_configType = nutModule; } m_optionType = nutString; m_parent = parent; m_hint = nutHintNone; m_itemId = wxTreeItemId(); switch (m_optionType) { case nutString: case nutEnumerated: m_value = wxEmptyString; break; case nutInteger: m_value = (long) 0; break; case nutBool: m_value = false; break; }}/*! * \brief Creates a CConfigItem from a given NUTCOMPONENTOPTION. */CConfigItem::CConfigItem(CConfigItem * parent, NUTCOMPONENTOPTION * option){ m_compo = NULL; m_option = option; m_name = wxString(option->nco_name,wxConvLocal); m_configType = nutOption; m_optionType = nutString; m_parent = parent; m_hint = nutHintNone; m_itemId = wxTreeItemId(); switch (m_optionType) { case nutString: case nutEnumerated: m_value = wxEmptyString; break; case nutInteger: m_value = (long) 0; break; case nutBool: m_value = false; break; }}wxTreeItemId CConfigItem::GetTreeItem() const{ return m_itemId;}void CConfigItem::SetTreeItem(wxTreeItemId id){ m_itemId = id;}nutComponentType CConfigItem::GetConfigType() const{ return m_configType;}void CConfigItem::SetUIHint(nutUIHint hint){ m_hint = hint;}nutUIHint CConfigItem::GetUIHint() const{ return m_hint;}void CConfigItem::SetValue(const wxVariant & value){ m_value = value;}wxVariant & CConfigItem::GetValue(){ return m_value;}/*! * \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;}/*! * \brief Create a control to edit our value. * * This routine is called when the user clicks on an editable * item in the value window. */wxWindow *CConfigItem::CreateEditWindow(wxWindow * parent){ wxWindow *window = NULL; switch (GetOptionType()) { case nutEnumerated: /* Create drop down box for enumerated values. */ { window = new CEnumEditCtrl(parent, ID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize, 0); wxArrayString arEnumStrings; GetEnumStrings(arEnumStrings); for (unsigned int i = 0; i < arEnumStrings.GetCount(); i++) { ((CEnumEditCtrl *) window)->Append(arEnumStrings[i]); } } break; case nutInteger: /* Use a spin control for integer values. */ window = new CIntEditCtrl(parent, ID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS); break; case nutString: /* Normal entry control for string values. */ window = new CTextEditCtrl(parent, ID_ITEM_EDIT_WINDOW, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); break; } wxASSERT(window != NULL); return window;}/*! * \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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -