XmText Widget

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
XmText Widget

Submitted by leetuckert on Wed, 01/03/2001 - 16:58. Developers
I have a XmNmodifyVerifyCallback on a text field. I have to do some formatting on the field as the user enters characters. In the callback, I create a character pointer called "fieldValue", and allocate memory based on the length resource of the text field. I assemble the existing value of the field, the new value entered by the user, and the formatting characters into fieldValue. Then I assgin the address of fieldValue to cbs->text->ptr as cbs->text->ptr = fieldValue. Question, should I free fieldValue? If I don`t free it, everything works correctly. If I don free it, I get sporadic behavior that results in garbage in the field when a character is entered. The variable fieldValue is local in scope, so if I don`t free it, do I have a memory leak?

ICS_support

If I understand correctly, you do have a memory leak, but you`re passing back memory with local scope; the address is re-used, and you have garbage.

There is sample code available, in O`Reilly Volume 6A and probably also in the comp.windows.x.motif FAQ, on how to create such a field, which is typically used for password-entry or telephone-number-entry.

The code is a little complex, because it follows conventions that were developed after the XmTextBlock, which was originally considered read-only, became a mechanism for adjusting the text value appearing in the text.

leetuckert

Thanks for the response dbl. I have ordered the O`Reilly book that you speak of. Hopefully, this will give me some insight. I still have one question that you or someone else may be able to answer. I suppose that my biggest problem is not understanding how XmText handles the operations of passing strings in and out of the widget. Using XmTextGetString returns a pointer to the string and that address must be freed by the application programmer. I assume then, that this is a copy of the string. So, in setting cbs->text->ptr to some address, does XmText copy this string to some internal data structure, or does the address have to stay in existance as long as the text widget lives?