Exemplo n.º 1
0
void
QueryEditor::edit_query (QueryGroup *query)
{
  static Boolean first_time = True;

//#ifdef UseFJMTF
#if 1
  // Fujitsu Motif seems to be buggy for HaL's Restraint widget.
  // You must not destroy and re-create the Restraint widget.
  // Instead keep the same Restraint widget forever. - 10/22/94 kamiya

  // Create a group with a single term if none provided.
  if (query == NULL)
    {
      query = new QueryGroup();
      // This QueryTerm is pointed to by the QueryGroup.
      new QueryTerm (query, NULL, NULL);
    }

  f_query = query;

  // re-load the query terms
  if (f_query_view != NULL)
	f_query_view->re_load_terms(f_query);

#else
  // Clean up old junk.
  // The query isn't destroyed sometimes??
  // Need to nuke only if it isn't saved on the history list.  DJB 
  if (f_query_view != NULL)
    {
      QueryGroup *group = f_query_view->query_group();
      f_query_view->destroy_widgets();
      delete f_query_view;
      delete f_query;
    }

  // NOTE: old query probably leaked!! 15:06 01/29/93 DJB
  // This is going to need to be fixed up to edit pre-existing querys.
  // NOTE: Another problem if this is called before the UI is created,
  // because thar's widgets created below.  17:19 02/03/93 DJB
  f_query = query;

  // Create a group with a single term if none provided.
  if (f_query == NULL)
    {
      f_null_terms = 0;
      f_query = new QueryGroup();
      // This QueryTerm is pointed to by the QueryGroup.
      new QueryTerm (f_query, NULL, NULL);
    }

  // QueryGroupView holds the pointer to the QueryGroup. 
  f_query_view =
    new QueryGroupView (f_query, WXmForm ((WObject &) f_query_area));
#endif

  if (first_time)
    {
//#ifdef UseFJMTF
#if 1
      f_null_terms = 0;

      // QueryGroupView holds the pointer to the QueryGroup. 
      f_query_view = new QueryGroupView (f_query, f_query_area);
#endif
      // Only let pane get small enough to show two query entries.
      // Start with the whole scrolled window, then take out the scrolling
      // area to leave the borders, then add the term height * 2 back in.
      // NOTE: This really needs to use the height of one row.  If this
      // dialog comes up with an existing query at this point, the
      // height will be wrong.  We need to get the height of a single
      // line somehow.  11:59 02/04/93 DJB 
      f_query_area.
	PaneMinimum (f_query_area.Height() -
		     WCore (XtParent(XtParent(*f_query_view))).Height() +
		     (2 * f_query_view->Height()));

      // Take the height of each pane - the min size of each pane.
      // That is the excess height of the dialog.
      // This needs to equal the current height - min height.
      // So subtract it from the current height to get the new min height.
      WXmForm qform (XtParent(f_query_text.Parent()));
#ifdef DEBUG
      printf ("qform height = %d, scrolled height = %d\n",
	      qform.Height(), f_query_area.Height());
      printf ("qform min = %d, scrolled min = %d\n",
	      qform.PaneMinimum(), f_query_area.PaneMinimum());
#endif
      Dimension excess_height = qform.Height() + f_query_area.Height() -
	qform.PaneMinimum() - f_query_area.PaneMinimum();

      ON_DEBUG(printf ("Query Editor excess height = %d\n", excess_height));

      f_shell.MinHeight (f_shell.Height() - excess_height);
      
      first_time = False;
    }

  //g_allow_query_text_change = TRUE;
  f_query_text.Value ("");
  //g_allow_query_text_change = FALSE;

  // Move the input focus to the term view.
  f_query_area.InitialFocus (*f_query_view);
  //  f_query_view->traverse_here();

  display();
}
Exemplo n.º 2
0
QueryGroupView::QueryGroupView (QueryGroup *group, Widget parent)
: f_query_group (group),
  f_term_view_list (NULL)
{
  f_restraint = WRestraint (WComposite (parent), "group_view", WAutoManage);
  f_form = WXmForm (f_restraint, "group_form");

  QueryTermView *view = NULL;
  QueryTerm *term;

  for (term= group->term_list(); term != NULL; term = term->next())
    view = new QueryTermView (term, this, view, NULL);

  f_form.Realize();  // This statement is extremely critical.  02/03/93 DJB 
  f_form.Manage();

  // Need special event handler for top level group to catch
  // resizes of window and resize the query view.
  // NOTE: It's just about time to move this to another method. 
  if (XtClass (XtParent (f_restraint)) == xmDrawingAreaWidgetClass)
    {
      // Let's see what the parent's size is now:
      ON_DEBUG(printf ("Drawing area is width: %d, height: %d\n",
		       WCore(f_restraint.Parent()).Width(),
		       WCore(f_restraint.Parent()).Height()));
      // We need to grow the drawing area if it is smaller than the
      // restraint widget, since we don't deal with horizontal scrolling.
      Dimension restraint_width = f_restraint.Width();
      Dimension da_width = WCore(f_restraint.Parent()).Width();
      
      if (da_width < restraint_width)
	{
	  // Can't resize the drawing area because the ^$&(*% Motif
	  // pane widget will not allow the horizontal resize.  So,
	  // instead calculate the size increase and do it on the shell. 
	  Dimension increase = restraint_width - da_width;
	  // Find the shell widget. 
	  Widget w = f_restraint.Parent();
	  while (!XtIsShell (w))
	    w = XtParent(w);
	  WTopLevelShell shell (w);

	  ON_DEBUG(printf ("** Resizing shell by = %d\n", increase));

	  // Change state if needed. 
	  Boolean allow_resize = shell.AllowShellResize();
	  if (!allow_resize)
	    shell.AllowShellResize (True);
	  // Change the width. 
	  shell.MinWidth (shell.Width() + increase);
	  shell.Width (shell.Width() + increase);
	  // Restore state if needed. 
	  if (!allow_resize)
	    shell.AllowShellResize (False);
	}
      else if (da_width > restraint_width)
	{
	  f_restraint.Width (WCore(f_restraint.Parent()).Width());
	}
      
      XtAddEventHandler (XtParent (f_restraint), StructureNotifyMask, False,
			 (XtEventHandler) &QueryGroupView::resize,
			 (Widget) f_restraint);
      // Store the min width in UserData...
      f_restraint.UserData ((XtPointer)(size_t) f_restraint.Width());
    }
  // Make sure the restraint widget isn't too narrow.
  else
    {
      f_restraint.Width (WCore(f_restraint.Parent()).Width());
    }
}