improved designer rubberband

git-svn-id: trunk@3652 -
This commit is contained in:
mattias 2002-11-18 17:06:29 +00:00
parent 860db3b542
commit aeec2f84b0
3 changed files with 63 additions and 14 deletions

View File

@ -332,7 +332,8 @@ type
property RubberbandActive: boolean read FRubberbandActive write FRubberbandActive; property RubberbandActive: boolean read FRubberbandActive write FRubberbandActive;
procedure DrawRubberband(DC: TDesignerDeviceContext); procedure DrawRubberband(DC: TDesignerDeviceContext);
procedure SelectWithRubberBand(ACustomForm:TCustomForm; procedure SelectWithRubberBand(ACustomForm:TCustomForm;
ClearBefore, ExclusiveOr: boolean; var SelectionChanged: boolean); ClearBefore, ExclusiveOr: boolean; var SelectionChanged: boolean;
MaxParentControl: TControl);
procedure Sort(SortProc: TSelectionSortCompare); procedure Sort(SortProc: TSelectionSortCompare);
property Visible:boolean read FVisible write SetVisible; property Visible:boolean read FVisible write SetVisible;
@ -778,7 +779,7 @@ begin
Result:=false; Result:=false;
if AComponent=nil then exit; if AComponent=nil then exit;
if AComponent is TControl then begin if AComponent is TControl then begin
if csNoDesignVisible in TControl(AComponent).ControlStyle then exit; if not ControlIsDesignerVisible(TControl(AComponent)) then exit;
if Count>0 then begin if Count>0 then begin
if OnlyNonVisualComponentsSelected then exit; if OnlyNonVisualComponentsSelected then exit;
end; end;
@ -1643,26 +1644,26 @@ var
// DrawRubberband // DrawRubberband
begin begin
if (FCustomForm=nil) then exit;
Diff:=DC.FormOrigin; Diff:=DC.FormOrigin;
with FRubberBandBounds do with FRubberBandBounds do
DrawInvertFrameRect(Left-Diff.X,Top-Diff.Y,Right-Diff.X,Bottom-Diff.Y); DrawInvertFrameRect(Left-Diff.X,Top-Diff.Y,Right-Diff.X,Bottom-Diff.Y);
end; end;
procedure TControlSelection.SelectWithRubberBand(ACustomForm:TCustomForm; procedure TControlSelection.SelectWithRubberBand(ACustomForm:TCustomForm;
ClearBefore, ExclusiveOr:boolean; var SelectionChanged: boolean); ClearBefore, ExclusiveOr:boolean; var SelectionChanged: boolean;
MaxParentControl: TControl);
var i:integer; var i:integer;
function ControlInRubberBand(AComponent:TComponent):boolean; function ControlInRubberBand(AComponent:TComponent):boolean;
var ALeft,ATop,ARight,ABottom:integer; var ALeft,ATop,ARight,ABottom:integer;
Origin:TPoint; Origin:TPoint;
begin begin
if (AComponent is TMenuItem)
or ((AComponent is TControl)
and (csNoDesignVisible in TControl(AComponent).ControlStyle))
then begin
Result:=false; Result:=false;
exit; if (AComponent is TMenuItem) then exit;
if (AComponent is TControl) then begin
if not ControlIsDesignerVisible(TControl(AComponent)) then exit;
if (MaxParentControl<>nil)
and (not MaxParentControl.IsParentOf(TControl(AComponent))) then exit;
end; end;
Origin:=GetParentFormRelativeTopLeft(AComponent); Origin:=GetParentFormRelativeTopLeft(AComponent);
ALeft:=Origin.X; ALeft:=Origin.X;

View File

@ -96,6 +96,8 @@ function GetComponentHeight(AComponent: TComponent): integer;
function GetParentLevel(AControl: TControl): integer; function GetParentLevel(AControl: TControl): integer;
function ControlIsDesignerVisible(AControl: TControl): boolean;
implementation implementation
@ -254,6 +256,18 @@ begin
end; end;
end; end;
function ControlIsDesignerVisible(AControl: TControl): boolean;
begin
Result:=true;
while AControl<>nil do begin
if csNoDesignVisible in AControl.ControlStyle then begin
Result:=false;
exit;
end;
AControl:=AControl.Parent;
end;
end;
{ TDesignerDeviceContext } { TDesignerDeviceContext }

