Ejemplo n.º 1
0
vi_rc GetNewValueDialog( char *value )
{
    bool        ret;
    vi_rc       rc;
    char        st[MAX_STR];
    window_id   clw;
    static char prompt[] = "New:";

    rc = NewWindow2( &clw, &setvalw_info );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    WPrintfLine( clw, 1, "Old: %s", value );
    ret = ReadStringInWindow( clw, 2, prompt, st, MAX_STR - 1, NULL );
    CloseAWindow( clw );
    SetWindowCursor();
    KillCursor();
    if( !ret ) {
        return( NO_VALUE_ENTERED );
    }
    if( st[0] == 0 ) {
        return( NO_VALUE_ENTERED );
    }
    Expand( st, NULL );
    strcpy( value, st );
    return( ERR_NO_ERR );

} /* GetNewValueDialog */
Ejemplo n.º 2
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 */
Ejemplo n.º 3
0
/*
 * GetsnoopStringDialog - create dialog settings
 */
bool GetSnoopStringDialog( fancy_find **ff )
{
    FARPROC     proc;
    bool        rc;

#ifdef __NT__
    if( hInstShell == NULL ) {
        hInstShell = GetModuleHandle( "SHELL32.DLL" );
        pfnSHBrowseForFolder = (PFNSHBFF)GetProcAddress( hInstShell, "SHBrowseForFolderA" );
        pfnSHGetPathFromIDList = (PFNSHGPFIL)GetProcAddress( hInstShell, "SHGetPathFromIDListA" );
    }
#endif

    /* set case_ignore and extension defaults based on global settings
     * all other values are saved from the last fgrep before
     */
    snoopData.case_ignore = EditFlags.CaseIgnore;
    ReplaceString( &snoopData.ext, EditVars.GrepDefault );
    *ff = &snoopData; /* data is no longer copied */
    proc = MakeDlgProcInstance( SnoopDlgProc, InstanceHandle );
#ifdef __NT__
    if( pfnSHBrowseForFolder != NULL ) {
        rc = DialogBox( InstanceHandle, "SNOOPDLG95", root_window_id, (DLGPROC)proc );
    } else {
#endif
        rc = DialogBox( InstanceHandle, "SNOOPDLG", root_window_id, (DLGPROC)proc );
#ifdef __NT__
    }
#endif
    FreeProcInstance( proc );
    SetWindowCursor();
    return( rc );

} /* GetsnoopStringDialog */
Ejemplo n.º 4
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 */
Ejemplo n.º 5
0
void DCUpdateAll( void )
{
    info        *curr, *info;
    bool        saved_cinfo;

    if( EditFlags.Quiet ) {
        return;
    }

    saved_cinfo = false;
    info = CurrentInfo;
    for( curr = info; curr != NULL; curr = curr->next ) {
        if( curr->CurrentFile->needs_display ) {
            if( !saved_cinfo ) {
                SaveCurrentInfo();
                saved_cinfo = true;
            }
            RestoreInfo( curr );
            DCUpdate();
            curr->CurrentFile->needs_display = false;
        }
    }
    if( saved_cinfo ) {
        RestoreInfo( info );
        SetWindowCursor();
    }
}
Ejemplo n.º 6
0
/*
 * DoneCurrentInsert - finished current insertion of text
 */
void DoneCurrentInsert( bool trim )
{
    if( EditFlags.InsertModeActive ) {
        EditFlags.InsertModeActive = FALSE;
        if( trim ) {
            trimWorkLine();
        }
        if( CurrentPos.column > WorkLine->len ) {
            if( EditFlags.Modeless ) {
                GoToColumnOK( WorkLine->len + 1 );
            } else {
                GoToColumnOK( WorkLine->len );
            }
        }
        doneWithCurrentLine();
        EndUndoGroup( UndoStack );
        if( !EditFlags.Modeless ) {
            NewCursor( CurrentWindow, EditVars.NormalCursorType );
            SetWindowCursor();
        }
        EditFlags.EscapedInsertChar = FALSE;
        EditFlags.NoReplaceSearchString = FALSE;
    }

} /* DoneCurrentInsert */
Ejemplo n.º 7
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 */
Ejemplo n.º 8
0
/*
 * GetReplaceStringDialog - create dialog settings
 */
bool GetReplaceStringDialog( fancy_find *ff )
{
    DLGPROC     proc;
    bool        rc;

    findData.find = ff->find;
    findData.findlen = ff->findlen;
    findData.replace = ff->replace;
    findData.replacelen = ff->replacelen;
    proc = (DLGPROC) MakeProcInstance( (FARPROC) RepDlgProc, InstanceHandle );
    rc = DialogBox( InstanceHandle, "REPDLG", Root, proc );
    FreeProcInstance( (FARPROC) proc );
    SetWindowCursor();

    if( strlen( findData.find ) == 0 ) {
        // no find string so pretend user cancelled
        rc = FALSE;
    }

    if( rc ) {
        ff->case_ignore = findData.case_ignore;
        ff->use_regexp = findData.use_regexp;
        // ff->search_forward = findData.search_forward;
        ff->search_wrap = findData.search_wrap;
        ff->prompt = findData.prompt;
        // ff->selection = findData.selection;
    }
    return( rc );

} /* GetReplaceStringDialog */
Ejemplo n.º 9
0
void ActiveWindow( window_id wid )
{
    if( !BAD_ID( wid ) ) {
        SetActiveWindow( wid );
        SetWindowCursor();
        SetWindowCursorForReal();
    }
}
Ejemplo n.º 10
0
/*
 * LocateCmd - parse a locate command (format: locate r,c[,len])
 */
vi_rc LocateCmd( const char *data )
{
    char        tmp[MAX_STR];
    linenum     r;
    int         c;
    int         len;

#ifdef __WIN__
    if( BAD_ID( current_window_id ) ) {
        return( ERR_INVALID_LOCATE );
    }
#endif
    data = GetNextWord1( data, tmp );
    if( *tmp == '\0' ) {
        return( ERR_INVALID_LOCATE );
    }
    r = atol( tmp );
    data = GetNextWord1( data, tmp );
    if( *tmp == '\0' ) {
        return( ERR_INVALID_LOCATE );
    }
    c = atoi( tmp );

    // real selection length
    while( isspace( *data ) ) {
        data++;
    }
    len = 0;
    if( *data != 0 ) {
        data = GetNextWord1( data, tmp );
        if( *tmp == '\0' ) {
            return( ERR_INVALID_LOCATE );
        }
        len = atoi( tmp );
    }

    GoToLineNoRelCurs( r );

    c = RealColumnOnCurrentLine( c );
    GoToColumnOnCurrentLine( c + len );

#ifdef __WIN__
    // likely only called by dde, which doesn't use event loop,
    // so must ensure cache ok and set cursor here

    DCInvalidateAllLines();
    DCDisplayAllLines();
    DCUpdate();
    SetWindowCursor();
    SetWindowCursorForReal();
#endif

    if( len > 0 ) {
        SetSelRegionCols( CurrentPos.line, c, c + len - 1 );
    }
    return( ERR_NO_ERR );

} /* LocateCmd */
Ejemplo n.º 11
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 */
Ejemplo n.º 12
0
/*
 * UpdateEditStatus - update current editing status
 */
void UpdateEditStatus( void )
{
    if( overStrike ) {
        UpdateCurrentStatus( CSTATUS_OVERSTRIKE );
        EditFlags.WasOverstrike = TRUE;
        NewCursor( CurrentWindow, EditVars.OverstrikeCursorType );
    } else {
        UpdateCurrentStatus( CSTATUS_INSERT );
        EditFlags.WasOverstrike = FALSE;
        NewCursor( CurrentWindow, EditVars.InsertCursorType );
    }
    SetWindowCursor();

} /* UpdateEditStatus */
Ejemplo n.º 13
0
/*
 * GetLineDialog - create dialog box & get result
 */
bool GetLineDialog( linenum *line )
{
    FARPROC     proc;
    bool        rc;

    lineStr[0] = '\0';
    lineVal = line;
    proc = MakeDlgProcInstance( GotoLineDlgProc, InstanceHandle );
    rc = DialogBox( InstanceHandle, "LINEDLG", Root, (DLGPROC)proc );
    FreeProcInstance( proc );
    SetWindowCursor();
    return( rc );

} /* GetLineDialog */
Ejemplo n.º 14
0
/*
 * ResetEditWindowCursor - display cursor on setfocus to a buffer
 */
void ResetEditWindowCursor( window_id id )
{
    if( !EditFlags.Modeless && !EditFlags.InsertModeActive ) {
        NewCursor( id, EditVars.NormalCursorType );
    } else {
        if( EditFlags.WasOverstrike ) {
            NewCursor( id, EditVars.OverstrikeCursorType );
        } else {
            NewCursor( id, EditVars.InsertCursorType );
        }
    }

    // position cursor in edit window
    SetWindowCursor();

} /* ResetEditWindowCursor */
Ejemplo n.º 15
0
/*
 * GetCmdDialog - create dialog settings
 */
bool GetCmdDialog( char *str, int len )
{
    DLGPROC     proc;
    bool        rc;

    cmdStr = str;
    cmdLen = len;
    proc = (DLGPROC) MakeProcInstance( (FARPROC) CmdDlgProc, InstanceHandle );
    rc = DialogBox( InstanceHandle, "CMDDLG", Root, proc );
    FreeProcInstance( (FARPROC) proc );

    /* this is technically a bug of some kind - if the above command
     * was a DDE message to another window to take focus, we will
     * temporarily be grabbing back the focus.  luckily this probably
     * won't happen too often.
     */
    SetWindowCursor();

    return( rc );

} /* GetCmdDialog */
Ejemplo n.º 16
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 */
Ejemplo n.º 17
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 */
Ejemplo n.º 18
0
/*
 * GoToColumn - go to a specified column
 */
