⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show.c

📁 Unix环境下的curses编程库。
💻 C
📖 第 1 页 / 共 4 页
字号:
        wclear( tempWindow->sWin );
        wrefresh( tempWindow->sWin );
        delwin( tempWindow->sWin );
    }
    if ( tempWindow->pWin ) {
        wclear( tempWindow->pWin );
        wrefresh( tempWindow->pWin );
        delwin( tempWindow->pWin );
    }
    free( tempWindow );
}    /* end delSHowWindow() */

/**************************************************************
 * Name: destroyWindows();                                    *
 * Description: delete all windows.                           *
 * Inputs: none.                                              *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void destroyWindows( void )
{
    int i;

    for ( i=0; i<MaxWindowNum+2; i++ )
    {
        delShowWindow( g_apWindow[i] );
        g_apWindow[i] = NULL;
    }
    g_pErrMsgWindow = NULL;
    g_pPromptWindow = NULL;
}    /* end destroyWindows() */

/**************************************************************
 * Name: displayTextShowWindow(ShowWindow *tempWindow);       *
 * Description: show text ShowWindow in curses window.        *
 * Inputs: ShowWindow *tempWindow . the window for display.   *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void displayTextShowWindow( ShowWindow *tempWindow )
{
    char tmpstr[100];
    int  i,j;
    int  nCurWinFirstRow, nCurrentRow;

    if ( g_nHaveInCurses!=1 || tempWindow==NULL )
        return ;
    if ( tempWindow->nCurrentRow<0 )
    {
        wclear( tempWindow->sWin );
        wrefresh( tempWindow->sWin );
        return ;
    }
    if ( tempWindow->nCurWinFirstRow<tempWindow->nStartRow )
        nCurWinFirstRow = tempWindow->nCurWinFirstRow+tempWindow->nMaxTotalRow;
    else
        nCurWinFirstRow = tempWindow->nCurWinFirstRow;
    if ( tempWindow->nCurrentRow<tempWindow->nStartRow )
        nCurrentRow = tempWindow->nCurrentRow+tempWindow->nMaxTotalRow;
    else
        nCurrentRow = tempWindow->nCurrentRow;
    if ( nCurWinFirstRow>=nCurrentRow ) {
        if ( nCurrentRow>=tempWindow->nSubWinMaxRow )
            nCurWinFirstRow = nCurrentRow - tempWindow->nSubWinMaxRow;
        else
            nCurWinFirstRow = 0;
        if ( nCurWinFirstRow>=tempWindow->nMaxTotalRow )
            tempWindow->nCurWinFirstRow = nCurWinFirstRow - tempWindow->nMaxTotalRow;
        else
            tempWindow->nCurWinFirstRow = nCurWinFirstRow;
    }

    for ( i=0; i<tempWindow->nSubWinMaxRow
            && i<nCurrentRow-nCurWinFirstRow+1; i++ ) {
        j = i+nCurWinFirstRow;
        if ( j>=tempWindow->nMaxTotalRow )
            j = j-tempWindow->nMaxTotalRow;
        strncpy( tmpstr, tempWindow->sWinContent + j * 80,
                  tempWindow->nSubWinMaxCol );
        tmpstr[tempWindow->nSubWinMaxCol] = '\0';
        if ( g_nHaveInColors==1 )
            wattrset( tempWindow->sWin, COLOR_PAIR(tempWindow->nTextAttrs(j)) );
        mvwaddstr( tempWindow->sWin, i, 0, tmpstr );
    }
    if ( g_nHaveInColors==1 )
        wattrset( tempWindow->sWin, COLOR_PAIR(0) );
    for ( j=0; j<tempWindow->nSubWinMaxCol; j++ )
        tmpstr[j] = ' ';
    tmpstr[tempWindow->nSubWinMaxCol] = '\0';
    for ( ; i<tempWindow->nSubWinMaxRow; i++ )
        mvwaddstr( tempWindow->sWin, i, 0, tmpstr );
}    /* end displayTextShowWindow() */

