Example #1
0
/*
 * AddLineToClipboard - add data on specified line to the clipboard
 */
int AddLineToClipboard( char *data, int scol, int ecol )
{
#ifdef __WINDOWS_386__
    char __far          *ptr;
#else
    char                *ptr;
#endif
    GLOBALHANDLE        hglob;
    int                 len;

    if( !openClipboardForWrite() ) {
        return( ERR_CLIPBOARD );
    }

    /*
     * get memory for line
     */
    len = ecol - scol + 2;
    hglob = GlobalAlloc( GMEM_MOVEABLE, len );
    if( hglob == NULL ) {
        CloseClipboard();
        return( ERR_CLIPBOARD );
    }

    ptr = GetPtrGlobalLock( hglob );
    if( ptr == NULL ) {
        CloseClipboard();
        return( ERR_CLIPBOARD );
    }

    /*
     * copy line data and put to clipboard
     */
    while( --len ) {
        *ptr++ = data[scol++];
    }
    *ptr = '\0';
    GlobalUnlock( hglob );
    SetClipboardData( CF_TEXT, hglob );
    CloseClipboard();

    return( ERR_NO_ERR );

} /* AddLineToClipboard */
Example #2
0
/*
 * DialogTemplate - build a dialog template
 */
GLOBALHANDLE DialogTemplate( LONG dtStyle, int dtx, int dty,
                             int dtcx, int dtcy, char *menuname, char *classname,
                             char *captiontext, int pointsize, char *typeface )
{
    GLOBALHANDLE        data;
    UINT                blocklen, menulen, classlen, captionlen, typefacelen;
    UINT                _ISFAR *numbytes;
    char                _ISFAR *dlgtemp;
    char                _ISFAR *dlgtypeface;
    _DLGTEMPLATE        _ISFAR *dt;
    FONTINFO            _ISFAR *fi;


    /*
     * get size of block and allocate memory
     */
    menulen = stringLength( menuname );
    classlen = stringLength( classname );
    captionlen = stringLength( captiontext );

    blocklen = sizeof( UINT ) + sizeof( _DLGTEMPLATE ) + menulen + classlen + captionlen;

    if( dtStyle & DS_SETFONT ) {
      typefacelen = stringLength( typeface );
      blocklen += sizeof( short ) + typefacelen;
    } else {
      typefacelen = 0;
    }

    ADJUST_BLOCKLEN( blocklen );

    data = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, blocklen );
    if( data == NULL ) {
        return( NULL );
    }

    numbytes = GetPtrGlobalLock( data );
    *numbytes = (UINT)blocklen;

    /*
     * set up template
     */
    dt = (_DLGTEMPLATE _ISFAR *)(numbytes + 1);

    dt->dtStyle = dtStyle;
    dt->dtItemCount = 0;
    dt->dtX = dtx;
    dt->dtY = dty;
    dt->dtCX = dtcx;
    dt->dtCY = dtcy;

    dlgtemp = (char _ISFAR *)(dt + 1);

    /*
     * add extra strings to block
     */
    dlgtemp = copyMBString( dlgtemp, menuname, menulen );
    dlgtemp = copyMBString( dlgtemp, classname, classlen );
    dlgtemp = copyMBString( dlgtemp, captiontext, captionlen );


    /*
     * add font data (if needed)
     */
    if( dtStyle & DS_SETFONT ) {
        fi = (FONTINFO _ISFAR *)dlgtemp;
        fi->PointSize = pointsize;
        dlgtypeface = (char _ISFAR *)(fi + 1);
        copyMBString( dlgtypeface, typeface, typefacelen );
    }

    GlobalUnlock( data );
    return( data );

} /* DialogTemplate */
Example #3
0
/*
 * GetClipboardSavebuf - gets data from the clipboard, and builds a
 *                       temporary savebuf from it
 */
int GetClipboardSavebuf( savebuf *clip )
{
    GLOBALHANDLE        hglob;
    char                _HUGE_ *ptr;
    char                _HUGE_ *cpos;
    fcb_list            fcblist;
    int                 i;
    bool                is_flushed;
    bool                has_lf;
    bool                record_done;
    char                ch;
    int                 used;

    if( !openClipboardForRead() ) {
        return( ERR_CLIPBOARD_EMPTY );
    }
    hglob = GetClipboardData( CF_TEXT );
    if( hglob == NULL ) {
        return( ERR_CLIPBOARD );
    }
    ptr = GetPtrGlobalLock( hglob );
    cpos = ptr;
    i = 0;
    is_flushed = false;
    has_lf = false;
    fcblist.head = NULL;
    fcblist.tail = NULL;
    record_done = false;

    /*
     * add all characters to ReadBuffer.  Each time this fills,
     * create a new FCB
     */
    while( (ch = *ptr) != '\0' ) {
        INC_POINTER( ptr );
        ReadBuffer[i++] = ch;
        if( ch == LF ) {
            has_lf = true;
        }
        if( i >= MAX_IO_BUFFER ) {
            is_flushed = true;
            used = addAnFcb( &fcblist, i );
            ptr = GET_POINTER( cpos, used );
            cpos = ptr;
            i = 0;
        }
    }

    /*
     * after we are done, see if any characters are left unprocessed
     */
    if( i != 0 ) {
        /*
         * check if this is a partial line
         */
        if( !is_flushed && !has_lf ) {
            clip->type = SAVEBUF_LINE;
            ReadBuffer[i] = 0;
            clip->u.data = MemAlloc( i + 1 );
            strcpy( clip->u.data, ReadBuffer );
            record_done = true;
        } else {
            // add LF to end of buffer
            if( i >= MAX_IO_BUFFER - 2 ) {
                addAnFcb( &fcblist, i );
                i = 0;
            }
            ReadBuffer[i++] = CR;
            ReadBuffer[i++] = LF;
            addAnFcb( &fcblist, i );
        }
    } else if( !is_flushed ) {
        clip->type = SAVEBUF_NOP;
        record_done = true;
    }

    if( !record_done ) {
        clip->type = SAVEBUF_FCBS;
        clip->u.fcbs.head = fcblist.head;
        clip->u.fcbs.tail = fcblist.tail;
    }

    GlobalUnlock( hglob );
    CloseClipboard();

    return( ERR_NO_ERR );

} /* GetClipboardSavebuf */
Example #4
0
/*
 * AddFcbsToClipboard - add all lines in a given set of fcbs to the clipboard
 */
int AddFcbsToClipboard( fcb_list *fcblist )
{
    fcb                 *cfcb;
    line                *cline;
    char                _HUGE_ *ptr;
    long                size;
    int                 i;
    GLOBALHANDLE        hglob;
    bool                crlf_left_to_write = false;

    if( !openClipboardForWrite() ) {
        return( ERR_CLIPBOARD );
    }

    /*
     * compute the number of bytes in total
     */
    size = 1;   // for trailing null char
    for( cfcb = fcblist->head; cfcb != NULL; cfcb = cfcb->next ) {
        size += (long)cfcb->byte_cnt +
                (long)(cfcb->end_line-cfcb->start_line + 1);
        if( cfcb == fcblist->tail ) {
            break;
        }
    }

    /*
     * get the memory to store this stuff
     */
    hglob = GlobalAlloc( GMEM_MOVEABLE, size );
    if( hglob == NULL ) {
        CloseClipboard();
        return( ERR_CLIPBOARD );
    }

    ptr = GetPtrGlobalLock( hglob );
    if( ptr == NULL ) {
        CloseClipboard();
        return( ERR_CLIPBOARD );
    }

    /*
     * copy all lines into this pointer
     */
    for( cfcb = fcblist->head; cfcb != NULL; cfcb = cfcb->next ) {
        FetchFcb( cfcb );
        for( cline = cfcb->lines.head; cline != NULL; cline = cline->next ) {
            // one CR,LF left to write?
            if( crlf_left_to_write ) {
                // yes: write it
                crlf_left_to_write = false;
                *ptr = CR;
                INC_POINTER( ptr );
                *ptr = LF;
                INC_POINTER( ptr );
            }
            for( i = 0; i < cline->len; i++ ) {
                *ptr = cline->data[i];
                INC_POINTER( ptr );
            }
            // remember to write one CR,LF next time
            crlf_left_to_write = true;
        }
        if( cfcb == fcblist->tail ) {
            break;
        }
    }
    // the last CR,LF is omitted
    *ptr = 0;
    GlobalUnlock( hglob );
    SetClipboardData( CF_TEXT, hglob );
    CloseClipboard();
    return( ERR_NO_ERR );

} /* AddFcbsToClipboard */
Example #5
0
/*
 * DialogTemplate - build a dialog template
 */
GLOBALHANDLE DialogEXTemplate( DWORD dtStyle, DWORD dtExStyle, DWORD dthelpID,
                               int dtx, int dty, int dtcx, int dtcy, char *menuname,
                               char *classname, char *captiontext, short pointsize,
                               char *typeface, short FontWeight, short FontItalic )
{
    GLOBALHANDLE        data;
    UINT                blocklen, menulen, classlen, captionlen, typefacelen;
    UINT                _ISFAR *numbytes;
    char                _ISFAR *dlgtypeface;
    char                _ISFAR *dlgtemp;
    _DLGEXTEMPLATE      _ISFAR *dt;
    FONTEXINFO          _ISFAR *fi;

    /*
     * get size of block and allocate memory
     */
    menulen = stringLength( menuname );
    classlen = stringLength( classname );
    captionlen = stringLength( captiontext );

    blocklen = sizeof( UINT ) + sizeof( _DLGEXTEMPLATE ) + menulen + classlen + captionlen;

    if( dtStyle & DS_SETFONT ) {
      typefacelen = stringLength( typeface );
      blocklen += 3 * sizeof( short ) + typefacelen;
    } else {
      typefacelen = 0;
    }

    ADJUST_BLOCKLEN_DWORD( blocklen );

    data = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, blocklen );
    if( data == NULL ) {
        return( NULL );
    }

    numbytes = GetPtrGlobalLock( data );
    *numbytes = (UINT)blocklen;

    /*
     * set up template
     */
    dt = (_DLGEXTEMPLATE _ISFAR *)(numbytes + 1);

    dt->dtVer = 0x0001;                 // signature dword is 0xffff0001
    dt->dtSignature = 0xffff;
    dt->dthelpID = dthelpID;
    dt->dtExtendedStyle = dtExStyle;
    dt->dtStyle = dtStyle;
    dt->dtItemCount = 0;

    dt->dtX = dtx;
    dt->dtY = dty;
    dt->dtCX = dtcx;
    dt->dtCY = dtcy;

    dlgtemp = (char _ISFAR *)(dt + 1);

    /*
     * add extra strings to block
     */
    dlgtemp = copyMBString( dlgtemp, menuname, menulen );
    dlgtemp = copyMBString( dlgtemp, classname, classlen );
    dlgtemp = copyMBString( dlgtemp, captiontext, captionlen );

    /*
     * add font data (if needed)
     */
    if( dtStyle & DS_SETFONT ) {
        fi = (FONTEXINFO _ISFAR *)dlgtemp;
        fi->PointSize = pointsize;
        fi->weight = FontWeight;
        fi->bItalic = FontItalic;
        dlgtypeface = (char _ISFAR *)(fi + 1);
        copyMBString( dlgtypeface, typeface, typefacelen );
        // copyMBString( fi->fontName, typeface, typefacelen );
    }

    GlobalUnlock( data );
    return( data );

} /* DialogEXTemplate */