-- $Date: 2004/03/08 10:42:42 $
-- $Revision: 1.9 $
-- $Author: jcrocholl $
-- $Hash: 7dbd9bb6d70a3c46eb0c8b17a75e9831 $

-- This file was automatically created with ado.php.
-- Manual changes will be lost when it is updated.

with Messages; use Messages;

package body Boxes.Staves is

   -- Constructor for instances.
   function Create
     return Stave_Box_Access -- The newly created stave box.
   is
      Result : Stave_Box_Access := new Stave_Box;
   begin
      Result.Measures := Measures_Lists.Create;
      return Result;
   end Create;

   -- Accessor to read the measures of a stave box.
   function Get_Measures
     (This : access Stave_Box)      -- The stave box to read from.
     return Measures_List_Access is -- The measures of that stave box.
   begin
      return This.Measures;
   end Get_Measures;

   procedure Add_Measure
     (This : access Stave_Box;         -- The stave box object instance.
      Add  : in Measure_Box_Access) is -- Add this measure.
   begin
      Measures_Lists.Push(This.Measures, Add);
   end Add_Measure;

   procedure Layout
     (This : access Stave_Box;   -- The stave box object instance.
      Font : access Font_Loader-- Use this font loader.
   is
      Cursor : Vector;

      use Measures_Lists;
      Measure : Measure_Box_Access;
   begin
      if not Quiet then Debug("preparing stave layout"); end if;

      Cursor := (0.0, 0.0);
      This.Minimum_Width := 0.0;
      This.Optimum_Width := 0.0;
      This.Bounds := (0.0, -200.0, 0.0, 200.0);

      Reset(This.Measures);
      while Next(This.Measures) loop
         Measure := Current(This.Measures);

         Layout(Measure, Font);
         Cursor.X := Cursor.X - Get_Left(Measure);
         Set_Center(Measure, Cursor);
         Cursor.X := Cursor.X + Get_Right(Measure);

         Estimate_Width(Measure);
         Add_Width(This, Measure);
         Max_Bounds(This, Measure);
      end loop;

      -- This.Bounds.Right := This.Bounds.Right;
      -- Debug("stave bounds: " & To_String(This.Bounds));
   end Layout;

   procedure Print
     (This   : access Stave_Box;          -- The stave box object instance.
      To     : access Printer'Class-- Render stave through this printer.
      Center : in Vector)                 -- Center of container.
   is
      use Measures_Lists;
   begin
      if not Quiet then Debug("printing measures"); end if;
      Reset(This.Measures);
      while Next(This.Measures) loop
         Print(Current(This.Measures), To, Center);
      end loop;
   end Print;

end Boxes.Staves;