/**************************************************************
 * Name: displayItemShowWindow(ShowWindow *tempWindow);       *
 * Description: show item ShowWindow in curses window.        *
 * Inputs: ShowWindow *tempWindow . the window for display.   *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void displayItemShowWindow( ShowWindow *tempWindow )
{
    int i, nRow, nCol;
    int nStartSerno, nEndSerno, nWidthPerItem;
    char sShowMsg[ItemConLen+8], sClearBar[80];

    if ( g_nHaveInCurses!=1 || tempWindow==NULL )
        return ;
    if ( tempWindow->nCurSerno<0 )
    {
        wclear( tempWindow->sWin );
        wrefresh( tempWindow->sWin );
        return ;
    }
    nStartSerno = ( tempWindow->nCurWinFirstRow / LinesPerItem ) * NumberPerLine;
    nEndSerno = ( (tempWindow->nCurWinFirstRow+tempWindow->nSubWinMaxRow) / LinesPerItem + 1 ) * NumberPerLine;
    nWidthPerItem = (tempWindow->nWidthPerItem<ItemConLen)?tempWindow->nWidthPerItem:ItemConLen;
    for ( i=0; i<tempWindow->nSubWinMaxCol && i<79; i++ )
        sClearBar[i] = ' ';
    sClearBar[i] = '\0';
    for ( i=0; i<tempWindow->nSubWinMaxRow; i++ )
        mvwaddstr( tempWindow->sWin, i, 0, sClearBar );
    for ( i=nStartSerno; i<nEndSerno && i<=tempWindow->nCurSerno; i++ )
    {
        if ( tempWindow->nItemValid(i)==1 ) {
            nRow = ( i / NumberPerLine ) * LinesPerItem - tempWindow->nCurWinFirstRow;
            nCol = ( i % NumberPerLine ) * tempWindow->nWidthPerItem+1;
            if ( nRow>=0 && nRow<tempWindow->nSubWinMaxRow ) {
                strcpy( sShowMsg, " " );
                strncpy( sShowMsg+1, tempWindow->sItemId(i), nWidthPerItem-1 );
                sShowMsg[nWidthPerItem+4] = '\0';
                if ( g_nHaveInColors==1 )
                    wattrset( tempWindow->sWin, COLOR_PAIR(tempWindow->nItemIdAttrs(i)) );
                mvwaddstr( tempWindow->sWin, nRow, nCol, sShowMsg );
            }
            if ( nRow>=-1 && nRow<tempWindow->nSubWinMaxRow-1 ) {
                strcpy( sShowMsg, " " );
                strncpy( sShowMsg+1, tempWindow->sItemSts(i), nWidthPerItem-1 );
                sShowMsg[nWidthPerItem+4] = '\0';
                if ( g_nHaveInColors==1 )
                    wattrset( tempWindow->sWin, COLOR_PAIR(tempWindow->nItemStsAttrs(i)) );
                mvwaddstr( tempWindow->sWin, nRow+1, nCol, sShowMsg );
            }
        }
    }
    if ( g_nHaveInColors==1 )
        wattrset( tempWindow->sWin, COLOR_PAIR(0) );
}    /* end displayItemShowWindow() */

/**************************************************************
 * Name: displayShowWindow(ShowWindow *tempWindow);           *
 * Description: show ShowWindow in curses window.             *
 * Inputs: ShowWindow *tempWindow . the window for display.   *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void displayShowWindow( ShowWindow *tempWindow )
{
    int nCurrentRow, nCurWinFirstRow;

    if ( g_nHaveInCurses!=1 || tempWindow==NULL )
        return ;
    if ( tempWindow->nWinType==PureTextWin )
        displayTextShowWindow( tempWindow );
    else if ( tempWindow->nWinType==SingleItemWin )
        displayItemShowWindow( tempWindow );
    else
        return ;

    if ( tempWindow->nCurWinFirstRow<tempWindow->nStartRow )
        nCurWinFirstRow = tempWindow->nCurWinFirstRow+tempWindow->nMaxTotalRow;
    else
        nCurWinFirstRow = tempWindow->nCurWinFirstRow;
    if ( tempWindow->nCurrentRow<tempWindow->nStartRow )
        nCurrentRow = tempWindow->nCurrentRow+tempWindow->nMaxTotalRow;
    else
        nCurrentRow = tempWindow->nCurrentRow;
    if ( nCurWinFirstRow>=nCurrentRow ) {
        if ( nCurrentRow>=tempWindow->nSubWinMaxRow )
            nCurWinFirstRow = nCurrentRow - tempWindow->nSubWinMaxRow;
        else
            nCurWinFirstRow = 0;
    }
    mvwaddch( tempWindow->pWin,
              tempWindow->nScrollSignPos+1,
              tempWindow->nSubWinMaxCol+3,
              ACS_SBSB );
    if ( nCurrentRow-tempWindow->nStartRow > tempWindow->nSubWinMaxRow )
        tempWindow->nScrollSignPos = ( nCurWinFirstRow-tempWindow->nStartRow )
                        * ( tempWindow->nSubWinMaxRow-1 )
                        / ( nCurrentRow - tempWindow->nSubWinMaxRow
                            - tempWindow->nStartRow + 1 );
    else
        tempWindow->nScrollSignPos = 0;
    if ( tempWindow->nScrollSignPos < 0 )
        tempWindow->nScrollSignPos = 0;
    else if ( tempWindow->nScrollSignPos >= tempWindow->nSubWinMaxRow )
        tempWindow->nScrollSignPos = tempWindow->nSubWinMaxRow-1;
    wstandout( tempWindow->pWin );
    mvwaddch( tempWindow->pWin,
              tempWindow->nScrollSignPos+1,
              tempWindow->nSubWinMaxCol+3,
              '*' );
    wstandend( tempWindow->pWin );

    if ( g_pCurWindow==tempWindow )
    {
        wrefresh( g_pCurWindow->pWin );
        wrefresh( g_pCurWindow->sWin );
    }
}    /* end displayShowWindow() */

/**************************************************************
 * Name: showAttrOneProcInfo(ShowWindow *pMainWindow,         *
 *               int nSerno, short nIdAttrs, short nStsAttrs, *
 *               char *sTitle, char *sContents);              *
 * Description: output the procid & status to content         *
 * Inputs: int nWindowNo     . window number of display.      *
 *         int nSerno        . serial number of contents.     *
 *         short nIdAttrs, nStsAttrs . the show attributes.   *
 *         char *sTitle      . title contents.                *
 *         char *sContents   . status contents.               *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void showAttrOneProcInfo( ShowWindow *pMainWindow, int nSerno,
            short nIdAttrs, short nStsAttrs, char *sTitle, char *sContents )
{
    char tmpstr[100], *sDstStr;
    int  i, length,  nWidthPerItem;

    if ( g_nHaveInCurses!=1 || pMainWindow==NULL )
        return ;
    nWidthPerItem = pMainWindow->nWidthPerItem;
    if ( sTitle==NULL && sContents==NULL )
        return ;

    /* output the channel */
    bzero( pMainWindow->sItemId(nSerno), ItemConLen );
    if ( sTitle!=NULL )
    {
        strncpy( pMainWindow->sItemId(nSerno), sTitle, ItemConLen-1 );
    }
    pMainWindow->nItemValid(nSerno) = 1;
    pMainWindow->nItemIdAttrs(nSerno) = nIdAttrs;
    /* output the status */
    bzero( pMainWindow->sItemSts(nSerno), ItemConLen );
    if ( sContents != NULL )
    {
        strncpy( pMainWindow->sItemSts(nSerno), sContents, ItemConLen-1 );
    }
    pMainWindow->nItemStsAttrs(nSerno) = nStsAttrs;

    /* update the position of last row */
    if ( ( nSerno / NumberPerLine + 1 ) * LinesPerItem - 1
                                     > pMainWindow->nCurrentRow )
        pMainWindow->nCurrentRow =
                ( nSerno / NumberPerLine + 1 ) * LinesPerItem - 1;
    if ( pMainWindow->nCurSerno < nSerno )
        pMainWindow->nCurSerno = nSerno;
}    /* end showAttrOneProcInfo() */

/**************************************************************
 * Name: upScrollWindow(int nScrollLines);                    *
 * Description: let current windows move up nScrollLines      *
 *                lines.                                      *
 * Inputs: int nScrollLines  . the lines moving up.           *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void upScrollWindow( int nScrollLines )
{
    int nCurWinFirstRow;

    if ( g_nHaveInCurses!=1 || g_pCurWindow == NULL )
        return ;
    if ( g_pCurWindow->nCurrentRow<0 )
        return ;
    if ( g_pCurWindow->nCurWinFirstRow<g_pCurWindow->nStartRow )
        nCurWinFirstRow = g_pCurWindow->nCurWinFirstRow
                         +g_pCurWindow->nMaxTotalRow;
    else
        nCurWinFirstRow = g_pCurWindow->nCurWinFirstRow;
    if ( g_pCurWindow->nCurWinFirstRow==g_pCurWindow->nStartRow )
    {
        return ;
    }

    if ( nCurWinFirstRow>=g_pCurWindow->nStartRow+nScrollLines )
        nCurWinFirstRow -= nScrollLines;
    else
        nCurWinFirstRow = g_pCurWindow->nStartRow;
    if ( nCurWinFirstRow>=g_pCurWindow->nMaxTotalRow )
        g_pCurWindow->nCurWinFirstRow = nCurWinFirstRow-g_pCurWindow->nMaxTotalRow;
    else
        g_pCurWindow->nCurWinFirstRow = nCurWinFirstRow;

    displayShowWindow( g_pCurWindow );
}    /* end upScrollWindow() */

