#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; Am_Object my_win; //define window to be global so callback functions have access //Define slot/part objects and register with amulet Am_Slot_Key OpenFileLabel = Am_Register_Slot_Name ("OpenFileLabel"); Am_Slot_Key OpenFileField = Am_Register_Slot_Name ("OpenFileField"); Am_Slot_Key OpenButton = Am_Register_Slot_Name ("OpenButton"); Am_Slot_Key ReadFile = Am_Register_Slot_Name ("ReadFile"); //Define callback function for Open File button Am_Define_Method(Am_Object_Method, void, OpenButton_do, (Am_Object self)) { cout << endl << "OpenButton_do() called" << endl << flush; //make the input text field visible - get the ReadFile object and set its Am_VISIBLE flag my_win.Get_Object(ReadFile).Set(Am_VISIBLE, true); } //Define callback function for ReadFile text inpuit field Am_Define_Method(Am_Object_Method, void, ReadFile_do, (Am_Object self)) { cout << endl << "ReadFile_do() called" << endl << flush; //change OpenFileField text to entered filename //get the ReadFile text input object and get its Am_VALUE //Am_String InFileName = my_win.Get_Object(ReadFile).Get(Am_VALUE); Am_String InFileName = self.Get(Am_VALUE); //equivalent to preceding commented line //get the OpenFileField object and set its Am_Text value my_win.Get_Object(OpenFileField).Set(Am_TEXT, InFileName); //hide the text input box my_win.Get_Object(ReadFile).Set(Am_VISIBLE, false); //convert entered Am_String to string object char* fstr = InFileName ; string filestring(fstr); cout << "Entered file name: " << filestring.c_str() << endl << flush; } void InitMenus (Am_Object& my_menu_bar); int main (void) { Am_Initialize (); //Initialize Amulet my_win = Am_Window.Create ("my_win") //Create an Amulet Window .Set (Am_LEFT, 20) .Set (Am_TOP, 50) .Set (Am_WIDTH, 500) .Set (Am_HEIGHT, 500) .Set (Am_TITLE, "My Window"); //add the OpenFileLabel label & OpenFileField objects to the window my_win.Add_Part(OpenFileLabel, Am_Text.Create("OpenFileLabel") .Set(Am_LEFT, 175) .Set(Am_TOP, 45) .Set(Am_WIDTH, 42) .Set(Am_HEIGHT, 14) .Set(Am_TEXT, "File:") .Set(Am_LINE_STYLE, Am_Black) .Set(Am_FILL_STYLE, Am_No_Style) ) .Add_Part(OpenFileField, Am_Text.Create("OpenFileField") .Set(Am_LEFT, 225) .Set(Am_TOP, 45) .Set(Am_WIDTH, 119) .Set(Am_HEIGHT, 14) .Set(Am_TEXT, "* no open file *") .Set(Am_LINE_STYLE, Am_Black) .Set(Am_FILL_STYLE, Am_No_Style) ); //create & add the OpenButton object to the window my_win.Add_Part(OpenButton, Am_Button.Create("OpenButton") .Set(Am_LEFT, 10) .Set(Am_TOP, 37) .Set(Am_WIDTH, 130) .Set(Am_HEIGHT, 30) .Set(Am_FILL_STYLE, Am_Motif_Gray) .Get_Object(Am_COMMAND) .Set(Am_LABEL, "Open File...") .Set(Am_ACTIVE, true) .Set(Am_DO_METHOD, OpenButton_do) //button callback function .Get_Owner() //must identify button command object owner "OpenButton" when adding as a part ); //to my_win, otherwise Add_Part() will try & treat the owner as my_win //create & add the ReadFile text input field widget object to the window my_win.Add_Part(ReadFile, Am_Text_Input_Widget.Create("ReadFile") .Set(Am_VALUE, "filename.bam") //set default value .Set(Am_LEFT, 175) .Set(Am_TOP, 100) .Set(Am_WIDTH, 250) .Set(Am_HEIGHT, 25) .Set(Am_FILL_STYLE, Am_White) // .Set(Am_WANT_PENDING_DELETE, true) //double mouse click selects entire string for replacement .Set(Am_VISIBLE, false) .Get_Object(Am_COMMAND) .Set(Am_LABEL, "Enter Filename") .Set(Am_DO_METHOD, ReadFile_do) //callback Fn for ReadFile text input - executes on return key .Get_Owner() ) // .Add_Part(Am_Tab_To_Next_Widget_Interactor.Create()) //allows tabbing between input fields - unnecessary ; Am_Object my_menu_bar; InitMenus (my_menu_bar); my_win.Add_Part(my_menu_bar); Am_Screen.Add_Part (my_win); cout << endl << "Start Event Loop" << endl << flush ; 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_Quit_No_Ask_Command.Create() ) //Amulet Quit FN callback ) ) ) ; } // InitMenus