Browse and Ownerdraw

This forum is for eXpress++ general support.
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Browse and Ownerdraw

#1 Post by rdonnay »

Ownerdrawing of Browse cells can get to be fun.

Here is an example of using ownerdraw to highlight portions of text and to make selected row a much larger font. Also, notice the bitmap in the selected row.
ownerdraw.jpg
ownerdraw.jpg (75.26 KiB) Viewed 15244 times

Code: Select all

STATIC FUNCTION DrawCellHighlighted( oPS, aInfo, cHighLight, oBrowse, oFontLarge, oBitmap )

LOCAL xData, nPos, nRow, aRect, oCell := aInfo[5], oColumn

IF oCell:isDerivedFrom('DC_MultiLineCellGroup') // It's a header
  RETURN .t.
ENDIF

xData := DC_XtoC(aInfo[ XBP_DRAWINFO_AREA ]:getCell( aInfo[ XBP_DRAWINFO_ITEM ] ))

nRow := aInfo[1]
oColumn := oCell:setParent()

IF nRow == oBrowse:rowPos
  oPS:setFont(oFontLarge)
ENDIF

IF xData <> nil .AND. ( nPos:= At( cHighlight, xData ) ) > 0

   oPS:setColor( IIF( aInfo[ XBP_DRAWINFO_STATE ] = XBP_DRAWSTATE_SELECTED, ;
                 XBPSYSCLR_MENUHILITE, XBPSYSCLR_WINDOWSTATICTEXT ) )

   GraCaptionStr( oPS, aInfo[ XBP_DRAWINFO_RECT ], { aInfo[ XBP_DRAWINFO_RECT, 3 ], ;
                                                     aInfo[ XBP_DRAWINFO_RECT, 4 ] }, xData )

   IF nRow == oBrowse:rowPos
     oPS:setColor( GRA_CLR_DARKPINK )
   ELSE
     oPS:setColor( GRA_CLR_RED )
   ENDIF

   IF nPos = 1
      GraCaptionStr( oPS, aInfo[ XBP_DRAWINFO_RECT ], { aInfo[ XBP_DRAWINFO_RECT, 3 ], ;
                     aInfo[ XBP_DRAWINFO_RECT, 4 ] }, cHighlight )
   ELSE
      aRect:= GraQueryTextBox( oPS, Left( xData, nPos - 1 ) )

      GraCaptionStr( oPS, { aInfo[ XBP_DRAWINFO_RECT, 1 ] + aRect[ 3, 1 ], aInfo[ XBP_DRAWINFO_RECT, 2 ] }, ;
                          { aInfo[ XBP_DRAWINFO_RECT, 3 ], aInfo[ XBP_DRAWINFO_RECT, 4 ] }, ;
                          cHighlight )
   ENDIF

   RETURN .F.

ELSE

   oPS:setColor( IIF( aInfo[ XBP_DRAWINFO_STATE ] = XBP_DRAWSTATE_SELECTED, ;
                 XBPSYSCLR_MENUHILITE, XBPSYSCLR_WINDOWSTATICTEXT ) )

   IF nRow == oBrowse:rowPos
     oPS:setColor( GRA_CLR_YELLOW )
   ENDIF

   IF nRow == oBrowse:rowPos .AND. oColumn == oBrowse:getColumn(1)

     aRect:= GraQueryTextBox( oPS, Left( xData, nPos - 1 ) )

     oBitmap:draw(oPS, { aInfo[ XBP_DRAWINFO_RECT, 1 ] + aRect[ 3, 1 ], ;
                         aInfo[ XBP_DRAWINFO_RECT, 2 ] } )

     GraCaptionStr( oPS,{ aInfo[ XBP_DRAWINFO_RECT, 1 ] + oBitmap:xSize + 2, ;
                          aInfo[ XBP_DRAWINFO_RECT, 2 ] }, ;
                        { aInfo[ XBP_DRAWINFO_RECT, 3 ] + oBitmap:xSize + 2, ;
                          aInfo[ XBP_DRAWINFO_RECT, 4 ] }, xData )

   ELSE

     GraCaptionStr( oPS, aInfo[ XBP_DRAWINFO_RECT ], ;
                        { aInfo[ XBP_DRAWINFO_RECT, 3 ], ;
                          aInfo[ XBP_DRAWINFO_RECT, 4 ] }, xData )

   ENDIF

   RETURN .f.

ENDIF

RETURN .T.
The eXpress train is coming - and it has more cars.

User avatar
RDalzell
Posts: 205
Joined: Thu Jan 28, 2010 6:57 am
Location: Alsip, Illinois USA

Re: Browse and Ownerdraw

#2 Post by RDalzell »

Roger,

Nice........

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Browse and Ownerdraw

#3 Post by c-tec »

Hello Roger,
looks great !
Regards,
Rudolf
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Browse and Ownerdraw

#4 Post by unixkd »

Hi Roger

Pls provide us with the source code of the program that produce the above browse

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Browse and Ownerdraw

#5 Post by skiman »

Hi,

Maybe you didn't notice but the first post in this thread contains the code. ;)

See also the thread 'Color within DCBROWSE'. This contains some modified source files for eXPress++.
Best regards,

Chris.
www.aboservice.be

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Browse and Ownerdraw

#6 Post by unixkd »

Yes the initial bOwnerDraw has 3 parameters thus:

bOwnerDraw := {|a,b|DrawCellHighlighted(a,b,Alltrim(cHighLight))}

BUT
the new DrawCellHighlighted function is declared with 6 parameters thus:

DrawCellHighlighted( oPS, aInfo, cHighLight, oBrowse, oFontLarge, oBitmap )

Please let us have a revised function call that produce the above browse.

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Browse and Ownerdraw

#7 Post by rdonnay »

Here is the rest of the code (this will work with build 254) :

Code: Select all

FUNCTION Main()

LOCAL GetList[0], GetOptions, oBrowse, aDir, bOwnerDraw, ;
      cHighlight := Space(10), oFontNormal, oFontLarge, oBitmap

LOCAL aBrowPres := ;
  { { XBP_PP_COL_HA_FGCLR, GRA_CLR_WHITE },            /* Header FG Color  */  ;
    { XBP_PP_COL_HA_BGCLR, GRA_CLR_DARKGRAY },         /* Header BG Color  */  ;
    { XBP_PP_COL_DA_ROWSEPARATOR, XBPCOL_SEP_DOTTED }, /* Row Sep          */  ;
    { XBP_PP_COL_DA_COLSEPARATOR, XBPCOL_SEP_DOTTED }, /* Col Sep          */  ;
    { XBP_PP_COL_DA_FGCLR, GRA_CLR_BLACK },            /* Row FG Color     */  ;
    { XBP_PP_COL_DA_BGCLR, GRA_CLR_WHITE },                /* Row BG Color     */  ;
    { XBP_PP_COL_DA_ROWHEIGHT, 16 },                   /* Row Height       */  ;
    { XBP_PP_COL_HA_HEIGHT, 10 },                      /* Header Height    */  ;
    { XBP_PP_HILITE_FGCLR, GRA_CLR_WHITE },            /* Hilite FG color  */  ;
    { XBP_PP_HILITE_BGCLR, GraMakeRGBColor({220,120,120}) },             /* Hilite BG color  */  ;
    { XBP_PP_COL_FA_FGCLR, GRA_CLR_WHITE },            /* Footer FG Color  */  ;
    { XBP_PP_COL_FA_BGCLR, GRA_CLR_DARKGRAY },         /* Footer BG Color  */  ;
    { XBP_PP_COL_FA_HEIGHT, 10 },                      /* Footer Height    */  ;
    { XBP_PP_COL_DA_CELLFRAMELAYOUT ,  2 },            /* Cell Frame Layout*/  ;
    { XBP_PP_COL_DA_COLSEPARATOR  ,    1 },            /* Column Separator */  ;
    { XBP_PP_COL_DA_FRAMELAYOUT  ,     0 },             /* Frame Layout     */  ;
    { XBP_PP_COL_DA_HILITEFRAMELAYOUT, DCGUI_BROWSEFRAME_THICK_RECESSED } }

oFontLarge := XbpFont():new():create('12.Lucida Console Bold')
oBitmap := XbpBitmap():new()
oBitmap:transparentClr := GraMakeRGBColor({192,192,192})
oBitmap:create()
oBitmap:loadFile('..\..\bitmaps\forwards.bmp')

