home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Config / screen.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  30KB  |  945 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 "config.h"
  32.  
  33. char old_general_font[30];
  34.  
  35. doscreenconfig()
  36. {
  37.     ULONG class;
  38.     USHORT code,gadgetid,qual;
  39.     struct ConfigUndo *undo;
  40.     struct Gadget *gad;
  41.     int mode=-1,realpen=1,x,y,cursel=-1,a,b,fontnum=0,arrowact=0,c;
  42.     char *fg=NULL,*bg=NULL,buf[256],*ptr;
  43.     struct DOpusListView *view;
  44.     struct Screen scrbuf;
  45.  
  46.     showconfigscreen(CFG_SCREEN);
  47.     undo=makeundo(UNDO_MAIN);
  48.     curmode=NULL;
  49.     if (version2) fontsizelistview.h=52;
  50.  
  51.     FOREVER {
  52.         Wait(1<<Window->UserPort->mp_SigBit);
  53.         while (IMsg=getintuimsg()) {
  54.             if (!(mode==SCREEN_SCREENMODE &&
  55.                 (view=ListViewIDCMP(&screenmodeview,IMsg))!=(struct DOpusListView *)-1) &&
  56.                 !(mode==SCREEN_FONTS &&
  57.                 (view=ListViewIDCMP(&fontplacelist,IMsg))!=(struct DOpusListView *)-1) &&
  58.                 !(mode==SCREEN_PALETTE &&
  59.                 (view=ListViewIDCMP(&palettelist,IMsg))!=(struct DOpusListView *)-1)) {
  60.                 class=IMsg->Class; code=IMsg->Code; qual=IMsg->Qualifier;
  61.                 x=IMsg->MouseX; y=IMsg->MouseY;
  62.                 if (class==GADGETUP || class==GADGETDOWN) {
  63.                     gad=(struct Gadget *)IMsg->IAddress;
  64.                     gadgetid=gad->GadgetID;
  65.                 }
  66.                 ReplyMsg((struct Message *)IMsg);
  67.                 switch (class) {
  68.                     case IDCMP_MENUPICK:
  69.                         if (code==MENUNULL) break;
  70.                         if (mode>-1) {
  71.                             select_gadget(&maingad[mode],0);
  72.                             removescreenedit(mode);
  73.                             mode=realpen=cursel=-1;
  74.                         }
  75.                         switch ((a=ITEMNUM(code))) {
  76.                             case 0:
  77.                             case 1:
  78.                                 if (doload(CFG_SCREEN,a)) {
  79.                                     if (config->scrdepth!=screen_depth)
  80.                                         close_screen();
  81.                                     open_screen();
  82.                                     showconfigscreen(CFG_SCREEN);
  83.                                 }
  84.                                 break;
  85.                         }
  86.                         break;
  87.  
  88.                     case IDCMP_MOUSEBUTTONS:
  89.                         if (code==SELECTDOWN) {
  90.                             if (mode==SCREEN_PALETTE) {
  91.                                 if (x>x_off+297 && y>y_off+33 && x<x_off+514 && y<y_off+46) {
  92.                                     for (a=0;a<(1<<screen_depth);a++) {
  93.                                         if (x>=palettegad_xy[a][0] && x<=palettegad_xy[a][2] &&
  94.                                             y>=palettegad_xy[a][1] && y<=palettegad_xy[a][3]) {
  95.                                             realpen=screen_pens[a].pen;
  96.                                             showcolourvals(realpen,1);
  97.                                             showpalettegad(a);
  98.                                             break;
  99.                                         }
  100.                                     }
  101.                                 }
  102.                             }
  103.                             else if (mode==SCREEN_ARROWS) {
  104.                                 for (a=0;a<3;a++) {
  105.                                     if (x>x_off+182+(a*129) && x<x_off+307+(a*129) &&
  106.                                         y>y_off+32 && y<y_off+89) {
  107.                                         if (arrowact!=a) {
  108.                                             showarrowborders(a,arrowact);
  109.                                             arrowact=a;
  110.                                             DoCycleGadget(&arrowgadgets[7],Window,arrowtypetxt,arrowact);
  111.                                             fixarrowgads(arrowact);
  112.                                             break;
  113.                                         }
  114.                                     }
  115.                                 }
  116.                             }
  117.                             else if (mode==SCREEN_COLOURS && fg && bg) {
  118.                                 a=*fg; b=*bg;
  119.                                 if (docolourgad(rp,x_off+208,y_off+33,x,y,
  120.                                     (cursel==COLBIT_3DBOXES)?NULL:cfg_string[STR_EXAMPLE],&a,&b,CFG_GADGET)) {
  121.                                     *fg=a; *bg=b;
  122.                                     if (cursel==COLBIT_3DBOXES) {
  123.                                         showfuncob(rp,cfg_string[STR_EXAMPLE],1,0,CFG_GADGET,x_off+302,y_off+23);
  124.                                         showscreencolours(COLOURS_ALL,NULL,NULL,4);
  125.                                     }
  126.                                     else showscreencolours((1<<cursel),NULL,NULL,0);
  127.                                 }
  128.                                 else {
  129.                                     for (a=0;;a++) {
  130.                                         if (coloursel[a].item==-1) break;
  131.                                         if (x>=x_off+coloursel[a].x1 && x<=x_off+coloursel[a].x2 &&
  132.                                             y>=y_off+coloursel[a].y1 && y<=y_off+coloursel[a].y2) {
  133.                                             if (version2 || (a!=COLBIT_STRINGS && a!=COLBIT_SELSTRINGS)) {
  134.                                                 cursel=coloursel[a].item;
  135.                                                 showscreencolours((1<<cursel),&fg,&bg,0);
  136.                                                 showcolourscycle(*fg,*bg,cursel);
  137.                                                 setupcolourbox(rp,x_off+208,y_off+33,*fg,*bg);
  138.                                             }
  139.                                             break;
  140.                                         }
  141.                                     }
  142.                                 }
  143.                             }
  144.                         }
  145.                         break;
  146.  
  147.                     case IDCMP_RAWKEY:
  148.                         if ((code>=0x60 && code<=0x67) || code&0x80) break;
  149.                         buf[0]=0;
  150.                         RawkeyToStr(code,qual,NULL,buf,10);
  151.                         switch (LToUpper(buf[0])) {
  152.                             case 'R':
  153.                                 if (mode==SCREEN_PALETTE) ActivateStrGad(&palettegads[3],Window);
  154.                                 break;
  155.                             case 'G':
  156.                                 if (mode==SCREEN_PALETTE) ActivateStrGad(&palettegads[4],Window);
  157.                                 break;
  158.                             case 'B':
  159.                                 if (mode==SCREEN_PALETTE) ActivateStrGad(&palettegads[5],Window);
  160.                                 break;
  161.                             case 'W':
  162.                                 if (mode==SCREEN_SCREENMODE) ActivateStrGad(&screenmodegads[0],Window);
  163.                                 break;
  164.                             case 'H':
  165.                                 if (mode==SCREEN_SCREENMODE) ActivateStrGad(&screenmodegads[1],Window);
  166.                                 break;
  167.                             case 'C':
  168.                                 if (mode==SCREEN_SCREENMODE) ActivateStrGad(&screenmodegads[2],Window);
  169.                                 break;
  170.                         }
  171.                         break;
  172.  
  173.                     case IDCMP_GADGETDOWN:
  174.                         if (gadgetid>=PALETTE_SLIDER && gadgetid<PALETTE_SLIDER+3) {
  175.                             updatecolourvals(realpen,0);
  176.                             FOREVER {
  177.                                 Wait(1<<Window->UserPort->mp_SigBit);
  178.                                 while (IMsg=getintuimsg()) {
  179.                                     class=IMsg->Class;
  180.                                     ReplyMsg((struct Message *)IMsg);
  181.                                     if (class==GADGETUP) break;
  182.                                     if (class==MOUSEMOVE) updatecolourvals(realpen,0);
  183.                                 }
  184.                                 if (class==GADGETUP) {
  185.                                     updatecolourvals(realpen,1);
  186.                                     break;
  187.                                 }
  188.                             }
  189.                         }
  190.                         else if (gadgetid>=ARROWBASE+3 && gadgetid<ARROWBASE+7) {
  191.                             gadgetid-=ARROWBASE+3; a=0;
  192.                             FOREVER {
  193.                                 if (IntuitionBase->ActiveWindow!=Window ||
  194.                                     !(gad->Flags&SELECTED)) break;
  195.                                 if ((arrowact==0 && gadgetid>1) ||
  196.                                     (arrowact>0 && gadgetid<2)) {
  197.                                     b=config->arrowsize[arrowact];
  198.                                     if ((arrowact==0 && gadgetid==2) ||
  199.                                         (arrowact>0 && gadgetid==0))
  200.                                         ++config->arrowsize[arrowact];
  201.                                     else --config->arrowsize[arrowact];
  202.                                     switch (arrowact) {
  203.                                         case 0:
  204.                                             showupdownslider();
  205.                                             break;
  206.                                         case 1:
  207.                                             showleftrightslider();
  208.                                             break;
  209.                                         case 2:
  210.                                             showstringgadget();
  211.                                             break;
  212.                                     }
  213.                                     if (b==config->arrowsize[arrowact]) a=-1;
  214.                                 }
  215.                                 else {
  216.                                     switch (arrowact) {
  217.                                         case 0:
  218.                                             b=config->sliderwidth;
  219.                                             if (gadgetid==1) config->sliderwidth-=2;
  220.                                             else config->sliderwidth+=2;
  221.                                             showupdownslider();
  222.                                             if (b==config->sliderwidth) {
  223.                                                 a=-1;
  224.                                                 break;
  225.                                             }
  226.                                             break;
  227.                                         case 1:
  228.                                             b=config->sliderheight;
  229.                                             if (gadgetid==3) config->sliderheight-=2;
  230.                                             else config->sliderheight+=2;
  231.                                             showleftrightslider();
  232.                                             if (b==config->sliderheight) {
  233.                                                 a=-1;
  234.                                                 break;
  235.                                             }
  236.                                             break;
  237.                                         case 2:
  238.                                             b=config->stringheight;
  239.                                             if (gadgetid==3) config->stringheight-=2;
  240.                                             else config->stringheight+=2;
  241.                                             showstringgadget();
  242.                                             if (b==config->stringheight) {
  243.                                                 a=-1;
  244.                                                 break;
  245.                                             }
  246.                                             break;
  247.                                     }
  248.                                 }
  249.                                 if (a==-1) break;
  250.                                 else if (a==0) {
  251.                                     Delay(5);
  252.                                     a=1;
  253.                                 }
  254.                                 else Delay(1);
  255.                                 while (IMsg=getintuimsg()) {
  256.                                     class=IMsg->Class;
  257.                                     ReplyMsg((struct Message *)IMsg);
  258.                                     if (class==GADGETUP) break;
  259.                                 }
  260.                                 if (class==GADGETUP) break;
  261.                             }
  262.                         }
  263.                         else if (gadgetid>=ARROWBASE && gadgetid<ARROWBASE+3) {
  264.                             gadgetid-=ARROWBASE;
  265.                             if (config->arrowpos[arrowact]!=gadgetid) {
  266.                                 config->arrowpos[arrowact]=gadgetid;
  267.                                 if (arrowact==0) showupdownslider();
  268.                                 else if (arrowact==1) showleftrightslider();
  269.                                 else showstringgadget();
  270.                             }
  271.                             fixarrowgads(arrowact);
  272.                         }
  273.                         break;
  274.  
  275.                     case IDCMP_GADGETUP:
  276.                         if (mode==SCREEN_GENERAL && gadgetid>GAD_BASE) {
  277.                             config->generalscreenflags=processtickgad(scr_generalgadgets,config->generalscreenflags,gadgetid-GAD_BASE,-1);
  278.                             break;
  279.                         }
  280.                         if (gadgetid<SCREEN_OKAY) {
  281.                             if (mode==gadgetid) {
  282.                                 removescreenedit(mode);
  283.                                 mode=realpen=cursel=-1;
  284.                                 makehelpname((char *)-1);
  285.                                 doscreentitle(cfg_string[STR_SCREEN_SCREEN]);
  286.                                 break;
  287.                             }
  288.                             if (mode>-1) {
  289.                                 if (mode==SCREEN_SCREENMODE || mode==SCREEN_FONTS)
  290.                                     select_gadget(&maingad[gadgetid],0);
  291.                                 select_gadget(&maingad[mode],0);
  292.                                 removescreenedit(mode);
  293.                                 if (mode==SCREEN_SCREENMODE || mode==SCREEN_FONTS)
  294.                                     select_gadget(&maingad[gadgetid],1);
  295.                                 mode=realpen=cursel=-1;
  296.                                 makehelpname((char *)-1);
  297.                             }
  298.                             makehelpname(screengadgets[gadgetid]);
  299.                             doscreentitle(currenthelpname);
  300.                         }
  301.                         if (gadgetid>=PALETTE_STRING && gadgetid<PALETTE_STRING+3) {
  302.                             updatecolourvals(realpen,-1);
  303.                             if (code!=0x9) getnextgadget(gad);
  304.                         }
  305.                         else switch (gadgetid) {
  306.                             case FONT_SIZE:
  307.                                 if (!version2) break;
  308.                                 RefreshStrGad(&fontsizegadget,Window);
  309.                                 a=atoi(fontsize_buf);
  310.                                 c=config->fontsizes[fontnum];
  311.                                 config->fontsizes[fontnum]=a;
  312.                                 for (b=0;b<fontsizelistview.count;b++)
  313.                                     if (atoi(fontsizelistview.items[b])==a) break;
  314.                                 if (b<fontsizelistview.count) {
  315.                                     fontsizelistview.itemselected=b;
  316.                                     if (b<fontsizelistview.topitem ||
  317.                                         b>fontsizelistview.topitem+fontsizelistview.lines-1)
  318.                                         fontsizelistview.topitem=b;
  319.                                     RefreshListView(&fontsizelistview,1);
  320.                                     fontsize_buf[0]=0;
  321.                                     RefreshStrGad(&fontsizegadget,Window);
  322.                                 }
  323.                                 else {
  324.                                     fontsizelistview.itemselected=-1;
  325.                                     RefreshListView(&fontsizelistview,1);
  326.                                 }
  327.                                 if (c!=a) dofontdemo(config->fontbufs[fontnum],config->fontsizes[fontnum]);
  328.                                 break;
  329.  
  330.                             case ARROWCYCLE:
  331.                                 a=arrowact;
  332.                                 if (qual&IEQUALIFIER_LSHIFT || qual&IEQUALIFIER_RSHIFT) {
  333.                                     if ((--arrowact)<0) arrowact=2;
  334.                                 }
  335.                                 else if ((++arrowact)==3) arrowact=0;
  336.                                 showarrowborders(arrowact,a);
  337.                                 DoCycleGadget(&arrowgadgets[7],Window,arrowtypetxt,arrowact);
  338.                                 fixarrowgads(arrowact);
  339.                                 break;
  340.  
  341.                             case SCREEN_SLIDER_LEFTCYCLE:
  342.                                 config->slider_pos^=1;
  343.                                 show_slider_setup(182,32,0);
  344.                                 break;
  345.  
  346.                             case SCREEN_SLIDER_RIGHTCYCLE:
  347.                                 config->slider_pos^=2;
  348.                                 show_slider_setup(373,32,1);
  349.                                 break;
  350.  
  351.                             case SCREEN_PALETTE:
  352.                                 realpen=screen_pens[1].pen;
  353.                             case SCREEN_FONTS:
  354.                                 fontnum=FONT_CLOCK;
  355.                             case SCREEN_ARROWS:
  356.                                 arrowact=0;
  357.                             case SCREEN_COLOURS:
  358.                             case SCREEN_GENERAL:
  359.                             case SCREEN_SCREENMODE:
  360.                             case SCREEN_SLIDERS:
  361.                                 mode=gadgetid;
  362.                                 makescreenedit(mode);
  363.                                 if (gadgetid==SCREEN_COLOURS) {
  364.                                     cursel=0;
  365.                                     fg=&config->statusfg; bg=&config->statusbg;
  366.                                 }
  367.                                 break;
  368.  
  369.                             case COLOURS_SELECT:
  370.                                 if (qual&IEQUALIFIER_LSHIFT || qual&IEQUALIFIER_RSHIFT) {
  371.                                     if ((--cursel)<0) cursel=(version2)?COLBIT_SELSTRINGS:COLBIT_3DBOXES;
  372.                                 }
  373.                                 else {
  374.                                     if (!coloursgadgets[++cursel] ||
  375.                                         (!version2 && cursel==COLBIT_STRINGS)) cursel=0;
  376.                                 }
  377.                                 showscreencolours((1<<cursel),&fg,&bg,0);
  378.                                 showcolourscycle(*fg,*bg,cursel);
  379.                                 setupcolourbox(rp,x_off+208,y_off+33,*fg,*bg);
  380.                                 break;
  381.  
  382.                             case SCREENMODE_WIDTH:
  383.                                 a=atoi(screenwidth_buf);
  384.                                 if (a%2) lsprintf(screenwidth_buf,"%ld",a+1);
  385.                                 CheckNumGad(&screenmodegads[SCREENMODE_WIDTH-300],Window,curmode->minw,curmode->maxw);
  386.                                 config->scrw=atoi(screenwidth_buf);
  387.                                 config->scr_winw=config->scrw;
  388.                                 if (code!=0x9) getnextgadget(gad);
  389.                                 break;
  390.  
  391.                             case SCREENMODE_HEIGHT:
  392.                                 CheckNumGad(&screenmodegads[SCREENMODE_HEIGHT-300],Window,curmode->minh,curmode->maxh);
  393.                                 config->scrh=atoi(screenheight_buf);
  394.                                 config->scr_winh=config->scrh;
  395.                                 if (code!=0x9) getnextgadget(gad);
  396.                                 break;
  397.  
  398.                             case SCREENMODE_DEPTH:
  399.                                 a=atoi(screendepth_buf);
  400.                                 for (b=curmode->maxdepth;b>=2;b--) {
  401.                                     if (a>=(1<<b)) {
  402.                                         a=b;
  403.                                         break;
  404.                                     }
  405.                                 }
  406.                                 if (b<=2) a=2;
  407.  
  408.                             case SCREENMODE_SLIDER:
  409.                                 if (gadgetid==SCREENMODE_SLIDER)
  410.                                     a=GetSliderPos(&screenmodegads[SCREENMODE_SLIDER-300],curmode->maxdepth-1,1)+2;
  411.                                 if (a>curmode->maxdepth) a=curmode->maxdepth;
  412.                                 else if (a<2) a=2;
  413.                                 lsprintf(screendepth_buf,"%ld",(1<<a));
  414.                                 RefreshStrGad(&screenmodegads[SCREENMODE_DEPTH-300],Window);
  415.                                 config->scrdepth=a;
  416.                                 FixSliderPot(Window,&screenmodegads[SCREENMODE_SLIDER-300],config->scrdepth-2,curmode->maxdepth-1,1,2);
  417.                                 if (gadgetid==SCREENMODE_DEPTH && code!=0x9) getnextgadget(gad);
  418.                                 break;
  419.  
  420.                             case SCREENMODE_DEFWIDTH:
  421.                                 if (screenmodegads[SCREENMODE_DEFWIDTH-300].Flags&SELECTED) {
  422.                                     config->screenflags|=SCRFLAGS_DEFWIDTH;
  423.                                     EnableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  424.                                     config->scrw=curmode->defw;
  425.                                     config->scr_winw=config->scrw;
  426.                                     fixmodegads(curmode);
  427.                                 }
  428.                                 else config->screenflags&=~SCRFLAGS_DEFWIDTH;
  429.                                 fixdefaultgads(curmode);
  430.                                 fixmodegads(curmode);
  431.                                 break;
  432.  
  433.                             case SCREENMODE_DEFHEIGHT:
  434.                                 if (screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags&SELECTED) {
  435.                                     config->screenflags|=SCRFLAGS_DEFHEIGHT;
  436.                                     EnableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  437.                                     config->scrh=curmode->defh;
  438.                                     config->scr_winh=config->scrh;
  439.                                     fixmodegads(curmode);
  440.                                 }
  441.                                 else config->screenflags&=~SCRFLAGS_DEFHEIGHT;
  442.                                 fixdefaultgads(curmode);
  443.                                 fixmodegads(curmode);
  444.                                 break;
  445.  
  446.                             case SCREENMODE_HALFHEIGHT:
  447.                                 if (screenmodegads[SCREENMODE_HALFHEIGHT-300].Flags&SELECTED)
  448.                                     config->screenflags|=SCRFLAGS_HALFHEIGHT;
  449.                                 else config->screenflags&=~SCRFLAGS_HALFHEIGHT;
  450.                                 break;
  451.  
  452.                             case SCREEN_CANCEL:
  453.                                 doundo(undo,UNDO_MAIN);
  454.                                 if (config->scrdepth!=screen_depth) {
  455.                                     if (mode>-1) {
  456.                                         removescreenedit(mode);
  457.                                         mode=-1;
  458.                                     }
  459.                                     close_screen();
  460.                                 }
  461.                                 open_screen();
  462.                             case SCREEN_OKAY:
  463.                                 if (mode>-1) removescreenedit(mode);
  464.                                 doundo(undo,0);
  465.                                 return((gadgetid==SCREEN_OKAY));
  466.                         }
  467.                         break;
  468.                 }
  469.             }
  470.             else if (view) {
  471.                 if (mode==SCREEN_FONTS) {
  472.                     if (view->listid==1) {
  473.                         if (version2) {
  474.                             fontsize_buf[0]=0;
  475.                             RefreshStrGad(&fontsizegadget,Window);
  476.                         }
  477.                         fontnum=fontplacevals[view->itemselected];
  478.                         initfontlist(fontnum,1,fontplaceflags[fontnum]);
  479.                     }
  480.                     else if (fontnum>=0 && fontnum<NUMFONTS) {
  481.                         if (view->listid==2) {
  482.                             strcpy(buf,config->fontbufs[fontnum]);
  483.                             if ((ptr=strstri(buf,".font"))) *ptr=0;
  484.                             if (strcmp(buf,view->items[view->itemselected])) {
  485.                                 if (version2) {
  486.                                     fontsize_buf[0]=0;
  487.                                     RefreshStrGad(&fontsizegadget,Window);
  488.                                 }
  489.                                 strcpy(config->fontbufs[fontnum],view->items[view->itemselected]);
  490.                                 config->fontsizes[fontnum]=initfontlist(fontnum,0,fontplaceflags[fontnum]);
  491.                                 StrConcat(config->fontbufs[fontnum],".font",40);
  492.                             }
  493.                         }
  494.                         else if (view->listid==3) {
  495.                             if (version2) {
  496.                                 fontsize_buf[0]=0;
  497.                                 RefreshStrGad(&fontsizegadget,Window);
  498.                             }
  499.                             a=config->fontsizes[fontnum];
  500.                             config->fontsizes[fontnum]=atoi(view->items[view->itemselected]);
  501.                             if (a!=config->fontsizes[fontnum])
  502.                                 dofontdemo(config->fontbufs[fontnum],config->fontsizes[fontnum]);
  503.                         }
  504.                     }
  505.                 }
  506.                 else if (view->listid==1) {
  507.                     curmode=showdisplaydesc();
  508.                     fixdefaultgads(curmode);
  509.                     if (screenmodegads[SCREENMODE_DEFWIDTH-300].Flags&SELECTED) {
  510.                         config->scrw=curmode->defw;
  511.                         config->scr_winw=config->scrw;
  512.                         EnableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  513.                     }
  514.                     if (screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags&SELECTED) {
  515.                         config->scrh=curmode->defh;
  516.                         config->scr_winh=config->scrh;
  517.                         EnableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  518.                     }
  519.                     fixmodegads(curmode);
  520.                     if (config->screenflags&SCRFLAGS_DEFWIDTH)
  521.                         DisableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  522.                     if (config->screenflags&SCRFLAGS_DEFHEIGHT)
  523.                         DisableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  524.                     config->screenmode=curmode->mode;
  525.  
  526.                     if (curmode->mode==MODE_PUBLICSCREENUSE /* ||
  527.                         curmode->mode==MODE_PUBLICSCREENCLONE */ ) {
  528.                         for (a=0;a<80;a++) {
  529.                             if (!curmode->name[a]) break;
  530.                             if (a>0 && curmode->name[a-1]==':') {
  531.                                 if ((strcmp(&curmode->name[a],cfg_string[STR_SCREEN_MODE_USE]))==0)
  532.                                     break;
  533. /*
  534.                                 if ((strcmp(&curmode->name[a],cfg_string[STR_SCREEN_MODE_CLONE]))==0)
  535.                                     break;
  536. */
  537.                             }
  538.                         }
  539.                         if (a>0 && curmode->name[a]) {
  540.                             strncpy(config->pubscreen_name,curmode->name,a);
  541.                             config->pubscreen_name[a-1]=0;
  542.                         }
  543.                     }
  544.                     else config->pubscreen_name[0]=0;
  545.  
  546.                     if (version2<OSVER_39) {
  547.                         if (config->screenmode==MODE_WORKBENCHUSE ||
  548.                             curmode->mode==MODE_PUBLICSCREENUSE)
  549.                             DisableGadget(&maingad[SCREEN_PALETTE],rp,2,1);
  550.                         else EnableGadget(&maingad[SCREEN_PALETTE],rp,2,1);
  551.                     }
  552.                 }
  553.                 else if (view->listid==2) {
  554.                     if (view->itemselected>=0 && view->itemselected<13) {
  555.                         if (view->itemselected==0)
  556.                             load_palette(Screen,palette_backup,1<<screen_depth);
  557.                         else if (view->itemselected==1)
  558.                             loadrgb4(Screen,def_dopus_palette,1<<screen_depth);
  559.                         else if (view->itemselected==3) {
  560.                             ULONG *palbuf;
  561.                             int wbdepth,size;
  562.  
  563.                             GetWBScreen(&scrbuf);
  564.                             wbdepth=1<<scrbuf.RastPort.BitMap->Depth;
  565.                             size=(wbdepth*3)*sizeof(ULONG);
  566.                             if (palbuf=AllocMem(size,MEMF_CLEAR)) {
  567.                                 ULONG palette[48];
  568.  
  569.                                 get_palette(&scrbuf,palbuf,wbdepth);
  570.                                 for (a=0;a<4;a++) {
  571.                                     palette[(a*3)]=palbuf[(a*3)];
  572.                                     palette[(a*3)+1]=palbuf[(a*3)+1];
  573.                                     palette[(a*3)+2]=palbuf[(a*3)+2];
  574.                                 }
  575.                                 for (a=4;a<16;a++) {
  576.                                     palette[(a*3)]=config->new_palette[(a*3)];
  577.                                     palette[(a*3)+1]=config->new_palette[(a*3)+1];
  578.                                     palette[(a*3)+2]=config->new_palette[(a*3)+2];
  579.                                 }
  580.                                 if (wbdepth>4 && screen_depth>2) {
  581.                                     int a,endwb,endme;
  582.  
  583.                                     endwb=wbdepth-4;
  584.                                     endme=(1<<screen_depth)-4;
  585.  
  586.                                     for (a=0;a<4;a++) {
  587.                                         palette[((a+endme)*3)]=palbuf[((a+endwb)*3)];
  588.                                         palette[((a+endme)*3)+1]=palbuf[((a+endwb)*3)+1];
  589.                                         palette[((a+endme)*3)+2]=palbuf[((a+endwb)*3)+2];
  590.                                     }
  591.                                 }
  592.                                 load_palette(Screen,palette,1<<screen_depth);
  593.                                 FreeMem(palbuf,size);
  594.                             }
  595.                         }
  596.                         else loadrgb4(Screen,defpalettes[view->itemselected-2],4);
  597.                         get_palette(Screen,config->new_palette,1<<screen_depth);
  598.                         showcolourvals(realpen,1);
  599.                     }
  600.                 }
  601.                 break;
  602.             }
  603.         }
  604.     }
  605. }
  606.  
  607. void makescreenedit(mode)
  608. int mode;
  609. {
  610.     int a,b,wclone,shortage,size,fnum,fontnum,nopropnum,only8num,num;
  611.     ULONG modeid;
  612.     char *ptr,buf[256];
  613.     DisplayInfoHandle *handle;
  614.     struct DisplayInfo *dispinfo;
  615.     struct AvailFonts *avail;
  616.  
  617.     borderkey=NULL;
  618.  
  619.     SetAPen(rp,screen_pens[1].pen);
  620.     switch (mode) {
  621.         case SCREEN_PALETTE:
  622.             bpg=4;
  623.             if (version2>=OSVER_39) {
  624.                 modeid=GetVPModeID(vp);
  625.                 if ((handle=FindDisplayInfo(config->screenmode)) ||
  626.                     (handle=FindDisplayInfo(modeid))) {
  627.                     GetDisplayInfoData(handle,buf,256,DTAG_DISP,0);
  628.                     dispinfo=(struct DisplayInfo *)buf;
  629.                     bpg=(dispinfo->RedBits+dispinfo->GreenBits+dispinfo->BlueBits)/3;
  630.                 }
  631.             }
  632.             for (a=0;a<3;a++) {
  633.                 fix_slider(&palettegads[a]);
  634.                 FixSliderBody(Window,&palettegads[a],1<<bpg,1,2);
  635.             }
  636.             AddGadgets(Window,
  637.                 palettegads,
  638.                 palettegadgets,
  639.                 6,
  640.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  641.             do3dbox(x_off+296,y_off+33,220,14);
  642.             do3dbox(x_off+250,y_off+33,40,14);
  643.             setuplist(&palettelist,250,93);
  644.             AddListView(&palettelist,1);
  645.             showpalettegad(1);
  646.             showcolourvals(screen_pens[1].pen,1);
  647.             get_palette(Screen,palette_backup,1<<screen_depth);
  648.             break;
  649.  
  650.         case SCREEN_COLOURS:
  651.             if (config->stringfgcol==config->stringbgcol) ++config->stringfgcol;
  652.             do3dbox(x_off+142,y_off+61,464,122);
  653.             AddGadgetBorders(&borderkey,
  654.                 &coloursgad,
  655.                 1,
  656.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  657.             AddGadgets(Window,
  658.                 &coloursgad,
  659.                 NULL,
  660.                 1,
  661.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  662.             setupcolourbox(rp,x_off+208,y_off+33,config->statusfg,config->statusbg);
  663.             showscreencolours(COLOURS_ALL,NULL,NULL,0);
  664.             showcolourscycle(config->statusfg,config->statusbg,0);
  665.             break;
  666.  
  667.         case SCREEN_SCREENMODE:
  668.             screenkey=NULL; firstmode=NULL;
  669.             screenmodeview.itemselected=-1; wclone=0;
  670.             busy();
  671.             if ((a=initscreenmodes()) &&
  672.                 (screenmodelist=LAllocRemember(&screenkey,(a+1)*4,MEMF_CLEAR))) {
  673.                 screenmode=firstmode;
  674.                 for (b=0;b<a;b++) {
  675.                     if (screenmodelist[b]=LAllocRemember(&screenkey,DISPLAYNAMELEN,MEMF_CLEAR))
  676.                         strcpy(screenmodelist[b],screenmode->name);
  677.                     if (screenmode->mode==MODE_WORKBENCHCLONE) wclone=b;
  678.                     if (screenmode->mode==config->screenmode) {
  679.                         if (screenmode->mode==MODE_PUBLICSCREENUSE) {
  680.                             lsprintf(buf,"%s:%s",config->pubscreen_name,cfg_string[STR_SCREEN_MODE_USE]);
  681.                             if (LStrCmpI(buf,screenmode->name)==0) screenmodeview.itemselected=b;
  682.                         }
  683. /*
  684.                         else if (screenmode->mode==MODE_PUBLICSCREENCLONE) {
  685.                             lsprintf(buf,"%s:%s",config->pubscreen_name,cfg_string[STR_SCREEN_MODE_CLONE]);
  686.                             if (LStrCmpI(buf,screenmode->name)==0) screenmodeview.itemselected=b;
  687.                         }
  688. */
  689.                         else screenmodeview.itemselected=b;
  690.                     }
  691.                     if (!(screenmode=screenmode->next)) break;
  692.                 }
  693.             }
  694.             unbusy();
  695.             if (screenmodeview.itemselected==-1) screenmodeview.itemselected=wclone;
  696.             setuplist(&screenmodeview,238,17);
  697.             screenmodeview.items=screenmodelist;
  698.             screenmodeview.topitem=screenmodeview.itemselected;
  699.             AddListView(&screenmodeview,1);
  700.             screenmodegads[0].Flags&=~GFLG_DISABLED;
  701.             screenmodegads[1].Flags&=~GFLG_DISABLED;
  702.             for (a=SCREENMODE_DEFWIDTH-300;a<SCREENMODE_SLIDER-300;a++)
  703.                 screenmodegads[a].Flags&=~(GFLG_SELECTED|GFLG_DISABLED);
  704.             if (config->screenflags&SCRFLAGS_HALFHEIGHT)
  705.                 screenmodegads[SCREENMODE_HALFHEIGHT-300].Flags|=GFLG_SELECTED;
  706.             else screenmodegads[SCREENMODE_HALFHEIGHT-300].Flags&=~GFLG_SELECTED;
  707.             fix_slider(&screenmodegads[SCREENMODE_SLIDER-300]);
  708.             AddGadgets(Window,
  709.                 screenmodegads,
  710.                 screenmodegadgets,
  711.                 7,
  712.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  713.             Do3DBox(rp,
  714.                 x_off+238,y_off+140,
  715.                 272,40,
  716.                 screen_pens[config->gadgetbotcol].pen,screen_pens[config->gadgettopcol].pen);
  717.             SetAPen(rp,screen_pens[1].pen);
  718.             UScoreText(rp,
  719.                 cfg_string[STR_DISPLAY_MODE_DESCRIPTION],
  720.                 x_off+238,y_off+136,
  721.                 -1);
  722.             fixmodegads((curmode=showdisplaydesc()));
  723.             fixdefaultgads(curmode);
  724.             break;
  725.  
  726.         case SCREEN_FONTS:
  727.             if (!fontdatabuf) {
  728.                 busy();
  729.                 size=(sizeof(struct AvailFonts)*512)+sizeof(struct AvailFontsHeader);
  730.                 do {
  731.                     if (!(fontdatabuf=LAllocRemember(&fontkey,size,MEMF_CLEAR)))
  732.                         break;
  733.                     if (shortage=AvailFonts(fontdatabuf,size,AFF_MEMORY|AFF_DISK)) {
  734.                         LFreeRemember(&fontkey);
  735.                         size+=shortage;
  736.                     }
  737.                     else break;
  738.                 } while (shortage);
  739.                 unbusy();
  740.                 if (!fontdatabuf) break;
  741.                 num=((struct AvailFontsHeader *)fontdatabuf)->afh_NumEntries;
  742.                 if (!num ||
  743.                     !(fontlist=LAllocRemember(&fontkey,(num+1)*4,MEMF_CLEAR)) ||
  744.                     !(fontsizelist=LAllocRemember(&fontkey,(num+1)*4,MEMF_CLEAR)))
  745.                     break;
  746.                 if (!(noproplist=LAllocRemember(&fontkey,(num+1)*4,MEMF_CLEAR)) ||
  747.                     !(nopropsizelist=LAllocRemember(&fontkey,(num+1)*4,MEMF_CLEAR))) {
  748.                     noproplist=fontlist;
  749.                     nopropsizelist=fontsizelist;
  750.                 }
  751.                 if (!(only8list=LAllocRemember(&fontkey,(num+1)*4,MEMF_CLEAR)))
  752.                     only8list=fontlist;
  753.                 sortfontlist((struct AvailFonts *)&fontdatabuf[sizeof(UWORD)],num,0);
  754.                 sortfontlist((struct AvailFonts *)&fontdatabuf[sizeof(UWORD)],num,1);
  755.                 avail=(struct AvailFonts *)&fontdatabuf[sizeof(UWORD)];
  756.                 for (fnum=0;fnum<num;fnum++) {
  757.                     if (ptr=strstri(avail[fnum].af_Attr.ta_Name,".font")) *ptr=0;
  758.                     avail[fnum].af_Attr.ta_Style=0;
  759.                     for (a=0;a<num;a++) {
  760.                         if (strcmp((char *)avail[a].af_Attr.ta_Name,(char *)avail[fnum].af_Attr.ta_Name))
  761.                             ++avail[fnum].af_Attr.ta_Style;
  762.                     }
  763.                 }
  764.                 for (fnum=0,fontnum=0,nopropnum=0,only8num=0;fnum<num;fnum++) {
  765.                     for (a=0;a<fontnum;a++) {
  766.                         if (strcmp(fontlist[a],(char *)avail[fnum].af_Attr.ta_Name)==0) break;
  767.                     }
  768.                     if (a==fontnum) {
  769.                         fontlist[fontnum]=(char *)avail[fnum].af_Attr.ta_Name;
  770.                         fontsizelist[fontnum]=LAllocRemember(&fontkey,(avail[fnum].af_Attr.ta_Style+1)*4,MEMF_CLEAR);
  771.                         if (!(avail[fnum].af_Attr.ta_Flags&FPF_PROPORTIONAL)) {
  772.                             noproplist[nopropnum]=fontlist[fontnum];
  773.                             nopropsizelist[nopropnum]=fontsizelist[fontnum];
  774.                             ++nopropnum;
  775.                             if (avail[fnum].af_Attr.ta_YSize==8) {
  776.                                 only8list[only8num]=fontlist[fontnum];
  777.                                 ++only8num;
  778.                             }
  779.                         }
  780.                         ++fontnum;
  781.                     }
  782.                     if (fontsizelist[a]) {
  783.                         for (b=0;;b++) {
  784.                             if (!fontsizelist[a][b]) break;
  785.                             if (atoi(fontsizelist[a][b])==avail[fnum].af_Attr.ta_YSize) {
  786.                                 b=-1;
  787.                                 break;
  788.                             }
  789.                         }
  790.                         if (b>-1 && (fontsizelist[a][b]=LAllocRemember(&fontkey,8,MEMF_CLEAR)))
  791.                             lsprintf(fontsizelist[a][b],"%4ld",avail[fnum].af_Attr.ta_YSize);
  792.                     }
  793.                 }
  794.             }
  795.             setuplist(&fontplacelist,146,18);
  796.             setuplist(&fontlistview,360,18);
  797.             setuplist(&fontsizelistview,566,18);
  798.             fontplacelist.itemselected=fontplacelist.topitem=0;
  799.             fontsizelistview.items=fontlistview.items=NULL;
  800.             AddListView(&fontplacelist,3);
  801.             SetAPen(rp,screen_pens[1].pen);
  802.             UScoreText(rp,
  803.                 cfg_string[STR_DISPLAY_ITEM],
  804.                 x_off+146,y_off+14,
  805.                 -1);
  806.             UScoreText(rp,
  807.                 cfg_string[STR_FONT],
  808.                 x_off+360,y_off+14,
  809.                 -1);
  810.             UScoreText(rp,
  811.                 cfg_string[STR_FONT_SIZE],
  812.                 x_off+566,y_off+14,
  813.                 -1);
  814.             if (version2) {
  815.                 fontsize_buf[0]=0;
  816.                 AddGadgets(Window,
  817.                     &fontsizegadget,
  818.                     NULL,
  819.                     1,
  820.                     screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  821.             }
  822.             initfontlist(FONT_CLOCK,1,0);
  823.             strcpy(old_general_font,config->fontbufs[0]);
  824.             break;
  825.  
  826.         case SCREEN_GENERAL:
  827.             inittickgads(scr_generalgadgets,config->generalscreenflags,0);
  828.             break;
  829.  
  830.         case SCREEN_ARROWS:
  831.             for (a=0;a<3;a++) {
  832.                 arrowgadgets[a].GadgetRender=(APTR)buttonoffimage;
  833.                 arrowgadgets[a].SelectRender=(APTR)buttononimage;
  834.                 do3dbox(x_off+184+(a*129),y_off+33,121,55);
  835.             }
  836.  
  837.             AddGadgetBorders(&borderkey,
  838.                 &arrowgadgets[3],
  839.                 2,
  840.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  841.             AddGadgetBorders(&borderkey,
  842.                 &arrowgadgets[5],
  843.                 2,
  844.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  845.             AddGadgetBorders(&borderkey,
  846.                 &arrowgadgets[7],
  847.                 1,
  848.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  849.  
  850.             AddGadgets(Window,
  851.                 arrowgadgets,
  852.                 arrowgadtxt,
  853.                 8,
  854.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  855.             for (a=0;a<2;a++) {
  856.                 DoArrow(rp,x_off+420+(a*34),y_off+144,10,9,screen_pens[1].pen,screen_pens[0].pen,3-a);
  857.                 DoArrow(rp,x_off+436,y_off+138+(a*12),12,9,screen_pens[1].pen,screen_pens[0].pen,a);
  858.             }
  859.             showupdownslider();
  860.             showleftrightslider();
  861.             showstringgadget();
  862.             showarrowborders(0,-1);
  863.             fixarrowgads(0);
  864.             SetAPen(rp,screen_pens[1].pen);
  865.             UScoreText(rp,
  866.                 cfg_string[STR_MODIFY_SIZE],
  867.                 x_off+294,y_off+151,
  868.                 -1);
  869.             DoCycleGadget(&arrowgadgets[7],Window,arrowtypetxt,0);
  870.             break;
  871.  
  872.         case SCREEN_SLIDERS:
  873.             for (a=0;a<2;a++) {
  874.                 AddGadgetBorders(&borderkey,
  875.                     &screen_sliders_gadgets[a],
  876.                     2,
  877.                     screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  878.             }
  879.  
  880.             AddGadgets(Window,
  881.                 screen_sliders_gadgets,
  882.                 NULL,
  883.                 2,
  884.                 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
  885.  
  886.             for (a=0;a<2;a++) show_slider_setup(182+(a*191),32,a);
  887.             break;
  888.     }
  889. }
  890.  
  891. void removescreenedit(mode)
  892. int mode;
  893. {
  894.     SetAPen(rp,screen_pens[0].pen);
  895.     RectFill(rp,
  896.         x_off+120,y_off+4,
  897.         x_bot,y_bot);
  898.     SetAPen(rp,screen_pens[1].pen);
  899.     switch (mode) {
  900.         case SCREEN_PALETTE:
  901.             RemoveGList(Window,palettegads,6);
  902.             RemoveListView(&palettelist,1);
  903.             break;
  904.  
  905.         case SCREEN_COLOURS:
  906.             RemoveGList(Window,&coloursgad,1);
  907.             doradiobuttons();
  908.             break;
  909.  
  910.         case SCREEN_SCREENMODE:
  911.             RemoveListView(&screenmodeview,1);
  912.             RemoveGList(Window,screenmodegads,7);
  913.             LFreeRemember(&screenkey);
  914.             if (config->scrdepth!=screen_depth) {
  915.                 close_screen();
  916.                 open_screen();
  917.                 showconfigscreen(CFG_SCREEN);
  918.             }
  919.             break;
  920.  
  921.         case SCREEN_FONTS:
  922.             RemoveListView(&fontplacelist,3);
  923.             if (version2) RemoveGList(Window,&fontsizegadget,1);
  924.             if (LStrCmpI(config->fontbufs[0],old_general_font)!=0) {
  925.                 close_screen();
  926.                 open_screen();
  927.                 showconfigscreen(CFG_SCREEN);
  928.             }
  929.             break;
  930.  
  931.         case SCREEN_ARROWS:
  932.             RemoveGList(Window,arrowgadgets,8);
  933.             break;
  934.  
  935.         case SCREEN_GENERAL:
  936.             removetickgads();
  937.             break;
  938.  
  939.         case SCREEN_SLIDERS:
  940.             RemoveGList(Window,screen_sliders_gadgets,2);
  941.             break;
  942.     }
  943.     LFreeRemember(&borderkey);
  944. }
  945.