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 / main16.c < prev    next >
C/C++ Source or Header  |  2000-01-30  |  8KB  |  283 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. #include <proto/powerpacker.h>
  33.  
  34. showfont(name,size,np)
  35. char *name;
  36. int size,np;
  37. {
  38.     int base,y,fred,t,len;
  39.     unsigned char a;
  40.     struct TextFont *font;
  41.     char fontbuf[256],*fontptr;
  42.     static UWORD fcols[2]={0xfff,0};
  43.     struct TextAttr sfattr;
  44.  
  45.     sfattr.ta_Name=(STRPTR)name;
  46.     sfattr.ta_Style=sfattr.ta_Flags=0;
  47.     sfattr.ta_YSize=size;
  48.  
  49.     if (DiskfontBase) font=OpenDiskFont(&sfattr);
  50.     else font=OpenFont(&sfattr);
  51.     if (!font || !(setupfontdisplay(1,NULL))) {
  52.         doerror(IoErr());
  53.         return(0);
  54.     }
  55.  
  56.     base=font->tf_Baseline;
  57.     SetFont(font_rp,font);
  58.     SetAPen(font_rp,1);
  59.     SetDrMd(font_rp,JAM1);
  60.  
  61.     y=base;
  62.     a=font->tf_LoChar;
  63.     len=t=0;
  64.  
  65.     Move(font_rp,0,y);
  66.     fontptr=fontbuf;
  67.  
  68.     FOREVER {
  69.         len+=TextLength(font_rp,(char *)&a,1);
  70.         if (len>fontscreen->Width || t>254) {
  71.             Text(font_rp,fontbuf,t);
  72.             y+=size;
  73.             Move(font_rp,0,y);
  74.             len=t=0; fontptr=fontbuf;
  75.             if (y-base>fontscreen->Height) break;
  76.         }
  77.         *(fontptr++)=a; ++t;
  78.         if ((++a)>font->tf_HiChar) a=font->tf_LoChar;
  79.     }
  80.  
  81.     ScreenToFront(fontscreen);
  82.     ActivateWindow(fontwindow);
  83.     FadeRGB4(fontscreen,fcols,2,1,config->fadetime);
  84.     show_global_font=font;
  85.  
  86.     fred=WaitForMouseClick(0,fontwindow);
  87.  
  88.     show_global_font=NULL;
  89.     if (fred!=-3) FadeRGB4(fontscreen,fcols,2,-1,config->fadetime);
  90.  
  91.     cleanup_fontdisplay();
  92.     CloseFont(font);
  93.  
  94.     return((fred==0)?1:-1);
  95. }
  96.     
  97. setupfontdisplay(depth,coltab)
  98. int depth;
  99. UWORD *coltab;
  100. {
  101.     font_scr.Width=GfxBase->NormalDisplayColumns;
  102.     font_scr.Height=STDSCREENHEIGHT;
  103.     font_scr.Depth=depth;
  104.     if (!(fontscreen=OpenScreen((struct NewScreen *)&font_scr))) return(0);
  105.     font_win.Width=fontscreen->Width;
  106.     font_win.Height=fontscreen->Height;
  107.     font_win.Screen=fontscreen;
  108.     if (!(fontwindow=OpenWindow(&font_win))) {
  109.         CloseScreen(fontscreen);
  110.         return(0);
  111.     }
  112.     font_rp=fontwindow->RPort;
  113.     if (coltab) {
  114.         int a,num;
  115.  
  116.         num=1<<depth;
  117.         if (num>16) num=16;
  118.         for (a=0;a<num;a++) coltab[a]=GetRGB4(fontscreen->ViewPort.ColorMap,a);
  119.     }
  120.     LoadRGB4(&fontscreen->ViewPort,nullpalette,1<<depth);
  121.     setnullpointer(fontwindow);
  122.     return(1);
  123. }
  124.  
  125. void cleanup_fontdisplay()
  126. {
  127.     if (blankscreen) ScreenToFront(blankscreen);
  128.     else ScreenToFront(Window->WScreen);
  129.     if (fontwindow) {
  130.         CloseWindow(fontwindow);
  131.         fontwindow=NULL;
  132.     }
  133.     if (fontscreen) {
  134.         CloseScreen(fontscreen);
  135.         fontscreen=NULL;
  136.     }
  137.     ActivateWindow(Window);
  138. }
  139.  
  140. void readhelp(file)
  141. char *file;
  142. {
  143.     doreadhelp(file);
  144.     if (dopus_firsthelp) screen_gadgets[SCRGAD_TINYHELP].Flags&=~GFLG_DISABLED;
  145.     else screen_gadgets[SCRGAD_TINYHELP].Flags|=GFLG_DISABLED;
  146.     if (Window && config->generalscreenflags&SCR_GENERAL_TINYGADS)
  147.         dolittlegads(&screen_gadgets[SCRGAD_TINYHELP],&globstring[STR_TINY_BUTTONS][4],1);
  148. }
  149.  
  150. void doreadhelp(file)
  151. char *file;
  152. {
  153.     int a,b,helpsize,inmsg;
  154.     char *helpbuf,*buf;
  155.     struct Help *temph,*curhelp;
  156.  
  157.     freehelp();
  158.     if (!file[0] || !(buf=AllocMem(10000,MEMF_CLEAR))) return;
  159.     if (readfile(file,&helpbuf,&helpsize)) {
  160.         FreeMem(buf,10000);
  161.         return;
  162.     }
  163.  
  164.     curhelp=NULL;
  165.     inmsg=0;
  166.     for (a=0;a<helpsize;a++) {
  167.         if (helpbuf[a]=='*' && !inmsg) {
  168.             inmsg=1; b=0;
  169.             continue;
  170.         }
  171.         else {
  172.             if (inmsg==1) {
  173.                 if (b==9999 || helpbuf[a]=='\n') {
  174.                     buf[b]=0;
  175.                     if (!(temph=LAllocRemember(&help_key,sizeof(struct Help),MEMF_CLEAR))) break;
  176.                     if (!(temph->lookup=LAllocRemember(&help_key,b+1,MEMF_CLEAR))) break;
  177.                     CopyMem(buf,temph->lookup,b);
  178.                     if (curhelp) curhelp->next=temph;
  179.                     else dopus_firsthelp=temph;
  180.                     curhelp=temph;
  181.                     inmsg=2; b=0;
  182.                     continue;
  183.                 }                   
  184.                 buf[b]=helpbuf[a];
  185.                 ++b;
  186.                 continue;
  187.             }
  188.             else if (inmsg==2) {
  189.                 if (b==9999 || helpbuf[a]=='^') {
  190.                     if (curhelp) {
  191.                         buf[b]=0;
  192.                         if (!(curhelp->message=LAllocRemember(&help_key,b+1,MEMF_CLEAR))) break;
  193.                         CopyMem(buf,curhelp->message,b);
  194.                     }
  195.                     inmsg=0; b=0;
  196.                     continue;
  197.                 }
  198.                 buf[b]=helpbuf[a];
  199.                 ++b;
  200.                 continue;
  201.             }
  202.         }
  203.     }
  204.     FreeMem(buf,10000);
  205.     FreeMem(helpbuf,helpsize);
  206. }
  207.  
  208. void dohelp(name,func,key,qual,defmsg)
  209. char *name,*func;
  210. int key,qual;
  211. char *defmsg;
  212. {
  213.     char *msg=NULL,*buf=NULL,buf1[40],buf2[30];
  214.     struct Help *help;
  215.     int s,s1;
  216.  
  217.     if (!dopus_firsthelp) return;
  218.     help=dopus_firsthelp;
  219.     while (help) {
  220.         if (help->lookup) {
  221.             if (help->lookup[0]=='*' && func) {
  222.                 if (LStrCmpI(help->lookup,func)==0) {
  223.                     msg=help->message;
  224.                     break;
  225.                 }
  226.             }
  227.             else if (name) {
  228.                 if (LStrCmpI(help->lookup,name)==0) {
  229.                     msg=help->message;
  230.                     break;
  231.                 }
  232.             }
  233.         }
  234.         help=help->next;
  235.     }
  236.     if (!msg) {
  237.         if (defmsg) msg=defmsg;
  238.         else msg=globstring[STR_HELP_NOT_AVAILABLE];
  239.     }
  240.     if (key>0) {
  241.         RawkeyToStr(key,qual,buf2,NULL,30);
  242.         strcpy(buf1,globstring[STR_KEY]); strcat(buf1,buf2); strcat(buf1,"\n\n");
  243.         s1=strlen(buf1);
  244.         s=strlen(msg)+1;
  245.         if (buf=AllocMem(s+s1,MEMF_CLEAR)) {
  246.             CopyMem(buf1,buf,s1);
  247.             CopyMem(msg,&buf[s1],s);
  248.             s+=s1;
  249.             msg=buf;
  250.         }
  251.     }
  252.     simplerequest(msg,globstring[STR_CONTINUE],NULL);
  253.     unbusy();
  254.     if (buf) FreeMem(buf,s);
  255.     return;
  256. }
  257.  
  258. void checkstringgads(a)
  259. int a;
  260. {
  261.     --a;
  262.     checkdir(str_pathbuffer[a],&path_strgadget[a]);
  263.     strcpy(dopus_curwin[a]->directory,str_pathbuffer[a]);
  264. }
  265.  
  266. void setdirsize(dir,byte,win)
  267. struct Directory *dir;
  268. int byte,win;
  269. {
  270.     if (status_iconified || win==-1) return;
  271.  
  272.     if (dir->size>0) {
  273.         dopus_curwin[win]->bytestot-=dir->size;
  274.         if (dir->selected) dopus_curwin[win]->bytessel-=dir->size;
  275.     }
  276.     if (byte<-1) byte=-1;
  277.     dir->size=byte;
  278.     if (dir->size!=-1) {
  279.         dopus_curwin[win]->bytestot+=byte;
  280.         if (dir->selected) dopus_curwin[win]->bytessel+=byte;
  281.     }
  282. }
  283.