Exemplo n.º 1
0
        public override void Dispose()
        {
            if (this._handlePen != null)
            {
                this._handlePen.Dispose();
                this._handlePen = null;
            }

            if (this._handleFont != null)
            {
                this._handleFont.Dispose();
                this._handleFont = null;
            }

            if (this._handleBkBrush != null)
            {
                this._handleBkBrush.Dispose();
                this._handleBkBrush = null;
            }

            if (this._handleBkActiveBrush != null)
            {
                this._handleBkActiveBrush.Dispose();
                this._handleBkActiveBrush = null;
            }
        }
Exemplo n.º 2
0
        public override void Paint(IntPtr hdc, ITextSegmentStyled styledSegment, ITextView textView, TextSegmentVisualInfo info, int x, int y, int lineHeight, StyleRenderInfo sri)
        {
            //if (this._paintUnderline == null)
            //{
            //    this._paintUnderline = this.Settings.SpellcheckUnderlineEnabled; // Bridge.Get().GetSafe("Text.Style.Spellcheck.Underline.Enabled", true);
            //}

            if (textView.Settings.SpellcheckUnderlineEnabled == false)
            {
                return;
            }

            if (staticPenUnderline == null)
            {
                staticUnderlineColor = textView.Settings.ColorSpellcheckUnderline; // Bridge.Get().GetSafe("Text.Style.Spellcheck.Underline.Color", Color.Red);

                //int underlineType = Bridge.Get().GetSafe("Text.Style.Spellcheck.Underline.Type", (int) PenType.Dot);
                staticPenUnderline = new SafeHandleGDI(SafeNativeMethods.CreatePen((int)textView.Settings.SpellcheckUnderlineType, -1, ColorTranslator.ToWin32(staticUnderlineColor)));
            }

            var wordSize = styledSegment.Parent.GetSize(hdc, x, styledSegment.Index, styledSegment.GetLength(info.TextColumnIndex), info);

            var previousPen    = SafeNativeMethods.SelectObject(hdc, staticPenUnderline.DangerousGetHandle());
            var previousBkMode = SafeNativeMethods.SetBkMode(hdc, NativeConstants.TRANSPARENT);

            SafeNativeMethods.MoveToEx(hdc, x - wordSize.Width, y + lineHeight - 2, IntPtr.Zero);
            SafeNativeMethods.LineTo(hdc, x, y + lineHeight - 2);

            SafeNativeMethods.SelectObject(hdc, previousPen);
            SafeNativeMethods.SetBkMode(hdc, previousBkMode);
        }
Exemplo n.º 3
0
        public override void Paint(IntPtr hdc, ITextSegmentStyled textSegment, ITextView textView, TextSegmentVisualInfo info, int x, int y, int lineHeight, StyleRenderInfo sri)
        {
            if (staticBrushRed == null)
            {
                staticBrushRed = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(Color.Red)));
            }

            var spaceSize = (lineHeight / 4d);

            var rectTop = new RECT
            {
                left   = x,
                top    = y,
                right  = x + (lineHeight / 8),
                bottom = (int)(y + (lineHeight - (spaceSize)))
            };

            var rectBottom = new RECT
            {
                left  = rectTop.left,
                top   = (int)(rectTop.bottom + (spaceSize / 2)),
                right = rectTop.right
            };

            rectBottom.bottom = (int)(rectBottom.top + (spaceSize / 2));

            SafeNativeMethods.FillRect(hdc, ref rectTop, staticBrushRed.DangerousGetHandle());
            SafeNativeMethods.FillRect(hdc, ref rectBottom, staticBrushRed.DangerousGetHandle());
        }
Exemplo n.º 4
0
        private void DisposeBuffer()
        {
            if (this.bufHBitmap != null)
            {
                this.bufHBitmap.Dispose();
                this.bufHBitmap = null;
            }

            if (this.bufHdc != null)
            {
                this.bufHdc.Dispose();
                this.bufHdc = null;
            }

            if (this.tempHdc != null)
            {
                this.tempHdc.Dispose();
                this.tempHdc = null;
            }

            if (this.hFont != null)
            {
                this.hFont.Dispose();
                this.hFont = null;
            }
        }
Exemplo n.º 5
0
        public override void Dispose()
        {
            this._hbmpInfo.Dispose();
            this._hbmpInfo = null;

            this._handlePen.Dispose();
            this._handlePen = null;
        }
Exemplo n.º 6
0
        private static SafeHandleGDI DisposeBuffer(SafeHandleGDI hbitmap)
        {
            if (hbitmap != null)
            {
                hbitmap.Dispose();
            }

            return(null);
        }
