Beispiel #1
0
Mark_mmdb::Mark_mmdb (MarkBase_mmdb &base, UAS_Pointer<UAS_Common> &doc_ptr,
		      const Anchor &anchor,
		      const char *name, const char *notes)
: f_doc_ptr (doc_ptr),
  f_anchor (anchor),
  f_mark_base (base),
  f_name (NULL),
  f_notes (NULL)
{
  // This creates a new user mark in the mmdb mark database. 

#ifdef FUJITSU_OLIAS
  // Id = bookcase id / section id
  UAS_String theId = doc_ptr->bid();
  theId = theId + "/" + doc_ptr->id();
#else
  UAS_String theId = doc_ptr->id();
#endif
  
  f_user_mark = new mark_smart_ptr (base, theId);
  set_name (name);
  set_notes (notes);

  // Flush the new mark to disk. 
  do_save();
}
Beispiel #2
0
static void
PrintOneUASCommon(UAS_Pointer<UAS_Common> &doc, Widget pshell, int *cur_pageP)
{
    Arg	args[15];
    int n;
    XmString label;
    char buf[BUFSIZ];

    // Retrieve the topic from the doc
    // The retrieve function will send a UAS_DocumentRetrievedMsg to the
    // print manager which will render the canvas with the appropriate topic

    doc->retrieve((void *)1);

    // set print orientation to either landscape or portrait (if set)

    if (f_printOrientation != NULL) {
	snprintf(buf, sizeof(buf),
			"*content-orientation: %s\n", f_printOrientation);
	XpSetAttributes(XtDisplay(pshell), XpGetContext(XtDisplay(pshell)),
			XPPageAttr, buf, XPAttrMerge);
    }
    
    for (gHelpDisplayArea->firstVisible = gHelpDisplayArea->nextNonVisible = 0;
	 gHelpDisplayArea->nextNonVisible >= 0;
	 gHelpDisplayArea->firstVisible = gHelpDisplayArea->nextNonVisible + 1)
    {
	(*cur_pageP)++;

	XpStartPage(XtDisplay(pshell), XtWindow(pshell));

	snprintf(buf, sizeof(buf), "%d", *cur_pageP);
	label = XmStringCreateLocalized(buf);

	n = 0;
	XtSetArg(args[n], XmNlabelString, label); n++;
	XtSetValues(footer_page_no, args, n);
	XmStringFree(label);

	// Process exposures so label is updated.
	XmUpdateDisplay(footer_page_no);

	// _DtHelpCleanAndDrawWholeCanvas((XtPointer)gHelpDisplayArea);

	XpEndPage(XtDisplay(pshell));
    }

    // Print chidren if appropriate
    if (print_hierarchy)
    {
	unsigned int i;
	UAS_List<UAS_Common> kids = doc->children();

	for (i = 0; i < kids.length(); i++)
	{
	    PrintOneUASCommon(kids[i], pshell, cur_pageP);
	}
    }
}
Beispiel #3
0
void
NodeViewInfo::set_search_hits(UAS_Pointer<UAS_List<UAS_TextRun> >& hits)
{
    if (f_current_hit) { // clear search hits previously displayed
	clear_search_hits();
    }

    // retrieve the top container
    _DtCvSegment* root_seg;
    if ((root_seg = top_container()) == NULL)
	return;

    unsigned int idx;

    for (idx = 0; idx < hits->length(); idx++) { // for each TextRun

	UAS_Pointer<UAS_TextRun>& hit = hits->item(idx);

	_DtCvSegment* seg;

	if ((seg = traverse_for_vcc(root_seg, hit->offset())) == NULL) {
#ifdef DEBUG
	    fprintf(stderr, "(DEBUG) traverse_for_vcc failed, offset=%d\n",
								hit->offset());
#endif
	    continue;
	}
#ifdef DEBUG
	else
	    fprintf(stderr, "(DEBUG) traverse_for_vcc succeeded, offset=%d\n",
								hit->offset());
#endif

	assert( (seg->type & _DtCvPRIMARY_MASK) == _DtCvSTRING );

	if (seg = highlight_search_hit(seg, hit->offset(), hit->length())) {
#ifdef DEBUG
	    fprintf(stderr, "(DEBUG) highlight_search_hit succeeded, "
			    			"offset=%d\n", hit->offset());
#endif
	    seg->type |=
			_DtCvSEARCH_FLAG | _DtCvSEARCH_BEGIN | _DtCvSEARCH_END;

            sr_DtCvSegment* sr_seg = new sr_DtCvSegment(seg);

	    if (idx == 0) {
		seg->type |= _DtCvAPP_FLAG2;
		f_current_hit = sr_seg;
	    }
	    f_hits.append(sr_seg);
	}
#ifdef DEBUG
	else
	    fprintf(stderr, "(DEBUG) highlight_search_hit failed, offset=%d\n",
								hit->offset());
#endif
    }
}
Beispiel #4
0
void
GraphicsMgr::reattach_graphic(UAS_Pointer<Graphic> &gr)
{
  Wait_Cursor bob;
  gr->set_detached(FALSE);
  ReAttachGraphic rg(gr);
  UAS_Sender<ReAttachGraphic>::send_message(rg);
  UAS_String locator_str = gr->locator();
  GraphicAgent *ga = get_agent(locator_str);
  remove_detached(ga);

  delete ga;
}
Beispiel #5
0
int main (int, char *[]) {
    INIT_EXCEPTIONS();
    UAS_Common::initialize ();
    UAS_List<UAS_String> locList = UAS_Common::rootLocators ();
    for (int i = 0; i < locList.length(); i ++) {
	UAS_String &cur = locList[i];
	UAS_Pointer<UAS_Common> curDoc = UAS_Common::create(cur);
	UAS_Pointer<UAS_Collection> curCol = (UAS_Collection *)
	    ((UAS_Common *) curDoc);
	printLocs (curCol->root(), 0);
	curDoc = curCol->root();
	curCol = 0;
	UAS_Common::destroy (curDoc);
    }
    UAS_Common::finalize ();
    return 0;
}
Beispiel #6
0
void
GraphicsMgr::init_gr(UAS_Pointer<Graphic> &gr)
{
  //gr->detached_graphic();
  //gr->pixmap_graphic();
  gr->set_detached(TRUE);
  //ga->set_graphic(gr);
}
Beispiel #7
0
void
MapAgent::clear_map(UAS_Pointer<UAS_Common> &lib)
{
  if(lib->lid() == f_doc_ptr->lid())
  {
    clear_it();
    f_doc_ptr = NULL;
  }
}
Beispiel #8
0
DtSR_SearchResultsEntry::DtSR_SearchResultsEntry(const char* id,
						 const char* book,
						 const char* section,
						 int dbn, short language,
					UAS_Pointer<DtSR_SearchResults>)
	: UAS_SearchResultsEntry(id, book, section, Inv_Relevance),
	  f_dbn(dbn), f_language(language), f_zone(0)
{
    int i;
    for (i=0; i<=UAS_SearchZones::uas_all; i++)
	f_proximity[i] = 0;

    UAS_String url("mmdb:LOCATOR=");
    url = url + id;
    UAS_Pointer<UAS_Common> sec = UAS_Common::create(url);

    f_id = sec->locator();
}
Beispiel #9
0
bool
GraphicsMgr::is_detached(UAS_Pointer<Graphic> &gr)
{
  // iterate through the list looking for our graphic.
  // if our graphic is in the list, return True.
  // Otherwise, return False.
  List_Iterator<GraphicAgent*> dgl (&f_detached_list);

  for (; dgl; dgl++)
  {
   UAS_Pointer<Graphic> g = dgl.item()->graphic();
    if (gr->locator() == g->locator())
    {
      return True;
    }
  }
  return False;
}
Beispiel #10
0
void
printLocs (UAS_Pointer<UAS_Common> doc, int level) {
    for (int i = 0; i < level; i ++)
	cerr << "    ";
    UAS_String theLoc = doc->locator();
    if (level >= 2) {
	char buf[1024];
	UAS_String loc = doc->id();
	(void) sprintf (buf, "mmdb:LOCATOR=%s", (char *) loc);
	UAS_Pointer<UAS_Common> theDoc = UAS_Common::create(buf);
	cerr << (char *) theLoc << ", " << (char *) theDoc->title() << endl;
    } else {
	cerr << (char *) theLoc << endl;
    }
    UAS_List<UAS_Common> kids = doc->children();
    for (i = 0; i < kids.length(); i ++) {
	printLocs (kids[i], level + 1);
    }
}
Beispiel #11
0
UAS_Pointer<UAS_EmbeddedObject>
UAS_Factory::create_embedded (const UAS_String &locator,
			      UAS_Pointer<UAS_Common> relative_to) {
    UAS_Factory *theFactory = get_factory (locator);
    if (theFactory != 0) {
	return theFactory->create_embedded_object (locator);
    } else {
	theFactory = get_factory (relative_to->locator());
	return theFactory->create_relative_embedded_object(locator,relative_to);
    }
}
Beispiel #12
0
void
MarkBase_mmdb::get_marks (UAS_Pointer<UAS_Common> &doc_ptr,
			  xList<UAS_Pointer<Mark> > &list)
{
#ifdef FUJITSU_OLIAS
  UAS_String theId = doc_ptr->bid();
  theId = theId + "/" + doc_ptr->id();
#else
  UAS_String theId = doc_ptr->id();
#endif

  oid_list_handler *l =
    f_mark_base->get_mark_list ((char *) theId);

  if (l != NULL)
    {
      for (int i = 1; i <= (*l)->count(); i++)
	{
	  // Pull the entry from the list and replace it with NULL so
	  // that it doesn't get deleted when the list is deleted.
	  oid_t id = (*l)-> operator()(i);

	  // Assure that the oid_t has not been deleted. qfc 7-6-93
          if (id.eq (oid_t (c_code_t(0), 0)) == false)
	    {
	      try
		{
		  Mark_mmdb *m = find_mark (id, doc_ptr);
		  list.append (m);
		}
	      catch_any()
		{
		  // ignore failure for now! DJB 
		}
	      end_try;
	    }
	}
      delete l;
    }
}
Beispiel #13
0
UAS_Pointer<UAS_SearchEngine>
MMDB_Library::search_engine() {

  UAS_List<UAS_Common> bookcases = bookcaseList();
  UAS_PtrList<const char> cList;

  unsigned int i;
#ifdef DEBUG
  for (i = 0; i < bookcases.length(); i++)
      fprintf(stderr, "(DEBUG) bookcases %d=%s\n",
					i, (char*)bookcases[i]->id());
#endif

  UAS_List<UAS_String> strings;
  for (i = 0; i < bookcases.length(); i++) {
      UAS_Pointer<UAS_String> string = new UAS_String;
      strings.insert_item(string);
  }

  for (i = 0; i < bookcases.length(); i++)
  {
      UAS_Pointer<UAS_Common> infolib = bookcases[i]->parent();

      UAS_String str = infolib->id();
      str = str + "/" + bookcases[i]->id();

      *(UAS_String *)strings[i] = str;
      cList.append((char*)(*(UAS_String *)strings[i]));
  }

#ifdef DTSEARCH
  fSearchEngine = &(DtSR_SearchEngine::search_engine (&cList));
#else
  fSearchEngine = &(Fulcrum_SearchEngine::search_engine (&cList));
#endif

  return fSearchEngine;
}
Beispiel #14
0
void
GraphicsMgr::remove_detached(GraphicAgent *ga)
{
  // iterate through the list looking for our graphic.
  // if our graphic is in the list, return it.
  // Otherwise, return NULL.
  List_Iterator<GraphicAgent*> dgl (&f_detached_list);
  if (ga == NULL)
  {
    return;
  }
  UAS_Pointer<Graphic> oldgr = ga->graphic();

  for (; dgl; dgl++)
  {
    UAS_Pointer<Graphic> gr(dgl.item()->graphic());
    if (gr->locator() == oldgr->locator())
    {
      f_detached_list.remove(ga);
      break;
    }
  }
}
Beispiel #15
0
UAS_BookcaseEntry::UAS_BookcaseEntry(UAS_Pointer<UAS_Common> &bookcase,
                                     int searchable) 
