fl_table.cpp

来自「ncbi源码」· C++ 代码 · 共 994 行 · 第 1/3 页

CPP
994
字号
                //    (C-1) is used if mouse is over the left hand side of the cell,                //    so that we resize the next column over to the left.                //                _resizing_col = ( resizeflag & RESIZE_COL_LEFT ) ? C-1 : C;                 _resizing_row = -1;                _dragging_x = Fl::event_x();                 ret = 1;            }            break;        case CONTEXT_ROW_HEADER:            // FL_PUSH on a row header?            if ( Fl::event_button() == 1 && resizeflag )            {                // Start resize if left mouse clicked on row border.                //    "ret = 1" ensures we get drag events from now on.                //    (R-1) is used if mouse is over the top of the cell,                //    so that we resize the row above.                //                _resizing_row = ( resizeflag & RESIZE_ROW_ABOVE ) ? R-1 : R;                 _resizing_col = -1;                _dragging_y = Fl::event_y();                 ret = 1;            }            break;        default:            ret = 0;        // express disinterest            break;        }        _last_row = R;        break;    case FL_DRAG:        if ( _resizing_col > -1 )        {            // Dragging column?            //            //    Let user drag even /outside/ the row/col widget.            //    Don't allow column width smaller than 1.            //    Continue to show FL_CURSOR_WE at all times during drag.            //            int offset = _dragging_x - Fl::event_x();            int new_w = col_width(_resizing_col) - offset;            if ( new_w < _col_resize_min ) new_w = _col_resize_min;            col_width(_resizing_col, new_w);            _dragging_x = Fl::event_x();            table_resized();            redraw();            change_cursor(FL_CURSOR_WE);            ret = 1;            if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED )            { do_callback(CONTEXT_RC_RESIZE, R, C); }        }        else if ( _resizing_row > -1 )        {            // Dragging row?            //            //    Let user drag even /outside/ the row/col widget.            //    Don't allow row width smaller than 1.            //    Continue to show FL_CURSOR_NS at all times during drag.            //            int offset = _dragging_y - Fl::event_y();            int new_h = row_height(_resizing_row) - offset;            if ( new_h < _row_resize_min ) new_h = _row_resize_min;            row_height(_resizing_row, new_h);            _dragging_y = Fl::event_y();            table_resized();            redraw();            change_cursor(FL_CURSOR_NS);            ret = 1;            if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED )            { do_callback(CONTEXT_RC_RESIZE, R, C); }        }        break;    case FL_RELEASE:        switch ( context )        {        case CONTEXT_ROW_HEADER:    // release on row header        case CONTEXT_COL_HEADER:    // release on col header        case CONTEXT_CELL:      // release on a cell        case CONTEXT_TABLE:     // release on dead zone            if ( _resizing_col == -1 &&             // not resizing a column                 _resizing_row == -1 &&             // not resizing a row                 Fl_Widget::callback() &&           // callback defined                 when() & FL_WHEN_RELEASE)          // on button release            {                // Need this for eg. left clicking on a cell to select it                do_callback(context, R, C);            }            break;        default:            break;        }        if ( Fl::event_button() == 1 )        {            change_cursor(FL_CURSOR_DEFAULT);            _resizing_col = -1;            _resizing_row = -1;            ret = 1;        }        break;    case FL_MOVE:        if ( context == CONTEXT_COL_HEADER &&   // in column header?             resizeflag )               // resize enabled + near boundary?        { change_cursor(FL_CURSOR_WE); }    // show resize cursor        else if ( context == CONTEXT_ROW_HEADER &&  // in row header?                  resizeflag )               // resize enabled + near boundary?        { change_cursor(FL_CURSOR_NS); }    // show resize cursor        else        { change_cursor(FL_CURSOR_DEFAULT); }   // normal cursor        ret = 1;        break;    case FL_ENTER:      // See FLTK event docs on the FL_ENTER widget    case FL_LEAVE:      // We want to track the mouse if resizing is allowed.        if ( resizeflag )        { ret = 1; }        if ( event == FL_LEAVE )        { change_cursor(FL_CURSOR_DEFAULT); }   // normal cursor        break;    case FL_FOCUS:    case FL_UNFOCUS:        // Currently no interest in keyboard focus.         //     This will likely change when we implement keyboard navigation of cells.        //        // if (Fl::visible_focus())         //     { ret = 1; }        break;    default:        change_cursor(FL_CURSOR_DEFAULT);        break;    }    return(ret);}// Resize FLTK override//     Handle resize events if user resizes parent window.//void Fl_Table::resize(int X, int Y, int W, int H){    // Tell group to resize, and recalc our own widget as well    Fl_Group::resize(X, Y, W, H);    table_resized();    redraw();}// Draw a cellvoid Fl_Table::_redraw_cell(TableContext context, int r, int c){    if ( r < 0 || c < 0 ) return;    int X,Y,W,H;    find_cell(context, r, c, X, Y, W, H);   // find positions of cell    draw_cell(context, r, c, X, Y, W, H);   // call users' function to draw it}// Draw the entire Fl_Table//    Override the draw() routine to draw the table.//    Then tell the group to draw over us.//void Fl_Table::draw(){    draw_cell(CONTEXT_STARTPAGE, 0, 0,      // let user's drawing routine              tix, tiy, tiw, tih);      // prep new page    // Let fltk widgets draw themselves first. Do this after    // draw_cell(CONTEXT_STARTPAGE) in case user moves widgets around.    // Use window 'inner' clip to prevent drawing into table border.    // (unfortunately this clips FLTK's border, so we must draw it explicity below)    //    fl_push_clip(wix, wiy, wiw, wih);    {        Fl_Group::draw();    }    fl_pop_clip();    // Explicitly draw border around widget, if any    draw_box(box(), x(), y(), w(), h(), color());    // If Fl_Scroll 'table' is hidden, draw its box    //    Do this after Fl_Group::draw() so we draw over scrollbars    //    that leak around the border.    //    if ( ! table->visible() )    {        if ( damage() & FL_DAMAGE_ALL || damage() & FL_DAMAGE_CHILD )        { draw_box(table->box(), tox, toy, tow, toh, table->color()); }    }    // Clip all further drawing to the inner widget dimensions    fl_push_clip(wix, wiy, wiw, wih);    {        // Only redraw a few cells?        if ( ! ( damage() & FL_DAMAGE_ALL ) && _redraw_leftcol != -1 )        {            fl_push_clip(tix, tiy, tiw, tih);            for ( int c = _redraw_leftcol; c <= _redraw_rightcol; c++ )                for ( int r = _redraw_toprow; r <= _redraw_botrow; r++ )                { _redraw_cell(CONTEXT_CELL, r, c); }            fl_pop_clip();        }        if ( damage() & FL_DAMAGE_ALL )        {            int X,Y,W,H;            // Draw row headers, if any            if ( row_header() )            {                get_bounds(CONTEXT_ROW_HEADER, X, Y, W, H);                fl_push_clip(X,Y,W,H);                for ( int r = toprow; r <= botrow; r++ )                {                    _redraw_cell(CONTEXT_ROW_HEADER, r, 0);                }                fl_pop_clip();            }            // Draw column headers, if any            if ( col_header() )            {                get_bounds(CONTEXT_COL_HEADER, X, Y, W, H);                fl_push_clip(X,Y,W,H);                for ( int c = leftcol; c <= rightcol; c++ )                {                    _redraw_cell(CONTEXT_COL_HEADER, 0, c);                }                fl_pop_clip();            }            // Draw all cells.            //    This includes cells partially obscured off edges of table.            //    No longer do this last; you might think it would be nice            //    to draw over dead zones, but on redraws it flickers. Avoid            //    drawing over deadzones; prevent deadzones by sizing columns.            //            fl_push_clip(tix, tiy, tiw, tih);            {                for ( int r = toprow; r <= botrow; r++ )                {                    for ( int c = leftcol; c <= rightcol; c++ )                    {                        _redraw_cell(CONTEXT_CELL, r, c);                    }                }            }            fl_pop_clip();            // Draw little rectangle in corner of headers            if ( row_header() && col_header() )            { fl_rectf(wix, wiy, row_header_width(), col_header_height(), color()); }            // Table has a boxtype? Close those few dead pixels            if ( table->box() )            {                if ( col_header() )                { fl_rectf(tox, wiy, Fl::box_dx(table->box()),                            col_header_height(), color()); }                if ( row_header() )                { fl_rectf(wix, toy, row_header_width(),                            Fl::box_dx(table->box()), color()); }            }            // Table width smaller than window? Fill remainder with rectangle            if ( table_w < tiw )            {                fl_rectf(tix + table_w, tiy, tiw - table_w, tih, color());                // Col header? fill that too                if ( col_header() )                {                    fl_rectf(tix + table_w,                              wiy,                              // get that corner just right..                             (tiw - table_w + Fl::box_dw(table->box()) -                               Fl::box_dx(table->box())),                             col_header_height(),                             color());                }            }            // Table height smaller than window? Fill remainder with rectangle            if ( table_h < tih )            {                fl_rectf(tix, tiy + table_h, tiw, tih - table_h, color());                if ( row_header() )                {                    // NOTE:                    //     Careful with that lower corner; don't use tih; when eg.                     //     table->box(FL_THIN_UPFRAME) and hscrollbar hidden,                     //     leaves a row of dead pixels.                    //                    fl_rectf(wix, tiy + table_h, row_header_width(),                              (wiy+wih)-(tiy+table_h)-(hscrollbar->visible()?                                                      SCROLLBAR_SIZE:0),                             color());                }            }        }        // Both scrollbars? Draw little box in lower right        if ( vscrollbar->visible() && hscrollbar->visible() )        {            fl_rectf(vscrollbar->x(), hscrollbar->y(),                      vscrollbar->w(), hscrollbar->h(), color());        }        draw_cell(CONTEXT_ENDPAGE, 0, 0,        // let user's drawing                  tix, tiy, tiw, tih);          // routines cleanup        _redraw_leftcol = _redraw_rightcol = _redraw_toprow = _redraw_botrow = -1;    }    fl_pop_clip();}

⌨️ 快捷键说明

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