📄 document.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: document.cpp,v $ * PRODUCTION Revision 1000.5 2004/06/01 20:44:03 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.48 * PRODUCTION * =========================================================================== *//* $Id: document.cpp,v 1000.5 2004/06/01 20:44:03 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: * CDocument -- the basic data unit for GBENCH */#include <ncbi_pch.hpp>#include <corelib/ncbicntr.hpp>#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/document.hpp>#include <gui/core/obj_convert.hpp>#include <gui/core/iview.hpp>#include <objects/seqset/Seq_entry.hpp>#include "doc_wkspace.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);// static counter for all documentsstatic CAtomicCounter s_DocIdCounter;// the steps for tiling new viewsstatic const int kTilingXStep = 25;static const int kTilingYStep = 25;// the default "top" positionsstatic const int kTopXPos = 25;static const int kTopYPos = 25;CDocument::CDocument() : m_LastX(kTopXPos), m_LastY(kTopYPos), m_DocId(s_DocIdCounter.Add(1)), m_AllViewsName("All Views"), m_MsgPosted(false){}CDocument::~CDocument(){}void CDocument::SetScope(CScope& scope){ CMutexGuard LOCK(m_Mutex); m_Scope.Reset(&scope);}// Show the workspace associated with this documentvoid CDocument::ShowWorkspace(void){ CMutexGuard LOCK(m_Mutex); NON_CONST_ITERATE (TViews, iter, m_Views) { (*iter)->Show(); }}// Hide the workspace associated with this documentvoid CDocument::HideWorkspace(void){ CMutexGuard LOCK(m_Mutex); NON_CONST_ITERATE (TViews, iter, m_Views) { (*iter)->Hide(); }}// internal function to retrieve a single message poolCDocument::TViewMsgPool* CDocument::x_GetMessagePool(const string& name, bool create){ if ( !m_MsgPoolMgr.get() ) { m_MsgPoolMgr.reset(new TViewMsgPoolMgr()); } TViewMsgPool* pool = m_MsgPoolMgr->FindPool(name); if ( !pool && create) { pool = m_MsgPoolMgr->CreatePool(name); } return pool;}CDocument::TViewMsgPool& CDocument::x_GetAllViewsPool(){ if ( !m_AllViewsPool ) { m_AllViewsPool.Reset(x_GetMessagePool(m_AllViewsName, true)); } return *m_AllViewsPool;}// internal message posting functionvoid CDocument::x_PostMessage(TViewMsgPool* pool, TUpdateFlags event, const void* data){ CMutexGuard LOCK(m_Mutex); if (m_MsgPosted) { // UpdateAllViews has been called from a message event // handler. This is not allowed. LOG_POST(Error << "CDocument::x_PostMessage(): invoked from " "a message event handler"); return; } m_MsgPosted = true; pool->PostMessage(event, data); m_MsgPosted = false;}//// function to update all of our views//void CDocument::UpdateAllViews(){ PostDocumentChanged();}void CDocument::PostDocumentChanged(const string& msg_pool){ TViewMsgPool* pool = x_GetMessagePool(msg_pool); if ( !pool ) { pool = &x_GetAllViewsPool(); } x_PostMessage(pool, fDocumentChanged, NULL);}// Force all views to update themselves to show a given visible rangevoid CDocument::PostVisibleRangeChanged(const CSeq_loc& loc, const string& msg_pool){ TViewMsgPool* pool = x_GetMessagePool(msg_pool); if ( !pool ) { pool = &x_GetAllViewsPool(); } x_PostMessage(pool, fVisibleRangeChanged, &loc);}// Force all views to update themselves to set a group of selectionsvoid CDocument::PostSelectionChanged(const CSelectionBuffer& buf, const string& msg_pool){ TViewMsgPool* pool = x_GetMessagePool(msg_pool); if ( !pool ) { pool = &x_GetAllViewsPool(); } x_PostMessage(pool, fSelectionChanged, &buf);}void CDocument::PostViewCreated(IView& view){ x_PostMessage(&x_GetAllViewsPool(), fViewCreated, &view);}void CDocument::PostViewReleased(IView& view){ x_PostMessage(&x_GetAllViewsPool(), fViewReleased, &view);}// Send event to a views group message poolvoid CDocument::PostGroupMessage(IView* view, TUpdateFlags event, const void* user_data){ TViewGroupPools::iterator iter = m_ViewGroupPools.find(view); if (iter == m_ViewGroupPools.end()) { LOG_POST(Error << "CDocument::PostGroupMessage: " "No group pool for the view"); return; } x_PostMessage(iter->second, event, user_data);}//// attach a view to the current documentvoid CDocument::AttachView(IView* view, const string& pool_name){ CMutexGuard LOCK(m_Mutex); m_Views.push_back(CRef<IView>(view)); // // make sure our new view comes up at a tiled position // int width; int height; view->GetSize(width, height); m_LastX += kTilingXStep; m_LastY += kTilingYStep; if (m_LastX > Fl::w() - width) { m_LastX = kTopXPos; } if (m_LastY > Fl::h() - height) { m_LastY = kTopYPos; } view->SetPosition(m_LastX, m_LastY); // // make sure the window is sized to appear wholly in the screen // bool resize = false; if (Fl::w() - m_LastX - width < 0) { width = Fl::w() - m_LastX; resize = true; } if (Fl::h() - m_LastY - height < 0) { height = Fl::h() - m_LastY; resize = true; } if (resize) { view->SetSize(width, height); } // Add view to "All Views" message pool x_GetAllViewsPool().Join(*view); // add to the named pool if ( !pool_name.empty() ) { CRef<TViewMsgPool> my_pool(x_GetMessagePool(pool_name, true)); my_pool->Join(*view); // Add view->msgpool map entry m_ViewGroupPools[view] = my_pool; } PostViewCreated(*view); CDocManager::UpdateAllViews(fViewCreated);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -