forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clipbord.c
52 lines (45 loc) · 1.29 KB
/
clipbord.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ----------- clipbord.c ------------ */
#include "dflat.h"
char *Clipboard;
unsigned ClipboardLength;
void CopyTextToClipboard(char *text)
{
ClipboardLength = strlen(text);
Clipboard = DFrealloc(Clipboard, ClipboardLength);
memmove(Clipboard, text, ClipboardLength);
}
void CopyToClipboard(WINDOW wnd)
{
if (TextBlockMarked(wnd)) {
char *bbl=TextLine(wnd,wnd->BlkBegLine)+wnd->BlkBegCol;
char *bel=TextLine(wnd,wnd->BlkEndLine)+wnd->BlkEndCol;
ClipboardLength = (int) (bel - bbl);
Clipboard = DFrealloc(Clipboard, ClipboardLength);
memmove(Clipboard, bbl, ClipboardLength);
}
}
void ClearClipboard(void)
{
if (Clipboard != NULL) {
free(Clipboard);
Clipboard = NULL;
}
}
BOOL PasteText(WINDOW wnd, char *SaveTo, unsigned len)
{
if (SaveTo != NULL && len > 0) {
unsigned plen = strlen(wnd->text) + len;
if (plen <= wnd->MaxTextLength) {
if (plen+1 > wnd->textlen) {
wnd->text = DFrealloc(wnd->text, plen+3);
wnd->textlen = plen+1;
}
memmove(CurrChar+len, CurrChar, strlen(CurrChar)+1);
memmove(CurrChar, SaveTo, len);
BuildTextPointers(wnd);
wnd->TextChanged = TRUE;
return TRUE;
}
}
return FALSE;
}