grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / nlist / nlist_mcc / NList_func3.c
blob24145ddc6537221891320231076648c1d3392618
1 /***************************************************************************
3 NList.mcc - New List MUI Custom Class
4 Registered MUI class, Serial Number: 1d51 0x9d510030 to 0x9d5100A0
5 0x9d5100C0 to 0x9d5100FF
7 Copyright (C) 1996-2001 by Gilles Masson
8 Copyright (C) 2001-2014 NList Open Source Team
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 NList classes Support Site: http://www.sf.net/projects/nlist-classes
22 $Id$
24 ***************************************************************************/
26 #include <string.h>
27 #include <ctype.h>
29 #include <dos/dos.h>
30 #include <exec/memory.h>
31 #include <libraries/iffparse.h>
32 #include <proto/console.h>
33 #include <proto/utility.h>
34 #include <proto/exec.h>
35 #include <proto/dos.h>
36 #include <proto/iffparse.h>
38 #include "private.h"
40 #include "NList_func.h"
42 IPTR MyCallHookPkt(Object *obj,BOOL hdata,struct Hook *hook,APTR object,APTR message)
44 if (hdata)
45 { IPTR retval;
46 APTR h_Data = hook->h_Data;
47 if (!h_Data)
48 hook->h_Data = obj;
49 retval = CallHookPkt(hook,object,message);
50 if (!h_Data)
51 hook->h_Data = h_Data;
52 return (retval);
54 else
55 return (CallHookPkt(hook,object,message));
58 #ifdef __AROS__
59 /* AROS uses a macro to handle this */
60 #else
61 IPTR STDARGS VARARGS68K MyCallHookPktA(Object *obj, struct Hook *hook, ...)
63 IPTR ret;
64 VA_LIST va;
66 VA_START(va, hook);
67 ret = CallHookPkt(hook, obj, VA_ARG(va, APTR));
68 VA_END(va);
70 return ret;
72 #endif
74 LONG DeadKeyConvert(struct NLData *data,struct IntuiMessage *msg,STRPTR buf,LONG bufsize,struct KeyMap *kmap)
76 int posraw,pos,postext = 0;
77 STRPTR text = buf;
79 if (msg->Class != IDCMP_RAWKEY)
80 return (-2);
82 text[0] = '\0';
84 * if (msg->Qualifier)
85 * { D(bug("Qual:"));
86 * if (msg->Qualifier & IEQUALIFIER_LSHIFT) D(bug("lshift "));
87 * if (msg->Qualifier & IEQUALIFIER_RSHIFT) D(bug("rshift "));
88 * if (msg->Qualifier & IEQUALIFIER_CAPSLOCK) D(bug("capslock "));
89 * if (msg->Qualifier & IEQUALIFIER_CONTROL) D(bug("ctrl "));
90 * if (msg->Qualifier & IEQUALIFIER_LALT) D(bug("lalt "));
91 * if (msg->Qualifier & IEQUALIFIER_RALT) D(bug("ralt "));
92 * if (msg->Qualifier & IEQUALIFIER_LCOMMAND) D(bug("lcommand "));
93 * if (msg->Qualifier & IEQUALIFIER_RCOMMAND) D(bug("rcommand "));
94 * if (msg->Qualifier & IEQUALIFIER_NUMERICPAD) D(bug("numpad "));
95 * if (msg->Qualifier & IEQUALIFIER_REPEAT) D(bug("repeat "));
96 * if (msg->Qualifier & IEQUALIFIER_MIDBUTTON) D(bug("mbutton "));
97 * if (msg->Qualifier & IEQUALIFIER_RBUTTON) D(bug("rbutton "));
98 * if (msg->Qualifier & IEQUALIFIER_LEFTBUTTON) D(bug("lbutton "));
99 * D(bug("\n"));
102 switch (msg->Code & 0x7F)
104 case 0x41 : strlcpy(text,"bs", bufsize); break;
105 case 0x42 : strlcpy(text,"tab", bufsize); break;
106 case 0x43 : strlcpy(text,"enter", bufsize); break;
107 case 0x44 : strlcpy(text,"return", bufsize); break;
108 case 0x45 : strlcpy(text,"esc", bufsize); break;
109 case 0x46 : strlcpy(text,"del", bufsize); break;
110 case 0x4C : strlcpy(text,"up", bufsize); break;
111 case 0x4D : strlcpy(text,"down", bufsize); break;
112 case 0x4E : strlcpy(text,"right", bufsize); break;
113 case 0x4F : strlcpy(text,"left", bufsize); break;
114 case 0x50 : strlcpy(text,"f1", bufsize); break;
115 case 0x51 : strlcpy(text,"f2", bufsize); break;
116 case 0x52 : strlcpy(text,"f3", bufsize); break;
117 case 0x53 : strlcpy(text,"f4", bufsize); break;
118 case 0x54 : strlcpy(text,"f5", bufsize); break;
119 case 0x55 : strlcpy(text,"f6", bufsize); break;
120 case 0x56 : strlcpy(text,"f7", bufsize); break;
121 case 0x57 : strlcpy(text,"f8", bufsize); break;
122 case 0x58 : strlcpy(text,"f9", bufsize); break;
123 case 0x59 : strlcpy(text,"f10", bufsize); break;
124 case 0x5F : strlcpy(text,"help", bufsize); break;
125 default:
126 data->ievent.ie_NextEvent = NULL;
127 data->ievent.ie_Class = IECLASS_RAWKEY;
128 data->ievent.ie_SubClass = 0;
129 data->ievent.ie_Code = msg->Code;
130 data->ievent.ie_Qualifier = 0;
131 data->ievent.ie_position.ie_addr = *((APTR *) msg->IAddress);
132 posraw = RawKeyConvert(&data->ievent,text,bufsize-postext-1,kmap);
133 if (posraw >= 0)
134 text[posraw+postext] = '\0';
135 if (posraw > 0)
137 ULONG realc;
138 data->rawtext[posraw] = '\0';
139 for (pos = 0; pos < posraw; pos++)
141 realc = data->rawtext[pos];
142 /*D(bug("RAWKEY KEY=%ld \n",realc));*/
143 if ((realc <= 0x1F)||((realc >= 0x80)&&(realc < 0xa0)))
144 data->rawtext[pos] = 0x7f;
147 break;
149 return ((LONG)strlen(buf));
153 /*static char *stpncpy_noesc(char *to,const char *from,int len)*/
154 static char *stpncpy_noesc(char *to,char *from,int len)
156 register char *to2 = to;
158 while (*from && (len > 0))
159 { if (*from == '\033')
160 { from++;
161 len--;
162 if ((*from == 'P') || (*from == 'I') || (*from == 'O') || (*from == 'o'))
163 { from++;
164 len--;
165 if (*from == '[')
166 { while ((*from) && (*from != ']'))
167 { from++;
168 len--;
170 if (*from == ']')
171 { from++;
172 len--;
176 else if (*from)
177 { from++;
178 len--;
181 else
182 { *to2++ = *from++;
183 len--;
186 *to2 = '\0';
187 return (to2);
190 #define FORMAT_TEMPLATE "DELTA=D/N,PREPARSE=P/K,COL=C/N,BAR/S,TBAR/S,NOBAR=NB/S,SIMPLEBAR=SBAR/S,"\
191 "NOTITLEBUTTON=NOTB/S,WEIGHT=W/N,MINWIDTH=MIW/N,MAXWIDTH=MAW/N,"\
192 "COLWIDTH=CW/N,MINCOLWIDTH=MICW/N,MAXCOLWIDTH=MACW/N,"\
193 "PIXWIDTH=PW/N,MINPIXWIDTH=MIPW/N,MAXPIXWIDTH=MAPW/N,"\
194 "PARTCOLSUBST=PCS/K\n"
196 struct parse_format
198 LONG *delta;
199 LONG *preparse;
200 LONG *col;
201 LONG bar;
202 LONG tbar;
203 LONG nobar;
204 LONG sbar;
205 LONG notb;
206 LONG *weight;
207 LONG *minwidth;
208 LONG *maxwidth;
209 LONG *colwidth;
210 LONG *mincolwidth;
211 LONG *maxcolwidth;
212 LONG *pixwidth;
213 LONG *minpixwidth;
214 LONG *maxpixwidth;
215 LONG *partcolsubst;
219 void NL_Free_Format(struct NLData *data)
221 if (data->cols)
222 { WORD column = 0;
223 while (column < data->numcols)
225 if(data->cols[column].preparse != NULL)
226 FreeVecPooled(data->Pool, data->cols[column].preparse);
228 column++;
230 FreeVecPooled(data->Pool, data->cols);
232 data->cols = NULL;
233 data->numcols = data->numcols2 = 0;
234 data->format_chge = 1;
238 BOOL NL_Read_Format(struct NLData *data,char *strformat,BOOL oldlist)
240 LONG column,colmax,pos1,pos2,col = 0;
241 char *sf = NULL;
242 struct RDArgs *rdargs,*ptr;
243 struct parse_format Line;
244 struct colinfo *tmpcols;
246 if (strformat && (sf = AllocVecPooled(data->Pool, strlen(strformat)+4)) != NULL)
248 if((ptr = AllocDosObject(DOS_RDARGS, NULL)))
250 colmax = 1;
251 pos2 = 0;
252 while (strformat[pos2] != '\0')
253 { if (strformat[pos2] == ',')
254 colmax++;
255 pos2++;
257 if ((colmax > 0) && (colmax < DISPLAY_ARRAY_MAX) && (tmpcols = AllocVecPooled(data->Pool, (colmax+1)*sizeof(struct colinfo))) != NULL)
259 NL_Free_Format(data);
260 data->cols = tmpcols;
261 data->numcols = data->numcols2 = colmax;
262 column = 0;
263 while (column < colmax)
265 data->cols[column].c = &(data->cols[column]);
266 data->cols[column].preparse = NULL;
267 data->cols[column].colwidthmax = (WORD) -1;
268 data->cols[column].colwidthbiggest = (WORD) -1;
269 data->cols[column].colwidthbiggestptr = (LONG) -2;
270 data->cols[column].delta = (WORD) 4;
271 data->cols[column].col = (WORD) column;
272 data->cols[column].userwidth = (WORD) -1;
273 data->cols[column].titlebutton = (WORD) TRUE;
274 if ((column == colmax-1) && !(oldlist && (column == 0)))
275 data->cols[column].width = (WORD) 100;
276 else
277 data->cols[column].width = (WORD) -1;
278 data->cols[column].minwidth = (WORD) 5;
279 data->cols[column].maxwidth = (WORD) 0;
280 data->cols[column].mincolwidth = (WORD) 0;
281 data->cols[column].maxcolwidth = (WORD) 0;
282 data->cols[column].minpixwidth = (WORD) 6;
283 data->cols[column].maxpixwidth = (WORD) 0;
284 data->cols[column].bar = (BYTE) 2;
285 data->cols[column].width_type = (BYTE) CI_PERCENT;
286 data->cols[column].partcolsubst = PCS_DISABLED;
287 column++;
289 column = 0;
290 pos2 = 0;
291 while (strformat[pos2] && (column < colmax))
292 { pos1 = 0;
293 while ((strformat[pos2] != ',') && (strformat[pos2] != '\0'))
294 sf[pos1++] = strformat[pos2++];
295 sf[pos1++] = '\n';
296 sf[pos1++] = '\0';
297 if (strformat[pos2] != '\0')
298 pos2++;
299 /*D(bug("col %ld ->%s",column,sf));*/
301 ptr->RDA_Source.CS_Buffer = sf;
302 ptr->RDA_Source.CS_Length = strlen(sf);
303 ptr->RDA_Source.CS_CurChr = 0;
304 ptr->RDA_DAList = 0;
305 ptr->RDA_Buffer = NULL;
306 ptr->RDA_BufSiz = 0L;
307 ptr->RDA_ExtHelp = NULL;
308 ptr->RDA_Flags = 0L;
310 // clear the Line structure
311 memset(&Line, 0, sizeof(Line));
313 if((rdargs = ReadArgs(FORMAT_TEMPLATE, (APTR)&Line, ptr)))
315 if (Line.delta) data->cols[column].delta = (WORD) *Line.delta;
316 if (Line.preparse)
318 int len = strlen((char *)Line.preparse)+2;
319 if((data->cols[column].preparse = AllocVecPooled(data->Pool,len)) != NULL)
320 strlcpy(data->cols[column].preparse, (char *)Line.preparse, len);
322 if (Line.col) data->cols[column].col = (WORD) *Line.col;
323 if (Line.tbar) data->cols[column].bar = (WORD) 2;
324 if (Line.bar) data->cols[column].bar = (WORD) 1;
325 if (Line.nobar) data->cols[column].bar = (WORD) 0;
326 if (Line.sbar) data->cols[column].bar |= (WORD) 4;
327 if (Line.notb) data->cols[column].titlebutton = (WORD) FALSE;
329 if (Line.weight)
331 data->cols[column].width = (WORD) *Line.weight;
332 data->cols[column].width_type = (BYTE) CI_PERCENT;
333 if ((column == colmax-1) && !(oldlist && (column == 0)) && (data->cols[column].width == -1))
334 data->cols[column].width = (WORD) 100;
335 else if (data->cols[column].width < 0)
336 data->cols[column].width = (WORD) -1;
338 if (Line.colwidth)
339 { data->cols[column].width = (WORD) *Line.colwidth;
340 data->cols[column].width_type = (BYTE) CI_COL;
341 if (data->cols[column].width < 1)
342 data->cols[column].width = 1;
344 if (Line.pixwidth)
345 { data->cols[column].width = (WORD) *Line.pixwidth;
346 data->cols[column].width_type = (BYTE) CI_PIX;
347 if (data->cols[column].width < 4)
348 data->cols[column].width = 4;
351 if (Line.minwidth)
352 data->cols[column].minwidth = (WORD) *Line.minwidth;
353 if (Line.maxwidth)
354 data->cols[column].maxwidth = (WORD) *Line.maxwidth;
356 if (Line.mincolwidth)
357 data->cols[column].mincolwidth = (WORD) *Line.mincolwidth;
358 if (Line.maxcolwidth)
359 data->cols[column].maxcolwidth = (WORD) *Line.maxcolwidth;
361 if (Line.minpixwidth)
362 data->cols[column].minpixwidth = (WORD) *Line.minpixwidth;
363 if (Line.maxpixwidth)
364 data->cols[column].maxpixwidth = (WORD) *Line.maxpixwidth;
366 if(Line.partcolsubst)
368 char c = toupper(((char *)Line.partcolsubst)[0]);
370 switch(c)
372 case 'D':
373 data->cols[column].partcolsubst = PCS_DISABLED;
374 break;
376 case 'R':
377 data->cols[column].partcolsubst = PCS_RIGHT;
378 break;
380 case 'L':
381 data->cols[column].partcolsubst = PCS_LEFT;
382 break;
384 case 'C':
385 data->cols[column].partcolsubst = PCS_CENTER;
386 break;
390 data->cols[column].minx = (WORD) -1;
391 data->cols[column].maxx = (WORD) -1;
392 data->cols[column].dx = (WORD) 4;
393 FreeArgs(rdargs);
396 if (data->cols[column].width < 1)
399 if ((column == colmax-1) && (data->cols[column].width >= -1))
400 data->cols[column].width = (WORD) 100;
401 else
403 data->cols[column].width = (WORD) -1;
404 data->cols[column].width_type = (BYTE) CI_PERCENT;
406 if (data->cols[column].delta < 0) data->cols[column].delta = 0;
407 if ((data->cols[column].bar != 0) &&
408 (data->cols[column].delta < 2)) data->cols[column].delta += 2;
409 if (data->cols[column].minwidth < 1)
412 if ((column == colmax-1) && (data->cols[column].minwidth >= -1))
413 data->cols[column].minwidth = 5;
414 else
416 data->cols[column].minwidth = -1;
418 if (data->cols[column].maxwidth <= 4) data->cols[column].maxwidth = 1000;
419 if (data->cols[column].mincolwidth < 0) data->cols[column].mincolwidth = 0;
420 if (data->cols[column].maxcolwidth <= 0) data->cols[column].maxcolwidth = 5000;
421 if (data->cols[column].minpixwidth < 6) data->cols[column].minpixwidth = 6;
422 if (data->cols[column].maxpixwidth <= 5) data->cols[column].maxpixwidth = 20000;
423 if (data->cols[column].col > col) col = data->cols[column].col;
424 column++;
426 /* data->cols[colmax-1].width = (WORD) 100;*/
428 FreeDosObject(DOS_RDARGS, ptr);
429 FreeVecPooled(data->Pool, sf);
431 col = colmax;
432 column = 1;
433 while (column < data->numcols)
434 { col = 0;
435 colmax = 0;
436 while (colmax < column)
437 { if (data->cols[column].col == data->cols[colmax].col)
438 { colmax = 0;
439 while (colmax < data->numcols)
440 { if (col == data->cols[colmax].col)
441 { col++;
442 if (col >= DISPLAY_ARRAY_MAX)
443 col = 0;
444 colmax = 0;
446 else
447 colmax++;
449 data->cols[column].col = col++;
450 if (col >= DISPLAY_ARRAY_MAX)
451 col = 0;
452 colmax = 0;
454 else
455 colmax++;
457 column++;
460 column = 0;
461 while (column < data->numcols)
462 { data->column[column] = data->cols[column].col;
463 data->cols[column].c = &(data->cols[column]);
464 column++;
466 data->numcols2 = data->numcols;
468 data->format_chge = 1;
469 data->do_setcols = data->do_updatesb = data->do_wwrap = TRUE;
470 data->display_ptr = NULL;
471 /*D(bug("%lx|NL_Read_Format >%s<\n",obj,strformat));*/
472 if (data->SHOW)
474 if (!data->DRAW)
475 NL_SetObjInfos(data,TRUE);
476 NL_SetCols(data);
478 return (TRUE);
480 FreeDosObject(DOS_RDARGS, ptr);
482 FreeVecPooled(data->Pool ,sf);
484 return (FALSE);
489 static BOOL CCB_string(struct NLData *data, char **cbstr, char *str, LONG len, char lc, BOOL skipesc)
491 char *tmpcb;
492 char *tmp;
493 LONG tmpcblen;
495 if(str != NULL)
497 tmpcblen = len + 2;
498 if(*cbstr != NULL)
499 tmpcblen += strlen(*cbstr);
501 if((tmpcb = AllocVecPooled(data->Pool, tmpcblen)) != NULL)
503 tmp = tmpcb;
505 if(*cbstr != NULL)
507 tmp += strlcpy(tmp, *cbstr, tmpcblen);
508 FreeVecPooled(data->Pool, *cbstr);
511 if(skipesc)
512 tmp = stpncpy_noesc(tmp,str,len);
513 else
514 tmp += strlcpy(tmp, str, len);
516 tmp[0] = lc;
517 tmp[1] = '\0';
519 *cbstr = tmpcb;
521 return TRUE;
524 return FALSE;
527 return TRUE;
531 static BOOL CCB_entry(struct NLData *data,char **cbstr,APTR entptr,SIPTR ent,struct Hook *hook,SIPTR c1,SIPTR p1,SIPTR c2,SIPTR p2)
533 char **display_array = &data->DisplayArray[2];
534 char *str;
535 SIPTR pos1,pos2,len,prep1,prep2;
536 char lc;
537 BOOL ln = FALSE;
538 WORD colwrap,wrap = 0;
540 if ((ent >= 0) && data->EntriesArray[ent]->Wrap)
542 SIPTR ent1 = ent;
544 if (data->EntriesArray[ent]->Wrap & TE_Wrap_TmpLine)
545 ent1 -= data->EntriesArray[ent]->dnum;
546 entptr = data->EntriesArray[ent1]->Entry;
547 wrap = data->EntriesArray[ent]->Wrap;
549 if (p1 < -PREPARSE_OFFSET_ENTRY) /* begin in general column preparse string */
551 p1 += PREPARSE_OFFSET_COL;
552 prep1 = 2;
554 else if (p1 < -2)
556 p1 += PREPARSE_OFFSET_ENTRY; /* begin in display hook column preparse string */
557 prep1 = 1;
559 else if (p1 == -1) /* begin at beginning of column */
560 prep1 = 2;
561 else
562 prep1 = 0;
564 if (p2 < -PREPARSE_OFFSET_ENTRY) /* end in general column preparse string */
565 { p2 += PREPARSE_OFFSET_COL;
566 prep2 = 2;
568 else if (p2 < -2)
570 p2 += PREPARSE_OFFSET_ENTRY; /* end in display hook column preparse string */
571 prep2 = 1;
573 else if (p2 == -1) /* end at beginning of column */
574 prep2 = 2;
575 else
576 prep2 = 0;
578 if (entptr)
580 if (!hook)
581 hook = data->NList_CopyEntryToClipHook;
582 if (hook)
583 { display_array[0] = (char *) entptr;
584 data->DisplayArray[0] = (char *) data->NList_PrivateData;
585 data->DisplayArray[1] = (char *) ent;
586 display_array[1] = (char *) c1;
587 display_array[2] = (char *) p1;
588 display_array[3] = (char *) c2;
589 display_array[4] = (char *) p2;
590 display_array[5] = (char *) prep1;
591 display_array[6] = (char *) prep2;
592 if (c1 <= 0) display_array[1] = (char *) -1;
593 if (c1 >= data->numcols-1) display_array[1] = (char *) -2;
594 if (c2 <= 0) display_array[3] = (char *) -1;
595 if (c2 >= data->numcols-1) display_array[3] = (char *) -2;
596 if (data->NList_CopyEntryToClipHook2)
597 { data->DisplayArray[0] = (char *) entptr;
598 MyCallHookPkt(data->this,FALSE,hook,data->this,data->DisplayArray);
600 else
601 MyCallHookPkt(data->this,TRUE,hook,display_array,entptr);
602 data->display_ptr = NULL;
603 return (CCB_string(data,cbstr,display_array[0],strlen(display_array[0]),'\0',FALSE));
605 else
607 WORD column,col1,col2;
609 NL_GetDisplayArray(data,ent);
611 if ((c1 == -2) || (c1 >= data->numcols-1))
612 col1 = data->numcols-1;
613 else if (c1 < 0)
614 col1 = 0;
615 else
616 col1 = c1;
618 if ((c2 == -2) || (c2 >= data->numcols-1))
620 col2 = data->numcols-1;
621 if (p2==-2)
622 ln = TRUE;
624 else if (c2 < 0)
625 col2 = 0;
626 else
627 col2 = c2;
628 for (column = col1;column <= col2;column++)
630 colwrap = (1 << data->cols[column].c->col) & TE_Wrap_TmpMask;
631 str = display_array[data->cols[column].c->col];
632 pos1 = -1;
633 pos2 = -2;
634 if (column == col1)
635 pos1 = p1;
636 if (column == col2)
637 pos2 = p2;
638 if (column == col2)
639 { if (ln)
640 lc = '\n';
641 else
642 lc = '\0';
644 else
645 lc = '\t';
646 if ((wrap & TE_Wrap_TmpLine) && !(wrap & colwrap))
647 { if (!CCB_string(data,cbstr,str,0,lc,TRUE))
648 return (FALSE);
649 continue;
651 if (wrap && (wrap & colwrap))
652 { if (pos1 < 0)
653 pos1 = data->EntriesArray[ent]->pos;
654 if (pos2 < 0)
655 pos2 = data->EntriesArray[ent]->pos + data->EntriesArray[ent]->len;
657 if (data->NList_CopyColumnToClipHook)
658 { display_array[0] = (char *) str;
659 data->DisplayArray[0] = (char *) data->NList_PrivateData;
660 data->DisplayArray[1] = (char *) ent;
661 display_array[1] = (char *) pos1;
662 display_array[2] = (char *) pos2;
663 if (data->NList_CopyColumnToClipHook2)
664 { data->DisplayArray[0] = (char *) str;
665 MyCallHookPkt(data->this,FALSE,data->NList_CopyColumnToClipHook,data->this,data->DisplayArray);
667 else
668 MyCallHookPkt(data->this,TRUE,data->NList_CopyColumnToClipHook,display_array,(APTR) str);
669 data->display_ptr = NULL;
670 len = (SIPTR) display_array[1];
671 if (len < 0)
672 len = 0;
673 if (!CCB_string(data,cbstr,display_array[0],len,lc,FALSE))
674 return (FALSE);
676 else
677 { len = 0;
678 while ((str[len] != '\0') && (str[len] != '\n'))
679 len++;
680 if (pos2 > len)
681 pos2 = len;
682 if (pos1 > len)
683 { pos1 = len;
684 len = 0;
686 if (pos1 <= -2)
687 pos1 = len = 0;
688 else if (pos1 == -1)
689 pos1 = 0;
690 if (pos2 >= pos1)
691 len = pos2-pos1;
692 else if (pos2 == -1)
693 len = 0;
694 if (!CCB_string(data,cbstr,&str[pos1],len,lc,TRUE /* FALSE */ ))
695 return (FALSE);
698 return (TRUE);
700 return (FALSE);
702 return (TRUE);
706 #define CCB_ENTRY_PTR_HOOK(ep,h) \
707 ok = CCB_entry(data,&clipstr,ep,-1,h,-1,-1,-2,-2);
709 #define CCB_ENTRY_PTR(ep) \
710 ok = CCB_entry(data,&clipstr,ep,-1,NULL,-1,-1,-2,-2);
712 #define CCB_ENTRY(e) \
713 { if ((e >= 0) && (e < data->NList_Entries)) \
714 ok = CCB_entry(data,&clipstr,data->EntriesArray[e]->Entry,e,NULL,-1,-1,-2,-2); \
717 #define CCB_ENTRY_START_END(e,c1,p1,c2,p2) \
718 { if ((e >= 0) && (e < data->NList_Entries)) \
719 ok = CCB_entry(data,&clipstr,data->EntriesArray[e]->Entry,e,NULL,c1,p1,c2,p2); \
722 static LONG CopyToFile(STRPTR filename, STRPTR buffer)
724 LONG result = MUIV_NLCT_Failed;
726 ENTER();
728 if(buffer != NULL)
730 BPTR file = 0;
732 if((file = Open(filename, MODE_NEWFILE)) != 0)
734 LONG pstr = 0;
735 LONG lstr = strlen(buffer);
736 LONG ret = 0;
738 while(lstr > 0 && (ret = Write(file, &buffer[pstr], lstr)) >= 0)
740 lstr -= ret;
741 pstr += ret;
744 if(ret < 0)
745 result = MUIV_NLCT_WriteErr;
746 else
747 result = MUIV_NLCT_Success;
749 Close(file);
751 else
752 result = MUIV_NLCT_OpenErr;
755 RETURN(result);
756 return result;
759 SIPTR NL_CopyTo(struct NLData *data,LONG pos,char *filename,ULONG clipnum,APTR *entries,struct Hook *hook)
761 char *retstr = NULL;
762 char *clipstr = NULL;
763 SIPTR ok = TRUE;
764 LONG ent;
766 ENTER();
768 switch (pos)
770 case MUIV_NList_CopyToClip_Active :
771 CCB_ENTRY(data->NList_Active);
772 break;
774 case MUIV_NList_CopyToClip_Selected:
776 if(!data->NList_TypeSelect)
778 ent = 0;
779 while (ok && (ent < data->NList_Entries))
781 if (data->EntriesArray[ent]->Select != TE_Select_None)
783 CCB_ENTRY(ent);
785 ent++;
788 else
790 LONG c1,p1,c2,p2;
791 c1 = data->sel_pt[data->min_sel].column;
792 p1 = data->sel_pt[data->min_sel].colpos;
793 c2 = data->sel_pt[data->max_sel].column;
794 p2 = data->sel_pt[data->max_sel].colpos;
795 ent = data->sel_pt[data->min_sel].ent;
796 D(DBF_STARTUP, "ok=%d ent=%d mincol=%d maxcol=%d minpos=%d maxpos=%d", ok, ent, c1, c2, p1, p2);
797 if (ok && (ent >= 0) && (ent < data->NList_Entries))
799 if (ent == data->sel_pt[data->max_sel].ent)
801 CCB_ENTRY_START_END(ent,c1,p1,c2,p2);
802 break;
804 else
806 CCB_ENTRY_START_END(ent,c1,p1,-2,-2);
807 ent++;
810 while (ok && (ent >= 0) && (ent < data->sel_pt[data->max_sel].ent) && (ent < data->NList_Entries))
812 CCB_ENTRY(ent);
813 ent++;
815 if (ok && (ent >= 0) && (ent == data->sel_pt[data->max_sel].ent) && (ent < data->NList_Entries))
817 CCB_ENTRY_START_END(ent,-1,-1,c2,p2);
818 ent++;
822 break;
824 case MUIV_NList_CopyToClip_All :
825 { ent = 0;
826 while (ok && (ent < data->NList_Entries))
828 CCB_ENTRY(ent);
829 ent++;
832 break;
833 case MUIV_NList_CopyToClip_Entries :
835 APTR *array = (APTR *) entries;
836 ent = 0;
837 while (ok && array[ent])
839 CCB_ENTRY_PTR(array[ent]);
840 ent++;
843 break;
844 case MUIV_NList_CopyToClip_Entry :
845 CCB_ENTRY_PTR(entries);
846 break;
848 case MUIV_NList_CopyToClip_Strings :
850 APTR *array = (APTR *) entries;
851 ent = 0;
852 while (ok && array[ent])
854 CCB_ENTRY_PTR_HOOK(array[ent],hook);
855 ent++;
858 break;
860 case MUIV_NList_CopyToClip_String :
861 CCB_ENTRY_PTR_HOOK(entries,hook);
862 break;
864 default :
865 CCB_ENTRY(pos);
866 break;
869 if(filename != NULL)
871 ok = CopyToFile(filename, clipstr);
873 else if((LONG)clipnum >= 0)
875 ok = StringToClipboard(clipnum, clipstr);
877 else
879 int len = strlen(clipstr) + 1;
881 if((retstr = (char *)AllocVecShared(len, 0L)) != NULL)
882 strlcpy(retstr, clipstr, len);
883 ok = (SIPTR)retstr;
886 if(clipstr != NULL)
887 FreeVecPooled(data->Pool, clipstr);
889 RETURN(ok);
890 return ok;
894 IPTR mNL_CopyToClip(struct IClass *cl,Object *obj,struct MUIP_NList_CopyToClip *msg)
896 struct NLData *data = INST_DATA(cl,obj);
897 /*DoSuperMethodA(cl,obj,(Msg) msg);*/
899 if((LONG)msg->clipnum < 0)
900 return (0);
902 return ((IPTR) NL_CopyTo(data,msg->pos,NULL,msg->clipnum,msg->entries,msg->hook));
906 IPTR mNL_CopyTo(struct IClass *cl,Object *obj,struct MUIP_NList_CopyTo *msg)
908 struct NLData *data = INST_DATA(cl,obj);
909 SIPTR res;
910 /*DoSuperMethodA(cl,obj,(Msg) msg);*/
911 res = NL_CopyTo(data,msg->pos,msg->filename,-1,msg->entries,NULL);
912 *msg->result = (APTR) res;
913 return (IPTR)res;