fl_table.cpp
来自「ncbi源码」· C++ 代码 · 共 994 行 · 第 1/3 页
CPP
994 行
/* * =========================================================================== * PRODUCTION $Log: Fl_Table.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:06:18 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//* * This is a third-party file, and is maintained and copyrighted as below. * Please see LICENSE at the root of the NCBI C++ toolkit for details on its * redistribution * * =========================================================================== * $Log: Fl_Table.cpp,v $ * Revision 1000.1 2004/06/01 21:06:18 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4 2004/05/21 22:27:51 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3 2003/09/24 18:29:57 dicuccio * Rearranged #include statements to avoid compiler warning on MSVC * * Revision 1.2 2003/08/01 19:02:21 dicuccio * Retabified / reindented. Changed calling of callback in Fl_Table::handle() - * was called only if the release happened in the same row as the initial push, * which prevenets a callback on click-drag-release for selection * * Revision 1.1 2003/07/25 13:37:45 dicuccio * Initial revision * * =========================================================================== *///// Fl_Table -- A table widget//// Copyright 2002 by Greg Ercolano.//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA.//// Please report all bugs and problems to "erco at seriss dot com".//#include <ncbi_pch.hpp>#include <gui/widgets/Fl_Table/Fl_Table.H>#include <stdio.h> // fprintf#include <FL/fl_draw.H>#define SCROLLBAR_SIZE 16// Scroll display so 'row' is at topvoid Fl_Table::row_position(int row){ if ( _row_position == row ) return; // OPTIMIZATION: no change? avoid redraw if ( row < 0 ) row = 0; else if ( row >= rows() ) row = rows() - 1; if ( table_h <= tih ) return; // don't scroll if table smaller than window double newtop = row_scroll_position(row); if ( newtop > vscrollbar->maximum() ) { newtop = vscrollbar->maximum(); } vscrollbar->Fl_Slider::value(newtop); table_scrolled(); redraw(); _row_position = row; // HACK: override what table_scrolled() came up with}// Scroll display so 'col' is at leftvoid Fl_Table::col_position(int col){ if ( _col_position == col ) return; // OPTIMIZATION: no change? avoid redraw if ( col < 0 ) col = 0; else if ( col >= cols() ) col = cols() - 1; if ( table_w <= tiw ) return; // don't scroll if table smaller than window double newleft = col_scroll_position(col); if ( newleft > hscrollbar->maximum() ) { newleft = hscrollbar->maximum(); } hscrollbar->Fl_Slider::value(newleft); table_scrolled(); redraw(); _col_position = col; // HACK: override what table_scrolled() came up with}// Find scroll position of a row (in pixels)long Fl_Table::row_scroll_position(int row){ int startrow = 0; long scroll = 0; // OPTIMIZATION: // Attempt to use precomputed row scroll position if ( toprow_scrollpos != -1 && row >= toprow ) { scroll = toprow_scrollpos; startrow = toprow; } for ( int t=startrow; t<row; t++ ) scroll += row_height(t); return(scroll);}// Find scroll position of a column (in pixels)long Fl_Table::col_scroll_position(int col){ int startcol = 0; long scroll = 0; // OPTIMIZATION: // Attempt to use precomputed row scroll position if ( leftcol_scrollpos != -1 && col >= leftcol ) { scroll = leftcol_scrollpos; startcol = leftcol; } for ( int t=startcol; t<col; t++ ) scroll += col_width(t); return(scroll);}// CtorFl_Table::Fl_Table(int X, int Y, int W, int H, const char *l) : Fl_Group(X,Y,W,H,l){ _rows = 0; _cols = 0; _row_header_w = 40; _col_header_h = 18; _row_header = 0; _col_header = 0; _row_header_color = color(); _col_header_color = color(); _row_resize = 0; _col_resize = 0; _row_resize_min = 1; _col_resize_min = 1; _redraw_toprow = -1; _redraw_botrow = -1; _redraw_leftcol = -1; _redraw_rightcol = -1; table_w = 0; table_h = 0; toprow = 0; botrow = 0; leftcol = 0; rightcol = 0; toprow_scrollpos = -1; leftcol_scrollpos = -1; _last_cursor = FL_CURSOR_DEFAULT; _resizing_col = -1; _resizing_row = -1; _dragging_x = -1; _dragging_y = -1; _last_row = -1; box(FL_THIN_DOWN_FRAME); vscrollbar = new Fl_Scrollbar(x()+w()-SCROLLBAR_SIZE, y(), SCROLLBAR_SIZE, h()-SCROLLBAR_SIZE); vscrollbar->type(FL_VERTICAL); vscrollbar->callback(scroll_cb, (void*)this); hscrollbar = new Fl_Scrollbar(x(), y()+h()-SCROLLBAR_SIZE, w(), SCROLLBAR_SIZE); hscrollbar->type(FL_HORIZONTAL); hscrollbar->callback(scroll_cb, (void*)this); table = new Fl_Scroll(x(), y(), w(), h()); table->box(FL_NO_BOX); table->type(0); // don't show Fl_Scroll's scrollbars -- use our own table->hide(); // hide unless children are present table->end(); table_resized(); redraw(); Fl_Group::end(); // end the group's begin() table->begin(); // leave with fltk children getting added to the scroll}// DtorFl_Table::~Fl_Table(){ // The parent Fl_Group takes care of destroying scrollbars}// Set height of a rowvoid Fl_Table::row_height(int row, int height){ if ( row < 0 ) return; if ( row < (int)_rowheights.size() && _rowheights[row] == height ) { return; } // OPTIMIZATION: no change? avoid redraw // Add row heights, even if none yet while ( row >= (int)_rowheights.size() ) { _rowheights.push_back(height); } _rowheights[row] = height; table_resized(); if ( row <= botrow ) // OPTIMIZATION: only redraw if onscreen or above screen { redraw(); }}// Set width of a columnvoid Fl_Table::col_width(int col, int width){ if ( col < 0 ) return; if ( col < (int)_colwidths.size() && _colwidths[col] == width ) { return; } // OPTIMIZATION: no change? avoid redraw // Add column widths, even if none yet while ( col >= (int)_colwidths.size() ) { _colwidths.push_back(width); } _colwidths[col] = width; table_resized(); if ( col <= rightcol ) // OPTIMIZATION: only redraw if onscreen or to the left { redraw(); }}// Return row/col clamped to realityint Fl_Table::row_col_clamp(TableContext context, int &R, int &C){ int clamped = 0; if ( R < 0 ) { R = 0; clamped = 1; } if ( C < 0 ) { C = 0; clamped = 1; } switch ( context ) { case CONTEXT_COL_HEADER: // Allow col headers to draw even if no rows if ( R >= _rows && R != 0 ) { R = _rows - 1; clamped = 1; } break; case CONTEXT_ROW_HEADER: // Allow row headers to draw even if no columns if ( C >= _cols && C != 0 ) { C = _cols - 1; clamped = 1; } break; case CONTEXT_CELL: default: // CLAMP R/C TO _rows/_cols if ( R >= _rows ) { R = _rows - 1; clamped = 1; } if ( C >= _cols ) { C = _cols - 1; clamped = 1; } break; } return(clamped);}// Return bounding region for given contextvoid Fl_Table::get_bounds(TableContext context, int &X, int &Y, int &W, int &H){ switch ( context ) { case CONTEXT_COL_HEADER: // Column header clipping. X = tox; Y = wiy; W = tow; H = col_header_height(); return; case CONTEXT_ROW_HEADER: // Row header clipping. X = wix; Y = toy; W = row_header_width(); H = toh; return; case CONTEXT_TABLE: // Table inner dimensions X = tix; Y = tiy; W = tiw; H = tih; return; // TODO: Add other contexts.. default: fprintf(stderr, "Fl_Table::get_bounds(): context %d unimplemented\n", (int)context); return; } //NOTREACHED}// Find row/col beneath cursor//// Returns R/C and context.// Also returns resizeflag, if mouse is hovered over a resize boundary.//Fl_Table::TableContext Fl_Table::cursor2rowcol(int &R, int &C, ResizeFlag &resizeflag){ // return values R = C = 0; resizeflag = RESIZE_NONE; int X, Y, W, H; // Row header? if ( row_header() ) { // Inside a row heading? get_bounds(CONTEXT_ROW_HEADER, X, Y, W, H); if ( Fl::event_inside(X, Y, W, H) ) { // Scan visible rows until found for ( R = toprow; R <= botrow; R++ ) { find_cell(CONTEXT_ROW_HEADER, R, 0, X, Y, W, H); if ( Fl::event_y() >= Y && Fl::event_y() < (Y+H) ) { // Found row? // If cursor over resize boundary, and resize enabled, // enable the appropriate resize flag. // if ( row_resize() ) { if ( Fl::event_y() <= (Y+3-0) ) { resizeflag = RESIZE_ROW_ABOVE; } if ( Fl::event_y() >= (Y+H-3) ) { resizeflag = RESIZE_ROW_BELOW; } } return(CONTEXT_ROW_HEADER); } } // Must be in row header dead zone return(CONTEXT_NONE);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?