#include "microdot.h"
#include "ogre.h"
#include "ogre_protos.h"

static char *holdflag_options[] = 
   {
      "Nicht ändern",
      "-> Nicht löschen",
      "-> Löschen",
      NULL
   };

static char *langopts[ 9 ];

static char **initlangopts( void )
{
	char *p;
	int c;

	langopts[ 0 ] = "Nicht ändern";

	for( c = 0; c < 7; c++ )
	{
		p = &prefs.langnames[ c * 30 ];

		if( !*p )
			sprintf( p, "Sprache %ld", c + 1 );

		langopts[ c + 1 ] = p;
	}
	return( langopts );
}


#define BW_OK 1
#define BW_CANCEL 2
#define BW_SETBET 3
#define BW_BET 4
#define BW_SETHOLD 5
#define BW_HOLD 6
#define BW_HOLDFLAG 7
#define BW_SETPFAD 8
#define BW_PFAD 9
#define BW_PFADSEL 10
#define BW_LANG 11

int dobrettwildreq( struct brett *p_brett, struct brettinfo *p_bi, int count )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;
	char wintitle[ 62 ];
	int rc;

	sprintf( wintitle, "Parameter von %lD Bretter%s ändern...",
		count, PLURALN( count ) );

	ogw = ogreInitWindow( scr, 0, 0, wintitle );

	ogreAddGroup( ogw, 0 , OGFRAME_OUTLINE, " Allgemein " );

	ogreAddCheckbox( ogw, 0, 'b', "       _Betreff ändern?", BW_SETBET, FALSE );
	ogreAddString( ogw, 0, 'B', "", BW_BET, "", 42, 32 );
	ogreAddCheckbox( ogw, 1, 'p', "Auslager_pfad ändern?", BW_SETPFAD, FALSE );
	ogreAddString( ogw, 1, 'P', "", BW_PFAD, "", 42, 128 );
	ogreAddCycle( ogw, 2, 's', "_Sprache:", BW_LANG, initlangopts(), 17, 0 );

	ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Haltezeit " );
	ogreAddCycle( ogw, 0, 'n', "'_Nicht löschen':", BW_HOLDFLAG, holdflag_options, 17, 0 );
	ogreAddCheckbox( ogw, 0, 'h', "_Haltezeit ändern?", BW_SETHOLD, FALSE );
	ogreAddInteger( ogw, 0, 'H', "", BW_HOLD, 7, 0, MAXINT, 8, 8 );

	ogreAddGroup( ogw, 2, OGFRAME_NONE, NULL );
	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", BW_OK );
	ogreAddHelp( ogw, 0 );
	ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", BW_CANCEL );

	iw = ogreOpenWindow( ogw );
	if( !iw )
		return( 0 );

	while( !Done )
	{

		ogreEnable( ogw, ogreValue( ogw, BW_SETBET ), BW_BET, 0 );
		ogreEnable( ogw, ogreValue( ogw, BW_SETPFAD ), BW_PFAD, 0 );
		ogreEnable( ogw, ogreValue( ogw, BW_SETHOLD ), BW_HOLD, 0 );

		im = ogreWaitIM( ogw );

		if( im->Class == IDCMP_GADGETHELP)
			showguidenum( "brettwildwin_gads", im->Code );
		else if( im->Class == IDCMP_GADGETUP )
		{
			switch( im->Code )
			{
				case BW_OK:
					Done = 2;
					break;
				case BW_CANCEL:
					Done = 1;
					break;

			}
		}
		ogreIMReply( ogw, im );
	}

	if( Done == 2 )
	{
		if( ogreValue( ogw, BW_SETBET ) )
			strcpy( p_brett->betreff, ogreStringValue( ogw, BW_BET ) );

		if( ogreValue( ogw, BW_SETPFAD ) ) 
			strcpy( p_bi->autoexpfad, ogreStringValue( ogw, BW_PFAD ) );

		if( ogreValue( ogw, BW_SETHOLD ) )
			p_brett->days = ogreValue( ogw, BW_HOLD );

		p_brett->language = ogreValue( ogw, BW_LANG );

		rc = ogreValue( ogw, BW_HOLDFLAG );
		if( rc )
		{
			p_brett->mails = 1;
			if( rc == 1 )
				p_brett->flags |= BFLAG_NOCRUNCH;
		}

	}

	ogreExitWindow( ogw );


	return( Done == 2 );
}
