{**************************
Shortcut icon script Ver1.0 by snowfox
**************************}
const
  RowHeight=30;
  RowSep=15;

var
  i: Integer;
  fIconBitmapName:string;
  
  ts1,ts2:TTabSheet;
  lblAction:TLabel;
  cbbAction:TComboBox;
  pnlDisk,pnlPath,pnlFile:TPanel;
  chkShowDescription:TCheckBox;
  mmoDescription:TMemo;
  lblDisk:TLabel;
  cbbDisk:TComboBox;
  lblPath,lblFile:TLabel;
  edtPath,edtFile:TEdit;
  btnSelPath,btnSelFile:TButton;
  
  lblIcon,lblLabel,lblLabelType,lblLabelText,lblDescRect,lblFormWidth,lblFormHeight:TLabel;
  edtIconRect,edtLabelRect,edtLabelText,edtDescRect,edtFormWidth,edtFormHeight:TEdit;
  cbbLabelType:TComboBox;
  
  pngImage:TPanel;
  img:TImage;
  dlgPic:TOpenPictureDialog;

  
//Init Skin form setting
procedure InitSetting;
var
	s:string;
	inifn:TIniFile;
	lst:TStrings;
	i:integer;
begin
  inifn:=TIniFile.create(SkinFileName);
	lst:=TStringList.create;
  with inifn do
  try
    //Tab1
    fIconBitmapName:=ReadString('Item1','BitmapName','MyComputer.png');
		LoadPngImage(img,fIconBitmapName,i,i);
    
    mmoDescription.lines.text:=s;
    cbbAction.ItemIndex:=ReadInteger('Item1','DBClickIndex',0);
	 	cbbActionChange(cbbAction);
  	case cbbAction.ItemIndex of
  	  0://Disk
  	    begin
          cbbDisk.ItemIndex:=ReadInteger('Item1','DiskIndex',0);
          cbbDiskChange(cbbDisk);;
  	    end;
  	  1://Path
  	    begin
          edtPath.text:=ReadString('Item1','PathStr','');
  	    end;
  	  2://File
  	    begin
  	      edtFile.text:=ReadString('Item1','FileStr','');
  	    end;
		end;
    s:=ReadString('Item3','Item0','');
    chkShowDescription.checked:=s<>'';
  	
  	//Tab2
  	edtIconRect.text:=ReadString('Item1','Rect','10/10/80/80');
  	edtLabelRect.text:=ReadString('Item2','Rect','18/98/66/27/4');
  	s:=ReadString('Item2','LabelSkin','SLP23');
  	i:=cbbLabelType.items.indexof(s);
  	if i>=0 then
  		cbbLabelType.itemindex:=i
  	else
  	  cbbLabelType.itemindex:=0;
  	edtLabelText.text:=ReadString('Item2','Text','');
  	edtDescRect.text:=ReadString('Item3','Rect','0/120/66/27/4');
  	edtFormWidth.text:=ReadString('system','Width','120');
  	edtFormHeight.text:=ReadString('system','Height','170');
  finally
    inifn.free;
    lst.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s:string;
	inifn:TIniFile;
	i:integer;
begin
  result:=false;
  result:=true;
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //Tab1
    i:=length(SkinPath);
    if pos(SkinPath,LowerCase(fIconBitmapName))=1 then
      s:=copy(fIconBitmapName,i+1,length(fIconBitmapName)-i)
    else
      s:=fIconBitmapName;
    WriteString('Item1','BitmapName',s);
    if chkShowDescription.checked then
    	WriteString('Item3','Item0',mmoDescription.lines.text)
    else 
    	WriteString('Item3','Item0','');
    WriteInteger('Item1','DBClickIndex',cbbAction.ItemIndex);
    case cbbAction.ItemIndex of
      0://Disk
        begin
          s:=cbbDisk.text+'\';
          WriteInteger('Item1','DiskIndex',cbbDisk.ItemIndex);
        end;
      1://Path
        begin
          s:=edtPath.text;
          WriteString('Item1','PathStr',s);
        end;
      2://File
        begin
          s:=edtFile.text;
          WriteString('Item1','FileStr',s);
        end;
      3: s:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';	//我的电脑
      4: s:='::{450D8FBA-AD25-11D0-98A8-0800361B1103}';	//我的文档”
      5: s:='::{208D2C60-3AEA-1069-A2D7-08002B30309D}';	//网上邻居
      6: s:='file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}/::{21EC2020-3AEA-1069-A2DD-08002B30309D}';	//控制面板
      7: s:='::{645FF040-5081-101B-9F08-00AA002F954E}';	//回收站
      8: s:='file:///::{2227A280-3AEA-1069-A2DE-08002B30309D}';	//打印机
      9: s:='::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}';	//任务计划
    end;
    if trim(s)<>'' then s:='<!Run='+s+'>';
    if (s<>ReadString('Item1','DBClick','')) then
    begin
    	WriteString('Item1','DBClick',s);
    	result:=true;
    end;
    //Tab2
    
   	WriteString('Item1','Rect', edtIconRect.text);
   	WriteString('Item0','Rect', edtIconRect.text);
   	WriteString('Item2','Rect', edtLabelRect.text);
   	s:=ReadString('Item2','LabelSkin','SLP23');
   	if s<>cbbLabelType.text then
  		WriteString('Item2','LabelSkin',cbbLabelType.text);
  	WriteString('Item2','Text',edtLabelText.text);
  	WriteString('Item3','Rect',edtDescRect.text);
  	WriteString('system','Width',edtFormWidth.text);
  	WriteString('system','Height',edtFormHeight.text);

  finally
    inifn.free;
  end;
end;

procedure CreateTab1;
begin
  //--- Tab 1 ---
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc;
  ts1.Caption:='动作设置';
  lblAction:=TLabel.Create(ts1);
  lblAction.caption:='双击图标后的动作：';
  lblAction.Left:=16;
  lblAction.Top:=16;
  lblAction.parent:=ts1;
  cbbAction:=TComboBox.Create(ts1);
  with cbbAction do
  begin
    Left:=16; Top:=32; width:=350;
    DropDownCount:=15;
    Parent:=ts1;
    Style:=csDropDownList;
    with Items do
    begin
      add('打开指定硬盘分区');
      add('打开指定目录');
      add('打开指定文件');
      add('打开“我的电脑”');
      add('打开“我的文档”');
      add('打开“网上邻居”');
      add('打开“控制面板”');
      add('打开“回收站”');
      add('打开“打印机”');
      add('打开“任务计划”');
      
    end;
    OnChange:=@cbbActionChange;
    ItemIndex:=0;
  end;
  chkShowDescription:=TCheckBox.Create(ts1);
  with chkShowDescription do
  begin
    parent:=ts1;
    Left:=16; Top:=58;
    caption:='显示描述文字';
    Checked:=true;
    OnClick:=@chkShowDescriptionClick;
  end;
  mmoDescription:=TMemo.Create(ts1);
  with mmoDescription do
  begin
    parent:=ts1;
    Left:=16; top:=80; width:=350; height:=60;
    ScrollBars:=ssVertical;
    lines.text:='';
    
  end;
  //Disk panel
  pnlDisk:=TPanel.Create(ts1);
  with pnlDisk do
  begin
	  parent:=ts1;
    caption:='';
    BevelOuter:=bvNone;
    Left:=16; Top:=145;
    width:=350; height:=120;
    lblDisk:=TLabel.Create(pnlDisk);
    with lblDisk do
    begin
      parent:=pnlDisk;
      left:=0; top:=4; width:=100;
      caption:='硬盘分区：           盘';
    end;
    cbbDisk:=TComboBox.create(pnlDisk);
    with cbbDisk do
    begin
      parent:=pnlDisk;
      left:=60; top:=0; width:=50;
    	Style:=csDropDownList;
    	with Items do
      begin
        add('C:');
        add('D:');
        add('E:');
        add('F:');
        add('G:');
        add('H:');
        add('I:');
        add('J:');
        add('K:');
        add('L:');
        add('M:');
        add('N:');
      end;
      ItemIndex:=0;
    end;
  end;
  //Path panel
  pnlPath:=TPanel.Create(ts1);
  with pnlPath do
  begin
	  parent:=ts1;
    caption:='';
    BevelOuter:=bvNone;
    Left:=16; Top:=145;
    width:=350; height:=120;
  	lblPath:=TLabel.create(pnlPath);
  	with lblPath do
  	begin
      parent:=pnlPath;
      left:=0; top:=4; width:=100;
      caption:='文件夹路径：';
  	end;
    edtPath:=TEdit.create(pnlPath);
    with edtPath do
    begin
      parent:=pnlPath;
      left:=0; top:=24; width:=250;
      text:='';
    end;
    btnSelPath:=TButton.create(pnlPath);
    with btnSelPath do
    begin
      parent:=pnlPath;
      left:=260; top:=24; width:=90; height:=23;
      caption:='选择文件夹...';
      OnClick:=@btnSelPathClick;
    end;
  end;
  //File panel
  pnlFile:=TPanel.Create(ts1);
  with pnlFile do
  begin
	  parent:=ts1;
    caption:='';
    BevelOuter:=bvNone;
    Left:=16; Top:=145;
    width:=350; height:=120;
  	lblFile:=TLabel.create(pnlFile);
  	with lblFile do
  	begin
      parent:=pnlFile;
      left:=0; top:=4; width:=100;
      caption:='请选择或输入快捷方式指向的文件名：';
  	end;
    edtFile:=TEdit.create(pnlFile);
    with edtFile do
    begin
      parent:=pnlFile;
      left:=0; top:=24; width:=250;
      text:='';
    end;
    btnSelFile:=TButton.create(pnlFile);
    with btnSelFile do
    begin
      parent:=pnlFile;
      left:=260; top:=24; width:=90; height:=23;
      caption:='选择文件...';
      OnClick:=@btnSelFileClick;
    end;
  end;
end;

procedure CreateTab2;
var
	i:integer;
begin
  //--- Tab 2 ---
  ts2:=TTabSheet.Create(pgc);
  ts2.PageControl:=pgc;
  ts2.Caption:='快捷方式设置';
  {lblImage:=TLabel.create(ts2);
  with lblImage do
  begin
    parent:=ts2;
    left:=16; top:=16; width:=100;
    caption:='图标设置：';
    
  end;}
  //image preview
  pngImage:=TPanel.create(ts2);
  with pngImage do
  begin
    parent:=ts2;
    left:=166; top:=16;
    width:=200; height:=200;
    caption:='';
    BevelOuter:=bvLowered;
  end;
  img:=TImage.create(pngImage);
  with img do
  begin
    cursor:=crHandPoint;
    parent:=pngImage;
    left:=1; top:=1;
    width:=198; height:=198;
    OnClick:=@imgClick;
  end;
  //Icon and Label
  lblIcon:=TLabel.create(self);
  with lblIcon do
  begin
    parent:=ts2;
    left:=8; top:=16;
    caption:='图标(水平/垂直/宽/高)：';
  end;
  edtIconRect:=TEdit.create(self);
  with edtIconRect do
  begin
    parent:=ts2;
    left:=8; top:=lblIcon.top+RowSep; width:=150;
  end;
  lblLabel:=TLabel.create(self);
  with lblLabel do
  begin
    parent:=ts2;
    left:=8; top:=edtIconRect.top+RowHeight;
    caption:='标签(水平/垂直/宽/高/对齐)';
  end;
  edtLabelRect:=TEdit.create(self);
  with edtLabelRect do
  begin
    parent:=ts2;
    left:=8; top:=lblLabel.top+RowSep; width:=150;
  end;
  
  lblLabelType:=TLabel.create(self);
  with lblLabelType do
  begin
    parent:=ts2;
    left:=8; top:=edtLabelRect.top+RowHeight;
    caption:='标签类型：';
  end;
	cbbLabelType:=TComboBox.create(self);
	with cbbLabelType do
	begin
	  parent:=ts2;
	  left:=8; top:=lblLabelType.top+RowSep; width:=150;
	  DropDownCount:=15;
    Style:=csDropDownList;
    items.text:=GetLabelsList;
	end;

  lblLabelText:=TLabel.create(self);
  with lblLabelText do
  begin
    parent:=ts2;
    left:=8; top:=cbbLabelType.top+RowHeight;
    caption:='标签文字：';
  end;
  edtLabelText:=TEdit.create(self);
  with edtLabelText do
  begin
    parent:=ts2;
    left:=8; top:=lblLabelText.top+RowSep; width:=150;
  end;

  lblDescRect:=TLabel.create(self);
  with lblDescRect do
  begin
    parent:=ts2;
    left:=8; top:=edtLabelText.top+RowHeight;
    caption:='描述(水平/垂直/宽/高/对齐)';
  end;
  edtDescRect:=TEdit.create(self);
  with edtDescRect do
  begin
    parent:=ts2;
    left:=8; top:=lblDescRect.top+RowSep; width:=150;
  end;
	
  lblFormWidth:=TLabel.create(self);
  with lblFormWidth do
  begin
    parent:=ts2;
    left:=8; top:=edtDescRect.top+RowHeight;
    caption:='窗口宽度：';
  end;
  edtFormWidth:=TEdit.create(self);
  with edtFormWidth do
  begin
    parent:=ts2;
    left:=lblFormWidth.left+60; top:=lblFormWidth.top-4; width:=50;
  end;
  lblFormHeight:=TLabel.create(self);
  with lblFormHeight do
  begin
    parent:=ts2;
    left:=edtFormWidth.left+60; top:=lblFormWidth.top;
    caption:='窗口高度：';
  end;
  edtFormHeight:=TEdit.create(self);
  with edtFormHeight do
  begin
    parent:=ts2;
    left:=lblFormHeight.left+60; top:=lblFormWidth.top-4; width:=50;
  end;
	
end;

procedure cbbDiskChange(Sender: TObject);
var
	s:string;
begin
  if cbbDisk.ItemIndex>-1 then
  begin
	  s:=copy(cbbDisk.text,1,1);
    mmoDescription.lines.text:='已用 <#DISK_'+s+'_USED> GB<#C_CR>可用 <#DISK_'+s+'_FREE> GB<#C_CR>共<#DISK_'+s+'_TOTAL> GB(<#DISK_'+s+'_PERCENT>%)';
    edtLabelText.text:=cbbDisk.text+'盘';
  end;
end;

procedure cbbActionChange(Sender: TObject);
var
	s:string;
	i,j:integer;
begin
  case cbbAction.ItemIndex of
    0://Disk
      begin
        if not pnlDisk.visible then pnlDisk.visible:=true;
        if pnlPath.visible then pnlPath.visible:=false;
        if pnlFile.visible then pnlFile.visible:=false;
        if not chkShowDescription.checked then chkShowDescription.checked:=true;
        cbbDiskChange(cbbDisk);
      end;
    1://Path
      begin
        if not pnlPath.visible then pnlPath.visible:=true;
        if pnlDisk.visible then pnlDisk.visible:=false;
        if pnlFile.visible then pnlFile.visible:=false;
        //if not chkShowDescription.checked then chkShowDescription.checked:=true;
        if chkShowDescription.checked then chkShowDescription.checked:=false;
      end;
    2://File
      begin
        if not pnlFile.visible then pnlFile.visible:=true;
        if pnlDisk.visible then pnlDisk.visible:=false;
        if pnlPath.visible then pnlPath.visible:=false;
        if chkShowDescription.checked then chkShowDescription.checked:=false;
        //if not chkShowDescription.checked then chkShowDescription.checked:=true;
      end;
    3..10: 
      begin
        if pnlDisk.visible then pnlDisk.visible:=false;
        if pnlPath.visible then pnlPath.visible:=false;
        if pnlFile.visible then pnlFile.visible:=false;
        if chkShowDescription.checked then chkShowDescription.checked:=false;
        s:=cbbAction.text;
        i:=pos('“',s); j:=pos('”',s);
        if i<j then
        	edtLabelText.text:=copy(s,i+2,j-i-2);
      end;
  end;
end;

procedure chkShowDescriptionClick(Sender: TObject);
begin
  mmoDescription.enabled:=chkShowDescription.checked;
end;

procedure btnSelPathClick(Sender:TObject);
var
  Dir: string;
begin
  Dir := '';
  if SelectDir('请选择快捷方式指向的目录：','',Dir) then
    edtPath.text := Dir;
end;

procedure btnSelFileClick(Sender: TObject);
var
  dlgopen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.Create(self);
  try
    if dlgOpen.Execute then
      edtFile.text:=dlgOpen.FileName;
  //if SelectDir('请选择快捷方式指向的目录：','',Dir) then
  finally
    dlgOpen.free;
  end;
end;

procedure imgClick(Sender: TObject);
var
  i:integer;
begin
  dlgPic:=TOpenPictureDialog.create(self);
  try
    dlgPic.FileName:=fIconBitmapName;
    if dlgPic.Execute then
    begin
      fIconBitmapName:=dlgPic.FileName;
      LoadPngImage(img,fIconBitmapName,i,i);
    end;
  finally
    dlgPic.free;
  end;
  
end;


begin
  CreateTab2;
  CreateTab1;
  cbbDisk.OnChange:=@cbbDiskChange;
  InitSetting;
  
end.