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

📄 cdd_book_ref_dialog.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: cdd_book_ref_dialog.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 18:27:57  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//*  $Id: cdd_book_ref_dialog.cpp,v 1000.2 2004/06/01 18:27:57 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Authors:  Paul Thiessen** File Description:*       dialog for editing CDD book references** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018)   // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <objects/cdd/Cdd_descr.hpp>#include <objects/cdd/Cdd_book_ref.hpp>#include "cdd_book_ref_dialog.hpp"#include "structure_set.hpp"#include "cn3d_tools.hpp"#include <wx/clipbrd.h>#include <wx/tokenzr.h>////////////////////////////////////////////////////////////////////////////////////////////////// The following is taken unmodified from wxDesigner's C++ header from cdd_book_ref_dialog.wdr////////////////////////////////////////////////////////////////////////////////////////////////#include <wx/image.h>#include <wx/statline.h>#include <wx/spinbutt.h>#include <wx/spinctrl.h>#include <wx/splitter.h>#include <wx/listctrl.h>#include <wx/treectrl.h>#include <wx/notebook.h>#include <wx/grid.h>// Declare window functions#define ID_LISTBOX 10000#define ID_B_UP 10001#define ID_B_LAUNCH 10002#define ID_B_NEW 10003#define ID_B_SAVE 10004#define ID_B_DOWN 10005#define ID_B_EDIT 10006#define ID_B_PASTE 10007#define ID_B_DELETE 10008#define ID_LINE 10009#define ID_TEXT 10010#define ID_T_NAME 10011#define ID_C_TYPE 10012#define ID_T_ADDRESS 10013#define ID_T_SUBADDRESS 10014#define ID_B_DONE 10015wxSizer *SetupBookRefDialog( wxWindow *parent, bool call_fit = TRUE, bool set_sizer = TRUE );////////////////////////////////////////////////////////////////////////////////////////////////USING_NCBI_SCOPE;USING_SCOPE(objects);BEGIN_SCOPE(Cn3D)#define DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(var, id, type) \    type *var; \    var = wxDynamicCast(FindWindow(id), type); \    if (!var) { \        ERRORMSG("Can't find window with id " << id); \        return; \    }BEGIN_EVENT_TABLE(CDDBookRefDialog, wxDialog)    EVT_CLOSE       (       CDDBookRefDialog::OnCloseWindow)    EVT_BUTTON      (-1,    CDDBookRefDialog::OnClick)    EVT_LISTBOX     (-1,    CDDBookRefDialog::OnClick)END_EVENT_TABLE()static TypeStringAssociator < CCdd_book_ref::ETextelement > enum2str;CDDBookRefDialog::CDDBookRefDialog(StructureSet *structureSet, CDDBookRefDialog **handle,    wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos) :        wxDialog(parent, id, title, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),        sSet(structureSet), dialogHandle(handle), selectedItem(-1), editOn(false){    if (enum2str.Size() == 0) {        enum2str.Associate(CCdd_book_ref::eTextelement_unassigned, "unassigned");        enum2str.Associate(CCdd_book_ref::eTextelement_section, "section");        enum2str.Associate(CCdd_book_ref::eTextelement_figgrp, "figgrp");        enum2str.Associate(CCdd_book_ref::eTextelement_table, "table");        enum2str.Associate(CCdd_book_ref::eTextelement_chapter, "chapter");        enum2str.Associate(CCdd_book_ref::eTextelement_biblist, "biblist");        enum2str.Associate(CCdd_book_ref::eTextelement_box, "box");        enum2str.Associate(CCdd_book_ref::eTextelement_glossary, "glossary");        enum2str.Associate(CCdd_book_ref::eTextelement_appendix, "appendix");        enum2str.Associate(CCdd_book_ref::eTextelement_other, "other");    }    if (!structureSet || !(descrSet = structureSet->GetCDDDescrSet())) {        ERRORMSG("CDDBookRefDialog::CDDBookRefDialog() - error getting descr set data");        Destroy();        return;    }    // construct the dialog    wxSizer *topSizer = SetupBookRefDialog(this, false);    // fill in list box with available references    SetWidgetStates();    // call sizer stuff    topSizer->Fit(this);    topSizer->SetSizeHints(this);}CDDBookRefDialog::~CDDBookRefDialog(void){    // so owner knows that this dialog has been destroyed    if (dialogHandle && *dialogHandle) *dialogHandle = NULL;    TRACEMSG("CDD book references dialog destroyed");}// same as hitting donevoid CDDBookRefDialog::OnCloseWindow(wxCloseEvent& event){    // see what user wants to do about unsaved edit    if (editOn) {        int option = wxYES_NO | wxYES_DEFAULT | wxICON_EXCLAMATION | wxCENTRE;        if (event.CanVeto()) option |= wxCANCEL;        wxMessageDialog dialog(NULL, "Do you want to save your edited item?", "", option);        option = dialog.ShowModal();        if (option == wxID_CANCEL) {            event.Veto();            return;        }        if (option == wxID_YES) {            wxCommandEvent fake(wxEVT_COMMAND_BUTTON_CLICKED, ID_B_SAVE);            OnClick(fake);        }    }    Destroy();}static wxString MakeRID(const CCdd_book_ref& bref){    wxString uid;    if (bref.IsSetSubelementid())        uid.Printf("%s.%s.%i#%i",            bref.GetBookname().c_str(), enum2str.Find(bref.GetTextelement())->c_str(),            bref.GetElementid(), bref.GetSubelementid());    else        uid.Printf("%s.%s.%i",            bref.GetBookname().c_str(), enum2str.Find(bref.GetTextelement())->c_str(), bref.GetElementid());    return uid;}void CDDBookRefDialog::SetWidgetStates(void){    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(listbox, ID_LISTBOX, wxListBox)    listbox->Clear();    // set items in listbox    CCdd_descr_set::Tdata::iterator d, de = descrSet->Set().end();    for (d=descrSet->Set().begin(); d!=de; ++d) {        if ((*d)->IsBook_ref()) {            // make client data of menu item a pointer to the CRef containing the CCdd_descr object            listbox->Append(MakeRID((*d)->GetBook_ref()), &(*d));        }    }    if (selectedItem < 0 && listbox->GetCount() > 0)        selectedItem = 0;    // set info fields    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tName, ID_T_NAME, wxTextCtrl)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(cType, ID_C_TYPE, wxChoice)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tAddress, ID_T_ADDRESS, wxTextCtrl)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tSubaddress, ID_T_SUBADDRESS, wxTextCtrl)    if (selectedItem >= 0 && selectedItem < listbox->GetCount()) {        listbox->SetSelection(selectedItem, true);        const CCdd_book_ref& bref =            (*(reinterpret_cast<CRef<CCdd_descr>*>(listbox->GetClientData(selectedItem))))->GetBook_ref();        tName->SetValue(bref.GetBookname().c_str());        cType->SetStringSelection(enum2str.Find(bref.GetTextelement())->c_str());        wxString s;        s.Printf("%i", bref.GetElementid());        tAddress->SetValue(s);        if (bref.IsSetSubelementid())            s.Printf("%i", bref.GetSubelementid());        else            s.Clear();        tSubaddress->SetValue(s);    } else {        tName->Clear();        cType->SetSelection(0);        tAddress->Clear();        tSubaddress->Clear();        // special case for new but as yet unsaved item, always last item        if (editOn && selectedItem == listbox->GetCount()) {            listbox->Append(wxString("(new item - hit 'Save' when finished)"), (void *) NULL);            listbox->SetSelection(selectedItem, true);        }    }    // set widget states    listbox->Enable(!editOn);    tName->Enable(editOn);    cType->Enable(editOn);    tAddress->Enable(editOn);    tSubaddress->Enable(editOn);    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bUp, ID_B_UP, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bDown, ID_B_DOWN, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bEdit, ID_B_EDIT, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bSave, ID_B_SAVE, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bNew, ID_B_NEW, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bDelete, ID_B_DELETE, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bLaunch, ID_B_LAUNCH, wxButton)    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bPaste, ID_B_PASTE, wxButton)    bool readOnly;    RegistryGetBoolean(REG_ADVANCED_SECTION, REG_CDD_ANNOT_READONLY, &readOnly);    bUp->Enable(!readOnly && !editOn && selectedItem > 0);    bDown->Enable(!readOnly && !editOn && selectedItem < listbox->GetCount() - 1);    bEdit->Enable(!readOnly && !editOn && selectedItem >= 0 && selectedItem < listbox->GetCount());    bSave->Enable(!readOnly && editOn);    bNew->Enable(!readOnly && !editOn);    bDelete->Enable(!readOnly && selectedItem >= 0 && selectedItem < listbox->GetCount());    bLaunch->Enable(!editOn);    bPaste->Enable(!readOnly && !editOn);}void CDDBookRefDialog::OnClick(wxCommandEvent& event){    DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(listbox, ID_LISTBOX, wxListBox)    CRef < CCdd_descr > *selDescr = reinterpret_cast<CRef<CCdd_descr>*>(listbox->GetClientData(selectedItem));    if (event.GetId() == ID_B_DONE) {

⌨️ 快捷键说明

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