You've already forked lazarus-ccr
* add demo to test drag and drop
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2191 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,52 @@
|
|||||||
|
object MainForm: TMainForm
|
||||||
|
Left = 569
|
||||||
|
Height = 362
|
||||||
|
Top = 219
|
||||||
|
Width = 461
|
||||||
|
Caption = 'VTV Drag and Drop'
|
||||||
|
ClientHeight = 362
|
||||||
|
ClientWidth = 461
|
||||||
|
Position = poDesktopCenter
|
||||||
|
LCLVersion = '0.9.31'
|
||||||
|
object VirtualStringTree1: TVirtualStringTree
|
||||||
|
Left = 8
|
||||||
|
Height = 315
|
||||||
|
Top = 24
|
||||||
|
Width = 200
|
||||||
|
DefaultText = 'Node'
|
||||||
|
DragMode = dmAutomatic
|
||||||
|
DragType = dtVCL
|
||||||
|
Header.AutoSizeIndex = 0
|
||||||
|
Header.Columns = <>
|
||||||
|
Header.DefaultHeight = 17
|
||||||
|
Header.MainColumn = -1
|
||||||
|
RootNodeCount = 30
|
||||||
|
TabOrder = 0
|
||||||
|
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScroll, toAutoScrollOnExpand, toAutoTristateTracking, toAutoDeleteMovedNodes]
|
||||||
|
OnDragOver = VirtualStringTree1DragOver
|
||||||
|
OnDragDrop = VirtualStringTree1DragDrop
|
||||||
|
OnGetText = VirtualStringTree1GetText
|
||||||
|
OnGetNodeDataSize = VirtualStringTree1GetNodeDataSize
|
||||||
|
OnInitNode = VirtualStringTree1InitNode
|
||||||
|
end
|
||||||
|
object ListBox1: TListBox
|
||||||
|
Left = 256
|
||||||
|
Height = 315
|
||||||
|
Top = 24
|
||||||
|
Width = 192
|
||||||
|
DragMode = dmAutomatic
|
||||||
|
Items.Strings = (
|
||||||
|
'List Item 1'
|
||||||
|
'List Item 2'
|
||||||
|
'List Item 3'
|
||||||
|
'List Item 4'
|
||||||
|
'List Item 5'
|
||||||
|
'List Item 6'
|
||||||
|
)
|
||||||
|
ItemHeight = 23
|
||||||
|
OnDragDrop = ListBox1DragDrop
|
||||||
|
OnDragOver = ListBox1DragOver
|
||||||
|
ScrollWidth = 190
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,128 @@
|
|||||||
|
unit fMain;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||||
|
VirtualTrees, FakeActiveX;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TMainForm }
|
||||||
|
|
||||||
|
TMainForm = class(TForm)
|
||||||
|
ListBox1: TListBox;
|
||||||
|
VirtualStringTree1: TVirtualStringTree;
|
||||||
|
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
|
||||||
|
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
|
||||||
|
State: TDragState; var Accept: Boolean);
|
||||||
|
procedure VirtualStringTree1DragDrop(Sender: TBaseVirtualTree;
|
||||||
|
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
|
||||||
|
Shift: TShiftState; const Pt: TPoint; var Effect: Integer; Mode: TDropMode
|
||||||
|
);
|
||||||
|
procedure VirtualStringTree1DragOver(Sender: TBaseVirtualTree;
|
||||||
|
Source: TObject; Shift: TShiftState; State: TDragState; const Pt: TPoint;
|
||||||
|
Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
|
||||||
|
procedure VirtualStringTree1GetNodeDataSize(Sender: TBaseVirtualTree;
|
||||||
|
var NodeDataSize: Integer);
|
||||||
|
procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree;
|
||||||
|
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
||||||
|
var CellText: String);
|
||||||
|
procedure VirtualStringTree1InitNode(Sender: TBaseVirtualTree; ParentNode,
|
||||||
|
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
|
||||||
|
private
|
||||||
|
{ private declarations }
|
||||||
|
public
|
||||||
|
{ public declarations }
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
MainForm: TMainForm;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
TNodeData = record
|
||||||
|
Title: String;
|
||||||
|
end;
|
||||||
|
|
||||||
|
PNodeData = ^TNodeData;
|
||||||
|
|
||||||
|
{ TMainForm }
|
||||||
|
|
||||||
|
procedure TMainForm.VirtualStringTree1GetText(Sender: TBaseVirtualTree;
|
||||||
|
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
||||||
|
var CellText: String);
|
||||||
|
begin
|
||||||
|
CellText := PNodeData(Sender.GetNodeData(Node))^.Title;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
|
||||||
|
ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
|
||||||
|
begin
|
||||||
|
PNodeData(Sender.GetNodeData(Node))^.Title := 'VTV Item ' + IntToStr(Node^.Index);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
|
||||||
|
State: TDragState; var Accept: Boolean);
|
||||||
|
begin
|
||||||
|
Accept := (Source = VirtualStringTree1) or (Source = ListBox1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
|
||||||
|
var
|
||||||
|
Node: PVirtualNode;
|
||||||
|
begin
|
||||||
|
if Source = VirtualStringTree1 then
|
||||||
|
begin
|
||||||
|
Node := VirtualStringTree1.FocusedNode;
|
||||||
|
if Node <> nil then
|
||||||
|
ListBox1.Items.Append(VirtualStringTree1.Text[Node, 0]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.VirtualStringTree1DragDrop(Sender: TBaseVirtualTree;
|
||||||
|
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
|
||||||
|
Shift: TShiftState; const Pt: TPoint; var Effect: Integer; Mode: TDropMode);
|
||||||
|
var
|
||||||
|
Node: PVirtualNode;
|
||||||
|
S: String;
|
||||||
|
begin
|
||||||
|
if Source = ListBox1 then
|
||||||
|
begin
|
||||||
|
Node := Sender.AddChild(Sender.DropTargetNode);
|
||||||
|
if ListBox1.ItemIndex = -1 then
|
||||||
|
S := 'Unknow Item from List'
|
||||||
|
else
|
||||||
|
S := ListBox1.Items[ListBox1.ItemIndex];
|
||||||
|
Sender.ValidateNode(Node, True);
|
||||||
|
PNodeData(Sender.GetNodeData(Node))^.Title := S;
|
||||||
|
end
|
||||||
|
else if Source = Sender then
|
||||||
|
begin
|
||||||
|
Node := Sender.AddChild(Sender.DropTargetNode);
|
||||||
|
Sender.ValidateNode(Node, True);
|
||||||
|
PNodeData(Sender.GetNodeData(Node))^.Title := VirtualStringTree1.Text[Sender.FocusedNode, 0];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.VirtualStringTree1DragOver(Sender: TBaseVirtualTree;
|
||||||
|
Source: TObject; Shift: TShiftState; State: TDragState; const Pt: TPoint;
|
||||||
|
Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
|
||||||
|
begin
|
||||||
|
Accept := (Sender = VirtualStringTree1) or (Source = ListBox1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.VirtualStringTree1GetNodeDataSize(Sender: TBaseVirtualTree;
|
||||||
|
var NodeDataSize: Integer);
|
||||||
|
begin
|
||||||
|
NodeDataSize := SizeOf(TNodeData);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<General>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
<UseXPManifest Value="True"/>
|
||||||
|
<Icon Value="0"/>
|
||||||
|
</General>
|
||||||
|
<i18n>
|
||||||
|
<EnableI18N LFM="False"/>
|
||||||
|
</i18n>
|
||||||
|
<VersionInfo>
|
||||||
|
<StringTable ProductVersion=""/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
|
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="2">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="virtualtreeview_package"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item2>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="2">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="vtvdragdrop.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="vtvdragdrop"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="fmain.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<ComponentName Value="MainForm"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
|
<UnitName Value="fMain"/>
|
||||||
|
</Unit1>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="vtvdragdrop"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Linking>
|
||||||
|
<Options>
|
||||||
|
<Win32>
|
||||||
|
<GraphicApplication Value="True"/>
|
||||||
|
</Win32>
|
||||||
|
</Options>
|
||||||
|
</Linking>
|
||||||
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,21 @@
|
|||||||
|
program vtvdragdrop;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||||
|
cthreads,
|
||||||
|
{$ENDIF}{$ENDIF}
|
||||||
|
Interfaces, // this includes the LCL widgetset
|
||||||
|
Forms, fMain, virtualtreeview_package
|
||||||
|
{ you can add units after this };
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
|
begin
|
||||||
|
RequireDerivedFormResource := True;
|
||||||
|
Application.Initialize;
|
||||||
|
Application.CreateForm(TMainForm, MainForm);
|
||||||
|
Application.Run;
|
||||||
|
end.
|
||||||
|
|
Reference in New Issue
Block a user