示例#1
0
/*
 * InvokeColSelHook - invoke column hook with specified data
 */
vi_rc InvokeColSelHook( int sc, int ec )
{
    int         j, i;
    char        wordbuff[MAX_STR];
    char        data[MAX_STR + 32];
    int         lne;
#ifndef __WIN__
    int         x1;
    int         has_bord;
#endif

#ifndef __WIN__
    has_bord = WindowAuxInfo( CurrentWindow, WIND_INFO_HAS_BORDER );
    x1 = WindowAuxInfo( CurrentWindow, WIND_INFO_X1 );
    if( LastEvent != VI_KEY( MOUSEEVENT ) ) {
        lne = WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 ) + CurrentPos.line - LeftTopPos.line;
        if( has_bord ) {
            ++lne;
        }
    } else {
        lne = MouseRow;
    }
#else
    if( LastEvent != VI_KEY( FAKEMOUSE ) ) {
        lne = (CurrentPos.line - LeftTopPos.line) * FontHeight( WIN_FONT( &EditWindow ) );
    } else {
        lne = MouseY;
    }
#endif

    j = 0;
    if( ec - sc >= MAX_STR ) {
        ec = sc + MAX_STR - 2;
    }
    for( i = sc - 1; i <= ec - 1; i++ ) {
        wordbuff[j++] = CurrentLine->data[i];
    }
    wordbuff[j] = 0;
#ifndef __WIN__
    sc = x1 + VirtualColumnOnCurrentLine( sc ) - LeftTopPos.column;
    ec = x1 + VirtualColumnOnCurrentLine( ec ) - LeftTopPos.column;
    if( !has_bord ) {
        sc--;
        ec--;
    }
#else
    sc = MyTextExtent( CurrentWindow, WIN_STYLE( &EditWindow ),
        &CurrentLine->data[0], sc );
    ec = MyTextExtent( CurrentWindow, WIN_STYLE( &EditWindow ),
        &CurrentLine->data[0], ec );
#endif
    MySprintf( data, "\"%s\" %d %d %d %d", wordbuff, lne, sc, ec, ec - sc + 1 );
    return( SourceHookData( SRC_HOOK_MOUSE_CHARSEL, data ) );

} /* InvokeColSelHook */
示例#2
0
/*
 * LineNumbersSetup - set up line number window
 */
vi_rc LineNumbersSetup( void )
{
    int         j;
    int         x1, x2;
    window_info wi;
    vi_rc       rc;

    if( EditFlags.LineNumbers ) {
        if( editw_info.x2 - editw_info.x1 < EditVars.LineNumWinWidth ) {
            return( ERR_CANNOT_OPEN_LINENUM_WIND );
        }
        if( !linenumw_info.has_border ) {
            j = 1;
        } else {
            j = 0;
        }
        memcpy( &wi, &linenumw_info, sizeof( window_info ) );
        x1 = WindowAuxInfo( CurrentWindow, WIND_INFO_X1 );
        x2 = WindowAuxInfo( CurrentWindow, WIND_INFO_X2 );
        wi.y1 = WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 );
        wi.y2 = WindowAuxInfo( CurrentWindow, WIND_INFO_Y2 );
        if( !EditFlags.LineNumsOnRight ) {
            rc = ResizeWindowRelative( CurrentWindow, EditVars.LineNumWinWidth, 0, 0, 0, FALSE );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            wi.x1 = x1;
            wi.x2 = x1 + EditVars.LineNumWinWidth - 1 - j;
        } else {
            rc = ResizeWindowRelative( CurrentWindow, 0, 0, -EditVars.LineNumWinWidth, 0, FALSE );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            wi.x1 = x2 - EditVars.LineNumWinWidth + 1;
            wi.x2 = x2 - j;
        }
        rc = NewWindow2( &CurrNumWindow, &wi );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    } else {
        CloseAWindow( CurrNumWindow );
        rc = ResizeWindow( CurrentWindow, editw_info.x1, editw_info.y1,
                          editw_info.x2, editw_info.y2, FALSE );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }
    SetWindowCursor();
    DCDisplayAllLines();
    return( ERR_NO_ERR );

} /* LineNumbersSetup */
示例#3
0
vi_rc PromptForString( char *prompt, char *buffer, int buffer_length, history_data *h )
{
    window_id           wid;
    vi_rc               rc;

    if( !EditFlags.NoInputWindow ) {
        rc = NewWindow2( &wid, &cmdlinew_info );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    } else {
        wid = NO_WINDOW;
    }

    if( !EditFlags.NoInputWindow &&
        strlen( prompt ) >= WindowAuxInfo( wid, WIND_INFO_TEXT_COLS ) ) {
        rc = ERR_PROMPT_TOO_LONG;
    } else {
        rc = NO_VALUE_ENTERED;
        if( ReadStringInWindow( wid, 1, prompt, buffer, buffer_length, h ) ) {
            rc = ERR_NO_ERR;
        }
    }

    if( !EditFlags.NoInputWindow ) {
        CloseAWindow( wid );
        SetWindowCursor();
    } else {
        EditFlags.NoInputWindow = false;
    }
    return( rc );

} /* PromptForString */
示例#4
0
/*
 * SetCurrentLine - reset current line after changes in current file structure
 */
vi_rc SetCurrentLine( linenum lineno )
{
    int         text_lines;
    fcb         *cfcb;
    line        *cline;
    vi_rc       rc;

    if( lineno <= 0 ) {
        lineno = 1;
    }
    rc = CGimmeLinePtr( lineno, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    CurrentLine = cline;
    CurrentFcb = cfcb;

    text_lines = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_LINES );
    if( lineno < LeftTopPos.line || lineno > (LeftTopPos.line + text_lines - 1) ) {
        LeftTopPos.line = lineno - text_lines / 2;
    }
    if( LeftTopPos.line < 1 ) {
        LeftTopPos.line = 1;
    }

    CheckCurrentColumn();
    SetCurrentLineNumber( lineno );
    UpdateStatusWindow();
    SetWindowCursor();
    DCDisplayAllLines();
    return( ERR_NO_ERR );

} /* SetCurrentLine */
示例#5
0
/*
 * SetCurrentColumn - set CurrentPos.column, positioning LeftTopPos.column nicely
 */
vi_rc SetCurrentColumn( int newcol )
{
    long        oldpos;
    int         text_cols;

    oldpos = CurrentPos.column - LeftTopPos.column;
    if( newcol <= 0 ) {
        newcol = 1;
    }

    text_cols = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_COLS );
    if( oldpos < 0 || oldpos >= text_cols ) {
        LeftTopPos.column = newcol - SCROLL_HLINE - 1;
    } else {
        LeftTopPos.column = newcol - oldpos - 1;
    }
    if( LeftTopPos.column < 0 ) {
        LeftTopPos.column = 0;
    }

    CurrentPos.column = newcol;

    CheckCurrentColumn();
    UpdateCursorDrag();
    VarAddRandC();

    PositionHorizontalScrollThumb( current_window_id, LeftTopPos.column );
    UpdateStatusWindow();
    SetWindowCursor();
    DCDisplayAllLines();
    return( ERR_NO_ERR );

} /* SetCurrentColumn */
示例#6
0
void DCResize( info *info )
{
    int     nlines, extra;
    dc      dc;

    if( info == NULL ) {
        // Windows is sending WM_SIZE before we've set CurrentInfo -
        // hang on & cache will be initialized in DCCreate in a moment
        return;
    }
    nlines = WindowAuxInfo( info->CurrentWindow, WIND_INFO_TEXT_LINES );
    dc = info->dc;
    dc += info->dc_size - 1;
    for( extra = nlines - info->dc_size; extra < 0; ++extra ) {
        deinitDCLine( dc );
        dc--;
    }
    if( nlines == 0 ) {
        // no room to display anything - trash the cache
        if( info->dc ) {
            MemFree( info->dc );
        }
        info->dc = NULL;
    } else {
        info->dc = dc = MemReAlloc( info->dc, nlines * sizeof( dc_line ) );
        dc += info->dc_size;
        for( ; extra > 0; --extra ) {
            initDCLine( dc );
            dc++;
        }
    }
    info->dc_size = nlines;
}
示例#7
0
/*
 * checkWrapMargin - see if we have moved past the wrap margin
 */
static void checkWrapMargin( void )
{
    int         i;
    int         width;
    int         pos;
    bool        old_ai;

    if( EditVars.WrapMargin != 0 ) {
        if( EditVars.WrapMargin < 0 ) {
            width = -EditVars.WrapMargin;
        } else {
            width = WindowAuxInfo( CurrentWindow, WIND_INFO_WIDTH ) - EditVars.WrapMargin;
        }
        if( CurrentPos.column > width ) {
            for( i = CurrentPos.column - 1; i >= 0; i-- ) {
                if( isspace( WorkLine->data[i] ) ) {
                    pos = CurrentPos.column - 1 - i;
                    CurrentPos.column = i + 2;
                    old_ai = EditFlags.AutoIndent;
                    EditFlags.AutoIndent = FALSE;
                    IMEnter();
                    EditFlags.AutoIndent = old_ai;
                    GoToColumnOK( pos );
                    return;
                }
            }
        }
    }

} /* checkWrapMargin */
示例#8
0
/*
 * InvokeLineSelHook - invoke the mouse selection
 */
vi_rc InvokeLineSelHook( linenum s, linenum e )
{
    char        tmp[32];
    int         lne, col;
#ifndef __WIN__
    int         has_bord;
#endif

#ifndef __WIN__
    if( LastEvent != VI_KEY( MOUSEEVENT ) ) {
        has_bord = WindowAuxInfo( CurrentWindow, WIND_INFO_HAS_BORDER );
        lne = WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 ) + CurrentPos.line - LeftTopPos.line;
        col = WindowAuxInfo( CurrentWindow, WIND_INFO_X1 ) + VirtualColumnOnCurrentLine( CurrentPos.column ) - LeftTopPos.column - 1;
        if( has_bord ) {
            ++lne;
            ++col;
        }
        if( col < 0 ) {
            col = 0;
        }
    } else {
        col = MouseCol;
        lne = MouseRow;
    }
#else
    if( LastEvent != VI_KEY( FAKEMOUSE ) ) {
        /* assume we're not in insert mode *ouch* */
        col = PixelFromColumnOnCurrentLine( CurrentPos.column );
        lne = (CurrentPos.line - LeftTopPos.line) * FontHeight( WIN_FONT( &EditWindow ) );
    } else {
        col = MouseX;
        lne = MouseY;
    }
#endif
    MySprintf( tmp, "%d %d %l %l", lne, col, s, e );
    return( SourceHookData( SRC_HOOK_MOUSE_LINESEL, tmp ) );

} /* InvokeLineSelHook */
示例#9
0
static void initInput( input_buffer *input )
{
    type_style      *s;
    window_id       wid;

    memset( input->buffer, 0, input->buffer_length );
    input->curr_pos = 0;
    if( input->h != NULL ) {
        input->curr_hist = input->h->curr;
    }
    input->left_column = 0;
    input->overstrike = true;
    s = &input->window.style;
    wid = input->window.id;
    thisWindow = wid;
    s->foreground = WindowAuxInfo( wid, WIND_INFO_TEXT_COLOR );
    s->background = WindowAuxInfo( wid, WIND_INFO_BACKGROUND_COLOR );
    s->font = WindowAuxInfo( wid, WIND_INFO_TEXT_FONT );
    input->window.width = WindowAuxInfo( wid, WIND_INFO_TEXT_COLS );
    PushMouseEventHandler( mouseHandler );
    NewCursor( input->window.id, EditVars.NormalCursorType );
    displayLine( input );

} /* initInput */
示例#10
0
static void ensureCursorDisplayed( void )
{
    int         len, wc, diff;

    if( EditFlags.Modeless && ( CurrentFile != NULL ) ) {
        len = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
        if( CurrentPos.line < LeftTopPos.line ||
            CurrentPos.line > LeftTopPos.line + len - 1 ) {
            SetCurrentLine( CurrentPos.line );
        }

        wc = VirtualColumnOnCurrentLine( CurrentPos.column ) - LeftTopPos.column;
        if( !ColumnInWindow( wc, &diff ) ) {
            SetCurrentColumn( CurrentPos.column );
        }
    }
}
示例#11
0
/*
 * MovePageMiddle - move to the middle of the page
 */
vi_rc MovePageMiddle( range *r, long count )
{
    linenum     ln, lne;

    if( CurrentLine == NULL ) {
        return( ERR_NO_FILE );
    }
    count = count;
    ln = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) - 1;
    CFindLastLine( &lne );
    lne = lne - LeftTopPos.line + 1;
    if( ln > lne ) {
        ln = lne;
    }
    return( verifyMoveFromPageTop( r, ln / 2 ) );

} /* MovePageMiddle */
示例#12
0
void DCCreate( void )
{
    int     nlines, i;
    dc      dc;

    assert( CurrentInfo );
    nlines = WindowAuxInfo( CurrentInfo->CurrentWindow, WIND_INFO_TEXT_LINES );
    CurrentInfo->dc = NULL;
    if( nlines > 0 ) {
        dc = MemAlloc( nlines * sizeof( dc_line ) );
        CurrentInfo->dc = dc;
        for( i = 0; i < nlines; i++ ) {
            initDCLine( dc );
            dc++;
        }
    }
    CurrentInfo->dc_size = nlines;
}
示例#13
0
/*
 * MovePosition - move to a screen position
 */
vi_rc MovePosition( void )
{
    linenum     lne, lines;
    vi_key      key;
    vi_rc       rc;

    if( RepeatDigits == 0 ) {
        lne = CurrentPos.line;
    } else {
        lne = GetRepeatCount();
        if( IsPastLastLine( lne ) ) {
            return( ERR_INVALID_REDRAW );
        }
    }
    lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
    key = GetNextEvent( false );
    switch( key ) {
    case '.':
        LeftTopPos.line = lne - lines / 2;
        break;
    case VI_KEY( ENTER ):
        LeftTopPos.line = lne;
        break;
    case '-':
        LeftTopPos.line = lne - lines + 1;
        break;
    default:
        return( ERR_INVALID_REDRAW );
    }
    if( LeftTopPos.line < 1 ) {
        LeftTopPos.line = 1;
    }
    SetCurrentLineNumber( lne );
    rc = CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine );
    CurrentPos.column = 1;
    DCInvalidateAllLines();
    DCDisplayAllLines();
    if( rc == ERR_NO_ERR ) {
        rc = GoToColumnOnCurrentLine( FindStartOfCurrentLine() );
    }
    return( rc );

} /* MovePosition */
示例#14
0
/*
 * StatusLine - display a line in the status window
 */
