Commit aecfd2f7 authored by paul's avatar paul
Browse files

lcl: implement TListBox.ScrollWidth:

  - win32, wince: set/get scrollwidth using LB_SETHORIZONTALEXTENT/LB_GETHORIZONTALEXTENT (issue #18912)
  - qt, gtk2: don't show listbox horizontal scrollbar by default. show it only when scrollwidth > content area

git-svn-id: trunk@30138 -
parent 031074fb
......@@ -136,6 +136,7 @@ begin
// free old items
OldItems.Free;
TWSCustomListBoxClass(WidgetSetClass).SetSorted(Self, FItems, FSorted);
TWSCustomListBoxClass(WidgetSetClass).SetScrollWidth(Self, FScrollWidth);
UnlockSelectionChange;
end;
......@@ -217,6 +218,13 @@ begin
TWSCustomListBoxClass(WidgetSetClass).SetColumnCount(Self, FColumns);
end;
procedure TCustomListBox.SetScrollWidth(const AValue: Integer);
begin
FScrollWidth := AValue;
if HandleAllocated then
TWSCustomListBoxClass(WidgetSetClass).SetScrollWidth(Self, FScrollWidth);
end;
{------------------------------------------------------------------------------
function TCustomListBox.GetCount: Integer;
------------------------------------------------------------------------------}
......@@ -225,6 +233,14 @@ begin
Result := Items.Count;
end;
function TCustomListBox.GetScrollWidth: Integer;
begin
if HandleAllocated then
Result := TWSCustomListBoxClass(WidgetSetClass).GetScrollWidth(Self)
else
Result := FScrollWidth;
end;
{------------------------------------------------------------------------------
procedure TCustomListBox.SetTopIndex(const AValue: Integer);
------------------------------------------------------------------------------}
......@@ -532,6 +548,7 @@ begin
FClickOnSelChange:= True;
FItemIndex:=-1;
FExtendedSelect := true;
FScrollWidth := 0;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
ParentColor := false;
......
......@@ -162,6 +162,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
......@@ -171,6 +172,7 @@ type
class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect,
AMultiSelect: boolean); override;
class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;
......@@ -495,8 +497,15 @@ begin
end;
end;
class function TGtk2WSCustomListBox.GetTopIndex(
const ACustomListBox: TCustomListBox): integer;
class function TGtk2WSCustomListBox.GetScrollWidth(const ACustomListBox: TCustomListBox): Integer;
var
Adjustment: PGtkAdjustment;
begin
Adjustment := gtk_scrolled_window_get_hadjustment(PGtkScrolledWindow(ACustomListBox.Handle));
Result := Trunc(Adjustment^.upper);
end;
class function TGtk2WSCustomListBox.GetTopIndex(const ACustomListBox: TCustomListBox): integer;
begin
Result := GetIndexAtXY(ACustomListBox, 0, 1);
end;
......@@ -595,6 +604,21 @@ begin
Dec(WidgetInfo^.ChangeLock);
end;
class procedure TGtk2WSCustomListBox.SetScrollWidth(
const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
const
BoolToPolicy: array[Boolean] of TGtkPolicyType = (GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
var
Adjustment: PGtkAdjustment;
ScrolledWindow: PGtkScrolledWindow;
begin
ScrolledWindow := PGtkScrolledWindow(ACustomListBox.Handle);
gtk_scrolled_window_set_policy(ScrolledWindow, BoolToPolicy[AScrollWidth > PgtkWidget(ScrolledWindow)^.allocation.width], GTK_POLICY_AUTOMATIC);
Adjustment := gtk_scrolled_window_get_hadjustment(ScrolledWindow);
Adjustment^.upper := AScrollWidth;
gtk_adjustment_changed(Adjustment);
end;
class procedure TGtk2WSCustomListBox.SetSelectionMode(
const ACustomListBox: TCustomListBox; const AExtendedSelect,
AMultiSelect: boolean);
......@@ -703,8 +727,9 @@ begin
GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.hscrollbar, GTK_CAN_FOCUS);
GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.vscrollbar, GTK_CAN_FOCUS);
// by default horz scrollbar is invisible. it is set by SetScrollWidth
gtk_scrolled_window_set_policy(PGtkScrolledWindow(p),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
//Set BorderStyle according to the provided Params
if (AParams.ExStyle and WS_EX_CLIENTEDGE) > 0 then
gtk_scrolled_window_set_shadow_type(PGtkScrolledWindow(p), GTK_SHADOW_ETCHED_IN)
......
......@@ -1102,6 +1102,7 @@ type
public
procedure AttachEvents; override;
procedure DetachEvents; override;
procedure InitializeWidget; override;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
function itemViewViewportEventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
......@@ -1133,7 +1134,7 @@ type
procedure setItemText(AIndex: Integer; AText: String); overload;
procedure setItemText(AIndex: Integer; AText: String; AAlignment: Integer); overload;
procedure setItemSelected(AItem: QListWidgetItemH; const ASelect: Boolean);
procedure setItemVisible(AItem: QListWidgetItemH; Const AVisible: Boolean);
procedure setItemVisible(AItem: QListWidgetItemH; const AVisible: Boolean);
procedure scrollToItem(row: integer; hint: QAbstractItemViewScrollHint);
procedure removeItem(AIndex: Integer);
function rowCount: integer;
......@@ -8834,6 +8835,13 @@ begin
inherited DetachEvents;
end;
procedure TQtListWidget.InitializeWidget;
begin
inherited InitializeWidget;
// by default horz scrollbars is off. it is set by SetScrollWidth
setScrollBarPolicy(False, QtScrollBarAlwaysOff);
end;
function TQtListWidget.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
cdecl;
var
......
......@@ -113,6 +113,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
......@@ -122,6 +123,7 @@ type
class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetColumnCount(const ACustomListBox: TCustomListBox; ACount: Integer); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean); override;
class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;
class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
......@@ -499,6 +501,15 @@ begin
ARect := Rect(-1,-1,-1,-1);
end;
class function TQtWSCustomListBox.GetScrollWidth(
const ACustomListBox: TCustomListBox): Integer;
var
QtListWidget: TQtListWidget;
begin
QtListWidget := TQtListWidget(ACustomListBox.Handle);
Result := QtListWidget.horizontalScrollBar.getMax;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListBox.GetTopIndex
Params: None
......@@ -564,6 +575,20 @@ begin
TQtListWidget(ACustomListBox.Handle).setCurrentRow(AIndex);
end;
class procedure TQtWSCustomListBox.SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
const
BoolToPolicy: array[Boolean] of QtScrollBarPolicy = (QtScrollBarAlwaysOff, QtScrollBarAlwaysOn);
var
QtListWidget: TQtListWidget;
ClientWidth: Integer;
begin
QtListWidget := TQtListWidget(ACustomListBox.Handle);
QtListWidget.horizontalScrollBar.setMaximum(AScrollWidth);
with QtListWidget.getClientBounds do
ClientWidth := Right - Left;
QtListWidget.ScrollBarPolicy[False] := BoolToPolicy[AScrollWidth > ClientWidth];
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListBox.SetSelectionMode
Params: None
......
......@@ -124,6 +124,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
......@@ -133,6 +134,7 @@ type
class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetColumnCount(const ACustomListBox: TCustomListBox; ACount: Integer); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect,
AMultiSelect: boolean); override;
class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
......@@ -674,6 +676,11 @@ begin
LPARAM(@ARect)) <> LB_ERR;
end;
class function TWin32WSCustomListBox.GetScrollWidth(const ACustomListBox: TCustomListBox): Integer;
begin
Result := Windows.SendMessage(ACustomListBox.Handle, LB_GETHORIZONTALEXTENT, 0, 0);
end;
class function TWin32WSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox): integer;
begin
// GetSelCount only works for multiple-selection listboxes
......@@ -766,6 +773,12 @@ begin
Windows.SendMessage(Handle, LB_SETCURSEL, Windows.WParam(AIndex), 0);
end;
class procedure TWin32WSCustomListBox.SetScrollWidth(
const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
begin
Windows.SendMessage(ACustomListBox.Handle, LB_SETHORIZONTALEXTENT, AScrollWidth, 0);
end;
class procedure TWin32WSCustomListBox.SetSelectionMode(const ACustomListBox: TCustomListBox;
const AExtendedSelect, AMultiSelect: boolean);
begin
......
......@@ -114,6 +114,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
......@@ -123,6 +124,7 @@ type
class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetColumnCount(const ACustomListBox: TCustomListBox; ACount: Integer); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect,
AMultiSelect: boolean); override;
class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
......@@ -499,6 +501,11 @@ begin
LPARAM(@ARect)) <> LB_ERR;
end;
class function TWinCEWSCustomListBox.GetScrollWidth(const ACustomListBox: TCustomListBox): Integer;
begin
Result := Windows.SendMessage(ACustomListBox.Handle, LB_GETHORIZONTALEXTENT, 0, 0);
end;
class function TWinCEWSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox): integer;
begin
// GetSelCount only works for multiple-selection listboxes
......@@ -588,6 +595,12 @@ begin
Windows.SendMessage(Handle, LB_SETCURSEL, Windows.WParam(AIndex), 0);
end;
class procedure TWinCEWSCustomListBox.SetScrollWidth(
const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
begin
Windows.SendMessage(ACustomListBox.Handle, LB_SETHORIZONTALEXTENT, AScrollWidth, 0);
end;
class procedure TWinCEWSCustomListBox.SetSelectionMode(const ACustomListBox: TCustomListBox;
const AExtendedSelect, AMultiSelect: boolean);
begin
......
......@@ -497,13 +497,16 @@ type
FOnDrawItem: TDrawItemEvent;
FOnMeasureItem: TMeasureItemEvent;
FOnSelectionChange: TSelectionChangeEvent;
FScrollWidth: Integer;
FSorted: boolean;
FStyle: TListBoxStyle;
FTopIndex: integer;
function GetCount: Integer;
function GetScrollWidth: Integer;
function GetTopIndex: Integer;
procedure RaiseIndexOutOfBounds(AIndex: integer);
procedure SetColumns(const AValue: Integer);
procedure SetScrollWidth(const AValue: Integer);
procedure SetTopIndex(const AValue: Integer);
procedure UpdateSelectionMode;
procedure UpdateSorted;
......@@ -604,6 +607,7 @@ type
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ScrollWidth: Integer read GetScrollWidth write SetScrollWidth default 0;
property SelCount: integer read GetSelCount;
property Selected[Index: integer]: boolean read GetSelected write SetSelected;
property ShowHint;
......@@ -671,6 +675,7 @@ type
property ParentShowHint;
property ParentFont;
property PopupMenu;
property ScrollWidth;
property ShowHint;
property Sorted;
property Style;
......
......@@ -112,6 +112,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; virtual;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; virtual;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; virtual;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; virtual;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; virtual;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; virtual;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; virtual;
......@@ -123,6 +124,7 @@ type
class procedure SetBorder(const ACustomListBox: TCustomListBox); virtual;
class procedure SetColumnCount(const ACustomListBox: TCustomListBox; ACount: Integer); virtual;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); virtual;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); virtual;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect,
AMultiSelect: boolean); virtual;
class procedure SetStyle(const ACustomListBox: TCustomListBox); virtual;
......@@ -297,6 +299,12 @@ begin
Result:=false;
end;
class function TWSCustomListBox.GetScrollWidth(
const ACustomListBox: TCustomListBox): Integer;
begin
Result := 0;
end;
class function TWSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox): integer;
begin
Result := 0;
......@@ -340,6 +348,12 @@ class procedure TWSCustomListBox.SetItemIndex(const ACustomListBox: TCustomListB
begin
end;
class procedure TWSCustomListBox.SetScrollWidth(
const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
begin
end;
class procedure TWSCustomListBox.SetSelectionMode(const ACustomListBox: TCustomListBox;
const AExtendedSelect, AMultiSelect: boolean);
begin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment