예제 #1
0
/**************************************************************************
  Appends the string to the chat output window.  The string should be
  inserted on its own line, although it will have no newline.
**************************************************************************/
void real_output_window_append(const char *astring,
                               const struct text_tag_list *tags,
                               int conn_id)
{
  /* this is properly a bad way to append to a text widget. Using the 
   * "useStringInPlace" resource and doubling mem alloc'ing would be better.  
   * Nope - tried it and many other variations and it wasn't any better. 
   * I'll replace this widget with a widget supportting hyperlinks later, so
   * leth's forget the problem.
   *
   * There seems to be an Xaw problem with doing both wrap and scroll:
   * its supposed to automatically scroll to end when we change the insertion
   * point, but if a line is wrapped the scroll lags behind a line, and
   * stays behind on subsequent additions, until the too-long line scrolls
   * off the top.  (I tried setting the insert position to the last char,
   * instead of the start of line as below, but that didn't help.)  So we
   * split the line ourselves.  I'm just using a fixed length split; should
   * perhaps check and use width of output window (but font size?)  -dwp
   *
   * Now uses window's font size and width.  Assumes fixed-width font.  --jjm
   */
  String theoutput;
  char *newout, *rmcr, *astring2 = mystrdup(astring);

  XtVaGetValues(outputwindow_text, XtNstring, &theoutput, NULL);
  newout=fc_malloc(strlen(astring2)+strlen(theoutput)+2);
  sprintf(newout, "%s\n%s", theoutput, astring2);

  /* calc carret position - last line, first pos */ 
  for(rmcr=newout+strlen(newout); rmcr>newout; rmcr--)
    if(*rmcr=='\n')
      break;

  /* shit happens when setting both values at the same time */
  XawTextDisableRedisplay(outputwindow_text);
  XtVaSetValues(outputwindow_text, XtNstring, newout, NULL);
  XtVaSetValues(outputwindow_text, XtNinsertPosition, rmcr-newout+1, NULL);
  XawTextEnableRedisplay(outputwindow_text);
  
  free(newout);
  free(astring2);
}
예제 #2
0
파일: AsciiText.c 프로젝트: aosm/X11libs
/*
 * Implementation
 */
static void
XawAsciiInitialize(Widget request, Widget cnew,
		   ArgList args, Cardinal *num_args)
{
    AsciiWidget w = (AsciiWidget)cnew;
    int i;
    int tabs[TAB_COUNT], tab;

    MultiSinkObject sink;

    /* superclass Initialize can't set the following,
     * as it didn't know the source or sink when it was called
     */
    if (XtHeight(request) == DEFAULT_TEXT_HEIGHT)
	XtHeight(cnew) = DEFAULT_TEXT_HEIGHT;

    /* This is the main change for internationalization  */
    if (w->simple.international == True) { /* The multi* are international */
	if (w->text.sink == NULL)
	    w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass,
					  cnew, args, *num_args);
	else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass))
	    XtError("Sink object is not a subclass of multiSink");

	if (w->text.source == NULL)
	    w->text.source = XtCreateWidget("textSource", multiSrcObjectClass,
					    cnew, args, *num_args);
	else if (!XtIsSubclass(w->text.source, multiSrcObjectClass))
	    XtError("Source object is not a subclass of multiSrc");
#ifndef OLDXAW
	else
	    _XawSourceAddText(w->text.source, cnew);
#endif
    }
    else {
	if (w->text.sink == NULL)
	    w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass,
					  cnew, args, *num_args);
	else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass))
	    XtError("Sink object is not a subclass of asciiSink");

	if (w->text.source == NULL)
	    w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass,
					    cnew, args, *num_args);
	else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass))
	    XtError("Source object is not a subclass of asciiSrc");
#ifndef OLDXAW
	else
	    _XawSourceAddText(w->text.source, cnew);
#endif
    }

    if (XtHeight(w) == DEFAULT_TEXT_HEIGHT)
	XtHeight(w) = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1);

    for (i = 0, tab = 0; i < TAB_COUNT; i++)
	tabs[i] = (tab += 8);
  
    XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs);

    XawTextDisableRedisplay(cnew);
    XawTextEnableRedisplay(cnew);

    _XawImRegister(cnew);

    /* If we are using a MultiSink we need to tell the input method stuff */
    if (w->simple.international == True) {
	Arg list[4];
	Cardinal ac = 0;

	sink = (MultiSinkObject)w->text.sink;
	XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset);	ac++;
	XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos);	ac++;
	XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground);	ac++;
	XtSetArg(list[ac], XtNbackground, sink->text_sink.background);	ac++;
	_XawImSetValues(cnew, list, ac);
    }
}