unit USwitcher;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls,IniFiles, ULanguage, CheckLst;
type
TItems =
class
private
public
panb : TPanel;
chk : TCheckBox;
lbl : TLabel;
text : TLabel;
constructor create(pan : TPanel; Y : integer; Capt,txt :
string; che : boolean);
procedure itemOnClick(Sender : TObject);
end;
TLangSwitcher =
class(TPanel)
private
items : TListBox;
itList : Tlist;
public
procedure setitems(ID :
string);
procedure createList;
function getList : TListBox;
end;
implementation
//******************************************************************************
// Items
constructor TItems.create(pan : TPanel; Y : integer; Capt,txt :
string; che : boolean);
begin
panb := TPanel.create(pan);
with panb
do
begin
Parent := pan;
Top := Y;
Left := 0;
Height := 15;
Width := pan.Width-1;
BorderStyle := bsNone;
Color := clWhite;
OnClick := itemOnClick;
if che = true
then Color := clBackground;
end;
chk := TCheckBox.Create(panb);
with chk
do
begin
parent := panb;
Height := 9;
Width := 9;
Left := 2;
Top := 2;
Caption := '
';
Font.Color := clBackground;
Font.Size := 8;
Checked := che;
if che = true
then Color := clBackground;
OnClick := itemOnClick;
end;
lbl := TLabel.Create(panb);
with lbl
do
begin
parent := panb;
Height := 12;
Width := 12;
Top := 0;
Left := 15;
AutoSize := false;
Alignment := taCenter;
Color := clBlack;
Font.Color := clBackground;
Font.
Name := '
Arial';
Font.Size := 6;
Caption := capt;
OnClick := itemOnClick;
end;
text := TLabel.Create(panb);
with text
do
begin
parent := panb;
Height := 15;
Top := 0;
Left := 27;
Width := pan.Width-Left;
AutoSize := false;
Font.Color := clBlack;
Font.
Name := '
Arial';
Font.Size := 8;
Caption := txt;
OnClick := itemOnClick;
end;
end;
procedure TItems.itemOnClick(Sender : TObject);
begin
if panb.Color = clBackground
then
begin
chk.Color := clWhite;
chk.Checked := false;
panb.Color := clWhite;
end
else
begin
chk.Color := clBackground;
chk.Checked := true;
panb.Color := clBackground;
end;
end;
//******************************************************************************
//******************************************************************************
// Switcher
procedure TLangSwitcher.createList;
begin
items := TListBox.Create(self);
items.Parent := self;
items.Visible := false;
itList := TList.Create;
end;
procedure TLangSwitcher.setitems(ID :
string);
var i,posy : integer;
begin
posy := 1;
for i := 0
to items.Items.Count-1
do
begin
if copy(items.Items[i],1,2) = ID
then itList.Add(TItems.Create(self,posy,copy(items.Items[i],1,2),copy(items.Items[i],3,Length(items.Items[i])),true))
else itList.Add(TItems.Create(self,posy,copy(items.Items[i],1,2),copy(items.Items[i],3,Length(items.Items[i])),false));
Height := Height + 14;
Top := Top - 14;
posy := posy + 14;
end;
self.Height := self.Height + 4;
end;
//---------------------- Getter ------------------------------------------------
function TLangSwitcher.getList : TListBox;
begin
result := items;
end;
//******************************************************************************
end.