PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 21  Author: Mattias Gaertner
 22
 23  Abstract:
 24    TCustomNonFormDesignerForm is a base designer form for non form components (TDataModule, TFrame).
 25}
 26unit CustomNonFormDesigner;
 27
 28{$mode objfpc}{$H+}
 29
 30interface
 31
 32uses
 33  Classes, SysUtils, LCLProc, Graphics, GraphType, Forms, Controls,
 34  IDEProcs, FormEditingIntf;
 35  
 36type
 37
 38  { TCustomNonFormDesignerForm }
 39
 40  TCustomNonFormDesignerForm = class(TInterfacedObject, INonFormDesigner)
 41  private
 42    FNonFormProxyDesignerForm: TNonFormProxyDesignerForm;
 43    FOnLoadBounds: TNotifyEvent;
 44    FOnSaveBounds: TNotifyEvent;
 45  protected
 46    function GetLookupRoot: TComponent; virtual;
 47    procedure SetLookupRoot(const AValue: TComponent); virtual;
 48    procedure Notification(AComponent: TComponent; Operation: TOperation); virtual;
 49  public
 50    procedure Create; virtual; overload;
 51    constructor Create(ANonFormProxyDesignerForm: TNonFormProxyDesignerForm); virtual; overload;
 52    destructor Destroy; override;
 53    procedure DoLoadBounds; virtual;
 54    procedure DoSaveBounds; virtual;
 55    procedure SetBounds({%H-}ALeft, {%H-}ATop, {%H-}AWidth, {%H-}AHeight: integer); virtual;
 56    procedure Paint; virtual;
 57  public
 58    property LookupRoot: TComponent read GetLookupRoot write SetLookupRoot;
 59    property NonFormProxyDesignerForm: TNonFormProxyDesignerForm read FNonFormProxyDesignerForm;
 60    property OnLoadBounds: TNotifyEvent read FOnLoadBounds write FOnLoadBounds;
 61    property OnSaveBounds: TNotifyEvent read FOnSaveBounds write FOnSaveBounds;
 62  end;
 63  
 64  
 65function CompareNonFormDesignerForms(Data1, Data2: Pointer): integer;
 66function CompareLookupRootAndNonFormDesignerForm(Key, Data: Pointer): integer;
 67
 68implementation
 69
 70
 71function CompareNonFormDesignerForms(Data1, Data2: Pointer): integer;
 72var
 73  Form1: INonFormDesigner;
 74  Form2: INonFormDesigner;
 75begin
 76  Form1 := TNonFormProxyDesignerForm(Data1) as INonFormDesigner;
 77  Form2 := TNonFormProxyDesignerForm(Data2) as INonFormDesigner;
 78  Result := PtrInt(Form1.LookupRoot) - PtrInt(Form2.LookupRoot);
 79end;
 80
 81function CompareLookupRootAndNonFormDesignerForm(Key, Data: Pointer): integer;
 82var
 83  LookupRoot: TComponent;
 84  Form: INonFormDesigner;
 85begin
 86  LookupRoot := TComponent(Key);
 87  Form := TNonFormProxyDesignerForm(Data) as INonFormDesigner;
 88  Result := PtrInt(LookupRoot) - PtrInt(Form.LookupRoot);
 89end;
 90
 91{ TCustomNonFormDesignerForm }
 92
 93function TCustomNonFormDesignerForm.GetLookupRoot: TComponent;
 94begin
 95  Result := FNonFormProxyDesignerForm.LookupRoot;
 96end;
 97
 98procedure TCustomNonFormDesignerForm.SetLookupRoot(const AValue: TComponent);
 99begin
100  if FNonFormProxyDesignerForm.LookupRoot = AValue then
101    Exit;
102  if FNonFormProxyDesignerForm.LookupRoot<>nil then
103    FNonFormProxyDesignerForm.LookupRoot.RemoveFreeNotification(FNonFormProxyDesignerForm);
104  DoSaveBounds;
105  FNonFormProxyDesignerForm.LookupRoot := AValue;
106  if FNonFormProxyDesignerForm.LookupRoot <> nil then begin
107    FNonFormProxyDesignerForm.LookupRoot.FreeNotification(FNonFormProxyDesignerForm);
108    FNonFormProxyDesignerForm.Caption := FNonFormProxyDesignerForm.LookupRoot.Name;
109  end;
110  DoLoadBounds;
111end;
112
113procedure TCustomNonFormDesignerForm.Notification(AComponent: TComponent;
114  Operation: TOperation);
115begin
116  if Operation=opRemove then begin
117    if AComponent=FNonFormProxyDesignerForm.LookupRoot then FNonFormProxyDesignerForm.LookupRoot:=nil;
118  end;
119end;
120
121constructor TCustomNonFormDesignerForm.Create(
122  ANonFormProxyDesignerForm: TNonFormProxyDesignerForm);
123begin
124  FNonFormProxyDesignerForm := ANonFormProxyDesignerForm;
125end;
126
127destructor TCustomNonFormDesignerForm.Destroy;
128begin
129  inherited Destroy;
130end;
131
132procedure TCustomNonFormDesignerForm.Create;
133begin
134  inherited Create;
135end;
136
137procedure TCustomNonFormDesignerForm.DoLoadBounds;
138begin
139  if Assigned(OnLoadBounds) then
140    OnLoadBounds(Self);
141end;
142
143procedure TCustomNonFormDesignerForm.DoSaveBounds;
144begin
145  if Assigned(OnSaveBounds) then
146    OnSaveBounds(Self);
147end;
148
149procedure TCustomNonFormDesignerForm.SetBounds(ALeft, ATop, AWidth,
150  AHeight: integer);
151begin
152end;
153
154procedure TCustomNonFormDesignerForm.Paint;
155begin
156
157end;
158
159end.
160