mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 16:59:20 +02:00
lcl: dialogs: added InputCombo, from Michael Van Canneyt
git-svn-id: trunk@52973 -
This commit is contained in:
parent
009d3c9089
commit
da0f71ea43
@ -582,6 +582,11 @@ function InputQuery(const ACaption: string; const APrompts: array of string;
|
|||||||
function DefaultInputDialog(const InputCaption, InputPrompt : String;
|
function DefaultInputDialog(const InputCaption, InputPrompt : String;
|
||||||
MaskInput : Boolean; var Value : String) : Boolean;// widgetset independent implementation, see InputDialogFunction
|
MaskInput : Boolean; var Value : String) : Boolean;// widgetset independent implementation, see InputDialogFunction
|
||||||
|
|
||||||
|
function InputCombo(const ACaption, APrompt: string; const AList: TStrings): Integer;
|
||||||
|
function InputCombo(const ACaption, APrompt: string; const AList : Array of String): Integer;
|
||||||
|
function InputComboEx(const ACaption, APrompt: string; const AList: TStrings; AllowCustomText: Boolean = False): String;
|
||||||
|
function InputComboEx(const ACaption, APrompt: string; const AList : Array of String; AllowCustomText: Boolean = False): String;
|
||||||
|
|
||||||
function ExtractColorIndexAndColor(const AColorList: TStrings; const AIndex: Integer;
|
function ExtractColorIndexAndColor(const AColorList: TStrings; const AIndex: Integer;
|
||||||
out ColorIndex: Integer; out ColorValue: TColor): Boolean;
|
out ColorIndex: Integer; out ColorValue: TColor): Boolean;
|
||||||
|
|
||||||
|
@ -99,4 +99,106 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DoInputCombo(const ACaption, APrompt: string; const AList: TStrings; AllowInput : Boolean; Out ASelected : Integer) : String;
|
||||||
|
const
|
||||||
|
CBStyles : array[Boolean] of TComboBoxStyle = (csDropDownList,csDropDown);
|
||||||
|
var
|
||||||
|
W,I,Sep,Margin: Integer;
|
||||||
|
Frm: TForm;
|
||||||
|
CBSelect : TComboBox;
|
||||||
|
LPrompt: TLabel;
|
||||||
|
BP: TButtonPanel;
|
||||||
|
begin
|
||||||
|
Margin:=24;
|
||||||
|
Sep:=8;
|
||||||
|
Result:='';
|
||||||
|
ASelected:=-1;
|
||||||
|
Frm:=TForm.Create(Application);
|
||||||
|
try
|
||||||
|
// Determine needed width
|
||||||
|
W:=frm.Canvas.TextWidth(APrompt);
|
||||||
|
W:=Max(W,frm.Canvas.TextWidth(ACaption));
|
||||||
|
for I:=0 to AList.Count-1 do
|
||||||
|
W:=Max(W,frm.Canvas.TextWidth(AList[i]+'WWW')); // WWW is just some extra.
|
||||||
|
frm.BorderStyle:=bsDialog;
|
||||||
|
frm.Caption:=ACaption;
|
||||||
|
frm.ClientWidth:=W+2*Margin;
|
||||||
|
frm.Position:=poScreenCenter;
|
||||||
|
// Prompt
|
||||||
|
LPrompt:=TLabel.Create(frm);
|
||||||
|
LPrompt.Parent:=frm;
|
||||||
|
LPrompt.Caption:=APrompt;
|
||||||
|
LPrompt.SetBounds(Margin,Margin,Frm.ClientWidth-2*Margin,frm.Canvas.TextHeight(APrompt));
|
||||||
|
LPrompt.WordWrap:=True;
|
||||||
|
LPrompt.AutoSize:=False;
|
||||||
|
// Selection combobox
|
||||||
|
CBSelect:=TComboBox.Create(Frm);
|
||||||
|
CBSelect.Parent:=Frm;
|
||||||
|
CBSelect.Style:=CBStyles[AllowInput];
|
||||||
|
CBSelect.Items.Assign(AList);
|
||||||
|
CBSelect.ItemIndex:=-1;
|
||||||
|
CBSelect.Left:=Margin;
|
||||||
|
CBSelect.Top:=LPrompt.Top + LPrompt.Height + Sep;
|
||||||
|
CBSelect.Width:=Frm.ClientWidth-2*Margin;
|
||||||
|
// Buttons
|
||||||
|
BP:=TButtonPanel.Create(Frm);
|
||||||
|
BP.Parent:=Frm;
|
||||||
|
BP.ShowButtons:=[pbOK,pbCancel];
|
||||||
|
Frm.ClientHeight:=LPrompt.Height+CBSelect.Height+BP.Height+2*Sep+Margin;
|
||||||
|
if (Frm.ShowModal=mrOk) then
|
||||||
|
begin
|
||||||
|
Result:=CBSelect.Text;
|
||||||
|
ASelected:=CBSelect.ItemIndex;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FreeAndNil(Frm);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function InputCombo(const ACaption, APrompt: string; const AList: TStrings
|
||||||
|
): Integer;
|
||||||
|
begin
|
||||||
|
DoInputCombo(ACaption,APrompt,AList,False,Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function InputCombo(const ACaption, APrompt: string;
|
||||||
|
const AList: array of String): Integer;
|
||||||
|
var
|
||||||
|
L : TStrings;
|
||||||
|
S : String;
|
||||||
|
begin
|
||||||
|
L:=TStringList.Create;
|
||||||
|
try
|
||||||
|
for S in AList do
|
||||||
|
L.Add(S);
|
||||||
|
Result:=InputCombo(ACaption,APrompt,L);
|
||||||
|
finally
|
||||||
|
L.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function InputComboEx(const ACaption, APrompt: string; const AList: TStrings;
|
||||||
|
AllowCustomText: Boolean): String;
|
||||||
|
var
|
||||||
|
D: Integer;
|
||||||
|
begin
|
||||||
|
Result:=DoInputCombo(ACaption,APrompt,AList,AllowCustomText,D);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function InputComboEx(const ACaption, APrompt: string;
|
||||||
|
const AList: array of String; AllowCustomText: Boolean): String;
|
||||||
|
var
|
||||||
|
L: TStrings;
|
||||||
|
S: String;
|
||||||
|
begin
|
||||||
|
L:=TstringList.Create;
|
||||||
|
try
|
||||||
|
for S in AList do
|
||||||
|
L.Add(S);
|
||||||
|
Result:=InputComboEx(ACaption,APrompt,L,AllowCustomText);
|
||||||
|
finally
|
||||||
|
L.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// included by dialogs.pp
|
// included by dialogs.pp
|
||||||
|
Loading…
Reference in New Issue
Block a user