예제 #1
0
void
QueryEditor::search_activate()
{
  Wait_Cursor bob;

  // Need to duplicate string returned, because it is in static data space. 
  char *human_readable =
    strdup (f_query_view->query_group()->
	    generate_query (QueryGroup::QUERY_TYPE_INFIX));

#ifdef DEBUG
  fprintf(stderr, "(DEBUG) human_readable=\"%s\"\n", human_readable);
#endif

  UAS_SearchScope *scope =
    (UAS_SearchScope *) WXmPushButton (f_scope_option.MenuHistory()).UserData();

  try {
      // Search manager owns query from this point on.  Don't delete it here. 
      search_mgr().parse_and_search (human_readable, scope);
   }
   catch (demoException &, demo) {
      message_mgr().demo_failure(demo);
   }
   end_try;

   free(human_readable);

}
예제 #2
0
// /////////////////////////////////////////////////////////////////
// display_help
// /////////////////////////////////////////////////////////////////
void
HelpAgent::display_help (Widget w)
{
  char* locator_id=get_locator_id(w);
  if(locator_id == NULL)
  {
    message_mgr().error_dialog ((char*)UAS_String(
                  CATGETS(Set_Messages, 3, "No help available")));
    return;
  }

  Wait_Cursor bob;

  if (f_helper == NULL)
    create_ui();
  XtVaSetValues(f_helper,
                DtNhelpType, DtHELP_TYPE_TOPIC,
                DtNhelpVolume, "Infomgr",
                DtNlocationId, locator_id,
                XmNdialogStyle, XmDIALOG_MODELESS,
                NULL);

  XtManageChild(f_helper);
  Popup();
}
예제 #3
0
파일: ServiceMgrX.C 프로젝트: juddy/edcde
void
ServiceMgr::process_olias_event (Window client,
				 unsigned char *stream, unsigned long)
{
  /* Return immediately if the selection couldn't be converted. */
  if (stream == NULL)
    return;

  unsigned char event_type = *stream++;
  int len, bufferlen;
  char *locator;		// NOTE: make fixed width and add "mmdb:" to
				// front ? Should eventually go into calling
				// program to determine doc type.

  if (event_type != 1)
    {
      ON_DEBUG(fprintf (stderr, "received unknown event"));
      return;
    }

  // Skip over the defunct infobase name.
  // NOTE:  It should be removed from the olias api.  DJB 
  while (*stream != '\0')
    stream++;
  stream++;
  locator = (char *) stream;

  UAS_Pointer<UAS_Common> d;
  mtry
    {
      if (strchr (locator, ':'))
	{
	  d = UAS_Common::create(locator);
	}
      else
	{
	  bufferlen = strlen("mmdb:LOCATOR=") + strlen(locator) + 1;
	  char *buffer = new char[bufferlen];
	  snprintf (buffer, bufferlen, "mmdb:LOCATOR=%s", locator);
	  d = UAS_Common::create (buffer);
	  if (d != (const int)0)
	    {
	      // (evil hack alert) 
	      g_scroll_to_locator = TRUE;
	      len = MIN(strlen(locator), 4096 - 1);
	      *((char *) memcpy(g_top_locator, locator, len) + len) = '\0';
	    }
	  delete [] buffer;
	}
    }
  mcatch (demoException&, demo)
    {
      message_mgr().demo_failure(demo);
    }
예제 #4
0
void
HelpAgent::display_help (const String locatoridResourceString)
{
  Wait_Cursor bob;

  if (f_helper == NULL)
    create_ui();

  if (f_appXrmDb)
  {
    char* type;
    XrmValue value;

    if(env().debug())
      cerr << "Resource string: " << locatoridResourceString << endl;
    if(XrmGetResource(f_appXrmDb, locatoridResourceString,
                        locatoridResourceString, &type, &value ))
    {
      if(env().debug())
        cerr << "Value: " << value.addr << endl;
      XtVaSetValues(f_helper,
                    DtNhelpType, DtHELP_TYPE_TOPIC,
                    DtNhelpVolume, "Infomgr",
                    DtNlocationId, value.addr,
                    XmNdialogStyle, XmDIALOG_MODELESS,
                    NULL);
      XtManageChild(f_helper);
      Popup();
    }
    else
    {
      message_mgr().error_dialog (UAS_String(
                    CATGETS(Set_Messages, 3, "No help available")));
    }
  }
}
예제 #5
0
UAS_Pointer<UAS_List<UAS_TextRun> >
DtSR_SearchResultsEntry::create_matches()
{

#ifdef DEBUG
    fprintf(stderr, "(DEBUG) UAS_Common is being created from id=\"%s\"\n",
							(char*)f_id);
#endif
    UAS_Pointer<UAS_Common> doc = UAS_Common::create(f_id);

#ifdef DEBUG
    fprintf(stderr,
		"(DEBUG) id=%s\n\t"
		"book_name=%s title=%s\n",
		(char*)(doc->id()),
		(char*)(doc->book_name()), (char*)(doc->title()));
#endif

#ifdef DUMP_NODES
    {
	ofstream out("OriginalText");
	out << (char *) doc->data();
    }
#endif

    mtry
	{
	    style_sheet_mgr().initOnlineStyleSheet(doc);
	}
//  catch_noarg (StyleSheetSyntaxError)
    mcatch_any()
	{
#ifdef JOE_HATES_THIS
	    message_mgr().error_dialog(
		(char*)UAS_String(CATGETS(Set_Messages, 39, "File a Bug")));
#else
	    throw(CASTEXCEPT Exception());
#endif
	}
    end_try;

    istringstream input((char *)doc->data());
    ostringstream output;
    
    mtry
	{
	    Tml_TextRenderer	renderer(output, f_search_res->search_zones());
	    Resolver resolver(*gPathTab, renderer);
	    DocParser docparser(resolver);

	    docparser.parse(input);
	}
    mcatch_any()
	{
	    ON_DEBUG(cerr << "DtSR_SearchResultsEntry::create_matches...exception thrown" << '\n' << flush);
	    rethrow;
	}
    end_try;

    string outpstr = output.str();
    char* text = (char*)outpstr.c_str();

#ifdef DUMP_NODES
    {
	ofstream out("ParsedText");
	out << text;
    }
#endif

#ifdef DEBUG
    fprintf(stderr, "(DEBUG) stems=0x%p, count=%d\n",
			(char*)f_search_res->stems(f_dbn)->stems(),
			f_search_res->stems(f_dbn)->count());

    int n_of_stems = 0;
    for (; n_of_stems < f_search_res->stems(f_dbn)->count(); n_of_stems++) {
	fprintf(stderr, "(DEBUG) %dth stem = %s\n", n_of_stems,
			(f_search_res->stems(f_dbn)->stems())[n_of_stems]);
    }
#endif

    int stype = f_search_res->search_type();

    DtSrHitword* kwics = NULL;
    long n_kwics = 0;

    char* parseout = NULL;

    // hack! overwrite f_language, since austext's value is wrong
    // In future, the next lines should be removed.
    const char* lang = getenv("LANG");
    if (lang && !strncmp(lang, "ja", strlen("ja")))
	f_language = DtSrLaJPN;
    else
	f_language = DtSrLaENG;
	
    if (f_language == DtSrLaJPN) { // do not trust DtSearchHighlight!
	int count        = f_search_res->stems(f_dbn)->count();

	ostringstream stemsbuf;
	for (int i = 0; i < count; i++) {
	    stemsbuf << (f_search_res->stems(f_dbn)->stems())[i] << '\n';
	}
	string stemsbstr = stemsbuf.str();
	char* stems = (char*)stemsbstr.c_str();

	parseout = StringParser::hilite(text, count, stems);

	assert( parseout != NULL );

	delete[] stems;
    }
    else {

	static DtSR_SearchEngine& search_engine = DtSR_SearchEngine::search_engine();
	if (DtSearchHighlight(
		search_engine.char_db_name(f_dbn),
		text, &kwics, &n_kwics, stype,
		(char*)f_search_res->stems(f_dbn)->stems(),
		f_search_res->stems(f_dbn)->count()) != DtSrOK) {

	    fprintf(stderr, "(ERROR) DtSearchHighlight failed\n");
#ifdef DEBUG
	    abort();
#endif
	}

#ifdef DEBUG
	fprintf(stderr, "(DEBUG) %ld hit found in %s\n", n_kwics, (char*)f_id);
#endif
    }

    UAS_Pointer<UAS_List<UAS_TextRun> >
				matches = new UAS_List<UAS_TextRun>;

    // convert kwics to textrun
    string textrbstr;
    if (parseout == NULL && kwics) {
	ostringstream textrunbuf;
	for (int i = 0; i < n_kwics; i++)
	    textrunbuf << kwics[i].offset << '\t' << kwics[i].length << '\n';
	textrbstr = textrunbuf.str();
	parseout = (char*)textrbstr.c_str();
    }
    else if (parseout == NULL)
    {
	return matches;
    }

#ifdef DEBUG
    fprintf(stderr, "(DEBUG) byte offset and length\n%s", parseout);
#endif

    istringstream textruns(parseout);

    char linebuf[128];
    while (textruns.get(linebuf, 128, '\n')) {
	char newline;
	textruns.get(newline);
	assert( newline == '\n');

	char* off_str = linebuf;
	char* len_str = strchr(linebuf, '\t');
	assert( len_str && *len_str == '\t' );
	*len_str++ = '\0';

	int mode = True;

	const char* cursor = (const char*)text;
	assert( *cursor == ShiftIn || *cursor == ShiftOut );

	int off = atoi(off_str);
	int vcc = 0;
	
	while (off > 0) {

	    int scanned = 0;
	    if (*cursor == '\n' || *cursor == '\t' || *cursor == ' '  ||
		*cursor == 0x0D || (unsigned char)*cursor == 0xA0) {
		scanned++;
	    }
	    else if (*cursor == ShiftIn || *cursor == ShiftOut) {
		if (*cursor == ShiftIn)
		    mode = True;
		else
		    mode = False;
		scanned++;
	    }
	    else {
		scanned = mblen(cursor, MB_CUR_MAX);
		vcc++;

		/* skip one byte in case of failure */
		if (scanned < 0)
		    scanned = 1;
	    }

	    off -= scanned;
	    cursor += scanned;
	}

	if (mode == False)
	    continue;

	assert( off == 0 );

	int len = atoi(len_str);
	// remove leading white-spaces
	for (; len && (*cursor == ' ' || *cursor == '\t' ||
		       *cursor == '\n'|| *cursor == 0x0D); cursor++, len--);

	// remove trailing white-spaces
	if (len > 0) {
	    for (const char*  p = cursor + len - 1;
		 *p==' ' || *p=='\t' || *p=='\n' || *p==0x0D; p--, len--);
	}

	if (len == 0)
	    continue;

	int vlen = 0;
	for (; len > 0; vlen++) {
	    int scanned = mblen(cursor, MB_CUR_MAX);
	    assert( scanned >= 0 );
	    len -= scanned;
	    cursor += scanned;
	}

	UAS_Pointer<UAS_TextRun> textrun = new UAS_TextRun(vcc, vlen);
	matches->insert_item(textrun);
    }

    return matches;
}
예제 #6
0
파일: MapAgentMotif.C 프로젝트: juddy/edcde
void
MapAgent::display (UAS_Pointer<UAS_Common> &doc_ptr, bool popup)
{
  static bool first_time = True;
  u_int i, num_children;
  MapButton *parent_button, *child_button, *this_button = NULL;

  if (f_shell == NULL)
    create_ui();

  // Just pop up the window if the map has already been created
  // for the specified document.
  if (doc_ptr == f_doc_ptr)
    {
      if (popup) {
	f_shell->Popup();
        XMapRaised(XtDisplay(*f_shell), XtWindow(*f_shell));
      }
      f_onscreen = TRUE;
      return;
    }

  // Must have to create a new tree, so start by wiping out the old one. 
  if (f_tree != NULL)
    {
      f_tree->Destroy();
      delete f_tree;
    }
  f_tree = new WXawTree (*f_porthole, "tree");
  //  f_tree->Realize();

  // Tree gravity should be a preference that is retrieved right here.
  // (Or better yet stored in the class record.) 

  /* -------- Start the local map at this node's parent. -------- */

  UAS_Pointer<UAS_Common> toc_this = doc_ptr;
  UAS_Pointer<UAS_Common> toc_parent =
      (doc_ptr != (UAS_Pointer<UAS_Common>)0)
	  ? doc_ptr->parent() : (UAS_Pointer<UAS_Common>)0;

  // If the entry has a parent, create a button for it and each of
  // the entry's siblings. 
  if (toc_parent != (UAS_Pointer<UAS_Common>)NULL)
    {
      parent_button = new MapButton (*f_tree, toc_parent, NULL);
      //  parent_button->expand();

      /* -------- Create a button for each sibling. -------- */

      UAS_List<UAS_Common> kids = toc_parent->children();
      num_children = kids.length();
      UAS_Pointer<UAS_Common> toc_kid;
      for (i = 0; i < num_children; i++)
	{
	  toc_kid = kids[i];
	  child_button = new MapButton (*f_tree, toc_kid, parent_button);
	  if (toc_kid == doc_ptr)
            {
              f_doc_ptr = doc_ptr;
   	      this_button = child_button;
            }
	}
    }
  else // No TOC parent -- SWM: Also may be no TOC!!!
    {
      f_doc_ptr = doc_ptr;
      this_button = new MapButton (*f_tree, toc_this, NULL);
    }

  if (this_button == NULL)
    {
      message_mgr().
	error_dialog (CATGETS(Set_Messages, 7, "File a Bug"));
      return;
    }
  else
    {
      static bool first_time = TRUE;
      static Pixel highlight_bg, highlight_fg;
      if (first_time)
	{
	  const char *s;
	  unsigned long status;
	  s = window_system().get_string_default ("MapHighlightBackground");
	  if (s == NULL || *s == '\0')
	    {
	      highlight_bg = this_button->f_button.Foreground();
	    }
	  else
	    {
	      status = window_system().get_color (s, highlight_bg);
	      // On failure to allocate, just invert. 
	      if (status == 0)
		{
		  highlight_bg = this_button->f_button.Foreground();
		  highlight_fg = this_button->f_button.Background();
		}
	      // Got bg, so now try for fg. 
	      else
		{
	          s = window_system().
		        get_string_default ("MapHighlightForeground");
		  if (s == NULL || *s == '\0')
		    {
		      highlight_fg =this_button->f_button.Background();
		    }
		  else
		    {
		      status = window_system().get_color (s, highlight_fg);
		      // If we cant get both colors, just invert the button. 
		      if (status == 0)
			{
			  Display *dpy = window_system().display();
			  XFreeColors (dpy,
				       DefaultColormap(dpy,DefaultScreen(dpy)),
				       &highlight_bg, 1, 0);
			  highlight_bg = this_button->f_button.Foreground();
			  highlight_fg = this_button->f_button.Background();
			}
		    }
		}
	    }
	  if (highlight_fg == this_button->f_button.Foreground() ||
	      highlight_bg == this_button->f_button.Background() ||
	      highlight_fg == highlight_bg)
	    {
	      highlight_bg = this_button->f_button.Foreground();
	      highlight_fg = this_button->f_button.Background();
	    }
	  first_time = FALSE;
	}
      this_button->f_button.Background (highlight_bg);
      this_button->f_button.Foreground (highlight_fg);
      //  this_button->expand();
    }

  /* -------- Create a button for each child. -------- */

  if (toc_this != (UAS_Pointer<UAS_Common>)NULL)
    {
      UAS_List<UAS_Common> myKids = toc_this->children();
      num_children = myKids.length();
      for (i = 0; i < num_children; i++)
	child_button =
	  new MapButton (*f_tree, myKids[i], this_button);

#if 0
  if (!XtIsRealized(*f_shell))
    {
      f_tree->Manage();
      f_shell->Realize();
    }
#endif

    }
  // Manage all the children.
  MapButton::ManageKids();

  UAS_String buffer = CATGETS(Set_MapAgent, 2, "Dtinfo: ");
  buffer = buffer + doc_ptr->title();
  f_shell->Title ((char*)buffer);

  if (!XtIsRealized (*f_shell))
    f_shell->Realize();

  f_tree->Realize();
  f_tree->ForceLayout();

  f_min_tree_width = f_tree->Width();
  f_min_tree_height = f_tree->Height();
  ON_DEBUG (printf ("+++++ Tree min dims: %d x %d\n",
		    f_min_tree_width, f_min_tree_height));

  center_on (this_button);
  f_tree->Manage();

  if (popup)
    {
      if (first_time)
	{
  	  WXmForm form (XtParent (XtParent (*f_panner)));
	  form.Height (50);
	  first_time = False;
	}
      f_shell->Popup();
      XMapRaised(XtDisplay(*f_shell), XtWindow(*f_shell));
    }

  f_onscreen = TRUE;
}