Esempio n. 1
0
 private static Format InternalGetFormat(string strName, int id)
 {
     lock (internalSyncObject)
     {
         EnsurePredefined();
         for (int i = 0; i < formatCount; i++)
         {
             if (formatList[i].Id == id)
             {
                 return(formatList[i]);
             }
         }
         StringBuilder lpString = new StringBuilder(0x80);
         if (SafeNativeMethods.GetClipboardFormatName(id, lpString, lpString.Capacity) == 0)
         {
             lpString.Length = 0;
             if (strName == null)
             {
                 lpString.Append("Format").Append(id);
             }
             else
             {
                 lpString.Append(strName);
             }
         }
         EnsureFormatSpace(1);
         formatList[formatCount] = new Format(lpString.ToString(), id);
         return(formatList[formatCount++]);
     }
 }
Esempio n. 2
0
        /// <devdoc>
        /// Gets a <see cref='System.Windows.Forms.DataFormats.Format'/> with the Windows
        /// Clipboard numeric ID and name for the specified ID.
        /// </devdoc>
        public static Format GetFormat(int id)
        {
            // Win32 uses an unsigned 16 bit type as a format ID, thus stripping off the leading bits.
            // Registered format IDs are in the range 0xC000 through 0xFFFF, thus it's important
            // to represent format as an unsigned type.
            ushort clampedId = (ushort)(id & 0xFFFF);

            lock (s_internalSyncObject)
            {
                EnsurePredefined();

                for (int n = 0; n < s_formatCount; n++)
                {
                    if (s_formatList[n].Id == clampedId)
                    {
                        return(s_formatList[n]);
                    }
                }

                // The max length of the name of clipboard formats is equal to the max length
                // of a Win32 Atom of 255 chars. An additional null terminator character is added,
                // giving a required capacity of 256 chars.
                var nameBuilder = new StringBuilder(256);

                // This can happen if windows adds a standard format that we don't know about,
                // so we should play it safe.
                if (SafeNativeMethods.GetClipboardFormatName(clampedId, nameBuilder, nameBuilder.Capacity) == 0)
                {
                    nameBuilder.Length = 0;
                    nameBuilder.Append("Format").Append(clampedId);
                }

                EnsureFormatSpace(1);
                s_formatList[s_formatCount] = new Format(nameBuilder.ToString(), clampedId);

                return(s_formatList[s_formatCount++]);
            }
        }
Esempio n. 3
0
        /// <include file='doc\DataFormats.uex' path='docs/doc[@for="DataFormats.InternalGetFormat"]/*' />
        /// <devdoc>
        ///     Allows a the new format name to be specified if the requested format is not
        ///     in the list
        /// </devdoc>
        /// <internalonly/>
        private static Format InternalGetFormat(string strName, ushort id)
        {
            lock (internalSyncObject) {
                EnsurePredefined();

                for (int n = 0; n < formatCount; n++)
                {
                    if (formatList[n].Id == id)
                    {
                        return(formatList[n]);
                    }
                }

                StringBuilder s = new StringBuilder(128);

                // This can happen if windows adds a standard format that we don't know about,
                // so we should play it safe.
                //
                if (0 == SafeNativeMethods.GetClipboardFormatName(id, s, s.Capacity))
                {
                    s.Length = 0;
                    if (strName == null)
                    {
                        s.Append("Format").Append(id);
                    }
                    else
                    {
                        s.Append(strName);
                    }
                }

                EnsureFormatSpace(1);
                formatList[formatCount] = new Format(s.ToString(), id);

                return(formatList[formatCount++]);
            }
        }