var
	g_lstJobString:TStrings;
	g_lstPicBall:TStrings;//以下全部为维护可视控件的LIST
	{g_lstPicItem:TStrings;}
	g_lstJobLabel:TStrings;
	g_imgAdd:TxspImage;
	g_lstStrJobName:TStrings; //以下为分别保存任务信息的LIST
	g_lstStrJobDate:TStrings;
	g_lstStrJobPRI:TStrings;
	g_lstStrJobLevel:TStrings;
	g_lstStrJobDetail:TStrings;
	g_lstStrBeenDone:TStrings;
	g_lstIndexPos:TStrings;  //维护各个按钮的Index对于实际文件lstJobString中的位置
	g_iModifyFlag:Integer;
	g_iAddFlag:Integer;
	g_bShowBeenDone:Boolean;  //是否显示过期和已完成任务的状态位.
	g_lstJobSeq:TStrings;  //代表工作优先级次序的List，例如:内容为[2,6,5,1,3,4] 表示了第2条记录优先级最高，依次类推
	g_lblEmptyJobName:TxspLabel;
	g_iLastItemIndex:Integer;
  conDelimiter:string;  //不支持常量？
	conDataFilePath:string;

//释放图片资源
procedure freeAllImages;
var i:integer;
begin
	{释放List内存之前首先释放内部添加的Objects内存}
	for i:=g_lstPicBall.count-1 downto 0 do
	begin
		TxspImage(g_lstPicBall.Objects[i]).free;
		//TxspImage(g_lstPicItem.Objects[i]).free;
		TxspLabel(g_lstJobLabel.Objects[i]).free;
	end;
end;

//当widget成Dock状态时触发此事件,执行此函数内代码
procedure OnWidgetDock;
begin
  BeginUpdate;
	imgItem.width:=128;
  imgItem.left:=5;
  widget.width:=142;
  imgEdit.left:=100;
  imgDelete.left:=115;
  g_imgAdd.left:=92;
  for i:=g_lstPicBall.count-1 downto 0 do
	begin
		TxspImage(g_lstPicBall.Objects[i]).left:=8;
    TxspLabel(g_lstJobLabel.Objects[i]).width:=100;
  end;
  imgItem.NeedRefresh:=True;
  EndUpDateAll;
end;

procedure OnWidgetUnDock;
begin
  BeginUpdate
  imgItem.width:=161;
  imgItem.left:=0;
  widget.width:=175;
  imgEdit.left:=125;
  imgDelete.left:=140;
  g_imgAdd.left:=120;
  for i:=g_lstPicBall.count-1 downto 0 do
	begin
		TxspImage(g_lstPicBall.Objects[i]).left:=5;
    TxspLabel(g_lstJobLabel.Objects[i]).width:=140;
  end;
  imgItem.NeedRefresh:=True;
  EndUpDateAll;
end;

//确认窗口代码
function myShowMsgBox(caption,msg):boolean;
var
	fm:TFrom;
	Label0:TLabel;
	Btn0,Btn1:TButton;
begin
  fm := TForm.create(widget);
  fm.Caption := caption;
  fm.Width := 340;
  fm.Height := 110;
  fm.BorderStyle := bsToolWindow;
  fm.Position := poDesktopCenter;
  fm.font.name := '宋体';
  fm.font.size := 9;
  fm.FormStyle := 3;    //窗口顶端显示

  //------文本 Label0
  Label0 :=  TLabel.Create( fm );
  Label0.Parent := fm;
  Label0.Left := 16;
  Label0.top := 14;
  Label0.width := 54;
  Label0.height := 12;
  Label0.AutoSize := -1;
  Label0.WordWrap := 0;
  Label0.Caption := msg;

  //------按钮 Btn0
  Btn0 :=  TButton.Create( fm );
  Btn0.Parent := fm;
  Btn0.Left := 90;
  Btn0.top := 45;
  Btn0.width := 75;
  Btn0.height := 25;
  Btn0.Caption := '确定';
  Btn0.ModalResult := 1;
  //Btn0.onclick := 'Btn0Click';

  //------按钮 Btn1
  Btn1 :=  TButton.Create( fm );
  Btn1.Parent := fm;
  Btn1.Left := 170;
  Btn1.top := 45;
  Btn1.width := 75;
  Btn1.height := 25;
  Btn1.Caption := '取消';
  Btn1.ModalResult := 2;

  //----显示配置窗口----
  if fm.ShowModal = mrOk then
  begin
    result := true;
  end
  else
    result := false;
  fm.free;
end;

//当鼠标移入imgItem时
procedure ItemMouseEnter(sender);
begin
	BeginUpdate;
	//TxspImage(g_lstPicItem.Objects[g_iLastItemIndex]).needRefresh:=True;
  imgItem.needRefresh:=True;
	g_iLastItemIndex:=sender.tag;
	g_imgAdd.visible:=True;
	imgEdit.tag:=sender.tag;
	imgDelete.tag:=Sender.tag;
	imgEdit.Top:=Sender.Top+1;
	imgDelete.Top:=Sender.Top+1;
	imgEdit.visible:=True;
	imgDelete.visible:=True;
	imgEdit.BringFront;
	imgDelete.BringFront;
	g_imgAdd.BringFront;
	EndUpdate;
end;

procedure ItemMouseLeave(sender);
begin
	BeginUpdate;
	//imgEdit.visible:=True;
	//imgDelete.visible:=True;
	EndUpdate;
end;

//以下过程显示一个工作信息
procedure ShowAJobInfo(aTag:Integer;aJobName:string;aJobPRI:string;aDoneFlag:string;iTop:integer;aJobDetail:string);//分别对应名称，优先级
var
	imgBall,imgEdit,imgDelete:TxspImage;
	lblJobName:TxspLabel;
	iTopValue:Integer;
	sTmpJobName,sMmoDelimiter:string;
begin
  iTopValue:=iTop;
  sMmoDelimiter:='*!~';
	sTmpJobName:=aJobName;  //这里将较长的标题转换为带省略号的。
	if Length(sTmpJobName)>14 then
	  sTmpJobName:=Copy(sTmpJobName,0,14)+'...';
	BeginUpDate;
	{创建ball图片}
	imgBall:=TxspImage.Create(widget);
	imgBall.parent:=Widget;
	case aJobPRI of
		'4':imgBall.FileName:=AppPath+'Widgets\what_to_do\ball\0.png';
		'3':imgBall.FileName:=AppPath+'Widgets\what_to_do\ball\1.png';
		'2':imgBall.FileName:=AppPath+'Widgets\what_to_do\ball\2.png';
		'1':imgBall.FileName:=AppPath+'Widgets\what_to_do\ball\3.png';
		'0':imgBall.FileName:=AppPath+'Widgets\what_to_do\ball\4.png';
	end;
	imgBall.top:=iTopValue+2;
	imgBall.Left:=5;
	imgBall.width:=16;
	imgBall.height:=16;
	imgBall.tag:=aTag;
	g_lstPicBall.addObject('',imgBall);
	{创建工作标题label}
	lblJobName:=TxspLabel.Create(widget);
	lblJobName.parent:=Widget;
	lblJobName.Caption:=sTmpJobName;
	lblJobName.fontstyle.font.size:=10;
	lblJobName.fontstyle.font.name := '宋体';
	//lblJobName.fontStyle.font.color:=$D4D0C8;
	lblJobName.fontStyle.ShadowStyle.Opacity:=100;
	lblJobName.fontStyle.ShadowStyle.Blur:=1;
	lblJobName.fontStyle.ShadowStyle.Enabled:=True;   //给文字加上阴影
	lblJobName.fontStyle.ShadowStyle.color:=$000000;
	case aDoneFlag of
		'0':lblJobName.fontstyle.font.style:=[];
		'1':lblJobName.fontstyle.font.style:=[3];//打上下划线
	end;
	case aJobPRI of   //按优先级给文字颜色赋值
		'4':lblJobName.fontStyle.font.color:=$3741BE;
		'3':lblJobName.fontStyle.font.color:=$3D92C7;
		'2':lblJobName.fontStyle.font.color:=$48C682;
		'1':lblJobName.fontStyle.font.color:=$F4DA78;
		'0':lblJobName.fontStyle.font.color:=$B0B0B0;
	end;	
	lblJobName.top:=iTopValue+3;
	lblJobName.Left:=20;
	lblJobName.width:=140;
	lblJobName.height:=20;
	lblJobName.tag:=aTag;
	lblJobName.onMouseEnter:='ItemMouseEnter';
	lblJobName.onMouseLeave:='ItemMouseLeave';
	lblJobName.OnDblClick:='imgEditOnClick';
	
	lblJobName.hint:=' 任务：'+aJobName+#13#10+StrToStrings(aJobDetail,sMmoDelimiter);
	g_lstJobLabel.addObject('',lblJobName);
	EndUpdate;
end;

procedure ShowEmptyJob;  //该过程显示一个空任务信息(当无任务任务显示时)
begin
	//提示无任务的Label
	g_lblEmptyJobName:=TxspLabel.create(Widget);
	g_lblEmptyJobName.top:=3;
	g_lblEmptyJobName.Caption:='休息一下！';
	g_lblEmptyJobName.fontstyle.font.size:=10;
	g_lblEmptyJobName.fontstyle.font.name := '宋体';
	g_lblEmptyJobName.fontStyle.font.color:=$FFFFFF;
	g_lblEmptyJobName.left:=20;
	g_lblEmptyJobName.width:=120;
	g_lblEmptyJobName.height:=120;
	g_lblEmptyJobName.visible:=False;
	g_lblEmptyJobName.Hint:='无任务';
end;

//首先遍历一边，取出优先级的高低次序，按照PRI+Level算出总优先级高低，排序后按照排列的位置定出高度
procedure GetJobSequence;
var
	i,j,m,n,iMax,iseq:integer;
	iTmpPRI,iTmpLevel,iTmpBeenDone:Integer;
  lstTmpStr,lstJobContent,lstTmpJobLevel:TStrings;
begin
	Try
		iMax:=-100;
		g_lstJobSeq.Clear;  
		imgEdit.visible:=False;
		imgDelete.visible:=False;  //重新刷新之前先隐藏两个图片
		lstTmpStr:=TStringList.Create;
		lstTmpJobLevel:=TStringList.create;	
		lstJobContent:=TStringList.Create;
		if FileExists(conDataFilePath) then
		  lstTmpStr.LoadFromFile(conDataFilePath);
		for i:=0 to lstTmpStr.Count-1 do
		begin
			lstJobContent.text:=StrToStrings(lstTmpStr.ValueFromIndex[i],conDelimiter);
			for j:=0 to lstJobContent.Count-1 do    //开始赋值
			begin
				case lstJobContent.Names[j] of        //这里只需要取出三项。
					'PRI':        iTmpPRI:=StrToInt(lstJobContent.ValueFromIndex[j]);
					'Level':      iTmpLevel:=StrToInt(lstJobContent.ValueFromIndex[j]);
					'BeenDone':	  iTmpBeenDone:=StrToInt(lstJobContent.ValueFromIndex[j]);
				end;
			end;
			if g_bShowBeenDone then  //若显示已经完成的
			begin
				lstTmpJobLevel.add(IntToStr(iTmpPRI+iTmpLevel));  //保存PRI+Level的值
			end else if iTmpBeenDone=0 then  //只显示未完成的
			begin
				lstTmpJobLevel.add(IntToStr(iTmpPRI+iTmpLevel));
			end;
		end;
		for n:=0 to lstTmpJobLevel.count-1 do
		begin
			for m:=0 to lstTmpJobLevel.count-1 do  //排序
			begin
				if StrToInt(lstTmpJobLevel.Strings[m])>iMax then
					begin
						iMax:=StrToInt(lstTmpJobLevel.Strings[m]);
						iseq:=m;
					end;
			end;
			iMax:=-100;
			lstTmpJobLevel.Strings[iseq]:=IntToStr(-100);  //去掉最大数
			g_lstJobSeq.add(IntToStr(iSeq));
		end;
		{至此把各个Index按照大小放在了g_lstJobSeq中}
		{for i:=0 to g_lstJobSeq.count-1 do
		begin
			ShowMsg(g_lstJobSeq.strings[i]);
		end;}
	finally
		lstTmpStr.free;
		lstJobContent.free;
		lstTmpJobLevel.free;
	end;
end;

//该过程读取用户数据文件
procedure GetJobInfo;
var 
	i,j,m,n,k:Integer;
	iCountNotDone:Integer;
	lstJobContent:TStrings;
	sJobName,sJobDate,sJobDetail,sJobPRI,sJobLevel,sBeenDone:string;
	iTop:Integer;
begin
	g_iLastItemIndex:=0;   //将上次保存的鼠标移入的图片Index重设为0
	iCountNotDone:=0;
  {为了第二次调用,首先释放所有已创建的IMAGE，再清空List}
	freeAllImages;
	g_lstJobString.Clear;
	g_lstPicBall.Clear;
	{g_lstPicItem.Clear;}
	g_lstJobLabel.Clear;
	g_lstStrJobName.Clear;
	g_lstStrJobDate.Clear;
	g_lstStrJobPRI.Clear;
	g_lstStrJobLevel.Clear;
	g_lstStrJobDetail.Clear;
	g_lstStrBeenDone.Clear;
	g_lstIndexPos.Clear;
	GetJobSequence;     //获取优先级次序
	Try
		BeginUpdate;
		lstJobContent:=TStringList.Create;
		if FileExists(conDataFilePath) then
  		g_lstJobString.LoadFromFile(conDataFilePath);
		for i:=0 to g_lstJobString.Count-1 do
		begin	
			lstJobContent.text:=StrToStrings(g_lstJobString.ValueFromIndex[i],conDelimiter);
			for j:=0 to lstJobContent.Count-1 do    //开始赋值
			begin
				case lstJobContent.Names[j] of
					'JobName':    sJobName:=lstJobContent.ValueFromIndex[j];
					'Date':       sJobDate:=lstJobContent.ValueFromIndex[j];
					'PRI':        sJobPRI:=lstJobContent.ValueFromIndex[j];
					'Level':      sJobLevel:=lstJobContent.ValueFromIndex[j];
					'DetailText': sJobDetail:=lstJobContent.ValueFromIndex[j];
					'BeenDone':	  sBeenDone:=lstJobContent.ValueFromIndex[j];
				end;
			end;
			if g_bShowBeenDone then  //若显示已经完成的(显示所有任务)
			begin
				g_lstIndexPos.add(IntToStr(i));
				iTop:=g_lstJobSeq.Indexof(IntToStr(i))*20;     //定义高度
				g_lstStrJobName.add(sJobName);
				g_lstStrJobDate.add(sJobDate);
				g_lstStrJobPRI.add(sJobPRI);
				g_lstStrJobLevel.add(sJobLevel);
				g_lstStrJobDetail.add(sJobDetail);
				g_lstStrBeenDone.add(sBeenDone);
				ShowAJobInfo(i,sJobName,sJobPRI,sBeenDone,iTop,sJobDetail);
			end else if sBeenDone='0' then //不显示已经完成的,只显示未完成的
			begin
				g_lstIndexPos.add(IntToStr(i));
				iTop:=g_lstJobSeq.Indexof(IntToStr(iCountNotDone))*20;     //定义高度
				g_lstStrJobName.add(sJobName);
				g_lstStrJobDate.add(sJobDate);
				g_lstStrJobPRI.add(sJobPRI);
				g_lstStrJobLevel.add(sJobLevel);
				g_lstStrJobDetail.add(sJobDetail);
				g_lstStrBeenDone.add(sBeenDone);
				ShowAJobInfo(iCountNotDone,sJobName,sJobPRI,sBeenDone,iTop,sJobDetail);
				Inc(iCountNotDone);
			end;
		end;
		if g_lstJobLabel.count>0 then
		begin
		  miClearAllJob.Enabled:=True;
			g_lblEmptyJobName.visible:=False;
			widget.height:=20*(g_lstJobSeq.count+1);//在此处设置Widget的高度
			g_imgAdd.Top:=20*g_lstJobSeq.count;
      imgItem.height:=20*g_lstJobSeq.count;
			//将所有创建的控件设置为可以移动Widget的
			for i:=g_lstJobLabel.count-1 downto 0 do
			begin
				SetAllowMoveWidget(TxspLabel(g_lstJobLabel.Objects[i]),True);
				SetAllowMoveWidget(TxspImage(g_lstPicBall.Objects[i]),True);
			end;
		end
		else
		begin
		  miClearAllJob.Enabled:=False;
			g_lblEmptyJobName.visible:=True;
			widget.height:=40;//在此处设置Widget的高度
			//隐藏修改和增加的图标
			imgEdit.visible:=False;
			imgDelete.visible:=False;
		  g_imgAdd.Top:=20;
		end;
    if Docking then
      OnWidgetDock else
      OnWidgetUndock;
    if Docking then RefreshSidebarOrder;
		EndUpdate;
	finally
		lstJobContent.free;
	end;
end;

//该过程保存StringList至文件
procedure SaveLstToFile;
begin
	 g_lstJobString.SavetoFile(conDataFilePath);
end;

//该过程修改一条记录
procedure ModifyRecord(lstRecord:TStringList;iIndex:integer);
var 
	sRecord:string;
begin
	sRecord:=StringsToStr(lstRecord.text,conDelimiter);
//	ShowMessage(sRecord);
	iIndex:=StrToInt(g_lstIndexPos.Strings[iIndex]);  //转换序号为实际Strings的位置
	g_lstJobString.strings[iIndex]:=sRecord;
	SaveLstToFile;
	//ShowMessage(inttostr(iIndex));
	GetJobInfo;
end;

//该过程添加一条记录
procedure AddRecord(lstRecord:TStringList);
var 
	 sRecord:string;
begin
	 sRecord:=StringsToStr(lstRecord.text,conDelimiter);  //组成一条记录
	 //ShowMessage(sRecord);
	 g_lstJobString.add(sRecord);
   SaveLstToFile;
	 GetJobInfo;        //刷新画面显示
end;

//该过程删除一条工作记录
procedure DeleteRecord(sender);
var 
	aTag:integer;
begin
	aTag:=sender.tag;
	//ShowMsg(inttostr(sender.tag));
	aTag:=StrToInt(g_lstIndexPos.Strings[aTag]);  //转换序号为实际Strings的位置
	//提示用户确认删除
	if myShowMsgBox('请确认','您将要删除一条工作记录') then
	begin
	//	ShowMessage(inttostr(aTag));
		g_lstJobString.Delete(aTag);
		SaveLstToFile;
		GetJobInfo;
	end;
end;
//该过程清空记录
procedure ClearAllOnClick(sender);
begin
  if myShowMsgBox('请确认','您将要删除所有工作记录！') then
	  begin
			g_lstJobString.clear;
			SaveLstToFile;
			GetJobInfo;
		end;
end;
//该过程导出记录到其它文件
procedure OutPutData;
var
	SaveDialog:TSaveDialog;
begin
  Try
		SaveDialog:=TSaveDialog.Create(widget);
		SaveDialog.defaultExt:='dat';
		SaveDialog.filter:='Dat文件|*.dat';
		if SaveDialog.execute then
		begin
			g_lstJobString.SaveToFile(SaveDialog.filename);
		end;
	finally
		saveDialog.free;
	end;
end;
//该过程导入记录到数据文件
procedure InputData;
var
  OpenDialog:TOpenDialog;
	tmpString:TStrings;
begin
  Try
	  tmpString:=TStringList.Create();
		OpenDialog:=TOpenDialog.create(widget);
		OpenDialog.filter:='Dat文件|*.dat';
		if OpenDialog.execute then
		begin
		  if myShowMsgBox('请确认','您将要覆盖所有工作记录') then
			begin
				tmpString.loadFromFile(OpenDialog.filename);
				if True then   //判断是否是准确格式的数据文件
				begin
					g_lstJobString.clear;
					g_lstJobString.text:=tmpString.text;
					SaveLstToFile;
					GetJobInfo;
				end;
			end;
		end;
	finally
		tmpString.Free;
		OpenDialog.Free;
	end;
end;

//该过程创建修改、增加任务的窗口并显示 p325
procedure AddModifyJobForm(sender;aflag:integer);
var
	newForm:TForm;
	lblJobName,lblDate,lblPRI,lblDetail,lblLevel:TLabel;
	edtJobName,edtDate:TEdit;
	cmboxPRI,cmboxLevel:TComboBox;
	mmoDetail:TMemo;
	mmoTextStr:string;
	sMmoDelimiter:string;   //自定义Memo分隔符
	btnConfirm,btnCancel:TButton;
	chkBeenDone:TCheckBox;
	iTag,i:Integer;
	lstRecord:TString;
begin
	iTag:=sender.Tag;
	sMmoDelimiter:='*!~';
	lstRecord:=TStringList.Create;
	BeginUpdate;
	{创建窗体}
	newForm:=TForm.Create(widget);
	newForm.Width := 390;
  newForm.Height := 285;                         
  newForm.BorderStyle := bsToolWindow;
  newForm.Position := poDesktopCenter;
  newForm.font.name := '宋体';
  newForm.font.size := 9;

	{任务名称Label}
	lblJobName:=TLabel.create(newForm);
	lblJobName.Parent:=newForm;
	lblJobName.left:=16;
	lblJobName.top:=18;
  lblJobName.width:=54;
  lblJobName.height:=12;
  lblJobName.AutoSize:=-1;
  lblJobName.WordWrap:=0;
  lblJobName.Caption:='任务名称:';
	{任务名称编辑Edit}
  edtJobName:=TEdit.create(newForm);
	edtJobName.Parent:=newForm;
	edtJobName.left:=82;
	edtJobName.top:=14;
	edtJobName.width:=190;
	edtJobName.height:=20;
	//对于Flag的判断置后，统一判断

	{日期Label}
	lblDate:=TLabel.create(newForm);
	lblDate.Parent:=newForm;
	lblDate.left:=16;
	lblDate.top:=47;
  lblDate.width:=54;
  lblDate.height:=12;
  lblDate.AutoSize:=-1;
  lblDate.WordWrap:=0;
  lblDate.Caption:='日期:';

	{日期Edit}
  edtDate:=TEdit.create(newForm);
	edtDate.Parent:=newForm;
	edtDate.left:=82;
	edtDate.top:=43;
	edtDate.width:=190;
	edtDate.height:=20;
	//对于Flag的判断置后，统一判断

 {优先级Label}
	lblPRI:=TLabel.create(newForm);
	lblPRI.Parent:=newForm;
	lblPRI.left:=16;
	lblPRI.top:=76;
  lblPRI.width:=54;
  lblPRI.height:=12;
  lblPRI.AutoSize:=-1;
  lblPRI.WordWrap:=0;
  lblPRI.Caption:='优先级别:';

	{优先级ComboBox}
  cmboxPRI :=TComboBox.Create(newForm);
  cmboxPRI.Parent:=newForm;
  cmboxPRI.Left:=82;
  cmboxPRI.top:=71;
  cmboxPRI.width:=194;
  cmboxPRI.height:=20;
  cmboxPRI.Style:=2;
  cmboxPRI.DropDownCount:=8;
  cmboxPRI.ItemIndex:=2;
  cmboxPRI.items.add('最低');
  cmboxPRI.items.add('较低');
  cmboxPRI.items.add('一般');
  cmboxPRI.items.add('较高');
  cmboxPRI.items.add('最高');
  cmboxPRI.Text := '一般';

	{紧急程度Lebel}
	lblLevel:=TLabel.Create(newForm);
	lblLevel.Parent:=newForm;
	lblLevel.left:=16;
	lblLevel.Top:=102;
	lblLevel.width:=54;
	lblLevel.height:=12;
	lblLevel.AutoSize:=-1;
	lblLevel.WordWrap:=0;
	lblLevel.Caption:='紧急程度:';

	{紧急程度ComboBox}
	cmboxLevel:=TComboBox.Create(newForm);
	cmboxLevel.Parent:=newForm;
	cmboxLevel.left:=82;
	cmboxLevel.top:=98;
	cmboxLevel.width:=194;
	cmboxLevel.height:=20;
	cmboxLevel.style:=2;
	cmboxLevel.DropDownCount:=5;
	cmboxLevel.ItemIndex:=1;
	cmboxLevel.items.add('时间充裕');
	cmboxLevel.items.add('时间正常');
	cmboxLevel.items.add('时间紧迫');
	cmboxLevel.Text:='时间正常';

	{详细信息lblDetail}
  lblDetail:=TLabel.Create(newForm);
  lblDetail.Parent:=newForm;
  lblDetail.Left:=16;
  lblDetail.top:=125;
  lblDetail.width:=54;
  lblDetail.height:=12;
  lblDetail.AutoSize:=-1;
  lblDetail.WordWrap:=0;
  lblDetail.Caption:='详细信息:';

	{文本框Memo}
  mmoDetail:=TMemo.Create(newForm);
  mmoDetail.Parent:=newForm;
  mmoDetail.Left:=16;
  mmoDetail.top:=140;
  mmoDetail.width:=356;
  mmoDetail.height:=100;
  mmoDetail.ScrollBars:=0;

	{确认按钮}
  btnConfirm:=TButton.Create(newForm);
  btnConfirm.Parent:=newForm;
  btnConfirm.Left:=296;
  btnConfirm.top:=13;
  btnConfirm.width:=75;
  btnConfirm.height:=25;
  btnConfirm.Caption:='确定';
  btnConfirm.ModalResult:=1;
//btnConfirm.onclick:='btnConfirmClick';

	{取消按钮}
  btnCancel:=TButton.Create(newForm);
  btnCancel.Parent:=newForm;
  btnCancel.Left:=296;
  btnCancel.top:=45;
  btnCancel.width:=75;
  btnCancel.height:=25;
  btnCancel.Caption:='取消';
  btnCancel.ModalResult:= 2;

	{标志是否完成的CheckBox}
	chkBeenDone:=TCheckBox.Create(newForm);
	chkBeenDone.Parent:=newForm;
	chkBeenDone.left:=296;
	chkBeenDone.Top:=100;
	chkBeenDone.width:=90;
	chkBeenDone.height:=17;
	chkBeenDone.Caption:='已经完成';
	chkBeenDone.checked:=False;

	{按照标志位设定窗口显示}
  if aflag=g_iAddFlag then
		begin
			newForm.caption:='增加新任务';
			edtDate.text:=FormatDateTime('yyyy-mm-dd',now); //增加新任务则取得当前时间
			edtJobName.text:='新任务';
			mmoDetail.Lines.Text:='';
			cmboxPRI.ItemIndex:=2;
			cmboxLevel.ItemIndex:=1;
			chkBeenDone.visible:=False;
		end
	  else if aflag=g_iModifyFlag then
		begin
	   {将自定义格式的MEMO文本读出,为了Memo文本Strings的保存不和下面的函数发生混淆}
  		mmoTextStr:=g_lstStrJobDetail.Strings[iTag];
  	  mmoTextStr:=StrToStrings(mmoTextStr,sMmoDelimiter);
			newForm.caption:='修改任务';
			edtDate.text:=g_lstStrJobDate.Strings[iTag];
			edtJobName.text:=g_lstStrJobName.Strings[iTag];
			mmoDetail.Lines.text:=mmoTextStr;
			cmboxPRI.ItemIndex:=StrToInt(g_lstStrJobPRI.Strings[iTag]);
			cmboxLevel.ItemIndex:=StrToInt(g_lstStrJobLevel.Strings[iTag])+1;
			if g_lstStrBeenDone.Strings[iTag]='0' then
				chkBeenDone.checked:=False
			else if g_lstStrBeenDone.Strings[iTag]='1' then
				chkBeenDone.checked:=True;
		end;
	EndUpdate;

	if newForm.ShowModal=mrOK then
	begin
		mmoTextStr:='';
		for i:=0 to mmoDetail.Lines.Count-1 do  //生成自定义的Momo文本保存格式
			mmoTextStr:=mmoTextStr+mmoDetail.Lines.Strings[i]+sMmoDelimiter;
		if aflag=g_iModifyFlag then  //修改记录并保存
		begin
			lstRecord.add('Record=JobName='+edtJobName.text);
			lstRecord.add('PRI='+IntToStr(cmboxPRI.ItemIndex));
			lstRecord.add('Date='+edtDate.text);
			lstRecord.add('DetailText='+mmoTextStr);
			if chkBeenDone.checked then
				lstRecord.add('BeenDone=1')
			else
				lstRecord.add('BeenDone=0');
			lstRecord.add('Level='+IntToStr(cmboxLevel.ItemIndex-1));
			ModifyRecord(lstRecord,iTag);		
		end else
		if aflag=g_iAddFlag then    //将新纪录加入
		begin
			lstRecord.add('Record=JobName='+edtJobName.text);
			lstRecord.add('PRI='+IntToStr(cmboxPRI.ItemIndex));
			lstRecord.add('Date='+edtDate.text);
			lstRecord.add('DetailText='+mmoTextStr);
			lstRecord.add('BeenDone=0');
			lstRecord.add('Level='+IntToStr(cmboxLevel.ItemIndex-1));
			AddRecord(lstRecord);	
		end;
	end;
	lstRecord.free;
end;

//新增工作图片点击
Procedure ImgAddOnClick(sender);
begin
	AddModifyJobForm(widget,g_iAddFlag);
end;

