From: Andreas H. <ah...@us...> - 2005-05-11 23:20:57
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17375/run Modified Files: JvTabBar.pas Log Message: ScrollButtons are now painted by the TabBarPainter Index: JvTabBar.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvTabBar.pas,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** JvTabBar.pas 5 May 2005 20:11:32 -0000 1.27 --- JvTabBar.pas 11 May 2005 23:20:45 -0000 1.28 *************** *** 60,63 **** --- 60,65 ---- TJvTabBarOrientation = (toTop, toBottom); + TJvTabBarScrollButtonKind = (sbScrollLeft, sbScrollRight); + TJvTabBarScrollButtonState = (sbsHidden, sbsNormal, sbsHot, sbsPressed, sbsDisabled); TJvGetModifiedEvent = procedure(Sender: TJvTabBarItem; var Modified: Boolean) of object; *************** *** 170,174 **** end; ! TJvTabBarPainterOptionType = (poPaintsHotTab); TJvTabBarPainterOptions = set of TJvTabBarPainterOptionType; --- 172,176 ---- end; ! TJvTabBarPainterOptionType = (poPaintsHotTab, poBottomScrollButtons); TJvTabBarPainterOptions = set of TJvTabBarPainterOptionType; *************** *** 187,190 **** --- 189,196 ---- function GetCloseRect(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect): TRect; virtual; abstract; function Options: TJvTabBarPainterOptions; virtual; abstract; + + procedure DrawScrollButton(Canvas: TCanvas; TabBar: TJvCustomTabBar; Button: TJvTabBarScrollButtonKind; + State: TJvTabBarScrollButtonState; R: TRect); virtual; + procedure GetScrollButtons(TabBar: TJvCustomTabBar; var LeftButton, RightButton: TRect); {virtual; reserved for future use } end; *************** *** 267,270 **** --- 273,277 ---- TJvTabBarSelectingEvent = procedure(Sender: TObject; Item: TJvTabBarItem; var AllowSelect: Boolean) of object; TJvTabBarClosingEvent = procedure(Sender: TObject; Item: TJvTabBarItem; var AllowClose: Boolean) of object; + TJvTabBarScrollButtonClickEvent = procedure(Sender: TObject; Button: TJvTabBarScrollButtonKind) of object; TJvCustomTabBar = class(TCustomControl) *************** *** 300,311 **** FRequiredWidth: Integer; FBarWidth: Integer; ! FBtnLeftScroll: TSpeedButton; ! FBtnRightScroll: TSpeedButton; ! FBmpLeftScroll: TBitmap; ! FBmpRightScroll: TBitmap; FHint: TCaption; FFlatScrollButtons: Boolean; FAllowTabMoving: Boolean; FOrientation: TJvTabBarOrientation; function GetLeftTab: TJvTabBarItem; --- 307,322 ---- FRequiredWidth: Integer; FBarWidth: Integer; ! FBtnLeftScroll: TJvTabBarScrollButtonState; ! FBtnRightScroll: TJvTabBarScrollButtonState; ! FBtnLeftScrollRect: TRect; ! FBtnRightScrollRect: TRect; ! FBtnLeftScrollExState: Boolean; ! FBtnRightScrollExState: Boolean; ! FScrollButtonBackground: TBitmap; FHint: TCaption; FFlatScrollButtons: Boolean; FAllowTabMoving: Boolean; FOrientation: TJvTabBarOrientation; + FOnScrollButtonClick: TJvTabBarScrollButtonClickEvent; function GetLeftTab: TJvTabBarItem; *************** *** 321,325 **** procedure SetClosingTab(Tab: TJvTabBarItem); procedure UpdateScrollButtons; - function GetScrollBarGlyph(Left: Boolean): TBitmap; function FindSelectableTab(Tab: TJvTabBarItem): TJvTabBarItem; procedure SetHint(const Value: TCaption); --- 332,335 ---- *************** *** 328,335 **** --- 338,347 ---- procedure SetOrientation(const Value: TJvTabBarOrientation); protected + procedure DrawScrollBarGlyph(Canvas: TCanvas; X, Y: Integer; Left, Disabled: Boolean); procedure Resize; override; procedure CalcTabsRects; procedure Paint; override; procedure PaintTab(Canvas: TCanvas; Tab: TJvTabBarItem); virtual; + procedure PaintScrollButtons; function GetTabWidth(Tab: TJvTabBarItem): Integer; *************** *** 345,349 **** procedure Changed; virtual; procedure ImagesChanged(Sender: TObject); virtual; ! procedure ScrollButtonClicked(Sender: TObject); virtual; procedure DragOver(Source: TObject; X: Integer; Y: Integer; --- 357,361 ---- procedure Changed; virtual; procedure ImagesChanged(Sender: TObject); virtual; ! procedure ScrollButtonClick(Button: TJvTabBarScrollButtonKind); virtual; procedure DragOver(Source: TObject; X: Integer; Y: Integer; *************** *** 351,354 **** --- 363,370 ---- procedure DragCanceled; override; + function ScrollButtonsMouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer): Boolean; virtual; + function ScrollButtonsMouseUp(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer): Boolean; virtual; + function ScrollButtonsMouseMove(Shift: TShiftState; X: Integer; Y: Integer): Boolean; virtual; + procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override; *************** *** 359,362 **** --- 375,379 ---- {$ENDIF VCL} {$IFDEF VisualCLX} + procedure InitWidget; override; procedure MouseLeave(AControl: TControl); override; {$ENDIF VisualCLX} *************** *** 403,406 **** --- 420,424 ---- property OnTabSelected: TJvTabBarItemEvent read FOnTabSelected write FOnTabSelected; property OnChange: TNotifyEvent read FOnChange write FOnChange; + property OnScrollButtonClick: TJvTabBarScrollButtonClickEvent read FOnScrollButtonClick write FOnScrollButtonClick; end; *************** *** 514,518 **** begin inherited Create(AOwner); ! ControlStyle := ControlStyle - [csAcceptsControls]; FTabs := TJvTabBarItems.Create(Self, TJvTabBarItem); --- 532,536 ---- begin inherited Create(AOwner); ! ControlStyle := ControlStyle - [csAcceptsControls, csOpaque]; FTabs := TJvTabBarItems.Create(Self, TJvTabBarItem); *************** *** 543,548 **** FChangeLink.Free; FreeAndNil(FTabs); ! FreeAndNil(FBmpLeftScroll); ! FreeAndNil(FBmpRightScroll); inherited Destroy; end; --- 561,565 ---- FChangeLink.Free; FreeAndNil(FTabs); ! FreeAndNil(FScrollButtonBackground); inherited Destroy; end; *************** *** 569,612 **** end; ! function TJvCustomTabBar.GetScrollBarGlyph(Left: Boolean): TBitmap; const ! W = 6; ! H = 6; var Pts: array [0..2] of TPoint; begin ! if Left then ! Result := FBmpLeftScroll ! else ! Result := FBmpRightScroll; ! ! if not Assigned(Result) then ! begin ! Result := TBitmap.Create; ! Result.Width := 8; ! Result.Height := 8; if Left then begin ! Pts[0] := Point(W div 2 + 1, 0); ! Pts[1] := Point(W div 2 + 1, H); ! Pts[2] := Point(0 + 1, H div 2); end else begin ! Pts[0] := Point(W div 2 - 1, 0); ! Pts[1] := Point(W div 2 - 1, H); ! Pts[2] := Point(W - 1, H div 2); end; ! Result.Canvas.Brush.Style := bsSolid; ! Result.Canvas.Brush.Color := clBlack; ! Result.Canvas.Pen.Color := Result.Canvas.Brush.Color; ! Result.Canvas.Polygon(Pts) ! end; ! if Left then ! FBmpLeftScroll := Result ! else ! FBmpRightScroll := Result; end; --- 586,648 ---- end; ! procedure TJvCustomTabBar.DrawScrollBarGlyph(Canvas: TCanvas; X, Y: Integer; Left, Disabled: Boolean); ! ! procedure OffsetPt(var Pt: TPoint; X, Y: Integer); ! begin ! Pt := Point(Pt.X + X, Pt.Y + Y); ! end; ! const ! W = 4; ! H = 7; var Pts: array [0..2] of TPoint; + Brush: TBrush; + Pen: TPen; begin ! Brush := TBrush.Create; ! Pen := TPen.Create; ! try ! Brush.Assign(Canvas.Brush); ! Pen.Assign(Canvas.Pen); if Left then begin ! Pts[0] := Point(X + W - 1, Y + 0); ! Pts[1] := Point(X + W - 1, Y + H - 1); ! Pts[2] := Point(X + 0, Y + (H - 1) div 2); end else begin ! Pts[0] := Point(X + 0, Y + 0); ! Pts[1] := Point(X + 0, Y + H - 1); ! Pts[2] := Point(X + W - 1, Y + (H - 1) div 2); end; ! Canvas.Brush.Style := bsSolid; ! if Disabled then ! begin ! Canvas.Brush.Color := clWhite; ! OffsetPt(Pts[0], 1, 1); ! OffsetPt(Pts[1], 1, 1); ! OffsetPt(Pts[2], 1, 1); ! end ! else ! Canvas.Brush.Color := clBlack; ! Canvas.Pen.Color := Canvas.Brush.Color; ! Canvas.Polygon(Pts); ! if Disabled then ! begin ! Canvas.Brush.Color := clGray; ! OffsetPt(Pts[0], -1, -1); ! OffsetPt(Pts[1], -1, -1); ! OffsetPt(Pts[2], -1, -1); ! Canvas.Pen.Color := Canvas.Brush.Color; ! Canvas.Polygon(Pts); ! end; ! finally ! Canvas.Pen.Assign(Pen); ! Canvas.Brush.Assign(Brush); ! end; end; *************** *** 889,892 **** --- 925,934 ---- {$IFDEF VisualCLX} + procedure TJvCustomTabBar.InitWidget; + begin + inherited InitWidget; + QWidget_setBackgroundMode(Handle, QWidgetBackgroundMode_NoBackground); // reduces flicker + end; + procedure TJvCustomTabBar.MouseLeave(AControl: TControl); begin *************** *** 902,905 **** --- 944,950 ---- LastSelected: TJvTabBarItem; begin + if ScrollButtonsMouseDown(Button, Shift, X, Y) then + Exit; + if Button = mbLeft then begin *************** *** 933,936 **** --- 978,984 ---- Tab: TJvTabBarItem; begin + if ScrollButtonsMouseUp(Button, Shift, X, Y) then + Exit; + try if RightClickSelect and not Assigned(PopupMenu) and (Button = mbRight) then *************** *** 968,972 **** NewHint: TCaption; begin ! CalcTabsRects; Tab := TabAt(X, Y); if HotTracking and ([ssLeft, ssMiddle, ssRight] * Shift = []) then --- 1016,1023 ---- NewHint: TCaption; begin ! CalcTabsRects; // maybe inefficent ! if ScrollButtonsMouseMove(Shift, X, Y) then ! Exit; ! Tab := TabAt(X, Y); if HotTracking and ([ssLeft, ssMiddle, ssRight] * Shift = []) then *************** *** 998,1001 **** --- 1049,1158 ---- end; + function TJvCustomTabBar.ScrollButtonsMouseDown(Button: TMouseButton; + Shift: TShiftState; X, Y: Integer): Boolean; + + function HandleButton(Kind: TJvTabBarScrollButtonKind; var State: TJvTabBarScrollButtonState; + X, Y: Integer; const R: TRect): Boolean; + begin + Result := PtInRect(R, Point(X, Y)); + case State of + sbsNormal, sbsHot: + begin + if Result then + begin + State := sbsPressed; + PaintScrollButtons; + end; + end; + end; + end; + + begin + Result := False; + if (FBtnLeftScroll <> sbsHidden) then + Result := HandleButton(sbScrollLeft, FBtnLeftScroll, X, Y, FBtnLeftScrollRect); + if (FBtnRightScroll <> sbsHidden) then + Result := HandleButton(sbScrollRight, FBtnRightScroll, X, Y, FBtnRightScrollRect); + end; + + function TJvCustomTabBar.ScrollButtonsMouseMove(Shift: TShiftState; X, Y: Integer): Boolean; + + function HandleButton(var ExState: Boolean; var State: TJvTabBarScrollButtonState; + X, Y: Integer; const R: TRect): Boolean; + begin + Result := PtInRect(R, Point(X, Y)); + case State of + sbsNormal: + begin + if Result then + begin + State := sbsHot; + PaintScrollButtons; + Result := True; + end; + end; + sbsPressed: + begin + if not Result then + begin + ExState := True; + State := sbsNormal; + PaintScrollButtons; + State := sbsPressed; + end + else + begin + if ExState then + begin + ExState := False; + PaintScrollButtons; + end; + end; + end; + sbsHot: + begin + if not Result then + begin + State := sbsNormal; + PaintScrollButtons; + end; + end; + end; + end; + + begin + Result := False; + if (FBtnLeftScroll <> sbsHidden) then + Result := HandleButton(FBtnLeftScrollExState, FBtnLeftScroll, X, Y, FBtnLeftScrollRect); + if (FBtnRightScroll <> sbsHidden) then + Result := HandleButton(FBtnRightScrollExState, FBtnRightScroll, X, Y, FBtnRightScrollRect); + end; + + function TJvCustomTabBar.ScrollButtonsMouseUp(Button: TMouseButton; + Shift: TShiftState; X, Y: Integer): Boolean; + + function HandleButton(Kind: TJvTabBarScrollButtonKind; var State: TJvTabBarScrollButtonState; + X, Y: Integer; const R: TRect): Boolean; + begin + Result := PtInRect(R, Point(X, Y)); + case State of + sbsPressed: + begin + State := sbsNormal; + PaintScrollButtons; + if Result then + ScrollButtonClick(Kind); + end; + end; + end; + + begin + Result := False; + if (FBtnLeftScroll <> sbsHidden) then + Result := HandleButton(sbScrollLeft, FBtnLeftScroll, X, Y, FBtnLeftScrollRect); + if (FBtnRightScroll <> sbsHidden) then + Result := HandleButton(sbScrollRight, FBtnRightScroll, X, Y, FBtnRightScrollRect); + end; + procedure TJvCustomTabBar.SetHotTab(Tab: TJvTabBarItem); begin *************** *** 1066,1072 **** end; - type - TSpeedButtonAccess = class(TSpeedButton); - procedure TJvCustomTabBar.Paint; var --- 1223,1226 ---- *************** *** 1081,1091 **** Bmp.Height := ClientHeight; CurrentPainter.DrawBackground(Bmp.Canvas, Self, ClientRect); ! if Assigned(FBtnLeftScroll) and Assigned(FBtnRightScroll) then begin ! // paint scroll button's background and the buttons R := Rect(FBarWidth, 0, Bmp.Width, Bmp.Height); ! Canvas.CopyRect(R, Bmp.Canvas, R); ! TSpeedButtonAccess(FBtnLeftScroll).Paint; ! TSpeedButtonAccess(FBtnRightScroll).Paint; if FBarWidth > 0 then Bmp.Width := FBarWidth; --- 1235,1247 ---- Bmp.Height := ClientHeight; CurrentPainter.DrawBackground(Bmp.Canvas, Self, ClientRect); ! if (FBtnLeftScroll <> sbsHidden) and (FBtnRightScroll <> sbsHidden) then begin ! if not Assigned(FScrollButtonBackground) then ! FScrollButtonBackground := TBitmap.Create; ! FScrollButtonBackground.Width := Bmp.Width - FBarWidth; ! FScrollButtonBackground.Height := Bmp.Height; R := Rect(FBarWidth, 0, Bmp.Width, Bmp.Height); ! FScrollButtonBackground.Canvas.CopyRect(Rect(0, 0, FScrollButtonBackground.Width, R.Bottom), Bmp.Canvas, R); ! PaintScrollButtons; if FBarWidth > 0 then Bmp.Width := FBarWidth; *************** *** 1122,1125 **** --- 1278,1292 ---- end; + procedure TJvCustomTabBar.PaintScrollButtons; + begin + if not Assigned(FScrollButtonBackground) and Visible then + Paint + else + // paint scroll button's background and the buttons + Canvas.Draw(FBarWidth, 0, FScrollButtonBackground); + CurrentPainter.DrawScrollButton(Canvas, Self, sbScrollLeft, FBtnLeftScroll, FBtnLeftScrollRect); + CurrentPainter.DrawScrollButton(Canvas, Self, sbScrollRight, FBtnRightScroll, FBtnRightScrollRect); + end; + function TJvCustomTabBar.GetTabHeight(Tab: TJvTabBarItem): Integer; begin *************** *** 1137,1141 **** Pt: TPoint; begin ! if not Assigned(FBtnLeftScroll) or (X < FBarWidth) then begin CalcTabsRects; --- 1304,1308 ---- Pt: TPoint; begin ! if (FBtnLeftScroll = sbsHidden) or (X < FBarWidth) then begin CalcTabsRects; *************** *** 1212,1215 **** --- 1379,1383 ---- procedure TJvCustomTabBar.UpdateScrollButtons; const + State: array[Boolean] of TJvTabBarScrollButtonState = (sbsDisabled, sbsNormal); BtnSize = 12; begin *************** *** 1218,1223 **** (FLastTabRight <= ClientWidth)) then begin ! FreeAndNil(FBtnLeftScroll); ! FreeAndNil(FBtnRightScroll); FLeftIndex := 0; FBarWidth := ClientWidth; --- 1386,1391 ---- (FLastTabRight <= ClientWidth)) then begin ! FBtnLeftScroll := sbsHidden; ! FBtnRightScroll := sbsHidden; FLeftIndex := 0; FBarWidth := ClientWidth; *************** *** 1226,1257 **** else begin ! if not Assigned(FBtnLeftScroll) then begin ! FBtnLeftScroll := TSpeedButton.Create(Self); ! FBtnLeftScroll.Caption := ''; ! FBtnLeftScroll.Flat := FlatScrollButtons; ! FBtnLeftScroll.Parent := Self; ! FBtnLeftScroll.OnClick := ScrollButtonClicked; ! FBtnLeftScroll.Glyph := GetScrollBarGlyph(True); ! end; ! if not Assigned(FBtnRightScroll) then begin ! FBtnRightScroll := TSpeedButton.Create(Self); ! FBtnRightScroll.Caption := ''; ! FBtnRightScroll.Flat := FlatScrollButtons; ! FBtnRightScroll.Parent := Self; ! FBtnRightScroll.OnClick := ScrollButtonClicked; ! FBtnRightScroll.Glyph := GetScrollBarGlyph(False); end; ! FBtnLeftScroll.SetBounds(ClientWidth - BtnSize * 2 - 1 - 1, ! ClientHeight - BtnSize - 2, BtnSize, BtnSize); ! FBtnRightScroll.SetBounds(ClientWidth - BtnSize - 1 - 1, ! ClientHeight - BtnSize - 2, BtnSize, BtnSize); ! FBarWidth := FBtnLeftScroll.Left - 2; ! FBtnLeftScroll.Enabled := FLeftIndex > 0; ! FBtnRightScroll.Enabled := FLastTabRight > ClientWidth; end; end; --- 1394,1423 ---- else begin ! FBtnLeftScroll := sbsNormal; ! FBtnRightScroll := sbsNormal; ! ! if poBottomScrollButtons in CurrentPainter.Options then begin ! FBtnLeftScrollRect := Bounds(ClientWidth - BtnSize * 2 - 1 - 1, ! ClientHeight - BtnSize - 2, BtnSize, BtnSize); ! FBtnRightScrollRect := Bounds(FBtnLeftScrollRect.Right, ! ClientHeight - BtnSize - 2, BtnSize, BtnSize); ! end ! else begin ! FBtnLeftScrollRect := Bounds(ClientWidth - BtnSize * 2 - 1 - 1, 2, BtnSize, BtnSize); ! FBtnRightScrollRect := Bounds(FBtnLeftScrollRect.Right, 2, BtnSize, BtnSize); end; + if not FlatScrollButtons then + OffsetRect(FBtnRightScrollRect, -1, 0); ! //CurrentPainter.GetScrollButtons(Self, FBtnLeftScrollRect, FBtnRightScrollRect); ! FBarWidth := FBtnLeftScrollRect.Left - 2; ! FBtnLeftScroll := State[FLeftIndex > 0]; ! FBtnRightScroll := State[FLastTabRight >= ClientWidth]; ! ! PaintScrollButtons; end; end; *************** *** 1263,1275 **** end; ! procedure TJvCustomTabBar.ScrollButtonClicked(Sender: TObject); begin ! if Sender = FBtnLeftScroll then Dec(FLeftIndex) else ! if Sender = FBtnRightScroll then Inc(FLeftIndex); UpdateScrollButtons; Invalidate; end; --- 1429,1443 ---- end; ! procedure TJvCustomTabBar.ScrollButtonClick(Button: TJvTabBarScrollButtonKind); begin ! if Button = sbScrollLeft then Dec(FLeftIndex) else ! if Button = sbScrollRight then Inc(FLeftIndex); UpdateScrollButtons; Invalidate; + if Assigned(FOnScrollButtonClick) then + FOnScrollButtonClick(Self, Button); end; *************** *** 1330,1335 **** begin FFlatScrollButtons := Value; ! FreeAndNil(FBtnLeftScroll); ! FreeAndNil(FBtnRightScroll); UpdateScrollButtons; end; --- 1498,1503 ---- begin FFlatScrollButtons := Value; ! FBtnLeftScroll := sbsHidden; ! FBtnRightScroll := sbsHidden; UpdateScrollButtons; end; *************** *** 1667,1670 **** --- 1835,1863 ---- end; + procedure TJvTabBarPainter.GetScrollButtons(TabBar: TJvCustomTabBar; var LeftButton, RightButton: TRect); + begin + { reserved for future use } + end; + + procedure TJvTabBarPainter.DrawScrollButton(Canvas: TCanvas; TabBar: TJvCustomTabBar; Button: TJvTabBarScrollButtonKind; + State: TJvTabBarScrollButtonState; R: TRect); + begin + {$IFDEF VCL} + if TabBar.FlatScrollButtons then + DrawButtonFace(Canvas, R, 1, bsNew, False, State = sbsPressed, False) + else + DrawButtonFace(Canvas, R, 1, bsWin31, False, State = sbsPressed, False); + {$ENDIF VCL} + {$IFDEF VisualCLX} + DrawButtonFace(Canvas, R, 1, State = sbsPressed, False, TabBar.FlatScrollButtons); + {$ENDIF VisualCLX} + if State = sbsPressed then + OffsetRect(R, 1, 1); + TabBar.DrawScrollBarGlyph(Canvas, + R.Left + (R.Right - R.Left - 4) div 2, + R.Top + (R.Bottom - R.Top - 7) div 2, + Button = sbScrollLeft, State = sbsDisabled); + end; + //=== { TJvModernTabBarPainter } ============================================= |