procedure GotoToday;
begin
  cal.date:=now;
end;

procedure WeatherChange;
begin
  xspfrm.beginupdate;
  cal.RefreshHintList;
  lblMonth.caption:=FormatDateTime('mmmm  ',cal.date)+GetWeatherInfo(0,'City')
  //lblw0.caption:=GetWeatherInfo(0,'tmplow')+'~'+GetWeatherInfo(0,'tmphigh')+'℃';
  lblw0.caption:=format('%s~%s℃ %s',[GetWeatherInfo(0,'tmplow'),GetWeatherInfo(0,'tmphigh'),GetWeatherInfo(0,'desc')]); 
  lblw1.caption:=GetWeatherInfo(1,'tmplow')+'/'+GetWeatherInfo(1,'tmphigh');
  lblw2.caption:=GetWeatherInfo(2,'tmplow')+'/'+GetWeatherInfo(2,'tmphigh');
  lblw3.caption:=GetWeatherInfo(3,'tmplow')+'/'+GetWeatherInfo(3,'tmphigh');
  lblw4.caption:=GetWeatherInfo(4,'tmplow')+'/'+GetWeatherInfo(4,'tmphigh');

  imgw0.Hint:=GetWeatherDayDesc(0);
  imgw1.Hint:=GetWeatherDayDesc(1);
  imgw2.Hint:=GetWeatherDayDesc(2);
  imgw3.Hint:=GetWeatherDayDesc(3);
  imgw4.Hint:=GetWeatherDayDesc(4);
  imgw0.FileName:=GetWeatherIconFile(0,'Default','');
  imgw1.FileName:=GetWeatherIconFile(1,'Default','am');
  imgw2.FileName:=GetWeatherIconFile(2,'Default','am');
  imgw3.FileName:=GetWeatherIconFile(3,'Default','am');
  imgw4.FileName:=GetWeatherIconFile(4,'Default','am');
  xspfrm.EndUpdate;
end;

procedure IncDate(value:integer);
begin
  //cal.date:=cal.date+value;
  cal.date:=incMonth(cal.date,value);
end;

procedure CalDateChange;
var
  y,m,d:word;
begin
  xspfrm.beginupdate;
  DecodeDate(Cal.Date,y,m,d);
  lblYear.Caption:=IntToStr(y);
  lblMonth.caption:=FormatDateTime('mmmm  ',cal.date)+GetWeatherInfo(0,'City')
  lblLunar.caption:=DateToDateCnStr(cal.date,'yyyyy(a)年mmmm月ddd');
  xspfrm.endupdate;
end;

//--- Widget初始化事件，当打开Widget时会触发此事件 ---
procedure OnWidgetInit;
begin
  BeginUpdate;
  cal.date:=now;
  //cal.showSolar:=false;
  CalDateChange;
 
  WeatherChange;
  EndUpdate;
  //xspfrm.update(true);
end;

//--- Widget停靠侧边栏事件，当停靠到侧边栏触发该事件   ---
procedure OnWidgetDock;
begin
	BeginUpdate;
  lblw0.left:=85;
	lblw0.top:=50;
	lblw1.visible:=False;
	lblw2.visible:=False;
	lblw3.visible:=False;
	lblw4.visible:=False;
	lblYear.left:=3;
	lblMonth.left:=3;
	lblLunar.left:=3;
	imgw0.left:=105;
	imgw0.top:=25;
	imgw0.width:=24;
	imgw0.height:=24;
	imgw1.visible:=False;
	imgw2.visible:=False;
	imgw3.visible:=False;
	imgw4.visible:=False;
	imgPrev.left:=100;
	imgNext.left:=115;
	imgRefresh.left:=116;
	imgbg.width:=135;
	imgbg.left:=2;
	Widget.Width:=140;
	cal.Width:=135;
	cal.ShowLunar:=False;
  cal.DayLunarWidth:=0;
	cal.DayWidth:=17;
	cal.ShortWeekCaption:=True;
	EndUpdate;
end;

//--- Widget取消停靠侧边栏事件，当取消停靠时触发该事件 ---
procedure OnWidgetUnDock;
begin
	BeginUpdate;
	lblw0.left:=120;
	lblw0.top:=52;
	lblw0.width:=60;
	lblw0.height:=32;
	lblw1.visible:=True;
	lblw2.visible:=True;
	lblw3.visible:=True;
	lblw4.visible:=True;
	lblYear.left:=10;
	lblMonth.left:=12;
	lblLunar.left:=12;
	imgw0.left:=120;
	imgw0.top:=2;
	imgw0.width:=60;
	imgw0.height:=60;
	imgw1.visible:=True;
	imgw2.visible:=True;
	imgw3.visible:=True;
	imgw4.visible:=True;
	imgPrev.left:=245;
	imgNext.left:=265;
	imgRefresh.left:=268;
	Widget.Width:=305;
	imgbg.width:=305;
	imgbg.left:=0;
	cal.width:=281;
	cal.ShowLunar:=True;
	cal.DayWidth:=17;
	cal.DayLunarWidth:=22;
	cal.ShortWeekCaption:=False;
	EndUpdate;
end;
//--- 刷新Widget天气信息，当天气成功刷新后会触发此事件 ---

procedure OnRefreshWidgetWeatherInfo;
begin
  WeatherChange;
end;

//--- 系统日期改变事件，当系统日期改变时会触发此事件 ---
procedure OnSystemDateChanged;
begin
  Cal.Date:=now;
end;
