Exemple #1
0
        public SuperToolTip( Drawing.ColorTable colorTable, SuperToolTipInfo info, Point p, bool balloon )
        {
            _colorTable = colorTable;
            _info = info;
            _balloon = balloon;

            using( Graphics g = CreateGraphics() )
            {
                Size size = GetSize( g, info );

                _width = size.Width;
                _height = size.Height;
            }

            Position( p );

            Setup();
        }
            // color_changes must contain a series of strictly increasing TextIndexes.
            // color_table can use Color.Empty to specify the default rtf color.
            // text_idx_delta offsets the text_index of items in the color_changes array.
            public RTFBuilder(Font font, string text, int text_idx_delta, List<ColorChangeInfo> color_changes, ref ColorTable color_table)
            {
                StringBuilder rtf = new StringBuilder();
                string font_name = font.Name;
                int font_size_in_half_points = (int)(font.SizeInPoints * 2.0f + 0.5f);
                rtf.Append(@"{\rtf1\ansi\deff0{\fonttbl{\f0 " + font_name + ";}}");
                //rtf.Append(@"{\rtf1\ansi\deff0");
                rtf.Append(color_table.rtf_color_table);
                rtf.Append(@"\viewkind4\uc0\f0\fs" + font_size_in_half_points.ToString());
                //rtf.Append(@"\viewkind4\uc0");
                if (color_changes.Count == 0 || color_changes[0].text_index + text_idx_delta > 0)
                {
                    rtf.Append(@"\cf0\highlight0");
                }
                else
                {
                    if (color_changes[0].fore_color_index < 0)
                        rtf.Append(@"\cf0");
                    if (color_changes[0].back_color_index < 0)
                        rtf.Append(@"\highlight0");
                }

                ProcessText(text, text_idx_delta, color_changes, ref color_table, rtf);
                rtf.Append('}');
                m_RTF = rtf.ToString();
            }
        public void Colorize(int start, int end, string text, List<ColorChangeInfo> color_changes, ref ColorTable color_table)
        {
            Debug.Assert(text.Length == end - start);
            if (!m_Colorized)
                return;
            if (color_changes.Count < 2)
                return;

            PausePainting();
            SaveSelectionAndScrollPos();
            try
            {
                int length = end - start;
                RTFBuilder rtf_builder = new RTFBuilder(Font, text, 0, color_changes, ref color_table);
                Select(start, length);
                SelectedRtf = rtf_builder.RTF;
            }
            finally
            {
                RestoreSelectionAndScrollPos();
                ResumePainting();
            }
        }
        // The color info of last item of color_changes isn't used, the last item is there only to provide the end iterator of the affected text.
        public void Colorize(List<ColorChangeInfo> color_changes, ref ColorTable color_table)
        {
            if (!m_Colorized)
                return;
            if (color_changes.Count < 2)
                return;

            PausePainting();
            SaveSelectionAndScrollPos();
            try
            {
                int start = color_changes[0].text_index;
                int end = color_changes[color_changes.Count - 1].text_index;
                int length = end - start;
                string text = GetTextRange(start, end);
                RTFBuilder rtf_builder = new RTFBuilder(Font, text, -start, color_changes, ref color_table);
                Select(start, length);
                SelectedRtf = rtf_builder.RTF;
            }
            finally
            {
                RestoreSelectionAndScrollPos();
                ResumePainting();
            }
        }
            void ProcessText(string text, int text_idx_delta, List<ColorChangeInfo> colore_changes, ref ColorTable color_table, StringBuilder rtf)
            {
                int text_idx = -text_idx_delta;
                int text_len = text.Length - text_idx_delta;
                #if DEBUG
                int last_info_text_idx = -text_idx_delta - 1;
                #endif
                int prev_color = -1;
                int prev_back_color = -1;
                for (int i = 0, e = colore_changes.Count; i < e; ++i)
                {
                    ColorChangeInfo info = colore_changes[i];
                #if DEBUG
                    Debug.Assert(i == e - 1 || info.fore_color_index >= 0 || info.back_color_index >= 0);
                    Debug.Assert(info.text_index > last_info_text_idx);
                    last_info_text_idx = info.text_index;
                #endif
                    if (info.text_index >= text_len)
                        break;
                    if ((info.fore_color_index < 0 || info.fore_color_index == prev_color) &&
                        (info.back_color_index < 0 || info.back_color_index == prev_back_color))
                        continue;

                    AppendEscapedText(text, text_idx + text_idx_delta, info.text_index + text_idx_delta, rtf);
                    text_idx = info.text_index;
                    if (info.fore_color_index >= 0 && info.fore_color_index != prev_color)
                    {
                        rtf.Append(color_table.fore_color_escapes[info.fore_color_index]);
                        prev_color = info.fore_color_index;
                    }
                    if (info.back_color_index >= 0 && info.back_color_index != prev_back_color)
                    {
                        rtf.Append(color_table.back_color_escapes[info.back_color_index]);
                        prev_back_color = info.back_color_index;
                    }
                }
                AppendEscapedText(text, text_idx + text_idx_delta, text_len + text_idx_delta, rtf);
            }
Exemple #6
0
            public GlowRenderer( TreeControl treeControl )
            {
                if( treeControl == null )
                {
                    throw new ArgumentNullException( "treeControl" );
                }

                _treeControl = treeControl;
                _colorTable = _treeControl.ColorTable;
            }