home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0922.lha / DesignerDemo / ToggleDemo / ToggleDemo.c < prev    next >
C/C++ Source or Header  |  1993-10-07  |  3KB  |  112 lines

  1. /* Simple demo using a Designer created file */
  2. /* Only run from CLI */
  3.  
  4. #include <toggledemowin.c>
  5.  
  6. ULONG MyTags[] =
  7. {
  8.     GTTX_Text,0,
  9.     TAG_DONE
  10. };
  11.  
  12. void main(void)
  13. {
  14. int done=0;
  15. ULONG class;
  16. UWORD code;
  17. struct Gadget *pgsel;
  18. struct IntuiMessage *imsg;
  19. UWORD GadNumber;
  20. if (OpenLibs()==0)
  21.     {
  22.     if (MakeImages()==0)
  23.         {
  24.         if (OpenWindowMainWindow()==0)
  25.             {
  26.             while (done==0)
  27.                 {
  28.                 Wait(1L << MainWindow->UserPort->mp_SigBit);
  29.                 imsg=GT_GetIMsg(MainWindow->UserPort);
  30.                 while (imsg != NULL )
  31.                     {
  32.                     class=imsg->Class;
  33.                     code=imsg->Code;
  34.                     pgsel=(struct Gadget *)imsg->IAddress; /* Only reference if it is a gadget message */
  35.                     GT_ReplyIMsg(imsg);
  36.                     GadNumber=99;
  37.                     switch (class)
  38.                         {
  39.                         case IDCMP_CLOSEWINDOW :
  40.                             done=1;
  41.                             break;
  42.                         case IDCMP_GADGETDOWN :
  43.                             GadNumber=pgsel->GadgetID;
  44.                             break;
  45.                         case IDCMP_VANILLAKEY :
  46.                             switch (code)
  47.                                 {
  48.                                 case 'F' :
  49.                                     GadNumber = FirstGadget;
  50.                                     break;
  51.                                 case 'S' :
  52.                                     GadNumber = SecondGadget;
  53.                                     break;
  54.                                 case 'T' :
  55.                                     GadNumber = ThirdGadget;
  56.                                     break;
  57.                                 }
  58.                             break;
  59.                         }
  60.                     switch (GadNumber)
  61.                         {
  62.                         case FirstGadget :
  63.                             /* Remove gadgets from window */
  64.                             RemoveGList(MainWindow,MainWindowGList,~0);
  65.                             /* Change Gadget Flags */
  66.                             MainWindowGadgets[FirstGadget ]->Flags |=  GFLG_SELECTED;
  67.                              MainWindowGadgets[SecondGadget]->Flags &= ~GFLG_SELECTED;
  68.                             MainWindowGadgets[ThirdGadget ]->Flags &= ~GFLG_SELECTED;
  69.                             /* Put Gadgets Back in window */
  70.                             AddGList(MainWindow,MainWindowGList,50,~0,NULL);
  71.                             /* Refresh Gadgets */
  72.                             RefreshGList(MainWindowGList,MainWindow,NULL,~0);
  73.                             MyTags[1] = "First Option";
  74.                             GT_SetGadgetAttrsA(MainWindowGadgets[DisplayGadget],MainWindow, NULL, MyTags);
  75.                             break;
  76.                         case SecondGadget :
  77.                             RemoveGList(MainWindow,MainWindowGList,~0);
  78.                             MainWindowGadgets[FirstGadget ]->Flags &= ~GFLG_SELECTED;
  79.                              MainWindowGadgets[SecondGadget]->Flags |=  GFLG_SELECTED;
  80.                             MainWindowGadgets[ThirdGadget ]->Flags &= ~GFLG_SELECTED;
  81.                             AddGList(MainWindow,MainWindowGList,0,~0,NULL);
  82.                             RefreshGList(MainWindowGList,MainWindow,NULL,~0);
  83.                             MyTags[1] = "Second Option";
  84.                             GT_SetGadgetAttrsA(MainWindowGadgets[DisplayGadget],MainWindow, NULL, MyTags);
  85.                             break;
  86.                         case ThirdGadget :
  87.                             RemoveGList(MainWindow,MainWindowGList,~0);
  88.                             MainWindowGadgets[FirstGadget ]->Flags &= ~GFLG_SELECTED;
  89.                              MainWindowGadgets[SecondGadget]->Flags &= ~GFLG_SELECTED;
  90.                             MainWindowGadgets[ThirdGadget ]->Flags |=  GFLG_SELECTED;
  91.                             AddGList(MainWindow,MainWindowGList,50,~0,NULL);
  92.                             RefreshGList(MainWindowGList,MainWindow,NULL,~0);
  93.                             MyTags[1] = "Third Option";
  94.                             GT_SetGadgetAttrsA(MainWindowGadgets[DisplayGadget],MainWindow, NULL, MyTags);
  95.                             break;
  96.                         }
  97.                     imsg=GT_GetIMsg(MainWindow->UserPort);
  98.                     }
  99.                 }
  100.             CloseWindowMainWindow();
  101.             }
  102.         else
  103.             printf("Cannot open window.\n");
  104.         FreeImages();
  105.         }
  106.     else
  107.         printf("Cannot make images.\n");
  108.     }
  109. else
  110.     printf("Cannot open libraries.\n");
  111. }
  112.