Border around focused line in browse?

Border around focused line in browse?

Postby modicr » Fri May 12, 2006 2:11 pm

Hello!

How to draw a box - border around
current/focused line in TWBrowse.

Thanks, Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia

Postby James Bott » Fri May 12, 2006 5:13 pm

You can't.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Fri May 12, 2006 5:24 pm

Roman, James,

Class TWBrowse Method Paint() can be easily modified to paint a dotted line or similar around the focused line.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Fri May 12, 2006 7:47 pm

Antonio,

Well, easy for you probably, but I remember spending quite some time trying to get it working without success. I think part of the problem was that the cells are kind of still 3d from the old days. There are actually two lines around each cell. Maybe one is drawn in the background color. I don't remember exactly, but there were issues.

I'd be happy if someone proved me wrong.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby modicr » Wed May 17, 2006 11:04 am

Hello!

I try to draw a box around the line and there are problems when I
move to the next line - the previous one is not redrawn correctly.

IMHO there is a (optimization) bug in static function WBrwLine (which is called from Paint method), because only left (gray) and bottom edge of each cell are redrawn:
Code: Select all  Expand view
               case nLineStyle == LINES_GRAY
                    hPen = CreatePen( PS_SOLID, 1, CLR_GRAY )
                    hOld = SelectObject( hDC, hPen )
                    MoveTo( hDC, nLeft - 2, nTop - 2 )
                    LineTo( hDC, nLeft - 2, nBottom )
                    LineTo( hDC, nRight , nBottom )
                    SelectObject( hDC, hOld )
                    DeleteObject( hPen )


One solution is to create subclass of TWBrowse, copy WBrwLine and all methods which are calling WBrwLine (DrawLine, DrawSelect, Paint and LButtonDown) and then change WBrwLine to something like that:
Code: Select all  Expand view
               case nLineStyle == LINES_GRAY
                    hPen = CreatePen( PS_SOLID, 1, CLR_GRAY )
                    hOld = SelectObject( hDC, hPen )
                    MoveTo( hDC, nLeft - 2, nTop - 1 )
                    LineTo( hDC, nLeft - 2, nBottom )
                    LineTo( hDC, nRight , nBottom )
                    MoveTo( hDC, nLeft - 2, nTop - 1 )
                    LineTo( hDC, nRight , nTop - 1 )
                    SelectObject( hDC, hOld )
                    DeleteObject( hPen )

                    hPen = CreatePen( PS_SOLID, 1, CLR_WHITE )
                    hOld = SelectObject( hDC, hPen )
                    MoveTo( hDC, nLeft - 1, nTop  )
                    LineTo( hDC, nLeft - 1, nBottom )
                    SelectObject( hDC, hOld )
                    DeleteObject( hPen )


The next step is to create function based on wBrwLine that draws frame around selected line, which is to be called after wBrwLine in DrawSelect method:

Code: Select all  Expand view
**************************************************************************
static function wBrwSimple( hWnd, hDC, nRowPos, aValues, aColSizes,;
                          nColPos, nClrText, nClrPane,;
                          hFont, lTree, aJustify, nPressed, nLineStyle,;
                          nColAct, lFocused, oVScroll, bLogicLen )
**************************************************************************

   local nTxtHeight, hOldFont
   local nColStart  := -1
   local nWidth     := WndWidth( hWnd ) - If( oVScroll != nil .and. ;
                       Eval( bLogicLen ) > 1,;
                       GetSysMetrics( SM_CYHSCROLL ) + 3, 0 )
   local nRow := nRowPos, nTop, nBottom, nLeft, nRight, n
   local lReleaseDC := .f.
   local nForeColor, nBackColor
   local  hPen, hOld, hBrush

   DEFAULT lTree := .f.

   if Empty( hDC )
      hDC = GetDC( hWnd )
      lReleaseDC = .t.
   endif

   hOldFont   = SelectObject( hDC, hFont )
   nTxtHeight = GetTextHeight( hWnd, hDC ) + 1

   nTop    = nTxtHeight * nRow
   nBottom = nTop + nTxtHeight - 1
   for n := nColPos to Len( aValues )
      nLeft   = nColStart + 1
      nRight  = Min( nColStart := ( nLeft + aColSizes[ n ] - 1 ), nWidth )
      if nLeft > nWidth
         exit
      endif
      if n == Len( aValues )
         nRight = nWidth
      endif
            if lFocused
                    hPen = CreatePen( PS_SOLID, 1, CLR_BLACK )
                    hOld = SelectObject( hDC, hPen )
                    MoveTo( hDC, nLeft-1 , nBottom-1 )
                    LineTo( hDC, nRight, nBottom-1 )
                    MoveTo( hDC, nRight-1, nTop )
                    LineTo( hDC, nLeft-2 , nTop )
                    SelectObject( hDC, hOld )
                    DeleteObject( hPen )
             else
                    hPen = CreatePen( PS_DOT, 1, CLR_BLACK )
                    hOld = SelectObject( hDC, hPen )
                    MoveTo( hDC, nLeft-1 , nBottom )
                    LineTo( hDC, nRight, nBottom )
                    MoveTo( hDC, nRight-1, nTop-1 )
                    LineTo( hDC, nLeft-2 , nTop-1 )
                    SelectObject( hDC, hOld )
                    DeleteObject( hPen )
            endif
      if nColPos > nWidth
         exit
      endif
   next
return NIL   // wBrwSimple


Here is the result: :)
Image

Regards, Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia

Postby Enrico Maria Giordano » Wed May 17, 2006 11:43 am

Great, Roman!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8419
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Wed May 17, 2006 3:52 pm

Good work Roman.

One question. Why a static function rather than a method?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby modicr » Thu May 18, 2006 9:39 am

Hello!

Because that's the way how wBrwLine is implemented in WBROWSE.PRG and I just copied code from it.

BTW, I created three more "skins": :)
Image

Image


Image


Cheers, Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia

Postby Antonio Linares » Thu May 18, 2006 9:58 am

Roman,

Excellent :)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

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