ButtonBar in resource ?

ButtonBar in resource ?

Postby TimStone » Sun Mar 22, 2015 1:01 am

I know how to create a Function with a button bar and bitmap buttons, then place it on a dialog. This requires me to have one function for the dialog and all its controls, and then a second one for the button bar and buttons which is then painted on the ACTIVATE command.

This works, but actually I want everything in one METHOD rather than two functions. So for now, I can use BTNBMPs in the Dialog for the controls, and in the resource files I use PUSHBUTTON controls. It works fine, except.

Using the 2 function method, I get a nice button bar background. However, without the bar, the Brush ( a graphic ) I use is also behind the buttons.

So, I would like to paint the area behind the buttons to simulate the button bar.

Of course there are other issues, like the difficulty of having dynamic buttons, etc. With the old method, that is not a problem, but incorporating everything into one Method makes it difficult.

Has anyone played with this ? Of course the easiest solution would be if the Button Bar / Bitmap buttons could be put into the same code as all of the other controls, but that only works for windows and not Dialogs.

Your suggestions are appreciated.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby Antonio Linares » Sun Mar 22, 2015 8:02 am

Tim,

The problem with the buttonbar is that is a control that will hold other controls, and a standard resources editor does not allows to define controls that belong to other controls. Thats why we did not implement a Class TBar Method Redefine().

Anyhow, I have implemented here for you and you will see that it works right, but there is no way to redefine the button, unless someone gets an idea of how to do it:

timbar.prg
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

   local oDlg, oBar

   DEFINE DIALOG oDlg RESOURCE "Test"

   REDEFINE BUTTONBAR oBar ID 100 OF oDlg 2007

   ACTIVATE DIALOG oDlg CENTERED

return nil


timbar.rc
Code: Select all  Expand view  RUN
#include <windows.h>

test DIALOG 0, 0, 186, 94
STYLE DS_MODALFRAME | WS_BORDER | WS_DLGFRAME | WS_POPUP | WS_SYSMENU
FONT 8, "MS Sans Serif"
CAPTION "Test"
BEGIN
   CONTROL "", 100, "TBar", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 200, 40
   DEFPUSHBUTTON   "OK", IDOK, 40, 68, 50, 14, WS_VISIBLE
   PUSHBUTTON      "Cancel", IDCANCEL, 101, 68, 50, 14, WS_VISIBLE
END


FiveWin.ch
Code: Select all  Expand view  RUN
#xcommand REDEFINE BUTTONBAR [<oBar>] ;
             [ ID <nId> ] ;
             [ <of: OF, DIALOG, WINDOW> <oWnd> ] ;
             [ SIZE <nWidth>, <nHeight> ];               
             [ <l2007: 2007, _2007> ] ;
             [ <l2010: 2010, _2010> ] ;
             [ <l2013: 2013, _2013> ] ;
      => ;
             [ <oBar> := ] TBar():Redefine( <nId>, <oWnd>, <nWidth>, <nHeight>,;
                                                <.l2007.>, <.l2010.>, <.l2013.> )   


bar.prg
Code: Select all  Expand view  RUN
METHOD Redefine( nId, oWnd, nWidth, nHeight, l2007, l2010, l2013 ) CLASS TBar

   ::Super:Redefine( nId, oWnd )
   
   ::nBtnWidth  = nWidth
   ::nBtnHeight = nHeight
   ::l2007      = l2007 
   ::l2010      = l2010
   ::l2013      = l2013

   ::SetGradients()
    
return Self  


and
Code: Select all  Expand view  RUN
METHOD SetGradients() CLASS TBar

   do case
      case ::l2007
           ::bClrGrad = { | lInvert | If( ! lInvert,;
                                        { { 0.25, RGB( 219, 230, 244 ), RGB( 207, 221, 239 ) },;
                                          { 0.75, RGB( 201, 217, 237 ), RGB( 231, 242, 255 ) } },;
                                        { { 0.25, RGB( 255, 253, 222 ), RGB( 255, 231, 151 ) }, ;
                                          { 0.75, RGB( 255, 215,  84 ), RGB( 255, 233, 162 ) } } ) }
      case ::l2010
           ::bClrGrad = { | lInvert | If( ! lInvert,;
                                        { { 1, RGB( 255, 255, 255 ), RGB( 229, 233, 238 ) } },;
                                        { { 2/5, RGB( 255, 253, 222 ), RGB( 255, 231, 147 ) },;
                                          { 3/5, RGB( 255, 215,  86 ), RGB( 255, 231, 153 ) } } ) }
      case ::l2013
           ::bClrGrad = { | lInvert | If( ! lInvert,;
                                        { { 1, RGB( 255, 255, 255 ), RGB( 255, 255, 255 ) } },;
                                        { { 1, RGB( 194, 213, 242 ), RGB( 194, 213, 242 ) } } ) }

      otherwise
           ::bClrGrad = { | lInvert | If( ! lInvert,;
                                        { { 0.25, RGB( 219, 230, 244 ), RGB( 207, 221, 239 ) },;
                                          { 0.75, RGB( 201, 217, 237 ), RGB( 231, 242, 255 ) } },;
                                        { { 0.25, RGB( 255, 253, 222 ), RGB( 255, 231, 151 ) }, ;
                                          { 0.75, RGB( 255, 215,  84 ), RGB( 255, 233, 162 ) } } ) }
   endcase

