No child in Container/Compound

I managed to code a running Widget called PtLabelImage3, til now it just should show up a Label inside a Container/Compound widget.
However the Label won´t show up, whatever i do.
I include my Full Source now, if anybody could tell me what i am doing wrong would be fine.

PS: Don`t mind the many Labels, and widgets in the struct, they are for further implementation, right now i just want to have ONE LABEL inside my Compound/Container. Btw. i tried both, container and compound, none worked.


#ifndef __PT_LABEL_IMAGE_3_H_INCLUDED
#define __PT_LABEL_IMAGE_3_H_INCLUDED


#ifndef __PT_COMPOUND_H_INCLUDED
 #include <photon/PtCompound.h>
#endif

#ifndef __PT_LABEL_H_INCLUDED
 #include <photon/PtLabel.h>
#endif

#ifndef _PXIMAGE_H_INCLUDED 
 #include <photon/PxImage.h>
#endif


#ifdef __cplusplus
extern "C" {
#endif

#define PtLI3Widget_t Pt_LabelImage3Widget_t

extern PtWidgetClassRef_t *const PtLabelImage3;

#define Pt_LI3_LEFT_IMAGE		Pt_RESOURCE(Pt_USER(1), 0)
#define Pt_LI3_CENTER_IMAGE		Pt_RESOURCE(Pt_USER(1), 1)
#define Pt_LI3_RIGHT_IMAGE		Pt_RESOURCE(Pt_USER(1), 2)
#define Pt_LI3_HAS_IMAGE		Pt_RESOURCE(Pt_USER(1), 3)
#define Pt_LI3_LEFT_WIDTH		Pt_RESOURCE(Pt_USER(1), 4)
#define Pt_LI3_CENTER_WIDTH		Pt_RESOURCE(Pt_USER(1), 5)
#define Pt_LI3_RIGHT_WIDTH		Pt_RESOURCE(Pt_USER(1), 6)
#define Pt_LI3_WIDTH			Pt_RESOURCE(Pt_USER(1), 7)
#define Pt_LI3_HEIGHT			Pt_RESOURCE(Pt_USER(1), 8)

#define Pt_LI3_LIMAGE	1
#define Pt_LI3_CIMAGE	2
#define Pt_LI3_RIMAGE	3


typedef struct Pt_LabelImage3 {
	 
	PtCompoundWidget_t	compound;		// Das Compound Widget immer als erstes!!!
	PtLabelWidget_t llabel;
	PtLabelWidget_t clabel;
	PtLabelWidget_t rlabel;
	PtWidget_t *llabelw;
	PtWidget_t *clabelw;
	PtWidget_t *rlabelw;
//	PhImage_t limage;
//	PhImage_t cimage;
//	PhImage_t rimage;
	unsigned int lwidth;
	unsigned int cwidth;
	unsigned int rwidth;
	char hasimage;
	unsigned int fullwidth;
	unsigned int height;
	char *text;

} Pt_LabelImage3Widget_t;

typedef union Pt_LabelImage3Union {
	PtWidget_t           core;
	PtBasicWidget_t      basic;
	PtContainerWidget_t  cntnr;
	PtCompoundWidget_t   cmpnd;
	PtLabelWidget_t		label;
	Pt_LabelImage3Widget_t	li3w;
} Pt_LabelImage3Union_t;


#ifdef __cplusplus
};
#endif
#endif





#include <string.h>
#include <stdlib.h>
#include <Pt.h>
#include <Ph.h>
#include "PtLabelImage3.h"

#include <string.h>
#include <Pt.h>
#include <Ph.h>


static PtWidgetClass_t * PtCreateLI3Class( void );
static void li3_defaults( PtWidget_t *widget );
static void li3_modify( PtWidget_t *widget, PtArg_t const *argt );
static int li3_query( PtWidget_t *widget, PtArg_t *argt );

static PtWidgetClassRef_t __Pt_LabelImage3 = { NULL, PtCreateLI3Class };
PtWidgetClassRef_t * const PtLabelImage3 = &__Pt_LabelImage3;
PtLabelWidget_t *label;


PtWidgetClass_t *PtCreateLI3Class( void ){

	static const PtResourceRec_t resources[] = 
	{

			Pt_LI3_LEFT_IMAGE,
			li3_modify,
			li3_query,
			Pt_ARG_IS_STRUCT(PtLabelWidget_t, data),
			0,

			Pt_LI3_RIGHT_IMAGE,
			li3_modify,
			li3_query,
			Pt_ARG_IS_STRUCT(PtLabelWidget_t, data),
			0,

			Pt_LI3_CENTER_IMAGE,
			li3_modify,
			li3_query,
			Pt_ARG_IS_STRUCT(PtLabelWidget_t, data),
			0,

			Pt_LI3_LEFT_WIDTH,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, lwidth),
			0,

			Pt_LI3_CENTER_WIDTH,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, cwidth),
			0,

			Pt_LI3_RIGHT_WIDTH,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, rwidth),
			0,

			Pt_LI3_WIDTH,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, fullwidth),
			0,

			Pt_LI3_HEIGHT,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, height),
			0,

			Pt_LI3_HAS_IMAGE,
			li3_modify,
			li3_query,
			Pt_ARG_IS_NUMBER(Pt_LabelImage3Widget_t, hasimage),
			0,

			Pt_ARG_TEXT_STRING,
			li3_modify,
			li3_query,
			Pt_ARG_IS_STRING(Pt_LabelImage3Widget_t, text),
			0

	};

	static ushort_t subs[] =
	{
			offsetof(Pt_LabelImage3Widget_t,    llabelw ),
			offsetof(Pt_LabelImage3Widget_t,    clabelw ),
			offsetof(Pt_LabelImage3Widget_t,    rlabelw )

	};

	static ulong_t blocked[] = { 
		Pt_ARG_BALLOON_COLOR
	};


	static PtArg_t args[] =
	{
			{ Pt_SET_VERSION, 110},
			{ Pt_SET_STATE_LEN, sizeof(Pt_LabelImage3Widget_t ) },
			{ Pt_SET_DFLTS_F, (long) li3_defaults },
			{ Pt_SET_NUM_RESOURCES, sizeof( resources ) / sizeof( resources[0] ) },
			{ Pt_SET_RESOURCES, (long)resources },
			{ Pt_SET_NUM_SUBORDINATES, sizeof( subs ) / sizeof( subs[0] ) },
			{ Pt_SET_SUBORDINATES, (long)subs, sizeof( subs ) / sizeof( subs[0] ) },
			{ Pt_SET_NUM_BLOCKED_RESOURCES, sizeof( blocked ) / sizeof( blocked[0] ) },
			{ Pt_SET_BLOCKED_RESOURCES, (long) blocked, sizeof( blocked ) / sizeof( blocked[0] ) },

	};

	PtLabelImage3->wclass = PtCreateWidgetClass(PtCompound,0,sizeof( args )/sizeof( args[0] ),args );
	return PtLabelImage3->wclass;
}

static int li3_destroy( PtWidget_t *widget )
{
 	widget = widget;

	return Pt_CONTINUE;
}
static void li3_defaults( PtWidget_t *widget )
{
    Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t *) widget;
	PtArg_t argt[10];
	int n;

	//Initialisationen
	li3->hasimage = 0;
	li3->text = NULL;
	n=0;
	PtSetArg (&argt[0], Pt_ARG_LABEL_TYPE, Pt_Z_STRING, 0 ); n++;
	PtSetArg (&argt[1], Pt_ARG_FLAGS, Pt_HIGHLIGHTED | Pt_PROCREATED, Pt_TRUE ); n++;
	PtSetArg( &argt[n], Pt_ARG_RESIZE_FLAGS, Pt_RESIZE_XY_AS_REQUIRED, Pt_TRUE ); n++;
//	PtSetArg (&argt[2], Pt_ARG_TEXT_STRING, "|", 0 ) ; n++;
	PtSetArg (&argt[3], Pt_ARG_DATA, &widget, sizeof( widget ) ); n++;
	li3->llabelw = PtCreateWidget( PtLabel, widget, n, argt );
	li3->rlabelw = PtCreateWidget( PtLabel, widget, n, argt );
	
//	PtSetArg (&argt[2], Pt_ARG_TEXT_STRING, "bla blubb", 0 );
	li3->clabelw = PtCreateWidget( PtLabel, widget, n, argt );

}

static void li3_modify( PtWidget_t *widget, PtArg_t const *argt )
{
	Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t *) widget;
	PhArea_t		larea,carea,rarea;
	PtArg_t args[1];

	//PtCalcCanvas(widget, &canvas);
    switch(argt->type)
    {
	case Pt_LI3_HAS_IMAGE:
		if( argt->value == 0 ){
			PtSetArg( &args[0], Pt_ARG_LABEL_TYPE, Pt_Z_STRING, 0);
			PtSetResources(li3->llabelw, 1, args);
			PtSetResources(li3->clabelw, 1, args);
			PtSetResources(li3->rlabelw, 1, args);
		}else{
			PtSetArg( &args[0], Pt_ARG_LABEL_TYPE, Pt_IMAGE, 0);
			PtSetResources(li3->llabelw, 1, args);
			PtSetResources(li3->rlabelw, 1, args);
			PtSetArg( &args[0], Pt_ARG_LABEL_TYPE, Pt_TEXT_IMAGE, 0);
			PtSetResources(li3->clabelw, 1, args);
		}
		break;
	case Pt_LI3_LEFT_IMAGE:
		PtSetArg(&args[0], Pt_ARG_LABEL_DATA, argt->value, argt->len);
		PtSetResources(li3->llabelw,1,args);
		break;
	case Pt_LI3_CENTER_IMAGE:
		PtSetArg(&args[0], Pt_ARG_LABEL_DATA, argt->value, argt->len);
		PtSetResources(li3->clabelw,1,args);
		break;
	case Pt_LI3_RIGHT_IMAGE:
		PtSetArg(&args[0], Pt_ARG_LABEL_DATA, argt->value, argt->len);
		PtSetResources(li3->rlabelw,1,args);
		break;
	case Pt_LI3_LEFT_WIDTH:
		PtSetArg( &args[0], Pt_ARG_AREA, &larea, 0);
		PtGetResources(li3->llabelw, 1, args);
		larea.size.w = argt->value;
		PtSetArg( &args[0], Pt_ARG_AREA, &larea, 0);
		PtSetResources(li3->llabelw, 1, args);
		break;
	case Pt_LI3_CENTER_WIDTH:
		PtSetArg( &args[0], Pt_ARG_AREA, &carea, 0);
		PtGetResources(li3->clabelw, 1, args);
		carea.size.w = argt->value;
		PtSetArg( &args[0], Pt_ARG_AREA, &carea, 0);
		PtSetResources(li3->clabelw, 1, args);
		break;
	case Pt_LI3_RIGHT_WIDTH:
		PtSetArg( &args[0], Pt_ARG_AREA, &rarea, 0);
		PtGetResources(li3->rlabelw, 1, args);
		rarea.size.w = argt->value;
		PtSetArg( &args[0], Pt_ARG_AREA, &rarea, 0);
		PtSetResources(li3->rlabelw, 1, args);
		break;	
	case Pt_ARG_TEXT_STRING:{
		char *cstr = (char *) argt->value;
		li3->text = malloc(1024);
		strcpy(li3->text, cstr);
		printf("bla %s\n",cstr);
		PtSetArg( &args[0], Pt_ARG_TEXT_STRING, argt->value, argt->len );
		PtSetResources(li3->clabelw, 1, args);
		PtSetArg( &args[0], Pt_ARG_TEXT_STRING, "|", 0 );
		PtSetResources(li3->llabelw, 1, args);
		PtSetResources(li3->rlabelw, 1, args);
		PtDamageWidget( li3->llabelw );
		PtDamageWidget( li3->clabelw );
		PtDamageWidget( li3->rlabelw );
		PtDamageWidget( widget );
		break;
	}
	case Pt_LI3_WIDTH:
		// blabla
		break;
    }
}

static int li3_query( PtWidget_t *widget, PtArg_t *argt )
{
	Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t * ) widget;

	switch(argt->type)
    {
	case Pt_LI3_HAS_IMAGE:
		*(char*) (argt->value = (char) (&li3->hasimage));
		return Pt_END;
		break;
	case Pt_LI3_LEFT_WIDTH:
		*(unsigned int*) (argt->value = (unsigned int) (&li3->lwidth));
		return Pt_END;
		break;
	case Pt_LI3_CENTER_WIDTH:
		*(unsigned int*) (argt->value = (unsigned int) (&li3->cwidth));
		return Pt_END;
		break;
	case Pt_LI3_RIGHT_WIDTH:
		*(unsigned int*) (argt->value = (unsigned int) (&li3->rwidth));
		return Pt_END;
		break;
	case Pt_LI3_WIDTH:
		*(unsigned int*) (argt->value = (unsigned int) (&li3->fullwidth));
		return Pt_END;
		break;
	default:
        return Pt_END;
		break;
    }
}


int main( int argc, char **argv ) {
	PtArg_t        args[ 10 ];
	PtWidget_t *   mainw;
	PtWidget_t *   list;
	PtAppContext_t app;

	PtSetArg( &args[0], Pt_ARG_WINDOW_TITLE, "PtCompound", 0 );

	mainw = PtAppInit( &app, &argc, argv, 1, args );
	if ( mainw == NULL ) {
		return(EXIT_FAILURE);
	}

	PtSetArg( &args[0], Pt_ARG_TEXT_STRING, "Juhuu .. n Label", 0 );
	PtSetArg( &args[1], Pt_ARG_FILL_COLOR, Pg_RED, 0 );
	list = PtCreateWidget( PtLabelImage3, mainw, 2, args );
	PtSetArg( &args[0], Pt_ARG_TEXT_STRING, "Juhuu .. das 2. Label", 0 );
	PtSetArg( &args[1], Pt_ARG_FILL_COLOR, Pg_BLUE, 0 );
	PtCreateWidget( PtLabel, mainw, 2, args );

	PtRealizeWidget( mainw );
	PtMainLoop();

	return(EXIT_SUCCESS);
}


Thx for help

anyone having experience with building custom widgets? write me pm please.

PtCompound/PtContainer would be nice if there is another example instead of the uncomplete one delivered with QNX …

I found a Mozilla PtContainer already, but not getting really more intelligent with it :stuck_out_tongue_winking_eye:

If someone could provide a simple PtCompound/PtContainer holding a single PtLabel would be nice :slight_smile:

someone already registered that 60% codeexamples given by QSS SIGSEGVing or similar??
This is really a bad service i think …
Most f… up example:
PtSampCompound.c - first of, the header file is mising.
After creating a Headerfile, i had to fix bout 50 Errors:
Unknown Definitions
Wrong Syntax
Massive Pointer Missmatches
Wrong Parametercounts or Prototyping (PtContainerChildRedirect)

I now already wrote a Mail to Service requesting a running PtCompound Example…
Lets see whats comming back, will quote it if permited

So far
micro

As promised i post a running example of ONE label inside custom Widget
(snipped out a lot of unused code)

Custom.h

[code]#ifndef __PT_CUSTOM_H_INCLUDED
#define __PT_CUSTOM_H_INCLUDED

#ifndef __PT_COMPOUND_H_INCLUDED
#include <photon/PtCompound.h>
#endif

#ifndef __PT_LABEL_H_INCLUDED
#include <photon/PtLabel.h>
#endif

#ifdef __cplusplus
extern “C” {
#endif

#define PtLI3Widget_t Pt_LabelImage3Widget_t

extern PtWidgetClassRef_t *const PtLabelImage3;

// These are just examples, they are not uses now
#define Pt_LI3_1ST_RESOURCE Pt_RESOURCE(Pt_USER(1), 0)
#define Pt_LI3_2ND_RESOURCE Pt_RESOURCE(Pt_USER(1), 1)

typedef struct Pt_LabelImage3 {

PtCompoundWidget_t compound; // Das Compound Widget immer als erstes!!!
PtWidget_t *clabelw;
unsigned int cwidth;

} Pt_LabelImage3Widget_t;

#ifdef __cplusplus
};
#endif
#endif[/code]

Custom.c

[code]#include <string.h>
#include <stdlib.h>
#include <Pt.h>
#include <Ph.h>
#include “custom.h”

static PtWidgetClass_t * PtCreateLI3Class( void );
static void li3_defaults( PtWidget_t *widget );
static void li3_modify( PtWidget_t *widget, PtArg_t const *argt );
static int li3_query( PtWidget_t *widget, PtArg_t *argt );
static void li3_extent( PtWidget_t *widget );

static PtWidgetClassRef_t __Pt_LabelImage3 = { NULL, PtCreateLI3Class };
PtWidgetClassRef_t * const PtLabelImage3 = &__Pt_LabelImage3;
PtLabelWidget_t *label;

PtWidgetClass_t *PtCreateLI3Class( void ){

static const PtResourceRec_t resources[] =
{

     Pt_ARG_TEXT_STRING,
     li3_modify,
     li3_query,
     Pt_ARG_IS_STRING(PtLabelWidget_t, string),
     0

};

static ushort_t subs[] =
{
offsetof(Pt_LabelImage3Widget_t, clabelw ),

};

static ulong_t blocked[] = {
Pt_ARG_BALLOON_COLOR
};

static PtArg_t args[] =
{
{ Pt_SET_VERSION, 110},
{ Pt_SET_STATE_LEN, sizeof(Pt_LabelImage3Widget_t ) },
{ Pt_SET_DFLTS_F, (long) li3_defaults },
{ Pt_SET_EXTENT_F, (long) li3_extent },
{ Pt_SET_NUM_RESOURCES, sizeof( resources ) / sizeof( resources[0] ) },
{ Pt_SET_RESOURCES, (long)resources },
{ Pt_SET_NUM_SUBORDINATES, sizeof( subs ) / sizeof( subs[0] ) },
{ Pt_SET_SUBORDINATES, (long)subs, sizeof( subs ) / sizeof( subs[0] ) },
{ Pt_SET_NUM_BLOCKED_RESOURCES, sizeof( blocked ) / sizeof( blocked[0] ) },
{ Pt_SET_BLOCKED_RESOURCES, (long) blocked, sizeof( blocked ) / sizeof( blocked[0] ) },

};

PtLabelImage3->wclass = PtCreateWidgetClass(PtCompound,0,sizeof( args )/sizeof( args[0] ),args );
return PtLabelImage3->wclass;
}

static void li3_defaults( PtWidget_t *widget )
{
Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t *) widget;
PtArg_t argt[10];
int n;

//Initialisationen
n=0;
PtSetArg (&argt[n], Pt_ARG_LABEL_TYPE, Pt_Z_STRING, 0 ); n++;
PtSetArg (&argt[n], Pt_ARG_FLAGS, Pt_HIGHLIGHTED | Pt_PROCREATED, Pt_TRUE ); n++;
PtSetArg( &argt[n], Pt_ARG_RESIZE_FLAGS, Pt_RESIZE_XY_AS_REQUIRED, Pt_TRUE ); n++;
li3->clabelw = PtCreateWidget( PtLabel, widget, n, argt );

// THIS IS NEW !!!
n=0;
PtSetArg( &argt[n], Pt_ARG_FLAGS, Pt_GETS_FOCUS , Pt_TRUE );n++;
PtSetArg( &argt[n], Pt_ARG_RESIZE_FLAGS, Pt_RESIZE_X_AS_REQUIRED | Pt_RESIZE_Y_AS_REQUIRED, Pt_TRUE );n++;
PtSetArg( &argt[n], Pt_ARG_CONTAINER_FLAGS, Pt_AUTO_EXTENT, Pt_TRUE );n++;
PtSuperClassSetResources( PtCompound, widget, n, argt );

}

// THIS IS ALSO NEW (not needed with just one Widget, but with more (calculates extent))!!!
static void li3_extent( PtWidget_t *widget ){

Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t *) widget;
PhRect_t canvas,render;
PhPoint_t pos;
int n;
PtArg_t args[10];

PtBasicWidgetCanvas( widget, &canvas );
render.ul = render.lr = canvas.ul;

n=0;
PtExtentWidget( li3->clabelw );
li3->cwidth = li3->clabelw->area.size.w;

PtChildBoundingBox( widget, &canvas, &render );
PtAttemptResize( widget, &canvas, &render );
PtSuperClassExtent( PtCompound, widget );

}

static void li3_modify( PtWidget_t *widget, PtArg_t const *argt )
{
Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t *) widget;
PtArg_t args[1];

//PtCalcCanvas(widget, &canvas);
switch(argt->type)
{
case Pt_ARG_TEXT_STRING:{
// You actually won´t need to do this, since its forwarded automatically,
// but its essential if you just want it to be applied to one of your n widgets inside the compound
PtSetArg( &args[0], Pt_ARG_TEXT_STRING, argt->value, argt->len );
PtSetResources(li3->clabelw, 1, args);
widget->flags |= Pt_WIDGET_RESIZE;
break;
}
default:
break;
}
}

/*
Forget about this one :stuck_out_tongue_winking_eye:
this is wrong, but won´t cause trouble yet
*/
static int li3_query( PtWidget_t *widget, PtArg_t *argt )
{
Pt_LabelImage3Widget_t *li3 = (Pt_LabelImage3Widget_t * ) widget;

li3=li3;
switch(argt->type)
{
	default:
		return Pt_END;
	break;
}

}

int main( int argc, char **argv ) {
PtArg_t args[ 10 ];
PtWidget_t * mainw;
PtWidget_t * list;
PtAppContext_t app;

PtSetArg( &args[0], Pt_ARG_WINDOW_TITLE, “PtCompound”, 0 );

mainw = PtAppInit( &app, &argc, argv, 1, args );
if ( mainw == NULL ) {
return(EXIT_FAILURE);
}

PtSetArg( &args[0], Pt_ARG_TEXT_STRING, “Juhuu … n Label”, 0 );
PtSetArg( &args[1], Pt_ARG_FILL_COLOR, Pg_RED, 0 );
list = PtCreateWidget( PtLabelImage3, mainw, 2, args );

PtRealizeWidget( mainw );
PtMainLoop();

return(EXIT_SUCCESS);
}[/code]

A friend of mine, right beside me, just told me he would like to see the Makefile too, so if your interested here it is:

ifndef DEBUG
DEBUG = -g2
endif
ifndef OPTIM
OPTIM = -Osax
endif

CFLAGS = $(OPTIM) $(DEBUG) -3 -mf -w5 -b
LDFLAGS = $(DEBUG) -3 -mf -b -l photon_s -l Aplib -l phexlib -l phcontrib -l phrtlib

custom: custom.o
$(CC) -o $(@) $(LDFLAGS) custom.o

[/code]