vi_rc GoToColumn( int colno, int maxcol )
{
    int vc;

    if( CurrentFile == NULL ) {
        return( ERR_NO_FILE );
    }

    if( maxcol == 0 ) {
        maxcol = 1;
    }
    if( colno == 0 ) {
        colno = 1;
    }
    if( colno < 1 || colno > maxcol ) {
        return( ERR_NO_SUCH_COLUMN );
    }

    /*
     * compute new location, and re-display text if needed
     */
    VirtualColumnDesired = VirtualColumnOnCurrentLine( colno );
    CurrentPos.column = colno;
    if( !CheckLeftColumn() ) {
        DCDisplayAllLines();
        PositionHorizontalScrollThumb( current_window_id, LeftTopPos.column );
    }

    SetWindowCursor();
    vc = VirtualColumnOnCurrentLine( CurrentPos.column );
    UpdateStatusWindow();
    VarAddGlobalLong( "C", (long) vc );
    UpdateCursorDrag();
    return( ERR_NO_ERR );

} /* GoToColumn */
Ejemplo n.º 19
0
/*
 * NewFile - load up a new file
 */
vi_rc NewFile( char *name, bool same_file )
{
    vi_rc       rc;
    bool        dup;
    status_type oldstatus;

    dup = EditFlags.DuplicateFile;
    EditFlags.DuplicateFile = false;
    oldstatus = UpdateCurrentStatus( CSTATUS_READING );

    ScreenPage( 1 );
#ifdef __WIN__
    EditFlags.ResizeableWindow = true;
#endif
    rc = createNewFile( name, same_file );
    if( rc != ERR_NO_ERR && rc != NEW_FILE ) {
        ScreenPage( -1 );
        if( !EditFlags.Starting ) {
            MoveWindowToFrontDammit( MessageWindow, true );
            MoveWindowToFrontDammit( CurrentWindow, true );
        }
        UpdateCurrentStatus( oldstatus );
        return( rc );
    }
    GoToLineNoRelCurs( 1 );
    GoToColumnOnCurrentLine( 1 );
    FileSPVAR();
    SaveCurrentInfo();
    if( !same_file ) {
        inReadHook++;
        rc = SourceHook( SRC_HOOK_READ, rc );
        inReadHook--;
    }

    /*
     * back from hook, so all loadings are done
     * (who should have priority - hook or fts commands?)
     */
#if 0
    rc = FTSRunCmds( CurrentFile->name );
    FTSRunCmds( CurrentFile->name );
#endif

    /*
     * reset the screen to the display page, display everything
     */
    ScreenPage( -1 );
    MoveWindowToFrontDammit( CurrentWindow, true );
    UpdateStatusWindow();
    SetWindowCursor();
    DCDisplayAllLines();
    EditFlags.DuplicateFile = dup;
    DisplayFileStatus();
    SaveCurrentInfo();
    ActiveWindow( CurrentWindow );
    VarAddRandC();
    SetModifiedVar( false );
    UpdateCurrentStatus( oldstatus );
    if( !same_file && !inReadHook ) {
        UpdateLastFileList( CurrentFile->name );
    }
#ifdef __WIN__
    DCUpdateAll();
    ResetEditWindowCursor( CurrentWindow );
    SetWindowCursorForReal();
    GotoFile( CurrentWindow );
#endif
    return( rc );

} /* NewFile */
Ejemplo n.º 20
0
/*
 * MainWindowProc - procedure for main (root) window
 */
WINEXPORT LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
    RECT        rect;
    vi_rc       rc;
    HANDLE      hfileinfo;
    int         cnt, i;
    char        *buff;

    switch( msg ) {
    case WM_CREATE:
        Root = hwnd;
        GetClientRect( hwnd, &rect );
        EditContainer = CreateContainerWindow( &rect );
        InitWindows();
        DragAcceptFiles( hwnd, TRUE );
        timerID = SetTimer( hwnd, TIMER_ID, 60L * 1000L, NULL );
        break;
    case WM_DROPFILES:
        hfileinfo = (HANDLE) wparam;
        cnt = DragQueryFile( hfileinfo, (UINT)-1, NULL, 0 );
        buff = alloca( FILENAME_MAX + 2 );   /* we add a " at the beginning and at the end so we can handle path- and filenames with spaces */
        if( buff != NULL ) {
            buff[0] = '"';      /* one " at the beginning of the filename */
            for( i = 0; i < cnt; i++ ) {
                if( DragQueryFile( hfileinfo, i, buff + 1, FILENAME_MAX ) == (UINT)-1 ) {
                    break;
                }
                strcat( buff, "\"" );
                rc = EditFile( buff, FALSE );
                if( rc > ERR_NO_ERR ) {
                    Error( GetErrorMsg( rc ) );
                }
            }
        }
        DragFinish( hfileinfo );
        break;
    case WM_TIMER:
        UpdateStatusWindow();
        break;
    case WM_KEYDOWN:
        if( WindowsKeyPush( wparam, HIWORD( lparam ) ) ) {
            return( 0 );
        }
        break;
    case WM_SIZE:
        DefFrameProc( hwnd, EditContainer, msg, wparam, lparam );
        RootState = wparam;
        if( wparam != SIZE_MINIMIZED ) {
            ResizeRoot();
            GetWindowRect( hwnd, &RootRect );
            if( wparam != SIZE_MAXIMIZED ) {
                RootState = 0;
            }
        }
        return( 0 );
    case WM_MOVE:
        DefFrameProc( hwnd, EditContainer, msg, wparam, lparam );
        if( RootState != SIZE_MINIMIZED ) {
            GetWindowRect( hwnd, &RootRect );
        }
        return( 0 );
    case WM_ACTIVATEAPP:
        if( BAD_ID( CurrentWindow ) ) {
            break;
        }
        SetFocus( Root );
#if 0
        if( !wparam ) {
            InactiveWindow( CurrentWindow );
        } else {
            SendMessage( EditContainer, WM_MDIACTIVATE, (WPARAM)CurrentWindow, 0L );
        }
#endif
        if( wparam ) {
            ResetEditWindowCursor( CurrentWindow );
        } else {
            GoodbyeCursor( CurrentWindow );
        }
        break;
    case WM_MOUSEACTIVATE:
        SetFocus( hwnd );
        return( MA_ACTIVATE );
    case WM_SETFOCUS:
        if( BAD_ID( CurrentWindow ) ) {
            break;
        }
        if( !IsIconic( CurrentWindow ) ) {
            SendMessage( EditContainer, WM_MDIACTIVATE, (WPARAM)CurrentWindow, 0L );
            DCUpdate();
            SetWindowCursor();
            SetWindowCursorForReal();
            return( 0 );
        }
        break;
    case WM_NCLBUTTONDBLCLK:
        break;
    case WM_COMMAND:
        if( LOWORD( wparam ) > 0xF000 ) {
            break;
        } else {
            rc = MenuCommand( LOWORD( wparam ) );
            if( rc != MENU_COMMAND_NOT_HANDLED ) {
                DCUpdateAll();
                if( rc > ERR_NO_ERR ) {
                    char        *msg;
                    msg = GetErrorMsg( rc );
                    Error( msg );
                }
            }
            SetWindowCursor();
        }
        return( 0 );
    case WM_INITMENU:
        if( (HMENU)wparam == GetMenu( hwnd ) ) {
            HandleInitMenu( (HMENU)wparam );
        } else {
            ResetMenuBits();
        }
        break;
    case WM_MENUSELECT:
        HandleMenuSelect( wparam, lparam );
        break;
    case WM_ENDSESSION:
        if( wparam ) {
            ExitEditor( 0 );
            // will not return
        }
        return( 0 );
    case WM_QUERYENDSESSION:
        return( ExitWithPrompt( FALSE, TRUE ) );
    case WM_CLOSE:
        ExitWithPrompt( TRUE, TRUE );
        return( 0 );
#ifdef __NT__        
    case WM_MOUSEWHEEL:
        {
            int     i, increment;
            ULONG   linesPerNotch;
            HWND    activeWnd;
            
            activeWnd = (HWND)SendMessage( EditContainer, WM_MDIGETACTIVE, 0, 0 );
            SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &linesPerNotch, 0 );
            
            increment = GET_WHEEL_DELTA_WPARAM( wparam ) / 120;
                // see WM_MOUSEWHEEL-documentation for information about the "120"

            if( increment > 0 ) {
                for( i = 0; i < increment * (int)linesPerNotch; i++ ) {
                    SendMessage( activeWnd, WM_VSCROLL, SB_LINEUP, 0 );
                }
            } else {
                for( i = 0; i < (-increment) * (int)linesPerNotch; i++ ) {
                    SendMessage( activeWnd, WM_VSCROLL, SB_LINEDOWN, 0 );
                }
            }
        }
        return( 0 );
#endif
    case WM_DESTROY:
        DestroyToolBar();
        DragAcceptFiles( hwnd, FALSE );
        EditContainer = 0;
        if( timerID ) {
            KillTimer( hwnd, TIMER_ID );
        }
        return( 0 );
    }
    return( DefFrameProc( hwnd, EditContainer, msg, wparam, lparam ) );

} /* MainWindowProc */
Ejemplo n.º 21
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 */
Ejemplo n.º 22
0
/*
 * Shift - shove a tab in/out over a line range
 */
