//读取配置
procedure InitIni;
var
  spath:string;
begin
  BeginUpdate; 
  spath:=WidgetPath+'images\Days\'+cbbDaySkin.text;
  cbbNormal.Items.text:=GetFileList(spath,'*.png',false,false,false);
  if cbbNormal.Items.count>0 then
  	for i:=0 to cbbNormal.Items.count-1 do
      cbbNormal.Items.strings[i]:=copy(cbbNormal.Items.strings[i],1,length(cbbNormal.Items.strings[i])-4);
  cbbWeekend.Items.text:=cbbNormal.Items.text;
  cbbHoliday.Items.text:=cbbNormal.Items.text;
  cbbEvent.Items.text:=cbbNormal.Items.text;
  
  cbbNormal.text:=GetSetting('NormalFile','白色');
  cbbWeekend.text:=GetSetting('WeekendFile','粉红');
  cbbEvent.text:=GetSetting('EventFile','红色');
  cbbHoliday.text:=GetSetting('HolidayFile','蓝色');
  if not FileExists(spath+cbbNormal.text+'.png') then cbbNormal.text:='白色';
  if not FileExists(spath+cbbWeekend.text+'.png') then cbbWeekend.text:='粉红';
  if not FileExists(spath+cbbEvent.text+'.png') then cbbEvent.text:='红色';
  if not FileExists(spath+cbbHoliday.text+'.png') then cbbHoliday.text:='蓝色';
  
  cbbToday.text:=GetSetting('TodayFile','Red');
  cbbMonth.text:=GetSetting('MonthFile','超粗黑');
  chkShowWeek.checked:=GetSettingBool('ShowWeek',false);
  cbbWeek.text:=GetSetting('WeekdaysFile','黑体');
  EndUpdate;
end;

//保存配置
procedure SaveIni;
begin
  SetSetting('DaySkin',cbbDaySkin.text);
  SetSetting('NormalFile',cbbNormal.text);
  SetSetting('WeekendFile',cbbWeekend.text);
  SetSetting('HolidayFile',cbbHoliday.text);
  SetSetting('EventFile',cbbEvent.text);

  SetSetting('TodayFile',cbbToday.text);
  SetSetting('MonthFile',cbbMonth.text);
  SetSettingBool('ShowWeek',chkShowWeek.checked);
  SetSetting('WeekdaysFile',cbbWeek.text);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  Beginupdate;
  cbbDaySkin.Items.text:=GetPathList(WidgetPath+'images\Days');
  cbbDaySkin.text:=GetSetting('DaySkin','Comic');

  cbbToday.Items.text:=GetFileList(WidgetPath+'images\Today\','*.png',false,false,false);
  if cbbToday.Items.count>0 then
  	for i:=0 to cbbToday.Items.count-1 do
      cbbToday.Items.strings[i]:=copy(cbbToday.Items.strings[i],1,length(cbbToday.Items.strings[i])-4);
  
  cbbMonth.Items.text:=GetFileList(WidgetPath+'images\Months\','*.png',false,false,false);
  if cbbMonth.Items.count>0 then
  	for i:=0 to cbbMonth.Items.count-1 do
      cbbMonth.Items.strings[i]:=copy(cbbMonth.Items.strings[i],1,length(cbbMonth.Items.strings[i])-4);
  
  cbbWeek.Items.text:=GetFileList(WidgetPath+'images\Weekdays\','*.png',false,false,false);
  if cbbWeek.Items.count>0 then
  	for i:=0 to cbbWeek.Items.count-1 do
      cbbWeek.Items.strings[i]:=copy(cbbWeek.Items.strings[i],1,length(cbbWeek.Items.strings[i])-4);
  
  InitIni;
  Endupdate;
  cbbDaySkin.OnSelect:='cbbDaySkinSelect';
end;

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

procedure cbbDaySkinSelect(Sender:TObject);
begin
  InitIni;
end;