Exemplo n.º 1
0
CDocument* CDocTemplate::CreateNewDocument()
{
	// default implementation constructs one from CRuntimeClass
	if (m_pDocClass == NULL)
	{
		TRACE0("Error: you must override CDocTemplate::CreateNewDocument.\n");
		ASSERT(FALSE);
		return NULL;
	}
	CDocument* pDocument = (CDocument*)m_pDocClass->CreateObject();
	if (pDocument == NULL)
	{
		TRACE1("Warning: Dynamic create of document type %hs failed.\n",
			m_pDocClass->m_lpszClassName);
		return NULL;
	}
	ASSERT_KINDOF(CDocument, pDocument);
	AddDocument(pDocument);
	return pDocument;
}
Exemplo n.º 2
0
void DocumentManagerModel::AddDocuments(const QList<IDocument *> &doc)
{
  Q_FOREACH(IDocument *ad, doc)
    AddDocument(ad);
}
Exemplo n.º 3
0
void __stdcall CEXMLDocumentStyleSheetsView::OnItemDblClick(IUITreeItem* item)
{
	DWORD itemdata;
	m_treeCtl->GetItemInfo(item, &itemdata, NULL, NULL);

	CComQIPtr<ILDOMNode> node = (IUnknown*)itemdata;

	CComQIPtr<ILDOMElement> element = node;

	if (element)
	{
		CComPtr<IEElement> eElement;
		m_viewGroup->m_pDocument->GetEElementFromDOMElement(element, &eElement);

		CEStyleElement* pStyleElement = static_cast<CEStyleElement*>(eElement.p);

		CComQIPtr<ILLinkStyle> linkStyle = node;

		CComPtr<ILCSSStyleSheet> styleSheet;
		linkStyle->get_sheet((ILStyleSheet**)&styleSheet);

		{
			ASSERT(0);
#if 0
			CComQIPtr<ILXAddin> addin = m_viewGroup->m_pDocument->m_app;

			WCHAR buf[512];
			swprintf(buf, L"%s/style", (BSTR)m_viewGroup->m_pDocument->m_fileTitle);

			pStyleElement->m_pCSSDocument->m_fileTitle = buf;
			pStyleElement->m_pCSSDocument->m_app = addin;
			pStyleElement->m_pCSSDocument->m_styleSheet = styleSheet;

			CComPtr<ILXAddinSite> addinSite;
			addin->GetSite(&addinSite);

			CComPtr<ILXFrameworkFrame> lxframe;
			addinSite->GetFrame(&lxframe);

			CComQIPtr<IEFrame> eframe = lxframe;

			pStyleElement->m_pCSSDocument->ShowViews(eframe);
#endif
		}
	}

	CComQIPtr<ILLinkStyle> linkStyle = node;

	if (linkStyle)
	{
	}

#if 0
	CComPtr<ILCSSStyleSheet> openStyleSheet;

	CComQIPtr<ILCSSStyleSheet> styleSheet = (IUnknown*)itemdata;
	CComQIPtr<ILCSSRule> rule = (IUnknown*)itemdata;
	if (styleSheet)
	{
		CComBSTR href;
		styleSheet->get_href(&href);
		if (href.Length())
		{
			openStyleSheet = styleSheet;
		}
	}
	else if (rule)
	{
		CComQIPtr<ILCSSImportRule> importRule = rule;
		if (importRule)
		{
			importRule->get_styleSheet(&openStyleSheet);
		}
	}

	if (openStyleSheet)
	{
		CComObject<CECSSDocument>* pCSSDocument;
		CComObject<CECSSDocument>::CreateInstance(&pCSSDocument);
		if (pCSSDocument)
		{
			pCSSDocument->m_styleSheet = openStyleSheet;

			BSTR cssText;
			openStyleSheet->get_cssText(&cssText);
			pCSSDocument->m_textData->put_data(cssText);

#if 0
			AddDocument(pCSSDocument->GetUnknown(), NULL);
#endif
		}
	}
#endif
}
Exemplo n.º 4
0
void CorpusReader::ReadProtobuf(const string& location, const string& filename,
                                bool is_test,
                                const vector< vector<string> >& vocab,
                                const vector< vector<string> >& pos,
                                Corpus* corpus) {
  // Read in the protocol buffer
  string combined = location + "/" + filename;
  fstream input((combined).c_str(), ios::in | ios::binary);
  cout << "Opening protobuffer: " << combined << " ... " << endl;
  assert(input);
  lib_corpora_proto::Corpus raw_corpus;
  assert(raw_corpus.ParseFromIstream(&input));

  // Create a vocab mapping
  vector<IntIntMap> vocab_mapping;
  CreateVocabMaps(raw_corpus, vocab, &vocab_mapping);

  // Create a synset mapping
  IntIntMap synset_mapping;
  CreateUnfilteredMap(raw_corpus.synsets(), &synset_lookup_, &synset_mapping);

  // Create an author mapping
  IntIntMap author_mapping;
  CreateUnfilteredMap(raw_corpus.authors(), &author_lookup_, &author_mapping);

  vector< set<int> > valid_pos;
  FindValidPos(raw_corpus, pos, &valid_pos);

  proto_doc doc;
  int docs_added = 0;
  int docs_ignored = 0;
  // For each document, open the file and read in the protocol buffer
  for (int dd = 0; dd < raw_corpus.doc_filenames_size(); ++dd) {
    const string doc_filename = raw_corpus.doc_filenames(dd);
    fstream input((location + "/" + doc_filename).c_str(),
                  ios::in | ios::binary);
    if (!doc.ParseFromIstream(&input)) {
      cout << "Failed to read doc " << location + "/" + doc_filename << endl;
      break;
    }
    int lang = doc.language();
    /*
      cout << "\nfile:" << location << ":" << doc_filename <<
      "(lang=" << lang << ")" << endl;
    */
    assert(lang < (int)vocab_mapping.size());
    BaseDoc* new_doc =
      DocumentFactory(doc, vocab_mapping[lang], valid_pos[lang], author_mapping,
                      synset_mapping, is_test);
    new_doc->set_title(doc.title());

    if (is_valid_doc(new_doc)) {
      AddDocument(corpus, new_doc);
      ++docs_added;
    } else {
      ++docs_ignored;
      delete new_doc;
    }
    if (is_test && test_limit_ > 0 && docs_added >= test_limit_) break;
    if (!is_test && train_limit_ > 0 && docs_added >= train_limit_) break;
  }

  cout << "     done adding " << docs_added << " documents, ignoring " <<
    docs_ignored << " (because they were too short)" << endl;

  // Update the corpus mapping
  corpus->UpdateMapping(author_lookup_, synset_lookup_);
}
Exemplo n.º 5
0
/* Add file to doc list */
static void AddVFSFile
    (
    UInt16              volRefNum,
    FileInfoType*       info,
    const Char*         dir,
    UInt16              location,
    EnumerateCardType   enumerateWhat
    )
{
    Err             err;
    Char*           path;
    FileRef         ref;
    DocumentInfo    docInfo;
    UInt32          type;
    UInt32          creatorID;

    /* Set path to document */
    path = SafeMemPtrNew( StrLen( dir ) + StrLen( info->nameP ) + 2 );
    StrCopy( path, dir );
    StrCat( path, info->nameP );
    err = VFSFileOpen( volRefNum, path, vfsModeRead, &ref );
    if ( err == errNone ) {
        Char volumeLabel[ LABEL_LEN ];

        err = VFSFileDBInfo( ref, docInfo.name,
                &docInfo.attributes, NULL, &docInfo.created,
                NULL, NULL, NULL, NULL, NULL, &type, &creatorID,
                NULL );
        if ( err == errNone && IsDocScan( enumerateWhat ) &&
             type == ViewerDocumentType && creatorID == ViewerAppID ) {
            DocumentData*   handlePtr;
            MemHandle       handle;
            UInt16          index;

            VFSFileSize( ref, &docInfo.size );
            GetPluckerVolumeLabel( volRefNum, volumeLabel, LABEL_LEN );
            docInfo.cardNo      = 0;
            docInfo.filename    = info->nameP;

            VFSFileClose( ref );

            handle = FindDocData( docInfo.name, numOfElements, &index );
            if ( handle != NULL ) {
                UInt16  categories;
                UInt32  oldCreated;
                UInt16  oldLocation;
                Boolean oldActive;
                Char    oldVolumeLabel[ LABEL_LEN ];
                UInt16  fileLen;
                UInt16  volumeLabelLen;
                UInt32  timestamp;

                SetFoundDocument( index );
                handlePtr       = MemHandleLock( handle );
                oldCreated      = handlePtr->created;
                oldLocation     = handlePtr->location;
                oldActive       = handlePtr->active;
                categories      = handlePtr->categories;
                timestamp       = handlePtr->timestamp;
                fileLen         = StrLen( handlePtr->data ) + 1;
                volumeLabelLen  = StrLen( handlePtr->data + fileLen ) + 1;
                StrNCopy( oldVolumeLabel, handlePtr->data + fileLen,
                    volumeLabelLen );
                MemHandleUnlock( handle );
                /* If the document is newer than the stored one, or
                   moved to external card then updated info */
                if ( ! oldActive || oldCreated < docInfo.created ||
                     oldLocation != location ||
                     ! STREQ( volumeLabel, oldVolumeLabel ) ) {
                    /* Assign remaining document data */
                    docInfo.location    = location;
                    docInfo.active      = true;
                    docInfo.categories  = categories;
                    /* A "new" document should be indicated as unread */
                    if ( ! oldActive || oldCreated < docInfo.created )
                        docInfo.timestamp = 0;
                    else
                        docInfo.timestamp = timestamp;

                    /* If document has been moved to external card the
                       meta database must be renamed */
                    if ( oldLocation != location )
                        VFSRenameMetaDocument( docInfo.name, oldLocation,
                            &docInfo );

                    UpdateDocument( &docInfo, volumeLabel, index,
                        &handle );
                }
            }
            else {
                docInfo.location    = location;
                docInfo.volumeRef   = volRefNum;
                docInfo.active      = true;
                docInfo.timestamp   = 0;

                ErrTry {
                    docInfo.categories = GetDefaultCategories( &docInfo );
                }
                ErrCatch( UNUSED_PARAM( err ) ) {
                    docInfo.categories = UNFILED_CATEGORY;
                } ErrEndCatch
                AddDocument( &docInfo, volumeLabel );
            }
        }