// sample amulet program to display a main window and active menu
//
// hussein suleman
// july 2000

#include <amulet.h>

// global Amulet definitions/declarations 

Am_Object MainWindow;   // main window object

char label[10][6];      // labels for text elements on window

// Amulet callbacks

Am_Define_Method (Am_Object_Method, void, open_add_dialog, (Am_Object cmd)) 
{
   Am_Beep ();
}

Am_Define_Method (Am_Object_Method, void, open_delete_dialog, (Am_Object cmd))
{
   Am_Slot_Key TextLine = Am_Register_Slot_Name ("text3");
	MainWindow.Set_Part (TextLine, Am_Text.Create ("text3")
			.Set (Am_LEFT, 10)
			.Set (Am_TOP, 130)
			.Set (Am_TEXT, "another line")
   );
}

// main program body

int main ()
{
   // initialize Amulet system
   Am_Initialize ();

   // create main window
	MainWindow = Am_Window.Create ("Student Information Database")
		.Set (Am_LEFT, 20)
		.Set (Am_TOP, 50)
		.Set (Am_WIDTH, 500)
		.Set (Am_HEIGHT, 300)
		.Set (Am_TITLE, "Student Information Database");

   // create menu bar 
   MainWindow.Add_Part (Am_Menu_Bar.Create ()
		.Set (Am_ITEMS, Am_Value_List ()
		   .Add (Am_Command.Create ("File")
	         .Set (Am_IMPLEMENTATION_PARENT, true)
            .Set (Am_LABEL, "File")
            .Set (Am_ITEMS, Am_Value_List ()
               .Add ("Open")
               .Add (Am_Menu_Line_Command.Create ("menuline"))
               .Add (Am_Quit_No_Ask_Command.Create ("Quit"))
            )
         )
         .Add (Am_Command.Create ("Edit")
	         .Set (Am_IMPLEMENTATION_PARENT, true)
            .Set (Am_LABEL, "Edit")
            .Set (Am_ITEMS, Am_Value_List ()
               .Add (Am_Command.Create ("Add Student")
						.Set (Am_LABEL, "Add Student")
						.Set (Am_DO_METHOD, open_add_dialog)
					)
               .Add (Am_Command.Create ("Delete Student")
						.Set (Am_LABEL, "Delete Student")
						.Set (Am_DO_METHOD, open_delete_dialog)
					)
            )
			)
		)
	);

   // add headings
   MainWindow.Add_Part (Am_Text.Create ()
		.Set (Am_LEFT, 10)
		.Set (Am_TOP, 30)
		.Set (Am_TEXT, "Name                                     SSN")
	);

   // create display of student data
   for ( int j=0; j<10; j++ )
   {
      strcpy (label[j], "text0");
      label[j][4] += j;
   }
	for ( int i=0; i<10; i++ )
	{
      Am_Slot_Key TextLine = Am_Register_Slot_Name (label[i]);
		MainWindow.Add_Part (TextLine, Am_Text.Create (label[i])
			.Set (Am_LEFT, 10)
			.Set (Am_TOP, 70+(i*20))
			.Set (Am_TEXT, label[i])
      );
	}

   // add all windows to screen
   Am_Screen.Add_Part (MainWindow);

	Am_Main_Event_Loop ();
  	
   Am_Cleanup ();

   return 0;
}
