/* * ErrorBox - show an error message in a dialog box */ void ErrorBox( char *str, ... ) { va_list al; char tmp[MAX_STR]; if( MessageWindow != NO_WINDOW ) { WindowAuxUpdate( MessageWindow, WIND_INFO_TEXT_COLOR, messagew_info.hilight.foreground ); WindowAuxUpdate( MessageWindow, WIND_INFO_BACKGROUND_COLOR, messagew_info.hilight.background ); va_start( al, str ); MyVSprintf( tmp, str, al ); va_end( al ); SourceError( tmp ); Message1Box( "%s", tmp ); WindowAuxUpdate( MessageWindow, WIND_INFO_TEXT_COLOR, messagew_info.text.foreground ); WindowAuxUpdate( MessageWindow, WIND_INFO_BACKGROUND_COLOR, messagew_info.text.background ); MyBeep(); } else { va_start( al, str ); #ifndef __WIN__ MyVPrintf( str, al ); MyPrintf( "\n" ); #endif va_end( al ); } } /* Error */
/* * MinimizeCurrentWindow - put next window into next minimize slot */ vi_rc MinimizeCurrentWindow( void ) { int i, j; int minx1, miny1; vi_rc rc; i = getMinSlot(); if( !i ) { return( ERR_NO_ERR ); } miny1 = EditVars.WindMaxHeight - 8; minx1 = 0; for( j = 1; j < i; j++ ) { minx1 += MIN_WIN_WIDTH; if( minx1 >= EditVars.WindMaxWidth - MIN_WIN_WIDTH ) { miny1 -= 3; if( miny1 < 0 ) { miny1 = EditVars.WindMaxHeight - 7; } minx1 = 0; } } rc = CurrentWindowResize( minx1, miny1, minx1 + MIN_WIN_WIDTH - 1, miny1 + 2 ); WindowAuxUpdate( CurrentWindow, WIND_INFO_MIN_SLOT, i ); return( rc ); } /* MinimizeCurrentWindow */
/* * 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 */
/* * WindowTile - tile windows given maximum in each direction */ vi_rc WindowTile( int maxx, int maxy ) { int cnt, max, xdiv, ydiv, tc, i; int xstart, xend, ystart, yend; int ystep, xstep, x, y, xextra, yextra, xx, yy, sxextra; info *cinfo, *cwinfo; vi_rc rc; max = maxx * maxy; xstart = editw_info.area.x1; xend = editw_info.area.x2; ystart = editw_info.area.y1; yend = editw_info.area.y2; /* * "untile" cmd */ if( CurrentInfo == NULL ) { return( ERR_NO_ERR ); } SaveCurrentInfo(); cwinfo = CurrentInfo; if( maxx == 1 && maxy == 1 ) { for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { BringUpFile( cinfo, false ); WindowAuxUpdate( current_window_id, WIND_INFO_TEXT_COLOR, editw_info.text_style.foreground ); WindowAuxUpdate( current_window_id, WIND_INFO_BACKGROUND_COLOR, editw_info.text_style.background ); WindowAuxUpdate( current_window_id, WIND_INFO_TEXT_FONT, editw_info.text_style.font ); WindowAuxUpdate( current_window_id, WIND_INFO_BORDER_COLOR2, editw_info.border_color2 ); ResizeCurrentWindow( editw_info.area.x1, editw_info.area.y1, editw_info.area.x2, editw_info.area.y2 ); } BringUpFile( cwinfo, false ); return( ERR_NO_ERR ); } /* * count the number of files */ cnt = GimmeFileCount(); if( cnt > max ) { cnt = max; } if( cnt > maxx ) { xdiv = maxx; } else { xdiv = cnt; } ydiv = (cnt - 1) / maxx + 1; /* * figure out positions */ ystep = (yend - ystart + 1) / ydiv; yextra = (yend - ystart + 1) % ydiv; xstep = (xend - xstart + 1) / xdiv; sxextra = xextra = (xend - xstart + 1) % xdiv; /* * save current file */ SaveCurrentInfo(); cwinfo = cinfo = CurrentInfo; /* * do retiling */ for( y = 0; y < ydiv; y++ ) { /* * y-direction round off allowance */ if( yextra ) { yextra--; yy = 1; } else { yy = 0; } for( x = 0; x < xdiv; x++ ) { /* * x-direction round off allowance */ if( xextra ) { xextra--; xx = 1; } else { xx = 0; } /* * resize the window and display it */ BringUpFile( cinfo, false ); if( EditVars.TileColors != NULL ) { for( i = 0, tc = 0; i < EditVars.MaxTileColors; i++, tc++ ) { if( tc > EditVars.MaxTileColors ) tc = 0; if( EditVars.TileColors[tc].foreground != -1 && EditVars.TileColors[tc].background != -1 ) { WindowAuxUpdate( current_window_id, WIND_INFO_TEXT_COLOR, EditVars.TileColors[tc].foreground ); WindowAuxUpdate( current_window_id, WIND_INFO_BACKGROUND_COLOR, EditVars.TileColors[tc].background ); /* tile fonts? Nah... sounds real stupid... */ WindowAuxUpdate( current_window_id, WIND_INFO_BORDER_COLOR2, EditVars.TileColors[tc].background ); break; } } } rc = ResizeCurrentWindow( xstart, ystart, xstart + xx + xstep - 1, ystart + yy + ystep - 1 ); if( rc != ERR_NO_ERR ) { return( rc ); } SaveInfo( cinfo ); /* * go to next file */ cnt--; if( cnt == 0 ) { break; } xstart += xstep + xx; cinfo = cinfo->next; if( cinfo == NULL ) { cinfo = InfoHead; } } xstart = editw_info.area.x1; xextra = sxextra; ystart += ystep + yy; } BringUpFile( cwinfo, false ); return( ERR_NO_ERR ); } /* WindowTile */