Beispiel #1
0
static void command_motion_callback(Widget w, XtPointer context, XtPointer info)
{
  XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)info;
  int pos;
  cbs->doit = true; 
  if (dont_check_motion) return;
  if (last_highlight_position != -1)
    {
      XmTextSetHighlight(w, last_highlight_position, last_highlight_position + 1, XmHIGHLIGHT_NORMAL);
      last_highlight_position = -1;
    }
  pos = cbs->newInsert - 1;
  if (pos > 0)
    {
      char *str = NULL;
      str = XmTextGetString(w);
      if ((str[pos] == ')') && 
	  ((pos <= 1) || (str[pos - 1] != '\\') || (str[pos - 2] != '#')))
	{
	  int parens;
	  parens = find_matching_paren(str, 1, pos, &last_highlight_position);
	  if (parens == 0)
	    XmTextSetHighlight(w, last_highlight_position, last_highlight_position + 1, XmHIGHLIGHT_SECONDARY_SELECTED);
	}
      if (str) XtFree(str);
    }
}
Beispiel #2
0
static void B1_move(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  XmTextPosition pos;
  XButtonEvent *ev = (XButtonEvent *)event;
  pos = XmTextXYToPos(w, (Position)(ev->x), (Position)(ev->y));
  if (last_pos > pos)                                 /* must have backed up the cursor */
    XmTextSetHighlight(w, pos, last_pos, XmHIGHLIGHT_NORMAL);
  if (down_pos != pos)
    XmTextSetHighlight(w, down_pos, pos, XmHIGHLIGHT_SELECTED);
  last_pos = pos;
}
Beispiel #3
0
static void flash_unbalanced_paren(XtPointer context, XtIntervalId *id)
{
  flashes--;
  XmTextSetHighlight(listener_text, paren_pos, paren_pos + 1, (flashes & 1) ? XmHIGHLIGHT_NORMAL : XmHIGHLIGHT_SELECTED);
  if (flashes > 0)
    XtAppAddTimeOut(MAIN_APP(ss),
		    (unsigned long)FLASH_TIME,
		    (XtTimerCallbackProc)flash_unbalanced_paren,
		    NULL);
  else 
    {
      XmTextSetHighlight(listener_text, paren_pos, paren_pos + 1, XmHIGHLIGHT_NORMAL);
      paren_pos = -1;
    }
}
Beispiel #4
0
bool highlight_unbalanced_paren(void)
{
  /* if cursor is positioned at close paren, try to find reason for unbalanced expr and highlight it */
  int pos;
  bool success = true;
  pos = XmTextGetInsertionPosition(listener_text);
  if (pos > 2)
    {
      char *str;
      str = XmTextGetString(listener_text);
      if ((str[pos - 1] == ')') &&
	  ((str[pos - 2] != '\\') || (str[pos - 3] != '#')))
	{
	  int parens;
	  parens = find_matching_paren(str, 2, pos - 1, &paren_pos);
	  if (parens == 0)
	    {
	      XmTextSetHighlight(listener_text, paren_pos, paren_pos + 1, XmHIGHLIGHT_SELECTED);
	      flashes = 4;
	      XtAppAddTimeOut(MAIN_APP(ss),
			      (unsigned long)FLASH_TIME,
			      (XtTimerCallbackProc)flash_unbalanced_paren,
			      NULL);
	    }
	  else success = false;
	}
      if (str) XtFree(str);
    }
  return(success);
}
Beispiel #5
0
/*
 * Another widget has taken the selection that we used to own.
 */
