DCBROWSE, visual styles and foreground colors

This forum is for eXpress++ general support.
Message
Author
User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

DCBROWSE, visual styles and foreground colors

#1 Post by Tom »

Some of you may have the problem that browses really look nice with visual styles and themes like "areo" on Vista or Windows 7, but aren't able to show different foreground colors (depending on the cell contens) anymore. Diego posted a sample "HighlightBrowse" on the GUI-newsgroup of Alaska. I modified this to have foreground colors in DCBROWSEs even with visual styles and themes. It uses the SUBCLASS clause of DCBROWSE.

This is the class:

Code: Select all

***************************************
CLASS XbpBrowseForeground FROM DC_XbpBrowse
***************************************
PROTECTED:

EXPORTED:
   INLINE METHOD destroy
   *********************
      ::DC_XbpBrowse:destroy()
   RETURN self

   INLINE METHOD init( oParent, oOwner, aPos, aSize, aPP, lVisible, oGetList )
   *****************************************************************
      ::DC_XbpBrowse:init( oParent, oOwner, aPos, aSize, aPP, lVisible, oGetList )
         ::drawMode:= XBP_DRAW_OWNER
   RETURN self

   INLINE METHOD create( oParent, oOwner, aPos, aSize, aPP, lVisible )
   *******************************************************************
      ::DC_XbpBrowse:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
   RETURN self

   INLINE METHOD customDrawCell( oPS, aInfo )
   ******************************************
     LOCAL xData, nPos, aRect, nFgCol, bColBlock

          xData:= aInfo[ XBP_DRAWINFO_AREA ]:getCell( aInfo[ XBP_DRAWINFO_ITEM ] ) // get cell contens

          aInfo[ XBP_DRAWINFO_AREA ]:getCellColor( aInfo[ XBP_DRAWINFO_ITEM ],@nFgCol ) // get foreground color

          IF xData <> nil .and. nFgCol # nil 

            oPS:setColor( nFgCol )

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

            RETURN .F.

        ENDIF
   RETURN .T.

ENDCLASS
To use it, two things are needed:

1. Use "Subclass" with DCBROWSE:

Code: Select all

@ 0,0 DCBROWSE .... SUBCLASS 'XbpBrowseForeground()'
2. Enable ownerdrawing for the dataareas (!) of the columns:

Code: Select all

DCBROWSECOL .... EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER} COLOR bColorBlock
That's it. Works perfect.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#2 Post by Tom »

Some remarks:

You may change this line:

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

to

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

to show numeric data or others. Catching ValType(xData) and reacting on this (DtoC()) would be a little more elegant, since Var2Char() creates something like DtoS() from dates.

This also ignores column alignments (data is always left-aligned). There is a parameter to set the alignment for GraCaptionStr, but I'm still looking for an elegant way to find out the column aligment. Don't use it with bitmaps or icons in columns!

I'm working on a sample class for multiline browses based on this. Even multiple colors within one browse cell are possible. Take a look at the sample from Diego, posted on public.xbase++.gui, "Re: Colour in xbpbrowse() cells", August 30, 2010.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#3 Post by Tom »

