// TxClip.CC
// Author.......: Jim Sare - jimsare@worldnet.att.net
// Original.....: 11/09/1998
// Last Modified: 12/14/1998 - Completed implementation of word-wrap
//                             and cleaned up comments.
//
// Purpose......: Text class to be used in reports to enforce
//                text clipping within borderless text object borders
//                when using single-line (Wrap = False) Text objects.
//                Text clipping can be enforced at the word or
//                character level.
//                Text clipping behavior is adjusted based on the
//                current setting of the AlignHorizontal property.
//
// Usage........: SET PROCEDURE TO TxClip.CC Additive
//
//                Use TxClip on your report where you need a borderless,
//                single-line (non-wrapped), clipped text output.
//
//                NOTE: The text will _not_ be clipped when in
//                      the Form Designer, but will be clipped
//                      when you run the report.
//
//                The default clipping action is at the character level.
//                To change the clipping action to the word level, set
//                the WordClip property member = True in the OnOpen event
//                handler of the TxClip object.

CLASS TxClip(f, n) Of Text(f, n) Custom

	this.WordClip =		False
	this.Design =			False


	PROTECT Design

	PROCEDURE OnDesignOpen

		this.Design := True

	FUNCTION CanRender
		LOCAL cSave, nLen, nRAt
		PRIVATE cText
 ? this.hWND

		If this.Design
			RETURN True
		EndIf
		If (Type("this.Text") == "CB") Or (Type("this.Text") == "FP") And;
														(Not Empty(this.Text))
			this.SaveText = this.Text
		EndIf
		cText = IIf(Type("this.SaveText") $ "CB|FP", this.SaveText(), this.Text)
		If Type("cText") # "C"
			cText := Transform(cText, "@T")
		EndIf
		nRat = 1
		nLen = this.GetTextExtent(cText)
		cSave = cText
		Do While nLen > this.Width
			If this.WordClip
				If this.AlignHorizontal = 0
					cText := Left(cText, RAt(" ", cText) - 1)
				ElseIf (this.AlignHorizontal = 1) Or (this.AlignHorizontal = 3)
					If nRat % 2 = 1
						cText := Left(cText, RAt(" ", cText) - 1)
					Else
						cText := SubStr(cText, At(" ", cText) + 1)
					EndIf
				Else
					cText := SubStr(cText, At(" ", cText) + 1)
				EndIf
				If Len(cText) = 0
					cText := Left(cSave, At(" ", cSave) - 1)
					Exit
				EndIf
			Else
				If this.AlignHorizontal = 0
					cText := Left(cText, Len(cText) - 1)
				ElseIf (this.AlignHorizontal = 1) Or (this.AlignHorizontal = 3)
					If nRat % 2 = 1
						cText := Left(cText, Len(cText) - 1)
					Else
						cText := Right(cText, Len(cText) - 1)
					EndIf
				Else
					cText := Right(cText, Len(cText) - 1)
				EndIf
			EndIf
			nLen := this.GetTextExtent(cText)
			nRat += 1
		EndDo
		this.Text := cText
		RETURN True

ENDCLASS  // TxClip Of Text

// EOF: TxClip.CC

