Forum > LCL

[CLOSED] Code cleanup in gtk widgetsets

(1/1)

lagprogramming:
The gtk2 and gtk3 widgetsets contain some useless result assignments. I have doubts they increase code readability.
Check out the following routines.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGtk2WidgetSet.FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool;var  GtkDC: Integer;  OldRgn: PGdkRegion;  DevCtx: TGtkDeviceContext absolute DC;  ARect: TRect;  CRect : TGDKRectangle;  hasClipping: Boolean;begin   Result := IsValidDC(DC) and IsValidGDIObject(hbr) and IsValidGDIObject(RegionHnd);  if not Result then Exit;  GtkDC := SaveDC(DC);  if (DevCtx.ClipRegion <> nil) and (DevCtx.ClipRegion^.GDIRegionObject <> nil) then    OldRgn := gdk_region_copy(DevCtx.ClipRegion^.GDIRegionObject)  else    OldRgn := nil;  hasClipping := Assigned(OldRgn);  try    if SelectClipRGN(DC, RegionHnd) <> ERROR then    begin      gdk_region_get_clipbox({%H-}PGDIObject(RegionHnd)^.GDIRegionObject, @CRect);      ARect := RectFromGdkRect(CRect);      DevCtx.FillRect(ARect, hbr, True);      // revert clip (whatever it is - null or valid region)      SelectClipRGN(DC, {%H-}HRGN(OldRgn));      Result := True;    end;  finally    if hasClipping then      gdk_region_destroy(OldRgn);    RestoreDC(DC, GtkDC);  end;end;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGtk3WidgetSet.SetForegroundWindow(hWnd: HWND): boolean;var  AWindow: TGtk3Window;begin  {$IFDEF GTK3DEBUGNOTIMPLEMENTED}  // DebugLn('WARNING: TGtk3WidgetSet.SetForegroundWindow not implemented ...');  {$ENDIF}  if not IsValidHandle(HWnd) then    exit(False);  Result := wtWindow in TGtk3Widget(HWND).WidgetType;  if Result then  begin    AWindow := TGtk3Window(HWND);    if not AWindow.Visible then      exit(False);    // DebugLn('TGtk3WidgetSet.SetForegroundWindow ',dbgsName(AWindow.LCLObject));    AWindow.Activate;    Result := True;  end;end; 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGtk3WidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;begin  {$IFDEF GTK3DEBUGNOTIMPLEMENTED}  DebugLn('WARNING: TGtk3WidgetSet.ShowWindow not implemented ...');  {$ENDIF}  Result := IsValidHandle(Hwnd);  if not result then exit;  if TObject(hWnd) is TGtk3Window then    Result:=TGtk3Window(hWnd).ShowState(nCmdShow)  else  begin    TGtk3Widget(hWnd).Show;    Result:=true;  end;end;
Notice the Result := True; lines. Result is already true when reaching those lines.

In addition, function TGtk3WidgetSet.GetKeyState starts with the following code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGtk3WidgetSet.GetKeyState(nVirtKey: Integer): Smallint;const  StateDown    = SmallInt($FF80);var  AKeyMap: PGdkKeymap;  AModifiers: TGdkModifierType;begin  Result := 0;   Result := 0;   case nVirtKey of    VK_LSHIFT:   nVirtKey := VK_SHIFT;    VK_LCONTROL: nVirtKey := VK_CONTROL;    VK_LMENU:    nVirtKey := VK_MENU;  end;....   
The following patch removes those three result:=true lines and also removes the duplicate Result:=0 line.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---diff --git a/lcl/interfaces/gtk2/gtk2winapi.inc b/lcl/interfaces/gtk2/gtk2winapi.incindex 475afa4cfb..12d3426b61 100644--- a/lcl/interfaces/gtk2/gtk2winapi.inc+++ b/lcl/interfaces/gtk2/gtk2winapi.inc@@ -3998,7 +3998,6 @@ var   CRect : TGDKRectangle;   hasClipping: Boolean; begin-   Result := IsValidDC(DC) and IsValidGDIObject(hbr) and IsValidGDIObject(RegionHnd);   if not Result then Exit;   GtkDC := SaveDC(DC);@@ -4015,7 +4014,6 @@ begin       DevCtx.FillRect(ARect, hbr, True);       // revert clip (whatever it is - null or valid region)       SelectClipRGN(DC, {%H-}HRGN(OldRgn));-      Result := True;     end;   finally     if hasClipping thendiff --git a/lcl/interfaces/gtk3/gtk3winapi.inc b/lcl/interfaces/gtk3/gtk3winapi.incindex 54aa27f35e..ac00749898 100644--- a/lcl/interfaces/gtk3/gtk3winapi.inc+++ b/lcl/interfaces/gtk3/gtk3winapi.inc@@ -2197,8 +2197,6 @@ var begin   Result := 0; -  Result := 0;-   case nVirtKey of     VK_LSHIFT:   nVirtKey := VK_SHIFT;     VK_LCONTROL: nVirtKey := VK_CONTROL;@@ -3561,7 +3559,6 @@ begin       exit(False);     // DebugLn('TGtk3WidgetSet.SetForegroundWindow ',dbgsName(AWindow.LCLObject));     AWindow.Activate;-    Result := True;   end; end; @@ -3975,10 +3972,7 @@ begin   if TObject(hWnd) is TGtk3Window then     Result:=TGtk3Window(hWnd).ShowState(nCmdShow)   else-  begin     TGtk3Widget(hWnd).Show;-    Result:=true;-  end; end;  function TGtk3WidgetSet.StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer;

AlexTP:
Posted to https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40489

Navigation

[0] Message Index

Go to full version