table_panel.cpp
来自「ncbi源码」· C++ 代码 · 共 608 行
CPP
608 行
/* * =========================================================================== * PRODUCTION $Log: table_panel.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 21:09:19 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//* $Id: table_panel.cpp,v 1000.2 2004/06/01 21:09:19 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: * CTablePanel -- Extends Fl_Table_Row to provide notions of hidden and * visible columns */#include <ncbi_pch.hpp>#include <gui/widgets/fl/table_panel.hpp>#include <FL/Fl.H>#include <FL/fl_draw.H>#include "colselect_dlg.hpp"BEGIN_NCBI_SCOPE//// default ctor//CTablePanelBase::CTablePanelBase(int x, int y, int w, int h, const char* label) : Fl_Table_Row(x, y, w, h, label), m_CellBox(FL_NO_BOX), m_RowHeaderBox(FL_THIN_UP_BOX), m_ColHeaderBox(FL_THIN_UP_BOX){ m_Handler.StandardConfig(); col_resize(RESIZE_COL_RIGHT); color(FL_BACKGROUND2_COLOR); selection_color(FL_BLUE);}bool CTablePanelBase::IsRowSelected(size_t row) const{ return const_cast<CTablePanelBase*>(this)->row_selected(row) ? true : false;}//// overloaded rows() handler//void CTablePanelBase::SetRows(size_t r){ Fl_Table_Row::rows(r); int orig_font = fl_font(); int orig_size = fl_size(); fl_font(labelfont(), labelsize()); row_height_all(fl_height() + fl_descent() + Fl::box_dh(GetCellBox()) + 2); fl_font(orig_font, orig_size);}size_t CTablePanelBase::GetRows() const{ return Fl_Table_Row::rows();}void CTablePanelBase::SetCols(size_t c){ Fl_Table_Row::cols(c);}size_t CTablePanelBase::GetCols() const{ return Fl_Table_Row::cols();}void CTablePanelBase::rows(int r){ SetRows(r);}int CTablePanelBase::rows() const{ return GetRows();}void CTablePanelBase::cols(int c){ SetCols(c);}int CTablePanelBase::cols() const{ return GetCols();}//// overloaded draw() - enforces clipping. Fl_Table_Row does not clip itself// properly and will overwrite neighboring widgets//void CTablePanelBase::draw(){ fl_push_clip(x(), y(), w(), h()); Fl_Table_Row::draw(); fl_pop_clip();}//// overloaded handle() - trap header clicks//int CTablePanelBase::handle(int event){ m_Handler.OnFLTKEvent(event); switch (event) { case FL_FOCUS: case FL_UNFOCUS: return 1; case FL_PUSH: Fl::focus(this); break; default: break; } switch (m_Handler.GetGUIState()) { case CGUIEvent::eSelectState: if (Fl::event_clicks() && m_Handler.GetGUISignal()== CGUIEvent::eRelease) { int row; int col; ResizeFlag resize_flag; switch (cursor2rowcol(row, col, resize_flag)) { case CONTEXT_ROW_HEADER: if (x_HandleRowHeaderClick(row)) { return 1; } break; case CONTEXT_COL_HEADER: if (x_HandleColHeaderClick(col)) { return 1; } break; case CONTEXT_CELL: if (x_HandleCellClick(row, col)) { return 1; } break; default: break; } } break; case CGUIEvent::eCopyState: if (x_OnCopy()) { return 1; } break; case CGUIEvent::eCutState: if (x_OnCut()) { return 1; } break; case CGUIEvent::ePasteState: if (x_OnPaste()) { return 1; } break; default: break; } return Fl_Table_Row::handle(event);}int CTablePanelBase::x_OnCopy(){ return 0;}int CTablePanelBase::x_OnCut(){ return 0;}int CTablePanelBase::x_OnPaste(){ return 0;}//// virtual event handlers for trapping cell/row clicks//int CTablePanelBase::x_HandleRowHeaderClick(size_t row){ return 0;}int CTablePanelBase::x_HandleColHeaderClick(size_t col){ return 0;}int CTablePanelBase::x_HandleCellClick(size_t row, size_t col){ return 0;}//// access cell box types//void CTablePanelBase::SetCellBox(CFltkUtils::EBoxType box){ m_CellBox = static_cast<Fl_Boxtype>(static_cast<int>(box));}void CTablePanelBase::SetCellBox(Fl_Boxtype box){ m_CellBox = box;}Fl_Boxtype CTablePanelBase::GetCellBox(void) const{ return m_CellBox;}void CTablePanelBase::SetRowHeaderBox(Fl_Boxtype box){ m_RowHeaderBox = box;}void CTablePanelBase::SetRowHeaderBox(CFltkUtils::EBoxType box){ m_RowHeaderBox = static_cast<Fl_Boxtype>(static_cast<int>(box));}Fl_Boxtype CTablePanelBase::GetRowHeaderBox(void) const{ return m_RowHeaderBox;}void CTablePanelBase::SetColHeaderBox(Fl_Boxtype box){ m_ColHeaderBox = box;}void CTablePanelBase::SetColHeaderBox(CFltkUtils::EBoxType box){ m_ColHeaderBox = static_cast<Fl_Boxtype>(static_cast<int>(box));}Fl_Boxtype CTablePanelBase::GetColHeaderBox(void) const{ return m_ColHeaderBox;}void CTablePanelBase::SetHeaderBox(Fl_Boxtype box){ SetRowHeaderBox(box); SetColHeaderBox(box);}void CTablePanelBase::SetHeaderBox(CFltkUtils::EBoxType box){ SetRowHeaderBox(box); SetColHeaderBox(box);}#if 0//// x_SetNumColumns()// internal function to adjust the number of (actual) columns//void CTablePanel::x_SetNumColumns(int cols){ m_ColInfo.resize(cols);}//// SetColType()// set the type of data represented in the column. This determines how the// column is sorted.//void CTablePanel::SetColType(int col, EColumnType type){ if (int (m_ColInfo.size()) <= col) { x_SetNumColumns(col + 1); } m_ColInfo[col].m_Type = type;}//// GetColType()// Return the type of data used in a given column// CTablePanel::EColumnType CTablePanel::GetColType(int col) const{ return m_ColInfo[col].m_Type;}//// SetRelWidth()// Set the relative width of a given column. The relative width only// makes sense in the context of the sum of the relative widths of all the// other visible columns.//void CTablePanel::SetRelWidth(int col, float width){ if (int (m_ColInfo.size()) <= col) { x_SetNumColumns(col + 1); } m_ColInfo[col].m_Width = width;}//// GetRelWidth()// Returns the relative width of a given column. The number returned only// makes sense in the context of the sum of the relative widths of all the// other visible columns.//float CTablePanel::GetRelWidth(int col) const{ return m_ColInfo[col].m_Width;}//// SetColAlign()// set the default alignment for a given column//void CTablePanel::SetColAlign(int col, Fl_Align align){ if (int (m_ColInfo.size()) <= col) { x_SetNumColumns(col + 1); } m_ColInfo[col].m_Align = align;}//// GetColAlign()// Return the current slignment setting for a given column//Fl_Align CTablePanel::GetColAlign(int col) const{ return m_ColInfo[col].m_Align;}//// SetColumn()// This function sets all column properties; internally, it just calls other// functions to set individual properties on the selected column.//void CTablePanel::SetColumn(int col, const string& header, EColumnType type, Fl_Align align, float rel_width){ SetColHeader(col, header); SetColType (col, type); SetColAlign (col, align); SetRelWidth (col, rel_width);}// set the virtual column for a given indexvoid CTablePanel::SetVirtualCol(int visible_col, int actual_col){ if (int (m_VirtCols.size()) <= visible_col) { m_VirtCols.resize(visible_col + 1, -1); } m_VirtCols[visible_col] = actual_col;}//// resize()// overloaded from Fl_Widget; handles resize events for the widget as a whole//void CTablePanel::resize(int x, int y, int wid, int ht){ // determine the ratio of expansion / contraction of our columns int orig_width = w(); float ratio = float (wid) / float (orig_width); // call the base class Fl_Table_Row::resize(x, y, wid, ht); // now, fit our columns to maintain their width, if need be int total_width = 0; int i; for ( i = 0; i < cols(); ++i) { total_width += col_width(i); } total_width = int (total_width * ratio); for (i = 0; i < cols() - 1; ++i) { col_width(i, int (col_width(i) * ratio)); total_width -= col_width(i); } col_width(cols() - 1, total_width);}//// x_SetupColumns()// Internal function to correctly set column widths and alignments. This is// intended to be called any time the column setup changes - i.e., any time the// user selects a different set of visible columns.//void CTablePanel::x_SetupColumns(){ cols(m_VirtCols.size()); float sum = 0; ITERATE(vector<int>, iter, m_VirtCols) { sum += GetRelWidth(*iter); } float widget_width = w() - 1; float total_rel_width = 0.0f; ITERATE(vector<int>, iter, m_VirtCols) { int actual_col = *iter; float prev_rel_width = total_rel_width; total_rel_width += GetRelWidth(actual_col); int prev_width = int (widget_width * prev_rel_width / sum); int total_width = int (widget_width * total_rel_width / sum); int width = total_width - prev_width; // actually set our width // we take this opportunity to set the column style as well int idx = iter - m_VirtCols.begin(); col_width(idx, width); }}//// ShowColSelectDlg()// This handles the business of showing a dialog box that allows selection of// an arbitrary number of visible columns//void CTablePanel::ShowColSelectDlg(){ if ( !m_SelectDlg.get() ) { m_SelectDlg.reset(new CColumnSelectDlg()); } // this is brute-force and potentially slow for a large number of columns m_SelectDlg->Clear(); ITERATE (TColInfo, col_iter, m_ColInfo) { int idx = col_iter - m_ColInfo.begin(); bool checked = (std::find(m_VirtCols.begin(), m_VirtCols.end(), idx) != m_VirtCols.end()); m_SelectDlg->AddColumn(col_iter->m_Header, idx, checked); } if (m_SelectDlg->Show() == eOK) { m_VirtCols = m_SelectDlg->GetSelected(); x_SetupColumns(); redraw(); }}#endifEND_NCBI_SCOPE/* * =========================================================================== * $Log: table_panel.cpp,v $ * Revision 1000.2 2004/06/01 21:09:19 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * * Revision 1.7 2004/05/28 15:09:49 dicuccio * Added finctions to set box styles using CFltkUtils::EBoxType * * Revision 1.6 2004/05/21 22:27:53 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5 2004/04/16 14:49:40 dicuccio * Set background and selection color to defaults in ctor. Added IsRowSelected() * * Revision 1.4 2004/03/11 17:52:15 dicuccio * Implemented virtual columns. Fixed double-click detection for sort * * Revision 1.3 2004/03/05 17:39:39 dicuccio * Added handling of standard cut/copy/paste events * * Revision 1.2 2004/01/20 18:20:52 dicuccio * Added handle() - report click events to virtual overrides. Introduced new * virtual APIs to trap calls to non-virtual rows()/cols() * * Revision 1.1 2003/12/09 15:51:51 dicuccio * Deprecated Fl_Toggle_Tree - replaced with Flu_Tree_Browser. Added CTreeBrowser * as a standard tree interface * * Revision 1.12 2003/12/04 18:15:57 dicuccio * Changed row height to take descent into account * * Revision 1.11 2003/09/24 18:35:49 dicuccio * Reinstated implementation file with new table panel base class * * Revision 1.10 2003/07/28 11:51:51 dicuccio * Rewrote CTablePanel<> to be more flexible and better contained. Added standard * multicolumn list dialog. Deprecated use of COutputDlg. * * Revision 1.9 2003/07/25 13:39:11 dicuccio * Replaced Flv_Table with the cleaner Fl_Table. * * Revision 1.8 2003/03/11 15:27:11 kuznets * iterate -> ITERATE * * Revision 1.7 2003/02/25 14:48:35 dicuccio * Added smart resizing of multicolumn list widgets * * Revision 1.6 2003/01/13 13:10:14 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/10 18:21:51 dicuccio * Added comments for each function * * Revision 1.4 2003/01/10 17:39:28 dicuccio * Remove setting of table selection color - handle this in fluid instead * * Revision 1.3 2003/01/08 15:05:44 dicuccio * Added column selection dialog to base class. Store type parameter with each * column - permits sorting absed on type (string vs. numeric) * * Revision 1.2 2003/01/03 17:37:02 dicuccio * Added accessors for various items in a virtual table. Added more consistent * and easier way to configure columns * * Revision 1.1 2002/12/30 18:42:21 dicuccio * Initial revision. * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?