Exemple #1
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
    }
}