Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!usc!trwind!venice!ries From: ries@venice.SEDD.TRW.COM (Marc Ries) Newsgroups: comp.windows.x Subject: Re: Changing case in a Motif Text Widget? Message-ID: <130@venice.SEDD.TRW.COM> Date: 8 Nov 89 18:47:31 GMT References: Reply-To: ries@venice.sedd.trw.com (Marc Ries) Distribution: comp.windows.x Organization: TRW Systems Engineering & Development Division, Redondo Beach, CA Lines: 112 In article chuck@Morgan.COM (Chuck Ocheret) writes: >All I want to do is have a Text widget which inverts upper/lower >case keystrokes. That is, when you type a lower case 'm', an upper >case 'M' should appear in the widget and vice versa. Other keys >should be unaffected. While the following example (highlight the text, then "U" or "L" keystroke will translate the highlighted text to upper or lower) does not solve your problem, it >might< give you something to go on [I haven't run this through a compiler so there may be some typos]: /* * RESOURCES * toplevel*text.editMode: MULTI_LINE_EDIT * toplevel*text.rows: 20 * toplevel*text.columns: 70 * toplevel*text.insertionPointVisible: TRUE * toplevel*text.autoShowCursorPosition: TRUE */ #include #include void myTextAction (); XtActionsRex myTextActions[] = {"changeCase", (XtActionProc) myTextAction) }; String myTransUpper = "CtrlU: changeCase(U)"; String myTransLower = "CtrlL: changeCase(L)"; void main(argc, argv) unsigned int argc; char **argv; { Widget toplevel, main, text; Arg myArgs[10]; int i; toplevel = XtInitialize (argv[0], "toplevel", NULL, 0, &argc, argv); main = XmCreateMainWindow(toplevel, "main", (Arglist)NULL, (Cardinal)0); XtManageChild(main); text = XmCreateScrolledText(main, "text", (Arglist)NULL, (Cardinal)0); XtManageChild(text); XtAddActions(myNewActions, XtNumber (myNewActions); XtOverrideTranlations(text, XtParseTranslationTable(myTransUpper)); XtOverrideTranlations(text, XtParseTranslationTable(myTransLower)); XtRealizeWidget(toplevel); XtMainLoop(); } /ARGSUSED*/ void myTextAction(w, ev, params) Widget w; XEvent *ev; String *params; { int i=0; char *myStr = XmTextGetSelection(w); XmTextPosition tpos; Arg al[2]; int ac; if(myStr != NULL) { DeletePrimarySelection(w); switch(params[0][0]) { case 'L': i = 0; while(myStr[i] != '\0' { myStr[i] = tolower(myStr[i]); i++ } break; case 'U': i = 0; while(myStr[i] != '\0' { myStr[i] = toupper(myStr[i]); i++ } default: break; } ac = 0; XtSetArg(al[ac], XmNcursorPosition, &tpos); a++; XtGetValues(w, al, ac); XmTextReplace(w, tpos, tpos, myStr); XtFree(myStr); } } void DeletePrimarySelection(w) Widget w; { XClientMessageEvent cm; cm.type = ClientMessage; cm.display = XtDisplay(w); cm.message_type = XmInternAtom(XtDisplay(w), "KILL_SELECTION", FALSE); cm.window = XtWindow(w); cm.format = 32; cm.data[0] = XA_PRIMARY; XSendEvent(XtDisplay(w), cm.window, TRUE, NoEventMask, &cm); } -- Marc Ries ries@venice.sedd.trw.com (ARPA) somewhere!trwind!venice!ries (UUCP) #include