Esempio n. 1
0
/*
 * 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 */
Esempio n. 2
0
/*
 * 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 */