Creating a new Gui Widget package


  1. Copy an old package to your new name:  For example, when creating Gui.Widget.Check_Button, I copied gui-widget-static.ad[bs] to gui-widget-check_button.ad[bs]
  2. In your new ads file, change the type declaration to have the attributes of your new widget.  The name, location and size of the widget will be inherited from Gui_Widget.  Also, change the package header and change all references from the old type to the new type in the procedure headers.
  3. In your adb file, you will reimplement all of the methods.  Following is a description of each method.
Read_Widget
Reads the information about a widget from a .gui file.  Implement by first doing a type-cast to the parent class and calling Read_Widget (to get the attributes shared by the parent).  Then, fill in the rest of the attributes by reading them from the file.  The File_Helpers package provides a Get_String procedure that may be helpful.
Write_Widget
Writes the information about a widget to a .gui file.  First, use Gui_Enum.IO.Put to write the name of the widget to the file.  Then, as above, call the Write_Widget method from the parent class to write the shared attributes.  Write the unique attributes to the file.  If an attribute contains spaces, enclosing it in quotes will allow the Read_Widget method to use File_Helpers.Get_String to read it in all at once.  If it also contains quotation marks, begin and end with quotation marks, and use File_Helpers.Put_String to write the attribute.  Always end with a line feed (i.e. use a Put_Line or New_Line).  Do not put any line feeds in the middle of the widget.
Generate_Widget_Creation
This generates the code for creating the widget that will be written when you compile a GUI.  You are writing Ada code that will be inside of the begin/end block of a procedure.  If you need to declare more variables, use a declare block.  After you have written code to generate the widget, call the parent method to generate code for things common to all widgets.  Be sure to attach actions, set colors, etc. after creating the widget
Generate_Widget_Context_Clause
Generates a with statement for the appropriate package in the Mcc.Tki hierarchy.
Generate_Widget_Declaration
Generates a variable declaration in the spec for this widget.
Generate_Action_Context_Clause
Generates a with statement for any actions associated with the widget.  For example, for a button, if when it is pushed, it calls File_Menu.New_Choice, then a with for "File_Menu" is generated by this method.
Display_Widget
This is Ada code that will display the widget from within RAPID while you are editing a GUI.  Do not implement any actions here (e.g., for a button, you do not want the button to do its action during editing, only when it is compiled).
Set_Properties
This method fills in the editing dialog box with the values from the widget.  Again, the parent method is used to fill in some of the values.  It also sets fields in each widget so that some of the work of setting and checking properties can be shared.  These fields point to the text entry widgets (or radio buttons or whatever) that are used to edit these values.
Check_Properties
This procedure validates the inputs.  As a convention, we highlight the first bad thing and set Ok to false.  The bell should be rung if there is an error, but do not do this unless this is a leaf in the inheritance tree (so that it doesn't get rung more than once).  The parent method checks shared properties.
Apply_Properties
Reads the values from the edit dialog and puts them in the record.  The parent method reads shared properties.
Generate_Widget_Font, Undisplay_Widget, Highlight, Unhighlight, Move_Highlight, Close_Properties
Should be able to inherit these unchanged.
 
Generate_Fill_Action
Writes out code that reads a variable to fill in the value of the widget (not all widgets have this).
Generate_Read_Action
Writes out code that reads the value currently in the widget to a variable (not all widgets have this).