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

📄 show.c

📁 Unix环境下的curses编程库。
💻 C
📖 第 1 页 / 共 4 页
字号:
void pageupWindow( void )
{
    ShowWindow *tempWindow;

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

    upScrollWindow( g_pCurWindow->nSubWinMaxRow-1 );
}    /* end pageupWindow() */

/**************************************************************
 * Name: pagedownWindow();                                    *
 * Description: let current window pagedown.                  *
 * Inputs: none.                                              *
 * Output: none.                                              *
 * Return: none.                                              *
 * Cautions: none.                                            *
 **************************************************************/
void pagedownWindow( void )
{
    ShowWindow *tempWindow;

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

    downScrollWindow( g_pCurWindow->nSubWinMaxRow-1 );
}    /* end pagedownWindow() */

/**************************************************************
 * Name: getPrompt(char *sGetContents, int nMaxLength);       *
 * Description: get prompt contents from prompt-window.       *
 * Inputs: char *sGetContents    . the contents gotten.       *
 * Output: none.                                              *
 * Return: the length of contents.                            *
 * Cautions: none.                                            *
 **************************************************************/
int getPrompt( char *sGetContents, int nMaxLength )
{
    char ch;
    char *sStrCurPos;
    int  i, j, x, y;
    int  nCurrentRow, nCurWinFirstRow;

    setCurActiveWindow( -2 );

    if ( g_pPromptWindow->nCurrentRow<0 )
        nCurrentRow = -1;
    else if ( g_pPromptWindow->nCurrentRow<g_pPromptWindow->nStartRow )
        nCurrentRow = g_pPromptWindow->nCurrentRow
                      + g_pPromptWindow->nMaxTotalRow;
    else
        nCurrentRow = g_pPromptWindow->nCurrentRow;
    if ( g_pPromptWindow->nCurWinFirstRow<g_pPromptWindow->nStartRow )
        nCurWinFirstRow = g_pPromptWindow->nCurWinFirstRow
                      + g_pPromptWindow->nMaxTotalRow;
    else
        nCurWinFirstRow = g_pPromptWindow->nCurWinFirstRow;

    if ( nCurrentRow-nCurWinFirstRow+1 >= g_pPromptWindow->nSubWinMaxRow )
    {
        x = g_pPromptWindow->nSubWinMaxRow-1;
        g_pPromptWindow->nCurWinFirstRow = nCurrentRow + 2
                                          - g_pPromptWindow->nSubWinMaxRow;
        if ( g_pPromptWindow->nCurWinFirstRow>=g_pPromptWindow->nMaxTotalRow )
            g_pPromptWindow->nCurWinFirstRow -= g_pPromptWindow->nMaxTotalRow;
        displayShowWindow( g_pPromptWindow );
    }
    else
        x = nCurrentRow-nCurWinFirstRow+1;

    nCurrentRow++;
    if ( nCurrentRow-g_pPromptWindow->nStartRow>=g_pPromptWindow->nMaxTotalRow )
    {
        if ( nCurrentRow+1>=g_pPromptWindow->nMaxTotalRow )
            g_pPromptWindow->nStartRow = nCurrentRow+1
                                   - g_pPromptWindow->nMaxTotalRow;
        else
            g_pPromptWindow->nStartRow = nCurrentRow+1;
/* Add % in Jul 22, 1998 */
        g_pPromptWindow->nStartRow %= g_pPromptWindow->nMaxTotalRow;
    }
    if ( nCurrentRow>=g_pPromptWindow->nMaxTotalRow )
        g_pPromptWindow->nCurrentRow = nCurrentRow
                                 - g_pPromptWindow->nMaxTotalRow;
    else
        g_pPromptWindow->nCurrentRow = nCurrentRow;

    mvwaddstr( g_pPromptWindow->sWin, x, 0, "In: " );
    y = 4;

    sStrCurPos = g_pPromptWindow->sWinContent
                 + 80 * g_pPromptWindow->nCurrentRow;
    memset( sStrCurPos, (int) ' ', g_pPromptWindow->nSubWinMaxCol );
    strncpy( sStrCurPos, "In: ", 4 );
    sStrCurPos += 4;
    i = 0;
    while ( i<nMaxLength )
    {
    /* get a string which length is less than nMaxLength */
        wmove( g_pPromptWindow->sWin, x, y );
        do {
            ch = wgetch( g_pPromptWindow->sWin );
            if ( ch==BackSpace && i>0 )
            {
            /* delete a char */
                i--;
                y--;
                if ( y<0 )
                {
                    x--;
                    y = g_pPromptWindow->nSubWinMaxCol-1;
                    if ( g_pPromptWindow->nCurrentRow==0 )
                        g_pPromptWindow->nCurrentRow = 
                                             g_pPromptWindow->nMaxTotalRow-1;
                    else
                        g_pPromptWindow->nCurrentRow--;
                    sStrCurPos = g_pPromptWindow->sWinContent
                                 + 80 * g_pPromptWindow->nCurrentRow;
                }
                else
                    sStrCurPos--;
                *sStrCurPos = ' ';
                mvwaddch( g_pPromptWindow->sWin, x, y, ' ' );
                wmove( g_pPromptWindow->sWin, x, y );
                continue;
            }
        } while ( !isprint( ch ) && ch!=Enter );
        if ( ch==Enter )
        {
            sGetContents[i++] = '\n';
            break;
        }
        sGetContents[i++] = (char) ch;
        mvwaddch( g_pPromptWindow->sWin, x, y, ch );
        *sStrCurPos++ = ch;

        y++;
        if ( y >= g_pPromptWindow->nSubWinMaxCol )
        {
        /* the next line */
            g_pPromptWindow->nCurrentRow++;
            if ( g_pPromptWindow->nCurrentRow==g_pPromptWindow->nStartRow
              && g_pPromptWindow->nCurrentRow<g_pPromptWindow->nMaxTotalRow-1 )
            {
/* Add % in Jul 22, 1998 */
                g_pPromptWindow->nStartRow = (g_pPromptWindow->nCurrentRow+1)%g_pPromptWindow->nMaxTotalRow;
            }
            else if ( g_pPromptWindow->nCurrentRow==g_pPromptWindow->nStartRow
              && g_pPromptWindow->nCurrentRow>=g_pPromptWindow->nMaxTotalRow )
            {
                g_pPromptWindow->nCurrentRow -= g_pPromptWindow->nMaxTotalRow;
/* Add % in Jul 22, 1998 */
                g_pPromptWindow->nStartRow = (g_pPromptWindow->nCurrentRow+1)%g_pPromptWindow->nMaxTotalRow;
            }
            else if ( g_pPromptWindow->nCurrentRow==g_pPromptWindow->nStartRow )
            {
                g_pPromptWindow->nStartRow = 0;
            }
            else if ( g_pPromptWindow->nCurrentRow
                          >= g_pPromptWindow->nMaxTotalRow )
            {
                g_pPromptWindow->nCurrentRow -= g_pPromptWindow->nMaxTotalRow;
            }

            sStrCurPos = g_pPromptWindow->sWinContent
                         + 80 * g_pPromptWindow->nCurrentRow;
            memset( sStrCurPos, (int) ' ', g_pPromptWindow->nSubWinMaxCol );

            if ( x >= g_pPromptWindow->nSubWinMaxRow-1 )
            {
                x = g_pPromptWindow->nSubWinMaxRow-1;
                g_pPromptWindow->nCurWinFirstRow++;
                if ( g_pPromptWindow->nCurWinFirstRow>=g_pPromptWindow->nMaxTotalRow )
                    g_pPromptWindow->nCurWinFirstRow -= g_pPromptWindow->nMaxTotalRow;
                displayShowWindow( g_pPromptWindow );
            }
            else
                x++;
            wmove( g_pPromptWindow->sWin, x, 0 );
            y = 0;
        }
    }

    sGetContents[i] = '\0';

    return i;
}    /* end getPrompt() */


/**************************************************************
 * Name: getPromptNoDisp(char *sGetContents, int nMaxLength); *
 * Description: get prompt contents from prompt-window.       *
 * Inputs: char *sGetContents    . the contents gotten.       *
 * Output: none.                                              *
 * Return: the length of contents.                            *
 * Cautions: none.                                            *
 **************************************************************/
int getPromptNoDisp( char sGetContents[], int nMaxLength )
{
    int nCur=0;

    do{
	sGetContents[nCur] = getCharDelay();
	nCur++;
    } while( (sGetContents[nCur-1]!=0x0d) && (nCur<nMaxLength) );

    sGetContents[nCur-1] = 0x00;

    return nCur-1;
}

/**************************************************************
 * Name: deleteContent(int nWindowNo, int nSerno);            *
 * Description: delete the message, which serial is nSerno,   *
 *               from No. nWindowNo window.                   *
 * Inputs: int nWindowNo      . the window's number.          *
 *         int nSerno         . the message's serial number.  *
 * Output: none.                                              *
 * Return: 0 for success, -1 for fail.                        *
 * Cautions: none.                                            *
 **************************************************************/
int deleteContent( int nWindowNo, int nSerno )
{
    int  i;
    ShowWindow *pMainWindow;

    if ( g_nHaveInCurses!=1 || nWindowNo<0 || nWindowNo>=MaxWindowNum )
        return (-1);
    if ( ( pMainWindow = g_apWindow[nWindowNo] ) == NULL )
        return (-1);
    if ( pMainWindow->nWinType!=SingleItemWin )
        return (-1);
    if ( nSerno > pMainWindow->nCurSerno || nSerno < 0 )
        return (-1);

    for ( i=nSerno; i<=pMainWindow->nCurSerno; i++ )
    {
		pMainWindow->ItemWhole(i) = pMainWindow->ItemWhole(i+1);
    }

    if ( pMainWindow->nCurSerno % NumberPerLine == 0 )
        pMainWindow->nCurrentRow -= LinesPerItem;
    if ( pMainWindow->nCurSerno>= 0 ) {
        pMainWindow->nItemValid(pMainWindow->nCurSerno) = 0;
        pMainWindow->nCurSerno--;
    }

    if ( g_nShowImmediate==1 && g_pCurWindow==pMainWindow )
        displayShowWindow( pMainWindow );

    return 0;
}    /* end deleteContent() */

