View Issue Details

IDProjectCategoryView StatusLast Update
0020291LazarusLCLpublic2011-09-27 15:15
ReporterFlávio Etrusco Assigned ToZeljan Rikalo  
PrioritylowSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version0.9.31 (SVN) 
Fixed in Version0.9.31 (SVN) 
Summary0020291: TGraphicControl.IsVisuallyEnabled should be renamed/moved to TControl.IsEnabled
DescriptionIMO TGraphicControl.IsVisuallyEnabled should be renamed/moved to TControl.IsEnabled, similarly to TControl.IsVisible.
TagsNo tags attached.
Fixed in Revision32492,32505,32512
LazTarget-
Widgetset
Attached Files

Relationships

related to 0020247 resolvedZeljan Rikalo TColorButton and TSpeedButton only turn grey when disabled explicitly, not when disabled via Parent component 

Activities

Flávio Etrusco

2011-09-19 07:49

developer   ~0052009

Let me clarify that "similary to IsVisible" also means checking the whole parent hierarchy (and check csDesigning).
Thinking better, maybe it should be implemented only in TWinControl and check against the OS idea of 'Enabled' (i.e. will receive events). I still have to check how each OS behave.

Zeljan Rikalo

2011-09-19 08:36

developer   ~0052010

TWinControl -> when parent is Enabled = False it does not change property Enabled of it's children, but ws make it visually "disabled" and disabled for input events.
Maybe I can add this to TControl then so both TGraphicControl and TWinControl can be checked against that (so no need to check if Enabled and Assigned(Parent) and Parent.Enabled). IMO, IsEnabled() isn't good name, I'll set it up as IsVisuallyEnabled and clarify meaning in documentation...

Flávio Etrusco

2011-09-19 10:01

developer   ~0052016

Sorry, Zeljan, I'm not sure what you mean in the first sentence. Are you describing the current (and desired) LCL behavior or something else?

Regarding the name, as I see it's the same situation as Visible vs IsVisible. And actually, the only thing we can affirm is that the control is disabled for UI input; whether it has a "disabled visual" is specific to the control...

2011-09-20 03:36

 

TControl-IsEnabled-r32432.patch (9,857 bytes)   
67be900e831e6ad767a138360504ab6b0a9a25b2
diff --git components/lazcontrols/treefilteredit.pas components/lazcontrols/treefilteredit.pas
index 25dd63e..2823be1 100644
--- components/lazcontrols/treefilteredit.pas
+++ components/lazcontrols/treefilteredit.pas
@@ -11,7 +11,7 @@ uses
 type
 
   TImageIndexEvent = function (Str: String; Data: TObject;
-                               var IsEnabled: Boolean): Integer of object;
+                               var AIsEnabled: Boolean): Integer of object;
 
   { TTreeFilterEdit }
 
diff --git ide/projectinspector.pas ide/projectinspector.pas
index fddbb5c..626540c 100644
--- ide/projectinspector.pas
+++ ide/projectinspector.pas
@@ -152,7 +152,7 @@ type
     procedure SetShowDirectoryHierarchy(const AValue: boolean);
     procedure SetSortAlphabetically(const AValue: boolean);
     procedure SetupComponents;
-    function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
+    function ChooseImageIndex(Str: String; Data: TObject; var AIsEnabled: Boolean): Integer;
     procedure UpdateProjectFiles(Immediately: boolean);
     procedure UpdateRequiredPackages;
     procedure UpdateRemovedRequiredPackages;
@@ -600,7 +600,7 @@ begin
 end;
 
 function TProjectInspectorForm.ChooseImageIndex(Str: String; Data: TObject;
-                                                var IsEnabled: Boolean): Integer;
+                                                var AIsEnabled: Boolean): Integer;
 begin
   if FilenameIsPascalUnit((Data as TUnitInfo).Filename) then
     Result:=ImageIndexUnit
diff --git lcl/controls.pp lcl/controls.pp
index dfd1b5f..6af304d 100644
--- lcl/controls.pp
+++ lcl/controls.pp
@@ -1350,6 +1350,7 @@ type
     function GetTopParent: TControl;
     function IsVisible: Boolean; virtual;// checks parents too
     function IsControlVisible: Boolean; virtual;// does not check parents
+    function IsEnabled: Boolean; // checks parent too
     function FormIsUpdating: boolean; virtual;
     function IsProcessingPaintMsg: boolean;
     procedure Hide;
@@ -2014,7 +2015,6 @@ type
     procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
   protected
     class procedure WSRegisterClass; override;
-    function VisuallyEnabled: Boolean;
     procedure FontChanged(Sender: TObject); override;
     procedure Paint; virtual;
     procedure DoOnChangeBounds; override;
diff --git lcl/include/control.inc lcl/include/control.inc
index 8357e41..a41fd21 100644
--- lcl/include/control.inc
+++ lcl/include/control.inc
@@ -655,6 +655,26 @@ begin
                   and (not (csNoDesignVisible in ControlStyle))));
 end;
 
+{------------------------------------------------------------------------------
+  Method: TControl.IsEnabled
+  Params:   none
+  Returns:  Boolean
+
+  Returns True only if both TControl and it's parent hierarchy are enabled.
+  Used internally by TGraphicControls for painting and various states during
+  runtime.
+ ------------------------------------------------------------------------------}
+function TControl.IsEnabled: Boolean;
+var
+  Aux: TControl;
+begin
+  Aux:=Self;
+  repeat
+    Result:=Aux.Enabled;
+    Aux:=Aux.Parent;
+  until (not Result) or (Aux.Parent=nil);
+end;
+
 function TControl.FormIsUpdating: boolean;
 begin
   Result := Assigned(Parent) and Parent.FormIsUpdating;
diff --git lcl/include/customlabel.inc lcl/include/customlabel.inc
index 7ccfb2d..84dd9df 100644
--- lcl/include/customlabel.inc
+++ lcl/include/customlabel.inc
@@ -412,7 +412,7 @@ begin
   R := Rect(0,0,Width,Height);
   with Canvas do
   begin
-    if VisuallyEnabled then
+    if IsEnabled then
       Brush.Color := Self.Color
     else
       Brush.Color := clNone;
@@ -463,7 +463,7 @@ begin
     //debugln('TCustomLabel.Paint ',dbgs(Alignment=tacenter),' ',dbgs(Layout=tlCenter),' ',dbgs(TextLeft),' TextTop=',dbgs(TextTop),' ',dbgs(R));
     LabelText := GetLabelText;
     OldFontColor := Font.Color;
-    if not VisuallyEnabled then
+    if not IsEnabled then
     begin
       Font.Color := clBtnHighlight;
       TextRect(R, TextLeft + 1, TextTop + 1, LabelText, TR);
diff --git lcl/include/graphiccontrol.inc lcl/include/graphiccontrol.inc
index 8d3fb62..62569e5 100644
--- lcl/include/graphiccontrol.inc
+++ lcl/include/graphiccontrol.inc
@@ -77,22 +77,6 @@ begin
   RegisterGraphicControl;
 end;
 
-{------------------------------------------------------------------------------
-  Method: TGraphicControl.VisuallyEnabled
-  Params:   none
-  Returns:  Boolean
-
-  Returns True only if both TGraphicControl and it's parent are enabled.
-  Used internally by TGraphicControls for painting and various states during
-  runtime.
- ------------------------------------------------------------------------------}
-function TGraphicControl.VisuallyEnabled: Boolean;
-begin
-  Result := Enabled;
-  if Result and Assigned(Parent) then
-    Result := Result and Parent.Enabled;
-end;
-
 procedure TGraphicControl.FontChanged(Sender: TObject);
 begin
   Canvas.Font:=Font;
diff --git lcl/include/speedbutton.inc lcl/include/speedbutton.inc
index cb49f90..3579517 100644
--- lcl/include/speedbutton.inc
+++ lcl/include/speedbutton.inc
@@ -291,7 +291,7 @@ var
   OldState: TButtonState;
 begin
   OldState := FState;
-  if not VisuallyEnabled then
+  if not IsEnabled then
   begin
     FState := bsDisabled;
     FDragging := False;
@@ -339,7 +339,7 @@ function TCustomSpeedButton.GetDrawDetails: TThemedElementDetails;
     
     // no check states available
     Result := tbPushButtonNormal;
-    if not VisuallyEnabled then
+    if not IsEnabled then
       Result := tbPushButtonDisabled
     else
     if FState in [bsDown, bsExclusive] then
@@ -355,7 +355,7 @@ function TCustomSpeedButton.GetDrawDetails: TThemedElementDetails;
   begin
     // ttbButtonNormal, ttbButtonHot, ttbButtonPressed, ttbButtonDisabled
     // ttbButtonChecked, ttbButtonCheckedHot
-    if not VisuallyEnabled then
+    if not IsEnabled then
       Result := ttbButtonDisabled
     else
     begin
