Example #1
0
void WGeMotif::change_value_cb( void *ge_ctx, void *value_object, char *text)
{
  Arg 		args[1];
  WGeMotif   *ge = (WGeMotif *)ge_ctx;

  if ( ge->value_input_open) 
  {
    XtUnmanageChild( ge->value_dialog);
    ge->value_input_open = 0;
    return;
  }

  XtManageChild( ge->value_dialog);

  message( ge, ' ', "");
  XtCallAcceptFocus( ge->value_input, CurrentTime);
  // XtSetKeyboardFocus( ge->toplevel, ge->value_input);

  XtSetArg(args[0],XmNvalue, text);
  XtSetValues( ge->value_input, args, 1);
  XmTextSetCursorPosition( ge->value_input, strlen(text));
  XmTextSetSelection( ge->value_input, 0, strlen(text), CurrentTime);
  ge->value_input_open = 1;
  ge->current_value_object = value_object;
}
Example #2
0
static void make_command_widget(int height)
{
  if (!listener_text)
    {
      Arg args[32];
      Widget wv, wh;
      int n;

      if (!actions_loaded) {XtAppAddActions(MAIN_APP(ss), acts, NUM_ACTS); actions_loaded = true;}

      n = attach_all_sides(args, 0);
      XtSetArg(args[n], XmNheight, height); n++;
      if ((sound_style(ss) == SOUNDS_IN_NOTEBOOK) || (sound_style(ss) == SOUNDS_HORIZONTAL))
	listener_pane = XtCreateManagedWidget("frm", xmFormWidgetClass, SOUND_PANE_BOX(ss), args, n);
      else listener_pane = XtCreateManagedWidget("frm", xmFormWidgetClass, SOUND_PANE(ss), args, n);
      /* this widget is not redundant at least in Metroworks Motif */

      n = 0;
      XtSetArg(args[n], XmNbackground, ss->sgx->listener_color); n++;
      XtSetArg(args[n], XmNforeground, ss->sgx->listener_text_color); n++;
      if (ss->sgx->listener_fontlist) {XtSetArg(args[n], XM_FONT_RESOURCE, ss->sgx->listener_fontlist); n++;}
      n = attach_all_sides(args, n);
      XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
      XtSetArg(args[n], XmNskipAdjust, true); n++;
      XtSetArg(args[n], XmNvalue, listener_prompt(ss)); n++;
      XtSetArg(args[n], XmNpendingDelete, false); n++; /* don't cut selection upon paste */
      XtSetArg(args[n], XmNpositionIndex, XmLAST_POSITION); n++;
      XtSetArg(args[n], XmNhighlightThickness, 1); n++;
      listener_text = XmCreateScrolledText(listener_pane, "lisp-listener", args, n);
      ss->sgx->listener_pane = listener_text;

      XtVaSetValues(MAIN_SHELL(ss), XmNallowShellResize, false, NULL);

      XtManageChild(listener_text);
      XmTextSetCursorPosition(listener_text, 1);
      if (!transTable4) 
	transTable4 = XtParseTranslationTable(TextTrans4);
      XtOverrideTranslations(listener_text, transTable4);
      printout_end = 0;
      XtAddCallback(listener_text, XmNactivateCallback, command_return_callback, NULL);
      XtAddCallback(listener_text, XmNmodifyVerifyCallback, command_modify_callback, NULL);
      XtAddCallback(listener_text, XmNmotionVerifyCallback, command_motion_callback, NULL);

      lisp_window = XtParent(listener_text);
      XtAddEventHandler(lisp_window, EnterWindowMask, false, listener_focus_callback, NULL);
      XtAddEventHandler(lisp_window, LeaveWindowMask, false, listener_unfocus_callback, NULL);
      
      XmChangeColor(lisp_window, ss->sgx->basic_color);
      XtVaGetValues(lisp_window, XmNverticalScrollBar, &wv, XmNhorizontalScrollBar, &wh, NULL);
      XmChangeColor(wv, ss->sgx->basic_color);
      XmChangeColor(wh, ss->sgx->basic_color);
      map_over_children(SOUND_PANE(ss), color_sashes);

      if (auto_resize(ss))
	XtVaSetValues(MAIN_SHELL(ss), XmNallowShellResize, true, NULL);
    }
}
Example #3
0
void append_listener_text(int end, const char *msg)
{
  if (listener_text)
    {
      if (end == -1) end = XmTextGetLastPosition(listener_text);
      XmTextInsert(listener_text, end, (char *)msg);
      XmTextSetCursorPosition(listener_text, XmTextGetLastPosition(listener_text));
    }
}
Example #4
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 #5
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);
    }
}
Example #6
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 #7
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 #8
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 #9
0
static void B1_press(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  XmTextPosition pos;
  XButtonEvent *ev = (XButtonEvent *)event;
  XmProcessTraversal(w, XmTRAVERSE_CURRENT);
  /* we're replacing the built-in take_focus action here, so do it by hand, but leave listener blue, so to speak */
  if (w != listener_text)
    XtVaSetValues(w, XmNbackground, ss->sgx->white, NULL);
  else XmTextClearSelection(listener_text, CurrentTime); /* should this happen in other windows as well? */
  pos = XmTextXYToPos(w, (Position)(ev->x), (Position)(ev->y));
  XmTextSetCursorPosition(w, pos);
  down_pos = pos;
  last_pos = pos;
  if (XEN_HOOKED(listener_click_hook))
    run_hook(listener_click_hook,
	     XEN_LIST_1(C_TO_XEN_INT((int)pos)),
	     S_listener_click_hook);
}
Example #10
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 #11
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;
}
Example #12
0
static void Listener_completion(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  /* used only by the listener widget -- needs to be smart about text since overall string can be enormous 
   *   and we don't want to back up past the last prompt
   *   also if at start of line (or all white-space to previous \n, indent
   */
  int beg, end, len, matches = 0;
  char *old_text;
  ss->sgx->completion_requestor = listener_text;
  ss->sgx->completion_requestor_dialog = NULL;
  beg = printout_end + 1;
  end = XmTextGetLastPosition(w);
  if (end <= beg) return;
  len = end - beg + 1;
  old_text = (char *)CALLOC(len + 1, sizeof(char));
  XmTextGetSubstring(w, beg, len, len + 1, old_text);
  /* now old_text is the stuff typed since the last prompt */
  if (old_text)
    {
      char *new_text = NULL, *file_text = NULL;
      bool try_completion = true;
      new_text = complete_listener_text(old_text, end, &try_completion, &file_text);
      if (!try_completion)
	{
	  FREE(old_text);
	  return;
	}
      if (strcmp(old_text, new_text) == 0) 
	matches = get_completion_matches();
      XmTextReplace(w, beg, end, new_text);
      XmTextSetCursorPosition(w, XmTextGetLastPosition(w));
      if (new_text) 
	{
	  FREE(new_text); 
	  new_text = NULL;
	}
      if (matches > 1)
	{
	  bool need_position;
	  clear_possible_completions();
	  set_save_completions(true);
	  if (file_text) 
	    new_text = filename_completer(file_text, NULL);
	  else new_text = command_completer(old_text, NULL);
	  if (new_text) 
	    {
	      FREE(new_text); 
	      new_text = NULL;
	    }
	  need_position = (completions_dialog == NULL);
	  display_completions();
	  set_save_completions(false);
	  if (need_position)
	    {
	      Position wx, wy;
	      int xoff, yoff; 
	      Window wn;
	      /* try to position the newly popped up help window below the text field */
	      XtVaGetValues(w, XmNx, &wx, XmNy, &wy, NULL);
	      XTranslateCoordinates(XtDisplay(w), XtWindow(w), DefaultRootWindow(XtDisplay(w)), 0, 0, &xoff, &yoff, &wn);
	      wx += xoff; 
	      wy += yoff;
	      XtVaSetValues(completions_dialog, XmNx, wx, XmNy, wy + 140, NULL);
	    }
	}
      if (file_text) FREE(file_text);
      if (old_text) FREE(old_text);
    }
}
Example #13
0
static void Name_completion(Widget w, XEvent *event, char **str, Cardinal *num) 
{
  /* non-listener tab completion */
  int data = -1, i;
  for (i = 0; i < cmpwids_size; i++)
    if (w == cmpwids[i])
      {
	data = i;
	break;
      }
  if (data >= 0)
    {
      int matches;
      char *old_text, *new_text;
      old_text = XmTextGetString(w);
      if (snd_strlen(old_text) == 0) return; /* C-x C-f TAB in minibuffer, for example */
      new_text = complete_text(old_text, data);
      if (snd_strlen(new_text) == 0) return; /* can this happen? */
      matches = get_completion_matches();
      XmTextSetString(w, new_text);
      XmTextSetCursorPosition(w, XmTextGetLastPosition(w));
      if ((strcmp(old_text, new_text) == 0) && 
	  (matches != -1))
	{
	  Pixel old_color;
	  XtVaGetValues(w, XmNforeground, &old_color, NULL);
	  if (matches > 1)
	    XtVaSetValues(w, XmNforeground, ss->sgx->green, NULL);
	  else 
	    if (matches == 0) 
	      XtVaSetValues(w, XmNforeground, ss->sgx->red, NULL);
	  XmUpdateDisplay(w);
#if HAVE_SLEEP
	  sleep(1);
#endif
	  XtVaSetValues(w, XmNforeground, old_color, NULL);
	  XmUpdateDisplay(w);
	  if (matches > 1) 
	    {
	      bool need_position = false;
	      char *search_text;
	      ss->sgx->completion_requestor = w;
	      ss->sgx->completion_requestor_dialog = widget_to_dialog(w);
	      set_save_completions(true);
	      search_text = complete_text(old_text, data);
	      if (search_text) FREE(search_text);
	      if ((!completions_dialog) ||
		  (!(XtIsManaged(completions_dialog))))
		need_position = true;
	      display_completions();
	      set_save_completions(false);
	      if (need_position)
		{
		  Dimension ww;
		  int xoff, yoff; 
		  Window wn;
		  XtVaGetValues(completions_dialog, XmNwidth, &ww, NULL);
		  XTranslateCoordinates(XtDisplay(w), XtWindow(w), DefaultRootWindow(XtDisplay(w)), 0, 0, &xoff, &yoff, &wn);
		  XtVaSetValues(completions_dialog, XmNx, xoff - ww - 40, XmNy, yoff, NULL);
		}
	    }
	  else
	    {
	      /* (if matches == 0) here we could back up the text looking for the nearest completion */
	    }
	}
      if (old_text) XtFree(old_text);
      if (new_text) FREE(new_text);
    }
}
Example #14
0
void goto_listener(void) 
{
  goto_window(listener_text);
  XmTextSetCursorPosition(listener_text, XmTextGetLastPosition(listener_text) + 1);
  XmTextSetInsertionPosition(listener_text, XmTextGetLastPosition(listener_text) + 1);
}