vi_rc Shift( linenum s, linenum e, char dir, bool msgflag )
{
    int         shv;
    linenum     fullcnt = 0;
    vi_rc       rc;

    /*
     * set up undo
     */
    if( rc = ModificationTest() ) {
        return( rc );
    }
    rc = UndoReplaceLines( s, e );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    /*
     * now, point to start line
     */
    rc = SaveAndResetFilePos( s );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    /*
     * process all lines
     */
    for( CurrentPos.line = s; CurrentPos.line <= e; CurrentPos.line++ ) {

        /*
         * Add/Subtract leading tab space
         */
        GetCurrentLine();
        shv = ShiftWidth;
        if( dir != '>' ) {
            shv *= -1;
        }
        if( AddLeadingTabSpace( &WorkLine->len, WorkLine->data, shv ) ) {
            ++fullcnt;
        }
        ReplaceCurrentLine();

        if( CurrentPos.line != e ) {
            rc = CGimmeNextLinePtr( &CurrentFcb, &CurrentLine );
            if( rc != ERR_NO_ERR ) {
                RestoreCurrentFilePos();
                return( rc );
            }
        }

    }

    /*
     * done, say so and go back
     */
    RestoreCurrentFilePos();
    if( msgflag ) {
        Message1( "%l lines %c'ed", e - s + 1, dir );
        if( fullcnt > 0 ) {
            Message2( "%l full lines not processed", fullcnt );
        }
    }
    if( CurrentPos.line >= s && CurrentPos.line <= e ) {
        CheckCurrentColumn();
    }
    DCDisplayAllLines();
    SetWindowCursor();
    Modified( TRUE );
    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* Shift */
Ejemplo n.º 23
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 */
Ejemplo n.º 24
0
/*
 * processSetToken - set value for set token
 */
static vi_rc processSetToken( int j, char *value, int *winflag, bool isnonbool )
{
    char        fn[MAX_STR], str[MAX_STR];
#ifndef VICOMP
    char        tmp[3];
    char        settokstr[TOK_MAX_LEN + 1];
    char        save[MAX_STR];
    vi_rc       rc = ERR_NO_ERR;
    int         i, clr, k;
    bool        newset;
    bool        set1, toggle, *ptr;
    jmp_buf     jmpaddr;
    cursor_type ct;
    char        *name;
    command_rtn fptr;
    event_bits  eb;
    bool        redisplay = FALSE;
#endif
    bool        bvalue;

#ifdef VICOMP
    winflag = winflag;
    isnonbool = isnonbool;
#endif
    /*
     * set up value for boolean set commands
     */
    if( j < 0 ) {
        j *= -1;
        bvalue = FALSE;
    } else {
        bvalue = TRUE;
    }
#ifndef VICOMP
    if( !(*winflag) ) {
        toggle = TRUE;
        set1 = isnonbool;
    } else {
        toggle = FALSE;
#endif
        if( j >= SET1_T_ ) {
#ifndef VICOMP
            if( EditFlags.CompileScript ) {
#endif
                if( !bvalue ) {
                    j *= -1;
                }
                itoa( j, str, 10 );
                StrMerge( 2, WorkLine->data, str, SingleBlank );
                return( ERR_NO_ERR );
#ifndef VICOMP
            }
            set1 = FALSE;
            j -= SET1_T_;
        } else {
            set1 = TRUE;
#endif
        }
#ifndef VICOMP
    }
    *winflag = FALSE;

    /*
     * process boolean settings
     */
    if( !set1 ) {
        if( j >= SET2_T_ ) {
            return( ERR_INVALID_SET_COMMAND );
        }
        ptr = &(((bool *)&EditFlags)[j]);
        newset = bvalue;
        if( toggle ) {
            newset = !(*ptr);
        }
        switch( j ) {
        case SET2_T_MODELESS:
            if( (newset && !EditFlags.Modeless) ||
                (!newset && EditFlags.Modeless) ) {
                for( k = 0; k < MAX_EVENTS; k++ ) {
                    fptr = EventList[k].rtn;
                    eb = EventList[k].b;
                    EventList[k].rtn = EventList[k].alt_rtn;
                    EventList[k].alt_rtn = fptr;
                    EventList[k].b = EventList[k].alt_b;
                    EventList[k].alt_b = eb;
                }
                if( !EditFlags.Modeless ) {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_INSERT );
                    }
                    EditFlags.WasOverstrike = FALSE;
                    NewCursor( CurrentWindow, EditVars.InsertCursorType );
                } else {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_COMMAND );
                    }
                    NewCursor( CurrentWindow, EditVars.NormalCursorType );
                    // nomodeless must be line based or it dies!
                    EditFlags.LineBased = TRUE;
                }
                /* re-position cursor in window
                */
                SetWindowCursor();
            }
            EditFlags.Modeless = newset;
            break;
        case SET2_T_UNDO:
            if( EditFlags.Undo && !newset ) {
                FreeAllUndos();
            }
            EditFlags.Undo = newset;
            break;
        case SET2_T_STATUSINFO:
            EditFlags.StatusInfo = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            rc = NewStatusWindow();
            break;
        case SET2_T_WINDOWGADGETS:
            EditFlags.WindowGadgets = newset;
            ResetAllWindows();
            *winflag = TRUE;
            redisplay = TRUE;
            break;
        case SET2_T_REALTABS:
            EditFlags.RealTabs = newset;
            redisplay = TRUE;
            break;
        case SET2_T_CLOCK:
            EditFlags.Clock = newset;
            redisplay = TRUE;
            break;
        case SET2_T_TOOLBAR:
            EditFlags.Toolbar = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            break;
        case SET2_T_COLORBAR:
            EditFlags.Colorbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Colorbar = FALSE;
            } else {
                RefreshColorbar();
            }
#endif
            break;
        case SET2_T_SSBAR:
            EditFlags.SSbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.SSbar = FALSE;
            } else {
                RefreshSSbar();
            }
#endif
            break;
        case SET2_T_FONTBAR:
            EditFlags.Fontbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Fontbar = FALSE;
            } else {
                RefreshFontbar();
            }
