wm_splitter.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: wm_splitter.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:14:51 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: wm_splitter.cpp,v 1000.1 2004/06/01 21:14:51 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 <gui/widgets/workspace/wm_splitter.hpp>
- #include <gui/widgets/fl/menu_window.hpp>
- BEGIN_NCBI_SCOPE
- ///////////////////////////////////////////////////////////////////////////////
- /// IWMPosition
- CWMSplitterPos::CWMSplitterPos()
- : m_Row(-1),
- m_Column(-1) // invaid position
- {
- }
- CWMSplitterPos::CWMSplitterPos(int row, int col)
- : m_Row(row), m_Column(col)
- {
- }
- CWMSplitterPos::~CWMSplitterPos()
- {
- }
- bool CWMSplitterPos::IsValid() const
- {
- return m_Row >=0 && m_Column >= 0;
- }
- IWMPosition* CWMSplitterPos::Clone() const
- {
- return new CWMSplitterPos(m_Row, m_Column);
- }
- int CWMSplitterPos::GetRow() const
- {
- return m_Row;
- }
- int CWMSplitterPos::GetColumn() const
- {
- return m_Column;
- }
- void CWMSplitterPos::Set(int column, int row)
- {
- m_Column = column;
- m_Row = row;
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// CWMSplitter
- CWMSplitter::CWMSplitter()
- : CSplitter(0, 0, 0, 0),
- m_pManager(NULL)
- {
- }
- CWMSplitter::CWMSplitter(int x, int y, int w, int h, const char* label)
- : CSplitter(x, y, w, h, label),
- m_pManager(NULL)
- {
- }
- CWMSplitter::~CWMSplitter()
- {
- }
- BEGIN_CMD_MAP(CWMSplitter, CCommandTarget)
- ON_COMMAND(eCmdDistributeEvenly, &CWMSplitter::OnDistributeEvenly)
- END_CMD_MAP()
- void CWMSplitter::SetManager(IWindowManager* manager)
- {
- m_pManager = manager;
- }
- bool CWMSplitter::IsVacant(const IWMPosition& pos)
- {
- const CWMSplitterPos* p_pos = dynamic_cast<const CWMSplitterPos*>(&pos);
- if(p_pos) {
- int i_x = p_pos->GetColumn();
- int i_y = p_pos->GetRow();
- if(IsValidCell(i_x, i_y)) {
- Fl_Widget* w = x_GetCell(i_x, i_y);
- return x_GetCell(i_x, i_y) == NULL;
- }
- }
- return false;
- }
- Fl_Widget* CWMSplitter::GetChild(const IWMPosition& pos)
- {
- const CWMSplitterPos* p_pos = dynamic_cast<const CWMSplitterPos*>(&pos);
- if(p_pos) {
- if(p_pos->IsValid()) {
- return x_GetCell(p_pos->GetColumn(), p_pos->GetRow());
- }
- }
- return NULL;
- }
- void CWMSplitter::GetChildren(vector<TChild*>& children)
- {
- children.clear();
- for( int i = 0; i < (int) m_vCells.size(); i++ ) {
- Fl_Widget* child = m_vCells[i];
- if(child) {
- children.push_back(child);
- }
- }
- }
- bool CWMSplitter::Insert(Fl_Widget* widget, const IWMPosition& pos)
- {
- const CWMSplitterPos* p_pos = dynamic_cast<const CWMSplitterPos*>(&pos);
- if(widget && p_pos) {
- if(p_pos->IsValid() && IsVacant(pos)) {
- return InsertToCell(widget, p_pos->GetColumn(), p_pos->GetRow());
- }
- }
- return false;
- }
- bool CWMSplitter::Remove(const IWMPosition& pos)
- {
- const CWMSplitterPos* p_pos = dynamic_cast<const CWMSplitterPos*>(&pos);
- if(p_pos && p_pos->IsValid()) {
- Fl_Widget* w = RemoveFromCell(p_pos->GetColumn(), p_pos->GetRow());
- return w != NULL;
- }
- return false;
- }
- bool CWMSplitter::Remove(TChild* child)
- {
- return CSplitter::Remove(child);
- }
- void CWMSplitter::RemoveAll()
- {
- CSplitter::RemoveAll();
- }
- void CWMSplitter::x_OnShowPopupMenu()
- {
- int i_cell_x, i_cell_y, i_sep_x, i_sep_y;
- x_HitTest(Fl::event_x() - x(), m_vSplitPosX, i_cell_x, i_sep_x);
- x_HitTest(Fl::event_y() - y(), m_vSplitPosY, i_cell_y, i_sep_y);
- CMenuItem* root = new CMenuItem("Root");
-
- m_PopupPos.Set(i_cell_x, i_cell_y);
- if(i_cell_x != -1 && i_cell_y != -1) { // hit the cell
- if(m_pManager) {
- vector<CMenuItem*> items;
- m_pManager->GetPopupItems(this, m_PopupPos, items);
- ITERATE(vector<CMenuItem*>, it, items) {
- root->AddSubItem(*it);
- }
- }
- } else {
- root->AddSubItem("Distribute Evenly (Dbl Click)", eCmdDistributeEvenly);
- }
- CPopupMenu1 menu(Fl::event_x_root(), Fl::event_y_root(), root, this);
- menu.Popup();
- }
- void CWMSplitter::OnDistributeEvenly()
- {
- x_DistributeEvenly(true, true);
- }
- bool CWMSplitter::OnCommand(const TCmdID cmd)
- {
- bool b_handled = CCommandTarget::OnCommand(cmd);
- if(! b_handled && m_pManager) {
- b_handled = m_pManager->OnContainerCommand(this, m_PopupPos, cmd);
- }
- return b_handled;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: wm_splitter.cpp,v $
- * Revision 1000.1 2004/06/01 21:14:51 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:56 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/05/07 14:27:25 yazhuk
- * Replaced CPopupMenu with CPopupMenu1
- *
- * Revision 1.1 2004/02/04 19:41:42 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */