[comp.sys.amiga] GadTools HELP!

es1@cunixb.cc.columbia.edu (Ethan Solomita) (10/04/90)

	I am trying to write a program to try and figure out the
intracacies of programming the Amiga. I am using 2.0 on an A3000
and am trying to make a reasonably simple program. It opens a
window and places a slider gadget in it which can range from 0 to
100. When it is slid to 100, the gadget is disabled. When it is
slid to 0, the program quits. You can also click the close gadget
to quit.
	Well, it ain't coming close to that and I am hoping that
someone out there in netville (Peter Cherna??? 8) could help me
find the problems. When I run the compiled version, the mouse
point hesitates for a few secs, control is returned to the CLI
with no exit code returned. The window opens, but is empty. The
title appears correctly, but when the window is moved it changes
either to garbage or blank. The slider gadget doesn't appear, but
when I try to find it and drag it it appears and slides. The
program no longer exists/responds, the close gadget and the
slider gadget create no effects. Also the text from the gadget
never appears.
	Here is the Lattice C program. I know it isn't short and
isn't commented. I appreciate the favor. Thanks.

#include <utility/tagitem.h>
#include <proto/gadtools.h>
#include <intuition/gadgetclass.h>
#include <intuition/screens.h>
int IntuitionOpen = 0;
int GadToolsOpen = 0;
struct IntuitionBase *IntuitionBase = NULL;
struct GadToolsBase *GadToolsBase = NULL;
struct window *window1 = NULL;
struct Screen *WBScreen = NULL;
APTR vi = NULL;
struct Gadget *currgad;
struct Gadget *gadlist = NULL;

void CleanExit(returnvalue)
int returnvalue;
{
    if (IntuitionBase)
        CloseLibrary ((struct Library *)IntuitionBase);
    if (GadToolsBase)
        CloseLibrary ((struct Library *)GadToolsBase);
    if (window1)
        CloseWindow (window1);
    if (WBScreen)
        UnlockPubScreen (NULL, WBScreen);
    if (vi)
        FreeVisualInfo(vi);
    if (gadlist)
        FreeGadgets(gadlist);
    exit (returnvalue);
}

struct TagItem WindowTags[] = {
    {WA_Title, (ULONG)"MyWindow"},
    {WA_Flags, (ULONG)SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG},
    {WA_Height, 150L},
    {WA_Width, 600L},
    {TAG_DONE, }
};

struct NewGadget ng = {
    150, 60,
    280, 60,
    "MyGadgetText",
    NULL,
    1,
    NULL,
    &vi,
    NULL
};

struct TagItem GadgetTags[] = {
    {GTSL_Min, 0L},
    {GTSL_Max, 100L},
    {GTSL_Level, 50L},
    {GTSL_LevelFormat, (ULONG)"(Level: %l)"},
    {GTSL_MaxLevelLen, 12L},
    {GTSL_LevelPlace, (ULONG)PLACETEXT_RIGHT},
    {TAG_DONE, }
};

void handleIDCMP(struct Window *win)
{
    struct IntuiMessage *message = NULL;
    APTR object;
    ULONG class;
    WORD code;

    while (message = (struct IntuiMessage *)GT_GetIMsg(win->UserPort))
    {
        object = message->IAddress;
        class = message->Class;
        code = (WORD)message->Code;
        GT_ReplyIMsg(message);
        switch(class)
        {
            case CLOSEWINDOW:
                CleanExit(0);
            case MOUSEMOVE:
                if (code = 100)
                    GT_SetGadgetAttrs(currgad, win, NULL, GA_DISABLED, TRUE, TAG_DONE);
                if (code = 0)
                    CleanExit(0);
                break;
        }
    }
}
            

void main(int argc, char *argv[])
{
    IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 36);
    if (IntuitionBase == NULL)
        CleanExit(30);
    GadToolsBase = (struct GadToolsBase *) OpenLibrary ("gadtools.library", 36);
    if (GadToolsBase == NULL)
        CleanExit(30);
    WBScreen = LockPubScreen(NULL);
    if (WBScreen == NULL) {
        printf ("lockpubscreen error");
        CleanExit(30);
    }
    ng.ng_TextAttr = WBScreen->Font;
    vi = GetVisualInfo (WBScreen);
    if (vi = NULL) {
        printf ("getvisualinfo error");
        CleanExit(30);
    }
    currgad = CreateContext (&gadlist);
    currgad = CreateGadgetA(SLIDER_KIND, currgad, &ng, GadgetTags);
    window1 = OpenWindowTagList (NULL, WindowTags);
    if (!currgad) {
        printf ("currgad is false");
        CleanExit(30);
    }
    AddGList (window1, gadlist, -1, -1, NULL);
    GT_RefreshWindow (window1, NULL);
    handleIDCMP (window1);    
}
	-- Ethan

Ethan Solomita: es1@cunixb.cc.columbia.edu

*Iraq += *Kuwait;
NumCountries--;

and by popular demand...

free(Kuwait);

eric@cbmvax.commodore.com (Eric Cotton) (10/04/90)

In article <1990Oct4.004459.7005@cunixf.cc.columbia.edu> es1@cunixb.cc.columbia.edu (Ethan Solomita) writes:
>
>	I am trying to write a program to try and figure out the
>intracacies of programming the Amiga. I am using 2.0 on an A3000
>and am trying to make a reasonably simple program. It opens a
>window and places a slider gadget in it which can range from 0 to
>100. When it is slid to 100, the gadget is disabled. When it is
>slid to 0, the program quits. You can also click the close gadget
>to quit.
>	Well, it ain't coming close to that and I am hoping that
>someone out there in netville (Peter Cherna??? 8) could help me
>find the problems. When I run the compiled version, the mouse
>point hesitates for a few secs, control is returned to the CLI
>with no exit code returned. The window opens, but is empty. The
>title appears correctly, but when the window is moved it changes
>either to garbage or blank. The slider gadget doesn't appear, but
>when I try to find it and drag it it appears and slides. The
>program no longer exists/responds, the close gadget and the
>slider gadget create no effects. Also the text from the gadget
>never appears.
>	Here is the Lattice C program. I know it isn't short and
>isn't commented. I appreciate the favor. Thanks.


Well, I'm not Peter (he's out of town), but I'll give it a quick once-over
and see if I can see any errors.  If the suggestions I've made don't help
let me know and I'll check it over again.


>#include <utility/tagitem.h>
>#include <proto/gadtools.h>
>#include <intuition/gadgetclass.h>
>#include <intuition/screens.h>
>int IntuitionOpen = 0;
>int GadToolsOpen = 0;
>struct IntuitionBase *IntuitionBase = NULL;
>struct GadToolsBase *GadToolsBase = NULL;
>struct window *window1 = NULL;
>struct Screen *WBScreen = NULL;
>APTR vi = NULL;
>struct Gadget *currgad;
>struct Gadget *gadlist = NULL;
>
>void CleanExit(returnvalue)
>int returnvalue;
>{
>    if (IntuitionBase)
>        CloseLibrary ((struct Library *)IntuitionBase);
>    if (GadToolsBase)
>        CloseLibrary ((struct Library *)GadToolsBase);
>    if (window1)
>        CloseWindow (window1);
>    if (WBScreen)
>        UnlockPubScreen (NULL, WBScreen);
>    if (vi)
>        FreeVisualInfo(vi);
>    if (gadlist)
>        FreeGadgets(gadlist);
>    exit (returnvalue);
>}


Well, for one thing, you are using functions in libraries you just closed:

	CloseWindow	->	intuition.library
	UnlockPubScreen	->	intuition.library
	FreeVisualInfo	->	gadtools.library
	FreeGadgets	->	gadtools.library


>struct TagItem WindowTags[] = {
>    {WA_Title, (ULONG)"MyWindow"},
>    {WA_Flags, (ULONG)SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG},
>    {WA_Height, 150L},
>    {WA_Width, 600L},
>    {TAG_DONE, }
>};
>
>struct NewGadget ng = {
>    150, 60,
>    280, 60,
>    "MyGadgetText",
>    NULL,
>    1,
>    NULL,
>    &vi,
>    NULL
>};

NewGadget.ng_VisualInfo should be set to the result of GetVisualInfo(), not
the address of the result.

>
>struct TagItem GadgetTags[] = {
>    {GTSL_Min, 0L},
>    {GTSL_Max, 100L},
>    {GTSL_Level, 50L},
>    {GTSL_LevelFormat, (ULONG)"(Level: %l)"},
>    {GTSL_MaxLevelLen, 12L},
>    {GTSL_LevelPlace, (ULONG)PLACETEXT_RIGHT},
>    {TAG_DONE, }
>};
>
>void handleIDCMP(struct Window *win)
>{
>    struct IntuiMessage *message = NULL;
>    APTR object;
>    ULONG class;
>    WORD code;
>
>    while (message = (struct IntuiMessage *)GT_GetIMsg(win->UserPort))
>    {
>        object = message->IAddress;
>        class = message->Class;
>        code = (WORD)message->Code;
>        GT_ReplyIMsg(message);
>        switch(class)
>        {
>            case CLOSEWINDOW:
>                CleanExit(0);
>            case MOUSEMOVE:
>                if (code = 100)
>                    GT_SetGadgetAttrs(currgad, win, NULL, GA_DISABLED, TRUE, TAG_DONE);
>                if (code = 0)
>                    CleanExit(0);
>                break;
>        }
>    }
>}
>            
>
>void main(int argc, char *argv[])
>{
>    IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 36);
>    if (IntuitionBase == NULL)
>        CleanExit(30);
>    GadToolsBase = (struct GadToolsBase *) OpenLibrary ("gadtools.library", 36);
>    if (GadToolsBase == NULL)
>        CleanExit(30);
>    WBScreen = LockPubScreen(NULL);
>    if (WBScreen == NULL) {
>        printf ("lockpubscreen error");
>        CleanExit(30);
>    }
>    ng.ng_TextAttr = WBScreen->Font;
>    vi = GetVisualInfo (WBScreen);


GetVisualInfo(WBScreen) should be GetVisualInfo(WBScreen, TAG_DONE).


>    if (vi = NULL) {
>        printf ("getvisualinfo error");
>        CleanExit(30);
>    }
>    currgad = CreateContext (&gadlist);
>    currgad = CreateGadgetA(SLIDER_KIND, currgad, &ng, GadgetTags);
>    window1 = OpenWindowTagList (NULL, WindowTags);
>    if (!currgad) {
>        printf ("currgad is false");
>        CleanExit(30);
>    }
>    AddGList (window1, gadlist, -1, -1, NULL);
>    GT_RefreshWindow (window1, NULL);
>    handleIDCMP (window1);    
>}
>	-- Ethan
>
>Ethan Solomita: es1@cunixb.cc.columbia.edu

-- 
Eric Cotton
Commodore-Amiga                                               (215) 431-9100
1200 Wilson Drive                        {uunet|pyramid|rutgers}!cbmvax!eric
West Chester, PA 19380            "I don't find this stuff amusing anymore."