static void StatusLine( int line, char *str, int format )
{
    int         len, width, blanks, i, j;
    type_style  *style;

    len = strlen( str );
    width = WindowAuxInfo( status_window_id, WIND_INFO_TEXT_COLS );
    style = &statusw_info.text_style;
    switch( format ) {
    case FMT_RIGHT:
        blanks = 0;
        if( width > len ) {
            blanks = width - len;
        }
        break;
    case FMT_CENTRE:
        blanks = 0;
        if( width > len ) {
            blanks = (width - len) / 2;
        }
        break;
    default:
        DisplayLineInWindow( status_window_id, line, str );
        return;
    }
    i = 1;
    while( i <= blanks ) {
        SetCharInWindowWithColor( status_window_id, line, i, ' ', style );
        i++;
    }
    j = 0;
    while( j < len && i <= width ) {
        SetCharInWindowWithColor( status_window_id, line, i, str[j], style );
        j += 1;
        i += 1;
    }
    while( i <= width ) {
        SetCharInWindowWithColor( status_window_id, line, i, ' ', style );
        i++;
    }

} /* StatusLine */
示例#15
0
vi_rc MovePageBottom( range *r, long count )
{
    linenum     ln;
    int         lines;
    int         amt;

    if( CurrentLine == NULL ) {
        return( ERR_NO_FILE );
    }
    lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
    if( IsPastLastLine( LeftTopPos.line + lines ) ) {
        CFindLastLine( &ln );
        amt = ln - LeftTopPos.line - count + 1;
    } else {
        amt = lines - count;
    }

    return( verifyMoveFromPageTop( r, amt ) );

} /* MovePageBottom */
示例#16
0
void SetCurrentLineNumber( linenum l )
{
    long        last;
    long        height;

    CurrentPos.line = l;
    UpdateCursorDrag();
    VarAddRandC();

    if( CurrentFile != NULL ) {
        height = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_LINES );
        last = CurrentFile->fcbs.tail->end_line - height + 1;
        if ( LeftTopPos.line > last ){
             last = LeftTopPos.line;
        }
    } else {
        last = 1;
    }
    PositionVerticalScrollThumb( current_window_id, LeftTopPos.line, last );
}
示例#17
0
/*
 * moveHalfPage - display half a page
 */
static vi_rc moveHalfPage( int dir )
{
    int         ople;
    vi_rc       rc;
    long        repcnt;
    int         ln;

    ople = EditVars.PageLinesExposed;
    repcnt = GetRepeatCount();
    if( repcnt > 1 ) {
        ln = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) - repcnt;
        if( ln < 1 ) {
            ln = 1;
        }
        HalfPageLines = ln;
    }

    EditVars.PageLinesExposed = HalfPageLines;
    rc = MovePage( dir, 1, false );
    EditVars.PageLinesExposed = ople;
    return( rc );

} /* moveHalfPage */
示例#18
0
/*
 * MoveScreenUp - expose top line
 */
vi_rc MoveScreenUp( void )
{
    linenum     lne, cnt, lines, top, nlne;

    lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
    CFindLastLine( &lne );
    cnt = GetRepeatCount();
    top = LeftTopPos.line - cnt;
    if( top < 1 ) {
        top = 1;
    }
    LeftTopPos.line = top;
    if( CurrentPos.line >= top + lines ) {
        nlne = top + lines - 1;
        if( nlne > lne ) {
            nlne = lne;
        }
        GoToLineNoRelCurs( nlne );
    }
    DCDisplayAllLines();
    SetWindowCursor();
    return( ERR_NO_ERR );

} /* MoveScreenUp */
示例#19
0
/*
 * MoveScreenDown - expose bottom line
 */
vi_rc MoveScreenDown( void )
{
    linenum     lne, cnt, lines, top, x;

    CFindLastLine( &lne );
    lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
    x = lne - lines + 1;
    if( x <= 0 ) {
        return( ERR_NO_ERR );
    }
    cnt = GetRepeatCount();
    top = LeftTopPos.line + cnt;
    if( top > x ) {
        top = x;
    }
    LeftTopPos.line = top;
    if( top >= CurrentPos.line ) {
        GoToLineNoRelCurs( top );
    }
    DCDisplayAllLines();
    SetWindowCursor();
    return( ERR_NO_ERR );

} /* MoveScreenDown */
示例#20
0
vi_rc MoveScreenUpPageML( void )
{
    return MoveScreenML( LeftTopPos.line -
                         WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) );
}
示例#21
0
/*
 * UpdateDrag - update selected region
 */
void UpdateDrag( window_id id, int win_x, int win_y )
{
    int         nx, ny, height;
    int         moveCursor;

    SelRgn.selected = TRUE;
    moveCursor = 0;
    height = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES );
#ifdef __WIN__
    if( id == CurrentWindow && InsideWindow( id, MouseX, MouseY ) ) {
#else
    if( id == CurrentWindow && InsideWindow( id, win_x, win_y ) ) {
#endif
        ny = LeftTopPos.line + win_y - 1;
        if( ny > CurrentFile->fcbs.tail->end_line ) {
            ny = CurrentFile->fcbs.tail->end_line;
            moveCursor = 1;
        } else if( ny < 1 ) {
            ny = 1;
            moveCursor = -1;
        }
        GoToLineRelCurs( ny );
        win_x += LeftTopPos.column;
        nx = RealColumnOnCurrentLine( win_x );
        GoToColumnOnCurrentLine( nx );
    } else {
#ifndef __WIN__
        if( MouseRow >= WindowAuxInfo( CurrentWindow, WIND_INFO_Y2 ) ) {
            GoToLineRelCurs( LeftTopPos.line + height );
        } else if( MouseRow <= WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 ) ) {
            GoToLineRelCurs( LeftTopPos.line - 1 );
        } else if( MouseCol <= WindowAuxInfo( CurrentWindow, WIND_INFO_X1 ) ) {
            GoToColumnOnCurrentLine( LeftTopPos.column - 1 );
        } else if( MouseCol >= WindowAuxInfo( CurrentWindow, WIND_INFO_X2 ) ) {
            GoToColumnOnCurrentLine( LeftTopPos.column + WindowAuxInfo( CurrentWindow, WIND_INFO_WIDTH ));
        }
#else
        {
            RECT            rect;

            GetClientRect( CurrentWindow, &rect );
            if( MouseY > rect.bottom ) {
                ny = LeftTopPos.line + height;
                if( ny > CurrentFile->fcbs.tail->end_line ) {
                    ny = CurrentFile->fcbs.tail->end_line;
                    moveCursor = 1;
                }
                GoToLineRelCurs( ny );
            } else if( MouseY < 0 ) {
                ny = LeftTopPos.line - 1;
                if( ny < 1 ) {
                    ny = 1;
                    moveCursor = -1;
                }
                GoToLineRelCurs( ny );
            } else if( MouseX < 0 ) {
                GoToColumnOnCurrentLine( LeftTopPos.column - 1 );
            } else if( MouseX > rect.right ) {
                if( EditFlags.Modeless ) {
                    GoToColumnOnCurrentLine( 1 + LeftTopPos.column +
                        WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_COLS ) );
                } else {
                    GoToColumnOnCurrentLine( LeftTopPos.column +
                        WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_COLS ) );
                }
            }
        }
#endif
    }

    if( moveCursor == -1 ) {
        GoToColumnOnCurrentLine( 1 );
    } else if( moveCursor == 1 ) {
        GoToColumnOnCurrentLine( CurrentFile->fcbs.tail->lines.tail->len + 1 );
    }

} /* UpdateDrag */

/*
 * UpdateCursorDrag - update drag after cursor movement
 */
void UpdateCursorDrag( void )
{
    if( !EditFlags.Dragging ) {
        return;
    }
    if( SelRgn.end.line == CurrentPos.line && SelRgn.end.column == CurrentPos.column ) {
        return;
    }
#ifndef __WIN__
    markRegion( FALSE );
#endif
    SelRgn.end = CurrentPos;
    if( EditFlags.LineBased == FALSE ) {
        SelRgn.lines = FALSE;
    } else if( SelRgn.start.line != SelRgn.end.line ) {
        SelRgn.lines = TRUE;
    } else if( SelRgn.start.column == SelRgn.end.column ) {
        SelRgn.lines = TRUE;
    } else {
        SelRgn.lines = FALSE;
    }
    updateRegion();

} /* UpdateCursorDrag */

/*
 * SetSelRegionCols - set selected region on a line
 */
void SetSelRegionCols( linenum sl, int sc, int ec )
{
    vi_rc   rc;
    line    *line;
    fcb     *fcb;
    char    *data;

    SelRgn.lines = FALSE;
    SelRgn.selected = TRUE;
    SelRgn.start.line = SelRgn.end.line = sl;
    SelRgn.start.column = sc;
    SelRgn.end.column = ec + 1;
    SelRgn.start_col_v = 0;
    rc = CGimmeLinePtr( sl, &fcb, &line );
    if( rc == ERR_NO_ERR ) {
        data = ( line->u.ld.nolinedata ) ? WorkLine->data : line->data;
        SelRgn.start_col_v = GetVirtualCursorPosition( data, SelRgn.start.column );
    }

    updateRegion();
    DCUpdate();

} /* SetSelRegionCols */
示例#22
0
/*
 * MovePage - move by a number of pages
 */
vi_rc MovePage( int dir, long repcnt, bool keepselect )
{
    vi_rc       rc;
    linenum     x, top, ll;
    linenum     tmp;

    if( EditFlags.Modeless && !keepselect ) {
        UnselectRegion();
    }

    tmp = (repcnt * dir * WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES )) - (dir * EditVars.PageLinesExposed);
#if 0
    x = CurrentPos.line + tmp;
    top = LeftTopPos.line + tmp;
    CFindLastLine( &ll );
    if( top > ll ) {
        top = ll;
    } else if( top < 1 ) {
        top = 1;
    }
    if( x > ll ) {
        x = ll;
    } else if( x < 1 ) {
        x = 1;
    }
#else
    top = LeftTopPos.line + tmp;
    if( top < 1 ) {
        top = 1;
    }
    rc = CAdvanceToLine( top );
    if( rc == ERR_NO_SUCH_LINE ) {
        rc = CFindLastLine( &ll );
        top = ll;
    }
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    x = CurrentPos.line + tmp;
    if( x < 1 ) {
        x = 1;
    }
    rc = CAdvanceToLine( x );
    if( rc == ERR_NO_SUCH_LINE ) {
        rc = CFindLastLine( &ll );
        x = ll;
    }
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
#endif
    LeftTopPos.line = top;
    SetCurrentLineNumber( x );
    rc = CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine );
    if( rc == ERR_NO_ERR ) {
        CheckCurrentColumn();
        UpdateStatusWindow();
        SetWindowCursor();
        DCInvalidateAllLines();
        DCDisplayAllLines();
    }
    return( rc );

} /* MovePage */
示例#23
0
/*
 * doInitializeEditor - do just that
 */
