From 38b995b4cc80f81c546177762c402dd41df3b63c Mon Sep 17 00:00:00 2001
From: Arioch <the_Arioch@nm.ru>
Date: Sat, 31 Aug 2013 15:23:32 +0400
Subject: [PATCH] #6191 1. Better demo for list boxes 2. Better drawing
 inter-items separators

---
 jvcl/examples/JvListComb/ListBoxFormU.dfm      | 151 ++++++++++++-------
 jvcl/examples/JvListComb/ListBoxFormU.pas      |   2 +
 jvcl/examples/JvListComb/ListCombMainFormU.dfm | 199 ++++++++++---------------
 jvcl/examples/JvListComb/ListCombMainFormU.pas |  13 +-
 jvcl/run/JvListBox.pas                         |  60 +++++---
 5 files changed, 219 insertions(+), 206 deletions(-)

diff --git a/jvcl/examples/JvListComb/ListBoxFormU.dfm b/jvcl/examples/JvListComb/ListBoxFormU.dfm
index ddab04a..c23dec2 100644
--- a/jvcl/examples/JvListComb/ListBoxFormU.dfm
+++ b/jvcl/examples/JvListComb/ListBoxFormU.dfm
@@ -3,12 +3,14 @@ object fmListBox: TfmListBox
   Top = 0
   BorderStyle = bsSizeToolWin
   Caption = 'TJvListBox'
-  ClientHeight = 490
-  ClientWidth = 548
+  ClientHeight = 443
+  ClientWidth = 545
   Color = clBtnFace
+  Constraints.MinHeight = 294
+  Constraints.MinWidth = 414
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
-  Font.Height = -13
+  Font.Height = -10
   Font.Name = 'Tahoma'
   Font.Style = []
   OldCreateOrder = False
@@ -16,50 +18,53 @@ object fmListBox: TfmListBox
   Visible = True
   OnCreate = FormCreate
   OnShow = FormShow
-  PixelsPerInch = 120
-  TextHeight = 16
+  PixelsPerInch = 96
+  TextHeight = 12
   object pnl1: TPanel
-    Left = 403
+    Left = 436
     Top = 0
-    Width = 145
-    Height = 490
+    Width = 109
+    Height = 443
+    Margins.Left = 2
+    Margins.Top = 2
+    Margins.Right = 2
+    Margins.Bottom = 2
     Align = alRight
     TabOrder = 0
+    ExplicitLeft = 302
+    ExplicitHeight = 368
     DesignSize = (
-      145
-      490)
+      109
+      443)
     object btnTextGen: TButton
-      Left = 27
-      Top = 443
-      Width = 92
-      Height = 31
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 20
+      Top = 407
+      Width = 69
+      Height = 24
       Anchors = [akRight, akBottom]
       Caption = 'Random...'
       TabOrder = 0
       OnClick = btnTextGenClick
+      ExplicitTop = 332
     end
     object chkWW: TCheckBox
-      Left = 16
-      Top = 19
-      Width = 108
-      Height = 17
+      Left = 12
+      Top = 14
+      Width = 81
+      Height = 13
+      Margins.Left = 2
+      Margins.Top = 2
+      Margins.Right = 2
+      Margins.Bottom = 2
       Caption = 'Wrap words'
       TabOrder = 1
       OnClick = chkWWClick
     end
     object cbcMain: TJvColorComboBox
-      Left = 7
-      Top = 81
-      Width = 130
-      Height = 23
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 5
+      Top = 61
+      Width = 98
+      Height = 19
       Anchors = [akLeft, akTop, akRight]
       ColorNameMap.Strings = (
         'clBlack=Black'
@@ -114,21 +119,17 @@ object fmListBox: TfmListBox
         'clMenuHighlight=Menu Highlight')
       ColorValue = clWhite
       ColorDialogText = '(Custom...)'
-      DroppedDownWidth = 130
+      DroppedDownWidth = 98
       NewColorText = 'New Color '
       Options = [coText, coCustomColors]
       TabOrder = 2
       OnChange = cbcMainChange
     end
     object cbcAlt: TJvColorComboBox
-      Left = 7
-      Top = 126
-      Width = 130
-      Height = 23
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 5
+      Top = 95
+      Width = 98
+      Height = 19
       Anchors = [akLeft, akTop, akRight]
       ColorNameMap.Strings = (
         'clBlack=Black'
@@ -183,27 +184,35 @@ object fmListBox: TfmListBox
         'clMenuHighlight=Menu Highlight')
       ColorValue = clWhite
       ColorDialogText = '(Custom...)'
-      DroppedDownWidth = 130
+      DroppedDownWidth = 98
       NewColorText = 'New Color '
       Options = [coText, coCustomColors]
       TabOrder = 3
       OnChange = cbcAltChange
     end
     object chkAlt: TCheckBox
-      Left = 40
-      Top = 155
-      Width = 97
-      Height = 17
+      Left = 30
+      Top = 116
+      Width = 73
+      Height = 13
+      Margins.Left = 2
+      Margins.Top = 2
+      Margins.Right = 2
+      Margins.Bottom = 2
       Caption = 'Alternate'
       TabOrder = 4
       OnClick = chkAltClick
     end
     object chkOutline: TCheckBox
-      Left = 16
-      Top = 224
-      Width = 97
-      Height = 17
-      Caption = 'chkOutline'
+      Left = 12
+      Top = 168
+      Width = 73
+      Height = 13
+      Margins.Left = 2
+      Margins.Top = 2
+      Margins.Right = 2
+      Margins.Bottom = 2
+      Caption = 'Outline Lines'
       TabOrder = 5
       OnClick = chkOutlineClick
     end
@@ -211,35 +220,67 @@ object fmListBox: TfmListBox
   object pgcLBs: TPageControl
     Left = 0
     Top = 0
-    Width = 403
-    Height = 490
+    Width = 436
+    Height = 443
+    Margins.Left = 2
+    Margins.Top = 2
+    Margins.Right = 2
+    Margins.Bottom = 2
     ActivePage = tsJVCL
     Align = alClient
     TabOrder = 1
     TabPosition = tpBottom
+    ExplicitWidth = 302
+    ExplicitHeight = 368
     object tsJVCL: TTabSheet
+      Margins.Left = 2
+      Margins.Top = 2
+      Margins.Right = 2
+      Margins.Bottom = 2
       Caption = 'JediVCL Listbox'
+      ExplicitWidth = 294
+      ExplicitHeight = 343
       object lst1: TJvListBox
         Left = 0
         Top = 0
-        Width = 395
-        Height = 461
+        Width = 428
+        Height = 418
+        Margins.Left = 2
+        Margins.Top = 2
+        Margins.Right = 2
+        Margins.Bottom = 2
         Align = alClient
+        ItemHeight = 12
         Background.FillMode = bfmTile
         Background.Visible = False
         TabOrder = 0
+        ExplicitWidth = 294
+        ExplicitHeight = 343
       end
     end
     object tsVCL: TTabSheet
+      Margins.Left = 2
+      Margins.Top = 2
+      Margins.Right = 2
+      Margins.Bottom = 2
       Caption = 'Standard ListBox'
       ImageIndex = 1
+      ExplicitWidth = 294
+      ExplicitHeight = 343
       object lst2: TListBox
         Left = 0
         Top = 0
-        Width = 395
-        Height = 461
+        Width = 428
+        Height = 418
+        Margins.Left = 2
+        Margins.Top = 2
+        Margins.Right = 2
+        Margins.Bottom = 2
         Align = alClient
+        ItemHeight = 12
         TabOrder = 0
+        ExplicitWidth = 294
+        ExplicitHeight = 343
       end
     end
   end
diff --git a/jvcl/examples/JvListComb/ListBoxFormU.pas b/jvcl/examples/JvListComb/ListBoxFormU.pas
index 7e308b9..3afac5b 100644
--- a/jvcl/examples/JvListComb/ListBoxFormU.pas
+++ b/jvcl/examples/JvListComb/ListBoxFormU.pas
@@ -83,6 +83,8 @@ procedure TfmListBox.FormCreate(Sender: TObject);
 begin
   lst1.ColorAlternate := clLime;
   lst1.Color := clYellow;
+
+  btnTextGenClick(Self);
 end;
 
 procedure TfmListBox.FormShow(Sender: TObject);
diff --git a/jvcl/examples/JvListComb/ListCombMainFormU.dfm b/jvcl/examples/JvListComb/ListCombMainFormU.dfm
index 9bf71b2..cb41888 100644
--- a/jvcl/examples/JvListComb/ListCombMainFormU.dfm
+++ b/jvcl/examples/JvListComb/ListCombMainFormU.dfm
@@ -2,40 +2,32 @@ object ListCombMainForm: TListCombMainForm
   Left = 276
   Top = 174
   Caption = 'JvComboBox sample'
-  ClientHeight = 561
-  ClientWidth = 694
+  ClientHeight = 456
+  ClientWidth = 564
   Color = clBtnFace
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
-  Font.Height = -14
+  Font.Height = -11
   Font.Name = 'MS Sans Serif'
   Font.Style = []
   OldCreateOrder = True
   OnCreate = FormCreate
-  PixelsPerInch = 120
-  TextHeight = 16
+  PixelsPerInch = 96
+  TextHeight = 13
   object Splitter1: TSplitter
-    Left = 348
-    Top = 86
-    Width = 6
-    Height = 475
-    Margins.Left = 4
-    Margins.Top = 4
-    Margins.Right = 4
-    Margins.Bottom = 4
+    Left = 283
+    Top = 75
+    Width = 5
+    Height = 381
     Align = alRight
-    ExplicitTop = 92
-    ExplicitHeight = 469
+    ExplicitTop = 70
+    ExplicitHeight = 386
   end
   object Panel2: TPanel
     Left = 0
-    Top = 86
-    Width = 348
-    Height = 475
-    Margins.Left = 4
-    Margins.Top = 4
-    Margins.Right = 4
-    Margins.Bottom = 4
+    Top = 75
+    Width = 283
+    Height = 381
     Align = alClient
     BevelOuter = bvNone
     BorderWidth = 2
@@ -44,16 +36,12 @@ object ListCombMainForm: TListCombMainForm
     object JvListBox1: TJvImageListBox
       Left = 2
       Top = 2
-      Width = 344
-      Height = 471
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Width = 279
+      Height = 377
       Align = alClient
       Font.Charset = DEFAULT_CHARSET
       Font.Color = clWindowText
-      Font.Height = -15
+      Font.Height = -12
       Font.Name = 'MS Sans Serif'
       Font.Style = []
       Items = <>
@@ -67,72 +55,51 @@ object ListCombMainForm: TListCombMainForm
     end
   end
   object Panel3: TPanel
-    Left = 354
-    Top = 86
-    Width = 340
-    Height = 475
-    Margins.Left = 4
-    Margins.Top = 4
-    Margins.Right = 4
-    Margins.Bottom = 4
+    Left = 288
+    Top = 75
+    Width = 276
+    Height = 381
     Align = alRight
     BevelOuter = bvNone
     TabOrder = 1
     DesignSize = (
-      340
-      475)
+      276
+      381)
     object Label1: TLabel
-      Left = 81
-      Top = 103
-      Width = 94
-      Height = 16
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
+      Left = 66
+      Top = 84
+      Width = 75
+      Height = 13
       Caption = 'a JvColorButton'
     end
     object Label2: TLabel
-      Left = 207
-      Top = 26
-      Width = 124
-      Height = 16
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
+      Left = 168
+      Top = 21
+      Width = 95
+      Height = 13
       Caption = 'a JvColorComboBox'
     end
     object Label3: TLabel
-      Left = 207
-      Top = 64
-      Width = 118
-      Height = 16
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
+      Left = 168
+      Top = 52
+      Width = 92
+      Height = 13
       Caption = 'a JvFontComboBox'
     end
     object Button2: TButton
-      Left = 20
-      Top = 153
-      Width = 92
-      Height = 30
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 16
+      Top = 124
+      Width = 75
+      Height = 25
       Caption = 'Toggle justify'
       TabOrder = 0
       OnClick = Button2Click
     end
     object CheckBox1: TCheckBox
-      Left = 20
-      Top = 128
-      Width = 119
-      Height = 21
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 16
+      Top = 104
+      Width = 97
+      Height = 17
       Caption = 'Images'
       Checked = True
       State = cbChecked
@@ -140,32 +107,24 @@ object ListCombMainForm: TListCombMainForm
       OnClick = CheckBox1Click
     end
     object JvColorComboBox1: TJvColorComboBox