static void
_XmTextLoseSelection(Widget w, Atom *selection)
{
    XmAnyCallbackStruct	cbs;
    XmTextWidget	tw = (XmTextWidget)w;

    if (*selection == XA_PRIMARY)
    {
	DEBUGOUT(_LtDebug(__FILE__, w, "_XmTextLoseSelection(PRIMARY)\n"));

	XmTextSetHighlight(w, 0, XmTextGetLastPosition(w),
			   XmHIGHLIGHT_NORMAL);

	/*
	 * FIX ME
	 * Need to call losePrimaryCallback here ?
	 */
	cbs.reason = XmCR_LOSE_PRIMARY;
	cbs.event = NULL;	/* ??? */
	XtCallCallbackList(w,
                           tw->text.lose_primary_callback,
                           (XtPointer)&cbs);
    }
    else
    {
	DEBUGOUT(_LtDebug(__FILE__, w, "_XmTextLoseSelection(?)\n"));
	/* ??? */
    }
}
Beispiel #6
0
void RXmTextSetHighlight(message_t message)
{
  Widget w;
  XmTextPosition left,right;
  XmHighlightMode mode;

  toolkit_read_value(message,&w,XtRWidget);
  toolkit_read_value(message,&left,XtRInt);
  toolkit_read_value(message,&right,XtRInt);
  toolkit_read_value(message,&mode,XtREnum);
  XmTextSetHighlight(w,left,right,mode);
}
Beispiel #7
0
static void B1_release(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  XmTextPosition pos;
  XButtonEvent *ev = (XButtonEvent *)event;
  pos = XmTextXYToPos(w, (Position)(ev->x), (Position)(ev->y));
  XmTextSetCursorPosition(w, pos);
  if (down_pos != pos)
    {
      XmTextSetHighlight(w, down_pos, pos, XmHIGHLIGHT_SELECTED);
      if (listener_selection) {XtFree(listener_selection); listener_selection = NULL;}
      XmTextSetSelection(w, down_pos, pos, CurrentTime);
      listener_selection = XmTextGetSelection(w);
    }
}
Beispiel #8
0
// Show prompt according to current mode
static void show_isearch()
{
    XmTextPosition start = start_of_line();
    if (start == XmTextPosition(-1))
	return;

    string prompt;
    switch (isearch_state)
    {
    case ISEARCH_NONE:
	prompt = gdb->prompt();
	break;

    case ISEARCH_NEXT:
	prompt = isearch_prompt;
	break;

    case ISEARCH_PREV:
	prompt = reverse_isearch_prompt;
	break;
    }

    if (isearch_state != ISEARCH_NONE)
	prompt += "`" + cook(isearch_string) + "': ";
    string input = current_line();
    string line  = prompt + input;

    bool old_private_gdb_output = private_gdb_output;
    private_gdb_output = true;
    XmTextReplace(gdb_w, start, XmTextGetLastPosition(gdb_w), XMST(line.chars()));
    promptPosition = start + prompt.length();

    XmTextPosition pos = promptPosition;
    int index = input.index(isearch_string);
    if (isearch_state == ISEARCH_NONE || index < 0)
    {
	XmTextSetHighlight(gdb_w, 0, XmTextGetLastPosition(gdb_w),
			   XmHIGHLIGHT_NORMAL);
    }
    else
    {
	XmTextSetHighlight(gdb_w,
			   0,
			   pos + index,
			   XmHIGHLIGHT_NORMAL);
	XmTextSetHighlight(gdb_w,
			   pos + index, 
			   pos + index + isearch_string.length(),
			   XmHIGHLIGHT_SECONDARY_SELECTED);
	XmTextSetHighlight(gdb_w, 
			   pos + index + isearch_string.length(),
			   XmTextGetLastPosition(gdb_w),
			   XmHIGHLIGHT_NORMAL);
    }

    if (index >= 0)
	pos += index;

    XmTextSetInsertionPosition(gdb_w, pos);
    XmTextShowPosition(gdb_w, pos);
    have_isearch_line = false;
    private_gdb_output = old_private_gdb_output;
}
Beispiel #9
0
/*
 * SetSelection : indicate that we have the selection.
 *
 * Actions :
 *      - indicate it in the source
 *      - deal with Xt Selections (XtOwnSelection etc.)
 *      - call callback(s) (LoseSelection,GainSelection)
 *      - tell the widgets that display us about this (highlight)
 */
