home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / show / amiga / app_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-06  |  5.5 KB  |  261 lines

  1. /* app_win.c */
  2.  
  3. #include "defines.h"
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuitionbase.h>
  7. #include <workbench/startup.h>
  8. #include <workbench/workbench.h>
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/icon_protos.h>
  16. #include <clib/wb_protos.h>
  17. #include <clib/dos_protos.h>
  18.  
  19. #include <pragmas/exec_pragmas.h>
  20. #include <pragmas/intuition_pragmas.h>
  21. #include <pragmas/icon_pragmas.h>
  22. #include <pragmas/wb_pragmas.h>
  23. #include <pragmas/dos_pragmas.h>
  24.  
  25.  
  26. #include "globals.h"
  27. #include "amscreen.h"
  28. #include "globals.i"
  29. #include "amscreen.i"
  30. #include "showdvi.i"
  31. #include "app_icon.i"
  32.  
  33.  
  34. /*
  35.  * Fuer die locale-Library:
  36.  *
  37.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  38.  * Achtung:
  39.  * Es muss/sollte 'multiple-include' erlaubt sein!
  40.  */
  41. #include "local.i"
  42.  
  43. #undef  CATCOMP_ARRAY
  44. #undef  CATCOMP_BLOCK
  45. #undef  CATCOMP_STRINGS
  46. #define CATCOMP_NUMBERS
  47. #include "localstr.h"
  48.  
  49.  
  50.  
  51. char *app_icon_name;                /* path/name of the icon */
  52.  
  53. extern struct Library        *WorkbenchBase;
  54. extern struct Library        *IconBase;
  55. extern struct IntuitionBase    *IntuitionBase;
  56. extern struct GfxBase        *GfxBase;
  57. extern struct DosLibrary    *DOSBase;
  58.  
  59. static struct MsgPort   *appMsgPort = NULL;    /* Vorbelegung ist WICHTIG! */
  60. static struct AppIcon   *ai         = NULL;
  61.  
  62.  
  63.  
  64.  
  65.  
  66. BOOL setup_app_icon(UBYTE *app_icon_sig)
  67. {
  68.   struct DiskObject *diskobj;
  69.   ULONG id = 1, userdata = 0;
  70.   BOOL ret = TRUE;
  71.   char ai_name[256], *ptr;
  72.  
  73.   appMsgPort = NULL;
  74.   ai = NULL;
  75.  
  76.   if ((appMsgPort = CreateMsgPort()) == NULL) {
  77.     ret = FALSE;
  78.   }
  79.   else {
  80.     strcpy(ai_name, app_icon_name);    /* damit ich nicht in einem constanten String aendere */
  81.     if ((ptr = strrchr(ai_name,'.')) != NULL) {
  82.       if (stricmp(ptr,".info") == 0) {
  83.         *ptr = '\0';
  84.       }
  85.     }
  86.     if ((diskobj = GetDiskObject(ai_name)) == NULL) {
  87.       clear_app_icon();
  88.       ret = FALSE;
  89.     }
  90.     else {
  91.       if (show_state.AppIconX != 0) {
  92.         diskobj->do_CurrentX = show_state.AppIconX;
  93.       }
  94.       else {
  95.         diskobj->do_CurrentX = NO_ICON_POSITION;
  96.       }
  97.       if (show_state.AppIconY != 0) {
  98.         diskobj->do_CurrentY = show_state.AppIconY;
  99.       }
  100.       else {
  101.         diskobj->do_CurrentY = NO_ICON_POSITION;
  102.       }
  103.       if ((ai = AddAppIconA(id, userdata, "ShowDVI", appMsgPort, NULL, diskobj, NULL)) == NULL) {
  104.         clear_app_icon();
  105.         ret = FALSE;
  106.       }
  107.       else {
  108.         *app_icon_sig    = appMsgPort->mp_SigBit;
  109.       }
  110.       FreeDiskObject(diskobj);
  111.     }
  112.   }
  113.  
  114.   if (!ret) {
  115.     Warning(MSG_NO_APP_ICON);
  116.     unset_appwin;
  117.   }
  118.  
  119.   return ret;
  120. }
  121.  
  122.  
  123. void clear_app_icon(void)
  124. {
  125.   struct AppMessage *amsg;
  126.  
  127.   if (ai != NULL) {
  128.     RemoveAppIcon(ai);
  129.     ai = NULL;
  130.   }
  131.   if (appMsgPort != NULL) {
  132.     while(amsg = (struct AppMessage *)GetMsg(appMsgPort)) {
  133.       ReplyMsg((struct Message *)amsg);
  134.     }
  135.     DeleteMsgPort(appMsgPort);
  136.     appMsgPort = NULL;
  137.   }
  138.   unset_appwin;
  139. }
  140.  
  141.  
  142. long work_with_app_icon(void)
  143. {
  144.   struct AppMessage *amsg;
  145.   struct WBArg *arg;
  146.   long ret = 0L;            /* no action */
  147.  
  148.   if (!is_appwin) {
  149.     return 0L;
  150.   }
  151.  
  152.   if (ai == NULL || appMsgPort == NULL) {
  153.     Fatal(20,MSG_INTERNAL_ERROR_W_ARG, "Application Icon");
  154.   }
  155.  
  156.  
  157.   /* and now, look for app-messages */
  158.   while (ret == 0L && (amsg = (struct AppMessage *)GetMsg(appMsgPort))) {
  159.     if (amsg->am_NumArgs == 1) {
  160.       arg = amsg->am_ArgList;               /* Argumentpointer bestimmen */
  161.       ret = CheckAppArgName(arg->wa_Name, arg->wa_Lock);
  162.     }
  163.     else {
  164.       if (amsg->am_NumArgs == 0) { /* doppelklick */
  165.         ScreenToFront(screen);
  166.         make_show_active();
  167.       }
  168.     }
  169.     ReplyMsg((struct Message *) amsg);
  170.   }
  171.  
  172.   if (ret != 0L) {
  173.     OpenNewDVI(filename, FALSE);
  174.     ScreenToFront(screen);
  175.     make_show_active();
  176.   }
  177.  
  178.   return ret;
  179. }
  180.  
  181.  
  182. long CheckAppArgName(char * name, BPTR lock)
  183. {
  184.   char file[256];
  185.   char *ptr;
  186.   BPTR tmplock;
  187.   long ret = 0;
  188.  
  189.   if (*name != '\0') {
  190.     /* new file is now: 'arg->wa_Name' */
  191.     if (NameFromLock(lock, file, 256)) {
  192.       if (AddPart(file, name, 256)) {
  193.         if (stricmp(file, filename) == 0) {    /* same file again */
  194.           ret = KOMM + 3;
  195.         }
  196.         else {
  197.           if ((ptr = strrchr(file, '.')) != NULL) {
  198.             ptr++;
  199.             if (stricmp(ptr, "dvi") == 0) {
  200.               strcpy(filename, file);
  201.               ret = KOMM + 4;            /* load new file */
  202.             }
  203.             else {
  204.               if (stricmp(ptr, "tex") == 0) {
  205.                 strcpy(ptr, "dvi");            /* ueberschreibe das .tex */
  206.          tmplock = Lock(file, ACCESS_READ);
  207.         if (tmplock != NULL) {
  208.                   strcpy(filename, file);
  209.                   ret = KOMM + 4;            /* load new file */
  210.                   UnLock(tmplock);
  211.                 }
  212.               }
  213.             }
  214.           }
  215.         }
  216.       }
  217.     }
  218.   }
  219.   
  220.   return ret;
  221. }
  222.  
  223.  
  224. BOOL save_app_icon_pos(void)
  225. {
  226. #if 0
  227.   struct DiskObject *diskobj;
  228.   char ai_name[256], *ptr;
  229. #endif
  230.  
  231.   return TRUE;    /* das funktioniert mit einem app_icon nicht! */
  232.  
  233. #if 0
  234.   if (ai == NULL || !is_appwin) {
  235.     return TRUE;
  236.   }
  237.  
  238.   strcpy(ai_name, app_icon_name);    /* damit ich nicht in einem constanten String aendere */
  239.   if ((ptr = strrchr(ai_name,'.')) != NULL) {
  240.     if (stricmp(ptr,".info") == 0) {
  241.       *ptr = '\0';
  242.     }
  243.   }
  244.   if ((diskobj = GetDiskObject(ai_name)) == NULL) {
  245.     return FALSE;
  246.   }
  247.   else {
  248.     /* diskobj->do_Gadget.Height = win->Height; */
  249.     /* diskobj->do_Gadget.Width = win->Width; */
  250.     diskobj->do_CurrentX = win->LeftEdge;
  251.     diskobj->do_CurrentY = win->TopEdge;
  252.     if (!PutDiskObject(ai_name, diskobj)) {
  253.       FreeDiskObject(diskobj);
  254.       return FALSE;
  255.     }
  256.     FreeDiskObject(diskobj);
  257.   }
  258.   return TRUE;
  259. #endif
  260. }
  261.