sparta: remove USE_GENERICS_COLLECTIONS ifdefs

git-svn-id: trunk@51170 -
This commit is contained in:
ondrej 2016-01-03 20:00:41 +00:00
parent 416b79849e
commit 3849445a19
3 changed files with 0 additions and 239 deletions

View File

@ -7,16 +7,13 @@ interface
uses
Classes, SysUtils;
{$IFNDEF USE_GENERICS_COLLECTIONS}
type
THash_TObject = record
class function Hash(A: TObject; B: SizeUInt): SizeUInt; static;
end;
{$ENDIF}
implementation
{$IFNDEF USE_GENERICS_COLLECTIONS}
class function THash_TObject.Hash(A: TObject; B: SizeUInt): SizeUInt;
begin
if A = nil then
@ -24,7 +21,6 @@ begin
Result := A.GetHashCode() and (b - 1);
end;
{$ENDIF}
end.

View File

@ -27,11 +27,7 @@ uses
Classes, SysUtils, SrcEditorIntf, LazIDEIntf, ComCtrls, Controls, Forms, {$IFDEF USE_POPUP_PARENT_DESIGNER}Windows,{$ENDIF} IDEImagesIntf,
Buttons, ExtCtrls, Graphics, IDEWindowIntf,
sparta_DesignedForm, sparta_resizer, PropEdits, PropEditUtils, FormEditingIntf, ComponentEditors, EditBtn,
{$IFDEF USE_GENERICS_COLLECTIONS}
Generics.Collections, Generics.Defaults,
{$ELSE}
ghashmap, sparta_HashUtils, gvector,
{$ENDIF}
TypInfo, LCLIntf, LCLType, LMessages, sparta_FakeForm, sparta_FakeFrame, SpartaAPI;
const
@ -41,11 +37,7 @@ const
type
{ TDesignFormData }
{$IFDEF USE_GENERICS_COLLECTIONS}
TDesignFormData = class(TSingletonImplementation, IDesignedForm)
{$ELSE}
TDesignFormData = class(TComponent, IDesignedForm)
{$ENDIF}
private
FWndMethod: TWndMethod;
@ -57,22 +49,14 @@ type
FLastScreenshot: TBitmap;
FPopupParent: TSourceEditorWindowInterface;
FHiding: boolean;
{$IFDEF USE_GENERICS_COLLECTIONS}
FFormImages: TList<TImage>;
{$ELSE}
FFormImages: TList;
{$ENDIF}
protected
procedure WndMethod(var TheMessage: TLMessage);
procedure SetPopupParent(AVal: TSourceEditorWindowInterface);
procedure DoAddForm;
public
{$IFDEF USE_GENERICS_COLLECTIONS}
class var AddFormEvents: TList<TNotifyEvent>;
{$ELSE}
class var AddFormEvents: TVector<TNotifyEvent>;
{$ENDIF}
class constructor Init;
class destructor Finit;
@ -118,11 +102,7 @@ type
private
FWndMethod: TWndMethod;
FForm: TSourceEditorWindowInterface;
{$IFDEF USE_GENERICS_COLLECTIONS}
FPageCtrlList: TDictionary<TSourceEditorInterface, TModulePageControl>;
{$ELSE}
FPageCtrlList: THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>;
{$ENDIF}
FLastTopParent: TControl;
procedure SetActiveDesignFormData(const AValue: TDesignFormData);
@ -201,11 +181,7 @@ type
var
Forms: Classes.TList; // normal forms
dsgForms: Classes.TList; // design forms
{$IFDEF USE_GENERICS_COLLECTIONS}
SourceEditorWindows: TObjectDictionary<TSourceEditorWindowInterface, TSourceEditorWindowData>;
{$ELSE}
SourceEditorWindows: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>;
{$ENDIF}
LastActiveSourceEditorWindow: TSourceEditorWindowInterface = nil;
LastActiveSourceEditor: TSourceEditorInterface = nil;
@ -275,16 +251,9 @@ end;
function AbsoluteFindModulePageControl(ASrcEditor: TSourceEditorInterface): TModulePageControl;
var
LSEWD: TSourceEditorWindowData;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
{$ENDIF}
begin
Result := nil;
{$IFDEF USE_GENERICS_COLLECTIONS}
for LSEWD in SourceEditorWindows.Values do
if LSEWD.FPageCtrlList.ContainsKey(ASrcEditor) then
Exit(LSEWD.FPageCtrlList[ASrcEditor]);
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -296,8 +265,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
end;
function FindSourceEditorForDesigner(ADesigner: TIDesigner): TSourceEditorInterface;
@ -338,29 +305,8 @@ procedure RefreshAllSourceWindowsModulePageControl;
var
LWindow: TSourceEditorWindowInterface;
LPageCtrl: TModulePageControl;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
{$ENDIF}
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
for LWindow in SourceEditorWindows.Keys do
begin
LPageCtrl := FindModulePageControl(LWindow);
// for example LPageCtrl is nil when we clone module to new window
if (LPageCtrl = nil) or (csDestroying in LWindow.ComponentState) then
Continue;
if LWindow.ActiveEditor = nil then
LPageCtrl.HideDesignPage
else
if LWindow.ActiveEditor.GetDesigner(True) <> nil then
// TODO some check function: is displayed right form?
LPageCtrl.ShowDesignPage
else
LPageCtrl.HideDesignPage;
end;
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -385,7 +331,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
end;
// sometimes at some level of initialization form can not contain TIDesigner
@ -409,30 +354,13 @@ function FindDesignFormData(AModulePageCtrl: TModulePageControl): TDesignFormDat
var
LSourceWindow: TSourceEditorWindowInterface;
LSourceEditor: TSourceEditorInterface;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
{$ENDIF}
begin
Result := nil;
if AModulePageCtrl = nil then
Exit;
{$IFDEF USE_GENERICS_COLLECTIONS}
for LSourceWindow in SourceEditorWindows.Keys do
begin
if AModulePageCtrl.Owner = LSourceWindow then
begin
LSourceEditor := LSourceWindow.ActiveEditor;
if LSourceEditor = nil then
Exit;
Result := FindDesignFormData(LSourceEditor.GetDesigner(True));
Exit;
end;
end;
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -453,7 +381,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
end;
{ TDesignFormData }
@ -545,11 +472,7 @@ end;
class constructor TDesignFormData.Init;
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
AddFormEvents := TList<TNotifyEvent>.Create;
{$ELSE}
AddFormEvents := TVector<TNotifyEvent>.Create;
{$ENDIF}
end;
class destructor TDesignFormData.Finit;
@ -582,21 +505,11 @@ end;
procedure TDesignFormData.DoAddForm;
var
{$IFDEF USE_GENERICS_COLLECTIONS}
ne: TNotifyEvent;
{$ELSE}
i: Integer;
{$ENDIF}
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
for ne in AddFormEvents do
ne(Self);
{$ELSE}
if AddFormEvents.Size > 0 then // Arithmetic overflow without a test. Size = unsigned.
for i := 0 to AddFormEvents.Size-1 do
AddFormEvents[i](Self);
{$ENDIF}
end;
constructor TDesignFormData.Create(AForm: TCustomForm);
@ -609,11 +522,7 @@ begin
if FForm.Form is TFakeForm then
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
FFormImages := TList<TImage>.Create;
{$ELSE}
FFormImages := TList.Create;
{$ENDIF}
DoAddForm;
end;
end;
@ -745,11 +654,7 @@ begin
FWndMethod := AForm.WindowProc;
AForm.WindowProc := WndMethod;
FForm := AForm;
{$IFDEF USE_GENERICS_COLLECTIONS}
FPageCtrlList := TDictionary<TSourceEditorInterface, TModulePageControl>.Create;
{$ELSE}
FPageCtrlList := THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>.Create;
{$ENDIF}
end;
destructor TSourceEditorWindowData.Destroy;
@ -770,21 +675,13 @@ end;
procedure TSourceEditorWindowData.AddPageCtrl(ASrcEditor: TSourceEditorInterface; APage: TModulePageControl);
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
FPageCtrlList.Add(ASrcEditor, APage);
{$ELSE}
FPageCtrlList.insert(ASrcEditor, APage);
{$ENDIF}
APage.Pages[1].OnChangeBounds:=OnChangeBounds;
end;
procedure TSourceEditorWindowData.RemovePageCtrl(ASrcEditor: TSourceEditorInterface);
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
FPageCtrlList.Remove(ASrcEditor);
{$ELSE}
FPageCtrlList.Delete(ASrcEditor);
{$ENDIF}
end;
{ TDTXTabMaster }
@ -969,10 +866,8 @@ var
LSEWD: TSourceEditorWindowData;
mpc: TModulePageControl;
LFormData: TDesignFormData;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
LIterator2: THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>.TIterator;
{$ENDIF}
begin
{$IFNDEF USE_POPUP_PARENT_DESIGNER}
Form.Parent := nil;
@ -982,19 +877,6 @@ begin
LFormData := FindDesignFormData(Form);
dsgForms.Remove(LFormData);
{$IFDEF USE_GENERICS_COLLECTIONS}
for LSEWD in SourceEditorWindows.Values do
begin
if LSEWD.ActiveDesignFormData <> nil then
if LSEWD.ActiveDesignFormData.Form.Form = Form then
LSEWD.FActiveDesignFormData := nil; // important - we can't call OnChange tab, because tab don't exist anymore
for mpc in LSEWD.FPageCtrlList.Values do
if mpc.DesignFormData <> nil then
if mpc.DesignFormData.Form.Form = Form then
mpc.DesignFormData := nil;
end;
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -1020,7 +902,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
LFormData.Free;
end;
@ -1045,11 +926,7 @@ begin
if Sender.ClassNameIs('TSourceNotebook') then
begin
LSourceEditorWindow := Sender as TSourceEditorWindowInterface;
{$IFDEF USE_GENERICS_COLLECTIONS}
SourceEditorWindows.Add(LSourceEditorWindow, TSourceEditorWindowData.Create(LSourceEditorWindow));
{$ELSE}
SourceEditorWindows.insert(LSourceEditorWindow, TSourceEditorWindowData.Create(LSourceEditorWindow));
{$ENDIF}
end;
end;
@ -1061,12 +938,8 @@ begin
for p in dsgForms do
if f.FForm.LastActiveSourceWindow = Sender then
f.FForm.LastActiveSourceWindow := nil;
{$IFDEF USE_GENERICS_COLLECTIONS}
SourceEditorWindows.Remove(Sender as TSourceEditorWindowInterface);
{$ELSE}
SourceEditorWindows[Sender as TSourceEditorWindowInterface].Free;
SourceEditorWindows.Delete(Sender as TSourceEditorWindowInterface);
{$ENDIF}
if LastActiveSourceEditorWindow = Sender then
LastActiveSourceEditorWindow := nil;
end;
@ -1079,17 +952,10 @@ var
begin
LWindow := Sender as TSourceEditorWindowInterface;
{$IFDEF USE_GENERICS_COLLECTIONS}
if not SourceEditorWindows.TryGetValue(LWindow, LWindowData) or
(LWindowData.ActiveDesignFormData = nil)
then
Exit;
{$ELSE}
if not SourceEditorWindows.contains(LWindow) then
Exit;
if SourceEditorWindows.GetData(LWindow).ActiveDesignFormData = nil then
Exit;
{$ENDIF}
LDesignedForm := LWindowData.ActiveDesignFormData as IDesignedForm;
LDesignedForm.ShowWindow;
@ -1103,18 +969,11 @@ var
begin
LWindow := Sender as TSourceEditorWindowInterface;
{$IFDEF USE_GENERICS_COLLECTIONS}
if not SourceEditorWindows.TryGetValue(LWindow, LWindowData) or
(LWindowData.ActiveDesignFormData = nil)
then
Exit;
{$ELSE}
if not SourceEditorWindows.contains(LWindow) then
Exit;
LWindowData := SourceEditorWindows[LWindow];
if LWindowData.ActiveDesignFormData = nil then
Exit;
{$ENDIF}
LDesignedForm := LWindowData.ActiveDesignFormData as IDesignedForm;
LDesignedForm.HideWindow;
@ -1133,9 +992,7 @@ class procedure TSpartaMainIDE.EditorActivated(Sender: TObject);
var
LDesigner: TIDesigner;
LSourceEditor: TSourceEditorInterface;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>.TIterator;
{$ENDIF}
function LastSourceEditorNotFound: boolean;
var
@ -1145,24 +1002,6 @@ var
if (LastActiveSourceEditorWindow = nil) or (LastActiveSourceEditor = nil) then
Exit(False);
{$IFDEF USE_GENERICS_COLLECTIONS}
for se in SourceEditorWindows[LastActiveSourceEditorWindow].FPageCtrlList.Keys do
begin
Result := True;
for i := 0 to LastActiveSourceEditorWindow.Count - 1 do
if se = LastActiveSourceEditorWindow.Items[i] then
begin
Result := False;
Break;
end;
if Result then
begin
LastActiveSourceEditor := se; // after moving code editor into other window, sometimes IDE switch to other tab :\ damn... this line prevent this.
Exit;
end;
end;
{$ELSE}
LIterator := SourceEditorWindows[LastActiveSourceEditorWindow].FPageCtrlList.Iterator;
if LIterator <> nil then
try
@ -1184,7 +1023,6 @@ var
finally
LIterator.Free;
end;
{$ENDIF}
Result := False;
end;
@ -1384,13 +1222,9 @@ class procedure TSpartaMainIDE.TabChange(Sender: TObject);
var
LActiveSourceWindow: TSourceEditorWindowInterface;
w: TSourceEditorWindowInterface;
{$IFDEF USE_GENERICS_COLLECTIONS}
p: TPair<TSourceEditorInterface, TModulePageControl>;
{$ELSE}
p: THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>.TPair;
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
LIterator2: THashmap<TSourceEditorInterface, TModulePageControl, THash_TObject>.TIterator;
{$ENDIF}
LDesigner: TIDesigner;
LFormData: TDesignFormData;
LPageCtrl: TModulePageControl;
@ -1409,34 +1243,6 @@ begin
LDesigner := LActiveSourceWindow.ActiveEditor.GetDesigner(True);
LFormData := FindDesignFormData(LDesigner);
{$IFDEF USE_GENERICS_COLLECTIONS}
if (LFormData <> nil) and SourceEditorWindows.TryGetValue(LActiveSourceWindow, LSourceWndData) then
begin
case LPageCtrl.ActivePageIndex of
0:
begin
LSourceWndData.ActiveDesignFormData := nil;
end;
1:
begin
// deactivate design tab in other page control :)
for w in SourceEditorWindows.Keys do
if w = LActiveSourceWindow then
Continue
else
for p in SourceEditorWindows[w].FPageCtrlList do
if (p.Value.DesignFormData = LFormData) and (p.Value <> Sender) then
begin
IDETabMaster.ShowCode(p.Key);
end;
LSourceWndData.ActiveDesignFormData := LFormData;
// to handle windows with different size
LPageCtrl.BoundToDesignTabSheet;
end;
end;
end;
{$ELSE}
if (LFormData <> nil) and SourceEditorWindows.contains(LActiveSourceWindow) then
begin
LSourceWndData := SourceEditorWindows[LActiveSourceWindow];
@ -1480,23 +1286,14 @@ begin
end;
end;
end;
{$ENDIF}
end;
end;
class procedure TSpartaMainIDE.GlobalOnChangeBounds(Sender: TObject);
var
sewd: TSourceEditorWindowData;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
{$ENDIF}
begin
{$IFDEF USE_GENERICS_COLLECTIONS}
for sewd in SourceEditorWindows.Values do
begin
sewd.OnChangeBounds(Sender);
end;
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -1507,7 +1304,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
end;
class procedure TSpartaMainIDE.GlobalSNOnChangeBounds(Sender: TObject);
@ -1520,14 +1316,9 @@ begin
LWindow := Sender as TSourceEditorWindowInterface;
// dock/undock event :)
{$IFDEF USE_GENERICS_COLLECTIONS}
if not SourceEditorWindows.TryGetValue(LWindow, LWindowData) then
Exit;
{$ELSE}
if not SourceEditorWindows.contains(LWindow) then
Exit;
LWindowData := SourceEditorWindows[LWindow];
{$ENDIF}
if LWindowData.FLastTopParent <> LWindow.GetTopParent then
begin
LWindowData.FLastTopParent := LWindow.GetTopParent;
@ -1578,9 +1369,7 @@ var
LPageCtrl, p: TModulePageControl;
w: TSourceEditorWindowInterface;
e: TSourceEditorInterface;
{$IFNDEF USE_GENERICS_COLLECTIONS}
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
{$ENDIF}
begin
LForm := FindDesignFormData(TCustomForm(Sender).Designer);
if LForm = nil then
@ -1597,18 +1386,6 @@ begin
if AComponentPaletteClassSelected then
begin
// if form is already opened do nothing, if not then show form for active module.
{$IFDEF USE_GENERICS_COLLECTIONS}
for w in SourceEditorWindows.Keys do
begin
e := w.ActiveEditor;
if (e = nil) or (e.GetDesigner(True) <> LForm.Form.Form.Designer) then
Continue;
p := FindModulePageControl(e);
if p.PageIndex = 1 then
Exit;
end;
{$ELSE}
LIterator := SourceEditorWindows.Iterator;
if LIterator <> nil then
try
@ -1625,7 +1402,6 @@ begin
finally
LIterator.Free;
end;
{$ENDIF}
end;
IDETabMaster.ShowDesigner(SourceEditorManagerIntf.ActiveEditor);
@ -1728,7 +1504,6 @@ begin
end;
end;
{$IFNDEF USE_GENERICS_COLLECTIONS}
class procedure FreeSourceEditorWindowsValues;
var
LIterator: THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.TIterator;
@ -1743,21 +1518,14 @@ begin
LIterator.Free;
end;
end;
{$ENDIF}
initialization
dsgForms := Classes.TList.Create;
{$IFDEF USE_GENERICS_COLLECTIONS}
SourceEditorWindows := TObjectDictionary<TSourceEditorWindowInterface, TSourceEditorWindowData>.Create([doOwnsValues]);
{$ELSE}
SourceEditorWindows := THashmap<TSourceEditorWindowInterface, TSourceEditorWindowData, THash_TObject>.Create();
{$ENDIF}
Forms := Classes.TList.Create;
finalization
Forms.Free;
{$IFNDEF USE_GENERICS_COLLECTIONS}
FreeSourceEditorWindowsValues;
{$ENDIF}
SourceEditorWindows.Free;
FreeAndNil(dsgForms);
end.

View File

@ -19,9 +19,6 @@ interface
uses
Classes, SysUtils, Controls, ExtCtrls, sparta_ResizerFrame, sparta_DesignedForm, Forms, Math, StdCtrls,
LCLType, LazIDEIntf, Buttons, SpartaAPI, Dialogs,
{$IFDEF USE_GENERICS_COLLECTIONS}
Generics.Defaults,
{$ENDIF}
FormEditingIntf;
type