Example #1
0
void clear_listener(void)
{
  if ((listener_text) && /* this can be called even when there is no listener */
      (XmTextGetCursorPosition(listener_text) > 1))
    {
      dont_check_motion = true;
      XmTextSetSelection(listener_text, 1, XmTextGetCursorPosition(listener_text), CurrentTime);
      XmTextRemove(listener_text);
      dont_check_motion = false;
    }
}
Example #2
0
static void Yank(Widget w, XEvent *ev, char **str, Cardinal *num) 
{
  /* copy current selection at current cursor position */
  if (listener_selection) 
    {
      XmTextPosition curpos;
      curpos = XmTextGetCursorPosition(w);
      XmTextInsert(w, curpos, listener_selection);
      curpos += strlen(listener_selection);
      XmTextShowPosition(w, curpos);
      XmTextSetCursorPosition(w, curpos);
      XmTextClearSelection(w, ev->xkey.time); /* so C-y + edit doesn't forbid the edit */
    }
}
Example #3
0
static void Word_upper(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  bool up, cap;
  XmTextPosition curpos, endpos;
  up = (str[0][0] == 'u');
  cap = (str[0][0] == 'c');
  curpos = XmTextGetCursorPosition(w);
  endpos = XmTextGetLastPosition(w);
  if (curpos < endpos)
    {
      int i, length, wstart, wend;
      char *buf = NULL;
      length = endpos - curpos;
      buf = (char *)CALLOC(length + 1, sizeof(char));
      XmTextGetSubstring(w, curpos, length, length + 1, buf);
      wstart = 0;
      wend = length;
      for (i = 0; i < length; i++)
	if (!isspace((int)(buf[i])))
	  {
	    wstart = i;
	    break;
	  }
      for (i = wstart + 1; i < length; i++)
	if (isspace((int)(buf[i])))
	  {
	    wend = i;
	    break;
	  }
      if (cap)
	{
	  buf[0] = toupper(buf[wstart]);
	  buf[1] = '\0';
	  XmTextReplace(w, curpos + wstart, curpos + wstart + 1, buf);
	}
      else
	{
	  int j;
	  for (i = wstart, j = 0; i < wend; i++, j++)
	    if (up) 
	      buf[j] = toupper(buf[i]);
	    else buf[j] = tolower(buf[i]);
	  buf[j] = '\0';
	  XmTextReplace(w, curpos + wstart, curpos + wend, buf);
	}
      XmTextSetCursorPosition(w, curpos + wend);
      if (buf) FREE(buf);
    }
}
Example #4
0
static void Text_transpose(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  XmTextPosition curpos;
  curpos = XmTextGetCursorPosition(w);
  if (curpos > 1)
    {
      char buf[3]; /* needs room for null */
      char tmp;
      XmTextGetSubstring(w, (XmTextPosition)(curpos - 1), 2, 3, buf);
      tmp = buf[0];
      buf[0] = buf[1];
      buf[1] = tmp;
      XmTextReplace(w, curpos - 1, curpos + 1, buf);
      XmTextSetCursorPosition(w, curpos + 1);
    }
}
Example #5
0
static void Kill_line(Widget w, XEvent *ev, char **str, Cardinal *num) 
{
  /* C-k with storage of killed text */
  XmTextPosition curpos, loc;
  Boolean found;
  curpos = XmTextGetCursorPosition(w);
  found = XmTextFindString(w, curpos, "\n", XmTEXT_FORWARD, &loc);
  if (!found) loc = XmTextGetLastPosition(w);
  if (loc > curpos)
    {
      if (listener_selection) {XtFree(listener_selection); listener_selection = NULL;}
      XmTextSetSelection(w, curpos, loc, CurrentTime);
      listener_selection = XmTextGetSelection(w); /* xm manual p329 sez storage is allocated here */
      XmTextCut(w, CurrentTime);
    }
}
Example #6
0
static void
handle_statusline_event(Widget w, XtPointer client_data,
			XEvent *ev, Boolean *cont)
{
    /*      const char *text = (const char *)client_data; */
    UNUSED(w);
    UNUSED(client_data);
    UNUSED(cont);

    /*      fprintf(stderr, "text: |%s|; event: %p\n", text, ev); */
    /* only used to do this if page history was already active, but it's probably
       nicer to be able to get the history by clicking on the statusline ...
    */
    if (/* strncmp(text, "Page history:", sizeof "Page history:" - 1) == 0 && */ ev != NULL) {
	XmTextPosition pos = XmTextGetCursorPosition(statusline);
	char *ptr1, *ptr2;
	int diff = 0;
	/*  	fprintf(stderr, "pos: %d\n", pos); */
	if (pos == 0) { /* just display the page history */
	    page_history_move(0);
	    return;
	}
	ptr1 = g_string_savebuf + pos;
	ptr2 = strchr(g_string_savebuf, '[');
	if (ptr2 == NULL) { /* some other string, also display the page history */
	    page_history_move(0);
	    return;
	}
	/* 	fprintf(stderr, "ptr1: |%s|; ptr2: |%s|\n", ptr1, ptr2); */
	while (ptr1 < ptr2) {
	    if (*ptr1 == ' ' && *(ptr1 + 1) != '-') /* separator */
		diff--;
	    ptr1++;
	}

	while (ptr1 > ptr2) {
	    if (*ptr1 == ' ' && *(ptr1 - 1) != '-') /* separator */
		diff++;
	    ptr1--;
	}
	/* 	fprintf(stderr, "diff: %d\n", diff); */
	page_history_move(diff);
    }
}
Example #7
0
static void Begin_of_line(Widget w, XEvent *ev, char **ustr, Cardinal *num) 
{
  /* don't back up before listener prompt */
  XmTextPosition curpos, loc;
  Boolean found;
  curpos = XmTextGetCursorPosition(w) - 1;
  found = XmTextFindString(w, curpos, "\n", XmTEXT_BACKWARD, &loc);
  if (found) 
    {
      char *str = NULL;
      str = (char *)CALLOC(ss->listener_prompt_length + 3, sizeof(char));
      XmTextGetSubstring(w, loc + 1, ss->listener_prompt_length, ss->listener_prompt_length + 2, str);
      if (strncmp(listener_prompt(ss), str, ss->listener_prompt_length) == 0)
	XmTextSetCursorPosition(w, loc + ss->listener_prompt_length + 1);
      else XmTextSetCursorPosition(w, loc + 1);
      FREE(str);
    }
  else XmTextSetCursorPosition(w, 1);
}
Example #8
0
static void Complain(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  /* if the minibuffer has focus (via pointer movement) and user types C-j (for example),
   *   the textfield widget doesn't have any action associated with that, so it prints
   *   C-j and leaves the cursor where it was; without this action, Motif posts a small
   *   empty box where the character should be, which can be confusing; another option
   *   would be to activate the keyboard instead (as in C-x), but I think that would only
   *   add to the confusion.
   */
  char *old_text, *new_text;
  XmTextPosition curpos;
  curpos = XmTextGetCursorPosition(w);
  old_text = XmTextGetString(w);
  new_text = (char *)CALLOC(snd_strlen(old_text) + 5, sizeof(char));
  sprintf(new_text, "%s C-%c", (old_text) ? old_text : "", str[0][0]);
  XmTextSetString(w, new_text);
  XmTextSetCursorPosition(w, curpos);
  if (old_text) XtFree(old_text);
  FREE(new_text);
}
Example #9
0
//
// Input from motif text-widget with recall
// Returns 1 if return i pressed, else 0.
//
int mrm_TextInput( Widget w, XEvent *event, char *recall, int line_size, 
	int recall_size, int *current_recall_line)
{
  KeySym keysym;
  Modifiers mod;
  int 	pos;
  char 	*text;
  char 	newtext[160];
  int	i;
  XmTextPosition   left, right;
  char  *s, *t;

  text = XmTextGetString( w);
  XtTranslateKeycode( flow_Display(w), event->xkey.keycode, event->xkey.state, 
	&mod, &keysym);
  keysym &= 0xFFFF;
  switch ( keysym) 
  {
    case XK_Return:
    case XK_Linefeed:
      // Insert in recall buffer
      if ( strcmp( text, "") != 0)
      {
        for ( i = recall_size - 2; i >= 0; i--)
          strcpy( recall + (i+1) * line_size, recall + i * line_size);
        strncpy( recall, text, line_size);
        recall[line_size-1] = 0;
      }
      *current_recall_line = 0;
      return 1;
    case XK_Up:
      (*current_recall_line)++;
      if ( *current_recall_line > recall_size - 1)
        *current_recall_line = recall_size - 1;
      XmTextSetString( w, recall + (*current_recall_line - 1) * line_size);
      XmTextSetCursorPosition( w, 
		strlen(recall + (*current_recall_line - 1) * line_size));
      break;
    case XK_Down:
      if ( *current_recall_line == 0)
        XmTextSetString( w, "");
      else if ( *current_recall_line == 1)
      {
        XmTextSetString( w, "");
        (*current_recall_line)--;
      }
      else
      {
        (*current_recall_line)--;
        XmTextSetString( w, recall + (*current_recall_line - 1) * line_size);
        XmTextSetCursorPosition( w, 
		strlen(recall + (*current_recall_line - 1) * line_size));
      }
      break;
    case XK_Left:
      XmTextClearSelection( w, CurrentTime);
      pos = XmTextGetCursorPosition( w);
      if ( pos == 0)
        break;
      pos--;
      XmTextSetCursorPosition( w, pos);
      break;
    case XK_Right:
      XmTextClearSelection( w, CurrentTime);
      pos = XmTextGetCursorPosition( w);
      if ( pos >= line_size - 1)
        break;
      pos++;
      if ( pos > strlen(text))
        break;
      XmTextSetCursorPosition( w, pos);
      break;
    case XK_BackSpace:
    case 65535:
      if ( XmTextGetSelectionPosition( w, &left, &right)) {
        for ( s = text + left, t = text + right; *t; s++,t++)
	  *s = *t; 
        *s = 0;
        XmTextSetString( w, text);
        XmTextSetCursorPosition( w, left);
      }
      else {
        pos = XmTextGetCursorPosition( w);
        if ( pos == 0)
          break;
        if ( pos == 1)
          strcpy( newtext, "");
        else
          strncpy( newtext, text, pos-1);
        newtext[pos-1] = 0;
        strncat( newtext, &text[pos], sizeof( newtext));
        XmTextSetString( w, newtext);
        XmTextSetCursorPosition( w, pos-1);
      }
      break;
    default:
      if ( event->xkey.state & ControlMask)
        return 0;
      if ( keysym > 256)
        return 0;

      if ( XmTextGetSelectionPosition( w, &left, &right)) {
        for ( s = text + left, t = text + right; *t; s++,t++)
	  *s = *t; 
        *s = 0;
        XmTextSetCursorPosition( w, left);
      }
      pos = XmTextGetCursorPosition( w);
      if ( pos >= line_size - 1)
        break;
      if ( pos == 0)
        strcpy( newtext, "");
      else
        strncpy( newtext, text, pos);
      newtext[pos] = keysym;
      newtext[pos+1] = 0;
      strncat( newtext, &text[pos], sizeof( newtext));
      XmTextSetString( w, newtext);
      XmTextSetCursorPosition( w, pos+1);
  }
  return 0;
}