home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / BOOPSI / GI1 / Examples / Tabs_Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  5.2 KB  |  196 lines

  1. /*****************************************************************************
  2.  *
  3.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1992-1999
  4.  * Amiga, Inc. All rights reserved.
  5.  *
  6.  * DISCLAIMER: This software is provided "as is".  No representations or
  7.  * warranties are made with respect to the accuracy, reliability,
  8.  * performance, currentness, or operation of this software, and all use is at
  9.  * your own risk. Neither Amiga nor the authors assume any responsibility
  10.  * or liability whatsoever with respect to your use of this software.
  11.  *
  12.  *****************************************************************************
  13.  * tabs_test.c
  14.  * test program for the tabs.gadget
  15.  * Written by David N. Junod
  16.  *
  17.  */
  18.  
  19. #include <dos/dos.h>
  20. #include <exec/types.h>
  21. #include <exec/libraries.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/gadgetclass.h>
  24. #include <intuition/intuitionbase.h>
  25. #include <gadgets/tabs.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28.  
  29. #include <clib/macros.h>
  30. #include <clib/dos_protos.h>
  31. #include <clib/exec_protos.h>
  32. #include <clib/intuition_protos.h>
  33.  
  34. #include <pragmas/dos_pragmas.h>
  35. #include <pragmas/exec_pragmas.h>
  36. #include <pragmas/intuition_pragmas.h>
  37.  
  38. /*****************************************************************************/
  39.  
  40. #define    IDCMP_FLAGS    IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_GADGETUP \
  41.             | IDCMP_MOUSEMOVE | IDCMP_INTUITICKS | IDCMP_MOUSEBUTTONS
  42.  
  43. /*****************************************************************************/
  44.  
  45. struct ClassLibrary *openclass (STRPTR name, ULONG version);
  46.  
  47. /*****************************************************************************/
  48.  
  49. extern struct Library *SysBase, *DOSBase;
  50. struct Library *IntuitionBase;
  51.  
  52. /*****************************************************************************/
  53.  
  54. TabLabel labels[] =
  55. {
  56.     {"Display",        -1, -1, -1, -1},
  57.     {"Edit",        -1, -1, -1, -1},
  58.     {"File",        -1, -1, -1, -1},
  59.     NULL
  60. };
  61.  
  62. /*****************************************************************************/
  63.  
  64. struct TextAttr topaz8 = {"topaz.font", 8,};
  65.  
  66. /*****************************************************************************/
  67.  
  68. void main (int argc, char **argv)
  69. {
  70.     struct IntuiMessage *imsg;
  71.     struct ClassLibrary *gLib;
  72.     struct Screen *scr;
  73.     struct Window *win;
  74.     struct Gadget *gad;
  75.     struct Gadget *g;
  76.     BOOL going = TRUE;
  77.     ULONG sigr;
  78.  
  79.     if (IntuitionBase = OpenLibrary ("intuition.library", 37))
  80.     {
  81.     scr = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  82.  
  83.     if (gLib = openclass ("gadgets/tabs.gadget", 37))
  84.     {
  85.         if (win = OpenWindowTags (NULL,
  86.                       WA_Title,        "tabs.gadget Test",
  87.                       WA_InnerWidth,    320,
  88.                       WA_InnerHeight,    8 + 6 + 34,
  89.                       WA_IDCMP,        IDCMP_FLAGS,
  90.                       WA_DragBar,    TRUE,
  91.                       WA_DepthGadget,    TRUE,
  92.                       WA_CloseGadget,    TRUE,
  93.                       WA_SimpleRefresh,    TRUE,
  94.                       WA_NoCareRefresh,    TRUE,
  95.                       WA_Activate,    TRUE,
  96.                       WA_SizeGadget,    TRUE,
  97.                       WA_MinWidth,    300,
  98.                       WA_MinHeight,    scr->BarHeight + 1 + 34,
  99.                       WA_MaxWidth,    1024,
  100.                       WA_MaxHeight,    1024,
  101.                       WA_CustomScreen,    scr,
  102.                       TAG_DONE))
  103.         {
  104.         /* The height of the gadget should be the font height + 6 */
  105.         if (gad = NewObject (NULL, "tabs.gadget",
  106.                     GA_Top,        win->BorderTop + 2,
  107.                     GA_Left,    win->BorderLeft + 4,
  108.                     GA_Height,    8 + 6,
  109.                     GA_RelWidth,    -(win->BorderLeft + 8 + win->BorderRight),
  110.                     GA_TextAttr,    &topaz8,
  111.                     GA_RelVerify,    TRUE,
  112.                     GA_Immediate,    TRUE,
  113.                     TABS_Labels,    labels,
  114.                     TABS_Current,    0,
  115.                     TAG_DONE))
  116.         {
  117.             /* Add the gadget */
  118.             AddGList (win, gad, -1, 1, NULL);
  119.             RefreshGList (gad, win, NULL, -1);
  120.  
  121.             while (going)
  122.             {
  123.             sigr = Wait ((1L << win->UserPort->mp_SigBit | SIGBREAKF_CTRL_C));
  124.  
  125.             if (sigr & SIGBREAKF_CTRL_C)
  126.                 going = FALSE;
  127.  
  128.             while (imsg = (struct IntuiMessage *) GetMsg (win->UserPort))
  129.             {
  130.                 switch (imsg->Class)
  131.                 {
  132.                 case IDCMP_CLOSEWINDOW:
  133.                     going = FALSE;
  134.                     break;
  135.  
  136.                 case IDCMP_VANILLAKEY:
  137.                     switch (imsg->Code)
  138.                     {
  139.                     case  27:
  140.                     case 'q':
  141.                     case 'Q':
  142.                         going = FALSE;
  143.                         break;
  144.                     }
  145.                     break;
  146.  
  147.                 case IDCMP_GADGETUP:
  148.                     g = (struct Gadget *) imsg->IAddress;
  149.                     Printf ("id=%ld code=%04lx\n", (ULONG)g->GadgetID, (ULONG)imsg->Code);
  150.                     break;
  151.                 }
  152.  
  153.                 ReplyMsg ((struct Message *) imsg);
  154.             }
  155.             }
  156.  
  157.             /* Delete the gadget */
  158.             RemoveGList (win, gad, 1);
  159.             DisposeObject (gad);
  160.         }
  161.  
  162.         CloseWindow (win);
  163.         }
  164.         else
  165.         Printf ("couldn't open the window\n");
  166.  
  167.         CloseLibrary ((struct Library *) gLib);
  168.     }
  169.     else
  170.         Printf ("couldn't open classes:gadgets/tabs.gadget\n");
  171.  
  172.     CloseLibrary (IntuitionBase);
  173.     }
  174. }
  175.  
  176. /*****************************************************************************/
  177.  
  178. /* Try opening the class library from a number of common places */
  179. struct ClassLibrary *openclass (STRPTR name, ULONG version)
  180. {
  181.     struct ExecBase *SysBase = (*((struct ExecBase **) 4));
  182.     struct Library *retval;
  183.     UBYTE buffer[256];
  184.  
  185.     if ((retval = OpenLibrary (name, version)) == NULL)
  186.     {
  187.     sprintf (buffer, ":classes/%s", name);
  188.     if ((retval = OpenLibrary (buffer, version)) == NULL)
  189.     {
  190.         sprintf (buffer, "classes/%s", name);
  191.         retval = OpenLibrary (buffer, version);
  192.     }
  193.     }
  194.     return (struct ClassLibrary *) retval;
  195. }
  196.