Beispiel #1
0
void
ScopeMenu::receive (ScopeRenamed &msg, void *client_data)
{
  ON_DEBUG (puts ("ScopeMenu: handling rename message"));
  // First find renamed button in our list.
  Arg args[2];
  int n;
  Cardinal num_kids;
  WidgetList kids;

  n = 0;
  XtSetArg(args[n], XmNnumChildren, &num_kids); n++;
  XtSetArg(args[n], XmNchildren, &kids); n++;
  XtGetValues(f_pull_menu, args, n);

  unsigned int i;
  for (i = 0; i < num_kids; i++)
    {
      if (XmIsPushButtonGadget (kids[i]) &&
	  msg.f_search_scope ==
	  ((UAS_SearchScope *) WXmPushButtonGadget (kids[i]).UserData()))
	break;
    }

  // It had better be in the list! 
  Xassert (i != num_kids);
  ON_DEBUG (printf ("ScopeMenu: widget #%d is the button\n", i));

  // Now find the new insertion position in the list.
  int position = 0, old_position = i;
  xList<UAS_SearchScope *> &scope_list = search_scope_mgr().scope_list();
  List_Iterator<UAS_SearchScope *> s (scope_list);

  // find the new position in the list
  for (; s != 0; s++)
    {
      if (s.item() == msg.f_search_scope)
	continue;
      position++;
      if (s.item()->read_only())
	continue;
      ON_DEBUG (printf ("ScopeMenu: strcmp <%s>\n", s.item()->name()));
      if (strcmp (msg.f_search_scope->name(), s.item()->name()) < 0)
	break;
    }

  if (s == NULL)
    position++;

  ON_DEBUG (printf ("ScopeMenu: Rename position = %d, old = %d\n",
		    position, old_position));
  WXmPushButtonGadget scope_btn (kids[i]);
  scope_btn.LabelString (msg.f_search_scope->name());
  if (position != old_position)
    scope_btn.PositionIndex (position);
}
Beispiel #2
0
void
ScopeMenu::receive (ScopeDeleted &msg, void *client_data)
{
  // find the associated button and nuke it
  ON_DEBUG (puts ("ScopeMenu: handling delete message"));
  // First find renamed button in our list.
  Arg args[2];
  int n, theKid;
  Cardinal num_kids;
  WidgetList kids;
  int separator_pos = -1;
  Widget selected;

  n = 0;
  XtSetArg(args[n], XmNmenuHistory, &selected); n++;
  XtGetValues(f_option_menu, args, n);

  n = 0;
  XtSetArg(args[n], XmNnumChildren, &num_kids); n++;
  XtSetArg(args[n], XmNchildren, &kids); n++;
  XtGetValues(f_pull_menu, args, n);

  unsigned int i;
  for (i = 0; i < num_kids; i++)
    {
      if (XmIsSeparator (kids[i]))
      {
	separator_pos = i + 1;
        continue;
      }
      if (XmIsPushButtonGadget (kids[i]) &&
	  msg.f_search_scope ==
	  ((UAS_SearchScope *) WXmPushButtonGadget (kids[i]).UserData()))
	break;
    }

  // It had better be in the list! 
  theKid = i;
  Xassert (theKid != (int) num_kids);
  ON_DEBUG (printf ("widget #%d is the button\n", theKid));

  // if it is selected, select first w/ callback called
  if (kids[theKid] == selected)
    {
      n = 0;
      if (XtIsManaged (kids[0]))
	  XtSetArg(args[n], XmNmenuHistory, kids[0]);
      else
	  XtSetArg(args[n], XmNmenuHistory, kids[1]);
      n++;
      XtSetValues(f_option_menu, args, n);
    }

  XtUnmanageChild (kids[theKid]);
  XtDestroyWidget (kids[theKid]);

  // Get rid of the separator if no user scopes remain.
  ON_DEBUG (printf ("ScopeMenu: sep pos = %d, num_kids = %d (%d)\n",
		    separator_pos, num_kids, num_kids -1 -2));
  // - 1 for deleted widget
  if (separator_pos == (int) (num_kids - 1))
    {
      ON_DEBUG (puts ("   destroying separator"));
      XtDestroyWidget (kids[separator_pos-1]);
    }
}
Beispiel #3
0
Widget 
XmCreateSimpleOptionMenu(
        Widget parent,
        String name,
        ArgList args,
        Cardinal arg_count )
{
	Widget rc, sub_rc;
	XmSimpleMenuRec mr;
	int n, i, button_count;
	Arg local_args[5];
	WidgetList buttons;
	Cardinal num_buttons;
	_XmWidgetToAppContext(parent);

	_XmAppLock(app);

	XtGetSubresources(parent, &mr, name, XmCSimpleOptionMenu,
		SimpleMenuResources, XtNumber(SimpleMenuResources), 
		args, arg_count);
	
	rc = XmCreateOptionMenu(parent, name, args, arg_count);

	sub_rc = XmCreatePulldownMenu(parent, name, args, arg_count);

	EvaluateConvenienceStructure(sub_rc, &mr);

	n = 0;
	if (mr.option_label)
	{
		XtSetArg(local_args[n], XmNlabelString, mr.option_label); n++;
	}
	if (mr.option_mnemonic)
	{
		XtSetArg(local_args[n], XmNmnemonic, mr.option_mnemonic); n++;
	}
	
	XtSetArg(local_args[n], XmNsubMenuId, sub_rc); n++;
	XtSetValues(rc, local_args, n);

	if (mr.button_set >= 0)
	{
		n = 0;
		XtSetArg(local_args[n], XtNchildren, &buttons); n++;
		XtSetArg(local_args[n], XtNnumChildren, &num_buttons); n++;
		XtGetValues(sub_rc, local_args, n);

		if (!num_buttons)
		{
			/* error condition */
			_XmAppUnlock(app);
			return(rc);
		}
		else
		{
			button_count = 0;
			for (i = 0; i < num_buttons; i++)
			{				/* count only PushB */
				if ((XmIsPushButtonGadget(buttons[i])) ||
					(XmIsPushButton(buttons[i])))
				{
					if (button_count == mr.button_set)
						break;
					button_count++;
				}
			}

			if ( i < num_buttons)
			{
				n = 0;
				XtSetArg(local_args[n], XmNmenuHistory, buttons[i]); n++;
				XtSetValues(rc, local_args, n);
			}
		}
	}

	_XmAppUnlock(app);
	return(rc);
}