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

var
  i: Integer;
  
  ts1:TTabSheet;
  grpSolar,grpLunar:TGroupBox;
  lblSolarNormal,lblSolarHoliday,lblSolarEvents,
  lblLunarNormal,lblLunarHoliday,lblLunarEvents,
  lblLunarPosition:TLabel;
  cbbSolarNormal,cbbSolarHoliday,cbbSolarEvents,
  cbbLunarNormal,cbbLunarHoliday,cbbLunarEvents,
  cbbLunarPosition:TComboBox;
  chkShowLunar,chkShowWeekNumbers,
  chkShowWeek,chkShowMonth,chkShowYear:TCheckBox;
  

function GetSolarItemIndexByFileName(afn:string):integer;
var
	s:string;
begin
  s:=LowerCase(afn);
  if s='large ex numbers white.png' then result:=0
  else if s='large ex numbers blue.png' then result:=1
  else if s='large ex numbers pink.png' then result:=2
  else if s='large ex numbers white highlight.png' then result:=3
  else result:=0;
end;

function GetSolarFileNameByItemIndex(Index:integer):string;
begin
  case Index of
    0: result:='large ex numbers white.png';
    1: result:='large ex numbers blue.png';
    2: result:='large ex numbers pink.png';
    3: result:='large ex numbers white highlight.png';
  else
    result:='large ex numbers white.png';
  end;
end;

function GetLunarItemIndexByFileName(afn:string):integer;
var
	s:string;
begin
  s:=LowerCase(afn);
  if s='large lunar white.png' then result:=0
  else if s='large lunar blue.png' then result:=1
  else if s='large lunar cyan.png' then result:=2
  else if s='large lunar gray.png' then result:=3
  else if s='large lunar magenta.png' then result:=4
  else if s='large lunar pink.png' then result:=5
  else if s='large lunar yellow.png' then result:=6
  else if s='large lunar nb brown.png' then result:=7
  else if s='large lunar nb black.png' then result:=8
  else result:=0;
end;

function GetLunarFileNameByItemIndex(Index:integer):string;
begin
  case Index of
    0: result:='large lunar white.png';
    1: result:='large lunar blue.png';
    2: result:='large lunar cyan.png';
    3: result:='large lunar gray.png';
    4: result:='large lunar magenta.png';
    5: result:='large lunar pink.png';
    6: result:='large lunar yellow.png';
    7: result:='large lunar nb brown.png';
    8: result:='large lunar nb black.png';
  else
    result:='large lunar white.png';
  end;
end;


  
//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
    s:=ReadString('Item0','DaysBitmapName','Large Ex Numbers White.png');
    cbbSolarNormal.ItemIndex:=GetSolarItemIndexByFileName(s);
    s:=ReadString('Item0','DaysHolidayBitmapName','Large Ex Numbers Pink.png');
    cbbSolarHoliday.ItemIndex:=GetSolarItemIndexByFileName(s);
    s:=ReadString('Item0','DaysEventBitmapName','Large Ex Numbers Blue.png');
    cbbSolarEvents.ItemIndex:=GetSolarItemIndexByFileName(s);
    //
    s:=ReadString('Item0','LunarDaysBitmapName','Large Lunar White.png');
    cbbLunarNormal.ItemIndex:=GetLunarItemIndexByFileName(s);
    s:=ReadString('Item0','LunarDaysHolidayBitmapName','Large Lunar Pink.png');
    cbbLunarHoliday.ItemIndex:=GetLunarItemIndexByFileName(s);
    s:=ReadString('Item0','LunarDaysEventBitmapName','Large Lunar Blue.png');
    cbbLunarEvents.ItemIndex:=GetLunarItemIndexByFileName(s);
    
    chkShowLunar.checked:=ReadBool('Item0','LunarDaysEnable',true);
    s:=ReadString('Item0','LunarDaysRect','0/2/15/21/0/0');
    StrToStrings(s,lst,'/');
    if lst.count>5 then
    begin
      //Align,Horz
      if lst[5]='0' then 
        cbbLunarPosition.ItemIndex:=0
      else
        cbbLunarPosition.ItemIndex:=1;
    end;
    chkShowWeekNumbers.Checked:=ReadBool('Item0','WeekNumbersEnable',true);
    chkShowWeek.Checked:=ReadBool('Item0','WeekdaysEnable',true);
    chkShowMonth.Checked:=ReadBool('Item0','MonthEnable',true);
    chkShowYear.Checked:=ReadBool('Item0','YearEnable',true);
  finally
    inifn.free;
    lst.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s:string;
	inifn:TIniFile;
	i:integer;
