Now the memo editor has its own unit to live in the editor link should also live there. Moves relevant code from main and rename the object to TMemoEditorLink to be more clear.

This commit is contained in:
Ansgar Becker
2008-08-07 22:39:22 +00:00
parent b0466f3de8
commit 7d168f5526
3 changed files with 123 additions and 126 deletions

View File

@ -576,7 +576,7 @@ uses
Main, fieldeditor, Main, fieldeditor,
copytable, sqlhelp, printlist, copytable, sqlhelp, printlist,
column_selection, data_sorting, runsqlfile, mysql_structures, column_selection, data_sorting, runsqlfile, mysql_structures,
Registry; Registry, memoeditor;
type type
@ -6035,13 +6035,10 @@ end;
procedure TMDIChild.DataGridCreateEditor(Sender: TBaseVirtualTree; Node: procedure TMDIChild.DataGridCreateEditor(Sender: TBaseVirtualTree; Node:
PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink); PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
var
Editor: TMemoEditor;
begin begin
if FDataGridResult.Columns[Column].IsMemo then begin if FDataGridResult.Columns[Column].IsMemo then
Editor := TMemoEditor.Create; EditLink := TMemoEditorLink.Create
EditLink := Editor; else
end else
EditLink := TStringEditLink.Create; EditLink := TStringEditLink.Create;
end; end;

View File

@ -18,7 +18,7 @@ uses
SynMemo, synedit, SynEditTypes, ZDataSet, ZSqlProcessor, SynMemo, synedit, SynEditTypes, ZDataSet, ZSqlProcessor,
HeidiComp, sqlhelp, MysqlQueryThread, Childwin, VirtualTrees, HeidiComp, sqlhelp, MysqlQueryThread, Childwin, VirtualTrees,
DateUtils, PngImageList, OptimizeTables, View, Usermanager, DateUtils, PngImageList, OptimizeTables, View, Usermanager,
SelectDBObject, TntStdCtrls, memoeditor; SelectDBObject;
type type
TMainForm = class(TForm) TMainForm = class(TForm)
@ -334,31 +334,6 @@ type
end; end;
TMemoEditor = class(TInterfacedObject, IVTEditLink)
private
FForm: TfrmMemoEditor;
FTree: TCustomVirtualStringTree; // A back reference to the tree calling.
FNode: PVirtualNode; // The node to be edited.
FColumn: TColumnIndex; // The column of the node.
FTextBounds: TRect; // Smallest rectangle around the text.
FStopping: Boolean; // Set to True when the edit link requests stopping the edit action.
public
FieldType: Integer;
MaxInputLength: Integer;
constructor Create;
destructor Destroy; override;
function BeginEdit: Boolean; virtual; stdcall;
function CancelEdit: Boolean; virtual; stdcall;
function EndEdit: Boolean; virtual; stdcall;
function GetBounds: TRect; virtual; stdcall;
function PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; virtual; stdcall;
procedure ProcessMessage(var Message: TMessage); virtual; stdcall;
procedure SetBounds(R: TRect); virtual; stdcall;
end;
var var
MainForm : TMainForm; MainForm : TMainForm;
appstarted : Boolean = false; // see connections.pas appstarted : Boolean = false; // see connections.pas
@ -2153,96 +2128,4 @@ begin
end; end;
constructor TMemoEditor.Create;
begin
inherited;
end;
destructor TMemoEditor.Destroy;
begin
inherited;
FForm.Free;
end;
function TMemoEditor.PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; stdcall;
// Retrieves the true text bounds from the owner tree.
var
Text: WideString;
F: TFont;
begin
Result := Tree is TCustomVirtualStringTree;
if not Result then
exit;
FTree := Tree as TVirtualStringTree;
FNode := Node;
FColumn := Column;
// Initial size, font and text of the node.
F := TFont.Create;
FTree.GetTextInfo(Node, Column, F, FTextBounds, Text);
// Create the editor form
FForm := TfrmMemoEditor.Create(Ftree);
FForm.Parent := Tree;
FForm.memoText.Font := F;
FForm.memoText.Text := Text;
end;
function TMemoEditor.BeginEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then
FForm.Show;
end;
function TMemoEditor.CancelEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then begin
FStopping := True;
FForm.Hide;
FTree.CancelEditNode;
end;
end;
function TMemoEditor.EndEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then try
FStopping := True;
if FForm.memoText.Text <> FTree.Text[FNode, FColumn] then
FTree.Text[FNode, FColumn] := FForm.memoText.Text;
FForm.Hide;
except
FStopping := False;
raise;
end;
end;
function TMemoEditor.GetBounds: TRect; stdcall;
begin
Result := FForm.BoundsRect;
end;
procedure TMemoEditor.ProcessMessage(var Message: TMessage); stdcall;
begin
end;
procedure TMemoEditor.SetBounds(R: TRect); stdcall;
begin
// Sets the top left corner of the edit control
if not FStopping then
FForm.TopLeft := R.TopLeft;
end;
end. end.

View File

@ -4,7 +4,7 @@ interface
uses uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TntStdCtrls, Registry; Dialogs, StdCtrls, TntStdCtrls, Registry, VirtualTrees;
{$I const.inc} {$I const.inc}
@ -21,6 +21,31 @@ type
end; end;
// The editor link, instanciated by VirtualTree.CreateEditor
TMemoEditorLink = class(TInterfacedObject, IVTEditLink)
private
FForm: TfrmMemoEditor;
FTree: TCustomVirtualStringTree; // A back reference to the tree calling.
FNode: PVirtualNode; // The node to be edited.
FColumn: TColumnIndex; // The column of the node.
FTextBounds: TRect; // Smallest rectangle around the text.
FStopping: Boolean; // Set to True when the edit link requests stopping the edit action.
public
FieldType: Integer;
MaxInputLength: Integer;
constructor Create;
destructor Destroy; override;
function BeginEdit: Boolean; virtual; stdcall;
function CancelEdit: Boolean; virtual; stdcall;
function EndEdit: Boolean; virtual; stdcall;
function GetBounds: TRect; virtual; stdcall;
function PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; virtual; stdcall;
procedure ProcessMessage(var Message: TMessage); virtual; stdcall;
procedure SetBounds(R: TRect); virtual; stdcall;
end;
implementation implementation
uses main, helpers; uses main, helpers;
@ -58,4 +83,96 @@ begin
memoText.SetFocus; memoText.SetFocus;
end; end;
constructor TMemoEditorLink.Create;
begin
inherited;
end;
destructor TMemoEditorLink.Destroy;
begin
inherited;
FForm.Free;
end;
function TMemoEditorLink.PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; stdcall;
// Retrieves the true text bounds from the owner tree.
var
Text: WideString;
F: TFont;
begin
Result := Tree is TCustomVirtualStringTree;
if not Result then
exit;
FTree := Tree as TVirtualStringTree;
FNode := Node;
FColumn := Column;
// Initial size, font and text of the node.
F := TFont.Create;
FTree.GetTextInfo(Node, Column, F, FTextBounds, Text);
// Create the editor form
FForm := TfrmMemoEditor.Create(Ftree);
FForm.Parent := Tree;
FForm.memoText.Font := F;
FForm.memoText.Text := Text;
end;
function TMemoEditorLink.BeginEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then
FForm.Show;
end;
function TMemoEditorLink.CancelEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then begin
FStopping := True;
FForm.Hide;
FTree.CancelEditNode;
end;
end;
function TMemoEditorLink.EndEdit: Boolean; stdcall;
begin
Result := not FStopping;
if Result then try
FStopping := True;
if FForm.memoText.Text <> FTree.Text[FNode, FColumn] then
FTree.Text[FNode, FColumn] := FForm.memoText.Text;
FForm.Hide;
except
FStopping := False;
raise;
end;
end;
function TMemoEditorLink.GetBounds: TRect; stdcall;
begin
Result := FForm.BoundsRect;
end;
procedure TMemoEditorLink.ProcessMessage(var Message: TMessage); stdcall;
begin
end;
procedure TMemoEditorLink.SetBounds(R: TRect); stdcall;
begin
// Sets the top left corner of the edit control
if not FStopping then
FForm.TopLeft := R.TopLeft;
end;
end. end.