home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk793.lha / Snap / src.lha / src / windows.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-15  |  14.1 KB  |  632 lines

  1. /* Auto: make "CCEXTRA=-wq -qf"
  2. */
  3.  
  4. IMPORT BOOL Kick36;
  5.  
  6. struct Window *ControlWindow = NULL;
  7.  
  8. IMPORT struct MsgPort *Sharedport;
  9. IMPORT WORD Sharedrefs;
  10. IMPORT struct Window *SaveWin;
  11.  
  12. IMPORT LONG TopBar;
  13. IMPORT LONG LeftBar;
  14. IMPORT LONG RightBar;
  15. IMPORT LONG BottomBar;
  16. IMPORT LONG ScreenFontHeight;
  17. IMPORT struct TextFont *ScreenFont;
  18. IMPORT struct RastPort MyRP;
  19.  
  20. #define IDCMPFLAGS (MOUSEMOVE | NEWSIZE | CLOSEWINDOW | GADGETUP | \
  21.                     ACTIVEWINDOW | INACTIVEWINDOW | MOUSEBUTTONS)
  22.  
  23. UBYTE *WindowTitle = (UBYTE *)"Snap 1.61 © 1991 Mikael Karlsson & Absolut Software\0";
  24.  
  25. /* Important!
  26.  * The Inactive Image structs contains the values to be used with Kickstart >= 36.
  27.  * The Active Image structs contains the values to be used with Kickstart < 36.
  28.  * The Image structs are copied accordingly in OpenStuff().
  29.  */
  30.  
  31. struct Image InactiveDiskImage = {
  32.     0, 0,
  33.     18, 12, 2,
  34.     NULL,
  35.     0x03, 0x00,
  36.     NULL
  37. };
  38.  
  39. struct Image ActiveDiskImage = {
  40.     -1, -1,
  41.     15, 13, 1,
  42.     NULL,
  43.     0x01, 0x00,
  44.     NULL
  45. };
  46.  
  47. struct Image SelDiskImage = {
  48.     0, 0,
  49.     18, 12, 2,
  50.     NULL,
  51.     0x03, 0x00,
  52.     NULL
  53. };
  54.  
  55. #if 0
  56. struct Image DiskImage = {
  57.     0, 0,
  58.     18, 13, 1,
  59.     NULL,
  60.     0x01, 0x00,
  61.     NULL
  62. };
  63. #endif
  64.  
  65. struct Image InactiveClipImage = {
  66.     0, 0,
  67.     18, 13, 2,
  68.     NULL,
  69.     0x03, 0x00,
  70.     NULL
  71. };
  72.  
  73. struct Image ActiveClipImage = {
  74.     -1, 0,
  75.     15, 14, 1,
  76.     NULL,
  77.     0x01, 0x00,
  78.     NULL
  79. };
  80.  
  81. struct Image SelClipImage = {
  82.     0, 0,
  83.     18, 13, 2,
  84.     NULL,
  85.     0x03, 0x00,
  86.     NULL
  87. };
  88.  
  89. struct Gadget DiskGad = {
  90.     NULL,
  91.     -12, 10,
  92.     10, 12,
  93.     GADGIMAGE | GRELRIGHT,
  94.     RIGHTBORDER | RELVERIFY,
  95.     BOOLGADGET,
  96.     (APTR)&InactiveDiskImage,
  97.     (APTR)&SelDiskImage,
  98.     NULL,
  99.     0L,
  100.     NULL,
  101.     DISKGAD,
  102.     NULL,
  103. };
  104.  
  105. struct Gadget ClipGad = {
  106.     NULL,
  107.     -12, 10,
  108.     10, 13,
  109.     GADGIMAGE | GRELRIGHT,
  110.     RIGHTBORDER | RELVERIFY,
  111.     BOOLGADGET,
  112.     (APTR)&InactiveClipImage,
  113.     (APTR)&SelClipImage,
  114.     NULL,
  115.     0L,
  116.     NULL,
  117.     CLIPGAD,
  118.     NULL,
  119. };
  120.  
  121. struct Gadget VProp = {
  122.     NULL,
  123.     -12, 10,
  124.     10, -15,
  125.     GADGHCOMP | GRELRIGHT | GRELHEIGHT,
  126.     RIGHTBORDER | GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY,
  127.     PROPGADGET,
  128.     NULL,
  129.     NULL,
  130.     NULL,
  131.     0L,
  132.     NULL,
  133.     VPROP,
  134.     NULL
  135. };
  136.  
  137. struct Gadget HProp = {
  138.     NULL,
  139.     4, -6,
  140.     -23, 5,
  141.     GADGHCOMP | GRELBOTTOM | GRELWIDTH,
  142.     BOTTOMBORDER | GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY,
  143.     PROPGADGET,
  144.     NULL,
  145.     NULL,
  146.     NULL,
  147.     0L,
  148.     NULL,
  149.     HPROP,
  150.     NULL
  151. };
  152.  
  153. struct PropInfo VInfo = {
  154.     AUTOKNOB | FREEVERT | PROPBORDERLESS,
  155.     0, 0,
  156.     MAXBODY, MAXBODY,
  157.     0, 0, 0, 0, 0, 0
  158. };
  159.  
  160. struct PropInfo HInfo = {
  161.     AUTOKNOB | FREEHORIZ | PROPBORDERLESS,
  162.     0, 0,
  163.     MAXBODY, MAXBODY,
  164.     0, 0, 0, 0, 0, 0
  165. };
  166.  
  167. struct Image VImage = {
  168.     0, 0, 0, 0, 0, NULL, 0, 0, NULL
  169. };
  170. struct Image HImage = {
  171.     0, 0, 0, 0, 0, NULL, 0, 0, NULL
  172. };
  173.  
  174. /* Window structure for snapped gfx */
  175. struct NewWindow Nw = {
  176.     0, 1,                   /* LeftEdge, TopEdge  */
  177.     0, 0,                   /* Width, Height */
  178.     -1, -1,                 /* DetailPen, BlockPen */
  179.     NULL,                   /* IDCMPFlags */
  180.     WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | WINDOWSIZING | RMBTRAP,
  181.     NULL, NULL,             /* FirstGadget, CheckMark */
  182.     NULL,
  183.     NULL, NULL,             /* Screen, BitMap */
  184.     0, 0,                   /* MinWidth, MinHeight */
  185.     0, 0,                   /* MaxWidth, MaxHeight */
  186.     WBENCHSCREEN            /* Type */
  187. };
  188.  
  189. SHORT Coords3[5][2] = {
  190.     {  0,  0},
  191.     { 74,  0},
  192.     { 74, 10},
  193.     {  0, 10},
  194.     {  0,  0}
  195. };
  196.  
  197. SHORT Coords2[5][2] = {
  198.     {  0,  0},
  199.     { 74,  0},
  200.     { 74, 10},
  201.     {  0, 10},
  202.     {  0,  0}
  203. };
  204.  
  205. SHORT Coords1[5][2] = {
  206.     {  0,  0},
  207.     { 34,  0},
  208.     { 34, 10},
  209.     {  0, 10},
  210.     {  0,  0}
  211. };
  212.  
  213. struct Border Border3 = {
  214.     -1, -2,
  215.     1, 0,
  216.     JAM1,
  217.     5,
  218.     (SHORT *)&Coords3,
  219.     NULL
  220. };
  221.  
  222. struct Border Border2 = {
  223.     -1, -1,
  224.     1, 0,
  225.     JAM1,
  226.     5,
  227.     (SHORT *)&Coords2,
  228.     NULL
  229. };
  230.  
  231. struct Border Border1 = {
  232.     -1, -1,
  233.     1, 0,
  234.     JAM1,
  235.     5,
  236.     (SHORT *)&Coords1,
  237.     NULL
  238. };
  239.  
  240. UBYTE TranspBuf[5];
  241.  
  242. struct StringInfo TranspSI = {
  243.     TranspBuf,  /* Buf */
  244.     NULL,       /* UndoBuf */
  245.     0,          /* BufferPos */
  246.     4,          /* MaxChars */
  247.     0,          /* DispPos */
  248.     0,          /* UndoPos */
  249.     0,          /* NumChars */
  250.     0,          /* DispCount */
  251.     0, 0,       /* CLeft, CTop */
  252.     NULL,       /* Layer */
  253.     0L,         /* LongInt */
  254.     NULL        /* AltKeyMap */
  255. };
  256.  
  257. struct Gadget TranspGad = {
  258.     NULL,
  259.     5, 16,
  260.     32, 8,
  261.     LONGINT,
  262.     RELVERIFY,
  263.     STRGADGET,
  264.     (APTR)&Border3,
  265.     NULL,
  266.     NULL,
  267.     0L,
  268.     (APTR)&TranspSI,
  269.     0,
  270.     NULL,
  271. };
  272.  
  273. IMPORT char SaveName[DSIZE+FCHARS+2];
  274.  
  275. struct StringInfo NameSI = {
  276.     (UBYTE *)SaveName,      /* Buf */
  277.     NULL,                   /* UndoBuf */
  278.     0,                      /* BufferPos */
  279.     DSIZE+FCHARS,           /* MaxChars */
  280.     0,                      /* DispPos */
  281.     0,                      /* UndoPos */
  282.     0,                      /* NumChars */
  283.     0,                      /* DispCount */
  284.     0, 0,                   /* CLeft, CTop */
  285.     NULL,                   /* Layer */
  286.     0L,                     /* LongInt */
  287.     NULL                    /* AltKeyMap */
  288. };
  289.  
  290. struct Gadget NameGad = {
  291.     &TranspGad,
  292.     5, 16,
  293.     32, 8,
  294.     NULL,
  295.     NULL,
  296.     NULL,
  297.     (APTR)&Border2,
  298.     NULL,
  299.     NULL,
  300.     0L,
  301.     NULL,
  302.     NAMEGAD,
  303.     NULL,
  304. };
  305.  
  306. struct Gadget SaveGad = {
  307.     &NameGad,
  308.     5, 16,
  309.     32, 8,
  310.     GADGHCOMP,
  311.     RELVERIFY,
  312.     BOOLGADGET,
  313.     (APTR)&Border1,
  314.     NULL,
  315.     NULL,
  316.     0L,
  317.     NULL,
  318.     SAVEGAD,
  319.     NULL,
  320. };
  321.  
  322. /* Window structure for control window */
  323. struct NewWindow NewCW = {
  324.     10, 10,           /* LeftEdge, TopEdge  */
  325.     326, 40,          /* Width, Height */
  326.     -1, -1,           /* DetailPen, BlockPen */
  327.     NULL,             /* IDCMPFlags */
  328.     WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | ACTIVATE |
  329.       SMART_REFRESH | NOCAREREFRESH | RMBTRAP,
  330.     NULL, NULL,       /* FirstGadget, CheckMark */
  331.     (UBYTE *)"Snap Control Window",
  332.     NULL, NULL,       /* Screen, BitMap */
  333.     32, 32,           /* MinWidth, MinHeight */
  334.     -1, -1,           /* MaxWidth, MaxHeight */
  335.     WBENCHSCREEN      /* Type */
  336. };
  337.  
  338. #ifdef REQLIB
  339. IMPORT struct ReqFileRequester *NameFR;
  340. #endif REQLIB
  341. #ifdef ASLLIB
  342. IMPORT struct FileRequester *AslNameFR;
  343. #endif ASLLIB
  344.  
  345. struct Window *opensharedwindow(nw)
  346. struct NewWindow *nw;
  347. {
  348.     struct Window *win;
  349.     struct Screen scr;
  350.  
  351.     if (!GetScreenData((char *)&scr, (LONG)sizeof(struct Screen),
  352.       WBENCHSCREEN, NULL)) {
  353.         return NULL;     /* No WB */
  354.     }
  355.     if (nw->TopEdge+nw->Height > scr.Height) {
  356.         nw->TopEdge = scr.Height-nw->Height;
  357.     }
  358.     if (nw->LeftEdge+nw->Width > scr.Width) {
  359.         nw->LeftEdge = scr.Width-nw->Width;
  360.     }
  361.     if (nw->TopEdge < 0) {
  362.         nw->TopEdge = 0;
  363.     }
  364.     if (nw->LeftEdge < 0) {
  365.         nw->LeftEdge = 0;
  366.     }
  367.     if (nw->TopEdge+nw->Height > scr.Height) {
  368.         nw->Height = scr.Height-nw->TopEdge;
  369.     }
  370.     if (nw->LeftEdge+nw->Width > scr.Width) {
  371.         nw->Width = scr.Width-nw->LeftEdge;
  372.     }
  373.  
  374.     nw->IDCMPFlags = NULL;
  375.  
  376.     if (win = OpenWindow(nw)) {
  377.         if (!Sharedport && !(Sharedport = CreatePort(0L, 0L))) {
  378.             return NULL;
  379.         }
  380.         win->UserPort = Sharedport;
  381.         ModifyIDCMP(win, IDCMPFLAGS);
  382.         ++Sharedrefs;
  383.     }
  384.     return(win);
  385. }
  386.  
  387.  
  388. VOID closesharedwindow(win)
  389. struct Window *win;
  390. {
  391.     REGISTER struct IntuiMessage *im, *safe;
  392.     Forbid();
  393.     Sharedrefs--;
  394.     SAFEMAPLIST(&win->UserPort->mp_MsgList,
  395.       struct IntuiMessage *, im, safe) {
  396.         if (im->IDCMPWindow == win) {
  397.             Remove((struct Node *)im);
  398.             ReplyMsg((struct Message *)im);
  399.         }
  400.     }
  401.     win->UserPort = NULL;
  402.     ModifyIDCMP(win, NULL);
  403.     Permit();
  404.     CloseWindow(win);
  405.     if (!Sharedrefs) {
  406.         DeletePort(Sharedport);
  407.         Sharedport = NULL;
  408.     }
  409. }
  410.  
  411. VOID SetUpBorder(Border, Gad)
  412. struct Border *Border;
  413. struct Gadget *Gad;
  414. {
  415.     Border->XY[2] = Border->XY[4] = Gad->Width + 1;
  416.     Border->XY[5] = Border->XY[7] = Gad->Height + 1;
  417. }
  418.  
  419. VOID DrawOldBorders(GS)
  420. struct GfxSnap *GS;
  421. {
  422.     REGISTER LONG right;
  423.     REGISTER LONG bottom;
  424.  
  425.     if (!Kick36) {
  426.         right = GS->window->Width - GS->rightbar;
  427.         bottom = GS->window->Height - GS->bottombar;
  428.         SetDrMd(GS->window->RPort, JAM1);
  429.         SetAPen(GS->window->RPort, 0L);
  430.         Move(GS->window->RPort, 2L,        bottom);
  431.         Draw(GS->window->RPort, right,     bottom);
  432.         Move(GS->window->RPort, 2L,        bottom + 2);
  433.         Draw(GS->window->RPort, right,     bottom + 2);
  434.         Move(GS->window->RPort, right,     (LONG)GS->topbar);
  435.         Draw(GS->window->RPort, right,     bottom);
  436.         Draw(GS->window->RPort, right + 1, bottom);
  437.         Draw(GS->window->RPort, right + 1, (LONG)GS->topbar);
  438.         SetAPen(GS->window->RPort, 1L);
  439.         Move(GS->window->RPort, right + 2, (LONG)GS->topbar);
  440.         Draw(GS->window->RPort, right + 2, bottom);
  441.         Draw(GS->window->RPort, right + 3, bottom);
  442.         Draw(GS->window->RPort, right + 3, (LONG)GS->topbar);
  443.         Move(GS->window->RPort, 2L,        bottom + 1);
  444.         Draw(GS->window->RPort, right + 1, bottom + 1);
  445.     }
  446. }
  447.  
  448. VOID AdjustSize(GS)
  449. struct GfxSnap *GS;
  450. {
  451.     ULONG w = GS->window->Width - GS->leftbar - GS->rightbar;
  452.     ULONG h = GS->window->Height - GS->topbar - GS->bottombar;
  453.     ULONG vb, hb;
  454.  
  455.     vb = hb = MAXBODY;
  456.  
  457.     if (w < GS->width) {
  458.         hb = w * (ULONG)MAXBODY / GS->width;
  459.     }
  460.     if (h < GS->height) {
  461.         vb = h * (ULONG)MAXBODY / GS->height;
  462.     }
  463.     NewModifyProp(&GS->VProp, GS->window, NULL,
  464.       (ULONG)AUTOKNOB | FREEVERT | PROPBORDERLESS,
  465.       0L, 0L, (ULONG)MAXBODY, vb, 1L);
  466.     NewModifyProp(&GS->HProp, GS->window, NULL,
  467.       (ULONG)AUTOKNOB | FREEHORIZ | PROPBORDERLESS,
  468.       0L, 0L, hb, (ULONG)MAXBODY, 1L);
  469.     RefreshWindowFrame(GS->window);
  470.     DrawOldBorders(GS);
  471.     InitRastPort(&MyRP);
  472.     MyRP.BitMap = &GS->BM;
  473.     SetAPen(GS->window->RPort, 0);
  474.     RectFill(GS->window->RPort,
  475.       (LONG)GS->leftbar, (LONG)GS->topbar,
  476.       (LONG)GS->leftbar + w - 1, (LONG)GS->topbar + h - 1);
  477.     if (w > GS->width)  w = GS->width;
  478.     if (h > GS->height) h = GS->height;
  479.     ClipBlit(&MyRP, 0L, 0L, GS->window->RPort,
  480.       (LONG)GS->leftbar, (LONG)GS->topbar, w, h, 0xC0L);
  481. }
  482.  
  483. VOID SyncGS(GS)
  484. struct GfxSnap *GS;
  485. {
  486.     ULONG w = GS->window->Width - GS->leftbar - GS->rightbar;
  487.     ULONG h = GS->window->Height - GS->topbar - GS->bottombar;
  488.     ULONG vpos, hpos;
  489.     LONG temp;
  490.  
  491.     temp = GS->width - w;
  492.     if (temp <= 0) {
  493.         hpos = 0;
  494.     } else {
  495.         hpos = temp * (LONG)GS->HInfo.HorizPot / MAXBODY;
  496.         if (hpos > temp) {
  497.             hpos = temp;
  498.         }
  499.     }
  500.     temp = GS->height - h;
  501.     if (temp <= 0) {
  502.         vpos = 0;
  503.     } else {
  504.         vpos = temp * (LONG)GS->VInfo.VertPot / MAXBODY;
  505.         if (vpos > temp) {
  506.             vpos = temp;
  507.         }
  508.     }
  509.     DrawOldBorders(GS);
  510.     InitRastPort(&MyRP);
  511.     MyRP.BitMap = &GS->BM;
  512.     if (w > GS->width) {
  513.         w = GS->width;
  514.     }
  515.     if (h > GS->height) {
  516.         h = GS->height;
  517.     }
  518.     ClipBlit(&MyRP, hpos, vpos, GS->window->RPort,
  519.       (LONG)GS->leftbar, (LONG)GS->topbar, w, h, 0xC0L);
  520. }
  521.  
  522. SHORT OpenCW()
  523. {
  524.     WORD temp;
  525.     struct RastPort TmpRP;
  526.  
  527.     FixHeights();
  528.  
  529.     InitRastPort(&TmpRP);
  530.     SetFont(&TmpRP, ScreenFont);
  531.  
  532.     SaveGad.TopEdge = NameGad.TopEdge = TopBar + 2;
  533.     SaveGad.Height = NameGad.Height = TranspGad.Height = ScreenFontHeight + 2;
  534.  
  535.     TranspGad.TopEdge = SaveGad.TopEdge + SaveGad.Height + 5;
  536.  
  537.     SaveGad.LeftEdge = LeftBar + 2;
  538.     SaveGad.Width = TextLength(&TmpRP, "Save", 4L) + 1;
  539.     SaveGad.Flags |= GADGDISABLED;
  540.  
  541.     NameGad.LeftEdge = SaveGad.LeftEdge +
  542.       TextLength(&TmpRP, "Save as ", 8L);
  543.  
  544.     temp = 322 - NameGad.LeftEdge;
  545.     NameGad.Width =
  546.       temp - (temp % TextLength(&TmpRP, " ", 1L)) + 1;
  547.  
  548.     TranspGad.LeftEdge = SaveGad.LeftEdge +
  549.       TextLength(&TmpRP, "Transparent color ", 18L);
  550.     TranspGad.Width = TextLength(&TmpRP, "0000", 4L) + 2;
  551.  
  552.     NewCW.Height = TopBar + BottomBar + ScreenFontHeight * 2 + 12;
  553.  
  554. #define dmax(a,b) ((a>b)?a:b)
  555.     NewCW.Width=dmax((TranspGad.LeftEdge + TranspGad.Width + 2 + RightBar), (NameGad.LeftEdge + NameGad.Width + 2 + RightBar));
  556. #undef dmax
  557.  
  558.     ControlWindow = opensharedwindow(&NewCW);
  559.     if (!ControlWindow) {
  560.         return 0;
  561.     }
  562.     SetFont(ControlWindow->RPort, ScreenFont);
  563.     ModifyIDCMP(ControlWindow, ControlWindow->IDCMPFlags&~NEWSIZE);
  564.  
  565.     SetUpBorder(&Border1, &SaveGad);
  566.     SetUpBorder(&Border2, &NameGad);
  567.     SetUpBorder(&Border3, &TranspGad);
  568.  
  569. #if defined(REQLIB) || defined(ASLLIB)
  570. #ifdef REQLIB
  571. #ifdef ASLLIB
  572.     if ((NameFR) || (AslNameFR))
  573. #else ASLLIB
  574.     if (NameFR)
  575. #endif ASLLIB
  576. #else
  577.     if (AslNameFR)
  578. #endif REQLIB
  579.     {
  580.         NameGad.Flags = GADGHCOMP;
  581.         NameGad.Activation = RELVERIFY;
  582.         NameGad.GadgetType = BOOLGADGET;
  583.         NameGad.SpecialInfo = NULL;
  584.     } else
  585. #endif REQLIB || ASLLIB
  586.     {
  587.         NameGad.Flags = SELECTED;
  588.         NameGad.Activation = NULL;
  589.         NameGad.GadgetType = STRGADGET;
  590.         NameGad.SpecialInfo = (APTR)&NameSI;
  591.         ++NameGad.LeftEdge;         /* Adjust string gadget position */
  592.         ++NameGad.TopEdge;          /* Adjust string gadget position */
  593.     }
  594.  
  595.     strcpy(SaveName, "Snap.pic");
  596.     strcpy((char *)TranspBuf, "0");
  597.     TranspSI.LongInt = 0L;
  598.  
  599.     SetAPen(ControlWindow->RPort, 1L);
  600.     SetBPen(ControlWindow->RPort, 0L);
  601.     SetDrMd(ControlWindow->RPort, JAM2);
  602.     Move(ControlWindow->RPort,
  603.       (LONG)SaveGad.LeftEdge + 1,
  604.       (LONG)SaveGad.TopEdge + ControlWindow->RPort->Font->tf_Baseline + 1);
  605.     Text(ControlWindow->RPort, "Save as", 7L);
  606.     Move(ControlWindow->RPort,
  607.       (LONG)SaveGad.LeftEdge + 1,
  608.       (LONG)TranspGad.TopEdge + ControlWindow->RPort->Font->tf_Baseline);
  609.     Text(ControlWindow->RPort, "Transparent color", 17L);
  610.     AddGList(ControlWindow, &SaveGad, -1L, 3L, NULL);
  611.     RefreshGList(&SaveGad, ControlWindow, NULL, 3L);
  612.  
  613. #if defined(REQLIB) || defined(ASLLIB)
  614. #ifdef REQLIB
  615. #ifdef ASLLIB
  616.     if ((NameFR) || (AslNameFR))
  617. #else  ASLLIB
  618.     if (NameFR)
  619. #endif ASLLIB
  620. #else
  621.     if (AslNameFR)
  622. #endif REQLIB
  623.     {
  624.         GadText(&NameGad, SaveName, 8L);
  625.     } else
  626. #endif REQLIB || ASLLIB
  627.     {
  628.         ActivateGadget(&NameGad, ControlWindow, NULL);
  629.     }
  630.     return 1;
  631. }
  632.