begin
  result:=true;
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //solar
    s:=GetSolarFileNameByItemIndex(cbbSolarNormal.ItemIndex);
    WriteString('Item0','DaysBitmapName',s);
    s:=GetSolarFileNameByItemIndex(cbbSolarHoliday.ItemIndex);
    WriteString('Item0','DaysHolidayBitmapName',s);
    s:=GetSolarFileNameByItemIndex(cbbSolarEvents.ItemIndex);
    WriteString('Item0','DaysEventBitmapName',s);
    //lunar
    s:=GetLunarFileNameByItemIndex(cbbLunarNormal.ItemIndex);
    WriteString('Item0','LunarDaysBitmapName',s);
    s:=GetLunarFileNameByItemIndex(cbbLunarHoliday.ItemIndex);
    WriteString('Item0','LunarDaysHolidayBitmapName',s);
    s:=GetLunarFileNameByItemIndex(cbbLunarEvents.ItemIndex);
    WriteString('Item0','LunarDaysEventBitmapName',s);
    
    WriteBool('Item0','LunarDaysEnable',chkShowLunar.checked);
    if (cbbLunarPosition.ItemIndex=0) then
    begin
	    WriteString('Item0','DaysRect','32/50/32/30/4/1');
	    WriteString('Item0','LunarDaysRect','0/2/15/21/0/0');
	    WriteString('Item0','TodayRect','0/-2/0/0/0/1/1');
	  end
	  else
	  begin
	    WriteString('Item0','DaysRect','32/50/32/40/1/1');
	    WriteString('Item0','LunarDaysRect','-24/22/15/21/0/1');
	    WriteString('Item0','TodayRect','1/-6/0/0/0/1/1');
	  end;
    WriteBool('Item0','WeekNumbersEnable',chkShowWeekNumbers.Checked);
    WriteBool('Item0','WeekdaysEnable',chkShowWeek.Checked);
    WriteBool('Item0','MonthEnable',chkShowMonth.Checked);
    WriteBool('Item0','YearEnable',chkShowYear.Checked);
  finally
    inifn.free;
  end;
end;

procedure CreateTab1;
begin
  //--- Tab 1 ---
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc;
  ts1.Caption:='月历设置';
  //--- solar setting ---
  grpSolar:=TGroupBox.create(ts1);
  with grpSolar do
  begin
    parent:=ts1;
    caption:='阳历文字颜色设置：';
    left:=8; top:=16; width:=145; height:=105;
  end;
  lblSolarNormal:=TLabel.create(self);
  with lblSolarNormal do
  begin
    parent:=grpSolar;
    left:=16; top:=28; width:=36;
    caption:='普通：';
  end;
  cbbSolarNormal:=TComboBox.Create(self);
  with cbbSolarNormal do
  begin
    Left:=56; Top:=24; width:=73;
    Parent:=grpSolar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('品红');
      add('品红高亮');
    end;
  end;
  lblSolarHoliday:=TLabel.create(self);
  with lblSolarHoliday do
  begin
    parent:=grpSolar;
    left:=16; top:=52; width:=36;
    caption:='节日：';
  end;
  cbbSolarHoliday:=TComboBox.Create(self);
  with cbbSolarHoliday do
  begin
    Left:=56; Top:=48; width:=73;
    Parent:=grpSolar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('品红');
      add('品红高亮');
    end;
  end;
  lblSolarEvents:=TLabel.create(self);
  with lblSolarEvents do
  begin
    parent:=grpSolar;
    left:=16; top:=76; width:=36;
    caption:='事件：';
  end;
  cbbSolarEvents:=TComboBox.Create(self);
  with cbbSolarEvents do
  begin
    Left:=56; Top:=72; width:=73;
    Parent:=grpSolar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('品红');
      add('品红高亮');
    end;
  end;
  //--- lunar setting ---
  grpLunar:=TGroupBox.create(ts1);
  with grpLunar do
  begin
    parent:=ts1;
    caption:='农历文字颜色设置：';
    left:=8; top:=128; width:=145; height:=105;
  end;
  lblLunarNormal:=TLabel.create(self);
  with lblLunarNormal do
  begin
    parent:=grpLunar;
    left:=16; top:=28; width:=36;
    caption:='普通：';
  end;
  cbbLunarNormal:=TComboBox.Create(self);
  with cbbLunarNormal do
  begin
    Left:=56; Top:=24; width:=73;
    Parent:=grpLunar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('普蓝');
      add('灰色');
      add('紫色');
      add('品红');
      add('黄色');
      add('褐色(无边)');
      add('黑色(无边)');
    end;
  end;
  lblLunarHoliday:=TLabel.create(self);
  with lblLunarHoliday do
  begin
    parent:=grpLunar;
    left:=16; top:=52; width:=36;
    caption:='节日：';
  end;
  cbbLunarHoliday:=TComboBox.Create(self);
  with cbbLunarHoliday do
  begin
    Left:=56; Top:=48; width:=73;
    Parent:=grpLunar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('普蓝');
      add('灰色');
      add('紫色');
      add('品红');
      add('黄色');
      add('褐色(无边)');
      add('黑色(无边)');
    end;
  end;
  lblLunarEvents:=TLabel.create(self);
  with lblLunarEvents do
  begin
    parent:=grpLunar;
    left:=16; top:=76; width:=36;
    caption:='事件：';
  end;
  cbbLunarEvents:=TComboBox.Create(self);
  with cbbLunarEvents do
  begin
    Left:=56; Top:=72; width:=73;
    Parent:=grpLunar;
    Style:=csDropDownList;
    with Items do
    begin
      add('白色');
      add('蓝色');
      add('普蓝');
      add('灰色');
      add('紫色');
      add('品红');
      add('黄色');
      add('褐色(无边)');
      add('黑色(无边)');
    end;
  end;
  //--- Others setting ---
  chkShowLunar:=TCheckBox.create(self);
  with chkShowLunar do
  begin
    parent:=ts1;
    caption:='显示农历';
    Left:=176; Top:=16; width:=97;
  end;
  lblLunarPosition:=TLabel.create(self);
  with lblLunarPosition do
  begin
    parent:=ts1;
    left:=176; top:=44; width:=72;
    caption:='农历的位置：';
  end;
  cbbLunarPosition:=TComboBox.Create(self);
  with cbbLunarPosition do
  begin
    Left:=264; Top:=40; width:=73;
    Parent:=ts1;
    Style:=csDropDownList;
    with Items do
    begin
      add('左边');
      add('下边');
    end;
  end;
  chkShowWeekNumbers:=TCheckBox.create(self);
  with chkShowWeekNumbers do
  begin
    parent:=ts1;
    caption:='显示周数';
    Left:=176; Top:=72; width:=97;
  end;
  chkShowWeek:=TCheckBox.create(self);
  with chkShowWeek do
  begin
    parent:=ts1;
    caption:='显示星期';
    Left:=176; Top:=96; width:=97;
  end;
  chkShowMonth:=TCheckBox.create(self);
  with chkShowMonth do
  begin
    parent:=ts1;
    caption:='显示月份';
    Left:=176; Top:=120; width:=97;
  end;
  chkShowYear:=TCheckBox.create(self);
  with chkShowYear do
  begin
    parent:=ts1;
    caption:='显示年份';
    Left:=176; Top:=144; width:=97;
  end;
end;




procedure StrToStrings(s:string; var aLst:TStrings; Sep:string=';');
var
  I, L: Integer;
  Left: String;
begin
  if alst=nil then exit;
  if Trim(s)='' then exit;
  if aLst.Count>0 then aLst.Clear;
  L := Length(Sep);
  I := Pos(Sep, S);
  //aLst.BeginUpdate;
  try
    while (I > 0) do
    begin
      Left :=Copy(S, 1, I - 1);
      aLst.Add(Left);
      Delete(S, 1, I + L - 1);
      I := Pos(Sep, S);
    end;
    if S <> '' then
      aLst.Add(S);
  except
    //aLst.EndUpdate;
  end;
end;

function StringsToStr(const aStrings:TStrings; Sep:string=';'):string;
var
  I: Integer;
begin
  result:='';
  if aStrings=nil then exit;
  if aStrings.Count=0 then exit
  else
  if aStrings.Count=1 then
    result:=aStrings[0]
  else
  if aStrings.Count>1 then
  begin
    for I := 0 to aStrings.Count-2 do    // Iterate
    begin
      result:=result+aStrings[i]+Sep;
    end;    // for
    result:=result+aStrings[aStrings.count-1];
  end;
end;


begin
  CreateTab1;
  InitSetting;
  
end.