static int motListSetSelectionPosAttrib(Ihandle* ih, const char* value) { int start=0, end=0; Widget cbedit; if (!ih->data->has_editbox) return 0; if (!value || iupStrEqualNoCase(value, "NONE")) { XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldClearSelection(cbedit, CurrentTime); return 0; } if (iupStrEqualNoCase(value, "ALL")) { XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetSelection(cbedit, (XmTextPosition)0, (XmTextPosition)XmTextFieldGetLastPosition(cbedit), CurrentTime); return 0; } if (iupStrToIntInt(value, &start, &end, ':')!=2) return 0; if(start<0 || end<0) return 0; /* end is inside the selection, in IUP is outside */ end--; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetSelection(cbedit, (XmTextPosition)start, (XmTextPosition)end, CurrentTime); return 0; }
void TextChange( Widget text, XtPointer client_data, XmTextVerifyCallbackStruct * callback_data ) { char *homeDir, *homeDirBackup; char *selection; if (callback_data->reason == XmCR_MODIFYING_TEXT_VALUE || callback_data->reason == XmCR_MOVING_INSERT_CURSOR ) { FileMgrData * file_mgr_data; file_mgr_data = (FileMgrData *) client_data; selection = XmTextFieldGetSelection(text); /* get whats in the text widget */ homeDir = homeDirBackup = XmTextFieldGetString(text); if(selection != NULL) { if(callback_data->event == NULL) XmTextFieldClearSelection(text, CurrentTime); else XmTextFieldClearSelection(text, callback_data->event->xkey.time); callback_data->doit = False; } else if(callback_data->reason == XmCR_MODIFYING_TEXT_VALUE) { /* see if the user is trying to back over the 'restricted' * text, in this case users_home_dir */ if( strcmp( homeDir, "" ) != 0 && strcmp( homeDir, file_mgr_data->restricted_directory ) <= 0 ) { if( callback_data->text->length != 0 ) { if( strncmp( file_mgr_data->restricted_directory, callback_data->text->ptr, strlen(file_mgr_data->restricted_directory)) != 0) { callback_data->doit = True; } } else { callback_data->doit = False; } } } else { int maxlength; maxlength = strlen( file_mgr_data->restricted_directory ); if(callback_data->newInsert < maxlength) { if(callback_data->event == NULL) _XmTextFieldSetDestination((Widget)text, (Position)callback_data->currInsert, CurrentTime); else { _XmTextFieldSetDestination((Widget)text, (Position)callback_data->currInsert, callback_data->event->xkey.time); callback_data->doit = False; } } } XtFree(homeDirBackup); XtFree(selection); } }