Пример #1
0
/*
 * _FreeWindowData - get rid of a windows data
 */
void _FreeWindowData( LPWDATA w )
{
    int i,j;

    for( i = 0; i < _MainWindowData->window_count; i++ ) {
        if( _MainWindowData->windows[i] == w ) {
            _MainWindowData->window_count--;
            for( j = i; j < _MainWindowData->window_count; j++ ) {
                _MainWindowData->windows[j] = _MainWindowData->windows[j + 1];
            }
            _ReleaseWindowResources( w );
            FARfree( w->image );
            FARfree( w->handles );
            FARfree( w->tmpbuff );
            FARfree( w );
            return;
        }
    }

} /* _FreeWindowData */
Пример #2
0
/*
 * _FiniMainWindowData - free main window data area
 */
void _FiniMainWindowData( void )
{

    FARfree( _MainWindowData );

} /* _FiniMainWindowData */
Пример #3
0
/*
 * _GetString - read in a string, return the length
 */
int _GetString( LPWDATA w, char *str, int maxbuff )
{
    HWND        hwnd;
    int         buff_end = 0;
    int         curr_pos = 0;
    BOOL        escape = FALSE;
    BOOL        insert_flag = FALSE;
    int         maxlen = maxbuff;
    LPSTR       res;
    int         wt;
    int         len;
    int         i;
    int         scan;
#ifdef _MBCS
    unsigned char *p;
    int         expectingTrailByte = 0;
    int         overwrote = 0;
    unsigned char   ci;
    unsigned char   cx;
#else
    char        ci;
    char        cx;
#endif

#ifdef _MBCS
    res = FARmalloc( MB_CUR_MAX * ( maxbuff + 1 ) );
#else
    res = FARmalloc( maxbuff + 1 );
#endif
    if( res == NULL)
        _OutOfMemoryExit();

    hwnd = w->hwnd;

    _MoveToLine( w, _GetLastLineNumber( w ), FALSE );
    _NewCursor( w, SMALL_CURSOR );
    _SetInputMode( w, TRUE );
    _GotEOF = FALSE;
    str[0] = 0;

    for( ;; ) {
        w->curr_pos = curr_pos;
        _DisplayCursor( w );
        while( !_KeyboardHit( TRUE ) );
        ci = _GetKeyboard( &scan );
#if defined( __OS2__ )
        WinShowCursor( hwnd, FALSE );
#else
        HideCaret( hwnd );
#endif

        if( escape ) {
#ifdef _MBCS
            p = __mbsninc( (unsigned char *)str, curr_pos++ );
            *p = ci;
#else
            str[curr_pos++] = ci;
#endif
            escape = FALSE;
        } else if( (ci == CTRL_V) || (scan != 0xFF) ) {
            if( ci == CTRL_V ) {
                escape = TRUE;      /* This is a VI thing - */
                ci = '^';           /* it permits insertion of any key */
            }
            if( insert_flag ) {
                if( buff_end < maxlen && !TOOWIDE( buff_end, w ) ) {
#ifdef _MBCS
                    if( !expectingTrailByte ) {     /* shift over two bytes */
                        if( _ismbblead( ci ) ) {
                            expectingTrailByte = 1;
                            p = __mbsninc( (unsigned char *)str, curr_pos );
                            for( i = strlen( (char *)p ) + 1; i-- > 0; )
                                p[i + 2] = p[i];
                            p[0] = ci;
                        } else {                    /* shift over one byte */
                            p = __mbsninc( (unsigned char *)str, curr_pos );
                            for( i = strlen( (char *)p ) + 1; i-- > 0; )
                                p[i + 1] = p[i];
                            p[0] = ci;
                        }
                    } else {
                        expectingTrailByte = 0;
                        p = __mbsninc( (unsigned char *)str, curr_pos );
                        p[1] = ci;
                    }
                    overwrote = 0;
#else
                    for( i = buff_end; i >= curr_pos; i-- )
                        str[i + 1] = str[i];
                    buff_end++;
                    str[curr_pos] = ci;
#endif
                } else {
                    continue;
                }
            } else if( curr_pos == buff_end ) {
                if( buff_end < maxlen ) {
#ifdef _MBCS
                    if( !expectingTrailByte ) {
                        if( _ismbblead( ci ) ) {
                            expectingTrailByte = 1;
                            p = __mbsninc( (unsigned char *)str, buff_end );
                        } else {
                            p = __mbsninc( (unsigned char *)str, buff_end );
                        }
                        p[0] = ci;
                        p[1] = p[2] = 0;
                    } else {
                        expectingTrailByte = 0;
                        p = __mbsninc( (unsigned char *)str, buff_end );
                        p[1] = ci;
                        p[2] = 0;
                    }
                    overwrote = 0;
#else
                    str[buff_end++] = ci;
                    str[buff_end] = 0;
#endif
                } else {
                    continue;
                }
            } else {
#ifdef _MBCS
                p = __mbsninc( (unsigned char *)str, curr_pos );
                if( !expectingTrailByte ) {
                    if( _ismbblead( ci ) ) {
                        expectingTrailByte = 1;
                        if( !_ismbblead( *p ) ) {
                            for( i = strlen( (char *)p ) + 1; i-- > 1; ) {
                                p[i + 1] = p[i];    /* shift over one byte */
                            }
                        }
                        p[0] = ci;
                    } else {
                        if( _ismbblead( *p ) ) {   /* shift over one byte */
                            for( i = 1; i < strlen( (char *)p ); i++ ) {
                                p[i] = p[i + 1];
                            }
                        }
                        p[0] = ci;
                    }
                } else {
                    expectingTrailByte = 0;
                    p[1] = ci;
                }
                overwrote = 1;
#else
                str[curr_pos] = ci;
#endif
            }
#ifdef _MBCS
            if( !escape && !expectingTrailByte ) {
                curr_pos++;
                if( !overwrote ) {
                    buff_end++;
                }
            }
#else
            if( !escape ) {
                curr_pos++;
            }
#endif
        } else {
            cx = ci;
            if( cx >= 0x80 )
                cx -= 0x80;
            switch( cx ) {
            case VK_HOME:
                curr_pos = 0;
                break;
            case VK_END:
                curr_pos = buff_end;
                break;
            case VK_RETURN:
#ifdef __OS2__
            case VK_ENTER:
#endif
#ifdef _MBCS
                p = __mbsninc( (unsigned char *)str, buff_end );
                *p = '\0';
#else
                str[buff_end] = 0;
#endif
                _NewCursor( w, ORIGINAL_CURSOR );
#ifdef _MBCS
                _UpdateInputLine( w, str, __mbslen( (unsigned char *)str ), TRUE );
#else
                _UpdateInputLine( w, str, strlen( str ), TRUE );
#endif
                _SetInputMode( w, FALSE );
                FARstrcat( res, str );
                FARstrcpy( str, res );
                FARfree( res );
                /* return number of bytes */
                return( strlen( str ) );
            case VK_LEFT:
                if( curr_pos > 0 )
                    curr_pos--;
                break;
            case VK_RIGHT:
                if( curr_pos < buff_end )
                    curr_pos++;
                break;
            case VK_DELETE:
                if( curr_pos == buff_end )
                    break;  /* DEL, not BS */
                if( curr_pos < buff_end )
                    curr_pos++;
                /* fall through to VK_BACK... */
            case VK_BACK:
                if( curr_pos > 0 ) {
#ifdef _MBCS
                    p = __mbsninc( (unsigned char *)str, curr_pos - 1 );
                    for( i = curr_pos; i < buff_end; i++ ) {
                        _mbccpy( __mbsninc( p, i - curr_pos ), __mbsninc( p, i - curr_pos + 1 ) );
                    }
                    p = __mbsninc( (unsigned char *)str, i - 1 );
                    *p = '\0';
#else
                    for( i = curr_pos; i <= buff_end; i++ )
                        str[i - 1] = str[i];
#endif
                    buff_end--;
                    curr_pos--;
                }
                break;
            case VK_INSERT:
                if( insert_flag ) {
                    insert_flag = FALSE;
                    _NewCursor( w, SMALL_CURSOR );
                } else {
                    insert_flag = TRUE;
                    _NewCursor( w, FAT_CURSOR );
                }
                break;
            default:
                continue;
            }
        }

        /*
         * update line.  if line was split, then we must reset
         * the current line info.
         */
#ifdef _MBCS
        wt = _UpdateInputLine( w, str, expectingTrailByte ? __mbslen( (unsigned char *)str ) - 1 : __mbslen( (unsigned char *)str ), FALSE );
#else
        wt = _UpdateInputLine( w, str, strlen( str ), FALSE );
#endif

        if( wt >= 0 ) {
#ifdef _MBCS
            len = __mbslen( (unsigned char *)str );
            p = __mbsninc( (unsigned char *)str, len - wt );
            ci = *p;
            *p = '\0';
            FARstrcat( res, str );
            *p = ci;
            for( i = 0; i <= wt; i++ )
                str[i] = str[len - wt + i];
#else
            len = strlen( str );
            ci = str[len - wt];
            str[len - wt] = 0;
            FARstrcat( res, str );
            str[len - wt] = ci;
            for( i = 0; i <= wt; i++ )
                str[i] = str[len - wt + i];
#endif
            curr_pos = wt;
            buff_end = wt;
            maxlen -= len + 1;
        }
    }

} /* _GetString */
Пример #4
0
void _RepaintWindow( LPWDATA w, PRECT rcPaint, HDC ph )
#endif
{
    WORD                i;
    WORD                ptop, pbot, pleft, pright, poff, pdown;
    WORD                width;
#ifdef _MBCS
    mb_char _WCI86FAR   *image;
    unsigned char       mbc[MB_CUR_MAX + 1];
#else
    LPSTR               image;
#endif
#if !defined( __OS2__ )
    HFONT               oldfont;
#endif

    /*
     * get area to redraw
     */
    ptop = rcPaint->top / w->ychar;
    if( ptop > 0 && ( rcPaint->top % w->ychar ) != 0 )
        ptop--;
    pbot = rcPaint->bottom / w->ychar ;
    if( pbot == 0 )
        return;
    if( pbot >= w->height )
        pbot = w->height - 1;
    if( ( rcPaint->bottom % w->ychar ) == 0 )
        pbot--;
    pleft = 0;
    pright = w->width - 1;
    width = w->width;
    poff = pleft * w->xchar;
    pdown = ptop * w->ychar;

    /*
     * draw all lines
     */
#if defined( __OS2__ )
#else
    oldfont = SelectObject( (HDC)ph, _FixedFont );
#endif
    for( i = ptop; i <= pbot; i++ ) {
        image = &w->image[i * w->width];
#if defined( __OS2__ )
        {
            POINTL      ptl;

            ptl.x = poff;
            ptl.y = ( w->y2 - w->y1 ) - ( pdown + w->ychar ) + w->base_offset;
    #ifdef _MBCS
            {
                WORD        count;
                LPSTR       buff;

                buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) );
                if( buff == NULL )
                    _OutOfMemoryExit();
                *buff = '\0';
                for( count = 0; count < width; count++ ) {
                    _mbvtop( image[pleft + count], mbc );
                    mbc[_mbclen( mbc )] = '\0';
                    FARstrcat( buff, (char *)mbc );
                }
                GpiCharStringAt( (HPS)ph, &ptl, FAR_mbsnbcnt( (PBYTE)buff, width ), buff );
                FARfree( buff );
            }
    #else
            GpiCharStringAt( (HPS)ph, &ptl, width, &image[pleft] );
    #endif
        }
#else
        SetBkColor( (HDC)ph, _ColorMap[w->background_color] );
        SetTextColor( (HDC)ph, _ColorMap[w->text_color] );
    #ifdef _MBCS
        {
            WORD        count;
            size_t      bytes;
            LPSTR       buff;

            buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) );
            if( buff == NULL )
                _OutOfMemoryExit();
            *buff = '\0';
            for( count = 0; count < width; count++ ) {
                _mbvtop( image[pleft + count], mbc );
                mbc[_mbclen( mbc )] = '\0';
                FARstrcat( buff, (LPSTR)mbc );
            }
            bytes = FARstrlen( buff );
            TextOut( (HDC)ph, poff, pdown, buff, bytes );
            FARfree( buff );
        }
    #else
        TextOut( (HDC)ph, poff, pdown, &image[pleft], width );
    #endif
#endif
        pdown += w->ychar;
    }
#if !defined( __OS2__ )
    SelectObject( (HDC)ph, oldfont );
#endif

} /* _RepaintWindow */
Пример #5
0
/*
 * _MemFree - free a block
 */
void _MemFree( void _WCI86FAR *ptr )
{
    FARfree( ptr );

} /* _MemFree */