#include "camulet.h" //use MSVC wrapper directives for use with standard namespace //#include //included by "console.h" and "am_io.h" #include #include #include //compile with amulet files: "console.cpp" & "console.h" for console output using namespace std; bool FileOpen = false ; Am_Object my_win; //define window to be global so callback functions have access Am_Object OpenOptionObject; //define amulet object to hold reference to File menu Open option object Am_Object CloseOptionObject;//define amulet object to hold reference to File menu Close option object //Define slot/part objects and register with amulet Am_Slot_Key MenuBarSlot = Am_Register_Slot_Name ("MenuBarSlot"); //Define File menu Open option formula for initialization Am_Define_Formula (bool, OpenOptionStatus) { OpenOptionObject = self ; //store reference to File menu Open option object return !FileOpen; } //Define File menu Close option formula for initialization Am_Define_Formula (bool, CloseOptionStatus) { CloseOptionObject = self; //store reference to File menu Close option object return FileOpen; } //Define callback function for File menu Open... option Am_Define_Method(Am_Object_Method, void, my_open_do, (Am_Object self)) { cout << endl << "my_open_do() called" << endl << flush; //call to driver() to open file FileOpen = true ; //store Open option status self.Set(Am_ACTIVE, false); //set self (i.e., File menu Open option) to inactive CloseOptionObject.Set(Am_ACTIVE, true); //use stored reference to Close option to set it to active } //Define callback function for File menu Save As... option Am_Define_Method(Am_Object_Method, void, my_saveas_do, (Am_Object self)) { cout << endl << "my_saveas_do() called" << endl << flush; } //Define callback function for File menu Close option Am_Define_Method(Am_Object_Method, void, my_close_do, (Am_Object self)) { cout << endl << "my_close_do() called" << endl << flush; //call to driver() to close file FileOpen = false; //store Open option status self.Set(Am_ACTIVE, false); //set self (i.e., File menu Close option) to inactive OpenOptionObject.Set(Am_ACTIVE, true); //use stored reference to Open option to set it to active } void InitMenus (Am_Object& my_menu_bar); int main (void) { Am_Initialize (); //Initialize Amulet //Create an Amulet Window my_win = Am_Window.Create ("my_win") .Set (Am_LEFT, 20) .Set (Am_TOP, 50) .Set (Am_WIDTH, 500) .Set (Am_HEIGHT, 500) .Set (Am_TITLE, "My Window"); Am_Object my_menu_bar; InitMenus (my_menu_bar); my_win.Add_Part(MenuBarSlot, my_menu_bar); Am_Screen.Add_Part (my_win); Am_Main_Event_Loop (); Am_Cleanup (); return 0; } void InitMenus (Am_Object& my_menu_bar) { my_menu_bar = Am_Menu_Bar.Create("my_menu_bar") .Set(Am_FILL_STYLE, Am_Motif_Gray) .Set(Am_ITEMS, Am_Value_List () .Add (Am_Command.Create("File_Command") .Set(Am_LABEL, "File") .Set(Am_IMPLEMENTATION_PARENT, true) //not undoable //File menu has no callback Fn .Set(Am_ITEMS, Am_Value_List () .Add (Am_Command.Create("New_Command") .Set(Am_LABEL, "New...") .Set(Am_ACCELERATOR, "^n") .Set(Am_ACTIVE, false) .Set(Am_IMPLEMENTATION_PARENT, true) ) //not undoable //New option has no callback Fn .Add (Am_Command.Create("Open_Command") .Set(Am_LABEL, "Open...") .Set(Am_ACCELERATOR, "^o") .Set(Am_ACTIVE, OpenOptionStatus) //call Open option fomula to initialize .Set(Am_DO_METHOD, my_open_do)) //callback Fn for Open option .Add (Am_Menu_Line_Command.Create("my menu line")) //menu spacer line .Add (Am_Command.Create("Save_Command") .Set(Am_LABEL, "Save") .Set(Am_ACCELERATOR, "^s") .Set(Am_ACTIVE, false) .Set(Am_IMPLEMENTATION_PARENT, true) ) //not undoable //Save option has no callback Fn .Add (Am_Command.Create("Save_As_Command") .Set(Am_LABEL, "Save As...") .Set(Am_ACCELERATOR, "^a") .Set(Am_ACTIVE, false) .Set(Am_DO_METHOD, my_saveas_do)) //callback Fn for Save As... option .Add (Am_Command.Create("Close_Command") .Set(Am_LABEL, "Close") .Set(Am_ACCELERATOR, "^w") .Set(Am_ACTIVE, CloseOptionStatus) //call Close option fomula to initialize .Set(Am_DO_METHOD, my_close_do)) //callback Fn for Close option .Add (Am_Menu_Line_Command.Create("my menu line")) //menu spacer line .Add (Am_Quit_No_Ask_Command.Create() ) //Amulet Quit FN callback ) ) ) ; } // InitMenus