#include "microdot.h"

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

#define BID_MAKEICONS 1
#define BID_BINEX 2
#define BID_BINEXSEL 12
#define BID_TXTEX 3
#define BID_TXTEXSEL 13
#define BID_BINPFAD 4
#define BID_BINPFADSEL 5
#define BID_TXTPFAD 6
#define BID_TXTPFADSEL 7

#define BID_DLT 14
#define BID_DLTSEL 15

#define BID_ESCCLRNEW 8
#define BID_ESCCLRONLYREAD 19
#define BID_OK 9
#define BID_CANCEL 10
#define BID_TEXT 11

#define BID_AUTOCLRNEW 20

#define BID_BRETTTREE 16
#define BID_IX 17
#define BID_MAKELOG 18


void dobedprefs( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;

	ogw = ogreInitWindow( scr, 0, 0, "Bedienung I" );

	ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Piktogramme " );
	ogreAddCheckbox( ogw, 0, 'p', "_Piktogramme erzeugen?", BID_MAKEICONS, ! ( prefs.flags & MDF_NOICONS ) );
	ogreAddText( ogw, 0, "", BID_TEXT, "Standardprogramme", 25, 0 );
	ogreAddString( ogw, 1, 'b', "für ausgelagerte _Binärnachrichten:", BID_BINEX, prefs.binex_defaulttool, 30, 128 );
	ogreAddButton( ogw, 1 | OGGP_KEEPSIZE, 'B', "?", BID_BINEXSEL );
	ogreAddString( ogw, 2, 't', "für ausgelagerte _Textnachrichten:", BID_TXTEX, prefs.txtex_defaulttool, 30, 128 );
	ogreAddButton( ogw, 2 | OGGP_KEEPSIZE, 'T', "?", BID_TXTEXSEL );
	ogreAddString( ogw, 3, 'd', "für _downgeloadete Dateien:", BID_DLT, prefs.dl_defaulttool, 30, 128 );
	ogreAddButton( ogw, 3 | OGGP_KEEPSIZE, 'D', "?", BID_DLTSEL );

	ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Sonstiges " );

	ogreAddCheckbox( ogw, 0, 'i', "auch Brettl_iste als Baum darstellen?", BID_BRETTTREE, prefs.showboardtree );
	ogreAddCheckbox( ogw, 1, 'f', "Log_file erzeugen?", BID_MAKELOG, prefs.do_logfile );

	ogreAddString( ogw, 2, 's', "Au_slagerpfad für Binärnachrichten:", BID_BINPFAD, prefs.binex_pfad, 30, 128 );
	ogreAddButton( ogw, 2 | OGGP_KEEPSIZE, 'S', "?", BID_BINPFADSEL );
	ogreAddString( ogw, 3, 'l', "Aus_lagerpfad für Textnachrichten:", BID_TXTPFAD, prefs.txtex_pfad, 30, 128 );
	ogreAddButton( ogw, 3 | OGGP_KEEPSIZE, 'L', "?", BID_TXTPFADSEL );

	ogreAddGroup( ogw, 2, OGFRAME_NONE, NULL );
	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", BID_OK );
	ogreAddButton( ogw, 0, 0x5f, "Hilfe", OGID_HELP );
	ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", BID_CANCEL );

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

	while( !Done )
	{
		ogreEnable( ogw, ogreValue( ogw, BID_MAKEICONS ), BID_BINEX, BID_BINEXSEL, BID_TXTEX, BID_TXTEXSEL, BID_DLT, BID_DLTSEL, 0 );

		im = ogreWaitIM( ogw );

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

				case BID_BINEXSEL:
					newdofrselfile( ogw, BID_BINEX, "Standardprogramm für Binärnachrichten auswählen:" );
					break;

				case BID_TXTEXSEL:
					newdofrselfile( ogw, BID_TXTEX, "Standardprogramm für Textnachrichten auswählen:" );
					break;

				case BID_DLTSEL:
					newdofrselfile( ogw, BID_DLT, "Standardprogramm für downgeloadete Dateien:" );
					break;

				case BID_BINPFADSEL:
					newdofrseldir( ogw, BID_BINPFAD, "Auslagerpfad für Binärnachrichten auswählen:" );
					break;

				case BID_TXTPFADSEL:
					newdofrseldir( ogw, BID_TXTPFAD, "Auslagerpfad für Textnachrichten auswählen:" );
					break;

			}
		}
		ogreIMReply( ogw, im );
	}

	if( Done == 2 )
	{
		if( ogreValue( ogw, BID_MAKEICONS ) )
			prefs.flags &= ~ MDF_NOICONS;
		else
			prefs.flags |= MDF_NOICONS;

		strcpy( prefs.binex_defaulttool, ogreStringValue( ogw, BID_BINEX ) );
		strcpy( prefs.txtex_defaulttool, ogreStringValue( ogw, BID_TXTEX ) );
		strcpy( prefs.dl_defaulttool, ogreStringValue( ogw, BID_DLT ) );

		strcpy( prefs.binex_pfad, ogreStringValue( ogw, BID_BINPFAD ) );
		strcpy( prefs.txtex_pfad, ogreStringValue( ogw, BID_TXTPFAD ) );

		rtChangeReqAttr( fr[ FR_EXCLUDE ], RTFI_Dir, prefs.txtex_pfad, TAG_DONE );
		rtChangeReqAttr( fr[ FR_EXCLUDE_BIN ], RTFI_Dir, prefs.binex_pfad, TAG_DONE );

		prefs.showboardtree = ogreValue( ogw, BID_BRETTTREE );
		prefs.do_logfile	= ogreValue( ogw, BID_MAKELOG );
	}

	ogreExitWindow( ogw );
}

#define BI_OK 2
#define BI_CANCEL 3

#define BI_TXTPEN 4
#define BI_TXTBAK 5
#define BI_TXTBOLD 11

#define BI_MARKPEN 7
#define BI_MARKBAK 8
#define BI_MARKBOLD 12

#define BI_SELPEN 9
#define BI_SELBAK 10
#define BI_SELBOLD 13

#define BI_READPEN 14
#define BI_READBAK 15
#define BI_READBOLD 16

#define BI_QUOTEPEN 17
#define BI_QUOTEBAK 18
#define BI_QUOTEBOLD 19

#define BI_HEADPEN 20
#define BI_HEADBAK 21
#define BI_HEADBOLD 22

#define BI_MARKSELPEN 23
#define BI_MARKSELBAK 24
#define BI_MARKSELBOLD 25

#define BI_QUOTEPEN2 40
#define BI_QUOTEPEN3 41
#define BI_QUOTEPEN4 42
#define BI_QUOTEPEN5 43
#define BI_QUOTEPEN6 44
#define BI_QUOTEPEN7 45

#define BI_COLACT 80
#define BI_COLSEL 81

#define BI_RESET 82

/* Read RGB32 into Prefs */
extern void getcolors( struct Screen * );

void dobed2prefs( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;

	ogw = ogreInitWindow( scr, 0, 0, "Farben..." );

	ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Bildschirmfarben " );
	ogreAddCheckbox( ogw, 0, 'w', "_Workbench-Farben?", BI_COLACT, !prefs.usecustomcolors );
	ogreAddButton( ogw, 0, 'f', "_Farben einstellen", BI_COLSEL );

	ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Listenfarben " );

	ogreAddPensel( ogw, 0, 't', "     _Text", BI_TXTPEN, prefs.pens[ PEN_TEXT ], 14 );
	ogreAddPensel( ogw, 0, 0, "HG", BI_TXTBAK, prefs.pens[ PEN_TEXTBAK ], 14 );
	ogreAddCheckbox( ogw, 0, 0, "Fett", BI_TXTBOLD, prefs.pens[ PEN_TEXTBOLD ] );

	ogreAddPensel( ogw, 1, 'l', " aktuel_le", BI_SELPEN, prefs.pens[ PEN_SEL ], 14 );
	ogreAddPensel( ogw, 1, 0, "HG", BI_SELBAK, prefs.pens[ PEN_SELBAK ], 14 );
	ogreAddCheckbox( ogw, 1, 0, "Fett", BI_SELBOLD, prefs.pens[ PEN_SELBOLD ] );

	ogreAddPensel( ogw, 2, 'm', "_markierte", BI_MARKPEN, prefs.pens[ PEN_MARK ], 14 );
	ogreAddPensel( ogw, 2, 0, "HG", BI_MARKBAK, prefs.pens[ PEN_MARKBAK ], 14 );
	ogreAddCheckbox( ogw, 2, 0, "Fett", BI_MARKBOLD, prefs.pens[ PEN_MARKBOLD ] );

	ogreAddPensel( ogw, 3, 'i', "   Be_ides", BI_MARKSELPEN, prefs.pens[ PEN_MARKSEL ], 14 );
	ogreAddPensel( ogw, 3, 0, "HG", BI_MARKSELBAK, prefs.pens[ PEN_MARKSELBAK ], 14 );
	ogreAddCheckbox( ogw, 3, 0, "Fett", BI_MARKSELBOLD, prefs.pens[ PEN_MARKSELBOLD ] );

	ogreAddGroup( ogw, 2, OGFRAME_OUTLINE, " Anzeigerfarben " );

	ogreAddPensel( ogw, 0, 'x', "     Te_xt", BI_READPEN, prefs.pens[ PEN_READ ], 14 );
	ogreAddPensel( ogw, 0, 0, "HG", BI_READBAK, prefs.pens[ PEN_READBAK ], 14 );
	ogreAddCheckbox( ogw, 0, 0, "Fett", BI_READBOLD, prefs.pens[ PEN_READBOLD ] );

	ogreAddPensel( ogw, 1, 'p', "     Ko_pf", BI_HEADPEN, prefs.pens[ PEN_HEAD ], 14 );
	ogreAddPensel( ogw, 1, 0, "HG", BI_HEADBAK, prefs.pens[ PEN_HEADBAK ], 14 );
	ogreAddCheckbox( ogw, 1, 0, "Fett", BI_HEADBOLD, prefs.pens[ PEN_HEADBOLD ] );

	ogreAddPensel( ogw, 2, 'q', "   _Quotes", BI_QUOTEPEN, prefs.quotepens[ 0 ], 14 );
	ogreAddPensel( ogw, 2, 0, "HG", BI_QUOTEBAK, prefs.pens[ PEN_QUOTEBAK ], 14 );
	ogreAddCheckbox( ogw, 2, 0, "Fett", BI_QUOTEBOLD, prefs.pens[ PEN_QUOTEBOLD ] );
	ogreAddPensel( ogw, 3, 0, "Weitere Quotes:", BI_QUOTEPEN2, prefs.quotepens[ 1 ], 12 );
	ogreAddPensel( ogw, 3, 0, "", BI_QUOTEPEN3, prefs.quotepens[ 2 ], 12 );
	ogreAddPensel( ogw, 3, 0, "", BI_QUOTEPEN4, prefs.quotepens[ 3 ], 12 );

	ogreAddPensel( ogw, 4, 0, "Weitere Quotes:", BI_QUOTEPEN5, prefs.quotepens[ 4 ], 12 );
	ogreAddPensel( ogw, 4, 0, "", BI_QUOTEPEN6, prefs.quotepens[ 5 ], 12 );
	ogreAddPensel( ogw, 4, 0, "", BI_QUOTEPEN7, prefs.quotepens[ 6 ], 12 );

	ogreAddGroup( ogw, 3, OGFRAME_NONE, NULL );
	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", BI_OK );
	ogreAddButton( ogw, 0, 0x5f, "Hilfe", OGID_HELP );
	ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", BI_CANCEL );

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

	ogreEnable( ogw, !wbwindow, BI_COLACT, 0 );

	while( !Done )
	{
		ogreEnable( ogw, ( !ogreValue( ogw, BI_COLACT ) ) && ( !wbwindow ), BI_COLSEL, 0 );

		im = ogreWaitIM( ogw );

		if( im->Class == IDCMP_GADGETHELP )
			showguidenum( "colwin_gads", im->Code );
		else if( im->Class == IDCMP_GADGETUP )
		{
			switch( im->Code )
			{
				case BI_OK:
					Done = 2;
					break;

				case BI_CANCEL:
					Done = 1;
					break;

				case BI_COLSEL:
					rtPaletteRequest( "Farben einstellen:", NULL, TAG_DONE );
					break;

				case BI_COLACT:
					if( wbwindow )
						break;
					if( !ogreValue( ogw, BI_COLACT ) )
						setcolors( scr );
					else
						setwbcolors( scr );
					break;

				case BI_RESET:
					if( !wbwindow )
						setwbcolors( scr );
					break;

			}
		}
		ogreIMReply( ogw, im );
	}

	if( Done == 2 )
	{
		prefs.usecustomcolors = !ogreValue( ogw, BI_COLACT );
		if( prefs.usecustomcolors && !wbwindow )
			getcolors( scr );

		prefs.pens[ PEN_TEXT ] = ogreValue( ogw, BI_TXTPEN );
		prefs.pens[ PEN_TEXTBAK ] = ogreValue( ogw, BI_TXTBAK );
		prefs.pens[ PEN_TEXTBOLD ] = ogreValue( ogw, BI_TXTBOLD );

		prefs.pens[ PEN_SEL ] = ogreValue( ogw, BI_SELPEN );
		prefs.pens[ PEN_SELBAK ] = ogreValue( ogw, BI_SELBAK );
		prefs.pens[ PEN_SELBOLD ] = ogreValue( ogw, BI_SELBOLD );

		prefs.pens[ PEN_MARKSEL ] = ogreValue( ogw, BI_MARKSELPEN );
		prefs.pens[ PEN_MARKSELBAK ] = ogreValue( ogw, BI_MARKSELBAK );
		prefs.pens[ PEN_MARKSELBOLD ] = ogreValue( ogw, BI_MARKSELBOLD );

		prefs.pens[ PEN_MARK ] = ogreValue( ogw, BI_MARKPEN );
		prefs.pens[ PEN_MARKBAK ] = ogreValue( ogw, BI_MARKBAK );
		prefs.pens[ PEN_MARKBOLD ] = ogreValue( ogw, BI_MARKBOLD );

		prefs.pens[ PEN_READ ] = ogreValue( ogw, BI_READPEN );
		prefs.pens[ PEN_READBAK ] = ogreValue( ogw, BI_READBAK );
		prefs.pens[ PEN_READBOLD ] = ogreValue( ogw, BI_READBOLD );

		prefs.pens[ PEN_QUOTEBAK ] = ogreValue( ogw, BI_QUOTEBAK );
		prefs.pens[ PEN_QUOTEBOLD ] = ogreValue( ogw, BI_QUOTEBOLD );

		prefs.pens[ PEN_HEAD ] = ogreValue( ogw, BI_HEADPEN );
		prefs.pens[ PEN_HEADBAK ] = ogreValue( ogw, BI_HEADBAK );
		prefs.pens[ PEN_HEADBOLD ] = ogreValue( ogw, BI_HEADBOLD );

		prefs.quotepens[ 0 ] = ogreValue( ogw, BI_QUOTEPEN );
		prefs.quotepens[ 1 ] = ogreValue( ogw, BI_QUOTEPEN2 );
		prefs.quotepens[ 2 ] = ogreValue( ogw, BI_QUOTEPEN3 );
		prefs.quotepens[ 3 ] = ogreValue( ogw, BI_QUOTEPEN4 );
		prefs.quotepens[ 4 ] = ogreValue( ogw, BI_QUOTEPEN5 );
		prefs.quotepens[ 5 ] = ogreValue( ogw, BI_QUOTEPEN6 );
		prefs.quotepens[ 6 ] = ogreValue( ogw, BI_QUOTEPEN7 );

		calcmaxpen();
	}

	ogreExitWindow( ogw );
}

#define EX_OK 1
#define EX_CANCEL 2

#define EX_ED 3
#define EX_ED_WB 4
#define EX_ED_STACK 5

#define EX_VIEW 6
#define EX_VIEW_WB 7
#define EX_VIEW_STACK 8

#define EX_DATA 9
#define EX_DATASEL 10
#define EX_TRANS 11
#define EX_TRANSSEL 12

#define EX_CON 13

#define EX_DOPACK 14
#define EX_SELXPK 15
#define EX_XPKTXT 16
#define EX_NOIXCACHE 17

extern struct Library *XpkBase;
static char *packopts[] = { "Aus", "Intern Schnell", "Intern Mittel", "Intern Optimal", "XPK", "XPK+Passwort", NULL };

void doexternprefs( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;
	char *p, *p2;

	ogw = ogreInitWindow( scr, 0, 0, "Externe Programme & Pfade" );
	ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Externe Programme " );
	ogreAddString( ogw, 0, 'e', "       _Editor:", EX_ED, prefs.editor, 26, 128 );
	ogreAddCheckbox( ogw, 0, 'w', "_WB?", EX_ED_WB, prefs.editor_wb );
	ogreAddInteger( ogw, 0, 's', "_Stack", EX_ED_STACK,  prefs.editor_stack, 4096, MAXINT, 8, 16 );

	ogreAddString( ogw, 1, 'i', "B_inäranzeiger:", EX_VIEW, prefs.binviewer, 26, 128 );
	ogreAddCheckbox( ogw, 1, 'b', "W_B?", EX_VIEW_WB, prefs.viewer_wb );
	ogreAddInteger( ogw, 1, 'c', "Sta_ck", EX_VIEW_STACK,  prefs.viewer_stack, 4096, MAXINT, 8, 16 );

	ogreAddGroup( ogw, 1 | OGGP_EXPANDSTRING, OGFRAME_OUTLINE, " Datenbank " );
	ogreAddString( ogw, 0, 'd', "   _Daten-Verzeichnis:", EX_DATA, prefs.datadir, 26, 128 );
	ogreAddButton( ogw, 0 | OGGP_KEEPSIZE, 'D', "?", EX_DATASEL );
	ogreAddString( ogw, 1, 't', "_Transfer-Verzeichnis:", EX_TRANS, prefs.transferdir, 26, 128 );
	ogreAddButton( ogw, 1 | OGGP_KEEPSIZE, 'T', "?", EX_TRANSSEL );

	ogreAddCycle( ogw, 2, 'p', "Datenbank _Packen", EX_DOPACK, packopts, 10, prefs.do_packmsg );
	ogreAddText( ogw, 3, "_XPK-Parameter", EX_XPKTXT, "", 40, TRUE );
	ogreAddButton( ogw, 3 | OGGP_KEEPSIZE, 'x', "?", EX_SELXPK );
	ogreAddCheckbox( ogw, 4, 'x', "Kein Index-Cache?", EX_NOIXCACHE, prefs.noixcache );

	ogreAddGroup( ogw, 2 | OGGP_EXPANDSTRING, OGFRAME_OUTLINE, " Konsolenfenster " );
	ogreAddString( ogw, 0, 'k', "_Konsole:", EX_CON, prefs.console_window, 26, 80 );

	ogreAddGroup( ogw, 3, OGFRAME_NONE, NULL );
	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", EX_OK );
	ogreAddButton( ogw, 0, 0x5f, "Hilfe", OGID_HELP );
	ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", EX_CANCEL );

	ogreEnable( ogw, isv37, EX_VIEW_STACK, EX_ED_STACK, 0 );
	ogreEnable( ogw, isv39, EX_NOIXCACHE, 0 );

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

	ogreSetStringValue( ogw, EX_XPKTXT, xpkinfostring() );

	while( !Done )
	{
		ogreEnable( ogw, ogreValue( ogw, EX_DOPACK ) >= PACKMODE_XPK, EX_SELXPK, EX_XPKTXT, 0 );

		im = ogreWaitIM( ogw );

		if( im->Class == IDCMP_GADGETHELP )
			showguidenum( "externwin_gads", im->Code );
		else if( im->Class == IDCMP_GADGETUP )
		{
			switch( im->Code )
			{
				case EX_OK:
					p = ogreStringValue( ogw, EX_DATA );
					p2 = ogreStringValue( ogw, EX_TRANS );
					if( ( !strchr( p, ':' ) ) || ( !strchr( p2, ':') ) )
					{
						askreq( "Fehler: Daten- und Transferpfad\nmüssen absolut angegeben werden!", "Abbruch" );
						break;
					}
					Done = 2;
					break;
				case EX_CANCEL:
					Done = 1;
					break;

				case EX_SELXPK:
					ogreLockWindow( ogw );
					selectxpk();
					ogreUnlockWindow( ogw );
					ogreSetStringValue( ogw, EX_XPKTXT, xpkinfostring() );
					break;

				case EX_DATASEL:
					newdofrseldir( ogw, EX_DATA, "Verzeichnis für Daten auswählen:" );
					break;

				case EX_TRANSSEL:
					newdofrseldir( ogw, EX_TRANS, "Verzeichnis für Übertragung auswählen:" );
					break;

				case EX_DOPACK:
					if( !registerinfo.serie )
					{
						askreq( "Diese Funktion ist nur in der registrierten\nVersion von MicroDot verfügbar.", "Abbruch" );
						ogreSetValue( ogw, EX_DOPACK, 0 );
					}
					break;
			}
		}
		ogreIMReply( ogw, im );
	}

	if( Done == 2 )
	{
		prefs.editor_wb = ogreValue( ogw, EX_ED_WB );
		prefs.editor_stack = ogreValue( ogw, EX_ED_STACK );
		ogreCopyStringValue( ogw, EX_ED, prefs.editor );

		prefs.do_packmsg = ogreValue( ogw, EX_DOPACK );

		if( ( !XpkBase ) && ( prefs.do_packmsg >= PACKMODE_XPK ) )
		{
			prefs.do_packmsg = 0;
			xpknotinstalled();
		}

		prefs.viewer_wb = ogreValue( ogw, EX_VIEW_WB );
		prefs.viewer_stack = ogreValue( ogw, EX_VIEW_STACK );
		prefs.noixcache = ogreValue( ogw, EX_NOIXCACHE );
		ogreCopyStringValue( ogw, EX_VIEW, prefs.binviewer );

		ogreCopyStringValue( ogw, EX_DATA, prefs.datadir );
		ogreCopyStringValue( ogw, EX_TRANS, prefs.transferdir );
		ogreCopyStringValue( ogw, EX_CON, prefs.console_window );

		makedospath( prefs.datadir );
		makedospath( prefs.transferdir );

	}

	ogreExitWindow( ogw );


}

#define MI_OK 1
#define MI_CANCEL 2
#define MI_MAPSNAME 3
#define MI_MAPSOUT 4
#define MI_MAPSADD 5
#define MI_MAPSDEL 6
#define MI_MAPSLIST 7
#define MI_MAPSLISTVERBOSE 8
#define MI_MAPSCLPM 9
#define MI_MAPSHELP 13
#define MI_LISTID 10
#define MI_LISTOFFS 11
#define MI_LISTBOFFS 12
#define MI_STD 14
#define MI_PREFIX 15
#define MI_ADDPREFIX 16
#define MI_DELPREFIX 17

static char *maps_options[] = {
	"Konfiguriert",
	"Connectline 4.x/5.x",
	"Fastcall",
	"JokerSystem 2.x",
	"Zerberus 5.x",
	"InfiMail",
	"Anubis OMaps",
	"ZConnect-MAPS",
	NULL
};

void domapsprefs( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;
	char prefix[ 512 ], *p;

	strcpy( prefix, prefs.maps_msgprefix );
	for( p = prefix; *p; p++ )
	{
		if( *p == 10 )
		{
			strins( p, "\\" );
			p[ 1 ] = 'n';
		}
	}

	ogw = ogreInitWindow( scr, WFLG_RMBTRAP, IDCMP_MENUPICK, "MAPS-Konfiguration" );

	ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );
	ogreAddString( ogw, 0, 'm', "Username von _MAPS:", MI_MAPSNAME, prefs.mapsname, 30, 40 );
	ogreAddString( ogw, 1,   0, "Absender von MAPS-Nachrichten:", MI_MAPSOUT, prefs.mapsoutname, 30, 40 );
	ogreAddString( ogw, 2,   0, "Betreff für 'Bretter bestellen':", MI_MAPSADD, prefs.maps_add, 30, 40 );
	ogreAddString( ogw, 3,   0, "Betreff für 'Bretter abbestellen':", MI_MAPSDEL, prefs.maps_del, 30, 40 );
	ogreAddString( ogw, 4,   0, "Betreff für 'kurze Brettliste':", MI_MAPSLIST, prefs.maps_list, 30, 40 );
	ogreAddString( ogw, 5,   0, "Betreff für 'ausführliche Brettliste':", MI_MAPSLISTVERBOSE, prefs.maps_list_verbose, 30, 40 );
	ogreAddString( ogw, 6,   0, "Betreff für 'Hilfe anfordern':", MI_MAPSHELP, prefs.maps_help, 30, 40 );
	ogreAddString( ogw, 7,   0, "Betreff für 'Postfach löschen':", MI_MAPSCLPM, prefs.maps_clearpm, 30, 40 );
	ogreAddString( ogw, 8,   0, "Betreff der Brettliste von MAPS:", MI_LISTID, prefs.maps_listid, 30, 40 );
	ogreAddString( ogw, 9,   0, "Nachrichtenbody-Prefix:", MI_PREFIX, prefix, 30, 255 );
	ogreAddInteger( ogw,  10, 0, "Spalte Namen in Liste:", MI_LISTBOFFS, prefs.maps_list_boffs, 0, 255, 15, 4 );
	ogreAddInteger( ogw, 10, 0, " Spalte Betreff:", MI_LISTOFFS, prefs.maps_list_offs, 0, 255, 15, 4 );
	ogreAddString( ogw, 11,   0, "  Brettnamenprefix für ADD:", MI_ADDPREFIX, prefs.maps_addprefix, 15, 20 );
	ogreAddString( ogw, 11,   0, "für DEL:", MI_DELPREFIX, prefs.maps_delprefix, 15, 20 );

	ogreAddCycle( ogw, 12, 's', "_Standard-MAPS-Typ:", MI_STD,
		maps_options, 20, prefs.std_maps_type
	);

	ogreAddGroup( ogw, 1, OGFRAME_NONE, NULL );

	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", MI_OK );
	ogreAddButton( ogw, 0, 0x5f, "Hilfe", OGID_HELP );
	ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", MI_CANCEL );

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

	while( !Done )
	{

		ogreEnable( ogw, !ogreValue( ogw, MI_STD ),
			3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 0
		);

		im = ogreWaitIM( ogw );

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

			}
		}
		ogreIMReply( ogw, im );
	}

	if( Done == 2 )
	{

		prefs.std_maps_type = ogreValue( ogw, MI_STD );

		if( prefs.std_maps_type )
			presetmapsprefs( prefs.std_maps_type );
		else
		{
			prefs.maps_list_boffs = ogreValue( ogw, MI_LISTBOFFS  );
			prefs.maps_list_offs = ogreValue( ogw, MI_LISTOFFS  );
			ogreCopyStringValue( ogw, MI_MAPSNAME, prefs.mapsname );
			ogreCopyStringValue( ogw, MI_MAPSOUT, prefs.mapsoutname );
			ogreCopyStringValue( ogw, MI_MAPSADD, prefs.maps_add );
			ogreCopyStringValue( ogw, MI_MAPSDEL, prefs.maps_del );
			ogreCopyStringValue( ogw, MI_MAPSLIST, prefs.maps_list );
			ogreCopyStringValue( ogw, MI_MAPSLISTVERBOSE, prefs.maps_list_verbose );
			ogreCopyStringValue( ogw, MI_MAPSCLPM, prefs.maps_clearpm );
			ogreCopyStringValue( ogw, MI_MAPSHELP, prefs.maps_help );
			ogreCopyStringValue( ogw, MI_LISTID, prefs.maps_listid );
			ogreCopyStringValue( ogw, MI_PREFIX, prefix );
			ogreCopyStringValue( ogw, MI_ADDPREFIX, prefs.maps_addprefix );
			ogreCopyStringValue( ogw, MI_DELPREFIX, prefs.maps_delprefix );

			while( p = strstr( prefix, "\\n" ) )
			{
				strcpy( p, p + 1 );
				*p = 10;
			}
			strcpy( prefs.maps_msgprefix, prefix );
			if( prefs.maps_msgprefix[ 0 ] && prefs.maps_msgprefix[ strlen( prefs.maps_msgprefix ) - 1 ] != '\n' )
				strcat( prefs.maps_msgprefix, "\n" );
		}
	}

	ogreExitWindow( ogw );

}

static char *reqpos_opt[] = {
	"relativ zum Mauspfeil",
	"Fensterzentriert",
	"Bildschirmzentriert",
	"Oben links im Fenster",
	"Oben links im Bildschirm",
	NULL
};

#define BW_OK 1
#define BW_CANCEL 2

#define BW_SCROLLJUMP 3
#define BW_AUTOLF 4

#define BW_READERTABSIZE 5

#define BW_REQPOS 6

#define BW_ESCCLRNEW 7
#define BW_ESCCLRONLYREAD 8
#define BW_AUTOCLRNEW 9
#define BW_NEXTNEWBOARD 10
#define BW_HOLDOWNMAILS 11
#define BW_HARDDEL 12
#define BW_OWNMAILSNEW 13
#define BW_NEXTNEWBOARDASK 14
#define BW_SORTINWINSMALL 15

void dobed3prefs( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;
	static char *nextnewopts[] = { "Stopp am Brettende", "Brettübergreifend", "Übergreifend mit Nachfrage", NULL };
	int nextnew;

	ogw = ogreInitWindow( scr, 0, 0, "Bedienung II" );

	nextnew = ( prefs.flags2 & MDF2_NEXTNEWBOARD ) ? 1 : 0;
	if( nextnew && ( prefs.flags2 & MDF2_NEXTNEWBOARDASK ) )
		nextnew = 2;

	ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Listerverhalten " );
	ogreAddCheckbox( ogw, 0, 'l', "_Lister-Sprung?", BW_SCROLLJUMP, ( prefs.flags2 & MDF2_SCROLLJUMP ) );
	ogreAddCheckbox( ogw, 0, 'z', "_Zeilen-Sprung?", BW_AUTOLF, ( prefs.flags2 & MDF2_AUTOLF ) );
	ogreAddCheckbox( ogw, 0, 'd', "'_DEL' löscht 'Halten'?",
		BW_HARDDEL, prefs.flags2 & MDF2_HARDDEL );

	ogreAddCheckbox( ogw, 1, 'n', "_NEU-Flags bei \"Brett verlassen\" automatisch löschen?",
		BW_ESCCLRNEW, prefs.flags2 & MDF2_ESCCLRNEW );
	ogreAddCheckbox( ogw, 2, 'g', "nur von _gelesenen Nachrichten NEU-Flags löschen?",
		BW_ESCCLRONLYREAD, prefs.flags2 & MDF2_ESCCLRONLYREAD );
	ogreAddCheckbox( ogw, 3, 'h', "NEU-Flags von allen berü_hrten Nachrichten löschen?",
		BW_AUTOCLRNEW, prefs.flags2 & MDF2_AUTOCLRNEW );
	ogreAddCheckbox( ogw, 4, 'e', "'_eigene Nachrichten auf 'Halten'?",
		BW_HOLDOWNMAILS, prefs.flags2 & MDF2_HOLDOWNMAILS );
	ogreAddCheckbox( ogw, 5, 'b', "'eigene Nachrichten als 'Neu' _behandeln?",
		BW_OWNMAILSNEW, prefs.flags2 & MDF2_OWNMAILSNEW );
	ogreAddCycle( ogw, 6, 'c', "'Nä_chste Neue':", BW_NEXTNEWBOARD, nextnewopts, 26, nextnew );

	ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Verschiedenes " );
	ogreAddCycle( ogw, 0, 'p', "Requester_position:", BW_REQPOS, reqpos_opt, 26, prefs.reqpos );
	ogreAddInteger( ogw, 1, 't', "Reader-_Tabulatorweite", BW_READERTABSIZE,  prefs.reader_tabsize, 1, 16, 4, 4 );
	ogreAddCheckbox( ogw, 2, 'f', "Sortin-_Fenster klein?",
		BW_SORTINWINSMALL, prefs.sortinwin_small
	);

	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;

	while( !Done )
	{
		im = ogreWaitIM( ogw );

		if( im->Class == IDCMP_GADGETHELP)
			showguidenum( "bed3win_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_SCROLLJUMP ) )
			prefs.flags2 |= MDF2_SCROLLJUMP;
		else
			prefs.flags2 &= ~MDF2_SCROLLJUMP;

		if( ogreValue( ogw, BW_AUTOLF ) )
			prefs.flags2 |= MDF2_AUTOLF;
		else
			prefs.flags2 &= ~MDF2_AUTOLF;

		if( ogreValue( ogw, BW_ESCCLRNEW ) )
			prefs.flags2 |= MDF2_ESCCLRNEW;
		else
			prefs.flags2 &= ~ MDF2_ESCCLRNEW;

		if( ogreValue( ogw, BW_ESCCLRONLYREAD ) )
			prefs.flags2 |= MDF2_ESCCLRONLYREAD;
		else
			prefs.flags2 &= ~ MDF2_ESCCLRONLYREAD;

		if( ogreValue( ogw, BW_AUTOCLRNEW ) )
			prefs.flags2 |= MDF2_AUTOCLRNEW;
		else
			prefs.flags2 &= ~ MDF2_AUTOCLRNEW;

		nextnew = ogreValue( ogw, BW_NEXTNEWBOARD );
		switch( nextnew )
		{
			case 0:
				prefs.flags2 &= ~ ( MDF2_NEXTNEWBOARD | MDF2_NEXTNEWBOARDASK );
				break;

			case 1:
				prefs.flags2 &= ~ MDF2_NEXTNEWBOARDASK;
				prefs.flags2 |= MDF2_NEXTNEWBOARD;
				break;

			case 2:
				prefs.flags2 |= ( MDF2_NEXTNEWBOARDASK | MDF2_NEXTNEWBOARD );
				break;
		}

		if( ogreValue( ogw, BW_HOLDOWNMAILS ) )
			prefs.flags2 |= MDF2_HOLDOWNMAILS;
		else
			prefs.flags2 &= ~ MDF2_HOLDOWNMAILS;

		if( ogreValue( ogw, BW_HARDDEL ) )
			prefs.flags2 |= MDF2_HARDDEL;
		else
			prefs.flags2 &= ~ MDF2_HARDDEL;


		if( ogreValue( ogw, BW_OWNMAILSNEW ) )
			prefs.flags2 |= MDF2_OWNMAILSNEW;
		else
			prefs.flags2 &= ~ MDF2_OWNMAILSNEW;

		prefs.reader_tabsize = ogreValue( ogw, BW_READERTABSIZE );
		prefs.sortinwin_small = ogreValue( ogw, BW_SORTINWINSMALL );
		rinfo->ReqPos = prefs.reqpos = ogreValue( ogw, BW_REQPOS );
	}

	ogreExitWindow( ogw );
}

#define LC_OK 1

#define LC_NB 10
#define LC_PO 20
#define LC_OO 30
#define LC_PQ 40
#define LC_OQ 50
#define LC_CO 60

static char *ofile[] = {
	"md_orig.priv",
	"md_orig.pub",
	"md_qh.priv",
	"md_qh.pub",
	"microdot.cookies"
};

void dolanguagecfg( void )
{
	struct ogwin *ogw;
	struct Window *iw;
	struct IntuiMessage *im;
	int Done = FALSE;
	int c, d;
	char name[ 64 ];

	ogw = ogreInitWindow( scr, 0, 0, "Sprachen" );

	ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );

	for( c = 0; c < 7; c++ )
	{
		ogreAddString( ogw, c, 0, "Sprache:", LC_NB + c, &prefs.langnames[ c * 30 ], 10, 30 );
		ogreAddButton( ogw, c, 0, "Ö.Origin", LC_OO + c );
		ogreAddButton( ogw, c, 0, "P.Origin", LC_PO + c );
		ogreAddButton( ogw, c, 0, "Ö.QHeader", LC_OQ + c );
		ogreAddButton( ogw, c, 0, "P.QHeader", LC_PQ + c );
		ogreAddButton( ogw, c, 0, "Cookies", LC_CO + c );
	}

	ogreAddGroup( ogw, 1, OGFRAME_NONE, NULL );
	ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", LC_OK );
	ogreAddHelp( ogw, 0 );

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

	while( !Done )
	{
		im = ogreWaitIM( ogw );

		if( im->Class == IDCMP_GADGETHELP)
			showguidenum( "langwin_gads", im->Code );
		else if( im->Class == IDCMP_GADGETUP )
		{
			if( im->Code == LC_OK )
			{
				Done = 2;
				break;
			}
			else
			{
				c = im->Code - 20;
				if( c >= 0 )
				{
					ogreLockWindow( ogw );
					d = c % 10;
					c = c / 10;

					if( d )
						sprintf( name, "%s.%ld", ofile[ c ], d );
					else
						sprintf( name, "%s", ofile[ c ] );
					pushhomedir();
					calleditor( name );
					popdir();
					ogreUnlockWindow( ogw );
				}
			}
		}
		ogreIMReply( ogw, im );
	}

	for( c = 0; c < 7; c++ )
		ogreCopyStringValue( ogw, LC_NB + c, &prefs.langnames[ c * 30 ] );

	ogreExitWindow( ogw );
}