static void
SetSelection(XmTextSource source, XmTextPosition left,
	     XmTextPosition right, Time time)
{
    XmSourceData d = source->data;
    int i;
    Boolean gain = False;

    DEBUGOUT(_LtDebug(__FILE__, NULL, "XmTextStrSource SetSelection %d %d\n",
		      left, right));

    if (left >= right)
    {				/* No decent selection */
        /* SG 23/08/1998, just bring into line with changes in TextF.c */
        if(!source->data->hasselection)
        {
            return; /* Already no selection, don't do unnecessary work */
        }
	source->data->hasselection = False;
	source->data->left = -1;
	source->data->right = -1;
	source->data->prim_time = time;

	XtDisownSelection((Widget)d->widgets[0], XA_PRIMARY, time);

	for (i = 0; i < d->numwidgets; i++)
	{
	    XmTextSetHighlight((Widget)d->widgets[i],
			       0, XmTextGetLastPosition((Widget)d->widgets[0]),
			       XmHIGHLIGHT_NORMAL);
	}

	return;
    }

    /* Remember whether we used to have the selection */
    gain = (source->data->hasselection == False);

    /* We have a decent selection; indicate in memory */
    source->data->hasselection = True;
    source->data->left = left;
    source->data->right = right;
    source->data->prim_time = time;

    /* Xt, callbacks */
    DEBUGOUT(_LtDebug(__FILE__, (Widget)d->widgets[0],
		      "XtOwnSelection(_, XA_PRIMARY, ...)\n"));

    if (!XtOwnSelection((Widget)d->widgets[0], XA_PRIMARY, time,
			_XmTextConvertSelection, _XmTextLoseSelection, NULL))
    {
	gain = False;
    }

    if (gain)
    {
	XmAnyCallbackStruct cbs;

	cbs.reason = XmCR_GAIN_PRIMARY;
	cbs.event = NULL;	/* Have no information nested this deep */

	/* FIX ME : Only for one widget ? */
	XtCallCallbackList((Widget)source->data->widgets[0],
			   source->data->widgets[0]->text.gain_primary_callback,
			   (XtPointer)&cbs);

    }

    /* Widgets */
    for (i = 0; i < d->numwidgets; i++) {
	/* Unset the highlight over the complete widget */
	XmTextSetHighlight((Widget)d->widgets[i],
		0, XmTextGetLastPosition((Widget)d->widgets[0]),
		XmHIGHLIGHT_NORMAL);
	/* Highlight the selected area */
	XmTextSetHighlight((Widget)d->widgets[i], left, right,
		XmHIGHLIGHT_SELECTED);
    }
}
Beispiel #10
0
/*
 * This function should also take care of highlighting and selections.
 *
 * NOTE: test/Xm/text/test3 shows that if a widget is modified, callbacks
 *      are called only for the widget involved, NOT for all widgets displaying
 *      that particular source.
 *      Therefore, we only work on one widget in part of the implementation.
 *
 * NOTE : Do NOT check for d->editable (in order not to do the editing).
 *      At this low level this function gets called for ALL editing, not just
 *      the user-inflicted ones. Therefore edits must happen.
 */
