IDE: fixed painting datamodules

git-svn-id: trunk@23103 -
This commit is contained in:
mattias 2009-12-12 15:51:01 +00:00
parent 6deb52fdc0
commit c64b628c67
3 changed files with 71 additions and 58 deletions

View File

@ -2294,13 +2294,13 @@ var
if not DC.RectVisible(RLeft, RTop, RRight, RBottom) then Exit; if not DC.RectVisible(RLeft, RTop, RRight, RBottom) then Exit;
if not RestoreBrush then if not RestoreBrush then
begin begin
DC.Save; DC.BeginPainting;
RestoreBrush := True;
with DC.Canvas do with DC.Canvas do
begin begin
OldBrushColor := Brush.Color; OldBrushColor := Brush.Color;
Brush.Color := GrabberColor; Brush.Color := GrabberColor;
end; end;
RestoreBrush := True;
end; end;
DC.Canvas.FillRect(Rect(RLeft, RTop, RRight, RBottom)); DC.Canvas.FillRect(Rect(RLeft, RTop, RRight, RBottom));
//DC.Canvas.TextOut(RLeft,RTop,dbgs(ord(g))); //DC.Canvas.TextOut(RLeft,RTop,dbgs(ord(g)));
@ -2327,7 +2327,7 @@ begin
if RestoreBrush then if RestoreBrush then
begin begin
DC.Canvas.Brush.Color:=OldBrushColor; DC.Canvas.Brush.Color:=OldBrushColor;
DC.Restore; DC.EndPainting;
end; end;
end; end;
@ -2342,7 +2342,7 @@ var
if not DC.RectVisible(RLeft, RTop, RRight, RBottom) then exit; if not DC.RectVisible(RLeft, RTop, RRight, RBottom) then exit;
if not RestoreBrush then if not RestoreBrush then
begin begin
DC.Save; DC.BeginPainting;
OldBrushColor:=DC.Canvas.Brush.Color; OldBrushColor:=DC.Canvas.Brush.Color;
DC.Canvas.Brush.Color:=MarkerColor; DC.Canvas.Brush.Color:=MarkerColor;
RestoreBrush := True; RestoreBrush := True;
@ -2360,7 +2360,7 @@ begin
if RestoreBrush then if RestoreBrush then
begin begin
DC.Canvas.Brush.Color:=OldBrushColor; DC.Canvas.Brush.Color:=OldBrushColor;
DC.Restore; DC.EndPainting;
end; end;
end; end;
@ -2465,7 +2465,7 @@ var
begin begin
if not DC.RectVisible(StartX, StartY, EndX, EndY) then exit; if not DC.RectVisible(StartX, StartY, EndX, EndY) then exit;
if not RestorePen then begin if not RestorePen then begin
DC.Save; DC.BeginPainting;
with DC.Canvas do begin with DC.Canvas do begin
OldPenColor:=Pen.Color; OldPenColor:=Pen.Color;
if RubberbandType=rbtSelection then if RubberbandType=rbtSelection then
@ -2499,7 +2499,7 @@ var
if RestorePen then if RestorePen then
begin begin
DC.Canvas.Pen.Color:=OldPenColor; DC.Canvas.Pen.Color:=OldPenColor;
DC.Restore; DC.EndPainting;
Include(FStates,cssRubberbandPainted); Include(FStates,cssRubberbandPainted);
end; end;
end; end;
@ -3109,7 +3109,7 @@ var
if not DC.RectVisible(ARect.Left,ARect.Top,ARect.Right,ARect.Bottom) then if not DC.RectVisible(ARect.Left,ARect.Top,ARect.Right,ARect.Bottom) then
exit; exit;
if not RestorePen then begin if not RestorePen then begin
DC.Save; DC.BeginPainting;
OldPenColor:=DC.Canvas.Pen.Color; OldPenColor:=DC.Canvas.Pen.Color;
RestorePen:=true; RestorePen:=true;
end; end;
@ -3136,7 +3136,6 @@ begin
RestorePen:=false; RestorePen:=false;
DC.Save;
DCOrigin:=DC.FormOrigin; DCOrigin:=DC.FormOrigin;
OldPenColor:=DC.Canvas.Pen.Color; OldPenColor:=DC.Canvas.Pen.Color;
// draw bottom guideline // draw bottom guideline
@ -3160,9 +3159,8 @@ begin
if RestorePen then if RestorePen then
begin begin
DC.Canvas.Pen.Color:=OldPenColor; DC.Canvas.Pen.Color:=OldPenColor;
DC.Restore; DC.EndPainting;
end; end;
DC.Restore;
Include(FStates,cssGuideLinesPainted); Include(FStates,cssGuideLinesPainted);
end; end;

View File

@ -1428,19 +1428,17 @@ begin
end; end;
function TDesigner.NonVisualComponentLeftTop(AComponent: TComponent): TPoint; function TDesigner.NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
var
ParentForm: TPoint;
begin begin
Result.X := LeftFromDesignInfo(AComponent.DesignInfo); Result.X := LeftFromDesignInfo(AComponent.DesignInfo);
Result.Y := TopFromDesignInfo(AComponent.DesignInfo); Result.Y := TopFromDesignInfo(AComponent.DesignInfo);
// convert to lookuproot coords // convert to lookuproot coords
if (AComponent.Owner <> FLookupRoot) and (FLookupRoot is TControl) then if (AComponent.Owner <> FLookupRoot) then
begin begin
AComponent := AComponent.Owner; ParentForm:=GetParentFormRelativeClientOrigin(AComponent.Owner);
if AComponent is TControl then inc(Result.X,ParentForm.X);
with TControl(FLookupRoot).ScreenToClient(TControl(AComponent).ClientToScreen(Point(0, 0))) do inc(Result.Y,ParentForm.Y);
begin
inc(Result.X, X);
inc(Result.Y, Y);
end;
end; end;
end; end;
@ -2683,7 +2681,7 @@ begin
or (not (csAcceptsControls in AWinControl.ControlStyle)) or (not (csAcceptsControls in AWinControl.ControlStyle))
or ((not ShowGrid) and (not ShowBorderSpacing)) then exit; or ((not ShowGrid) and (not ShowBorderSpacing)) then exit;
aDDC.Save; aDDC.BeginPainting;
try try
// exclude all child control areas // exclude all child control areas
Count:=AWinControl.ControlCount; Count:=AWinControl.ControlCount;
@ -2724,7 +2722,7 @@ begin
end; end;
end; end;
finally finally
aDDC.Restore; aDDC.EndPainting;
end; end;
end; end;
@ -2995,19 +2993,45 @@ var
OwnerRect, IconRect, TextRect: TRect; OwnerRect, IconRect, TextRect: TRect;
TextSize: TSize; TextSize: TSize;
IsSelected: Boolean; IsSelected: Boolean;
Root: TComponent;
RGN: HRGN; RGN: HRGN;
begin begin
// also call draw for the inline components children if (AComponent is TControl)
if (csInline in AComponent.ComponentState) or (AComponent.Owner=nil) then and (csNoDesignVisible in TControl(AComponent).ControlStyle) then
Root:=AComponent exit;
else
Root:=AComponent.Owner; // draw children
TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, Root); if (AComponent.Owner=nil) then
begin
FDDC.BeginPainting;
TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, AComponent);
FDDC.EndPainting;
end
else if (csInline in AComponent.ComponentState) then
begin
if AComponent is TControl then
begin
// clip to client area
FDDC.BeginPainting;
FDDC.Canvas.SaveHandleState;
OwnerRect := TControl(AComponent).ClientRect;
GetParentFormRelativeClientOrigin(AComponent);
with OwnerRect do
RGN := CreateRectRGN(Left, Top, Right, Bottom);
SelectClipRGN(FDDC.DC, RGN);
DeleteObject(RGN);
end;
TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, AComponent);
if AComponent is TControl then
begin
FDDC.Canvas.RestoreHandleState;
FDDC.EndPainting;
end;
end else begin
TComponentAccess(AComponent).GetChildren(@DrawNonVisualComponent, AComponent.Owner);
end;
if not ComponentIsIcon(AComponent) or (AComponent.Owner = nil) then if not ComponentIsIcon(AComponent) or (AComponent.Owner = nil) then
Exit; Exit;
if not (AComponent.Owner is TControl) then
Exit;
// actual draw // actual draw
Diff := FDDC.FormOrigin; Diff := FDDC.FormOrigin;
//DebugLn(['FDDC.FormOrigin - ', Diff.X, ' : ' ,Diff.Y]); //DebugLn(['FDDC.FormOrigin - ', Diff.X, ' : ' ,Diff.Y]);
@ -3021,20 +3045,6 @@ begin
Exit; Exit;
IsSelected := ControlSelection.IsSelected(AComponent); IsSelected := ControlSelection.IsSelected(AComponent);
FDDC.Save;
// set clipping
if AComponent.Owner <> FDDC.Form then
begin
OwnerRect := TControl(AComponent.Owner).ClientRect;
Diff := FDDC.Form.ScreenToClient(TControl(AComponent.Owner).ClientToScreen(Point(0, 0)));
OffsetRect(OwnerRect, Diff.X, Diff.Y);
// don't restore later FDDC.Restore will do this itself
with OwnerRect do
RGN := CreateRectRGN(Left, Top, Right, Bottom);
SelectClipRGN(FDDC.DC, RGN);
DeleteObject(RGN);
end;
if FSurface = nil then if FSurface = nil then
begin begin
@ -3051,7 +3061,8 @@ begin
InflateRect(IconRect, -NonVisualCompBorder + 1, -NonVisualCompBorder + 1); InflateRect(IconRect, -NonVisualCompBorder + 1, -NonVisualCompBorder + 1);
// draw component Name // draw component Name
if ShowComponentCaptions and (((GetKeyState(VK_LBUTTON) and $80) = 0) or not IsSelected) then if ShowComponentCaptions
and (((GetKeyState(VK_LBUTTON) and $80) = 0) or not IsSelected) then
begin begin
// workarounds gtk2 problem with DrawText on gc with GDK_INCLUDE_INFERIORS // workarounds gtk2 problem with DrawText on gc with GDK_INCLUDE_INFERIORS
// it uses pango drawing and this for some reason does not take subwindow_mode // it uses pango drawing and this for some reason does not take subwindow_mode
@ -3093,17 +3104,13 @@ begin
if (ControlSelection.Count > 1) and IsSelected then if (ControlSelection.Count > 1) and IsSelected then
ControlSelection.DrawMarkerAt(FDDC, ControlSelection.DrawMarkerAt(FDDC,
ItemLeft, ItemTop, NonVisualCompWidth, NonVisualCompWidth); ItemLeft, ItemTop, NonVisualCompWidth, NonVisualCompWidth);
FDDC.Restore;
end; end;
procedure TDesigner.DrawNonVisualComponents(aDDC: TDesignerDeviceContext); procedure TDesigner.DrawNonVisualComponents(aDDC: TDesignerDeviceContext);
var
i: integer;
begin begin
FSurface := nil; FSurface := nil;
FDDC := aDDC; FDDC := aDDC;
for i := 0 to FLookupRoot.ComponentCount - 1 do DrawNonVisualComponent(FLookupRoot);
DrawNonVisualComponent(FLookupRoot.Components[i]);
FDDC := nil; FDDC := nil;
if FSurface <> nil then if FSurface <> nil then
FSurface.Free; FSurface.Free;
@ -3122,7 +3129,9 @@ begin
//writeln('TDesigner.DrawDesignerItems B painting'); //writeln('TDesigner.DrawDesignerItems B painting');
DesignerDC := GetDesignerDC(Form.Handle); DesignerDC := GetDesignerDC(Form.Handle);
DDC.SetDC(Form, Form, DesignerDC); DDC.SetDC(Form, Form, DesignerDC);
DDC.BeginPainting;
DoPaintDesignerItems; DoPaintDesignerItems;
DDC.EndPainting;
DDC.Clear; DDC.Clear;
ReleaseDesignerDC(Form.Handle, DesignerDC); ReleaseDesignerDC(Form.Handle, DesignerDC);
end; end;

View File

@ -54,9 +54,10 @@ type
FFlags: TDesignerDCFlags; FFlags: TDesignerDCFlags;
FFormClientOrigin: TPoint; // Form client origin on desktop FFormClientOrigin: TPoint; // Form client origin on desktop
FFormOrigin: TPoint; // DC origin relative to designer Form FFormOrigin: TPoint; // DC origin relative to designer Form
FSavedDC: HDC;
FDcSize: TPoint; FDcSize: TPoint;
FForm: TCustomForm; FForm: TCustomForm;
FSavedDC: HDC;
FPaintCount: integer;
function GetDCOrigin: TPoint; function GetDCOrigin: TPoint;
function GetDCSize: TPoint; function GetDCSize: TPoint;
function GetFormClientOrigin: TPoint; function GetFormClientOrigin: TPoint;
@ -66,8 +67,8 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure SetDC(AForm: TCustomForm; ADCControl: TWinControl; ADC: HDC); procedure SetDC(AForm: TCustomForm; ADCControl: TWinControl; ADC: HDC);
procedure Clear; procedure Clear;
procedure Save; procedure BeginPainting;
procedure Restore; procedure EndPainting;
function RectVisible(ALeft, ATop, ARight, ABottom: integer): boolean; function RectVisible(ALeft, ATop, ARight, ABottom: integer): boolean;
property Canvas: TCanvas read FCanvas; property Canvas: TCanvas read FCanvas;
property DC: HDC read FDC; property DC: HDC read FDC;
@ -455,23 +456,28 @@ end;
procedure TDesignerDeviceContext.Clear; procedure TDesignerDeviceContext.Clear;
begin begin
Restore; if (FSavedDC<>0) or (FPaintCount>0) then
RaiseGDBException('');
FDC := 0; FDC := 0;
FFlags := FFlags - [ddcFormOriginValid, ddcFormClientOriginValid, ddcDCOriginValid, ddcSizeValid]; FFlags := FFlags - [ddcFormOriginValid, ddcFormClientOriginValid, ddcDCOriginValid, ddcSizeValid];
end; end;
procedure TDesignerDeviceContext.Save; procedure TDesignerDeviceContext.BeginPainting;
begin begin
if FSavedDC = 0 then if FSavedDC = 0 then
begin begin
FSavedDC := SaveDC(DC); FSavedDC := SaveDC(DC);
FCanvas.Handle := DC; FCanvas.Handle := DC;
end; end;
inc(FPaintCount);
//DebugLn(['TDesignerDeviceContext.BeginPainting ',FPaintCount]);
end; end;
procedure TDesignerDeviceContext.Restore; procedure TDesignerDeviceContext.EndPainting;
begin begin
if FSavedDC <> 0 then //DebugLn(['TDesignerDeviceContext.EndPainting ',FPaintCount]);
dec(FPaintCount);
if (FPaintCount=0) and (FSavedDC <> 0) then
begin begin
FCanvas.Handle := 0; FCanvas.Handle := 0;
RestoreDC(DC, FSavedDC); RestoreDC(DC, FSavedDC);