static void darkness_text_cb(Widget w, XtPointer client_data, XtPointer call_data) { char *text; int val; struct topic_info *info = (struct topic_info *)client_data; struct prefs_choice *prefs = (struct prefs_choice *)(info->data); #if USE_SPINBOX /* synchronize internal spinbox value. Apparently this loses the insertion position, so we need to save it and set it again. */ XmTextPosition pos = XmTextFieldGetInsertionPosition(w); UNUSED(call_data); text = XmTextFieldGetString(w); val = strtol(text, (char **)NULL, 10); if (val != 0) { XtVaSetValues(w, XmNposition, val, NULL); XmTextFieldSetInsertionPosition(w, pos); } #else Widget text_field; UNUSED(call_data); XtVaGetValues(w, XmNuserData, &text_field, NULL); XtVaGetValues(text_field, XmNvalue, &text, NULL); val = strtol(text, (char **)NULL, 10); #endif if (XtIsRealized(w)) { do_set_density(val / 100.0, True, False); store_preference(&(prefs->db), "gamma", "%f", val / 100.0); } XtFree(text); }
static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args) { Boolean refresh = False; #ifdef DEBUG printf("NumEntry - set_values(%s) - >%s< >%s<\n", XtName(new_w), NumEntry_Value(old), NumEntry_Value(new_w)); #endif if (XtIsSensitive(old) != XtIsSensitive(new_w) && !XtIsSensitive(new_w)) { if (NumEntry_TimerId(new_w)) { XtRemoveTimeOut(NumEntry_TimerId(new_w)); NumEntry_TimerId(new_w) = (XtIntervalId)NULL; } } if (NumEntry_LabelString(old) != NumEntry_LabelString(new_w)) { NumEntry_LabelString(new_w) = XmStringCopy(NumEntry_LabelString(new_w)); XtVaSetValues(NumEntry_Label(new_w), XmNlabelString, NumEntry_LabelString(new_w), NULL); if (NumEntry_LabelString(old)) { XmStringFree(NumEntry_LabelString(old)); } } if (NumEntry_Value(old) != NumEntry_Value(new_w)) { char *tmp; Position Place; #ifdef DEBUG printf("NumEntry - set_values(%s) - value old >%s< new >%s<\n", XtName(new_w), NumEntry_Value(old), NumEntry_Value(new_w)); #endif tmp = NumEntry_Value(new_w); NumEntry_Value(new_w) = XtNewString(tmp); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(new_w)); XmTextFieldSetString(NumEntry_TextField(new_w), NumEntry_Value(new_w)); XmTextFieldSetInsertionPosition(NumEntry_TextField(new_w), Place); if (NumEntry_Value(old)) { XtFree(NumEntry_Value(old)); } refresh = True; DoMath(new_w); } if (NumEntry_Columns(old) != NumEntry_Columns(new_w)) { Dimension old_width = XtWidth(NumEntry_TextField(new_w)); XtVaSetValues(NumEntry_TextField(new_w), XmNcolumns, NumEntry_Columns(new_w), NULL); XtWidth(new_w) -= (old_width - XtWidth(NumEntry_TextField(new_w))); refresh = True; } return (refresh); }
static void initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args) { #ifdef DEBUG printf("%s:initialize(%d) - %s %ix%i\n", __FILE__, __LINE__, XtName(new_w), XtWidth(new_w), XtHeight(new_w)); #endif FilePicker_Label(new_w) = XmCreateLabel(new_w, XtName(new_w), args, *num_args); FilePicker_TextField(new_w) = XmCreateTextField(new_w, "TextField", args, *num_args); FilePicker_Button(new_w) = XltCreateBubbleButton(new_w, "Browse", args, *num_args); if (XtHeight(new_w) == 0) { XtHeight(new_w) = XtHeight(FilePicker_Label(new_w)) > XtHeight(FilePicker_TextField(new_w)) ? XtHeight(FilePicker_Label(new_w)) : XtHeight(FilePicker_TextField(new_w)); XtHeight(new_w) = XtHeight(new_w) > XtHeight(FilePicker_Button(new_w)) ? XtHeight(new_w) : XtHeight(FilePicker_Button(new_w)); } XtVaSetValues(FilePicker_Label(new_w), XmNalignment, XmALIGNMENT_BEGINNING, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, FilePicker_TextField(new_w), XmNbottomAttachment, XmATTACH_FORM, NULL); XtVaSetValues(FilePicker_Button(new_w), XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, (int)((XtHeight(new_w) - XtHeight(FilePicker_Button(new_w))) / 2), XmNrightAttachment, XmATTACH_FORM, NULL); XtVaSetValues(FilePicker_TextField(new_w), XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, (int)((XtHeight(new_w) - XtHeight(FilePicker_TextField(new_w))) / 2), XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, FilePicker_Button(new_w), NULL); if (FilePicker_Value(new_w)) { XmTextFieldSetString(FilePicker_TextField(new_w), FilePicker_Value(new_w)); XmTextFieldSetInsertionPosition(FilePicker_TextField(new_w), XmTextFieldGetLastPosition(FilePicker_TextField(new_w))); } XtManageChild(FilePicker_Label(new_w)); XtManageChild(FilePicker_Button(new_w)); XtManageChild(FilePicker_TextField(new_w)); XtAddCallback(FilePicker_Button(new_w), XmNactivateCallback, (XtCallbackProc)BrowseCallback, NULL); /* XtAddCallback(new_w, XmNhelpCallback, (XtCallbackProc)Help, NULL); */ }
static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args) { Boolean refresh = False; #ifdef DEBUG printf("%s:set_values(%d) - %s\n", __FILE__,__LINE__, XtName(new_w)); #endif if (FilePicker_Value(new_w) != FilePicker_Value(old)) { XmTextFieldSetString(FilePicker_TextField(new_w), FilePicker_Value(new_w)); XmTextFieldSetInsertionPosition(FilePicker_TextField(new_w), XmTextFieldGetLastPosition(FilePicker_TextField(new_w))); } return (refresh); }
static void BrowseOkCallback(Widget w, Widget fp, XmFileSelectionBoxCallbackStruct *cbs) { Widget FSB_TextField; String Value; #ifdef DEBUG printf("%s:BrowseOkCallback(%d) - %s %s\n", __FILE__, __LINE__, XtName(w), XtName(fp)); #endif FSB_TextField = XmFileSelectionBoxGetChild(w, XmDIALOG_TEXT); Value = XmTextFieldGetString(FSB_TextField); XmTextFieldSetString(FilePicker_TextField(fp), Value); XmTextFieldSetInsertionPosition(FilePicker_TextField(fp), XmTextFieldGetLastPosition(FilePicker_TextField(fp))); XtFree(Value); XtUnmanageChild(w); }
static int motListSetCaretPosAttrib(Ihandle* ih, const char* value) { int pos = 0; Widget cbedit; if (!ih->data->has_editbox) return 0; if (!value) return 0; iupStrToInt(value, &pos); if (pos < 0) pos = 0; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetInsertionPosition(cbedit, (XmTextPosition)pos); XmTextFieldShowPosition(cbedit, (XmTextPosition)pos); return 0; }
static int motListSetCaretAttrib(Ihandle* ih, const char* value) { int pos = 1; Widget cbedit; if (!ih->data->has_editbox) return 0; if (!value) return 0; sscanf(value,"%i",&pos); pos--; /* IUP starts at 1 */ XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); XmTextFieldSetInsertionPosition(cbedit, (XmTextPosition)pos); XmTextFieldShowPosition(cbedit, (XmTextPosition)pos); return 0; }
static void DoMath(Widget W) { String value; double result; Position Place; #ifdef DEBUG printf("DoMath(%s)\n", XtName(W)); #endif value = XmTextFieldGetString(NumEntry_TextField(W)); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(W)); result = XltCalc(value); if (result != NumEntry_Result(W)) { char buf[1024]; XltNumEntryVerifyCallbackStruct cbs; NumEntry_Result(W) = result; sprintf(buf, "%.*g", NumEntry_Columns(W), result); cbs.reason = XmCR_VALUE_CHANGED; cbs.event = NULL; cbs.doit = True; cbs.value = XtNewString(buf); cbs.dvalue = NumEntry_Result(W); XtCallCallbacks(W, XmNvalueChangedCallback, &cbs); if (cbs.doit) { XtFree(NumEntry_Value(W)); NumEntry_Value(W) = cbs.value; NumEntry_Result(W) = cbs.dvalue; } else { XtFree(cbs.value); } } XmTextFieldSetString(NumEntry_TextField(W), NumEntry_Value(W)); XmTextFieldSetInsertionPosition(NumEntry_TextField(W), Place); XtFree(value); }
static void StepValue(Widget W, int a, int b) { Widget Rc = XtParent(XtParent(W)); Position Place; char *buf; #ifdef DEBUG printf("NumEntry - StepValue(%s) - %s\n", XtName(W), XtName(Rc)); #endif buf = XmTextFieldGetString(NumEntry_TextField(Rc)); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(Rc)); if (buf[Place] != '.') { buf = IncDigit(buf, &Place, a); XmTextFieldSetString(NumEntry_TextField(Rc), buf); XmTextFieldSetInsertionPosition(NumEntry_TextField(Rc), Place); DoMath(Rc); } XtFree(buf); }
/************************************************************************ * * XtActionProc - VFTextChangeSpace() - this is the callback which gets * called when a user type 'Space' in a text widget which has * this translation tied to it. * ***********************************************************************/ void VFTextChangeSpace( Widget text, XEvent *event, XtPointer params, XtPointer num_params) { char *value; char *currentDirectoryText; char path[MAX_PATH]; char *test; char **temp; int length, shortest, val = 0; int i,j; Boolean match; /* get the current text from the widget */ value = (char *)XmTextFieldGetString(text); currentDirectoryText = GetRestrictedDirectory(text); /* Extract the path */ path[0] = NULL; if(currentDirectoryText == NULL) { strcpy (path, value); } else { if (strcmp(currentDirectoryText, "/") == 0) sprintf(path, "%s%s", currentDirectoryText, value); else sprintf(path, "%s/%s", currentDirectoryText, value); } /* add a '*' at the end of the path so the shellscan will no to return * all possible matches. */ test = (char *)XtMalloc(strlen(path) + strlen("*") + 1); sprintf(test, "%s%s", path, "*"); /* do a shellscan to get all possible matches to the path */ temp = (char **)shellscan(test, &val, 0); if(val == 1 && strcmp(*temp, test) != 0) { /* there was one and only one match */ if(currentDirectoryText == NULL) XmTextFieldSetString(text, *temp); else XmTextFieldSetString(text, *temp + strlen(currentDirectoryText)); XmTextFieldSetInsertionPosition(text, XmTextFieldGetLastPosition(text)); } else if (val > 1) { /* more than one filename matches the path */ length = strlen(path); /* first find the shortest of the matches */ shortest = strlen(temp[0]); for(i = 1; i < val; i++) { j = strlen(temp[i]); if(j < shortest) shortest = j; } /* find the most characters which will match in all patterns found. * i.e. if I have /use, /user, /users, and /used, the most chars * which match are /use */ match = True; for(i=0; i < shortest; i++) { for(j=0; j < val - 1; j++) { if(temp[j][length + i] != temp[j + 1][length + i]) { match = False; break; } } if(match == False) break; } temp[0][length + i] = '\0'; if(currentDirectoryText == NULL) XmTextFieldSetString(text, *temp); else XmTextFieldSetString(text, *temp + strlen(currentDirectoryText)); XmTextFieldSetInsertionPosition(text, XmTextFieldGetLastPosition(text)); /* ring the bell so the users knows the filename is not complete */ XBell(XtDisplay(text), 100); } else /* no matches found */ XBell(XtDisplay(text), 100); XtFree(test); }
/*ARGSUSED*/ static void ListCallback( Widget w, /* unused */ XtPointer client_data, XtPointer call_data ) { XmListCallbackStruct * listCB = (XmListCallbackStruct *) call_data ; XmCommandCallbackStruct cmdCB ; XmCommandWidget cmdWid = (XmCommandWidget) client_data ; char * text_value ; Arg argv[5] ; Cardinal argc ; int count ; XmString tmpXmString ; /*********** reset is not used ************ Boolean reset = FALSE ; ****************/ argc = 0 ; XtSetArg( argv[argc], XmNitemCount, &count) ; ++argc ; XtGetValues( SB_List( cmdWid), argv, argc) ; if( !count ) { return ; } if( cmdWid->command.error ) { if( (listCB->item_position == (count - 1)) || ( (listCB->item_position == count) && (listCB->reason != XmCR_DEFAULT_ACTION)) ) { /* Selection or default action on the blank line, or selection on * error message. Restore previous selection and return. */ XmListDeselectPos( SB_List( cmdWid), listCB->item_position) ; if( cmdWid->selection_box.list_selected_item_position ) { XmListSelectPos( SB_List( cmdWid), cmdWid->selection_box.list_selected_item_position, FALSE) ; } return ; } XmListDeletePos( SB_List( cmdWid), 0) ; /* Delete error message.*/ XmListDeletePos( SB_List( cmdWid), 0) ; /* Delete blank line.*/ cmdWid->command.error = FALSE ; if( count <= 2 ) { /* List only contained error message and blank line. */ cmdWid->selection_box.list_selected_item_position = 0 ; return ; } count -= 2 ; if( (listCB->item_position > count) && (listCB->reason == XmCR_DEFAULT_ACTION) ) { /* Default action on the error message line. Restore previous * selection, clear text area, and return. */ if( cmdWid->selection_box.list_selected_item_position ) { XmListSelectPos( SB_List( cmdWid), cmdWid->selection_box.list_selected_item_position, FALSE) ; } XmTextFieldSetString( cmdWid->selection_box.text, "") ; return ; } } if( listCB->reason == XmCR_DEFAULT_ACTION ) { /* If we are already at max items, remove first item. */ if( count >= cmdWid->command.history_max_items ) { XmListDeletePos( cmdWid->selection_box.list, 1) ; if( cmdWid->selection_box.list_selected_item_position > 0 ) { cmdWid->selection_box.list_selected_item_position-- ; } } tmpXmString = XmStringCopy( listCB->item) ; XmListAddItemUnselected( cmdWid->selection_box.list, tmpXmString, 0) ; XmListSetBottomPos( cmdWid->selection_box.list, 0) ; XmTextFieldSetString( cmdWid->selection_box.text, "") ; /* Call the users command entered callback. */ cmdCB.reason = XmCR_COMMAND_ENTERED ; cmdCB.event = NULL ; cmdCB.value = tmpXmString ; cmdCB.length = XmStringLength( tmpXmString) ; XtCallCallbackList( (Widget) cmdWid, cmdWid->command.callback, &cmdCB) ; XmStringFree( tmpXmString) ; } else /* listCB->reason is BROWSE_SELECT or SINGLE_SELECT */ { /* Update the text widget to relect the latest list selection. */ cmdWid->selection_box.list_selected_item_position = listCB->item_position ; if((text_value = _XmStringGetTextConcat( listCB->item)) != NULL) { XmTextFieldSetString( SB_Text( cmdWid), text_value) ; XmTextFieldSetInsertionPosition( SB_Text( cmdWid), XmTextFieldGetLastPosition( SB_Text( cmdWid))) ; XtFree( text_value) ; } } return ; }