Exemplo n.º 7
0
        public override unsafe void PaintLine(IntPtr hdc, RendererState rs)
        {
            if (this._handleFont == null)
            {
                using (var f = new Font(rs.TextView.Font.FontFamily, rs.TextView.Font.Size - 2))
                {
                    this._handleFont = new SafeHandleGDI(f.ToHfont());
                }

                this._handlePen           = new SafeHandleGDI(SafeNativeMethods.CreatePen(NativeConstants.PS_SOLID, -1, ColorTranslator.ToWin32(Color.Silver)));
                this._handleBkBrush       = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(Color.White)));
                this._handleBkActiveBrush = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(Color.FromArgb(240, 240, 250))));
            }

            var str        = (rs.LineIndexVirtual + 1).ToString();
            var textLength = rs.TextView.GetVisualLineCount().ToString().Length;

            if (textLength != this._previousLength)
            {
                // We check if the number of lines have changed to contain an extra character.
                // In that case we'll need to perform a layout calculation for the whole text control.
                // So, call on PerformLayout(). This *might* screw up the current painting, but it is very inlikely.
                this._previousLength = textLength;
                rs.TextView.PerformLayout();
            }

            fixed(char *c = str)
            {
                var isCurrentLine = rs.LineIndexVirtual == rs.LineIndexVirtualFocused;

                var previousFont = SafeNativeMethods.SelectObject(hdc, this._handleFont.DangerousGetHandle());
                var previousPen  = SafeNativeMethods.SelectObject(hdc, this._handlePen.DangerousGetHandle());

                var color             = isCurrentLine ? Color.DimGray : Color.LightSteelBlue;
                var previousForeColor = SafeNativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(color));
                var previousBkMode    = SafeNativeMethods.SetBkMode(hdc, NativeConstants.TRANSPARENT);

                var r = new RECT
                {
                    top    = rs.Y - rs.ViewportY,
                    right  = rs.X + this.Width,
                    bottom = rs.Y + rs.LineHeight,
                    left   = rs.X
                };

                SafeNativeMethods.FillRect(hdc, ref r, this._handleBkActiveBrush.DangerousGetHandle());
                SafeNativeMethods.MoveToEx(hdc, rs.X + this.Width, rs.Y - rs.ViewportY, IntPtr.Zero);
                SafeNativeMethods.LineTo(hdc, rs.X + this.Width, rs.Y + rs.LineHeight - rs.ViewportY);
                SafeNativeMethods.TextOut(hdc, 2 + rs.X, rs.Y - rs.ViewportY, c, str.Length);

                SafeNativeMethods.SelectObject(hdc, previousPen);
                SafeNativeMethods.SetTextColor(hdc, previousForeColor);
                SafeNativeMethods.SetBkMode(hdc, previousBkMode);
                SafeNativeMethods.SelectObject(hdc, previousFont);
            }
        }
Exemplo n.º 8
0
        public void DisposeDynamicBuffer(bool valueChange = false)
        {
            if (valueChange == false)
            {
                this._hbitmapTrack        = DisposeBuffer(this._hbitmapTrack);
                this._hbitmapTrackHot     = DisposeBuffer(this._hbitmapTrackHot);
                this._hbitmapTrackPressed = DisposeBuffer(this._hbitmapTrackPressed);

                this._hbitmapThumb        = DisposeBuffer(this._hbitmapThumb);
                this._hbitmapThumbHot     = DisposeBuffer(this._hbitmapThumbHot);
                this._hbitmapThumbPressed = DisposeBuffer(this._hbitmapThumbPressed);
            }
        }
Exemplo n.º 9
0
        public void Dispose()
        {
            if (this._caretTimer != null)
            {
                this._caretTimer.Dispose();
            }

            if (this._caretBrush != null)
            {
                this._caretBrush.Dispose();
                this._caretBrush = null;
            }
        }
Exemplo n.º 10
0
        public Caret(ITextView textView)
        {
            this._textView = textView;

            var c = Color.FromArgb(
                (byte)(255 - this._textView.BackColor.R),
                (byte)(255 - this._textView.BackColor.G),
                (byte)(255 - this._textView.BackColor.B));

            this._caretBrush = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(c)));

            this._caretTimer = new System.Threading.Timer(this.caretTimer_Tick, null, staticCaretBlinkTime, Timeout.Infinite);
        }
            public void Dispose()
            {
                if (this._brushCurrentLine != null)
                {
                    this._brushCurrentLine.Dispose();
                    this._brushCurrentLine = null;
                }

                if (this._fontTooltipOverlay != null)
                {
                    this._fontTooltipOverlay.Dispose();
                }
            }
Exemplo n.º 12
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            this.DisposeDynamicBuffer();

            this._hbitmapArrow1        = DisposeBuffer(this._hbitmapArrow1);
            this._hbitmapArrow1Hot     = DisposeBuffer(this._hbitmapArrow1Hot);
            this._hbitmapArrow1Pressed = DisposeBuffer(this._hbitmapArrow1Pressed);

            this._hbitmapArrow2        = DisposeBuffer(this._hbitmapArrow2);
            this._hbitmapArrow2Hot     = DisposeBuffer(this._hbitmapArrow2Hot);
            this._hbitmapArrow2Pressed = DisposeBuffer(this._hbitmapArrow2Pressed);
        }
Exemplo n.º 13
0
        private void SetDefaultPaintState(IntPtr hdc)
        {
            if (this.hFont == null)
            {
                this.hFont = new SafeHandleGDI(this.Font.ToHfont());
            }

            var styleDefault = this.GetTextStyle("Default") as TextStyles.TextStyleManual;

            SafeNativeMethods.SetBkMode(hdc, styleDefault.ColorBackground == Color.Transparent ? NativeConstants.TRANSPARENT : NativeConstants.OPAQUE);
            SafeNativeMethods.SetBkColor(hdc, ColorTranslator.ToWin32(styleDefault.ColorBackground));
            SafeNativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(styleDefault.ColorFont));
            SafeNativeMethods.SelectObject(hdc, this.hFont.DangerousGetHandle());
        }
            public unsafe void Render(IntPtr hdc, int vpx, int vpy, Size size)
            {
                #region Initialize GDI resources

                if (this._brushCurrentLine == null)
                {
                    var colorWithoutTransparency = Color.FromArgb(this.TextView.LineHighlightColor.R, this.TextView.LineHighlightColor.G, this.TextView.LineHighlightColor.B);
                    this._brushCurrentLine = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(colorWithoutTransparency)));
                }

                #endregion

                var styleSelection = this.TextView.GetTextStyle("Selection");
                var styleDefault   = this.TextView.GetTextStyle("Default");

                var rs = new RendererState(this.TextView.GetTextRectangle(false), this.TextView.LineHeight);
                rs.TextView    = this.TextView;
                rs.RenderState = new RenderState(this.TextView, styleDefault);
                rs.ViewportX   = vpx - rs.TextRectangle.Left;
                rs.ViewportY   = vpy;

                ITextSegmentStyled selectionSegment = null;
                ITextSegment       firstVisibleLine = null;

                //var foundActiveLine = this.TextView.LineHighlightColor.A == Color.Transparent.A || this.TextView.LineHighlightColor == Color.Empty;

                var textColumnIndex = this.TextView.CurrentTextColumnIndex;

                var sri = new StyleRenderInfo(this.FocusedStyledSegment);

                // TODO: Paint some nice graphics for the current text column index, when it is stable enough.
                var clientSize        = this.TextView.ClientSize;
                var lineCount         = this.Strategy.Lines.Count;
                var firstCharIndex    = this.TextView.GetFirstCharIndexFromLine(this.TextView.GetCurrentLine());
                var lineIndexPhysical = 0;
                for (rs.LineIndexPhysical = 0; rs.LineIndexPhysical < lineCount; lineIndexPhysical++, rs.LineIndexPhysical++)
                {
                    if (rs.Y > rs.ViewportY + size.Height)
                    {
                        // This line is after the viewport and does not need painting.
                        break;
                    }

                    rs.Line = this.Strategy.Lines[lineIndexPhysical];
                    var visualInfo      = this.TextView.GetVisualInformation(lineIndexPhysical);
                    var lineCountVisual = visualInfo.GetLineCountVisual(textColumnIndex);
                    var linesHeight     = lineCountVisual * rs.LineHeight;

                    if (rs.Y + linesHeight <= rs.ViewportY)
                    {
                        // This line is before the viewport.
                        rs.Y += linesHeight;
                        rs.LineIndexVirtual += lineCountVisual;
                        continue;
                    }

                    if (rs.Line.Index >= firstCharIndex && rs.Line.Index <= (this.TextView.SelectionStart + this.TextView.SelectionLength))
                    {
                        rs.LineIndexVirtualFocused = rs.LineIndexVirtual;

                        if (this.TextView.SelectionLength == 0)
                        {
                            this.RenderSelectedLineBackground(hdc, rs);
                        }
                    }

                    var textPoints = new Dictionary <int, List <ITextSegmentStyled> >();

                    if (firstVisibleLine == null)
                    {
                        firstVisibleLine = rs.Line;

                        #region Special handling for selection

                        if (this.TextView.SelectionLength > 0)
                        {
                            if (this.TextView.SelectionStart < rs.Line.Index && this.TextView.SelectionStart + this.TextView.SelectionLength >= rs.Line.Index)
                            {
                                // The selection begins on the line before this.
                                selectionSegment       = new TextAnchor(styleSelection);
                                selectionSegment.Index = firstVisibleLine.Index;

                                var textPointIndex = rs.Line.Index;
                                if (textPoints.ContainsKey(textPointIndex) == false)
                                {
                                    textPoints.Add(textPointIndex, new List <ITextSegmentStyled>());
                                }

                                textPoints[textPointIndex].Add(selectionSegment);
                            }
                        }

                        #endregion
                    }

                    var lineLength = rs.Line.GetLength(textColumnIndex);
                    if (this.TextView.SelectionLength > 0)
                    {
                        #region Special handling for selection

                        if (this.TextView.SelectionStart >= rs.Line.Index && this.TextView.SelectionStart <= rs.Line.Index + lineLength)
                        {
                            // The selection begins on this line.
                            selectionSegment       = new TextAnchor(styleSelection);
                            selectionSegment.Index = rs.Line.Index;
                            selectionSegment.SetLength(textColumnIndex, this.TextView.SelectionLength);

                            var textPointIndex = this.TextView.SelectionStart;
                            if (textPoints.ContainsKey(textPointIndex) == false)
                            {
                                textPoints.Add(textPointIndex, new List <ITextSegmentStyled>());
                            }

                            textPoints[textPointIndex].Add(selectionSegment);
                        }

                        if (this.TextView.SelectionStart + this.TextView.SelectionLength >= rs.Line.Index &&
                            this.TextView.SelectionStart + this.TextView.SelectionLength <= rs.Line.Index + lineLength)
                        {
                            // The selection ends on this line.
                            var textPointIndex = -(this.TextView.SelectionStart + this.TextView.SelectionLength);
                            if (textPoints.ContainsKey(textPointIndex) == false)
                            {
                                textPoints.Add(textPointIndex, new List <ITextSegmentStyled>());
                            }

                            textPoints[textPointIndex].Add(selectionSegment);
                        }

                        #endregion
                    }

                    var textLine = (TextLine)rs.Line;
                    if (textLine.StyledTextSegments != null && textLine.StyledTextSegments.Count > 0)
                    {
                        foreach (var textSegment in textLine.StyledTextSegments)
                        {
                            var textPointStartIndex = textLine.Index + textSegment.Index;
                            if (textPoints.ContainsKey(textPointStartIndex) == false)
                            {
                                textPoints.Add(textPointStartIndex, new List <ITextSegmentStyled>());
                            }

                            textPoints[textPointStartIndex].Add(textSegment);

                            var textPointEndIndex = -(textLine.Index + textSegment.Index + textSegment.GetLength(textColumnIndex));
                            if (textPoints.ContainsKey(textPointEndIndex) == false)
                            {
                                textPoints.Add(textPointEndIndex, new List <ITextSegmentStyled>());
                            }

                            textPoints[textPointEndIndex].Add(textSegment);
                        }
                    }

                    var wordWrapIndex = 0;
                    var tabIndex      = 0;
                    rs.X = 0;
                    var previousTextIndex = 0;
                    //var textLength = rs.Line.GetLength(textColumnIndex);
                    var lineSplitIndexes = visualInfo.GetLineSplitIndexes(textColumnIndex);
                    for (var textIndex = 0; textIndex <= lineLength; textIndex++)
                    {
                        var isLastIndex = textIndex == lineLength;

                        var isNewline = lineSplitIndexes != null;
                        if (isNewline)
                        {
                            isNewline = wordWrapIndex < lineSplitIndexes.Length && lineSplitIndexes[wordWrapIndex] == textIndex;

                            if (isNewline)
                            {
                                wordWrapIndex++;
                            }
                        }

                        var isTab = visualInfo.GetTabSplitIndexes(textColumnIndex) != null;
                        if (isTab)
                        {
                            isTab = tabIndex < visualInfo.GetTabSplitIndexes(textColumnIndex).Length&& visualInfo.GetTabSplitIndexes(textColumnIndex)[tabIndex] == textIndex;

                            if (isTab)
                            {
                                tabIndex++;
                            }
                        }

                        var globalIndex = rs.Line.Index + textIndex;
                        var styleStart  = textPoints.ContainsKey(globalIndex) ? textPoints[globalIndex] : null;
                        var styleEnd    = globalIndex != 0 && textPoints.ContainsKey(-globalIndex) ? textPoints[-globalIndex] : null;

                        if ((isLastIndex || isNewline || isTab || styleStart != null || styleEnd != null) == false)
                        {
                            // This is a regular character, and no change is done for it.
                            continue;
                        }

                        var start  = previousTextIndex;
                        var length = textIndex - start;

                        var outputText = rs.Line.GetText(textColumnIndex);

                        #region Add empty space at end of text if selection goes beyond current line

                        if (start + length == lineLength)
                        {
                            foreach (var rsi in rs.RenderState.GetRenderStateItems())
                            {
                                if (rsi.Segment.Style.NameKey != styleSelection.NameKey)
                                {
                                    continue;
                                }

                                if (styleEnd != null)
                                {
                                    var isStyleSelection = false;
                                    foreach (var se in styleEnd)
                                    {
                                        if (se.Style.NameKey == styleSelection.NameKey)
                                        {
                                            isStyleSelection = true;
                                            break;
                                        }
                                    }

                                    if (isStyleSelection)
                                    {
                                        break;
                                    }
                                }

                                outputText += " ";
                                length++;

                                break;
                            }
                        }

                        #endregion

                        fixed(char *c = outputText)
                        {
                            SafeNativeMethods.TextOut(hdc, rs.TextRectangle.Left + (rs.X - rs.ViewportX), rs.TextRectangle.Top + rs.Y - rs.ViewportY, c + start, length);

                            if ((isNewline == false && isLastIndex == false) || styleEnd != null)
                            {
                                rs.X += rs.Line.GetSize(hdc, rs.X, start, length, visualInfo.GetVisualInfo(textColumnIndex)).Width;
                            }

                            if (styleEnd != null)
                            {
                                foreach (var t in styleEnd)
                                {
                                    switch (t.Style.PaintMode)
                                    {
                                    case TextStylePaintMode.Custom:
                                    {
                                        t.Style.Paint(hdc, t, this.TextView, visualInfo.GetVisualInfo(textColumnIndex),
                                                      rs.TextRectangle.Left + (rs.X - rs.ViewportX),
                                                      rs.TextRectangle.Top + rs.Y - rs.ViewportY,
                                                      rs.LineHeight,
                                                      sri);
                                    }
                                    break;
                                    }
                                }
                            }
                        }

                        if (isNewline)
                        {
                            this.RenderLineColumns(hdc, clientSize, rs);
                            rs.X = 0;
                            rs.LineIndexVirtual++;
                            rs.Y += rs.LineHeight;
                        }

                        if (styleStart != null)
                        {
                            foreach (var t in styleStart)
                            {
                                rs.RenderState.Add(this.TextView, t);
                            }

                            rs.RenderState.Apply(hdc);
                        }

                        if (styleEnd != null)
                        {
                            foreach (var t in styleEnd)
                            {
                                rs.RenderState.Remove(t);
                            }

                            rs.RenderState.Apply(hdc);
                        }

                        previousTextIndex = textIndex;
                    }

                    if (this.TextView.WordWrapGlyphs && lineCountVisual > 1)
                    {
                        RenderWordWrapGlyph(hdc, rs.ViewportY, rs.Y, rs.TextRectangle, rs.LineHeight);
                    }

                    this.RenderLineColumns(hdc, clientSize, rs);
                    rs.X = 0;
                    rs.LineIndexVirtual++;
                    rs.Y += rs.LineHeight;
                }

                this.PaintTooltipOverlay(hdc);
            }
