home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Program / dirtree.c < prev    next >
C/C++ Source or Header  |  2000-01-29  |  5KB  |  155 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. char *tree_buffer,*tree_path_buffer;
  34.  
  35. void dotree(win)
  36. int win;
  37. {
  38.     int a,ret;
  39.     struct Directory *entry;
  40.     char *name;
  41.  
  42.     if (status_iconified ||
  43.         dopus_curwin[win]->total==0 ||
  44.         str_pathbuffer[win][0]==0) return;
  45.  
  46.     name=dopus_curwin[win]->directory;
  47.     advancebuf(win,1);
  48.     strcpy(dopus_curwin[win]->directory,name);
  49.     strcpy(str_pathbuffer[win],name);
  50.     checkdir(str_pathbuffer[win],&path_strgadget[win]);
  51.     freedir(dopus_curwin[win],win);
  52.     dopus_curwin[win]->diskfree=dopus_curwin[win]->disktot=dopus_curwin[win]->diskblock=-1;
  53.     strcpy(dopus_curwin[win]->diskname,globstring[STR_DIR_TREE]);
  54.  
  55.     dostatustext(globstring[STR_SCANNING_TREE]);
  56.     busy();
  57.     data_active_window=win;
  58.  
  59.     ret=recursedir(str_pathbuffer[win],NULL,R_GETNAMES,0);
  60.  
  61.     if (first_recurse) {
  62.         recurse_parent_array=LAllocRemember(&recurse_dir_key,(recurse_max_depth+1)*4,MEMF_CLEAR);
  63.         if (tree_buffer=LAllocRemember(&recurse_dir_key,1024,MEMF_CLEAR)) {
  64.             tree_path_buffer=LAllocRemember(&recurse_dir_key,1024,MEMF_CLEAR);
  65.             dostatustext(globstring[STR_BUILDING_TREE]);
  66.             ret=1;
  67.             build_tree(first_recurse);
  68.         }
  69.         LFreeRemember(&recurse_dir_key);
  70.     }
  71.  
  72.     entry=dopus_curwin[win]->firstentry;
  73.     a=0;
  74.     while (entry) {
  75.         if (a<strlen(entry->comment)) a=strlen(entry->comment);
  76.         entry=entry->next;
  77.     }
  78.     if (a<scrdata_dispwin_nchars[win]) a=scrdata_dispwin_nchars[win];
  79.     dopus_curwin[win]->hlen=a;
  80.  
  81.     refreshwindow(win,3);
  82.     if (ret!=-1 && ret!=-10) okay();
  83.     unbusy();
  84. }
  85.  
  86. build_tree(rec)
  87. struct RecursiveDirectory *rec;
  88. {
  89.     static int recdepth;
  90.     int a,b;
  91.  
  92.     while (rec) {
  93.         b=0;
  94.         if (tree_path_buffer) strcpy(tree_path_buffer,str_pathbuffer[data_active_window]);
  95.         for (a=0;a<recdepth;a++) {
  96.             if (!recurse_parent_array || !recurse_parent_array[a])
  97.                 tree_buffer[b++]='|';
  98.             else {
  99.                 if (recurse_parent_array[a]->next) tree_buffer[b++]='|';
  100.                 else tree_buffer[b++]=' ';
  101.                 if (tree_path_buffer)
  102.                     TackOn(tree_path_buffer,recurse_parent_array[a]->name,1024);
  103.             }
  104.             tree_buffer[b++]=' '; tree_buffer[b++]=' ';
  105.         }
  106.         if (rec->next) strcpy(&tree_buffer[b],"|--");
  107.         else strcpy(&tree_buffer[b],"+--");
  108.         strcpy(&tree_buffer[b+3],rec->name);
  109.         if (tree_path_buffer) TackOn(tree_path_buffer,rec->name,1024);
  110.         if (!(addfile(dopus_curwin[data_active_window],data_active_window,
  111.             rec->name,0,ENTRY_CUSTOM,&rec->date,tree_buffer,0,
  112.             CUSTOMENTRY_DIRTREE,FALSE,tree_path_buffer,NULL,0,0))) return(0);
  113.         if (rec->child) {
  114.             recurse_parent_array[recdepth]=rec;
  115.             recdepth++;
  116.             if (!(build_tree(rec->child))) return(0);
  117.             recdepth--;
  118.             recurse_parent_array[recdepth]=NULL;
  119.         }
  120.         rec=rec->next;
  121.     }
  122.     return(1);
  123. }
  124.  
  125. void draw_dirtree_gfx(rp,x,y,type)
  126. struct RastPort *rp;
  127. int x,y,type;
  128. {
  129.     int half_xsize,half_ysize,x_plus_half;
  130.  
  131.     half_xsize=scrdata_font_xsize/2;
  132.     half_ysize=scrdata_font_ysize/2;
  133.     x_plus_half=x+half_xsize;
  134.     if (status_flags&STATUS_SQUAREPIXEL) ++x_plus_half;
  135.  
  136.     switch (type) {
  137.         case DIRTREEGFX_VERT:
  138.         case DIRTREEGFX_VERTCROSS:
  139.             rectfill(rp,x_plus_half,y,(status_flags&STATUS_SQUAREPIXEL)?1:2,scrdata_font_ysize);    
  140.             if (type==DIRTREEGFX_VERTCROSS)
  141.                 RectFill(rp,x_plus_half,y+half_ysize,x+scrdata_font_xsize-1,y+half_ysize);
  142.             break;
  143.         case DIRTREEGFX_CROSS:
  144.             rectfill(rp,x,y+half_ysize,scrdata_font_xsize,1);
  145.             break;
  146.         case DIRTREEGFX_FINALCROSS:
  147.             rectfill(rp,x,y+half_ysize,scrdata_font_xsize-1,1);
  148.             break;
  149.         case DIRTREEGFX_BRANCH:
  150.             rectfill(rp,x_plus_half,y,(status_flags&STATUS_SQUAREPIXEL)?1:2,half_ysize);
  151.             RectFill(rp,x_plus_half,y+half_ysize,x+scrdata_font_xsize-1,y+half_ysize);
  152.             break;
  153.     }
  154. }
  155.