Hello
I would like to show different fonts in the same cell with xbrowse.
I remember seing something like this from Otto, i have searched but couldn't find it
If anyone knows how we can acheive this,
Thanks for the help,
Richard
different fonts in the same cell xbrowse
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Hello Richard,
I changed METHOD PaintData. I send a # as a prefix in my data string.
Then in the paintData method I check if the first character is # if yes I us another font.
It is hardcoded but for my task ok.
Regards,
Otto
IF left(cdata,1)="#"
cLine = SubStr(ExtractLine( cData, @nFrom ),2)
oFont1 := ::oFntGross
oFont1:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
DrawTextEx( hDC, cLine ,;
{nRow, nCol, nRow + oFont1:nHeight(), Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont1:Deactivate( hDC )
cLine = Alltrim(SubStr(cData, nFrom ))
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
//msginfo(oFont:nHeight())
DrawTextEx( hDC, cLine,;
{nRow+oFont1:nHeight(), nCol, nRow +oFont1:nHeight() + (oFont:nHeight())*2 + 5 , Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont:Deactivate( hDC )
else
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
DrawTextEx( hDC, cData,;
{nRow, nCol, nRow + nHeight, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont:Deactivate( hDC )
ENDIF
I changed METHOD PaintData. I send a # as a prefix in my data string.
Then in the paintData method I check if the first character is # if yes I us another font.
It is hardcoded but for my task ok.
Regards,
Otto
IF left(cdata,1)="#"
cLine = SubStr(ExtractLine( cData, @nFrom ),2)
oFont1 := ::oFntGross
oFont1:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
DrawTextEx( hDC, cLine ,;
{nRow, nCol, nRow + oFont1:nHeight(), Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont1:Deactivate( hDC )
cLine = Alltrim(SubStr(cData, nFrom ))
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
//msginfo(oFont:nHeight())
DrawTextEx( hDC, cLine,;
{nRow+oFont1:nHeight(), nCol, nRow +oFont1:nHeight() + (oFont:nHeight())*2 + 5 , Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont:Deactivate( hDC )
else
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
DrawTextEx( hDC, cData,;
{nRow, nCol, nRow + nHeight, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont:Deactivate( hDC )
ENDIF
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Otto's work is very nice. We observe that there are times need is felt to extend the drawing facilities natively provided by XBrowse. It is not always possible to accommodate all such requirements in a general way and even otherwise we may not be able to provide the facility within the time required. This is entailing change of source code. We thought we could make it easier by providing facility to allow the programmer to draw the text in the manner required, when needed.
We have provided a new DATA bPaintText in the TXBrwColumn class. If a codeblock is assigned to this data, this codeblock is called to paint the data in the cell. Details are givien in the Whatsnew.txt.
We give here an example of how to use this facility, in the above case.
Example:
Here is a screenshot of the result:
We welcome comments and feedback
We have provided a new DATA bPaintText in the TXBrwColumn class. If a codeblock is assigned to this data, this codeblock is called to paint the data in the cell. Details are givien in the Whatsnew.txt.
We give here an example of how to use this facility, in the above case.
Example:
Code: Select all
#include 'fivewin.ch'
#include 'xbrowse.ch'
function main()
local oDlg, oBrw
local oFont, oBold, oItalic
local aData := {}
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE FONT oBold NAME 'TAHOMA' SIZE 0,-12 BOLD
DEFINE FONT oItalic NAME 'TAHOMA' SIZE 0,-12 ITALIC
AAdd( aData, { 1, 'Otto ', ;
'Mr.Otto' + CRLF + ;
'deleveloped using multiple fonts in the same cell' } )
AAdd( aData, { 2, 'Richard', ;
"MR.OTTO'S" + CRLF + ;
'work is well appreciated' } )
AAdd( aData, { 3, 'Chidak ', ;
'Mr.Richard Chidak' + CRLF + ;
'also has similar requirement. But needs to change the library' } )
AAdd( aData, { 4, 'Antonio', ;
'FWH' + CRLF + ;
'Provides easier solution for owner drawing data without changing library code' } )
DEFINE DIALOG oDlg SIZE 440,440 PIXEL FONT oFont
@ 10, 10 XBROWSE oBrw ;
HEADERS 'No', 'Name', 'Text' ;
SIZE 200, 200 PIXEL ;
OF oDlg ;
ARRAY aData AUTOCOLS ;
LINES
oBrw:nStretchCol := STRETCHCOL_LAST
WITH OBJECT oBrw:aCols[3]
:nHeadStrAlign := AL_CENTER
:nWidth := 200
:bPaintText := { |oCol, hDC, cText, aCoord| DrawText( oCol, hDC, cText, aCoord, oBold, oItalic ) }
END
oBrw:nDataLines := 6
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
RELEASE FONT oBold
RELEASE FONT oItalic
return nil
static function DrawText( oCol, hDC, cText, aCoord, oBold, oItalic )
local nTop := aCoord[ 1 ], nLeft := aCoord[ 2 ]
local nBottom := aCoord[ 3 ], nRight := aCoord[ 4 ]
local nRow := nTop
local cLine, nFontHt, nAt
nAt := AT( CRLF, cText )
if nAt > 0
cLine := Left( cText, nAt - 1 )
oBold:Activate( hDC )
nFontHt := GetTextHeight( oCol:oBrw:hWnd, hDC )
DrawTextEx( hDC, cLine, { nRow, nLeft, nRow + nFontHt + 4, nRight }, 1 ) //oCol:nDataStyle )
oBold:DeActivate( hDC )
nRow += nFontHt + 4
cLine := SubStr( cText, nAt + 2 )
else
cLine := cText
endif
oItalic:Activate( hDC )
DrawTextEx( hDC, cLine, { nRow, nLeft, nBottom, nRight }, oCol:nDataStyle )
oItalic:DeActivate( hDC )
return nil
We welcome comments and feedback
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact: