different fonts in the same cell xbrowse

different fonts in the same cell xbrowse

Postby Richard Chidiak » Thu Jun 26, 2008 2:19 pm

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
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Silvio » Thu Jun 26, 2008 2:21 pm

Ask to Otto
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby Otto » Thu Jun 26, 2008 2:54 pm

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
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby Richard Chidiak » Thu Jun 26, 2008 6:30 pm

Otto

Thank you

Richard :)
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Antonio Linares » Fri Jun 27, 2008 4:25 pm

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:
Code: Select all  Expand view
#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


Here is a screenshot of the result:
Image

We welcome comments and feedback
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Fri Jun 27, 2008 5:51 pm

Antonio,

Very impressive!

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests