xBrowse, how to add / change Images in structure browser ?

xBrowse, how to add / change Images in structure browser ?

Postby ukoenig » Fri Sep 03, 2010 7:43 pm

Hello,

is it possible, to add / change Images inside the Record-Browser in Sample < xBrstru.prg > ?
It would make it much easier for me, to display Settings from a Record of the Project-dbf
Maybe something to include for automaticly Image-Detection.
Sample : all Fieldnames starting with "BTN_" are Bitmaps. Any idea ?

Image

The Structure-Browser :
Code: Select all  Expand view

STATIC FUNCTION MakeStruBrowse( oDlg )
LOCAL oBrw, nMaxWidth   := 0

oBrw := TXBrowse():new( oDlg )

WITH OBJECT oBrw
      :nTop      := INT(HGT/2)+5
      :nLeft     := 10
      :nBottom   := HGT-10
      :nRight    := WID-10

      :SetArray( CUST->( dbStruct() ), .f. )

END

ASIZE( oBrw:aCols, 4 )
AEVAL( oBrw:aArrayData, { |a| nMaxWidth := Max( nMaxWidth, a[3] ) } )
WITH OBJECT oBrw:AddCol()
      :bStrData   := ;
      :bEditvalue := { || PADR( cValToChar( CUST->( FieldGet( oBrw:nArrayAt ) ) ), nMaxWidth ) }
      :nEditType  := EDIT_GET
      :bOnPostEdit:= { | oCol, xValue, nLastKey | OnEdit( oCol, xValue, nLastKey ) }
END
AEval( oBrw:aCols, { |oCol, nCol| oCol:cHeader := { "FldName", "Typ", "Len", "Dec","Value" }[ nCol ] } )

// needed => oCol:cHeader := { "FldName", "Typ", "Len", "Dec","IMAGE", "Value" }[ nCol ] } )

oBrw:aCols[ 1 ]:nWidth           := 80
oBrw:aCols[ 3 ]:nDataStrAlign    := AL_RIGHT
oBrw:aCols[ 4 ]:nDataStrAlign    := AL_RIGHT
oBrw:nColSel   := 5

oBrw:lUpdate   := .t.

SetBrwStyle( oBrw )
oBrw:CreateFromCode()

RETURN ( oBrw )
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: xBrowse, how to add / change Images in structure browser ?

Postby nageswaragunupudi » Sat Sep 04, 2010 6:30 am

Sample program:
Can be compiled and run in a folder containing fwh sample dbf, customer.dbf. Please change define BMPPATH to your bitmaps path.

Code: Select all  Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

#define BS CHR(92)
#define BMPPATH "c:" + BS + "fwh" + BS + "bitmaps" + BS + "AlphaBmp" + BS

function Main()

   local oDlg, oBrw, oFont

   SET DATE ITALIAN
   SET CENTURY ON

   RDDSetDefault( 'DBFCDX' )

   PrepareData()

   USE CUSTBMP NEW ALIAS CUST SHARED

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 500,480 PIXEL FONT oFont TITLE "DB STRUCTURE"

   @ 15,10 XBROWSE oBrw SIZE -10,-30 PIXEL OF oDlg ;
      COLUMNS 1,2,3,4 ;
      HEADERS 'FldName', 'Typ', 'Len', 'Dec' ;
      ARRAY CUST->( DbStruct() ) ;
      LINES CELL FASTEDIT NOBORDER

   ADD TO oBrw TITLE 'Image' ;
      DATA { || If( oBrw:FldName:Value = 'BTN_',BMPPATH + CUST->(FieldGet(oBrw:nArrayAt)),'' ) } ;
      WIDTH 40
   oBrw:Image:cDataType := 'F'

   ADD TO oBrw TITLE 'Field Value' ;
      DATA { |x| If( x == nil,CUST->(FieldGet(oBrw:nArrayAt)), ;
                   (CUST->(FieldPut(oBrw:nArrayAt,x)),x ) ) } ;
      EDITABLE

   WITH OBJECT oBrw
      :nStretchCol   := STRETCHCOL_LAST
      :nColSel       := 6
      :bLock         := { || CUST->(RLOCK()) }
      :nRowHeight    := 30
   END
   oBrw:CreateFromCode()

   @ oDlg:nHeight/2 - 22,10 BUTTON 'Prev' SIZE 40,12 PIXEL OF oDlg ;
      WHEN ( CUST->( RecNo() ) > 1 ) ;
      ACTION ( CUST->(DbSkip(-1)), oBrw:aEvalWhen(), oBrw:Refresh(), oBrw:SetFocus() )

   @ oDlg:nHeight/2 - 22,55 BUTTON 'Next' SIZE 40,12 PIXEL OF oDlg ;
      WHEN ( CUST->( RecNo() < LastRec() ) ) ;
      ACTION ( CUST->(DbSkip()), oBrw:aEvalWhen(), oBrw:Refresh(), oBrw:SetFocus() )

   @ oDlg:nHeight/2 - 22,oDlg:nWidth/2-50 BUTTON 'Close' SIZE 40,12 PIXEL OF oDlg ;
      ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )
   RELEASE FONT oFont

