/* * SetCursorOnLine - set cursor at specified column in single line text string */ void SetCursorOnLine( window_id id, int col, char *str, type_style *style ) { window *w; int x, y; int width, height; if( BAD_ID( id ) ) { return; } w = WINDOW_FROM_ID( id ); // y = FontHeight( WIN_FONT( w ) ) - cursorHeight; x = MyTextExtent( id, style, str, col - 1 ); width = MyTextExtent( id, style, str, col ) - x; /* adjust so that Insert cursor is 0 width * Also make the overstrike cursor the height of the insert cursor. */ width = (long) width * cursorType.width / 100L; height = EditVars.InsertCursorType.height; y = FontHeight( WIN_FONT( w ) ) - height; MyHideCaret( id ); DestroyCaret(); // CreateCaret( id, (HBITMAP)NULLHANDLE, width, cursorHeight ); CreateCaret( id, (HBITMAP)NULLHANDLE, width, height ); SetCaretPos( x, y ); MyShowCaret( id ); } /* SetCursorOnLine */
/* * NewCursor - create a new cursor for a window */ void NewCursor( window_id id, cursor_type ct ) { window *w; int height; int width; if( BAD_ID( id ) ) { return; } w = WINDOW_FROM_ID( id ); height = FontHeight( WIN_FONT( w ) ); width = FontAverageWidth( WIN_FONT( w ) ); height = (long) height * ct.height / 100L; width = (long) width * ct.width / 100L; MyHideCaret( id ); DestroyCaret(); cursorHeight = height; cursorWidth = width; if( !haveOldBlinkTime ) { oldBlinkTime = GetCaretBlinkTime(); haveOldBlinkTime = TRUE; } CreateCaret( id, (HBITMAP)NULLHANDLE, cursorWidth, cursorHeight ); SetCursorBlinkRate( EditVars.CursorBlinkRate ); MyShowCaret( id ); cursorType = ct; } /* NewCursor */
static void sendNewColour( NewColourOps op ) { type_style *mod_style; if( BAD_ID( mod_wid ) ) { return; } if( mod_wid == GetToolbarWindow() ) { sendNewColourToolbar(); } else if( mod_wid == current_window_id ) { sendNewColourCurrentWindow( op ); } else { mod_style = WIN_TEXT_STYLE( WINDOW_FROM_ID( mod_wid ) ); if( op == NC_FORE ) { mod_style->foreground = INDEX_FROM_XY( cursx, cursy ); } else { mod_style->background = INDEX_FROM_XY( cursx, cursy ); } StatusWndChangeSysColors( RGBValues[statusw_info.text_style.background], RGBValues[statusw_info.text_style.foreground], GetSysColor( COLOR_BTNHIGHLIGHT ), GetSysColor( COLOR_BTNSHADOW ) ); ReDisplayScreen(); } }
/* * setCursorOnScreen - set cursor at specified row and column in edit window */ static void setCursorOnScreen( int row, int col ) { window *w; int x, y; int width; int funny; if( BAD_ID( CurrentWindow ) ) { return; } if( EditFlags.Quiet || EditFlags.NoSetCursor ) { return; } funny = getCursorInfo( CurrentWindow, row, col, &x, &width ); w = WINDOW_FROM_ID( CurrentWindow ); y = row * FontHeight( WIN_FONT( w ) ) - cursorHeight; width = (long) width * cursorType.width / 100L; if( cursorWidth != width ) { MyHideCaret( CurrentWindow ); DestroyCaret(); CreateCaret( CurrentWindow, (HBITMAP)NULLHANDLE, width, cursorHeight ); cursorWidth = width; } // adjust position for italic sillyness SetCaretPos( x - funny, y ); MyShowCaret( CurrentWindow ); } /* setCursorOnScreen */
/* * ResizeWindowRelative - resize current window with relative shifts */ vi_rc ResizeWindowRelative( window_id wid, windim x1, windim y1, windim x2, windim y2, bool scrflag ) { window *w; w = WINDOW_FROM_ID( wid ); return( ResizeWindow( wid, w->area.x1 + x1, w->area.y1 + y1, w->area.x2 + x2, w->area.y2 + y2, scrflag ) ); } /* ResizeWindowRelative */
/* * ResizeWindow - give a window a new size */ vi_rc ResizeWindow( window_id wid, windim x1, windim y1, windim x2, windim y2, bool scrflag ) { window *oldw; // int bt, k; // char *txt, *tptr; // char *ot; // int i, j; oldw = WINDOW_FROM_ID( wid ); AccessWindow( oldw ); if( !ValidDimension( x1, y1, x2, y2, oldw->has_border ) ) { ReleaseWindow( oldw ); return( ERR_WIND_INVALID ); } RestoreOverlap( wid, scrflag ); AllocWindow( wid, x1, y1, x2, y2, oldw->has_border, oldw->has_gadgets, true, oldw->border_color1, oldw->border_color2, oldw->text_color, oldw->background_color ); MarkOverlap( wid ); /* * display the new text */ ClearWindow( wid ); if( oldw->title != NULL ) { WindowTitle( wid, oldw->title ); } else { DrawBorder( wid ); } DCResize( CurrentInfo ); DCDisplayAllLines(); DCUpdate(); FreeWindow( oldw ); ReleaseWindow( WINDOW_FROM_ID( wid ) ); return( ERR_NO_ERR ); } /* ResizeWindow */
static void sendNewFont( void ) { type_style *mod_style; if( mod_hwnd == NULL ) { return; } mod_style = (&(WINDOW_FROM_ID( mod_hwnd )->info->text)); if( mod_hwnd == CurrentWindow ) { sendNewFontCurrentWindow(); } else if( mod_hwnd != GetToolbarWindow() ) { /* (toolbar has no font) */ SetUpFont( &CurLogfont, mod_style->font ); } }
int WindowAuxInfo( window_id wid, int type ) { window *w; int value, height; RECT area; if( BAD_ID( wid ) || !IsWindow( wid ) ) { return( 0 ); } w = WINDOW_FROM_ID( wid ); GetClientRect( wid, &area ); switch( type ) { case WIND_INFO_X1: value = area.left; break; case WIND_INFO_Y1: value = area.top; break; case WIND_INFO_X2: value = area.right; break; case WIND_INFO_Y2: value = area.bottom; break; case WIND_INFO_TEXT_LINES: height = FontHeight( WIN_TEXT_FONT( w ) ); // the 4/5 is a rather arbitrary constant chosen so that we don't show // less than 20% of a line // value = area.bottom - area.top + (height / 5); value = area.bottom - area.top; // + height - 1; value /= height; break; case WIND_INFO_TEXT_COLS: value = area.right - area.left; value /= FontAverageWidth( WIN_TEXT_FONT( w ) ); break; case WIND_INFO_HEIGHT: value = area.bottom - area.top; break; case WIND_INFO_WIDTH: value = area.right - area.left; break; case WIND_INFO_TEXT_COLOR: value = WIN_TEXT_COLOR( w ); break; case WIND_INFO_BACKGROUND_COLOR: value = WIN_TEXT_BACKCOLOR( w ); break; case WIND_INFO_HAS_SCROLL_GADGETS: case WIND_INFO_HAS_BORDER: value = false; break; case WIND_INFO_TEXT_FONT: value = WIN_TEXT_FONT( w ); break; case WIND_INFO_BORDER_COLOR1: case WIND_INFO_BORDER_COLOR2: value = -1; break; default: value = 0; break; } return( value ); }
/* * 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 */