tangxu
2024-10-14 6cd995b71dfc74d4d96347d0bc535fddf36fa9df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// *********************************
// Message from Original Author:
//
// 2008 Jose Menendez Poo
// Please give me credit if you use this code. It's all I ask.
// Contact me for more info: menendezpoo@gmail.com
// *********************************
//
// Original project from http://ribbon.codeplex.com/
// Continue to support and maintain by http://officeribbon.codeplex.com/
 
 
using System.Drawing;
using System.Drawing.Imaging;
 
namespace System.Windows.Forms
{
    /// <summary>
    /// Provides render functionallity for the Ribbon control
    /// </summary>
    /// <remarks></remarks>
    public class RibbonRenderer
    {
        #region Static
 
        private static ColorMatrix _disabledImageColorMatrix;
 
        /// <summary>
        /// Gets the disabled image color matrix
        /// </summary>
        private static ColorMatrix DisabledImageColorMatrix
        {
            get
            {
                if (_disabledImageColorMatrix == null)
                {
                    float[][] numArray = new float[5][];
                    numArray[0] = new[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
                    numArray[1] = new[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
                    numArray[2] = new[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
                    float[] numArray3 = new float[5];
                    numArray3[3] = 1f;
                    numArray[3] = numArray3;
                    numArray[4] = new[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
                    float[][] numArray2 = new float[5][];
                    float[] numArray4 = new float[5];
                    numArray4[0] = 1f;
                    numArray2[0] = numArray4;
                    float[] numArray5 = new float[5];
                    numArray5[1] = 1f;
                    numArray2[1] = numArray5;
                    float[] numArray6 = new float[5];
                    numArray6[2] = 1f;
                    numArray2[2] = numArray6;
                    float[] numArray7 = new float[5];
                    numArray7[3] = 0.7f;
                    numArray2[3] = numArray7;
                    numArray2[4] = new float[5];
                    _disabledImageColorMatrix = MultiplyColorMatrix(numArray2, numArray);
                }
                return _disabledImageColorMatrix;
            }
        }
 
        /// <summary>
        /// Multiplies the color matrix (Extracted from .NET Framework
        /// </summary>
        /// <param name="matrix1"></param>
        /// <param name="matrix2"></param>
        /// <returns></returns>
        internal static ColorMatrix MultiplyColorMatrix(float[][] matrix1, float[][] matrix2)
        {
            int num = 5;
            float[][] newColorMatrix = new float[num][];
            for (int i = 0; i < num; i++)
            {
                newColorMatrix[i] = new float[num];
            }
            float[] numArray2 = new float[num];
            for (int j = 0; j < num; j++)
            {
                for (int k = 0; k < num; k++)
                {
                    numArray2[k] = matrix1[k][j];
                }
                for (int m = 0; m < num; m++)
                {
                    float[] numArray3 = matrix2[m];
                    float num6 = 0f;
                    for (int n = 0; n < num; n++)
                    {
                        num6 += numArray3[n] * numArray2[n];
                    }
                    newColorMatrix[m][j] = num6;
                }
            }
            return new ColorMatrix(newColorMatrix);
        }
 
        /// <summary>
        /// Creates the disabled image for the specified Image
        /// </summary>
        /// <param name="normalImage"></param>
        /// <returns></returns>
        public static Image CreateDisabledImage(Image normalImage)
        {
            ImageAttributes imageAttr = new ImageAttributes();
            imageAttr.ClearColorKey();
            imageAttr.SetColorMatrix(DisabledImageColorMatrix);
            Size size = normalImage.Size;
            Bitmap image = new Bitmap(size.Width, size.Height);
            Graphics graphics = Graphics.FromImage(image);
            graphics.DrawImage(normalImage, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, imageAttr);
            graphics.Dispose();
            return image;
        }
 
        #endregion
 
        /// <summary>
        /// Renders the Ribbon Orb's DropDown background
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderOrbDropDownBackground(RibbonOrbDropDownEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the Ribbon's caption bar
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderRibbonCaptionBar(RibbonRenderEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the orb of the ribbon
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderRibbonOrb(RibbonRenderEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the background of the QuickAccess toolbar
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderRibbonQuickAccessToolbarBackground(RibbonRenderEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the Ribbon's background
        /// </summary>
        public virtual void OnRenderRibbonBackground(RibbonRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders a RibbonTab
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonTab(RibbonTabRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders a RibbonContext
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonContext(RibbonContextRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders a RibbonItem
        /// </summary>
        public virtual void OnRenderRibbonItem(RibbonItemRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the background of the content of the specified tab
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonTabContentBackground(RibbonTabRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the background of the specified ribbon panel
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonPanelBackground(RibbonPanelRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the text of the tab specified on the event
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonTabText(RibbonTabRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the text of the context specified on the event
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonContextText(RibbonContextRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the text of the item specified on the event
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonItemText(RibbonTextEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the border of the item, after the text and image of the item
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderRibbonItemBorder(RibbonItemRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the image of the item specified on the event
        /// </summary>
        public virtual void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the text of the specified panel
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderRibbonPanelText(RibbonPanelRenderEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Renders the background of a dropdown
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderDropDownBackground(RibbonCanvasEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the image separator of a dropdown
        /// </summary>
        /// <param name="item"></param>
        /// <param name="e"></param>
        public virtual void OnRenderDropDownDropDownImageSeparator(RibbonItem item, RibbonCanvasEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the background of a panel background
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderPanelPopupBackground(RibbonCanvasEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Call to draw the scroll buttons on the tab
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderTabScrollButtons(RibbonTabRenderEventArgs e)
        {
        }
 
        /// <summary>
        /// Call to draw the scrollbar on the Control
        /// </summary>
        /// <param name="g"></param>
        /// <param name="item"></param>
        /// <param name="ribbon"></param>
        public virtual void OnRenderScrollbar(Graphics g, Control item, Ribbon ribbon)
        {
        }
 
        /// <summary>
        /// Call to draw the Tooltip
        /// </summary>
        /// <param name="e"></param>
        public virtual void OnRenderToolTipBackground(RibbonToolTipRenderEventArgs e)
        {
        }
 
        /// <summary>
        /// Renders the text of the Tooltip specified on the event
        /// </summary>
        /// <param name="e">Event data and paint tools</param>
        public virtual void OnRenderToolTipText(RibbonToolTipRenderEventArgs e)
        {
        }
 
        public virtual void OnRenderToolTipImage(RibbonToolTipRenderEventArgs e)
        {
        }
    }
}