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