static void doInitializeEditor( int argc, char *argv[] )
{
    int         i, arg, cnt, ocnt, startcnt = 0;
    srcline     sline;
    int         k, j;
    char        tmp[FILENAME_MAX], c[1];
    char        buff[MAX_STR], file[MAX_STR], **list;
    char        cmd[MAX_STR * 2];
    char        *parm;
    char        *startup[MAX_STARTUP];
    char        *startup_parms[MAX_STARTUP];
    vi_rc       rc;
    vi_rc       rc1;

    /*
     * Make sure WATCOM is setup and if it is not, make a best guess.
     */
    watcom_setup_env();

    /*
     * If EDPATH is not set, use system default %WATCOM%\EDDAT.
     */
    if( getenv( "EDPATH" ) == NULL ) {
        char *watcom;

        watcom = getenv( "WATCOM" );
        if( watcom != NULL ) {
            char edpath[FILENAME_MAX];

            sprintf( edpath, "%s%c%s", watcom, FILE_SEP, "eddat" );

            if( setenv( "EDPATH", edpath, 0 ) != 0 ) {
                /*
                 * Bail out silently on error, as we will get error message later on.
                 */
            }
        }
    }

    /*
     * misc. set up
     */
    MaxMemFree = MemSize();
    StaticStart();
    FTSInit();
    BoundDataInit();
    EditFlags.Starting = true;
    InitCommandLine();
    ChkExtendedKbd();
    SSInitBeforeConfig();

    GetCWD1( &HomeDirectory );
    GetCWD1( &CurrentDirectory );
    SetCWD( HomeDirectory );
    if( cfgFN == NULL ){
        cfgFN = DupString( CFG_NAME );
    }

    checkFlags( &argc, argv, startup, startup_parms, &startcnt );
    ScreenInit();
    SetWindowSizes();
    EditFlags.ClockActive = false;
    SetInterrupts();
#ifdef __WIN__
    InitClrPick();
    InitFtPick();
    SubclassGenericInit();
    CursorOp( COP_INIT );
#else
    InitColors();
#endif
    InitSavebufs();
    InitKeyMaps();

    /*
     * initial configuration
     */
    EditVars.Majick = MemStrDup( "()~@" );
    EditVars.FileEndString = MemStrDup( "[END_OF_FILE]" );
    MatchInit();
    SetGadgetString( NULL );
    WorkLine = MemAlloc( sizeof( line ) + EditVars.MaxLine + 2 );
    WorkLine->len = -1;

    sline = 0;
    if( cfgFN[0] != 0 ) {
        c[0] = 0;
        rc = Source( cfgFN, c, &sline );
        if( rc == ERR_FILE_NOT_FOUND ) {
#ifdef __WIN__
            CloseStartupDialog();
            MessageBox( (HWND)NULLHANDLE, "Could not locate configuration information; please make sure your EDPATH environment variable is set correctly",
                        EditorName, MB_OK );
            ExitEditor( -1 );
#else
            rc = ERR_NO_ERR;
#endif
        }
    } else {
        rc = ERR_NO_ERR;
    }
    if( wantNoReadEntireFile ) {
        EditFlags.ReadEntireFile = false;
    }
    VerifyTmpDir();
    while( LostFileCheck() );
    HookScriptCheck();

    if( EditFlags.Quiet ) {
        EditFlags.Spinning = false;
        EditFlags.Clock = false;
    }
    ExtendedMemoryInit();

    /*
     * more misc. setup
     */
    if( EditVars.WordDefn == NULL ) {
        EditVars.WordDefn = DupString( &WordDefnDefault[6] );
        InitWordSearch( EditVars.WordDefn );
    }
    if( EditVars.WordAltDefn == NULL ) {
        EditVars.WordAltDefn = DupString( WordDefnDefault );
    }
    if( EditVars.TagFileName == NULL ) {
        EditVars.TagFileName = DupString( "tags" );
    }
    DotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    AltDotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    DotCmd = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    SwapBlockInit( EditVars.MaxSwapBlocks );
    ReadBuffer = MemAlloc( MAX_IO_BUFFER + 6 );
    WriteBuffer = MemAlloc( MAX_IO_BUFFER + 6 );
    FindHistInit( EditVars.FindHist.max );
    FilterHistInit( EditVars.FilterHist.max );
    CLHistInit( EditVars.CLHist.max );
    LastFilesHistInit( EditVars.LastFilesHist.max );
    GetClockStart();
    GetSpinStart();
    SelRgnInit();
    SSInitAfterConfig();
#if defined( VI_RCS )
    ViRCSInit();
#endif

    /*
     * create windows
     */
    StartWindows();
    InitMouse();
    rc1 = NewMessageWindow();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    DoVersion();
    rc1 = InitMenu();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    EditFlags.SpinningOurWheels = true;
    EditFlags.ClockActive = true;
    EditFlags.DisplayHold = true;
    rc1 = NewStatusWindow();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    EditFlags.DisplayHold = false;

    MaxMemFreeAfterInit = MemSize();

    /*
     * look for a tag: if there is one, set it up as the file to start
     */
    EditFlags.WatchForBreak = true;
    if( cTag != NULL && !EditFlags.NoInitialFileLoad ) {
#if defined( __NT__ ) && !defined( __WIN__ )
        {
            if( !EditFlags.Quiet ) {
                SetConsoleActiveScreenBuffer( OutputHandle );
            }
        }
#endif
        rc1 = LocateTag( cTag, file, buff );
        cFN = file;
        if( rc1 != ERR_NO_ERR ) {
            if( rc1 == ERR_TAG_NOT_FOUND ) {
                Error( GetErrorMsg( rc1 ), cTag );
                ExitEditor( 0 );
            }
            FatalError( rc1 );
        }
    }

    /*
     * start specified file(s)
     */
    cmd[0] = 'e';
    cmd[1] = 0;

    arg = argc - 1;
    k = 1;
    while( !EditFlags.NoInitialFileLoad ) {

        if( cFN == nullFN && !EditFlags.UseNoName ) {
            break;
        }

#ifdef __NT__
        {
            int     k2;
            int     arg2;
            char    path[_MAX_PATH];
            int     found;
            int     fd;
            size_t  len;
            size_t  len1;
            char    *p;

            /*
             * check for the existence of a file name containing spaces, and open it if
             * there is one
             */
            len = _MAX_PATH - 1;
            found = 0;
            p = path;
            arg2 = arg;
            for( k2 = k; argv[k2] != NULL; ) {
                len1 = strlen( argv[k2] );
                if( len1 > len )
                    break;
                memcpy( p, argv[k2], len1 );
                p += len1;
                *p = '\0';
                len -= len1;
                --arg2;
                ++k2;
                fd = open( path, O_RDONLY );
                if( fd != -1 ) {
                    close( fd );
                    k = k2;
                    arg = arg2;
                    found = 1;
                    break;
                }
                *p++ = ' ';
            }
            if( found ) {
#ifndef __UNIX__
                len1 = strlen( path );
                if( path[len1 - 1] == '.' )
                    path[len1 - 1] = '\0';
#endif
                rc1 = NewFile( path, false );
                if( rc1 != ERR_NO_ERR ) {
                    FatalError( rc1 );
                }
                cFN = argv[k];
                if( arg < 1 ) {
                    break;
                }
                continue;
            }
        }
#endif

        strcat( cmd, SingleBlank );
        strcat( cmd, cFN );
        ocnt = cnt = ExpandFileNames( cFN, &list );
        if( cnt == 0 ) {
            cnt = 1;
        } else {
            cFN = list[0];
        }

        for( j = 0; j < cnt; j++ ) {
            rc1 = NewFile( cFN, false );
            if( rc1 != ERR_NO_ERR && rc1 != NEW_FILE ) {
                FatalError( rc1 );
            }
            if( EditFlags.BreakPressed ) {
                break;
            }
            if( cnt > 0 && j < cnt - 1 ) {
                cFN = list[j + 1];
            }
        }
        if( ocnt > 0 ) {
            MemFreeList( ocnt, list );
        }
        if( EditFlags.BreakPressed ) {
            ClearBreak();
            break;
        }
        k++;
        arg--;
        if( cTag != NULL || arg < 1 ) {
            break;
        }
        cFN = argv[k];
    }
    if( EditFlags.StdIOMode ) {
        rc1 = NewFile( "stdio", false );
        if( rc1 != ERR_NO_ERR ) {
            FatalError( rc1 );
        }
    }
    EditFlags.WatchForBreak = false;
    EditFlags.Starting = false;

    /*
     * if there was a tag, do the appropriate search
     */
    if( cTag != NULL && !EditFlags.NoInitialFileLoad ) {
        if( buff[0] != '/' ) {
            i = atoi( buff );
            rc1 = GoToLineNoRelCurs( i );
        } else {
            rc1 = FindTag( buff );
        }
        if( rc1 > 0 ) {
            Error( GetErrorMsg( rc1 ) );
        }
    }

    /*
     * try to run startup file
     */
    if( EditFlags.RecoverLostFiles ) {
        startcnt = 0;
    }
    for( i = 0; i < startcnt; i++ ) {
        GetFromEnv( startup[i], tmp );
        ReplaceString( &cfgFN, tmp );
        if( cfgFN[0] != 0 ) {
            if( startup_parms[i] != NULL ) {
                parm = startup_parms[i];
            } else {
                c[0] = 0;
                parm = c;
            }
#if defined( __NT__ ) && !defined( __WIN__ )
            {
                if( !EditFlags.Quiet ) {
                    SetConsoleActiveScreenBuffer( OutputHandle );
                }
            }
#endif
            sline = 0;
            rc = Source( cfgFN, parm, &sline );
        }
    }
    if( rc > ERR_NO_ERR ) {
        Error( "%s on line %u of \"%s\"", GetErrorMsg( rc ), sline, cfgFN );
    }
    if( argc == 1 ) {
        LoadHistory( NULL );
    } else {
        LoadHistory( cmd );
    }
    if( EditVars.GrepDefault == NULL ) {
        EditVars.GrepDefault = DupString( "*.(c|h)" );
    }
    if( goCmd[0] != 0 ) {
        KeyAddString( goCmd );
    }
    if( keysToPush != NULL ) {
        KeyAddString( keysToPush );
    }
#ifdef __WIN__
    if( lineToGoTo != 0 ) {
        SetCurrentLine( lineToGoTo );
        NewCursor( CurrentWindow, EditVars.NormalCursorType );
    }
#endif
    AutoSaveInit();
    HalfPageLines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) / 2 - 1;
#if defined( _M_X64 )
    VarAddGlobalStr( "OSX64", "1" );
#elif defined( _M_IX86 ) && !defined( _M_I86 )
    VarAddGlobalStr( "OS386", "1" );
#endif
    if( EditVars.StatusString == NULL ) {
        EditVars.StatusString = DupString( "L:$6L$nC:$6C" );
    }
    UpdateStatusWindow();
#ifdef __WIN__
    if( CurrentInfo == NULL ) {
        // no file loaded - screen is disconcertenly empty - reassure
        DisplayFileStatus();
    }
#endif
    NewCursor( CurrentWindow, EditVars.NormalCursorType );
#if defined( __NT__ ) && !defined( __WIN__ )
    {
        SetConsoleActiveScreenBuffer( OutputHandle );
    }
