/************************************************************************ * "Epsilon" is a registered trademark licensed to Lugaru Software, Ltd. * * "EEL" and "Lugaru" are trademarks of Lugaru Software, Ltd. * * * * Copyright (C) 1993 Lugaru Software Ltd. All rights reserved. * * * * Limited permission is hereby granted to reproduce and modify this * * copyrighted material provided that the resulting code is used only in * * conjunction with Lugaru products and that this notice is retained in * * any such reproduction or modification. * ************************************************************************/ /* Access to MS-Windows clipboard, for Epsilon 6.03 and later. */ #include "eel.h" #include "lowlevel.h" #define MAXCHARS 65500 /* our malloc() can only allocate this much */ command copy_to_clipboard() // copy current region to clipboard { int tmp, sz, ok, max; char *p; sz = point - mark; // actually, may be slightly smaller if (sz < 0) sz = -sz; winclip_limit(sz); winclip_avail(); m_regs.w.si = sz >> 16; m_regs.w.cx = sz; ok = winclip_int(0x1709); // compact clipboard & get max size max = (m_regs.w.dx << 16) + m_regs.w.ax; if (max < ok) { winclip_int(0x1708); // close clipboard error("No room on clipboard for %d characters.", sz); } tmp = tmp_buf(); buf_xfer(tmp, point, mark); save_var bufnum = tmp; if (strip_returns) { point = size(); while (search(-1, "\n")) insert('\r'); } p = malloc(size() + 1); grab(0, size(), p); winclip_int(0x1702); // empty clipboard m_regs.w.dx = 1; // put data w/ this format m_regs.w.es = get_pointer(p, SEGMENT); m_regs.w.bx = get_pointer(p, OFFSET); m_regs.w.si = size() >> 16; m_regs.w.cx = size(); ok = winclip_int(0x1703); // put data on clipboard free(p); winclip_int(0x1708); // close clipboard restore_vars(); buf_delete(tmp); if (!ok) error("Couldn't put text on clipboard."); } command insert_clipboard() // insert text on clipboard at point { int sz, ok; char *p; winclip_avail(); sz = winclip_size(1); if (!sz) { winclip_int(0x1708); // close clipboard error("Can't get data in that format."); } winclip_limit(sz); p = malloc(sz + 1); m_regs.w.dx = 1; // look for data w/ this format m_regs.w.es = get_pointer(p, SEGMENT); m_regs.w.bx = get_pointer(p, OFFSET); ok = winclip_int(0x1705); // get data into p winclip_int(0x1708); // close clipboard p[sz] = 0; if (ok) stuff(p); free(p); if (!ok) error("Couldn't get data from clipboard."); if (strip_returns) { save_var narrow_start = point - sz; // now strip ^M's save_var narrow_end = size() - point; save_spot point = 0; while (search(1, "\r")) delete(point - 1, point); } } winclip_limit(i) { if (i > MAXCHARS) error("Can only transfer %d characters at a time.", MAXCHARS); } winclip_size(format) { m_regs.w.dx = format; // look for data w/ this format winclip_int(0x1704); // get size of data return (m_regs.w.dx << 16) + m_regs.w.ax; // return size } winclip_avail() { if (winclip_int(0x1700) == 0x1700) error("Sorry, the Windows clipboard is not available."); winclip_int(0x1701); // open clipboard (ignore if already open) } winclip_int(cmd) { m_regs.w.ax = cmd; do_interrupt(0x2f, &m_regs); return m_regs.w.ax; }