Problem with TPanel Paint Method

Problem with TPanel Paint Method

Postby James Bott » Tue Sep 08, 2015 11:39 pm

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 view
#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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby Antonio Linares » Wed Sep 09, 2015 7:27 am

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 view
#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
regards, saludos

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

Re: Problem with TPanel Paint Method

Postby cnavarro » Wed Sep 09, 2015 9:22 am

James, try

Code: Select all  Expand view


#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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Problem with TPanel Paint Method

Postby James Bott » Wed Sep 09, 2015 2:26 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby James Bott » Wed Sep 09, 2015 2:30 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby James Bott » Wed Sep 09, 2015 2:41 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby cnavarro » Wed Sep 09, 2015 3:39 pm

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 view

oBrw:= TXBrowse():new( oPanel )
 


Please, James, try the following sample

Code: Select all  Expand view


#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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Problem with TPanel Paint Method

Postby nageswaragunupudi » Wed Sep 09, 2015 3:48 pm

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 view
#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
Regards

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

Re: Problem with TPanel Paint Method

Postby James Bott » Wed Sep 09, 2015 4:43 pm

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
Last edited by James Bott on Wed Sep 09, 2015 5:16 pm, edited 1 time in total.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby James Bott » Wed Sep 09, 2015 5:14 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with TPanel Paint Method

Postby Antonio Linares » Wed Sep 09, 2015 5:37 pm

I also missed it, I guess I was still sleepy when I reviewed it :-)

Thanks Rao and Cristobal for solving it
regards, saludos

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

Re: Problem with TPanel Paint Method

Postby nageswaragunupudi » Thu Sep 10, 2015 1:38 am

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
Regards

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

Re: Problem with TPanel Paint Method

Postby James Bott » Thu Sep 10, 2015 2:28 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

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