mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-02 06:39:36 +01:00
added listview items property editor
git-svn-id: trunk@3855 -
This commit is contained in:
parent
2fd70be9c2
commit
91a8b2248b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -140,6 +140,7 @@ designer/filesystem.pp svneol=native#text/pascal
|
||||
designer/graphpropedits.pas svneol=native#text/pascal
|
||||
designer/jitform/jitform.pas svneol=native#text/pascal
|
||||
designer/jitforms.pp svneol=native#text/pascal
|
||||
designer/listviewpropedit.pp svneol=native#text/pascal
|
||||
designer/menueditorform.pas svneol=native#text/pascal
|
||||
designer/menupropedit.pp svneol=native#text/pascal
|
||||
designer/objectinspector.pp svneol=native#text/pascal
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
""
|
||||
"Last-Translator: \n"
|
||||
"PO-Revision-Date: 2003-02-17 23:19+0100\n"
|
||||
"Language-Team: <fr@li.org>\n"
|
||||
"Content-Type: text/plain; charset=ISO-8859-1\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: KBabel 0.9.6\n"
|
||||
|
||||
#: codetoolsstrconsts:ctsothercompilerdefines
|
||||
msgid "%s Compiler Defines"
|
||||
msgstr "options compilateur définies %s"
|
||||
@ -116,7 +126,7 @@ msgstr "classe sans nom"
|
||||
|
||||
#: codetoolsstrconsts:ctscommentendnotfound
|
||||
msgid "Comment end not found"
|
||||
msgstr ""
|
||||
msgstr "Fin de commentaire non trouvé"
|
||||
|
||||
#: codetoolsstrconsts:ctscompiler
|
||||
msgid "Compiler"
|
||||
@ -160,7 +170,7 @@ msgstr "OS source par d
|
||||
|
||||
#: codetoolsstrconsts:ctsdefaultppc386symbol
|
||||
msgid "Default ppc386 symbol"
|
||||
msgstr ""
|
||||
msgstr "Symbole par défaut de ppc386"
|
||||
|
||||
#: codetoolsstrconsts:ctsdefaultppc386targetoperatingsystem
|
||||
msgid "Default ppc386 target Operating System"
|
||||
|
||||
463
designer/listviewpropedit.pp
Normal file
463
designer/listviewpropedit.pp
Normal file
@ -0,0 +1,463 @@
|
||||
{
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
}
|
||||
|
||||
{
|
||||
Property editor for TListView objects
|
||||
|
||||
Author: Olivier guilbaud (golivier@free.fr)
|
||||
|
||||
History
|
||||
01/28/2003 OG - Create
|
||||
18/02/2003 OG - First release
|
||||
}
|
||||
unit ListViewPropEdit;
|
||||
|
||||
{$MODE OBJFPC}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, LResources, ComCtrls,
|
||||
StdCtrls, Buttons, ExtCtrls,Menus,PropEdits,ComponentEditors,LCLProc,LMessages;
|
||||
|
||||
Implementation
|
||||
Const
|
||||
sccsLvEdtCaption = 'ListView editor';
|
||||
sccsLvEdtGrpLCaption = ' Items ';
|
||||
sccsLvEdtGrpRCaption = ' Item property ';
|
||||
sccsLvEdtlabCaption = 'Label';
|
||||
sccsLvEdtImgIndexCaption= 'Image index';
|
||||
sccsLvEdtBtnAdd = 'New';
|
||||
sccsLvEdtBtnDel = 'Delete';
|
||||
|
||||
Type
|
||||
{TMenuItemsPropertyEditorDlg}
|
||||
TListViewItemsPropertyEditorDlg = Class(TForm)
|
||||
private
|
||||
edtLabel : TEdit;
|
||||
edtIndex : TEdit;
|
||||
LB : TListBox;
|
||||
LstIndex : TStringList;
|
||||
|
||||
fBuild : Boolean;
|
||||
|
||||
Procedure btnAddOnClick(Sender : TObject);
|
||||
Procedure btnDelOnClick(Sender : TObject);
|
||||
Procedure LBOnClick(Sender: TObject);
|
||||
procedure EdtLabelOnChange(Sender: TObject);
|
||||
procedure EdtIndexOnChange(Sender: TObject);
|
||||
public
|
||||
constructor Create(aOwner : TComponent); override;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
TListViewComponentEditor = class(TDefaultComponentEditor)
|
||||
protected
|
||||
procedure DoShowEditor;
|
||||
|
||||
public
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
function GetVerb(Index: Integer): string; override;
|
||||
function GetVerbCount: Integer; override;
|
||||
end;
|
||||
|
||||
{TListViewItemsPropertyEditor
|
||||
Property editor for the Items properties of TListView object.
|
||||
Brings up the dialog for editing items}
|
||||
TListViewItemsPropertyEditor = Class(TClassPropertyEditor)
|
||||
public
|
||||
procedure Edit; override;
|
||||
function GetAttributes: TPropertyAttributes; override;
|
||||
end;
|
||||
|
||||
//This function find the Designer of aComponent
|
||||
function GetDesignerOfComponent(aComponent : TComponent): TComponentEditorDesigner;
|
||||
var
|
||||
OwnerForm: TCustomForm;
|
||||
begin
|
||||
Result:=nil;
|
||||
if (aComponent is TCustomForm) and (TCustomForm(aComponent).Parent=nil) then
|
||||
OwnerForm:=TCustomForm(aComponent)
|
||||
else
|
||||
begin
|
||||
OwnerForm:=TCustomForm(aComponent.Owner);
|
||||
if OwnerForm=nil then
|
||||
begin
|
||||
raise Exception.Create('TComponentInterface.GetDesigner: '
|
||||
+aComponent.Name+' Owner=nil');
|
||||
end;
|
||||
|
||||
if not (OwnerForm is TCustomForm) then
|
||||
begin
|
||||
raise Exception.Create('TComponentInterface.GetDesigner: '
|
||||
+aComponent.Name+' OwnerForm='+OwnerForm.ClassName);
|
||||
end;
|
||||
Result:=TComponentEditorDesigner(OwnerForm.Designer);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TListViewItemsPropertyEditor }
|
||||
|
||||
procedure TListViewItemsPropertyEditor.Edit;
|
||||
Var DI : TComponentEditorDesigner;
|
||||
Ds : TBaseComponentEditor;
|
||||
LV : TCustomListView;
|
||||
begin
|
||||
LV:=TListItems(GetOrdValue).Owner;
|
||||
DI:=GetDesignerOfComponent(LV);
|
||||
If Assigned(DI) then
|
||||
begin
|
||||
Ds:=GetComponentEditor(LV,DI);
|
||||
If Assigned(Ds) then
|
||||
Ds.ExecuteVerb(0);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TListViewItemsPropertyEditor.GetAttributes: TPropertyAttributes;
|
||||
begin
|
||||
Result:=[paDialog,paReadOnly,paRevertable];
|
||||
end;
|
||||
|
||||
{ TListViewComponentEditor }
|
||||
|
||||
procedure TListViewComponentEditor.DoShowEditor;
|
||||
Var Dlg : TListViewItemsPropertyEditorDlg;
|
||||
LV : TListView;
|
||||
C : TPersistent;
|
||||
i : Integer;
|
||||
Li : TListItem;
|
||||
Hook: TPropertyEditorHook;
|
||||
begin
|
||||
Dlg:=TListViewItemsPropertyEditorDlg.Create(Application);
|
||||
try
|
||||
C:=GetComponent;
|
||||
if C is TListView then LV:=TListView(C);
|
||||
if C is TListItems then LV:=TListView(TListItems(C).Owner);
|
||||
GetHook(Hook);
|
||||
if Assigned(LV) then
|
||||
begin
|
||||
//Initialize the listbox items with ListView items
|
||||
for i:=0 to LV.Items.Count-1 do
|
||||
begin
|
||||
Dlg.fBuild:=True;
|
||||
Dlg.LB.Items.Add(LV.Items.Item[i].Caption);
|
||||
Dlg.LstIndex.Add(IntToStr(LV.Items[i].ImageIndex));
|
||||
end;
|
||||
if LV.Items.Count>0 then
|
||||
begin
|
||||
Dlg.LB.ItemIndex:=0;
|
||||
Dlg.LB.OnClick(nil);
|
||||
end;
|
||||
|
||||
//ShowEditor
|
||||
if (Dlg.ShowModal=mrOk) then
|
||||
begin
|
||||
LV.BeginUpdate;
|
||||
try
|
||||
//Clear items
|
||||
LV.Items.Clear;
|
||||
|
||||
//Recreate new items or modify
|
||||
for i:=0 to Dlg.LB.Items.Count-1 do
|
||||
begin
|
||||
Li:=LV.Items.Add;
|
||||
Li.Caption:=Dlg.LB.Items.Strings[i];
|
||||
Li.ImageIndex:=StrToInt(Dlg.LstIndex.Strings[i]);
|
||||
end;
|
||||
finally
|
||||
LV.EndUpdate;
|
||||
if Assigned(Hook) then
|
||||
Hook.Modified;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
Dlg.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TListViewComponentEditor.ExecuteVerb(Index: Integer);
|
||||
begin
|
||||
If Index=0 then
|
||||
DoShowEditor;
|
||||
end;
|
||||
|
||||
function TListViewComponentEditor.GetVerb(Index: Integer): string;
|
||||
begin
|
||||
Result:='';
|
||||
If Index=0 then
|
||||
Result:=sccsLvEdtCaption;
|
||||
end;
|
||||
|
||||
function TListViewComponentEditor.GetVerbCount: Integer;
|
||||
begin
|
||||
Result:=1;
|
||||
end;
|
||||
|
||||
{ TListViewItemsPropertyEditorDlg }
|
||||
constructor TListViewItemsPropertyEditorDlg.Create(aOwner: TComponent);
|
||||
Var Cmp : TWinControl;
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
|
||||
LstIndex:=TStringList.Create;
|
||||
fBuild:=False;
|
||||
|
||||
//Sise of window
|
||||
Height:=261;
|
||||
Width :=640;
|
||||
BorderStyle:=bsSingle;
|
||||
Position :=poScreenCenter;
|
||||
Caption :=sccsLvEdtCaption;
|
||||
|
||||
Cmp:=TPanel.Create(self);
|
||||
With TPanel(Cmp) do
|
||||
begin
|
||||
Parent:=Self;
|
||||
Height:=41;
|
||||
Align :=alBottom;
|
||||
end;
|
||||
|
||||
//Bnt cancel
|
||||
With TBitBtn.Create(self) do
|
||||
begin
|
||||
Left :=533;
|
||||
Width :=91;
|
||||
Top :=8;
|
||||
Kind :=bkCancel;
|
||||
Parent:=Cmp;
|
||||
end;
|
||||
|
||||
//Bnt Ok
|
||||
With TBitBtn.Create(self) do
|
||||
begin
|
||||
Left :=437;
|
||||
Width :=91;
|
||||
Top :=8;
|
||||
Kind :=bkOk;
|
||||
Parent:=Cmp;
|
||||
end;
|
||||
|
||||
//Left group box
|
||||
Cmp:=TGroupBox.Create(self);
|
||||
With TgroupBox(Cmp) do
|
||||
begin
|
||||
Width :=329;
|
||||
Top :=0;
|
||||
Left :=3;
|
||||
Height :=217;
|
||||
Parent :=Self;
|
||||
Caption:=sccsLvEdtGrpLCaption
|
||||
end;
|
||||
|
||||
With TButton.Create(self) do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Left :=192;
|
||||
Width :=121;
|
||||
Top :=32;
|
||||
Caption:=sccsLvEdtBtnAdd;
|
||||
OnClick:=@btnAddOnClick;
|
||||
end;
|
||||
|
||||
With TButton.Create(self) do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Left :=192;
|
||||
Width :=121;
|
||||
Top :=72;
|
||||
Caption:=sccsLvEdtBtnDel;
|
||||
OnClick:=@btnDelOnClick;
|
||||
end;
|
||||
|
||||
LB:=TListBox.Create(self);
|
||||
With LB do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Top :=3;
|
||||
Width :=164;
|
||||
Left :=5;
|
||||
Height :=190;
|
||||
ExtendedSelect:=True;
|
||||
OnClick :=@LBOnClick;
|
||||
end;
|
||||
|
||||
//Right group box
|
||||
Cmp:=TGroupBox.Create(self);
|
||||
With TgroupBox(Cmp) do
|
||||
begin
|
||||
Width :=297;
|
||||
Top :=0;
|
||||
Left :=339;
|
||||
Height :=217;
|
||||
Parent :=Self;
|
||||
Caption:=sccsLvEdtGrpRCaption
|
||||
end;
|
||||
|
||||
With TLabel.Create(self) do
|
||||
begin
|
||||
Parent :=cmp;
|
||||
Left :=16;
|
||||
Top :=32;
|
||||
Caption:=sccsLvEdtlabCaption;
|
||||
end;
|
||||
|
||||
With TLabel.Create(self) do
|
||||
begin
|
||||
Parent :=cmp;
|
||||
Left :=16;
|
||||
Top :=72;
|
||||
Caption:=sccsLvEdtImgIndexCaption;
|
||||
end;
|
||||
|
||||
EdtLabel:= TEdit.Create(self);
|
||||
With EdtLabel do
|
||||
begin
|
||||
Parent:=Cmp;
|
||||
Left :=104;
|
||||
Text :='';
|
||||
Width :=185;
|
||||
Top :=24;
|
||||
|
||||
OnChange:=@EdtLabelOnChange;
|
||||
end;
|
||||
|
||||
EdtIndex:= TEdit.Create(self);
|
||||
With EdtIndex do
|
||||
begin
|
||||
Parent:=Cmp;
|
||||
Left :=104;
|
||||
Text :='';
|
||||
Width :=73;
|
||||
Top :=64;
|
||||
|
||||
OnChange:=@EdtIndexOnChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TListViewItemsPropertyEditorDlg.Destroy;
|
||||
begin
|
||||
LstIndex.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
//Créate new item
|
||||
procedure TListViewItemsPropertyEditorDlg.btnAddOnClick(Sender: TObject);
|
||||
begin
|
||||
fBuild:=True;
|
||||
try
|
||||
LB.Items.Add(sccsLvEdtBtnAdd);
|
||||
LstIndex.Add('-1');
|
||||
LB.ItemIndex:=LB.Items.Count-1;
|
||||
|
||||
edtLabel.Text:=LB.Items.Strings[LB.ItemIndex];
|
||||
edtIndex.Text:=LstIndex.Strings[LB.ItemIndex];
|
||||
finally
|
||||
fbuild:=False;
|
||||
end;
|
||||
|
||||
//Select the label editor
|
||||
if EdtLabel.CanFocus then
|
||||
begin
|
||||
EdtLabel.SetFocus;
|
||||
EdtLabel.SelectAll;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Delete the selected item
|
||||
procedure TListViewItemsPropertyEditorDlg.btnDelOnClick(Sender: TObject);
|
||||
Var i : Integer;
|
||||
begin
|
||||
If LB.ItemIndex<>-1 then
|
||||
begin
|
||||
i:=LB.ItemIndex;
|
||||
LB.Items.Delete(i);
|
||||
LstIndex.Delete(i);
|
||||
if LB.Items.Count=0 then
|
||||
i:=-1
|
||||
else
|
||||
begin
|
||||
If i>LB.Items.Count-1 then
|
||||
i:=LB.Items.Count-1;
|
||||
end;
|
||||
|
||||
try
|
||||
if i=-1 then
|
||||
begin
|
||||
EdtLabel.Text:='';
|
||||
EdtIndex.Text:='';
|
||||
end;
|
||||
|
||||
LB.ItemIndex:=i;
|
||||
except
|
||||
end;
|
||||
LBOnClick(nil);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
//Modify the TEdit for the Label and Image index
|
||||
procedure TListViewItemsPropertyEditorDlg.LBOnClick(Sender: TObject);
|
||||
begin
|
||||
If LB.ItemIndex<>-1 then
|
||||
begin
|
||||
fBuild:=True;
|
||||
try
|
||||
edtLabel.Text:=LB.Items.Strings[LB.ItemIndex];
|
||||
edtIndex.Text:=LstIndex.Strings[LB.ItemIndex];
|
||||
finally
|
||||
fBuild:=False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Refrsh the label list
|
||||
procedure TListViewItemsPropertyEditorDlg.EdtLabelOnChange(Sender: TObject);
|
||||
Var i : Integer;
|
||||
begin
|
||||
If (LB.ItemIndex<>-1) and not fBuild then
|
||||
begin
|
||||
i:=LB.ItemIndex;
|
||||
LB.Items.Strings[LB.ItemIndex]:=edtLabel.Text;
|
||||
LB.ItemIndex:=i;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Refresh the index list
|
||||
procedure TListViewItemsPropertyEditorDlg.EdtIndexOnChange(Sender: TObject);
|
||||
Var i,E : Integer;
|
||||
begin
|
||||
If (LB.ItemIndex<>-1) and not fBuild then
|
||||
begin
|
||||
Val(edtIndex.Text,i,E);
|
||||
if E<>0 then i:=-1;
|
||||
LstIndex.Strings[LB.ItemIndex]:=IntToStr(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
//Initialization of properties Items of TMainMenu and TPopupMenu
|
||||
RegisterPropertyEditor(ClassTypeInfo(TListItems), TListView,'Items',
|
||||
TListViewItemsPropertyEditor);
|
||||
|
||||
//Register a component editor for with mouse right clic, the popup
|
||||
RegisterComponentEditor(TListView,TListViewComponentEditor);
|
||||
end.
|
||||
@ -34,7 +34,8 @@ interface
|
||||
uses
|
||||
Forms, SysUtils, Buttons, Classes, Graphics, GraphType, StdCtrls, LCLType,
|
||||
LCLLinux, LMessages, Controls, ComCtrls, ExtCtrls, PropEdits, GraphPropEdits,
|
||||
TypInfo, Messages, LResources, Laz_XMLCfg, Menus, Dialogs, ObjInspStrConsts;
|
||||
TypInfo, Messages, LResources, Laz_XMLCfg, Menus, Dialogs, ObjInspStrConsts,
|
||||
listviewpropedit;
|
||||
|
||||
|
||||
type
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
""
|
||||
"Last-Translator: \n"
|
||||
"PO-Revision-Date: 2003-02-17 23:16+0100\n"
|
||||
"Language-Team: <fr@li.org>\n"
|
||||
"Content-Type: text/plain; charset=ISO-8859-1\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: KBabel 0.9.6\n"
|
||||
|
||||
#: lazarusidestrconsts:uemaddwatchatcursor
|
||||
msgid "&Add Watch At Cursor"
|
||||
msgstr "&Ajouter un suivi sous le curseur"
|
||||
@ -432,7 +442,7 @@ msgstr "Compteur (.pp;1)"
|
||||
|
||||
#: lazarusidestrconsts:dlgruberbandcreationcolor
|
||||
msgid "Creation"
|
||||
msgstr ""
|
||||
msgstr "Création"
|
||||
|
||||
#: lazarusidestrconsts:lismenuinsertdatetime
|
||||
msgid "Current date and time"
|
||||
@ -760,7 +770,7 @@ msgstr "Notice GPL"
|
||||
|
||||
#: lazarusidestrconsts:dlggrabbercolor
|
||||
msgid "Grabber color"
|
||||
msgstr ""
|
||||
msgstr "Couleur d'accroches"
|
||||
|
||||
#: lazarusidestrconsts:dlgenvgrid
|
||||
msgid "Grid"
|
||||
@ -1080,7 +1090,7 @@ msgstr "Menu principal"
|
||||
|
||||
#: lazarusidestrconsts:lismenumakeresourcestring
|
||||
msgid "Make Resource String"
|
||||
msgstr ""
|
||||
msgstr "Construire une resource de chaines"
|
||||
|
||||
#: lazarusidestrconsts:dlgmargingutter
|
||||
msgid "Margin and gutter"
|
||||
@ -1088,7 +1098,7 @@ msgstr "Marge et goutti
|
||||
|
||||
#: lazarusidestrconsts:dlgmarkercolor
|
||||
msgid "Marker color"
|
||||
msgstr ""
|
||||
msgstr "Couleur de marqueur"
|
||||
|
||||
#: lazarusidestrconsts:dlgmaxlinelength
|
||||
msgid "Max line length:"
|
||||
@ -1300,7 +1310,7 @@ msgstr "Pause"
|
||||
|
||||
#: lazarusidestrconsts:dlgpersistentcaret
|
||||
msgid "Persistent Caret"
|
||||
msgstr ""
|
||||
msgstr "Curseur persistent"
|
||||
|
||||
#: lazarusidestrconsts:lisplzcheckthecompilername
|
||||
msgid "Please check the compiler name"
|
||||
@ -1552,7 +1562,7 @@ msgstr "S
|
||||
|
||||
#: lazarusidestrconsts:dlgrubberbandselectsgrandchilds
|
||||
msgid "Select grand childs"
|
||||
msgstr ""
|
||||
msgstr "Choisir les grands enfants"
|
||||
|
||||
#: lazarusidestrconsts:lismenuselectline
|
||||
msgid "Select line"
|
||||
@ -1572,7 +1582,7 @@ msgstr "S
|
||||
|
||||
#: lazarusidestrconsts:dlgruberbandselectioncolor
|
||||
msgid "Selection"
|
||||
msgstr ""
|
||||
msgstr "Sélectionner"
|
||||
|
||||
#: lazarusidestrconsts:lisselectiontool
|
||||
msgid "Selection tool"
|
||||
|
||||
@ -163,6 +163,7 @@ type
|
||||
function GetIndex : Integer;
|
||||
protected
|
||||
Procedure ItemChanged(sender : TObject); //called by the onchange of the tstringlist in TListItem
|
||||
function IsEqual(Item : TListItem) : Boolean;
|
||||
public
|
||||
constructor Create(AOwner : TListItems);
|
||||
destructor Destroy; override;
|
||||
@ -192,6 +193,11 @@ type
|
||||
function GetItem(const AIndex: Integer): TListItem;
|
||||
procedure SetITem(const AIndex: Integer; const AValue: TListItem);
|
||||
procedure ItemChanged(sender : TObject); //called by TListItem in response to SubItems changing
|
||||
|
||||
procedure DefineProperties(Filer: TFiler); override;
|
||||
procedure ReadData(Stream: TStream);
|
||||
procedure WriteData(Stream: TStream);
|
||||
|
||||
public
|
||||
function Add: TListItem;
|
||||
procedure Clear;
|
||||
@ -1713,6 +1719,9 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.63 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
Revision 1.62 2002/12/28 11:29:47 mattias
|
||||
xmlcfg deletion, focus fixes
|
||||
|
||||
|
||||
@ -72,6 +72,11 @@ begin
|
||||
FOwner.ItemChanged(self);
|
||||
end;
|
||||
|
||||
function TListItem.IsEqual(Item: TListItem): Boolean;
|
||||
begin
|
||||
Result:=(Caption = Item.Caption) and (Data = Item.Data);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem Destructor }
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -116,6 +121,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.13 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
Revision 1.12 2002/11/25 11:37:18 mattias
|
||||
applied patch from Vasily
|
||||
|
||||
|
||||
@ -142,9 +142,166 @@ begin
|
||||
FOwner.ItemChanged(Index);
|
||||
end;
|
||||
|
||||
procedure TListItems.DefineProperties(Filer: TFiler);
|
||||
|
||||
function WriteItems: Boolean;
|
||||
var
|
||||
I: Integer;
|
||||
Items: TListItems;
|
||||
begin
|
||||
Items := TListItems(Filer.Ancestor);
|
||||
if not Assigned(Items) then
|
||||
Result := Count > 0
|
||||
else if (Items.Count <> Count) then
|
||||
Result := True
|
||||
else
|
||||
begin
|
||||
Result := False;
|
||||
for I := 0 to Count - 1 do
|
||||
begin
|
||||
Result := not Item[I].IsEqual(Items[I]);
|
||||
if Result then Break;
|
||||
end
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
inherited DefineProperties(Filer);
|
||||
Filer.DefineBinaryProperty('Data', @ReadData, @WriteData,WriteItems);
|
||||
end;
|
||||
|
||||
type
|
||||
PItemHeader = ^TItemHeader;
|
||||
TItemHeader = packed record
|
||||
Size, Count: Integer;
|
||||
Items: record end;
|
||||
end;
|
||||
PItemInfo = ^TItemInfo;
|
||||
TItemInfo = packed record
|
||||
ImageIndex: Integer;
|
||||
StateIndex: Integer;
|
||||
OverlayIndex: Integer;
|
||||
SubItemCount: Integer;
|
||||
Data: Pointer;
|
||||
Caption: string[255];
|
||||
end;
|
||||
ShortStr = string[255];
|
||||
PShortStr = ^ShortStr;
|
||||
|
||||
procedure TListItems.ReadData(Stream: TStream);
|
||||
var
|
||||
I, J, Size, L, Len: Integer;
|
||||
ItemHeader : PItemHeader;
|
||||
ItemInfo : PItemInfo;
|
||||
PStr : PShortStr;
|
||||
Flag : Boolean;
|
||||
begin
|
||||
Clear;
|
||||
Flag:=False;
|
||||
Stream.ReadBuffer(Size, SizeOf(Integer));
|
||||
ItemHeader := AllocMem(Size);
|
||||
Owner.BeginUpdate;
|
||||
try
|
||||
Stream.ReadBuffer(ItemHeader^.Count, Size - SizeOf(Integer));
|
||||
ItemInfo := @ItemHeader^.Items;
|
||||
PStr := nil;
|
||||
for I := 0 to ItemHeader^.Count - 1 do
|
||||
begin
|
||||
with Add do
|
||||
begin
|
||||
Flag:=True;
|
||||
Caption := ItemInfo^.Caption;
|
||||
ImageIndex := ItemInfo^.ImageIndex;
|
||||
Data := ItemInfo^.Data;
|
||||
PStr := @ItemInfo^.Caption;
|
||||
Inc(Integer(PStr), Length(PStr^) + 1);
|
||||
Len := 0;
|
||||
for J := 0 to ItemInfo^.SubItemCount - 1 do
|
||||
begin
|
||||
SubItems.Add(PStr^);
|
||||
L := Length(PStr^);
|
||||
Inc(Len, L + 1);
|
||||
Inc(Integer(PStr), L + 1);
|
||||
end;
|
||||
end;
|
||||
Inc(Integer(ItemInfo), SizeOf(TItemInfo)-255+Length(ItemInfo^.Caption)+Len);
|
||||
end;
|
||||
finally
|
||||
FreeMem(ItemHeader, Size);
|
||||
Owner.EndUpdate;
|
||||
|
||||
if Flag then
|
||||
Owner.ItemAdded;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TListItems.WriteData(Stream: TStream);
|
||||
var
|
||||
I, J, Size, L, Len: Integer;
|
||||
ItemHeader: PItemHeader;
|
||||
ItemInfo: PItemInfo;
|
||||
PStr: PShortStr;
|
||||
|
||||
function GetLength(const S: string): Integer;
|
||||
begin
|
||||
Result := Length(S);
|
||||
if Result > 255 then Result := 255;
|
||||
end;
|
||||
|
||||
begin
|
||||
Size := SizeOf(TItemHeader);
|
||||
for I := 0 to Count - 1 do
|
||||
begin
|
||||
L := GetLength(Item[I].Caption) + 1;
|
||||
for J := 0 to Item[I].SubItems.Count - 1 do
|
||||
begin
|
||||
Inc(L, GetLength(Item[I].SubItems[J]) + 1);
|
||||
Inc(L, SizeOf(Integer));
|
||||
end;
|
||||
Inc(Size, SizeOf(TItemInfo) - 255 + L);
|
||||
end;
|
||||
ItemHeader := AllocMem(Size);
|
||||
try
|
||||
ItemHeader^.Size := Size;
|
||||
ItemHeader^.Count := Count;
|
||||
ItemInfo := @ItemHeader^.Items;
|
||||
PStr := nil;
|
||||
for I := 0 to Count - 1 do
|
||||
begin
|
||||
with Item[I] do
|
||||
begin
|
||||
ItemInfo^.Caption := Caption;
|
||||
ItemInfo^.ImageIndex := ImageIndex;
|
||||
ItemInfo^.OverlayIndex := -1 {OverlayIndex};
|
||||
ItemInfo^.StateIndex := -1 {StateIndex};
|
||||
ItemInfo^.Data := Data;
|
||||
ItemInfo^.SubItemCount := SubItems.Count;
|
||||
PStr := @ItemInfo^.Caption;
|
||||
Inc(Integer(PStr), Length(ItemInfo^.Caption) + 1);
|
||||
Len := 0;
|
||||
for J := 0 to SubItems.Count - 1 do
|
||||
begin
|
||||
PStr^ := SubItems[J];
|
||||
L := Length(PStr^);
|
||||
Inc(Len, L + 1);
|
||||
Inc(Integer(PStr), L + 1);
|
||||
end;
|
||||
end;
|
||||
Inc(Integer(ItemInfo), SizeOf(TItemInfo) - 255 +
|
||||
Length(ItemInfo^.Caption) + Len);
|
||||
end;
|
||||
Stream.WriteBuffer(ItemHeader^, Size);
|
||||
finally
|
||||
FreeMem(ItemHeader, Size);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.16 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
Revision 1.15 2002/11/18 13:38:44 mattias
|
||||
fixed buffer overrun and added several checks
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user