#endif
            break;
        case SET2_T_MARKLONGLINES:
            EditFlags.MarkLongLines = newset;
            break;
        case SET2_T_MENUS:
            EditFlags.Menus = newset;
            InitMenu();
            break;
        case SET2_T_LINENUMBERS:
            if( toggle ) {
                newset = !EditFlags.LineNumbers;
            }
            if( newset != EditFlags.LineNumbers ) {
                EditFlags.LineNumbers = newset;
                rc = LineNumbersSetup();
                *winflag = TRUE;
            }
            break;
        case SET2_T_CURRENTSTATUS:
            EditFlags.CurrentStatus = newset;
            InitMenu();
            break;
        case SET2_T_DISPLAYSECONDS:
            EditFlags.DisplaySeconds = newset;
            redisplay = TRUE;
            break;
        case SET2_T_PPKEYWORDONLY:
            EditFlags.PPKeywordOnly = newset;
            redisplay = TRUE;
            break;
        case SET2_T_LASTEOL:
#ifndef __WIN__
            *ptr = TRUE;
            toggle = FALSE;
            break;
#endif
        default:
            *ptr = newset;
            break;
        }
        if( msgFlag ) {
            if( !newset ) {
                tmp[0] = 'n';
                tmp[1] = 'o';
                tmp[2] = 0;
            } else {
                tmp[0] = 0;
            }
            MySprintf( fn, "%s%s set", tmp, GetTokenStringCVT( SetTokens2, j, settokstr, TRUE ) );
        }
        if( toggle ) {
            strcpy( save, BoolStr[(int) newset] );
            (*winflag) += 1;
        }

    /*
     * process value settings
     */
    } else {
        if( toggle ) {
            rc = GetNewValueDialog( value );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            strcpy( save, value );
        }
#endif /* VICOMP */
        RemoveLeadingSpaces( value );
        if( value[0] == '"' ) {
            NextWord( value, fn, "\"" );
            EliminateFirstN( value, 1 );
        } else {
            NextWord1( value, fn );
        }
#ifndef VICOMP
        if( EditFlags.CompileScript ) {
#endif
            itoa( j, str, 10 );
            strcat( WorkLine->data, str );
            if( fn[0] == '\0' )
                return( ERR_NO_ERR );
            switch( j ) {
            case SET1_T_STATUSSTRING:
            case SET1_T_FILEENDSTRING:
            case SET1_T_HISTORYFILE:
            case SET1_T_TMPDIR:
            case SET1_T_TAGFILENAME:
                StrMerge( 4, WorkLine->data, SingleBlank, SingleQuote, fn, SingleQuote );
                break;
            case SET1_T_COMMANDCURSORTYPE:
            case SET1_T_OVERSTRIKECURSORTYPE:
            case SET1_T_INSERTCURSORTYPE:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            case SET1_T_TILECOLOR:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( NextWord1( value, str ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StrMerge( 4, WorkLine->data, fn, SingleBlank, str, SingleBlank );
                break;
            case SET1_T_STATUSSECTIONS:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                while( NextWord1( value, fn ) > 0 ) {
#ifdef VICOMP
                    int k;
#endif
                    k = atoi( fn );
                    if( k <= 0 ) {
                        break;
                    }
                    StrMerge( 2, WorkLine->data, SingleBlank, fn );
                }
                break;
            default:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            }
            return( ERR_NO_ERR );
#ifndef VICOMP
        }
        switch( j ) {
        case SET1_T_STATUSSECTIONS:
            if( EditVars.StatusSections != NULL ) {
                MemFree( EditVars.StatusSections );
                EditVars.StatusSections = NULL;
                EditVars.NumStatusSections = 0;
            }
            for( ;; ) {
                k = atoi( fn );
                if( k <= 0 ) {
                    break;
                }
                EditVars.StatusSections = MemReAlloc( EditVars.StatusSections,
                                    sizeof( short ) * (EditVars.NumStatusSections + 1) );
                EditVars.StatusSections[EditVars.NumStatusSections] = k;
                EditVars.NumStatusSections++;
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
            }
            if( EditVars.StatusSections == NULL ) {
                MySprintf( fn, "statussections turned off" );
            } else {
                MySprintf( fn, "statussections set" );
            }
            break;
        case SET1_T_FILEENDSTRING:
            AddString2( &EditVars.FileEndString, fn );
            ResetAllWindows();
            redisplay = TRUE;
            break;
        case SET1_T_STATUSSTRING:
            AddString2( &EditVars.StatusString, fn );
            if( StatusWindow != NO_WINDOW ) {
                ClearWindow( StatusWindow );
                UpdateStatusWindow();
            }
            if( msgFlag ) {
                MySprintf( fn, "statusstring set to %s", EditVars.StatusString );
            }
            break;
        case SET1_T_GREPDEFAULT:
            AddString2( &EditVars.GrepDefault, fn );
            break;
        case SET1_T_TILECOLOR:
            if( EditVars.TileColors == NULL ) {
                EditVars.TileColors = (type_style *) MemAlloc( sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( i = 0; i <= EditVars.MaxTileColors; ++i ) {
                    EditVars.TileColors[i].foreground = -1;
                    EditVars.TileColors[i].background = -1;
                    EditVars.TileColors[i].font = -1;
                }
            }
            clr = atoi( fn );
            if( clr > EditVars.MaxTileColors ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].foreground = atoi( fn );
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].background = atoi( fn );
            EditVars.TileColors[clr].font = FONT_DEFAULT;
            if( msgFlag ) {
                MySprintf( fn, "tilecolor %d set", clr );
            }
            break;
        case SET1_T_GADGETSTRING:
            SetGadgetString( fn );
            if( msgFlag ) {
                MySprintf( fn, "gadget string set to %s", EditVars.GadgetString );
            }
            ResetAllWindows();
            break;
        case SET1_T_SHELLPROMPT:
            AddString2( &EditVars.SpawnPrompt, fn );
            if( msgFlag ) {
                MySprintf( fn, "prompt string set to %s", EditVars.SpawnPrompt );
            }
            break;
        case SET1_T_FIGNORE:
            if( fn[0] == 0 ) {
                MemFreePtr( (void **)&EditVars.FIgnore );
                EditVars.CurrFIgnore = 0;
                if( msgFlag ) {
                    MySprintf( fn, "fignore reset" );
                }
            } else {
                EditVars.FIgnore = MemReAlloc( EditVars.FIgnore, EXTENSION_LENGTH * (EditVars.CurrFIgnore + 1) );
                str[0] = '.';
                str[1] = 0;
                strcat( str, fn );
                str[EXTENSION_LENGTH - 1] = 0;
                strcpy( &EditVars.FIgnore[EXTENSION_LENGTH * EditVars.CurrFIgnore], str );
                EditVars.CurrFIgnore++;
                if( msgFlag ) {
                    MySprintf( fn, "%s added to fignore", str );
                }
            }
            break;
        case SET1_T_HISTORYFILE:
            AddString2( &EditVars.HistoryFile, fn );
            if( msgFlag ) {
                MySprintf( fn, "history file set to %s", EditVars.HistoryFile );
            }
            break;

        case SET1_T_TAGFILENAME:
            AddString2( &EditVars.TagFileName, fn );
            if( msgFlag ) {
                MySprintf( fn, "tag file name set to %s", EditVars.TagFileName );
            }
            break;

        case SET1_T_FILENAME:
            if( CurrentFile != NULL ) {
                AddString2( &(CurrentFile->name), fn );
                SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE );
                if( msgFlag ) {
                    MySprintf( fn, "filename set to %s", CurrentFile->name );
                }
                FileSPVAR();
            }
            break;
        case SET1_T_TMPDIR:
            AddString2( &EditVars.TmpDir, fn );
            VerifyTmpDir();
            if( msgFlag ) {
                MySprintf( fn, "tmpdir set to %s", EditVars.TmpDir );
            }
            break;
        case SET1_T_WORD:
            AddString2( &EditVars.WordDefn, fn );
            InitWordSearch( EditVars.WordDefn );
            if( msgFlag ) {
                MySprintf( fn, "word set to %s", EditVars.WordDefn );
            }
            break;
        case SET1_T_WORDALT:
            AddString2( &EditVars.WordAltDefn, fn );
            if( msgFlag ) {
                MySprintf( fn, "wordalt set to %s", EditVars.WordAltDefn );
            }
            break;
        case SET1_T_MAGICSTRING:
            AddString2( &EditVars.Majick, fn );
            if( msgFlag ) {
                MySprintf( fn, "magicstring set to %s", EditVars.Majick );
            }
            break;
        case SET1_T_COMMANDCURSORTYPE:
        case SET1_T_OVERSTRIKECURSORTYPE:
        case SET1_T_INSERTCURSORTYPE:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            ct.height = GetConstExpr();
            if( NextWord1( value, fn ) <= 0 ) {
                ct.width = 100;
            } else {
                i = setjmp( jmpaddr );
                if( i != 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StartExprParse( fn, jmpaddr );
                ct.width = GetConstExpr();
            }
            if( j == SET1_T_COMMANDCURSORTYPE ) {
                EditVars.NormalCursorType = ct;
                name = "command";
            } else if( j == SET1_T_OVERSTRIKECURSORTYPE ) {
                EditVars.OverstrikeCursorType = ct;
                name = "overstrike";
            } else {
                EditVars.InsertCursorType = ct;
                name = "insert";
            }
            if( msgFlag ) {
                MySprintf( fn, "%s cursor type set to %d,%d", name,
                                ct.height, ct.width );
            }
            break;
        default:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            i = GetConstExpr();
            if( i < 0 ) {
                i = 0;
            }
            switch( j ) {
            case SET1_T_WRAPMARGIN:
                EditVars.WrapMargin = i;
                break;
            case SET1_T_CURSORBLINKRATE:
                SetCursorBlinkRate( i );
                break;
            case SET1_T_MAXPUSH:
                EditVars.MaxPush = i;
                if( EditVars.MaxPush < 1 ) {
                    EditVars.MaxPush = 1;
                }
                InitFileStack();
                break;
            case SET1_T_RADIX:
                EditVars.Radix = i;
                break;
            case SET1_T_AUTOSAVEINTERVAL:
                EditVars.AutoSaveInterval = i;
                SetNextAutoSaveTime();
                break;
            case SET1_T_LANGUAGE:
                if( i < LANG_NONE || i >= LANG_MAX ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( CurrentInfo != NULL ) {
                    LangFini( CurrentInfo->fsi.Language );
                    LangInit( i );
                    redisplay = TRUE;
                }
                break;
            case SET1_T_MOVECOLOR:
                EditVars.MoveColor = i;
                break;
            case SET1_T_RESIZECOLOR:
                EditVars.ResizeColor = i;
                break;
            case SET1_T_MOUSEDCLICKSPEED:
                EditVars.MouseDoubleClickSpeed = i;
                break;
            case SET1_T_MOUSESPEED:
                SetMouseSpeed( i );
                break;
            case SET1_T_MOUSEREPEATDELAY:
                EditVars.MouseRepeatDelay = i;
                break;
            case SET1_T_CURRENTSTATUSCOLUMN:
                EditVars.CurrentStatusColumn = i;
                InitMenu();
                break;
            case SET1_T_ENDOFLINECHAR:
                EditVars.EndOfLineChar = i;
                break;
            case SET1_T_EXITATTR:
                EditVars.ExitAttr = (char) i;
                break;
            case SET1_T_INACTIVEWINDOWCOLOR:
                EditVars.InactiveWindowColor = i;
                break;
            case SET1_T_TABAMOUNT:
                EditVars.TabAmount = i;
                break;
            case SET1_T_SHIFTWIDTH:
                EditVars.ShiftWidth = i;
                break;
            case SET1_T_PAGELINESEXPOSED:
                EditVars.PageLinesExposed = i;
                break;
            case SET1_T_HARDTAB:
                EditVars.HardTab = i;
                redisplay = TRUE;
                break;
            case SET1_T_STACKK:
                if( EditFlags.Starting ) {
                    EditVars.StackK = i;
                }
                break;
            case SET1_T_LINENUMWINWIDTH:
                EditVars.LineNumWinWidth = i;
                break;
            case SET1_T_MAXWINDOWTILEX:
                EditVars.MaxWindowTileX = i;
                break;
            case SET1_T_MAXWINDOWTILEY:
                EditVars.MaxWindowTileY = i;
                break;
            case SET1_T_MAXSWAPK:
                SwapBlockInit( i );
                break;
            case SET1_T_MAXEMSK:
#ifndef NOEMS
                EMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXXMSK:
#ifndef NOXMS
                XMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXFILTERHISTORY:
                FilterHistInit( i );
                break;
            case SET1_T_MAXCLHISTORY:
                CLHistInit( i );
                break;
            case SET1_T_MAXFINDHISTORY:
                FindHistInit( i );
                break;
            case SET1_T_MAXLASTFILESHISTORY:
                LastFilesHistInit( i );
                break;
            case SET1_T_MAXTILECOLORS:
                k = (EditVars.TileColors == NULL) ? 0 : EditVars.MaxTileColors + 1;
                EditVars.MaxTileColors = i;
                EditVars.TileColors = MemReAlloc( EditVars.TileColors, sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( ; k <= EditVars.MaxTileColors; ++k ) {
                    EditVars.TileColors[k].foreground = -1;
                    EditVars.TileColors[k].background = -1;
                    EditVars.TileColors[k].font = -1;
                }
                break;
            case SET1_T_CLOCKX:
                EditVars.ClockX = i;
                GetClockStart();
                break;
            case SET1_T_CLOCKY:
                EditVars.ClockY = i;
                GetClockStart();
                break;
            case SET1_T_SPINX:
                EditVars.SpinX = i;
                GetSpinStart();
                break;
            case SET1_T_SPINY:
                EditVars.SpinY = i;
                GetSpinStart();
                break;
            case SET1_T_MAXLINELEN:
                /* file save fails if 1 line is > MAX_IO_BUFFER */
                i = __min( i, MAX_IO_BUFFER );
                EditVars.MaxLine = i;
                StaticStart();
                WorkLine = MemReAlloc( WorkLine, sizeof( line ) + EditVars.MaxLine + 2 );
                break;
            case SET1_T_TOOLBARBUTTONHEIGHT:
                EditVars.ToolBarButtonHeight = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARBUTTONWIDTH:
                EditVars.ToolBarButtonWidth = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARCOLOR:
                EditVars.ToolBarColor = i;
#ifdef __WIN__
                if( GetToolbarWindow() != NULL ) {
                    InvalidateRect( GetToolbarWindow(), NULL, TRUE );
                    UpdateWindow( GetToolbarWindow() );
                }
#endif
                break;
            default:
                return( ERR_INVALID_SET_COMMAND );
            }

            if( msgFlag ) {
                MySprintf( fn, "%s set to %d", GetTokenStringCVT( SetTokens1, j, settokstr, TRUE ), i );
            }
            break;
        }
    }

    if( msgFlag && rc == ERR_NO_ERR && !EditFlags.Quiet ) {
        setMessage( fn, redisplay );
        rc = DO_NOT_CLEAR_MESSAGE_WINDOW;
    }
    if( rc == ERR_NO_ERR && toggle ) {
        strcpy( value, save );
    }
    return( rc );
#endif /* VICOMP */

} /* processSetToken */
Ejemplo n.º 25
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 */