home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / protectdata.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  9KB  |  387 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 "DOpus.h"
  32.  
  33. enum {
  34.     PROTECT_SET_ALL=10,
  35.     PROTECT_SET_NONE,
  36.     PROTECT_SET_TOGGLE,
  37.     PROTECT_SET_REVERT,
  38.     PROTECT_OKAY,
  39.     PROTECT_ALL,
  40.     PROTECT_CANCEL};
  41.  
  42. struct RequesterBase protect_req={
  43.     42,9,92,64,
  44.     8,8,
  45.     0,0,0,0,NULL,NULL,NULL,NULL,
  46.     NULL,NULL,NULL,
  47.     0,0,NULL,IDCMP_GADGETUP|IDCMP_VANILLAKEY|IDCMP_MOUSEBUTTONS,NULL};
  48.  
  49. struct TagItem
  50.     protect_bit_template[]={
  51.         {RO_Type,OBJECT_GADGET},
  52.         {RO_GadgetType,GADGET_CHECK},
  53.         {RO_GadgetID,0},
  54.         {RO_Top,0},
  55.         {RO_TopFine,0},
  56.         {RO_TextNum,0},
  57.         {RO_TextPos,TEXTPOS_RIGHT},
  58.         {RO_ChkCenter,TRUE},
  59.         {TAG_END,0}},
  60.  
  61.     protect_bits[8][9],
  62.  
  63.     protect_set_all[]={
  64.         {RO_Type,OBJECT_GADGET},
  65.         {RO_GadgetType,GADGET_BOOLEAN},
  66.         {RO_GadgetID,PROTECT_SET_ALL},
  67.         {RO_Left,14},
  68.         {RO_LeftFine,50},
  69.         {RO_TopFine,18},
  70.         {RO_Width,10},
  71.         {RO_Height,1},
  72.         {RO_HeightFine,4},
  73.         {RO_TextNum,STR_PROTECT_ALL_BITS},
  74.         {RO_TextPos,TEXTPOS_CENTER},
  75.         {RO_HighRecess,TRUE},
  76.         {TAG_END,0}},
  77.     protect_set_none[]={
  78.         {RO_Type,OBJECT_GADGET},
  79.         {RO_GadgetType,GADGET_BOOLEAN},
  80.         {RO_GadgetID,PROTECT_SET_NONE},
  81.         {RO_Left,14},
  82.         {RO_LeftFine,50},
  83.         {RO_Top,2},
  84.         {RO_TopFine,18},
  85.         {RO_Width,10},
  86.         {RO_Height,1},
  87.         {RO_HeightFine,4},
  88.         {RO_TextNum,STR_PROTECT_NONE},
  89.         {RO_TextPos,TEXTPOS_CENTER},
  90.         {RO_HighRecess,TRUE},
  91.         {TAG_END,0}},
  92.     protect_set_toggle[]={
  93.         {RO_Type,OBJECT_GADGET},
  94.         {RO_GadgetType,GADGET_BOOLEAN},
  95.         {RO_GadgetID,PROTECT_SET_TOGGLE},
  96.         {RO_Left,14},
  97.         {RO_LeftFine,50},
  98.         {RO_Top,4},
  99.         {RO_TopFine,18},
  100.         {RO_Width,10},
  101.         {RO_Height,1},
  102.         {RO_HeightFine,4},
  103.         {RO_TextNum,STR_PROTECT_TOGGLE},
  104.         {RO_TextPos,TEXTPOS_CENTER},
  105.         {RO_HighRecess,TRUE},
  106.         {TAG_END,0}},
  107.     protect_set_revert[]={
  108.         {RO_Type,OBJECT_GADGET},
  109.         {RO_GadgetType,GADGET_BOOLEAN},
  110.         {RO_GadgetID,PROTECT_SET_REVERT},
  111.         {RO_Left,14},
  112.         {RO_LeftFine,50},
  113.         {RO_Top,6},
  114.         {RO_TopFine,18},
  115.         {RO_Width,10},
  116.         {RO_Height,1},
  117.         {RO_HeightFine,4},
  118.         {RO_TextNum,STR_PROTECT_REVERT},
  119.         {RO_TextPos,TEXTPOS_CENTER},
  120.         {RO_HighRecess,TRUE},
  121.         {TAG_END,0}},
  122.  
  123.     protect_old_text[]={
  124.         {RO_Type,OBJECT_BORDER},
  125.         {RO_BorderType,BORDER_NONE},
  126.         {RO_Left,33},
  127.         {RO_LeftFine,80},
  128.         {RO_Top,1},
  129.         {RO_TopFine,18},
  130.         {RO_Width,8},
  131.         {RO_Height,1},
  132.         {RO_TextNum,STR_PROTECT_OLD},
  133.         {RO_TextPos,TEXTPOS_LEFT},
  134.         {TAG_END,0}},
  135.     protect_new_text[]={
  136.         {RO_Type,OBJECT_BORDER},
  137.         {RO_BorderType,BORDER_NONE},
  138.         {RO_Left,33},
  139.         {RO_LeftFine,80},
  140.         {RO_Top,3},
  141.         {RO_TopFine,18},
  142.         {RO_Width,8},
  143.         {RO_Height,1},
  144.         {RO_TextNum,STR_PROTECT_NEW},
  145.         {RO_TextPos,TEXTPOS_LEFT},
  146.         {TAG_END,0}},
  147.     protect_mask_text[]={
  148.         {RO_Type,OBJECT_BORDER},
  149.         {RO_BorderType,BORDER_NONE},
  150.         {RO_Left,33},
  151.         {RO_LeftFine,80},
  152.         {RO_Top,5},
  153.         {RO_TopFine,18},
  154.         {RO_Width,8},
  155.         {RO_Height,1},
  156.         {RO_TextNum,STR_PROTECT_MASK},
  157.         {RO_TextPos,TEXTPOS_LEFT},
  158.         {TAG_END,0}},
  159.  
  160.     protect_okay_gadget[]={
  161.         {RO_Type,OBJECT_GADGET},
  162.         {RO_GadgetType,GADGET_BOOLEAN},
  163.         {RO_GadgetID,PROTECT_OKAY},
  164.         {RO_Top,8},
  165.         {RO_TopFine,45},
  166.         {RO_Width,12},
  167.         {RO_Height,1},
  168.         {RO_HeightFine,4},
  169.         {RO_TextNum,STR_OKAY},
  170.         {RO_TextPos,TEXTPOS_CENTER},
  171.         {RO_HighRecess,TRUE},
  172.         {TAG_END,0}},
  173.     protect_all_gadget[]={
  174.         {RO_Type,OBJECT_GADGET},
  175.         {RO_GadgetType,GADGET_BOOLEAN},
  176.         {RO_GadgetID,PROTECT_ALL},
  177.         {RO_Left,15},
  178.         {RO_LeftFine,36},
  179.         {RO_Top,8},
  180.         {RO_TopFine,45},
  181.         {RO_Width,12},
  182.         {RO_Height,1},
  183.         {RO_HeightFine,4},
  184.         {RO_TextNum,STR_ALL},
  185.         {RO_TextPos,TEXTPOS_CENTER},
  186.         {RO_HighRecess,TRUE},
  187.         {TAG_END,0}},
  188.     protect_cancel_gadget[]={
  189.         {RO_Type,OBJECT_GADGET},
  190.         {RO_GadgetType,GADGET_BOOLEAN},
  191.         {RO_GadgetID,PROTECT_CANCEL},
  192.         {RO_Left,31},
  193.         {RO_LeftFine,67},
  194.         {RO_Top,8},
  195.         {RO_TopFine,45},
  196.         {RO_Width,12},
  197.         {RO_Height,1},
  198.         {RO_HeightFine,4},
  199.         {RO_TextNum,STR_CANCEL},
  200.         {RO_TextPos,TEXTPOS_CENTER},
  201.         {RO_HighRecess,TRUE},
  202.         {TAG_END,0}};
  203.  
  204. struct TagItem
  205.     *protect_gadgets[]={
  206.         protect_bits[0],
  207.         protect_bits[1],
  208.         protect_bits[2],
  209.         protect_bits[3],
  210.         protect_bits[4],
  211.         protect_bits[5],
  212.         protect_bits[6],
  213.         protect_bits[7],
  214.         protect_set_all,
  215.         protect_set_none,
  216.         protect_set_toggle,
  217.         protect_set_revert,
  218.         protect_okay_gadget,
  219.         protect_all_gadget,
  220.         protect_cancel_gadget,
  221.         NULL};
  222.  
  223. char prot_template[9];
  224.  
  225. getprotectdata(prot,mask)
  226. int *prot,*mask;
  227. {
  228.     ULONG class;
  229.     USHORT gadgetid,code;
  230.     int oldprot,a,x,y;
  231.     struct Gadget *gadlist;
  232.     Object_Border *old_text,*new_text,*mask_text;
  233.     struct Window *pwindow;
  234.  
  235.     for (a=0;a<8;a++) prot_template[a]=globstring[STR_PROTBIT_ALLBITS][7-a];
  236.     prot_template[8]=0;
  237.  
  238.     fix_requester(&protect_req,globstring[STR_SELECT_PROTECTION_BITS]);
  239.  
  240.     for (a=0;a<8;a++) {
  241.         CopyMem((char *)protect_bit_template,
  242.             (char *)protect_bits[a],
  243.             sizeof(protect_bit_template));    
  244.  
  245.         protect_bits[a][2].ti_Data=7-a;
  246.         protect_bits[a][3].ti_Data=a;
  247.         protect_bits[a][4].ti_Data=a*5;
  248.         protect_bits[a][5].ti_Data=STR_PROTECT_HIDDEN+a;
  249.     }
  250.  
  251.     if (!(pwindow=OpenRequester(&protect_req)) ||
  252.         !(gadlist=addreqgadgets(&protect_req,protect_gadgets,0,NULL)) ||
  253.         !(old_text=AddRequesterObject(&protect_req,protect_old_text)) ||
  254.         !(new_text=AddRequesterObject(&protect_req,protect_new_text)) ||
  255.         !(mask_text=AddRequesterObject(&protect_req,protect_mask_text))) {
  256.         CloseRequester(&protect_req);
  257.         return(0);
  258.     }
  259.     RefreshRequesterObject(&protect_req,NULL);
  260.  
  261.     do_prot_display(*prot,old_text,NULL);
  262.     do_prot_display(*prot,new_text,gadlist);
  263.     do_prot_display((*mask)^15,mask_text,NULL);
  264.     oldprot=*prot;
  265.  
  266.     FOREVER {
  267.         while (IMsg=(struct IntuiMessage *)GetMsg(pwindow->UserPort)) {
  268.             class=IMsg->Class; code=IMsg->Code;
  269.             x=IMsg->MouseX; y=IMsg->MouseY;
  270.             if (class==IDCMP_GADGETUP)
  271.                 gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
  272.             ReplyMsg((struct Message *) IMsg);
  273.  
  274.             switch (class) {
  275.                 case IDCMP_MOUSEBUTTONS:
  276.                     if (code==SELECTDOWN &&
  277.                         x>=mask_text->ob_left && x<(mask_text->ob_left+mask_text->ob_width) &&
  278.                         y>=mask_text->ob_top && y<(mask_text->ob_top+mask_text->ob_height)) {
  279.                         a=7-((x-mask_text->ob_left)/protect_req.rb_font->tf_XSize);
  280.                         *mask^=(1<<a);
  281.                         do_prot_display((*mask)^15,mask_text,NULL);
  282.                     }
  283.                     break;
  284.  
  285.                 case IDCMP_VANILLAKEY:
  286.                     for (a=0;a<8;a++) {
  287.                         if (tolower(code)==prot_template[a]) {
  288.                             if (isupper(code)) {
  289.                                 *mask^=(1<<a);
  290.                                 do_prot_display((*mask)^15,mask_text,NULL);
  291.                             }
  292.                             else {
  293.                                 *prot^=(1<<a);
  294.                                 do_prot_display(*prot,new_text,gadlist);
  295.                             }
  296.                             break;
  297.                         }
  298.                     }
  299.                     gadgetid=0;
  300.                     switch (code) {
  301.                         case '\r':
  302.                             gadgetid=PROTECT_OKAY;
  303.                             break;
  304.                         case 0x1b:
  305.                             gadgetid=PROTECT_CANCEL;
  306.                             break;
  307.                         case 'l':
  308.                             gadgetid=PROTECT_ALL;
  309.                             break;
  310.                     }
  311.                     if (!gadgetid) break;
  312.                     hilite_req_gadget(pwindow,gadgetid);
  313.  
  314.                 case IDCMP_GADGETUP:
  315.                     if (gadgetid<8) {
  316.                         *prot^=(1<<gadgetid);
  317.                         do_prot_display(*prot,new_text,NULL);
  318.                         break;
  319.                     }
  320.                     switch (gadgetid) {
  321.                         case PROTECT_SET_ALL:
  322.                             *prot=240;
  323.                             do_prot_display(*prot,new_text,gadlist);
  324.                             break;
  325.                         case PROTECT_SET_NONE:
  326.                             *prot=15;
  327.                             do_prot_display(*prot,new_text,gadlist);
  328.                             break;
  329.                         case PROTECT_SET_TOGGLE:
  330.                             *prot=(~*prot)&255;
  331.                             do_prot_display(*prot,new_text,gadlist);
  332.                             break;
  333.                         case PROTECT_SET_REVERT:
  334.                             *prot=oldprot;
  335.                             do_prot_display(*prot,new_text,gadlist);
  336.                             break;
  337.  
  338.                         case PROTECT_OKAY:
  339.                         case PROTECT_ALL:
  340.                         case PROTECT_CANCEL:
  341.                             CloseRequester(&protect_req);
  342.                             return((gadgetid==PROTECT_CANCEL)?0:
  343.                                 ((gadgetid==PROTECT_ALL)?2:1));
  344.                     }
  345.                     break;
  346.             }
  347.         }
  348.         Wait(1<<pwindow->UserPort->mp_SigBit);
  349.     }
  350. }
  351.  
  352. void do_prot_display(bits,border,gadgets)
  353. int bits;
  354. Object_Border *border;
  355. struct Gadget *gadgets;
  356. {
  357.     char bitbuf[10];
  358.     int gadnum;
  359.     struct Gadget *gad;
  360.  
  361.     getprot(bits,bitbuf);
  362.  
  363.     ObjectText(&protect_req,
  364.         border->ob_left,
  365.         border->ob_top,
  366.         border->ob_width,
  367.         border->ob_height,
  368.         bitbuf,
  369.         TEXTPOS_CENTER);
  370.  
  371.     if (gadgets) {
  372.         gad=gadgets;
  373.         for (gadnum=0;gadnum<8 && gad;gadnum++) {
  374.             if (bits&(1<<gad->GadgetID)) {
  375.                 if (gadnum<4) gad->Flags|=GFLG_SELECTED;
  376.                 else gad->Flags&=~GFLG_SELECTED;
  377.             }
  378.             else {
  379.                 if (gadnum<4) gad->Flags&=~GFLG_SELECTED;
  380.                 else gad->Flags|=GFLG_SELECTED;
  381.             }
  382.             gad=gad->NextGadget;
  383.         }
  384.         RefreshGList(gadgets,protect_req.rb_window,NULL,8);
  385.     }
  386. }
  387.