winclip.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1999 by Pierre Muller
  5. Connection with Windows Clipboard
  6. based on Ralph Brown Interrupt List
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$i globdir.inc}
  14. unit WinClip;
  15. interface
  16. {$ifdef WinClipSupported}
  17. function WinClipboardSupported : boolean;
  18. function OpenWinClipboard : boolean;
  19. function EmptyWinClipboard : boolean;
  20. function GetTextWinClipboardSize : longint;
  21. function GetTextWinClipBoardData(var p : pchar;var l : longint) : boolean;
  22. function SetTextWinClipBoardData(p : pchar;l : longint) : boolean;
  23. {$endif WinClipSupported}
  24. implementation
  25. {$ifdef WinClipSupported}
  26. {$ifdef DOS}
  27. uses
  28. pmode,
  29. {$ifdef go32v2}
  30. {go32 sorry Gabor, but its still not compiling without that ! }
  31. {now it works. btw. you don't have to sorry - just to tell me... ;)) Gabor }
  32. {$endif go32v2}
  33. dos;
  34. {$endif DOS}
  35. {$ifdef win32}
  36. uses
  37. strings,windows;
  38. {$endif win32}
  39. {$ifdef DOS}
  40. function WinClipboardSupported : boolean;
  41. var
  42. r : registers;
  43. begin
  44. r.ax:=$1700;
  45. RealIntr($2F,r);
  46. WinClipboardSupported:=(r.ax<>$1700);
  47. end;
  48. function OpenWinClipboard : boolean;
  49. var
  50. r : Registers;
  51. begin
  52. r.ax:=$1701;
  53. RealIntr($2F,r);
  54. OpenWinClipboard:=(r.ax<>0);
  55. end;
  56. function EmptyWinClipboard : boolean;
  57. var
  58. r : Registers;
  59. begin
  60. r.ax:=$1702;
  61. RealIntr($2F,r);
  62. EmptyWinClipboard:=(r.ax<>0);
  63. end;
  64. function CloseWinClipboard : boolean;
  65. var
  66. r : Registers;
  67. begin
  68. r.ax:=$1708;
  69. RealIntr($2F,r);
  70. CloseWinClipboard:=(r.ax<>0);
  71. end;
  72. function InternGetDataSize : longint;
  73. var
  74. r : Registers;
  75. begin
  76. r.ax:=$1704;
  77. r.dx:=7 {OEM Text rather then 1 : Text };
  78. RealIntr($2F,r);
  79. InternGetDataSize:=(r.dx shl 16) + r.ax;
  80. end;
  81. {$endif DOS}
  82. {$ifdef win32}
  83. function WinClipboardSupported : boolean;
  84. begin
  85. WinClipboardSupported:=true;
  86. end;
  87. function OpenWinClipboard : boolean;
  88. begin
  89. OpenWinClipboard:=OpenClipboard(0);
  90. end;
  91. function EmptyWinClipboard : boolean;
  92. begin
  93. EmptyWinClipboard:=EmptyClipboard;
  94. end;
  95. function CloseWinClipboard : boolean;
  96. begin
  97. CloseWinClipboard:=CloseClipboard;
  98. end;
  99. function InternGetDataSize : longint;
  100. var HC : Handle;
  101. begin
  102. HC:=GetClipBoardData(CF_OEMTEXT);
  103. if HC<>0 then
  104. begin
  105. InternGetDataSize:=strlen(pchar(GlobalLock(HC)));
  106. GlobalUnlock(HC);
  107. end
  108. else
  109. InternGetDataSize:=0;
  110. end;
  111. {$endif win32}
  112. function GetTextWinClipboardSize : longint;
  113. begin
  114. OpenWinClipboard;
  115. GetTextWinClipboardSize:=InternGetDataSize;
  116. CloseWinClipboard;
  117. end;
  118. function GetTextWinClipBoardData(var p : pchar;var l : longint) : boolean;
  119. var
  120. {$ifdef DOS}
  121. r : Registers;
  122. M : MemPtr;
  123. {$endif DOS}
  124. {$ifdef win32}
  125. h : HGlobal;
  126. pp : pchar;
  127. {$endif win32}
  128. begin
  129. p:=nil;
  130. GetTextWinClipBoardData:=False;
  131. if not OpenWinClipBoard then
  132. exit;
  133. {$ifdef DOS}
  134. l:=InternGetDataSize;
  135. if (l=0) or (l>65520) then
  136. begin
  137. l:=0;
  138. CloseWinClipBoard;
  139. exit;
  140. end;
  141. GetMem(p,l);
  142. GetDosMem(M,l);
  143. r.ax:=$1705;
  144. r.dx:=7{ OEM Text rather then 1 : Text };
  145. r.es:=M.DosSeg;
  146. r.bx:=M.DosOfs;
  147. RealIntr($2F,r);
  148. GetTextWinClipBoardData:=(r.ax<>0);
  149. {$endif DOS}
  150. {$ifdef win32}
  151. h:=GetClipboardData(CF_OEMTEXT);
  152. if h<>0 then
  153. begin
  154. pp:=pchar(GlobalLock(h));
  155. l:=strlen(pp)+1;
  156. getmem(p,l);
  157. move(pp^,p^,l);
  158. GlobalUnlock(h);
  159. end;
  160. GetTextWinClipBoardData:=h<>0;
  161. {$endif win32}
  162. CloseWinClipBoard;
  163. {$ifdef DOS}
  164. M.MoveDataFrom(l,P^);
  165. FreeDosMem(M);
  166. {$endif DOS}
  167. end;
  168. function SetTextWinClipBoardData(p : pchar;l : longint) : boolean;
  169. var
  170. {$ifdef DOS}
  171. r : Registers;
  172. M : MemPtr;
  173. {$endif DOS}
  174. {$ifdef win32}
  175. h : HGlobal;
  176. pp : pchar;
  177. {$endif win32}
  178. begin
  179. SetTextWinClipBoardData:=False;
  180. if (l=0) or (l>65520) then
  181. exit;
  182. if not OpenWinClipBoard then
  183. exit;
  184. EmptyWinClipBoard;
  185. {$ifdef DOS}
  186. GetDosMem(M,l);
  187. M.MoveDataTo(P^,l);
  188. r.ax:=$1703;
  189. r.dx:=7{ OEM Text rather then 1 : Text };
  190. r.es:=M.DosSeg;
  191. r.bx:=M.DosOfs;
  192. r.si:=l shr 16;
  193. r.cx:=l and $ffff;
  194. RealIntr($2F,r);
  195. SetTextWinClipBoardData:=(r.ax<>0);
  196. FreeDosMem(M);
  197. {$endif DOS}
  198. {$ifdef win32}
  199. h:=GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE,l);
  200. pp:=pchar(GlobalLock(h));
  201. move(p^,pp^,l);
  202. GlobalUnlock(h);
  203. SetTextWinClipBoardData:=(SetClipboardData(CF_OEMTEXT,h)=h);
  204. {$endif win32}
  205. CloseWinClipBoard;
  206. end;
  207. {$endif WinClipSupported}
  208. end.
  209. {
  210. $Log$
  211. Revision 1.1 2000-07-13 09:48:37 michael
  212. + Initial import
  213. Revision 1.7 2000/06/16 08:50:45 pierre
  214. + new bunch of Gabor's changes
  215. Revision 1.6 2000/04/25 08:42:35 pierre
  216. * New Gabor changes : see fixes.txt
  217. Revision 1.5 2000/04/18 11:42:39 pierre
  218. lot of Gabor changes : see fixes.txt
  219. Revision 1.4 1999/11/05 13:46:26 pierre
  220. * Use CF_OEMTEXT under win32 and dx=7 under go32v2 to obtain
  221. OEM to ANSI conversion
  222. * GetClipboardDataSize for Win32
  223. Revision 1.3 1999/10/14 14:22:23 florian
  224. * if no ini file is found the ide uses some useful defaults
  225. }