home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
bgui-1.1a.lha
/
BGUI
/
demos
/
Addbuttons.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-07
|
6KB
|
182 lines
/*
** $RCSfile: Addbuttons.c,v $
** Description: Simple demonstration how to add and insert
** objects.
** Copyright: (C) Copyright 1994 Paul Weterings
** All Rights Reserved.
**
** $Author: Paul $
** $Revision: 1.2 $
** $Date: 1994/09/07 6:43:03 $
**/
#include <libraries/bgui.h>
#include <libraries/bgui_macros.h>
#include <libraries/gadtools.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/bgui_protos.h>
#include <clib/intuition_protos.h>
#include <stdio.h>
#include <stdlib.h>
/*
** Library base pointer.
** NOTE: The intuition.library is opened by DICE
** it's auto-init code.
**/
struct Library *BGUIBase;
/*
** Object ID's. Please note that the ID's are shared
** between the menus and the gadget objects.
**/
#define ID_ADD 21
#define ID_QUIT 22
#define ID_INS 23
#define ID_REM 24
/*
** Simple menu strip.
**/
struct NewMenu SimpleMenu[] = {
NM_TITLE, "Project", NULL, 0, 0, NULL,
NM_ITEM, "Add", "a", 0, 0, ( APTR )ID_ADD,
NM_ITEM, "Insert", "i", 0, 0, ( APTR )ID_INS,
NM_ITEM, "Remove all", "r", 0, 0, ( APTR )ID_REM,
NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL,
NM_ITEM, "Quit", "Q", 0, 0, ( APTR )ID_QUIT,
NM_END, NULL, NULL, 0, 0, NULL
}
;
int main( int argc, char *argv[] )
{
struct Window *window;
Object *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
ULONG signal = 0, rc, tmp = 0;
BOOL running = TRUE, ok = FALSE;
int x = 0, xx;
if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION ))
{
WO_Window = WindowObject,
WINDOW_Title, "Add/Insert Demo",
WINDOW_MenuStrip, SimpleMenu,
WINDOW_SizeGadget, TRUE,
WINDOW_MasterGroup,
base = HGroupObject,
StartMember, GO_Add = XenKeyButton( "_Add", ID_ADD ), EndMember,
StartMember, GO_Ins = XenKeyButton( "_Insert", ID_INS ), EndMember,
StartMember, GO_Rem = XenKeyButton( "_Remove all", ID_REM ), EndMember,
StartMember, GO_Quit = XenKeyButton( "_Quit", ID_QUIT ), EndMember,
EndObject,
EndObject;
if ( WO_Window )
{
tmp += GadgetKey( WO_Window, GO_Add, "a" );
tmp += GadgetKey( WO_Window, GO_Quit, "q" );
tmp += GadgetKey( WO_Window, GO_Ins, "i" );
tmp += GadgetKey( WO_Window, GO_Rem, "r" );
if ( tmp == 4 )
{
if ( window = WindowOpen( WO_Window ))
{
GetAttr( WINDOW_SigMask, WO_Window, &signal );
do
{
Wait( signal );
while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
{
switch ( rc )
{
case WMHI_CLOSEWINDOW:
case ID_QUIT:
running = FALSE;
break;
case ID_ADD:
x++;
WindowClose( WO_Window );
addobj[x] = KeyButton( "Added", x );
ok = DoMethod( base, GRM_ADDMEMBER, addobj[x],
LGO_FixMinHeight, FALSE,
LGO_Weight, DEFAULT_WEIGHT,
TAG_END );
window = WindowOpen( WO_Window );
if (!window)
goto error;
break;
case ID_REM:
if (x>0)
{
WindowClose( WO_Window );
for (xx=1;xx<=x;xx++)
DoMethod( base, GRM_REMMEMBER, addobj[xx]);
window = WindowOpen( WO_Window );
x=0;
}
else
printf("Were out of gadgets!\n");
break;
case ID_INS:
x++;
WindowClose( WO_Window );
addobj[x] = KeyButton( "Inserted", x );
ok = DoMethod( base, GRM_INSERTMEMBER, addobj[x], GO_Rem,
LGO_FixMinHeight, FALSE,
LGO_Weight, DEFAULT_WEIGHT,
TAG_END );
window = WindowOpen( WO_Window );
if (!window)
goto error;
break;
}
}
}
while ( running );
}
else
puts ( "Could not open the window" );
}
else
puts( "Could not assign gadget keys" );
error:
DisposeObject( WO_Window );
}
else
puts( "Could not create the window object" );
CloseLibrary( BGUIBase );
}
else
puts( "Unable to open the bgui.library" );
return( 0 );
}
#ifdef _DCC
int wbmain( struct WBStartup *wbs )
{
return( main( 0, NULL ));
}
#endif
/*
* $Log: Addbuttons.c,v $
* Revision 1.2 1994/09/07 6:43:03 Paul
* Initial revision
*
*/