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 / main6.c < prev    next >
C/C++ Source or Header  |  2000-01-30  |  12KB  |  372 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. void get_printdir_data(pddata)
  34. struct PrintDirData *pddata;
  35. {
  36.     char buf[256];
  37.     int win;
  38.  
  39.     if (pddata->win<0 || pddata->win>1) win=data_active_window;
  40.     else win=pddata->win;
  41.  
  42.     pddata->entry=dopus_curwin[win]->firstentry;
  43.     pddata->titlebuf[0]=0;
  44.     if ((dopus_curwin[win]->filesel+
  45.         dopus_curwin[win]->dirsel)>0) pddata->onlysel=1;
  46.     else pddata->onlysel=0;
  47.  
  48.     switch (ENTRYTYPE(pddata->entry->type)) {
  49.         case ENTRY_DEVICE:
  50.             strcpy(pddata->titlebuf,globstring[STR_DEVICE_LIST]);
  51.             break;
  52.         case ENTRY_CUSTOM:
  53.             switch (pddata->entry->subtype) {
  54.                 case CUSTOMENTRY_DIRTREE:
  55.                     strcpy(pddata->titlebuf,globstring[STR_DIR_TREE]);
  56.                     strcat(pddata->titlebuf,"\n");
  57.                     goto printdiskname;
  58.                 default:
  59.                     strcpy(pddata->titlebuf,globstring[STR_CUSTOM_LIST]);
  60.                     break;
  61.             }
  62.             break;
  63.         default:
  64. printdiskname:                      
  65.             strcat(pddata->titlebuf,globstring[STR_DIRECTORY]);
  66.             if (expand_path(str_pathbuffer[win],buf))
  67.                 strcat(pddata->titlebuf,buf);
  68.             else strcat(pddata->titlebuf,str_pathbuffer[win]);
  69.             break;
  70.     }
  71.     strcat(pddata->titlebuf,"\n");
  72. }
  73.  
  74. void startnotify(win)
  75. int win;
  76. {
  77.     if (!dos_notify_req[win]) return;
  78.     main_proc->pr_WindowPtr=(APTR)-1;
  79.     endnotify(win);
  80.     if (config->dynamicflags&UPDATE_NOTIFY && str_pathbuffer[win][0]) {
  81.         if (dopus_curwin[win]->disktot>(2*(1<<20))) {
  82.             strcpy(dos_notify_names[win],str_pathbuffer[win]);
  83.             dos_notify_req[win]->nr_UserData=win;
  84.             dos_notify_req[win]->nr_Flags=NRF_SEND_MESSAGE;
  85.             dos_notify_req[win]->nr_stuff.nr_Msg.nr_Port=count_port;
  86.             if (!(StartNotify(dos_notify_req[win])))
  87.                 dos_notify_names[win][0]=0;
  88.         }
  89.     }
  90.     if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  91. }
  92.  
  93. void endnotify(win)
  94. int win;
  95. {
  96.     if (dos_notify_req[win] && dos_notify_names[win][0]) {
  97.         EndNotify(dos_notify_req[win]);
  98.         dos_notify_names[win][0]=0;
  99.     }
  100. }
  101.  
  102. void startnotifies()
  103. {
  104.     int a;
  105.  
  106.     for (a=0;a<2;a++) {
  107.         if (LStrCmpI(dos_notify_names[a],str_pathbuffer[a]))
  108.             startnotify(a);
  109.     }
  110. }
  111.  
  112. void endnotifies()
  113. {
  114.     int a;
  115.  
  116.     for (a=0;a<2;a++) endnotify(a);
  117. }
  118.  
  119. dormbgadget(x1,y1,gad1,gad2)
  120. int x1,y1;
  121. struct newdopusfunction *gad1,*gad2;
  122. {
  123.     struct RMBGadget rmbgad;
  124.     int a;
  125.  
  126.     if (config->generalscreenflags&SCR_GENERAL_INDICATERMB)
  127.         do3dbox(main_rp,x1+2,y1+1,scrdata_gadget_width-4,scrdata_gadget_height-2);
  128.     rmbgad.flags=RGF_ALTTEXT; rmbgad.id=0;
  129.     
  130.     if (gadget_unsel_border) {
  131.         rmbgad.flags|=RGF_ALTBORD;
  132.         rmbgad.high_bord[0]=gadget_unsel_border;
  133.         rmbgad.high_bord[1]=gadget_sel_border;
  134.     }
  135.     for (a=0;a<2;a++) {
  136.         rmbgad.txt[a].x=2;
  137.         rmbgad.txt[a].y=1;
  138.         rmbgad.txt[a].w=scrdata_gadget_width-4;
  139.         rmbgad.txt[a].h=scrdata_gadget_height-2;
  140.     }
  141.     rmbgad.x=x1;
  142.     rmbgad.y=y1;
  143.     rmbgad.w=scrdata_gadget_width;
  144.     rmbgad.h=scrdata_gadget_height;
  145.     rmbgad.txt[0].fg=screen_pens[gad1->fpen].pen;
  146.     rmbgad.txt[0].bg=screen_pens[gad1->bpen].pen;
  147.     rmbgad.txt[0].text=gad1->name;
  148.     rmbgad.txt[1].fg=screen_pens[gad2->fpen].pen;
  149.     rmbgad.txt[1].bg=screen_pens[gad2->bpen].pen;
  150.     rmbgad.txt[1].text=gad2->name;
  151.     if (status_iconified<1) SetFont(main_rp,scr_font[FONT_GADGETS]);
  152.     a=DoRMBGadget(&rmbgad,Window);
  153.     if (status_iconified<1) SetFont(main_rp,scr_font[FONT_GENERAL]);
  154.     if (config->generalscreenflags&SCR_GENERAL_INDICATERMB)
  155.         drawgadgetcorner(main_rp,x1+2,y1+1);
  156.     return(a);
  157. }
  158.  
  159. gadgetfrompos(x,y)
  160. int x,y;
  161. {
  162.     int xg,yg,gad;
  163.  
  164.     if (y<scrdata_gadget_ypos-1 || x<scrdata_gadget_xpos) return(-1);
  165.     x-=scrdata_gadget_xpos; y-=(scrdata_gadget_ypos-1);
  166.     xg=x/scrdata_gadget_width; yg=y/scrdata_gadget_height;
  167.     gad=(yg*7)+xg;
  168.     if (gad<0 || gad>=(scr_gadget_rows*7)) return(-1);
  169.     xg=(gad%7)*scrdata_gadget_width; yg=(gad/7)*scrdata_gadget_height;
  170.     if (x>=xg && x<xg+scrdata_gadget_width && y>=yg && y<yg+scrdata_gadget_height) return(gad);
  171.     return(-1);
  172. }
  173.  
  174. isvalidgad(gad)
  175. struct newdopusfunction *gad;
  176. {
  177.     return((gad->name && gad->name[0] && gad->function && gad->function[0]));
  178. }
  179.  
  180. getpal()
  181. {
  182.     int p;
  183.     struct Screen *screen;
  184.     ULONG modeid=LORES_KEY;
  185.     struct DisplayInfo displayinfo;
  186.  
  187.     p=(GfxBase->DisplayFlags&PAL)?1:0;
  188.     if (system_version2>=OSVER_37) {
  189.         if (screen=LockPubScreen(NULL)) {
  190.             if ((modeid=GetVPModeID(&(screen->ViewPort)))!=INVALID_ID) {
  191.                 if (!((modeid&MONITOR_ID_MASK)==NTSC_MONITOR_ID ||
  192.                     (modeid&MONITOR_ID_MASK)==PAL_MONITOR_ID))
  193.                     modeid=LORES_KEY;
  194.             }
  195.             UnlockPubScreen(NULL,screen);
  196.         }
  197.         if (GetDisplayInfoData(NULL,(UBYTE *)&displayinfo,sizeof(struct DisplayInfo),DTAG_DISP,modeid)) {
  198.             if (displayinfo.PropertyFlags&DIPF_IS_PAL) p=1;
  199.             else p=0;
  200.         }
  201.     }
  202.     return(p);
  203. }
  204.  
  205. void quickfixmenus()
  206. {
  207.     int a;
  208.     ULONG class;
  209.     USHORT code;
  210.  
  211.     if (Window->MenuStrip) {
  212.         Forbid();
  213.         a=0;
  214.         while (getintuimsg()) {
  215.             class=IMsg->Class; code=IMsg->Code;
  216.             if (class==MOUSEBUTTONS && code==MENUUP) {
  217.                 a=1;
  218.                 break;
  219.             }
  220.             ReplyMsg((struct Message *)IMsg);
  221.         }
  222.         if (!a) {
  223.             Window->Flags&=~RMBTRAP;
  224.             sendmouseevent(IECLASS_RAWMOUSE,IECODE_RBUTTON|IECODE_UP_PREFIX,0,0);
  225.             sendmouseevent(IECLASS_RAWMOUSE,IECODE_RBUTTON,0,0);
  226.         }
  227.         Permit();
  228.     }
  229. }
  230.  
  231. void sendmouseevent(class,code,x,y)
  232. UBYTE class;
  233. UWORD code;
  234. int x,y;
  235. {
  236.     struct InputEvent inputev;
  237.  
  238.     input_req->io_Command=IND_WRITEEVENT;
  239.     input_req->io_Flags=0;
  240.     input_req->io_Length=sizeof(struct InputEvent);
  241.     input_req->io_Data=(APTR)&inputev;
  242.     inputev.ie_NextEvent=NULL;
  243.     inputev.ie_Class=class;
  244.     inputev.ie_Code=code;
  245.     inputev.ie_Qualifier=0;
  246.     inputev.ie_X=x;
  247.     inputev.ie_Y=y;
  248.     DoIO((struct IORequest *)input_req);
  249. }
  250.  
  251. char *getfiledescription(name,win)
  252. char *name;
  253. int win;
  254. {
  255.     int a;
  256.     char buf[256];
  257.     struct dopusfiletype *type;
  258.  
  259.     for (a=0;a<DISPLAY_LAST+1;a++) {
  260.         if (config->displaypos[win][a]==DISPLAY_FILETYPE) break;
  261.     }
  262.     if (a>DISPLAY_LAST || !name[0]) return(NULL);
  263.     StrCombine(buf,str_pathbuffer[win],name,256);
  264.     if (!(type=checkfiletype(buf,-1,0))) return(NULL);
  265.     if ((strcmp(type->type,"Default")==0) ||
  266.         (strcmp(type->type,globstring[STR_FTYPE_DEFAULT])==0))
  267.         return(globstring[STR_FTYPE_UNKNOWN]);
  268.     return(type->type);
  269. }
  270.  
  271. void fixhlen(win)
  272. int win;
  273. {
  274.     int a;
  275.  
  276.     if (dopus_curwin[win]->total>0 &&
  277.         (dopus_curwin[win]->firstentry->type==ENTRY_CUSTOM ||
  278.         dopus_curwin[win]->firstentry->type==ENTRY_DEVICE)) {
  279.         if (dopus_curwin[win]->firstentry->type==ENTRY_DEVICE)
  280.             dopus_curwin[win]->hlen=scrdata_dispwin_nchars[win];
  281.     }
  282.     else {
  283.         dopus_curwin[win]->hlen=0;
  284.         if (dopus_curwin[win]->total>0 || str_pathbuffer[win][0]) {
  285.             for (a=0;a<=DISPLAY_LAST;a++) {
  286.                 if (config->displaypos[win][a]==DISPLAY_NAME)
  287.                     dopus_curwin[win]->hlen+=config->displaylength[win][0];
  288.                 else if (config->displaypos[win][a]==DISPLAY_SIZE)
  289.                     dopus_curwin[win]->hlen+=8;
  290.                 else if (config->displaypos[win][a]==DISPLAY_PROTECT)
  291.                     dopus_curwin[win]->hlen+=9;
  292.                 else if (config->displaypos[win][a]==DISPLAY_DATE) {
  293.                     if (config->dateformat&DATE_12HOUR)
  294.                         dopus_curwin[win]->hlen+=20;
  295.                     else dopus_curwin[win]->hlen+=19;
  296.                 }
  297.                 else if (config->displaypos[win][a]==DISPLAY_COMMENT)
  298.                     dopus_curwin[win]->hlen+=config->displaylength[win][1];
  299.                 else if (config->displaypos[win][a]==DISPLAY_FILETYPE)
  300.                     dopus_curwin[win]->hlen+=config->displaylength[win][2];
  301.                 else if (AccountsBase) {
  302.                     if (config->displaypos[win][a]==DISPLAY_OWNER)
  303.                         dopus_curwin[win]->hlen+=config->displaylength[win][3];
  304.                     else if (config->displaypos[win][a]==DISPLAY_GROUP)
  305.                         dopus_curwin[win]->hlen+=config->displaylength[win][4];
  306.                     else if (config->displaypos[win][a]==DISPLAY_NETPROT)
  307.                         dopus_curwin[win]->hlen+=10;
  308.                 }
  309.             }
  310.         }
  311.         if (dopus_curwin[win]->hlen<scrdata_dispwin_nchars[win])
  312.             dopus_curwin[win]->hlen=scrdata_dispwin_nchars[win];
  313.         if (dopus_curwin[win]->hoffset>=(dopus_curwin[win]->hlen-scrdata_dispwin_nchars[win]))
  314.             dopus_curwin[win]->hoffset=dopus_curwin[win]->hlen-scrdata_dispwin_nchars[win];
  315.     }
  316. }
  317.  
  318.  
  319. /* Get the name of the screen we are currently on */
  320.  
  321. char *get_our_pubscreen()
  322. {
  323.     char *name;
  324.  
  325.     if (Window) {
  326.         /* Under 2.0 we lock the pubscreen list, and scan it to find
  327.            the screen we're on */
  328.         if (system_version2) {
  329.             struct List *pubscreenlist;
  330.             struct PubScreenNode *node;
  331.  
  332.             if (pubscreenlist=LockPubScreenList()) {
  333.                 for (node=(struct PubScreenNode *)pubscreenlist->lh_Head;
  334.                     node->psn_Node.ln_Succ;
  335.                     node=(struct PubScreenNode *)node->psn_Node.ln_Succ) {
  336.  
  337.                     /* See if this node is our screen */
  338.                     if (node->psn_Screen==Window->WScreen) {
  339.  
  340.                         /* Get name pointer */
  341.                         name=node->psn_Node.ln_Name;
  342.                         break;
  343.                     }
  344.                 }
  345.                 UnlockPubScreenList();
  346.             }
  347.         }
  348.  
  349.         /* Otherwise use default title */
  350.         if (!name) name=Window->WScreen->DefaultTitle;
  351.     }
  352.  
  353.     /* If no window open, use port name */
  354.     else name=str_arexx_portname;
  355.  
  356.     return(name);
  357. }
  358.  
  359.  
  360. /* Change name of arexx port */
  361.  
  362. void change_port_name(name)
  363. char *name;
  364. {
  365.     Forbid();
  366.     RemPort(arexx_port);
  367.     strncpy(str_arexx_portname,name,29);
  368.     str_arexx_portname[29]=0;
  369.     AddPort(arexx_port);
  370.     Permit();
  371. }
  372.