Exemplo n.º 15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.EnsureSelectionArrays(this.CurrentTextColumnIndex);

            #region buf

            if (this.bufHBitmap != null)
            {
                if (this.bufHBitmapSize.Width != Width || this.bufHBitmapSize.Height != Height)
                {
                    this.DisposeBuffer();
                }
            }

            var destHdc = e.Graphics.GetHdc();

            if (this.bufHdc == null || this.bufHdc.IsInvalid)
            {
                this.bufHdc = new SafeHandleDC(SafeNativeMethods.CreateCompatibleDC(destHdc));
            }

            if (this.bufHBitmap == null || this.bufHBitmap.IsInvalid)
            {
                var width  = Width;
                var height = Height;

                if (width <= 0 || height <= 0)
                {
                    e.Graphics.ReleaseHdc(destHdc);
                    return;
                }

                this.bufHBitmap     = new SafeHandleGDI(SafeNativeMethods.CreateCompatibleBitmap(destHdc, width, height));
                this.bufHBitmapSize = new Size(width, height);

                SafeNativeMethods.SelectObject(this.bufHdc.DangerousGetHandle(), this.bufHBitmap.DangerousGetHandle());
            }

            #endregion

            #region Initialize GDI resources

            if (this.backBrush == null)
            {
                var c = this.BackColor;
                this.backBrush = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(c)));

                c = Color.FromArgb((byte)(255 - SystemColors.Highlight.R), (byte)(255 - SystemColors.Highlight.G), (byte)(255 - SystemColors.Highlight.B));

                this.caretBrushSelection = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(c)));
            }

            #endregion

            var hdc = this.bufHdc;

            this.SetDefaultPaintState(hdc.DangerousGetHandle());

            var clientRect = new RECT
            {
                right  = ClientRectangle.Width,
                bottom = ClientRectangle.Height
            };

            if (BackgroundImage != null)
            {
                if (staticBackgroundHBitmap == null)
                {
                    staticBackgroundHBitmap = new SafeHandleGDI((BackgroundImage as Bitmap).GetHbitmap());
                }

                var bkgHdc     = SafeNativeMethods.CreateCompatibleDC(destHdc);
                var bkgHdcPrev = SafeNativeMethods.SelectObject(bkgHdc, staticBackgroundHBitmap.DangerousGetHandle());

                for (var imgX = 0; imgX < ClientSize.Width; imgX += BackgroundImage.Width)
                {
                    for (var imgY = 0; imgY < ClientSize.Height; imgY += BackgroundImage.Height)
                    {
                        SafeNativeMethods.BitBlt(hdc.DangerousGetHandle(), imgX, imgY, BackgroundImage.Width, BackgroundImage.Height, bkgHdc, 0, 0, NativeConstants.SRCCOPY);
                    }
                }

                SafeNativeMethods.SelectObject(bkgHdc, bkgHdcPrev);
                SafeNativeMethods.DeleteDC(bkgHdc);
            }
            else
            {
                SafeNativeMethods.FillRect(hdc.DangerousGetHandle(), ref clientRect, this.backBrush.DangerousGetHandle());
            }

            #region Paint overlay under text if the control is read-only

            if (this.IsReadOnly)
            {
                using (var g = Graphics.FromHdc(hdc.DangerousGetHandle()))
                {
                    using (var hatchBrush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.FromArgb(50, Color.Gray), Color.Transparent))
                    {
                        g.FillRectangle(hatchBrush, 0, 0, Width, Height);
                    }
                }
            }

            #endregion

            this._renderer.Render(hdc.DangerousGetHandle(), this.ScrollHost.ScrollPosH + this.GetTextRectangle(false).Left, this.ScrollHost.ScrollPosVIntegral, ClientSize);

            #region Paint overlay if control is not enabled or virtual

            if (Enabled == false)
            {
                using (var g = Graphics.FromHdc(hdc.DangerousGetHandle()))
                {
                    using (var hatchBrush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Gray, Color.Transparent))
                    {
                        g.FillRectangle(hatchBrush, 0, 0, Width, Height);
                    }
                }
            }
            else if (this.IsVirtual)
            {
                this.SetDefaultPaintState(hdc.DangerousGetHandle());

                var brush = SafeNativeMethods.CreateHatchBrush(NativeConstants.HS_FDIAGONAL, ColorTranslator.ToWin32(Color.Gray));

                var previousBrush = SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), brush);

                var leftsideFillRect = new RECT
                {
                    bottom = Height,
                    right  = Padding.Left
                };

                SafeNativeMethods.FillRect(hdc.DangerousGetHandle(), ref leftsideFillRect, brush);

                SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), previousBrush);
                SafeNativeMethods.DeleteObject(brush);
            }

            #endregion

            #region Paint caret

            if (this._imeComposition != null && this._imeComposition.IsCompositioning)
            {
                this._imeComposition.Paint(hdc.DangerousGetHandle(), this.Caret.Location.X, this.Caret.Location.Y, this.Caret);
            }
            else
            {
                this.Caret.Render(hdc.DangerousGetHandle());
            }

            #endregion

            #region Paint text limitation guides (when scrolling outside)

            if (this.CanScrollOutside)
            {
                if (this.ScrollHost != null)
                {
                    var endY = this.ScrollHost.VerticalMax - this.ScrollHost.ScrollPosVIntegral - this.LineHeight;

                    if (endY + this.LineHeight < ClientRectangle.Height)
                    {
                        // TODO: Should not be gray. Should be ControlPaint.Light(255 - this.BackColor)
                        var penHandle = SafeNativeMethods.CreatePen(NativeConstants.PS_DOT, -1, ColorTranslator.ToWin32(Color.Gray));
                        var previous  = SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), penHandle);

                        SafeNativeMethods.MoveToEx(hdc.DangerousGetHandle(), 0, endY, IntPtr.Zero);
                        SafeNativeMethods.LineTo(hdc.DangerousGetHandle(), ClientRectangle.Width, endY);

                        SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), previous);
                        SafeNativeMethods.DeleteObject(penHandle);
                    }

                    var endX = this.ScrollHost.HorizontalMax - this.ScrollHost.ScrollPosH + Padding.Left + Padding.Right;

                    if (endX + this.LineHeight < ClientRectangle.Width)
                    {
                        var penHandle = SafeNativeMethods.CreatePen(NativeConstants.PS_DOT, -1,
                                                                    ColorTranslator.ToWin32(Color.Gray));
                        var previous = SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), penHandle);

                        SafeNativeMethods.MoveToEx(hdc.DangerousGetHandle(), endX, 0, IntPtr.Zero);
                        SafeNativeMethods.LineTo(hdc.DangerousGetHandle(), endX, endY == -1
                            ? ClientRectangle.Height
                            : endY);

                        SafeNativeMethods.SelectObject(hdc.DangerousGetHandle(), previous);
                        SafeNativeMethods.DeleteObject(penHandle);
                    }
                }
            }

            #endregion

            SafeNativeMethods.BitBlt(destHdc, 0, 0, this.bufHBitmapSize.Width, this.bufHBitmapSize.Height, hdc.DangerousGetHandle(), 0, 0, (int)NativeConstants.SRCCOPY);

            e.Graphics.ReleaseHdc(destHdc);
            destHdc = IntPtr.Zero;

            base.OnPaint(e);
        }
