|
From: Peter T. <pe...@us...> - 2004-05-07 07:18:35
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24639/run Modified Files: JvLabel.pas Log Message: - Replaced LeftMargin/RightMargin with just Margin. Margin also applies to Top/Bottom edges - Drawing of image follows Layout - RoundedFrame now respects Transparent Index: JvLabel.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvLabel.pas,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** JvLabel.pas 6 May 2004 12:01:53 -0000 1.42 --- JvLabel.pas 7 May 2004 07:18:25 -0000 1.43 *************** *** 45,49 **** Known Issues: ! * Images are only displayed in TJvCustomLabel if Angle = 0. -----------------------------------------------------------------------------} // $Id$ --- 45,49 ---- Known Issues: ! * AutoSize calculations aren't correct when RoundedFrame and/or Shadow are active -----------------------------------------------------------------------------} // $Id$ *************** *** 84,89 **** FFocused: Boolean; FDragging: Boolean; ! FLeftMargin: Integer; ! FRightMargin: Integer; FImageIndex: TImageIndex; FImages: TCustomImageList; --- 84,88 ---- FFocused: Boolean; FDragging: Boolean; ! FMargin: Integer; FImageIndex: TImageIndex; FImages: TCustomImageList; *************** *** 101,105 **** FTextEllipsis: TJvTextEllipsis; FFrameColor: TColor; ! FRoundedFrame: Integer; // DS function GetTransparent: Boolean; procedure UpdateTracking; --- 100,104 ---- FTextEllipsis: TJvTextEllipsis; FFrameColor: TColor; ! FRoundedFrame: Integer; // DS function GetTransparent: Boolean; procedure UpdateTracking; *************** *** 107,112 **** procedure SetFocusControl(Value: TWinControl); procedure SetLayout(Value: TTextLayout); ! procedure SetLeftMargin(Value: Integer); ! procedure SetRightMargin(Value: Integer); procedure SetShadowColor(Value: TColor); procedure SetShadowSize(Value: Byte); --- 106,110 ---- procedure SetFocusControl(Value: TWinControl); procedure SetLayout(Value: TTextLayout); ! procedure SetMargin(Value: Integer); procedure SetShadowColor(Value: TColor); procedure SetShadowSize(Value: Byte); *************** *** 119,124 **** procedure SetImages(Value: TCustomImageList); procedure DoImagesChange(Sender: TObject); ! procedure DrawAngleText(var Rect: TRect; Flags: Word; HasImage:boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); procedure SetAngle(Value: TJvLabelRotateAngle); procedure SetHotTrackFont(Value: TFont); --- 117,122 ---- procedure SetImages(Value: TCustomImageList); procedure DoImagesChange(Sender: TObject); ! procedure DrawAngleText(var Rect: TRect; Flags: Word; HasImage: boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); procedure SetAngle(Value: TJvLabelRotateAngle); procedure SetHotTrackFont(Value: TFont); *************** *** 149,152 **** --- 147,151 ---- function GetDefaultFontColor: TColor; virtual; function GetLabelCaption: string; virtual; + function IsValidImage:boolean; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; *************** *** 175,179 **** property AutoSize: Boolean read FAutoSize write SetAutoSize default True; property FocusControl: TWinControl read FFocusControl write SetFocusControl; ! property FrameColor:TColor read FFrameColor write SetFrameColor default clNone; property Images: TCustomImageList read FImages write SetImages; property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1; --- 174,178 ---- property AutoSize: Boolean read FAutoSize write SetAutoSize default True; property FocusControl: TWinControl read FFocusControl write SetFocusControl; ! property FrameColor: TColor read FFrameColor write SetFrameColor default clNone; property Images: TCustomImageList read FImages write SetImages; property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1; *************** *** 182,187 **** property Spacing: Integer read FSpacing write SetSpacing default 4; property Layout: TTextLayout read FLayout write SetLayout default tlTop; ! property LeftMargin: Integer read FLeftMargin write SetLeftMargin default 0; ! property RightMargin: Integer read FRightMargin write SetRightMargin default 0; property RoundedFrame: Integer read FRoundedFrame write SetRoundedFrame default 0; //DS property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnHighlight; --- 181,185 ---- property Spacing: Integer read FSpacing write SetSpacing default 4; property Layout: TTextLayout read FLayout write SetLayout default tlTop; ! property Margin: Integer read FMargin write SetMargin default 0; property RoundedFrame: Integer read FRoundedFrame write SetRoundedFrame default 0; //DS property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnHighlight; *************** *** 224,232 **** property Constraints; property Layout; property ParentColor; property ParentFont; property ParentShowHint; property PopupMenu; ! property RoundedFrame; property ShadowColor; property ShadowSize; --- 222,231 ---- property Constraints; property Layout; + property Margin; property ParentColor; property ParentFont; property ParentShowHint; property PopupMenu; ! property RoundedFrame; property ShadowColor; property ShadowSize; *************** *** 390,400 **** SizeShadow: Byte; ColorShadow: TColor; ! ! function IsValidImage: boolean; ! begin ! Result := (Images <> nil) and (ImageIndex >= 0); ! // and (ImageIndex < Images.Count); ! end; ! begin Text := GetLabelCaption; --- 389,393 ---- SizeShadow: Byte; ColorShadow: TColor; ! X,Y:Integer; begin Text := GetLabelCaption; *************** *** 440,449 **** // (p3) draw image here since it can potentionally change background and font color if IsValidImage and (Flags and DT_CALCRECT = 0) then {$IFDEF VCL} ! Images.Draw(Canvas, 0, (Height - Images.Height) div 2, ImageIndex, Enabled); ! {$ENDIF VCL} ! {$IFDEF VisualCLX} ! Images.Draw(Canvas, 0, (Height - Images.Height) div 2, ImageIndex, itImage, Enabled); ! {$ENDIF VisualCLX} end; --- 433,454 ---- // (p3) draw image here since it can potentionally change background and font color if IsValidImage and (Flags and DT_CALCRECT = 0) then + begin + X := Margin; + case Layout of + tlTop: + Y := Margin; + tlBottom: + Y := Height - Images.Height - Margin; + else + Y := (Height - Images.Height) div 2; + end; + if Y < Margin then Y := Margin; {$IFDEF VCL} ! Images.Draw(Canvas, X, Y, ImageIndex, Enabled); ! {$ENDIF VCL} ! {$IFDEF VisualCLX} ! Images.Draw(Canvas, X, Y, ImageIndex, itImage, Enabled); ! {$ENDIF VisualCLX} ! end; end; *************** *** 499,504 **** {$IFDEF VCL} ! procedure TJvCustomLabel.DrawAngleText(var Rect: TRect; Flags: Word; HasImage:boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); var Text: array[0..4096] of Char; --- 504,509 ---- {$IFDEF VCL} ! procedure TJvCustomLabel.DrawAngleText(var Rect: TRect; Flags: Word; HasImage: boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); var Text: array[0..4096] of Char; *************** *** 536,540 **** w := Rect.Right - Rect.Left; h := Rect.Bottom - Rect.Top; ! TextX := Trunc(0.5 * w - 0.5 * Canvas.TextWidth(Text) * Cos(Phi) - 0.5 * Canvas.TextHeight(Text) * Sin(Phi)); TextY := Trunc(0.5 * h - 0.5 * Canvas.TextHeight(Text) * Cos(Phi) + 0.5 * Canvas.TextWidth(Text) * --- 541,545 ---- w := Rect.Right - Rect.Left; h := Rect.Bottom - Rect.Top; ! TextX := Trunc(0.5 * w - 0.5 * Canvas.TextWidth(Text) * Cos(Phi) - 0.5 * Canvas.TextHeight(Text) * Sin(Phi)); TextY := Trunc(0.5 * h - 0.5 * Canvas.TextHeight(Text) * Cos(Phi) + 0.5 * Canvas.TextWidth(Text) * *************** *** 563,566 **** --- 568,573 ---- if HasImage then Inc(Rect.Right, Images.Width); + Inc(Rect.Right, Margin * 2); + Inc(Rect.Bottom, Margin * 2); end else *************** *** 568,571 **** --- 575,580 ---- if HasImage then Inc(TextX, Images.Width); + Inc(TextX, Margin); + Inc(TextY, Margin); if ShadowSize > 0 then begin *************** *** 574,596 **** case ShadowPos of spLeftTop: ! begin ! Dec(ShadowX, ShadowSize); ! Dec(ShadowY, ShadowSize); ! end; spRightBottom: ! begin ! Inc(ShadowX, ShadowSize); ! Inc(ShadowY, ShadowSize); ! end; spLeftBottom: ! begin ! Dec(ShadowX, ShadowSize); ! Inc(ShadowY, ShadowSize); ! end; spRightTop: ! begin ! Inc(ShadowX, ShadowSize); ! Dec(ShadowY, ShadowSize); ! end; end; Canvas.Font.Color := ShadowColor; --- 583,605 ---- case ShadowPos of spLeftTop: ! begin ! Dec(ShadowX, ShadowSize); ! Dec(ShadowY, ShadowSize); ! end; spRightBottom: ! begin ! Inc(ShadowX, ShadowSize); ! Inc(ShadowY, ShadowSize); ! end; spLeftBottom: ! begin ! Dec(ShadowX, ShadowSize); ! Inc(ShadowY, ShadowSize); ! end; spRightTop: ! begin ! Inc(ShadowX, ShadowSize); ! Dec(ShadowY, ShadowSize); ! end; end; Canvas.Font.Color := ShadowColor; *************** *** 611,616 **** {$IFDEF VisualCLX} ! procedure TJvCustomLabel.DrawAngleText(var Rect: TRect; Flags: Word;HasImage:boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); var Text: array[0..4096] of Char; --- 620,625 ---- {$IFDEF VisualCLX} ! procedure TJvCustomLabel.DrawAngleText(var Rect: TRect; Flags: Word; HasImage: boolean; ! ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition); var Text: array[0..4096] of Char; *************** *** 634,639 **** if not AutoSize then begin ! w := Rect.Right - Rect.Left; ! h := Rect.Bottom - Rect.Top; TextX := Trunc(0.5 * w - 0.5 * Canvas.TextWidth(Text) * Cos(Phi) - 0.5 * Canvas.TextHeight(Text) * Sin(Phi)); --- 643,648 ---- if not AutoSize then begin ! w := Rect.Right - Rect.Left; ! h := Rect.Bottom - Rect.Top; TextX := Trunc(0.5 * w - 0.5 * Canvas.TextWidth(Text) * Cos(Phi) - 0.5 * Canvas.TextHeight(Text) * Sin(Phi)); *************** *** 655,659 **** begin TextX := ClientWidth - 3 - Trunc(Canvas.TextHeight(Text) * Sin(Phi) / 2); - ; TextY := ClientHeight - 3 + Ceil(Canvas.TextHeight(Text) * Cos(Phi)); end --- 664,667 ---- *************** *** 667,676 **** // QPainter_translate(Canvas.Handle, TextX, TextY); // QPainter_rotate(Canvas.Handle, -(Angle {div 2})); ! if CalcRect then ! begin ! Rect.Right := Rect.Left + w; Rect.Bottom := Rect.Top + h; if HasImage then Inc(Rect.Right, Images.Width); end else --- 675,685 ---- // QPainter_translate(Canvas.Handle, TextX, TextY); // QPainter_rotate(Canvas.Handle, -(Angle {div 2})); ! if CalcRect then ! begin ! Rect.Right := Rect.Left + w; Rect.Bottom := Rect.Top + h; if HasImage then Inc(Rect.Right, Images.Width); + InflateRect(Rect, -XOffsetFrame, -YOffsetFrame); end else *************** *** 678,681 **** --- 687,693 ---- if HasImage then Inc(TextX, Images.Width); + Inc(TextX, XOffsetFrame); + Inc(TextY, YOffsetFrame); + if not Enabled then begin *************** *** 687,691 **** else TextOutAngle(Canvas, Angle, TextX, TextY, Text); ! end; finally // QPainter_restore(Canvas.Handle); --- 699,703 ---- else TextOutAngle(Canvas, Angle, TextX, TextY, Text); ! end; finally // QPainter_restore(Canvas.Handle); *************** *** 699,715 **** Rect: TRect; DrawStyle: Integer; begin if not Enabled and not (csDesigning in ComponentState) then FDragging := False; with Canvas do begin ! {$IFDEF VisualCLX} ! Brush.Style := bsSolid; ! {$ENDIF VisualCLX} ! ! if not ((RoundedFrame > 0) and (FrameColor <> clNone)) then ! // if RoundedFrame then Floodfill background ! // only FillRect mode because Transparent is always True on JVCLThemesEnabled ! DrawThemedBackground(Self, Canvas, ClientRect, Self.Color); if FrameColor <> clNone then begin --- 711,727 ---- Rect: TRect; DrawStyle: Integer; + InteriorMargin: integer; begin + InteriorMargin := 0; if not Enabled and not (csDesigning in ComponentState) then FDragging := False; with Canvas do begin ! Canvas.Brush.Color := Color; ! Canvas.Brush.Style := bsSolid; ! if not Transparent and ((RoundedFrame = 0) or (FrameColor = clNone))then ! DrawThemedBackground(Self, Canvas, ClientRect) ! else if Transparent then ! Canvas.Brush.Style := bsClear; if FrameColor <> clNone then begin *************** *** 729,758 **** end; end; - Brush.Style := bsClear; Rect := ClientRect; ! // if Angle <> 0 then ! // DrawAngleText(Rect, DT_EXPANDTABS or DT_WORDBREAK or Alignments[Alignment]) ! // else begin ! // Rect := ClientRect; ! Inc(Rect.Left, FLeftMargin); ! Dec(Rect.Right, FRightMargin); ! InflateRect(Rect, -1, 0); ! DrawStyle := DT_EXPANDTABS or WordWraps[FWordWrap] or Alignments[FAlignment]; ! { Calculate vertical layout } ! if FLayout <> tlTop then ! begin ! DoDrawText(Rect, DrawStyle or DT_CALCRECT); ! Rect.Left := ClientRect.Left + FLeftMargin; ! Rect.Right := ClientRect.Right - FRightMargin; ! // if Images <> nil then ! // Inc(Rect.Left,GetImageWidth + 4); ! if FLayout = tlBottom then ! OffsetRect(Rect, 0, Height - Rect.Bottom) ! else ! OffsetRect(Rect, 0, (Height - Rect.Bottom) div 2); ! end; ! DoDrawText(Rect, DrawStyle); end; if FShowFocus and Assigned(FFocusControl) and FFocused and not (csDesigning in ComponentState) then --- 741,767 ---- end; end; Rect := ClientRect; ! Inc(Rect.Left, Margin + InteriorMargin); ! Dec(Rect.Right, Margin + InteriorMargin); ! Inc(Rect.Top, Margin + InteriorMargin); ! Dec(Rect.Bottom, Margin + InteriorMargin); ! InflateRect(Rect, -1, 0); ! DrawStyle := DT_EXPANDTABS or WordWraps[FWordWrap] or ! Alignments[FAlignment]; ! { Calculate vertical layout } ! if FLayout <> tlTop then begin ! DoDrawText(Rect, DrawStyle or DT_CALCRECT); ! Rect.Left := ClientRect.Left + Margin; ! Rect.Right := ClientRect.Right - Margin; ! Rect.Top := ClientRect.Top + Margin; ! Rect.Bottom := ClientRect.Bottom - Margin; ! // Inc(Rect.Top, YOffsetFrame); ! if FLayout = tlBottom then ! OffsetRect(Rect, 0, Height - Rect.Bottom) ! else ! OffsetRect(Rect, 0, (Height - Rect.Bottom) div 2); end; + DoDrawText(Rect, DrawStyle); if FShowFocus and Assigned(FFocusControl) and FFocused and not (csDesigning in ComponentState) then *************** *** 785,793 **** begin Rect := ClientRect; ! Inc(Rect.Left, FLeftMargin); ! Dec(Rect.Right, FRightMargin); ! InflateRect(Rect, -1, 0); ! DC := GetDC(NullHandle); ! Canvas.Handle := DC; {$IFDEF VisualCLX} Canvas.Start(False); --- 794,800 ---- begin Rect := ClientRect; ! // InflateRect(Rect, -1, 0); ! // DC := GetDC(NullHandle); ! // Canvas.Handle := DC; {$IFDEF VisualCLX} Canvas.Start(False); *************** *** 796,807 **** if Angle = 0 then begin DoDrawText(Rect, DT_EXPANDTABS or DT_CALCRECT or WordWraps[FWordWrap]); ! Dec(Rect.Left, FLeftMargin); ! Inc(Rect.Right, FRightMargin); end else begin ! DrawAngleText(Rect, DT_CALCRECT or DT_EXPANDTABS or DT_WORDBREAK or Alignments[Alignment], (Images <> nil) and (ImageIndex >= 0),0, 0, spLeftTop); ! end; {$IFDEF VisualCLX} finally --- 803,815 ---- if Angle = 0 then begin + InflateRect(Rect, -Margin, -Margin); DoDrawText(Rect, DT_EXPANDTABS or DT_CALCRECT or WordWraps[FWordWrap]); ! InflateRect(Rect, Margin, Margin); ! Inc(Rect.Bottom, Margin); end else begin ! DrawAngleText(Rect, DT_CALCRECT or DT_EXPANDTABS or DT_WORDBREAK or Alignments[Alignment], IsValidImage, 0, 0, spLeftTop); ! end; {$IFDEF VisualCLX} finally *************** *** 809,825 **** end; {$ENDIF VisualCLX} ! Canvas.Handle := NullHandle; ! ReleaseDC(NullHandle, DC); ! InflateRect(Rect, 1, 0); X := Left; AAlignment := FAlignment; if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment); ! if ImageIndex > -1 then Rect.Bottom := Max(Rect.Bottom, Rect.Top + GetImageHeight); ! if (AAlignment = taRightJustify) and (Images = nil) then ! Inc(X, Width - Rect.Right); ! if Images <> nil then ! Dec(Rect.Left, GetImageWidth + Spacing); SetBounds(X, Top, Rect.Right, Rect.Bottom); end; --- 817,834 ---- end; {$ENDIF VisualCLX} ! // Canvas.Handle := NullHandle; ! // ReleaseDC(NullHandle, DC); ! // InflateRect(Rect, 1, 0); X := Left; AAlignment := FAlignment; if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment); ! if IsValidImage then ! begin Rect.Bottom := Max(Rect.Bottom, Rect.Top + GetImageHeight); ! Inc(Rect.Right, GetImageWidth + Spacing); ! end; ! // if (AAlignment = taRightJustify) and not IsValidImage then ! // Inc(X, Width - Rect.Right); SetBounds(X, Top, Rect.Right, Rect.Bottom); end; *************** *** 855,874 **** end; ! procedure TJvCustomLabel.SetLeftMargin(Value: Integer); ! begin ! if FLeftMargin <> Value then ! begin ! FLeftMargin := Max(Value, 0); ! FNeedsResize := true; ! AdjustBounds; ! Invalidate; ! end; ! end; ! ! procedure TJvCustomLabel.SetRightMargin(Value: Integer); begin ! if FRightMargin <> Value then begin ! FRightMargin := Max(Value, 0); FNeedsResize := true; AdjustBounds; --- 864,872 ---- end; ! procedure TJvCustomLabel.SetMargin(Value: Integer); begin ! if FMargin <> Value then begin ! FMargin := Max(Value, 0); FNeedsResize := true; AdjustBounds; *************** *** 1095,1099 **** if FImageIndex <> Value then begin ! if Images <> nil then NonProviderChange; FNeedsResize := true; --- 1093,1097 ---- if FImageIndex <> Value then begin ! if IsValidImage then NonProviderChange; FNeedsResize := true; *************** *** 1133,1137 **** begin Result := 0; ! if not ProviderActive and (Images <> nil) then Result := Images.Height; end; --- 1131,1135 ---- begin Result := 0; ! if not ProviderActive and IsValidImage then Result := Images.Height; end; *************** *** 1166,1170 **** begin Result := 0; ! if not ProviderActive and (Images <> nil) then Result := Images.Width; end; --- 1164,1168 ---- begin Result := 0; ! if not ProviderActive and IsValidImage then Result := Images.Width; end; *************** *** 1207,1211 **** FAngle := Value; if FAngle < 0 then ! Inc(FAngle,360); FNeedsResize := Autosize; AdjustBounds; --- 1205,1209 ---- FAngle := Value; if FAngle < 0 then ! Inc(FAngle, 360); FNeedsResize := Autosize; AdjustBounds; *************** *** 1271,1275 **** if FRoundedFrame <> Value then begin ! // limit range to reasonable values if (Value < Height div 2) and (Value >= 0) then begin --- 1269,1273 ---- if FRoundedFrame <> Value then begin ! // no negative and too hight value if (Value < Height div 2) and (Value >= 0) then begin *************** *** 1280,1287 **** end; - procedure FrameRounded(Canvas: TCanvas; ARect: TRect; AColor: TColor; R: Integer); begin ! // draw frame with rounded corners with Canvas, ARect do begin --- 1278,1284 ---- end; procedure FrameRounded(Canvas: TCanvas; ARect: TRect; AColor: TColor; R: Integer); begin ! // Draw Frame with round corners with Canvas, ARect do begin *************** *** 1291,1303 **** Polygon([ Point(Left + R, Top), ! Point(Right - R, Top), ! Point(Right, Top + R), ! Point(Right, Bottom - R), ! Point(Right - R, Bottom), ! Point(Left + R, Bottom), ! Point(Left, Bottom - R), ! Point(Left, Top + R), ! Point(Left + R, Top) ! ]); Inc(Right); Inc(Bottom); --- 1288,1300 ---- Polygon([ Point(Left + R, Top), ! Point(Right - R, Top), ! Point(Right, Top + R), ! Point(Right, Bottom - R), ! Point(Right - R, Bottom), ! Point(Left + R, Bottom), ! Point(Left, Bottom - R), ! Point(Left, Top + R), ! Point(Left + R, Top) ! ]); Inc(Right); Inc(Bottom); *************** *** 1305,1308 **** --- 1302,1309 ---- end; + function TJvCustomLabel.IsValidImage: boolean; + begin + Result := (Images <> nil) and (ImageIndex >= 0); + end; end. |