FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour resize a column to multiline in xbrowse
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
resize a column to multiline in xbrowse
Posted: Mon May 23, 2011 09:16 PM
To All

I have an ( second browse ) xbrowse that I would like to fit a long array field into a column and allow the column to word wrap into multi-line and resize the row to the depth of the deepest column ..

Thanks
Rick Lipkin

Code (fw): Select all Collapse
DEFINE BRUSH oBrush FILENAME (cDEFA+"\grey.bmp" )
DEFINE ICON oICO RESOURCE "WORLD"

DEFINE DIALOG oGRPS RESOURCE "VENDOR" ;
       ICON oICO                   ;
       TITLE cTITLE BRUSH oBrush TRANSPARENT

   REDEFINE xBROWSE oLBX1                ;
       RECORDSET oRsWeb                  ;
       COLUMNS "Run_This",               ;
               "URL"                     ;
       COLSIZES 30,200                   ;
       HEADERS "Run",                    ;
               "Web Site to Search"      ;
       ID 111 of oGrps                   ;
       AUTOSORT FASTEDIT LINES CELL

       oLbx1:bClrRowFocus    := { || { CLR_BLACK, RGB(185,220,255) } }
       oLbx1:nMarqueeStyle   := MARQSTYLE_HIGHLROWMS

       if ! Empty( oCol := oLbx1:oCol( "Run" ) )
            oCol:SetCheck( { "ON", "OFF" } )
            oCol:cSortOrder  := nil
          //  oCol:lBmpStretch = .T.
       endif

       AEVAL( oLbx1:aCols, { |o| o:nEditType := EDIT_GET } )

       * COLSIZES 30,30,30,100,30,30       ;

   // resize the row ( multi-line ) on this xbrowse listbox when desc
   // is wider than the column 

   REDEFINE xBROWSE oLBX2                ;
       ARRAY aResults                    ;
       COLUMNS 1,2,3,4,5,6               ;
       HEADERS "Site",                   ;
               "Part",                   ;
               "Name",                   ;
               "Desc",                   ;
               "Price",                  ;
               "Qty"                     ;
       ID 121 of oGrps                   ;
       AUTOSORT AUTOCOLS FASTEDIT LINES CELL

   REDEFINE BUTTON oBTN1 ID 112 of oGrps  //    ;    // add files
    *   ACTION ( _FileView("A"),;
    *            oLBX1:REFRESH(), SysReFresh(),;
    *            oLBX1:SetFocus() )

   REDEFINE BUTTON oBTN2 ID 114 of oGrps  //  ;    // edit files
     *  ACTION ( _FileView( "E"), ;
     *           oLBX1:REFRESH(), SysReFresh(),;
     *           oLBX1:SetFocus() )

   REDEFINE BUTTON oBTN3 ID 119 of oGrps  //  ;    // del files
     *  ACTION ( Delete_Um() )


   REDEFINE BUTTON oBTN10 ID 124 of oGrps  // ;    // view log file
    *   ACTION ( WaitRun( "NOTEPAD.EXE ERRORLOG.TXT" ) )

   REDEFINE BUTTON oBTN5 ID 117 of oGrps  //  ;    // run
    *   ACTION ( _RunDist( cNAME ) )

   REDEFINE BUTTON oBTN6 ID 118 of oGrps    ;    // quit
       ACTION ( dbCloseAll(), ;
                oGrps:END() )

ACTIVATE DIALOG oGrps NOWAIT          ;
       ON INIT( oLbx1:SetFocus(), .F. );
       VALID ( IIF( !lOK, ExitPgm(.T., oRsWeb), .F. ))


RETURN( NIL )


Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Wed May 25, 2011 02:05 AM
Please try this suggestion:

Add this code in the ON INIT clause:
Code (fw): Select all Collapse
oLbx2:nRowHeight := XbrColMaxHeight( oLbx2:Desc )


Function XbrColMaxHeight( oCol )
Code (fw): Select all Collapse
#define DT_WORDBREAK                0x00000010
#define DT_CALCRECT                 0x00000400

function XbrColMaxHeight( oCol )

   local oBrw, hDC
   local nLeft, nHeight, nRight, nWidth
   local cData, oFont, aRect
   local uSave, nMaxHeight

   oBrw              := oCol:oBrw
   nMaxHeight        := 0
   nLeft             := oCol:nDisplayCol
   nRight            := Min( nLeft + oCol:nWidth, ::BrwWidth() - 5 )
   if nRight - nLeft < 10
      return oBrw:nRowHeight
   endif

   hDC               := oBrw:GetDC()
   oFont             := If( ValType( oCol:oDataFont ) == 'B', Eval( oCol:oDataFont ), oCol:oDataFont )
   oFont:Activate( hDC )
   aRect             := oBrw:DataRect()
   aRect[ 2 ]        := nLeft
   aRect[ 4 ]        := nRight
   uSave             := oBrw:BookMark
   oBrw:GoTop()

   REPEAT

      cData          := Trim( cValToChar( Eval( oCol:bStrData ) ) )
      if ! Empty( cData )
         nMaxHeight  := Max( DrawTextEx( hDC, cData, aRect, nOr( DT_CALCRECT, DT_WORDBREAK ) ), ;
                             nMaxHeight )
      endif
      // not handling bitmap width, indent, if any.

   UNTIL oBrw:Skip( 1 ) != 1

   oBrw:BookMark     := uSave

