Compiler warnings about misleading indentation removed.
[AROS-Contrib.git] / dopus / Program / select.c
blob356bcf99c88c03afdf1e8588659f73e93f92b190
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
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
15 GNU General Public License for more details.
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, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
33 static struct Directory *selectedentry;
35 void doselection(win,state)
36 int win,state;
38 int
39 a,b,c,d,e,x,y,ox,oy,fa,la,juststart,atot,drag,offx,offy,candrag,
40 comp=-1,oc,gad,multidrag=0,type,okrepeatdrag=0;
41 ULONG class;
42 UWORD code,qual;
43 char buf[40],*ptr;
44 struct Directory *next;
46 candrag=drag=(config->generalflags&GENERAL_DRAG && drag_bob_buffer)?1:0;
47 /*a=0;*/ atot=dopus_curwin[win]->total-scrdata_dispwin_lines;
48 a=makeactive(win,1);
49 if (dopus_curwin[win]->total==0) return;
50 ox=x=Window->MouseX; oy=y=Window->MouseY; selectedentry=NULL;
51 if (!a) {
52 a=(y-scrdata_dirwin_ypos[data_active_window])/scrdata_font_ysize;
53 if (drag) {
54 offx=x-scrdata_dirwin_xpos[data_active_window];
55 if (offx<0) offx=0;
56 else if (offx>drag_sprite.Width*16) offx=drag_sprite.Width*16;
57 offy=y-(scrdata_dirwin_ypos[data_active_window]+(a*scrdata_font_ysize));
59 if ((b=select(win,a))==2) {
60 return;
62 if (!b || !selectedentry) drag=0;
63 a=juststart=0;
64 Window->Flags|=WFLG_REPORTMOUSE;
65 FOREVER {
66 while (getintuimsg()) {
67 gotmsgloop:
68 class=IMsg->Class; code=IMsg->Code; qual=IMsg->Qualifier;
69 ReplyMsg((struct Message *) IMsg);
70 getcoordsloop:
71 x=Window->MouseX; y=Window->MouseY;
72 okrepeatdrag=0;
73 if (class==MOUSEBUTTONS) {
74 if (code==MENUDOWN && candrag && selectedentry) {
75 status_haveaborted=status_justabort=0;
76 if (drag!=2) goto startdragging;
77 else {
78 drag=0;
79 goto enddragging;
82 else if (code==SELECTUP) {
83 a=1;
84 break;
87 else if (class==MOUSEMOVE) {
88 if (drag==2) {
89 if (x!=ox || y!=oy) {
90 if (scr_gadget_rows && dopus_curgadbank) {
91 oc=gadgetfrompos(x,y); gad=oc+(data_gadgetrow_offset*7);
92 if (oc>-1 && !(isvalidgad(&dopus_curgadbank->gadgets[gad]))) oc=-1;
93 if (oc!=comp) {
94 RemIBob(&drag_bob,main_rp,ViewPortAddress(Window));
95 if (comp>-1) dragcompgad(comp,0);
96 if (oc>-1 && isvalidgad(&dopus_curgadbank->gadgets[gad])) {
97 dragcompgad(oc,1);
98 comp=oc;
100 else comp=-1;
101 AddBob(&drag_bob,main_rp);
104 drag_sprite.X=x-offx; drag_sprite.Y=y-offy;
105 SortGList(main_rp);
106 DrawGList(main_rp,ViewPortAddress(Window));
107 WaitTOF();
109 ox=x; oy=y;
111 else {
112 fa=(y-scrdata_dirwin_ypos[data_active_window])/scrdata_font_ysize; la=(oy-scrdata_dirwin_ypos[data_active_window])/scrdata_font_ysize;
113 if (fa==la && drag && selectedentry) {
114 if (x<scrdata_dirwin_xpos[data_active_window] || x>scrdata_dirwin_xpos[data_active_window]+scrdata_dirwin_width[data_active_window]) {
115 startdragging:
116 ptr=NULL;
117 if (qual&IEQUALIFIER_ANYSHIFT && dopus_curwin[win]->filesel>1) {
118 multidrag=1;
119 lsprintf(buf,globstring[STR_MULTI_DRAG],dopus_curwin[win]->filesel);
120 ptr=buf;
121 type=-1;
123 else {
124 if (selectedentry->type==ENTRY_CUSTOM) {
125 switch (selectedentry->subtype) {
126 case CUSTOMENTRY_BUFFERLIST:
127 ptr=selectedentry->comment;
128 break;
129 case CUSTOMENTRY_DIRTREE:
130 ptr=selectedentry->dispstr;
131 break;
132 case CUSTOMENTRY_USER:
133 if (selectedentry->size&CUSTENTRY_CANSELECT)
134 ptr=selectedentry->comment;
135 break;
138 else ptr=selectedentry->name;
139 type=selectedentry->type;
141 if (ptr) {
142 dotaskmsg(clockmsg_port,CLOCK_ACTIVE,0,0,NULL,0);
143 SetAPen(&drag_bob_rastport,
144 (type<=ENTRY_FILE ||
145 (type==ENTRY_DEVICE &&
146 (selectedentry->size==DLT_DEVICE || selectedentry->size==DLT_VOLUME)))?
147 screen_pens[config->filesselfg].pen:
148 screen_pens[config->dirsselfg].pen);
149 SetRast(&drag_bob_rastport,
150 (type<=ENTRY_FILE ||
151 (type==ENTRY_DEVICE &&
152 (selectedentry->size==DLT_DEVICE || selectedentry->size==DLT_VOLUME)))?
153 screen_pens[config->filesselbg].pen:
154 screen_pens[config->dirsselbg].pen);
155 Move(&drag_bob_rastport,0,scr_font[FONT_DIRS]->tf_Baseline);
156 c=(drag_sprite.Width*16)/scrdata_font_xsize;
157 d=strlen(ptr);
158 if (d>c) e=d-c;
159 else {
160 e=0;
161 c=d;
163 Text(&drag_bob_rastport,&ptr[e],c);
164 drag_sprite.X=x-offx; drag_sprite.Y=y-offy;
165 AddBob(&drag_bob,main_rp);
166 SortGList(main_rp);
167 DrawGList(main_rp,ViewPortAddress(Window));
168 WaitTOF();
169 drag=2; y=-1;
173 else {
174 if (drag) drag=0;
175 if (la<fa) {
176 ++fa; ++la;
177 d=la; la=fa; fa=d;
179 if (y>=scrdata_dispwin_ypos && y<scrdata_dispwin_height+scrdata_dispwin_ypos) {
180 if (state) {
181 for (d=fa;d<la;d++) defselect(win,d,b);
184 else if (y<scrdata_dispwin_ypos) {
185 if (juststart!=-1) {
186 if (fa<0) fa=0;
187 if (la>=scrdata_dispwin_lines) la=scrdata_dispwin_lines;
188 if (state) {
189 for (d=fa;d<la;d++) defselect(win,d,b);
190 defselect(win,0,b);
192 juststart=-1;
194 if (dopus_curwin[win]->offset==0) continue;
195 verticalscroll(win,-1);
196 if (state) defselect(win,0,b);
197 okrepeatdrag=1;
199 else if (y>=scrdata_dispwin_height+scrdata_dispwin_ypos) {
200 if (juststart!=1) {
201 if (fa<0) fa=0;
202 if (la>=scrdata_dispwin_lines) la=scrdata_dispwin_lines;
203 if (state) {
204 for (d=fa;d<la;d++) defselect(win,d,b);
205 defselect(win,scrdata_dispwin_lines-1,b);
207 juststart=1;
209 if (dopus_curwin[win]->offset==atot) continue;
210 verticalscroll(win,1);
211 if (state) defselect(win,scrdata_dispwin_lines-1,b);
212 okrepeatdrag=1;
215 oy=y;
219 if (a) break;
220 if (getintuimsg()) goto gotmsgloop;
221 if (okrepeatdrag) goto getcoordsloop;
222 Wait(1<<Window->UserPort->mp_SigBit);
224 if (drag==2) {
225 enddragging:
226 RemIBob(&drag_bob,main_rp,ViewPortAddress(Window));
227 if (comp>-1) dragcompgad(comp,0);
228 dotaskmsg(clockmsg_port,CLOCK_ACTIVE,1,0,NULL,0);
229 if (x>=scrdata_dirwin_xpos[1-data_active_window] &&
230 x<=scrdata_dirwin_xpos[1-data_active_window]+scrdata_dirwin_width[1-data_active_window] &&
231 y>=scrdata_dirwin_ypos[1-data_active_window] &&
232 y<=scrdata_dirwin_ypos[1-data_active_window]+scrdata_dirwin_height && drag==2) {
233 if (multidrag) {
234 last_selected_entry=dopus_curwin[win]->firstentry;
235 while (last_selected_entry) {
236 if (status_haveaborted || status_justabort) {
237 myabort();
238 break;
240 next=last_selected_entry->next;
241 if (last_selected_entry->type<=ENTRY_FILE && last_selected_entry->selected) {
242 CurrentTime(&time_previous_sec,&time_previous_micro);
243 time_current_sec=time_previous_sec;
244 time_current_micro=time_previous_micro;
245 makeactive(1-data_active_window,1);
247 last_selected_entry=next;
250 else {
251 time_previous_sec=time_current_sec;
252 time_previous_micro=time_current_micro;
253 last_selected_entry=selectedentry;
254 makeactive(1-data_active_window,1);
257 else if (comp>-1) {
258 gad=comp+(data_gadgetrow_offset*7);
259 if (dopus_curgadbank && isvalidgad(&dopus_curgadbank->gadgets[gad])) {
260 if (multidrag) {
261 last_selected_entry=NULL;
262 func_single_file[0]=0;
263 status_flags|=STATUS_GLOBALFILE;
265 else {
266 last_selected_entry=selectedentry;
267 strcpy(func_single_file,selectedentry->name);
268 if (selectedentry->selected) unselect(data_active_window,selectedentry);
270 dofunctionstring(dopus_curgadbank->gadgets[gad].function,
271 dopus_curgadbank->gadgets[gad].name,
272 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[gad].which);
273 status_flags&=~STATUS_GLOBALFILE;
274 if (!multidrag) checkselection(selectedentry);
278 Window->Flags&=~WFLG_REPORTMOUSE;
282 void dormbscroll(win)
283 int win;
285 ULONG class;
286 UWORD code;
287 int x,y,d,__unused a,__unused ret=0;
288 __unused struct Directory *temp;
290 if (data_active_window!=win) {
291 makeactive(win,0);
292 ret=1;
294 #ifdef _USE_SMALL_Q
295 if (dopus_curwin[win]->total>0 && status_flags&STATUS_IANSCRAP) {
296 CurrentTime(&time_current_sec,&time_current_micro);
297 y=Window->MouseY;
298 a=(y-scrdata_dirwin_ypos[data_active_window]-2)/scrdata_font_ysize;
299 if (a<scrdata_dispwin_lines) {
300 a+=dopus_curwin[win]->offset;
301 if (a<=dopus_curwin[win]->total) {
302 temp=dopus_curwin[win]->firstentry;
303 while (a--) temp=temp->next;
304 if (temp && temp->type<=ENTRY_FILE && temp->selected &&
305 (DoubleClick(time_previous_sec,time_previous_micro,
306 time_current_sec,time_current_micro)) &&
307 last_selected_entry==temp &&
308 config->generalflags&GENERAL_DOUBLECLICK) {
309 unselect(win,temp);
310 ftype_doubleclick(str_pathbuffer[win],temp->name,0);
311 unbusy();
312 time_previous_sec=0;
313 return;
317 if (ret) return;
319 #endif
320 FOREVER {
321 while (!getintuimsg()) {
322 x=Window->MouseX; y=Window->MouseY;
323 d=0;
324 if (y<scr_scroll_borders[win].MinY) {
325 verticalscroll(win,-1);
326 if (y>scr_scroll_borders[win].MinY-(scrdata_font_ysize*4)) d=1;
328 else if (y>scr_scroll_borders[win].MaxY) {
329 verticalscroll(win,1);
330 if (y<scr_scroll_borders[win].MaxY+(scrdata_font_ysize*4)) d=1;
332 else if (x<scr_scroll_borders[win].MinX) horizontalscroll(win,-1);
333 else if (x>scr_scroll_borders[win].MaxX) horizontalscroll(win,1);
334 if (d) Delay(d);
336 class=IMsg->Class; code=IMsg->Code;
337 ReplyMsg((struct Message *) IMsg);
338 if (class==MOUSEBUTTONS && code==MENUUP) break;
342 int select(win,o)
343 int win,o;
345 int a,dbclick/*=0*/,sel=1,foundcount;
346 char sbuf[FILEBUF_SIZE],*dir;
347 struct Directory *temp,*temp2;
349 a=o+dopus_curwin[win]->offset;
350 if (o>=scrdata_dispwin_lines || a>=dopus_curwin[win]->total) return(0);
351 temp=dopus_curwin[win]->firstentry;
352 while (a--) temp=temp->next;
353 selectedentry=temp;
354 if (temp && ((ENTRYTYPE(temp->type)!=ENTRY_CUSTOM) ||
355 (temp->subtype!=CUSTOMENTRY_USER) || (temp->size&CUSTENTRY_CANSELECT))) {
356 sel=temp->selected;
357 temp->selected=sel?FALSE:TRUE;
358 updateselectinfo(temp,win,1);
359 if (!status_iconified) {
360 display_entry(temp,win,
361 scrdata_dirwin_xpos[win]-dopus_curwin[win]->hoffset+1,
362 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
363 if (config->iconflags&ICONFLAG_AUTOSELECT) {
364 StrCombine(sbuf,temp->name,".info",FILEBUF_SIZE-1);
365 if ((temp2=findfile(dopus_curwin[win],sbuf,&foundcount))) {
366 if (temp2->selected!=temp->selected) {
367 temp2->selected=temp->selected;
368 updateselectinfo(temp2,win,1);
369 if (foundcount>=dopus_curwin[win]->offset &&
370 foundcount<dopus_curwin[win]->offset+scrdata_dispwin_lines) {
371 o=foundcount-dopus_curwin[win]->offset;
372 display_entry(temp2,win,
373 scrdata_dirwin_xpos[win]-dopus_curwin[win]->hoffset+1,
374 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
382 if (last_selected_entry!=temp ||
383 !(dbclick=DoubleClick(time_previous_sec,time_previous_micro,
384 time_current_sec,time_current_micro))) {
385 last_selected_entry=temp;
387 time_previous_sec=time_current_sec;
388 time_previous_micro=time_current_micro;
391 if (sel) {
392 dbclick=DoubleClick(time_previous_sec,time_previous_micro,
393 time_current_sec,time_current_micro);
395 else {
396 dbclick=-1;
397 time_previous_sec=time_current_sec;
398 time_previous_micro=time_current_micro;
401 switch (ENTRYTYPE(temp->type)) {
402 case ENTRY_DEVICE:
403 case ENTRY_DIRECTORY:
404 if (dbclick==-1) last_selected_entry=temp;
405 else if (dbclick && last_selected_entry==temp) {
406 dir=dopus_curwin[win]->directory;
407 if (!(dopus_curwin[win]->flags & DWF_ARCHIVE)) advancebuf(win,1);
408 if (temp->type==ENTRY_DEVICE) strcpy(str_pathbuffer[win],temp->name);
409 else
411 if (temp->subtype == ST_SOFTLINK)
413 struct FileInfoBlock __aligned fib;
414 struct DevProc *dp;
415 BPTR ld, lf;
416 char linkbuf[512],buf[256];
418 strcpy(linkbuf,dir);
421 //D(bug("SoftLink! path: %s\t name: %s\n",linkbuf,temp->name));
422 ld = Lock(linkbuf,ACCESS_READ);
423 if (dp = GetDeviceProc(linkbuf,NULL))
425 //D(bug("DeviceProc: %lX\n",dp));
426 if (ReadLink(dp->dvp_Port,ld,temp->name,buf,256))
428 AddPart(linkbuf,buf,512);
429 //D(bug("Resolved: %s\n",linkbuf));
430 if (lf = Lock(linkbuf,ACCESS_READ))
432 //D(bug("Locked\n"));
433 NameFromLock(lf,linkbuf,512);
434 if (Examine(lf,&fib))
436 //D(bug("Examined: type: %ld, name: %s\n",fib.fib_DirEntryType,fib.fib_FileName));
437 if (fib.fib_DirEntryType == ST_SOFTLINK) *PathPart(linkbuf) = 0;
439 UnLock(lf);
441 else
443 //D(bug("Lock() failed!\n"));
444 fib.fib_DirEntryType = ST_USERDIR;
447 FreeDeviceProc(dp);
448 UnLock(ld);
450 } while (fib.fib_DirEntryType == ST_SOFTLINK);
451 strcpy(str_pathbuffer[win],linkbuf);
453 else
455 strcpy(str_pathbuffer[win],dir);
456 TackOn(str_pathbuffer[win],temp->name,256);
459 D(bug("Get dir: %s\n",str_pathbuffer[win]));
460 startgetdir(win,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
461 time_previous_sec=0;
462 return(2);
464 break;
466 case ENTRY_CUSTOM:
467 if (dbclick==-1) last_selected_entry=temp;
468 else if (dbclick && last_selected_entry==temp) {
469 if (temp->subtype==CUSTOMENTRY_BUFFERLIST ||
470 temp->subtype==CUSTOMENTRY_DIRTREE) {
471 if (temp->subtype==CUSTOMENTRY_BUFFERLIST)
472 bringinbuffer(last_selected_entry->dispstr,win,1);
473 else {
474 strcpy(str_pathbuffer[win],last_selected_entry->dispstr);
475 startgetdir(win,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
477 time_previous_sec=0;
478 return(2);
480 else if (temp->subtype==CUSTOMENTRY_USER) {
481 userentrymessage(dopus_curwin[win],temp,USERENTRY_DOUBLECLICK);
482 time_previous_sec=0;
483 return(2);
486 break;
488 case ENTRY_FILE:
489 if (dbclick==-1) last_selected_entry=temp;
490 else if (dbclick && last_selected_entry==temp) {
491 if (config->generalflags&GENERAL_DOUBLECLICK) {
492 if (dopus_curwin[win]->flags & DWF_ARCHIVE)
494 char path[256], tempname[FILEBUF_SIZE];
496 strcpy(path,"T:");
497 if (unarcfiledir(dopus_curwin[win],path,tempname,temp->name))
499 ftype_doubleclick(path,tempname,1);
500 AddPart(path,tempname,256);
501 removetemparcfile(path);
504 else ftype_doubleclick(str_pathbuffer[win],temp->name,1);
505 unbusy();
506 time_previous_sec=0;
507 return(2);
510 break;
513 return(!sel);
516 int unselect(win,file)
517 int win;
518 struct Directory *file;
520 int a=0;
521 struct Directory *t;
523 if (win==-1 || !file->selected) return(0);
524 t=dopus_curwin[win]->firstentry;
525 while (t!=file && t) {
526 ++a;
527 t=t->next;
529 if (!t) return(0);
530 switch (ENTRYTYPE(file->type)) {
531 case ENTRY_DIRECTORY:
532 case ENTRY_DEVICE:
533 --dopus_curwin[win]->dirsel;
534 if (file->type>0 && file->size!=-1) dopus_curwin[win]->bytessel-=file->size;
535 break;
536 case ENTRY_FILE:
537 --dopus_curwin[win]->filesel;
538 dopus_curwin[win]->bytessel-=file->size;
539 break;
541 file->selected=FALSE;
542 if (a<dopus_curwin[win]->offset ||
543 a>(dopus_curwin[win]->offset+scrdata_dispwin_lines-1)) return(0);
544 a-=dopus_curwin[win]->offset;
545 if (!status_iconified) {
546 display_entry(t,win,
547 scrdata_dirwin_xpos[win]-dopus_curwin[win]->hoffset+1,
548 scrdata_font_baseline+(scrdata_font_ysize*a)+scrdata_dirwin_ypos[win]);
550 return(1);
553 void defselect(win,o,state)
554 int win,o,state;
556 int a,foundcount;
557 struct Directory *temp,*temp2;
558 char sbuf[FILEBUF_SIZE];
560 if (o<0 || o>scrdata_dispwin_lines-1) return;
561 a=o+dopus_curwin[win]->offset;
562 if (a>=dopus_curwin[win]->total) return;
563 temp=dopus_curwin[win]->firstentry;
564 while (a--) temp=temp->next;
565 if (state) selectedentry=temp;
566 else selectedentry=NULL;
567 if (temp && ((ENTRYTYPE(temp->type)!=ENTRY_CUSTOM) ||
568 (temp->subtype!=CUSTOMENTRY_USER) || (temp->size&CUSTENTRY_CANSELECT))) {
569 if (temp->selected!=state) {
570 temp->selected=state;
571 updateselectinfo(temp,win,1);
572 if (!status_iconified) {
573 display_entry(temp,win,
574 scrdata_dirwin_xpos[win]-dopus_curwin[win]->hoffset+1,
575 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
578 if (config->iconflags&ICONFLAG_AUTOSELECT) {
579 StrCombine(sbuf,temp->name,".info",FILEBUF_SIZE-1);
580 if ((temp2=findfile(dopus_curwin[win],sbuf,&foundcount))) {
581 if (temp2->selected!=temp->selected) {
582 temp2->selected=temp->selected;
583 updateselectinfo(temp2,win,1);
584 if (foundcount>=dopus_curwin[win]->offset &&
585 foundcount<dopus_curwin[win]->offset+scrdata_dispwin_lines) {
586 if (!status_iconified) {
587 o=foundcount-dopus_curwin[win]->offset;
588 display_entry(temp2,win,
589 scrdata_dirwin_xpos[win]-dopus_curwin[win]->hoffset+1,
590 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
599 void globalselect(win,all)
600 int win,all;
602 struct Directory *temp;
604 if ((temp=dopus_curwin[win]->firstentry) && temp->type!=ENTRY_CUSTOM) {
605 while (temp) {
607 if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
608 temp->size&CUSTENTRY_CANSELECT) temp->selected=all;
610 temp->selected=all;
611 temp=temp->next;
613 if (all) {
614 dopus_curwin[win]->filesel=dopus_curwin[win]->filetot;
615 dopus_curwin[win]->dirsel=dopus_curwin[win]->dirtot;
616 dopus_curwin[win]->bytessel=dopus_curwin[win]->bytestot;
618 else {
619 dopus_curwin[win]->filesel=0;
620 dopus_curwin[win]->dirsel=0;
621 dopus_curwin[win]->bytessel=0;
623 doselinfo(win);
627 void updateselectinfo(temp,win,show)
628 struct Directory *temp;
629 int win,show;
631 if (temp->selected) {
632 switch (ENTRYTYPE(temp->type)) {
633 case ENTRY_DIRECTORY:
634 if (temp->size!=-1) dopus_curwin[win]->bytessel+=temp->size;
635 case ENTRY_DEVICE:
636 ++dopus_curwin[win]->dirsel;
637 break;
638 case ENTRY_FILE:
639 ++dopus_curwin[win]->filesel;
640 dopus_curwin[win]->bytessel+=temp->size;
641 break;
643 if (show) {
644 if (config->generalflags&GENERAL_DISPLAYINFO) doinfodisplay(temp,TRUE);
645 else doselinfo(data_active_window);
648 else {
649 switch (ENTRYTYPE(temp->type)) {
650 case ENTRY_DIRECTORY:
651 if (temp->size!=-1) dopus_curwin[win]->bytessel-=temp->size;
652 case ENTRY_DEVICE:
653 --dopus_curwin[win]->dirsel;
654 break;
655 case ENTRY_FILE:
656 --dopus_curwin[win]->filesel;
657 dopus_curwin[win]->bytessel-=temp->size;
658 break;
660 if (show) doselinfo(data_active_window);
664 void globaltoggle(win)
665 int win;
667 struct Directory *temp;
669 temp=dopus_curwin[win]->firstentry;
670 while (temp) {
671 switch (ENTRYTYPE(temp->type)) {
672 case ENTRY_FILE:
673 if (temp->selected) {
674 dopus_curwin[win]->bytessel-=temp->size;
675 --dopus_curwin[win]->filesel;
676 temp->selected=0;
678 else {
679 dopus_curwin[win]->bytessel+=temp->size;
680 ++dopus_curwin[win]->filesel;
681 temp->selected=1;
683 break;
684 case ENTRY_DIRECTORY:
685 if (temp->selected) {
686 if (temp->size>0) dopus_curwin[win]->bytessel-=temp->size;
687 --dopus_curwin[win]->dirsel;
688 temp->selected=0;
690 else {
691 if (temp->size>0) dopus_curwin[win]->bytessel+=temp->size;
692 ++dopus_curwin[win]->dirsel;
693 temp->selected=1;
695 break;
697 temp=temp->next;
699 doselinfo(win);
702 void doselect(rexx)
703 int rexx;
705 char buf[160];
706 int boobs,prot[2];
707 struct DateStamp ds1,ds2;
708 int selecttype;
710 if (dopus_curwin[data_active_window]->total==0 ||
711 dopus_curwin[data_active_window]->firstentry->type==ENTRY_CUSTOM) return;
713 if (!rexx) {
714 boobs=getselectdata(str_select_pattern,&selecttype);
716 else {
717 boobs=rexx_arg_value[0]; selecttype=rexx_arg_value[1];
718 strcpy(str_select_pattern[selecttype],rexx_args[0]);
720 if (boobs) {
721 if (dopus_curwin[data_active_window]->total==0) return;
722 switch (selecttype) {
723 case 0:
724 LParsePatternI(str_select_pattern[0],buf);
725 wildselect(buf,boobs,1,WILDSELECT_NAME);
726 findfirstsel(data_active_window,-2);
727 break;
728 case 1:
729 if (str_select_pattern[1][0]==0) break;
730 getseldatestamps(str_select_pattern[1],&ds1,&ds2);
731 dateselect(&ds1,&ds2,boobs,1);
732 findfirstsel(data_active_window,-2);
733 break;
734 case 2:
735 if (str_select_pattern[2][0]==0) break;
736 getprotselvals(str_select_pattern[2],prot);
737 protselect(prot[0],prot[1],boobs,1);
738 findfirstsel(data_active_window,-2);
739 break;
740 case 3:
741 LParsePatternI(str_select_pattern[3],buf);
742 wildselect(buf,boobs,1,WILDSELECT_COMMENT);
743 findfirstsel(data_active_window,-2);
744 break;
749 void getseldatestamps(buf,ds1,ds2)
750 char *buf;
751 struct DateStamp *ds1,*ds2;
753 char datebuf[2][85],timebuf[2][85],*ptr;
754 int a/*,b*/;
756 datebuf[0][0]=datebuf[1][0]=timebuf[0][0]=timebuf[1][0]=a/*=b*/=0;
757 ptr=parsedatetime(buf/*str_select_pattern[1]*/,datebuf[0],timebuf[0],&a);
758 switch (a) {
759 case 0:
760 strcpy(datebuf[1],datebuf[0]);
761 strcpy(timebuf[1],"23:59:59");
762 break;
763 case -1:
764 strcpy(datebuf[1],datebuf[0]);
765 strcpy(timebuf[1],timebuf[0]);
766 break;
767 default:
768 parsedatetime(ptr,datebuf[1],timebuf[1],&a/*&b*/);
769 break;
771 D(bug("getseldatestamps(%s,%s,%s,%s)\n",datebuf[0],timebuf[0],datebuf[1],timebuf[1]));
772 strtostamp(datebuf[0],timebuf[0],ds1);
773 strtostamp(datebuf[1],timebuf[1],ds2);
774 ds1->ds_Tick=((ds1->ds_Tick/50)*50);
775 ds2->ds_Tick=((ds2->ds_Tick/50)*50)+49;
776 D(bug("getseldatestamp: ds1=%ld,%ld,%ld\n",ds1->ds_Days,ds1->ds_Minute,ds1->ds_Tick));
777 D(bug("getseldatestamp: ds2=%ld,%ld,%ld\n",ds2->ds_Days,ds2->ds_Minute,ds2->ds_Tick));
780 void getprotselvals(buf,prot)
781 char *buf;
782 int *prot;
784 int a,b,c,notflag=0;
785 char ch;
787 prot[0]=prot[1]=0;
788 b=strlen(buf);
789 for (a=0;a<b;a++) {
790 ch=ToUpper(buf[a]);
791 if (ch=='-') notflag=1;
792 else if (ch=='+') notflag=0;
793 else {
794 for (c=0;c<8;c++) {
795 if (ch==str_protbits[c]) {
796 prot[notflag]|=(1<<(7-c));
797 break;
804 void wildselect(wild,boobs,and,mode)
805 char *wild;
806 int boobs,and,mode;
808 char buf[256];
809 struct Directory *temp;
811 temp=dopus_curwin[data_active_window]->firstentry;
812 #ifdef __SASC__
813 if (!and)
815 dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel= 0;
816 dopus_curwin[data_active_window]->bytessel=0;
818 #else
819 if (!and) dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel=dopus_curwin[data_active_window]->bytessel=0;
820 #endif
821 while (temp) {
822 if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
823 temp->size&CUSTENTRY_CANSELECT) {
824 if (!and) temp->selected=0;
825 if (temp->type==ENTRY_CUSTOM) {
826 if (!temp->selected && temp->comment) {
827 StrToUpper(temp->comment,buf);
828 if (LMatchPatternI(wild,buf)) wildselectthisone(temp,data_active_window,boobs);
831 else {
832 if (!temp->selected) {
833 StrToUpper((mode==WILDSELECT_NAME)?temp->name:temp->comment,buf);
834 if (LMatchPatternI(wild,buf)) wildselectthisone(temp,data_active_window,boobs);
838 temp=temp->next;
840 refreshwindow(data_active_window,0);
841 doselinfo(data_active_window);
844 void dateselect(ds1,ds2,boobs,and)
845 struct DateStamp *ds1,*ds2;
846 int boobs,and;
848 struct Directory *temp;
850 temp=dopus_curwin[data_active_window]->firstentry;
851 if (!and) {
852 dopus_curwin[data_active_window]->dirsel=
853 dopus_curwin[data_active_window]->filesel=
854 dopus_curwin[data_active_window]->bytessel=0;
856 while (temp) {
857 if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
858 temp->size&CUSTENTRY_CANSELECT) {
859 if (!and) temp->selected=0;
860 if (!temp->selected &&
861 CompareDate(&(temp->date),ds1)>=0 && CompareDate(ds2,&(temp->date))>=0)
862 wildselectthisone(temp,data_active_window,boobs);
864 temp=temp->next;
866 refreshwindow(data_active_window,0);
867 doselinfo(data_active_window);
870 void protselect(protyes,protno,boobs,and)
871 int protyes,protno,boobs,and;
873 struct Directory *temp;
874 int prot;
876 temp=dopus_curwin[data_active_window]->firstentry;
877 #ifdef __SASC__
878 if (!and)
880 dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel=0;
881 dopus_curwin[data_active_window]->bytessel=0;
883 #else
884 if (!and) dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel=dopus_curwin[data_active_window]->bytessel=0;
885 #endif
886 while (temp) {
887 if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
888 temp->size&CUSTENTRY_CANSELECT) {
889 if (!and) temp->selected=0;
890 if (!temp->selected) {
891 prot=((~temp->protection)&15)+(temp->protection&~15);
892 if ((prot&protyes)==protyes && ((prot&~protyes)&protno)==0)
893 wildselectthisone(temp,data_active_window,boobs);
896 temp=temp->next;
898 refreshwindow(data_active_window,0);
899 doselinfo(data_active_window);
902 void wildselectthisone(temp,win,boobs)
903 struct Directory *temp;
904 int win,boobs;
906 if (boobs==1 && temp->type!=ENTRY_DEVICE) temp->selected=1;
907 else if (boobs==2 && temp->type<=ENTRY_FILE) temp->selected=1;
908 else if (boobs==3 && temp->type>=ENTRY_DIRECTORY) temp->selected=1;
909 if (temp->selected) {
910 if (temp->type>=ENTRY_DIRECTORY) {
911 ++dopus_curwin[win]->dirsel;
912 if (temp->size!=-1) dopus_curwin[win]->bytessel+=temp->size;
914 else if (temp->type<=ENTRY_FILE) {
915 ++dopus_curwin[win]->filesel;
916 dopus_curwin[win]->bytessel+=temp->size;
921 void doselinfo(win)
922 int win;
924 char b1[24],b2[24];
926 if (!dopus_curwin[win]->firstentry || dopus_curwin[win]->firstentry->type!=ENTRY_CUSTOM) {
927 buildkmgstring(b1,/*(long long)*/dopus_curwin[win]->bytessel,config->listerdisplayflags[win] & SIZE_KMG);
928 buildkmgstring(b2,/*(long long)*/dopus_curwin[win]->bytestot,config->listerdisplayflags[win] & SIZE_KMG);
929 D(bug("doselinfo(): b1 = %s, b2 = %s\n",b1,b2));
930 lsprintf(str_select_info,globstring[STR_DIRS_FILES_BYTES_COUNT],
931 dopus_curwin[win]->dirsel,dopus_curwin[win]->dirtot,dopus_curwin[win]->filesel,
932 dopus_curwin[win]->filetot,b1,b2);
934 else {
935 switch (dopus_curwin[win]->firstentry->subtype) {
936 case CUSTOMENTRY_DIRTREE:
937 lsprintf(str_select_info,globstring[STR_ENTRIES_IN_TREE],dopus_curwin[win]->total);
938 break;
939 case CUSTOMENTRY_BUFFERLIST:
940 lsprintf(str_select_info,globstring[STR_DIRS_IN_BUFFERS],dopus_curwin[win]->total);
941 break;
942 case CUSTOMENTRY_USER:
943 lsprintf(str_select_info,globstring[STR_USER_ENTRIES],dopus_curwin[win]->total);
944 break;
947 dostatustext(str_select_info);
950 int makeactive(win,state)
951 int win,state;
953 if (data_active_window!=win) {
954 data_active_window=win;
955 return(doactive(state,1));
957 return(0);
960 int doactive(state,showinfo)
961 int state,showinfo;
963 int oe;
964 char buf[256];
965 struct dopusfiletype *type;
966 struct dopusfuncpar par;
967 struct Directory *entry;
969 if (status_iconified) return(0);
970 if (showinfo) doselinfo(data_active_window);
971 if (last_selected_entry &&
972 last_selected_entry->type<=ENTRY_FILE) {
973 if (state && config->generalflags&GENERAL_DOUBLECLICK) {
974 if (DoubleClick(time_previous_sec,time_previous_micro,
975 time_current_sec,time_current_micro)) {
976 data_active_window=1-data_active_window;
977 unselect(data_active_window,last_selected_entry);
978 entry=last_selected_entry;
979 dostatustext(globstring[STR_INTERROGATING_FILE]);
980 StrCombine(buf,str_pathbuffer[data_active_window],last_selected_entry->name,256);
981 busy();
982 if ((type=checkfiletype(buf,FTFUNC_CLICKMCLICK,0))) {
983 char title[256];
985 strcpy(func_single_file,last_selected_entry->name);
986 par.which=type->which[FTFUNC_CLICKMCLICK];
987 par.stack=type->stack[FTFUNC_CLICKMCLICK];
988 par.key=par.qual=0; par.type=3;
989 par.pri=type->pri[FTFUNC_CLICKMCLICK];
990 par.delay=type->delay[FTFUNC_CLICKMCLICK];
992 if (type->actionstring[FTFUNC_CLICKMCLICK][0]) {
993 do_title_string(type->actionstring[FTFUNC_CLICKMCLICK],title,0,NULL);
994 dostatustext(title);
996 else title[0]=0;
998 dofunctionstring(type->function[FTFUNC_CLICKMCLICK],
999 last_selected_entry->name,title,&par);
1000 unbusy();
1001 checkselection(entry);
1002 return(1);
1004 unbusy();
1005 return(0);
1008 last_selected_entry=NULL;
1010 for (oe=0;oe<2;oe++) displayname(oe,1);
1011 if (last_selected_entry &&
1012 last_selected_entry->type>=ENTRY_DEVICE && state) {
1013 if (DoubleClick(time_previous_sec,time_previous_micro,
1014 time_current_sec,time_current_micro)) {
1015 if (last_selected_entry->type==ENTRY_CUSTOM &&
1016 last_selected_entry->subtype==CUSTOMENTRY_USER) {
1017 if (last_selected_entry->size&CUSTENTRY_CANSELECT) {
1018 userentrymessage(dopus_curwin[1-data_active_window],last_selected_entry,USERENTRY_CLICKMCLICK);
1019 time_previous_sec=0;
1022 else {
1023 unselect(1-data_active_window,last_selected_entry);
1024 advancebuf(data_active_window,1);
1025 if (last_selected_entry->type==ENTRY_CUSTOM) {
1026 if (last_selected_entry->subtype==CUSTOMENTRY_BUFFERLIST) {
1027 bringinbuffer(last_selected_entry->dispstr,data_active_window,1);
1028 time_previous_sec=0;
1029 return(1);
1031 else strcpy(str_pathbuffer[data_active_window],last_selected_entry->dispstr);
1033 else {
1034 strcpy(str_pathbuffer[data_active_window],dopus_curwin[1-data_active_window]->directory);
1035 TackOn(str_pathbuffer[data_active_window],last_selected_entry->name,256);
1037 startgetdir(data_active_window,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
1038 time_previous_sec=0;
1039 return(1);
1043 return(0);
1046 void unbyte(win)
1047 int win;
1049 struct Directory *entry;
1051 entry=dopus_curwin[win]->firstentry;
1052 while (entry) {
1053 if (entry->selected && ENTRYTYPE(entry->type)==ENTRY_DIRECTORY &&
1054 entry->size!=-1) {
1055 setdirsize(entry,-1,win);
1057 if (entry->next) entry=entry->next;
1058 else entry=NULL;
1060 refreshwindow(win,0);
1061 if (win==data_active_window) doselinfo(win);
1064 void checkselection(entry)
1065 struct Directory *entry;
1067 struct Directory *temp;
1069 last_selected_entry=NULL; func_single_file[0]=0;
1070 temp=dopus_curwin[data_active_window]->firstentry;
1071 while (temp) {
1072 if (temp==entry) break;
1073 temp=temp->next;
1075 if (temp && temp->selected) unselect(data_active_window,temp);