home *** CD-ROM | disk | FTP | other *** search
- /*
- * Sample2
- *
- * Sample of the new List_ID gadget type.
- *
- * Written by Thomas Krehbiel, 20-Apr-94
- *
- */
-
- #include <scan/hooks.h>
- #include <clib/dos_protos.h>
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #include <string.h>
-
-
- /* This information is required by the "start.o" startup code. */
- char *HookName = "GedSample2";
-
- /* A version string so the Version command works on us. */
- char *HookVersion = "\0$VER: GedSample2 2.0.2 (15.2.95)";
-
-
- /*******************************************************************
- *
- * Defines
- *
- *******************************************************************/
-
- #define WINDOW_WIDTH (300)
- #define WINDOW_HEIGHT (100)
-
-
- /*******************************************************************
- *
- * Text Array and Indexes
- *
- *******************************************************************/
-
- #include "gedsample2_strings.h"
-
- #if 0
-
- char *DefaultStrings[] = {
- "Dummy",
-
- "GED Listview Sample Window",
- "_Okay",
- "_Cancel",
- };
-
- enum {
- G_Dummy = 0,
- G_Title, /* gadget labels must start from 1! */
- G_Okay,
- G_Cancel,
- TXT_COUNT
- };
-
- /* This information is required by the "start.o" startup code. */
- char *HookText = "Hook_GedSample";
- int HookTextCount = TXT_COUNT;
-
- #endif
-
- /*******************************************************************
- *
- * These are filled in by the ImageFX Ged system
- *
- *******************************************************************/
-
- LONG OutsideArea[4]; /* will contain border size,
- [0] = leftedge,
- [1] = topedge,
- [2] = width,
- [3] = height */
-
- LONG InsideArea[4]; /* will contain border size,
- [0] = leftedge,
- [1] = topedge,
- [2] = width,
- [3] = height */
-
- LONG ListValue; /* current listview active element */
-
- /*******************************************************************
- *
- * Gadget ID's
- *
- *******************************************************************/
-
- enum {
- ID_Okay = 300, /* start high to avoid conflicts */
- ID_Cancel, /* with ImageFX gadgets */
- ID_Listview,
- };
-
- /*******************************************************************
- *
- * Gadget callbacks - these are called when the gadget associated
- * with the callback is "fiddled" with.
- *
- * Be sure to use __saveds for all callbacks!
- *
- * Any callback that returns non-zero will cause GedWin() to
- * return immediately.
- *
- *******************************************************************/
-
- int __saveds ListCode (GedListProto)
- {
- /*
- * This callback is for the listview gadget. When the user
- * selects an entry, we are called.
- */
-
- NewList((struct List *)lv->List);
- lv->Count = 0;
- Ged_Set(w, ID_Listview, NULL);
-
- // DisplayBeep(NULL); /* nothing special for this demo,
- // but we could activate a string
- // gadget or something */
-
- return(0);
- }
-
- /*******************************************************************
- *
- * NewGad array - defines elements of our interface
- *
- *******************************************************************/
-
- struct NewGad newGads[] = {
-
- { Scale_ID }, /* voodoo magic */
-
- /* okay gadget */
- { Button_ID, /* style */
- ID_Okay, /* gadget id */
- 8, /* left */
- WINDOW_HEIGHT - 16, /* top */
- 100, /* width */
- 12, /* height - 12's a good height for buttons */
- G_Okay, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - not used */
- ID_Okay, /* data1 - exit GedWin with this return code
- when user clicks this gadget */
- 0, /* data2 - unused */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* cancel gadget */
- { Button_ID, /* style */
- ID_Cancel, /* gadget id */
- WINDOW_WIDTH - 108, /* left */
- WINDOW_HEIGHT - 16, /* top */
- 100, /* width */
- 12, /* height - 12's a good height for buttons */
- G_Cancel, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - not used */
- ID_Cancel, /* data1 - exit GedWin with this return code
- when user clicks this gadget */
- 0, /* data2 - unused */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* listview gadget */
- { List_ID, /* style */
- ID_Listview, /* gadget id */
- 20, /* left */
- 20, /* top */
- WINDOW_WIDTH-40, /* width */
- WINDOW_HEIGHT-40, /* height */
- 0, /* label - listviews don't have labels */
- ListCode, /* code - callback function */
- 0, /* userdata - none needed */
- &ListValue, /* pointer - where to store current value */
- 0, /* data1 - EListView (filled later) */
- ID_Okay, /* data2 - double-click return value */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* window title */
- { Text_ID, /* style */
- 0, /* id - none needed */
- WINDOW_WIDTH/2, /* left */
- 4, /* top */
- 0, /* width - unneeded */
- 0, /* height - unneeded */
- G_Title, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - unused */
- 2, /* data1 - drawing pen (2=white) */
- 0, /* data2 - unused */
- 2, /* data3 - justification
- (0=left, 1=right, 2=center) */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* window border */
- { Border_ID, /* style */
- 0, /* id - none needed */
- 0, /* left */
- 0, /* top */
- WINDOW_WIDTH, /* width */
- WINDOW_HEIGHT, /* height */
- 0, /* label - none needed */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- OutsideArea, /* pointer - (optional) - fill in actual
- size of the border when created;
- useful for drawing stuff inside
- the border so we know where the
- actual border coords are. Use NULL
- if you don't need this. This is just
- here as an example. */
- FALSE, /* data1 - recessed border? */
- TRUE, /* data2 - double thick? */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* inside border */
- { Border_ID, /* style */
- 0, /* id - none needed */
- 8, /* left */
- 14, /* top */
- WINDOW_WIDTH-16, /* width */
- WINDOW_HEIGHT-14-18, /* height */
- 0, /* label - none needed */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- InsideArea, /* pointer - (optional) - fill in actual
- size of the border when created;
- useful for drawing stuff inside
- the border so we know where the
- actual border coords are. Use NULL
- if you don't need this. This is just
- here as an example. */
- TRUE, /* data1 - recessed border? */
- FALSE, /* data2 - double thick? */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- { End_ID } /* must end with End_ID! */
- };
-
- /*******************************************************************
- *
- * NewWindow - defines the window (flags and such)
- *
- *******************************************************************/
-
- struct NewWindow newWindow = {
-
- 0, 0, /* left, top */
- WINDOW_WIDTH, WINDOW_HEIGHT, /* width, height */
- 0, 1, /* 1.3 stuff... :) */
- IDCMP_GADGETUP, /* IDCMP flags (must set correctly!) */
- WFLG_BORDERLESS | /* Window flags */
- WFLG_SMART_REFRESH |
- WFLG_NOCAREREFRESH |
- WFLG_RMBTRAP |
- WFLG_ACTIVATE,
- NULL, /* Firstgadget - unused */
- NULL,
- NULL,
- NULL, /* Screen - set by ImageFX in PrepareNW */
- NULL,
- 0,0,0,0, /* Min/max size */
- WBENCHSCREEN /* Type - set by ImageFX in PrepareNW */
-
- };
-
-
- /*******************************************************************
- *
- * Hook entry point is here.
- *
- *******************************************************************/
-
- void hook_main (int argc, char **argv)
- {
- int returncode;
- struct EListView lv;
- struct List list;
- int i;
- struct Node node[16];
- char *elem_label[] = {
- "Element #0",
- "Element #1",
- "Element #2",
- "Element #3",
- "Element #4",
- "Element #5",
- "Element #6",
- "Element #7",
- "Element #8",
- "Element #9",
- "Element #10",
- "Element #11",
- "Element #12",
- "Element #13",
- "Element #14",
- "Element #15"
- };
-
- /*
- * Listviews are only in ImageFX 2.0 and above.
- */
- if (ScanBase->Library.lib_Version < 107) {
- hook_fail("This hook requires ImageFX 2.0");
- }
-
- /* make a list of stuff */
- NewList(&list);
-
- for (i = 0; i < 16; i++) {
- node[i].ln_Name = elem_label[i];
- AddTail(&list, &node[i]);
- }
-
- memset(&lv, 0, sizeof(struct EListView));
- lv.List = &list;
- lv.Flags = 0; // ELVF_SHOWSELECTED;
- lv.Count = 16;
- lv.Spacing = pWindow->RPort->TxHeight;
- lv.Active = -1;
-
- newGads[3].Data1 = (long)&lv;
-
- /*
- * PrepareNW() fills in the NewWindow structure with appropriate
- * values to open on the ImageFX screen (or on Workbench).
- */
- PrepareNW(&newWindow,
- WINDOW_WIDTH, WINDOW_HEIGHT, TRUE);
-
- /*
- * GedWin() opens the window, processes events, and returns when
- * the window is closed.
- */
- returncode = GedWin(&newWindow, /* newwindow */
- newGads, /* newgad array */
- 0, /* id of first string gad to activate */
- NULL, /* init function callback */
- NULL, /* cleanup function callback */
- HookTextArray); /* text array */
-
- if (returncode == ID_Okay) {
- InfoRequest("You selected element %ld!", ListValue);
- }
- else if (returncode == ID_Cancel) {
- Errorf("You cancelled, ya bum!");
- }
- }
-