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 iupmotCBmask(Widget w, XtPointer client_data, XtPointer call_data) { if (fill[0]) { XmTextFieldInsert(w, XmTextFieldGetLastPosition(w), fill); fill[0] = 0; } }
static int motListSetAppendAttrib(Ihandle* ih, const char* value) { if (value && ih->data->has_editbox) { XmTextPosition pos; Widget cbedit; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); pos = XmTextFieldGetLastPosition(cbedit); iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); /* disable callbacks */ XmTextFieldInsert(cbedit, pos+1, (char*)value); iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } return 0; }
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 void motListEditKeyPressEvent(Widget cbedit, Ihandle *ih, XKeyEvent *evt, Boolean *cont) { *cont = True; iupmotKeyPressEvent(cbedit, ih, (XEvent*)evt, cont); if (*cont == False) return; if (evt->state & ControlMask) /* Ctrl */ { KeySym motcode = iupmotKeycodeToKeysym(evt); if (motcode == XK_c) { motListSetClipboardAttrib(ih, "COPY"); *cont = False; return; } else if (motcode == XK_x) { motListSetClipboardAttrib(ih, "CUT"); *cont = False; return; } else if (motcode == XK_v) { motListSetClipboardAttrib(ih, "PASTE"); *cont = False; return; } else if (motcode == XK_a) { XmTextFieldSetSelection(cbedit, 0, XmTextFieldGetLastPosition(cbedit), CurrentTime); *cont = False; return; } } }
/************************************************************************ * * 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 ; }
void RequestCB( XtPointer client_data, int *source, XtInputId *id) { char buf[512]; int count; int remainder; RequestHeader *phdr = (RequestHeader *)buf; #ifdef VG_TRACE vg_TRACE_EXECUTION("main: entered RequestCB ..."); #endif /* VG_TRACE */ /* * There's a request in the pipe. Read the header. */ count = read(0, buf, sizeof(*phdr)); if (count != sizeof(*phdr)) { return; } /* * Calculate amount of data after header. */ remainder = phdr->length - sizeof(*phdr); if (remainder > 0) { /* * Read remainder of request. */ count = read(0, buf+sizeof(*phdr), remainder); } /* * Initiate response to request. */ switch(phdr->opcode) { case REQUEST_OP_EXIT: #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_EXIT ..."); #endif /* VG_TRACE */ RespondExitCB(NULL, NULL, NULL); break; case REQUEST_OP_MESSAGE: { RequestMessage *r = (RequestMessage *)phdr; XmString string; #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_MESSAGE ..."); #endif /* VG_TRACE */ if (r->idMC) { FILE *fp; /* * Caller passed in MC_* message id. */ if (r->idMC == MC_NO_LOGIN && (fp = fopen(NO_LOGIN_FILE,"r")) != NULL) { /* * For MC_NO_LOGIN read message from file. */ char buffer[256]; int j; string = NULL; while (fgets(buffer, 256, fp) != NULL) { j = strlen(buffer); if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0'; string = XmStringConcat(xmstr, XmStringCreate(buffer, XmFONTLIST_DEFAULT_TAG)); string = XmStringConcat(xmstr, XmStringSeparatorCreate()); } } else { /* * Read message from message catalog. */ string = ReadCatalogXms(MC_ERROR_SET, r->idMC, buf+r->offMessage); } } else { /* * Generate message from provided string. */ #ifdef SIA string = multiline_xmstring(buf+r->offMessage); #else string = XmStringCreate(buf+r->offMessage,XmFONTLIST_DEFAULT_TAG); #endif } _DtShowDialog(error, string); XmStringFree(string); } break; case REQUEST_OP_HOSTNAME: #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_HOSTNAME ..."); #endif /* VG_TRACE */ _DtShowDialog(hostname, NULL); break; case REQUEST_OP_EXPASSWORD: #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_EXPASSWORD ..."); #endif /* VG_TRACE */ _DtShowDialog(expassword, NULL); break; case REQUEST_OP_CHPASS: #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_CHPASS ..."); #endif /* VG_TRACE */ break; case REQUEST_OP_CHALLENGE: { RequestChallenge *r = (RequestChallenge *)phdr; XmString string; int i; LoginTextPtr textdata; Boolean change; #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_CHALLENGE ..."); #endif /* VG_TRACE */ textdata = GetLoginTextPtr(login_text); change = (textdata->bEcho != r->bEcho); XtUnmapWidget(textdata->text[textdata->bEcho]); textdata->bEcho = r->bEcho; textdata->noechobuf[0] = '\0'; XtAddEventHandler(textdata->text[textdata->bEcho], ExposureMask, False, FakeFocusIn, NULL); XtMapWidget(textdata->text[textdata->bEcho]); XtPopup(login_shell, XtGrabNone); XGrabKeyboard (dpyinfo.dpy, XtWindow (textdata->text[textdata->bEcho]), False, GrabModeAsync, GrabModeAsync, CurrentTime); XmTextFieldSetString( textdata->text[textdata->bEcho], r->offUserNameSeed ? buf+r->offUserNameSeed : ""); XmTextFieldSetSelection ( textdata->text[1], 0, XmTextFieldGetLastPosition(textdata->text[1]), CurrentTime ); if (r->idMC) { /* * Read message from message catalog. */ string = ReadCatalogXms(MC_LABEL_SET, r->idMC, buf+r->offChallenge); } else { /* * Generate message from provided string. */ string = XmStringCreate(buf+r->offChallenge,XmFONTLIST_DEFAULT_TAG); } i = 0; XtSetArg(argt[i], XmNlabelString, string ); i++; XtSetValues(login_label, argt, i); XmStringFree(string); if (change) { char buf[256]; i = 0; if (textdata->bEcho) { XtSetArg(argt[i], XmNlabelString, textdata->onGreeting ); i++; } else { sprintf(buf, textdata->offGreetingFormat, textdata->offGreetingUname); string = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG); XtSetArg(argt[i], XmNlabelString, string ); i++; free(textdata->offGreetingUname); } XtSetValues(greeting, argt, i); /* set the dt_label with the session that is enabled */ SetDtLabelAndIcon(); } XtSetSensitive(ok_button, True); XtSetSensitive(clear_button, True); XtSetSensitive(options_button, True); XtSetSensitive(help_button, True); XUngrabKeyboard(dpyinfo.dpy,CurrentTime); } break; #ifdef SIA case REQUEST_OP_FORM: { RequestForm *r = (RequestForm *)buf; int i; char *prompt_ptr; #ifdef VG_TRACE vg_TRACE_EXECUTION("main: got REQUEST_OP_FORM ..."); #endif /* VG_TRACE */ siaFormInfo.num_prompts = r->num_prompts; siaFormInfo.rendition = r->rendition; siaFormInfo.title = XtMalloc(strlen(buf + r->offTitle)); strcpy(siaFormInfo.title, buf + r->offTitle); prompt_ptr = buf + r->offPrompts; for (i=0; i < siaFormInfo.num_prompts; i++) { siaFormInfo.visible[i] = r->visible[i]; siaFormInfo.prompts[i] = XtMalloc(strlen(prompt_ptr)); siaFormInfo.answers[i] = NULL; strcpy(siaFormInfo.prompts[i], prompt_ptr); prompt_ptr += strlen(prompt_ptr) + 1; } /* * Create Widgets: * Form * Title * prompt labels and answer text fields for each prompt * OK button * Add callbacks as needed. If not visible don't echo. * On OK callback, collect info and send it. Destroy widgets. */ SiaForm(&siaFormInfo); } break; #endif /* SIA */ } #if 0 { /* * Send immediate response to debug. */ char outbuf[512]; char *p; ResponseDebug *rdebug = (ResponseDebug *)outbuf; rdebug->hdr.opcode = REQUEST_OP_DEBUG; rdebug->hdr.reserved = 0; rdebug->offString = sizeof(*rdebug); p = ((char *)(rdebug)) + rdebug->offString; strcpy(p, "This is my debug string"); rdebug->hdr.length = sizeof(*rdebug) + strlen(p) + 1; TellRequester(outbuf, (size_t) rdebug->hdr.length); } #endif }