unit uNavPaneUtils;

interface

uses
  Forms, ImgList, ActnList, JvPageList, JvNavigationPane, Menus,
  Controls;

procedure PopulateNavPagePane(AParentControl : TWinControl;
  AMenuItem: TMenuItem; AImageList : TCustomImageList;
  AStyleManager : TJvNavPaneStyleManager); overload;
  
implementation

uses
  ComCtrls, Classes, Math, TBXDkPanels, StrUtils, SysUtils,
  ExtCtrls, Graphics, Dialogs;


procedure PopulateNavPagePane(AParentControl : TWinControl;
  AMenuItem: TMenuItem; AImageList : TCustomImageList;
  AStyleManager : TJvNavPaneStyleManager);
var
  ItemIndex : Integer;
  AHeight : Integer;
begin
  AHeight := 0;
  for ItemIndex := 0 to (AMenuItem.Count - 1) do
  begin
    if ((not AMenuItem[ItemIndex].IsLine)  // que no sea una línea separadora
         and (AMenuItem[ItemIndex].Count = 0)  // y que no sea el padre de un submenú
         and (AMenuItem[ItemIndex].Visible)) // y que sea una acción visible para el submenú
    then
      with TTBXLink.Create(Application) do
      begin
        Parent := AParentControl;//APanel;
        Align := alTop;
        ParentFont := True;
        Tag := AMenuItem[ItemIndex].Tag;
        Caption := AMenuItem[ItemIndex].Caption;
        Action := AMenuItem[ItemIndex].Action;
        Images := AImageList;
        ImageIndex := AMenuItem[ItemIndex].ImageIndex;
        if ItemIndex = 0 then
          Margins.Top := 15
        else
          Margins.Top := 6;
        Margins.Bottom := 6;
        Margins.Left := 10;
        Margins.Right := 10;
        Height := 18;
        Invalidate;
        AHeight := AHeight + Margins.Top + Margins.Bottom + Height; 
      end;
  end;
  AParentControl.Height := AHeight;
end;

end.