return nMaxHeight

I have not tested. Please check for any minor errors and test.
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Wed May 25, 2011 01:27 PM
Rao

Thank you for your help .. I did get an error on line 207 ..

Application
===========
Path and name: C:\Fox\WebCrawl\WebCrawl.Exe (32 bits)
Size: 2,065,920 bytes
Time from start: 0 hours 0 mins 3 secs
Error occurred at: 05/25/2011, 09:17:12
Error description: Error BASE/1003 Variable does not exist: SELF
Args:

Stack Calls
===========
Called from: SEARCH.PRG => XBRCOLMAXHEIGHT(207)
Called from: SEARCH.PRG => (b)_SEARCH(125)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:INITIATE(705)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(912)
Called from: => DIALOGBOX(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
Called from: SEARCH.PRG => _SEARCH(125)
Called from: main.prg => (b)MAIN(210)
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:CLICK(445)
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:LBUTTONUP(631)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1469)
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:HANDLEEVENT(1295)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE(966)
Called from: main.prg => MAIN(261)

Code (fw): Select all Collapse
ACTIVATE DIALOG oGrps ; //NOWAIT          ;
       ON INIT(oLbx2:nRowHeight := XbrColMaxHeight( oLbx2:Desc ),oParts:Setfocus(),SysReFresh() );
       VALID ( IIF( !lOK, ExitPgm(.T., oRsWeb, @aResults ), .F. ))



Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Wed May 25, 2011 04:16 PM

Please change
::BrwWidth()
as
oBrw:BrwWidth()

Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Wed May 25, 2011 05:23 PM
Rao

What I am trying to do is take the Desc column and be able to 'word wrap' the text within the column width which will then force the entire row depth to be re-evaluated.

Since the oLbx2 xBrowse is an array .. I had to create a blank ( phantom ) record when my program starts. Upon execution the array rows are deleted and re-populated as the program runs.

I tried your code two ways .. creating a 'phantom' record with bogus information and one with blanks :

Code (fw): Select all Collapse
*AAdd( aResults,{"www.google.com ","130794 ",;
*                "We stock the most popular fast moving engines, but often we can't keep up",;
*                "$44.95 ","see shipping tab" } )

AAdd( aResults, {"   ","   ",;
                 space(200),;
                 "   ","   " })


With phantom startup data :



With blank phantom data at startup and run-time results



Run-time results with blank phantom data :



If it is possible to create a Desc column that breaks a long string and wrap it into multiple lines within the column .. then re-size the row to the depth of the column ..

Don't know if this can be done ?

Thanks
Rick Lipkin
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 01:19 AM
Don't know if this can be done ?


This can be done.

To start with, define the browse in the normal way. Please also assign column widths appropriately.

Before adding a line, read the line in to an array aLine.

Example:
Code (fw): Select all Collapse
aLine := {"www.google.com ","130794 ",;
               "We stock the most popular fast moving engines, but often we can't keep up",;
                "$44.95 ","see shipping tab" }


Then, call the function:
Code (fw): Select all Collapse
SetRowHeight( oLbx2:Desc, aLine[ 3 ] )
AAdd( aResults, aLine )
oLbx2:Refresh()
oLbx2:GoBottom()


function:
Code (fw): Select all Collapse
function SetRowHeight( oCol, cData )

   static nOrglHeight

   local oBrw     := oCol:oBrw
   local hDC, oFont, aRect, nHeight

   DEFAULT nOrglHeight := oBrw:nRowHeight

   if PCount() < 2
      if oBrw:nRowHeight != nOrglHeight
         oBrw:nRowHeight   := nOrglHeight
         oBrw:Refresh()
      endif
      return nil
   endif

   hDC            := oBrw:GetDC()
   oFont          := If( ValType( oCol:oDataFont ) == 'B', Eval( oCol:oDataFont ), oCol:oDataFont )
   oFont:Activate( hDC )
   aRect             := oBrw:DataRect()
   aRect[ 4 ]     := aRect[ 2 ] + oCol:nWidth
   nHeight        := DrawTextEx( hDC, cData, aRect, nOr( DT_CALCRECT, DT_WORDBREAK ) )
   oFont:DeActivate( hDC )
   oBrw:ReleaseDC()

   if nHeight > oBrw:nRowHeight
      oBrw:nRowHeight   := nHeight
   endif


