View Issue Details

IDProjectCategoryView StatusLast Update
0030497LazarusWidgetsetpublic2016-12-24 16:51
ReporterStefan Kopf Assigned ToFelipe Monteiro de Carvalho  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformMac 
Product Version1.6 
Summary0030497: [PATCH] Fix: TListBox.ItemHeight does not work on Mac / Carbon
DescriptionThe ItemHeight property of TListBox does not work consistently on the Mac. There
has even been a change request to update the documentation that ItemHeight is
not supported on the Mac (http://bugs.freepascal.org/view.php?id=27799).
The attached fix solves this problem.

Please
1. Accept this patch
2. Revert documentation changes of ID 27799 accepted in r51847.

Abstract
When setting the Font of a Carbon x, the ItemHeight is automatically set to the
Font height. So we need to always set the ItemHeights after setting the Font.

Current problem
Setting the ItemHeight does only work on the initial creation of the TListBox
on the Mac, for instance by setting it in the designer. But when trying to set
the ItemHeight at runtime, then the ItemHeight is automatically set to the
height of the Font instead of the given value.

Problem analysis
Further analysis showed that the ItemHeight is no longer respected when the
widget is re-created due to property updates.
When updating a property, the widget is typically re-created by a call to
RecreateWnd (/lcl/controls.pp). This procedure invokes DestroyHandle which
invokes DestroyWnd. This procedure sets the wcfColorChanged and wcfFontChanged
flags in FWinControlFlags. After destroying the handle, RecreateWnd initiates
the creation again. TWinControl.CreateWnd creates the FHandle again, which
ulimately invokes TCarbonListBox.CreateWidget. This procedure sets up the
ItemHeight properly.
TWinControl.CreateWnd invokes InitializeWnd afterwards, which checks for the
wcfFontChanged flag in FWinControlFlags and sets the Font on the control. This
re-sets the ItemHeight to the Font height again and the value set up by
TCarbonListBox.CreateWidget is ignored.

The fix
1. Restrict setting the ItemHeight to owner drawn lists with a fixed line height
2. Whenever the font is set, the ItemHeight is set again afterwards
Steps To Reproduce1. Add a TListBox to a Form in the designer
2. Add some lines to the ListBox
3. Set style to lbOwnerDrawnFixed
4. Set an ItemHeight of 25 px
--> note: the designer will not show this
5. Add a button with this code "ListBox1.ItemHeight := 30;"
6. Run it
Observation:
In contrast to the designer UI, the ListBox actually has an ItemHeight of 25px
7. Click the button
Expected:
The lines in the ListBox expand to the new ItemHeight of 30 px
However:
The lines shrink to the text height of 19px
TagsNo tags attached.
Fixed in Revision53770, 53773
LazTarget-
WidgetsetCarbon
Attached Files

Relationships

related to 0027799 closedBart Broersma Mac Listbox don't support ItemHeight, please document as "restricted" 

Activities

Stefan Kopf

2016-08-21 17:44

reporter  

Carbon_ListBox_ItemHeight.patch (1,388 bytes)   
Index: lcl/interfaces/carbon/carbonlistviews.pp
===================================================================
--- lcl/interfaces/carbon/carbonlistviews.pp	(revision 52841)
+++ lcl/interfaces/carbon/carbonlistviews.pp	(working copy)
@@ -273,6 +273,7 @@
     procedure DrawItem(AIndex: Integer; AState: DataBrowserItemState); override;
     procedure SelectionChanged(AIndex: Integer; ASelect: Boolean); override;
     procedure FocusedChanged({%H-}AIndex: Integer); override;
+    procedure SetFont(const AFont: TFont); override;
   end;
   
   { TCarbonCheckListBox }
@@ -1944,7 +1945,8 @@
   ShowColumnHeaders(False);
   ShowCheckboxes(False);
   ShowAsList(True);
-  SetItemsHeight((LCLObject as TCustomListBox).ItemHeight);
+  if (LCLObject as TCustomListBox).Style = lbOwnerDrawFixed then
+    SetItemsHeight((LCLObject as TCustomListBox).ItemHeight);
   SetRowSelect(True);
   SetScrollBars(ssAutoVertical);
   SetSelectionMode((LCLObject as TCustomListBox).ExtendedSelect,
@@ -2011,6 +2013,13 @@
   LCLSendSelectionChangedMsg(LCLObject);
 end;
 
+procedure TCarbonListBox.SetFont(const AFont: TFont);
+begin
+  inherited SetFont(AFont);
+  if (LCLObject as TCustomListBox).Style = lbOwnerDrawFixed then
+    SetItemsHeight((LCLObject as TCustomListBox).ItemHeight);
+end;
+
 { TCarbonCheckListBox }
 
 procedure TCarbonCheckListBox.CreateWidget(const AParams: TCreateParams);

CudaText man

2016-12-20 22:46

reporter   ~0096965

Checked the dif: it is ok: for OwnerDrawFixed listbox, ItemHeight changes, visible in OI and runtime.
Pls apply

Issue History

Date Modified Username Field Change
2016-08-21 17:44 Stefan Kopf New Issue
2016-08-21 17:44 Stefan Kopf File Added: Carbon_ListBox_ItemHeight.patch
2016-08-21 17:50 Juha Manninen Relationship added related to 0027799
2016-12-20 22:46 CudaText man Note Added: 0096965
2016-12-23 13:12 Juha Manninen Assigned To => Bart Broersma
2016-12-23 13:12 Juha Manninen Status new => assigned
2016-12-23 20:36 Felipe Monteiro de Carvalho Assigned To Bart Broersma => Felipe Monteiro de Carvalho
2016-12-23 20:38 Felipe Monteiro de Carvalho Fixed in Revision => 53770
2016-12-23 20:38 Felipe Monteiro de Carvalho LazTarget => -
2016-12-23 20:38 Felipe Monteiro de Carvalho Status assigned => resolved
2016-12-23 20:38 Felipe Monteiro de Carvalho Resolution open => fixed
2016-12-24 16:51 Bart Broersma Fixed in Revision 53770 => 53770, 53773