/**************************************************************
 * Name: clearContent(int nWindowNo, int nSerno);             *
 * Description: clear the message, which serial is nSerno,    *
 *               from No. nWindowNo window.                   *
 * Inputs: int nWindowNo      . the window's number.          *
 *         int nSerno         . the message's serial number.  *
 * Output: none.                                              *
 * Return: 0 for success, -1 for fail.                        *
 * Cautions: none.                                            *
 **************************************************************/
int clearContent( int nWindowNo, int nSerno )
{
    ShowWindow *pMainWindow;

    if ( g_nHaveInCurses!=1 || nWindowNo<0 || nWindowNo>=MaxWindowNum )
        return (-1);
    if ( ( pMainWindow = g_apWindow[nWindowNo] ) == NULL )
        return (-1);
    if ( pMainWindow->nWinType!=SingleItemWin )
        return (-1);
    if ( nSerno > pMainWindow->nCurSerno )
        return (-1);

    pMainWindow->nItemValid(nSerno) = 0;

    if ( g_nShowImmediate==1 )
        displayShowWindow( pMainWindow );

    return 0;
}    /* end clearContent() */

/**************************************************************
 * Name: displayAttrErrorMsg(short nAttrs, char *spErrMsg);   *
 * Description: Display the new error message in window.      *
 * Inputs: char *spErrMsg      . the error messages.          *
 *         short nAttrs,       . the show attributes.         *
 * Output: the specified messages to window.                  *
 * Return: 0 if success, -1 if fail.                          *
 * Cautions: none.                                            *
 **************************************************************/
int displayAttrErrorMsg( short nAttrs, char *spErrMsg )
{
    return displayAttrMessage( -1, nAttrs, spErrMsg );
}    /* end displayAttrErrorMsg() */

