unit uDMBase;

interface

uses
  Controls, SyncObjs, PngImageList, JvComponent, JvNavigationPane, TBXSwitcher,
  TBXOffice2003Theme, Classes, ImgList, SysUtils,
  DataAbstract4_Intf, uDADataTable, JvAppStorage, JvAppRegistryStorage, cxintl,
  JvComponentBase, cxIntlPrintSys3, JvLogFile, dxPSGlbl, dxPSUtl, dxPrnPg,
  dxBkgnd, dxWrap, dxPrnDev, dxPgsDlg, dxPSCore;

type
  TdmBase = class(TDataModule)
    SmallImages: TPngImageList;
    StyleManager: TJvNavPaneStyleManager;
    TBXSwitcher: TTBXSwitcher;
    JvLogFile: TJvLogFile;
    cxIntl: TcxIntl;
    cxIntlPrintSys3: TcxIntlPrintSys3;
    dxPrintStyleManager1: TdxPrintStyleManager;
    dxPrintStyleManager1Style1: TdxPSPrintStyle;
    procedure DAClientDataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    FOnThemeChange: TNotifyEvent;
    FEscribirLog : TCriticalSection;
    {procedure IniciarLog;
    procedure DetenerLog;}
    procedure InitStyleManager;
    procedure OnTBXThemeChange(Sender: TObject);
    procedure LeerConfiguracion;
  public
    {procedure EscribirLog(const AMensaje : String);}  
    procedure SalvarConfiguracion;
    property OnThemeChange: TNotifyEvent read FOnThemeChange write
            FOnThemeChange;
  end;

var
  dmBase: TdmBase = nil;

implementation

{$R *.DFM}

uses
  uDataModuleConexion, Dialogs, TBX, TBXThemes, Forms, Windows,
  JclFileUtils, cxControls, uDataModuleConfiguracion,
  SHFolder, uSistemaFunc, uAppInfoUtils;

{
*********************************** TdmBase ************************************
}
procedure TdmBase.DAClientDataModuleCreate(Sender: TObject);
begin
  //IniciarLog; <- NO SE USA

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

  LeerConfiguracion;
end;

{procedure TdmBase.IniciarLog;
var
  AIniFile : String;
begin
  inherited;
  FEscribirLog := TCriticalSection.Create;

  AIniFile := GetSpecialFolderPath(CSIDL_LOCAL_APPDATA); //[All Users]\Application Data
  AIniFile := AIniFile + PathDelim + GetAppName + PathDelim;

  if not DirectoryExists(AIniFile) then
    CreateDir(AIniFile);

  JvLogFile.Active := False;
  JvLogFile.FileName := AIniFile + 'ClientLog.txt';
  JvLogFile.AutoSave := True;
  JvLogFile.Active := True;
  JvLogFile.Clear;
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;

procedure TdmBase.DataModuleDestroy(Sender: TObject);
begin
  // DetenerLog; <- NO SE USA
end;

{procedure TdmBase.DetenerLog;
begin
  FreeAndNIL(FEscribirLog);
end;

procedure TdmBase.EscribirLog(const AMensaje: String);
begin
//  dxPrintStyleManager1Style1.PrinterPage.PageFooter.LeftTitle.Add(FEmpresaInformesBase);

  FEscribirLog.Acquire;
  try
    JvLogFile.Add(AMensaje);
  finally
    FEscribirLog.Release;
  end;
end;}

end.
