Page 1 of 1

Problem with TPanel Paint Method

Posted: Tue Sep 08, 2015 11:39 pm
by James Bott
Antonio,

I am having a problem with the TPanel:paint() method.

When I put a xbrowse on a panel and the panel on a window, the scrollbars of the xbrowse don't display. Actually, they display very briefly when resizing the window but then they vanish leaving the panel showing through.

I found that if I subclass TPanel and use the parent classes' paint method instead, it works fine. So there is apparently a problem with the paint method in the TPanel class.

I have provided simple test code below to show the problem. Use it with the FWH\samples\customer.dbf file.

I am using FWH 15.05.

Regards,
James

Code: Select all | Expand

#include "fivewin.ch"
#include "xbrowse.ch"

function main()
   local oWnd,oBar,oPanel,oBrw,oCust

   DEFINE WINDOW oWnd TITLE "Test Panel Containing xBrowse"

   define buttonbar oBar of oWnd 2007

   oPanel:= TPanel():new()
   //oPanel:= MyPanel():new()            // This solves the problem with a new class
   oPanel:setColor(CLR_BLACK,CLR_BLUE)

   oCust:= TDatabase():New(,"customer")
   oCust:use()
   oCust:gotop()

   oBrw:= TXBrowse():new()
   add column to oBrw data oCust:first header "First"
   oBrw:bSkip:= {|nRecs| oCust:skipper(nRecs) }
   oBrw:createFromCode()

   oPanel:oClient:= oBrw
   
   oWnd:oClient:= oPanel    // oBrw scrollbars only display during resizing
   //oWnd:oClient:= oBrw    // This works OK

   set message to "F1 for help" of oWnd 2007

   activate window oWnd

return nil

 
// New class overrides the TPanel:paint() method and
// instead calls the parent class's paint method
Class MyPanel from TPanel
   Method paint
endclass

Method paint class mypanel
return ::TControl():paint()

// EOF

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 7:27 am
by Antonio Linares
James,

I guess it happens as we don't let Windows do the default painting there.

This is another way to fix it:

Code: Select all | Expand

#include "fivewin.ch"
#include "xbrowse.ch"
#include "c:\harbour\contrib\xhb\xhbcls.ch"

function main()
   local oWnd,oBar,oPanel,oBrw,oCust

   EXTEND CLASS TPanel WITH MESSAGE Paint INLINE nil

   DEFINE WINDOW oWnd TITLE "Test Panel Containing xBrowse"

   define buttonbar oBar of oWnd 2007

   oPanel:= TPanel():new()
   oPanel:setColor(CLR_BLACK,CLR_BLUE)

   oCust:= TDatabase():New(,"customer")
   oCust:use()
   oCust:gotop()

   oBrw:= TXBrowse():new()
   add column to oBrw data oCust:first header "First"
   oBrw:bSkip:= {|nRecs| oCust:skipper(nRecs) }
   oBrw:createFromCode()

   oPanel:oClient:= oBrw
   
   oWnd:oClient:= oPanel    // oBrw scrollbars only display during resizing
   //oWnd:oClient:= oBrw    // This works OK

   set message to "F1 for help" of oWnd 2007

   activate window oWnd

return nil

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 9:22 am
by cnavarro
James, try

Code: Select all | Expand



#include "fivewin.ch"
#include "xbrowse.ch"

function main()
   local oWnd,oBar,oPanel,oBrw,oCust

   DEFINE WINDOW oWnd TITLE "Test Panel Containing xBrowse"

   define buttonbar oBar of oWnd 2007


   oPanel:= TPanel():new()
   oPanel:setColor(CLR_BLACK,CLR_BLUE)

   oWnd:oClient:= oPanel    // oBrw scrollbars only display during resizing

   oCust:= TDatabase():New(,"customer")
   oCust:use()
   oCust:gotop()

   oBrw:= TXBrowse():new( oPanel )
   add column to oBrw data oCust:first header "First"
   oBrw:bSkip:= {|nRecs| oCust:skipper(nRecs) }
   oBrw:createFromCode()

   oPanel:oClient:= oBrw
   
   set message to "F1 for help" of oWnd 2007

   activate window oWnd

return nil

 

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 2:26 pm
by James Bott
Antonio,

I don't have the contrib directory in my installation (the standard one you provide).

#include "c:\harbour\contrib\xhb\xhbcls.ch"

Can you explain why TPanel has a different Paint method? Why is it needed?

James

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 2:30 pm
by James Bott
Cristobal,

It looks like the only change you made was to remove this line:

oWnd:oClient:= oPanel

However I need this line since I also need to have a control attached to oWnd:oLeft (I left this out to simplify the example). So I do need the oWnd:oClient statement.

Thanks for the suggestion, however.

