1
2 // ------------------------------------------------------------------
3 // GoldED+
4 // Copyright (C) 1990-1999 Odinn Sorensen
5 // Copyright (C) 1999-2000 Alexander S. Aganichev
6 // ------------------------------------------------------------------
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 // MA 02111-1307 USA
21 // ------------------------------------------------------------------
22 // $Id: geedit3.cpp,v 1.6 2005/10/11 01:54:39 ssianky Exp $
23 // ------------------------------------------------------------------
24 // OS/2 clipboard to/from edit paste buffer.
25 // ------------------------------------------------------------------
26
27 #include <golded.h>
28 #include <geedit.h>
29 #include <gutlclip.h>
30
31 #if defined(__USE_ALLOCA__)
32 #include <malloc.h>
33 #endif
34
35
Clip2Buf()36 void IEclass::Clip2Buf() {
37
38 gclipbrd clipbrd;
39
40 if(not clipbrd.openread())
41 return;
42
43 int tabsz = CFG->disptabsize ? CFG->disptabsize : 1;
44 #if defined(__USE_ALLOCA__)
45 char *spaces = (char*)alloca(tabsz+1);
46 #else
47 __extension__ char spaces[tabsz+1];
48 #endif
49 memset(spaces, ' ', tabsz);
50 spaces[tabsz] = NUL;
51
52 // Allocate paragraph read buffer
53 size_t buf_len = EDIT_PARABUFLEN;
54 char *buf = (char *)throw_malloc(EDIT_PARABUFLEN);
55 Line *__line = NULL;
56
57 Undo->undo_enabled = NO;
58
59 // Read paragraphs
60 while(clipbrd.read(buf, EDIT_PARABUFLEN-6)) {
61
62 size_t read_len = strlen(buf);
63
64 // Replace tabs
65 char *ht = buf;
66 while((ht = strchr(ht, '\t')) != NULL) {
67 int rposn = ht-buf;
68 int rstart = rposn%tabsz+1;
69 *ht = ' ';
70 if(tabsz > rstart) {
71 if((read_len + tabsz - rstart) >= (buf_len - 6)) {
72 buf_len += tabsz;
73 buf = (char*)throw_realloc(buf, buf_len);
74 }
75 strins(spaces+rstart, buf, rposn);
76 }
77 }
78
79 // Copy the paragraph to the new line and retype it
80 __line = insertlinebelow(__line, buf);
81 if(Edit__pastebuf == NULL)
82 Edit__pastebuf = __line;
83 setlinetype(__line);
84 }
85 Undo->undo_enabled = YES;
86 throw_free(buf);
87 clipbrd.close();
88 }
89
90
Buf2Clip()91 void IEclass::Buf2Clip() {
92
93 gclipbrd clipbrd;
94 Line *_bufline;
95 std::string clipdata;
96
97 for(_bufline = Edit__pastebuf; _bufline; _bufline = _bufline->next)
98 if(not _bufline->txt.empty()) {
99 clipdata += _bufline->txt;
100 if(*(clipdata.end()-1) == '\n')
101 clipdata.replace(clipdata.end()-1, clipdata.end(), "\r\n");
102 }
103
104 clipbrd.writeclipbrd(clipdata.c_str());
105 }
106