bOwnerDraw := {|a,b|DrawCellHighlighted(a,b,Alltrim(cHighLight),oBrowse,oFontLarge,oBitmap)}

aDir := Directory()

@ 0,0 DCSAY 'Enter some characters' GET cHighLight ;
      KEYBLOCK {|a,b,o| o:getData(), oBrowse:invalidateRect()} ;
      RESIZE DCGUI_RESIZE_REPOSONLY_Y ;
      SAYSIZE 0 SAYBOTTOM ;
      COLOR GRA_CLR_WHITE

@ 1.1,0 DCBROWSE oBrowse DATA aDir SIZE 10,10 FIT ;
      EVAL {|o|o:ownerDrawBlock := bOwnerDraw} ;
      SUBCLASS "DC_XbpBrowseOwnerDraw()" ;
      USEVISUALSTYLE ;
      CURSORMODE XBPBRW_CURSOR_ROW ;
      FONT '10.Lucida Console' ;
      RESIZE DCGUI_RESIZE_RESIZEONLY ;
      ITEMMARKED {||oBrowse:invalidateRect()} ;
      PRESENTATION aBrowPres ;
      COLOR {||IIF(oBrowse:arrayElement%2==0,{nil,GraMakeRGBColor({220,220,255})},{nil,GRA_CLR_WHITE})}

DCBROWSECOL ELEMENT 1 HEADER 'File Name' WIDTH 20 PARENT oBrowse EVAL {|o|o:drawMode := XBP_DRAW_OWNER}
DCBROWSECOL ELEMENT 2 HEADER 'File Size' WIDTH 10 PARENT oBrowse EVAL {|o|o:drawMode := XBP_DRAW_OWNER}
DCBROWSECOL ELEMENT 3 HEADER 'File Date' WIDTH 15 PARENT oBrowse EVAL {|o|o:drawMode := XBP_DRAW_OWNER}
DCBROWSECOL ELEMENT 4 HEADER 'File Time' WIDTH 15 PARENT oBrowse EVAL {|o|o:drawMode := XBP_DRAW_OWNER}

DCGETOPTIONS RESIZE COLOR GRA_CLR_DARKCYAN CASCADE

DCREAD GUI FIT TITLE 'Testing Owner Draw Browse (254)' OPTIONS GetOptions 
  
RETURN nil

* -----------

CLASS DC_XbpBrowseOwnerDraw FROM DC_XbpBrowse

PROTECTED: ; EXPORTED:
VAR ownerDrawBlock
INLINE METHOD destroy ; ::DC_XbpBrowse:destroy() ; RETURN self
INLINE METHOD Init( a,b,c,d,e,f,g) ; ::DC_XbpBrowse:init(a,b,c,d,e,f,g) ; ::drawMode := XBP_DRAW_OWNER ; RETURN self
INLINE METHOD Create( a,b,c,d,e,f,g) ; ::DC_XbpBrowse:create( a,b,c,d,e,f,g) ; RETURN self
INLINE METHOD CustomDrawCell( a,b ) ; RETURN Eval(::ownerdrawBlock, a,b)

ENDCLASS

* ----------

proc appsys ; return
The eXpress train is coming - and it has more cars.

Wolfgang Ciriack
Posts: 478
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Browse and Ownerdraw

#8 Post by Wolfgang Ciriack »

Hi Roger,
does this example work with tagging and taggingcolor ?
I have problems to get the zebra feature together with Toms ownerdrawing and tagging.
_______________________
Best Regards
Wolfgang

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Browse and Ownerdraw

#9 Post by rdonnay »

I don't see any problem with tagging.

It should work with ownerdraw because it uses the XbpBrowse() base color system, just as Zebra does. My example screens show a zebra pattern.
The eXpress train is coming - and it has more cars.

Wolfgang Ciriack
Posts: 478
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Browse and Ownerdraw

#10 Post by Wolfgang Ciriack »

Hi Roger,
the COLOR clause and the TAGCOLOR clause does not work together.

I have attached your sample completed with tagging.
I had to modify the COLOR clause to get tagging work.
Is this the right way, or is there a solution that the tagcolor clause is working ?

Regards Wolfgang
Attachments
ownerdraw.zip
(2.05 KiB) Downloaded 713 times
_______________________
Best Regards
Wolfgang

Post Reply