var
  bgIndex,bgCount:integer;
  lstSkins:TStrings;
  
procedure RefreshPreview;
begin
  BeginUpdate;
  
  if bgindex<lstSkins.count then
  begin
    imgbg.FileName:=WidgetPath+lstSkins.strings[bgIndex]+'\back.png';
    lblIndex.caption:=inttostr(bgIndex+1)+'/'+inttostr(bgCount);
  end;
  EndUpdate;
end;

//读取配置
procedure InitIni;
begin
  chkSmooth.checked:=GetSettingInt('Smooth',1);
  lstSkins.text:=GetPathList(WidgetPath);
  bgCount:=lstSkins.count;
  bgIndex:=GetSettingInt('bgIndex',0);
  RefreshPreview;
end;

//保存配置
procedure SaveIni;
begin
  SetSettingInt('Smooth',chkSmooth.checked);
  SetSettingInt('bgIndex',bgIndex);
  if bgindex<lstSkins.count then
    SetSetting('bg',lstSkins.strings[bgIndex]);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  lstSkins:=TStringList.create;
  Beginupdate;
  InitIni;
  Endupdate;
end;

//--- 按下设置窗口的应用按钮时，触发此事件 ---
procedure OnSettingApply;
begin
  SaveIni;
end;

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