home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / select.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  28KB  |  983 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  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
  9. as published by the Free Software Foundation; either version 2
  10. of the 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
  15. GNU 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, MA  02111-1307, USA.
  20.  
  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.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. struct Directory *selectedentry;
  34.  
  35. void doselection(win,state)
  36. int win,state;
  37. {
  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.     USHORT code,qual;
  43.     char buf[40],*ptr;
  44.     struct Directory *next;
  45.  
  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));
  58.         }
  59.         if ((b=select(win,a))==2) {
  60.             return;
  61.         }
  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;
  80.                         }
  81.                     }
  82.                     else if (code==SELECTUP) {
  83.                         a=1;
  84.                         break;
  85.                     }
  86.                 }
  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;
  99.                                     }
  100.                                     else comp=-1;
  101.                                     AddBob(&drag_bob,main_rp);
  102.                                 }
  103.                             }
  104.                             drag_sprite.X=x-offx; drag_sprite.Y=y-offy;
  105.                             SortGList(main_rp);
  106.                             DrawGList(main_rp,ViewPortAddress(Window));
  107.                             WaitTOF();
  108.                         }
  109.                         ox=x; oy=y;
  110.                     }
  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;
  122.                                 }
  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;
  136.                                         }
  137.                                     }
  138.                                     else ptr=selectedentry->name;
  139.                                     type=selectedentry->type;
  140.                                 }
  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;
  162.                                     }
  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;
  170.                                 }
  171.                             }
  172.                         }
  173.                         else {
  174.                             if (drag) drag=0;
  175.                             if (la<fa) {
  176.                                 ++fa; ++la;
  177.                                 d=la; la=fa; fa=d;
  178.                             }
  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);
  182.                                 }
  183.                             }
  184.                             else if (y<scrdata_dispwin_ypos) {
  185.                                 if (juststart!=-1) {
  186.                                     if (fa<0) fa=0; if (la>=scrdata_dispwin_lines) la=scrdata_dispwin_lines;
  187.                                     if (state) {
  188.                                         for (d=fa;d<la;d++) defselect(win,d,b);
  189.                                         defselect(win,0,b);
  190.                                     }
  191.                                     juststart=-1;
  192.                                 }
  193.                                 if (dopus_curwin[win]->offset==0) continue;
  194.                                 verticalscroll(win,-1);
  195.                                 if (state) defselect(win,0,b);
  196.                                 okrepeatdrag=1;
  197.                             }
  198.                             else if (y>=scrdata_dispwin_height+scrdata_dispwin_ypos) {
  199.                                 if (juststart!=1) {
  200.                                     if (fa<0) fa=0; if (la>=scrdata_dispwin_lines) la=scrdata_dispwin_lines;
  201.                                     if (state) {
  202.                                         for (d=fa;d<la;d++) defselect(win,d,b);
  203.                                         defselect(win,scrdata_dispwin_lines-1,b);
  204.                                     }
  205.                                     juststart=1;
  206.                                 }
  207.                                 if (dopus_curwin[win]->offset==atot) continue;
  208.                                 verticalscroll(win,1);
  209.                                 if (state) defselect(win,scrdata_dispwin_lines-1,b);
  210.                                 okrepeatdrag=1;
  211.                             }
  212.                         }
  213.                         oy=y;
  214.                     }
  215.                 }
  216.             }
  217.             if (a) break;
  218.             if (getintuimsg()) goto gotmsgloop;
  219.             if (okrepeatdrag) goto getcoordsloop;
  220.             Wait(1<<Window->UserPort->mp_SigBit);
  221.         }
  222.         if (drag==2) {
  223. enddragging:
  224.             RemIBob(&drag_bob,main_rp,ViewPortAddress(Window));
  225.             if (comp>-1) dragcompgad(comp,0);
  226.             dotaskmsg(clockmsg_port,CLOCK_ACTIVE,1,0,NULL,0);
  227.             if (x>=scrdata_dirwin_xpos[1-data_active_window] &&
  228.                 x<=scrdata_dirwin_xpos[1-data_active_window]+scrdata_dirwin_width[1-data_active_window] &&
  229.                 y>=scrdata_dirwin_ypos[1-data_active_window] &&
  230.                 y<=scrdata_dirwin_ypos[1-data_active_window]+scrdata_dirwin_height && drag==2) {
  231.                 if (multidrag) {
  232.                     last_selected_entry=dopus_curwin[win]->firstentry;
  233.                     while (last_selected_entry) {
  234.                         if (status_haveaborted || status_justabort) {
  235.                             myabort();
  236.                             break;
  237.                         }
  238.                         next=last_selected_entry->next;
  239.                         if (last_selected_entry->type<=ENTRY_FILE && last_selected_entry->selected) {
  240.                             CurrentTime(&time_previous_sec,&time_previous_micro);
  241.                             time_current_sec=time_previous_sec;
  242.                             time_current_micro=time_previous_micro;
  243.                             makeactive(1-data_active_window,1);
  244.                         }
  245.                         last_selected_entry=next;
  246.                     }
  247.                 }
  248.                 else {
  249.                     time_previous_sec=time_current_sec;
  250.                     time_previous_micro=time_current_micro;
  251.                     last_selected_entry=selectedentry;
  252.                     makeactive(1-data_active_window,1);
  253.                 }
  254.             }
  255.             else if (comp>-1) {
  256.                 gad=comp+(data_gadgetrow_offset*7);
  257.                 if (dopus_curgadbank && isvalidgad(&dopus_curgadbank->gadgets[gad])) {
  258.                     if (multidrag) {
  259.                         last_selected_entry=NULL;
  260.                         func_single_file[0]=0;
  261.                         status_flags|=STATUS_GLOBALFILE;
  262.                     }
  263.                     else {
  264.                         last_selected_entry=selectedentry;
  265.                         strcpy(func_single_file,selectedentry->name);
  266.                         if (selectedentry->selected) unselect(data_active_window,selectedentry);
  267.                     }
  268.                     dofunctionstring(dopus_curgadbank->gadgets[gad].function,
  269.                         dopus_curgadbank->gadgets[gad].name,
  270.                         NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[gad].which);
  271.                     status_flags&=~STATUS_GLOBALFILE;
  272.                     if (!multidrag) checkselection(selectedentry);
  273.                 }
  274.             }
  275.         }
  276.         Window->Flags&=~WFLG_REPORTMOUSE;
  277.     }
  278. }
  279.  
  280. void dormbscroll(win)
  281. int win;
  282. {
  283.     ULONG class;
  284.     USHORT code;
  285.     int x,y,d,a,ret=0;
  286.     struct Directory *temp;
  287.  
  288.     if (data_active_window!=win) {
  289.         makeactive(win,0);
  290.         ret=1;
  291.     }
  292.  
  293.     if (dopus_curwin[win]->total>0 && status_flags&STATUS_IANSCRAP) {
  294.         CurrentTime(&time_current_sec,&time_current_micro);
  295.         y=Window->MouseY;
  296.         a=(y-scrdata_dirwin_ypos[data_active_window]-2)/scrdata_font_ysize;
  297.         if (a<scrdata_dispwin_lines) {
  298.             a+=dopus_curwin[win]->offset;
  299.             if (a<=dopus_curwin[win]->total) {
  300.                 temp=dopus_curwin[win]->firstentry;
  301.                 while (a--) temp=temp->next;
  302.                 if (temp && temp->type<=ENTRY_FILE && temp->selected &&
  303.                     (DoubleClick(time_previous_sec,time_previous_micro,
  304.                         time_current_sec,time_current_micro)) &&
  305.                     last_selected_entry==temp &&
  306.                     config->generalflags&GENERAL_DOUBLECLICK) {
  307.                     unselect(win,temp);
  308.                     ftype_doubleclick(str_pathbuffer[win],temp->name,0);
  309.                     unbusy();
  310.                     time_previous_sec=0;
  311.                     return;
  312.                 }
  313.             }
  314.         }
  315.         if (ret) return;
  316.     }
  317.  
  318.     FOREVER {
  319.         while (!getintuimsg()) {
  320.             x=Window->MouseX; y=Window->MouseY;
  321.             d=0;
  322.             if (y<scr_scroll_borders[win].MinY) {
  323.                 verticalscroll(win,-1);
  324.                 if (y>scr_scroll_borders[win].MinY-(scrdata_font_ysize*4)) d=1;
  325.             }
  326.             else if (y>scr_scroll_borders[win].MaxY) {
  327.                 verticalscroll(win,1);
  328.                 if (y<scr_scroll_borders[win].MaxY+(scrdata_font_ysize*4)) d=1;
  329.             }
  330.             else if (x<scr_scroll_borders[win].MinX) horizontalscroll(win,-1);
  331.             else if (x>scr_scroll_borders[win].MaxX) horizontalscroll(win,1);
  332.             if (d) Delay(d);
  333.         }
  334.         class=IMsg->Class; code=IMsg->Code;
  335.         ReplyMsg((struct Message *) IMsg);
  336.         if (class==MOUSEBUTTONS && code==MENUUP) break;
  337.     }
  338. }
  339.  
  340. select(win,o)
  341. int win,o;
  342. {
  343.     int a,dbclick=0,sel=1,foundcount;
  344.     char sbuf[32],*dir;
  345.     struct Directory *temp,*temp2;
  346.  
  347.     a=o+dopus_curwin[win]->offset;
  348.     if (o>=scrdata_dispwin_lines || a>=dopus_curwin[win]->total) return(0);
  349.     temp=dopus_curwin[win]->firstentry;
  350.     while (a--) temp=temp->next;
  351.     selectedentry=temp;
  352.     if (temp && ENTRYTYPE(temp->type)!=ENTRY_CUSTOM ||
  353.         temp->subtype!=CUSTOMENTRY_USER || temp->size&CUSTENTRY_CANSELECT) {
  354.         sel=temp->selected;
  355.         temp->selected=sel?FALSE:TRUE;
  356.         updateselectinfo(temp,win,1);
  357.         if (!status_iconified) {
  358.             display_entry(temp,win,
  359.                 scrdata_dirwin_xpos[win],
  360.                 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
  361.             if (config->iconflags&ICONFLAG_AUTOSELECT) {
  362.                 StrCombine(sbuf,temp->name,".info",31);
  363.                 if ((temp2=findfile(dopus_curwin[win],sbuf,&foundcount))) {
  364.                     if (temp2->selected!=temp->selected) {
  365.                         temp2->selected=temp->selected;
  366.                         updateselectinfo(temp2,win,1);
  367.                         if (foundcount>=dopus_curwin[win]->offset &&
  368.                             foundcount<dopus_curwin[win]->offset+scrdata_dispwin_lines) {
  369.                             o=foundcount-dopus_curwin[win]->offset;
  370.                             display_entry(temp2,win,
  371.                                 scrdata_dirwin_xpos[win],
  372.                                 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
  373.                         }
  374.                     }
  375.                 }
  376.             }
  377.         }
  378.  
  379. /*
  380.         if (last_selected_entry!=temp ||
  381.             !(dbclick=DoubleClick(time_previous_sec,time_previous_micro,
  382.                 time_current_sec,time_current_micro))) {
  383.             last_selected_entry=temp;
  384.         }
  385.         time_previous_sec=time_current_sec;
  386.         time_previous_micro=time_current_micro;
  387. */
  388.         
  389.         if (sel) {
  390.             dbclick=DoubleClick(time_previous_sec,time_previous_micro,
  391.                 time_current_sec,time_current_micro);
  392.         }
  393.         else {
  394.             dbclick=-1;
  395.             time_previous_sec=time_current_sec;
  396.             time_previous_micro=time_current_micro;
  397.         }
  398.  
  399.         switch (ENTRYTYPE(temp->type)) {
  400.             case ENTRY_DEVICE:
  401.             case ENTRY_DIRECTORY:
  402.                 if (dbclick==-1) last_selected_entry=temp;
  403.                 else if (dbclick && last_selected_entry==temp) {
  404.                     dir=dopus_curwin[win]->directory;
  405.                     advancebuf(win,1);
  406.                     if (temp->type==ENTRY_DEVICE) strcpy(str_pathbuffer[win],temp->name);
  407.                     else {
  408.                         strcpy(str_pathbuffer[win],dir);
  409.                         TackOn(str_pathbuffer[win],temp->name,256);
  410.                     }
  411.                     startgetdir(win,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
  412.                     time_previous_sec=0;
  413.                     return(2);
  414.                 }
  415.                 break;
  416.  
  417.             case ENTRY_CUSTOM:
  418.                 if (dbclick==-1) last_selected_entry=temp;
  419.                 else if (dbclick && last_selected_entry==temp) {
  420.                     if (temp->subtype==CUSTOMENTRY_BUFFERLIST ||
  421.                         temp->subtype==CUSTOMENTRY_DIRTREE) {
  422.                         if (temp->subtype==CUSTOMENTRY_BUFFERLIST)
  423.                             bringinbuffer(last_selected_entry->dispstr,win,1);
  424.                         else {
  425.                             strcpy(str_pathbuffer[win],last_selected_entry->dispstr);
  426.                             startgetdir(win,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
  427.                         }
  428.                         time_previous_sec=0;
  429.                         return(2);
  430.                     }
  431.                     else if (temp->subtype==CUSTOMENTRY_USER) {
  432.                         userentrymessage(dopus_curwin[win],temp,USERENTRY_DOUBLECLICK);
  433.                         time_previous_sec=0;
  434.                         return(2);
  435.                     }
  436.                 }
  437.                 break;
  438.  
  439.             case ENTRY_FILE:
  440.                 if (dbclick==-1) last_selected_entry=temp;
  441.                 else if (dbclick && last_selected_entry==temp) {
  442.                     if (config->generalflags&GENERAL_DOUBLECLICK) {
  443.                         ftype_doubleclick(str_pathbuffer[win],temp->name,1);
  444.                         unbusy();
  445.                         time_previous_sec=0;
  446.                         return(2);
  447.                     }
  448.                 }
  449.                 break;
  450.         }
  451.     }
  452.     return(!sel);
  453. }
  454.  
  455. unselect(win,file)
  456. int win;
  457. struct Directory *file;
  458. {
  459.     int a=0;
  460.     struct Directory *t;
  461.  
  462.     if (win==-1 || !file->selected) return(0);
  463.     t=dopus_curwin[win]->firstentry;
  464.     while (t!=file && t) {
  465.         ++a;
  466.         t=t->next;
  467.     }
  468.     if (!t) return(0);
  469.     switch (ENTRYTYPE(file->type)) {
  470.         case ENTRY_DIRECTORY:
  471.         case ENTRY_DEVICE:
  472.             --dopus_curwin[win]->dirsel;
  473.             if (file->type>0 && file->size!=-1) dopus_curwin[win]->bytessel-=file->size;
  474.             break;
  475.         case ENTRY_FILE:
  476.             --dopus_curwin[win]->filesel;
  477.             dopus_curwin[win]->bytessel-=file->size;
  478.             break;
  479.     }
  480.     file->selected=FALSE;
  481.     if (a<dopus_curwin[win]->offset ||
  482.         a>(dopus_curwin[win]->offset+scrdata_dispwin_lines-1)) return(0);
  483.     a-=dopus_curwin[win]->offset;
  484.     if (!status_iconified) {
  485.         display_entry(t,win,
  486.             scrdata_dirwin_xpos[win],
  487.             scrdata_font_baseline+(scrdata_font_ysize*a)+scrdata_dirwin_ypos[win]);
  488.     }
  489.     return(1);
  490. }
  491.  
  492. void defselect(win,o,state)
  493. int win,o,state;
  494. {
  495.     int a,foundcount;
  496.     struct Directory *temp,*temp2;
  497.     char sbuf[32];
  498.  
  499.     if (o<0 || o>scrdata_dispwin_lines-1) return;
  500.     a=o+dopus_curwin[win]->offset;
  501.     if (a>=dopus_curwin[win]->total) return;
  502.     temp=dopus_curwin[win]->firstentry;
  503.     while (a--) temp=temp->next;
  504.     if (state) selectedentry=temp;
  505.     else selectedentry=NULL;
  506.     if (temp && ENTRYTYPE(temp->type)!=ENTRY_CUSTOM ||
  507.         temp->subtype!=CUSTOMENTRY_USER || temp->size&CUSTENTRY_CANSELECT) {
  508.         if (temp->selected!=state) {
  509.             temp->selected=state;
  510.             updateselectinfo(temp,win,1);
  511.             if (!status_iconified) {
  512.                 display_entry(temp,win,
  513.                     scrdata_dirwin_xpos[win],
  514.                     scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
  515.             }
  516.         }
  517.         if (config->iconflags&ICONFLAG_AUTOSELECT) {
  518.             StrCombine(sbuf,temp->name,".info",31);
  519.             if ((temp2=findfile(dopus_curwin[win],sbuf,&foundcount))) {
  520.                 if (temp2->selected!=temp->selected) {
  521.                     temp2->selected=temp->selected;
  522.                     updateselectinfo(temp2,win,1);
  523.                     if (foundcount>=dopus_curwin[win]->offset &&
  524.                         foundcount<dopus_curwin[win]->offset+scrdata_dispwin_lines) {
  525.                         if (!status_iconified) {
  526.                             o=foundcount-dopus_curwin[win]->offset;
  527.                             display_entry(temp2,win,
  528.                                 scrdata_dirwin_xpos[win],
  529.                                 scrdata_font_baseline+(scrdata_font_ysize*o)+scrdata_dirwin_ypos[win]);
  530.                         }
  531.                     }
  532.                 }
  533.             }
  534.         }
  535.     }
  536. }
  537.  
  538. void globalselect(win,all)
  539. int win,all;
  540. {
  541.     struct Directory *temp;
  542.  
  543.     if ((temp=dopus_curwin[win]->firstentry) && temp->type!=ENTRY_CUSTOM) {
  544.         while (temp) {
  545. /*
  546.             if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
  547.                 temp->size&CUSTENTRY_CANSELECT) temp->selected=all;
  548. */
  549.             temp->selected=all;
  550.             temp=temp->next;
  551.         }
  552.         if (all) {
  553.             dopus_curwin[win]->filesel=dopus_curwin[win]->filetot;
  554.             dopus_curwin[win]->dirsel=dopus_curwin[win]->dirtot;
  555.             dopus_curwin[win]->bytessel=dopus_curwin[win]->bytestot;
  556.         }
  557.         else {
  558.             dopus_curwin[win]->filesel=0;
  559.             dopus_curwin[win]->dirsel=0;
  560.             dopus_curwin[win]->bytessel=0;
  561.         }
  562.         doselinfo(win);
  563.     }
  564. }
  565.  
  566. void updateselectinfo(temp,win,show)
  567. struct Directory *temp;
  568. int win,show;
  569. {
  570.     if (temp->selected) {
  571.         switch (ENTRYTYPE(temp->type)) {
  572.             case ENTRY_DIRECTORY:
  573.                 if (temp->size!=-1) dopus_curwin[win]->bytessel+=temp->size;
  574.             case ENTRY_DEVICE:
  575.                 ++dopus_curwin[win]->dirsel;
  576.                 break;
  577.             case ENTRY_FILE:
  578.                 ++dopus_curwin[win]->filesel;
  579.                 dopus_curwin[win]->bytessel+=temp->size;
  580.                 break;
  581.         }
  582.         if (show) {
  583.             if (config->generalflags&GENERAL_DISPLAYINFO) doinfodisplay(temp,TRUE);
  584.             else doselinfo(data_active_window);
  585.         }
  586.     }
  587.     else {
  588.         switch (ENTRYTYPE(temp->type)) {
  589.             case ENTRY_DIRECTORY:
  590.                 if (temp->size!=-1) dopus_curwin[win]->bytessel-=temp->size;
  591.             case ENTRY_DEVICE:
  592.                 --dopus_curwin[win]->dirsel;
  593.                 break;
  594.             case ENTRY_FILE:
  595.                 --dopus_curwin[win]->filesel;
  596.                 dopus_curwin[win]->bytessel-=temp->size;
  597.                 break;
  598.         }
  599.         if (show) doselinfo(data_active_window);
  600.     }
  601. }
  602.  
  603. void globaltoggle(win)
  604. int win;
  605. {
  606.     struct Directory *temp;
  607.  
  608.     temp=dopus_curwin[win]->firstentry;
  609.     while (temp) {
  610.         switch (ENTRYTYPE(temp->type)) {
  611.             case ENTRY_FILE:
  612.                 if (temp->selected) {
  613.                     dopus_curwin[win]->bytessel-=temp->size;
  614.                     --dopus_curwin[win]->filesel;
  615.                     temp->selected=0;
  616.                 }
  617.                 else {
  618.                     dopus_curwin[win]->bytessel+=temp->size;
  619.                     ++dopus_curwin[win]->filesel;
  620.                     temp->selected=1;
  621.                 }
  622.                 break;
  623.             case ENTRY_DIRECTORY:
  624.                 if (temp->selected) {
  625.                     if (temp->size>0) dopus_curwin[win]->bytessel-=temp->size;
  626.                     --dopus_curwin[win]->dirsel;
  627.                     temp->selected=0;
  628.                 }
  629.                 else {
  630.                     if (temp->size>0) dopus_curwin[win]->bytessel+=temp->size;
  631.                     ++dopus_curwin[win]->dirsel;
  632.                     temp->selected=1;
  633.                 }
  634.                 break;
  635.         }
  636.         temp=temp->next;
  637.     }
  638.     doselinfo(win);
  639. }
  640.  
  641. void doselect(rexx)
  642. int rexx;
  643. {
  644.     char buf[160];
  645.     int boobs,prot[2];
  646.     struct DateStamp ds1,ds2;
  647.     int selecttype;
  648.  
  649.     if (dopus_curwin[data_active_window]->total==0 ||
  650.         dopus_curwin[data_active_window]->firstentry->type==ENTRY_CUSTOM) return;
  651.  
  652.     if (!rexx) {
  653.         boobs=getselectdata(str_select_pattern,&selecttype);
  654.     }
  655.     else {
  656.         boobs=rexx_arg_value[0]; selecttype=rexx_arg_value[1];
  657.         strcpy(str_select_pattern[selecttype],rexx_args[0]);
  658.     }
  659.     if (boobs) {
  660.         if (dopus_curwin[data_active_window]->total==0) return;
  661.         switch (selecttype) {
  662.             case 0:
  663.                 LParsePatternI(str_select_pattern[0],buf);
  664.                 wildselect(buf,boobs,1);
  665.                 findfirstsel(data_active_window,-2);
  666.                 break;
  667.             case 1:
  668.                 if (str_select_pattern[1][0]==0) break;
  669.                 getseldatestamps(str_select_pattern[1],&ds1,&ds2);
  670.                 dateselect(&ds1,&ds2,boobs,1);
  671.                 findfirstsel(data_active_window,-2);
  672.                 break;
  673.             case 2:
  674.                 if (str_select_pattern[2][0]==0) break;
  675.                 getprotselvals(str_select_pattern[2],prot);
  676.                 protselect(prot[0],prot[1],boobs,1);
  677.                 findfirstsel(data_active_window,-2);
  678.                 break;
  679.         }
  680.     }
  681. }
  682.  
  683. void getseldatestamps(buf,ds1,ds2)
  684. char *buf;
  685. struct DateStamp *ds1,*ds2;
  686. {
  687.     char datebuf[2][85],timebuf[2][85],*ptr;
  688.     int a,b;
  689.  
  690.     datebuf[0][0]=datebuf[1][0]=timebuf[0][0]=timebuf[1][0]=a=b=0;
  691.     ptr=parsedatetime(str_select_pattern[1],datebuf[0],timebuf[0],&a);
  692.     strtostamp(datebuf[0],timebuf[0],ds1);
  693.     if (!a) {
  694.         strcpy(datebuf[1],datebuf[0]);
  695.         strcpy(timebuf[1],"23:59:59");
  696.     }
  697.     else if (a==-1) {
  698.         strcpy(datebuf[1],datebuf[0]);
  699.         strcpy(timebuf[1],timebuf[0]);
  700.     }
  701.     else parsedatetime(ptr,datebuf[1],timebuf[1],&b);
  702.     strtostamp(datebuf[1],timebuf[1],ds2);
  703.     ds1->ds_Tick=((ds1->ds_Tick/50)*50);
  704.     ds2->ds_Tick=((ds2->ds_Tick/50)*50)+49;
  705. }
  706.  
  707. void getprotselvals(buf,prot)
  708. char *buf;
  709. int *prot;
  710. {
  711.     int a,b,c,notflag=0;
  712.     char ch;
  713.  
  714.     prot[0]=prot[1]=0;
  715.     b=strlen(buf);
  716.     for (a=0;a<b;a++) {
  717.         ch=tolower(buf[a]);
  718.         if (ch=='-') notflag=1;
  719.         else if (ch=='+') notflag=0;
  720.         else {
  721.             for (c=0;c<8;c++) {
  722.                 if (ch==globstring[STR_PROTBIT_ALLBITS][c]) {
  723.                     prot[notflag]|=(1<<(7-c));
  724.                     break;
  725.                 }
  726.             }
  727.         }
  728.     }
  729. }
  730.  
  731. void wildselect(wild,boobs,and)
  732. char *wild;
  733. int boobs,and;
  734. {
  735.     char buf[256];
  736.     struct Directory *temp;
  737.  
  738.     temp=dopus_curwin[data_active_window]->firstentry;
  739.     if (!and) dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel=dopus_curwin[data_active_window]->bytessel=0;
  740.     while (temp) {
  741.         if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
  742.             temp->size&CUSTENTRY_CANSELECT) {
  743.             if (!and) temp->selected=0;
  744.             if (temp->type==ENTRY_CUSTOM) {
  745.                 if (!temp->selected && temp->comment) {
  746.                     StrToUpper(temp->comment,buf);
  747.                     if (LMatchPatternI(wild,buf)) wildselectthisone(temp,data_active_window,boobs);
  748.                 }
  749.             }
  750.             else {
  751.                 if (!temp->selected) {
  752.                     StrToUpper(temp->name,buf);
  753.                     if (LMatchPatternI(wild,buf)) wildselectthisone(temp,data_active_window,boobs);
  754.                 }
  755.             }
  756.         }
  757.         temp=temp->next;
  758.     }
  759.     refreshwindow(data_active_window,0);
  760.     doselinfo(data_active_window);
  761. }
  762.  
  763. void dateselect(ds1,ds2,boobs,and)
  764. struct DateStamp *ds1,*ds2;
  765. int boobs,and;
  766. {
  767.     struct Directory *temp;
  768.  
  769.     temp=dopus_curwin[data_active_window]->firstentry;
  770.     if (!and) {
  771.         dopus_curwin[data_active_window]->dirsel=
  772.             dopus_curwin[data_active_window]->filesel=
  773.             dopus_curwin[data_active_window]->bytessel=0;
  774.     }
  775.     while (temp) {
  776.         if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
  777.             temp->size&CUSTENTRY_CANSELECT) {
  778.             if (!and) temp->selected=0;
  779.             if (!temp->selected &&
  780.                 CompareDate(&(temp->date),ds1)>=0 && CompareDate(ds2,&(temp->date))>=0)
  781.                 wildselectthisone(temp,data_active_window,boobs);
  782.         }
  783.         temp=temp->next;
  784.     }
  785.     refreshwindow(data_active_window,0);
  786.     doselinfo(data_active_window);
  787. }
  788.  
  789. void protselect(protyes,protno,boobs,and)
  790. int protyes,protno,boobs,and;
  791. {
  792.     struct Directory *temp;
  793.     int prot;
  794.  
  795.     temp=dopus_curwin[data_active_window]->firstentry;
  796.     if (!and) dopus_curwin[data_active_window]->dirsel=dopus_curwin[data_active_window]->filesel=dopus_curwin[data_active_window]->bytessel=0;
  797.     while (temp) {
  798.         if (temp->type!=ENTRY_CUSTOM || temp->subtype!=CUSTOMENTRY_USER ||
  799.             temp->size&CUSTENTRY_CANSELECT) {
  800.             if (!and) temp->selected=0;
  801.             if (!temp->selected) {
  802.                 prot=((~temp->protection)&15)+(temp->protection&~15);
  803.                 if ((prot&protyes)==protyes && ((prot&~protyes)&protno)==0)
  804.                     wildselectthisone(temp,data_active_window,boobs);
  805.             }
  806.         }
  807.         temp=temp->next;
  808.     }
  809.     refreshwindow(data_active_window,0);
  810.     doselinfo(data_active_window);
  811. }
  812.  
  813. void wildselectthisone(temp,win,boobs)
  814. struct Directory *temp;
  815. int win,boobs;
  816. {
  817.     if (boobs==1 && temp->type!=ENTRY_DEVICE) temp->selected=1;
  818.     else if (boobs==2 && temp->type<=ENTRY_FILE) temp->selected=1;
  819.     else if (boobs==3 && temp->type>=ENTRY_DIRECTORY) temp->selected=1;
  820.     if (temp->selected) {
  821.         if (temp->type>=ENTRY_DIRECTORY) {
  822.             ++dopus_curwin[win]->dirsel;
  823.             if (temp->size!=-1) dopus_curwin[win]->bytessel+=temp->size;
  824.         }
  825.         else if (temp->type<=ENTRY_FILE) {
  826.             ++dopus_curwin[win]->filesel;
  827.             dopus_curwin[win]->bytessel+=temp->size;
  828.         }
  829.     }
  830. }
  831.  
  832. void doselinfo(win)
  833. int win;
  834. {
  835.     if (!dopus_curwin[win]->firstentry || dopus_curwin[win]->firstentry->type!=ENTRY_CUSTOM) {
  836.         lsprintf(str_select_info,globstring[STR_DIRS_FILES_BYTES_COUNT],
  837.             dopus_curwin[win]->dirsel,dopus_curwin[win]->dirtot,dopus_curwin[win]->filesel,
  838.             dopus_curwin[win]->filetot,dopus_curwin[win]->bytessel,dopus_curwin[win]->bytestot);
  839.     }
  840.     else {
  841.         switch (dopus_curwin[win]->firstentry->subtype) {
  842.             case CUSTOMENTRY_DIRTREE:
  843.                 lsprintf(str_select_info,globstring[STR_ENTRIES_IN_TREE],dopus_curwin[win]->total);
  844.                 break;
  845.             case CUSTOMENTRY_BUFFERLIST:
  846.                 lsprintf(str_select_info,globstring[STR_DIRS_IN_BUFFERS],dopus_curwin[win]->total);
  847.                 break;
  848.             case CUSTOMENTRY_USER:
  849.                 lsprintf(str_select_info,globstring[STR_USER_ENTRIES],dopus_curwin[win]->total);
  850.                 break;
  851.         }
  852.     }
  853.     dostatustext(str_select_info);
  854. }
  855.  
  856. makeactive(win,state)
  857. int win,state;
  858. {
  859.     if (data_active_window!=win) {
  860.         data_active_window=win;
  861.         return(doactive(state,1));
  862.     }
  863.     return(0);
  864. }
  865.  
  866. doactive(state,showinfo)
  867. int state,showinfo;
  868. {
  869.     int oe;
  870.     char buf[256];
  871.     struct dopusfiletype *type;
  872.     struct dopusfuncpar par;
  873.     struct Directory *entry;
  874.  
  875.     if (status_iconified) return(0);
  876.     if (showinfo) doselinfo(data_active_window);
  877.     if (last_selected_entry &&
  878.         last_selected_entry->type<=ENTRY_FILE) {
  879.         if (state && config->generalflags&GENERAL_DOUBLECLICK) {
  880.             if (DoubleClick(time_previous_sec,time_previous_micro,
  881.                 time_current_sec,time_current_micro)) {
  882.                 data_active_window=1-data_active_window;
  883.                 unselect(data_active_window,last_selected_entry);
  884.                 entry=last_selected_entry;
  885.                 dostatustext(globstring[STR_INTERROGATING_FILE]);
  886.                 StrCombine(buf,str_pathbuffer[data_active_window],last_selected_entry->name,256);
  887.                 busy();
  888.                 if ((type=checkfiletype(buf,FTFUNC_CLICKMCLICK,0))) {
  889.                     char title[256];
  890.  
  891.                     strcpy(func_single_file,last_selected_entry->name);
  892.                     par.which=type->which[FTFUNC_CLICKMCLICK];
  893.                     par.stack=type->stack[FTFUNC_CLICKMCLICK];
  894.                     par.key=par.qual=0; par.type=3;
  895.                     par.pri=type->pri[FTFUNC_CLICKMCLICK];
  896.                     par.delay=type->delay[FTFUNC_CLICKMCLICK];
  897.  
  898.                     if (type->actionstring[FTFUNC_CLICKMCLICK][0]) {
  899.                         do_title_string(type->actionstring[FTFUNC_CLICKMCLICK],title,0,NULL);
  900.                         dostatustext(title);
  901.                     }
  902.                     else title[0]=0;
  903.  
  904.                     dofunctionstring(type->function[FTFUNC_CLICKMCLICK],
  905.                         last_selected_entry->name,title,&par);
  906.                     unbusy();
  907.                     checkselection(entry);
  908.                     return(1);
  909.                 }
  910.                 unbusy();
  911.                 return(0);
  912.             }
  913.         }
  914.         last_selected_entry=NULL;
  915.     }
  916.     for (oe=0;oe<2;oe++) displayname(oe,1);
  917.     if (last_selected_entry &&
  918.         last_selected_entry->type>=ENTRY_DEVICE && state) {
  919.         if (DoubleClick(time_previous_sec,time_previous_micro,
  920.             time_current_sec,time_current_micro)) {
  921.             if (last_selected_entry->type==ENTRY_CUSTOM &&
  922.                 last_selected_entry->subtype==CUSTOMENTRY_USER) {
  923.                 if (last_selected_entry->size&CUSTENTRY_CANSELECT) {
  924.                     userentrymessage(dopus_curwin[1-data_active_window],last_selected_entry,USERENTRY_CLICKMCLICK);
  925.                     time_previous_sec=0;
  926.                 }
  927.             }
  928.             else {
  929.                 unselect(1-data_active_window,last_selected_entry);
  930.                 advancebuf(data_active_window,1);
  931.                 if (last_selected_entry->type==ENTRY_CUSTOM) {
  932.                     if (last_selected_entry->subtype==CUSTOMENTRY_BUFFERLIST) {
  933.                         bringinbuffer(last_selected_entry->dispstr,data_active_window,1);
  934.                         time_previous_sec=0;
  935.                         return(1);
  936.                     }
  937.                     else strcpy(str_pathbuffer[data_active_window],last_selected_entry->dispstr);
  938.                 }
  939.                 else {
  940.                     strcpy(str_pathbuffer[data_active_window],dopus_curwin[1-data_active_window]->directory);
  941.                     TackOn(str_pathbuffer[data_active_window],last_selected_entry->name,256);
  942.                 }
  943.                 startgetdir(data_active_window,SGDFLAGS_CANMOVEEMPTY|SGDFLAGS_CANCHECKBUFS);
  944.                 time_previous_sec=0;
  945.                 return(1);
  946.             }
  947.         }
  948.     }
  949.     return(0);
  950. }
  951.  
  952. void unbyte(win)
  953. int win;
  954. {
  955.     struct Directory *entry;
  956.  
  957.     entry=dopus_curwin[win]->firstentry;
  958.     while (entry) {
  959.         if (entry->selected && ENTRYTYPE(entry->type)==ENTRY_DIRECTORY &&
  960.             entry->size!=-1) {
  961.             setdirsize(entry,-1,win);
  962.         }
  963.         if (entry->next) entry=entry->next;
  964.         else entry=NULL;
  965.     }
  966.     refreshwindow(win,0);
  967.     if (win==data_active_window) doselinfo(win);
  968. }
  969.  
  970. void checkselection(entry)
  971. struct Directory *entry;
  972. {
  973.     struct Directory *temp;
  974.  
  975.     last_selected_entry=NULL; func_single_file[0]=0;
  976.     temp=dopus_curwin[data_active_window]->firstentry;
  977.     while (temp) {
  978.         if (temp==entry) break;
  979.         temp=temp->next;
  980.     }
  981.     if (temp && temp->selected) unselect(data_active_window,temp);
  982. }
  983.