#endif

} /* doInitializeEditor */
示例#24
0
vi_rc DCUpdate( void )
{
    vi_rc           rc;
    int             i, nlines;
    fcb             *fcb;
    line            *line;
    dc              dc;
    bool            firstLine, firstTilde;
    linenum         line_no;
    int             displayOffset;
    char            *displayText;
#ifdef __WIN__
    HDC             hdc_wnd;
#ifdef BITBLT_BUFFER_DISPLAY
    HDC             hdc_mem;
    HBITMAP         hbitmap;
    type_style      *ws;
#endif
#else
    bool            hasMouse;
    unsigned int    hdc_wnd = 0;
#endif

    if( EditFlags.Quiet || CurrentInfo == NULL ) {
        return( ERR_NO_ERR );
    }

#ifdef __WIN__
    MyHideCaret( CurrentWindow );
    hdc_wnd = GetDC( CurrentWindow );
#ifdef BITBLT_BUFFER_DISPLAY
    hdc_mem = CreateCompatibleDC( hdc_wnd );
    ws = &(SEType[SE_WHITESPACE]);
    hbitmap = CreateCompatibleBitmap( hdc_wnd,
                    WindowAuxInfo( CurrentWindow, WIND_INFO_WIDTH ),
                    FontHeight( ws->font ) );
    SelectObject( hdc_mem, hbitmap );
    SelectObject( hdc_mem, ColorBrush( ws->background ) );
#endif
#else
    hasMouse = DisplayMouse( false );
#endif

    rc = CGimmeLinePtr( LeftTopPos.line, &fcb, &line );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    nlines = CurrentInfo->dc_size;
    dc = CurrentInfo->dc;
    firstLine = true;
    firstTilde = true;
    for( i = 0, line_no = LeftTopPos.line; i < nlines; i++, line_no++ ) {
        if( dc->display ) {
            if( line ) {
                if( firstLine ) {
                    if( dc->valid ) {
                         // major speedup
                         SSInitLanguageFlagsGivenValues( &(dc->flags) );
                    } else {
                        SSInitLanguageFlags( line_no );
                    }
                    firstLine = false;
                }

                displayText = line->data;
                if( line->u.ld.nolinedata ) {
                    if( WorkLine->len >= 0 ) {
                        displayText = WorkLine->data;
                    } else {
                        displayText = "*** ERR NULL DATA ***";
                    }
                }
                displayOffset = VirtualLineLen( displayText );
                if( displayOffset > LeftTopPos.column ) {
                    displayOffset = LeftTopPos.column;
                }
            } else {
                if( EditFlags.DrawTildes ) {
                    displayText = "~";
                } else {
                    displayText = "";
                    if( firstTilde ) {
                        displayText = EditVars.FileEndString;
                        firstTilde = false;
                    }
                }
                displayOffset = 0;
            }
#ifdef BITBLT_BUFFER_DISPLAY
            DisplayLineInWindowWithSyntaxStyle( CurrentWindow, i + 1,
                                line, line_no, displayText, displayOffset,
                                hdc_wnd,
                                hdc_mem );
#else
            DisplayLineInWindowWithSyntaxStyle( CurrentWindow, i + 1,
                                line, line_no, displayText, displayOffset,
                                hdc_wnd );
#endif
            dc->display = false;
        } else {
            // just in case displaying 2+ blocks in one update
            firstLine = true;
        }
        if( line ) {
            rc = CGimmeNextLinePtr( &fcb, &line );
        }
        if( rc != ERR_NO_ERR && rc != ERR_NO_MORE_LINES ) {
            return( rc );
        }
        dc++;
    }
#ifdef __WIN__
#ifdef BITBLT_BUFFER_DISPLAY
    DeleteDC( hdc_mem );
    DeleteObject( hbitmap );
#endif
    ReleaseDC( CurrentWindow, hdc_wnd );
    MyShowCaret( CurrentWindow );
#else
    DisplayMouse( hasMouse );
#endif
    return( ERR_NO_ERR );
}
示例#25
0
vi_rc MoveScreenRightPageML( void )
{
    return MoveScreenLeftRightML(
        LeftTopPos.column + WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_COLS ) - 2 );
}
示例#26
0
/*
 * SelectLineInFile - select a line in a given file
 */