So far, it seems my subclass solution works and is the best solution. I just wondered if there was a bug in the TPanel Paint method.

James

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 2:41 pm
by James Bott
I forgot to mention that I also discovered something else that is not working properly. When the browse is on a panel the arrow keys work for navigation but the cursor does not. If I put the browse directly on the window without the panel then both work as expected.

The reason I want to put the browse on a panel is so I can also put other controls on the panel too.

James

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 3:39 pm
by cnavarro
James Bott wrote:Cristobal,

It looks like the only change you made was to remove this line:

oWnd:oClient:= oPanel

However I need this line since I also need to have a control attached to oWnd:oLeft (I left this out to simplify the example). So I do need the oWnd:oClient statement.

Thanks for the suggestion, however.

So far, it seems my subclass solution works and is the best solution. I just wondered if there was a bug in the TPanel Paint method.

James


James, I have not taken anything
I like much use TPanel to include controls on them as a module then reused in different parts of my programs
Look
viewtopic.php?f=19&t=27296&start=30#p152413
This line has been modified

Code: Select all | Expand


oBrw:= TXBrowse():new( oPanel )
 


Please, James, try the following sample

Code: Select all | Expand



#include "fivewin.ch"
#include "xbrowse.ch"

function main()
   local oWnd,oBar,oPanel,oBrw,oCust

   DEFINE WINDOW oWnd TITLE "Test Panel Containing xBrowse"

   define buttonbar oBar of oWnd 2007


   oPanel:= TPanel():new()
   oPanel:setColor(CLR_BLACK,CLR_BLUE)

   oWnd:oClient:= oPanel  // oBrw scrollbars only display during resizing

   oCust:= TDatabase():New(,"customer")
   oCust:use()
   oCust:gotop()

   oBrw:= TXBrowse():new( oPanel )
   add column to oBrw data oCust:first header "First"
   oBrw:bSkip:= {|nRecs| oCust:skipper(nRecs) }
   oBrw:createFromCode()

   oPanel:oClient:= oBrw
   
   set message to "F1 for help" of oWnd 2007

   activate window oWnd

return nil

 

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 3:48 pm
by nageswaragunupudi
Mr James

I use panels extensively and I never faced any issues.
Minor modifications to the program in the 1st post.

Code: Select all | Expand

#include "fivewin.ch"

function main()

   local oWnd,oBar,oPanel,oBrw,oCust

   DEFINE WINDOW oWnd TITLE "Test Panel Containing xBrowse"

   define buttonbar oBar of oWnd 2007

   oPanel:= TPanel():new(,,,,oWnd)
   oPanel:setColor(CLR_BLACK,CLR_BLUE)

   oCust:= TDatabase():New(,"customer")
   oCust:use()
   oCust:gotop()

   @ 0,0 XBROWSE oBrw OF oPanel DATASOURCE oCust ;
      COLUMNS "First" NOBORDER
   oBrw:CreateFromCode()

   oPanel:oClient := oBrw
   oWnd:oClient := oPanel

   set message of oWnd to "F1 for help" 2007

   activate window oWnd centered

return nil
 


Image

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 4:43 pm
by James Bott
Rao,

You example works OK--mostly. It does navigate when clicking, but it always changes the name to "Andy." Strange...

Update: It changes to another name, and that name changes after awhile. Then the next few times you click it changes to the new name.

I am using FWH 15.05/xHarbour

Update 2: OK, I found the problem. Replace this line:

oBrw:bSkip:= {|nRecs| oCust:skipper(nRecs) }

With this:

oBrw:setoDBF( oCust )

And all is OK. My bad!

James

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 5:14 pm
by James Bott
Cristobal,

OK, I see my mistake. I was doing:


oBrw:= TXBrowse():new(,,,, oPanel )

And it should be:

oBrw:= TXBrowse():new( oPanel )

I see from xbrowse.ch that the row, col, width, and height are after the window parameter and I thought they were before it. Now the scrollbars display correctly.

Thanks for finding that.

James

Re: Problem with TPanel Paint Method

Posted: Wed Sep 09, 2015 5:37 pm
by Antonio Linares
I also missed it, I guess I was still sleepy when I reviewed it :-)

Thanks Rao and Cristobal for solving it

Re: Problem with TPanel Paint Method

Posted: Thu Sep 10, 2015 1:38 am
by nageswaragunupudi
Mr James

You might not have tested my code as it is. That works perfectly.
You might have changed and so it might not have worked

Re: Problem with TPanel Paint Method

Posted: Thu Sep 10, 2015 2:28 pm
by James Bott
Rao,

I remember just cutting and pasting your code, but I double checked and indeed it was different. It may be because I had about 15 prgs open in my editor and I modified yours when I meant to modify a different one. Thanks for pointing that out.

Anyway, thanks for your input and everything is working now.

Regards,
James