NiceSidebar: Cleanup. Less hints. Tested to work in win32/64, gtk2, gtk3, qt5 and cocoa widget sets.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8866 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
d22992ea64
commit
7c8f15a4bf
@ -562,7 +562,7 @@ object Form1: TForm1
|
||||
000000000000}
|
||||
end
|
||||
object ImageList2: TImageList
|
||||
Left = 256
|
||||
Left = 296
|
||||
Top = 136
|
||||
Bitmap = {
|
||||
494C010107000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
|
||||
|
@ -14,6 +14,9 @@ uses
|
||||
{$ENDIF}
|
||||
SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, StdCtrls, ExtCtrls, NiceSideBar, ImgList;
|
||||
|
||||
// When switching compilation from Delphi XE11 to Delphi 7, the automatically
|
||||
// added unit System.ImageList must be removed manually.
|
||||
|
||||
type
|
||||
|
||||
|
@ -33,6 +33,7 @@ unit NiceSideBar;
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$MODE Delphi}
|
||||
{$WARN 4055 off : Conversion between ordinals and pointers is not portable}
|
||||
{$ENDIF}
|
||||
|
||||
interface
|
||||
@ -43,7 +44,7 @@ uses
|
||||
{$ELSE}
|
||||
Windows, Messages,
|
||||
{$ENDIF}
|
||||
Graphics, SysUtils, Controls, Classes, ImgList, Math,
|
||||
Graphics, SysUtils, Types, Controls, Classes, ImgList, Math,
|
||||
ExtCtrls, Forms;
|
||||
|
||||
const
|
||||
@ -304,7 +305,6 @@ type
|
||||
procedure ClearList;
|
||||
procedure ListChange(RebuildItems: Boolean);
|
||||
procedure DoDrawItem(Index: Integer);
|
||||
procedure InvalidateItem(Index: Integer); // <---
|
||||
function GetIndexAtPos(X, Y: Integer): Integer;
|
||||
function CreateItem: TSideBarItem;
|
||||
procedure UpdateItem(Index: Integer);
|
||||
@ -327,6 +327,7 @@ type
|
||||
procedure DrawSubItem(ACanvas: TCanvas; Rc: TRect; Str: string; States: TSideBarStates); virtual;
|
||||
procedure DrawNonItem(ACanvas: TCanvas; Rc: TRect); virtual;
|
||||
procedure DrawScroller(ACanvas: TCanvas; Rc: TRect; Up: Boolean; Hover: Boolean); virtual;
|
||||
procedure InvalidateItem(Index: Integer); virtual;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
{$IFDEF FPC}
|
||||
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override;
|
||||
@ -412,6 +413,11 @@ const
|
||||
SBITEM_STATE_DISABLED = $00000001;
|
||||
SBITEM_STATE_HIDDEN = $00000004;
|
||||
|
||||
{$HINTS OFF}
|
||||
procedure Unused(const A1);
|
||||
begin
|
||||
end;
|
||||
{$HINTS ON}
|
||||
|
||||
{ TSideBarItem }
|
||||
|
||||
@ -515,16 +521,16 @@ function TSideBarItem.GetItemEnabled(Index: Integer): Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
if (FStates.Count > Index)
|
||||
then Result := (Integer(FStates[Index]) and SBITEM_STATE_DISABLED) = 0;
|
||||
then Result := (NativeUInt(FStates[Index]) and SBITEM_STATE_DISABLED) = 0;
|
||||
end;
|
||||
|
||||
procedure TSideBarItem.SetItemEnabled(Index: Integer; const Value: Boolean);
|
||||
var
|
||||
State: Integer;
|
||||
State: NativeUInt;
|
||||
begin
|
||||
while (FStates.Count <= Index)
|
||||
do FStates.Add(nil);
|
||||
State := Integer(FStates[Index]);
|
||||
State := NativeUInt(FStates[Index]);
|
||||
if Value
|
||||
then State := State and not SBITEM_STATE_DISABLED
|
||||
else State := State or SBITEM_STATE_DISABLED;
|
||||
@ -536,16 +542,16 @@ function TSideBarItem.GetItemVisible(Index: Integer): Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
if (FStates.Count > Index)
|
||||
then Result := (Integer(FStates[Index]) and SBITEM_STATE_HIDDEN) = 0;
|
||||
then Result := (NativeUInt(FStates[Index]) and SBITEM_STATE_HIDDEN) = 0;
|
||||
end;
|
||||
|
||||
procedure TSideBarItem.SetItemVisible(Index: Integer; const Value: Boolean);
|
||||
var
|
||||
State: Integer;
|
||||
State: NativeUInt;
|
||||
begin
|
||||
while (FStates.Count <= Index)
|
||||
do FStates.Add(nil);
|
||||
State := Integer(FStates[Index]);
|
||||
State := NativeUInt(FStates[Index]);
|
||||
if Value
|
||||
then State := State and not SBITEM_STATE_HIDDEN
|
||||
else State := State or SBITEM_STATE_HIDDEN;
|
||||
@ -845,10 +851,6 @@ begin
|
||||
FSubItemIndex := P^.SubIndex;
|
||||
InvalidateItem(LastSubIndex);
|
||||
InvalidateItem(i);
|
||||
{
|
||||
DoDrawItem(LastSubIndex);
|
||||
DoDrawItem(i);
|
||||
}
|
||||
LastSubIndex := i;
|
||||
end;
|
||||
end;
|
||||
@ -864,11 +866,6 @@ begin
|
||||
InvalidateItem(LastIndex);
|
||||
InvalidateItem(LastSubIndex);
|
||||
InvalidateItem(i);
|
||||
{
|
||||
DoDrawItem(LastIndex);
|
||||
DoDrawItem(LastSubIndex);
|
||||
DoDrawItem(i);
|
||||
}
|
||||
LastIndex := i;
|
||||
LastSubIndex := -1;
|
||||
end else
|
||||
@ -886,12 +883,6 @@ begin
|
||||
InvalidateItem(LastSubIndex);
|
||||
InvalidateItem(i);
|
||||
InvalidateItem(i - FSubItemIndex - 1);
|
||||
{
|
||||
DoDrawItem(LastIndex);
|
||||
DoDrawItem(LastSubIndex);
|
||||
DoDrawItem(i);
|
||||
DoDrawItem(i - FSubItemIndex - 1);
|
||||
}
|
||||
LastSubIndex := i;
|
||||
LastIndex := i - FSubItemIndex - 1;
|
||||
end;
|
||||
@ -908,6 +899,7 @@ procedure TNiceSidebar.MouseMove(Shift: TShiftState; X, Y: Integer);
|
||||
var
|
||||
i: Integer;
|
||||
P: PSBInfo;
|
||||
Rc, tmpRc: TRect;
|
||||
begin
|
||||
|
||||
if ScTopVisible then
|
||||
@ -919,10 +911,6 @@ begin
|
||||
HoverIndex := SCTOPINDEX;
|
||||
InvalidateItem(LastHover);
|
||||
InvalidateItem(HoverIndex);
|
||||
{
|
||||
DoDrawItem(LastHover);
|
||||
DoDrawItem(HoverIndex);
|
||||
}
|
||||
LastHover := SCTOPINDEX;
|
||||
end;
|
||||
Exit;
|
||||
@ -938,10 +926,6 @@ begin
|
||||
HoverIndex := SCBOTTOMINDEX;
|
||||
InvalidateItem(LastHover);
|
||||
InvalidateItem(HoverIndex);
|
||||
{
|
||||
DoDrawItem(LastHover);
|
||||
DoDrawItem(HoverIndex);
|
||||
}
|
||||
LastHover := SCBOTTOMINDEX;
|
||||
end;
|
||||
Exit;
|
||||
@ -953,8 +937,8 @@ begin
|
||||
if (i > -1) then
|
||||
begin
|
||||
P := PSBInfo(FList[i]);
|
||||
if (P^.Level = 0) and FAlwaysExpand
|
||||
then i := -1;
|
||||
if (P^.Level = 0) and FAlwaysExpand then
|
||||
i := -1;
|
||||
end;
|
||||
|
||||
if FHandPointCursor then
|
||||
@ -967,15 +951,23 @@ begin
|
||||
if (i <> HoverIndex) then
|
||||
begin
|
||||
HoverIndex := i;
|
||||
if (LastHover >= 0) and (LastHover < FList.Count)
|
||||
then InvalidateItem(LastHover); //DoDrawItem(LastHover);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count) then
|
||||
InvalidateItem(LastHover);
|
||||
if (HoverIndex > -1) then
|
||||
begin
|
||||
InvalidateItem(HoverIndex);
|
||||
//DoDrawItem(HoverIndex);
|
||||
P := PSBInfo(FList[i]);
|
||||
if Assigned(FOnHover)
|
||||
then FOnHover(Self, P^.ItemIndex, P^.SubIndex, P^.Caption);
|
||||
|
||||
Rc := P^.Rc;
|
||||
OffsetRect(Rc, 0, -DeltaY);
|
||||
tmpRc := Rect(0, 0, 0, 0); // To silence the compiler
|
||||
if IntersectRect(tmpRc, ScTop, Rc) then
|
||||
InvalidateItem(SCTOPINDEX);
|
||||
|
||||
if IntersectRect(tmpRc, ScBottom, Rc) then
|
||||
InvalidateItem(SCBOTTOMINDEX);
|
||||
end;
|
||||
LastHover := HoverIndex;
|
||||
end;
|
||||
@ -986,11 +978,12 @@ end;
|
||||
|
||||
procedure TNiceSideBar.CMMouseLeave(var Msg: {$IFDEF FPC}TLMessage{$ELSE}TMessage{$ENDIF});
|
||||
begin
|
||||
Unused(Msg);
|
||||
if (HoverIndex <> -1) then
|
||||
begin
|
||||
HoverIndex := -1;
|
||||
if (LastHover >= 0) and (LastHover < FList.Count)
|
||||
then InvalidateItem(LastHover); //DoDrawItem(LastHover);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count) then
|
||||
InvalidateItem(LastHover);
|
||||
LastHover := -1;
|
||||
end;
|
||||
if Assigned(FOnHover)
|
||||
@ -1076,10 +1069,9 @@ begin
|
||||
BottomIndex := FList.Count-1;
|
||||
ScBottomVisible := False;
|
||||
end;
|
||||
{$IFDEF FPC}
|
||||
delta := Scale96ToFont(12);
|
||||
{$ELSE}
|
||||
delta := 12;
|
||||
{$IFDEF FPC}
|
||||
delta := Scale96ToFont(delta);
|
||||
{$ENDIF}
|
||||
if (FAlignment = saRight) then
|
||||
begin
|
||||
@ -1109,7 +1101,7 @@ begin
|
||||
else
|
||||
begin
|
||||
Info := PSBInfo(FList[Index]);
|
||||
CopyRect(Rc, Info^.Rc);
|
||||
Rc := Info^.Rc;
|
||||
OffsetRect(Rc, 0, -DeltaY);
|
||||
end;
|
||||
InvalidateRect(Handle, @Rc, false);
|
||||
@ -1120,9 +1112,7 @@ var
|
||||
Info: PSBInfo;
|
||||
States: TSideBarStates;
|
||||
Rc, Tmp: TRect;
|
||||
|
||||
begin
|
||||
|
||||
if (Index = SCTOPINDEX) then
|
||||
begin
|
||||
if ScTopVisible then
|
||||
@ -1149,7 +1139,7 @@ begin
|
||||
then Exit;
|
||||
|
||||
Info := PSBInfo(FList[Index]);
|
||||
CopyRect(Rc, Info^.Rc);
|
||||
Rc := Info^.Rc;
|
||||
OffsetRect(Rc, 0, -DeltaY);
|
||||
|
||||
if (Index = HoverIndex)
|
||||
@ -1179,6 +1169,7 @@ begin
|
||||
else DrawItem(Canvas, Rc, Info^.Caption, States, FItems[Info^.ItemIndex].FImageIndex);
|
||||
end;
|
||||
|
||||
Tmp := Rect(0, 0, 0, 0); // to silence the compiler
|
||||
if IntersectRect(Tmp, Rc, ScTop) and ScTopVisible then
|
||||
begin
|
||||
if Assigned(FOnCustomDrawScroller)
|
||||
@ -1208,7 +1199,7 @@ var
|
||||
ppi: Integer;
|
||||
{$ENDIF}
|
||||
begin
|
||||
CopyRect(RcItem, Rc);
|
||||
RcItem := Rc;
|
||||
with ACanvas do
|
||||
begin
|
||||
Brush.Style := bsSolid;
|
||||
@ -1290,6 +1281,10 @@ begin
|
||||
ImgWidth := Img.Width;
|
||||
ImgHeight := Img.Height;
|
||||
{$ENDIF}
|
||||
end else
|
||||
begin
|
||||
ImgWidth := 0;
|
||||
ImgHeight := 0;
|
||||
end;
|
||||
|
||||
w := TextWidth(Str);
|
||||
@ -1335,9 +1330,9 @@ var
|
||||
x, y, w, h, i: Integer;
|
||||
Old: TColor;
|
||||
begin
|
||||
CopyRect(RcItem, Rc);
|
||||
CopyRect(Rc2, Rc);
|
||||
Rc2.Bottom := Rc2.Bottom + 1;
|
||||
RcItem := Rc;
|
||||
Rc2 := Rc;
|
||||
inc(Rc2.Bottom);
|
||||
case FAlignment of
|
||||
saLeft:
|
||||
begin
|
||||
@ -1610,6 +1605,7 @@ end;
|
||||
|
||||
procedure TNiceSideBar.WMSize(var Msg: {$IFDEF FPC}TLMSize{$ELSE}TWMSize{$ENDIF});
|
||||
begin
|
||||
Unused(Msg);
|
||||
TopIndex := 0;
|
||||
ListChange(False);
|
||||
Invalidate;
|
||||
@ -1617,6 +1613,7 @@ end;
|
||||
|
||||
procedure TNiceSidebar.CMColorChanged(var Msg: {$IFDEF FPC}TLMessage{$ELSE}TMessage{$ENDIF});
|
||||
begin
|
||||
Unused(Msg);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
@ -1670,7 +1667,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
InvalidateItem(i);
|
||||
//DoDrawItem(i);
|
||||
end;
|
||||
|
||||
procedure TNiceSideBar.UpdateItems;
|
||||
@ -1721,10 +1717,6 @@ begin
|
||||
begin
|
||||
InvalidateItem(LastIndex);
|
||||
InvalidateItem(LastSubIndex);
|
||||
{
|
||||
DoDrawItem(LastIndex);
|
||||
DoDrawItem(LastSubIndex);
|
||||
}
|
||||
end else
|
||||
begin
|
||||
FItems[FItemIndex].Expand;
|
||||
@ -1734,10 +1726,6 @@ begin
|
||||
begin
|
||||
InvalidateItem(LastIndex);
|
||||
InvalidateItem(LastSubIndex);
|
||||
{
|
||||
DoDrawItem(LastIndex);
|
||||
DoDrawItem(LastSubIndex);
|
||||
}
|
||||
end;
|
||||
|
||||
if IsUpdating then
|
||||
@ -1757,8 +1745,8 @@ begin
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
if Redraw
|
||||
then InvalidateItem(LastIndex); //DoDrawItem(LastIndex);
|
||||
if Redraw then
|
||||
InvalidateItem(LastIndex);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1792,10 +1780,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
InvalidateItem(LastSubIndex);
|
||||
//DoDrawItem(LastSubIndex);
|
||||
LastSubIndex := i;
|
||||
if (i > -1)
|
||||
then InvalidateItem(i); //DoDrawItem(i);
|
||||
if (i > -1) then
|
||||
InvalidateItem(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -2027,14 +2014,12 @@ begin
|
||||
LastHover := TopIndex;
|
||||
HoverIndex := TopIndex;
|
||||
InvalidateItem(HoverIndex);
|
||||
//DoDrawItem(HoverIndex);
|
||||
end else
|
||||
begin
|
||||
HoverIndex := Min(FList.Count-1, HoverIndex + 1);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count)
|
||||
then InvalidateItem(LastHover); //DoDrawItem(LastHover);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count) then
|
||||
InvalidateItem(LastHover);
|
||||
InvalidateItem(HoverIndex);
|
||||
//DoDrawItem(HoverIndex);
|
||||
LastHover := HoverIndex;
|
||||
end;
|
||||
if (HoverIndex >= BottomIndex-1) and ScBottomVisible then
|
||||
@ -2059,14 +2044,12 @@ begin
|
||||
LastHover := BottomIndex;
|
||||
HoverIndex := BottomIndex;
|
||||
InvalidateItem(HoverIndex);
|
||||
//DoDrawItem(HoverIndex);
|
||||
end else
|
||||
begin
|
||||
HoverIndex := Max(0, HoverIndex - 1);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count)
|
||||
then InvalidateItem(LastHover); //DoDrawItem(LastHover);
|
||||
if (LastHover >= 0) and (LastHover < FList.Count) then
|
||||
InvalidateItem(LastHover);
|
||||
InvalidateItem(HoverIndex);
|
||||
//DoDrawItem(HoverIndex);
|
||||
LastHover := HoverIndex;
|
||||
end;
|
||||
end else
|
||||
@ -2075,7 +2058,7 @@ begin
|
||||
if (HoverIndex < TopIndex) or (HoverIndex > BottomIndex)
|
||||
or (HoverIndex < 0) or (HoverIndex >= FList.Count)
|
||||
then Exit;
|
||||
CopyRect(Rc, PSBInfo(FList[HoverIndex])^.Rc);
|
||||
Rc := PSBInfo(FList[HoverIndex])^.Rc;
|
||||
OffsetRect(Rc, 0, -DeltaY);
|
||||
MouseDown(mbLeft, [], Rc.Left + 1, Rc.Top + 1);
|
||||
end;
|
||||
|
@ -24,10 +24,10 @@ uses
|
||||
|
||||
type
|
||||
TNiceSideBarEditor = class(TComponentEditor)
|
||||
protected
|
||||
public
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
function GetVerbCount: Integer; override;
|
||||
function GetVerb(Index: Integer): string; override;
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
end;
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ function TNiceSideBarEditor.GetVerb(Index: Integer): string;
|
||||
begin
|
||||
case Index of
|
||||
0: Result := 'Edit Items ...';
|
||||
1: Result := 'About';
|
||||
1: Result := 'About TNiceSideBar...';
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user