static XmTextStatus
Replace(XmTextWidget w,
	XEvent *ev,
	XmTextPosition *startret,
	XmTextPosition *endret,
	XmTextBlock block,
	Boolean call_callback)
{
    XmSourceData d;
    int i;
    XmTextPosition start, end, lastPos = 0;
    XmTextVerifyCallbackStruct cbs;

	DEBUGOUT(_LtDebug(__FILE__, (Widget)w,
		"XmTextStrSrc-Replace(start %d, end %d, call %d)\n",
		*startret, *endret, call_callback));

    if (!call_callback || _XmTextModifyVerify(w, ev, startret, endret, &Text_CursorPos(w), block, NULL, False))
    {
	d = Text_Source(w)->data;

	start = *startret;
	end = *endret;

	if (start > end)
	{
	    int swap;

	    swap = start;
	    start = end;
	    end = swap;
	}

	if (end > d->length)
	{
	    end = d->length;
	}

	if (start > d->length)
	{
	    return EditError;
	}

	if ( ( start >= end ) &&
		   d->length + (end - start) + block->length > d->maxallowed)
	{
	    return EditError;
	}

	for (i = 0; i < d->numwidgets; i++)
	{
	    _XmTextDisableRedisplay(d->widgets[i], True);
	}

	if (end > start)
	{				/* we need to delete some stuff */
	    char *dest, *source, *last;

	    dest = d->ptr + start;
	    source = d->ptr + end;
	    last = d->ptr + d->length;
	    while (source < last)
	    {
		*dest++ = *source++;
	    }

	    d->length -= end - start;
	}

	if (block && block->length > 0)
	{
	    CheckSize(d, block->length);
	    Insert(d, start, block->ptr, block->length);
	}

	for (i = 0; i < d->numwidgets; i++)
	{
	    XmTextPosition startPos = (*Text_Source(w)->Scan)(Text_Source(w), 0, XmSELECT_ALL, XmsdLeft, 1, False ) ;
	    lastPos = (*Text_Source(w)->Scan)(Text_Source(w), startPos, XmSELECT_ALL, XmsdRight, 1, False ) ;
	}

       if ( d -> hasselection )
	    {
	    /* rws 15 Jan 2000
	       What if only part of the selection is being replaced???
	    if ( start == d->left && end == d-> right )
	    */
	    if ( start <= d->right && end >= d->left )
		{
		    /* CP:15 May 1999: If the text we are replacing is the
		    ** selected text then unselect it. */
		d->hasselection = False;
		for (i = 0; i < d->numwidgets; i++)
		  {
#if 0
		    _XmHighlightRecNode* p;
		    p = Text_Highlight(d->widgets[i]).list;
		    while (p) {
		      _XmHighlightRecNode* k=p;
		      p = p->next;
		      XtFree((XtPointer)k);
		    }
		    Text_Highlight(d->widgets[i]).list = NULL;
#else
		    Text_Highlight(d->widgets[i]).number = 0;
#endif
		  }
		}
	    /*CP:15 May 1999:
		    at this point we do not want to overwrite the selection
		    but just to move its coordinates if we are inserting
		    text before the selection. */

	    else if ( start <  d-> left )
		    {
		    d-> left += block -> length;
		    d-> right += block -> length;
		    for (i = 0; i < d->numwidgets; i++)
			    {
			    XmTextSetHighlight((Widget)d->widgets[i],
				    d-> left, d->right, XmHIGHLIGHT_SELECTED);
			    }
		    }
	    }
	/* End selection */

	if (Text_CursorPos(w) == Text_LastPos(w))
	{
	    if (call_callback)
	    {
		Text_LastPos(w) = lastPos;
	    }
	    if (lastPos != Text_CursorPos(w))
	    {
		_XmTextSetCursorPosition((Widget)w, lastPos);
	    }
	}
	Text_LastPos(w) = lastPos;
	if (Text_CursorPos(w) > Text_LastPos(w))
	{
	    Text_CursorPos(w) = Text_LastPos(w);
	}
	if (Text_ValueChangedCallback(w))
	{
	    cbs.reason = XmCR_VALUE_CHANGED;
	    cbs.currInsert = cbs.newInsert = start;
	    cbs.startPos = cbs.endPos = start;
	    cbs.text = block;

	    XtCallCallbacks((Widget)w, XmNvalueChangedCallback, &cbs);
	}

	for (i = 0; i < d->numwidgets; i++) {
		_XmTextUpdateLineTable((Widget)d->widgets[i], start, end, block, True);
	}

	for (i = 0; i < d->numwidgets; i++) {
		_XmTextInvalidate(d->widgets[i], start, end, block->length - end + start);
	}

#if 1
	/* Update the insertion position */
	for (i = 0; i < d->numwidgets; i++)
	{
	    XmTextPosition	p = Text_CursorPos(d->widgets[i]);

	    if (p < *startret) {
		    /* no action */
	    } else if (p < *endret) {
		    _XmTextSetCursorPosition((Widget)d->widgets[i], *startret);
	    } else {
		    _XmTextSetCursorPosition((Widget)d->widgets[i], p + block->length);
	    }
	}
#endif

	for (i = 0; i < d->numwidgets; i++)
	{
	    _XmTextEnableRedisplay(d->widgets[i]);
	}
    }

    return EditDone;
}