Creating a new Gui Widget package
-
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]
-
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.
-
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
This generates the code for creating the widget that will be
written when you compile a GUI. For the RAPID Tcl implementation,
Tcl_Helpers will be of use. 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 the widget's placement. Don't worry about actions
(e.g. a button push) yet, that comes later.
Display_Widget
This is Ada code that will display the widget from within RAPID
while you are editing a GUI. It uses Tcl.Ada.Tcl_Eval to evaluate
Tcl commands. 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. Tcl_Utilities has procedures that will help here.
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. Tcl_Utilities
will again be of help here.
Properties_Dialog_Name
Return the name of the dialog you designed.
Generate_Actions
Only widgets that have callbacks need to override this.
Links Ada commands the user wants executed with Tcl names. Use Tcl_Helpers.Generate_Command
to associate an Ada action with a Tcl command name. The Tcl command
name should be unique, and follow the rules for an Ada identifier, but
not begin with an uppercase letter.
Generate_Action_Bindings
For each call to Tcl_Helpers.Generate_Command above, put a
call to Tcl_Helpers.Generate_Command binding here. Use the same command
name.
Generate_Context_Clauses
Each Ada statement should be fully qualified (e.g. Mypackage.Callback1
instead of just Callback1). Calling Tcl_Helpers.Generate_With for
each action will generate the necessary with clauses so that you don't
have to add them to the autogenerated code.
Undisplay_Widget, Highlight, Unhighlight, Move_Highlight, Close_Properties
Should be able to inherit these unchanged.