Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to check in a checkbox?: (10 Items)
   
How to check in a checkbox?  
Dear Photon experts,

Can anyone of you answer an easy question?

How do you put a check mark in a PtOnOffButton??

Yes I've read the help file, and still stumped. 
What is the resource name to set?
I have a simple dialoig with an OnOffButton.
Have tried all of following, but the #$%^&!  checkbox does not react.

 PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_SET, 1 ); 
 PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_SET, 0 ); 
 
long *px;
PtGetResource(  ABW_ckbox, Pt_ARG_FLAGS, &px, 1 ); // success
 PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, *px | Pt_SET, 0 ); 
 PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, *px | Pt_SET, 1 );
 
Thanks for any idea,
-- S.
RE: How to check in a checkbox?  
I think the resource you want to set is Pt_ARG_ONOFF_STATE; see:

http://www.qnx.com/developers/docs/6.4.1/photon/widget_ref/ptonoffbutton
.html

In addition, your code below for setting the flags might not work the
way you expect. For Flag resources, the third argument is the value of
the bits to set, and the fourth is a bitmask that indicates which bits
you want to set. See "Flag resources" in here:

http://www.qnx.com/developers/docs/6.4.1/photon/prog_guide/res_code.html
#SettingResources


Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 

> -----Original Message-----
> From: Saul A [mailto:community-noreply@qnx.com] 
> Sent: Wednesday, December 22, 2010 4:22 PM
> To: photon-graphics
> Subject: How to check in a checkbox?
> 
> Dear Photon experts,
> 
> Can anyone of you answer an easy question?
> 
> How do you put a check mark in a PtOnOffButton??
> 
> Yes I've read the help file, and still stumped. 
> What is the resource name to set?
> I have a simple dialoig with an OnOffButton.
> Have tried all of following, but the #$%^&!  checkbox does not react.
> 
>  PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_SET, 1 ); 
>  PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_SET, 0 ); 
>  
> long *px;
> PtGetResource(  ABW_ckbox, Pt_ARG_FLAGS, &px, 1 ); // success
>  PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, *px | Pt_SET, 0 ); 
>  PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, *px | Pt_SET, 1 );
>  
> Thanks for any idea,
> -- S.
> 
> 
> 
> 
> _______________________________________________
> 
> Photon microGUI
> http://community.qnx.com/sf/go/post80092
> 
> 
Re: RE: How to check in a checkbox?  
Thank you very much, Steve, for the reply.

Unfortunately the line below does not set the checkbox.

PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 0 );  

And all below does not work:

PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 1 );  
PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 0xFF, 0 );  
PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 0xFF, 0xFF );  

Do you have more ideas? 

( hint:  add more examples to the documentation!  Examples are great! there cannot be too much examples! )

- S.
Re: RE: How to check in a checkbox?  
Well, here is the answer:

PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_TRUE, Pt_SET ); // ON

PtSetResource( ABW_ckbox, Pt_ARG_FLAGS, Pt_FALSE, Pt_SET ); // OFF

Works with PhAB v 2.03.

Hope it will be useful to others who look for this information. Because Google is huge, and life is short.


-- S.
Re: RE: How to check in a checkbox?  
Hi Saul,

Sorry for not replying earlier... Pt_ARG_FLAGS is the correct resource -at least it works-, but keep in mind: it is a 
flag-type resource. For flag resources, the third argument of PtSetResource() is the 'value', whereas the fourth is used
 as the 'mask'. This means that only bits set to 1 in the mask will be affected in the resource - and will.be set to the
 according bit from the value argument.

For this reason, I'd recommend not using Pt_TRUE for the value, but instead the flag(s) you want to set. PR_TRUE happens
 to be defined as -1, which is an integer full of all 1s on a 2's-complement machine, so it is usually sufficient for 
setting a number of flag bits. But if we decided to redefine it as, e.g., +1, setting of most flag bits would be 
rendered broken in your code. 

In theory, you could also use a 'value' of (explicitly) -1L, or, to be real safe, ~0L. I do this myself when setting 
many flags at once.

But of course, the flag setting mechanism is more powerful, as three examples show.

'set' a widget:
PtSetResource( widget, Pt_ARG_FLAGS, ~0L, Pt_SET );

'unset' the widget:
PtSetResource( widget, Pt_ARG_FLAGS, 0, Pt_SET );

'ghost' a widget and make it non-selectable:
PtSetResource( widget, Pt_ARG_FLAGS, Pt_GHOST, Pt_GHOST | Pt_SELECTABLE );

Note how in the last example, value and mask are used to set one flag while unsetting another one at the same time.