Exemplo n.º 16
0
        private SafeHandleGDI GetBufferTrack()
        {
            ScrollBarState state;
            SafeHandleGDI  target;

            if (this._trackDown)
            {
                state  = ScrollBarState.Pressed;
                target = this._hbitmapTrackPressed;
            }
            else if (this._trackHover)
            {
                state  = ScrollBarState.Hot;
                target = this._hbitmapTrackHot;
            }
            else
            {
                state  = ScrollBarState.Normal;
                target = this._hbitmapTrack;
            }

            if (target != null)
            {
                return(target);
            }

            if (this.track.Width <= 0 || this.track.Height <= 0)
            {
                return(null);
            }

            using (var bmp = new Bitmap(this.track.Width, this.track.Height))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    if (ScrollBarRenderer.IsSupported)
                    {
                        if (this.Horizontal)
                        {
                            ScrollBarRenderer.DrawRightHorizontalTrack(g, new Rectangle(0, 0, bmp.Width, bmp.Height), state);
                        }
                        else
                        {
                            ScrollBarRenderer.DrawUpperVerticalTrack(g, new Rectangle(0, 0, bmp.Width, bmp.Height), state);
                        }
                    }
                    else
                    {
                        var bgColor1 = state == ScrollBarState.Pressed ? Color.Black : SystemColors.ControlLightLight;
                        var bgColor2 = state == ScrollBarState.Pressed
                            ? SystemColors.ControlDarkDark
                            : SystemColors.Control;

                        using (var b = new HatchBrush(HatchStyle.Percent50, bgColor1, bgColor2))
                        {
                            g.FillRectangle(b, 0, 0, bmp.Width, bmp.Height);
                        }
                    }
                }

                target = new SafeHandleGDI(bmp.GetHbitmap());
            }

            if (this._trackDown)
            {
                return(this._hbitmapTrackPressed = target);
            }

            if (this._trackHover)
            {
                return(this._hbitmapTrackHot = target);
            }

            return(this._hbitmapTrack = target);
        }
Exemplo n.º 17
0
        private SafeHandleGDI GetBufferArrow2()
        {
            SafeHandleGDI target;

            if (this._arrow2Down)
            {
                target = this._hbitmapArrow2Pressed;
            }
            else if (this._arrow2Hover)
            {
                target = this._hbitmapArrow2Hot;
            }
            else
            {
                target = this._hbitmapArrow2;
            }

            if (target != null)
            {
                return(target);
            }

            if (this.arrow2.Width <= 0 || this.arrow2.Height <= 0)
            {
                return(null);
            }

            using (var bmp = new Bitmap(this.arrow2.Width, this.arrow2.Height))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    if (ScrollBarRenderer.IsSupported)
                    {
                        if (this.Horizontal)
                        {
                            var s4 = this._arrow2Down
                                ? ScrollBarArrowButtonState.RightPressed
                                : this._arrow2Hover
                                    ? ScrollBarArrowButtonState.RightHot
                                    : ScrollBarArrowButtonState.RightNormal;
                            ScrollBarRenderer.DrawArrowButton(g, new Rectangle(0, 0, this.arrow2.Width, this.arrow2.Height), s4);
                        }
                        else
                        {
                            var s4 = this._arrow2Down
                                ? ScrollBarArrowButtonState.DownPressed
                                : this._arrow2Hover
                                    ? ScrollBarArrowButtonState.DownHot
                                    : ScrollBarArrowButtonState.DownNormal;
                            ScrollBarRenderer.DrawArrowButton(g, new Rectangle(0, 0, this.arrow2.Width, this.arrow2.Height), s4);
                        }
                    }
                    else
                    {
                        ControlPaint.DrawScrollButton(
                            g,
                            new Rectangle(0, 0, this.arrow2.Width, this.arrow2.Height),
                            this.Horizontal ? ScrollButton.Right : ScrollButton.Down,
                            this._arrow2Down
                                ? ButtonState.Pushed
                                : ButtonState.Normal);
                    }
                }

                target = new SafeHandleGDI(bmp.GetHbitmap());
            }

            if (this._arrow2Down)
            {
                return(this._hbitmapArrow2Pressed = target);
            }

            if (this._arrow2Hover)
            {
                return(this._hbitmapArrow2Hot = target);
            }

            return(this._hbitmapArrow2 = target);
        }
Exemplo n.º 18
0
        public override unsafe void PaintLine(IntPtr hdc, RendererState rs)
        {
            if (this._hbmpInfo == null)
            {
                this._hbmpInfo = new SafeHandleGDI(((Bitmap)this.GetImage(rs.TextView)).GetHbitmap(Color.White));
            }

            if (this._handlePen == null)
            {
                this._handlePen       = new SafeHandleGDI(SafeNativeMethods.CreatePen(NativeConstants.PS_SOLID, -1, ColorTranslator.ToWin32(Color.Silver)));
                this._brushBackground = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(Color.White)));

                using (var faded = new Bitmap(16, 16))
                {
                    using (var g = Graphics.FromImage(faded))
                    {
                        g.DrawImage(this.GetImage(rs.TextView), 0, 0);

                        using (var b = new SolidBrush(Color.FromArgb(240, Color.White)))
                        {
                            g.FillRectangle(b, 0, 0, 16, 16);
                        }
                    }

                    this._hbmpInfoFaded = new SafeHandleGDI(faded.GetHbitmap(Color.White));
                }
            }

            var clientSize = rs.TextView.ClientSize;

            var previousPen = SafeNativeMethods.SelectObject(hdc, this._handlePen.DangerousGetHandle());

            SafeNativeMethods.MoveToEx(hdc, clientSize.Width - this.Width, rs.Y - rs.ViewportY, IntPtr.Zero);
            SafeNativeMethods.LineTo(hdc, clientSize.Width - this.Width, rs.Y - rs.ViewportY + rs.LineHeight);

            var hasNote = rs.Line.Metadata.ContainsKey("Note");

            if (hasNote)
            {
                SafeHandleGDI hbmp = this._hbmpInfo;

                // create a mirror device context associated with the target device context
                var hdcCreated = SafeNativeMethods.CreateCompatibleDC(hdc);

                // connect the bitmap with the mirror device context
                var hBmOld = SafeNativeMethods.SelectObject(hdcCreated, hbmp.DangerousGetHandle());

                // transfer the bitmap data from the mirror device context to the target DC
                SafeNativeMethods.BitBlt(hdc, clientSize.Width - 16, rs.Y - rs.ViewportY, 16, 16, hdcCreated, 0, 0, NativeConstants.SRCCOPY);

                SafeNativeMethods.SelectObject(hdc, previousPen);
                SafeNativeMethods.DeleteObject(hBmOld);
                SafeNativeMethods.DeleteDC(hdcCreated);
            }
            else
            {
                var r = new RECT
                {
                    top    = rs.Y - rs.ViewportY,
                    right  = rs.X + this.Width,
                    bottom = rs.Y + rs.LineHeight,
                    left   = rs.X + 1
                };

                SafeNativeMethods.FillRect(hdc, ref r, this._brushBackground.DangerousGetHandle());
            }

            if (rs.LineIndexVirtual == rs.LineIndexVirtualFocused && hasNote)
            {
                // We are currently on the same line
                var note = rs.Line.Metadata["Note"];
                var size = TextRenderer.MeasureText(note, rs.TextView.Font, rs.TextRectangle.Size);

                var r = new RECT
                {
                    top    = rs.Y - rs.ViewportY,
                    right  = rs.X - 5,
                    bottom = rs.Y + size.Height,
                    left   = rs.X - size.Width - 5
                };

                SafeNativeMethods.FillRect(hdc, ref r, this._brushBackground.DangerousGetHandle());

                fixed(char *c = note)
                {
                    SafeNativeMethods.TextOut(hdc, r.left, r.top, c, note.Length);
                }
            }
        }
Exemplo n.º 19
0
        private SafeHandleGDI GetBufferThumb()
        {
            ScrollBarState state;
            SafeHandleGDI  target;

            if (this._thumbDown)
            {
                state  = ScrollBarState.Pressed;
                target = this._hbitmapThumbPressed;
            }
            else if (this._thumbHover)
            {
                state  = ScrollBarState.Hot;
                target = this._hbitmapThumbHot;
            }
            else
            {
                state  = ScrollBarState.Normal;
                target = this._hbitmapThumb;
            }

            if (target != null)
            {
                return(target);
            }

            if (this.thumb.Height <= 0)
            {
                return(null);
            }

            var w = this.thumb.Width;
            var h = this.thumb.Height;

            if (w <= 0 || h <= 0)
            {
                return(null);
            }

            using (var bmp = new Bitmap(w, h))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    if (ScrollBarRenderer.IsSupported)
                    {
                        if (this.Horizontal)
                        {
                            ScrollBarRenderer.DrawHorizontalThumb(g, new Rectangle(-1, 0, bmp.Width + 2, bmp.Height), state);
                            ScrollBarRenderer.DrawHorizontalThumbGrip(
                                g,
                                new Rectangle(
                                    (bmp.Width / 2) - (this.thumbGrip.Width / 2),
                                    (bmp.Height / 2) - (this.thumbGrip.Height / 2),
                                    this.thumbGrip.Width,
                                    this.thumbGrip.Height),
                                state);
                        }
                        else
                        {
                            ScrollBarRenderer.DrawVerticalThumb(g, new Rectangle(0, -1, bmp.Width, bmp.Height + 2), state);
                            ScrollBarRenderer.DrawVerticalThumbGrip(
                                g,
                                new Rectangle(
                                    (bmp.Width / 2) - (this.thumbGrip.Width / 2),
                                    (bmp.Height / 2) - (this.thumbGrip.Height / 2),
                                    this.thumbGrip.Width,
                                    this.thumbGrip.Height),
                                state);
                        }
                    }
                    else
                    {
                        ControlPaint.DrawButton(g, new Rectangle(0, 0, bmp.Width, bmp.Height), ButtonState.Normal);
                    }
                }

                target = new SafeHandleGDI(bmp.GetHbitmap());
            }

            if (this._thumbDown)
            {
                return(this._hbitmapThumbPressed = target);
            }

            if (this._thumbHover)
            {
                return(this._hbitmapThumbHot = target);
            }

            return(this._hbitmapThumb = target);
        }
Exemplo n.º 20
0
        public override void Paint(IntPtr hdc, ITextSegmentStyled textSegment, ITextView textView,
                                   TextSegmentVisualInfo info, int x, int y, int lineHeight, StyleRenderInfo sri)
        {
            var index = (int)textSegment.Object;

            var allSegments = sri.Get <ITextSegmentStyled[]>("speaker.segments");

            if (allSegments == null)
            {
                allSegments = textView.TextDocument.TextSegmentStyledManager.GetStyledTextSegments(NameKey).ToArray();
                sri.Set("speaker.segments", allSegments);
            }

            Color color;

            if (index == -1)
            {
                // TODO: Figure out the current speaker's index

                foreach (var styledSegment in allSegments)
                {
                    var otherIndex = (int)styledSegment.Object;
                    if (otherIndex == -1)
                    {
                        index = index == 1 ? 2 : 1;
                    }
                    else
                    {
                        index = otherIndex;
                    }

                    if (styledSegment == textSegment)
                    {
                        // We've arrived at our own row, so let's abort now.
                        break;
                    }
                }
            }

            var fill = false;

            switch (index)
            {
            case 1:
                color = Color.WhiteSmoke;
                break;

            case 2:
                color = Color.FromArgb(242, 255, 22);
                break;

            case 3:
                color = Color.FromArgb(189, 189, 255);
                break;

            case 4:
                color = Color.FromArgb(178, 255, 159);
                break;

            case 5:
                color = Color.FromArgb(255, 189, 189);
                break;

            case -2:
                fill  = true;
                color = Color.FromArgb(255, 0, 0);
                break;

            default:
                color = Color.FromArgb(200, 200, 200);
                break;
            }

            if (fill)
            {
                var brush = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(color)));

                var previousBrush  = SafeNativeMethods.SelectObject(hdc, brush.DangerousGetHandle());
                var previousBkMode = SafeNativeMethods.SetBkMode(hdc, NativeConstants.TRANSPARENT);

                var r = new RECT
                {
                    top    = y,
                    right  = textView.ClientSize.Width,
                    bottom = y + lineHeight,
                    left   = info.Size.Width + 10
                };

                SafeNativeMethods.FillRect(hdc, ref r, brush.DangerousGetHandle());

                SafeNativeMethods.SelectObject(hdc, previousBrush);
                SafeNativeMethods.SetBkMode(hdc, previousBkMode);
            }
            else
            {
                var pen = new SafeHandleGDI(SafeNativeMethods.CreatePen(NativeConstants.PS_SOLID, -1,
                                                                        ColorTranslator.ToWin32(color)));

                var previousPen    = SafeNativeMethods.SelectObject(hdc, pen.DangerousGetHandle());
                var previousBkMode = SafeNativeMethods.SetBkMode(hdc, NativeConstants.TRANSPARENT);

                SafeNativeMethods.MoveToEx(hdc, 1, y, IntPtr.Zero);
                SafeNativeMethods.LineTo(hdc, 1, y + lineHeight);

                SafeNativeMethods.MoveToEx(hdc, fill ? info.Size.Width : 2, y, IntPtr.Zero);
                SafeNativeMethods.LineTo(hdc, fill ? info.Size.Width : 2, y + lineHeight);

                SafeNativeMethods.SelectObject(hdc, previousPen);
                SafeNativeMethods.SetBkMode(hdc, previousBkMode);
            }
        }