return nil

static function PrepareData

   local aDir, n, m
   local aCols := { ;
      { 'ZIP',      'C', 10,  0 }, ;
      { 'HIREDATE', 'D',  8,  0 }, ;
      { 'MARRIED',  'L',  1,  0 }, ;
      { 'AGE',      'N',  2,  0 }, ;
      { 'SALARY',   'N', 10,  2 }, ;
      { 'BTN_IMG1', 'C', 15,  0 }, ;
      { 'BTN_IMG2', 'C', 15,  0 }, ;
      { 'BTN_IMG3', 'C', 15,  0 }, ;
      { 'BTN_IMG4', 'C', 15,  0 }, ;
      { 'BTN_IMG5', 'C', 15,  0 }, ;
      { 'BTN_IMG6', 'C', 15,  0 }  }

   DbCreate( 'CUSTBMP', aCols, 'DBFCDX', .t., 'CUST' )

   APPEND FROM CUSTOMER FIELDS ZIP,HIREDATE,MARRIED,AGE,SALARY ;
      WHILE RECNO() <= 10

   aDir  := Directory( BMPPATH + "*.bmp" )
   GO TOP
   m  := 0
   do while !eof()
      for n := 1 to 6
         FieldPut( n + 5, cFileNoPath( aDir[ m + n ][ 1 ]) )
      next n
      m  += 6
      if m > Len( aDir ) - 6
         m  := 0
      endif
      skip
   enddo

   CLOSE DATA

return nil
 

Screenshot:
Image


1. If a column's bEditValue ealuates to a valid image file name and if that file exists and if that column's cDataType is set to 'F', xbrowse reads the image of that file and shows the image in the column, if necessary shrinking its size to fit the cell size.

2. Since a long time FWH deprecated the use of bStrData directly and stongly recommends not to directly assign any codeblock to bStrData. It is better to leave it to XBrowse to handle internally, though for backward compatibility with many years old software, xbrowse still respects direct assignment.

3. Let bEditValue return the original values with its own native datatype. Then XBrowse determines the appropriate alignment, picture clause, etc.

4. XBrowse automatically aligns numeric values to righr and character values to left. We need not assign alignment value, unless we want to center the display or want to show numerics left aligned or character values right aligned.

5. From version 10.8 onwards it is possible to assign values to all the columns in one single line. Example:
Code: Select all  Expand view

oBrw:cHeaders := { "FldName", "Typ", "Len", "Dec","IMAGE", "Value" }
 

Pleae note the assignment is "plural". cHeaderS not cHeader.

6. In case of arrays, XBrowse traverses the entire array and caluculate the maximum width required to display each column.

7. Coding of bOnPostEdit block is quite complex and at times needs lot of lines of code and also requires handling of locks, etc.

XBrowse automatically constructs bOnPostEdit codeblock depending on the data source, including locking of database, if only we allow XBrowse to do the job. XBrowse's internally built codeblock is more appropriate and well tested for all kinds of data sources eg. arrays, rdd, recordsets, tdatabase, excel, etc. But IF ONLY we want to avail the built in facilties of XBrowse.
Regards

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

Re: xBrowse, how to add / change Images in structure browser ?

Postby ukoenig » Sat Sep 04, 2010 8:34 am

Dear Rao,

thank You very much for Your Help and Infos.
I compiled Your extended Version of the xbrowse-structure.
I runs perfect and will be included in my new Fontpainter-Update.
Maybe we can keep this nice Example in the Sample-folder of FWH.
As well it shows how to use Wildcards, to add new Image-fields to a existing Database.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests