Ejemplo n.º 1
0
void clipsrv(void *foo) {
    HAB hab;
    HMQ hmq;
    ULONG Cmd;
    ULONG len;
    char *text;
    void *shmem = "the text";
    
    hab = NULLHANDLE;

    if ((WinOpenClipbrd(hab) == TRUE) &&
        ((text = (char *) WinQueryClipbrdData(hab, CF_TEXT)) != 0))
    {
        DosGetSharedMem(text, PAG_READ);
        len = strlen(text);
        puts(text);
    }
    WinCloseClipbrd(hab);
    
    len = strlen(shmem);
    if (len) {
        DosAllocSharedMem((void **)&text,
                          0,
                          len + 1,
                          PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE | OBJ_GETTABLE);
        strcpy(text, shmem);
    }
    
    if (WinOpenClipbrd(hab) == TRUE) {
        if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
            DosBeep(100, 1500);
        WinCloseClipbrd(hab);
    }
}
Ejemplo n.º 2
0
void put_clipboard (char *s)
{
    int   len, rc;
    char  *mem;

    len = strlen (s);
    if (len == 0) return;

    create_pm ();
    if (WinOpenClipbrd (hab0) == TRUE)
    {
        WinEmptyClipbrd (hab0);
    
        rc = DosAllocSharedMem ((void **)&mem, NULL, len+1,
                                PAG_READ|PAG_WRITE|PAG_COMMIT|OBJ_GIVEABLE);
        if (rc == 0)
        {
            strcpy (mem, s);
            WinSetClipbrdData (hab0, (ULONG)mem, CF_TEXT, CFI_POINTER);
        }
    }
    
    WinCloseClipbrd (hab0);
    destroy_pm ();
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------
                                  CmdCopy
---------------------------------------------------------------------------*/
void CmdCopy( WNDATTR *wndattr )
{
 LPELEM *elem;
 ULONG   length;
 void   *text;

   length = 0;
   elem = wndattr->list->nextmk;
   while (elem != wndattr->list) {
      length += strlen( elem->data );
      elem = elem->nextmk;
   }
   if (length == 0)
      return;

   DosAllocSharedMem( &text, NULL, length,
                      PAG_COMMIT | OBJ_GIVEABLE | PAG_WRITE );
   elem = wndattr->list->next;
   while (elem != wndattr->list) {
      if (elem->nextmk != NULL) {
         strcat( text, elem->data );
         strcat( text, "\r\n" );
      };
      elem = elem->next;
   }

   WinOpenClipbrd( wndattr->hab );
   WinSetClipbrdData( wndattr->hab, ( ULONG )text, CF_TEXT, CFI_POINTER );
   WinCloseClipbrd( wndattr->hab );

   return;
}
Ejemplo n.º 4
0
/*
 * _CopyAllLines - copy lines to clipboard
 */
void _CopyAllLines( LPWDATA w )
{
    LPLDATA     ld;
    ULONG       total;
    unsigned    len;
    char        *data;
    char        *ptr;
    unsigned    slen;
    LONG        rc;

    /*
     * get number of bytes
     */
    total = 0;
    for( ld = w->LineHead; ld != NULL; ld = ld->next ) {
        total += strlen( ld->data ) + 2;
    }
    if( total > MAX_BYTES ) {
        len = (unsigned) MAX_BYTES;
    } else {
        len = total;
    }

    /*
     * get memory block
     */
    rc = PAG_COMMIT | OBJ_GIVEABLE | PAG_WRITE;
    rc = DosAllocSharedMem( (PPVOID)&data, NULL, len + 1, rc );
    if( rc ) {
        _Error( NULLHANDLE, "Copy to Clipboard Error", "Out of Memory" );
        return;
    }

    /*
     * copy data into block
     */
    total = 0;
    ptr = data;
    for( ld = w->LineHead; ld != NULL; ld = ld->next ) {
        slen = strlen( ld->data ) + 2;
        if( total + slen > MAX_BYTES )
            break;
        memcpy( &ptr[total], ld->data, slen - 2 );
        ptr[total + slen - 2] = 0x0d;
        ptr[total + slen - 1] = 0x0a;
        total += slen;
    }
    ptr[total] = 0;

    /*
     * dump data to the clipboard
     */
    if( WinOpenClipbrd( _AnchorBlock ) ) {
        WinEmptyClipbrd( _AnchorBlock );
        WinSetClipbrdData( _AnchorBlock, (ULONG)data, CF_TEXT, CFI_POINTER );
        WinCloseClipbrd( _AnchorBlock );
    }

} /* _CopyAllLines */
Ejemplo n.º 5
0
VOID PMfrWriteClipbrdBmp(HAB hab)
   {

   HDC hdcClip;         /* memory DC and PS to extract from the clipboard */
   HPS hpsClip;
   HBITMAP hbmClip;
   SIZEL sizl;
   BITMAPINFOHEADER bmp;
   ULONG _far *alRGBColors;
   LONG errorcode;
   char _far *fp1;
   char _far *fp2;
   int i;

   if (WinOpenClipbrd(hab))
      {
      /* get the memory DC and PS to copy the bitmap */
      hdcClip = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;

      sizl.cx = cp.cx; sizl.cy = cp.cy;

      hpsClip = GpiCreatePS (hab, hdcClip, &sizl,
                   PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

      bmp.cbFix   = sizeof bmp;
      bmp.cx      = cp.cx;
      bmp.cy      = cp.cy;
      bmp.cPlanes = cp.cPlanes;
      bmp.cBitCount = cp.cBitCount;
      hbmClip = GpiCreateBitmap (hpsClip, &bmp, 0L, NULL, NULL);

      GpiSetBitmap(hpsClip, hbmClip);

      /* initialize and black out the bitmap */
      alRGBColors = (ULONG _far *) _fmalloc(sizeof(ULONG) * cp.colors);
      /* beginning of source array */
      fp2 = (char _far *) &cp.pbmiMemory->argbColor[0];
      /* beginning of dest array */
      fp1 = (char _far *) &alRGBColors[0];
      for (i = 0; i < cp.colors; i++)
          {   /* copy base bytes for number of screen colors */
          alRGBColors[i] = 0;
          _fmemcpy(fp1, fp2, sizeof(RGB) );
          fp1 += sizeof(ULONG);
          fp2 += sizeof(RGB);
          }

      GpiSetMix ( hpsClip, FM_OVERPAINT) ;
      GpiSetBackMix (hpsClip, BM_LEAVEALONE) ;
      GpiCreateLogColorTable(hpsClip, LCOL_RESET | LCOL_REALIZABLE,
              LCOLF_CONSECRGB, 0L, cp.colors, alRGBColors);

      /* now copy the bits */
      cp.pbmiMemory->cx = cp.cx;
      cp.pbmiMemory->cy = cp.cy;
      cp.pbmiMemory->cPlanes = cp.cPlanes;
      cp.pbmiMemory->cBitCount = cp.cBitCount;
      errorcode = GpiSetBitmapBits(hpsClip, 0L, (LONG) cp.cy,
                                cp.pixels, cp.pbmiMemory);

      /* unlink the new bitmap */
      GpiSetBitmap(hpsClip, (HBITMAP) NULL);

      /* write to the clipboard */
      WinEmptyClipbrd (hab);
      WinSetClipbrdData (hab, (ULONG) hbmClip, CF_BITMAP, CFI_HANDLE);

      /* now clean up */

      _ffree(alRGBColors);
      GpiDestroyPS(hpsClip);
      DevCloseDC(hdcClip);

      WinCloseClipbrd(hab);
      }

   }
Ejemplo n.º 6
0
// Set some data onto the clipboard
void nsClipboard::SetClipboardData(const char *aFlavor)
{
  void *pMozData = nsnull;
  PRUint32 NumOfBytes = 0;

  // Get the data from the transferable
  nsCOMPtr<nsISupports> genericDataWrapper;
#ifdef DEBUG
  nsresult errCode =
#endif
  mTransferable->GetTransferData( aFlavor, getter_AddRefs(genericDataWrapper), &NumOfBytes );
#ifdef DEBUG
  if (NS_FAILED(errCode)) printf( "nsClipboard:: Error getting data from transferable\n" );
#endif
  if (NumOfBytes == 0) return;
  nsPrimitiveHelpers::CreateDataFromPrimitive( aFlavor, genericDataWrapper, &pMozData, NumOfBytes );

  /* If creating the data failed, just return */
  if (!pMozData) {
    return;
  }

  ULONG ulFormatID = GetFormatID( aFlavor );

  if (strstr( aFlavor, "text/" ))  // All text/.. flavors are null-terminated
  {
    if (ulFormatID == CF_TEXT)     // CF_TEXT is one byte character set
    {
      char* pByteMem = nsnull;

      if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pByteMem), nsnull, NumOfBytes + sizeof(char), 
                             PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR)
      {
        memcpy( pByteMem, pMozData, NumOfBytes );       // Copy text string
        pByteMem[NumOfBytes] = '\0';                    // Append terminator

        // With Warp4 copying more than 64K to the clipboard works well, but
        // legacy apps cannot always handle it. So output an alarm to alert the
        // user that there might be a problem.
        if (strlen(pByteMem) > 0xFFFF) {
          WinAlarm(HWND_DESKTOP, WA_ERROR);
        }
        WinSetClipbrdData(0, reinterpret_cast<ULONG>(pByteMem), ulFormatID, CFI_POINTER);
      }
    }
    else                           // All other text/.. flavors are in unicode
    {
      UniChar* pUnicodeMem = nsnull;
      PRUint32 NumOfChars = NumOfBytes / sizeof(UniChar);
   
      if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pUnicodeMem), nsnull, NumOfBytes + sizeof(UniChar), 
                             PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
      {
        memcpy( pUnicodeMem, pMozData, NumOfBytes );    // Copy text string
        pUnicodeMem[NumOfChars] = L'\0';                // Append terminator

        WinSetClipbrdData( 0, reinterpret_cast<ULONG>(pUnicodeMem), ulFormatID, CFI_POINTER );
      }

      // If the flavor is unicode, we also put it on the clipboard as CF_TEXT
      // after conversion to locale charset.

      if (!strcmp( aFlavor, kUnicodeMime ))
      {
        char* pByteMem = nsnull;

        if (DosAllocSharedMem(reinterpret_cast<PPVOID>(&pByteMem), nsnull,
                              NumOfBytes + 1, 
                              PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
        {
          PRUnichar* uchtemp = (PRUnichar*)pMozData;
          for (PRUint32 i=0;i<NumOfChars;i++) {
            switch (uchtemp[i]) {
              case 0x2018:
              case 0x2019:
                uchtemp[i] = 0x0027;
                break;
              case 0x201C:
              case 0x201D:
                uchtemp[i] = 0x0022;
                break;
              case 0x2014:
                uchtemp[i] = 0x002D;
                break;
            }
          }

          nsAutoCharBuffer buffer;
          PRInt32 bufLength;
          WideCharToMultiByte(0, static_cast<PRUnichar*>(pMozData),
                              NumOfBytes, buffer, bufLength);
          memcpy(pByteMem, buffer.Elements(), NumOfBytes);
          // With Warp4 copying more than 64K to the clipboard works well, but
          // legacy apps cannot always handle it. So output an alarm to alert the
          // user that there might be a problem.
          if (strlen(pByteMem) > 0xFFFF) {
            WinAlarm(HWND_DESKTOP, WA_ERROR);
          }
          WinSetClipbrdData(0, reinterpret_cast<ULONG>(pByteMem), CF_TEXT, CFI_POINTER);
        }
      }
    }
  }
  else                             // Assume rest of flavors are binary data
  {
    PBYTE pBinaryMem = nsnull;

    if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pBinaryMem), nsnull, NumOfBytes + sizeof(PRUint32), 
                           PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) 
    {
      *(reinterpret_cast<PRUint32*>(pBinaryMem)) = NumOfBytes;          // First DWORD contains data length
      memcpy( pBinaryMem + sizeof(PRUint32), pMozData, NumOfBytes );  // Copy binary data

      WinSetClipbrdData( 0, reinterpret_cast<ULONG>(pBinaryMem), ulFormatID, CFI_POINTER );
    }

    // If the flavor is image, we also put it on clipboard as CF_BITMAP
    // after conversion to OS2 bitmap

    if (strstr (aFlavor, "image/"))
    {
      //  XXX OS2TODO  Convert jpg, gif, png to bitmap
#ifdef DEBUG
      printf( "nsClipboard:: Putting image on clipboard; should also convert to BMP\n" );
#endif
    }
  }
  nsMemory::Free(pMozData);
}
/*********************************************************************
 *  Name: EditCopy
 *
 *  Description : Processes the Edit menu's Copy item.
 *
 *  Concepts : Called whenever Copy from the Edit menu is selected
 *             Sends a MLM_COPY message to the MLE control.
 *
 *  API's : WinSendMsg
 *
 *  Parameters : mp1 - Message parameter
 *             : mp2 - Message parameter
 *
 *  Returns: Void
 *
 ****************************************************************/
VOID EditCopy(MPARAM mp1, MPARAM mp2)
{
   HAB hab;
   PCHAR pchClipText, pText;
   APIRET rc;
   ULONG  BidiAttr;
   BOOL   fSetClipAttr;
   LONG   Offset =0;

      rc = DosAllocSharedMem ( (PPVOID) &pchClipText,
                    NULL,
                    sizeof(szPasteText),
                    (PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE) );

      if (rc) {
          DosBeep(100,100);
          return;
          } /* endif */

      hab =  WinQueryAnchorBlock( hwndMain);

//BIDI
//
// Load the national strings from the resource file.
// These will be copied to the clipbaord.
//
      if (WinQueryCp(HMQ_CURRENT) == 864) Offset = ARA_OFF;

      WinLoadString( hab, NULLHANDLE, IDS_COPYVISUALTEXT+Offset,
                     127, szCopyVisualText);
      WinLoadString( hab, NULLHANDLE, IDS_COPYIMPLICITTEXT+Offset,
                     127, szCopyImplicitText);

      //
      // Check if we have to SET the Clipboard Bidi Attribute
      // and if so, with which value.
      //
      switch(SHORT1FROMMP(mp1)) {
      case IDM_EDITCOPY_NOCONV:
         BidiAttr     = 0L;
         pText        = szCopyImplicitText;
         fSetClipAttr = TRUE;
         break;

      case IDM_EDITCOPY_CONV_VISUAL:
         BidiAttr     = BDA_TEXTTYPE_VISUAL | BDA_INIT | BDA_LEVEL ;
         pText        = szCopyVisualText;
         fSetClipAttr = TRUE;
         break;

      case IDM_EDITCOPY_CONV_IMPLICIT:
         BidiAttr     = BDA_TEXTTYPE_IMPLICIT | BDA_INIT | BDA_LEVEL;
         pText        = szCopyImplicitText;
         fSetClipAttr = TRUE;
         break;

      case IDM_EDITCOPY_AUTOCONV:
      default:
         pText        = szCopyImplicitText;
         fSetClipAttr = FALSE;
         break;

      }  /* end switch*/

      //
      // Copy the 'relevant' text to the memory that we are
      // going to hand to the clipboard.
      //
      strcpy(pchClipText, pText );

      /* Now, make give this text to the clipboard. */
      hab =  WinQueryAnchorBlock( hwndMain);
      WinOpenClipbrd  ( hab ) ;
      WinEmptyClipbrd ( hab ) ;
      WinSetClipbrdData ( hab, (ULONG) pchClipText, CF_TEXT, CFI_POINTER) ;


      //
      // If conversion is required, mark what kind of conversion
      // (or none) is required.
      //
      if (fSetClipAttr)
          WinSetLangInfo (NULLHANDLE,
                          LI_BD_CLIP_ATTR,
                          BidiAttr,
                          0L,
                          (ULONG)CF_TEXT,
                          0L);


      WinCloseClipbrd ( hab ) ;


}   /*   End of EditCopy()                                              */
Ejemplo n.º 8
0
ULONG CopyTempFileData2ClipBoard(void)
{
  APIRET rc;
  ULONG Result = NO_ERROR, MsgID;
  PSZ pszMem, p;
  FILE *fp;
  int c;

  if (NULL == (fp = fopen(TempOutFile, "rb")))
  {
   /* result handled by MainDlgProc() */
   return ERROR_OPEN_FAILED;
  }
  else
  {
    rc = DosAllocSharedMem((PVOID) &pszMem,
                           NULL, (ULONG)FileSize(fp, NULL)+1,
                           PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);

    if (NO_ERROR != rc)
    {
     Result = ERROR_OPEN_FAILED;
    }
    else
    {
     p = pszMem;
     while (EOF != (c = fgetc(fp)))
      *p++ = (CHAR) c;
    }

    fclose(fp);

    *p = 0; /* signal end of data! */

    if (WinOpenClipbrd(Hab))
    {

      WinEmptyClipbrd(Hab);
      if (FALSE == WinSetClipbrdData(Hab,
                                     (ULONG) pszMem,
                                     CF_TEXT,
                                     CFI_POINTER))
       Result = ERROR_ACCESS_DENIED;

      WinCloseClipbrd(Hab);

    }
    else
     Result = ERROR_ACCESS_DENIED;

  }
  if (NO_ERROR != Result)
  {
     switch(Result)
     {

      case ERROR_ACCESS_DENIED:
        MsgID = IDS_NO_CLIPBOARD_ACCESS;
       break;

      default:
        MsgID = IDS_GENERAL_PROCESS_FAILURE;
       break;

     }

     Len = WinLoadString(Hab, hRessourceModule, MsgID,
                         MSGSTRN_MAXLEN, Msg);
     WinMessageBox(HWND_DESKTOP, hwndMainDialog, Msg, NULL, 0L, MB_ERROR | MB_OK);
  }

  return Result;
}
Ejemplo n.º 9
0
// *******************************************************************************
// FUNCTION:     PutBitmapInClipboard
//
// FUNCTION USE: Copies a bitmap into the system clipboard
//
// DESCRIPTION:  This function is used to copy the bitmap data captured as a
//               result of the tracking to status window, to the system
//               clipboard.
//
// PARAMETERS:   HBITMAP  The bitmap handle of the bitmap to be placed
//                        in the clipboard.
//
// RETURNS:      TRUE     success
//               FALSE    error
//
// HISTORY:
//
// *******************************************************************************
BOOL PutBitmapInClipboard(HBITMAP hbmClipboard)
{
  HAB  habTemp;
  BOOL rc;


  // --------------------------------------------------------------------------                         
  // Get an anchor block handle                                                                        
  // --------------------------------------------------------------------------                         
  habTemp = WinQueryAnchorBlock(HWND_DESKTOP);

  // --------------------------------------------------------------------------                         
  // Attempt to open the Clipboard                                                                      
  // --------------------------------------------------------------------------                         
  rc = WinOpenClipbrd(habTemp);

  // --------------------------------------------------------------------------       
  // If we get an error opening, return FALSE and post message           
  // --------------------------------------------------------------------------       
  if (rc != TRUE)  
   {
    DisplayMessages(NULLHANDLE, "Error Opening Clipboard", MSG_ERROR);
    return rc;
   }

  // --------------------------------------------------------------------------                    
  // OK, no error so let's empty the clipboard and
  // place our bitmap in there!
  // --------------------------------------------------------------------------                    
  else
   {
    rc = WinEmptyClipbrd(habTemp);
    if (rc != TRUE)
     {
      DisplayMessages(NULLHANDLE, "Error Emptying Data In Clipboard", MSG_ERROR);
      return rc;
     }

    rc = WinSetClipbrdData(habTemp,         // anchor block handle
                           hbmClipboard,    // bitmap handle
                           CF_BITMAP,       // clipboard data format
                           CFI_HANDLE);     // format information

    if (rc != TRUE)
     {
      DisplayMessages(NULLHANDLE, "Error Placing Data In Clipboard", MSG_ERROR);
      return rc;
     }

    // --------------------------------------------------------------------------     
    // Close the clipboard                      
    // --------------------------------------------------------------------------     
    rc = WinCloseClipbrd(habTemp);
    if (rc != TRUE)
     {
      DisplayMessages(NULLHANDLE, "Error Closing Clipboard", MSG_ERROR);
      return rc;
     }
   }
  return TRUE;
}