コード例 #1
0
        public override void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
        {
            // See if it is a CmPicture.
            ISilDataAccess sda   = vwenv.DataAccess;
            int            clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);

            if (clsid != CmPictureTags.kClassId)
            {
                // don't know how to deal with it. Maybe the base implementation does.
                base.DisplayEmbeddedObject(vwenv, hvo);
                return;
            }
            int hvoFile = sda.get_ObjectProp(hvo, CmPictureTags.kflidPictureFile);

            if (hvoFile == 0)
            {
                return;
            }
            string path;
            string fileName = sda.get_UnicodeProp(hvoFile, CmFileTags.kflidInternalPath);

            if (Path.IsPathRooted(fileName))
            {
                path = fileName;
            }
            else
            {
                if (m_hvoLangProject == 0)
                {
                    // REVIEW (TimS/TomB): Hvo is for a CmPicture which means it might not be owned.
                    // If it's not owned, there will be no way to walk up the owner tree to find the
                    // Language Project. Review all clients to see if they have embedded objects.
                    // If so, they need to set the cache.
                    TryToSetLangProjectHvo(sda, hvo);
                }
                string linkedFilesRoot = sda.get_UnicodeProp(m_hvoLangProject, LangProjectTags.kflidLinkedFilesRootDir);
                if (String.IsNullOrEmpty(linkedFilesRoot))
                {
                    path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
                }
                else
                {
                    path = Path.Combine(linkedFilesRoot, fileName);
                }
            }
            vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
                                  (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);

            IPicture picture = new PictureWrapper(path);

            // -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
            vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
        }
コード例 #2
0
ファイル: FwBaseVc.cs プロジェクト: bbriggs/FieldWorks
		public override void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
		{
			// See if it is a CmPicture.
			ISilDataAccess sda = vwenv.DataAccess;
			int clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);
			if (clsid != CmPictureTags.kClassId)
			{
				// don't know how to deal with it. Maybe the base implementation does.
				base.DisplayEmbeddedObject(vwenv, hvo);
				return;
			}
			int hvoFile = sda.get_ObjectProp(hvo, CmPictureTags.kflidPictureFile);
			if (hvoFile == 0)
				return;
			string path;
			string fileName = sda.get_UnicodeProp(hvoFile, CmFileTags.kflidInternalPath);
			if (Path.IsPathRooted(fileName))
			{
				path = fileName;
			}
			else
			{
				if (m_hvoLangProject == 0)
				{
					// REVIEW (TimS/TomB): Hvo is for a CmPicture which means it might not be owned.
					// If it's not owned, there will be no way to walk up the owner tree to find the
					// Language Project. Review all clients to see if they have embedded objects.
					// If so, they need to set the cache.
					TryToSetLangProjectHvo(sda, hvo);
				}
				string linkedFilesRoot = sda.get_UnicodeProp(m_hvoLangProject, LangProjectTags.kflidLinkedFilesRootDir);
				if (String.IsNullOrEmpty(linkedFilesRoot))
					path = Path.Combine(FwDirectoryFinder.DataDirectory, fileName);
				else
					path = Path.Combine(linkedFilesRoot, fileName);
			}
			vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
				(int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);

			IPicture picture = new PictureWrapper(path);
			// -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
			vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
		}
コード例 #3
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Display the specified object (from an ORC embedded in a string). The default
        /// here knows how to display IPictures.
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// -----------------------------------------------------------------------------------
        public virtual void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
        {
            CheckDisposed();
            // See if it is a CmPicture.
            ISilDataAccess sda   = vwenv.DataAccess;
            int            clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);

            if (clsid != CmPicture.kclsidCmPicture)
            {
                return;                 // don't know how to deal with it.
            }
            int hvoFile = sda.get_ObjectProp(hvo, (int)CmPicture.CmPictureTags.kflidPictureFile);

            if (hvoFile == 0)
            {
                return;
            }
            string path;
            string fileName = sda.get_UnicodeProp(hvoFile, (int)CmFile.CmFileTags.kflidInternalPath);

            if (Path.IsPathRooted(fileName))
            {
                path = fileName;
            }
            else
            {
                if (m_hvoLangProject == 0)
                {
                    TryToSetLangProjectHvo(sda, hvo);
                }
                string externalRoot = sda.get_UnicodeProp(m_hvoLangProject, (int)LangProject.LangProjectTags.kflidExtLinkRootDir);
                if (String.IsNullOrEmpty(externalRoot))
                {
                    path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
                }
                else
                {
                    path = Path.Combine(externalRoot, fileName);
                }
            }
            vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
                                  (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
            Image image;

            try
            {
                image = Image.FromFile(FileUtils.ActualFilePath(path));
            }
            catch
            {
                // unable to read image. set to default image that indicates an invalid image.
                image = ResourceHelper.ImageNotFoundX;
            }
            stdole.IPicture picture;
            try
            {
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            catch
            {
                // conversion to OLE format from current image format is not supported (e.g. WMF file)
                // try to convert it to a bitmap and convert it to OLE format again.
                // TODO: deal with transparency
                // We could just do the following line (creating a new bitmap) instead of going
                // through a memory stream, but then we end up with an image that is too big.
                //image = new Bitmap(image, image.Size);
                using (MemoryStream imageStream = new MemoryStream())
                {
                    image.Save(imageStream, ImageFormat.Png);
                    image = Image.FromStream(imageStream, true);
                }
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            // -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
            vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
            image.Dispose();
        }
コード例 #4
0
ファイル: VwBaseVc.cs プロジェクト: sillsdev/WorldPad
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Display the specified object (from an ORC embedded in a string). The default
		/// here knows how to display IPictures.
		/// </summary>
		/// <param name="vwenv"></param>
		/// <param name="hvo"></param>
		/// -----------------------------------------------------------------------------------
		public virtual void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
		{
			CheckDisposed();
			// See if it is a CmPicture.
			ISilDataAccess sda = vwenv.DataAccess;
			int clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);
			if (clsid != CmPicture.kclsidCmPicture)
				return; // don't know how to deal with it.
			int hvoFile = sda.get_ObjectProp(hvo, (int)CmPicture.CmPictureTags.kflidPictureFile);
			if (hvoFile == 0)
				return;
			string path;
			string fileName = sda.get_UnicodeProp(hvoFile, (int)CmFile.CmFileTags.kflidInternalPath);
			if (Path.IsPathRooted(fileName))
			{
				path = fileName;
			}
			else
			{
				if (m_hvoLangProject == 0)
					TryToSetLangProjectHvo(sda, hvo);
				string externalRoot = sda.get_UnicodeProp(m_hvoLangProject, (int)LangProject.LangProjectTags.kflidExtLinkRootDir);
				if (String.IsNullOrEmpty(externalRoot))
					path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
				else
					path = Path.Combine(externalRoot, fileName);
			}
			vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
				(int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			Image image;
			try
			{
				image = Image.FromFile(FileUtils.ActualFilePath(path));
			}
			catch
			{
				// unable to read image. set to default image that indicates an invalid image.
				image = ResourceHelper.ImageNotFoundX;
			}
			stdole.IPicture picture;
			try
			{
				picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
			}
			catch
			{
				// conversion to OLE format from current image format is not supported (e.g. WMF file)
				// try to convert it to a bitmap and convert it to OLE format again.
				// TODO: deal with transparency
				// We could just do the following line (creating a new bitmap) instead of going
				// through a memory stream, but then we end up with an image that is too big.
				//image = new Bitmap(image, image.Size);
				using (MemoryStream imageStream = new MemoryStream())
				{
					image.Save(imageStream, ImageFormat.Png);
					image = Image.FromStream(imageStream, true);
				}
				picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
			}
			// -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
			vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
			image.Dispose();
		}