/* * SetSelectedRegion - set the selected region to a specific area */ vi_rc SetSelectedRegion( range *r ) { vi_rc rc; line *line; fcb *fcb; UnselectRegion(); SelRgn.start.line = r->start.line; SelRgn.end.line = r->end.line; SelRgn.start_col_v = 1; if( r->line_based ) { SelRgn.lines = TRUE; SelRgn.start.column = 1; SelRgn.end.column = LineLength( r->end.line ); } else { SelRgn.lines = FALSE; if( r->start.column < r->end.column ) { SelRgn.start.column = r->start.column + 1; SelRgn.end.column = r->end.column + 2; } else { SelRgn.start.column = r->end.column + 1; SelRgn.end.column = r->start.column + 2; } rc = CGimmeLinePtr( SelRgn.start.line, &fcb, &line ); if( rc == ERR_NO_ERR ) { SelRgn.start_col_v = WinVirtualCursorPosition( line->data, SelRgn.start.column ); } } SelRgn.selected = TRUE; updateRegion(); return( ERR_NO_ERR ); } /* SetSelectedRegion */
/* * myToolBarProc - called by toolbar window proc */ static bool myToolBarProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l ) { switch( msg ) { case WM_KILLFOCUS: UnselectRegion(); break; case WM_LBUTTONDBLCLK: // flip the current state of the toolbar - if we are fixed then start to float or vice versa // newToolBarWindow(); // return( true ); break; case WM_MOVE: case WM_SIZE: // Whenever we are moved or sized as a floating toolbar, we // remember our position so that we can restore it when dbl. clicked if( !fixedToolBar && userClose ) { DefWindowProc( hwnd, msg, w, l ); GetWindowRect( hwnd, &ToolBarFloatRect ); } return( false ); case WM_DESTROY: if( userClose ) { // the user closed the toolbar so remember this EditFlags.Toolbar = false; } break; } return( false ); } /* myToolBarProc */
/* * NullResponse - give null response for keystroke */ vi_rc NullResponse( void ) { if( !EditFlags.EscapeMessage ) { ClearWindow( MessageWindow ); } else { DisplayFileStatus(); } UnselectRegion(); return( ERR_NO_ERR ); } /* NullResponse */
/* * Modified - set file modified flag */ void Modified( bool f ) { if( f ) { CurrentFile->need_autosave = true; if( EditFlags.ReadOnlyCheck ) { if( CFileReadOnly() ) { EditFlags.ReadOnlyError = true; } } } if( CurrentFile->modified != f ) { CurrentFile->modified = f; SetModifiedVar( f ); } UnselectRegion(); } /* Modified */
/* * startSelectedRegion - start selection region area from keyboard */ int startSelectedRegion( bool line_based ) { if( ShiftDown() && SelRgn.selected ) { EditFlags.Dragging = TRUE; UpdateCursorDrag(); } else { if( SelRgn.selected ) { UnselectRegion(); return( ERR_NO_ERR ); } EditFlags.Dragging = TRUE; InitSelectedRegion(); SelRgn.lines = line_based; SelRgn.selected = TRUE; updateRegion(); } return( ERR_NO_ERR ); } /* startSelectedRegion */
/* * DoSelectSelection - selected region was selected, invoke aprops script */ vi_rc DoSelectSelection( bool doMenu ) { linenum sl, el, tl; int sc, ec, tc; vi_rc rc = ERR_NO_ERR; if( SelRgn.selected && doMenu ) { sl = SelRgn.start.line; el = SelRgn.end.line; if( sl > el ) { tl = sl; sl = el; el = tl; } if( CurrentPos.line >= sl && CurrentPos.line <= el ) { if( sl == el && !SelRgn.lines ) { sc = SelRgn.start.column; ec = SelRgn.end.column; if( sc > ec ) { sc--; tc = sc; sc = ec; ec = tc; } else if( sc < ec ) { ec--; } if( CurrentPos.column >= sc && CurrentPos.column <= (ec + 1) ) { rc = InvokeColSelHook( sc, ec ); } } else { rc = InvokeLineSelHook( SelRgn.start.line, SelRgn.end.line ); } UnselectRegion(); return( rc ); } UnselectRegion(); } if( ShiftDown() && LastEvent != '_' ) { sc = 1; ec = CurrentLine->len; SetSelRegionCols( CurrentPos.line, sc, ec ); if( doMenu ) { rc = InvokeLineSelHook( CurrentPos.line, CurrentPos.line ); } } else { rc = GimmeCurrentEntireWordDim( &sc, &ec, FALSE ); if( rc != ERR_NO_ERR ) { return( ERR_NO_ERR ); } SetSelRegionCols( CurrentPos.line, sc, ec ); if( doMenu ) { rc = InvokeColSelHook( sc, ec ); } } if( doMenu ) { UnselectRegion(); } return( rc ); } /* DoSelectSelection */
/* * DoLastEvent - process the last keystroke event */ vi_rc DoLastEvent( void ) { event *event; vi_rc rc; bool keep_sel; if( LastEvent >= MAX_EVENTS ) { rc = InvalidKey(); } else if( !EditFlags.Modeless && EditFlags.InsertModeActive ) { // UnselectRegion(); if( EditFlags.EscapedInsertChar ) { rc = IMChar(); } else if( InputKeyMaps[LastEvent].data != NULL && !InputKeyMaps[LastEvent].inuse ) { rc = StartInputKeyMap( LastEvent ); } else { rc = (EventList[LastEvent].ins)(); } } else if( !EditFlags.Modeless && KeyMaps[LastEvent].data != NULL && !KeyMaps[LastEvent].inuse ) { rc = DoKeyMap( LastEvent ); } else { event = &EventList[LastEvent]; keep_sel = event->b.keep_selection; if( event->b.keep_selection_maybe ) { if( SelRgn.selected ) { keep_sel = true; } } if( !keep_sel && !EditFlags.ScrollCommand ) { UnselectRegion(); } if( !EditFlags.ScrollCommand ) { ensureCursorDisplayed(); } rc = ERR_NO_ERR; switch( event->b.type ) { case EVENT_INS: if( EditFlags.Modeless ) { /* don't allow following cursor movements to affect seln */ keep_sel = SelRgn.selected; DeleteSelectedRegion(); SelRgn.selected = keep_sel; InsertLikeLast(); rc = event->rtn.ins(); DoneCurrentInsert( false ); SelRgn.selected = false; } else { if( !EditFlags.InsertModeActive ) { InsertLikeLast(); } rc = event->rtn.ins(); } break; case EVENT_OP: DoneCurrentInsert( true ); rc = doOperator( event ); break; case EVENT_REL_MOVE: case EVENT_ABS_MOVE: DoneCurrentInsert( true ); rc = DoMove( event ); break; case EVENT_MISC: DoneCurrentInsert( true ); rc = event->rtn.old(); break; } } return( rc ); } /* DoLastEvent */
/* * HandleMouseEvent - handle main editor mouse events */ vi_rc HandleMouseEvent( void ) { windim win_x, win_y; window_id wid; info *cinfo; window *w; int i; bool diff_word; vi_rc rc; wid = GetMousePosInfo( &win_x, &win_y ); if( BAD_ID( wid ) ) { return( ERR_NO_ERR ); } w = WINDOW_FROM_ID( wid ); if( !w->has_border ) { win_x += 1; win_y += 1; } if( dragThumb ) { if( LastMouseEvent == MOUSE_RELEASE ) { dragThumb = false; } if( wid != current_window_id ) { return( ERR_NO_ERR ); } if( win_x == w->width - 1 ) { return( PositionToNewThumbPosition( w, win_y ) ); } return( ERR_NO_ERR ); } if( EditFlags.Dragging ) { if( LastMouseEvent == MOUSE_DRAG || LastMouseEvent == MOUSE_REPEAT ) { UpdateDrag( wid, win_x, win_y ); } else { if( LastMouseEvent == MOUSE_PRESS_R || LastMouseEvent == MOUSE_PRESS ) { EditFlags.Dragging = false; if( LastMouseEvent == MOUSE_PRESS_R ) { LastMouseEvent = MOUSE_RELEASE_R; } } } } if( LastMouseEvent == MOUSE_RELEASE_R || LastMouseEvent == MOUSE_DCLICK ) { if( wid == current_window_id && InsideWindow( wid, win_x, win_y ) ) { diff_word = (LastMouseEvent == MOUSE_DCLICK); if( GoToLineRelCurs( LeftTopPos.line + win_y - 1 ) ) { return( ERR_NO_ERR ); } win_x += LeftTopPos.column; win_x = RealColumnOnCurrentLine( win_x ); GoToColumnOnCurrentLine( win_x ); if( diff_word ) { InitWordSearch( EditVars.WordAltDefn ); } rc = DoSelectSelection( true ); if( diff_word ) { InitWordSearch( EditVars.WordDefn ); } return( rc ); } } /* * all kinds of stuff to do if the button was pressed */ if( LastMouseEvent == MOUSE_PRESS || LastMouseEvent == MOUSE_PRESS_R ) { if( wid != current_window_id ) { /* * swap to another window */ for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { if( wid == cinfo->current_window_id ) { BringUpFile( cinfo, true ); break; } } } if( wid == current_window_id ) { if( !ShiftDown() ) { UnselectRegion(); } if( w->has_border && LastMouseEvent == MOUSE_PRESS ) { /* * clicked on menu for window */ if( win_x == 0 && win_y == 0 ) { return( DoWindowGadgetMenu() ); } /* * check for resize request */ if( win_x == w->width - 1 && win_y == w->height - 1 ) { return( ResizeCurrentWindowWithMouse() ); } /* * check for move request */ if( win_y == 0 ) { return( MoveCurrentWindowWithMouse() ); } } /* * check for locate cursor */ if( InsideWindow( wid, win_x, win_y ) ) { if( ShiftDown() ) { EditFlags.Dragging = true; } if( GoToLineRelCurs( LeftTopPos.line + win_y - 1 ) ) { return( ERR_NO_ERR ); } win_x += LeftTopPos.column; win_x = RealColumnOnCurrentLine( win_x ); GoToColumnOnCurrentLine( win_x ); if( ShiftDown() ) { EditFlags.Dragging = false; } else { InitSelectedRegion(); } return( ERR_NO_ERR ); } } if( EditFlags.Menus && wid == menu_window_id ) { i = GetMenuIdFromCoord( win_x - 1 ); if( i >= 0 ) { return( SetToMenuId( i ) ); } } } /* * allow double click to close window */ if( wid == current_window_id && LastMouseEvent == MOUSE_DCLICK ) { if( win_y == 0 && win_x == 0 ) { return( NextFile() ); } } /* * try to scroll screen */ if( (LastMouseEvent == MOUSE_REPEAT || LastMouseEvent == MOUSE_DCLICK || LastMouseEvent == MOUSE_PRESS) && w->has_border && wid == current_window_id && win_x == w->width - 1 ) { if( win_y == w->height - 2 ) { return( MoveScreenDown() ); } if( win_y == 1 ) { return( MoveScreenUp() ); } /* * if we have gadgets, then scroll based on position of scroll * thumb. furthermore, if the thumb is selected, then begin * thumb dragging mode */ if( w->has_gadgets ) { if( win_y == w->vert_scroll_pos ) { dragThumb = true; return( ERR_NO_ERR ); } else if( win_y < w->vert_scroll_pos ) { return( MovePageUp() ); } else { return( MovePageDown() ); } } else { if( win_y < w->height / 2 ) { return( MovePageUp() ); } else { return( MovePageDown() ); } } } /* * start dragging */ if( wid == current_window_id && (LastMouseEvent == MOUSE_DRAG || LastMouseEvent == MOUSE_DRAG_R ) && InsideWindow( wid, win_x, win_y ) ) { EditFlags.Dragging = true; UpdateDrag( wid, win_x, win_y ); } return( ERR_NO_ERR ); } /* HandleMouseEvent */
vi_rc Change( range *r ) { int scol, ecol; int tmp; vi_rc rc; vi_key key; #ifndef __WIN__ int vecol; #endif /* * change line ranges */ if( r->start.line != r->end.line ) { StartUndoGroup( UndoStack ); if( !r->line_based ) { rc = Cut( r->start.line, r->start.column, r->end.line, r->end.column, true ); r->end.column = -1; scol = -1; ecol = -1; } else { if( r->start.line == CurrentPos.line ) { r->start.line++; } else { r->end.line--; } if( r->start.line <= r->end.line ) { rc = DeleteLineRange( r->start.line, r->end.line, 0 ); if( rc != ERR_NO_ERR ) { EndUndoGroup( UndoStack ); return( rc ); } } scol = FindStartOfCurrentLine() - 1; ecol = CurrentLine->len - 1; } DCDisplayAllLines(); rc = DeleteAndInsertText( scol, ecol ); EndUndoGroup( UndoStack ); return( rc ); } /* * change text on current line */ rc = ERR_NO_ERR; GoToLineNoRelCurs( r->start.line ); ecol = r->end.column; scol = r->start.column; #ifdef __WIN__ // GetCurrentLine(); strcpy( WorkLine->data, CurrentLine->data ); tmp = WorkLine->data[ecol]; WorkLine->data[ecol] = '$'; #else vecol = VirtualColumnOnCurrentLine( ecol + 1 ); vecol--; ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, WorkLine->data, EditVars.MaxLine + 1 ); WorkLine->len = strlen( WorkLine->data ); tmp = WorkLine->data[vecol]; WorkLine->data[vecol] = '$'; #endif if( WorkLine->len == 0 ) { WorkLine->data[1] = '\0'; } EditFlags.InsertModeActive = true; GoToColumn( scol + 1, CurrentLine->len ); EditFlags.InsertModeActive = false; DisplayWorkLine( true ); UnselectRegion(); DCUpdate(); #ifndef __WIN__ HiliteAColumnRange( CurrentPos.line, scol, ecol ); #endif /* * now, get ready to do change */ key = GetNextEvent( false ); #ifdef __WIN__ WorkLine->data[ecol] = tmp; #else WorkLine->data[vecol] = tmp; #endif DisplayWorkLine( true ); if( key == VI_KEY( ESC ) && !EditFlags.ChangeLikeVI ) { WorkLine->len = -1; GoToColumn( scol + 1, CurrentLine->len ); } else { KeyAdd( key ); rc = DeleteAndInsertText( scol, ecol ); } return( rc ); } /* Change */
/* * 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 */