vi_rc SelectLineInFile( selflinedata *sfd )
{
    int         i, winflag;
    int         leftcol = 0, key2;
    bool        done = FALSE, redraw = TRUE;
    bool        hiflag = FALSE, drawbord = FALSE;
    int         farx, text_lines;
    linenum     pagetop = 1, lln = 1;
    char        tmp[MAX_STR];
    hilst       *ptr;
    linenum     cln;
    linenum     endline;
    vi_rc       rc;
    vi_key      key;

    /*
     * create the window
     */
    cln = sfd->cln;
    endline = sfd->f->fcbs.tail->end_line;
    farx = sfd->wi->x2;
    if( sfd->show_lineno ) {
        farx++;
    }
    if( sfd->hilite != NULL ) {
        hiflag = TRUE;
    }
    rc = NewWindow2( &cWin, sfd->wi );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    if( !sfd->is_menu ) {
        WindowAuxUpdate( cWin, WIND_INFO_HAS_SCROLL_GADGETS, TRUE );
        DrawBorder( cWin );
    }
    oWin = sfd->eiw;
    isMenu = sfd->is_menu;
    PushMouseEventHandler( SelectLineMouseHandler );
    KillCursor();
    text_lines = WindowAuxInfo( cWin, WIND_INFO_TEXT_LINES );
    sfd->sl = -1;
    if( sfd->title != NULL ) {
        WindowTitle( cWin, sfd->title );
    }
    pagetop = text_lines * (cln / text_lines);
    if( cln % text_lines != 0 ) {
        pagetop++;
    }
    key = 0;
    if( LastEvent == VI_KEY( MOUSEEVENT ) ) {
        DisplayMouse( TRUE );
    }

    /*
     * now, allow free scrolling and selection
     */
    while( !done ) {

        if( redraw ) {
            if( sfd->show_lineno ) {
                MySprintf(tmp, "%l/%l", cln, endline );
                i = sfd->wi->x2 - sfd->wi->x1;
                WindowBorderData( cWin, tmp, i - strlen( tmp ) );
                drawbord = TRUE;
            }
            if( hiflag ) {
                ptr = sfd->hilite;
                ptr += cln - 1;
                if( ptr->_char == (char)-1 ) {
                    if( cln > lln ) {
                        cln++;
                    } else if( cln < lln ) {
                        cln--;
                    }
                }
            }
            if( drawbord ) {
                DrawBorder( cWin );
            }
            displayGenericLines( sfd->f, pagetop, leftcol, cln, &(sfd->wi->hilight), sfd->hilite, sfd->vals, sfd->valoff );
        }
        lln = cln;
        redraw = TRUE;
        drawbord = FALSE;
        mouseLine = -1;
        rlMenu = FALSE;
        if( key == VI_KEY( MOUSEEVENT ) ) {
            DisplayMouse( TRUE );
        }
        key = GetNextEvent( TRUE );
        if( hiflag && ((key >= VI_KEY( ALT_A ) && key <= VI_KEY( ALT_Z )) ||
                       (key >='a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
                       (key >= '1' && key <= '9')) ) {
            i = 0;
            if( key >= VI_KEY( ALT_A ) && key <= VI_KEY( ALT_Z ) ) {
                key2 = key - VI_KEY( ALT_A ) + 'A';
            } else if( key >= 'a' && key <= 'z' ) {
                key2 = key - 'a' + 'A';
            } else {
                key2 = key;
            }
            ptr = sfd->hilite;
            while( ptr->_char != '\0' ) {
                if( toupper( ptr->_char ) == key2 ) {
                    cln = i + 1;
                    key = VI_KEY( ENTER );
                    break;
                }
                ++i;
                ++ptr;
            }
        }

        /*
         * check if a return-event has been selected
         */
        if( sfd->retevents != NULL ) {
            i = 0;
            if( key == VI_KEY( MOUSEEVENT ) ) {
                if( mouseWin == oWin && LastMouseEvent == MOUSE_PRESS ) {
                    DisplayMouse( FALSE );
                    sfd->event = sfd->retevents[mouseLine];
                    key = VI_KEY( ENTER );
                }
            } else {
                while( sfd->retevents[i] != 0 ) {
                    if( key == sfd->retevents[i] ) {
                        sfd->event = key;
                        key = VI_KEY( ENTER );
                        break;
                    }
                    i++;
                }
            }
        }

        /*
         * process key stroke
         */
        switch( key ) {
        case VI_KEY( MOUSEEVENT ):
            DisplayMouse( FALSE );
            if( hiflag ) {
                ptr = sfd->hilite;
                ptr += mouseLine;
                if( ptr->_char == (char) -1 ) {
                    break;
                }
            }
            if( rlMenu && sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = rlMenuNum;
                done = TRUE;
                break;
            }
            if( mouseScroll != MS_NONE ) {
                switch( mouseScroll ) {
                case MS_UP: goto evil_up;
                case MS_DOWN: goto evil_down;
                case MS_PAGEUP: goto evil_pageup;
                case MS_PAGEDOWN: goto evil_pagedown;
                case MS_EXPOSEDOWN:
                    adjustCLN( &cln, &pagetop, pagetop + text_lines - cln - 1, endline, text_lines );
                    adjustCLN( &cln, &pagetop, 1, endline, text_lines );
                    drawbord = TRUE;
                    break;
                case MS_EXPOSEUP:
                    adjustCLN( &cln, &pagetop, pagetop - cln, endline, text_lines );
                    adjustCLN( &cln, &pagetop, -1, endline, text_lines );
                    drawbord = TRUE;
                    break;

                }
                break;
            }
            switch( LastMouseEvent ) {
            case MOUSE_DRAG:
                if( mouseWin != cWin ) {
                    break;
                }
                cln = mouseLine + pagetop;
                break;
            case MOUSE_RELEASE:
                if( !sfd->is_menu ) {
                    break;
                }
                if( mouseWin == cWin ) {
                    cln = mouseLine + pagetop;
                    if( cln <= endline ) {
                        goto evil_enter;
                    }
                }
                break;
            case MOUSE_DCLICK:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                } else {
                    cln = mouseLine + pagetop;
                    if( cln <= endline ) {
                        goto evil_enter;
                    }
                }
                break;
            case MOUSE_PRESS_R:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                }
                break;
            case MOUSE_PRESS:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                } else {
                    cln = mouseLine + pagetop;
                }
                break;
            }
            break;

        case VI_KEY( ESC ):
            done = TRUE;
            break;

        evil_enter:
        case VI_KEY( ENTER ):
        case ' ':
            /*
             * see if we need to do a callback for this
             */
            if( sfd->checkres != NULL ) {
                line    *cline;
                fcb     *cfcb;
                char    data[64];

                i = cln - 1;
                GimmeLinePtr( cln, sfd->f, &cfcb, &cline );
                strcpy( data, cline->data );
                RemoveLeadingSpaces( data );
                winflag = FALSE;
                strcpy( tmp, sfd->vals[i] );
                rc = sfd->checkres( data, tmp, &winflag );
                if( winflag ) {
                    if( winflag == 2 ) {
                        winflag = TRUE;
                    } else {
                        winflag = FALSE;
                    }
                }
                if( winflag ) {
                    MoveWindowToFront( cWin );
                }
                if( rc == ERR_NO_ERR ) {
                    AddString2( &(sfd->vals[i]), tmp );
                    redraw = TRUE;
                }
                break;

            /*
             * no value window, so just return line selected
             */
            } else {
                if( isMenu && InvokeMenuHook( CurrentMenuNumber, cln ) == -1 ) {
                    break;
                }
                sfd->sl = cln;
                done = TRUE;
            }
            break;

        case VI_KEY( LEFT ):
        case 'h':
            if( sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = -1;
                done = TRUE;
            }
            break;

        case VI_KEY( RIGHT ):
        case 'l':
            if( sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = 1;
                done = TRUE;
            }
            break;

        evil_up:
        case VI_KEY( UP ):
        case 'k':
            drawbord = adjustCLN( &cln, &pagetop, -1, endline, text_lines );
            break;

        evil_down:
        case VI_KEY( DOWN ):
        case 'j':
            drawbord = adjustCLN( &cln, &pagetop, 1, endline, text_lines );
            break;

        case VI_KEY( CTRL_PAGEUP ):
            drawbord = adjustCLN( &cln, &pagetop, -cln + 1, endline, text_lines );
            break;

        case VI_KEY( CTRL_PAGEDOWN ):
            drawbord = adjustCLN( &cln, &pagetop, endline - cln, endline, text_lines );
            break;

        evil_pageup:
        case VI_KEY( PAGEUP ):
        case VI_KEY( CTRL_B ):
            drawbord = adjustCLN( &cln, &pagetop, -text_lines, endline, text_lines );
            break;

        evil_pagedown:
        case VI_KEY( PAGEDOWN ):
        case VI_KEY( CTRL_F ):
            drawbord = adjustCLN( &cln, &pagetop, text_lines, endline, text_lines );
            break;

        case VI_KEY( HOME ):
            drawbord = TRUE;
            cln = 1;
            pagetop = 1;
            break;

        case VI_KEY( END ):
            drawbord = TRUE;
            cln = endline;
            pagetop = endline - text_lines + 1;
            if( pagetop < 1 ) {
                pagetop = 1;
            }
            break;

        default:
            redraw = FALSE;
            break;

        }

    }
    PopMouseEventHandler();
    CloseAWindow( cWin );
    RestoreCursor();
    SetWindowCursor();
    return( rc );

} /* SelectLineInFile */
示例#27
0
/*
 * SelectLineMouseHandler - handle mouse events for line selector
 */
bool SelectLineMouseHandler( window_id id, int win_x, int win_y )
{
    int x, y, i;

    if( LastMouseEvent != MOUSE_DRAG && LastMouseEvent != MOUSE_PRESS &&
        LastMouseEvent != MOUSE_DCLICK && LastMouseEvent != MOUSE_RELEASE &&
        LastMouseEvent != MOUSE_REPEAT && LastMouseEvent != MOUSE_PRESS_R ) {
        return( FALSE );
    }
    mouseWin = id;
    mouseScroll = MS_NONE;

    if( !isMenu && (id == cWin) && (LastMouseEvent == MOUSE_REPEAT ||
                                    LastMouseEvent == MOUSE_PRESS ||
                                    LastMouseEvent == MOUSE_DCLICK ) ) {
        x = WindowAuxInfo( cWin, WIND_INFO_WIDTH );
        y = WindowAuxInfo( cWin, WIND_INFO_HEIGHT );
        if( win_x == x - 1 ) {
            if( win_y == 1 ) {
                mouseScroll = MS_EXPOSEUP;
                return( TRUE );
            } else if( win_y == y - 2 ) {
                mouseScroll = MS_EXPOSEDOWN;
                return( TRUE );
            } else if( win_y > 1 && win_y < y / 2 ) {
                mouseScroll = MS_PAGEUP;
                return( TRUE );
            } else if( win_y >= y / 2 && win_y < y - 1 ) {
                mouseScroll = MS_PAGEDOWN;
                return( TRUE );
            }
        }
    }
    if( LastMouseEvent == MOUSE_REPEAT ) {
        if( id != cWin && !isMenu ) {
            y = WindowAuxInfo( cWin, WIND_INFO_Y1 );
            if( MouseRow < y ) {
                mouseScroll = MS_UP;
                return( TRUE );
            }
            y = WindowAuxInfo( cWin, WIND_INFO_Y2 );
            if( MouseRow > y ) {
                mouseScroll = MS_DOWN;
                return( TRUE );
            }
        }
        return( FALSE );
    }
    if( isMenu && EditFlags.Menus && id == MenuWindow &&
        LastMouseEvent != MOUSE_PRESS_R ) {
        i = GetMenuIdFromCoord( win_x );
        if( i >= 0 ) {
            rlMenuNum = i - GetCurrentMenuId();
            if( rlMenuNum != 0 ) {
                rlMenu = TRUE;
            }
        }
        return( TRUE );
    }
    if( id != cWin && id != oWin ) {
        return( TRUE );
    }

    if( !InsideWindow( id, win_x, win_y ) ) {
        return( FALSE );
    }
    mouseLine = win_y - 1;
    return( TRUE );

} /* SelectLineMouseHandler */
示例#28
0
/*
 * displayGenericLines - display all lines in a window
 */
