home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / show / amiga / app_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-15  |  6.1 KB  |  266 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_win.i"
  32.  
  33.  
  34. char *app_icon_name;                /* path/name of the icon */
  35.  
  36. extern struct Library        *WorkbenchBase;
  37. extern struct Library        *IconBase;
  38. extern struct IntuitionBase    *IntuitionBase;
  39. extern struct GfxBase        *GfxBase;
  40. extern struct DosLibrary    *DOSBase;
  41.  
  42. static struct MsgPort   *appMsgPort = NULL;    /* Vorbelegung ist WICHTIG! */
  43. static struct Window    *win        = NULL;
  44. static struct AppWindow *aw         = NULL;
  45.  
  46. static ULONG secs;                /* time of last click */
  47. static ULONG mics;
  48.  
  49.  
  50. static struct Gadget dragit =
  51.    { 0,0, 0, 0, 0,GADGHNONE|GRELWIDTH,GADGIMMEDIATE,
  52.    WDRAGGING, 0,0,0,0,0,0,0 };
  53.  
  54. static struct NewWindow NewWI = {
  55.    0, 1, 0, 0, 2,0, GADGETDOWN,
  56.    SMART_REFRESH | BORDERLESS | NOCAREREFRESH,
  57.    NULL, NULL, NULL, NULL, NULL, 0,0,0,0, WBENCHSCREEN
  58. };
  59.  
  60.  
  61.  
  62.  
  63. BOOL setup_app_win(UBYTE *app_sig, UBYTE *appwin_sig)
  64. {
  65.   struct DiskObject *diskobj;
  66.   ULONG id = 1, userdata = 0;
  67.   BOOL ret = TRUE;
  68.   char ai_name[256], *ptr;
  69.  
  70.   appMsgPort = NULL;
  71.   win = NULL;
  72.   aw = NULL;
  73.  
  74.   if ((appMsgPort = CreateMsgPort()) == NULL) {
  75.     ret = FALSE;
  76.   }
  77.   else {
  78.     strcpy(ai_name, app_icon_name);    /* damit ich nicht in einem constanten String aendere */
  79.     if ((ptr = strrchr(ai_name,'.')) != NULL) {
  80.       if (stricmp(ptr,".info") == 0) {
  81.         *ptr = '\0';
  82.       }
  83.     }
  84.     if ((diskobj = GetDiskObject(ai_name)) == NULL) {
  85.       clear_app_win();
  86.       ret = FALSE;
  87.     }
  88.     else {
  89.       dragit.Height = NewWI.Height = diskobj->do_Gadget.Height;
  90.       NewWI.Width  = diskobj->do_Gadget.Width;
  91.       if (diskobj->do_CurrentX >= 0) {
  92.     NewWI.LeftEdge = diskobj->do_CurrentX;
  93.       }
  94.       if (diskobj->do_CurrentY >= 0) {
  95.     NewWI.TopEdge = diskobj->do_CurrentY;
  96.       }
  97.  
  98.       if ((win = OpenWindow(&NewWI)) == NULL) {
  99.         clear_app_win();
  100.         ret = FALSE;
  101.       }
  102.       else {
  103.     AddGList(win,&dragit,0,1,0);
  104.     RefreshGadgets(&dragit,win,0);
  105.     if ((aw = AddAppWindowA(id, userdata, win, appMsgPort, NULL)) == NULL) {
  106.       clear_app_win();
  107.       ret = FALSE;
  108.     }
  109.     else {
  110.           DrawImage(win->RPort,(diskobj->do_Gadget.GadgetRender),0,0);
  111.       *app_sig    = appMsgPort->mp_SigBit;
  112.       *appwin_sig = win->UserPort->mp_SigBit;
  113.         }
  114.       }
  115.       FreeDiskObject(diskobj);
  116.     }
  117.   }
  118.  
  119.   if (!ret) {
  120.     Warning("Can't setup app-window!");
  121.     unset_appwin;
  122.   }
  123.  
  124.   secs = 0;
  125.   mics = 0;
  126.   
  127.   return ret;
  128. }
  129.  
  130.  
  131. void clear_app_win(void)
  132. {
  133.   struct AppMessage *amsg;
  134.  
  135.   if (aw != NULL) {
  136.     RemoveAppWindow(aw);
  137.     aw = NULL;
  138.   }
  139.   if (win != NULL) {
  140.     RemoveGadget(win,&dragit);
  141.     CloseWindow(win);
  142.     win = NULL;
  143.   }
  144.   if (appMsgPort != NULL) {
  145.     while(amsg = (struct AppMessage *)GetMsg(appMsgPort)) {
  146.       ReplyMsg((struct Message *)amsg);
  147.     }
  148.     DeleteMsgPort(appMsgPort);
  149.     appMsgPort = NULL;
  150.   }
  151.   unset_appwin;
  152. }
  153.  
  154.  
  155. long work_with_app_win(void)
  156. {
  157.   struct IntuiMessage *imess;
  158.   struct AppMessage *amsg;
  159.   struct WBArg *arg;
  160.   char file[256];
  161.   char *ptr;
  162.   ULONG sec2,mic2;
  163.   BOOL double_click;
  164.   long ret = 0L;            /* no action */
  165.   BPTR lock;
  166.  
  167.   if (!is_appwin) {
  168.     return 0L;
  169.   }
  170.  
  171.   if (win == NULL || aw == NULL || appMsgPort == NULL) {
  172.     Fatal(20,"internal error with app-win!");
  173.   }
  174.  
  175.   /* first look for normal window messages */
  176.   while (imess = (struct IntuiMessage *)GetMsg(win->UserPort)) {
  177.     sec2 = imess->Seconds;
  178.     mic2 = imess->Micros;
  179.     ReplyMsg(&(imess->ExecMessage));
  180.     double_click = DoubleClick(secs,mics,sec2,mic2);
  181.     secs = sec2;
  182.     mics = mic2;
  183.     if (double_click) {
  184.       ScreenToFront(screen);
  185.       make_show_active();
  186.     }
  187.   }
  188.  
  189.   /* and now, look for app-messages */
  190.   while (ret == 0L && (amsg = (struct AppMessage *)GetMsg(appMsgPort))) {
  191.     if (amsg->am_NumArgs == 1) {
  192.       arg = amsg->am_ArgList;               /* Argumentpointer bestimmen */
  193.       if (*arg->wa_Name != '\0') {
  194.         /* new file is now: 'arg->wa_Name' */
  195.         if (NameFromLock(arg->wa_Lock, file, 256)) {
  196.           if (AddPart(file, arg->wa_Name, 256)) {
  197.             if (stricmp(file, filename) == 0) {    /* same file again */
  198.               ret = KOMM + 3;
  199.             }
  200.             else {
  201.               if ((ptr = strrchr(file, '.')) != NULL) {
  202.                 ptr++;
  203.                 if (stricmp(ptr, "dvi") == 0) {
  204.                   strcpy(filename, file);
  205.                   ret = KOMM + 4;            /* load new file */
  206.                 }
  207.                 else if (stricmp(ptr, "tex") == 0) {
  208.                   strcpy(ptr, "dvi");            /* ueberschreibe das .tex */
  209.           lock = Lock(file, ACCESS_READ);
  210.           if (lock != NULL) {
  211.                     strcpy(filename, file);
  212.                     ret = KOMM + 4;            /* load new file */
  213.                     UnLock(lock);
  214.                   }
  215.                 }
  216.               }
  217.             }
  218.           }
  219.         }
  220.       }
  221.     }
  222.     ReplyMsg((struct Message *) amsg);
  223.   }
  224.  
  225.   if (ret != 0L) {
  226.     OpenNewDVI(filename, FALSE);
  227.     ScreenToFront(screen);
  228.     make_show_active();
  229.   }
  230.  
  231.   return ret;
  232. }
  233.  
  234.  
  235. BOOL save_app_win_pos(void)
  236. {
  237.   struct DiskObject *diskobj;
  238.   char ai_name[256], *ptr;
  239.  
  240.   if (win == NULL || !is_appwin) {
  241.     return TRUE;
  242.   }
  243.  
  244.   strcpy(ai_name, app_icon_name);    /* damit ich nicht in einem constanten String aendere */
  245.   if ((ptr = strrchr(ai_name,'.')) != NULL) {
  246.     if (stricmp(ptr,".info") == 0) {
  247.       *ptr = '\0';
  248.     }
  249.   }
  250.   if ((diskobj = GetDiskObject(ai_name)) == NULL) {
  251.     return FALSE;
  252.   }
  253.   else {
  254.     /* diskobj->do_Gadget.Height = win->Height; */
  255.     /* diskobj->do_Gadget.Width = win->Width; */
  256.     diskobj->do_CurrentX = win->LeftEdge;
  257.     diskobj->do_CurrentY = win->TopEdge;
  258.     if (!PutDiskObject(ai_name, diskobj)) {
  259.       FreeDiskObject(diskobj);
  260.       return FALSE;
  261.     }
  262.     FreeDiskObject(diskobj);
  263.   }
  264.   return TRUE;
  265. }
  266.