View Issue Details

IDProjectCategoryView StatusLast Update
0036463PatchesWidgetsetpublic2019-12-22 11:38
ReporterCudaText man Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionreopened 
Product Version2.1 (SVN) 
Summary0036463: gtk3: Simplify a little
DescriptionPatch removes several getters/setters because they were trivial.
TagsNo tags attached.
Fixed in Revisionr62428, r62429
LazTarget-
WidgetsetGTK 3
Attached Files

Activities

CudaText man

2019-12-21 01:04

reporter  

si1.diff (6,501 bytes)   
Index: lcl/interfaces/gtk3/gtk3objects.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3objects.pas	(revision 62426)
+++ lcl/interfaces/gtk3/gtk3objects.pas	(working copy)
@@ -193,15 +193,8 @@
     FvClipRect: TRect;
     FCurrentPen: TGtk3Pen;
     FBkMode: Integer;
-    function GetBkMode: Integer;
-    function getBrush: TGtk3Brush;
-    function GetFont: TGtk3Font;
     function GetOffset: TPoint;
-    function getPen: TGtk3Pen;
-    function GetvImage: TGtk3Image;
-    procedure SetBkMode(AValue: Integer);
     procedure setBrush(AValue: TGtk3Brush);
-    procedure SetCurrentTextColor(AValue: TColorRef);
     procedure SetFont(AValue: TGtk3Font);
     procedure SetOffset(AValue: TPoint);
     procedure setPen(AValue: TGtk3Pen);
@@ -260,29 +253,25 @@
     function MoveTo(const X, Y: Integer; OldPoint: PPoint): Boolean;
     function SetClipRegion(ARgn: TGtk3Region): Integer;
     procedure SetSourceColor(AColor: TColor);
-    procedure SetCurrentBrush(ABrush: TGtk3Brush);
-    procedure SetCurrentFont(AFont: TGtk3Font);
-    procedure SetCurrentPen(APen: TGtk3Pen);
-    procedure SetCurrentImage(AImage: TGtk3Image);
     procedure SetImage(AImage: TGtk3Image);
     function ResetClip: Integer;
     procedure TranslateCairoToDevice;
     procedure Translate(APoint: TPoint);
-    property BkMode: Integer read GetBkMode write SetBkMode;
+    property BkMode: Integer read FBkMode write FBkMode;
     property CanRelease: Boolean read FCanRelease write FCanRelease;
-    property CurrentBrush: TGtk3Brush read FCurrentBrush;
-    property CurrentFont: TGtk3Font read FCurrentFont;
-    property CurrentImage: TGtk3Image read FCurrentImage;
-    property CurrentPen: TGtk3Pen read FCurrentPen;
+    property CurrentBrush: TGtk3Brush read FCurrentBrush write FCurrentBrush;
+    property CurrentFont: TGtk3Font read FCurrentFont write FCurrentFont;
+    property CurrentImage: TGtk3Image read FCurrentImage write FCurrentImage;
+    property CurrentPen: TGtk3Pen read FCurrentPen write FCurrentPen;
     property CurrentRegion: TGtk3Region read FCurrentRegion;
-    property CurrentTextColor: TColorRef read FCurrentTextColor write SetCurrentTextColor;
+    property CurrentTextColor: TColorRef read FCurrentTextColor write FCurrentTextColor;
     property Offset: TPoint read GetOffset write SetOffset;
     property OwnsSurface: Boolean read FOwnsSurface;
-    property vBrush: TGtk3Brush read getBrush write setBrush;
+    property vBrush: TGtk3Brush read FBrush write setBrush;
     property vClipRect: TRect read FvClipRect write FvClipRect;
-    property vFont: TGtk3Font read GetFont write SetFont;
-    property vImage: TGtk3Image read GetvImage write SetvImage;
-    property vPen: TGtk3Pen read getPen write setPen;
+    property vFont: TGtk3Font read FFont write SetFont;
+    property vImage: TGtk3Image read FvImage write SetvImage;
+    property vPen: TGtk3Pen read FPen write setPen;
   end;
 
 function CheckBitmap(const ABitmap: HBITMAP; const AMethodName: String;
@@ -934,21 +923,6 @@
 
 { TGtk3DeviceContext }
 
-function TGtk3DeviceContext.getBrush: TGtk3Brush;
-begin
-  Result := FBrush;
-end;
-
-function TGtk3DeviceContext.GetBkMode: Integer;
-begin
-  Result := FBkMode;
-end;
-
-function TGtk3DeviceContext.GetFont: TGtk3Font;
-begin
-  Result := FFont;
-end;
-
 function TGtk3DeviceContext.GetOffset: TPoint;
 var
   dx,dy: Double;
@@ -957,21 +931,6 @@
   Result := Point(Round(dx), Round(dy));
 end;
 
-function TGtk3DeviceContext.getPen: TGtk3Pen;
-begin
-  Result := FPen;
-end;
-
-function TGtk3DeviceContext.GetvImage: TGtk3Image;
-begin
-  Result := FvImage;
-end;
-
-procedure TGtk3DeviceContext.SetBkMode(AValue: Integer);
-begin
-  FBkMode := AValue;
-end;
-
 procedure TGtk3DeviceContext.setBrush(AValue: TGtk3Brush);
 begin
   if Assigned(FBrush) then
@@ -979,12 +938,6 @@
   FBrush := AValue;
 end;
 
-procedure TGtk3DeviceContext.SetCurrentTextColor(AValue: TColorRef);
-begin
-  if FCurrentTextColor=AValue then Exit;
-  FCurrentTextColor:=AValue;
-end;
-
 procedure TGtk3DeviceContext.SetFont(AValue: TGtk3Font);
 begin
   if Assigned(FFont) then
@@ -1053,7 +1006,6 @@
     AFont := FCurrentFont
   else
     AFont := FFont;
-
 end;
 
 procedure TGtk3DeviceContext.ApplyPen;
@@ -1702,7 +1654,7 @@
     begin
       ATempBrush := FCurrentBrush;
       fBkMode := OPAQUE;
-      SetCurrentBrush(TGtk3Brush(ABrush));
+      CurrentBrush:= TGtk3Brush(ABrush);
     end;
 
     applyBrush;
@@ -1715,7 +1667,7 @@
     cairo_stroke(Widget);
 
     if ABrush <> 0 then
-      SetCurrentBrush(ATempBrush);
+      CurrentBrush:= ATempBrush;
   finally
     cairo_restore(Widget);
   end;
@@ -1924,26 +1876,6 @@
   cairo_set_source_rgb(Widget, R, G, B);
 end;
 
-procedure TGtk3DeviceContext.SetCurrentBrush(ABrush: TGtk3Brush);
-begin
-  FCurrentBrush := ABrush;
-end;
-
-procedure TGtk3DeviceContext.SetCurrentFont(AFont: TGtk3Font);
-begin
-  FCurrentFont := AFont;
-end;
-
-procedure TGtk3DeviceContext.SetCurrentPen(APen: TGtk3Pen);
-begin
-  FCurrentPen := APen;
-end;
-
-procedure TGtk3DeviceContext.SetCurrentImage(AImage: TGtk3Image);
-begin
-  FCurrentImage := AImage;
-end;
-
 procedure TGtk3DeviceContext.SetImage(AImage: TGtk3Image);
 var
   APixBuf: PGdkPixbuf;
Index: lcl/interfaces/gtk3/gtk3winapi.inc
===================================================================
--- lcl/interfaces/gtk3/gtk3winapi.inc	(revision 62426)
+++ lcl/interfaces/gtk3/gtk3winapi.inc	(working copy)
@@ -3481,18 +3481,18 @@
     begin
       // DebugLn('TGtk3WidgetSet.SelectObject PEN ');
       Result := HGDIOBJ(TGtk3DeviceContext(DC).CurrentPen);
-      TGtk3DeviceContext(DC).SetCurrentPen(TGtk3Pen(GDIObj));
+      TGtk3DeviceContext(DC).CurrentPen:= TGtk3Pen(GDIObj);
     end else
     if TObject(GDIObj) is TGtk3Brush then
     begin
       Result := HGDIOBJ(TGtk3DeviceContext(DC).CurrentBrush);
       // DebugLn('TGtk3WidgetSet.SelectObject BRUSH ',dbgHex(Result),'  ',TimeToStr(Now()));
-      TGtk3DeviceContext(DC).SetCurrentBrush(TGtk3Brush(GDIObj));
+      TGtk3DeviceContext(DC).CurrentBrush:= TGtk3Brush(GDIObj);
     end else
     if TObject(GDIObj) is TGtk3Font then
     begin
       Result := HGDIOBJ(TGtk3DeviceContext(DC).CurrentFont);
-      TGtk3DeviceContext(DC).SetCurrentFont(TGtk3Font(GDIObj));
+      TGtk3DeviceContext(DC).CurrentFont:= TGtk3Font(GDIObj);
       // DebugLn('TGtk3WidgetSet.SelectObject Font ');
     end else
     if TObject(GDIObj) is TGtk3Region then
si1.diff (6,501 bytes)   

Anton Kavalenka

2019-12-21 08:01

reporter   ~0119986

if TObject(GDIObj) is TGtk3Brush then
     begin
....
if TObject(GDIObj) is TGtk3Font then
     begin

is a general OOP paradigm violation.
Should be virtual method TGdiObject.ApplyToDc(ADC:TGtk3DeviceContext) with different implementations for Pen,Brush and Font

Juha Manninen

2019-12-21 10:06

developer   ~0119987

Applied, thanks.
The semantics of the "Current..." properties was changes a little. They used to be read-only. The associated values were set by separate procedures. However it is logical to turn them into read-write properties because apparently the values must be changed from outside.

Juha Manninen

2019-12-21 10:10

developer   ~0119988

Sorry, I saw Anton Kavalenka's note only now. How is it related to this issue? The patch did not add any
 if TObject(GDIObj) is TGtk3Brush then ...
tests or similar.

CudaText man

2019-12-21 13:13

reporter   ~0119991

Next patch, si2.diff, does the same.

Anton's note-- i made a patch according to it, then my Canvas Figures demo painted empty panel... something wrong i did. i reverted my change.
si2.diff (5,973 bytes)   
Index: lcl/interfaces/gtk3/gtk3lclintf.inc
===================================================================
--- lcl/interfaces/gtk3/gtk3lclintf.inc	(revision 62428)
+++ lcl/interfaces/gtk3/gtk3lclintf.inc	(working copy)
@@ -276,7 +276,7 @@
   ADesc.LineOrder := riloTopToBottom;
   ADesc.LineEnd := rileDWordBoundary;
 
-  ADesc.Depth := CairoImageFormatToDepth[Image.getFormat];
+  ADesc.Depth := CairoImageFormatToDepth[Image.Format];
   ADesc.BitsPerPixel := ADesc.Depth;
   if ADesc.BitsPerPixel = 24 then
     ADesc.BitsPerPixel := 32;
Index: lcl/interfaces/gtk3/gtk3objects.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3objects.pas	(revision 62428)
+++ lcl/interfaces/gtk3/gtk3objects.pas	(working copy)
@@ -59,13 +59,12 @@
     FLogFont: TLogFont;
     FFontName: String;
     FHandle: PPangoFontDescription;
-    procedure SetFontName(const AValue: String);
   public
     constructor Create(ACairo: Pcairo_t; AWidget: PGtkWidget = nil);
     constructor Create(ALogFont: TLogFont; const ALongFontName: String);
     destructor Destroy; override;
     procedure UpdateLogFont;
-    property FontName: String read FFontName write SetFontName;
+    property FontName: String read FFontName write FFontName;
     property Handle: PPangoFontDescription read FHandle;
     property Layout: PPangoLayout read FLayout;
     property LogFont: TLogFont read FLogFont;
@@ -78,15 +77,13 @@
     FColor: TColor;
     FContext: TGtk3DeviceContext;
     FStyle: LongWord;
-    function GetColor: TColor;
     procedure SetColor(AValue: TColor);
-    procedure SetStyle(AValue: cardinal);
   public
     LogBrush: TLogBrush;
     constructor Create; override;
-    property Color: TColor read GetColor write SetColor;
+    property Color: TColor read FColor write SetColor;
     property Context: TGtk3DeviceContext read FContext write FContext;
-    property Style: LongWord read FStyle write SetStyle;
+    property Style: LongWord read FStyle write FStyle;
   end;
 
   { TGtk3Pen }
@@ -102,28 +99,22 @@
     FColor: TColor;
     FContext: TGtk3DeviceContext;
     FIsExtPen: Boolean;
-    function GetColor: TColor;
-    function GetWidth: Integer;
     procedure SetColor(AValue: TColor);
     procedure setCosmetic(b: Boolean);
-    procedure SetEndCap(AValue: TPenEndCap);
-    procedure SetJoinStyle(AValue: TPenJoinStyle);
-    procedure SetPenMode(AValue: TPenMode);
-    procedure SetStyle(AValue: TFPPenStyle);
     procedure setWidth(p1: Integer);
   public
     LogPen: TLogPen;
     constructor Create; override;
-    property Color: TColor read GetColor write SetColor;
+    property Color: TColor read FColor write SetColor;
     property Context: TGtk3DeviceContext read FContext write FContext;
 
     property Cosmetic: Boolean read FCosmetic write SetCosmetic;
-    property EndCap: TPenEndCap read FEndCap write SetEndCap;
+    property EndCap: TPenEndCap read FEndCap write FEndCap;
     property IsExtPen: Boolean read FIsExtPen write FIsExtPen;
-    property JoinStyle: TPenJoinStyle read FJoinStyle write SetJoinStyle;
-    property Mode: TPenMode read FPenMode write SetPenMode;
-    property Style: TFPPenStyle read FStyle write SetStyle;
-    property Width: Integer read GetWidth write SetWidth;
+    property JoinStyle: TPenJoinStyle read FJoinStyle write FJoinStyle;
+    property Mode: TPenMode read FPenMode write FPenMode;
+    property Style: TFPPenStyle read FStyle write FStyle;
+    property Width: Integer read FWidth write SetWidth;
   end;
 
   { TGtk3Region }
@@ -164,7 +155,7 @@
     function bits: PByte;
     function numBytes: LongWord;
     function bytesPerLine: Integer;
-    function getFormat: cairo_format_t;
+    property Format: cairo_format_t read FFormat;
     property Handle: PGdkPixbuf read FHandle;
   end;
 
@@ -418,12 +409,6 @@
 
 { TGtk3Font }
 
-procedure TGtk3Font.SetFontName(const AValue: String);
-begin
-  if FFontName=AValue then Exit;
-  FFontName:=AValue;
-end;
-
 procedure TGtk3Font.UpdateLogFont;
 var
   sz:integer;
@@ -806,23 +791,8 @@
   Result := FHandle^.rowstride;
 end;
 
-function TGtk3Image.getFormat: cairo_format_t;
-begin
-  Result := FFormat;
-end;
-
 { TGtk3Pen }
 
-function TGtk3Pen.GetColor: TColor;
-begin
-  Result := FColor;
-end;
-
-function TGtk3Pen.GetWidth: Integer;
-begin
-  Result := FWidth;
-end;
-
 procedure TGtk3Pen.SetColor(AValue: TColor);
 var
   ARed, AGreen, ABlue: Double;
@@ -833,27 +803,6 @@
     cairo_set_source_rgb(FContext.Widget, ARed, AGreen, ABlue);
 end;
 
-procedure TGtk3Pen.SetEndCap(AValue: TPenEndCap);
-begin
-  FEndCap := AValue;
-end;
-
-procedure TGtk3Pen.SetJoinStyle(AValue: TPenJoinStyle);
-begin
-  FJoinStyle:=AValue;
-end;
-
-procedure TGtk3Pen.SetPenMode(AValue: TPenMode);
-begin
-  if FPenMode=AValue then Exit;
-  FPenMode:=AValue;
-end;
-
-procedure TGtk3Pen.SetStyle(AValue: TFPPenStyle);
-begin
-  FStyle := AValue;
-end;
-
 constructor TGtk3Pen.Create;
 begin
   inherited Create;
@@ -890,11 +839,6 @@
 
 { TGtk3Brush }
 
-function TGtk3Brush.GetColor: TColor;
-begin
-  Result := FColor;
-end;
-
 procedure TGtk3Brush.SetColor(AValue: TColor);
 var
   ARed, AGreen, ABlue: Double;
@@ -905,12 +849,6 @@
     cairo_set_source_rgb(FContext.Widget, ARed, AGreen, ABlue);
 end;
 
-procedure TGtk3Brush.SetStyle(AValue: cardinal);
-begin
-  if FStyle=AValue then Exit;
-  FStyle:=AValue;
-end;
-
 constructor TGtk3Brush.Create;
 begin
   inherited Create;
@@ -1897,7 +1835,7 @@
   if FOwnsSurface and (CairoSurface <> nil) then
     cairo_surface_destroy(CairoSurface);
   CairoSurface := cairo_image_surface_create_for_data(APixBuf^.pixels,
-                                                AImage.getFormat,
+                                                AImage.Format,
                                                 APixBuf^.get_width,
                                                 APixBuf^.get_height,
                                                 APixBuf^.rowstride);
si2.diff (5,973 bytes)   

Juha Manninen

2019-12-22 11:38

developer   ~0120011

Applied the latest patch. Thanks.

Issue History

Date Modified Username Field Change
2019-12-21 01:04 CudaText man New Issue
2019-12-21 01:04 CudaText man File Added: si1.diff
2019-12-21 08:01 Anton Kavalenka Note Added: 0119986
2019-12-21 09:54 Juha Manninen Assigned To => Juha Manninen
2019-12-21 09:54 Juha Manninen Status new => assigned
2019-12-21 10:06 Juha Manninen Status assigned => resolved
2019-12-21 10:06 Juha Manninen Resolution open => fixed
2019-12-21 10:06 Juha Manninen Fixed in Revision => r62428
2019-12-21 10:06 Juha Manninen LazTarget => -
2019-12-21 10:06 Juha Manninen Widgetset GTK 3 => GTK 3
2019-12-21 10:06 Juha Manninen Note Added: 0119987
2019-12-21 10:10 Juha Manninen Status resolved => assigned
2019-12-21 10:10 Juha Manninen Resolution fixed => reopened
2019-12-21 10:10 Juha Manninen Note Added: 0119988
2019-12-21 13:13 CudaText man File Added: si2.diff
2019-12-21 13:13 CudaText man Note Added: 0119991
2019-12-22 11:38 Juha Manninen Status assigned => resolved
2019-12-22 11:38 Juha Manninen Fixed in Revision r62428 => r62428, r62429
2019-12-22 11:38 Juha Manninen Widgetset GTK 3 => GTK 3
2019-12-22 11:38 Juha Manninen Note Added: 0120011