mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 01:00:26 +02:00
IDE carbon: improved designer drawing
git-svn-id: trunk@14016 -
This commit is contained in:
parent
1760486308
commit
31ca02018a
@ -35,6 +35,10 @@ interface
|
|||||||
{off $DEFINE VerboseDesigner}
|
{off $DEFINE VerboseDesigner}
|
||||||
{off $DEFINE VerboseDesignerDraw}
|
{off $DEFINE VerboseDesignerDraw}
|
||||||
|
|
||||||
|
{$IFDEF LCLCarbon}
|
||||||
|
{$DEFINE CantPaintOnIdle}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Math, LCLProc, LCLType, LResources, LCLIntf, LMessages,
|
Classes, SysUtils, Math, LCLProc, LCLType, LResources, LCLIntf, LMessages,
|
||||||
Forms, Controls, GraphType, Graphics, Dialogs, ExtCtrls, Menus, ClipBrd,
|
Forms, Controls, GraphType, Graphics, Dialogs, ExtCtrls, Menus, ClipBrd,
|
||||||
@ -1160,14 +1164,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
LastPaintSender:=Sender;
|
LastPaintSender:=Sender;
|
||||||
|
|
||||||
|
if IsDesignerDC(Form.Handle, TheMessage.DC) then
|
||||||
|
begin
|
||||||
|
DoPaintDesignerItems;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
// client grid
|
// client grid
|
||||||
if (Sender is TWinControl)
|
if (Sender is TWinControl)
|
||||||
and (csAcceptsControls in Sender.ControlStyle) then begin
|
and (csAcceptsControls in Sender.ControlStyle) then begin
|
||||||
PaintClientGrid(TWinControl(Sender),DDC);
|
PaintClientGrid(TWinControl(Sender),DDC);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFNDEF CantPaintOnIdle}
|
||||||
if not EnvironmentOptions.DesignerPaintLazy then
|
if not EnvironmentOptions.DesignerPaintLazy then
|
||||||
DoPaintDesignerItems;
|
DoPaintDesignerItems;
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
DDC.Clear;
|
DDC.Clear;
|
||||||
@ -2418,9 +2431,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDesigner.DrawDesignerItems(OnlyIfNeeded: boolean);
|
procedure TDesigner.DrawDesignerItems(OnlyIfNeeded: boolean);
|
||||||
|
{$IFNDEF CantPaintOnIdle}
|
||||||
var
|
var
|
||||||
DesignerDC: HDC;
|
DesignerDC: HDC;
|
||||||
|
{$ENDIF}
|
||||||
begin
|
begin
|
||||||
|
{$IFNDEF CantPaintOnIdle}
|
||||||
if OnlyIfNeeded and (not (dfNeedPainting in FFlags)) then exit;
|
if OnlyIfNeeded and (not (dfNeedPainting in FFlags)) then exit;
|
||||||
Exclude(FFlags,dfNeedPainting);
|
Exclude(FFlags,dfNeedPainting);
|
||||||
|
|
||||||
@ -2432,6 +2448,7 @@ begin
|
|||||||
DoPaintDesignerItems;
|
DoPaintDesignerItems;
|
||||||
DDC.Clear;
|
DDC.Clear;
|
||||||
ReleaseDesignerDC(Form.Handle,DesignerDC);
|
ReleaseDesignerDC(Form.Handle,DesignerDC);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDesigner.CheckFormBounds;
|
procedure TDesigner.CheckFormBounds;
|
||||||
|
@ -202,6 +202,23 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: IsDesignerDC
|
||||||
|
Params: WindowHandle - Handle of window
|
||||||
|
DC - Handle of device context
|
||||||
|
Returns: If the device context is designer
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
function TCarbonWidgetSet.IsDesignerDC(WindowHandle: HWND; DC: HDC): Boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
{$IFDEF VerboseLCLIntf}
|
||||||
|
DebugLn('TCarbonWidgetSet.IsDesignerDC Handle: ' + DbgS(WindowHandle), ' DC: ' + DbgS(DC));
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
if not CheckWidget(WindowHandle, 'IsDesignerDC', TCarbonDesignWindow) then Exit;
|
||||||
|
Result := DC = HDC(TCarbonDesignWindow(WindowHandle).GetDesignContext);
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: PromptUser
|
Method: PromptUser
|
||||||
Params: DialogCaption - Dialog caption
|
Params: DialogCaption - Dialog caption
|
||||||
|
@ -43,6 +43,8 @@ function GetLCLOwnerObject(Handle: HWnd): TObject; override;
|
|||||||
|
|
||||||
function IntfSendsUTF8KeyPress: boolean; override;
|
function IntfSendsUTF8KeyPress: boolean; override;
|
||||||
|
|
||||||
|
function IsDesignerDC(WindowHandle: HWND; DC: HDC): Boolean; override;
|
||||||
|
|
||||||
function PromptUser(const DialogCaption : string;
|
function PromptUser(const DialogCaption : string;
|
||||||
const DialogMessage : string;
|
const DialogMessage : string;
|
||||||
DialogType : LongInt;
|
DialogType : LongInt;
|
||||||
|
@ -172,7 +172,6 @@ type
|
|||||||
private
|
private
|
||||||
FDesignControl: HIViewRef;
|
FDesignControl: HIViewRef;
|
||||||
FDesignContext: TCarbonContext;
|
FDesignContext: TCarbonContext;
|
||||||
FDesignBitmap: TCarbonBitmap;
|
|
||||||
procedure BringDesignerToFront;
|
procedure BringDesignerToFront;
|
||||||
protected
|
protected
|
||||||
procedure RegisterEvents; override;
|
procedure RegisterEvents; override;
|
||||||
@ -393,8 +392,7 @@ function CarbonDesign_Draw(ANextHandler: EventHandlerCallRef;
|
|||||||
AWidget: TCarbonWidget): OSStatus; {$IFDEF darwin}mwpascal;{$ENDIF}
|
AWidget: TCarbonWidget): OSStatus; {$IFDEF darwin}mwpascal;{$ENDIF}
|
||||||
var
|
var
|
||||||
ADesignWindow: TCarbonDesignWindow;
|
ADesignWindow: TCarbonDesignWindow;
|
||||||
AContext: TCarbonDeviceContext;
|
AStruct: PPaintStruct;
|
||||||
ABitmap: TCarbonBitmap;
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerbosePaint}
|
{$IFDEF VerbosePaint}
|
||||||
Debugln('CarbonDesign_Draw ', DbgSName(AWidget.LCLObject));
|
Debugln('CarbonDesign_Draw ', DbgSName(AWidget.LCLObject));
|
||||||
@ -402,25 +400,31 @@ begin
|
|||||||
|
|
||||||
ADesignWindow := (AWidget as TCarbonDesignWindow);
|
ADesignWindow := (AWidget as TCarbonDesignWindow);
|
||||||
|
|
||||||
AContext := TCarbonControlContext.Create(AWidget);
|
ADesignWindow.FDesignContext := TCarbonControlContext.Create(ADesignWindow);
|
||||||
try
|
try
|
||||||
// set canvas context
|
// set canvas context
|
||||||
if OSError(
|
if OSError(
|
||||||
GetEventParameter(AEvent, kEventParamCGContextRef, typeCGContextRef, nil,
|
GetEventParameter(AEvent, kEventParamCGContextRef, typeCGContextRef, nil,
|
||||||
SizeOf(CGContextRef), nil, @AContext.CGContext),
|
SizeOf(CGContextRef), nil, @(ADesignWindow.FDesignContext.CGContext)),
|
||||||
'CarbonDesign_Draw', SGetEvent, 'kEventParamCGContextRef') then Exit;
|
'CarbonDesign_Draw', SGetEvent, 'kEventParamCGContextRef') then Exit;
|
||||||
|
|
||||||
// let carbon draw/update
|
// let carbon draw/update
|
||||||
Result := CallNextEventHandler(ANextHandler, AEvent);
|
Result := CallNextEventHandler(ANextHandler, AEvent);
|
||||||
|
|
||||||
// draw designer stuff
|
// draw designer stuff
|
||||||
ABitmap := ADesignWindow.FDesignBitmap;
|
New(AStruct);
|
||||||
if ADesignWindow.FDesignContext <> nil then
|
FillChar(AStruct^, SizeOf(TPaintStruct), 0);
|
||||||
AContext.StretchDraw(0, 0, ABitmap.Width, ABitmap.Height,
|
AStruct^.hdc := HDC(ADesignWindow.FDesignContext);
|
||||||
TCarbonBitmapContext(ADesignWindow.FDesignContext),
|
try
|
||||||
0, 0, ABitmap.Width, ABitmap.Height, nil, 0, 0, SRCCOPY);
|
{$IFDEF VerbosePaint}
|
||||||
|
DebugLn('CarbonDesign_Draw LM_PAINT to ', DbgSName(AWidget.LCLObject));
|
||||||
|
{$ENDIF}
|
||||||
|
LCLSendPaintMsg(AWidget.LCLObject, HDC(ADesignWindow.FDesignContext), AStruct);
|
||||||
finally
|
finally
|
||||||
AContext.Free;
|
Dispose(AStruct);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FreeAndNil(ADesignWindow.FDesignContext);
|
||||||
end;
|
end;
|
||||||
{$IFDEF VerbosePaint}
|
{$IFDEF VerbosePaint}
|
||||||
Debugln('CarbonDesign_Draw end ', DbgSName(AWidget.LCLObject));
|
Debugln('CarbonDesign_Draw end ', DbgSName(AWidget.LCLObject));
|
||||||
@ -504,9 +508,6 @@ begin
|
|||||||
DisposeControl(FDesignControl);
|
DisposeControl(FDesignControl);
|
||||||
|
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
FreeAndNil(FDesignContext);
|
|
||||||
FreeAndNil(FDesignBitmap);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -560,29 +561,9 @@ end;
|
|||||||
Returns: Context for drawing designer stuff
|
Returns: Context for drawing designer stuff
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCarbonDesignWindow.GetDesignContext: TCarbonContext;
|
function TCarbonDesignWindow.GetDesignContext: TCarbonContext;
|
||||||
var
|
|
||||||
R: TRect;
|
|
||||||
begin
|
begin
|
||||||
GetClientRect(R);
|
if FDesignContext <> nil then Result := FDesignContext
|
||||||
OffsetRect(R, -R.Left, -R.Top);
|
else Result := DefaultContext;
|
||||||
|
|
||||||
if FDesignBitmap <> nil then
|
|
||||||
if (R.Right - R.Left = FDesignBitmap.Width) and (R.Bottom - R.Top = FDesignBitmap.Height) then
|
|
||||||
begin
|
|
||||||
// the designer area has not been resized - clear it only
|
|
||||||
CGContextClearRect(FDesignContext.CGContext, RectToCGRect(R));
|
|
||||||
Result := FDesignContext;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
FreeAndNil(FDesignContext);
|
|
||||||
FreeAndNil(FDesignBitmap);
|
|
||||||
|
|
||||||
FDesignContext := TCarbonBitmapContext.Create;
|
|
||||||
FDesignBitmap := TCarbonBitmap.Create(R.Right - R.Left, R.Bottom - R.Top, 32, 32, cbaDQWord, cbtARGB, nil);
|
|
||||||
(FDesignContext as TCarbonBitmapContext).Bitmap := FDesignBitmap;
|
|
||||||
|
|
||||||
Result := FDesignContext;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -592,8 +573,7 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TCarbonDesignWindow.ReleaseDesignContext;
|
procedure TCarbonDesignWindow.ReleaseDesignContext;
|
||||||
begin
|
begin
|
||||||
// redraw designer
|
// nothing
|
||||||
Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCarbonCustomControl }
|
{ TCarbonCustomControl }
|
||||||
|
@ -606,6 +606,7 @@ end;
|
|||||||
procedure TCarbonControl.Invalidate(Rect: PRect);
|
procedure TCarbonControl.Invalidate(Rect: PRect);
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
if Rect = nil then
|
if Rect = nil then
|
||||||
begin
|
begin
|
||||||
@ -614,9 +615,13 @@ begin
|
|||||||
HiViewSetNeedsDisplay(Frames[I], True), Self, SInvalidate, SViewNeedsDisplay);
|
HiViewSetNeedsDisplay(Frames[I], True), Self, SInvalidate, SViewNeedsDisplay);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
|
R := Rect^;
|
||||||
|
InflateRect(R, 1, 1);
|
||||||
OSError(
|
OSError(
|
||||||
HiViewSetNeedsDisplayInRect(Content, RectToCGRect(Rect^), True), Self,
|
HiViewSetNeedsDisplayInRect(Content, RectToCGRect(R), True), Self,
|
||||||
SInvalidate, SViewNeedsDisplayRect);
|
SInvalidate, SViewNeedsDisplayRect);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
@ -1124,14 +1124,20 @@ end;
|
|||||||
Invalidates the specified rect or entire area of window content
|
Invalidates the specified rect or entire area of window content
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TCarbonWindow.Invalidate(Rect: PRect);
|
procedure TCarbonWindow.Invalidate(Rect: PRect);
|
||||||
|
var
|
||||||
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
if Rect = nil then
|
if Rect = nil then
|
||||||
OSError(HiViewSetNeedsDisplay(HIViewRef(Content), True), Self, SInvalidate,
|
OSError(HiViewSetNeedsDisplay(HIViewRef(Content), True), Self, SInvalidate,
|
||||||
SViewNeedsDisplay)
|
SViewNeedsDisplay)
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
|
R := Rect^;
|
||||||
|
InflateRect(R, 1, 1);
|
||||||
OSError(
|
OSError(
|
||||||
HiViewSetNeedsDisplayInRect(HIViewRef(Content), RectToCGRect(Rect^), True),
|
HiViewSetNeedsDisplayInRect(HIViewRef(Content), RectToCGRect(R), True),
|
||||||
Self, SInvalidate, SViewNeedsDisplayRect);
|
Self, SInvalidate, SViewNeedsDisplayRect);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user