@@ -738,7 +738,7 @@ begin
   inherited MouseDown(Button, Shift, X, Y);
   if csDesigning in ComponentState then exit;
 
-  if (Button = mbLeft) and VisuallyEnabled then
+  if (Button = mbLeft) and IsEnabled then
   begin
     if not FDown then
     begin
@@ -1053,7 +1053,7 @@ end;
 procedure TCustomSpeedButton.MouseEnter;
 begin
   if csDesigning in ComponentState then exit;
-  if not FMouseInControl and VisuallyEnabled and (GetCapture = 0) then
+  if not FMouseInControl and IsEnabled and (GetCapture = 0) then
   begin
     FMouseInControl := True;
     UpdateState(true);
@@ -1074,7 +1074,7 @@ begin
   if FMouseInControl then
   begin
     FMouseInControl := False;
-    if VisuallyEnabled then
+    if IsEnabled then
     begin
       if FDragging and (not MouseCapture) then
       begin
diff --git packager/addtopackagedlg.pas packager/addtopackagedlg.pas
index 54c2a72..bd0847f 100644
--- packager/addtopackagedlg.pas
+++ packager/addtopackagedlg.pas
@@ -205,7 +205,8 @@ type
   
 function ShowAddToPackageDlg(Pkg: TLazPackage; var Params: TAddToPkgResult;
   OnGetIDEFileInfo: TGetIDEFileStateEvent;
-  OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo): TModalResult;
+  OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo;
+  DefaultAction: TAddToPkgType = d2ptNewFile): TModalResult;
 function CheckAddingUnitFilename(LazPackage: TLazPackage;
   AddFileType: TAddToPkgType; OnGetIDEFileInfo: TGetIDEFileStateEvent;
   var AFilename: string): boolean;
@@ -221,7 +222,8 @@ implementation
 
 function ShowAddToPackageDlg(Pkg: TLazPackage; var Params: TAddToPkgResult;
   OnGetIDEFileInfo: TGetIDEFileStateEvent;
-  OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo): TModalResult;
+  OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo;
+  DefaultAction: TAddToPkgType): TModalResult;
 var
   AddDlg: TAddToPackageDlg;
 begin
diff --git packager/installpkgsetdlg.pas packager/installpkgsetdlg.pas
index 78d1ce5..c241ef8 100644
--- packager/installpkgsetdlg.pas
+++ packager/installpkgsetdlg.pas
@@ -99,7 +99,7 @@ type
     procedure SetOldInstalledPackages(const AValue: TPkgDependency);
     procedure AssignOldInstalledPackagesToList;
     function PackageInInstallList(PkgName: string): boolean;
-    function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
+    function ChooseImageIndex(Str: String; Data: TObject; var AIsEnabled: Boolean): Integer;
     procedure UpdateAvailablePackages(Immediately: boolean = false);
     procedure UpdateNewInstalledPackages;
     procedure OnIteratePackages(APackageID: TLazPackageID);
@@ -354,7 +354,7 @@ begin
 end;
 
 function TInstallPkgSetDialog.ChooseImageIndex(Str: String; Data: TObject;
-                                               var IsEnabled: Boolean): Integer;
+                                               var AIsEnabled: Boolean): Integer;
 var
   Pkg: TLazPackageID;
   APackage: TLazPackage;
diff --git packager/packageeditor.pas packager/packageeditor.pas
index c6df897..1cb81b9 100644
--- packager/packageeditor.pas
+++ packager/packageeditor.pas
@@ -248,7 +248,7 @@ type
     procedure SetShowDirectoryHierarchy(const AValue: boolean);
     procedure SetSortAlphabetically(const AValue: boolean);
     procedure SetupComponents;
-    function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
+    function ChooseImageIndex(Str: String; Data: TObject; var AIsEnabled: Boolean): Integer;
     procedure UpdateTitle;
     procedure UpdateButtons;
     procedure UpdateFiles;
@@ -1625,7 +1625,7 @@ begin
 end;
 
 function TPackageEditorForm.ChooseImageIndex(Str: String; Data: TObject;
-                                             var IsEnabled: Boolean): Integer;
+                                             var AIsEnabled: Boolean): Integer;
 begin
   case TPkgFile(Data).FileType of
     pftUnit,pftVirtualUnit,pftMainUnit:

Flávio Etrusco

2011-09-20 03:40

developer   ~0052052

