MG: new designer and controlselection code

git-svn-id: trunk@222 -
This commit is contained in:
lazarus 2001-03-12 18:57:32 +00:00
parent 5718818c2a
commit 5c2ae1e0e1
8 changed files with 1107 additions and 880 deletions

View File

@ -17,10 +17,10 @@
* *
***************************************************************************/
}
{$H+}
unit AbstractFormEditor;
{$mode objfpc}
{$mode objfpc}{$H-}
interface
uses
@ -70,7 +70,7 @@ or use TPropertyType
TIFormInterface = class
public
Function Filename : String; virtual; abstract;
Function Filename : AnsiString; virtual; abstract;
Function FormModified : Boolean; virtual; abstract;
Function MArkModified : Boolean; virtual; abstract;
Function GetFormComponent : TIComponentInterface; virtual; abstract;
@ -92,7 +92,7 @@ or use TPropertyType
TAbstractFormEditor = class
public
Function Filename : String; virtual; abstract;
Function Filename : AnsiString; virtual; abstract;
Function FormModified : Boolean; virtual; abstract;
Function FindComponentByName(const Name : String) : TIComponentInterface; virtual; abstract;
Function FindComponent(AComponent: TComponent): TIComponentInterface; virtual; abstract;

File diff suppressed because it is too large Load Diff

View File

