Field Formatting

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

Questions about motif? Contact us

5 posts / 0 new
Last post
Field Formatting

Submitted by leetuckert on Fri, 03/23/2001 - 20:53. Developers
Hello X-Window Gurus

I am trying to write a couple of XmNmodifyVerifyCallbacks which format the data for a text widget. I am trying to put the insertion cursor just to the left of the decimal point on a numerically formatted text field. When the first number is typed, the insertion cursor positions itself excactly where I specify by setting cbs->newInsert. On entry of the second number, the insertion cursor ignores my instructions and is positioned at the end of the field. On entry of the thrird number, the insertion cursor is again placed exactly where I specify. On the fourth entry, it goes to the end of the field again. On every input character, I am rebuilding the entire text widget value and replacing the entire string by setting cbs->startPos to zero and cbs->endPos to the length of the text widget. Why can`t I consistently position the insertion cursor where I want it within the text widget? Has anyone else out there experineced this behavior?

ICS_support

For problems of this sort, it`s best to use existing code that has already figured out the weirdnesses of the text widgets. There`s sample code for this field (US-style phone numbers or Social Security Numbers) in O`Reilly`s Volume 6A. There may also be code in the comp.windows.x.motif FAQ.

leetuckert

Believe me, I wouldn`t be tackling this unless I had to. I have the O`Reilly book and have studied the code. The phone number/social security number stuff is a piece of cake. However, I have numeric fields that have to right justify. The fields are money fields (US Dollar) and the cursor needs to stay positioned to the left of the decimal point as one type numbers. If the user enters a decimal point, then the cursor needs to move to the right of the decimal point.

I have discovered that the problem arises because the text widget seems to want to move that cursor to some different location. As long as I make a change to cbs->newInsert that would cause the cursor to move out of it present location, all is well. If, however, I try to make the cursor stay where it was when the callback was entered, the text widget overrides my direction and puts the cursor at the end of the field.

Does anyone have any examples of code that performs this type of formatting, or am I the only idiot trying to do this? We are doing this because we are writting our own interface to an application and we are attempting to emulate the behavior that we see in the current interface. So, it can be done.

ICS_support

That`s perfectly reasonable,and I can understand that you might have problems, although I don`t know why the text widgets aren`t cooperating.

When I hit problems of this sort, I often decide that Motif is more of a hindrance in this case than a help. It`s time to figure out exactly what you`re getting out of the use of the text widget (XmText or XmTextField) in this case. Cut-paste? I18N text entry? Probably not. It may be time to think about making a special-purpose text-field widget which handles only numeric values, fills from the right, places the decimal point, etc., and allows minimal deletions. You can put the smarts into the widget rather than into your callbacks.

Motif is a fine toolkit, but it can`t satisfy 100% of the needs of 100% of the applications. The framework, however, allows you to add your own pieces.

leetuckert

I have been able to resolve the issues I mentioned in my original post. I have two callbacks that do decent formatting. One formats strings and the other will format numbers. The numbers are right justified and fill from right to left. The callbacks expect a pointer to a structure as the client data. The structure defines several attributes of the text widget including a format string. If anyone is interested in the code, let me know.