resize a column to multiline in xbrowse

resize a column to multiline in xbrowse

Postby Rick Lipkin » Mon May 23, 2011 9: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: Select all  Expand view  RUN

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 )

 


Image
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Wed May 25, 2011 2:05 am

Please try this suggestion:

Add this code in the ON INIT clause:
Code: Select all  Expand view  RUN
oLbx2:nRowHeight := XbrColMaxHeight( oLbx2:Desc )


Function XbrColMaxHeight( oCol )
Code: Select all  Expand view  RUN

#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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » Wed May 25, 2011 1: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: Select all  Expand view  RUN

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



Image
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Wed May 25, 2011 4:16 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » Wed May 25, 2011 5: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: Select all  Expand view  RUN

*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 :

Image

With blank phantom data at startup and run-time results

Image

Run-time results with blank phantom data :

Image

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
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Thu May 26, 2011 1: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: Select all  Expand view  RUN
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: Select all  Expand view  RUN

SetRowHeight( oLbx2:Desc, aLine[ 3 ] )
AAdd( aResults, aLine )
oLbx2:Refresh()
oLbx2:GoBottom()

 


function:
Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » 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
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » Thu May 26, 2011 3: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

Image
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Thu May 26, 2011 3:40 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » Thu May 26, 2011 4: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

Image
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby Rick Lipkin » Thu May 26, 2011 6: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

Image

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

Image

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

Image

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

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
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: resize a column to multiline in xbrowse

Postby hua » Mon Mar 09, 2015 4: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Mon Mar 09, 2015 6: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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: resize a column to multiline in xbrowse

Postby hua » Mon Mar 09, 2015 8:49 am

This is what I got Rao,
Code: Select all  Expand view  RUN

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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: resize a column to multiline in xbrowse

Postby nageswaragunupudi » Mon Mar 09, 2015 1:37 pm

Ok Thanks.

In the code above, please see the line
Code: Select all  Expand view  RUN
  aRect             := oBrw:DataRect()
 

Please change it as
Code: Select all  Expand view  RUN
  aRect             := oBrw:DataRect():aRect
 

and try.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 12 guests