@ -20,12 +20,13 @@
}
unit designer;
{$mode objfpc}
{$mode objfpc}{$H+}
interface
uses
classes, Forms, controls, lmessages, graphics, ControlSelection, CustomFormEditor,FormEditor, UnitEditor,Main;
Classes, Forms, Controls, LMessages, Graphics, ControlSelection,
CustomFormEditor, FormEditor, UnitEditor, CompReg;
type
TGridPoint = record
@ -33,21 +34,37 @@ type
y: integer;
end;
TOnGetSelectedComponentClass = procedure(Sender: TObject;
var RegisteredComponent: TRegisteredComponent) of object;
TOnSetDesigning = procedure(Sender: TObject; Component: TComponent;
Value: boolean) of object;
TOnAddComponent = procedure(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent) of object;
TDesigner = class(TIDesigner)
private
FCustomForm: TCustomForm;
FFormEditor : TFormEditor;
FSourceEditor : TSourceEditor;
FMainIDE : TMainIDE;
FActiveRubberband:boolean;
FOnGetSelectedComponentClass: TOnGetSelectedComponentClass;
FOnUnselectComponentClass: TNotifyEvent;
FOnSetDesigning: TOnSetDesigning;
FOnComponentListChanged: TNotifyEvent;
FOnPropertiesChanged: TNotifyEvent;
FOnAddComponent: TOnAddComponent;
function GetIsControl: Boolean;
procedure SetIsControl(Value: Boolean);
protected
MouseDownControl : TObject;
MouseDownPos, MouseUpPos, LastMouseMovePos : TPoint;
Procedure MouseDownOnControl(Sender : TControl; Message : TLMessage);
procedure MouseMoveOnControl(Sender : TControl; var Message : TLMessage);
Procedure MouseUpOnControl(Sender : TControl; Message:TLMessage);
function Paint(Sender: TControl; Message: TLMPaint):boolean;
Procedure MouseDownOnControl(Sender : TControl; Message : TLMMouse);
Procedure MouseMoveOnControl(Sender : TControl; var Message : TLMMouse);
Procedure MouseUpOnControl(Sender : TControl; Message:TLMMouse);
Procedure KeyDown(Sender : TControl; Message:TLMKEY);
Procedure KeyUP(Sender : TControl; Message:TLMKEY);
@ -58,9 +75,8 @@ type
public
ControlSelection : TControlSelection;
constructor Create(customform : TCustomform);
constructor Create(Customform : TCustomform);
destructor Destroy; override;
Procedure AddControlCode(Control : TComponent);
procedure CreateNew(FileName : string);
procedure LoadFile(FileName: string);
@ -69,28 +85,39 @@ type
procedure Modified; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure PaintGrid; override;
procedure ValidateRename(AComponent: TComponent; const CurName, NewName: string); override;
procedure ValidateRename(AComponent: TComponent;
const CurName, NewName: shortstring); override;
Procedure SelectOnlyThisComponent(AComponent:TComponent);
property IsControl: Boolean read GetIsControl write SetIsControl;
property Form: TCustomForm read FCustomForm write FCustomForm;
property FormEditor : TFormEditor read FFormEditor write FFormEditor;
property SourceEditor : TSourceEditor read FSourceEditor write FSourceEditor;
property MainIDE : TMainIDE read FMainIDE write FMainIDE;
end;
property OnGetSelectedComponentClass: TOnGetSelectedComponentClass
read FOnGetSelectedComponentClass write FOnGetSelectedComponentClass;
property OnUnselectComponentClass: TNotifyEvent
read FOnUnselectComponentClass write FOnUnselectComponentClass;
property OnSetDesigning: TOnSetDesigning read FOnSetDesigning write FOnSetDesigning;
property OnComponentListChanged: TNotifyEvent
read FOnComponentListChanged write FOnComponentListChanged;
property OnPropertiesChanged: TNotifyEvent
read FOnPropertiesChanged write FOnPropertiesChanged;
property OnAddComponent: TOnAddComponent read FOnAddComponent write FOnAddComponent;
end;
implementation
implementation
uses
Sysutils, Typinfo,Math;
Sysutils, Typinfo, Math, LCLLinux;
const
mk_lbutton = 1;
mk_rbutton = 2;
mk_shift = 4;
mk_control = 8;
mk_lbutton = 1;
mk_rbutton = 2;
mk_shift = 4;
mk_control = 8;
mk_mbutton = $10;
var
@ -100,12 +127,8 @@ constructor TDesigner.Create(CustomForm : TCustomForm);
begin
inherited Create;
FCustomForm := CustomForm;
ControlSelection := TControlSelection.Create(CustomForm);
//the source is created when the form is created.
//the TDesigner is created in Main.pp and then TDesigner.SourceEditor := SourceNotebook.CreateFormFromUnit(CustomForm);
ControlSelection := TControlSelection.Create;
FActiveRubberband:=false;
end;
destructor TDesigner.Destroy;
@ -114,7 +137,6 @@ Begin
Inherited;
end;
procedure TDesigner.CreateNew(FileName : string);
begin
@ -123,152 +145,213 @@ end;
Procedure TDesigner.RemoveControl(Control : TComponent);
Begin
Writeln('RemoveControl called');
FSourceEditor.RemoveControlCode(Control);
Writeln('1');
FCustomForm.RemoveControl(TCOntrol(Control)); //this send a message to notification and removes it from the controlselection
Writeln('2');
FFormEditor.DeleteControl(Control);
Writeln('3');
Writeln('[TDesigner.RemoveControl] ',Control.Name,':',Control.ClassName);
FSourceEditor.RemoveControlCode(Control);
Writeln('[TDesigner.RemoveControl] 1');
FCustomForm.RemoveControl(TCOntrol(Control));
//this send a message to notification and removes it from the controlselection
Writeln('[TDesigner.RemoveControl] 2');
FFormEditor.DeleteControl(Control);
Writeln('[TDesigner.RemoveControl] end');
end;
Procedure TDesigner.NudgeControl(Value1,Value2 : Integer);
Begin
Writeln('NudgeControl');
Writeln('[TDesigner.NudgeControl]');
ControlSelection.MoveSelection(Value1,Value2);
end;
Procedure TDesigner.NudgeSize(Value1,Value2 : Integer);
Begin
Writeln('NudgeSize');
Writeln('[TDesigner.NudgeSize]');
ControlSelection.SizeSelection(Value1,Value2);
end;
procedure TDesigner.SelectOnlyThisComponent(AComponent:TComponent);
begin
Writeln('Control Added '+TCOntrol(aComponent).name);
ControlSelection.Clear;
ControlSelection.Add(TControl(AComponent));
Writeln('Control Added ',TControl(aComponent).name);
ControlSelection.Clear;
ControlSelection.Add(TControl(AComponent));
FFormEditor.ClearSelected;
// this will automatically inform the object inspector
FFormEditor.AddSelected(AComponent);
end;
function TDesigner.Paint(Sender: TControl; Message: TLMPaint):boolean;
begin
Result:=true;
Sender.Dispatch(Message);
if (ControlSelection.IsSelected(Sender)) then begin
writeln('*** LM_PAINT ',Sender.Name,':',Sender.ClassName,' DC=',Message.DC);
ControlSelection.DrawMarker(Sender,Message.DC);
ControlSelection.DrawGrabbers;
end;
end;
procedure TDesigner.MouseDownOnControl(Sender : TControl; Message : TLMessage);
procedure TDesigner.MouseDownOnControl(Sender : TControl; Message : TLMMouse);
var i,
MouseX,MouseY,
CompIndex:integer;
FormOrigin,SenderOrigin:TPoint;
AControlSelection:TControlSelection;
SelectedCompClass: TRegisteredComponent;
Begin
// if assigned(MouseDownControl) and (MOuseDownControl <> Sender) then Exit;
Writeln('Left is '+Inttostr(TCOntrol(Sender).left));
Writeln('Top is '+Inttostr(TCOntrol(Sender).Top));
Writeln('***************************');
Writeln('TDesigner.MouseDownOnControl');
Writeln(Format('X,Y = %d,%d',[TLMMOuse(Message).pos.x,TLMMOuse(Message).pos.Y]));
Writeln(Format('Control left and top are %d,%d',[TCOntrol(sender).Left,TCOntrol(sender).Top]));
Writeln('***************************');
if (MouseDownControl<>nil) or (getParentForm(Sender)=nil) then exit;
MouseDownControl:=Sender;
FormOrigin:=GetParentForm(Sender).ClientOrigin;
SenderOrigin:=Sender.ClientOrigin;
MouseX:=Message.Pos.X+SenderOrigin.X-FormOrigin.X;
MouseY:=Message.Pos.Y+SenderOrigin.Y-FormOrigin.Y;
if GetCaptureGrabber<>nil then exit;
MouseDownPos := Point(MouseX,MouseY);
LastMouseMovePos:=MouseDownPos;
if not assigned(MouseDownControl) then
Begin
MouseDownPos.X := TLMMOuse(Message).pos.X;
MouseDownPos.Y := TLMMOuse(Message).pos.Y;
//adjust X and Y by adding the Control corners.
MouseDownControl:=Sender;
if not (Sender is TCustomForm) then
begin
inc(MouseDownPos.X,TControl(Sender).Left);
inc(MouseDownPos.Y,TControl(Sender).Top);
end;
LastMouseMovePos:=MouseDownPos;
end;
writeln('************************************************************');
write('MouseDownOnControl');
write(' ',Sender.Name,':',Sender.ClassName,' Sender=',SenderOrigin.X,',',SenderOrigin.Y);
write(' Msg=',Message.Pos.X,',',Message.Pos.Y);
write(' Mouse=',MouseX,',',MouseY);
writeln('');
if (TLMMouse(Message).keys and MK_Shift) = MK_Shift then
ControlSelection.ActiveGrabber:=
ControlSelection.GrabberAtPos(MouseDownPos.X,MouseDownPos.Y);
if (Message.Keys and MK_Shift) = MK_Shift then
Writeln('Shift down')
else
else
Writeln('No Shift down');
if (TLMMouse(Message).keys and MK_Control) = MK_Control then
if (Message.Keys and MK_Control) = MK_Control then
Writeln('CTRL down')
else
else
Writeln('No CTRL down');
if Assigned(FOnGetSelectedComponentClass) then
FOnGetSelectedComponentClass(Self,SelectedCompClass)
else
SelectedCompClass:=nil;
Writeln('Sender is '+sender.name);
if FMainIDE.SelectedComponent = nil then
Begin //mouse pointer button pressed.
if not (Sender is TCustomForm) then begin
if (TLMMouse(Message).keys and MK_Shift) = MK_Shift then
ControlSelection.Add(sender)
else
SelectOnlyThisComponent(TComponent(Sender));
if SelectedCompClass = nil then begin
// selection mode
if ControlSelection.ActiveGrabber=nil then begin
CompIndex:=ControlSelection.IndexOf(Sender);
if (Message.Keys and MK_SHIFT)>0 then begin
// shift key
if CompIndex<0 then begin
// not selected
// add component to selection
if (ControlSelection.Count=0)
or (not (Sender is TCustomForm)) then begin
ControlSelection.Add(Sender);
Sender.Invalidate;
if Sender.Parent<>nil then
Sender.Parent.Invalidate;
end;
end else begin
// remove from multiselection
ControlSelection.Delete(CompIndex);
Sender.Invalidate;
if Sender.Parent<>nil then
Sender.Parent.Invalidate;
end;
end else begin
if (CompIndex<0) then begin
// select only this component
AControlSelection:=TControlSelection.Create;
AControlSelection.Assign(ControlSelection);
ControlSelection.Clear;
for i:=0 to AControlSelection.Count-1 do
AControlSelection[i].Control.Invalidate;
ControlSelection.Add(Sender);
Sender.Invalidate;
if Sender.Parent<>nil then
Sender.Parent.Invalidate;
AControlSelection.Free;
end;
end;
end;
ControlSelection.SaveBounds;
end else begin
// add component mode -> handled in mousemove and mouseup
end;
writeln('[TDesigner.MouseDownOnControl] END');
End;
procedure TDesigner.MouseUpOnControl(Sender : TControl; Message:TLMessage);
procedure TDesigner.MouseUpOnControl(Sender : TControl; Message:TLMMouse);
var
ParentCI, NewCI : TComponentInterface;
NewLeft, NewTop, NewWidth, NewHeight : Integer;
// CInterface : TComponentInterface;
CaptureGrabber:TGrabber;
Button : TMouseButton;
NewLeft, NewTop, NewWidth, NewHeight,
MouseX, MouseY, I : Integer;
Shift : TShiftState;
SenderParentForm:TCustomForm;
RubberBandWasActive:boolean;
FormOrigin,SenderOrigin:TPoint;
SelectedCompClass: TRegisteredComponent;
AControlSelection: TControlSelection;
Begin
SenderParentForm:=GetParentForm(Sender);
if (MouseDownControl=nil) or (SenderParentForm=nil) then exit;
ControlSelection.ActiveGrabber:=nil;
RubberBandWasActive:=FActiveRubberBand;
if FActiveRubberband then begin
FActiveRubberband:=false;
ControlSelection.DrawRubberBand(false,ControlSelection.RubberBandBounds);
end;
Writeln('***************************');
Writeln('In TDesigner.UpOnControl');
Writeln(Format('X,Y = %d,%d',[TLMMOuse(Message).pos.x,TLMMOuse(Message).pos.Y]));
Writeln('***************************');
if (TLMMouse(Message).keys and MK_LButton) = MK_LButton then
Button := mbLEft
else
if (TLMMouse(Message).keys and MK_LButton) = MK_RButton then
Button := mbRight;
Shift := [];
Shift := [];
if (TLMMouse(Message).keys and MK_Shift) = MK_Shift then
shift := [ssShift];
Shift := [ssShift];
if (TLMMouse(Message).keys and MK_Control) = MK_Control then
shift := shift +[ssCTRL];
Shift := Shift +[ssCTRL];
CaptureGrabber:=GetCaptureGrabber;
if CaptureGrabber<>nil then begin
CaptureGrabber.CaptureMouseUp(TControl(Sender),Button,Shift,TLMMouse(Message).pos.X,TLMMouse(Message).pos.Y);
exit;
end;
FormOrigin:=SenderParentForm.ClientOrigin;
SenderOrigin:=Sender.ClientOrigin;
MouseX:=Message.Pos.X+SenderOrigin.X-FormOrigin.X;
MouseY:=Message.Pos.Y+SenderOrigin.Y-FormOrigin.Y;
MouseUpPos := Point(MouseX,MouseY);
dec(MouseX,MouseDownPos.X);
dec(MouseY,MouseDownPos.Y);
MouseUpPos.X := TLMMouse(Message).pos.X;
MouseUpPos.Y := TLMMouse(Message).pos.Y;
if not (Sender is TCustomForm) then begin
inc(MouseUpPos.X,TControl(Sender).Left);
inc(MouseUpPos.Y,TControl(Sender).Top);
end;
if FMainIDE.SelectedComponent = nil then
Begin //mouse pointer button pressed.
end
if Assigned(FOnGetSelectedComponentClass) then
FOnGetSelectedComponentClass(Self,SelectedCompClass)
else
Begin //add a new control
SelectedCompClass:=nil;
FMainIDE.SetDesigning(FCustomForm,False);
ParentCI:=TComponentInterface(FFormEditor.FindComponent(TComponent(Sender)));
if (TComponent(Sender) is TWinControl)
and (not (csAcceptsControls in TWinControl(Sender).ControlStyle)) then
begin
if SelectedCompClass = nil then begin
// selection mode
if (ControlSelection.Count=1)
and (ControlSelection[0].Control is TCustomForm) then begin
// rubberband selection
if RubberBandWasActive then begin
AControlSelection:=TControlSelection.Create;
AControlSelection.Assign(ControlSelection);
ControlSelection.Clear;
for i:=0 to AControlSelection.Count-1 do
AControlSelection[i].Control.Invalidate;
AControlSelection.Free;
ControlSelection.SelectWithRubberBand(SenderParentForm);
for i:=0 to ControlSelection.Count-1 do
ControlSelection[i].Control.Invalidate;
end;
end;
end else begin
// add a new control
if Assigned(FOnSetDesigning) then FOnSetDesigning(Self,FCustomForm,False);
ParentCI:=TComponentInterface(FFormEditor.FindComponent(Sender));
if (Sender is TWinControl)
and (not (csAcceptsControls in TWinControl(Sender).ControlStyle)) then begin
ParentCI:=TComponentInterface(
FFormEditor.FindComponent(TWinControl(Sender).Parent));
end;
if Assigned(ParentCI) then begin
NewLeft:=Min(MouseDownPos.X,MouseUpPos.X);
NewWidth:=Abs(MouseUpPos.X-MouseDownPos.X);
NewLeft:=Min(MouseDownPos.X,MouseUpPos.X)-(SenderOrigin.X-FormOrigin.X);
NewWidth:=Abs(MouseUpPos.X-MouseDownPos.X)-(SenderOrigin.Y-FormOrigin.Y);
NewTop:=Min(MouseDownPos.Y,MouseUpPos.Y);
NewHeight:=Abs(MouseUpPos.Y-MouseDownPos.Y);
if Abs(NewWidth+NewHeight)<7 then begin
@ -276,29 +359,33 @@ Begin
NewWidth:=0;
NewHeight:=0;
end;
NewCI := TComponentInterface(FFormEditor.CreateComponent(ParentCI,FMainIDE.SelectedComponent.ComponentClass
NewCI := TComponentInterface(FFormEditor.CreateComponent(
ParentCI,SelectedCompClass.ComponentClass
,NewLeft,NewTop,NewWidth,NewHeight));
NewCI.SetPropByName('Visible',True);
NewCI.SetPropByName('Designing',True);
FMainIDE.SetDesigning(NewCI.Control,True);
ObjectInspector1.FillComponentComboBox;
AddControlCode(NewCI.Control);
SelectOnlyThisComponent(TComponent(NewCI.Control));
Writeln('Calling ControlClick with nil from MouseUpOnControl');
FMainIDE.ControlClick(FMainIDE.Notebook1); //this resets it to the mouse.
FMainIDE.SetDesigning(FCustomForm,True);
if Assigned(FOnSetDesigning) then
FOnSetDesigning(Self,NewCI.Control,True);
if Assigned(FOnComponentListChanged) then
FOnComponentListChanged(Self);
if Assigned(FOnAddComponent) then
FOnAddComponent(Self,NewCI.Control,SelectedCompClass);
SelectOnlyThisComponent(TComponent(NewCI.Control));
Writeln('Calling ControlClick with nil from MouseUpOnControl');
if not (ssCtrl in Shift) then
if Assigned(FOnUnselectComponentClass) then
// this resets it to the mouse. (= selection tool)
FOnUnselectComponentClass(Self);
if Assigned(FOnSetDesigning) then FOnSetDesigning(Self,FCustomForm,True);
end;
end;
MouseDownControl:=nil;
writeln('[TDesigner.MouseUpOnControl] END');
end;
Procedure TDesigner.MouseMoveOnControl(Sender : TControl; var Message : TLMessage);
Procedure TDesigner.MouseMoveOnControl(Sender : TControl; var Message : TLMMouse);
const
mk_lbutton = 1;
mk_rbutton = 2;
@ -306,55 +393,53 @@ const
mk_control = 8;
mk_mbutton = $10;
var
CaptureGrabber : TGrabber;
Shift : TShiftState;
X,Y : Integer;
FormOrigin, SenderOrigin:TPoint;
SenderParentForm:TCustomForm;
MouseX, MouseY :integer;
Begin
if MouseDownControl=nil then exit;
// if assigned(MouseDownControl) and (MOuseDownControl <> Sender) then Exit;
Writeln('MouseMoveOnControl');
X :=TLMMouse(Message).Pos.x;
Y := TLMMouse(Message).Pos.Y;
Writeln('MousePos');
Writeln(Format('X,y = %d,%d',[Mouse.CursorPos.X,MOuse.CursorPos.Y]));
Writeln('X and Y are '+inttostr(x)+','+inttostr(y));
If (sender is TControl) then Begin
Writeln('Sender is '+TControl(sender).Name);
Writeln('Left is '+Inttostr(TControl(sender).Left));
Writeln('Width is '+Inttostr(TControl(sender).Width));
Writeln('Top is '+Inttostr(TControl(sender).Top));
Writeln('Height is '+Inttostr(TControl(sender).Height));
end;
if Assigned(MouseDownControl) then Writeln('MouseDownControl is '+TCOntrol(MouseDownControl).Name);
SenderParentForm:=GetParentForm(Sender);
if SenderParentForm=nil then exit;
FormOrigin:=SenderParentForm.ClientOrigin;
SenderOrigin:=Sender.ClientOrigin;
MouseX:=Message.Pos.X+SenderOrigin.X-FormOrigin.X;
MouseY:=Message.Pos.Y+SenderOrigin.Y-FormOrigin.Y;
if (Message.keys and MK_LButton) = MK_LButton then begin
Write('TDesigner.MouseMoveOnControl');
Write(' Cur=',MouseX,',',MouseY);
Write(' Msg=',Message.Pos.x,',',Message.Pos.Y);
Write(' ',Sender.Name,':',Sender.ClassName,'=',Sender.Left,',',Sender.Top);
writeln();
end;
Shift := [];
if (TLMMouse(Message).keys and MK_Shift) = MK_Shift then
shift := [ssShift];
Shift := [ssShift];
if (TLMMouse(Message).keys and MK_Control) = MK_Control then
shift := Shift + [ssCTRL];
Shift := Shift + [ssCTRL];
CaptureGrabber:=GetCaptureGrabber;
if CaptureGrabber<>nil then begin
CaptureGrabber.CaptureMouseMove(TControl(Sender),Shift,X,Y);
if ControlSelection.ActiveGrabber<>nil then begin
if (Message.keys and MK_LButton) = MK_LButton then begin
ControlSelection.SizeSelection(MouseX-MouseDownPos.X, MouseY-LastMouseMovePos.Y);
if Assigned(FOnPropertiesChanged) then
FOnPropertiesChanged(Self);
end;
end else begin
if Assigned(MouseDownControl) then begin
if FMainIDE.SelectedComponent = nil then begin
// mouse pointer button pressed
{ if not (Sender is TCustomForm) then} begin
// move selection
Writeln('moving stuff');
{ if not(X in ([0 ..(TControl(sender).Width)])) or
not(Y in ([0 ..(TControl(sender).Height)])) then
exit; }
ControlSelection.MoveSelection(X-LastMouseMovePos.X, Y-LastMouseMovePos.Y);
// ControlSelection.MoveContent(X-LastMouseMovePos.X, Y-LastMouseMovePos.Y);
LastMouseMovePos:=Point(X,Y);
end;
end;
if (Message.keys and MK_LButton) = MK_LButton then begin
if (ControlSelection.Count>=1)
and not (ControlSelection[0].Control is TCustomForm) then begin
// move selection
ControlSelection.MoveSelection(
MouseX-MouseDownPos.X, MouseY-MouseDownPos.Y);
if Assigned(FOnPropertiesChanged) then
FOnPropertiesChanged(Self);
end;
end;
end;
LastMouseMovePos:=Point(MouseX,MouseY);
end;
{
@ -362,85 +447,62 @@ end;
}
{
Handles the keydown messages. DEL deletes the selected controls, CTRL-UPARROR/DOWNARROW
moves the selction up one, etc.
moves the selection up one, etc.
}
Procedure TDesigner.KeyDown(Sender : TControl; Message:TLMKEY);
var
I : Integer;
Continue : Boolean;
Shift : TShiftState;
Begin
Writeln('KEYDOWN');
with MEssage do
with MEssage do
Begin
Writeln('CHARCODE = '+inttostr(charcode));
Writeln('KEYDATA = '+inttostr(KeyData));
Writeln('CHARCODE = '+inttostr(charcode));
Writeln('KEYDATA = '+inttostr(KeyData));
end;
Shift := KeyDataToShiftState(Message.KeyData);
if Message.CharCode = 46 then //DEL KEY
begin
Continue := True;
While Continue do
Begin
Continue := False;
for I := 0 to FCustomForm.ComponentCount-1 do
Begin
Writeln('I = '+inttostr(i));
if (FCustomForm.Components[i] is TControl) and
ControlSelection.IsSelected(TControl(FCustomForm.Components[i])) then
Begin
Continue := True;
RemoveControl(TControl(FCustomForm.Components[i]));
Break;
end;
end;
End;
SelectOnlythisComponent(FCustomForm);
end
else
if Message.CharCode = 38 then //UP ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(0,-1)
else
if (ssShift in Shift) then
NudgeSize(0,-1);
end
else
if Message.CharCode = 40 then //DOWN ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(0,1)
else
if (ssShift in Shift) then
NudgeSize(0,1);
end
else
if Message.CharCode = 39 then //RIGHT ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(1,0)
else
if (ssShift in Shift) then
NudgeSize(1,0);
end
else
if Message.CharCode = 37 then //LEFT ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(-1,0)
else
if (ssShift in Shift) then
NudgeSize(-1,0);
end;
Shift := KeyDataToShiftState(Message.KeyData);
if Message.CharCode = 46 then //DEL KEY
begin
for I := ControlSelection.Count-1 downto 0 do Begin
Writeln('I = '+inttostr(i));
RemoveControl(ControlSelection.Items[I].Control);
End;
SelectOnlythisComponent(FCustomForm);
end
else
if Message.CharCode = 38 then //UP ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(0,-1)
else if (ssShift in Shift) then
NudgeSize(0,-1);
end
else if Message.CharCode = 40 then //DOWN ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(0,1)
else if (ssShift in Shift) then
NudgeSize(0,1);
end
else
if Message.CharCode = 39 then //RIGHT ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(1,0)
else if (ssShift in Shift) then
NudgeSize(1,0);
end
else
if Message.CharCode = 37 then //LEFT ARROW
Begin
if (ssCtrl in Shift) then
NudgeControl(-1,0)
else if (ssShift in Shift) then
NudgeSize(-1,0);
end;
end;
@ -448,49 +510,34 @@ end;
Procedure TDesigner.KeyUp(Sender : TControl; Message:TLMKEY);
Begin
Writeln('KEYUp');
with MEssage do
with MEssage do
Begin
Writeln('CHARCODE = '+inttostr(charcode));
Writeln('KEYDATA = '+inttostr(KeyData));
Writeln('CHARCODE = '+inttostr(charcode));
Writeln('KEYDATA = '+inttostr(KeyData));
end;
end;
function TDesigner.IsDesignMsg(Sender: TControl; var Message: TLMessage): Boolean;
Begin
result := false;
if ((Message.msg >= LM_MOUSEFIRST) and (Message.msg <= LM_MOUSELAST)) then
Result := true
else
if ((Message.msg >= LM_KeyFIRST) and (Message.msg <= LM_KeyLAST)) then
Begin
Writeln('KEY MESSAGE in IsDesignMsg');
if MEssage.MSG = LM_KEYDOWN then KeyDown(Sender,TLMKey(Message))
else
if MEssage.MSG = LM_KEYUP then KeyUP(Sender,TLMKey(Message));
Result := true;
result := false;
if csDesigning in Sender.ComponentState then begin
if ((Message.msg >= LM_MOUSEFIRST) and (Message.msg <= LM_MOUSELAST)) then
Result := true
else
if ((Message.msg >= LM_KeyFIRST) and (Message.msg <= LM_KeyLAST)) then
Result:=true;
case Message.MSG of
LM_PAINT: Result:=Paint(Sender,TLMPAINT(Message));
LM_KEYDOWN: KeyDown(Sender,TLMKey(Message));
LM_KEYUP: KeyUP(Sender,TLMKey(Message));
LM_LBUTTONDOWN: MouseDownOnControl(sender,TLMMouse(Message));
LM_LBUTTONUP: MouseUpOnControl(sender,TLMMouse(Message));
LM_MOUSEMOVE: MouseMoveOnControl(Sender, TLMMouse(Message));
end;
if (Message.msg=LM_LBUTTONDOWN) then
begin
MouseDownonControl(sender,message);
end
else
if (Message.msg=LM_LBUTTONUP) then
begin
MouseUPONControl(sender,message);
end
else
if Message.msg = LM_MOUSEMOVE then
MouseMoveonCOntrol(Sender, Message)
{if Result then Writeln('It IS a design message')
else
Writeln('It IS NOT a design message');
}
end;
end;
procedure TDesigner.LoadFile(FileName: string);
@ -503,13 +550,6 @@ Begin
end;
Procedure TDesigner.AddControlCode(Control : TComponent);
Begin
FSourceEditor.AddControlCode(Control);
end;
procedure TDesigner.Notification(AComponent: TComponent; Operation: TOperation);
Begin
if Operation = opInsert then
@ -530,32 +570,32 @@ procedure TDesigner.PaintGrid;
var
x,y : integer;
begin
with FCustomForm do
Begin
canvas.Pen.Color := clGray;
x := left;
while x <= left + width do
begin
y := Top;
while y <= top+height do
begin
//if Controlatpos(TPOINT([x,y]),True) = nil then
Canvas.Rectangle(x-left,y-top,x-left+1,y-top);
Inc(y, GridPoints.Y);
end;
Inc(x, GridPoints.X);
end;
writeln('PaintGrid DC=',FCustomForm.Canvas.Handle,' ',Cardinal(Pointer(FCustomForm)));
with FCustomForm.Canvas do begin
Pen.Color := clGray;
x := 0;
while x <= FCustomForm.Width do begin
y := 0;
while y <= FCustomForm.Height do begin
//if Controlatpos(Point(x,y),True) = nil then
MoveTo(x,y);
LineTo(x+1,y);
Inc(y, GridPoints.Y);
end;
Inc(x, GridPoints.X);
end;
end;
end;
procedure TDesigner.ValidateRename(AComponent: TComponent; const CurName, NewName: string);
procedure TDesigner.ValidateRename(AComponent: TComponent;
const CurName, NewName: shortstring);
Begin
end;
function TDesigner.GetIsControl: Boolean;
Begin
Result := True;
Result := True;
end;
procedure TDesigner.SetIsControl(Value: Boolean);

View File

@ -73,6 +73,15 @@ function FindResourceInCode(Source:string; AddCode:string;
var Position,EndPosition:integer):boolean;
function AddResourceCode(var Source:string; AddCode:string):boolean;
// form components
function FindFormClassDefinitionInSource(Source:string; FormClassName:string;
var FormClassNameStartPos, FormBodyStartPos: integer
):boolean;
function FindFormComponentInSource(Source: string; FormBodyStartPos: integer;
ComponentName, ComponentClassName: string): integer;
function AddFormComponentToSource(var Source:string; FormBodyStartPos: integer;
ComponentName, ComponentClassName: string): boolean;
// code search
function SearchCodeInSource(Source,Find:string; StartPos:integer;
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
@ -622,6 +631,89 @@ begin
Result:=true;
end;
function FindFormClassDefinitionInSource(Source:string; FormClassName:string;
var FormClassNameStartPos, FormBodyStartPos: integer
):boolean;
var AtomEnd,AtomStart: integer;
begin
Result:=false;
if FormClassName='' then exit;
repeat
FormClassNameStartPos:=SearchCodeInSource(Source,
FormClassName+'=class(TForm)',1,FormBodyStartPos,false);
if FormClassNameStartPos<1 then exit;
AtomEnd:=FormBodyStartPos;
until ReadNextPascalAtom(Source,AtomEnd,AtomStart)<>';';
Result:=true;
end;
function FindFormComponentInSource(Source: string; FormBodyStartPos: integer;
ComponentName, ComponentClassName: string): integer;
var AtomStart, OldPos: integer;
Atom: string;
begin
ComponentName:=lowercase(ComponentName);
ComponentClassName:=lowercase(ComponentClassName);
Result:=FormBodyStartPos;
repeat
Atom:=lowercase(ReadNextPascalAtom(Source,Result,AtomStart));
if (Atom='public') or (Atom='published') or (Atom='private') or (Atom='end')
or (Atom='protected') or (Atom='') then begin
Result:=-1;
exit;
end;
OldPos:=Result;
if (lowercase(ReadNextPascalAtom(Source,Result,AtomStart))=ComponentName)
and (ReadNextPascalAtom(Source,Result,AtomStart)=':')
and (lowercase(ReadNextPascalAtom(Source,Result,AtomStart))=ComponentClassName)
and (ReadNextPascalAtom(Source,Result,AtomStart)=';') then begin
Result:=OldPos;
exit;
end;
until Result>length(Source);
Result:=-1;
end;
function AddFormComponentToSource(var Source:string; FormBodyStartPos: integer;
ComponentName, ComponentClassName: string): boolean;
var Position, AtomStart: integer;
Atom: string;
PriorSpaces, NextSpaces: string;
begin
Result:=false;
if FindFormComponentInSource(Source,FormBodyStartPos
,ComponentName,ComponentClassName)>0 then begin
Result:=true;
exit;
end;
repeat
// find a good position to insert the component
// in front of next section and in front of procedures/functions
Position:=FormBodyStartPos;
Atom:=lowercase(ReadNextPascalAtom(Source,Position,AtomStart));
if (Atom='procedure') or (Atom='function') or (Atom='end') or (Atom='class')
or (Atom='constructor') or (Atom='destructor')
or (Atom='public') or (Atom='private') or (Atom='protected')
or (Atom='published') or (Atom='class') or (Atom='property') then begin
// insert component definition in source
if (Atom='public') or (Atom='private') or (Atom='protected')
or (Atom='published') then begin
PriorSpaces:=' ';
NextSpaces:=' ';
end else begin
PriorSpaces:='';
NextSpaces:=' ';
end;
Source:=copy(Source,1,AtomStart-1)
+PriorSpaces+ComponentName+': '+ComponentClassName+';'+EndOfLine
+NextSpaces+copy(Source,AtomStart,length(Source)-AtomStart+1);
Result:=true;
exit;
end;
until Position>length(Source);
Result:=false;
end;
function SearchCodeInSource(Source,Find:string; StartPos:integer;
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
// search pascal atoms of Find in Source

View File

@ -31,7 +31,7 @@ type
property Page:TRegisteredComponentPage read FPage;
property ComponentClass:TComponentClass read FComponentClass;
property IndexInPage:integer read FIndexInPage;
property UnitName:ShortString;
property UnitName:ShortString read FUnitName;
constructor Create(APage:TRegisteredComponentPage; TheIndexInPage:integer;
AUnitName:ShortString; AComponentClass:TComponentClass);
end;

View File

@ -17,10 +17,9 @@
* *
***************************************************************************/
}
{$H+}
unit CustomFormEditor;
{$mode objfpc}
{$mode objfpc}{$H+}
interface
@ -47,27 +46,27 @@ each control that's dropped onto the form
protected
Function GetPPropInfobyIndex(Index : Integer) : PPropInfo;
Function GetPPropInfobyName(Name : String) : PPropInfo;
Function GetPPropInfobyName(Name : ShortString) : PPropInfo;
public
constructor Create;
destructor Destroy; override;
Function GetComponentType : String; override;
Function GetComponentType : ShortString; override;
Function GetComponentHandle : LongInt; override;
Function GetParent : TIComponentInterface; override;
Function IsTControl : Boolean; override;
Function GetPropCount : Integer; override;
Function GetPropType(Index : Integer) : TTypeKind; override;
Function GetPropTypeInfo(Index : Integer) : PTypeInfo;
Function GetPropName(Index : Integer) : String; override;
Function GetPropTypeName(Index : Integer) : String; override;
Function GetPropTypebyName(Name : String) : TTypeKind; override;
Function GetPropName(Index : Integer) : ShortString; override;
Function GetPropTypeName(Index : Integer) : ShortString; override;
Function GetPropTypebyName(Name : ShortString) : TTypeKind; override;
Function GetPropValue(Index : Integer; var Value) : Boolean; override;
Function GetPropValuebyName(Name: String; var Value) : Boolean; override;
Function GetPropValuebyName(Name: ShortString; var Value) : Boolean; override;
Function SetProp(Index : Integer; const Value) : Boolean; override;
Function SetPropbyName(Name : String; const Value) : Boolean; override;
Function SetPropbyName(Name : ShortString; const Value) : Boolean; override;
Function GetControlCount: Integer; override;
@ -105,7 +104,7 @@ TCustomFormEditor
Procedure DeleteControl(Value : TComponent);
Function Filename : String; override;
Function FormModified : Boolean; override;
Function FindComponentByName(const Name : String) : TIComponentInterface; override;
Function FindComponentByName(const Name : ShortString) : TIComponentInterface; override;
Function FindComponent(AComponent: TComponent): TIComponentInterface; override;
Function GetFormComponent : TIComponentInterface; override;
// Function CreateComponent(CI : TIComponentInterface; TypeName : String;
@ -115,7 +114,8 @@ TCustomFormEditor
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; override;
Function NewFormFromLFM(_Filename : String): TCustomform;
Procedure ClearSelected;
property SelectedComponents : TComponentSelectionList read FSelectedComponents write FSelectedComponents;
property SelectedComponents : TComponentSelectionList
read FSelectedComponents write FSelectedComponents;
property Obj_Inspector : TObjectInspector read FObj_Inspector write FObj_Inspector;
end;
@ -156,7 +156,7 @@ writeln('Index = '+inttostr(PRI^.index));
tkAString,
tkWString : Begin
Writeln('String...');
SetStrProp(FControl,PRI,String(Value));
SetStrProp(FControl,PRI,ShortString(Value));
Result := True;
end;
tkInteger,
@ -195,7 +195,7 @@ Result := True;
tkAString,
tkWString : Begin
Writeln('Get String...');
String(Value) := GetStrProp(FControl,PRI);
ShortString(Value) := GetStrProp(FControl,PRI);
Writeln('The string returned is '+String(value));
Writeln('*Get String...');
end;
@ -243,7 +243,7 @@ Begin
Freemem(PP);
end;
Function TComponentInterface.GetPPropInfoByName(Name:String): PPropInfo;
Function TComponentInterface.GetPPropInfoByName(Name:ShortString): PPropInfo;
var
PT : PTypeData;
PP : PPropList;
@ -268,7 +268,7 @@ Begin
Freemem(PP);
end;
Function TComponentInterface.GetComponentType : String;
Function TComponentInterface.GetComponentType : ShortString;
Begin
Result:=FControl.ClassName;
end;
@ -340,11 +340,11 @@ end;
{This returns "Integer" or "Boolean"}
Function TComponentInterface.GetPropTypeName(Index : Integer) : String;
Function TComponentInterface.GetPropTypeName(Index : Integer) : ShortString;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
Begin
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
@ -359,7 +359,7 @@ end;
{This returns "Left" "Align" "Visible"}
Function TComponentInterface.GetPropName(Index : Integer) : String;
Function TComponentInterface.GetPropName(Index : Integer) : ShortString;
var
PT : PTypeData;
PP : PPropList;
@ -377,7 +377,7 @@ Begin
freemem(PP);
end;
Function TComponentInterface.GetPropTypebyName(Name : String) : TTypeKind;
Function TComponentInterface.GetPropTypebyName(Name : ShortString) : TTypeKind;
var
PT : PTypeData;
PP : PPropList;
@ -411,7 +411,7 @@ PP := GetPPropInfoByIndex(Index);
Result := FGetProp(PP,Value);
end;
Function TComponentInterface.GetPropValuebyName(Name: String; var Value) : Boolean;
Function TComponentInterface.GetPropValuebyName(Name: ShortString; var Value) : Boolean;
var
PRI : PPropInfo;
Begin
@ -435,7 +435,7 @@ Begin
end;
Function TComponentInterface.SetPropbyName(Name : String; const Value) : Boolean;
Function TComponentInterface.SetPropbyName(Name : ShortString; const Value) : Boolean;
var
PRI : PPropInfo;
Begin
@ -563,7 +563,8 @@ Begin
Result := FModified;
end;
Function TCustomFormEditor.FindComponentByName(const Name : String) : TIComponentInterface;
Function TCustomFormEditor.FindComponentByName(
const Name : ShortString) : TIComponentInterface;
Var
Num : Integer;
Begin
@ -593,7 +594,7 @@ Begin
end;
Function TCustomFormEditor.CreateComponent(ParentCI : TIComponentInterface;
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface;
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface;
Var
Temp : TComponentInterface;
TempName : String;
@ -615,9 +616,9 @@ Begin
else
Begin
//this should be a form
NewFormIndex := JITFormList.AddNewJITForm;
if NewFormIndex >= 0 then
Temp.FControl := JITFormList[NewFormIndex];
NewFormIndex := JITFormList.AddNewJITForm;
if NewFormIndex >= 0 then
Temp.FControl := JITFormList[NewFormIndex];
end;
if Assigned(ParentCI) then
@ -638,21 +639,20 @@ Begin
end;
end;
if ParentCI <> nil then
Begin
if ParentCI <> nil then Begin
Writeln('ParentCI <> nil');
TempName := Temp.FControl.ClassName;
delete(TempName,1,1);
writeln('TempName is '''+TempName+'''');
Num := 0;
Found := True;
While Found do
Begin
While Found do Begin
Found := False;
inc(num);
for I := 0 to FComponentInterfaceList.Count-1 do
begin
DummyComponent:=TComponent(TComponentInterface(FComponentInterfaceList.Items[i]).FControl);
DummyComponent:=TComponent(TComponentInterface(
FComponentInterfaceList.Items[i]).FControl);
if UpCase(DummyComponent.Name)=UpCase(TempName+IntToStr(Num)) then
begin
Found := True;
@ -662,7 +662,7 @@ Begin
end;
Temp.FControl.Name := TempName+IntToStr(Num);
Writeln('TempName + num = '+TempName+Inttostr(num));
end;
end;
if (Temp.FControl is TControl) then
Begin

View File

@ -114,7 +114,7 @@ type
itmEnvEditorOptions: TMenuItem;
CheckBox1 : TCheckBox;
Notebook1 : TNotebook;
ComponentNotebook : TNotebook;
cmdTest: TButton;
cmdTest2: TButton;
Label2 : TLabel;
@ -205,6 +205,7 @@ type
function DoViewUnitsAndForms(OnlyForms: boolean): TModalResult;
// project(s)
property Project: TProject read fProject write fProject;
function DoNewProject(NewProjectType:TProjectType):TModalResult;
function DoSaveProject(SaveAs:boolean):TModalResult;
function DoCloseProject:TModalResult;
@ -237,9 +238,18 @@ type
procedure FormPaint(Sender : TObject);
procedure LoadFormFromFile(Value : String);
// form editor and designer
property SelectedComponent : TRegisteredComponent
read FSelectedComponent write FSelectedComponent;
property Project: TProject read fProject write fProject;
procedure OnDesignerGetSelectedComponentClass(Sender: TObject;
var RegisteredComponent: TRegisteredComponent);
procedure OnDesignerUnselectComponentClass(Sender: TObject);
procedure OnDesignerSetDesigning(Sender: TObject; Component: TComponent;
Value: boolean);
procedure OnDesignerComponentListChanged(Sender: TObject);
procedure OnDesignerPropertiesChanged(Sender: TObject);
procedure OnDesignerAddComponent(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent);
procedure SaveDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
procedure LoadDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
@ -345,15 +355,16 @@ begin
Bitmap1 := TBitmap.Create;
Bitmap1.Handle := CreatePixmapIndirect(@IMGOK_Check, ColorToRGB(clBtnFace));
Notebook1 := TNotebook.Create(Self);
Notebook1.Parent := Self;
Notebook1.Align := alBottom;
Notebook1.Left := 1;
// Notebook1.Top :=50+ mnuBarMain.Top+MnuBarMain.Height + 2;
Notebook1.Top :=50+ 2;
Notebook1.Width := ClientWidth;
Notebook1.Height := 100; //ClientHeight - Notebook1.Top;
ComponentNotebook := TNotebook.Create(Self);
with ComponentNotebook do begin
Parent := Self;
Align := alBottom;
Left := 1;
// ComponentNotebook.Top :=50+ MnuBarMain.Top+MnuBarMain.Height + 2;
Top :=50+ 2;
Width := Self.ClientWidth;
Height := 100; //Self.ClientHeight - ComponentNotebook.Top;
end;
SelectionPointerPixmap:=LoadSpeedBtnPixMap('tmouse');
PageCount := 0;
@ -363,12 +374,12 @@ begin
if RegCompPage.Name <> '' then
Begin
if (pagecount = 0) then
Notebook1.Pages.Strings[pagecount] := RegCompPage.Name
else Notebook1.Pages.Add(RegCompPage.Name);
ComponentNotebook.Pages.Strings[pagecount] := RegCompPage.Name
else ComponentNotebook.Pages.Add(RegCompPage.Name);
GlobalMouseSpeedButton := TSpeedButton.Create(Self);
with GlobalMouseSpeedButton do
Begin
Parent := Notebook1.Page[PageCount];
Parent := ComponentNotebook.Page[PageCount];
Enabled := True;
Width := 25;
Height := 25;
@ -386,7 +397,7 @@ begin
IDEComponent := TIDEComponent.Create;
IdeComponent.RegisteredComponent := RegComp;
Writeln('Name is '+RegComp.ComponentClass.ClassName);
IDEComponent._SpeedButton(Self,Notebook1.Page[PageCount]);
IDEComponent._SpeedButton(Self,ComponentNotebook.Page[PageCount]);
IDEComponent.SpeedButton.OnClick := @ControlClick;
IDEComponent.SpeedButton.Hint := RegComp.ComponentClass.ClassName;
IDEComponent.SpeedButton.Name := IDEComponent.SpeedButton.Hint;
@ -395,10 +406,10 @@ begin
inc(PageCount);
end;
end;
Notebook1.PageIndex := 0; // Set it to the first page
Notebook1.Show;
Notebook1.OnPageChanged := @ControlClick;
Notebook1.Name := 'Notebook1';
ComponentNotebook.PageIndex := 0; // Set it to the first page
ComponentNotebook.Show;
ComponentNotebook.OnPageChanged := @ControlClick;
ComponentNotebook.Name := 'ComponentNotebook';
ViewUnitsSpeedBtn := TSpeedButton.Create(Self);
with ViewUnitsSpeedBtn do
@ -631,7 +642,7 @@ end;
procedure TMainIDE.OIOnAddAvailableComponent(AComponent:TComponent;
var Allowed:boolean);
begin
Allowed:=(not (AComponent is TGrabber));
//Allowed:=(not (AComponent is TGrabber));
end;
procedure TMainIDE.OIOnSelectComponent(AComponent:TComponent);
@ -1054,13 +1065,13 @@ begin
:= False
else begin
Temp := nil;
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
for i := 0 to ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1 do
begin
if CompareText(
TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(ComponentNotebook.Pageindex)) = 0 then
begin
temp := TControl(Notebook1.Page[Notebook1.Pageindex].Controls[i]);
temp := TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[i]);
Break;
end;
end;
@ -1068,7 +1079,7 @@ begin
TSpeedButton(Temp).down := False
else
Writeln('*****************ERROR - Control ',
'GlobalMouseSpeedButton',inttostr(Notebook1.Pageindex),' not found');
'GlobalMouseSpeedButton',inttostr(ComponentNotebook.Pageindex),' not found');
end;
if IDECOmp <> nil then Begin
//draw this button down
@ -1077,13 +1088,13 @@ begin
end else begin
SelectedComponent := nil;
Temp := nil;
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
for i := 0 to ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1 do
begin
if CompareText(
TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(ComponentNotebook.Pageindex)) = 0 then
begin
temp := TControl(Notebook1.Page[Notebook1.Pageindex].Controls[i]);
temp := TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[i]);
Break;
end;
end;
@ -1091,7 +1102,7 @@ begin
TSpeedButton(Temp).down := True
else
Writeln('*****************ERROR - Control '
+'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)+' not found');
+'GlobalMouseSpeedButton'+inttostr(ComponentNotebook.Pageindex)+' not found');
end;
end
else
@ -1104,13 +1115,13 @@ begin
:= False;
SelectedComponent := nil;
Temp := nil;
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
for i := 0 to ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1 do
begin
if CompareText(
TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[I]).Name
,'GlobalMouseSpeedButton'+inttostr(ComponentNotebook.Pageindex)) = 0 then
begin
temp := TControl(Notebook1.Page[Notebook1.Pageindex].Controls[i]);
temp := TControl(ComponentNotebook.Page[ComponentNotebook.Pageindex].Controls[i]);
Break;
end;
end;
@ -1118,7 +1129,7 @@ begin
TSpeedButton(Temp).down := True
else
Writeln('*****************ERROR - Control '
+'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)+' not found');
+'GlobalMouseSpeedButton'+inttostr(ComponentNotebook.Pageindex)+' not found');
end;
Writeln('Exiting ControlClick');
end;
@ -1295,8 +1306,15 @@ end;
Procedure TMainIDE.SetDefaultsforForm(aForm : TCustomForm);
Begin
aForm.Designer := TDesigner.Create(aForm);
TDesigner(aForm.Designer).MainIDE := Self;
TDesigner(aForm.Designer).FormEditor := FormEditor1;
with TDesigner(aForm.Designer) do begin
FormEditor := FormEditor1;
OnGetSelectedComponentClass:=@OnDesignerGetSelectedComponentClass;
OnUnselectComponentClass:=@OnDesignerUnselectComponentClass;
OnSetDesigning:=@OnDesignerSetDesigning;
OnComponentListChanged:=@OnDesignerComponentListChanged;
OnPropertiesChanged:=@OnDesignerPropertiesChanged;
OnAddComponent:=@OnDesignerAddComponent;
end;
end;
@ -2683,6 +2701,92 @@ begin
end;
end;
procedure TMainIDE.OnDesignerGetSelectedComponentClass(Sender: TObject;
var RegisteredComponent: TRegisteredComponent);
begin
RegisteredComponent:=SelectedComponent;
end;
procedure TMainIDE.OnDesignerUnselectComponentClass(Sender: TObject);
begin
ControlClick(ComponentNoteBook);
end;
procedure TMainIDE.OnDesignerSetDesigning(Sender: TObject;
Component: TComponent; Value: boolean);
begin
SetDesigning(Component,Value);
end;
procedure TMainIDE.OnDesignerComponentListChanged(Sender: TObject);
begin
ObjectInspector1.FillComponentComboBox;
end;
procedure TMainIDE.OnDesignerPropertiesChanged(Sender: TObject);
begin
ObjectInspector1.RefreshPropertyValues;
end;
procedure TMainIDE.OnDesignerAddComponent(Sender: TObject;
Component: TComponent; ComponentClass: TRegisteredComponent);
var i: integer;
ActiveForm: TCustomForm;
ActiveUnitInfo: TUnitInfo;
SrcTxt: string;
SrcTxtChanged: boolean;
ActiveSrcEdit: TSourceEditor;
FormClassName: string;
FormClassNameStartPos, FormBodyStartPos: integer;
begin
ActiveForm:=TDesigner(Sender).Form;
if ActiveForm=nil then begin
writeln('[TMainIDE.OnDesignerAddComponent] Error: TDesigner without a form');
halt;
end;
// find source for form
i:=Project.UnitCount-1;
while (i>=0) do begin
if (Project.Units[i].Loaded)
and (Project.Units[i].Form=ActiveForm) then break;
dec(i);
end;
if i<0 then begin
writeln('[TMainIDE.OnDesignerAddComponent] Error: form without source');
halt;
end;
ActiveUnitInfo:=Project.Units[i];
SrcTxt:=ActiveUnitInfo.Source.Text;
SrcTxtChanged:=false;
// add needed unit to source
SrcTxtChanged:=SrcTxtChanged
or AddToInterfaceUsesSection(SrcTxt,ComponentClass.UnitName,'');
// add component definition to form source
FormClassName:=ActiveForm.ClassName;
if FindFormClassDefinitionInSource(SrcTxt,FormClassName,
FormClassNameStartPos, FormBodyStartPos) then begin
if AddFormComponentToSource(SrcTxt,FormBodyStartPos,
Component.Name, Component.ClassName) then begin
SrcTxtChanged:=true;
end else begin
Application.MessageBox('No insert point in source for the new component found.'
,'Code tool failure',mb_ok);
end;
end else begin
// the form is not mentioned in the source?
// ignore silently
end;
// update source
if SrcTxtChanged then begin
ActiveUnitInfo.Source.Text:=SrcTxt;
ActiveUnitInfo.Modified:=true;
ActiveSrcEdit:=SourceNoteBook.FindSourceEditorWithPageIndex(
ActiveUnitInfo.EditorIndex);
ActiveSrcEdit.EditorComponent.Lines.Text:=SrcTxt;
ActiveSrcEdit.EditorComponent.Modified:=true;
end;
end;
initialization
{$I images/laz_images.lrs}
@ -2695,8 +2799,8 @@ end.
{ =============================================================================
$Log$
Revision 1.73 2001/03/12 09:34:52 lazarus
MG: added transfermacros, renamed dlgmessage.pp to msgview.pp
Revision 1.74 2001/03/12 18:57:31 lazarus
MG: new designer and controlselection code
Revision 1.68 2001/03/03 11:06:15 lazarus
added project support, codetools

View File

@ -1536,7 +1536,7 @@ begin
end;
// load active breakpoint image
Pixmap1:=TPixMap.Create;
//Pixmap1.TransparentColor:=clBtnFace;
Pixmap1.TransparentColor:=clBtnFace;
if not LoadPixmapRes('ActiveBreakPoint',Pixmap1) then
LoadPixmapRes('default',Pixmap1);
MarksImgList.Add(Pixmap1,nil);