Another point against IsEnabled :( There's an event (from TTreeFilterEdit) which already has an IsEnabled param. And/but it's not used enywhere anyhow :-/
FWIW I attached a patch.

Zeljan Rikalo

2011-09-24 10:21

developer   ~0052137

Please test and close if ok.

Flávio Etrusco

2011-09-24 13:54

developer   ~0052141

Last edited: 2011-09-24 14:25

Thanks, Zeljan. However it seems *I* introduced a bug while refectoring the TControl.IsEnabled function with "repeat..until" :-$ The condition should read "TheControl <> nil". Sorry.
(Edit: But I can't get the bug to trigger??? -- correction: duh, of course I can. It exits before checking the Form.Enabled, so disabling the form doesn't disable the control.)

BTW the patch still doesn't test csDesigning. Shouldn't it?

Zeljan Rikalo

2011-09-24 21:00

developer   ~0052154

Please test and close if ok.
csDesigning check isn't needed.

Flávio Etrusco

2011-09-25 15:42

developer   ~0052173

Sorry, Zeljan, this didn't fix it yet. The check for "Parent <> nil" must be removed altogether. (There was no chance of AV, it just doesn't disable a label not placed directly on the form - to test place a label inside a panel and disable the form).

     Result := TheControl.Enabled;
     TheControl := TheControl.Parent;
-  until (TheControl = nil) or (not Result) or (TheControl.Parent = nil);
+  until (TheControl = nil) or (not Result);
 end;
 
 function TControl.FormIsUpdating: boolean;

Zeljan Rikalo

2011-09-27 10:36

developer   ~0052217

Test and close if ok.

Flávio Etrusco

2011-09-27 15:15

developer   ~0052227

Thanks!

Issue History

Date Modified Username Field Change
2011-09-19 01:24 Flávio Etrusco New Issue
2011-09-19 01:24 Flávio Etrusco LazTarget => -
2011-09-19 01:25 Flávio Etrusco Relationship added related to 0020247
2011-09-19 07:49 Flávio Etrusco Note Added: 0052009
2011-09-19 08:36 Zeljan Rikalo Note Added: 0052010
2011-09-19 10:01 Flávio Etrusco Note Added: 0052016
2011-09-20 03:36 Flávio Etrusco File Added: TControl-IsEnabled-r32432.patch
2011-09-20 03:40 Flávio Etrusco Note Added: 0052052
2011-09-24 10:14 Zeljan Rikalo Status new => assigned
2011-09-24 10:14 Zeljan Rikalo Assigned To => Zeljan Rikalo
2011-09-24 10:21 Zeljan Rikalo Fixed in Revision => 32492
2011-09-24 10:21 Zeljan Rikalo Status assigned => resolved
2011-09-24 10:21 Zeljan Rikalo Resolution open => fixed
2011-09-24 10:21 Zeljan Rikalo Note Added: 0052137
2011-09-24 13:54 Flávio Etrusco Status resolved => assigned
2011-09-24 13:54 Flávio Etrusco Resolution fixed => reopened
2011-09-24 13:54 Flávio Etrusco Note Added: 0052141
2011-09-24 14:10 Flávio Etrusco Note Edited: 0052141
2011-09-24 14:10 Flávio Etrusco Note Edited: 0052141
2011-09-24 14:25 Flávio Etrusco Note Edited: 0052141
2011-09-24 21:00 Zeljan Rikalo Fixed in Revision 32492 => 32492,32505
2011-09-24 21:00 Zeljan Rikalo Status assigned => resolved
2011-09-24 21:00 Zeljan Rikalo Resolution reopened => fixed
2011-09-24 21:00 Zeljan Rikalo Note Added: 0052154
2011-09-25 15:42 Flávio Etrusco Status resolved => assigned
2011-09-25 15:42 Flávio Etrusco Resolution fixed => reopened
2011-09-25 15:42 Flávio Etrusco Note Added: 0052173
2011-09-27 10:36 Zeljan Rikalo Fixed in Revision 32492,32505 => 32492,32505,32512
2011-09-27 10:36 Zeljan Rikalo Status assigned => resolved
2011-09-27 10:36 Zeljan Rikalo Resolution reopened => fixed
2011-09-27 10:36 Zeljan Rikalo Note Added: 0052217
2011-09-27 15:15 Flávio Etrusco Status resolved => closed
2011-09-27 15:15 Flávio Etrusco Note Added: 0052227
2011-09-27 15:15 Flávio Etrusco Fixed in Version => 0.9.31 (SVN)