unit uDataModuleBase;

interface

uses
  Controls, PngImageList, JvComponent, JvNavigationPane, TBXSwitcher,
  TBXOffice2003Theme, Classes, ImgList,
  DataAbstract_Intf, uDADataTable, JvAppStorage, JvAppRegistryStorage, cxintl,
  JvComponentBase, cxIntlPrintSys3;

type
  TdmBase = class(TDataModule)
    SmallImages: TPngImageList;
    StyleManager: TJvNavPaneStyleManager;
    TBXSwitcher: TTBXSwitcher;
    cxIntl: TcxIntl;
    cxIntlPrintSys31: TcxIntlPrintSys3;
    procedure DAClientDataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    FOnThemeChange: TNotifyEvent;
    procedure InitStyleManager;
    procedure OnTBXThemeChange(Sender: TObject);
    procedure LeerConfiguracion;
  public
    procedure SalvarConfiguracion;
    function DarVersion : String;
    property OnThemeChange: TNotifyEvent read FOnThemeChange write
            FOnThemeChange;
  end;

var
  dmBase: TdmBase;

implementation

{$R *.DFM}

uses
  uDataModuleConexion, Dialogs, TBX, TBXThemes, Forms, Windows,
  JclFileUtils, cxControls, SysUtils, uDataModuleConfiguracion;

{
*********************************** TdmBase ************************************
}
procedure TdmBase.DAClientDataModuleCreate(Sender: TObject);
begin
  dmConexion := TdmConexion.Create(NIL);
  dmConfiguracion := TdmConfiguracion.Create(NIL);

  TBXSwitcher.OnThemeChange := OnTBXThemeChange;
  TBXSetTheme('Office2003');

  LeerConfiguracion;
end;

procedure TdmBase.InitStyleManager;
begin
  if not USE_THEMES then
  begin
    TBXSwitcher.EnableXPStyles := False;
    StyleManager.Theme := nptStandard;
  end
  else begin
    TBXSwitcher.EnableXPStyles := True;
    with StyleManager do
    begin
      if CurrentTheme is TTBXOffice2003Theme then
      begin
        case GetOffice2003Scheme of
          osBlue      : Theme := nptXPBlue;
          osMetallic  : Theme := nptXPSilver;
          osGreen     : Theme := nptXPOlive;
          else
                        Theme := nptStandard;
        end;
      end;
    end;
  end;
end;


procedure TdmBase.LeerConfiguracion;
begin
  dmConfiguracion.LeerConfiguracion;
end;

procedure TdmBase.OnTBXThemeChange(Sender: TObject);
begin
  InitStyleManager;

  if Assigned(FOnThemeChange) then
    FOnThemeChange(Sender);
end;

procedure TdmBase.SalvarConfiguracion;
begin
  dmConfiguracion.SalvarConfiguracion;
end;

function TdmBase.DarVersion: String;
var
  Obj : TJclFileVersionInfo;
begin
  Obj := TJclFileVersionInfo.Create(Application.ExeName);
  try
    Result := 'v' + Obj.FileVersion;
  finally
    FreeAndNil(Obj);
  end;
end;

procedure TdmBase.DataModuleDestroy(Sender: TObject);
begin
  FreeANDNIL(dmConfiguracion);
  FreeAndNil(dmConexion);
end;

initialization
  dmBase := TdmBase.Create(NIL);

finalization
  dmBase.Free;

end.