-      Left = 20
-      Top = 20
-      Width = 178
-      Height = 23
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 16
+      Top = 16
+      Width = 145
+      Height = 20
       ColorValue = clWhite
       ColorDialogText = '(Custom...)'
-      DroppedDownWidth = 178
+      DroppedDownWidth = 145
       NewColorText = 'New Color '
       Options = [coText, coCustomColors]
       TabOrder = 2
       OnChange = JvColorComboBox1Change
     end
     object JvFontComboBox1: TJvFontComboBox
-      Left = 20
-      Top = 59
-      Width = 178
-      Height = 23
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
-      DroppedDownWidth = 178
+      Left = 16
+      Top = 48
+      Width = 145
+      Height = 22
+      DroppedDownWidth = 145
       MaxMRUCount = 0
       FontName = '@Arial Unicode MS'
       ItemIndex = 0
@@ -174,43 +133,39 @@ object ListCombMainForm: TListCombMainForm
       OnChange = JvFontComboBox1Change
     end
     object JvColorButton1: TJvColorButton
-      Left = 20
-      Top = 98
-      Width = 51
-      Height = 26
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 16
+      Top = 80
       OtherCaption = '&Other...'
       Options = []
       OnChange = JvColorButton1Change
       TabOrder = 4
     end
     object Button1: TButton
-      Left = 20
-      Top = 427
-      Width = 92
-      Height = 31
-      Margins.Left = 4
-      Margins.Top = 4
-      Margins.Right = 4
-      Margins.Bottom = 4
+      Left = 16
+      Top = 347
+      Width = 75
+      Height = 25
       Anchors = [akLeft, akBottom]
       Caption = 'Load...'
       TabOrder = 5
       OnClick = Button1Click
     end
+    object btnListBoxDemo: TButton
+      Left = 176
+      Top = 347
+      Width = 89
+      Height = 25
+      Anchors = [akRight, akBottom]
+      Caption = 'TJvListBox >>'
+      TabOrder = 6
+      OnClick = btnListBoxDemoClick
+    end
   end
   object JvComboBox1: TJvImageComboBox
     Left = 0
-    Top = 60
-    Width = 694
+    Top = 49
+    Width = 564
     Height = 26
-    Margins.Left = 4
-    Margins.Top = 4
-    Margins.Right = 4
-    Margins.Bottom = 4
     Style = csOwnerDrawVariable
     Align = alTop
     ButtonFrame = True
@@ -219,7 +174,7 @@ object ListCombMainForm: TListCombMainForm
     DropDownCount = 10
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clBlack
-    Font.Height = -15
+    Font.Height = -12
     Font.Name = 'MS Sans Serif'
     Font.Style = []
     ImageHeight = 0
@@ -234,17 +189,13 @@ object ListCombMainForm: TListCombMainForm
   object PanelTop: TPanel
     Left = 0
     Top = 0
-    Width = 694
-    Height = 60
-    Margins.Left = 4
-    Margins.Top = 4
-    Margins.Right = 4
-    Margins.Bottom = 4
+    Width = 564
+    Height = 49
     Align = alTop
     Caption = 'Here you can see some Combo and List Boxes from the JVCL'
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
-    Font.Height = -17
+    Font.Height = -15
     Font.Name = 'MS Sans Serif'
     Font.Style = [fsBold]
     ParentFont = False
diff --git a/jvcl/examples/JvListComb/ListCombMainFormU.pas b/jvcl/examples/JvListComb/ListCombMainFormU.pas
index 4cfae83..15c34af 100644
--- a/jvcl/examples/JvListComb/ListCombMainFormU.pas
+++ b/jvcl/examples/JvListComb/ListCombMainFormU.pas
@@ -52,7 +52,7 @@ type
     Label1: TLabel;
     Label2: TLabel;
     Label3: TLabel;
-    procedure TransparentButton1Click(Sender: TObject);
+    btnListBoxDemo: TButton;
     procedure Button1Click(Sender: TObject);
     procedure Button2Click(Sender: TObject);
     procedure CheckBox1Click(Sender: TObject);
@@ -60,18 +60,23 @@ type
     procedure JvFontComboBox1Change(Sender: TObject);
     procedure JvColorButton1Change(Sender: TObject);
     procedure FormCreate(Sender: TObject);
