I must have an old set of includes.
From the gadgetclass datasheet:
Code: Select all
GA_Width (int16)
GA_Height (int16)
These attribute corresponds to the Width and Height fields
in the Intuition Gadget structure.
Defaults to arbitrary positive number.
Applicability is (OM_NEW, OM_SET, OM_GET, OM_UPDATE)
Just to make sure, I put together a short example.
Just copy the entire code block into a file named gadwidth.c and execute it to compile.
Then run the result, which will be named GadWidth.
You'll get a window with a listbrowser gadget, and you can check the gadget width at any time by
entering Ctrl-D into the shell.. Feel free to re-size the window and check it a few times.
Ctrl-C into the shell will close the window.
Code: Select all
;/* gadwidth.c - example of reading a listgad width
SDK:gcc/bin/gcc -c gadwidth.c
SDK:gcc/bin/gcc -N -o GadWidth gadwidth.o
quit
*/
#include <proto/intuition.h>
#include <proto/utility.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <classes/window.h>
#include <gadgets/layout.h>
#include <gadgets/listbrowser.h>
#include <string.h>
#define BUFSIZE 256 // char bufffer for window title
struct Library *IntuitionBase = NULL, *UtilityBase = NULL;
struct IntuitionIFace *IIntuition = NULL;
struct UtilityIFace *IUtility = NULL;
struct ClassLibrary *WindowBase = NULL,*LayoutBase = NULL;
struct ClassLibrary *ListBrowserBase = NULL;
Class *WindowClass = NULL, *LayoutClass = NULL;
Class *ListBrowserClass = NULL;
// RETURN_OK or RETURN_FAIL
// cleans up for itself if FAIL
int32 openAll(void);
// always RETURN_FAIL
int32 closeAll(STRPTR why);
enum
{
GID_MAIN = 0,
GID_LISTBR,
GID_MAX
};
enum
{
WID_MAIN = 0,
WID_MAX
};
int main(int argc, char **argv)
{
struct Window *win[WID_MAX];
Object *winOb[WID_MAX];
Object *gadOb[GID_MAX];
if(RETURN_OK != openAll())
{
return(RETURN_FAIL);
}
if((winOb[WID_MAIN] = IIntuition->NewObject(WindowClass, NULL,
WA_SizeGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_IDCMP, IDCMP_NEWSIZE,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_ParentGroup, gadOb[GID_MAIN] = IIntuition->NewObject(LayoutClass, NULL,
LAYOUT_AddChild, gadOb[GID_LISTBR] = IIntuition->NewObject(ListBrowserClass, NULL,
GA_ID, GID_LISTBR,
TAG_END),
TAG_END),
TAG_END)))
{
if((win[WID_MAIN] = (struct Window *)IIntuition->IDoMethod(winOb[WID_MAIN], WM_OPEN, NULL)))
{
uint32 signal, signalmask, alive = 1;
uint32 result, x;
uint16 code;
char winTitle[BUFSIZE];
IDOS->Printf("Window is now open\n");
IDOS->Printf("Change window size with size gadget\n");
IDOS->Printf("Press Ctrl-D in this console to get gadget width\n");
IDOS->Printf("Press Ctrl-C in this console to close window\n");
IIntuition->GetAttr(WINDOW_SigMask, winOb[WID_MAIN], &signalmask);
while(alive)
{
signal = IExec->Wait(signalmask | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
if(signal & signalmask)
{
while((result = IIntuition->IDoMethod(winOb[WID_MAIN], WM_HANDLEINPUT, &code))!= WMHI_LASTMSG)
{
switch (result & WMHI_CLASSMASK)
{
case WMHI_CLOSEWINDOW:
win[WID_MAIN] = NULL;
alive = 0;
break;
case WMHI_NEWSIZE:
if(IIntuition->GetAttr(GA_Width, gadOb[GID_LISTBR], &x))
{
IUtility->SNPrintf(winTitle, BUFSIZE, "Width %ld", x);
IIntuition->SetWindowAttr(win[WID_MAIN], WA_Title, winTitle, strlen(winTitle +1));
}
break;
}
}
}
if(signal & SIGBREAKF_CTRL_C)
{
alive = 0;
}
if(signal & SIGBREAKF_CTRL_D)
{
if(IIntuition->GetAttr(GA_Width, gadOb[GID_LISTBR], &x))
{
IDOS->Printf("Gadget Width is %ld\n", x);
}
}
}
}
IIntuition->DisposeObject(winOb[WID_MAIN]);
}
else
{
IDOS->Printf("Failed to create WinOb\n");
}
closeAll(NULL);
return(RETURN_OK);
}
// RETURN_OK or RETURN_FAIL
// cleans up for itself if FAIL
int32 openAll(void)
{
if(!(UtilityBase = IExec->OpenLibrary("utility.library", 53)))
{
return(closeAll("Failed to open utility.library"));
}
if(!(IUtility = (struct UtilityIFace *)IExec->GetInterface(
UtilityBase, "main", 1, NULL)))
{
return(closeAll("Failed to get utility interface"));
}
if(!(IntuitionBase = IExec->OpenLibrary("intuition.library", 53)))
{
return(closeAll("Failed to open intuition.library"));
}
if(!(IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase, "main", 1, NULL)))
{
return(closeAll("Failed to get intuition interface"));
}
if(!(WindowBase = IIntuition->OpenClass("window.class", 53, &WindowClass)))
{
return(closeAll("Failed to open window class"));
}
if(!(LayoutBase = IIntuition->OpenClass("gadgets/layout.gadget", 53, &LayoutClass)))
{
return(closeAll("Failed to open layout gadget"));
}
if(!(ListBrowserBase = IIntuition->OpenClass("gadgets/listbrowser.gadget", 53, &ListBrowserClass)))
{
return(closeAll("Failed to open listbrowser gadget"));
}
return(RETURN_OK);
}
// always RETURN_FAIL
int32 closeAll(STRPTR why)
{
if(why)
{
IDOS->Printf("%s\n", why);
}
if(IIntuition)
{
IIntuition->CloseClass(ListBrowserBase);
IIntuition->CloseClass(LayoutBase);
IIntuition->CloseClass(WindowBase);
}
IExec->DropInterface((struct Interface *)IIntuition);
IExec->CloseLibrary(IntuitionBase);
IExec->DropInterface((struct Interface *)IUtility);
IExec->CloseLibrary(UtilityBase);
return(RETURN_FAIL);
}
Not exactly a well formed program, but it fits into one file for easy posting.
Have Fun!
edit: it looks like the website adds characters to the text.
If you'd like a copy just PM me with your email address, and I'l send the code directly.
edit2: cleaned up a bit, and replaced tabs with spaces.. might work better.?