This modified method CustomDrawCell finds alignment information (code stolen from DC_XbpBrowse) and shows data inside the cell 2-lined if CRLF is in the cell data (don't use with vertical alignment parameters!):

Code: Select all

   INLINE METHOD customDrawCell( oPS, aInfo )
   ******************************************
     LOCAL xData, nPos, aRect, nFgCol, bColBlock, nAlign, nFound, aPP, xData1, xData2, nHeight

          aPP := aInfo[ XBP_DRAWINFO_COLUMN ]:presArray
          nFound := AScan(aPP,{|a|Valtype(a[1])=='N'.AND. ;
                           (a[1]==XBPCOL_DA_CELLALIGNMENT .OR. ;
                            a[1]==XBP_PP_COL_DA_CELLALIGNMENT) } )

          IF nFound > 0
            nAlign := aPP[nFound,2]
          ELSE
            nAlign := XBPALIGN_VCENTER
          ENDIF

          aPP := aInfo[ XBP_DRAWINFO_COLUMN ]:presArray

          nFound := AScan(aPP,{|a|Valtype(a[1])=='N'.AND. ;
                           (a[1]==XBP_PP_COL_DA_ROWHEIGHT .OR. ;
                            a[1]==XBP_PP_COL_DA_CELLHEIGHT) } )
          IF nFound == 0
            aPP := ::setPresParam()
            nFound := AScan(aPP,{|a|Valtype(a[1])=='N'.AND. ;
                             (a[1]==XBP_PP_COL_DA_ROWHEIGHT .OR. ;
                              a[1]==XBP_PP_COL_DA_CELLHEIGHT) } )
          ENDIF

          IF nFound > 0
            nHeight := aPP[nFound,2]
          ELSE
            nHeight := 14 // default height <g>
          ENDIF
          nHeight := nHeight/2

          * get column data
          xData:= aInfo[ XBP_DRAWINFO_AREA ]:getCell( aInfo[ XBP_DRAWINFO_ITEM ] )

          * get column foreground color
          aInfo[ XBP_DRAWINFO_AREA ]:getCellColor( aInfo[ XBP_DRAWINFO_ITEM ],@nFgCol )

          IF xData <> nil .and. nFgCol # nil // need to paint

            IF ValType(xData) = 'D'
              xData := DtoC(xData)
            ELSE
              xData := Var2Char(xData)
            ENDIF

            oPS:setColor( nFgCol )

            IF CrLf() $ xData // 2 lines (just a sample!)

              xData1 := Left(xData,At(CrLf(),xData)-1) // top portion
              xData2 := StrTran(xData,xData1+CrLf(),'') // bottom portion

              GraCaptionStr( oPS, aInfo[ XBP_DRAWINFO_RECT ], { aInfo[ XBP_DRAWINFO_RECT, 3 ], aInfo[ XBP_DRAWINFO_RECT, 4 ] }, xData1, nAlign )

              GraCaptionStr( oPS, aInfo[ XBP_DRAWINFO_RECT ], { aInfo[ XBP_DRAWINFO_RECT, 3 ], aInfo[ XBP_DRAWINFO_RECT, 4 ]-nHeight }, xData2, nAlign )

            ELSE

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

            ENDIF

            RETURN .F.

          ENDIF
   RETURN .T.
"CrLf()" is a function which returns Chr(13)+Chr(10).
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#4 Post by Tom »

Just to show what I mean with all this:
Attachments
3-line-browse with foreground color on a themed OS.
3-line-browse with foreground color on a themed OS.
multilinebrowse.png (91.84 KiB) Viewed 15962 times
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: DCBROWSE, visual styles and foreground colors

#5 Post by skiman »

Hi Tom,

This looks very very nice.

Every time when I start with a manifest file, I encounter some problems. I tested some weeks ago, and with a manifest file for the visualstyle browses, my application blocked very regular on my shortcutbar with xcodejock buttons.

Afaik you are also using codejock? Don't you have problems with it?
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#6 Post by Tom »

Hi, Chris.

Yes, I use Codejock and an embedded manifest (linked ressource). These are the problems I encountered:

- Codejock-pushbuttons with icons show black backgrounds instead of transparency.

- Items on tabpages (with visual styles), especially checkboxes, 3states and so on, are blacked out (fore- and background) when a skin is used. This only happens on Vista/7 with an active theme.

- Docking panes tend to destroy the Z-order of complex dialogs completely. If they are docked, items move to the foreground which should be (and stay) in the background.

There is something basically wrong with the XBPSYSCLR_TRANSPARENT mechanism in 1.9 SL1. Sometimes, this doesn't reflect the AutomationTranslateColor()-results correctly.

Something like an app freeze with manifest and cj-pushbuttons doesn't happen at my or customer's sites. What version of CJ/XCodejock/eXpress++ are you using?
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: DCBROWSE, visual styles and foreground colors

#7 Post by skiman »

Tom,

I'm using latest versions eXPress and xcodejock. Since there were several little modifications since the latest 'full' release, I don't know which version it is.

eXpress is 254 according to the readme.txt. I don't think there is a later version. Same for xcodejock, my latest version are some modifications made in april 2010.

My codejock is cj_version("13.3.1").

What do you mean with the transparent problem with your buttons? I have cj-buttons with a bitmap and without any transparency problem. I'm using them on a shortcutbar.
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#8 Post by Tom »

Hi, Chris.

My CJ version is 13.4.0.

If I place an icon (loaded from file using CJLoadIcon) on a CJ-pushbutton, the background is black instead of being transparent. :cry:
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: DCBROWSE, visual styles and foreground colors

#9 Post by skiman »

Tom,

Could you post your dcbrowse and dcbrowsecolums source of your screen sample?

I implemented the modifications, but I don't get a 2 line cell when I have the following column, see my attachment. Text is on the same line, and overwrites.

Code: Select all

DCBROWSECOL DATA {|| klant->naam +crlf()+klant->naam2 } HEADER fMessage(2101) PARENT oBrowse WIDTH 18 ;
   SORT {|| klant->(_sortBrowse(oBrowse,"klant","klant->naam","")),cSeek0:=space(75),DC_SetAppFocus(DC_GetObject(GetList,'oSeek')) } ;
   COLOR bCOlor;
   EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
Attachments
browse.png
browse.png (7.27 KiB) Viewed 15947 times
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: DCBROWSE, visual styles and foreground colors

#10 Post by Tom »

Hi, Chris.

The IMG-tag only supports pictures on a webserver. You need to upload the file as a message attachment.

This sample uses another class "Xbp3LineBrowse", which retrieves 3 lines (using MemoLine()) from xData and paints three caption strings. It also sets the foreground color to GRA_CLR_BLUE for the first caption. You can easily derive this from the last sample. Remark: Use '0' (zero) as the alignment parameter for GraSetCaption (last parameter) in that situation.

Add: You need to double (at least) the cell heights in your presentation array if you want to show more than one line!
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Post Reply