+    procedure btnListBoxDemoClick(Sender: TObject);
   end;
 
 var
   ListCombMainForm: TListCombMainForm;
 
-implementation
+implementation  uses ListBoxFormU;
 
 {$R *.DFM}
 
-procedure TListCombMainForm.TransparentButton1Click(Sender: TObject);
+procedure TListCombMainForm.btnListBoxDemoClick(Sender: TObject);
 begin
-  ShowMessage('Hej Simon!')
+  with fmListBox do begin
+    if Visible
+       then BringToFront
+       else Show;
+  end;
 end;
 
 procedure TListCombMainForm.Button1Click(Sender: TObject);
diff --git a/jvcl/run/JvListBox.pas b/jvcl/run/JvListBox.pas
index ab2b756..2daeb34 100644
--- a/jvcl/run/JvListBox.pas
+++ b/jvcl/run/JvListBox.pas
@@ -1076,6 +1076,8 @@ end;
 
 { This procedure is a slightly modified version of TCustomListbox.DrawItem! }
 
+const JvCustomListBoxItemsSeparatorIndent = 6;
+
 procedure TJvCustomListBox.DefaultDrawItem(Index: Integer; ARect: TRect;
   State: TOwnerDrawState);
 const
@@ -1088,10 +1090,18 @@ var
   AColor: TColor;
 
  procedure DrawSeparatorBar(const ALine: byte);
+ var dX, Y: integer;
  begin
    Canvas.Pen.Color := AColor;
-   Canvas.MoveTo(ActualRect.Left, ActualRect.Bottom - 1 + ALine);
-   Canvas.LineTo(ActualRect.Right - 1, ActualRect.Bottom - 1 + ALine);
+   Y := ActualRect.Bottom - 1 + ALine;
+
+   dX := 0;
+   if Color = ColorAlternate then
+      if ActualRect.Right - ActualRect.Left > 4 * JvCustomListBoxItemsSeparatorIndent then
+         dX := JvCustomListBoxItemsSeparatorIndent;
+
+   Canvas.MoveTo( ActualRect.Left + dX, Y );
+   Canvas.LineTo( ActualRect.Right - dX, Y );
  end;
 begin
   if csDestroying in ComponentState then
@@ -1139,13 +1149,36 @@ begin
     else
       Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX or
         AlignFlags[FAlignment]);
+
+    If ItemHasSeparator(Index) then
+    begin
+      // This sequence has to be executed before "UseRightToLeftAlignment" check
+      //   below would cripple ActualRect horizontal coordinates!
+
+      Dec(ActualRect.Bottom, 3);
+
+      Canvas.Pen.Style := psSolid;
+      Canvas.Pen.Mode  := pmCopy;
+
+      if Odd(Index)
+         then AColor := ColorAlternate
+         else AColor := Color;
+      DrawSeparatorBar(+1);
+
+      AColor := clBlack;
+      DrawSeparatorBar(+2);
+
+      if not Odd(Index)
+         then AColor := ColorAlternate
+         else AColor := Color;
+      DrawSeparatorBar(+3);
+    end;
+
     if not UseRightToLeftAlignment then
       Inc(ActualRect.Left, 2)
     else
       Dec(ActualRect.Right, 2);
 
-    If ItemHasSeparator(Index) then Dec(ActualRect.Bottom, 3);
-
     if IsProviderSelected then
       DrawProviderItem(Canvas, ActualRect, Index, State)
     else
@@ -1163,25 +1196,6 @@ begin
     if Background.DoDraw and (odSelected in State) then
       InvertRect(Canvas.Handle, ActualRect);
     // no need to draw focus rect, CNDrawItem does that for us
-
-    If ItemHasSeparator(Index) then
-    begin
-      Canvas.Pen.Style := psSolid;
-      Canvas.Pen.Mode  := pmCopy;
-
-      if Odd(Index)
-         then AColor := ColorAlternate
-         else AColor := Color;
-      DrawSeparatorBar(+1);
-
-      AColor := clBlack;
-      DrawSeparatorBar(+2);
-
-      if not Odd(Index)
-         then AColor := ColorAlternate
-         else AColor := Color;
-      DrawSeparatorBar(+3);
-    end;
   end;
 end;
 
-- 
1.8.3.msysgit.0

