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

📄 configtree.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//####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####// configtree.cpp :////===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   julians// Contact(s):  julians// Date:        2000/08/24// Version:     $Id: configtree.cpp,v 1.8 2001/04/24 14:39:13 julians Exp $// Purpose:// Description: Implementation file for ecConfigTreeCtrl// Requires:// Provides:// See also:// Known bugs:// Usage:////####DESCRIPTIONEND####////===========================================================================// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifdef __GNUG__#pragma implementation "configtree.h"#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__#pragma hdrstop#endif#include "wx/cshelp.h"// Include XPM icons#if !defined(__WXMSW__)#include "bitmaps/closedfolder.xpm"#include "bitmaps/closedfolder_dis.xpm"#include "bitmaps/package_closed.xpm"#include "bitmaps/package_closed_dis.xpm"#include "bitmaps/package_open.xpm"#include "bitmaps/package_open_dis.xpm"#include "bitmaps/checked.xpm"#include "bitmaps/checked_dis.xpm"#include "bitmaps/unchecked.xpm"#include "bitmaps/unchecked_dis.xpm"#include "bitmaps/integer.xpm"#include "bitmaps/integer_dis.xpm"#include "bitmaps/integer2.xpm"#include "bitmaps/integer2_dis.xpm"#include "bitmaps/enumerated.xpm"#include "bitmaps/enumerated_dis.xpm"#include "bitmaps/radioon.xpm"#include "bitmaps/radioon_dis.xpm"#include "bitmaps/radiooff.xpm"#include "bitmaps/radiooff_dis.xpm"#include "bitmaps/text.xpm"#include "bitmaps/text_dis.xpm"#endif#include "configtree.h"#include "configpropdlg.h"#include "configtooldoc.h"#include "configtoolview.h"/* * ecConfigTreeCtrl */IMPLEMENT_CLASS(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)BEGIN_EVENT_TABLE(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)    EVT_PAINT(ecConfigTreeCtrl::OnPaint)    EVT_MOUSE_EVENTS(ecConfigTreeCtrl::OnMouseEvent)    EVT_CHAR(ecConfigTreeCtrl::OnKeyDown)    EVT_TREE_SEL_CHANGED(-1, ecConfigTreeCtrl::OnSelChanged)    EVT_TREE_ITEM_EXPANDED(-1, ecConfigTreeCtrl::OnCollapseExpand)    EVT_TREE_ITEM_COLLAPSED(-1, ecConfigTreeCtrl::OnCollapseExpand)    EVT_HELP(-1, ecConfigTreeCtrl::OnHelp)END_EVENT_TABLE()ecConfigTreeCtrl::ecConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,                                   const wxSize& sz, long style):wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style){    LoadIcons();        m_propertiesMenu = new wxMenu;        m_propertiesMenu->Append(ecID_WHATS_THIS, _("&What's This?"));    m_propertiesMenu->AppendSeparator();    m_propertiesMenu->Append(ecID_TREE_PROPERTIES, _("P&roperties"));    m_propertiesMenu->Append(ecID_TREE_RESTORE_DEFAULTS, _("Restore &Defaults"));    m_propertiesMenu->Append(ecID_TREE_VISIT_DOC, _("Visit Documentation"));    m_propertiesMenu->Append(ecID_TREE_VIEW_HEADER, _("View Header"));    m_propertiesMenu->AppendSeparator();    m_propertiesMenu->Append(ecID_TREE_UNLOAD_PACKAGE, _("&Unload Package..."));    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")).Ok())    {        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")));    }}// Load the icons and initialize the treevoid ecConfigTreeCtrl::LoadIcons(){    m_imageList = new wxImageList(16, 16, TRUE);    m_iconDB.SetImageList(m_imageList);    SetImageList(m_imageList);        // We associate names and states so we can easily get the appropriate    // icon for a given tree item. This gets used in ecConfigItem::UpdateTreeIcon.        m_iconDB.AddInfo("Container", wxICON(closedfolder), 0, TRUE);    m_iconDB.AddInfo("Container", wxICON(closedfolder_dis), 0, FALSE);        m_iconDB.AddInfo("Package", wxICON(package_open), 0, TRUE);    m_iconDB.AddInfo("Package", wxICON(package_open_dis), 0, FALSE);        m_iconDB.AddInfo("Checkbox", wxICON(checked), 0, TRUE);    m_iconDB.AddInfo("Checkbox", wxICON(checked_dis), 0, FALSE);    m_iconDB.AddInfo("Checkbox", wxICON(unchecked), 1, TRUE);    m_iconDB.AddInfo("Checkbox", wxICON(unchecked_dis), 1, FALSE);        m_iconDB.AddInfo("Radiobox", wxICON(radioon), 0, TRUE);    m_iconDB.AddInfo("Radiobox", wxICON(radioon_dis), 0, FALSE);    m_iconDB.AddInfo("Radiobox", wxICON(radiooff), 1, TRUE);    m_iconDB.AddInfo("Radiobox", wxICON(radiooff_dis), 1, FALSE);        m_iconDB.AddInfo("Text", wxICON(text), 0, TRUE);    m_iconDB.AddInfo("Text", wxICON(text_dis), 0, FALSE);        m_iconDB.AddInfo("Enumerated", wxICON(enumerated), 0, TRUE);    m_iconDB.AddInfo("Enumerated", wxICON(enumerated_dis), 0, FALSE);        m_iconDB.AddInfo("Integer", wxICON(integer), 0, TRUE);    m_iconDB.AddInfo("Integer", wxICON(integer_dis), 0, FALSE);    #if 0    // Add some dummy items    ecConfigItem* item = NULL;    wxTreeItemId rootId = AddRoot(_(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(NULL, _("Configuration"), ecContainer)));        item->SetTreeItem(rootId);    item->UpdateTreeItem(* this);        wxTreeItemId childId1 = AppendItem(rootId, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("My Package"), ecPackage, ecFlavorData, ecString)));    item->SetTreeItem(childId1);    item->GetValue() = _("v1_4_1");    item->UpdateTreeItem(* this);        wxTreeItemId childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 1"), ecOption, ecFlavorData, ecString)));    item->SetTreeItem(childId2);    item->GetValue() = _("The value for this option");    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 2"), ecOption, ecFlavorData, ecLong)));    item->SetTreeItem(childId2);    item->GetValue() = (long) 176343;    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId2, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 3"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, TRUE, ecHintCheck)));    item->SetTreeItem(childId2);    item->GetValue() = (bool) TRUE;    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 4"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, FALSE, ecHintCheck)));    item->SetTreeItem(childId2);    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 5"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, TRUE, ecHintRadio)));    item->SetTreeItem(childId2);    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 6"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, FALSE, ecHintRadio)));    item->SetTreeItem(childId2);    item->GetValue() = (bool) TRUE ;    item->UpdateTreeItem(* this);        // Another branch    childId1 = AppendItem(rootId, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("My Container"), ecContainer)));    item->SetTreeItem(childId1);    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 1"), ecOption, ecFlavorData, ecString, FALSE)));    item->SetTreeItem(childId2);    item->GetValue() = _("The value for this option");    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 2"), ecOption, ecFlavorData, ecLong, FALSE)));    item->SetTreeItem(childId2);    item->GetValue() = (long) 176343;    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 3"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, TRUE, ecHintCheck)));    item->SetTreeItem(childId2);    item->GetValue() = (bool) TRUE;    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 4"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, FALSE, ecHintCheck)));    item->SetTreeItem(childId2);    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 5"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, TRUE, ecHintRadio)));    item->SetTreeItem(childId2);    item->UpdateTreeItem(* this);        childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 6"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, FALSE, ecHintRadio)));    item->SetTreeItem(childId2);    item->GetValue() = (bool) TRUE ;    item->UpdateTreeItem(* this);        Expand(rootId);#endif}ecConfigTreeCtrl::~ecConfigTreeCtrl(){    delete m_propertiesMenu;        SetImageList(NULL);    delete m_imageList;}// Draw the lines on top of the treevoid ecConfigTreeCtrl::OnPaint(wxPaintEvent& event){    wxPaintDC dc(this);        wxTreeCtrl::OnPaint(event);        // Reset the device origin since it may have been set    dc.SetDeviceOrigin(0, 0);        wxSize sz = GetClientSize();        wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);    dc.SetPen(pen);    dc.SetBrush(* wxTRANSPARENT_BRUSH);        wxSize clientSize = GetClientSize();    wxRect itemRect;    int cy=0;    wxTreeItemId h, lastH;    for(h=GetFirstVisibleItem();h;h=GetNextVisible(h))    {        if (GetBoundingRect(h, itemRect))        {            cy = itemRect.GetTop();            dc.DrawLine(0, cy, clientSize.x, cy);            lastH = h;        }    }        if (lastH && lastH.IsOk() && GetBoundingRect(lastH, itemRect))    {        cy = itemRect.GetBottom();        dc.DrawLine(0, cy, clientSize.x, cy);    }}void ecConfigTreeCtrl::OnSelChanged(wxTreeEvent& event){    ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();    if (doc)    {        ecConfigToolHint hint(NULL, ecSelChanged);        doc->UpdateAllViews(NULL, & hint);    }}void ecConfigTreeCtrl::OnMouseEvent(wxMouseEvent& event){    int flags = 0;    wxTreeItemId item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);        if (item == 0 || !item.IsOk())    {        if (event.RightDown())            PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());        return;    }        if (event.LeftDown())    {        if (flags & wxTREE_HITTEST_ONITEMICON)        {            ecTreeItemData* data = (ecTreeItemData*) GetItemData(item);            data->GetConfigItem()->OnIconLeftDown(* this);        }    }    else if (event.RightDown())    {        if ((flags & wxTREE_HITTEST_ONITEMBUTTON) ||            (flags & wxTREE_HITTEST_ONITEMICON) ||            (flags & wxTREE_HITTEST_ONITEMINDENT) ||            (flags & wxTREE_HITTEST_ONITEMLABEL))        {            SelectItem(item);            GetPropertiesMenu()->SetClientData((void*) TRUE);            PopupMenu(GetPropertiesMenu(), event.GetX(), event.GetY());        }        else        {            wxGetApp().GetWhatsThisMenu()->SetClientData((void*) FALSE);            PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());        }        return;    }    event.Skip();}void ecConfigTreeCtrl::OnKeyDown(wxKeyEvent& event){    wxTreeItemId id = GetSelection();    if (event.GetKeyCode() == WXK_F10 && event.ShiftDown())    {        if (id.IsOk())        {

⌨️ 快捷键说明

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