home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / filereqsetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-02  |  27.2 KB  |  916 lines

  1. /**************************************************************
  2. *                                                             *
  3. *      File/Font/Screenmode requester                         *
  4. *                                                             *
  5. *                                 (c) Nico François 1991-1994 *
  6. **************************************************************/
  7.  
  8. #include "filereq.h"
  9.  
  10. /****************************************************************************************/
  11.  
  12. /***************************
  13. *                          *
  14. *  REQUESTER WINDOW SETUP  *
  15. *                          *
  16. ***************************/
  17.  
  18. /****************************************************************************************/
  19.  
  20. static void REGARGS CheckGadgetsSize (ULONG *gadlen, ULONG *width, ULONG availwidth, ULONG num)
  21. {
  22.     ULONG overlap;
  23.     int   i;
  24.  
  25.     if (availwidth >= *width) return;
  26.     
  27.     overlap = ((((*width - availwidth) << 16) / num) + 0xffff) >> 16;
  28.     for (i = 0; i < num; i++)
  29.     {
  30.     gadlen[i] -= overlap;
  31.     *width -= overlap;
  32.     }
  33. }
  34.  
  35. /****************************************************************************************/
  36.  
  37. LONG ColorsDispFunc (struct Gadget *gad, WORD i)
  38. {
  39.     return (1 << i);
  40. }
  41.  
  42. /****************************************************************************************/
  43.  
  44. static char *oscanlabs_cat[] =
  45.     { MSG_REGULAR_SIZE, MSG_TEXT_SIZE, MSG_GFX_SIZE, MSG_MAX_SIZE, NULL };
  46.  
  47. /****************************************************************************************/
  48.  
  49. void REGARGS RenderLED (GlobData *glob)
  50. {
  51.     if (glob->led_x)
  52.     {
  53.     SetDrMd (glob->reqrp, JAM2);
  54.     SetAPen (glob->reqrp, glob->pens[glob->ledon ? FILLPEN : BACKGROUNDPEN]);
  55.     RectFill (glob->reqrp, glob->led_x + 2, glob->led_y + 1,
  56.           glob->led_x + glob->led_w - 3, glob->led_y + glob->led_h - 2);
  57.     }
  58. }
  59.  
  60. /****************************************************************************************/
  61.  
  62. void REGARGS RenderReqWindow (GlobData *glob, int refresh, int dowait)
  63. {
  64.     if (refresh)
  65.     GT_BeginRefresh (glob->reqwin);
  66.     
  67.     RenderLED (glob);
  68.     if (glob->numselectedgad)
  69.     UpdateNumSelGad (glob);
  70.         
  71.     if (glob->reqtype == RT_FONTREQ)
  72.     ShowFontSample (glob, refresh, dowait);
  73.     
  74.     if (refresh)
  75.     {
  76.     PrintFiles (glob);
  77.     GT_EndRefresh (glob->reqwin, TRUE);
  78.     }
  79. }
  80.  
  81. /****************************************************************************************/
  82.  
  83. static int scrollpens[] =
  84.     { TEXTPEN,FILLPEN,FILLTEXTPEN,BACKGROUNDPEN,HIGHLIGHTTEXTPEN,-1 };
  85.  
  86. /****************************************************************************************/
  87.  
  88. int REGARGS SetupReqWindow (GlobData *glob, int resized)
  89. {
  90.     struct NewGadget         ng;
  91.     struct Gadget         *gad;
  92.     struct Image         *img;
  93.     struct ReqDefaults         *reqdefs;
  94.     struct ReqToolsPrefs     *reqtoolsprefs;
  95.     int             top, val, val2, buttonheight, spacing, winheight;
  96.     int             scrwidth, scrheight, createpatgad, createstyle, winwidth, start_top;
  97.     int             i, width1, width2, num1, num2;
  98.     int             firsttime = TRUE;
  99.     int             isfilereq, isfontreq, isvolreq, isscreenmodereq, checkboxcount;
  100.     int             stdgadheight, defaultheight, dotinfowidth;
  101.     int             gadlen[8] , gadpos[8], reqdefnum, maxpen;
  102.     int             overscanstrlen, widthstrlen, heightstrlen, widthheightlen, dimgadwidth;
  103.     int             reqpos, check, led_off = 0, do_led;
  104.     int             checkw, checkh, checkskip, checktopoff;
  105.     int             leftoff, rightoff, totaloff;
  106.     char             **gadtxt = glob->gadtxt, *str, *dotinfostr;
  107.     char             *overscanstr, *widthstr, *heightstr, *defaultstr;
  108.     ULONG             mask;
  109.  
  110.  
  111.  
  112.     defaultheight = (glob->reqheight == 0);
  113.     spacing = rtGetVScreenSize (glob->scr, (ULONG *)&scrwidth, (ULONG *)&scrheight);
  114.     createpatgad = (glob->flags & FREQF_PATGAD) && !(glob->flags & FREQF_NOFILES);
  115.     createstyle = (glob->flags & FREQF_STYLE);
  116.     isvolreq = (glob->volumerequest);
  117.     isfilereq = (glob->reqtype == RT_FILEREQ) && !isvolreq;
  118.     isfontreq = (glob->reqtype == RT_FONTREQ);
  119.     isscreenmodereq = (glob->reqtype == RT_SCREENMODEREQ);
  120.     stdgadheight = glob->fontheight + 6;
  121.  
  122.     glob->entryheight = glob->fontheight + 1;
  123.  
  124.  
  125.     switch (glob->reqtype)
  126.     {
  127.     case RT_FILEREQ:
  128.         if (isvolreq) reqdefnum = RTPREF_VOLUMEREQ;
  129.         else reqdefnum = RTPREF_FILEREQ;
  130.         break;
  131.         
  132.     case RT_FONTREQ:
  133.         reqdefnum = RTPREF_FONTREQ;
  134.         break;
  135.         
  136.     case RT_SCREENMODEREQ:
  137.         reqdefnum = RTPREF_SCREENMODEREQ;
  138.         break;
  139.         
  140.     }
  141.  
  142.     leftoff = glob->scr->WBorLeft + 5;
  143.     rightoff = glob->scr->WBorRight + 5;
  144.     totaloff = (leftoff + rightoff);
  145.  
  146.  
  147. //rebuildwindow:
  148.     reqdefs = &rtLockPrefs()->ReqDefaults[reqdefnum];
  149.  
  150.     if (!glob->reqheight)
  151.     {
  152.     glob->reqheight = ((int)reqdefs->Size * scrheight) / 100;
  153.     }
  154.     else if (!resized)
  155.     {
  156.     if (glob->reqheight > scrheight) glob->reqheight = scrheight;
  157.     }
  158.  
  159.     rtUnlockPrefs();
  160.  
  161.  
  162.     start_top = (glob->scr->WBorTop + glob->scr->Font->ta_YSize + 1) + spacing;
  163.  
  164.     ng.ng_VisualInfo = glob->visinfo;
  165.     ng.ng_TextAttr = &glob->font;
  166.     glob->itxt.ITextFont = &glob->font;
  167.  
  168.  
  169.     checkw = CheckBoxWidth (&ng);
  170.     checkh = checkskip = CheckBoxHeight (&ng);
  171.     if (glob->fontheight > checkskip) checkskip = glob->fontheight;
  172.  
  173.  
  174.     if (isfilereq)
  175.     {
  176.     val = (stdgadheight + spacing) * 4 + 4;
  177.     if (createpatgad) val += stdgadheight + spacing / 2;
  178.     if (glob->flags & FREQF_NOFILES) val -= stdgadheight + spacing;
  179.     if (!(glob->flags & FREQF_MULTISELECT)) val -= stdgadheight + spacing;
  180.     }
  181.     else if (isfontreq)
  182.     {
  183.     val = stdgadheight * 2 + spacing * 3 + spacing / 2 + 8 + glob->sampleheight;
  184.     if (createstyle) val += checkskip + 4 + spacing;
  185.     }
  186.     else if (isvolreq)
  187.     {
  188.     val = (stdgadheight + spacing) * 2 + spacing / 2 + 4;
  189.     }
  190.     else
  191.     {
  192.     val = stdgadheight + glob->fontheight + spacing * 2 + 8;
  193.     if (glob->flags & SCREQF_SIZEGADS)
  194.         val += spacing + stdgadheight * 2 + spacing / 2;
  195.     if (glob->flags & SCREQF_DEPTHGAD)
  196.         val += glob->fontheight + 3 + spacing;
  197.     if (glob->flags & SCREQF_OVERSCANGAD)
  198.         val += stdgadheight + spacing;
  199.     if (glob->flags & SCREQF_AUTOSCROLLGAD)
  200.         val += checkskip + spacing;
  201.     }
  202.     glob->numentries = (glob->reqheight - val - start_top
  203.                 - BottomBorderHeight (glob->scr)) / glob->entryheight;
  204.  
  205.  
  206. retryopenwindow:
  207.  
  208.     top = start_top;
  209.  
  210.     gad = (struct Gadget *)CreateContext (&glob->buttoninfo.glist);
  211.     img = &glob->labelimages;
  212.  
  213.  
  214.     reqtoolsprefs = rtLockPrefs();
  215.  
  216.     do_led = !(reqtoolsprefs->Flags & RTPRF_NOLED);
  217.     reqdefs = &(reqtoolsprefs->ReqDefaults[reqdefnum]);
  218.  
  219.     val = (!firsttime || !defaultheight) ? 3 : reqdefs->MinEntries;
  220.     if (glob->numentries < val) glob->numentries = val;
  221.     firsttime = FALSE;
  222.     val = !defaultheight ? 50 : reqdefs->MaxEntries;
  223.     if (glob->numentries > val) glob->numentries = val;
  224.  
  225.     rtUnlockPrefs();
  226.  
  227.  
  228.     /* calculate width of gadgets and window */
  229.     gadtxt[7] = GetStr (glob->catalog, MSG_CANCEL);
  230.     glob->led_x = 0;
  231.     if (isfilereq || isfontreq)
  232.     {
  233.     for (i = 0; i < 4; i++) gadlen[i] = 0;
  234.     if (isfilereq)
  235.     {
  236.         if (do_led)
  237.         {
  238.         glob->led_h = glob->fontheight - 4;
  239.         if (glob->led_h < 7) glob->led_h = 7;
  240.         glob->led_w = 15 + (glob->led_h - 7) * 2;
  241.         glob->led_x = leftoff;
  242.         led_off = glob->led_w + 6;
  243.         }
  244.         gadtxt[0] = GetStr (glob->catalog, MSG_SELECTED);
  245.         gadlen[0] = StrWidth_noloc (&glob->itxt, "0000");
  246.         gadtxt[1] = GetStr (glob->catalog, MSG_ALL);
  247.         gadtxt[2] = GetStr (glob->catalog, MSG_MATCH);
  248.         gadtxt[3] = GetStr (glob->catalog, MSG_CLEAR);
  249.         num1 = 4;
  250.         gadtxt[5] = GetStr (glob->catalog, MSG_VOLUMES);
  251.         gadtxt[6] = GetStr (glob->catalog, MSG_PARENT);
  252.         num2 = 4;
  253.     }
  254.     else
  255.     {
  256.         gadtxt[0] = GetStr (glob->catalog, MSG_BOLD);
  257.         gadtxt[1] = GetStr (glob->catalog, MSG_ITALIC);
  258.         gadtxt[2] = GetStr (glob->catalog, MSG_UNDERLINE);
  259.         for (i = 0; i < 3; i++) gadlen[i] = checkw + 8 - 16;
  260.         num1 = 3;
  261.         num2 = 2;
  262.     }
  263.  
  264.     /* Calculate width of top row of gadgets */
  265.     width1 = 0;
  266.     for (i = 0; i < num1; i++)
  267.     {
  268.         gadlen[i] += StrWidth_noloc (&glob->itxt, gadtxt[i]) + 16;
  269.         width1 += gadlen[i];
  270.     }
  271.     }
  272.     else
  273.     {
  274.     /* isvolreq or screenmode request */
  275.     num1 = 4; num2 = 2;
  276.     width1 = 0;
  277.     }
  278.     if (num2 == 2) gadtxt[5] = gadtxt[7];
  279.  
  280.  
  281.     /* Calculate width of button row of gadgets */
  282.     width2 = 0;
  283.     for (i = 0; i < num2; i++)
  284.     {
  285.     val = StrWidth_noloc (&glob->itxt, gadtxt[i+4]) + 16;
  286.     if (val > width2) width2 = val;
  287.     }
  288.     for (i = 0; i < num2; i++) gadlen[i+4] = width2;
  289.     width2 *= num2;
  290.  
  291.  
  292.     if (isfilereq && !(glob->flags & FREQF_MULTISELECT)) width1 = 0;
  293.  
  294.  
  295.     if (isscreenmodereq)
  296.     {
  297.     int len;
  298.  
  299.  
  300.     overscanstr = GetStr (glob->catalog, MSG_OVERSCAN);
  301.     overscanstrlen = StrWidth_noloc (&glob->itxt, overscanstr);
  302.     widthstr = GetStr (glob->catalog, MSG_WIDTH);
  303.     widthstrlen = widthheightlen = StrWidth_noloc (&glob->itxt, widthstr);
  304.     heightstr = GetStr (glob->catalog, MSG_HEIGHT);
  305.     heightstrlen = StrWidth_noloc (&glob->itxt, heightstr);    
  306.     if (heightstrlen > widthheightlen) widthheightlen = heightstrlen;
  307.     defaultstr = GetStr (glob->catalog, MSG_DEFAULT);
  308.     winwidth = 276;
  309.     val = len = 0;
  310.     
  311.     if (glob->flags & SCREQF_OVERSCANGAD)
  312.     {
  313.         if (overscanstrlen > widthheightlen) widthheightlen = overscanstrlen;
  314.         for (i = 0; oscanlabs_cat[i]; i++)
  315.         {
  316.         glob->oscanlabs[i] = GetStr (glob->catalog, oscanlabs_cat[i]);
  317.         val = StrWidth_noloc (&glob->itxt, glob->oscanlabs[i]);
  318.         if (val > len) len = val;
  319.         }
  320.         val = len + overscanstrlen + 36 + 8 + (rightoff + leftoff) + 2;
  321.     }
  322.     if (glob->flags & SCREQF_SIZEGADS)
  323.     {
  324.         dimgadwidth = StrWidth_noloc (&glob->itxt, "000000") + 12;
  325.         val2 = widthheightlen + StrWidth_noloc (&glob->itxt, defaultstr) +
  326.            dimgadwidth + 8 + 8 + checkw + 8 + 4 + totaloff;
  327.         if (val2 > val) val = val2;
  328.     }
  329.     }
  330.     else
  331.     {
  332.     winwidth = width1 + (num1-1) * 8 + totaloff;
  333.     if (isfontreq) winwidth += 12;
  334.     if (winwidth < 300) winwidth = 300;
  335.     val = width2 + (num2-1) * 8 + totaloff;
  336.     }
  337.  
  338.     if (val > winwidth) winwidth = val;
  339.     if (winwidth > scrwidth) winwidth = scrwidth;
  340.     if (isfontreq || (isfilereq && (glob->flags & FREQF_MULTISELECT)))
  341.     {
  342.         CheckGadgetsSize ((ULONG *)gadlen, (ULONG *)&width1, winwidth - totaloff, num1);
  343.     rtSpread ((ULONG *)gadpos, (ULONG *)gadlen, width1, leftoff, winwidth - rightoff, num1);
  344.     }
  345.  
  346.     CheckGadgetsSize ((ULONG *)gadlen + 4, (ULONG *)&width2, winwidth - totaloff, num2);
  347.     
  348.     rtSpread ((ULONG *)gadpos + 4, (ULONG *)gadlen + 4, width2, leftoff, winwidth - rightoff, num2);
  349.  
  350.     if (num2 == 2)
  351.     {
  352.     gadpos[7] = gadpos[5];
  353.     gadlen[7] = gadlen[5];
  354.     }
  355.  
  356.  
  357.     if (isfilereq && (glob->flags & FREQF_MULTISELECT) && (width2 > width1))
  358.     {
  359.     for (i = 1; i < 4; i++)
  360.     {
  361.         val = gadpos[i-1] + gadlen[i-1] + 8;
  362.         gadlen[i] += (gadpos[i] - val);
  363.         gadpos[i] = val;
  364.     }
  365.     }
  366.  
  367.  
  368.     glob->boxleft = leftoff + 2; glob->boxtop = top + 2;
  369.     glob->boxheight = glob->numentries * glob->entryheight;
  370.     glob->boxright = winwidth - 21 - rightoff;
  371.  
  372.     /* create files gadget and scroller gadget */
  373.     ng.ng_Flags = 0;
  374.     InitNewGadget (&ng, leftoff + 4, top + 2,
  375.            winwidth - 26 - totaloff, glob->boxheight, NULL, FILES);
  376.  
  377.     gad = myCreateGadget (GENERIC_KIND, gad, &ng, TAG_END);
  378.     if (gad)
  379.     {
  380.     gad->GadgetType |= GTYP_BOOLGADGET;
  381.     gad->Flags |= GFLG_GADGHNONE;
  382.     gad->Activation |= GACT_IMMEDIATE|GACT_FOLLOWMOUSE|GACT_RELVERIFY;
  383.     }
  384.  
  385.     ng.ng_LeftEdge -= 4;
  386.     ng.ng_Width += 8;
  387.     ng.ng_TopEdge -= 2;
  388.     ng.ng_Height += 4;
  389.     ng.ng_GadgetID = 0;
  390.  
  391.     gad = my_CreateButtonGadget (gad, 0, &ng);
  392.  
  393.     if (gad) gad->Flags |= GFLG_GADGHNONE;
  394.  
  395.     InitNewGadget (&ng, winwidth - 18 - rightoff, top, 18, glob->boxheight + 4, NULL, FPROP);
  396.     gad = glob->scrollergad = myCreateGadget (SCROLLER_KIND, gad, &ng, GTSC_Visible, glob->numentries,
  397.                                            GTSC_Arrows, glob->fontheight + 1,
  398.                                        PGA_Freedom, LORIENT_VERT,
  399.                                            GTSC_Top, glob->buff->pos,
  400.                                        GTSC_Total, glob->buff->currentnum,
  401.                                            GA_RelVerify, TRUE,
  402.                                        GA_Immediate, TRUE,
  403.                                        TAG_END);
  404.     top += glob->boxheight + 4 + spacing / 2;
  405.  
  406.  
  407.     if (isfilereq || isvolreq)
  408.     {
  409.  
  410.     /*
  411.      * File Requester gadgets
  412.      */
  413.  
  414.     glob->strgaduserdata.flags = USERFLAG_UP_DOWN_ARROW;
  415.     glob->fnamegaduserdata.flags = USERFLAG_UP_DOWN_ARROW|USERFLAG_MATCH_FILE;
  416.     glob->fnamegaduserdata.proc = ThisProcess();
  417.  
  418.     /* create string gadgets */
  419.     if (createpatgad)
  420.     {
  421.         str = GetStr (glob->catalog, MSG_PATTERN);
  422.         glob->patkey = KeyFromStr (str, '_');
  423.         val = StrWidth_noloc (&glob->itxt, str) + 8;
  424.         InitNewGadget (&ng, leftoff + 2 + val, top, winwidth - 2 - val - totaloff,
  425.                             stdgadheight, NULL, PATSTR);
  426.         glob->patgad = gad = my_CreateStringGadget (gad, &ng, 60, glob->freq->patstr);
  427.         if (gad)
  428.         {
  429.         glob->patgadstr = ((struct StringInfo *)gad->SpecialInfo)->Buffer;
  430.         gad->UserData = &glob->strgaduserdata;
  431.         }
  432.         img = my_CreateGadgetLabelImage (img, &ng, str, leftoff + 2, top + 3, TEXTPEN);
  433.         top += ng.ng_Height + spacing / 2;
  434.     }
  435.     else glob->patgad = NULL;
  436.  
  437.     dotinfostr = GetStr (glob->catalog, MSG_DOT_INFO);
  438.     dotinfowidth = StrWidth_noloc (&glob->itxt, dotinfostr) + 8;
  439.     if (isfilereq)
  440.     {
  441.         str = GetStr (glob->catalog, MSG_GET);
  442.         val = StrWidth_noloc (&glob->itxt, str) + 8;
  443.         
  444.         if (val > dotinfowidth) dotinfowidth = val;
  445.         
  446.         val = dotinfowidth;
  447.         InitNewGadget (&ng, winwidth - rightoff - val, top, val,
  448.                             stdgadheight, str, GETDIR);
  449.         gad = my_CreateButtonGadget (gad, '_', &ng);
  450.     }
  451.     else val = 0;
  452.  
  453.     InitNewGadget (&ng, leftoff + led_off, top, winwidth - totaloff - val - led_off,
  454.                stdgadheight, NULL, DRAWERSTR);
  455.     gad = glob->drawergad =
  456.           my_CreateStringGadget (gad, &ng, 255, glob->freq->dirname);
  457.           
  458.     if (gad)
  459.     {
  460.         glob->led_y = top + (stdgadheight - glob->led_h - 1) / 2;
  461.         glob->drawerstr = ((struct StringInfo *)gad->SpecialInfo)->Buffer;
  462.         if (!(glob->flags & FREQF_NOFILES))
  463.         gad->UserData = &glob->strgaduserdata;
  464.     }
  465.         
  466.     top += ng.ng_Height + spacing / 2;
  467.     if (!(glob->flags & FREQF_NOFILES))
  468.     {
  469.         ng.ng_TopEdge = top;
  470.         ng.ng_LeftEdge -= led_off;
  471.         ng.ng_Width += led_off;
  472.         ng.ng_GadgetID = FILESTR;
  473.         gad = glob->filegad = my_CreateStringGadget (gad, &ng, 107, NULL);
  474.         if ((glob->mainstrgad = gad))
  475.         gad->UserData = &glob->fnamegaduserdata;
  476.  
  477.         ng.ng_LeftEdge = winwidth - rightoff - val;
  478.         ng.ng_Width = dotinfowidth;
  479.         ng.ng_GadgetText = dotinfostr;
  480.         ng.ng_GadgetID = INFO;
  481.         gad = my_CreateButtonGadget (gad, '_', &ng);
  482.         if (gad)
  483.         {
  484.         gad->Activation |= GACT_TOGGLESELECT;
  485.         if (!glob->freq->hideinfo) gad->Flags |= GFLG_SELECTED;
  486.         }
  487.  
  488.         top += ng.ng_Height + spacing;
  489.     }
  490.     else
  491.     {
  492.         glob->filegad = NULL;
  493.         glob->mainstrgad = glob->drawergad;
  494.         top += spacing / 2;
  495.     }
  496.  
  497.     if (glob->led_x)
  498.     {
  499.         InitNewGadget (&ng, glob->led_x, glob->led_y, glob->led_w, glob->led_h, NULL, 0);
  500.         gad = myCreateGadget (TEXT_KIND, gad, &ng, GTTX_Border, TRUE, TAG_END);
  501.     }
  502.         
  503.     } /* if (isfilereq || isvolreq) */
  504.     else if (isfontreq)
  505.     {
  506.  
  507.     /*
  508.      * Font Requester gadgets
  509.      */
  510.  
  511.     InitNewGadget (&ng, leftoff, top, winwidth - 65 - totaloff, stdgadheight, NULL, FILESTR);
  512.     gad = glob->filegad = my_CreateStringGadget (gad, &ng, 107, NULL);
  513.     glob->mainstrgad = glob->filegad;
  514.     ng.ng_LeftEdge = winwidth - 57 - rightoff; ng.ng_Width = 57; ng.ng_GadgetID = FONTSIZE;
  515.     gad = glob->drawergad = my_CreateIntegerGadget (gad, &ng, 4,
  516.                             glob->fontreq->Attr.ta_YSize, GACT_STRINGLEFT);
  517.     top += ng.ng_Height + spacing;
  518.  
  519.     glob->fontdisplayleft = leftoff + 4; glob->fontdisplayright = winwidth - rightoff - 5;
  520.     glob->fontdisplaytop = top + 2;
  521.     InitNewGadget (&ng, leftoff, top, winwidth - totaloff, glob->sampleheight + 4, NULL, 0);
  522.     gad = myCreateGadget (TEXT_KIND, gad, &ng, GTTX_Border, TRUE, TAG_END);
  523.     top += glob->sampleheight + 4 + spacing;
  524.  
  525.     glob->fontstyle = glob->fontreq->Attr.ta_Style;
  526.     }
  527.     else
  528.     {
  529.  
  530.  
  531.     /*
  532.      * ScreenMode Requester gadgets
  533.      */
  534.  
  535.     top -= spacing / 2;
  536.     InitNewGadget (&ng, leftoff, top, winwidth - totaloff, glob->fontheight + 4, NULL, 0);
  537.     /* Remove this one please. ;) */
  538.     gad = glob->modetxtgad = myCreateGadget (TEXT_KIND, gad, &ng,
  539.                          GTTX_Text, glob->nameinfo.Name,
  540.                          GTTX_Border, TRUE, TAG_END);
  541.     top += ng.ng_Height + spacing;
  542.  
  543.  
  544.     if (glob->flags & SCREQF_OVERSCANGAD)
  545.     {
  546.         glob->overscankey = KeyFromStr (overscanstr, '_');
  547.         val = overscanstrlen + 8;
  548.         InitNewGadget (&ng, leftoff + 2 + val, top, winwidth - rightoff - leftoff - 2 - val,
  549.                             stdgadheight, NULL, OVERSCN);
  550.                             
  551.         gad = glob->overscangad = myCreateGadget (CYCLE_KIND, gad, &ng,
  552.                               GTCY_Labels, glob->oscanlabs,
  553.                               GTCY_Active, glob->overscantype,
  554.                               TAG_END);
  555.                               
  556.         img = my_CreateGadgetLabelImage (img, &ng, overscanstr,
  557.                          leftoff + 2, top + 3, TEXTPEN);
  558.         top += stdgadheight + spacing;
  559.     }
  560.  
  561.  
  562.     if (glob->flags & SCREQF_SIZEGADS)
  563.     {
  564.  
  565.         /* Screen width and height gadgets */
  566.         glob->widthkey = KeyFromStr (widthstr, '_');
  567.  
  568.         val = widthheightlen + 8 + leftoff + 2;
  569.         InitNewGadget (&ng, val, top, dimgadwidth, stdgadheight, NULL, SCRWIDTH);
  570.  
  571.         gad = glob->widthgad = my_CreateIntegerGadget (gad, &ng, 5,
  572.                                glob->width, GACT_STRINGLEFT);
  573.  
  574.         img = my_CreateGadgetLabelImage (img, &ng, widthstr,
  575.  
  576.                                                     val - 8 - widthstrlen, top + 3, TEXTPEN);
  577.  
  578.  
  579.         ng.ng_Flags = PLACETEXT_RIGHT;
  580.  
  581.         checktopoff = 3 - (checkh - glob->fontheight + 1) / 2;
  582.         ng.ng_TopEdge = top + (glob->os30 ? checktopoff : 1);
  583.         ng.ng_LeftEdge += dimgadwidth + 8;
  584.         ng.ng_Width = checkw;
  585.         ng.ng_Height = checkh;
  586.         ng.ng_GadgetText = defaultstr;
  587.         ng.ng_GadgetID = DEFWIDTH;
  588.  
  589.         gad = glob->defwgad = myCreateGadget (CHECKBOX_KIND, gad, &ng, GTCB_Scaled, TRUE,
  590.                                        GTCB_Checked, glob->usedefwidth,
  591.                                        TAG_END);
  592.  
  593.         top += stdgadheight + spacing / 2;
  594.  
  595.         ng.ng_TopEdge = top + (glob->os30 ? checktopoff : 1);
  596.         ng.ng_GadgetID = DEFHEIGHT;
  597.  
  598.         gad = glob->defhgad = myCreateGadget (CHECKBOX_KIND, gad, &ng, GTCB_Scaled, TRUE,
  599.                                        GTCB_Checked, glob->usedefheight,
  600.                                        TAG_END);
  601.  
  602.  
  603.         ng.ng_Flags = 0;
  604.  
  605.         ng.ng_TopEdge = top;
  606.         ng.ng_LeftEdge = val;
  607.         ng.ng_Width = dimgadwidth;
  608.         ng.ng_Height = stdgadheight;
  609.         ng.ng_GadgetText = NULL;
  610.         ng.ng_GadgetID = SCRHEIGHT;
  611.         str = heightstr;
  612.         glob->heightkey = KeyFromStr (str, '_');
  613.  
  614.         gad = glob->heightgad = my_CreateIntegerGadget (gad, &ng, 5,
  615.  
  616.                                                             glob->height, GACT_STRINGLEFT);
  617.  
  618.         img = my_CreateGadgetLabelImage (img, &ng, str,
  619.                          val - 8 - heightstrlen, top + 3, TEXTPEN);
  620.  
  621.  
  622.         top += ng.ng_Height + spacing;
  623.     }
  624.  
  625.     if (glob->flags & SCREQF_DEPTHGAD)
  626.     {
  627.  
  628.  
  629.         /* Colors gadget */
  630.         str = GetStr (glob->catalog, MSG_COLORS);
  631.         glob->depthkey = KeyFromStr (str, '_');
  632.         val = StrWidth_noloc (&glob->itxt, str) + 8;
  633.         val2 = StrWidth_noloc (&glob->itxt, GetStr (glob->catalog, MSG_MAX));
  634.         InitNewGadget (&ng, leftoff + 2 + val, top, StrWidth_noloc (&glob->itxt, "0000 "),
  635.                             glob->fontheight + 3, NULL, 0);
  636.         BuildColStr (glob->currcolstr, glob->depth, glob->modeid);
  637.         gad = glob->currcolgad = myCreateGadget (TEXT_KIND, gad, &ng,
  638.                     GTTX_Text, glob->currcolstr, GTTX_Clipped, TRUE,
  639.                     (GadToolsBase->lib_Version >= 40) ? GTTX_Justification : TAG_IGNORE, GTJ_RIGHT, TAG_END);
  640.         ng.ng_LeftEdge += ng.ng_Width + 8;
  641.         val = StrWidth_noloc (&glob->itxt, "0000 ");
  642.         ng.ng_Width = winwidth - 22 - rightoff - ng.ng_LeftEdge - val - val2;
  643.         ng.ng_GadgetID = DEPTH;
  644.  
  645.         gad = glob->depthgad = myCreateGadget (SLIDER_KIND, gad, &ng,
  646.                            GA_RelVerify, TRUE, GA_Immediate , TRUE,
  647.                            GTSL_Min, glob->currmindepth, GTSL_Max, glob->currmaxdepth,
  648.                            GTSL_Level, glob->depth,
  649.                            GA_Disabled, (glob->currmindepth == glob->currmaxdepth), TAG_END);
  650.  
  651.         img = my_CreateGadgetLabelImage (img, &ng, str,
  652.                     leftoff + 2, top + 2, TEXTPEN);
  653.  
  654.         ng.ng_LeftEdge += ng.ng_Width + val2 + 20;
  655.         ng.ng_GadgetText = GetStr (glob->catalog, MSG_MAX);
  656.         ng.ng_Width = val;
  657.         BuildColStr (glob->maxcolstr, glob->currmaxdepth, 0);
  658.         gad = glob->maxcolgad = myCreateGadget (TEXT_KIND, gad, &ng,
  659.                             GTTX_Text, glob->maxcolstr, GTTX_Clipped, TRUE,
  660.                             (GadToolsBase->lib_Version >= 40) ? GTTX_Justification : TAG_IGNORE, GTJ_RIGHT, TAG_END);
  661.  
  662.         top += ng.ng_Height + spacing;
  663.     }
  664.  
  665.     if (glob->flags & SCREQF_AUTOSCROLLGAD)
  666.     {
  667.  
  668.         str = GetStr (glob->catalog, MSG_AUTOSCROLL);
  669.         glob->gadkey[CHECKBOX_AUTOSCROLL] = KeyFromStr (str, '_');
  670.         val = StrWidth_noloc (&glob->itxt, str) + 8;
  671.         InitNewGadget (&ng, leftoff + 2 + val, top + (checkskip - checkh + 1) / 2, checkw,
  672.                checkh, NULL, AUTOSCR);
  673.         gad = glob->checkboxgad[CHECKBOX_AUTOSCROLL] =
  674.          myCreateGadget (CHECKBOX_KIND, gad, &ng, GTCB_Scaled, TRUE,
  675.                               GTCB_Checked, glob->autoscroll, TAG_END);
  676.         img = my_CreateGadgetLabelImage (img, &ng, str, leftoff + 2,
  677.                          top + (checkskip - glob->fontheight + 1) / 2, TEXTPEN);
  678.         top += checkskip + spacing;
  679.     }
  680.  
  681.     ng.ng_Flags = 0;
  682.     }
  683.  
  684.  
  685.     /* create buttons */
  686.     buttonheight = createstyle ? (checkskip + 4) : (glob->fontheight + 6);
  687.     ng.ng_TextAttr = &glob->font;
  688.     checkboxcount = CHECKBOX_BOLD;
  689.  
  690.     for (i = 0; i < 8; i++)
  691.     {
  692.  
  693.     if (i == num1)
  694.     {
  695.         if (createstyle || (isfilereq && (glob->flags & FREQF_MULTISELECT)))
  696.         top += buttonheight + spacing;
  697.         if (createstyle) buttonheight = (glob->fontheight + 6);
  698.     }
  699.  
  700.     ng.ng_TopEdge = top;
  701.     ng.ng_LeftEdge = gadpos[i];
  702.     ng.ng_Width = gadlen[i];
  703.     ng.ng_Height = buttonheight;
  704.     ng.ng_GadgetText = gadtxt[i];
  705.     ng.ng_GadgetID = INFO + i;
  706.     
  707.     if (!isfilereq)
  708.     {
  709.         if (isfontreq)
  710.         {
  711.         if ((i == 3) || (i == 5) || (i == 6)) continue;
  712.         if (i < 3)
  713.         {
  714.             if (createstyle)
  715.             {
  716.  
  717.             check = FALSE;
  718.             
  719.             switch (i)
  720.             {
  721.                 case 0: check = (glob->fontstyle & FSF_BOLD); break;
  722.                 case 1: check = (glob->fontstyle & FSF_ITALIC); break;
  723.                 case 2: check = (glob->fontstyle & FSF_UNDERLINED); break;
  724.             }
  725.             
  726.             glob->gadkey[i] = KeyFromStr (gadtxt[i], '_');
  727.             ng.ng_Width = checkw;
  728.             ng.ng_Height = checkh;
  729.             ng.ng_GadgetID = BOLD + i;
  730.             ng.ng_GadgetText = NULL;
  731.             ng.ng_LeftEdge += (2 - i);
  732.             img = my_CreateGadgetLabelImage (img, &ng, gadtxt[i],
  733.                         ng.ng_LeftEdge, top + 2 + (checkskip - glob->fontheight + 1) / 2, TEXTPEN);
  734.             ng.ng_LeftEdge += gadlen[i] - checkw;
  735.             ng.ng_TopEdge += 2 + (checkskip - checkh + 1) / 2;
  736.             glob->checkboxgad[checkboxcount++] = gad = myCreateGadget
  737.                 (CHECKBOX_KIND, gad, &ng, GTCB_Checked, check, GTCB_Scaled, TRUE, TAG_END);
  738.             }
  739.             continue;
  740.             
  741.         }
  742.         
  743.         } /* if (isfontreq) */
  744.         else if (i < 4 || i == 5 || i == 6) continue;
  745.  
  746.     } /* if (!isfilereq) */
  747.  
  748.     if (i == 0)
  749.     {
  750.         if (glob->flags & FREQF_MULTISELECT)
  751.         {
  752.         ng.ng_GadgetText = NULL;
  753.         gad = glob->numselectedgad =
  754.               myCreateGadget (TEXT_KIND, gad, &ng, GTTX_Border, TRUE, TAG_END);
  755.         }
  756.     }
  757.     else
  758.     {
  759.         if ((i > 3) || (glob->flags & FREQF_MULTISELECT))
  760.         gad = my_CreateButtonGadget (gad, (i == 4) ? glob->underchar : '_', &ng);
  761.         if (i == 4) glob->okgad = gad;
  762.         if (i == 7) glob->cancelgad = gad;
  763.     }
  764.  
  765.     } /* for (i = 0; i < 8; i++) */
  766.  
  767.  
  768.     ng.ng_LeftEdge = ng.ng_TopEdge = ng.ng_Width = ng.ng_Height = 0;
  769.     ng.ng_GadgetText = NULL;
  770.     gad = myCreateGadget (GENERIC_KIND, gad, &ng, TAG_END);
  771.     
  772.     if (gad)
  773.     {
  774.     gad->GadgetType |= GTYP_BOOLGADGET;
  775.     gad->Flags |= GFLG_GADGIMAGE|GFLG_GADGHNONE;
  776.     gad->GadgetRender = (APTR)glob->labelimages.NextImage;
  777.     
  778.     if (glob->numselectedgad)
  779.     {
  780.         glob->selitxt.LeftEdge = glob->numselectedgad->LeftEdge + 8;
  781.         glob->selitxt.TopEdge = glob->numselectedgad->TopEdge + 3;
  782.         glob->selitxt.DrawMode = JAM1;
  783.         glob->selitxt.FrontPen = glob->pens[TEXTPEN];
  784.         glob->selitxt.IText = gadtxt[0];
  785.         glob->selitxt.ITextFont = &glob->font;
  786.         gad->GadgetText = &glob->selitxt;
  787.         glob->numselectedoff = IntuiTextLength (&glob->selitxt);
  788.     }
  789.     }
  790.  
  791.     /* is the window being rebuild or do we open it for the first time? */
  792.     winheight = top + buttonheight + spacing + BottomBorderHeight (glob->scr);
  793.     if (!glob->reqwin)
  794.     {
  795.     glob->newreqwin.Width = winwidth;
  796.     glob->newreqwin.Height = winheight;
  797.     glob->newreqwin.IDCMPFlags = glob->shareidcmp ? 0 : REQ_IDCMP;
  798.     glob->newreqwin.Flags = WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET
  799.                    |WFLG_CLOSEGADGET|WFLG_SIZEBBOTTOM|WFLG_ACTIVATE
  800.                    |WFLG_RMBTRAP|WFLG_SIMPLE_REFRESH;
  801.     glob->newreqwin.DetailPen = ( UBYTE ) -1;  /* glob->pens[BACKGROUNDPEN]; */
  802.     glob->newreqwin.BlockPen = ( UBYTE ) -1;   /* glob->pens[SHADOWPEN]; */
  803.     glob->newreqwin.Title = glob->title;
  804.     glob->newreqwin.LeftEdge = glob->leftedge;
  805.     glob->newreqwin.TopEdge = glob->topedge;
  806.     glob->newreqwin.MinWidth = glob->newreqwin.MaxWidth = winwidth;
  807.     glob->newreqwin.MinHeight = winheight;
  808.     
  809.     if (glob->numentries > 3)
  810.         glob->newreqwin.MinHeight -= (glob->numentries - 3) * glob->entryheight;
  811.         
  812.     glob->newreqwin.MaxHeight =
  813.             winheight + (50 - glob->numentries) * glob->entryheight;
  814.  
  815.     reqpos = CheckReqPos (glob->reqpos, reqdefnum, &glob->newreqwin);
  816.     
  817.     if (reqpos == REQPOS_POINTER)
  818.     {
  819.         glob->newreqwin.LeftEdge = -winwidth / 2;
  820.         glob->newreqwin.TopEdge = -winheight / 2;
  821.     }
  822.     
  823.     rtSetReqPosition (reqpos, &glob->newreqwin, glob->scr, glob->prwin);
  824.  
  825.     glob->zoom[2] = glob->newreqwin.MinWidth;
  826.     glob->zoom[3] = glob->newreqwin.MinHeight;
  827.     
  828.     if (!img || !gad || !(glob->reqwin = OpenWindowBF (&glob->newreqwin,
  829.         &glob->backfillhook, glob->pens, &glob->rpmask, glob->zoom, FALSE)))
  830.     {     
  831.         my_FreeGadgets (glob->buttoninfo.glist);
  832.         glob->buttoninfo.glist = NULL;
  833.         my_FreeLabelImages (&glob->labelimages);
  834.         glob->labelimages.NextImage = NULL;
  835.         
  836.         if (gad && img && (glob->numentries > 3))
  837.         {
  838.         glob->numentries--;
  839.         goto retryopenwindow;
  840.         }
  841.         
  842.         return (FALSE);
  843.     }
  844.     
  845.     glob->buttoninfo.win = glob->reqwin;
  846.  
  847.     glob->winaddr = (struct Window **)&(ThisProcess()->pr_WindowPtr);
  848.     glob->oldwinptr = *glob->winaddr;
  849.     *glob->winaddr = glob->reqwin;
  850.  
  851.     if (glob->shareidcmp)
  852.     {
  853.         glob->reqwin->UserPort = glob->prwin->UserPort;
  854.         ModifyIDCMP (glob->reqwin, REQ_IDCMP);
  855.     }
  856.     
  857.     glob->fnamegaduserdata.msgport = glob->reqwin->UserPort;
  858.     glob->timereq.tr_node.io_Message.mn_ReplyPort = glob->reqwin->UserPort;
  859.  
  860.     if ((WorkbenchBase = OpenLibrary ("workbench.library", 0)))
  861.     {
  862.         if ((glob->appwinport = CreateMsgPort()))
  863.         {
  864.         glob->appwindow = AddAppWindowA (0, NULL, glob->reqwin, glob->appwinport, NULL);
  865.         }
  866.     }
  867.  
  868.     maxpen = 0;
  869.     for (i = 0; scrollpens[i] >= 0; i++)
  870.         if (glob->pens[scrollpens[i]] > maxpen)
  871.             maxpen = glob->pens[scrollpens[i]];
  872.     mask = 1;
  873.     while (mask < maxpen)
  874.     {
  875.         mask <<= 1;
  876.         mask |= 1;
  877.     }
  878.     glob->entrymask = mask;
  879.     }
  880.     else
  881.     {
  882.     if (!img || !gad)
  883.     {
  884.         my_FreeGadgets (glob->buttoninfo.glist);
  885.         glob->buttoninfo.glist = NULL;
  886.         my_FreeLabelImages (&glob->labelimages);
  887.         glob->labelimages.NextImage = NULL;
  888.         return (FALSE);
  889.     }
  890.     
  891.     RefreshWindowFrame (glob->reqwin);
  892.     SetAPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  893.     RectFill (glob->reqrp, glob->reqwin->BorderLeft,
  894.                    glob->reqwin->BorderTop,
  895.                    glob->reqwin->Width - glob->reqwin->BorderRight - 1,
  896.                    glob->reqwin->Height - glob->reqwin->BorderBottom - 1);
  897.     }
  898.  
  899.     ((FI_REQ)glob->req)->ReqHeight = winheight;
  900.  
  901.     if (glob->filegad)
  902.     glob->filestr = ((struct StringInfo *)glob->filegad->SpecialInfo)->Buffer;
  903.  
  904.     glob->reqrp = glob->reqwin->RPort;
  905.     SetFont (glob->reqrp, glob->reqfont);
  906.     AddGList (glob->reqwin, glob->buttoninfo.glist, -1L, -1L, NULL);
  907.     RefreshGList (glob->buttoninfo.glist, glob->reqwin, NULL, -1L);
  908.     GT_RefreshWindow (glob->reqwin, NULL);
  909.  
  910.     glob->activegadget = glob->mainstrgad;
  911.     
  912.     return (1);
  913. }
  914.  
  915. /****************************************************************************************/
  916.