: f_searchable(searchable),
  f_name(0),
  f_base_num(-1)
{
    const char *bc_path = bookcase->id();
    if (! bc_path) {
	f_name = f_path = NULL;
    }
    else {

	const char *bc_name = UASbasename(bc_path);

	f_name = new char[strlen(bc_name)+1];
	strcpy(f_name, bc_name);

	f_path = new char[strlen(bc_path)+1];
	strcpy (f_path, bc_path);
    }

   f_infolib_id  = bookcase->lid();
   f_bookcase_id = bookcase->bid();
}
Beispiel #16
0
void
LocalHistoryMgr::append (UAS_Pointer<UAS_Common> &doc_ptr)
{
    ON_DEBUG (printf ("&&&&& APPENDING <%s> to history\n", doc_ptr->title()));
    LocalHistoryEntry *entry = new LocalHistoryEntry (doc_ptr);
    truncate();
    entry->f_previous = f_current;
    if (f_current != NULL)
        f_current = f_current->f_next = entry;
    else
    {
        // Once the first element is set it can never be truncated.
        f_first = f_current = entry;
    }
    entry->f_next = NULL;
}
Beispiel #17
0
void
printTitles (UAS_Pointer<UAS_Common> doc, int level) {
    int i;
    for (i = 0; i < level; i ++)
	fprintf (stderr, "    ");
    fprintf (stderr, "%s\n", (char *) doc->title ());
    UAS_Pointer<UAS_Common> curDoc;
    if (doc->type() == UAS_BOOK) {
	curDoc = doc->next();
	while (curDoc != 0) {
	    fprintf (stderr, "********** %s \n", (char *) curDoc->title ());
	    curDoc = curDoc->next();
	}
    } else {
	UAS_List<UAS_Common> theList = doc->children ();
	for (i = 0; i < theList.length(); i ++)
	    printTitles (theList[i], level + 1);
    }
}
Beispiel #18
0
void
GraphicsMgr::detach (UAS_Pointer<UAS_Common> &node_ptr,
		     UAS_Pointer<Graphic> &gr)
{
  // called from ViewportAgent
  // ViewportAgent will actually remove it from display

  gr->set_detached(TRUE);
  //PixmapGraphic *pgraphic = gr->pixmap_graphic();
  GraphicAgent *ga = new GraphicAgent(node_ptr, gr);

  //gr->set_agent(ga);

  // add graphic agent to list if not already there.
  add_detached(ga);

  DetachGraphic dg(gr, ga);
  //pgraphic->UAS_Sender<DetachGraphic>::send_message(dg);
  UAS_Sender<DetachGraphic>::send_message(dg);

  ga->display() ;

}
Beispiel #19
0
void
MapButton::expand()
{
  if (f_expanded)
    {
      f_arrow.ArrowDirection (XmARROW_RIGHT);
      f_expanded = FALSE;
    }
  else
    {
      f_arrow.ArrowDirection (XmARROW_DOWN);
      f_expanded = TRUE;
      // Create a button for each child.
      UAS_List<UAS_Common> kids (f_doc_ptr->children());
      WXawTree tree (XtParent (f_form));
      for (unsigned int i = 0; i < kids.length(); i++)
	new MapButton (tree, kids[i], this);
      ON_DEBUG (puts ("managing kids"));
      MapButton::ManageKids();
      ON_DEBUG (puts ("calling force layout"));
      tree.ForceLayout();
      ON_DEBUG (puts ("called force layout"));
    }
}
Beispiel #20
0
// /////////////////////////////////////////////////////////////////
// display
// /////////////////////////////////////////////////////////////////
void
NodePrintAgent::display(UAS_Pointer<UAS_Common> &node_ptr)
{
    Arg	args[15];
    int n;
    XmString label;
    char buf[6];  // good enuf for 99,999 pages!
    int margin;

    RCS_DEBUG("NodePrintAgent::display called.\n");

    bool first_time = False;

    // if f_help_dsp_area is NULL then this is the first time through
    // if gHelpDisplayArea is 0 it has been reset because a new print
    // server was selected.  in either case we need to create a new
    // ui

    if ((f_help_dsp_area == NULL) || (gHelpDisplayArea == 0)) {
	create_ui(f_print_shell);
	first_time = TRUE;
    }
    
    // update book name (long title) in footer
    
    n = 0;
    label = XmStringCreate(node_ptr->book_name(UAS_LONG_TITLE), XmFONTLIST_DEFAULT_TAG);
    
    XtSetArg(args[n], XmNlabelString, label); n++;
    XtSetValues(footer_book_name, args, n);
    XmStringFree(label);
    
    // update page number in footer
    
    n = 0;
    snprintf(buf, sizeof(buf), "%d", 1);
    label = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
    
    XtSetArg(args[n], XmNlabelString, label); n++;
    XtSetValues(footer_page_no, args, n);
    XmStringFree(label);

    // load section 
    
    f_node_view_info = print_mgr().load(node_ptr);

    _DtCvTopicInfo *topic = f_node_view_info->topic();
    
    if (another_g_top_locator[0] != 0) {
	topic->id_str = another_g_top_locator ;
    }
    
    SetTopic(f_node_view_info->topic());
    another_g_top_locator[0] = 0;

    // set margins on the footer form containing both 
    // the book title and the page number

    n = 0;
    XtSetArg(args[n], XmNleftOffset, left_margin); n++;
    XtSetArg(args[n], XmNrightOffset, right_margin); n++;

    // offset bottom by fixed offset of 1/4 inch or 18 pts

    XtSetArg(
	args[n], 
	XmNbottomOffset, 
	XmConvertUnits(window_system().printToplevel(), XmVERTICAL, XmPOINTS, 18, XmPIXELS)
	); n++;
	
    XtSetValues(footer_form, args, n);

    // if the bottom margin is larger than 18 points, subtract 18 points from the margin
    // and used the reduced size

    margin = XmConvertUnits(
	window_system().printToplevel(), XmVERTICAL, XmPIXELS, bottom_margin, XmPOINTS);

    if (margin > 18) {
	margin = margin - 18;

	margin = XmConvertUnits(
	    window_system().printToplevel(), XmVERTICAL, XmPOINTS, margin, XmPIXELS);
    }
   
    // if bottom margin smaller than 18 points just use the entire margin

    else {
	margin = bottom_margin;
    }

    // set offsets for margins on the canvas 

    n = 0;
    XtSetArg(args[n], XmNleftOffset, left_margin); n++;
    XtSetArg(args[n], XmNrightOffset, right_margin); n++;
    XtSetArg(args[n], XmNtopOffset, top_margin); n++;
    XtSetArg(args[n], XmNbottomOffset, margin); n++;
    XtSetValues(f_help_dsp_area->dispWid, args, n);
    
    if (first_time == TRUE) {
	XtManageChild(f_form);
    }

    RCS_DEBUG("NodePrintAgent::display exiting.\n");   
}
Beispiel #21
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;
}
XmString
SearchHistoryListView::display_value(FolioObject *object)
{
  ResultID &rid = *(ResultID*)object;

  char buf[8];
  snprintf(buf, sizeof(buf), "%d", rid.ndocs());
  WXmString matchString = buf;

  UAS_Pointer<UAS_SearchResults> results = rid.results();  
  WXmString scopeString = (char*)*results->scope_name();

  WXmString queryString = rid.display_as();

  XmFontList fontlist = f_list->FontList();

  int number_width = WXmString("0").Width(fontlist) ;

  WXmString matchPostfix(
	window_system().make_space(
		8 * number_width - matchString.Width(fontlist),
		*f_list
	),
	False);

  int scope_field_width = 22 * number_width;

  int allowance;

  if ((allowance = scope_field_width - scopeString.Width(fontlist)) < 0)
  {
    char* dots = (char*)"...";

    // need to free ungenerated at the end
    char* ungenerated = (char*)(scopeString + WXmString(dots));

    wchar_t* buf = WString(ungenerated);
    wchar_t* ptr = buf + wcslen(buf) - (strlen(dots)+1);

    XtFree(ungenerated);

    WXmString stake;
    WString wdots(dots);

    do
    {
      char* str;
      memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));

      stake = str = WString(buf).get_mbstr();
      allowance = scope_field_width - stake.Width(fontlist);

      delete[] str;
    }
    while (allowance <= 0 && ptr >= buf);

    while (*ptr <= (wchar_t)' ' && ptr >= buf)
    {
      char* str;
      memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));

      stake = str = WString(buf).get_mbstr();
      allowance = scope_field_width - stake.Width(fontlist);

      delete[] str;
    }

    scopeString = stake;
  }

  WXmString scopePostfix(
	window_system().make_space(allowance, *f_list), False);

  WXmString entry_string = matchString + matchPostfix +
			   scopeString + scopePostfix +
			   queryString;

  return entry_string.disown();
}
Beispiel #23
0
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;
}
Beispiel #24
0
void
MapButton::activate()
{
  f_doc_ptr->retrieve();
}
Beispiel #25
0
void
UAS_Factory::destroyRoot (UAS_Pointer<UAS_Common> theRoot) {
    UAS_Factory *theFactory = get_factory (theRoot->locator());
    if (theFactory)
	theFactory->destroy_root_object (theRoot);
}