/**************************************************************
 * Name: displayAttrPromptMsg(short nAttrs, char *sPromptMsg);*
 * Description: Display the new prompt message in window.     *
 * Inputs: char *spErrMsg      . the prompt messages.         *
 *         short nAttrs,       . the show attributes.         *
 * Output: the specified messages to window.                  *
 * Return: 0 if success, -1 if fail.                          *
 * Cautions: none.                                            *
 **************************************************************/
int displayAttrPromptMsg( short nAttrs, char *sPromptMsg )
{
    return displayAttrMessage( -2, nAttrs, sPromptMsg );
}    /* end displayAttrPromptMsg() */

void setShowImmediate( void )
{
    g_nShowImmediate = 1;
}

void clearShowImmediate( void )
{
    g_nShowImmediate = 0;
}

/*
 * These two functions are added in Jul 13, 1998.
 */
void displayAttrPromptStatus( int nSerial, short nAttrs, char *sContents )
{
    int nMaxLen, nMaxNum = 5;
    char sShowContents[20];   /* 20 is greater than 80/5. */

    if ( g_pPromptWindow==NULL )
        return ;
    nMaxLen = g_pPromptWindow->nSubWinMaxCol / nMaxNum-1;
    if ( nMaxLen<=2 )
        return ;
    if ( nSerial<=0 )
        nSerial = 1;
    else if ( nSerial>nMaxNum )
        nSerial = nMaxNum;
    strncpy( sShowContents, sContents, nMaxLen );
    sShowContents[nMaxLen] = '\0';

    if ( g_nHaveInColors==1 )
        wattrset( g_pPromptWindow->pWin, COLOR_PAIR(nAttrs) );
    mvwaddstr( g_pPromptWindow->pWin, g_pPromptWindow->nSubWinMaxRow+1,
                (nSerial-1)*(nMaxLen+1)+1, sShowContents );
    if ( g_nHaveInColors==1 )
        wattrset( g_pPromptWindow->pWin, COLOR_PAIR(0) );
    if ( g_nShowImmediate==1 && g_pPromptWindow==g_pCurWindow ) {
        wrefresh( g_pPromptWindow->pWin );
        wrefresh( g_pPromptWindow->sWin );
    }
}    /* end displayAttrPromptStatus() */

void clearPromptStatus( int nSerial )
{
    int i;
    int nMaxLen, nMaxNum = 5;

    if ( g_pPromptWindow==NULL )
        return ;
    nMaxLen = g_pPromptWindow->nSubWinMaxCol / nMaxNum-1;
    if ( nMaxLen<=2 )
        return ;
    if ( nSerial<=0 )
        nSerial = 1;
    else if ( nSerial>nMaxNum )
        nSerial = nMaxNum;
    for ( i=0; i<nMaxLen; i++ )
        mvwaddch( g_pPromptWindow->pWin, g_pPromptWindow->nSubWinMaxRow+1,
                (nSerial-1)*(nMaxLen+1)+i+1, ACS_SBSB );
    if ( g_nShowImmediate==1 && g_pPromptWindow==g_pCurWindow ) {
        wrefresh( g_pPromptWindow->pWin );
        wrefresh( g_pPromptWindow->sWin );
    }
}    /* end clearPromptStatus() */

int clearWindows( int nWindowNo )
{
    ShowWindow *tempWindow;
    register int i;

    if ( g_nHaveInCurses!=1 || nWindowNo<-2 || nWindowNo>=MaxWindowNum )
        return (-1);
    if ( nWindowNo==-1 )
        nWindowNo = MaxWindowNum;
    else if ( nWindowNo==-2 )
        nWindowNo = MaxWindowNum+1;
    if ( ( tempWindow = g_apWindow[nWindowNo] ) == NULL )
        return (-1);
    wclear( tempWindow->sWin );
    wrefresh( tempWindow->sWin );
    for ( i=0; i<80*ComMaxRow; i++ )
        tempWindow->sWinContent[i] = ' ';
    tempWindow->sWinContent[80*ComMaxRow] = '\0';
    return 0;
}    /* end clearWindows() */

⌨️ 快捷键说明

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