IDEIntf: designer mediator: mouse events

git-svn-id: trunk@21730 -
This commit is contained in:
mattias 2009-09-16 09:59:02 +00:00
parent 522164c337
commit 3d4e211dbf
3 changed files with 109 additions and 59 deletions

View File

@ -138,7 +138,7 @@ type
MouseDownComponent: TComponent; MouseDownComponent: TComponent;
MouseDownSender: TComponent; MouseDownSender: TComponent;
MouseDownPos: TPoint; MouseDownPos: TPoint;
MouseDownClickCount: integer; MouseDownShift: TShiftState;
MouseUpPos: TPoint; MouseUpPos: TPoint;
LastMouseMovePos: TPoint; LastMouseMovePos: TPoint;
PopupMenuComponentEditor: TBaseComponentEditor; PopupMenuComponentEditor: TBaseComponentEditor;
@ -158,6 +158,8 @@ type
procedure KeyDown(Sender: TControl; var TheMessage: TLMKEY); procedure KeyDown(Sender: TControl; var TheMessage: TLMKEY);
procedure KeyUp(Sender: TControl; var TheMessage: TLMKEY); procedure KeyUp(Sender: TControl; var TheMessage: TLMKEY);
function HandleSetCursor(var TheMessage: TLMessage): boolean; function HandleSetCursor(var TheMessage: TLMessage): boolean;
procedure GetMouseMsgShift(TheMessage: TLMMouse; var Shift: TShiftState;
var Button: TMouseButton);
// procedures for working with components and persistents // procedures for working with components and persistents
function GetDesignControl(AControl: TControl): TControl; function GetDesignControl(AControl: TControl): TControl;
@ -1253,6 +1255,45 @@ begin
end; end;
end; end;
procedure TDesigner.GetMouseMsgShift(TheMessage: TLMMouse;
var Shift: TShiftState; var Button: TMouseButton);
begin
Shift := [];
if (TheMessage.keys and MK_Shift) = MK_Shift then
Include(Shift,ssShift);
if (TheMessage.keys and MK_Control) = MK_Control then
Include(Shift,ssCtrl);
case TheMessage.Msg of
LM_LBUTTONUP,LM_LBUTTONDBLCLK,LM_LBUTTONTRIPLECLK,LM_LBUTTONQUADCLK:
begin
Include(Shift,ssLeft);
Button:=mbLeft;
end;
LM_MBUTTONUP,LM_MBUTTONDBLCLK,LM_MBUTTONTRIPLECLK,LM_MBUTTONQUADCLK:
begin
Include(Shift,ssMiddle);
Button:=mbMiddle;
end;
LM_RBUTTONUP,LM_RBUTTONDBLCLK,LM_RBUTTONTRIPLECLK,LM_RBUTTONQUADCLK:
begin
Include(Shift,ssRight);
Button:=mbRight;
end;
else
Button:=mbExtra1;
end;
case TheMessage.Msg of
LM_LBUTTONDBLCLK,LM_MBUTTONDBLCLK,LM_RBUTTONDBLCLK:
Include(Shift,ssDouble);
LM_LBUTTONTRIPLECLK,LM_MBUTTONTRIPLECLK,LM_RBUTTONTRIPLECLK:
Include(Shift,ssTriple);
LM_LBUTTONQUADCLK,LM_MBUTTONQUADCLK,LM_RBUTTONQUADCLK:
Include(Shift,ssQuad);
end;
end;
function TDesigner.GetDesignControl(AControl: TControl): TControl; function TDesigner.GetDesignControl(AControl: TControl): TControl;
// checks if AControl is designable. // checks if AControl is designable.
// if not check Owner. // if not check Owner.
@ -1313,6 +1354,8 @@ var
ParentForm: TCustomForm; ParentForm: TCustomForm;
Shift: TShiftState; Shift: TShiftState;
DesignSender: TControl; DesignSender: TControl;
Button: TMouseButton;
Handled: Boolean;
begin begin
FHintTimer.Enabled := False; FHintTimer.Enabled := False;
Exclude(FFLags, dfHasSized); Exclude(FFLags, dfHasSized);
@ -1342,28 +1385,8 @@ begin
end; end;
MouseDownSender := DesignSender; MouseDownSender := DesignSender;
case TheMessage.Msg of GetMouseMsgShift(TheMessage,Shift,Button);
LM_LBUTTONDOWN, LM_MBUTTONDOWN, LM_RBUTTONDOWN: MouseDownShift:=Shift;
MouseDownClickCount := 1;
LM_LBUTTONDBLCLK,LM_MBUTTONDBLCLK,LM_RBUTTONDBLCLK:
MouseDownClickCount := 2;
LM_LBUTTONTRIPLECLK,LM_MBUTTONTRIPLECLK,LM_RBUTTONTRIPLECLK:
MouseDownClickCount := 3;
LM_LBUTTONQUADCLK,LM_MBUTTONQUADCLK,LM_RBUTTONQUADCLK:
MouseDownClickCount := 4;
else
MouseDownClickCount := 1;
end;
Shift := [];
if (TheMessage.keys and MK_Shift) = MK_Shift then
Include(Shift, ssShift);
if (TheMessage.keys and MK_Control) = MK_Control then
Include(Shift, ssCtrl);
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
DebugLn('************************************************************'); DebugLn('************************************************************');
@ -1384,9 +1407,15 @@ begin
DebugLn(', No CTRL down'); DebugLn(', No CTRL down');
{$ENDIF} {$ENDIF}
if Mediator<>nil then begin
Handled:=false;
Mediator.MouseDown(Button,Shift,MouseDownPos,Handled);
if Handled then exit;
end;
SelectedCompClass := GetSelectedComponentClass; SelectedCompClass := GetSelectedComponentClass;
if (TheMessage.Keys and MK_LButton) > 0 then begin if Button=mbLeft then begin
// left button // left button
// -> check if a grabber was activated // -> check if a grabber was activated
ControlSelection.ActiveGrabber:= ControlSelection.ActiveGrabber:=
@ -1460,6 +1489,7 @@ procedure TDesigner.MouseUpOnControl(Sender : TControl;
var var
ParentCI, NewCI: TComponentInterface; ParentCI, NewCI: TComponentInterface;
NewLeft, NewTop, NewWidth, NewHeight: Integer; NewLeft, NewTop, NewWidth, NewHeight: Integer;
Button: TMouseButton;
Shift: TShiftState; Shift: TShiftState;
SenderParentForm: TCustomForm; SenderParentForm: TCustomForm;
RubberBandWasActive: boolean; RubberBandWasActive: boolean;
@ -1468,28 +1498,6 @@ var
SelectionChanged, NewRubberbandSelection: boolean; SelectionChanged, NewRubberbandSelection: boolean;
DesignSender: TControl; DesignSender: TControl;
procedure GetShift;
begin
Shift := [];
if (TheMessage.keys and MK_Shift) = MK_Shift then
Include(Shift,ssShift);
if (TheMessage.keys and MK_Control) = MK_Control then
Include(Shift,ssCtrl);
case TheMessage.Msg of
LM_LBUTTONUP: Include(Shift,ssLeft);
LM_MBUTTONUP: Include(Shift,ssMiddle);
LM_RBUTTONUP: Include(Shift,ssRight);
end;
if MouseDownClickCount=2 then
Include(Shift,ssDouble);
if MouseDownClickCount=3 then
Include(Shift,ssTriple);
if MouseDownClickCount=4 then
Include(Shift,ssQuad);
end;
procedure AddComponent; procedure AddComponent;
var var
NewParent: TComponent; NewParent: TComponent;
@ -1665,7 +1673,7 @@ var
begin begin
// select only the mouse down component // select only the mouse down component
ControlSelection.AssignPersistent(MouseDownComponent); ControlSelection.AssignPersistent(MouseDownComponent);
if (MouseDownClickCount = 2) and (ControlSelection.SelectionForm = Form) then if (ssDouble in MouseDownShift) and (ControlSelection.SelectionForm = Form) then
begin begin
// Double Click -> invoke 'Edit' of the component editor // Double Click -> invoke 'Edit' of the component editor
FShiftState := Shift; FShiftState := Shift;
@ -1682,6 +1690,8 @@ var
end; end;
end; end;
var
Handled: Boolean;
Begin Begin
FHintTimer.Enabled := False; FHintTimer.Enabled := False;
SetCaptureControl(nil); SetCaptureControl(nil);
@ -1705,7 +1715,7 @@ Begin
RubberBandWasActive:=ControlSelection.RubberBandActive; RubberBandWasActive:=ControlSelection.RubberBandActive;
SelectedCompClass:=GetSelectedComponentClass; SelectedCompClass:=GetSelectedComponentClass;
GetShift; GetMouseMsgShift(TheMessage,Shift,Button);
MouseUpPos:=GetFormRelativeMousePosition(Form); MouseUpPos:=GetFormRelativeMousePosition(Form);
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
@ -1716,7 +1726,13 @@ Begin
DebugLn(''); DebugLn('');
{$ENDIF} {$ENDIF}
if TheMessage.Msg=LM_LBUTTONUP then begin if Mediator<>nil then begin
Handled:=false;
Mediator.MouseUp(Button,Shift,MouseUpPos,Handled);
if Handled then exit;
end;
if Button=mbLeft then begin
if SelectedCompClass = nil then begin if SelectedCompClass = nil then begin
// layout mode (selection, moving and resizing) // layout mode (selection, moving and resizing)
if not (dfHasSized in FFlags) then begin if not (dfHasSized in FFlags) then begin
@ -1733,7 +1749,7 @@ Begin
// create new a component on the form // create new a component on the form
AddComponent; AddComponent;
end; end;
end else if TheMessage.Msg=LM_RBUTTONUP then begin end else if Button=mbRight then begin
// right click -> popup menu // right click -> popup menu
DisableRubberBand; DisableRubberBand;
if EnvironmentOptions.RightClickSelects if EnvironmentOptions.RightClickSelects
@ -1763,6 +1779,7 @@ end;
procedure TDesigner.MouseMoveOnControl(Sender: TControl; procedure TDesigner.MouseMoveOnControl(Sender: TControl;
var TheMessage: TLMMouse); var TheMessage: TLMMouse);
var var
Button: TMouseButton;
Shift : TShiftState; Shift : TShiftState;
SenderParentForm:TCustomForm; SenderParentForm:TCustomForm;
OldMouseMovePos: TPoint; OldMouseMovePos: TPoint;
@ -1771,13 +1788,15 @@ var
SelectedCompClass: TRegisteredComponent; SelectedCompClass: TRegisteredComponent;
CurSnappedMousePos, OldSnappedMousePos: TPoint; CurSnappedMousePos, OldSnappedMousePos: TPoint;
DesignSender: TControl; DesignSender: TControl;
Handled: Boolean;
begin begin
GetMouseMsgShift(TheMessage,Shift,Button);
if [dfShowEditorHints]*FFlags<>[] then begin if [dfShowEditorHints]*FFlags<>[] then begin
FHintTimer.Enabled := False; FHintTimer.Enabled := False;
// hide hint // hide hint
FHintTimer.Enabled := FHintTimer.Enabled := Shift*[ssLeft,ssRight,ssMiddle]=[];
(TheMessage.keys or (MK_LButton and MK_RButton and MK_MButton) = 0);
if FHintWindow.Visible then if FHintWindow.Visible then
FHintWindow.Visible := False; FHintWindow.Visible := False;
end; end;
@ -1792,6 +1811,12 @@ begin
if (OldMouseMovePos.X=LastMouseMovePos.X) if (OldMouseMovePos.X=LastMouseMovePos.X)
and (OldMouseMovePos.Y=LastMouseMovePos.Y) then exit; and (OldMouseMovePos.Y=LastMouseMovePos.Y) then exit;
if Mediator<>nil then begin
Handled:=false;
Mediator.MouseMove(Shift,LastMouseMovePos,Handled);
if Handled then exit;
end;
if ControlSelection.SelectionForm=Form then if ControlSelection.SelectionForm=Form then
Grabber:=ControlSelection.GrabberAtPos( Grabber:=ControlSelection.GrabberAtPos(
LastMouseMovePos.X, LastMouseMovePos.Y) LastMouseMovePos.X, LastMouseMovePos.Y)
@ -1812,12 +1837,6 @@ begin
exit; exit;
end; end;
Shift := [];
if (TheMessage.keys and MK_Shift) = MK_Shift then
Include(Shift,ssShift);
if (TheMessage.keys and MK_Control) = MK_Control then
Include(Shift,ssCtrl);
if (ControlSelection.SelectionForm=nil) if (ControlSelection.SelectionForm=nil)
or (ControlSelection.SelectionForm=Form) or (ControlSelection.SelectionForm=Form)
then begin then begin

View File

@ -181,6 +181,13 @@ When you handled a key, set Key:=0.</descr>
<element name="TDesignerMediator.Root"> <element name="TDesignerMediator.Root">
<short>The designed Root component.</short> <short>The designed Root component.</short>
</element> </element>
<element name="TDesignerMediator.MouseDown"/>
<element name="TDesignerMediator.MouseMove">
<short>Called by the IDE before it handles a mouse move message</short>
</element>
<element name="TDesignerMediator.MouseUp">
<short>Called by the IDE before it handles a mouse up message</short>
</element>
</module> </module>
</package> </package>
</fpdoc-descriptions> </fpdoc-descriptions>

View File

@ -119,7 +119,6 @@ type
procedure GetClientArea(AComponent: TComponent; out CurClientArea: TRect; procedure GetClientArea(AComponent: TComponent; out CurClientArea: TRect;
out ScrollOffset: TPoint); virtual; out ScrollOffset: TPoint); virtual;
function GetComponentOriginOnForm(AComponent: TComponent): TPoint; virtual; function GetComponentOriginOnForm(AComponent: TComponent): TPoint; virtual;
procedure Paint; virtual;
function ComponentIsIcon(AComponent: TComponent): boolean; virtual; function ComponentIsIcon(AComponent: TComponent): boolean; virtual;
function ParentAcceptsChild(Parent: TComponent; Child: TComponentClass): boolean; virtual; function ParentAcceptsChild(Parent: TComponent; Child: TComponentClass): boolean; virtual;
function ComponentIsVisible(AComponent: TComponent): Boolean; virtual; function ComponentIsVisible(AComponent: TComponent): Boolean; virtual;
@ -127,9 +126,16 @@ type
function ComponentAtPos(p: TPoint; MinClass: TComponentClass; function ComponentAtPos(p: TPoint; MinClass: TComponentClass;
Flags: TDMCompAtPosFlags): TComponent; virtual; Flags: TDMCompAtPosFlags): TComponent; virtual;
procedure GetChilds(Parent: TComponent; ChildComponents: TFPList); virtual; procedure GetChilds(Parent: TComponent; ChildComponents: TFPList); virtual;
// events
procedure InitComponent(AComponent, NewParent: TComponent; NewBounds: TRect); virtual; procedure InitComponent(AComponent, NewParent: TComponent; NewBounds: TRect); virtual;
procedure Paint; virtual;
procedure KeyDown(Sender: TControl; var Key: word; Shift: TShiftState); virtual; procedure KeyDown(Sender: TControl; var Key: word; Shift: TShiftState); virtual;
procedure KeyUp(Sender: TControl; var Key: word; Shift: TShiftState); virtual; procedure KeyUp(Sender: TControl; var Key: word; Shift: TShiftState); virtual;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; p: TPoint; var Handled: boolean); virtual;
procedure MouseMove(Shift: TShiftState; p: TPoint; var Handled: boolean); virtual;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; p: TPoint; var Handled: boolean); virtual;
property LCLForm: TForm read FLCLForm write SetLCLForm; property LCLForm: TForm read FLCLForm write SetLCLForm;
property Designer: TComponentEditorDesigner read FDesigner write SetDesigner; property Designer: TComponentEditorDesigner read FDesigner write SetDesigner;
property Root: TComponent read FRoot write SetRoot; property Root: TComponent read FRoot write SetRoot;
@ -541,5 +547,23 @@ begin
end; end;
procedure TDesignerMediator.MouseDown(Button: TMouseButton; Shift: TShiftState;
p: TPoint; var Handled: boolean);
begin
end;
procedure TDesignerMediator.MouseMove(Shift: TShiftState; p: TPoint;
var Handled: boolean);
begin
end;
procedure TDesignerMediator.MouseUp(Button: TMouseButton; Shift: TShiftState;
p: TPoint; var Handled: boolean);
begin
end;
end. end.