using buttons and cointainers

Hello

I have some problems. Look:
First I create window
Then I create: 50 buttons (5X10),no space between buttons, window
is the parent for all buttons

For each other button: first click creates Rectangle (PtRect),
so I can create 50 rectangles (one rectangle
for one button), button is the parent for
rectangle

Now, I want to delete created rectangles by second click. To destroy
rectangle widget I have to know pointer to rectangle. But I can’t get
that pointer, becouse button can’t give me that pointer (when using
PtWidgetChildFront etc). Button can be parent (when creating rectangle) but realy parent is cointainer object above button widget. So parent for rectangle is window, parent for button.
So I can’t delete created rectangle.

I think use container class for each other button it’s good idea.
I tested PtPane. PtPane object was parent for button, and rectangle.
But then I can’t create buttons witout some space between buttons.

Any suggestions? If you can, please post some code configuring container
object, or slimply explain how to do it.

Vitor

Every widget in Photon can have a resource which is a pointer, the resource is called Pt_ARG_POINTER, so what you could do, is something like this:

widget = PtCreateWidget(PtButton,…)
rect = PtCreateWidget(PtRectangle,…);
PtSetResource(widget,Pt_ARG_POINTER,rect,1);

Now attach a callback to button, when the callback is called you wil be able to PtGetResource the pointer from the widget variable in the callback and run PtDestroyWidget on the rect.

I’m not sure if I’ve got the above quite right or if it will solve your problem, I’m not in front of my QNX machine right now.

Cheers

Garry

Hello

Once again thank you for reply.
It works perfectly. You’re my favoritue Photon Programmer :slight_smile:.

For everyone interested in this problem:
If you want to associate more than one rectangle (Widgets etc.) you can use Pt_ARG_USER_DATA. Like this:
struct my_struct
{
PtWidget_t * vertical;
PtWidget_t * horizontal;
};
my_struct data;

widget = PtCreateWidget(PtButton,…);
data.vertical = PtCreateWidget(…);
data.horizontal = PtCreateWidget(…);
PtSetResource(widget, Pt_ARG_USER_DATA, &data, sizeof(data));

Best regards
Vitor

I am having a problem getting this working. Here is my code… (QNX 4.25G)

/* global var decs /
typedef struct
{
PtWidget_t * PtPane_ptr;
PtWidget_t * PtLine_ptr;
} STORED_WIDGET_PTRS; /
struct of widget pointers */

.
.
.

(a local function in code) {
STORED_WIDGET_PTRS widget_data;

.
.
.

/* store widget ptr info from widgets created above */
	widget_data.PtPane_ptr = pane;
	widget_data.PtLine_ptr = line;
	PtSetArg( &userdata_arg[0], Pt_ARG_USER_DATA, &widget_data, 
											sizeof(widget_data));
	PtSetResources( button, 1, userdata_arg );

} //(end of function)
.
.
.
(callback on a PtButton) {
PtSetArg( &userdata_arg[0], Pt_ARG_USER_DATA, &userdata,
sizeof(userdata));
PtGetResources( widget, 1, userdata_arg );

if ( PtWidgetIsRealized( userdata.PtPane_ptr ) )
	PtDestroyWidget( userdata.PtPane_ptr );
else
	fprintf(stderr, "PtPane pointer not found\n");

if ( PtWidgetIsRealized( userdata.PtLine_ptr ) )
	PtDestroyWidget( userdata.PtLine_ptr );
else
	fprintf(stderr, "PtLine pointer not found\n");

} //( end of callback)

My problem is that I am getting my fprintf “not found” errors. I am not sure why, but it doesn’t seem to be storing the pointers in the userdata. It is not giving me and compilation errors or crashing either. Can anyone tell me where I am making a mistake?

Thanks.

Sure, it looks like you are storing the pointer of a local variable - which becomes really useless, if not harmful, once you leave that stack frame (that function). Either malloc the data for the STORED_WIDGET_PTRS or leave it global. Obviously if you malloc it, don’t forget to free it when you are done.

Rick…