const
  Count=5;

var
  Index:integer;
  isCustomFile:boolean;
  CustomFile1,CustomFile2:string;

procedure OnPreviewClick;
var
  dlgOpen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.create(nil);
  try
    dlgOpen.FileName:=imgPreview.FileName;
    dlgOpen.DefaultExt:='.png';
    dlgOpen.Filter:='PNG图片|*.png';
    if dlgOpen.Execute then
    begin
      isCustomFile:=true;
      imgPreview.FileName:=dlgOpen.FileName;
    end;
  finally
    dlgOpen.free;
  end;
end;

procedure OnPreviewFullClick;
var
  dlgOpen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.create(nil);
  try
    dlgOpen.FileName:=imgPreviewFull.FileName;
    dlgOpen.DefaultExt:='.png';
    dlgOpen.Filter:='PNG图片|*.png';
    if dlgOpen.Execute then
    begin
      isCustomFile:=true;
      imgPreviewFull.FileName:=dlgOpen.FileName;
    end;
  finally
    dlgOpen.free;
  end;
end;

procedure lblPropertiesOnClick;
begin
  ShowRecycleBinProperty;
end;

procedure RefreshPreview;
begin
  xspfrm.beginupdate;
  if Index>=Count then 
    Index:=Index mod Count
  else if Index<0 then
    Index:=Index+Count;
  imgPreview.FileName:=WidgetPath+'images\'+inttostr(Index)+'.png';
  imgPreviewFull.FileName:=WidgetPath+'images\'+inttostr(Index)+'f.png';
  lblIndex.caption:=inttostr(Index+1)+'/'+inttostr(Count);
  isCustomFile:=false;
  xspfrm.endupdate;
end;

procedure InitIni;
begin
  Index:=GetSettingInt('Index',0);
  isCustomFile:=GetSettingInt('CustomFile',0)=1;
  if isCustomFile then
  begin
    CustomFile1:=GetSetting('CustomFile1','');
    CustomFile2:=GetSetting('CustomFile2','');
    imgPreview.FileName:=CustomFile1;
    imgPreviewFull.FileName:=CustomFile2;
  end
  else
  begin
    CustomFile1:='';
    CustomFile2:='';
  end;
  if Index<>0 then RefreshPreview;
end;

procedure SaveIni;
begin
  if isCustomFile then
  begin
    SetSetting('CustomFile',1);
    SetSetting('CustomFile1',imgPreview.FileName);
    SetSetting('CustomFile2',imgPreviewFull.FileName);
  end
  else
  begin
    SetSetting('Index',Index);
    SetSetting('CustomFile',0);
  end;
end;

procedure OnSettingInit;
begin
  Index:=0;
  xspfrm.beginupdate;
  InitIni;
  xspfrm.endupdate;
//  cbbTimeZone.OnSelect:='OnSelected';
end;

//--- 按下设置窗口的确定按钮时，触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
begin
  result:=true;
  SaveIni;
end;


