mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-02 01:59:29 +01:00
implemented auto add on double click on component palette
git-svn-id: trunk@6358 -
This commit is contained in:
parent
9c2fcfd062
commit
93cb3ed38c
@ -2056,8 +2056,7 @@ var
|
||||
begin
|
||||
for i:=0 to FLookupRoot.ComponentCount-1 do begin
|
||||
AComponent:=FLookupRoot.Components[i];
|
||||
if (not (AComponent is TControl))
|
||||
and (not ComponentIsInvisible(AComponent)) then begin
|
||||
if ComponentIsNonVisual(AComponent) then begin
|
||||
Diff:=aDDC.FormOrigin;
|
||||
// non-visual component
|
||||
ItemLeftTop:=NonVisualComponentLeftTop(AComponent);
|
||||
|
||||
@ -89,6 +89,7 @@ var
|
||||
function GetParentLevel(AControl: TControl): integer;
|
||||
function ControlIsInDesignerVisible(AControl: TControl): boolean;
|
||||
function ComponentIsInvisible(AComponent: TComponent): boolean;
|
||||
function ComponentIsNonVisual(AComponent: TComponent): boolean;
|
||||
function ComponentBoundsDesignable(AComponent: TComponent): boolean;
|
||||
|
||||
function GetParentFormRelativeTopLeft(Component: TComponent): TPoint;
|
||||
@ -294,6 +295,13 @@ begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
function ComponentIsNonVisual(AComponent: TComponent): boolean;
|
||||
begin
|
||||
Result:=(AComponent<>nil)
|
||||
and (not (AComponent is TControl))
|
||||
and (not ComponentIsInvisible(AComponent));
|
||||
end;
|
||||
|
||||
function ComponentBoundsDesignable(AComponent: TComponent): boolean;
|
||||
begin
|
||||
Result:=(not ComponentIsInvisible(AComponent));
|
||||
|
||||
@ -24,10 +24,10 @@
|
||||
<Loaded Value="True"/>
|
||||
<TopLine Value="1"/>
|
||||
<UnitName Value="OIExample"/>
|
||||
<UsageCount Value="21"/>
|
||||
<UsageCount Value="29"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<CursorPos X="39" Y="25"/>
|
||||
<CursorPos X="6" Y="21"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<Filename Value="mainunit.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
@ -36,7 +36,7 @@
|
||||
<ResourceFilename Value="mainunit.lrs"/>
|
||||
<TopLine Value="1"/>
|
||||
<UnitName Value="MainUnit"/>
|
||||
<UsageCount Value="21"/>
|
||||
<UsageCount Value="29"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
<PublishOptions>
|
||||
@ -60,7 +60,7 @@
|
||||
<CompilerOptions>
|
||||
<Version Value="3"/>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value="$(LazarusDir)/;$(LazarusDir)/components/units/"/>
|
||||
<OtherUnitFiles Value="$(LazarusDir)/components/units/"/>
|
||||
<LCLWidgetType Value="gtk"/>
|
||||
<SrcPath Value="$(LazarusDir)/designer/"/>
|
||||
</SearchPaths>
|
||||
|
||||
@ -38,18 +38,16 @@ unit ComponentPalette;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Controls, Dialogs, Graphics, ExtCtrls, Buttons, Menus,
|
||||
LResources, OldAvLTree,
|
||||
Classes, SysUtils, LCLProc, Controls, Dialogs, Graphics, ExtCtrls, Buttons,
|
||||
Menus, LResources, OldAvLTree, FormEditingIntf,
|
||||
{$IFDEF CustomIDEComps}
|
||||
CustomIDEComps,
|
||||
{$ENDIF}
|
||||
LazarusIDEStrConsts, ComponentReg, DesignerProcs, IDEProcs, PackageDefs;
|
||||
|
||||
const
|
||||
ComponentPaletteBtnWidth = 25;
|
||||
ComponentPaletteBtnHeight = 25;
|
||||
|
||||
type
|
||||
{ TComponentPalette }
|
||||
|
||||
TComponentPalette = class(TBaseComponentPalette)
|
||||
PopupMenu: TPopupMenu;
|
||||
OpenPackageMenuItem: TMenuItem;
|
||||
@ -71,6 +69,7 @@ type
|
||||
procedure SetNoteBook(const AValue: TNotebook);
|
||||
procedure SelectionToolClick(Sender: TObject);
|
||||
procedure ComponentBtnClick(Sender: TObject);
|
||||
procedure ComponentBtnDblClick(Sender: TObject);
|
||||
procedure SetSelected(const AValue: TRegisteredComponent);
|
||||
procedure CreatePopupMenu;
|
||||
protected
|
||||
@ -87,7 +86,7 @@ type
|
||||
function GetUnregisteredIcon: TBitmap;
|
||||
function GetSelectButtonIcon: TBitmap;
|
||||
procedure ClearButtons; override;
|
||||
procedure SelectButton(Button: TComponent);
|
||||
function SelectButton(Button: TComponent): boolean;
|
||||
procedure UpdateNoteBookButtons;
|
||||
procedure OnGetNonVisualCompIconCanvas(Sender: TObject;
|
||||
AComponent: TComponent; var IconCanvas: TCanvas;
|
||||
@ -200,6 +199,26 @@ begin
|
||||
SelectButton(TComponent(Sender));
|
||||
end;
|
||||
|
||||
procedure TComponentPalette.ComponentBtnDblClick(Sender: TObject);
|
||||
var
|
||||
TypeClass: TComponentClass;
|
||||
ParentCI: TIComponentInterface;
|
||||
X, Y: integer;
|
||||
begin
|
||||
//debugln('TComponentPalette.ComponentBtnDblClick ',TComponent(Sender).Name);
|
||||
if SelectButton(TComponent(Sender)) and (FSelected<>nil) then begin
|
||||
if FormEditingHook<>nil then begin
|
||||
TypeClass:=FSelected.ComponentClass;
|
||||
ParentCI:=FormEditingHook.GetDefaultComponentParent(TypeClass);
|
||||
if ParentCI=nil then exit;
|
||||
if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentCI,X,Y)
|
||||
then exit;
|
||||
//debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
|
||||
FormEditingHook.CreateComponent(ParentCI,TypeClass,X,Y,0,0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TComponentPalette.SetSelected(const AValue: TRegisteredComponent);
|
||||
var
|
||||
SelectButtonOnPage: TSpeedButton;
|
||||
@ -362,9 +381,13 @@ begin
|
||||
inherited ClearButtons;
|
||||
end;
|
||||
|
||||
procedure TComponentPalette.SelectButton(Button: TComponent);
|
||||
function TComponentPalette.SelectButton(Button: TComponent): boolean;
|
||||
var
|
||||
NewComponent: TRegisteredComponent;
|
||||
begin
|
||||
Selected:=FindButton(Button);
|
||||
NewComponent:=FindButton(Button);
|
||||
Selected:=NewComponent;
|
||||
Result:=(Selected=NewComponent);
|
||||
end;
|
||||
|
||||
procedure TComponentPalette.UpdateNoteBookButtons;
|
||||
@ -458,6 +481,8 @@ begin
|
||||
GroupIndex := 1;
|
||||
Flat := true;
|
||||
OnClick := @ComponentBtnClick;
|
||||
OnDblClick := @ComponentBtnDblClick;
|
||||
ControlStyle:=ControlStyle+[csDoubleClicks];
|
||||
Hint := CurComponent.ComponentClass.ClassName;
|
||||
CurBtn.PopupMenu:=Self.PopupMenu;
|
||||
Visible:=true;
|
||||
|
||||
@ -45,8 +45,8 @@ uses
|
||||
// components
|
||||
OldAvLTree, PropEdits, ObjectInspector, IDECommands,
|
||||
// IDE
|
||||
JITForms, NonControlForms, FormEditingIntf, ComponentReg, IDEProcs,
|
||||
ComponentEditors, KeyMapping, EditorOptions, DesignerProcs;
|
||||
LazarusIDEStrConsts, JITForms, NonControlForms, FormEditingIntf, ComponentReg,
|
||||
IDEProcs, ComponentEditors, KeyMapping, EditorOptions, DesignerProcs;
|
||||
|
||||
Const OrdinalTypes = [tkInteger,tkChar,tkENumeration,tkbool];
|
||||
|
||||
@ -61,7 +61,6 @@ each control that's dropped onto the form
|
||||
|
||||
TComponentInterface = class(TIComponentInterface)
|
||||
private
|
||||
FComponent : TComponent;
|
||||
FComponentEditor: TBaseComponentEditor;
|
||||
FDesigner: TComponentEditorDesigner;
|
||||
FFormEditor : TCustomFormEditor; //used to call it's functions
|
||||
@ -106,8 +105,6 @@ each control that's dropped onto the form
|
||||
|
||||
function GetComponentEditor: TBaseComponentEditor;
|
||||
property Designer: TComponentEditorDesigner read GetDesigner write FDesigner;
|
||||
|
||||
property Component: TComponent read FComponent;
|
||||
end;
|
||||
|
||||
|
||||
@ -194,6 +191,11 @@ each control that's dropped onto the form
|
||||
OwnerComponent: TComponent): string;
|
||||
Function CreateComponentInterface(AComponent: TComponent): TIComponentInterface;
|
||||
procedure CreateChildComponentInterfaces(AComponent: TComponent);
|
||||
Function GetDefaultComponentParent(TypeClass: TComponentClass
|
||||
): TIComponentInterface; override;
|
||||
Function GetDefaultComponentPosition(TypeClass: TComponentClass;
|
||||
ParentCI: TIComponentInterface;
|
||||
var X,Y: integer): boolean; override;
|
||||
Function CreateComponent(ParentCI : TIComponentInterface;
|
||||
TypeClass: TComponentClass;
|
||||
X,Y,W,H : Integer): TIComponentInterface; override;
|
||||
@ -1203,6 +1205,7 @@ Var
|
||||
JITList: TJITComponentList;
|
||||
AControl: TControl;
|
||||
NewComponentName: String;
|
||||
DesignForm: TCustomForm;
|
||||
Begin
|
||||
Result:=nil;
|
||||
Temp:=nil;
|
||||
@ -1337,12 +1340,16 @@ Begin
|
||||
Lo:=word(Min(32000,CompLeft));
|
||||
Hi:=word(Min(32000,CompTop));
|
||||
end;
|
||||
if (ParentComponent<>nil) then begin
|
||||
DesignForm:=GetDesignerForm(ParentComponent);
|
||||
if DesignForm<>nil then DesignForm.Invalidate;
|
||||
end;
|
||||
end;
|
||||
except
|
||||
on e: Exception do begin
|
||||
MessageDlg('Error moving component',
|
||||
'Error moving component '
|
||||
+Temp.Component.Name+':'+Temp.Component.ClassName,
|
||||
MessageDlg(lisErrorMovingComponent,
|
||||
Format(lisErrorMovingComponent2, [Temp.Component.Name,
|
||||
Temp.Component.ClassName]),
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
@ -1751,6 +1758,128 @@ begin
|
||||
CreateComponentInterface(AComponent.Components[i]);
|
||||
end;
|
||||
|
||||
function TCustomFormEditor.GetDefaultComponentParent(TypeClass: TComponentClass
|
||||
): TIComponentInterface;
|
||||
var
|
||||
NewParent: TComponent;
|
||||
Root: TPersistent;
|
||||
begin
|
||||
Result:=nil;
|
||||
// find selected component
|
||||
if (FSelection = nil) or (FSelection.Count <= 0) then Exit;
|
||||
NewParent:=TComponent(FSelection[0]);
|
||||
if not (NewParent is TComponent) then exit;
|
||||
if TypeClass<>nil then begin
|
||||
if TypeClass.InheritsFrom(TControl) then begin
|
||||
// New TypeClass is a TControl => use only a TWinControl as parent
|
||||
while (NewParent<>nil) do begin
|
||||
if (NewParent is TWinControl)
|
||||
and (csAcceptsControls in TWinControl(NewParent).ControlStyle) then
|
||||
break;
|
||||
end;
|
||||
end else begin
|
||||
// New TypeClass is not a TControl => Root component as parent
|
||||
Root:=GetLookupRootForComponent(NewParent);
|
||||
if Root is TComponent then
|
||||
NewParent:=TComponent(Root);
|
||||
end;
|
||||
end;
|
||||
Result:=FindComponent(NewParent);
|
||||
end;
|
||||
|
||||
function TCustomFormEditor.GetDefaultComponentPosition(
|
||||
TypeClass: TComponentClass; ParentCI: TIComponentInterface; var X, Y: integer
|
||||
): boolean;
|
||||
var
|
||||
ParentComponent: TComponent;
|
||||
i: Integer;
|
||||
CurComponent: TComponent;
|
||||
P: TPoint;
|
||||
AForm: TNonFormDesignerForm;
|
||||
MinX: Integer;
|
||||
MinY: Integer;
|
||||
MaxX: Integer;
|
||||
MaxY: Integer;
|
||||
begin
|
||||
Result:=true;
|
||||
X:=10;
|
||||
Y:=10;
|
||||
if ParentCI=nil then
|
||||
ParentCI:=GetDefaultComponentParent(TypeClass);
|
||||
if (ParentCI=nil) or (ParentCI.Component=nil) then exit;
|
||||
if TypeClass<>nil then begin
|
||||
if not (TypeClass.InheritsFrom(TControl)) then begin
|
||||
// a non visual component
|
||||
// put it somewhere right or below the other non visual components
|
||||
ParentComponent:=ParentCI.Component;
|
||||
MinX:=-1;
|
||||
MinY:=-1;
|
||||
if ParentComponent is TWinControl then begin
|
||||
MaxX:=TWinControl(ParentComponent).ClientWidth-ComponentPaletteBtnWidth;
|
||||
MaxY:=TWinControl(ParentComponent).ClientHeight-ComponentPaletteBtnHeight;
|
||||
end else begin
|
||||
AForm:=FindNonControlForm(ParentComponent);
|
||||
if AForm<>nil then begin
|
||||
MaxX:=AForm.ClientWidth-ComponentPaletteBtnWidth;
|
||||
MaxY:=AForm.ClientHeight-ComponentPaletteBtnHeight;
|
||||
end else begin
|
||||
MaxX:=300;
|
||||
MaxY:=0;
|
||||
end;
|
||||
end;
|
||||
// find top left most non visual component
|
||||
for i:=0 to ParentComponent.ComponentCount-1 do begin
|
||||
CurComponent:=ParentComponent.Components[i];
|
||||
if ComponentIsNonVisual(CurComponent) then begin
|
||||
P:=GetParentFormRelativeTopLeft(CurComponent);
|
||||
if (P.X>=0) and (P.Y>=0) then begin
|
||||
if (MinX<0) or (P.Y<MinY) or ((P.Y=MinY) and (P.X<MinX)) then begin
|
||||
MinX:=P.X;
|
||||
MinY:=P.Y;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if MinX<0 then begin
|
||||
MinX:=10;
|
||||
MinY:=10;
|
||||
end;
|
||||
// find a position without intersection
|
||||
X:=MinX;
|
||||
Y:=MinY;
|
||||
//debugln('TCustomFormEditor.GetDefaultComponentPosition Min=',dbgs(MinX),',',dbgs(MinY));
|
||||
i:=0;
|
||||
while i<ParentComponent.ComponentCount do begin
|
||||
CurComponent:=ParentComponent.Components[i];
|
||||
inc(i);
|
||||
if ComponentIsNonVisual(CurComponent) then begin
|
||||
P:=GetParentFormRelativeTopLeft(CurComponent);
|
||||
//debugln('TCustomFormEditor.GetDefaultComponentPosition ',dbgsName(CurComponent),' P=',dbgs(P));
|
||||
if (P.X>=0) and (P.Y>=0) then begin
|
||||
if (X+ComponentPaletteBtnWidth>=P.X)
|
||||
and (X<=P.X+ComponentPaletteBtnWidth)
|
||||
and (Y+ComponentPaletteBtnHeight>=P.Y)
|
||||
and (Y<=P.Y+ComponentPaletteBtnHeight) then begin
|
||||
// intersection found
|
||||
// move position
|
||||
inc(X,ComponentPaletteBtnWidth+2);
|
||||
if X>MaxX then begin
|
||||
inc(Y,ComponentPaletteBtnHeight+2);
|
||||
X:=MinX;
|
||||
end;
|
||||
// restart intersection test
|
||||
i:=0;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// keep it visible
|
||||
if X>MaxX then X:=MaxX;
|
||||
if Y>MaxY then Y:=MaxY;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomFormEditor.OnObjectInspectorModified(Sender: TObject);
|
||||
var
|
||||
CustomForm: TCustomForm;
|
||||
|
||||
@ -2606,6 +2606,8 @@ resourcestring
|
||||
lisA2PFilename2 = 'Filename';
|
||||
lisFRIFindOrRenameIdentifier = 'Find or Rename Identifier';
|
||||
lisSelectAHelpItem = 'Select a help item:';
|
||||
lisErrorMovingComponent = 'Error moving component';
|
||||
lisErrorMovingComponent2 = 'Error moving component %s:%s';
|
||||
|
||||
implementation
|
||||
end.
|
||||
|
||||
@ -24,10 +24,16 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, TypInfo, Forms, Controls, ComponentEditors;
|
||||
|
||||
const
|
||||
ComponentPaletteBtnWidth = 25;
|
||||
ComponentPaletteBtnHeight = 25;
|
||||
|
||||
type
|
||||
{ TIComponentInterface }
|
||||
|
||||
TIComponentInterface = class
|
||||
protected
|
||||
FComponent : TComponent;
|
||||
public
|
||||
Function GetComponentType : ShortString; virtual; abstract;
|
||||
Function GetComponentHandle : LongInt; virtual; abstract;
|
||||
@ -41,7 +47,6 @@ type
|
||||
// Function GetPropTypebyName(Name : ShortString) : TPropertyType; virtual; abstract;
|
||||
Function GetPropTypeName(Index : Integer) : ShortString; virtual; abstract;
|
||||
|
||||
|
||||
Function GetPropValue(Index : Integer; var Value) : Boolean; virtual; abstract;
|
||||
Function GetPropValuebyName(Name: Shortstring; var Value) : Boolean; virtual; abstract;
|
||||
Function SetProp(Index : Integer; const Value) : Boolean; virtual; abstract;
|
||||
@ -53,13 +58,15 @@ type
|
||||
Function GetComponentCount: Integer; virtual; abstract;
|
||||
Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function Select : Boolean; virtual; abstract;
|
||||
Function Focus : Boolean; virtual; abstract;
|
||||
Function Delete : Boolean; virtual; abstract;
|
||||
Function Select: Boolean; virtual; abstract;
|
||||
Function Focus: Boolean; virtual; abstract;
|
||||
Function Delete: Boolean; virtual; abstract;
|
||||
|
||||
property Component: TComponent read FComponent;
|
||||
end;
|
||||
|
||||
|
||||
{ TIFormInterface - currently not used }
|
||||
{ TIFormInterface }
|
||||
|
||||
TIFormInterface = class
|
||||
public
|
||||
@ -76,6 +83,7 @@ type
|
||||
X,Y,W,H : Integer): TIComponentInterface; virtual; abstract;
|
||||
end;
|
||||
|
||||
|
||||
{ TAbstractFormEditor }
|
||||
|
||||
TAbstractFormEditor = class
|
||||
@ -87,9 +95,14 @@ type
|
||||
): TIComponentInterface; virtual; abstract;
|
||||
Function FindComponent(AComponent: TComponent): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function CreateComponent(CI : TIComponentInterface;
|
||||
TypeClass : TComponentClass;
|
||||
X,Y,W,H : Integer): TIComponentInterface; virtual; abstract;
|
||||
Function GetDefaultComponentParent(TypeClass: TComponentClass
|
||||
): TIComponentInterface; virtual; abstract;
|
||||
Function GetDefaultComponentPosition(TypeClass: TComponentClass;
|
||||
ParentCI: TIComponentInterface;
|
||||
var X,Y: integer): boolean; virtual; abstract;
|
||||
Function CreateComponent(ParentCI: TIComponentInterface;
|
||||
TypeClass: TComponentClass;
|
||||
X,Y,W,H: Integer): TIComponentInterface; virtual; abstract;
|
||||
Function CreateComponentFromStream(BinStream: TStream;
|
||||
AncestorType: TComponentClass;
|
||||
const NewUnitName: ShortString;
|
||||
|
||||
@ -1080,6 +1080,7 @@ var
|
||||
LastMouse.Down := True;
|
||||
LastMouse.Component:=AWinControl;
|
||||
|
||||
//DebugLn('DeliverMouseDownMessage ',AWinControl.Name,':',AWinControl.ClassName,' Mapped=',dbgs(MappedXY.X),',',dbgs(MappedXY.Y),' Event=',dbgs(EventXY.X),',',dbgs(EventXY.Y),' ',dbgs(LastMouse.ClickCount));
|
||||
case LastMouse.ClickCount of
|
||||
1: MessI.Msg := MsgNormal;
|
||||
2: MessI.Msg := MsgDouble;
|
||||
@ -2882,6 +2883,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.252 2004/12/10 19:22:28 mattias
|
||||
implemented auto add on double click on component palette
|
||||
|
||||
Revision 1.251 2004/11/10 18:23:56 mattias
|
||||
impementing changing a TLabel.Font properties Size, Height, Name, Style - set only at Handle creation time
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user