Ejemplo n.º 1
0
        internal static EncoderParameters ConvertFromMemory(IntPtr memory)
        {
            if (memory == IntPtr.Zero)
            {
                throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.InvalidParameter);
            }

            int count = Marshal.ReadIntPtr(memory).ToInt32();

            EncoderParameters p = new EncoderParameters(count);
            int  size           = Marshal.SizeOf(typeof(EncoderParameter));
            long arrayOffset    = (long)memory + Marshal.SizeOf(typeof(IntPtr));

            IntSecurity.UnmanagedCode.Assert();

            try {
                for (int i = 0; i < count; i++)
                {
                    Guid guid                      = (Guid)UnsafeNativeMethods.PtrToStructure((IntPtr)(i * size + arrayOffset), typeof(Guid));
                    int  numberOfValues            = Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 16));
                    EncoderParameterValueType type = (EncoderParameterValueType)Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 20));
                    IntPtr value                   = Marshal.ReadIntPtr((IntPtr)(i * size + arrayOffset + 24));

                    p.param[i] = new EncoderParameter(new Encoder(guid), numberOfValues, type, value);
                }
            }
            finally {
                System.Security.CodeAccessPermission.RevertAssert();
            }

            return(p);
        }
Ejemplo n.º 2
0
        /// <include file='doc\ToolBarButton.uex' path='docs/doc[@for="ToolBarButton.GetTBBUTTONINFO"]/*' />
        /// <devdoc>
        ///     Returns a TBBUTTONINFO object that represents this ToolBarButton.
        /// </devdoc>
        internal NativeMethods.TBBUTTONINFO GetTBBUTTONINFO(bool updateText, int newCommandId) {

            NativeMethods.TBBUTTONINFO button = new NativeMethods.TBBUTTONINFO();
            button.cbSize = Marshal.SizeOf(typeof(NativeMethods.TBBUTTONINFO));
            button.dwMask = NativeMethods.TBIF_IMAGE
                            | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE;

            // Comctl on Win98 interprets null strings as empty strings, which forces
            // the button to leave space for text.  The only workaround is to avoid having comctl 
            // update the text.
            if (updateText) {
                button.dwMask |= NativeMethods.TBIF_TEXT;
            }

            button.iImage = ImageIndexer.ActualIndex;

            if (newCommandId != commandId) {
                commandId = newCommandId;
                button.idCommand = newCommandId;
                button.dwMask |= NativeMethods.TBIF_COMMAND;
            }

            // set up the state of the button
            //
            button.fsState = 0;
            if (enabled) button.fsState |= NativeMethods.TBSTATE_ENABLED;
            if (partialPush && style == ToolBarButtonStyle.ToggleButton) button.fsState |= NativeMethods.TBSTATE_INDETERMINATE;
            if (pushed) button.fsState |= NativeMethods.TBSTATE_CHECKED;
            if (!visible) button.fsState |= NativeMethods.TBSTATE_HIDDEN;

            // set the button style
            //
            switch (style) {
                case ToolBarButtonStyle.PushButton:
                    button.fsStyle = NativeMethods.TBSTYLE_BUTTON;
                    break;
                case ToolBarButtonStyle.ToggleButton:
                    button.fsStyle = NativeMethods.TBSTYLE_CHECK;
                    break;
                case ToolBarButtonStyle.Separator:
                    button.fsStyle = NativeMethods.TBSTYLE_SEP;
                    break;
            }


            if (text == null) {
                button.pszText = Marshal.StringToHGlobalAuto("\0\0");
            }
            else {
                string textValue = this.text;
                PrefixAmpersands(ref textValue);
                button.pszText = Marshal.StringToHGlobalAuto(textValue);
            }

            return button;
        }
