const
  NoteCount=6;

var
  NoteIndex:integer;
  NoteNames,NoteHighlights;
  
procedure RefreshPreview;
begin
  xspfrm.beginupdate;
  if NoteIndex>=NoteCount then 
    NoteIndex:=NoteIndex mod NoteCount
  else if NoteIndex<0 then
    NoteIndex:=NoteIndex+NoteCount;
  imgPreview.FileName:=WidgetPath+'images\sticky_'+NoteNames[NoteIndex]+'_docked.png';
  lblNoteIndex.caption:=inttostr(NoteIndex+1)+'/'+inttostr(NoteCount);
  xspfrm.endupdate;
end;

procedure InitIni;
var
  s:string;
begin
  NoteIndex:=GetSetting('NoteIndex',0);
  shpColor.Color:=GetSettingInt('Color',$000000);
  shpColor.ColorTo:=shpColor.Color;
  s:=GetSetting('FontName','微软雅黑');
  if cbbFontName.Items.Indexof(s)>=0 then 
    cbbFontName.text:=s
  else
    cbbFontName.text:='宋体';
	edtFontSize.text:=GetSettingInt('FontSize',9);
  if NoteIndex<>0 then RefreshPreview;
end;

procedure SaveIni;
begin
  SetSetting('NoteIndex',NoteIndex);
  SetSetting('FontName',cbbFontName.text);
  SetSettingInt('FontSize',edtFontSize.text);
  SetSetting('Color',shpColor.Color);
end;

procedure OnSettingInit;
begin
  NoteNames:=['yellow', 'blue', 'green', 'pink', 'purple', 'white'];
  NoteCaption:=['黄色', '蓝色', '绿色', '粉红色', '紫色',  '白色'];
  Index:=0;
  BeginUpdate;
  cbbFontName.items.text:=screen.Fonts.text;
  InitIni;
  EndUpdate;
end;

//--- 按下设置窗口的确定按钮时，触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
var
  i:integer;
begin
  try
    i:=StrToInt(edtFontSize.text);
    if i>3 then
      result:=true
    else
    begin
      result:=false;
      showmsg('字体太小！');
    end;
  except
    result:=false;
    showmsg('无效的字体大小！');
  end;
  if result then SaveIni;
end;

procedure OnshpColorClick;
var
  dlgColor:TColorDialog;
begin
  dlgColor:=TColorDialog.create(WidgetSetting);
  try
    dlgColor.Color:=shpColor.Color;
    if dlgColor.Execute then
    begin
		  BeginUpdate;
      shpColor.Color:=dlgColor.Color;
  		shpColor.ColorTo:=shpColor.Color;
		  EndUpdate;
   end;
  finally
    dlgColor.free;
  end;
end;
