erritem_view.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: erritem_view.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:03:14 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: erritem_view.cpp,v 1000.1 2004/06/01 21:03:14 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: Mati Shomrat
- *
- * File Description:
- * Main graphical view class for the validator
- *
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbistd.hpp>
- #include <corelib/ncbistr.hpp>
- #include <objtools/validator/validator.hpp>
- #include <FL/Fl.H>
- #include <FL/Fl_Text_Display.H>
- #include <FL/Fl_Text_Buffer.H>
- #include "erritem_view.hpp"
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects::validator);
- const string CValidErrItemView::sm_Prefix = " "; // 10 spaces
- const string CValidErrItemView::sm_NewLine = "n";
-
- CValidErrItemView::CValidErrItemView
- (const CValidErrItem& item,
- int W,
- EMessage message) :
- Fl_Text_Display(0, 0, W, 0, 0),
- m_Item(&item),
- m_Message(message),
- m_Selected(false)
- {
- box(FL_NO_BOX);
- scrollbar_width(0);
- textfont(FL_COURIER);
- Fl_Text_Buffer* buf = new Fl_Text_Buffer;
- buf->text(CreateTextString(W).c_str());
- buffer(buf);
- size( W, Height() );
- end();
- }
- CValidErrItemView::~CValidErrItemView(void)
- {
- }
- void CValidErrItemView::Select(void)
- {
- m_Selected = true;
- color (FL_SELECTION_COLOR);
- textcolor(FL_WHITE);
- redraw();
- }
- void CValidErrItemView::DeSelect(void)
- {
- m_Selected = false;
- color(FL_WHITE);
- textcolor(FL_FOREGROUND_COLOR);
- redraw();
- }
- void CValidErrItemView::DoubleClick(void)
- {
- }
- int CValidErrItemView::handle (int event)
- {
- switch (event) {
- case FL_PUSH:
- if ( Fl::event_clicks() ) {
- Select();
- DoubleClick ();
- } else if ( !m_Selected ) {
- Select();
- } else {
- DeSelect();
- }
-
- return 1;
- default:
- return Fl_Text_Display::handle(event);
- }
- }
- void CValidErrItemView::resize(int X, int Y, int W, int H)
- {
- if ( W != w() ) {
- buffer()->text(CreateTextString(W).c_str());
- }
- Fl_Text_Display::resize(X, Y, W, Height());
- }
- // private
- string CValidErrItemView::CreateTextString(int W)
- {
- if ( W < 0 ) {
- W = w();
- }
- // Create the message
- string sev = m_Item->GetSevAsStr();
- sev.resize(10, ' ');
- NStr::ToUpper(sev);
- string msg = m_Item->GetErrCode();
- msg += sm_NewLine;
- msg += m_Item->GetMsg();
- msg += sm_NewLine;
- if ( m_Message == eMessage_Verbose ) {
- msg += sm_NewLine;
- msg += m_Item->GetVerbose();
- msg += sm_NewLine;
- }
- // Wrap it to fit the window size
- list<string> arr;
- double font_width = textsize() * 0.64;
- SIZE_TYPE width = static_cast<SIZE_TYPE>(W / font_width);
- NStr::Wrap(msg, width, arr, 0, sm_Prefix, sev);
-
- return NStr::Join(arr, "n");
- }
- void CValidErrItemView::SetMessage(EMessage new_message)
- {
- if ( m_Message != new_message ) {
- m_Message = new_message;
- buffer()->text(CreateTextString(w()).c_str());
- resize(x(), y(), w(), Height());
- }
- }
- int CValidErrItemView::Height(void)
- {
- SIZE_TYPE lines = buffer()->count_lines(0, buffer()->length() - 1) + 1;
- return lines * textsize() + 10;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: erritem_view.cpp,v $
- * Revision 1000.1 2004/06/01 21:03:14 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/21 22:27:50 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.3 2003/06/02 16:06:24 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.2 2003/04/22 16:25:51 shomrat
- * Fl -> FL
- *
- * Revision 1.1 2003/04/18 19:56:37 shomrat
- * Initial revision
- *
- *
- * ===========================================================================
- */