View File

@ -217,9 +217,8 @@ begin
APage.Parent := fNotebook; APage.Parent := fNotebook;
if NewZPosition>=0 then if NewZPosition>=0 then
fNoteBook.SetControlIndex(APage,NewZPosition); fNoteBook.SetControlIndex(APage,NewZPosition);
// this is workaround til visible=true is default in TControl
APage.Visible:=true; APage.Visible:=true;
fNoteBook.UpdateDesignerFlags(Index);
if FNoteBook.HandleAllocated if FNoteBook.HandleAllocated
and (not (csLoading in FNoteBook.ComponentState)) and (not (csLoading in FNoteBook.ComponentState))
@ -462,6 +461,7 @@ procedure TCustomNotebook.SetPageIndex(Value: Integer);
begin begin
if fPageIndex = Value then exit; if fPageIndex = Value then exit;
fPageIndex := Value; fPageIndex := Value;
UpdateAllDesignerFlags;
DoSendPageIndex; DoSendPageIndex;
end; end;
@ -473,6 +473,9 @@ begin
Result := fPageIndex; Result := fPageIndex;
end; end;
{------------------------------------------------------------------------------
function TCustomNotebook.IsStoredActivePage: boolean;
------------------------------------------------------------------------------}
function TCustomNotebook.IsStoredActivePage: boolean; function TCustomNotebook.IsStoredActivePage: boolean;
begin begin
Result:=false; Result:=false;
@ -524,6 +527,30 @@ begin
DoSendTabPosition; DoSendTabPosition;
end; end;
{------------------------------------------------------------------------------
procedure TCustomNotebook.UpdateAllDesignerFlags;
------------------------------------------------------------------------------}
procedure TCustomNotebook.UpdateAllDesignerFlags;
var
i: integer;
begin
for i:=0 to PageCount-1 do
UpdateDesignerFlags(i);
end;
{------------------------------------------------------------------------------
procedure TCustomNotebook.UpdateDesignerFlags(APageIndex: integer);
------------------------------------------------------------------------------}
procedure TCustomNotebook.UpdateDesignerFlags(APageIndex: integer);
begin
if APageIndex<>fPageIndex then
Page[APageIndex].ControlStyle:=
Page[APageIndex].ControlStyle+[csNoDesignVisible]
else
Page[APageIndex].ControlStyle:=
Page[APageIndex].ControlStyle-[csNoDesignVisible];
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TCustomNotebook CreateParams TCustomNotebook CreateParams
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -606,6 +633,7 @@ Begin
FPageIndex := NMHDR^.idfrom; FPageIndex := NMHDR^.idfrom;
if FPageIndex>=PageCount then if FPageIndex>=PageCount then
FPageIndex:=-1; FPageIndex:=-1;
UpdateAllDesignerFlags;
Change; Change;
if csDesigning in ComponentState then if csDesigning in ComponentState then
OwnerFormDesignerModified(Self); OwnerFormDesignerModified(Self);
@ -630,8 +658,11 @@ begin
if not HandleAllocated or (csLoading in ComponentState) then exit; if not HandleAllocated or (csLoading in ComponentState) then exit;
Msg.Parent := Self; Msg.Parent := Self;
Msg.fCompStyle := fCompStyle; Msg.fCompStyle := fCompStyle;
if (FPageIndex<0) and (PageCount>0) then fPageIndex:=0; if (FPageIndex<0) and (PageCount>0) then begin
Msg.Page := FPageIndex; fPageIndex:=0;
UpdateAllDesignerFlags;
end;
Msg.Page := fPageIndex;
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TCustomNotebook.DoSendPageIndex] A ',Name,' PageIndex=',fPageIndex); writeln('[TCustomNotebook.DoSendPageIndex] A ',Name,' PageIndex=',fPageIndex);
{$ENDIF} {$ENDIF}
@ -703,6 +734,9 @@ end;}
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.27 2002/11/18 17:06:29 mattias
improved designer rubberband
Revision 1.26 2002/11/18 13:38:44 mattias Revision 1.26 2002/11/18 13:38:44 mattias
fixed buffer overrun and added several checks fixed buffer overrun and added several checks