home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / clip.c < prev    next >
C/C++ Source or Header  |  1999-02-24  |  2KB  |  112 lines

  1. /*
  2.  * clip.c - PM VNC Viewer, Clipboard Handling
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define INCL_PM
  10. #include <os2.h>
  11.  
  12. #include "pmvncdef.h"
  13.  
  14. static  PUCHAR  serverCutText = NULL ;
  15.  
  16. /*
  17.  * clipHold - hold 'Server Cut Text'
  18.  */
  19.  
  20. void    clipHold(HWND hwnd, PUCHAR text)
  21. {
  22.     if (serverCutText) {
  23.         free(serverCutText) ;
  24.     }
  25.     serverCutText = text ;
  26. }
  27.  
  28. /*
  29.  * clipChkLocalClip - check if local clip text exist
  30.  */
  31.  
  32. BOOL    clipChkLocalClip(HWND hwnd)
  33. {
  34.     HAB     hab  ;
  35.     BOOL    stat ;
  36.  
  37.     hab = WinQueryAnchorBlock(hwnd) ;
  38.     WinOpenClipbrd(hab)  ;
  39.     if (WinQueryClipbrdData(hab, CF_TEXT) == 0) {
  40.         stat = FALSE ;
  41.     } else {
  42.         stat = TRUE ;
  43.     }
  44.     WinCloseClipbrd(hab) ;
  45.     return TRUE ;
  46. }
  47.  
  48. /*
  49.  * clipChkRemoteClip - check if remote clip text exist
  50.  */
  51.  
  52. BOOL    clipChkRemoteClip(HWND hwnd)
  53. {
  54.     return (serverCutText != NULL) ? TRUE : FALSE ;
  55.  
  56. /*
  57.  * clipCopy - copy Server Cut Text to local clipboard
  58.  */
  59.  
  60. void    clipCopy(HWND hwnd)
  61. {
  62.     PUCHAR  shm  ;
  63.     ULONG   leng ;
  64.     ULONG   flag ;
  65.     HAB     hab  ;
  66.     
  67.     if (serverCutText == NULL) {
  68.         return ;
  69.     }
  70.     
  71.     /*
  72.      * copy data into shared memory
  73.      */
  74.  
  75.     leng = strlen(serverCutText) + 2 ;
  76.     flag = OBJ_GIVEABLE | OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE ;
  77.     
  78.     if (DosAllocSharedMem((PPVOID) &shm, NULL, leng, flag) != 0) {
  79.         return ;
  80.     }
  81.     strcpy(shm, serverCutText) ;
  82.  
  83.     /*
  84.      * set to clipboard
  85.      */
  86.  
  87.     hab = WinQueryAnchorBlock(hwnd) ;
  88.     WinOpenClipbrd(hab)  ;
  89.     WinEmptyClipbrd(hab) ;
  90.     WinSetClipbrdData(hab, (ULONG) shm, CF_TEXT, CFI_POINTER) ;
  91.     WinCloseClipbrd(hab) ;
  92. }
  93.  
  94. /*
  95.  * clipPaste - paste local clipboard to remote machine
  96.  */
  97.  
  98. void    clipPaste(HWND hwnd)
  99. {
  100.     HAB     hab  ;
  101.     PUCHAR  ptr  ;
  102.  
  103.     hab = WinQueryAnchorBlock(hwnd) ;
  104.     WinOpenClipbrd(hab)  ;
  105.     if ((ptr = (PUCHAR) WinQueryClipbrdData(hab, CF_TEXT)) != NULL) {
  106.         protoSendCutText(ptr) ;
  107.     }
  108.     WinCloseClipbrd(hab) ;
  109. }
  110.  
  111.