/**************************************************************
 * Name: downScrollWindow(int nScrollLines);                  *
 * Description: let current windows move down nScrollLines    *
 *                lines.                                      *
 * Inputs: int nScrollLines  . the lines moving down.         *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void downScrollWindow( int nScrollLines )
{
    int nCurrentRow;

    if ( g_nHaveInCurses!=1 || g_pCurWindow == NULL )
        return ;
    if ( g_pCurWindow->nCurrentRow<0 )
        return ;
    if ( g_pCurWindow->nCurrentRow<g_pCurWindow->nCurWinFirstRow )
        nCurrentRow = g_pCurWindow->nCurrentRow+g_pCurWindow->nMaxTotalRow;
    else
        nCurrentRow = g_pCurWindow->nCurrentRow;
    if ( nCurrentRow - g_pCurWindow->nCurWinFirstRow <=
                 g_pCurWindow->nSubWinMaxRow - 1 )
    {
        return ;
    }
    g_pCurWindow->nCurWinFirstRow += nScrollLines;
    if ( g_pCurWindow->nCurWinFirstRow-1
           > nCurrentRow-g_pCurWindow->nSubWinMaxRow )
        g_pCurWindow->nCurWinFirstRow =
                            nCurrentRow-g_pCurWindow->nSubWinMaxRow+1;
    if ( g_pCurWindow->nCurWinFirstRow>=g_pCurWindow->nMaxTotalRow )
        g_pCurWindow->nCurWinFirstRow -= g_pCurWindow->nMaxTotalRow;

    displayShowWindow( g_pCurWindow );
}    /* end downScrollWindow() */

/**************************************************************
 * Name: showAttrMessage(ShowWindow *pTempWindow,             *
 *                        short nAttrs, char *sMessage);      *
 * Description: ouput the error message to ErrMsgWindow.      *
 * Inputs: ShowWindow *pTempWindow  . the window for showing  *
 *         short nAttrs,            . the show attributes.    *
 *         char *sMessage           . the error messages.     *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void showAttrMessage( ShowWindow *pTempWindow, short nAttrs, char *spErrMsg )
{
    int  length, lines, nMinLines, i, j, nRow;
    char *sDstStr, *sSrcStr;
    int  nCurrentRow, nOldRow, nStartRow, nCurWinFirstRow;

    if ( g_nHaveInCurses!=1 || pTempWindow==NULL )
        return ;

    length = strlen( spErrMsg );
    if ( length<=0 )
        return ;
    lines = ( length-1 ) / pTempWindow->nSubWinMaxCol + 1;
    if ( pTempWindow->nCurrentRow<0 )
    {
        nCurrentRow = -1;
        nStartRow = nCurWinFirstRow = 0;
        sDstStr = pTempWindow->sWinContent;
    }
    else
    {
        sDstStr = pTempWindow->sWinContent
                + ( pTempWindow->nCurrentRow+1 ) * 80;
        if ( pTempWindow->nCurrentRow<pTempWindow->nStartRow )
            nCurrentRow = pTempWindow->nCurrentRow+pTempWindow->nMaxTotalRow;
        else
            nCurrentRow = pTempWindow->nCurrentRow;
        if ( pTempWindow->nCurWinFirstRow<pTempWindow->nStartRow )
            nCurWinFirstRow = pTempWindow->nCurWinFirstRow
                              + pTempWindow->nMaxTotalRow;
        else
            nCurWinFirstRow = pTempWindow->nCurWinFirstRow;
        nStartRow = pTempWindow->nStartRow;
    }

    sSrcStr = spErrMsg;
    if ( nCurrentRow+1==pTempWindow->nMaxTotalRow )
        sDstStr = pTempWindow->sWinContent;
    for ( i=0; i<lines; i++ )
    {
        nCurrentRow++;
        length = getoutString( sDstStr, sSrcStr,
                      0, pTempWindow->nSubWinMaxCol, 2 );
        nRow = (sDstStr - pTempWindow->sWinContent)/80;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -