/designer/customnonformdesigner.pas

http://github.com/graemeg/lazarus · Pascal · 160 lines · 106 code · 26 blank · 28 comment · 7 complexity · 53cbc8de200e509cbc91c9702cad8c5b MD5 · raw file

  1. {
  2. ***************************************************************************
  3. * *
  4. * This source is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This code is distributed in the hope that it will be useful, but *
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  12. * General Public License for more details. *
  13. * *
  14. * A copy of the GNU General Public License is available on the World *
  15. * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
  16. * obtain it by writing to the Free Software Foundation, *
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. * *
  19. ***************************************************************************
  20. Author: Mattias Gaertner
  21. Abstract:
  22. TCustomNonFormDesignerForm is a base designer form for non form components (TDataModule, TFrame).
  23. }
  24. unit CustomNonFormDesigner;
  25. {$mode objfpc}{$H+}
  26. interface
  27. uses
  28. Classes, SysUtils, LCLProc, Graphics, GraphType, Forms, Controls,
  29. IDEProcs, FormEditingIntf;
  30. type
  31. { TCustomNonFormDesignerForm }
  32. TCustomNonFormDesignerForm = class(TInterfacedObject, INonFormDesigner)
  33. private
  34. FNonFormProxyDesignerForm: TNonFormProxyDesignerForm;
  35. FOnLoadBounds: TNotifyEvent;
  36. FOnSaveBounds: TNotifyEvent;
  37. protected
  38. function GetLookupRoot: TComponent; virtual;
  39. procedure SetLookupRoot(const AValue: TComponent); virtual;
  40. procedure Notification(AComponent: TComponent; Operation: TOperation); virtual;
  41. public
  42. procedure Create; virtual; overload;
  43. constructor Create(ANonFormProxyDesignerForm: TNonFormProxyDesignerForm); virtual; overload;
  44. destructor Destroy; override;
  45. procedure DoLoadBounds; virtual;
  46. procedure DoSaveBounds; virtual;
  47. procedure SetBounds({%H-}ALeft, {%H-}ATop, {%H-}AWidth, {%H-}AHeight: integer); virtual;
  48. procedure Paint; virtual;
  49. public
  50. property LookupRoot: TComponent read GetLookupRoot write SetLookupRoot;
  51. property NonFormProxyDesignerForm: TNonFormProxyDesignerForm read FNonFormProxyDesignerForm;
  52. property OnLoadBounds: TNotifyEvent read FOnLoadBounds write FOnLoadBounds;
  53. property OnSaveBounds: TNotifyEvent read FOnSaveBounds write FOnSaveBounds;
  54. end;
  55. function CompareNonFormDesignerForms(Data1, Data2: Pointer): integer;
  56. function CompareLookupRootAndNonFormDesignerForm(Key, Data: Pointer): integer;
  57. implementation
  58. function CompareNonFormDesignerForms(Data1, Data2: Pointer): integer;
  59. var
  60. Form1: INonFormDesigner;
  61. Form2: INonFormDesigner;
  62. begin
  63. Form1 := TNonFormProxyDesignerForm(Data1) as INonFormDesigner;
  64. Form2 := TNonFormProxyDesignerForm(Data2) as INonFormDesigner;
  65. Result := PtrInt(Form1.LookupRoot) - PtrInt(Form2.LookupRoot);
  66. end;
  67. function CompareLookupRootAndNonFormDesignerForm(Key, Data: Pointer): integer;
  68. var
  69. LookupRoot: TComponent;
  70. Form: INonFormDesigner;
  71. begin
  72. LookupRoot := TComponent(Key);
  73. Form := TNonFormProxyDesignerForm(Data) as INonFormDesigner;
  74. Result := PtrInt(LookupRoot) - PtrInt(Form.LookupRoot);
  75. end;
  76. { TCustomNonFormDesignerForm }
  77. function TCustomNonFormDesignerForm.GetLookupRoot: TComponent;
  78. begin
  79. Result := FNonFormProxyDesignerForm.LookupRoot;
  80. end;
  81. procedure TCustomNonFormDesignerForm.SetLookupRoot(const AValue: TComponent);
  82. begin
  83. if FNonFormProxyDesignerForm.LookupRoot = AValue then
  84. Exit;
  85. if FNonFormProxyDesignerForm.LookupRoot<>nil then
  86. FNonFormProxyDesignerForm.LookupRoot.RemoveFreeNotification(FNonFormProxyDesignerForm);
  87. DoSaveBounds;
  88. FNonFormProxyDesignerForm.LookupRoot := AValue;
  89. if FNonFormProxyDesignerForm.LookupRoot <> nil then begin
  90. FNonFormProxyDesignerForm.LookupRoot.FreeNotification(FNonFormProxyDesignerForm);
  91. FNonFormProxyDesignerForm.Caption := FNonFormProxyDesignerForm.LookupRoot.Name;
  92. end;
  93. DoLoadBounds;
  94. end;
  95. procedure TCustomNonFormDesignerForm.Notification(AComponent: TComponent;
  96. Operation: TOperation);
  97. begin
  98. if Operation=opRemove then begin
  99. if AComponent=FNonFormProxyDesignerForm.LookupRoot then FNonFormProxyDesignerForm.LookupRoot:=nil;
  100. end;
  101. end;
  102. constructor TCustomNonFormDesignerForm.Create(
  103. ANonFormProxyDesignerForm: TNonFormProxyDesignerForm);
  104. begin
  105. FNonFormProxyDesignerForm := ANonFormProxyDesignerForm;
  106. end;
  107. destructor TCustomNonFormDesignerForm.Destroy;
  108. begin
  109. inherited Destroy;
  110. end;
  111. procedure TCustomNonFormDesignerForm.Create;
  112. begin
  113. inherited Create;
  114. end;
  115. procedure TCustomNonFormDesignerForm.DoLoadBounds;
  116. begin
  117. if Assigned(OnLoadBounds) then
  118. OnLoadBounds(Self);
  119. end;
  120. procedure TCustomNonFormDesignerForm.DoSaveBounds;
  121. begin
  122. if Assigned(OnSaveBounds) then
  123. OnSaveBounds(Self);
  124. end;
  125. procedure TCustomNonFormDesignerForm.SetBounds(ALeft, ATop, AWidth,
  126. AHeight: integer);
  127. begin
  128. end;
  129. procedure TCustomNonFormDesignerForm.Paint;
  130. begin
  131. end;
  132. end.