static vi_rc displayGenericLines( file *f, linenum pagetop, int leftcol,
                                linenum hilite, type_style *style, hilst *hilist,
                                char **vals, int valoff )
{
    int         i, j, k, text_lines;
    linenum     cl = pagetop;
    fcb         *cfcb, *tfcb;
    line        *cline;
    hilst       *ptr;
    type_style  *text, *hot_key;
    window_info *info;
    type_style  base;
    char        tmp[MAX_STR];
//    bool        disabled;
    vi_rc       rc;

    /*
     * get pointer to first line on page, and window info
     */
    rc = GimmeLinePtr( pagetop, f, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    base.foreground = WindowAuxInfo( cWin, WIND_INFO_TEXT_COLOR );
    base.background = WindowAuxInfo( cWin, WIND_INFO_BACKGROUND_COLOR );
    base.font = WindowAuxInfo( cWin, WIND_INFO_TEXT_FONT );
    text_lines = WindowAuxInfo( cWin, WIND_INFO_TEXT_LINES );

    /*
     * mark all fcb's as being not in display
     */
    for( tfcb = f->fcbs.head; tfcb != NULL; tfcb = tfcb->next ) {
        tfcb->on_display = FALSE;
    }
    cfcb->on_display = TRUE;

    /*
     * run through each line in the window
     */
    ptr = hilist;
    if( ptr != NULL ) {
        ptr += pagetop - 1;
    }
    for( j = 1; j <= text_lines; j++ ) {
        if( cline != NULL ) {
            if( isMenu ) {
                if( InvokeMenuHook( CurrentMenuNumber, cl ) == -1 ) {
//                    disabled = TRUE;
                    if( cl == hilite ) {
                        info = &activegreyedmenu_info;
                    } else {
                        info = &greyedmenu_info;
                    }
                } else {
//                    disabled = FALSE;
                    if( cl == hilite ) {
                        info = &activemenu_info;
                    } else {
                        info = &menuw_info;
                    }
                }
                text = &info->text;
                hot_key = &info->hilight;
            } else {
                text = &base;
                if( cl == hilite ) {
                    text = style;
                }
                hot_key = text;
            }

            /*
             * now, display what we can of the line on the window
             */
            if( cline->len == 0 ) {
                DisplayCrossLineInWindow( cWin, j );
                goto evil_goto;
            } else if( cline->len > leftcol ) {
                if( vals != NULL ) {
                    i = cline->len - leftcol;
                    strncpy( tmp, &(cline->data[leftcol]), EditVars.WindMaxWidth + 5 );
                    for( k = i; k < valoff; k++ ) {
                        tmp[k] = ' ';
                    }
                    tmp[k] = 0;
                    strcat( tmp, vals[j + pagetop - 2] );
                    DisplayLineInWindowWithColor( cWin, j, tmp, text, 0 );
                } else {
                    DisplayLineInWindowWithColor( cWin, j, cline->data, text, leftcol );
                }
            } else {
                DisplayLineInWindowWithColor( cWin, j, SingleBlank, text, 0 );
            }
            if( ptr != NULL ) {
                SetCharInWindowWithColor( cWin, j, 1 + ptr->_offs, ptr->_char, hot_key );
            }
evil_goto:  if( ptr != NULL ) {
                ptr += 1;
            }
            rc = GimmeNextLinePtr( f, &cfcb, &cline );
            if( rc != ERR_NO_ERR ) {
                if( rc == ERR_NO_MORE_LINES ) {
                    continue;
                }
                return( rc );
            }
            cl++;
            cfcb->on_display = TRUE;
        } else {
            DisplayLineInWindow( cWin, j, "~" );
        }

    }
    return( ERR_NO_ERR );

} /* displayGenericLines */
示例#29
0
/*
 * goToLine - go to a specified line number
 */
static vi_rc goToLine( linenum lineno, bool relcurs )
{
    int         text_lines, tl;
    linenum     diff, cwl, nwl;
//    linenum   s, e, hiddcnt;
    bool        dispall, pageshift;
    fcb         *cfcb;
    line        *cline;
    int         pad;
    vi_rc       rc;

    if( lineno < 1 ) {
        return( ERR_NO_SUCH_LINE );
    }

    /*
     * get pointer to requested line
     */
    rc = CGimmeLinePtr( lineno, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
#if 0
    if( cline->u.ld.hidden ) {
        GetHiddenRange( lineno, &s, &e );
        if( lineno > CurrentPos.line ) {
            lineno = e + 1;
        } else {
            lineno = s - 1;
        }
        rc = CGimmeLinePtr( lineno, &cfcb, &cline );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }
#endif

    /*
     * compute new location
     */
    CurrentFcb = cfcb;
    CurrentLine = cline;
    diff = lineno - CurrentPos.line;
    if( diff == 0 && !EditFlags.GlobalInProgress ) {
        return( ERR_NO_ERR );
    }
    cwl = CurrentPos.line - LeftTopPos.line + 1;
    nwl = cwl + diff;

    /*
     * if we go off the window, relocate
     */
    pageshift = false;
    dispall = false;

    text_lines = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_LINES );
    if( nwl < 1 || nwl > text_lines ) {
        tl = text_lines / 2;
        if( !relcurs ) {
            LeftTopPos.line = lineno - tl;
        } else {
            LeftTopPos.line = lineno + 1 - cwl;
            pad = ( EditFlags.JumpyScroll ) ? 1 : 0;
            if( diff > 0 ) {
                LeftTopPos.line += pad;
                diff += pad;
            } else {
                LeftTopPos.line -= pad;
                diff -= pad;
            }
            if( diff > -tl && diff < tl && !dispall ) {
                pageshift = true;
            }
        }
        if( LeftTopPos.line < 1 ) {
            assert( diff <= 0 ); // < -> <= W.Briscoe 20031003 to avoid debug build failure of
            // C:\watcom\source\docs\nt) wmake -h -f ..\mif\master.mif hbook=wccerrs dotarget=nt
            diff += ( 1 - LeftTopPos.line );
            LeftTopPos.line = 1;
        }
        if( LeftTopPos.line > lineno ) {
            assert( diff > 0 );
            diff = LeftTopPos.line - lineno;
            LeftTopPos.line = lineno;
        }
        dispall = true;
    }
#if 0
    hiddcnt = GetHiddenLineCount( LeftTopPos.line, lineno );
    if( hiddcnt > 0 ) {
        pageshift = false;
        dispall = true;
    }
#endif

    if( CheckCurrentColumn() || EditFlags.Dragging ) {
        // pageshift wont help if we also have to column shift
        // and not really useful if dragging

        dispall = true;
        pageshift = false;
    }


    /* call SetCurrentLineNumber AFTER LeftTopPos.line set & CurrentColumn checked
    */
    SetCurrentLineNumber( lineno );

    if( pageshift ) {
        dispall = false;
        ShiftWindowUpDown( current_window_id, diff );
        if( EditFlags.LineNumbers ) {
            ShiftWindowUpDown( curr_num_window_id, diff );
        }
        if( diff > 0 ) {
            DCDisplaySomeLines( text_lines - diff, text_lines - 1 );
        } else {
            DCDisplaySomeLines( 0, -diff - 1 );
        }
    }
    UpdateStatusWindow();
    SetWindowCursor();
    if( dispall ) {
        DCInvalidateAllLines(); // lines definitely invalid
        DCDisplayAllLines();
    }
    return( ERR_NO_ERR );

} /* goToLine */