From 203c7aab05c61e4e5414a3683cd766136d542b2e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 28 Apr 2019 11:25:50 +0000 Subject: [PATCH] jvcllaz: Fix painting issues in JvComboListbox demo on Linux. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6878 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../JvComboListBox/jvcombolistboxdemoform.lfm | 2 -- .../jvcllaz/run/JvCtrls/jvcombolistbox.pas | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/jvcllaz/examples/JvComboListBox/jvcombolistboxdemoform.lfm b/components/jvcllaz/examples/JvComboListBox/jvcombolistboxdemoform.lfm index 628309101..cdf11a646 100644 --- a/components/jvcllaz/examples/JvComboListBox/jvcombolistboxdemoform.lfm +++ b/components/jvcllaz/examples/JvComboListBox/jvcombolistboxdemoform.lfm @@ -10,8 +10,6 @@ object JvComboListBoxDemoFrm: TJvComboListBoxDemoFrm Constraints.MinHeight = 480 Constraints.MinWidth = 500 Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'MS Shell Dlg 2' OnCreate = FormCreate LCLVersion = '2.1.0.0' object Splitter1: TSplitter diff --git a/components/jvcllaz/run/JvCtrls/jvcombolistbox.pas b/components/jvcllaz/run/JvCtrls/jvcombolistbox.pas index f4e24df96..c1af9a994 100644 --- a/components/jvcllaz/run/JvCtrls/jvcombolistbox.pas +++ b/components/jvcllaz/run/JvCtrls/jvcombolistbox.pas @@ -102,6 +102,7 @@ type FOnGetText: TJvListBoxDataEvent; procedure SetDrawStyle(const Value: TJvComboListBoxDrawStyle); function DestRect(Picture: TPicture; ARect: TRect): TRect; + procedure FixItemRect(var ARect: TRect); function GetOffset(OrigRect, ImageRect: TRect): TRect; procedure SetButtonWidth(const Value: Integer); procedure SetDropdownMenu(const Value: TPopupMenu); @@ -203,7 +204,7 @@ type implementation uses - Math, Themes, JvJVCLUtils; + Types, Math, Themes, LCLPlatformDef, InterfaceBase, JvJVCLUtils; constructor TJvComboListBox.Create(AOwner: TComponent); begin @@ -362,9 +363,9 @@ var uState: Cardinal; details: TThemedElementDetails; begin - if ThemeServices.ThemesEnabled then begin + if ThemeServices.ThemesEnabled and (WidgetSet.LclPlatform <> lpQT) then begin details := ThemeServices.GetElementDetails(DROPDOWN_DETAILS[Highlight, Pushed]); - ThemeServices.DrawElement(ACanvas.Handle, details, R, nil) + ThemeServices.DrawElement(ACanvas.Handle, details, R, nil); end else begin uState := DFCS_SCROLLDOWN; @@ -389,6 +390,7 @@ var begin if (Index < 0) or (Index >= Items.Count) or Assigned(OnDrawItem) then Exit; + FixItemRect(ARect); Canvas.Lock; try if State * [odSelected, odFocused] <> [] then @@ -486,6 +488,15 @@ begin end; end; +procedure TJvComboListBox.FixItemRect(var ARect: TRect); +var + w: Integer; +begin + if Columns = 0 then w := ClientWidth else w := ClientWidth div Columns; + if ARect.Right - ARect.Left > w then + ARect.Right := ARect.Left + w; +end; + function TJvComboListBox.GetOffset(OrigRect, ImageRect: TRect): TRect; var W, H, W2, H2: Integer; @@ -517,19 +528,20 @@ end; procedure TJvComboListBox.InvalidateItem(Index: Integer); var - R, R2: TRect; + R: TRect; begin if Index < 0 then Index := ItemIndex; R := ItemRect(Index); - R2 := R; +// R2 := R; // we only want to redraw the combo button if not IsRectEmpty(R) then begin + FixItemRect(R); R.Right := R.Right - ButtonWidth; // don't redraw content, just button ExcludeClipRect(Canvas.Handle, R.Left, R.Top, R.Right, R.Bottom); - InvalidateRect(Handle, @R2, False); + InvalidateRect(Handle, @R, False); end; end; @@ -547,6 +559,7 @@ begin P := Point(X, Y); I := ItemAtPos(P, True); R := ItemRect(I); + FixItemRect(R); if (I = ItemIndex) and (X >= R.Right - ButtonWidth) and (X <= R.Right) then begin FMouseOver := True; @@ -588,6 +601,7 @@ begin P := Point(X, Y); I := ItemAtPos(P, True); R := ItemRect(I); + FixItemRect(R); if HotTrackCombo and (I <> FLastHotTrack) then begin if FLastHotTrack > -1 then