- Thomas

RE: RE: How to check in a checkbox?  
This code works for me:

/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 2.03  */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"

int count = 0;

int
on_off_cb( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )

	{

        unsigned char * button_state, new_state;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

        PtGetResource (widget, Pt_ARG_ONOFF_STATE, &button_state, 0);
	printf ("Current state is %d\n", *button_state);

        count++;

	if (count % 4 == 1) {
		if (*button_state == 0) 
		{
			new_state = 1;
		}
		else
		{
			new_state = 0;
		}
		PtSetResource (widget, Pt_ARG_ONOFF_STATE, new_state,
0);
	
        	PtGetResource (widget, Pt_ARG_ONOFF_STATE,
&button_state, 0);
		printf ("State has been reset to %d\n", *button_state);
	}

	return( Pt_CONTINUE );

}




Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 

> -----Original Message-----
> From: Saul A [mailto:community-noreply@qnx.com] 
> Sent: Wednesday, December 22, 2010 5:52 PM
> To: photon-graphics
> Subject: Re: RE: How to check in a checkbox?
> 
> Thank you very much, Steve, for the reply.
> 
> Unfortunately the line below does not set the checkbox.
> 
> PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 0 );  
> 
> And all below does not work:
> 
> PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 1 );  
> PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 0xFF, 0 );  
> PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 0xFF, 0xFF );  
> 
> Do you have more ideas? 
> 
> ( hint:  add more examples to the documentation!  Examples 
> are great! there cannot be too much examples! )
> 
> - S.
> 
> 
> 
> 
> _______________________________________________
> 
> Photon microGUI
> http://community.qnx.com/sf/go/post80119
> 
> 
Re: How to check in a checkbox?  
Steve, Thomas, thank you for the help. Am a bit under pressure with this gui stuff.

This definitely did not work for me:
PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 0 );  

Maybe because I called this from a dialog post-realize callback (whaetever is the correct name for it) - not from widget
 callback.

The variant proposed by Thomas works.

The variant with ... Pt_ARG_FLAGS, Pt_TRUE, Pt_SET ) I've found somewhere on google, for radio buttons.

Anyway, would be great just to see the correct variant in the documentation, for most typical use cases.

Have happy holidays and happy new year,

- S
RE: How to check in a checkbox?  
That seems odd. Just to check: is the widget a PtOnOffButton or a
PtToggleButton?

Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 

> -----Original Message-----
> From: Saul A [mailto:community-noreply@qnx.com] 
> Sent: Thursday, December 23, 2010 11:21 AM
> To: photon-graphics
> Subject: Re: How to check in a checkbox?
> 
> Steve, Thomas, thank you for the help. Am a bit under 
> pressure with this gui stuff.
> 
> This definitely did not work for me:
> PtSetResource( ABW_ckbox, Pt_ARG_ONOFF_STATE , 1, 0 );  
> 
> Maybe because I called this from a dialog post-realize 
> callback (whaetever is the correct name for it) - not from 
> widget callback.
> 
> The variant proposed by Thomas works.
> 
> The variant with ... Pt_ARG_FLAGS, Pt_TRUE, Pt_SET ) I've 
> found somewhere on google, for radio buttons.
> 
> Anyway, would be great just to see the correct variant in the 
> documentation, for most typical use cases.
> 
> Have happy holidays and happy new year,
> 
> - S
> 
> 
> 
> 
> _______________________________________________
> 
> Photon microGUI
> http://community.qnx.com/sf/go/post80245
> 
> 
Re: RE: How to check in a checkbox?  
> That seems odd. Just to check: is the widget a PtOnOffButton or a
> PtToggleButton?
> 


It was a toggle  button. Sorry, my fault.

- S.
RE: RE: How to check in a checkbox?  
That explains everything: for a toggle button, you use Pt_ARG_FLAGS.
That widget doesn't have a Pt_ARG_ONOFF_STATE resource.

At least we sorted it all out -- and I now have some code that I can
make into an example for the PtOnOffButton docs.

Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 

> -----Original Message-----
> From: Saul A [mailto:community-noreply@qnx.com] 
> Sent: Thursday, December 23, 2010 3:16 PM
> To: photon-graphics
> Subject: Re: RE: How to check in a checkbox?
> 
> > That seems odd. Just to check: is the widget a PtOnOffButton or a
> > PtToggleButton?
> > 
> 
> 
> It was a toggle  button. Sorry, my fault.
> 
> - S.
> 
> 
> 
> 
> _______________________________________________
> 
> Photon microGUI
> http://community.qnx.com/sf/go/post80298
> 
>