home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xclipbrd.cpp < prev    next >
C/C++ Source or Header  |  1997-04-04  |  2KB  |  88 lines

  1. #include "XClipBrd.h"
  2. #include "XWindow.h"
  3. #include "XBitmap.h"
  4. #include "XString.h"
  5.  
  6.  
  7. /*@ XClipBoard :: XClipBoard( const XWindow * win)
  8. @group constructors/destructors
  9. @remarks Open the clipboard
  10. @parameters XWindow * theOwner          the owning window
  11. */
  12. XClipBoard :: XClipBoard(const XWindow * win)
  13. {
  14.     isOpen = FALSE;
  15.     hab = WinQueryAnchorBlock(win->GetHandle());
  16.     if (WinOpenClipbrd(hab) == FALSE)
  17.         return;
  18.     isOpen = TRUE;
  19. }
  20.  
  21.  
  22. /*@ XClipBoard :: GetText( XString * buffer )
  23. @group get data
  24. @remarks Get the text in the clipboard
  25. @parameters    XString * buffer     buffer to hold the data
  26. */
  27. void XClipBoard::GetText(XString * buffer)
  28. {
  29.     *buffer = (char *) WinQueryClipbrdData(hab, CF_TEXT);
  30. }
  31.  
  32.  
  33. /*@ XClipBoard :: GetBitmap( XBitmap * bmp )
  34. @group get data
  35. @remarks Get a bitmap from the clipboard
  36. @parameters XBitmap *   buffer to hold the data
  37. */
  38. void XClipBoard::GetBitmap(XBitmap * bmp)
  39. {
  40.     bmp->hbm = WinQueryClipbrdData(hab, CF_BITMAP);
  41.     XSize size;
  42.     bmp->GetDimensions(&size);
  43.     bmp->width = bmp->cx = size.GetWidth();
  44.     bmp->height = bmp->cy = size.GetHeight();
  45. }
  46.  
  47.  
  48. /*@ XClipBoard :: SetBitmap( const XBitmap * bmp)
  49. @group set data
  50. @remarks Set a bitmap to the clipboard
  51. @parameters XBitmap *                    the bitmap
  52. @returns    BOOL                         success
  53. */
  54. BOOL XClipBoard::SetBitmap(const XBitmap * bmp)
  55. {
  56.     return WinSetClipbrdData(hab, (ULONG) bmp->GetHandle(), CF_BITMAP, CFI_HANDLE);
  57. }
  58.  
  59.  
  60. /*@ XClipBoard :: SetText( const char * p, const ULONG len)
  61. @group set data
  62. @remarks Set text to the clipboard
  63. @parameters char * theText               text<BR>
  64.             ULONG len                    length of the text (default is 0)
  65. @returns    BOOL                         success
  66. */
  67. BOOL XClipBoard::SetText(const char *p, const ULONG len)
  68. {
  69.     void *pp;
  70.  
  71.     ULONG l = (len == 0 ? strlen(p) + 1 : len + 1);
  72.  
  73.     DosAllocSharedMem(&pp, NULL, l, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
  74.     strcpy((char *) pp, p);
  75.     return WinSetClipbrdData(hab, (ULONG) pp, CF_TEXT, CFI_POINTER);
  76. }
  77.  
  78.  
  79. /*@ XClipBoard :: ~XClipBoard()
  80. @group constructor/destructor
  81. @remarks Never forget to close the clipboard by calling the destructor!
  82. */
  83. XClipBoard :: ~XClipBoard()
  84. {
  85.     if (isOpen)
  86.         WinCloseClipbrd(hab);
  87. }
  88.