return nil


Image
regards, saludos

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

Re: ButtonBar in resource ?

Postby TimStone » Sun Mar 22, 2015 5:16 pm

Antonio,

Thanks. That does allow for the resource to be used.

Maybe I'm missing something that may have been resolved in more recent versions. Use of DEFINE for the button bar and bitmap buttons would be fine IF I didn't have to create a separate function and then activate that when painting a dialog.

In other words, if ALL controls, including the button bar and bitmap buttons placed on it, could be combined in the same METHOD, that would be the optimum solution. Then it is easy to use dynamic buttons created by the program.

As an example:

DEFINE DIALOG oDlg .... OF oWnd

REDEFINE GET ....
REDEFINE GET ....

DEFINE BUTTONBAR oBar OF oDlg
DEFINE BUTTON .... OF oBar
DEFINE BUTTON ... OF oBar

ACTIVATE oDlg ....

Now we have to define the button bar and buttons in a separate function and call it with an ON PAINT in the ACTIVATE command.

Why is this important ? The Method has many variables which may need to be present in the called proceedures from the buttons. Each variable would have to be passed to the button bar control when it's a separate function, and that can be a lot of variables. It would be much nicer to keep them local, and have the buttons in the same method so they are always available. It's easier to update and debug also.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby nageswaragunupudi » Mon Mar 23, 2015 12:14 am

ON PAINT in the ACTIVATE command.

Should be ON INIT in the ACTIVATE command. Not ON PAINT.
Regards

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

Re: ButtonBar in resource ?

Postby TimStone » Mon Mar 23, 2015 12:49 am

Actually it is, and it's been working fine that way for a long time ... just experimenting with ways to do it better with METHOD in a class ....

THE SOLUTION: I simply made both functions into METHODS in the same class, and now they work fine.

My goal has been to unify similar code and condense it, putting most procedures / functions into classes. It make the operation faster, easier to debug, and much easier to enhance. It's just a lot of work with such a large program. I'm condensing over 215 .prg files to under 100, and each will have a significant reduction in code.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby nageswaragunupudi » Mon Mar 23, 2015 2:41 am

So, you want to create buttonbar and its buttons in the same function/method in which you create the dialog and also use the local variables of that function/method.

Can you please try this?
Code: Select all  Expand view  RUN
#include "fivewin.ch"

//----------------------------------------------------------------------------//

#ifdef __XHARBOUR__
   #xtranslate BEGINBAR OF <o> => <o>:bInit := \<||
   #xcommand   ENDBAR => \>
#else
   #xtranslate BEGINBAR OF <o> => <o>:bInit := \{||
   #xcommand   ENDBAR [<*x*>] => return nil; } <x>
#endif

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oBar, oFont, oBrw

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 400,400 PIXEL FONT oFont TRUEPIXEL

   BEGINBAR OF oDlg

      DEFINE BUTTONBAR oBar OF oDlg SIZE 64,32 2007

      DEFINE BUTTON OF oBar PROMPT "Top"  ACTION oBrw:GoTop()
      DEFINE BUTTON OF oBar PROMPT "Bott" ACTION oBrw:GoBottom()

   ENDBAR

   @ 32,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE { 1, 2, 3, 4, 5 } NOBORDER

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED
   // do NOT use any ON INIT clause for this test

   RELEASE FOnt oFont

return nil

//----------------------------------------------------------------------------//
 

For this code to work, we need to make a small modification to dialog.prg.
In the method Activate, please locate the DEFAULT clause.
Add one more line DEFAULT bInit := ::bInit
After modification the Activate method of dialog.prg looks like this:
Code: Select all  Expand view  RUN
METHOD Activate( bLClicked, bMoved, bPainted, lCentered, ;
                 bValid, lModal, bInit, bRClicked, bWhen, lResize16, ;
                 lCenterInWnd ) CLASS TDialog

   static nDlgCount := 0

   local hActiveWnd, hWnd, bDlgProc

   DEFAULT lCentered := .f., lModal := .t., ::hWnd := 0, lResize16 := .f., lCenterInWnd := .f.
   DEFAULT bInit  := ::bInit   // INSERTED NOW
 


Image
If this approach works well then we can request Mr Antonio to consider making suitable modifications on these lines.
Regards

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

Re: ButtonBar in resource ?

Postby James Bott » Mon Mar 23, 2015 1:55 pm

Whenever you need to pass lots of variables, you should be using an object. Then you only pass one object and you can use or change as many variables as you wish in the function or method you are passing to. Further, you don't need to return the object as any changes you make will exist in the object that was passed.

I know you already know all this, but I thought little reminder might help (and help others).
Last edited by James Bott on Mon Mar 23, 2015 1:59 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: ButtonBar in resource ?

Postby nageswaragunupudi » Mon Mar 23, 2015 1:58 pm

James Bott wrote:Whenever you need to pass lots of variables, you should be using an object. Then you only pass one object and you can change as many variables as you wish in the function or method you are passing to.

Mr James

There is no need to "pass" any variables. Lots or few, the code simply uses the local variables.
Regards

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

Re: ButtonBar in resource ?

Postby James Bott » Mon Mar 23, 2015 2:07 pm

Rao,

Yes, granted, not with your solution. However, I was answering his original question--and it applies to lots of other situations too.

James
Last edited by James Bott on Mon Mar 23, 2015 3:48 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: ButtonBar in resource ?

Postby James Bott » Mon Mar 23, 2015 2:10 pm

Tim,

Here is your example using an object.



Code: Select all  Expand view  RUN
Function Main()
   
   Local oCustomer
   Local cCustNo:="1007"
   
   oCustomer:= TCustomer():new( cCustNo )
   myFunction( oCustomer )

   msgInfo( oCustomer:address )

Return nil


FUNCTION MyFunction( oCustomer )

   DEFINE DIALOG oDlg .... OF oWnd

   REDEFINE GET .... oCustomer:name
   REDEFINE GET .... oCustomer:address

   DEFINE BUTTONBAR oBar OF oDlg
   DEFINE BUTTON .... OF oBar ACTION oCustomer:save()
   DEFINE BUTTON ... OF oBar  ACTION oCustomer:add()

   ACTIVATE oDlg ....

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

Re: ButtonBar in resource ?

Postby nageswaragunupudi » Mon Mar 23, 2015 4:53 pm

Mr James

If at all your code works, it should work with or without object and with or without a database.

The point is we can not define a buttonbar of a dialog within the same function (or method) that defines the dialog itself, whether from resource or source. The buttonbar has to be defined in the INIT clause of the ACTIVATE DIALOG command.

May I request you to post fully working code after testing at your end first?
Regards

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

Re: ButtonBar in resource ?

Postby TimStone » Mon Mar 23, 2015 9:19 pm

Good Afternoon,

Sorry for the delay. Rao I will work with your suggestion now and report back shortly.

Microsoft has a contest for Insiders that results in 2 days on campus meeting with senior staff. It requires a video explaining why we want to go. I just finished the recording and submitted my contest entry.
It would be a fun couple of days and very informative, but I expect there will be a lot of entries and only 10 people will be chosen.

A couple of things. 1) If I use two methods in a class, it does work. 2) Remember these are bitmap buttons, not straight buttons.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby TimStone » Mon Mar 23, 2015 9:23 pm

James,

I'm way beyond that. Now I'm working on a class for my Vendor editor. I have a class for the vendor database, and one for the transaction database. Now I have the full screen editor which incorporates the browse and edit fields. All routines are called by bitmap buttons. It all works, but the button bar has to be created in a separate method and called in the ACTIVATE command. Previously these were two functions ( dialog and button bar ), now they are two methods. The idea is to see if I can bring the two across into the one method.

It's working ... just seeking one more way to reduce the overhead ! BTW, your example is what I've done throughout the program when obtaining data ... and when sharing it

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby TimStone » Mon Mar 23, 2015 9:44 pm

Rao,

That didn't work. First, the dialog and controls are from resources, and the buttons are bitmaps. That may play into this since "create from code" does not apply.

When trying it, the program just stopped working, and shows no error message.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ButtonBar in resource ?

Postby nageswaragunupudi » Tue Mar 24, 2015 2:25 am

Mr Antonio

This is my feedback while testing the modified bar.prg for creating buttonbar from resource.

1) Defining buttons on the buttonbar still need to be done in the ON INIT clause only. This is not an issue but for clarification only.

2) While defining buttons, we get runtime errors because oBar:l3D, oBar:nBtnWidth and oBar:nBtnHeight remain nil. I suggest assigning suitable default values for l3D, nWith and nHeight in the method Redefine(). Because the bar is created from the resource, the height should be taken from the resource and should override whatever height the programmer defines in the command.

Can you please suggest the changes?
Regards

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 48 guests