Ejemplo n.º 3
0
        // VSWhidbey 177016: This is necessary to get the width of the buttons in the toolbar,
        // including the width of separators, so that we can accurately position the tooltip adjacent
        // to the currently hot button when the user uses keyboard navigation to access the toolbar.
        internal int GetButtonWidth() {

            // Assume that this button is the same width as the parent's ButtonSize's Width
            int buttonWidth = Parent.ButtonSize.Width;
            
            NativeMethods.TBBUTTONINFO button = new NativeMethods.TBBUTTONINFO();
            button.cbSize = Marshal.SizeOf(typeof(NativeMethods.TBBUTTONINFO));
            button.dwMask = NativeMethods.TBIF_SIZE;
            
            int buttonID = (int)UnsafeNativeMethods.SendMessage(new HandleRef(Parent, Parent.Handle), NativeMethods.TB_GETBUTTONINFO, commandId, ref button);
            if (buttonID != -1) {
                buttonWidth = button.cx;
            }
            
            return buttonWidth;
        }
Ejemplo n.º 4
0
            internal static object GetDefaultValue(ref PARAMDESC paramdesc)
            {
                if ((paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FHASDEFAULT) == 0)
                {
                    return(DBNull.Value);
                }

                PARAMDESCEX varValue = (PARAMDESCEX)Marshal.PtrToStructure(paramdesc.lpVarValue, typeof(PARAMDESCEX));

                if (varValue._cByte != (ulong)(Marshal.SizeOf((typeof(PARAMDESCEX)))))
                {
                    throw Error.DefaultValueCannotBeRead();
                }

                return(varValue._varDefaultValue.ToObject());
            }
Ejemplo n.º 5
0
        // This is necessary to get the width of the buttons in the toolbar,
        // including the width of separators, so that we can accurately position the tooltip adjacent
        // to the currently hot button when the user uses keyboard navigation to access the toolbar.
        internal int GetButtonWidth()
        {
            // Assume that this button is the same width as the parent's ButtonSize's Width
            int buttonWidth = Parent.ButtonSize.Width;

            var button = new ComCtl32.TBBUTTONINFOW
            {
                cbSize = (uint)Marshal.SizeOf <ComCtl32.TBBUTTONINFOW>(),
                dwMask = ComCtl32.TBIF.SIZE
            };

            int buttonID = (int)User32.SendMessageW(Parent, (User32.WindowMessage)ComCtl32.TB.GETBUTTONINFOW, (IntPtr)commandId, ref button);

            if (buttonID != -1)
            {
                buttonWidth = button.cx;
            }

            return(buttonWidth);
        }
Ejemplo n.º 6
0
        public void Open(string path)
        {
            string parentFolder = Path.GetDirectoryName(path);
            string baseFilename = Path.GetFileName(path);

            parentFolder ??= "";

            var finderDatStream =
                new FileStream(Path.Combine(parentFolder, FINDER_INFO), FileMode.Open, FileAccess.Read);

            while (finderDatStream.Position + 0x5C <= finderDatStream.Length)
            {
                var    datEntry  = new PcExchangeEntry();
                byte[] datEntryB = new byte[Marshal.SizeOf(datEntry)];
                finderDatStream.Read(datEntryB, 0, Marshal.SizeOf(datEntry));
                datEntry = Helpers.Marshal.ByteArrayToStructureBigEndian <PcExchangeEntry>(datEntryB);

                string macName = StringHandlers.PascalToString(datEntry.macName, Encoding.GetEncoding("macintosh"));

                byte[] tmpDosNameB = new byte[8];
                byte[] tmpDosExtB  = new byte[3];
                Array.Copy(datEntry.dosName, 0, tmpDosNameB, 0, 8);
                Array.Copy(datEntry.dosName, 8, tmpDosExtB, 0, 3);

                string dosName = Encoding.ASCII.GetString(tmpDosNameB).Trim() + "." +
                                 Encoding.ASCII.GetString(tmpDosExtB).Trim();

                string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture);

                if (baseFilename != macName &&
                    baseFilename != dosName &&
                    baseFilename != dosNameLow)
                {
                    continue;
                }

                if (File.Exists(Path.Combine(parentFolder, macName ?? throw new InvalidOperationException())))
                {
                    _dataPath = Path.Combine(parentFolder, macName);
                }
Ejemplo n.º 7
0
        internal IntPtr ConvertToMemory()
        {
            int size = Marshal.SizeOf(typeof(EncoderParameter));

            Debug.Assert(size == (16 + 4 + 4 + 4), "wrong size! (" + size + ")");

            IntPtr memory = (IntPtr)((long)Marshal.AllocHGlobal(param.Length * size + Marshal.SizeOf(typeof(Int32))));

            if (memory == IntPtr.Zero)
            {
                throw SafeNativeMethods.StatusException(SafeNativeMethods.OutOfMemory);
            }

            Marshal.WriteInt32(memory, param.Length);

            for (int i = 0; i < param.Length; i++)
            {
                Marshal.StructureToPtr(param[i], (IntPtr)((long)memory + Marshal.SizeOf(typeof(Int32)) + i * size), false);
            }

            return(memory);
        }
Ejemplo n.º 8
0
        internal static EncoderParameters ConvertFromMemory(IntPtr memory)
        {
            if (memory == IntPtr.Zero)
            {
                throw SafeNativeMethods.StatusException(SafeNativeMethods.InvalidParameter);
            }

            int count;

            count = Marshal.ReadInt32(memory);

            EncoderParameters p;

            p = new EncoderParameters(count);
            int size = (int)Marshal.SizeOf(typeof(EncoderParameter));

            for (int i = 0; i < count; i++)
            {
                Guid guid;
                guid = (Guid)UnsafeNativeMethods.PtrToStructure((IntPtr)(i * size + (long)memory + 4), typeof(Guid));

                int NumberOfValues;
                NumberOfValues = Marshal.ReadInt32((IntPtr)(i * size + (long)memory + 4 + size - 12));

                int Type;
                Type = Marshal.ReadInt32((IntPtr)(i * size + (long)memory + 4 + size - 8));

                int Value;
                Value = Marshal.ReadInt32((IntPtr)(i * size + (long)memory + 4 + size - 4));

                p.param[i] = new EncoderParameter(new Encoder(guid),
                                                  NumberOfValues,
                                                  Type,
                                                  Value);
            }

            return(p);
        }
Ejemplo n.º 9
0
        /// <devdoc>
        ///     Copy the EncoderParameters data into a chunk of memory to be consumed by native GDI+ code.
        ///
        ///     We need to marshal the EncoderParameters info from/to native GDI+ ourselve since the definition of the managed/unmanaged classes
        ///     are different and the native class is a bit weird. The native EncoderParameters class is defined in GDI+ as follows:
        ///
        ///      class EncoderParameters {
        ///          UINT Count;                      // Number of parameters in this structure
        ///          EncoderParameter Parameter[1];   // Parameter values
        ///      };
        ///
        ///     We don't have the 'Count' field since the managed array contains it. In order for this structure to work with more than one
        ///     EncoderParameter we need to preallocate memory for the extra n-1 elements, something like this:
        ///
        ///         EncoderParameters* pEncoderParameters = (EncoderParameters*) malloc(sizeof(EncoderParameters) + (n-1) * sizeof(EncoderParameter));
        ///
        ///     Also, in 64-bit platforms, 'Count' is aligned in 8 bytes (4 extra padding bytes) so we use IntPtr instead of Int32 to account for
        ///     that (See VSW#451333).
        /// </devdoc>
        internal IntPtr ConvertToMemory()
        {
            int size = Marshal.SizeOf(typeof(EncoderParameter));

            int    length = param.Length;
            IntPtr memory = Marshal.AllocHGlobal(checked (length * size + Marshal.SizeOf(typeof(IntPtr))));

            if (memory == IntPtr.Zero)
            {
                throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.OutOfMemory);
            }

            Marshal.WriteIntPtr(memory, (IntPtr)length);

            long arrayOffset = checked ((long)memory + Marshal.SizeOf(typeof(IntPtr)));

            for (int i = 0; i < length; i++)
            {
                Marshal.StructureToPtr(param[i], (IntPtr)(arrayOffset + i * size), false);
            }

            return(memory);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///  Returns a TBBUTTONINFOW object that represents this ToolBarButton.
        /// </summary>
        internal ComCtl32.TBBUTTONINFOW GetTBBUTTONINFO(bool updateText, int newCommandId)
        {
            var button = new ComCtl32.TBBUTTONINFOW
            {
                cbSize = (uint)Marshal.SizeOf <ComCtl32.TBBUTTONINFOW>(),
                dwMask = ComCtl32.TBIF.IMAGE | ComCtl32.TBIF.STATE | ComCtl32.TBIF.STYLE
            };

            // Older platforms interpret null strings as empty, which forces the button to
            // leave space for text.
            // The only workaround is to avoid having comctl update the text.
            if (updateText)
            {
                button.dwMask |= ComCtl32.TBIF.TEXT;
            }

            button.iImage = ImageIndexer.ActualIndex;

            if (newCommandId != commandId)
            {
                commandId        = newCommandId;
                button.idCommand = newCommandId;
                button.dwMask   |= ComCtl32.TBIF.COMMAND;
            }

            // set up the state of the button
            button.fsState = 0;
            if (enabled)
            {
                button.fsState |= ComCtl32.TBSTATE.ENABLED;
            }

            if (partialPush && style == ToolBarButtonStyle.ToggleButton)
            {
                button.fsState |= ComCtl32.TBSTATE.INDETERMINATE;
            }

            if (pushed)
            {
                button.fsState |= ComCtl32.TBSTATE.CHECKED;
            }

            if (!visible)
            {
                button.fsState |= ComCtl32.TBSTATE.HIDDEN;
            }

            // set the button style
            switch (style)
            {
            case ToolBarButtonStyle.PushButton:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.BUTTON;
                break;

            case ToolBarButtonStyle.ToggleButton:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.CHECK;
                break;

            case ToolBarButtonStyle.Separator:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.SEP;
                break;
            }

            if (text == null)
            {
                button.pszText = Marshal.StringToHGlobalAuto("\0\0");
            }
            else
            {
                string textValue = text;
                PrefixAmpersands(ref textValue);
                button.pszText = Marshal.StringToHGlobalAuto(textValue);
            }

            return(button);
        }
Ejemplo n.º 11
0
        public bool Identify(string path)
        {
            string parentFolder = Path.GetDirectoryName(path);

            parentFolder ??= "";

            if (!File.Exists(Path.Combine(parentFolder, FINDER_INFO)))
            {
                return(false);
            }

            if (!Directory.Exists(Path.Combine(parentFolder, RESOURCES)))
            {
                return(false);
            }

            string baseFilename = Path.GetFileName(path);

            bool dataFound = false;
            bool rsrcFound = false;

            var finderDatStream =
                new FileStream(Path.Combine(parentFolder, FINDER_INFO), FileMode.Open, FileAccess.Read);

            while (finderDatStream.Position + 0x5C <= finderDatStream.Length)
            {
                var    datEntry  = new PcExchangeEntry();
                byte[] datEntryB = new byte[Marshal.SizeOf(datEntry)];
                finderDatStream.Read(datEntryB, 0, Marshal.SizeOf(datEntry));
                datEntry = Helpers.Marshal.ByteArrayToStructureBigEndian <PcExchangeEntry>(datEntryB);

                // TODO: Add support for encoding on filters
                string macName = StringHandlers.PascalToString(datEntry.macName, Encoding.GetEncoding("macintosh"));

                byte[] tmpDosNameB = new byte[8];
                byte[] tmpDosExtB  = new byte[3];
                Array.Copy(datEntry.dosName, 0, tmpDosNameB, 0, 8);
                Array.Copy(datEntry.dosName, 8, tmpDosExtB, 0, 3);

                string dosName = Encoding.ASCII.GetString(tmpDosNameB).Trim() + "." +
                                 Encoding.ASCII.GetString(tmpDosExtB).Trim();

                string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture);

                if (baseFilename != macName &&
                    baseFilename != dosName &&
                    baseFilename != dosNameLow)
                {
                    continue;
                }

                dataFound |=
                    File.Exists(Path.Combine(parentFolder, macName ?? throw new InvalidOperationException())) ||
                    File.Exists(Path.Combine(parentFolder, dosName)) ||
                    File.Exists(Path.Combine(parentFolder, dosNameLow));

                rsrcFound |= File.Exists(Path.Combine(parentFolder, RESOURCES, dosName)) ||
                             File.Exists(Path.Combine(parentFolder, RESOURCES, dosNameLow));

                break;
            }

            finderDatStream.Close();

            return(dataFound && rsrcFound);
        }