Noeud « Next »: , Noeud « Previous »: Installation, Noeud « Up »: Top

2 Using GTKAda Wrapper

To use GTKAda Wrapper, you must add a with clause to the GTKAda_Wrapper package.

The following example gives the source code of an application that builds an empty windows, waits for a mouse click and then exits. The file name has to be necessarily empty_window.adb:

--  This example, creates an empty default main window then exits

with Gtkada_Wrapper; use Gtkada_Wrapper;

with Ada.Text_IO;

procedure Empty_Window is
   X      : Float;
   Y      : Float;
   Button : Natural;
   --  Create the graphic window


   --  Wait for the mouse click

   Get_Mouse_Pointer (X, Y, Button);

   --  Display the properties of the given click

   Ada.Text_IO.Put_Line ("Got Click:");
   Ada.Text_IO.Put_Line ("   X      = " & X'Img);
   Ada.Text_IO.Put_Line ("   Y      = " & Y'Img);
   Ada.Text_IO.Put_Line ("   Button = " & Button'Img);

   --  Destroy the graphic window

end Empty_Window;

You must also use the GNAT project files to compile your application. This makes the application build easy and encapsulates the complexity of the building process (fetching the necessary include files and libraries).

The following example gives the code of the project file relative to the empty_window.adb. The file name can have a name different from the source name. But it must have necessarily the .gpr extension and mut be coherent with the package name givent in the file. In our case, the project file name is empty.gpr

with "/full/or/relative/path/to/gtkada_wrapper.gpr";

--  In the case you installed GTKAda Wrapper in the same path as GNAT,
--  you can give simply:
--  with "gtkada_wrapper";

project Empty is
   for main use ("empty_window.adb");
end Empty;

As mentioned in the project file code. If you installed GTKAda Wrapper in a location different from the GNAT compiler location, you must indicate event the fill path to gtkada_wrapper.gpr or the path to this file relatively to the path of your project file. However, if you installed GTKAda Wrapper in the same location as the GNAT compiler, you can indicate simply the name (without even the suffix) of the GTKAda Wrapper project file.

Finally, compile you example by issuing:

 % gnatmake -P empty.gpr

If you followed all the steps given above you should obtain an executable named empty_window that you can run.