//修改图片点击
Procedure imgEditOnClick(sender);
begin
	//showmessage(IntToStr(sender.tag));
  AddModifyJobForm(sender,g_iModifyFlag);
end;

procedure ShowBeenDoneJob(sender);  //设置显示还是隐藏已经完成的任务
begin
	g_bShowBeenDone:=not g_bShowBeenDone;
	miConcealPassed.checked:=not g_bShowBeenDone;
	GetJobInfo;
end;


//--- Widget鼠标移入事件，当鼠标移入Widget时触发该事件 ---
procedure OnWidgetMouseEnter;
begin
	BeginUpdate;
	g_imgAdd.visible:=True;
	EndUpdate;
end;

//--- Widget鼠标移出事件，当鼠标移出Widget区域时触发此事件 ---
procedure OnWidgetMouseLeave;
begin
  BeginUpdate;
		g_imgAdd.visible:=False;
		imgEdit.visible:=False;
		imgDelete.visible:=False;
  EndUpdate;
end;

//--- Widget初始化事件，当Widget初始化时触发该事件 ---
procedure OnWidgetInit;
begin
  imgItem.ImageStyle.StretchStyle:=xsVertTitle;
  imgItem.AutoSize:=False;
	g_lstJobString:=TStringList.Create;
	g_lstPicBall:=TStringList.Create;
	{g_lstPicItem:=TStringList.Create;}
	g_lstJobLabel:=TStringList.Create;
	g_lstStrJobName:=TStringList.Create;
	g_lstStrJobDate:=TStringList.Create;
	g_lstStrJobPRI:=TStringList.Create;
	g_lstStrJobLevel:=TStringList.Create;
	g_lstStrJobDetail:=TStringList.Create;
	g_lstStrBeenDone:=TStringList.Create;
	g_lstIndexPos:=TStringList.Create;
	g_lstJobSeq:=TStringList.Create;
	g_bShowBeenDone:=GetSettingInt('ShowBeenDone',1)=1;  //读取设置
	miConcealPassed.checked:=Not g_bShowBeenDone;
	miConcealPassed.onclick:='ShowBeenDoneJob';          //Skin.xml内部设定Onclick过程无效？
	miNewJob.onClick:='ImgAddOnClick';
	miClearAllJob.onClick:='ClearAllOnClick';
	miInputJob.onClick:='InputData';
	miOutputJob.onClick:='OutputData';
	imgEdit.OnClick:='imgEditOnClick';   //编辑图片鼠标点击事件
	imgDelete.OnClick:='DeleteRecord';   //删除鼠标点击事件
	conDelimiter:='^$%';                  //分隔符
	conDataFilePath:=AppPath+'Widgets\what_to_do\ToDoList.dat' //赋予数据文件目录地址
	g_iModifyFlag:=0;
	g_iAddFlag:=1;
	{创建一个Add图片}
	g_imgAdd:=TxspImage.Create(widget);
	g_imgAdd.parent:=Widget;
	g_imgAdd.FileName:=AppPath+'Widgets\what_to_do\add.png';
	g_imgAdd.left:=120;
	g_imgAdd.Top:=100;
	g_imgAdd.width:=42;
	g_imgAdd.height:=20;
	g_imgAdd.Cursor:=crHandPoint;
	g_imgAdd.onClick:='ImgAddOnClick';
	g_imgAdd.Hint:='增加一个工作备忘';
	g_imgAdd.visible:=False;
	ShowEmptyJob;
	GetJobInfo;
	//showtrayhint('',inttostr(widget.height));
end;

//--- Widget关闭事件，当关闭Widget时会触发此事件 ---
procedure OnWidgetClose;
var 
	i:Integer;
begin
	if g_bShowBeenDone then
		SetSettingInt('ShowBeenDone',1)
	else
		SetSettingInt('ShowBeenDone',0);
	freeAllImages;
  g_lstJobString.free;	
	g_lstPicBall.free;
	{g_lstPicItem.free;}
	g_lstJobLabel.free;
	g_lstStrJobName.free;
	g_lstStrJobDate.free;
	g_lstStrJobPRI.free;
	g_lstStrJobLevel.free;
	g_lstStrJobDetail.free;
	g_lstStrBeenDone.free;
	g_lstIndexPos.free;
	g_lstJobSeq.free;
	g_lblEmptyJobName.free;
end;
