?? bsbuttongroup.pas
字號:
NewLTPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewCLRect,
LeftBitMap, TopBitMap, RightBitMap, BottomBitMap,
FSkinPicture, SkinRect, Width, Height, False, False, False, False);
end;
if NewClRect.Bottom > NewClRect.Top
then
ExcludeClipRect(Cnvs.Handle,
NewClRect.Left, NewClRect.Top, NewClRect.Right, NewClRect.Bottom);
Cnvs.Draw(0, 0, TopBitMap);
Cnvs.Draw(0, TopBitMap.Height, LeftBitMap);
Cnvs.Draw(Width - RightBitMap.Width, TopBitMap.Height, RightBitMap);
Cnvs.Draw(0, Height - BottomBitMap.Height, BottomBitMap);
//
TopBitMap.Free;
LeftBitMap.Free;
RightBitMap.Free;
BottomBitMap.Free;
Cnvs.Handle := 0;
ReleaseDC(Handle, DC);
Cnvs.Free;
end;
procedure TbsSkinButtonGroup.WMSIZE;
begin
inherited;
if FShowBorder then PaintBorder;
end;
procedure TbsSkinButtonGroup.WMNCCALCSIZE;
var
PanelData: TbsDataSkinPanelControl;
CIndex: Integer;
begin
if FShowBorder
then
begin
if (SkinData <> nil) and (not SkinData.Empty) and
(SkinData.GetControlIndex('panel') <> -1)
then
begin
CIndex := SkinData.GetControlIndex('panel');
PanelData := TbsDataSkinPanelControl(SkinData.CtrlList[CIndex]);
with PanelData, TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0] do
begin
Inc(Left, ClRect.Left);
Inc(Top, ClRect.Top);
Dec(Right, RectWidth(SkinRect) - ClRect.Right);
Dec(Bottom, RectHeight(SkinRect) - ClRect.Bottom);
if Right < Left then Right := Left;
if Bottom < Top then Bottom := Top;
end;
end
else
begin
with TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0] do
begin
Inc(Left, 2);
Inc(Top, 2);
Dec(Right, 2);
Dec(Bottom, 2);
if Right < Left then Right := Left;
if Bottom < Top then Bottom := Top;
end;
end;
end
else
inherited;
end;
procedure TbsSkinButtonGroup.WMEraseBkgnd;
begin
if not FromWMPaint
then
PaintWindow(Message.DC);
end;
procedure TbsSkinButtonGroup.SetShowBorder;
begin
if FShowBorder <> Value
then
begin
FShowBorder := Value;
RecreateWnd;
end;
end;
function TbsSkinButtonGroup.CreateButton: TbsGrpButtonItem;
begin
Result := GetButtonClass.Create(FButtonItems);
end;
procedure TbsSkinButtonGroup.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
end;
destructor TbsSkinButtonGroup.Destroy;
begin
if FSkinScrollBar <> nil then FSkinScrollBar.Free;
FSkinScrollBar := nil;
FDragImageList.Free;
FButtonItems.Free;
FImageChangeLink.Free;
inherited;
end;
function TbsSkinButtonGroup.GetButtonClass: TbsGrpButtonItemClass;
begin
Result := TbsGrpButtonItem;
end;
function TbsSkinButtonGroup.GetButtonRect(const Index: Integer): TRect;
var
ButtonsPerRow: Integer;
HiddenCount: Integer;
Item: Integer;
Row, Col: Integer;
begin
ButtonsPerRow := CalcButtonsPerRow;
HiddenCount := FHiddenItems*ButtonsPerRow;
{ Subtract out what we can't see }
Item := Index - HiddenCount;
Row := Item div ButtonsPerRow;
Result.Top := Row*FButtonHeight;
if bsgboFullSize in FButtonOptions then
begin
Result.Left := 0;
Result.Right := ClientWidth - GetScrollSize;
end
else
begin
Col := Item mod ButtonsPerRow;
Result.Left := Col*FButtonWidth;
Result.Right := Result.Left + FButtonWidth;
end;
Result.Bottom := Result.Top + FButtonHeight;
end;
function TbsSkinButtonGroup.GetButtonsClass: TbsGrpButtonItemsClass;
begin
Result := TbsGrpButtonItems;
end;
procedure TbsSkinButtonGroup.ImageListChange(Sender: TObject);
begin
UpdateAllButtons;
end;
procedure TbsSkinButtonGroup.Notification(AComponent: TComponent;
Operation: TOperation);
var
I: Integer;
begin
inherited;
if (Operation = opRemove) then
begin
if AComponent = Images then
Images := nil
else
if AComponent is TBasicAction then
for I := 0 to FButtonItems.Count - 1 do
if AComponent = FButtonItems[I].Action then
FButtonItems[I].Action := nil;
end;
end;
procedure TbsSkinButtonGroup.Paint;
procedure DrawSkinBGRect(R: TRect);
var
PanelData: TbsDataSkinPanelControl;
w, h, X, Y, XCnt, YCnt: Integer;
Buffer: TBitMap;
FSkinPicture: TBitMap;
begin
PanelData := TbsDataSkinPanelControl(SkinData.CtrlList[SkinData.GetControlIndex('panel')]);
Buffer := TBitMap.Create;
with PanelData do
begin
FSkinPicture := TBitMap(SkinData.FActivePictures.Items[PictureIndex]);
Buffer.Width := RectWidth(ClRect);
Buffer.Height := RectHeight(ClRect);
Buffer.Canvas.CopyRect(Rect(0, 0, Buffer.Width, Buffer.Height),
FSkinPicture.Canvas,
Rect(SkinRect.Left + ClRect.Left, SkinRect.Top + ClRect.Top,
SkinRect.Left + ClRect.Right,
SkinRect.Top + ClRect.Bottom));
w := RectWidth(ClRect);
h := RectHeight(ClRect);
XCnt := RectWidth(R) div w;
YCnt := RectHeight(R) div h;
for X := 0 to XCnt do
for Y := 0 to YCnt do
Canvas.Draw(X * w + R.Left, Y * h + R.Top, Buffer);
end;
Buffer.Free;
end;
var
ButtonCount: Integer;
RowsSeen, ButtonsPerRow: Integer;
HiddenCount, VisibleCount: Integer;
CurOffset: TPoint;
RowPos: Integer;
X: Integer;
ItemRect: TRect;
ActualWidth, ActualHeight: Integer;
DrawState: TbsButtonDrawState;
begin
//
Canvas.Brush.Color := clBtnFace;
//
ButtonCount := FButtonItems.Count;
if ButtonCount > 0 then
begin
RowsSeen := CalcRowsSeen;
ButtonsPerRow := CalcButtonsPerRow;
HiddenCount := FHiddenItems * ButtonsPerRow;
VisibleCount := RowsSeen*ButtonsPerRow;
if (HiddenCount + VisibleCount) > ButtonCount then
VisibleCount := ButtonCount - HiddenCount; { We can see more items than we have }
CurOffset.X := 0; { Start at the very top left }
CurOffset.Y := 0;
RowPos := 0;
if bsgboFullSize in ButtonOptions then
ActualWidth := ClientWidth - GetScrollSize
else
ActualWidth := FButtonWidth;
ActualHeight := FButtonHeight;
for X := HiddenCount to HiddenCount + VisibleCount - 1 do
begin
ItemRect := Bounds(CurOffset.X, CurOffset.Y, ActualWidth, ActualHeight);
DrawState := [];
if X = FHotIndex then
begin
Include(DrawState, bsbdsHot);
if X = FDownIndex then
Include(DrawState, bsbdsDown);
end;
if X = FItemIndex then
Include(DrawState, bsbdsSelected);
if X = FInsertTop then
Include(DrawState, bsbdsInsertTop)
else if X = FInsertBottom then
Include(DrawState, bsbdsInsertBottom)
else if X = FInsertRight then
Include(DrawState, bsbdsInsertRight)
else if X = FInsertLeft then
Include(DrawState, bsbdsInsertLeft);
if (X = FFocusIndex) and Focused then
Include(DrawState, bsbdsFocused);
DrawButton(X, Canvas, ItemRect, DrawState);
Inc(RowPos);
{ Should we go to the next line? }
if RowPos >= ButtonsPerRow then
begin
{ Erase to the end }
Inc(CurOffset.X, ActualWidth);
if (SkinData <> nil) and (not Skindata.Empty) and
(SkinData.GetControlIndex('panel') <> -1)
then
DrawSkinBGRect(Rect(CurOffset.X, CurOffset.Y, ClientWidth - GetScrollSize,
CurOffset.Y + ActualHeight))
else
DoFillRect(Rect(CurOffset.X, CurOffset.Y, ClientWidth - GetScrollSize,
CurOffset.Y + ActualHeight));
RowPos := 0;
CurOffset.X := 0;
Inc(CurOffset.Y, ActualHeight);
end
else
Inc(CurOffset.X, ActualWidth);
end;
{ Erase to the end }
if (SkinData <> nil) and (not Skindata.Empty) and
(SkinData.GetControlIndex('panel') <> -1)
then
DrawSkinBGRect(Rect(CurOffset.X, CurOffset.Y,
ClientWidth - GetScrollSize, CurOffset.Y + ActualHeight))
else
DoFillRect(Rect(CurOffset.X, CurOffset.Y,
ClientWidth - GetScrollSize, CurOffset.Y + ActualHeight));
{ Erase to the bottom }
if (SkinData <> nil) and (not Skindata.Empty) and
(SkinData.GetControlIndex('panel') <> -1)
then
DrawSkinBGRect(Rect(0, CurOffset.Y + ActualHeight, ClientWidth - GetScrollSize, ClientHeight))
else
DoFillRect(Rect(0, CurOffset.Y + ActualHeight, ClientWidth - GetScrollSize, ClientHeight));
end
else
begin
if (SkinData <> nil) and (not Skindata.Empty) and
(SkinData.GetControlIndex('panel') <> -1)
then
DrawSkinBGRect(Rect(0, 0, ClientWidth - GetScrollSize, ClientHeight))
else
DoFillRect(ClientRect);
end;
end;
function TbsSkinButtonGroup.CalcButtonsPerRow: Integer;
begin
if bsgboFullSize in ButtonOptions then
Result := 1
else
begin
Result := (ClientWidth - GetScrollSize) div FButtonWidth;
if Result = 0 then
Result := 1;
end;
end;
function TbsSkinButtonGroup.CalcRowsSeen: Integer;
begin
Result := ClientHeight div FButtonHeight
end;
procedure TbsSkinButtonGroup.Resize;
var
RowsSeen: Integer;
ButtonsPerRow: Integer;
TotalRowsNeeded: Integer;
ScrollInfo: TScrollInfo;
begin
inherited;
{ Reset the original position }
FHiddenItems := 0;
{ How many rows can we show? }
RowsSeen := CalcRowsSeen;
ButtonsPerRow := CalcButtonsPerRow;
{ Do we have to take the scrollbar into consideration? }
if (ButtonsPerRow*RowsSeen < FButtonItems.Count) then
begin
TotalRowsNeeded := FButtonItems.Count div ButtonsPerRow;
if FButtonItems.Count mod ButtonsPerRow <> 0 then
Inc(TotalRowsNeeded);
if TotalRowsNeeded > RowsSeen then
FPageAmount := RowsSeen
else
FPageAmount := TotalRowsNeeded;
{ Adjust the max to NOT contain the page amount }
FScrollBarMax := TotalRowsNeeded - FPageAmount;
ScrollInfo.cbSize := SizeOf(TScrollInfo);
ScrollInfo.fMask := SIF_RANGE or SIF_POS or SIF_PAGE;
ScrollInfo.nMin := 0;
ScrollInfo.nMax := TotalRowsNeeded - 1;
ScrollInfo.nPos := 0;
ScrollInfo.nPage := FPageAmount;
if FSkinScrollBar = nil
then
begin
ShowSkinScrollBar(True);
end;
FSkinScrollBar.SetRange(ScrollInfo.nMin, ScrollInfo.nMax,
ScrollInfo.nPos, ScrollInfo.nPage);
end
else
begin
if FSkinScrollBar <> nil
then
ShowSkinScrollBar(False);
end;
end;
procedure TbsSkinButtonGroup.SetButtonHeight(const Value: Integer);
begin
if FButtonHeight <> Value then
begin
FButtonHeight := Value;
UpdateAllButtons;
end;
end;
procedure TbsSkinButtonGroup.SeTbsGrpButtonItems(const Value: TbsGrpButtonItems);
begin
FButtonItems.Assign(Value);
end;
procedure TbsSkinButtonGroup.SetGrpButtonOptions(const Value: TbsGrpButtonOptions);
begin
if FButtonOptions <> Value then
begin
FButtonOptions := Value;
if not (bsgboGroupStyle in FButtonOptions) then
FItemIndex := -1;
if HandleAllocated then
begin
Resize;
UpdateAllButtons;
end;
end;
end;
procedure TbsSkinButtonGroup.SetButtonWidth(const Value: Integer);
begin
if FButtonWidth <> Value then
begin
FButtonWidth := Value;
UpdateAllButtons;
end;
end;
procedure TbsSkinButtonGroup.SetImages(const Value: TCustomImageList);
begin
if Images <> Value then
begin
if Images <> nil then
Images.UnRegisterChanges(FImageChangeLink);
FImages := Value;
if Images <> nil then
begin
Images.RegisterChanges(FImageChangeLink);
Images.FreeNotification(Self);
end;
UpdateAllButtons;
end;
end;
procedure TbsSkinButtonGroup.SetItemIndex(const Value: Integer);
var
OldIndex: Integer;
begin
if (FItemIndex <> Value) and (bsgboGroupStyle in ButtonOptions) then
begin
OldIndex := FItemIndex;
{ Assign the index before painting }
FItemIndex := Value;
FFocusIndex := Value; { Assign it to the focusl item too }
UpdateButton(OldIndex);
UpdateButton(FItemIndex);
end;
end;
const
cScrollBarKind = SB_VERT;
procedure TbsSkinButtonGroup.UpdateAllButtons;
begin
Invalidate;
end;
procedure TbsSkinButtonGroup.UpdateButton(const Index: Integer);
var
R: TRect;
begin
{ Just invalidate one button's rect }
if Index >= 0 then
begin
R := GetButtonRect(Index);
InvalidateRect(Handle, @R, False);
end;
end;
procedure TbsSkinButtonGroup.ScrollPosChanged(ScrollCode: TScrollCode;
ScrollPos: Integer);
var
OldPos: Integer;
begin
OldPos := FHiddenItems;
if (ScrollCode = scLineUp) and (FHiddenItems > 0) then
Dec(FHiddenItems)
else if (ScrollCode = scLineDown) and (FHiddenItems < FScrollBarMax) then
Inc(FHiddenItems)
else if (ScrollCode = scPageUp) then
begin
Dec(FHiddenItems, FPageAmount);
if FHiddenItems < 0 then
FHiddenItems := 0;
end
else if ScrollCode = scPageDown then
begin
Inc(FHiddenItems, FPageAmount);
if FHiddenItems > FScrollBarMax then
FHiddenItems := FScrollBarMax;
end
else if ScrollCode in [scPosition, scTrack] then
FHiddenItems := ScrollPos
else if ScrollCode = scTop then
FHiddenItems := 0
else if ScrollCode = scBottom then
FHiddenItems := FScrollBarMax;
if OldPos <> FHiddenItems then
begin
if FSkinScrollBar <> nil
then
FSkinScrollBar.SetRange(FSkinScrollBar.Min,
FSkinScrollBar.Max, FHiddenItems, FSkinScrollBar.PageSize);
Invalidate;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -