records_table.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:10k
- /*
- * ===========================================================================
- * PRODUCTION $Log: records_table.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 20:48:47 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.23
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: records_table.cpp,v 1000.2 2004/06/01 20:48:47 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: Mike DiCuccio
- *
- * File Description:
- * CGBenchApp -- main application class for GBENCH
- */
- #include <ncbi_pch.hpp>
- #include "records_table.hpp"
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/utils/fltk_utils.hpp>
- #include <objects/seq/Seq_hist.hpp>
- #include <objects/seq/Seq_inst.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <FL/fl_draw.H>
- BEGIN_NCBI_SCOPE
- //
- // requirement for the tabe: sort by underlying data structure
- //
- bool operator< (const IDocument& doc0, const IDocument& doc1)
- {
- return (&doc0 < &doc1);
- }
- //
- // default ctor
- //
- CRecordsTable::CRecordsTable(int x, int y, int w, int h, const char* label)
- : CTablePanel<IDocument*>(x, y, w, h, label)
- {
- //
- // set up the actual columns for our internal data
- //
- SetColumn(eBriefTitle, "Brief", eString, FL_ALIGN_LEFT, 1.0f);
- SetColumn(eTitle, "Title", eString, FL_ALIGN_LEFT, 4.0f);
- SetColumn(eViews, "Views", eString, FL_ALIGN_RIGHT, 1.0f);
- //SetColumn(eOrganism, "Organism", eString, FL_ALIGN_LEFT, 0.1f);
- /**
- // set the default virtual columns
- // this defines the order in which all the columns appear
- m_VirtCols.push_back(eBriefTitle);
- m_VirtCols.push_back(eTitle);
- m_VirtCols.push_back(eViews);
- **/
- Update(fAllEvents);
- }
- //
- // dtor
- //
- CRecordsTable::~CRecordsTable()
- {
- }
- //
- // Update()
- // Here we fill our internal data structures with information from the document
- // manager.
- //
- void CRecordsTable::Update(TUpdateFlags flags)
- {
- if ( (flags & fDocumentChanged) || (flags & fDocumentCreated) ||
- (flags & fDocumentReleased) ) {
- int row = 0;
- NON_CONST_ITERATE(CDocManager::TDocList, iter,
- CDocManager::GetDocuments()) {
- IDocument* doc = *iter;
- if ( !doc ) {
- return;
- }
- SetCell(row, eTitle, doc->GetTitle());
- SetCell(row, eBriefTitle, doc->GetShortTitle());
- SetCell(row, eViews, NStr::IntToString(doc->GetViews().size()));
- SetData(row, doc);
- ++row;
- }
- /**
- m_Data.clear();
- NON_CONST_ITERATE(CDocManager::TDocList, iter,
- CDocManager::GetDocuments()) {
- IDocument* doc = *iter;
- if ( !doc ) {
- return;
- }
- TColumns cols(eMaxCols);
- cols[eTitle ] = doc->GetTitle();
- cols[eBriefTitle] = doc->GetShortTitle();
- cols[eViews ] = NStr::IntToString(doc->GetViews().size());
- TRow row;
- row.m_Data = doc;
- row.m_Columns = cols;
- m_Data.push_back(row);
- }
- // make sure that the added document appears in sorted order!
- int sort_idx = -1;
- ITERATE (TColInfo, col_iter, m_ColInfo) {
- if (col_iter->m_SortState != eNotSorted) {
- sort_idx = col_iter - m_ColInfo.begin();
- break;
- }
- }
- if (sort_idx != -1) {
- if (m_ColInfo[sort_idx].m_SortState == eAscending) {
- m_ColInfo[sort_idx].m_SortState = eDescending;
- } else {
- m_ColInfo[sort_idx].m_SortState = eAscending;
- }
- SortByCol(sort_idx);
- }
- **/
- }
- if ( flags & fViewCreated ) {
- for (size_t i = 0; i < GetRows(); ++i) {
- SetCell(i, eViews,
- NStr::IntToString(GetData(i)->GetViews().size()));
- }
- }
- // finalize the view
- redraw();
- }
- //
- // handle()
- // generic FLTK event handler
- //
- int CRecordsTable::handle(int event)
- {
- switch (event)
- {
- case FL_PUSH:
- {{
- CFltkEvent::EEvent ev = CFltkEvent::GetProcessedEvent();
- // we ignore events bound to our internal popup state
- // this removes an artifact with selection mode - it protects our
- // selections when we popup our context menu
- if (ev == CFltkEvent::ePopupState) {
- break;
- }
- int ev_y = Fl::event_y();
- int widget_y = y();
- int hdr_ht = col_header_height();
- if (ev_y >= y() && ev_y <= y() + col_header_height() &&
- ev == CFltkEvent::eMultiSelectState) {
- //ShowColSelectDlg();
- return 1;
- }
- }}
- break;
- default:
- break;
- };
- return CTablePanel<IDocument*>::handle(event);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: records_table.cpp,v $
- * Revision 1000.2 2004/06/01 20:48:47 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.23
- *
- * Revision 1.23 2004/05/21 22:27:42 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.22 2004/05/07 15:34:37 dicuccio
- * Fixed unsigned/signed comparison
- *
- * Revision 1.21 2004/01/20 18:15:52 dicuccio
- * Changed to match new API in CTablePanel
- *
- * Revision 1.20 2003/12/04 18:12:55 dicuccio
- * Changed to match API change in CTablePanel
- *
- * Revision 1.19 2003/09/29 15:43:01 dicuccio
- * Deprecated gui/scope.hpp. Merged gui/core/types.hpp into gui/types.hpp
- *
- * Revision 1.18 2003/09/04 14:02:36 dicuccio
- * Introduce IDocument as abstract base class for CDocument; replace use of
- * CDocument with IDocument
- *
- * Revision 1.17 2003/08/06 13:24:31 dicuccio
- * Deprecated old main window; introduced new, compact window for multiple
- * document management
- *
- * Revision 1.16 2003/07/28 11:51:47 dicuccio
- * Rewrote CTablePanel<> to be more flexible and better contained. Added standard
- * multicolumn list dialog. Deprecated use of COutputDlg.
- *
- * Revision 1.15 2003/07/25 13:43:40 dicuccio
- * Replaced Flv_Table with Fl_Table
- *
- * Revision 1.14 2003/06/02 16:06:19 dicuccio
- * Rearranged src/objects/ subtree. This includes the following shifts:
- * - src/objects/asn2asn --> arc/app/asn2asn
- * - src/objects/testmedline --> src/objects/ncbimime/test
- * - src/objects/objmgr --> src/objmgr
- * - src/objects/util --> src/objmgr/util
- * - src/objects/alnmgr --> src/objtools/alnmgr
- * - src/objects/flat --> src/objtools/flat
- * - src/objects/validator --> src/objtools/validator
- * - src/objects/cddalignview --> src/objtools/cddalignview
- * In addition, libseq now includes six of the objects/seq... libs, and libmmdb
- * replaces the three libmmdb? libs.
- *
- * Revision 1.13 2003/04/24 16:36:49 dicuccio
- * Removed unnecessary / unavailable columns from display. Updated to reflect
- * changes in IDocument API
- *
- * Revision 1.12 2003/03/21 17:02:17 dicuccio
- * Moved fltk_utils.hpp --> gui/utils. Added link against libgui_utils
- *
- * Revision 1.11 2003/03/11 15:18:57 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.10 2003/02/28 20:42:29 lebedev
- * Popup bug fixed
- *
- * Revision 1.9 2003/02/26 14:30:15 dicuccio
- * Fixed thinko in handling of mouse clicks and pop-up events - was preventing
- * selecting multiple documents and using the pop-up menu with these multiple
- * documents
- *
- * Revision 1.8 2003/02/05 19:57:34 dicuccio
- * Make sure that records added to the table don't upset the sort order for the table
- *
- * Revision 1.7 2003/01/15 21:12:49 dicuccio
- * Added update flags - allows partial updates, for example, when a view is created
- *
- * Revision 1.6 2003/01/13 13:10:10 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.5 2003/01/08 15:02:26 dicuccio
- * Moved column selection dialog into base class. Added ability to sort columns
- * based on column type (string vs. numeric)
- *
- * Revision 1.4 2003/01/03 17:29:06 dicuccio
- * Added ability to select columns for viewing and sorting
- *
- * Revision 1.3 2002/12/30 20:51:43 dicuccio
- * Tweak to avoid compiler warnings in Windows
- *
- * Revision 1.2 2002/12/30 18:51:53 dicuccio
- * Updated to support new table widget base class. Updated to add new tabular
- * views.
- *
- * Revision 1.1 2002/12/23 16:40:13 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */