⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table_panel.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 4 页
字号:
        SetRows(row + 1);    }    return x_SetData().SetCell(row, col);}template <class RowData>inlineconst string& CTablePanel<RowData>::GetCell(size_t row, size_t col) const{    return x_GetData().GetCell(row, col);}template <class RowData>inlinestring& CTablePanel<RowData>::SetRowHeader(size_t row){    return x_SetData().SetRowHeader(row);}template <class RowData>inlinevoid CTablePanel<RowData>::SetRowHeader(size_t row, const string& str){    x_SetData().SetRowHeader(row) = str;}template <class RowData>inlineconst string& CTablePanel<RowData>::GetRowHeader(size_t row) const{    return x_GetData().GetRowHeader(row);}//// overloaded resize().  Here, we force the columns to size correctly.//template <class RowData>inlinevoid CTablePanel<RowData>::resize(int x, int y, int w, int h){    float total_width = 0;    ITERATE (vector<size_t>, iter, m_VirtCols) {        const SColInfo& info = m_ColInfo[*iter];        total_width += info.width;    }    Fl_Table_Row::resize(x, y, w, h);    if (w > total_width) {        int idx = 0;        NON_CONST_ITERATE (vector<size_t>, iter, m_VirtCols) {            SColInfo& info = m_ColInfo[*iter];            info.width *= w / total_width;            col_width(idx++, (int)info.width);        }    }}template <class RowData>inlineint CTablePanel<RowData>::x_HandleColHeaderClick(size_t col){    if (Fl::event_clicks() != 0) {        NON_CONST_ITERATE (typename TColInfo, iter, m_ColInfo) {            string::size_type pos = iter->header.find_last_of("@");            if (pos != string::npos  &&  pos > 0) {                iter->header.erase(pos - 1);            }        }        SColInfo& col_info = m_ColInfo[col];        // double click - sort by column        switch (col_info.sort_state) {        case eNotSorted:        case eDescending:            {{                 col_info.sort_state = eAscending;                 col_info.header += " @-28UpArrow";             }}            break;        case eAscending:            {{                 col_info.sort_state = eDescending;                 col_info.header += " @-22UpArrow";             }}            break;        }        SortByCol(col, col_info.sort_state);        redraw();        return 1;    }    return CTablePanelBase::x_HandleColHeaderClick(col);}template <class RowData>inline Fl_ColorCTablePanel<RowData>::x_GetRowForegroundColor(size_t row){    return labelcolor();}template <class RowData>inline Fl_ColorCTablePanel<RowData>::x_GetRowBackgroundColor(size_t row){    return FL_BACKGROUND2_COLOR;}//// sort by a given column//template <class RowData>inlinevoid CTablePanel<RowData>::SortByCol(size_t col, ESortState sort_order){    _ASSERT(col < GetCols());    x_SetData().SortByCol(col,                          (sort_order == eAscending),                          (m_ColInfo[col].type == eNumeric));}//// SetColType()// set the type of data represented in the column.  This determines how the// column is sorted.//template <class RowData>inlinevoid CTablePanel<RowData>::SetColType(size_t col, EColumnType type){    if (col >= GetCols()) {        SetCols(col + 1);    }    m_ColInfo[col].type = type;}//// GetColType()// Return the type of data used in a given column// template <class RowData>inline typename CTablePanel<RowData>::EColumnTypeCTablePanel<RowData>::GetColType(size_t col) const{    _ASSERT(col < GetCols());    return m_ColInfo[col].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.//template <class RowData>inlinevoid CTablePanel<RowData>::SetRelWidth(size_t col, float width_frac){    if (col >= GetCols()) {        SetCols(col + 1);    }    m_ColInfo[col].width_frac = width_frac;}//// 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.//template <class RowData>inlinefloat CTablePanel<RowData>::GetRelWidth(size_t col) const{    _ASSERT(col < GetCols());    return m_ColInfo[col].width_frac;}//// SetWidth()// Set the actual width in pixels for a given columntemplate <class RowData>inlinevoid CTablePanel<RowData>::SetWidth(size_t col, float width){    if (col >= GetCols()) {        SetCols(col + 1);    }    m_ColInfo[col].width = width;    ITERATE (vector<size_t>, iter, m_VirtCols) {        if (*iter == col) {            col_width(iter - m_VirtCols.begin(), (int)width);        }    }}//// GetWidth()// 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.//template <class RowData>inlinefloat CTablePanel<RowData>::GetWidth(size_t col) const{    _ASSERT(col < GetCols());    return m_ColInfo[col].width;}//// SetColAlign()// set the default alignment for a given column//template <class RowData>inlinevoid CTablePanel<RowData>::SetColAlign(size_t col, Fl_Align align){    if (col >= GetCols()) {        SetCols(col + 1);    }    m_ColInfo[col].align = align;}//// GetColAlign()// Return the current slignment setting for a given column//template <class RowData>inlineFl_Align CTablePanel<RowData>::GetColAlign(size_t col) const{    _ASSERT(col < GetCols());    return m_ColInfo[col].align;}//// SetColumn()// This function sets all column properties; internally, it just calls other// functions to set individual properties on the selected column.//template <class RowData>inlinevoid CTablePanel<RowData>::SetColumn(size_t 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);    // always add a new column    SetVirtualCol(m_VirtCols.size(), col);    SetupColumns();}//// SetVirtualCol()//template <class RowData>inline voidCTablePanel<RowData>::ClearVirtualCols(){    m_VirtCols.clear();    CTablePanelBase::SetCols(0);}//// SetVirtualCol()//template <class RowData>inline voidCTablePanel<RowData>::SetVirtualCol(int virt_col, int actual_col){    m_VirtCols.push_back(actual_col);    // call our base class's resize    CTablePanelBase::SetCols(m_VirtCols.size());}//// 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.//template <class RowData>inlinevoid CTablePanel<RowData>::SetupColumns(){    float sum = 0;    ITERATE (vector<size_t>, iter, m_VirtCols) {        const SColInfo& info = m_ColInfo[ *iter];        sum += info.width_frac;    }    float widget_width = (float)(w() - 1);    int idx = 0;    float total_rel_width = 0.0f;    NON_CONST_ITERATE (vector<size_t>, iter, m_VirtCols) {        SColInfo& info = m_ColInfo[ *iter];        float prev_rel_width = total_rel_width;        total_rel_width += info.width_frac;        float prev_width  = (widget_width * prev_rel_width / sum);        float total_width = (widget_width * total_rel_width / sum);        info.width = total_width - prev_width;        // actually set our width        // we take this opportunity to set the column style as well        col_width(idx++, (int)info.width);    }}//// access a column header//template <class RowData>inlinevoid CTablePanel<RowData>::SetColHeader(size_t col, const string& str){    if (col >= GetCols()) {        SetCols(col + 1);    }    m_ColInfo[col].header = str;}template <class RowData>inlineconst string& CTablePanel<RowData>::GetColHeader(size_t col) const{    _ASSERT(col < GetCols());    return m_ColInfo[col].header;}//// Fl_Table_Row overload: draw_cell()// This actually does the work of drawing our data//template <class Data>inlinevoid CTablePanel<Data>::draw_cell(TableContext ctx,                                  int row, int col,                                  int x, int y, int w, int h){    // flip for our virtual columns    if (m_VirtCols.size()) {        col = m_VirtCols[col];    }    switch (ctx) {    case CONTEXT_STARTPAGE:		fl_font(labelfont(), labelsize());        break;    case CONTEXT_ROW_HEADER:        fl_push_clip(x, y, w, h);        {{            fl_draw_box(m_RowHeaderBox, x, y, w, h, row_header_color());            if ((size_t)row < GetRows()) {                fl_color(labelcolor());                fl_draw(GetRowHeader(row).c_str(),                        x, y, w, h, FL_ALIGN_CENTER);            }         }}        fl_pop_clip();        break;    case CONTEXT_COL_HEADER:        fl_push_clip(x, y, w, h);        {{            fl_draw_box(m_ColHeaderBox, x, y, w, h, col_header_color());            if ((size_t)col < GetCols()) {                fl_color(labelcolor());                fl_draw(GetColHeader(col).c_str(),                        x, y, w, h, FL_ALIGN_CENTER);            }         }}        fl_pop_clip();        break;    case CONTEXT_CELL:        fl_push_clip(x, y, w, h);        {{		    // BG COLOR            if (row_selected(row)) {		        fl_color(selection_color());            } else {                fl_color(x_GetRowBackgroundColor(row));            }		    fl_rectf(x, y, w, h);		    // TEXT            if ((size_t)row < GetRows()  && (size_t)col < GetCols()) {                if (row_selected(row)) {                    fl_color(FL_YELLOW);                } else {                    fl_color(x_GetRowForegroundColor(row));                }                const char *p = GetCell(row, col).c_str();                fl_draw(p,                        x + Fl::box_dx(m_CellBox),                        y + Fl::box_dy(m_CellBox),                        w - Fl::box_dw(m_CellBox),                        h - Fl::box_dh(m_CellBox),                        GetColAlign(col));            }            // BORDER            fl_draw_box(m_CellBox, x, y, w, h, FL_LIGHT2);        }}        fl_pop_clip();        break;    case CONTEXT_ENDPAGE:        fl_push_clip(this->x(), this->y(), this->w(), this->h());        {{            fl_draw_box(box(),                        this->x(), this->y(), this->w(), this->h(),                        color());        }}        fl_pop_clip();        break;    default:        break;    }}#if 0//// stock data comparators - one to dereference, and one to compare by value//template <class Data>struct SCompareByPtr {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -