#include <proto/dos.h>
#include <proto/gadtools.h>

#include "App.bh"

#include "Popdir.h"

void myputch( void );

static const char *centr[] = {
	"MUI",
	"3BCC",
	NULL
};

static const char *ce2[] = {
	"version",
	"3noversion",
	NULL
};

static const char *ce3[] = {
	"noverbose",
	"3verbose",
	NULL
};

static const char *ce4[] = {
	"noforcetrans",
	"3forcetrans",
	NULL
};

static const char *bclinese[] = {
	"no '#line's",
	"3'#line's",
	NULL
};


cleardata Method App::App() :
		MUIA_Application_Author, "Rafaî Mantiuk",
		MUIA_Application_Base, "BCCOPTS",
		MUIA_Application_Title, "BCCOpts",
		MUIA_Application_Version, "$VER: BCCOPTS 1.2 "__AMIGADATE__,
		MUIA_Application_Copyright, "Copyright (c)1997, Rafaî Mantiuk",
		MUIA_Application_Description, "Set options for BCC.",
		SubWindow, win = WindowObject,
			MUIA_Window_Title, "Set BCC options (GUI v1.2)",
			MUIA_Window_ID, MAKE_ID('M', 'A', 'I', 'N'),
			WindowContents, GroupObject,
				MUIA_Background, MUII_WindowBack,
				Child, GroupObject, 
					MUIA_Background, MUII_GroupBack,
					MUIA_Frame, MUIV_Frame_Group,
					MUIA_Group_Columns, 2,
					Child, GroupObject, 
						MUIA_FrameTitle, "Global",
						MUIA_Frame, MUIV_Frame_Group,
						Child, deftype = CycleObject,
							MUIA_Cycle_Entries, centr,
							MUIA_CycleChain, TRUE,
							MUIA_Background, MUII_TextBack,
						End,
						Child, HGroup,
							Child, Label2( "Tag base" ),
							Child, tagbase = StringObject,
								MUIA_Frame, MUIV_Frame_String,
								MUIA_CycleChain, TRUE,
								MUIA_String_MaxLen, 5,
								MUIA_String_Accept, "1234567890abcdefABCDEFnoe",
								MUIA_String_Contents, "none",
							End,
						End,
						Child, bclines = CycleObject,
							MUIA_Cycle_Entries, bclinese,
							MUIA_CycleChain, TRUE,
							MUIA_Background, MUII_TextBack,
						End,
					End,
					Child, GroupObject, 
						MUIA_FrameTitle, "Report",
						MUIA_Frame, MUIV_Frame_Group,
						Child, noversion = CycleObject,
							MUIA_Cycle_Entries, ce2,
							MUIA_CycleChain, TRUE,
							MUIA_Background, MUII_TextBack,
						End,
						Child, verbose = CycleObject,
							MUIA_Cycle_Entries, ce3,
							MUIA_CycleChain, TRUE,
							MUIA_Background, MUII_TextBack,
						End,
					End,
					Child, GroupObject, 
						MUIA_FrameTitle, "Include files dir",
						MUIA_Frame, MUIV_Frame_Group,
						Child, PopdirObject,
							MUIA_Popstring_String, incdir = StringObject,
								MUIA_Frame, MUIV_Frame_String,
								MUIA_CycleChain, TRUE,
								MUIA_String_MaxLen, 80,
								MUIA_String_Contents, "ENV:bcc/",
							End,
							MUIA_Popstring_Button, PopButton(MUII_PopFile),
						End,
					End,
					Child, GroupObject, 
						MUIA_FrameTitle, ".bh files",
						MUIA_Frame, MUIV_Frame_Group,
						Child, forcetrans = CycleObject,
							MUIA_Cycle_Entries, ce4,
							MUIA_CycleChain, TRUE,
							MUIA_Background, MUII_TextBack,
						End,
					End,
				End,
				Child, GroupObject,
					MUIA_Background, MUII_GroupBack,
					MUIA_FrameTitle, "Creators",
					MUIA_Frame, MUIV_Frame_Group,
					Child, createinitcl = KeyButton( "Create <initcl> files", 'i' ),
				End,
				Child, GroupObject,
					MUIA_Group_Horiz, TRUE,
					Child, savedef = KeyButton( "Save as default", 'd' ),
					Child, save = KeyButton( "Save", 's' ),
					Child, cancel = KeyButton( "Cancel", 'c' ),
				End,
			End,
			MUIA_Window_Menustrip, MenustripObject,
				MUIA_Family_Child, MenuObject,
					MUIA_Menu_Title, "Project",
					MUIA_Family_Child, maboutmui = MenuitemObject,
						MUIA_Menuitem_Title, "About MUI...",
					End,
					MUIA_Family_Child, MenuitemObject,
						MUIA_Menuitem_Title, NM_BARLABEL,
					End,
					MUIA_Family_Child, mquit = MenuitemObject,
						MUIA_Menuitem_Title, "Quit",
						MUIA_Menuitem_Shortcut, "Q",
					End,
				End,
			End,
		End
{


	win->_Notify( 
		MUIA_Window_CloseRequest, TRUE,
		obj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

	mquit->_Notify(
		MUIA_Menuitem_Trigger, MUIV_EveryTime,
		obj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

	maboutmui->_Notify(
		MUIA_Menuitem_Trigger, MUIV_EveryTime,
		obj, 2, MUIM_Application_AboutMUI, win );

	cancel->_Notify( 
		MUIA_Pressed, TRUE,
		obj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

	save->_Notify( 
		MUIA_Pressed, TRUE,
		obj, 2, MUIM_App_SaveOpts, 0 );

	savedef->_Notify( 
		MUIA_Pressed, TRUE,
		obj, 2, MUIM_App_SaveOpts, 1 );

	createinitcl->_Notify( 
		MUIA_Pressed, TRUE,
		obj, 1, MUIM_App_CreateInitcl );

	tagbase->_Notify(
		MUIA_String_Acknowledge, MUIV_EveryTime,
		obj, 2, MUIM_App_NewTagBase, MUIV_TriggerValue );
	

	obj->LoadOpts();

	win->Open = TRUE;

}

nodata Method App::CreateInitcl()
{
	obj->Application_Sleep = TRUE;

	Execute( "BCC initcl", 0, Output() );

	obj->Application_Sleep = FALSE;
}

Method App::NewTagBase( char *txt )
{
 char buf[6];
 short i;

	if( !*txt ) tagbase->Contents = "none";
	else 
	if( strlen( txt ) < 4 ) {
		strcpy( buf, txt );
		for( i = strlen( txt ); i < 4; i++ ) buf[i] = '0';
		buf[5] = 0;
		tagbase->Contents = buf;
	}

}
