alnmulti_pane.cpp
来自「ncbi源码」· C++ 代码 · 共 885 行 · 第 1/2 页
CPP
885 行
/* * =========================================================================== * PRODUCTION $Log: alnmulti_pane.cpp,v $ * PRODUCTION Revision 1000.6 2004/06/01 21:07:09 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.42 * PRODUCTION * =========================================================================== *//* $Id: alnmulti_pane.cpp,v 1000.6 2004/06/01 21:07:09 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: Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <corelib/ncbitime.hpp>#include <gui/opengl/glutils.hpp>#include <gui/utils/command.hpp>#include <gui/widgets/aln_multiple/alnmulti_settings.hpp>#include <gui/widgets/aln_multiple/alnmulti_pane.hpp>#include <algorithm>#include <FL/Fl.H>BEGIN_NCBI_SCOPEstatic const int kRulerSpace = 4;static const int kMasterRowSpace = 4;CAlnMultiPane::CAlnMultiPane(int PosX, int PosY, int Width, int Height, const char* Label): CGlCanvas2d(PosX, PosY, Width, Height, Label), m_pParent(NULL), m_pModel(NULL), m_pCurrHandler(NULL), m_Renderer(TVPRect(0, 0, Width, Height)){ m_Tooltip.SetMode(CTooltip::eHideOnMove); m_HandlerPane.EnableOffset(); m_Renderer.SetBackColor(CGlColor(0.95f, 1.0f, 0.95f)); //setup Event Handlers m_MarkHandler.SetHost(static_cast<IAlignMarkHandlerHost*>(this)); x_AddHandler(dynamic_cast<IEventHandler*>(&m_MarkHandler), fAlignArea); m_SelHandler.SetHost(static_cast<ISelHandlerHost*>(this)); x_AddHandler(dynamic_cast<IEventHandler*>(&m_SelHandler), fAlignArea); m_MouseZoomHandler.SetHost(static_cast<IMouseZoomHandlerHost*>(this)); x_AddHandler(dynamic_cast<IEventHandler*>(&m_MouseZoomHandler), fAlignArea); x_AddHandler(dynamic_cast<IEventHandler*>(this), fDescrArea); m_Event.StandardConfig();}void CAlnMultiPane::SetWidget(IAlnMultiPaneParent* p_parent){ m_pParent = p_parent;}void CAlnMultiPane::SetContext(IAlnMultiRendererContext* p_context) { m_pContext = p_context; m_Renderer.SetContext(m_pContext); if(m_pContext) { m_HandlerPane = x_GetContext()->GetAlignPort(); }}void CAlnMultiPane::SetBackColor(const CGlColor Color){ m_Renderer.SetBackColor(Color);}CRuler& CAlnMultiPane::GetRuler(){ return m_Renderer.GetRuler();}CAlnMultiRenderer& CAlnMultiPane::GetRenderer(){ return m_Renderer;}void CAlnMultiPane::resize(int x, int y, int w, int h){ CGlCanvas2d::resize(x, y, w, h); m_Renderer.Resize(TVPRect(0, 0, w - 1, h - 1)); if(x_GetParent()) x_GetParent()->OnChildResize();}int CAlnMultiPane::handle(int event){ m_Event.OnFLTKEvent(event); int res = 0; switch(event) { case FL_FOCUS: case FL_UNFOCUS: redraw(); return 1; case FL_KEYDOWN: case FL_KEYUP: res = x_HandleKeyEvent(); break; case FL_MOVE: res = x_HandleMouseMove(); break; case FL_PUSH: res = x_HandleMousePush(); break; case FL_DRAG: res = x_HandleMouseDrag(); break; case FL_RELEASE: res = x_HandleMouseRelease(); break; case FL_MOUSEWHEEL: res = x_HandleMouseWheel(); break; case FL_ENTER: case FL_LEAVE: //fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); // drop to default default: res = CGlCanvas2d::handle(event); } m_Tooltip.Handle(event); return res;}int CAlnMultiPane::x_HandleKeyEvent(){ IEventHandler* pH = NULL; //dummy int res = x_Handlers_handle(fAllAreas, pH, false); if(res == 0 && m_Event.GetFLTKEvent() == FL_KEYDOWN) { switch(m_Event.GetGUISignal()) { case CGUIEvent::eZoomInSignal: x_SendCommand(eCmdZoomIn); break; case CGUIEvent::eZoomOutSignal: x_SendCommand(eCmdZoomOut); break; case CGUIEvent::eZoomAllSignal: x_SendCommand(eCmdZoomAll); break; default: break; } } return res;}void CAlnMultiPane::x_SendCommand(TCmdID cmd){ CCommandTarget* target = dynamic_cast<CCommandTarget*>(m_pParent); if(target) { target->OnCommand(cmd); }}int CAlnMultiPane::x_HandleMouseMove(){ int res = 0; IEventHandler* pH = NULL; //dummy EColumnType type = m_Renderer.GetColumnTypeByX(Fl::event_x()); switch(type) { case IAlignRow::eDescr: res = x_Handlers_handle(fDescrArea, pH, true); break; case IAlignRow::eAlignment: res = x_Handlers_handle(fAlignArea, pH); break; default: break; } if(res == 0) { fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); } x_UpdateTooltip(); m_pCurrHandler = NULL; return res;}int CAlnMultiPane::x_HandleMousePush(){ if(Fl::focus() != static_cast<Fl_Widget*>(this)) { take_focus(); m_Event.OnFLTKEvent(FL_PUSH); // restore event state after focus handling } int res = 0; if(m_Event.GetGUISignal() == CGUIEvent::ePopupSignal) { x_GetParent()->OnShowPopup(); res = 1; } else { IEventHandler* pH = NULL; //dummy EColumnType type = m_Renderer.GetColumnTypeByX(Fl::event_x()); switch(type) { case IAlignRow::eDescr: res = x_Handlers_handle(fDescrArea, pH, true); break; case IAlignRow::eIcons: res = x_Row_handle(); break; case IAlignRow::eAlignment: res = x_Handlers_handle(fAlignArea, pH); break; default: break; } m_pCurrHandler = pH; } if(res == 0) { fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); } return res;}int CAlnMultiPane::x_HandleMouseDrag(){ int res = 0; if(m_pCurrHandler) { res = m_pCurrHandler->handle(m_Event, m_HandlerPane); } if(res ==0) { fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); } return res;}int CAlnMultiPane::x_HandleMouseRelease(){ if(m_Event.GetGUISignal() == CGUIEvent::ePopupSignal) { x_GetParent()->OnShowPopup(); return 1; } else return x_HandleMouseDrag();}int CAlnMultiPane::x_HandleMouseWheel(){ IEventHandler* pH = NULL; //dummy int res = x_Handlers_handle(fAllAreas, pH, false); if(! res) { int d_y = Fl::event_dy(); x_GetParent()->OnScroll(0, (TModelUnit) d_y); } return res;}int CAlnMultiPane::x_Row_handle(){ int i_line = x_GetLineByWindowY(Fl::event_y()); if(i_line >= 0) { IAlignRow* p_row = x_GetContext()->GetRowByLine(i_line); _ASSERT(p_row); int i_col = m_Renderer.GetColumnIndexByX(Fl::event_x()); IAlignRow::EColumnType type = (IAlignRow::EColumnType) (int) m_Renderer.GetColumn(i_col).m_UserData; const CGlPane& VP = x_GetContext()->GetAlignPort(); int vp_top_y = m_Renderer.GetVPListTop() + (int) VP.GetVisibleRect().Top() - x_GetContext()->GetLinePosY(i_line); CGlPane pane(CGlPane::eNeverUpdate); pane.EnableOffset(); m_Renderer.SetupPaneForRow(pane, p_row, vp_top_y); m_Renderer.SetupPaneForColumn(pane, i_col); return p_row->handle(m_Event, type, pane); } return 0;}void CAlnMultiPane::x_UpdateTooltip(){ int x = Fl::event_x(); int y = Fl::event_y(); int vp_top = m_Renderer.GetRulerAreaHeight() + m_Renderer.GetMasterAreaHeight(); bool b_deactivate = true; IAlignRow* p_row = NULL; int row_top_y = 0; if(x_GetContext()->GetMasterRow() && y >= m_Renderer.GetRulerAreaHeight() + kMasterRowSpace && y < vp_top - kMasterRowSpace) { p_row = x_GetContext()->GetMasterRow(); row_top_y = m_Renderer.GetRulerAreaHeight() + kMasterRowSpace; } else if(y >= vp_top && y < h()) { // show tooltips only for rows int line = x_GetLineByWindowY(y); if(line >= 0) { p_row = x_GetContext()->GetRowByLine(line); row_top_y = x_GetContext()->GetLinePosY(line); } } if(p_row) { int i_col = m_Renderer.GetColumnIndexByX(x); if(i_col != -1) { const CGlPane& VP = x_GetContext()->GetAlignPort(); int vp_top_y = m_Renderer.GetVPListTop() + (int) VP.GetVisibleRect().Top() - row_top_y; string s_tip = x_GetRowTooltip(p_row, i_col, vp_top_y); if(s_tip.size()) { b_deactivate = false; m_Tooltip.Activate(this, s_tip, x, y); } } } if(b_deactivate) { m_Tooltip.Deactivate(true); } }string CAlnMultiPane::x_GetRowTooltip(IAlignRow* p_row, int i_col, int vp_top_y){ CGlPane pane; pane.EnableOffset(); m_Renderer.SetupPaneForRow(pane, p_row, vp_top_y); m_Renderer.SetupPaneForColumn(pane, i_col); EColumnType type = m_Renderer.GetColumnTypeByIndex(i_col); return p_row->GetTooltip(type, pane);}///////////////////////////////////////////////////////////////////////////////// Handlers managementvoid CAlnMultiPane::x_AddHandler(IEventHandler* handler, int area){ _ASSERT(handler && area); m_lsHandlers.push_back(make_pair(handler, area));}int CAlnMultiPane::x_Handlers_handle(int area, IEventHandler*& handler, bool ignore_curr){ int res = 0; IEventHandler* pFirst = ignore_curr ? NULL : m_pCurrHandler; if(pFirst) { handler = m_pCurrHandler; res = m_pCurrHandler->handle(m_Event, m_HandlerPane); } if(res == 0) { // not handles by pFirst - iterate through over handlers NON_CONST_ITERATE(THandlerList, it, m_lsHandlers) { handler = it->first; if( (it->second & area) && (handler != pFirst) ) { res = handler->handle(m_Event, m_HandlerPane); if(res) break; } } } if(res == 0) handler = NULL; return res;}void CAlnMultiPane::draw(){ Render(); }void CAlnMultiPane::Render(){ //_TRACE("\n\nCAlnMultiPane::Render()"); //CStopWatch sw; //sw.Start(); m_Renderer.SetFocused(Fl::focus() == this); //CAlnMultiRenderer::TAreaVector areas; //m_Renderer.Render(areas); m_Renderer.Render(); x_RenderSelection(); x_RenderMark(); x_RenderZoomHandler(); //_TRACE("\nEND CAlnMultiPane::Render() " << sw.Elapsed());}void CAlnMultiPane::Update() { //_TRACE("\n\nBEGIN CAlnMultiPane::Update() "); m_Renderer.Update(); if(x_GetParent()) x_GetParent()->OnChildResize(); //_TRACE("\nEND CAlnMultiPane::Update() ");}//void CAlnMultiPane::SetRulerHeight(int height){ m_Renderer.SetRulerHeight(height);}CRange<TSeqPos> CAlnMultiPane::GetSelectionLimits(){ return m_SelHandler.GetSelectionLimits();}const CAlnMultiPane::TRangeColl& CAlnMultiPane::GetSelection() const{ return m_SelHandler.GetSelection();}void CAlnMultiPane::SetSelection(const TRangeColl& C, bool bRedraw){ m_SelHandler.SetSelection(C, bRedraw);}void CAlnMultiPane::ResetSelection(bool bRedraw){ m_SelHandler.ResetSelection(bRedraw);}void CAlnMultiPane::MarkSelectedRows(const TRangeColl& C, bool bMark){ m_MarkHandler.MarkSelectedRows(C, bMark);}void CAlnMultiPane::UnMarkAll(){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?