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

📄 dynamicpreferencesctrl.cpp

📁 linux下的电骡下载程序源码 包含emule协议的应用。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// This file is a part of the Dynamic Preferences Library.//// Copyright (c) 2004 Theodore R. Smith (hopeseekr@xmule.ws / http://www.xmule.ws/)// DSA-1024 Fingerprint: 10A0 6372 9092 85A2 BB7F 907B CB8B 654B E33B F1ED//// This file is dually licensed under the terms of the following licenses:// * Primary License: OSSAL - Open Source Software Alliance License//   * See the included License.OSSAL for complete details.//   * Key points://       5.Redistributions of source code in any non-textual form (i.e.//          binary or object form, etc.) must not be linked to software that is//          released with a license that requires disclosure of source code//          (ex: the GPL).//       6.Redistributions of source code must be licensed under more than one//          license and must not have the terms of the OSSAL removed.//// * Secondary License: Creative Commons Attribution-NoDerivs License v1.0//   * See the included License.CCANDL for complete details.//   * Key Points://       * You are free://           * to copy, distribute, display, and perform the work//           * to make non-commercial use of the work in its original form//       * Under the following conditions://           * Attribution.You must give the original author credit.//           * No Derivative Works.You may not alter, transform, or build upon//             this work.//// * Special exceptions://   I, Theodore R.Smith, hereby grant, as the sole author of this library,//   exclusive permission to the xMule Project to distribute and link to this//   library, specifically voiding clause 5 of the OSSAL for the xMule Project.//   As a further exclusive permission, when linked to the xMule Project,//   the terms of the GPL concerning binary distribution must be observed.//// For more information on legality, see README.txt.#include "DynPrefsCtrl.h"                   // Needed for Module's Prototype(s)#include "DynPrefs.h"                       // Needed for DynamicPreferences#include <iostream>                         // Needed for std::cout std::endl#include <list>                             // Needed for std::list#include <map>                              // Needed for std::map#include <utility>                          // Needed for std::pair#include <vector>                           // Needed for std::vector#include <wx/log.h>                         // Needed for wxLogDebug#if wxCHECK_VERSION(2, 5, 1)    #include <wx/xml/xml.h>                 // Needed for wxXmlNode#else    #include <wx/xrc/xml.h>                 // Needed for wxXmlNode#endif#include <wx/button.h>                      // Needed for wxButton#include <wx/checkbox.h>                    // Needed for wxCheckBox#include <wx/combobox.h>                    // Needed for wxComboBox#include <wx/dirdlg.h>                      // Needed for wxDirDialog#include <wx/filesys.h>                     // Needed for wxFileSystem#include <wx/intl.h>                        // Needed for _#include <wx/msgdlg.h>                      // Needed for wxMessageBox#include <wx/sizer.h>                       // Needed for wxBoxSizer#include <wx/slider.h>                      // Needed for wxSlider#include <wx/statline.h>                    // Needed for wxStaticLine#include <wx/stattext.h>                    // Needed for wxStaticText#include <wx/textctrl.h>                    // Needed for EVT_TEXT#include <wx/valtext.h>                     // Needed for wxFILTER_NUMERICusing std::cout;using std::endl;using std::list;static std::list< std::pair<const wxString, const short int > > controls;const wxEventType wxEVT_PREFS_CHANGED = wxNewEventType();short int E_BROWSE1 = 6660;short int E_BROWSE2 = 7770;// Begin private functionsnamespace{    void RegisterControl(const wxString& preference, const short int type);    inline wxString ControlName(const wxString& in);    wxString GetNodeText(wxXmlNode *node);    wxSize GetNodeSize(wxXmlNode* node);    void parse_xml(wxTreeMultiCtrl* parent, wxXmlNode* node, wxTreeMultiItem& current_item);};wxWindow* add_item(wxTreeMultiCtrl* parent, wxXmlNode* node, wxPanel* panel=NULL);// End private functionsBEGIN_EVENT_TABLE(DynamicPreferencesCtrl, wxTreeMultiCtrl)    EVT_PREFS_CHANGED(DynamicPreferencesCtrl::OnChangedPrefs)    EVT_CHECKBOX(-1, DynamicPreferencesCtrl::OnCheckBox)    EVT_TEXT(-1, DynamicPreferencesCtrl::OnTextChange)    EVT_ROOT_EXPANDED(-1, DynamicPreferencesCtrl::OnExpandNode)    EVT_COMBOBOX(-1, DynamicPreferencesCtrl::OnCombo)END_EVENT_TABLE()  class SmartSlider: public wxSlider{public:    SmartSlider(wxWindow* parent, wxWindowID id, int value, int minValue, int maxValue,         const wxPoint& point=wxDefaultPosition, const wxSize& size=wxDefaultSize,         long style=wxSL_HORIZONTAL, const wxValidator& validator=wxDefaultValidator,        const wxString& name=wxT("slider")):            wxSlider(parent, id, value, minValue, maxValue, point, size, style, validator, name)    {    }    virtual ~SmartSlider()    {    }    wxString m_string;};void DynamicPreferencesCtrl::OnExpandNode(const wxTreeMultiEvent& event){    wxTreeMultiItem current_item(event.GetItem());    if (GetChildrenCount(current_item) > 0)    {        return;    }        wxXmlNode* node = doc->GetRoot();    node = node->GetChildren();    do    {        if (node->GetName() == wxT("section"))        {            if (node->GetProperties()->GetValue() == event.GetLabel())            {                parse_xml(this, node->GetChildren(), current_item);                Expand(current_item, true);            }        }    }    while ((node = node->GetNext()) != NULL);    OnChangedPrefs(event);}void DynamicPreferencesCtrl::OnCheckBox(wxCommandEvent& event){    dynprefs->Add(ControlName(this->FindWindowById(event.GetId())->GetName()), event.IsChecked());}void DynamicPreferencesCtrl::OnTextChange(wxCommandEvent& event){    wxChar first_char = this->FindWindowById(event.GetId())->GetName().GetChar(0);    if (first_char == wxT('l'))    {        long number;        event.GetString().ToLong(&number);        dynprefs->Add(ControlName(this->FindWindowById(event.GetId())->GetName()), number);    }    else if (first_char == wxT('f'))    {        double number;        event.GetString().ToDouble(&number);        dynprefs->Add(ControlName(this->FindWindowById(event.GetId())->GetName()), number);    }    else    {        dynprefs->Add(ControlName(this->FindWindowById(event.GetId())->GetName()), event.GetString());    }}DynamicPreferencesCtrl::DynamicPreferencesCtrl(const wxString& filename, wxWindow* parent, DynamicPreferences* dp, wxWindowID id, const wxPoint& pos, const wxSize& size):    wxTreeMultiCtrl(parent, id, pos, size){    if (dp == NULL)    {        dynprefs = new DynamicPreferences();    }    else    {        dynprefs = dp;    }    this->SetSpacingY(0);    wxFileSystem fsys;    wxFSFile* f = fsys.OpenFile(filename);        doc = new wxXmlDocument(*f->GetStream());    wxXmlNode* node;    node = doc->GetRoot();    if ((node->GetProperties()->GetName() == wxT("version")) && (node->GetProperties()->GetValue() != wxT("2.0")))    {        wxMessageBox(wxT("This version of dynamic preferences is not supported."), wxT("Warning"), wxICON_WARNING);    }    node = node->GetChildren();    /* Get Sections */    wxTreeMultiItem current_item;    do    {        if (node->GetName() == wxT("section"))        {            wxString section_name(node->GetProperties()->GetValue());                        current_item = AddRoot(section_name);//            if (a == 0)//            {//                parse_xml(this, node->GetChildren(), current_item);//                ++a;//            }//            else//            {/* This method should *really* be done better. */            if (section_name == wxT("Advanced Settings"))            {                parse_xml(this, node->GetChildren(), current_item);            }            Collapse(current_item, false);//            }        }    }    while ((node = node->GetNext()) != NULL);    delete node;    }namespace{wxString GetNodeText(wxXmlNode* node){    wxXmlNode* tmp = node;    if (tmp == NULL)    {        return wxEmptyString;    }    tmp = tmp->GetChildren();    do    {        if (tmp->GetType() == wxXML_CDATA_SECTION_NODE || tmp->GetType() == wxXML_TEXT_NODE)        {            return tmp->GetContent();        }    } while ((tmp = tmp->GetNext()) != NULL);    return wxEmptyString;}void parse_xml(wxTreeMultiCtrl* parent, wxXmlNode* node, wxTreeMultiItem& current_item){    do    {        if (node->GetName() == wxT("item"))        {            parent->AppendWindow(current_item, add_item(parent, node));        }        else if (node->GetName() == wxT("multi"))        {            int orient = 0;            wxPanel* panel = new wxPanel(parent, -1);            wxBoxSizer* sizer;            wxBoxSizer* sizer_v1 = new wxBoxSizer(wxVERTICAL);            wxBoxSizer* sizer_v2 = new wxBoxSizer(wxVERTICAL);            wxBoxSizer* sizer_v3 = new wxBoxSizer(wxHORIZONTAL);            wxXmlNode* parent_node2 = node;            node = node->GetChildren();            if (node != NULL && node->GetName() == wxT("orient"))            {                if (GetNodeText(node) == wxT("1"))                {                    orient = 1;                    sizer = new wxBoxSizer(wxVERTICAL);                }                else                {                    sizer = new wxBoxSizer(wxHORIZONTAL);                }                node = node->GetNext();            }            else            {                sizer = new wxBoxSizer(wxHORIZONTAL);            }            if (node != NULL && node->GetName() == wxT("item"))            {                                sizer_v1->Add(add_item(parent, node, panel), 0, wxALIGN_BOTTOM | wxLEFT, 5);            }            while (node = node->GetNext())            {                if (node->GetName() == wxT("item"))

⌨️ 快捷键说明

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