return nil


If and when you want to empty the entire array, first call SetRowHeight( oLbx:Desc ) [ only one parameter] and then ASize( aResults, 0 ), oBrw:Refresh( .t. )
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 12:17 PM

Rao

Thank you for your diligence .. just looking at the code .. I did not see where the Desc text will line wrap within the confines of the pre-determined width of the column ??

Let me apply your code and see how it works !

Again, thank you !
Rick Lipkin

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 03:05 PM
Rao

Your code works great for setting the depth ot the row .. I did have to find the references for DT_CALCRECT and DT_WORDBREAK ( in \bcc55\include\winuser.h ) .. I just added the two lines :

#define DT_CALCRECT 0x00000200
#define DT_WORDBREAK 0x00000010

Unfortunately the text in the column does not wrap .. however the depth of the row seems to be correct ..

As always your incite is VERY welcome!

Rick

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 03:40 PM

After creating the browse,
please add oBrw:Desc:cDataType := "M"

Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 04:06 PM
Rao

PERFECT .. my next task is show the picture of the part .. the link to the picture is in the DOM .. I will either try to capture the link to the pic and try to execute it in another xbrowse column ( no clue yet ) or download the pic and display it as I crawl thru each web site.

Thanks
Rick

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: resize a column to multiline in xbrowse
Posted: Thu May 26, 2011 06:25 PM
Rao

One unexpected side effect .. as I am looping thru my table gathering results .. the first row has a small Desc and returns perfect



The second loop generated a large Desc and returns an adjusted row



Unfortunately .. all the rows have been adjusted to the last column width



Your suggestions are perfect .. but it appears I will need a codeblock that will eval each row and re-size the browse at run-time somewhere here in this code ?

Code (fw): Select all Collapse
REDEFINE xBROWSE oLBX2                ;
       ARRAY aResults                    ;
       COLUMNS 1,2,3,4,5                 ;
       COLSIZES 150,70,300,70,50         ;
       HEADERS "Site",                   ;
               "Part",                   ;
               "Desc",                   ;
               "Price",                  ;
               "Qty"                     ;
       ID 121 of oGrps                   ;
       AUTOSORT AUTOCOLS FASTEDIT LINES CELL

       oLbx2:Desc:cDataType := "M"


Thanks again for all your HELP !

Rick Lipkin
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: resize a column to multiline in xbrowse
Posted: Mon Mar 09, 2015 04:10 AM

Rao,

When I try your XbrColMaxHeight() function, I always get 1 for DrawTextEx( hDC, cData, aRect, nOr( DT_CALCRECT, DT_WORDBREAK ) ) eventhough cData does contains varying length of strings. How to fix this?

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Mon Mar 09, 2015 06:11 AM

Just before using DrawTextEx() function write to log file values of hDC, cData and aRect and verify if they are valid values.

You may use
FWLOG hDC, cData, aRect
You can see the results in <exename>.log

Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: resize a column to multiline in xbrowse
Posted: Mon Mar 09, 2015 08:49 AM
This is what I got Rao,
Code (fw): Select all Collapse
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchase transactions which disregarded under GST legislation (e.g. purchase within GST group registration)]   aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Imports under special scheme with no GST incurred (e.g. Approved Trader Scheme, ATMS Scheme).] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchase from non GST-registered supplier with no GST incurred.]   aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchase transactions which is out of the scope of GST legislation (e.g. purchase of goods overseas).] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchase from GST-registered supplier with no GST incurred. (e.g. supplier provides transportation of goods that qualify as international services).]  aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Any adjustment made to Input Tax e.g.: Bad Debt Relief & other input tax adjustment.]  aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchases with GST incurred but not claimable (Disallowance of Input Tax) (e.g. medical expenses for staff).]  aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [GST incurred for import of goods.] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchases with GST incurred at 6% and directly attributable to taxable supplies.]  aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [GST incurred directly attributable to incidental exempt supplies.] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [GST incurred directly attributable to non-incidental exempt supplies.] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [GST incurred that is not directly attributable to taxable or exempt supplies.] aRect = TRECT   
09/03/2015 16:45:26: XBRCOLMAXHEIGHT( 843 ) hDC = 755048059 cData = [Purchases exempted from GST. E.g. purchase of residential property or financial services.] aRect = TRECT


Thank you very much for your assistance.
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: resize a column to multiline in xbrowse
Posted: Mon Mar 09, 2015 01:37 PM
Ok Thanks.

In the code above, please see the line
Code (fw): Select all Collapse
   aRect             := oBrw:DataRect()

Please change it as
Code (fw): Select all Collapse
   aRect             := oBrw:DataRect():aRect

and try.
Regards



G. N. Rao.

Hyderabad, India