home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / hooks / gedsample2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  13.5 KB  |  393 lines

  1. /*
  2.  * Sample2
  3.  *
  4.  * Sample of the new List_ID gadget type.
  5.  *
  6.  * Written by Thomas Krehbiel, 20-Apr-94
  7.  *
  8.  */
  9.  
  10. #include <scan/hooks.h>
  11. #include <clib/dos_protos.h>
  12. #include <clib/alib_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <string.h>
  17.  
  18.  
  19. /* This information is required by the "start.o" startup code. */
  20. char *HookName = "GedSample2";
  21.  
  22. /* A version string so the Version command works on us. */
  23. char *HookVersion = "\0$VER: GedSample2 2.0.2 (15.2.95)";
  24.  
  25.  
  26. /*******************************************************************
  27.  *
  28.  *  Defines
  29.  *
  30.  *******************************************************************/
  31.  
  32. #define WINDOW_WIDTH    (300)
  33. #define WINDOW_HEIGHT   (100)
  34.  
  35.  
  36. /*******************************************************************
  37.  *
  38.  *  Text Array and Indexes
  39.  *
  40.  *******************************************************************/
  41.  
  42. #include "gedsample2_strings.h"
  43.  
  44. #if 0
  45.  
  46. char *DefaultStrings[] = {
  47.    "Dummy",
  48.  
  49.    "GED Listview Sample Window",
  50.    "_Okay",
  51.    "_Cancel",
  52. };
  53.  
  54. enum {
  55.    G_Dummy = 0,
  56.    G_Title,       /* gadget labels must start from 1! */
  57.    G_Okay,
  58.    G_Cancel,
  59.    TXT_COUNT
  60. };
  61.  
  62. /* This information is required by the "start.o" startup code. */
  63. char *HookText = "Hook_GedSample";
  64. int   HookTextCount = TXT_COUNT;
  65.  
  66. #endif
  67.  
  68. /*******************************************************************
  69.  *
  70.  *  These are filled in by the ImageFX Ged system
  71.  *
  72.  *******************************************************************/
  73.  
  74. LONG OutsideArea[4];             /* will contain border size,
  75.                                     [0] = leftedge,
  76.                                     [1] = topedge,
  77.                                     [2] = width,
  78.                                     [3] = height */
  79.  
  80. LONG InsideArea[4];              /* will contain border size,
  81.                                     [0] = leftedge,
  82.                                     [1] = topedge,
  83.                                     [2] = width,
  84.                                     [3] = height */
  85.  
  86. LONG ListValue;                  /* current listview active element */
  87.  
  88. /*******************************************************************
  89.  *
  90.  *  Gadget ID's
  91.  *
  92.  *******************************************************************/
  93.  
  94. enum {
  95.    ID_Okay = 300,                /* start high to avoid conflicts */
  96.    ID_Cancel,                    /*    with ImageFX gadgets */
  97.    ID_Listview,
  98. };
  99.  
  100. /*******************************************************************
  101.  *
  102.  *  Gadget callbacks - these are called when the gadget associated
  103.  *  with the callback is "fiddled" with.
  104.  *
  105.  *  Be sure to use __saveds for all callbacks!
  106.  *
  107.  *  Any callback that returns non-zero will cause GedWin() to
  108.  *  return immediately.
  109.  *
  110.  *******************************************************************/
  111.  
  112. int __saveds ListCode (GedListProto)
  113. {
  114.    /*
  115.     * This callback is for the listview gadget.  When the user
  116.     * selects an entry, we are called.
  117.     */
  118.  
  119.    NewList((struct List *)lv->List);
  120.    lv->Count = 0;
  121.    Ged_Set(w, ID_Listview, NULL);
  122.  
  123. // DisplayBeep(NULL);         /* nothing special for this demo,
  124. //                               but we could activate a string
  125. //                               gadget or something */
  126.  
  127.    return(0);
  128. }
  129.  
  130. /*******************************************************************
  131.  *
  132.  *  NewGad array - defines elements of our interface
  133.  *
  134.  *******************************************************************/
  135.  
  136. struct NewGad newGads[] = {
  137.  
  138.    { Scale_ID },                 /* voodoo magic */
  139.  
  140.    /* okay gadget */
  141.    { Button_ID,                  /* style */
  142.          ID_Okay,                /* gadget id */
  143.          8,                      /* left */
  144.          WINDOW_HEIGHT - 16,     /* top */
  145.          100,                    /* width */
  146.          12,                     /* height - 12's a good height for buttons */
  147.          G_Okay,                 /* label - index into text array */
  148.          NULL,                   /* code - none needed */
  149.          0,                      /* userdata - none needed */
  150.          NULL,                   /* pointer - not used */
  151.          ID_Okay,                /* data1 - exit GedWin with this return code
  152.                                        when user clicks this gadget */
  153.          0,                      /* data2 - unused */
  154.          0,                      /* data3 - unused */
  155.          0,                      /* data4 - unused */
  156.          0,                      /* data5 - unused */
  157.          0,                      /* data6 - unused */
  158.          0,                      /* data7 - unused */
  159.          0                       /* data8 - unused */
  160.    },
  161.  
  162.    /* cancel gadget */
  163.    { Button_ID,                  /* style */
  164.          ID_Cancel,              /* gadget id */
  165.          WINDOW_WIDTH - 108,     /* left */
  166.          WINDOW_HEIGHT - 16,     /* top */
  167.          100,                    /* width */
  168.          12,                     /* height - 12's a good height for buttons */
  169.          G_Cancel,               /* label - index into text array */
  170.          NULL,                   /* code - none needed */
  171.          0,                      /* userdata - none needed */
  172.          NULL,                   /* pointer - not used */
  173.          ID_Cancel,              /* data1 - exit GedWin with this return code
  174.                                        when user clicks this gadget */
  175.          0,                      /* data2 - unused */
  176.          0,                      /* data3 - unused */
  177.          0,                      /* data4 - unused */
  178.          0,                      /* data5 - unused */
  179.          0,                      /* data6 - unused */
  180.          0,                      /* data7 - unused */
  181.          0                       /* data8 - unused */
  182.    },
  183.  
  184.    /* listview gadget */
  185.    { List_ID,                    /* style */
  186.          ID_Listview,            /* gadget id */
  187.          20,                     /* left */
  188.          20,                     /* top */
  189.          WINDOW_WIDTH-40,        /* width */
  190.          WINDOW_HEIGHT-40,       /* height */
  191.          0,                      /* label - listviews don't have labels */
  192.          ListCode,               /* code - callback function */
  193.          0,                      /* userdata - none needed */
  194.          &ListValue,             /* pointer - where to store current value */
  195.          0,                      /* data1 - EListView (filled later) */
  196.          ID_Okay,                /* data2 - double-click return value */
  197.          0,                      /* data3 - unused */
  198.          0,                      /* data4 - unused */
  199.          0,                      /* data5 - unused */
  200.          0,                      /* data6 - unused */
  201.          0,                      /* data7 - unused */
  202.          0                       /* data8 - unused */
  203.    },
  204.  
  205.    /* window title */
  206.    { Text_ID,                    /* style */
  207.          0,                      /* id - none needed */
  208.          WINDOW_WIDTH/2,         /* left */
  209.          4,                      /* top */
  210.          0,                      /* width - unneeded */
  211.          0,                      /* height - unneeded */
  212.          G_Title,                /* label - index into text array */
  213.          NULL,                   /* code - none needed */
  214.          0,                      /* userdata - none needed */
  215.          NULL,                   /* pointer - unused */
  216.          2,                      /* data1 - drawing pen (2=white) */
  217.          0,                      /* data2 - unused */
  218.          2,                      /* data3 - justification
  219.                                        (0=left, 1=right, 2=center) */
  220.          0,                      /* data4 - unused */
  221.          0,                      /* data5 - unused */
  222.          0,                      /* data6 - unused */
  223.          0,                      /* data7 - unused */
  224.          0                       /* data8 - unused */
  225.    },
  226.  
  227.    /* window border */
  228.    { Border_ID,                  /* style */
  229.          0,                      /* id - none needed */
  230.          0,                      /* left */
  231.          0,                      /* top */
  232.          WINDOW_WIDTH,           /* width */
  233.          WINDOW_HEIGHT,          /* height */
  234.          0,                      /* label - none needed */
  235.          NULL,                   /* code - none needed */
  236.          0,                      /* userdata - none needed */
  237.          OutsideArea,            /* pointer - (optional) - fill in actual
  238.                                     size of the border when created;
  239.                                     useful for drawing stuff inside
  240.                                     the border so we know where the
  241.                                     actual border coords are.  Use NULL
  242.                                     if you don't need this.  This is just
  243.                                     here as an example. */
  244.          FALSE,                  /* data1 - recessed border? */
  245.          TRUE,                   /* data2 - double thick? */
  246.          0,                      /* data3 - unused */
  247.          0,                      /* data4 - unused */
  248.          0,                      /* data5 - unused */
  249.          0,                      /* data6 - unused */
  250.          0,                      /* data7 - unused */
  251.          0                       /* data8 - unused */
  252.    },
  253.  
  254.    /* inside border */
  255.    { Border_ID,                  /* style */
  256.          0,                      /* id - none needed */
  257.          8,                      /* left */
  258.          14,                     /* top */
  259.          WINDOW_WIDTH-16,        /* width */
  260.          WINDOW_HEIGHT-14-18,    /* height */
  261.          0,                      /* label - none needed */
  262.          NULL,                   /* code - none needed */
  263.          0,                      /* userdata - none needed */
  264.          InsideArea,             /* pointer - (optional) - fill in actual
  265.                                     size of the border when created;
  266.                                     useful for drawing stuff inside
  267.                                     the border so we know where the
  268.                                     actual border coords are.  Use NULL
  269.                                     if you don't need this.  This is just
  270.                                     here as an example. */
  271.          TRUE,                   /* data1 - recessed border? */
  272.          FALSE,                  /* data2 - double thick? */
  273.          0,                      /* data3 - unused */
  274.          0,                      /* data4 - unused */
  275.          0,                      /* data5 - unused */
  276.          0,                      /* data6 - unused */
  277.          0,                      /* data7 - unused */
  278.          0                       /* data8 - unused */
  279.    },
  280.  
  281.    { End_ID }                    /* must end with End_ID! */
  282. };
  283.  
  284. /*******************************************************************
  285.  *
  286.  *  NewWindow - defines the window (flags and such)
  287.  *
  288.  *******************************************************************/
  289.  
  290. struct NewWindow newWindow = {
  291.  
  292.    0, 0,                         /* left, top */
  293.    WINDOW_WIDTH, WINDOW_HEIGHT,  /* width, height */
  294.     0, 1,                         /* 1.3 stuff... :) */
  295.     IDCMP_GADGETUP,               /* IDCMP flags (must set correctly!) */
  296.     WFLG_BORDERLESS |             /* Window flags */
  297.        WFLG_SMART_REFRESH |
  298.        WFLG_NOCAREREFRESH |
  299.        WFLG_RMBTRAP |
  300.        WFLG_ACTIVATE,
  301.     NULL,                         /* Firstgadget - unused */
  302.     NULL,
  303.     NULL,
  304.     NULL,                         /* Screen - set by ImageFX in PrepareNW */
  305.     NULL,
  306.     0,0,0,0,                      /* Min/max size */
  307.     WBENCHSCREEN                  /* Type - set by ImageFX in PrepareNW */
  308.  
  309. };
  310.  
  311.  
  312. /*******************************************************************
  313.  *
  314.  *  Hook entry point is here.
  315.  *
  316.  *******************************************************************/
  317.  
  318. void hook_main (int argc, char **argv)
  319. {
  320.    int returncode;
  321.    struct EListView lv;
  322.    struct List list;
  323.    int i;
  324.    struct Node node[16];
  325.    char *elem_label[] = {
  326.       "Element #0",
  327.       "Element #1",
  328.       "Element #2",
  329.       "Element #3",
  330.       "Element #4",
  331.       "Element #5",
  332.       "Element #6",
  333.       "Element #7",
  334.       "Element #8",
  335.       "Element #9",
  336.       "Element #10",
  337.       "Element #11",
  338.       "Element #12",
  339.       "Element #13",
  340.       "Element #14",
  341.       "Element #15"
  342.    };
  343.  
  344.    /*
  345.     * Listviews are only in ImageFX 2.0 and above.
  346.     */
  347.    if (ScanBase->Library.lib_Version < 107) {
  348.       hook_fail("This hook requires ImageFX 2.0");
  349.    }
  350.  
  351.    /* make a list of stuff */
  352.    NewList(&list);
  353.  
  354.    for (i = 0; i < 16; i++) {
  355.       node[i].ln_Name = elem_label[i];
  356.       AddTail(&list, &node[i]);
  357.    }
  358.  
  359.    memset(&lv, 0, sizeof(struct EListView));
  360.    lv.List = &list;
  361.    lv.Flags = 0; // ELVF_SHOWSELECTED;
  362.    lv.Count = 16;
  363.    lv.Spacing = pWindow->RPort->TxHeight;
  364.    lv.Active = -1;
  365.  
  366.    newGads[3].Data1 = (long)&lv;
  367.  
  368.    /*
  369.     * PrepareNW() fills in the NewWindow structure with appropriate
  370.     * values to open on the ImageFX screen (or on Workbench).
  371.     */
  372.    PrepareNW(&newWindow,
  373.       WINDOW_WIDTH, WINDOW_HEIGHT, TRUE);
  374.  
  375.    /*
  376.     * GedWin() opens the window, processes events, and returns when
  377.     * the window is closed.
  378.     */
  379.    returncode = GedWin(&newWindow,  /* newwindow */
  380.                   newGads,          /* newgad array */
  381.                   0,                /* id of first string gad to activate */
  382.                   NULL,             /* init function callback */
  383.                   NULL,             /* cleanup function callback */
  384.                   HookTextArray);   /* text array */
  385.  
  386.    if (returncode == ID_Okay) {
  387.       InfoRequest("You selected element %ld!", ListValue);
  388.    }
  389.    else if (returncode == ID_Cancel) {
  390.       Errorf("You cancelled, ya bum!");
  391.    }
  392. }
  393.