PtComboBox, PtText, PtTextCallback_t

Hi!
That code beneath is a little part of my program. So, don’t think it makes any sense.
I create a PtComboBox and a PtText widget. To the PtText widget I add a callback which shall in future controll the input of the text field. So far it just print the string which is going to be inserted. There is the problem. After I started the program and type some numbers I get the expected output. But after I change the entry of the PtComboBox with the mouse I get a few chars too much. What’s wrong? Or isn’t it even wrong? But if not, where is it mentioned that the cbs->text isn’t 0 terminated?

cc try.c -o try -lph -lphrender -w[9]

########OUTPUT
cbs->text[1]
cbs->text[2]
cbs->text[5]
cbs->text[4]
cbs->text[8]
cbs->text[5]
#PtComboBox switch
cbs->text[4o/ ]
cbs->text[2o/ ]
cbs->text[5o/ ]
cbs->text[1o/ ]

#######CODE

[code]#include <Pt.h>

int cb_validateTxtNbr1(PtWidget_t *,void *,PtCallbackInfo_t *);

char fontNames[MAX_FONT_TAG];
PtWidget_t *w_sender, *w_pageNbr=NULL;

int main(void){

PtWidget_t *w_window=NULL, *w_main_group=NULL, *w_ctrl_group=NULL;
PtArg_t pt_args[4];
unsigned char *sendernamen[]={“hello”};

if(PtInit(NULL) == -1)
PtExit(EXIT_FAILURE);

if(!PfGenerateFontName(“Helvetica”,0,15,fontNames))
perror(“Unable to generate font name”);

if((w_window = PtCreateWidget(PtWindow,Pt_NO_PARENT,0,NULL)) == NULL)
PtExit( EXIT_FAILURE );

w_main_group = PtCreateWidget(PtGroup,w_window,0,NULL);
w_ctrl_group = PtCreateWidget(PtGroup,w_main_group,0,NULL);

PtSetArg(&pt_args[0],Pt_ARG_FLAGS,Pt_FALSE,Pt_GETS_FOCUS);
PtSetArg(&pt_args[1],Pt_ARG_ITEMS,sendernamen,1);
PtSetArg(&pt_args[2],Pt_ARG_CBOX_FLAGS,Pt_TRUE,Pt_COMBOBOX_MAX_WIDTH);
if((w_sender = PtCreateWidget(PtComboBox,w_ctrl_group,3,pt_args)) == NULL)
PtExit( EXIT_FAILURE );

PtSetArg(&pt_args[0],Pt_ARG_MAX_LENGTH,3,0);
PtSetArg(&pt_args[1],Pt_ARG_COLUMNS,3,0);
w_pageNbr = PtCreateWidget(PtText,w_ctrl_group,2,pt_args);
PtAddCallback(w_pageNbr, Pt_CB_MODIFY_VERIFY, cb_validateTxtNbr1, NULL);

PtRealizeWidget(w_window);
PtMainLoop();
return (EXIT_SUCCESS);
}

int cb_validateTxtNbr1(PtWidget_t *w_w,void *client_data,PtCallbackInfo_t *info){
PtTextCallback_t *cbs = (PtTextCallback_t *)info->cbdata;
printf(“cbs->text[%s]\n”,cbs->text);
return Pt_CONTINUE;
}[/code]

I didnt find a mention that cbs->text isnt 0 terminated, but also i didnt find mention that it is 0 terminated.

You should use cbs->length to work correctly with cbs->text

Thanks a lot for your help!
But in the meanwhile I solved the problem. I used length indeed after I found a confirmation that text in PtTextCallback_t isn’t zero-terminated. It’s on this page qnx.com/developers/docs/qnx_ … itext.html
under the description of Pt_CB_MODIFY_VERIFY. What a nice place for such an important information! :wink:

Yes, it should be added also here
qnx.com/developers/docs/mome … IFY_VERIFY