1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Alexander Olk
23 // Alexander Olk, alex.olk@googlemail.com
25 // based on ThemeWin32Classic
27 // - You can activate this Theme with export MONO_THEME=clearlooks
29 // This theme tries to match clearlooks theme
32 // - if an other control draws over a ScrollBar button you can see artefacts on the rounded edges
33 // (maybe use theme backcolor, but that looks ugly on a white background, need to find a way to get the backcolor of the parent control)
34 // - more correct drawing of disabled controls
37 using System.Drawing.Drawing2D;
38 using System.Drawing.Imaging;
39 using System.Drawing.Text;
41 namespace System.Windows.Forms {
42 internal class ThemeClearlooks : ThemeWin32Classic {
43 public override Version Version {
45 return new Version( 0, 0, 0, 2 );
49 static readonly Color theme_back_color = Color.FromArgb( 239, 235, 231 );
51 static readonly Color gradient_first_color = Color.FromArgb( 250, 248, 247 );
52 static readonly Color gradient_second_color = Color.FromArgb( 226, 219, 212 );
53 static readonly Color gradient_second_color_nr2 = Color.FromArgb( 234, 229, 224 );
54 static readonly Color pressed_gradient_first_color = Color.FromArgb( 217, 207, 202 );
55 static readonly Color pressed_gradient_second_color = Color.FromArgb( 199, 193, 187 );
56 static readonly Color border_normal_dark_color = Color.FromArgb( 129, 117, 106 );
57 static readonly Color border_normal_light_color = Color.FromArgb( 158, 145, 131 );
58 static readonly Color border_pressed_dark_color = Color.FromArgb( 109, 103, 98 );
59 static readonly Color border_pressed_light_color = Color.FromArgb( 120, 114, 107 );
60 static readonly Color button_outer_border_dark_color = Color.FromArgb( 232, 226, 220 );
61 static readonly Color button_outer_border_light_color = Color.FromArgb( 250, 248, 247 );
62 static readonly Color inner_border_dark_color = Color.FromArgb( 226, 219, 212 );
63 static readonly Color pressed_inner_border_dark_color = Color.FromArgb( 192, 181, 169 );
64 static readonly Color edge_top_inner_color = Color.FromArgb( 206, 200, 194 );
65 static readonly Color edge_bottom_inner_color = Color.FromArgb( 215, 209, 202 );
66 static readonly Color button_edge_top_outer_color = Color.FromArgb( 237, 233, 228 );
67 static readonly Color button_edge_bottom_outer_color = Color.FromArgb( 243, 239, 236 );
68 static readonly Color button_focus_color = Color.FromArgb( 101, 94, 86 );
69 static readonly Color button_mouse_entered_second_gradient_color = Color.FromArgb( 230, 226, 219 );
71 static readonly Color scrollbar_background_color = Color.FromArgb( 209, 200, 191 );
72 static readonly Color scrollbar_border_color = Color.FromArgb( 170, 156, 143 );
73 static readonly Color scrollbar_gradient_first_color = Color.FromArgb( 248, 247, 245 );
74 static readonly Color scrollbar_gradient_second_color = Color.FromArgb( 234, 229, 224 );
76 new static readonly Color arrow_color = Color.FromArgb( 16, 16, 16 );
78 static readonly Color tab_border_color = Color.FromArgb( 166, 151, 138 );
79 static readonly Color tab_not_selected_gradient_first_color = Color.FromArgb( 227, 223, 220 );
80 static readonly Color tab_not_selected_gradient_second_color = Color.FromArgb( 214, 209, 204 );
81 static readonly Color tab_selected_gradient_first_color = Color.FromArgb( 243, 239, 236 );
82 static readonly Color tab_selected_gradient_second_color = Color.FromArgb( 234, 228, 223 );
83 static readonly Color tab_edge_color = Color.FromArgb( 200, 196, 191 );
84 static readonly Color tab_inner_border_color = Color.FromArgb( 221, 212, 205 );
85 static readonly Color tab_top_border_focus_color = Color.FromArgb( 70, 91, 110 );
86 static readonly Color tab_focus_color = Color.FromArgb( 105, 147, 185 );
88 static readonly Color menuitem_gradient_first_color = Color.FromArgb( 98, 140, 178 );
89 static readonly Color menuitem_gradient_second_color = Color.FromArgb( 81, 113, 142 );
90 static readonly Color menuitem_border_color = Color.FromArgb( 80, 112, 141 );
91 static readonly Color menu_separator_color = Color.FromArgb( 219, 211, 203 );
92 static readonly Color menu_background_color = Color.FromArgb( 248, 245, 242 );
93 static readonly Color menu_border_color = Color.FromArgb( 141, 122, 104 );
94 static readonly Color menu_inner_border_color = Color.FromArgb( 236, 228, 221 );
96 static readonly Color combobox_border_color = Color.FromArgb( 159, 146, 132 );
97 static readonly Color combobox_focus_border_color = Color.FromArgb( 70, 91, 110 );
98 //static readonly Color combobox_focus_inner_border_color = Color.FromArgb( 167, 198, 225 );
99 static readonly Color combobox_button_second_gradient_color = Color.FromArgb( 226, 220, 213 );
101 static readonly Color progressbar_edge_dot_color = Color.FromArgb( 219, 212, 205 );
102 static readonly Color progressbar_inner_border_color = Color.FromArgb( 139, 176, 209 );
103 static readonly Color progressbar_first_gradient_color = Color.FromArgb( 104, 146, 184 );
104 static readonly Color progressbar_second_gradient_color = Color.FromArgb( 91, 133, 172 );
106 static readonly Color checkbox_inner_boder_color = Color.FromArgb( 237, 234, 231 );
107 static readonly Color checkbox_pressed_inner_boder_color = Color.FromArgb( 203, 196, 189 );
108 static readonly Color checkbox_pressed_backcolor = Color.FromArgb( 212, 207, 202 );
110 static readonly Color trackbar_second_gradient_color = Color.FromArgb( 114, 154, 190 );
111 static readonly Color trackbar_third_gradient_color = Color.FromArgb( 130, 168, 202 );
112 static readonly Color trackbar_inner_first_gradient_color = Color.FromArgb( 238, 233, 229 );
113 static readonly Color trackbar_inner_second_gradient_color = Color.FromArgb( 223, 215, 208 );
114 static readonly Color trackbar_inner_pressed_second_gradient_color = Color.FromArgb( 224, 217, 210 );
116 //static readonly Color disabled_color_foreground = Color.FromArgb( 182, 180, 173 );
118 static readonly Color active_caption = Color.FromArgb( 85, 152, 215 );
120 static readonly Color radio_button_border_circle_color = Color.FromArgb( 126, 118, 105 );
121 static readonly Color radio_button_dot_color = Color.FromArgb( 94, 160, 221 );
123 const int SEPARATOR_HEIGHT = 7;
124 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
125 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
127 int platform = (int) Environment.OSVersion.Platform;
129 static Color control_parent_backcolor;
131 #region Principal Theme Methods
132 public ThemeClearlooks( ) {
133 ColorControl = theme_back_color;
136 public override Color DefaultControlBackColor {
137 get { return theme_back_color; }
140 public override Color DefaultWindowBackColor {
141 get { return theme_back_color; }
144 public override Color ColorControl {
145 get { return theme_back_color;}
148 public override Color ColorHighlight {
149 get { return menuitem_gradient_first_color; }
152 public override Color ColorActiveCaption {
153 get { return active_caption; }
156 public override Size Border3DSize {
158 return new Size( 3, 3 );
162 public override Color ColorInfo {
163 get { return Color.FromArgb (255, 255, 191); }
166 static readonly Color info_border_color = Color.FromArgb (218, 178, 85);
167 static readonly Color info_second_color = Color.FromArgb (220, 220, 160);
169 public override Image Images(UIIcon index, int size) {
171 case UIIcon.PlacesRecentDocuments:
172 if ((platform == 4) || (platform == 128))
173 return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
175 return base.Images (UIIcon.PlacesRecentDocuments, size);
176 case UIIcon.PlacesDesktop:
177 if ((platform == 4) || (platform == 128))
178 return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
180 return base.Images (UIIcon.PlacesDesktop, size);
181 case UIIcon.PlacesPersonal:
182 if ((platform == 4) || (platform == 128))
183 return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
185 return base.Images (UIIcon.PlacesPersonal, size);
186 case UIIcon.PlacesMyComputer:
187 if ((platform == 4) || (platform == 128))
188 return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
190 return base.Images (UIIcon.PlacesMyComputer, size);
191 case UIIcon.PlacesMyNetwork:
192 if ((platform == 4) || (platform == 128))
193 return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
195 return base.Images (UIIcon.PlacesMyNetwork, size);
197 // Icons for message boxes
198 case UIIcon.MessageBoxError: return base.Images (UIIcon.MessageBoxError, size);
199 case UIIcon.MessageBoxInfo: return base.Images (UIIcon.MessageBoxInfo, size);
200 case UIIcon.MessageBoxQuestion: return base.Images (UIIcon.MessageBoxQuestion, size);
201 case UIIcon.MessageBoxWarning: return base.Images (UIIcon.MessageBoxWarning, size);
204 case UIIcon.NormalFolder:
205 if ((platform == 4) || (platform == 128))
206 return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
208 return base.Images (UIIcon.NormalFolder, size);
211 throw new ArgumentException("Invalid Icon type requested", "index");
215 #endregion // Internal Methods
218 protected override void ButtonBase_DrawButton( ButtonBase button, Graphics dc ) {
219 dc.FillRectangle( ResPool.GetSolidBrush( button.BackColor ), button.ClientRectangle );
221 Color first_gradient_color = gradient_first_color;
222 Color second_gradient_color = gradient_second_color;
224 if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
225 ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
226 first_gradient_color = button.is_entered ? gradient_second_color : pressed_gradient_first_color;
227 second_gradient_color = button.is_entered ? gradient_second_color : pressed_gradient_second_color;
229 if (!button.is_enabled) {
230 button.is_entered = false;
232 if (button.is_entered) {
233 if (!button.is_pressed) {
234 first_gradient_color = Color.White;
235 second_gradient_color = button_mouse_entered_second_gradient_color;
237 first_gradient_color = pressed_gradient_first_color;
238 second_gradient_color = pressed_gradient_second_color;
242 bool paint_acceptbutton_black_border = false;
243 Form form = button.TopLevelControl as Form;
245 if (form != null && (form.AcceptButton == button as IButtonControl))
246 paint_acceptbutton_black_border = true;
248 CL_Draw_Button(dc, button.ClientRectangle, button.FlatStyle,
249 button.is_entered, button.is_enabled, button.is_pressed,
250 first_gradient_color, second_gradient_color,
251 paint_acceptbutton_black_border);
254 private void CL_Draw_Button(Graphics dc, Rectangle buttonRectangle, FlatStyle flat_style,
255 bool is_entered, bool is_enabled, bool is_pressed,
256 Color first_gradient_color, Color second_gradient_color,
257 bool paint_acceptbutton_black_border)
259 Rectangle lgbRectangle = new Rectangle (buttonRectangle.X + 3, buttonRectangle.Y + 3,
260 is_pressed ? buttonRectangle.Width - 5 : buttonRectangle.Width - 6,
261 buttonRectangle.Height - 6);
263 if (flat_style != FlatStyle.Popup || ((flat_style == FlatStyle.Popup) && is_entered)) {
264 LinearGradientBrush lgbr;
265 if (flat_style == FlatStyle.Flat) {
266 lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
267 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
268 second_gradient_color, first_gradient_color);
270 lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
271 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
272 first_gradient_color, second_gradient_color);
274 dc.FillRectangle (lgbr, lgbRectangle);
277 Point[] points_top = {
278 new Point (buttonRectangle.X + 2, buttonRectangle.Y + 2),
279 new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
280 new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
281 new Point (buttonRectangle.Right - 3 , buttonRectangle.Y + 2)
284 Point[] points_bottom = {
285 new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 3),
286 new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
287 new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
288 new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 3)
291 Point[] points_top_outer = {
292 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 1),
293 new Point (buttonRectangle.X + 2, buttonRectangle.Y),
294 new Point (buttonRectangle.Right - 3, buttonRectangle.Y),
295 new Point (buttonRectangle.Right - 2 , buttonRectangle.Y + 1)
298 Point[] points_bottom_outer = {
299 new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 2),
300 new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 1),
301 new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 1),
302 new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 2)
309 Color top_color = Color.Black;
310 Color bottom_color = Color.Black;
312 if (!paint_acceptbutton_black_border) {
313 top_color = is_pressed ? border_pressed_dark_color : border_normal_dark_color;
314 bottom_color = is_pressed ? border_pressed_light_color : border_normal_light_color;
317 pen = ResPool.GetPen (top_color);
318 dc.DrawLines (pen, points_top);
319 pen = ResPool.GetPen (bottom_color);
320 dc.DrawLines (pen, points_bottom);
322 using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
323 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
324 top_color, bottom_color)) {
325 using (Pen lgbrpen = new Pen (lgbr2)) {
326 dc.DrawLine (lgbrpen, buttonRectangle.X + 1, buttonRectangle.Y + 3, buttonRectangle.X + 1, buttonRectangle.Bottom - 3);
327 dc.DrawLine (lgbrpen, buttonRectangle.Right - 2, buttonRectangle.Y + 3, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3);
331 Point[] points_button_complete = {
332 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3),
333 new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
334 new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
335 new Point (buttonRectangle.Right - 2, buttonRectangle.Y + 3),
336 new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 4),
337 new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
338 new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
339 new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 4),
340 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3)
343 pen = ResPool.GetPen (pressed_inner_border_dark_color);
344 dc.DrawLines (pen, points_button_complete);
348 pen = ResPool.GetPen (button_outer_border_dark_color);
349 dc.DrawLines (pen, points_top_outer);
350 pen = ResPool.GetPen (button_outer_border_light_color);
351 dc.DrawLines (pen, points_bottom_outer);
353 using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 2),
354 new Point (buttonRectangle.X, buttonRectangle.Bottom - 1),
355 button_outer_border_dark_color, button_outer_border_light_color)) {
356 using (Pen lgbrpen = new Pen(lgbr2)) {
357 dc.DrawLine (lgbrpen, buttonRectangle.X, buttonRectangle.Y + 2, buttonRectangle.X, buttonRectangle.Bottom - 3);
358 dc.DrawLine (lgbrpen, buttonRectangle.Right - 1, buttonRectangle.Y + 2, buttonRectangle.Right - 1, buttonRectangle.Bottom - 3);
363 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : inner_border_dark_color);
365 dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 4);
367 dc.DrawLine (pen, buttonRectangle.X + 3, buttonRectangle.Bottom - 3, buttonRectangle.Right - 4, buttonRectangle.Bottom - 3);
368 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : Color.White);
369 dc.DrawLine (pen, buttonRectangle.X + 2, buttonRectangle.Y + 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 4);
370 dc.DrawLine (pen, buttonRectangle.X + 3 , buttonRectangle.Y + 2, buttonRectangle.Right - 4, buttonRectangle.Y + 2);
373 pen = ResPool.GetPen (edge_top_inner_color);
374 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Y + 2, buttonRectangle.X + 2, buttonRectangle.Y + 1);
375 dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 1, buttonRectangle.Right - 2, buttonRectangle.Y + 2);
377 pen = ResPool.GetPen (button_edge_top_outer_color);
378 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Y + 1, buttonRectangle.X + 1, buttonRectangle.Y);
379 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Y, buttonRectangle.Right - 1, buttonRectangle.Y + 1);
381 pen = ResPool.GetPen (edge_bottom_inner_color);
382 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Bottom - 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 2);
383 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 2);
385 pen = ResPool.GetPen (button_edge_bottom_outer_color);
386 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Bottom - 2, buttonRectangle.X + 1, buttonRectangle.Bottom - 1);
387 dc.DrawLine (pen, buttonRectangle.Right - 1, buttonRectangle.Bottom - 2, buttonRectangle.Right - 2, buttonRectangle.Bottom - 1);
391 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc ) {
393 if ( !button.is_enabled || button.FlatStyle == FlatStyle.Popup )
396 Pen pen = ResPool.GetPen( button_focus_color );
397 DashStyle old_dash_style = pen.DashStyle;
398 pen.DashStyle = DashStyle.Dot;
400 Rectangle focus_rect = new Rectangle( button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9 );
402 dc.DrawRectangle( pen, focus_rect );
404 pen.DashStyle = old_dash_style;
407 // FIXME: remove if libgdiplus DrawOrMeasureString is fixed
408 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc ) {
409 if ( !( button is CheckBox ) && !( button is RadioButton ) ) {
410 Rectangle buttonRectangle = button.ClientRectangle;
411 Rectangle text_rect = Rectangle.Inflate( buttonRectangle, -4, -4 );
413 string text = button.Text;
415 if ( text.Length > 1 ) {
416 SizeF sizef = dc.MeasureString( text, button.Font, text_rect.Width, button.text_format );
418 if ( (int)sizef.Width > text_rect.Width - 3 ) {
419 for ( int i = 1; i < text.Length + 1; i++ ) {
420 sizef = dc.MeasureString( text.Substring( 0, i ), button.Font, text_rect.Width, button.text_format );
422 if ( (int)sizef.Width > text_rect.Width - 3 ) {
423 text = text.Substring( 0, i - 1 );
430 if ( button.is_pressed ) {
435 if ( button.is_enabled ) {
436 dc.DrawString( text, button.Font, ResPool.GetSolidBrush( button.ForeColor ), text_rect, button.text_format );
438 if ( button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup ) {
439 dc.DrawString( text, button.Font, ResPool.GetSolidBrush( ControlPaint.DarkDark( this.ColorControl ) ), text_rect, button.text_format );
441 CPDrawStringDisabled( dc, text, button.Font, ColorControlText, text_rect, button.text_format );
446 #endregion // ButtonBase
449 public override void DrawMenuItem( MenuItem item, DrawItemEventArgs e ) {
450 StringFormat string_format;
451 Rectangle rect_text = e.Bounds;
453 if ( item.Visible == false )
456 if ( item.MenuBar ) {
457 string_format = string_format_menu_menubar_text;
459 string_format = string_format_menu_text;
462 if ( item.Separator ) {
463 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
464 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 1 );
466 e.Graphics.DrawLine( ResPool.GetPen( Color.White ),
467 e.Bounds.X, e.Bounds.Y + 2, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 2 );
473 rect_text.X += MenuCheckSize.Width;
475 if ( item.BarBreak ) { /* Draw vertical break bar*/
476 Rectangle rect = e.Bounds;
479 rect.Height = item.MenuHeight - 6;
481 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
482 rect.X, rect.Y , rect.X, rect.Y + rect.Height );
484 e.Graphics.DrawLine( ResPool.GetPen( ColorControlLight ),
485 rect.X + 1, rect.Y , rect.X + 1, rect.Y + rect.Height );
488 Color color_text = ColorMenuText;
491 /* Draw background */
492 Rectangle rect_back = e.Bounds;
494 rect_back.Width -= 2;
496 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected ) {
497 color_text = ColorHighlightText;
498 color_back = item.MenuBar ? theme_back_color : menu_background_color;
500 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rect_back.X, rect_back.Y + 1 ), new Point( rect_back.X, rect_back.Bottom - 1 ), menuitem_gradient_first_color, menuitem_gradient_second_color ) ) {
501 e.Graphics.FillRectangle( lgbr, rect_back.X + 1, rect_back.Y + 1, rect_back.Width - 1, rect_back.Height - 1 );
505 Pen tmp_pen = ResPool.GetPen( menuitem_border_color );
506 e.Graphics.DrawLine( tmp_pen, rect_back.X + 1, rect_back.Y, rect_back.Right - 1, rect_back.Y );
507 e.Graphics.DrawLine( tmp_pen, rect_back.Right, rect_back.Y + 1, rect_back.Right, rect_back.Bottom - 1 );
508 e.Graphics.DrawLine( tmp_pen, rect_back.Right - 1, rect_back.Bottom, rect_back.X + 1, rect_back.Bottom );
509 e.Graphics.DrawLine( tmp_pen, rect_back.X, rect_back.Bottom - 1, rect_back.X, rect_back.Y + 1 );
511 color_text = ColorMenuText;
512 color_back = item.MenuBar ? theme_back_color : menu_background_color;
514 e.Graphics.FillRectangle( ResPool.GetSolidBrush( color_back ), rect_back );
517 if ( item.Enabled ) {
518 e.Graphics.DrawString( item.Text, e.Font,
519 ResPool.GetSolidBrush( color_text ),
520 rect_text, string_format );
522 if ( !item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut ) {
523 string str = item.GetShortCutText( );
524 Rectangle rect = rect_text;
526 rect.Width -= item.XTab;
528 e.Graphics.DrawString( str, e.Font, ResPool.GetSolidBrush( color_text ),
529 rect, string_format_menu_shortcut );
532 ControlPaint.DrawStringDisabled( e.Graphics, item.Text, e.Font,
533 Color.Black, rect_text, string_format );
537 if ( item.MenuBar == false && item.IsPopup ) {
538 int cx = MenuCheckSize.Width;
539 int cy = MenuCheckSize.Height;
540 using ( Bitmap bmp = new Bitmap( cx, cy ) ) {
541 using ( Graphics dc = Graphics.FromImage( bmp ) ) {
542 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
543 dc.SmoothingMode = SmoothingMode.AntiAlias;
545 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
546 ControlPaint.DrawMenuGlyph( dc, rect_arrow, MenuGlyph.Arrow );
547 bmp.MakeTransparent( );
549 if ( item.Enabled ) {
550 e.Graphics.DrawImage( bmp, e.Bounds.X + e.Bounds.Width - cx,
551 e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
553 ControlPaint.DrawImageDisabled( e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
554 e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ), color_back );
557 dc.SmoothingMode = old_smoothing_mode;
562 /* Draw checked or radio */
563 if ( item.MenuBar == false && item.Checked ) {
565 Rectangle area = e.Bounds;
566 int cx = MenuCheckSize.Width;
567 int cy = MenuCheckSize.Height;
568 using ( Bitmap bmp = new Bitmap( cx, cy ) ) {
569 using ( Graphics gr = Graphics.FromImage( bmp ) ) {
570 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
572 if ( item.RadioCheck )
573 ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Bullet );
575 ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Checkmark );
577 bmp.MakeTransparent( );
578 e.Graphics.DrawImage( bmp, area.X, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
584 public override void DrawPopupMenu( Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect ) {
586 dc.FillRectangle( ResPool.GetSolidBrush
587 ( menu_background_color ), cliparea );
589 /* Draw menu borders */
590 dc.DrawRectangle( ResPool.GetPen( menu_border_color ), rect.X, rect.Y, rect.Width - 1, rect.Height - 1 );
593 Pen tmp_pen = ResPool.GetPen( Color.White );
594 dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 1, rect.Right - 2, rect.Y + 1 );
595 dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 2, rect.X + 1, rect.Bottom - 2 );
597 tmp_pen = ResPool.GetPen( menu_inner_border_color );
598 dc.DrawLine( tmp_pen, rect.Right - 2, rect.Y + 2, rect.Right - 2, rect.Bottom - 2 );
599 dc.DrawLine( tmp_pen, rect.Right - 3, rect.Bottom - 2, rect.X + 2, rect.Bottom - 2 );
601 for ( int i = 0; i < menu.MenuItems.Count; i++ )
602 if ( cliparea.IntersectsWith( menu.MenuItems[ i ].bounds ) ) {
603 MenuItem item = menu.MenuItems[ i ];
604 item.MenuHeight = menu.Height;
605 item.PerformDrawItem( new DrawItemEventArgs( dc, MenuFont,
606 item.bounds, i, item.Status ) );
612 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl ) {
613 Rectangle client_area = ctrl.client_area;
615 Rectangle bar = ctrl.client_area;
617 barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
619 bar.Width = barpos_pixels + 1;
621 // Draw bar background
622 dc.FillRectangle( ResPool.GetSolidBrush( menu_separator_color ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
625 Pen tmp_pen = ResPool.GetPen( progressbar_edge_dot_color );
626 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1 );
627 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
628 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1 );
629 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
631 tmp_pen = ResPool.GetPen( scrollbar_border_color );
632 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Y );
633 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
634 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Bottom - 1 );
635 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
637 if ( barpos_pixels <= 0 )
640 if ((bar.Width - 2) <= 0 || (bar.Height - 1) <= 0)
644 dc.DrawRectangle( ResPool.GetPen( combobox_focus_border_color ), bar.X - 1, bar.Y - 1, bar.Width, bar.Height + 1 );
645 tmp_pen = ResPool.GetPen( progressbar_inner_border_color );
646 dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.Right - 2, bar.Y );
647 dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.X, bar.Bottom - 1 );
649 using ( Bitmap bmp = new Bitmap( bar.Width - 2, bar.Height - 1 ) ) {
650 using ( Graphics gr = Graphics.FromImage( bmp ) ) {
651 gr.FillRectangle( ResPool.GetSolidBrush( tab_focus_color ), 0, 0, bmp.Width, bmp.Height );
653 LinearGradientBrush lgbr = new LinearGradientBrush( new Rectangle( 0, 0, bmp.Height, bmp.Height ), progressbar_first_gradient_color, progressbar_second_gradient_color, 0.0f, true );
655 lgbr.RotateTransform( 45.0f, MatrixOrder.Append );
657 float pen_width = bmp.Height / 2;
659 Pen pen = new Pen( lgbr, pen_width );
661 int add = bmp.Height + (int)pen.Width / 2;
664 int x_bottom = - bmp.Height;
666 while ( x_bottom < bmp.Width ) {
667 gr.DrawLine( pen, x_top, 0, x_bottom, bmp.Height );
675 dc.DrawImage( bmp, bar.X + 1, bar.Y + 1 );
678 #endregion // ProgressBar
682 // renders a radio button with the Flat and Popup FlatStyle
683 protected override void DrawFlatStyleRadioButton (Graphics dc, Rectangle rectangle, RadioButton radio_button)
685 if (radio_button.Enabled) {
686 // draw the outer flatstyle arcs
687 if (radio_button.FlatStyle == FlatStyle.Flat) {
688 dc.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
690 // fill in the area depending on whether or not the mouse is hovering
691 if (radio_button.is_entered && radio_button.Capture) {
692 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
694 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
697 // must be a popup radio button
699 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
701 if (radio_button.is_entered || radio_button.Capture) {
702 // draw the popup 3d button knob
703 dc.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
705 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
706 dc.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
709 // just draw lighter flatstyle outer circle
710 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);
715 // fill control background color regardless of actual backcolor
716 dc.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
717 // draw the ark as control dark
718 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
722 if (radio_button.Checked) {
723 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
724 dc.SmoothingMode = SmoothingMode.AntiAlias;
726 CL_Draw_RadioButton_Dot (dc, rectangle, true, false);
728 dc.SmoothingMode = old_smoothing_mode;
731 #endregion // RadioButton
734 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
735 int scrollbutton_width = bar.scrollbutton_width;
736 int scrollbutton_height = bar.scrollbutton_height;
737 Rectangle first_arrow_area;
738 Rectangle second_arrow_area;
741 thumb_pos = bar.ThumbPos;
744 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
745 bar.FirstArrowArea = first_arrow_area;
747 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
748 bar.SecondArrowArea = second_arrow_area;
750 thumb_pos.Width = bar.Width;
751 bar.ThumbPos = thumb_pos;
754 switch ( bar.thumb_moving ) {
755 case ScrollBar.ThumbMoving.None: {
756 ScrollBar_Vertical_Draw_ThumbMoving_None( scrollbutton_height, bar, clip, dc );
759 case ScrollBar.ThumbMoving.Forward: {
760 ScrollBar_Vertical_Draw_ThumbMoving_Forward( scrollbutton_height, bar, thumb_pos, clip, dc );
764 case ScrollBar.ThumbMoving.Backwards: {
765 ScrollBar_Vertical_Draw_ThumbMoving_Backwards( scrollbutton_height, bar, thumb_pos, clip, dc );
774 if ( clip.IntersectsWith( first_arrow_area ) )
775 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
776 if ( clip.IntersectsWith( second_arrow_area ) )
777 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
779 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
780 bar.FirstArrowArea = first_arrow_area;
782 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
783 bar.SecondArrowArea = second_arrow_area;
785 thumb_pos.Height = bar.Height;
786 bar.ThumbPos = thumb_pos;
789 switch ( bar.thumb_moving ) {
790 case ScrollBar.ThumbMoving.None: {
791 ScrollBar_Horizontal_Draw_ThumbMoving_None( scrollbutton_width, bar, clip, dc );
795 case ScrollBar.ThumbMoving.Forward: {
796 ScrollBar_Horizontal_Draw_ThumbMoving_Forward( scrollbutton_width, thumb_pos, bar, clip, dc );
800 case ScrollBar.ThumbMoving.Backwards: {
801 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( scrollbutton_width, thumb_pos, bar, clip, dc );
807 if ( clip.IntersectsWith( first_arrow_area ) )
808 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
809 if ( clip.IntersectsWith( second_arrow_area ) )
810 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
814 ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
817 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
818 if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
819 DrawScrollBarThumb( dc, thumb_pos, bar );
822 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc ) {
823 Rectangle r = new Rectangle( 0,
824 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
825 Rectangle intersect = Rectangle.Intersect( clip, r );
827 if ( intersect != Rectangle.Empty ) {
828 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
829 Pen pen = ResPool.GetPen( scrollbar_border_color );
830 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
831 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
835 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
836 Rectangle r = new Rectangle( 0, scrollbutton_height,
837 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
838 Rectangle intersect = Rectangle.Intersect( clip, r );
840 if ( intersect != Rectangle.Empty ) {
841 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
842 Pen pen = ResPool.GetPen( scrollbar_border_color );
843 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
844 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
848 r.Y = thumb_pos.Y + thumb_pos.Height;
849 r.Width = bar.ClientRectangle.Width;
850 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
852 intersect = Rectangle.Intersect( clip, r );
853 if ( intersect != Rectangle.Empty ) {
854 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
855 Pen pen = ResPool.GetPen( scrollbar_border_color );
856 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
857 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
861 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
862 Rectangle r = new Rectangle( 0, scrollbutton_height,
863 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
864 Rectangle intersect = Rectangle.Intersect( clip, r );
866 if ( intersect != Rectangle.Empty ) {
867 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
868 Pen pen = ResPool.GetPen( scrollbar_border_color );
869 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
870 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
874 r.Y = thumb_pos.Y + thumb_pos.Height;
875 r.Width = bar.ClientRectangle.Width;
876 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
878 intersect = Rectangle.Intersect( clip, r );
879 if ( intersect != Rectangle.Empty ) {
880 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
881 Pen pen = ResPool.GetPen( scrollbar_border_color );
882 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
883 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
887 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc ) {
888 Rectangle r = new Rectangle( scrollbutton_width,
889 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
890 Rectangle intersect = Rectangle.Intersect( clip, r );
892 if ( intersect != Rectangle.Empty ) {
893 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
894 Pen pen = ResPool.GetPen( scrollbar_border_color );
895 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
896 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
900 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
901 Rectangle r = new Rectangle( scrollbutton_width, 0,
902 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
903 Rectangle intersect = Rectangle.Intersect( clip, r );
905 if ( intersect != Rectangle.Empty ) {
906 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
907 Pen pen = ResPool.GetPen( scrollbar_border_color );
908 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
909 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
912 r.X = thumb_pos.X + thumb_pos.Width;
914 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
915 r.Height = bar.ClientRectangle.Height;
917 intersect = Rectangle.Intersect( clip, r );
918 if ( intersect != Rectangle.Empty ) {
919 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
920 Pen pen = ResPool.GetPen( scrollbar_border_color );
921 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
922 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
926 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
927 Rectangle r = new Rectangle( scrollbutton_width, 0,
928 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
929 Rectangle intersect = Rectangle.Intersect( clip, r );
931 if ( intersect != Rectangle.Empty ) {
932 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
933 Pen pen = ResPool.GetPen( scrollbar_border_color );
934 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
935 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
938 r.X = thumb_pos.X + thumb_pos.Width;
940 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
941 r.Height = bar.ClientRectangle.Height;
943 intersect = Rectangle.Intersect( clip, r );
944 if ( intersect != Rectangle.Empty ) {
945 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
946 Pen pen = ResPool.GetPen( scrollbar_border_color );
947 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
948 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
951 #endregion // ScrollBar
954 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
955 Brush br_forecolor, StatusBarPanel panel ) {
956 int border_size = 3; // this is actually const, even if the border style is none
958 area.Height -= border_size;
959 if ( panel.BorderStyle != StatusBarPanelBorderStyle.None ) {
960 dc.DrawRectangle( ResPool.GetPen( pressed_inner_border_dark_color ), area );
963 if ( panel.Style == StatusBarPanelStyle.OwnerDraw ) {
964 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
965 dc, panel.Parent.Font, area, index, DrawItemState.Default,
966 panel, panel.Parent.ForeColor, panel.Parent.BackColor );
967 panel.Parent.OnDrawItemInternal( e );
971 int left = area.Left;
972 if ( panel.Icon != null ) {
974 dc.DrawIcon( panel.Icon, left, area.Top );
975 left += panel.Icon.Width;
978 if ( panel.Text == String.Empty )
981 string text = panel.Text;
982 StringFormat string_format = new StringFormat( );
983 string_format.Trimming = StringTrimming.Character;
984 string_format.FormatFlags = StringFormatFlags.NoWrap;
986 if ( text[ 0 ] == '\t' ) {
987 string_format.Alignment = StringAlignment.Center;
988 text = text.Substring( 1 );
989 if ( text[ 0 ] == '\t' ) {
990 string_format.Alignment = StringAlignment.Far;
991 text = text.Substring( 1 );
995 int x = left + border_size;
996 int y = border_size + 2;
997 Rectangle r = new Rectangle( x, y,
998 area.Right - x - border_size,
999 area.Bottom - y - border_size );
1001 dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
1003 #endregion // StatusBar
1005 // FIXME: regions near the borders don't get filled with the correct backcolor
1006 // TODO: TabAlignment.Left and TabAlignment.Bottom
1007 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) {
1008 if (tab.Parent != null)
1009 dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area );
1011 dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area );
1012 Rectangle panel_rect = TabControlGetPanelRect( tab );
1014 if ( tab.Appearance == TabAppearance.Normal ) {
1016 switch ( tab.Alignment ) {
1017 case TabAlignment.Top:
1019 Pen pen = ResPool.GetPen( Color.White );
1021 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1022 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top , panel_rect.Right - 2, panel_rect.Top );
1024 pen = ResPool.GetPen( tab_inner_border_color );
1025 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1026 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1029 pen = ResPool.GetPen( tab_border_color );
1031 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Top - 1 );
1032 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Bottom - 2 );
1033 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom - 2, panel_rect.Right - 3, panel_rect.Bottom );
1034 dc.DrawLine( pen, panel_rect.Right - 3, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1035 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1036 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top - 1 );
1039 // FIXME: the size of the tab page is to big to draw the upper inner white border
1040 case TabAlignment.Right:
1042 pen = ResPool.GetPen( Color.White );
1044 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top + 1, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1045 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top + 1 , panel_rect.Right - 2, panel_rect.Top + 1 );
1047 pen = ResPool.GetPen( tab_inner_border_color );
1048 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1049 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1052 pen = ResPool.GetPen( tab_border_color );
1054 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top, panel_rect.Right - 1, panel_rect.Top );
1055 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top, panel_rect.Right - 1, panel_rect.Bottom );
1056 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1057 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1058 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top + 2 );
1059 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top + 2, panel_rect.Left + 2, panel_rect.Top );
1064 if (tab.Alignment == TabAlignment.Top) {
1065 for (int r = tab.TabPages.Count; r > 0; r--) {
1066 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1067 if (i == tab.SelectedIndex)
1069 if (r != tab.TabPages [i].Row)
1071 Rectangle rect = tab.GetTabRect (i);
1072 if (!rect.IntersectsWith (area))
1074 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1078 for (int r = 0; r < tab.TabPages.Count; r++) {
1079 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1080 if (i == tab.SelectedIndex)
1082 if (r != tab.TabPages [i].Row)
1084 Rectangle rect = tab.GetTabRect (i);
1085 if (!rect.IntersectsWith (area))
1087 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1092 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
1093 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
1094 if (rect.IntersectsWith (area))
1095 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
1098 if (tab.ShowSlider) {
1099 Rectangle right = TabControlGetRightScrollRect (tab);
1100 Rectangle left = TabControlGetLeftScrollRect (tab);
1101 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
1102 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
1106 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
1108 int FlatButtonSpacing = 8;
1110 int res = bounds.Width;
1112 if (page.BackColor != tab_selected_gradient_second_color)
1113 page.BackColor = tab_selected_gradient_second_color;
1115 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
1117 StringFormat string_format = new StringFormat ();
1119 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
1120 dc.FillRectangle (ResPool.GetSolidBrush (tab_selected_gradient_second_color), bounds);
1123 if (tab.Appearance == TabAppearance.FlatButtons) {
1124 int width = bounds.Width;
1125 bounds.Width += (FlatButtonSpacing - 2);
1127 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
1128 bounds.Width = width;
1132 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1133 } else if (tab.Appearance != TabAppearance.FlatButtons) {
1134 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1137 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
1139 string_format.Alignment = StringAlignment.Center;
1140 string_format.LineAlignment = StringAlignment.Center;
1141 string_format.FormatFlags = StringFormatFlags.NoWrap;
1143 Color tab_first_color = is_selected ? tab_selected_gradient_first_color : tab_not_selected_gradient_first_color;
1144 Color tab_second_color = is_selected ? tab_selected_gradient_second_color : tab_not_selected_gradient_second_color;
1146 switch (tab.Alignment) {
1147 case TabAlignment.Top:
1149 Rectangle tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1151 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom), tab_first_color, tab_second_color)) {
1152 dc.FillRectangle (lgbr, tab_interior);
1156 Pen tmp_pen = ResPool.GetPen (tab_edge_color);
1157 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 1, bounds.Left + 1, bounds.Top);
1158 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top, bounds.Right, bounds.Top + 1);
1161 tmp_pen = ResPool.GetPen (Color.White);
1162 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 1);
1163 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 1);
1166 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1167 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1168 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1169 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1171 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_dark_color, border_pressed_light_color)) {
1172 int diff = is_selected ? 3 : 2;
1173 using (Pen lgbrpen = new Pen (lgbr)) {
1174 dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - diff);
1175 dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Right, bounds.Bottom - diff);
1180 tmp_pen = ResPool.GetPen (tab_focus_color);
1181 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Right - 1, bounds.Top + 2);
1182 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1184 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1185 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1186 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1187 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1190 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1192 string_format.Alignment = StringAlignment.Center;
1193 string_format.LineAlignment = StringAlignment.Center;
1194 string_format.FormatFlags = StringFormatFlags.NoWrap;
1198 case TabAlignment.Bottom:
1200 tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1202 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom - 1), tab_first_color, tab_second_color)) {
1203 dc.FillRectangle (lgbr, tab_interior);
1207 tmp_pen = ResPool.GetPen (tab_edge_color);
1208 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1209 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom, bounds.Right, bounds.Bottom - 1);
1212 tmp_pen = ResPool.GetPen (Color.White);
1213 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 2);
1214 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
1217 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1218 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1219 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1220 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1222 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_light_color, border_pressed_dark_color)) {
1223 int diff = is_selected ? 3 : 2;
1224 using (Pen lgbrpen = new Pen (lgbr)) {
1225 dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1226 dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1231 tmp_pen = ResPool.GetPen (tab_focus_color);
1232 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Bottom - 2);
1233 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
1235 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1236 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1237 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1238 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1241 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1243 string_format.Alignment = StringAlignment.Center;
1244 string_format.LineAlignment = StringAlignment.Center;
1245 string_format.FormatFlags = StringFormatFlags.NoWrap;
1249 case TabAlignment.Left:
1251 int w_diff = is_selected ? 2 : 0;
1253 tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2 - w_diff, bounds.Height - 2);
1255 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Right - w_diff, bounds.Top + 2), tab_first_color, tab_second_color)) {
1256 dc.FillRectangle (lgbr, tab_interior);
1260 tmp_pen = ResPool.GetPen (tab_edge_color);
1261 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top, bounds.Left, bounds.Top + 1);
1262 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1265 tmp_pen = ResPool.GetPen (Color.White);
1266 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 3, bounds.Top + 1);
1267 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1270 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1271 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Left, bounds.Top + 2);
1272 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);
1273 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1275 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_dark_color, border_pressed_light_color)) {
1276 int diff = is_selected ? 3 : 1;
1278 using (Pen lgbrpen = new Pen (lgbr)) {
1279 dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Top, bounds.Right - diff, bounds.Left + 2);
1280 dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Bottom, bounds.Right - diff, bounds.Left + 2);
1285 tmp_pen = ResPool.GetPen (tab_focus_color);
1286 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top + 1, bounds.Left + 3, bounds.Bottom - 1);
1287 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 2, bounds.Left + 2, bounds.Bottom - 2);
1289 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1290 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top, bounds.Left + 1, bounds.Top + 2);
1291 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1292 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
1295 interior = new Rectangle (bounds.Left + 2, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1297 string_format.Alignment = StringAlignment.Center;
1298 string_format.LineAlignment = StringAlignment.Center;
1299 string_format.FormatFlags = StringFormatFlags.NoWrap;
1300 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1305 // TabAlignment.Right
1307 tab_interior = new Rectangle (bounds.Left, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2);
1309 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right, bounds.Top + 2), tab_second_color, tab_first_color)) {
1310 dc.FillRectangle (lgbr, tab_interior);
1313 int l_diff = is_selected ? 2 : 0;
1316 tmp_pen = ResPool.GetPen (tab_edge_color);
1317 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right - 1, bounds.Top + 1);
1318 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom);
1321 tmp_pen = ResPool.GetPen (Color.White);
1322 dc.DrawLine (tmp_pen, bounds.Left + l_diff, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1323 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1326 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1327 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1328 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1329 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1331 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_light_color, border_pressed_dark_color)) {
1332 int diff = is_selected ? 3 : 1;
1334 using (Pen lgbrpen = new Pen (lgbr)) {
1335 dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Top, bounds.Right - diff, bounds.Top);
1336 dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Bottom, bounds.Right - diff, bounds.Bottom);
1341 tmp_pen = ResPool.GetPen (tab_focus_color);
1342 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top + 1, bounds.Right - 3, bounds.Bottom - 1);
1343 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1345 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1346 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1347 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1348 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1351 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1353 string_format.Alignment = StringAlignment.Center;
1354 string_format.LineAlignment = StringAlignment.Center;
1355 string_format.FormatFlags = StringFormatFlags.NoWrap;
1356 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1362 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
1363 if (tab.Alignment == TabAlignment.Left) {
1364 int wo = interior.Width / 2;
1365 int ho = interior.Height / 2;
1366 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
1367 dc.RotateTransform (180);
1368 dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
1369 dc.ResetTransform ();
1371 dc.DrawString (page.Text, page.Font,
1372 ResPool.GetSolidBrush (SystemColors.ControlText),
1373 interior, string_format);
1375 } else if (page.Text != null) {
1376 DrawItemState state = DrawItemState.None;
1377 if (page == tab.SelectedTab)
1378 state |= DrawItemState.Selected;
1379 DrawItemEventArgs e = new DrawItemEventArgs (dc,
1380 tab.Font, bounds, tab.IndexForTabPage (page),
1381 state, page.ForeColor, page.BackColor);
1382 tab.OnDrawItemInternal (e);
1389 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state ) {
1390 Point[] arrow = new Point[ 3 ];
1400 bool pushed = false;
1402 Color first_color = Color.White;
1403 Color second_color = combobox_button_second_gradient_color;
1405 dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1407 if ( state == ButtonState.Pushed ) {
1408 first_color = pressed_gradient_first_color;
1409 second_color = pressed_gradient_second_color;
1413 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 2 ), first_color, second_color ) ) {
1414 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
1418 Pen tmp_pen = ResPool.GetPen( !pushed ? Color.White : pressed_inner_border_dark_color );
1419 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 1 );
1420 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 2 );
1422 tmp_pen = ResPool.GetPen( !pushed ? inner_border_dark_color : pressed_inner_border_dark_color );
1423 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y + 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1424 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1427 Point[] points = new Point[] {
1428 new Point( rectangle.X, rectangle.Y ),
1429 new Point( rectangle.Right - 3, rectangle.Y ),
1430 new Point( rectangle.Right - 1, rectangle.Y + 2 ),
1431 new Point( rectangle.Right - 1, rectangle.Bottom - 3 ),
1432 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
1433 new Point( rectangle.X, rectangle.Bottom - 1 ),
1434 new Point( rectangle.X, rectangle.Y )
1437 dc.DrawPolygon( ResPool.GetPen( pushed ? border_pressed_dark_color : border_normal_dark_color ), points );
1439 // edges on right side
1440 tmp_pen = ResPool.GetPen( control_parent_backcolor );
1441 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1442 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1444 tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
1445 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1446 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1448 rect = new Rectangle( rectangle.X + 1 + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2 - 1, rectangle.Height / 2 );
1449 centerX = rect.Left + rect.Width / 2;
1450 centerY = rect.Top + rect.Height / 2;
1451 shiftX = Math.Max( 1, rect.Width / 8 );
1452 shiftY = Math.Max( 1, rect.Height / 8 );
1454 if ( ( state & ButtonState.Pushed ) != 0 ) {
1462 P1 = new Point( rect.Left, centerY );
1463 P2 = new Point( centerX, rect.Bottom );
1464 P3 = new Point( rect.Right - 1, centerY );
1470 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1471 dc.SmoothingMode = SmoothingMode.AntiAlias;
1473 /* Draw the arrow */
1474 if ( state == ButtonState.Inactive ) {
1475 /* Move away from the shadow */
1476 P1.X += 1; P1.Y += 1;
1477 P2.X += 1; P2.Y += 1;
1478 P3.X += 1; P3.Y += 1;
1484 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) ) {
1485 dc.DrawLines( pen, arrow );
1488 P1 = new Point( rect.Left, centerY );
1489 P2 = new Point( centerX, rect.Bottom );
1490 P3 = new Point( rect.Right - 1, centerY );
1496 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) ) {
1497 dc.DrawLines( pen, arrow );
1500 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) ) {
1501 dc.DrawLines( pen, arrow );
1505 dc.SmoothingMode = old_smoothing_mode;
1508 /* Scroll button: regular button + direction arrow */
1509 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state ) {
1510 bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1512 DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1517 color_arrow = arrow_color;
1519 color_arrow = ColorGrayText;
1523 int centerX = area.Left + area.Width / 2;
1524 int centerY = area.Top + area.Height / 2;
1528 if ( ( state & ButtonState.Pushed ) != 0 )
1533 if ( area.Width < 12 || area.Height < 12 ) {
1538 Point[] arrow = new Point[ 4 ];
1540 switch (scroll_button_type) {
1541 case ScrollButton.Down:
1542 centerY += shift + 1;
1543 arrow [0] = new Point (centerX - min_4, centerY - min_2);
1544 arrow [1] = new Point (centerX, centerY + min_2);
1545 arrow [2] = new Point (centerX + min_4, centerY - min_2);
1546 arrow [3] = new Point (centerX - min_4, centerY - min_2);
1548 case ScrollButton.Up:
1550 arrow [0] = new Point (centerX - min_4, centerY + min_2);
1551 arrow [1] = new Point (centerX, centerY - min_2);
1552 arrow [2] = new Point (centerX + min_4, centerY + min_2);
1553 arrow [3] = new Point (centerX - min_4, centerY + min_2);
1555 case ScrollButton.Left:
1557 arrow [0] = new Point (centerX + min_2, centerY - min_4);
1558 arrow [1] = new Point (centerX + min_2, centerY + min_4);
1559 arrow [2] = new Point (centerX - min_2, centerY);
1560 arrow [3] = new Point (centerX + min_2, centerY - min_4);
1562 case ScrollButton.Right:
1563 centerX += shift + 1;
1564 arrow [0] = new Point (centerX - min_2, centerY - min_4);
1565 arrow [1] = new Point (centerX + min_2, centerY);
1566 arrow [2] = new Point (centerX - min_2, centerY + min_4);
1567 arrow [3] = new Point (centerX - min_2, centerY - min_4);
1573 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1574 dc.SmoothingMode = SmoothingMode.AntiAlias;
1575 dc.FillPolygon( ResPool.GetSolidBrush( color_arrow ), arrow );
1576 dc.SmoothingMode = old_smoothing_mode;
1579 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds ) {
1580 Point pt1 = new Point( bounds.Right - 3, bounds.Bottom );
1581 Point pt2 = new Point( bounds.Right, bounds.Bottom - 3 );
1584 Pen tmp_pen = ResPool.GetPen( Color.White );
1585 for ( int i = 0; i < 4; i++ ) {
1586 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1592 tmp_pen = ResPool.GetPen( pressed_inner_border_dark_color );
1593 for ( int i = 0; i < 4; i++ ) {
1594 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1598 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
1599 LinearGradientBrush lgbr = null;
1602 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.Right - 2, area.Y + 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1604 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1606 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1611 Pen pen = ResPool.GetPen( border_normal_dark_color );
1613 dc.DrawRectangle( pen, area.X, area.Y, area.Width - 1, area.Height - 1 );
1616 pen = ResPool.GetPen( Color.White );
1617 dc.DrawLine( pen, area.X + 1, area.Bottom - 2, area.X + 1, area.Y + 1 );
1618 dc.DrawLine( pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1620 pen = ResPool.GetPen( inner_border_dark_color );
1621 dc.DrawLine( pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1622 dc.DrawLine( pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1625 if ( area.Height > 12 ) {
1626 int mid_y = area.Y + ( area.Height / 2 );
1627 int mid_x = area.X + ( area.Width / 2 );
1629 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1630 dc.DrawLine( pen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1631 dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x + 3, mid_y - 3 );
1632 dc.DrawLine( pen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1634 Pen spen = ResPool.GetPen( Color.White );
1635 dc.DrawLine( spen, mid_x - 3, mid_y + 1, mid_x + 3, mid_y + 1 );
1636 dc.DrawLine( spen, mid_x - 3, mid_y - 2, mid_x + 3, mid_y - 2 );
1637 dc.DrawLine( spen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1640 // draw grip lines only if there is enough space
1641 if ( area.Width > 12 ) {
1642 int mid_x = area.X + ( area.Width / 2 );
1643 int mid_y = area.Y + ( area.Height / 2 );
1645 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1646 dc.DrawLine( pen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1647 dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x - 3, mid_y + 3 );
1648 dc.DrawLine( pen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1650 Pen spen = ResPool.GetPen( Color.White );
1651 dc.DrawLine( spen, mid_x + 1, mid_y - 3, mid_x + 1, mid_y + 3 );
1652 dc.DrawLine( spen, mid_x - 2, mid_y - 3, mid_x - 2, mid_y + 3 );
1653 dc.DrawLine( spen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1658 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type ) {
1659 Pen pen = ResPool.GetPen( border_normal_dark_color );
1661 Color first_gradient_color = gradient_first_color;
1662 Color second_gradient_color = gradient_second_color_nr2;
1664 bool pushed = false;
1666 if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed ) {
1667 first_gradient_color = pressed_gradient_first_color;
1668 second_gradient_color = pressed_gradient_second_color;
1672 Point[] points = null;
1674 LinearGradientBrush lgbr = null;
1676 switch ( scroll_button_type ) {
1677 case ScrollButton.Left:
1678 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1679 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.X, area.Bottom - 1 );
1681 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1682 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1684 Pen tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1685 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 2, area.X + 1, area.Bottom - 2 );
1686 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1688 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1689 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1690 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1692 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1693 dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1694 dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1696 points = new Point[] {
1697 new Point( area.X + 2, area.Y ),
1698 new Point( area.Right - 1, area.Y ),
1699 new Point( area.Right - 1, area.Bottom - 1 ),
1700 new Point( area.X + 2, area.Bottom - 1 ),
1701 new Point( area.X, area.Bottom - 3 ),
1702 new Point( area.X, area.Y + 2 ),
1703 new Point( area.X + 2, area.Y )
1705 dc.DrawPolygon( pen, points );
1707 case ScrollButton.Right:
1708 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1709 dc.DrawLine( ResPool.GetPen( ColorControl ), area.Right - 1, area.Y, area.Right - 1, area.Bottom - 1 );
1711 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1712 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1714 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1715 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1716 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1718 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1719 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1720 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1722 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1723 dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1724 dc.DrawLine( tmp_pen, area.Right - 1, area.Bottom - 2, area.Right - 2, area.Bottom - 1 );
1726 points = new Point[] {
1727 new Point( area.X, area.Y ),
1728 new Point( area.Right - 3, area.Y ),
1729 new Point( area.Right - 1, area.Y + 2 ),
1730 new Point( area.Right - 1, area.Bottom - 3 ),
1731 new Point( area.Right - 3, area.Bottom - 1 ),
1732 new Point( area.X, area.Bottom - 1 ),
1733 new Point( area.X, area.Y ),
1735 dc.DrawPolygon( pen, points );
1737 case ScrollButton.Up:
1738 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1739 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.Right - 1, area.Y );
1741 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1742 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1744 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1745 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1746 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1748 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1749 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1750 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1752 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1753 dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1754 dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1756 points = new Point[] {
1757 new Point( area.X + 2, area.Y ),
1758 new Point( area.Right - 3, area.Y ),
1759 new Point( area.Right - 1, area.Y + 2 ),
1760 new Point( area.Right - 1, area.Bottom - 1 ),
1761 new Point( area.X, area.Bottom - 1 ),
1762 new Point( area.X, area.Y + 2 ),
1763 new Point( area.X + 2, area.Y )
1765 dc.DrawPolygon( pen, points );
1767 case ScrollButton.Down:
1768 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1769 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Bottom - 1, area.Right - 1, area.Bottom - 1 );
1771 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1772 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1774 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1775 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1776 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1778 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1779 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1780 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1782 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1783 dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1784 dc.DrawLine( tmp_pen, area.Right - 2, area.Bottom - 1, area.Right - 1, area.Bottom - 2 );
1786 points = new Point[] {
1787 new Point( area.X, area.Y ),
1788 new Point( area.Right - 1, area.Y ),
1789 new Point( area.Right - 1, area.Bottom - 3 ),
1790 new Point( area.Right - 3, area.Bottom - 1 ),
1791 new Point( area.X + 2, area.Bottom - 1 ),
1792 new Point( area.X, area.Bottom - 3 ),
1793 new Point( area.X, area.Y )
1795 dc.DrawPolygon( pen, points );
1804 #endregion // ToolBar
1807 public override void DrawGroupBox( Graphics dc, Rectangle area, GroupBox box ) {
1808 StringFormat text_format;
1814 rect = box.ClientRectangle;
1816 dc.FillRectangle( ResPool.GetSolidBrush( box.BackColor ), rect );
1818 text_format = new StringFormat( );
1819 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1821 size = dc.MeasureString( box.Text, box.Font );
1822 width = (int) size.Width;
1824 if ( width > box.Width - 16 )
1825 width = box.Width - 16;
1827 y = box.Font.Height / 2;
1829 Pen pen = ResPool.GetPen( pressed_inner_border_dark_color );
1833 new Point( 8 + width, y ),
1834 new Point( box.Width - 3, y ),
1835 new Point( box.Width - 1, y + 2 ),
1836 new Point( box.Width - 1, box.Height - 3 ),
1837 new Point( box.Width - 3, box.Height - 1 ),
1838 new Point( 2, box.Height - 1 ),
1839 new Point( 0, box.Height - 3 ),
1840 new Point( 0, y + 2 ),
1844 dc.DrawLines( pen, points );
1847 if ( box.Enabled ) {
1848 dc.DrawString( box.Text, box.Font, ResPool.GetSolidBrush( box.ForeColor ), 10, 0, text_format );
1850 CPDrawStringDisabled( dc, box.Text, box.Font, box.ForeColor,
1851 new RectangleF( 10, 0, width, box.Font.Height ), text_format );
1853 text_format.Dispose( );
1858 private void DrawTrackBar_Vertical( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1859 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1860 float ticks, int value_pos, bool mouse_value ) {
1862 Point toptick_startpoint = new Point( );
1863 Point bottomtick_startpoint = new Point( );
1864 Point channel_startpoint = new Point( );
1866 float pixels_betweenticks;
1867 const int space_from_right = 8;
1868 const int space_from_left = 8;
1869 Rectangle area = tb.ClientRectangle;
1871 switch ( tb.TickStyle ) {
1872 case TickStyle.BottomRight:
1873 case TickStyle.None:
1874 channel_startpoint.Y = 8;
1875 channel_startpoint.X = 9;
1876 bottomtick_startpoint.Y = 13;
1877 bottomtick_startpoint.X = 24;
1879 case TickStyle.TopLeft:
1880 channel_startpoint.Y = 8;
1881 channel_startpoint.X = 19;
1882 toptick_startpoint.Y = 13;
1883 toptick_startpoint.X = 8;
1885 case TickStyle.Both:
1886 channel_startpoint.Y = 8;
1887 channel_startpoint.X = 18;
1888 bottomtick_startpoint.Y = 13;
1889 bottomtick_startpoint.X = 32;
1890 toptick_startpoint.Y = 13;
1891 toptick_startpoint.X = 8;
1897 thumb_area.X = area.X + channel_startpoint.X;
1898 thumb_area.Y = area.Y + channel_startpoint.Y;
1899 thumb_area.Height = area.Height - space_from_right - space_from_left;
1900 thumb_area.Width = 4;
1902 pixel_len = thumb_area.Height - 11;
1903 pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
1905 /* Convert thumb position from mouse position to value*/
1906 if ( mouse_value ) {
1908 if ( value_pos >= channel_startpoint.Y )
1909 value_pos = (int)( ( (float) ( value_pos - channel_startpoint.Y ) ) / pixels_betweenticks );
1913 if ( value_pos + tb.Minimum > tb.Maximum )
1914 value_pos = tb.Maximum - tb.Minimum;
1916 tb.Value = value_pos + tb.Minimum;
1919 thumb_pos.Width = 13;
1920 thumb_pos.Height = 29;
1922 thumb_pos.Y = channel_startpoint.Y + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Height / 3 );
1924 if ( thumb_pos.Y < channel_startpoint.Y )
1925 thumb_pos.Y = channel_startpoint.Y;
1927 if ( thumb_pos.Y > thumb_area.Bottom - 29 )
1928 thumb_pos.Y = thumb_area.Bottom - 29;
1932 Pen pen = ResPool.GetPen( tab_top_border_focus_color );
1933 dc.DrawLine( pen, channel_startpoint.X, thumb_pos.Y + 29, channel_startpoint.X, thumb_area.Bottom );
1934 dc.DrawLine( pen, channel_startpoint.X, thumb_area.Bottom, channel_startpoint.X + 4, thumb_area.Bottom );
1935 dc.DrawLine( pen, channel_startpoint.X + 4, thumb_pos.Y + 29, channel_startpoint.X + 4, thumb_area.Bottom );
1937 pen = ResPool.GetPen( menuitem_gradient_first_color );
1938 dc.DrawLine( pen, channel_startpoint.X + 1, thumb_pos.Y + 28, channel_startpoint.X + 1, thumb_area.Bottom - 1 );
1939 pen = ResPool.GetPen( trackbar_second_gradient_color );
1940 dc.DrawLine( pen, channel_startpoint.X + 2, thumb_pos.Y + 28, channel_startpoint.X + 2, thumb_area.Bottom - 1 );
1941 pen = ResPool.GetPen( trackbar_third_gradient_color );
1942 dc.DrawLine( pen, channel_startpoint.X + 3, thumb_pos.Y + 28, channel_startpoint.X + 3, thumb_area.Bottom - 1 );
1945 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1946 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, channel_startpoint.X + 1, thumb_pos.Y );
1947 dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), channel_startpoint.X + 2, channel_startpoint.Y + 1, 1, thumb_pos.Y );
1949 pen = ResPool.GetPen( scrollbar_border_color );
1950 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, thumb_pos.Y );
1951 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X + 4, channel_startpoint.Y );
1952 dc.DrawLine( pen, channel_startpoint.X + 4, channel_startpoint.Y, channel_startpoint.X + 4, thumb_pos.Y );
1955 thumb_pos.X = channel_startpoint.X - 4;
1958 pen = ResPool.GetPen( Color.White );
1959 dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
1960 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
1962 pen = ResPool.GetPen( menu_separator_color );
1963 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1964 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1968 new Point( thumb_pos.X + 2, thumb_pos.Y ),
1969 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
1970 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
1971 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
1972 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
1973 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
1974 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
1975 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
1976 new Point( thumb_pos.X + 2, thumb_pos.Y )
1979 dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
1981 Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
1982 Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
1984 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
1985 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
1989 pen = ResPool.GetPen( edge_top_inner_color );
1990 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
1991 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
1993 pen = ResPool.GetPen( edge_bottom_inner_color );
1994 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
1995 dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
1998 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1999 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 11, thumb_pos.X + 8, thumb_pos.Y + 11 );
2000 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 14, thumb_pos.X + 8, thumb_pos.Y + 14 );
2001 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 17, thumb_pos.X + 8, thumb_pos.Y + 17 );
2003 pen = ResPool.GetPen( Color.White );
2004 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 12, thumb_pos.X + 8, thumb_pos.Y + 12 );
2005 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 15, thumb_pos.X + 8, thumb_pos.Y + 15 );
2006 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 18, thumb_pos.X + 8, thumb_pos.Y + 18 );
2008 pixel_len = thumb_area.Height - 11;
2009 pixels_betweenticks = pixel_len / ticks;
2012 thumb_area.X = thumb_pos.X;
2013 thumb_area.Y = channel_startpoint.Y;
2014 thumb_area.Width = thumb_pos.Width;
2016 Region outside = new Region( area );
2017 outside.Exclude( thumb_area );
2019 if ( outside.IsVisible( clip_rectangle ) ) {
2020 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2021 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2023 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2024 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2025 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
2026 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc );
2028 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
2029 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc );
2033 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2034 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2036 pixel_len = thumb_area.Height - 11;
2037 pixels_betweenticks = pixel_len / ticks;
2039 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2040 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2041 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
2042 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc );
2044 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
2045 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc );
2054 private void DrawTrackBar_Horizontal( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
2055 ref Rectangle thumb_pos, ref Rectangle thumb_area,
2056 float ticks, int value_pos, bool mouse_value ) {
2057 Point toptick_startpoint = new Point( );
2058 Point bottomtick_startpoint = new Point( );
2059 Point channel_startpoint = new Point( );
2061 float pixels_betweenticks;
2062 const int space_from_right = 8;
2063 const int space_from_left = 8;
2064 Rectangle area = tb.ClientRectangle;
2066 switch ( tb.TickStyle ) {
2067 case TickStyle.BottomRight:
2068 case TickStyle.None:
2069 channel_startpoint.X = 8;
2070 channel_startpoint.Y = 9;
2071 bottomtick_startpoint.X = 13;
2072 bottomtick_startpoint.Y = 24;
2074 case TickStyle.TopLeft:
2075 channel_startpoint.X = 8;
2076 channel_startpoint.Y = 19;
2077 toptick_startpoint.X = 13;
2078 toptick_startpoint.Y = 8;
2080 case TickStyle.Both:
2081 channel_startpoint.X = 8;
2082 channel_startpoint.Y = 18;
2083 bottomtick_startpoint.X = 13;
2084 bottomtick_startpoint.Y = 32;
2085 toptick_startpoint.X = 13;
2086 toptick_startpoint.Y = 8;
2092 thumb_area.X = area.X + channel_startpoint.X;
2093 thumb_area.Y = area.Y + channel_startpoint.Y;
2094 thumb_area.Width = area.Width - space_from_right - space_from_left;
2095 thumb_area.Height = 4;
2097 pixel_len = thumb_area.Width - 11;
2098 pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
2100 /* Convert thumb position from mouse position to value*/
2101 if ( mouse_value ) {
2102 if ( value_pos >= channel_startpoint.X )
2103 value_pos = (int)( ( (float) ( value_pos - channel_startpoint.X ) ) / pixels_betweenticks );
2107 if ( value_pos + tb.Minimum > tb.Maximum )
2108 value_pos = tb.Maximum - tb.Minimum;
2110 tb.Value = value_pos + tb.Minimum;
2113 thumb_pos.Width = 29;
2114 thumb_pos.Height = 13;
2116 thumb_pos.X = channel_startpoint.X + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Width / 3 );
2118 if ( thumb_pos.X < channel_startpoint.X )
2119 thumb_pos.X = channel_startpoint.X;
2121 if ( thumb_pos.X > thumb_area.Right - 29 )
2122 thumb_pos.X = thumb_area.Right - 29;
2126 Pen pen = ResPool.GetPen( tab_top_border_focus_color );
2127 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, thumb_pos.X, channel_startpoint.Y );
2128 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, channel_startpoint.Y + 4 );
2129 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y + 4, thumb_pos.X, channel_startpoint.Y + 4 );
2131 pen = ResPool.GetPen( menuitem_gradient_first_color );
2132 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, thumb_pos.X, channel_startpoint.Y + 1 );
2133 pen = ResPool.GetPen( trackbar_second_gradient_color );
2134 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 2, thumb_pos.X, channel_startpoint.Y + 2 );
2135 pen = ResPool.GetPen( trackbar_third_gradient_color );
2136 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 3, thumb_pos.X, channel_startpoint.Y + 3 );
2139 pen = ResPool.GetPen( pressed_inner_border_dark_color );
2140 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 1, thumb_area.Right - 1, channel_startpoint.Y + 1 );
2141 dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), thumb_pos.X + 29, channel_startpoint.Y + 2, thumb_area.Right - thumb_pos.X - 30, 1 );
2143 pen = ResPool.GetPen( scrollbar_border_color );
2144 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y );
2145 dc.DrawLine( pen, thumb_area.Right, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y + 4 );
2146 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 4, thumb_area.Right, channel_startpoint.Y + 4 );
2150 thumb_pos.Y = channel_startpoint.Y - 4;
2153 pen = ResPool.GetPen( Color.White );
2154 dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
2155 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
2157 pen = ResPool.GetPen( menu_separator_color );
2158 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2159 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2163 new Point( thumb_pos.X + 2, thumb_pos.Y ),
2164 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
2165 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
2166 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
2167 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
2168 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
2169 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
2170 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
2171 new Point( thumb_pos.X + 2, thumb_pos.Y )
2174 dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
2176 Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
2177 Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
2179 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
2180 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
2184 pen = ResPool.GetPen( edge_top_inner_color );
2185 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
2186 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
2188 pen = ResPool.GetPen( edge_bottom_inner_color );
2189 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
2190 dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
2193 pen = ResPool.GetPen( pressed_inner_border_dark_color );
2194 dc.DrawLine( pen, thumb_pos.X + 11, thumb_pos.Y + 4, thumb_pos.X + 11, thumb_pos.Y + 8 );
2195 dc.DrawLine( pen, thumb_pos.X + 14, thumb_pos.Y + 4, thumb_pos.X + 14, thumb_pos.Y + 8 );
2196 dc.DrawLine( pen, thumb_pos.X + 17, thumb_pos.Y + 4, thumb_pos.X + 17, thumb_pos.Y + 8 );
2198 pen = ResPool.GetPen( Color.White );
2199 dc.DrawLine( pen, thumb_pos.X + 12, thumb_pos.Y + 4, thumb_pos.X + 12, thumb_pos.Y + 8 );
2200 dc.DrawLine( pen, thumb_pos.X + 15, thumb_pos.Y + 4, thumb_pos.X + 15, thumb_pos.Y + 8 );
2201 dc.DrawLine( pen, thumb_pos.X + 18, thumb_pos.Y + 4, thumb_pos.X + 18, thumb_pos.Y + 8 );
2203 pixel_len = thumb_area.Width - 11;
2204 pixels_betweenticks = pixel_len / ticks;
2207 thumb_area.Y = thumb_pos.Y;
2208 thumb_area.X = channel_startpoint.X;
2209 thumb_area.Height = thumb_pos.Height;
2210 Region outside = new Region( area );
2211 outside.Exclude( thumb_area );
2213 if ( outside.IsVisible( clip_rectangle ) ) {
2214 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2215 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2217 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2218 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2219 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
2220 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3 );
2222 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
2223 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2 );
2227 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2228 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2230 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2231 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2232 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
2233 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y );
2235 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
2236 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2244 public override void DrawTrackBar( Graphics dc, Rectangle clip_rectangle, TrackBar tb ) {
2247 float ticks = ( tb.Maximum - tb.Minimum ) / tb.tickFrequency; /* N of ticks draw*/
2249 Rectangle thumb_pos = tb.ThumbPos;
2250 Rectangle thumb_area = tb.ThumbArea;
2252 if ( tb.thumb_pressed ) {
2253 value_pos = tb.thumb_mouseclick;
2256 value_pos = tb.Value - tb.Minimum;
2257 mouse_value = false;
2260 area = tb.ClientRectangle;
2262 /* Control Background */
2263 if ( tb.BackColor == DefaultControlBackColor ) {
2264 dc.FillRectangle( ResPool.GetSolidBrush( ColorControl ), clip_rectangle );
2266 dc.FillRectangle( ResPool.GetSolidBrush( tb.BackColor ), clip_rectangle );
2269 if ( tb.Orientation == Orientation.Vertical ) {
2270 DrawTrackBar_Vertical( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2271 ticks, value_pos, mouse_value );
2274 DrawTrackBar_Horizontal( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2275 ticks, value_pos, mouse_value );
2278 // TODO: draw better focus rectangle
2280 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, area.Width - 1, 1 );
2281 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y + area.Height - 1, area.Width - 1, 1 );
2282 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, 1, area.Height - 1 );
2283 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X + area.Width - 1, area.Y, 1, area.Height - 1 );
2286 tb.ThumbPos = thumb_pos;
2287 tb.ThumbArea = thumb_area;
2289 #endregion // TrackBar
2292 // draws the ListViewItem of the given index
2293 protected override void DrawListViewItem( Graphics dc, ListView control, ListViewItem item ) {
2294 Rectangle rect_checkrect = item.CheckRectReal;
2295 Rectangle rect_iconrect = item.GetBounds( ItemBoundsPortion.Icon );
2296 Rectangle full_rect = item.GetBounds( ItemBoundsPortion.Entire );
2297 Rectangle text_rect = item.GetBounds( ItemBoundsPortion.Label );
2299 if ( control.CheckBoxes ) {
2300 if ( control.StateImageList == null ) {
2301 // Make sure we've got at least a line width of 1
2302 int check_wd = Math.Max( 3, rect_checkrect.Width / 6 );
2303 int scale = Math.Max( 1, rect_checkrect.Width / 12 );
2305 // set the checkbox background
2306 dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorWindow ),
2308 // define a rectangle inside the border area
2309 Rectangle rect = new Rectangle( rect_checkrect.X + 2,
2310 rect_checkrect.Y + 2,
2311 rect_checkrect.Width - 4,
2312 rect_checkrect.Height - 4 );
2313 Pen pen = new Pen( this.ColorWindowText, 2 );
2314 dc.DrawRectangle( pen, rect );
2316 // Need to draw a check-mark
2317 if ( item.Checked ) {
2319 // adjustments to get the check-mark at the right place
2320 rect.X ++; rect.Y ++;
2321 // following logic is taken from DrawFrameControl method
2322 for ( int i = 0; i < check_wd; i++ ) {
2323 dc.DrawLine( pen, rect.Left + check_wd / 2,
2324 rect.Top + check_wd + i,
2325 rect.Left + check_wd / 2 + 2 * scale,
2326 rect.Top + check_wd + 2 * scale + i );
2328 rect.Left + check_wd / 2 + 2 * scale,
2329 rect.Top + check_wd + 2 * scale + i,
2330 rect.Left + check_wd / 2 + 6 * scale,
2331 rect.Top + check_wd - 2 * scale + i );
2335 if ( item.Checked && control.StateImageList.Images.Count > 1 )
2336 control.StateImageList.Draw( dc,
2337 rect_checkrect.Location, 1 );
2338 else if ( ! item.Checked && control.StateImageList.Images.Count > 0 )
2339 control.StateImageList.Draw( dc,
2340 rect_checkrect.Location, 0 );
2344 // Item is drawn as a special case, as it is not just text
2345 if ( control.View == View.LargeIcon ) {
2346 if ( item.ImageIndex > -1 &&
2347 control.LargeImageList != null &&
2348 item.ImageIndex < control.LargeImageList.Images.Count ) {
2350 Point image_location = rect_iconrect.Location;
2351 Image image = control.LargeImageList.Images[ item.ImageIndex ];
2352 if ( image.Width < rect_iconrect.Width ) {
2353 int icon_rect_middle = rect_iconrect.Width / 2;
2354 int image_middle = image.Width / 2;
2355 image_location.X = image_location.X + icon_rect_middle - image_middle;
2357 control.LargeImageList.Draw( dc, image_location,
2361 if ( item.ImageIndex > -1 &&
2362 control.SmallImageList != null &&
2363 item.ImageIndex < control.SmallImageList.Images.Count )
2364 control.SmallImageList.Draw( dc, rect_iconrect.Location,
2368 // draw the item text
2369 // format for the item text
2370 StringFormat format = new StringFormat( );
2371 format.LineAlignment = StringAlignment.Center;
2372 if ( control.View == View.LargeIcon )
2373 format.Alignment = StringAlignment.Center;
2375 format.Alignment = StringAlignment.Near;
2377 if ( !control.LabelWrap )
2378 format.FormatFlags = StringFormatFlags.NoWrap;
2380 if ( item.Selected ) {
2381 if ( control.View == View.Details ) {
2382 if ( control.FullRowSelect ) {
2383 // fill the entire rect excluding the checkbox
2384 full_rect.Location = item.GetBounds (ItemBoundsPortion.Label).Location;
2385 dc.FillRectangle( this.ResPool.GetSolidBrush
2386 ( this.ColorHighlight ), full_rect );
2388 Size text_size = Size.Ceiling( dc.MeasureString( item.Text,
2390 text_rect.Width = text_size.Width;
2391 dc.FillRectangle( this.ResPool.GetSolidBrush
2392 ( this.ColorHighlight ), text_rect );
2395 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
2397 Point loc = text_rect.Location;
2398 loc.X += (text_rect.Width - text_size.Width) / 2;
2399 text_rect.Width = text_size.Width;*/
2400 dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorHighlight ),
2404 dc.FillRectangle( ResPool.GetSolidBrush( item.BackColor ), text_rect );
2406 if ( item.Text != null && item.Text.Length > 0 ) {
2408 if ( control.View != View.LargeIcon ) {
2409 if ( item.Selected )
2410 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2411 ( this.ColorHighlightText ), text_rect, format );
2413 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2414 ( item.ForeColor ), text_rect, format );
2416 // ListView CalcTextSize says wrapping is done for two lines only !?!
2417 // text is centered for the complete text_rect but it should be centered per available row/line
2419 // calculate how much lines we get out of text_rect and current item.Font
2420 int nr_lines = text_rect.Height / item.Font.Height;
2421 int rest = text_rect.Height % item.Font.Height;
2422 int line_height = item.Font.Height + ( rest > 1 ? 2 : 0 );
2424 Rectangle[] text_rects = new Rectangle[ nr_lines ];
2426 for ( int i = 0; i < nr_lines; i++ ) {
2427 text_rects[ i ].X = text_rect.X;
2428 text_rects[ i ].Y = text_rect.Y + i * line_height;
2429 text_rects[ i ].Width = text_rect.Width;
2430 text_rects[ i ].Height = line_height;
2433 string[] lines = new string[ nr_lines ];
2435 string text = item.Text;
2438 int current_pos = 0;
2439 for ( int k = 1; k <= text.Length; k++ ) {
2440 lines[ line_nr ] = text.Substring( current_pos, k - current_pos );
2442 // FIXME: Graphics.MeasureString returns wrong results if there is a
2443 // space char in the string
2444 SizeF sizef = dc.MeasureString( lines[ line_nr ], item.Font, text_rect.Width, format );
2446 if ( (int)sizef.Width > text_rect.Width - 3 ) {
2447 lines[ line_nr ] = lines[ line_nr ].Remove( lines[ line_nr ].Length - 1, 1 );
2451 if ( line_nr == nr_lines )
2457 foreach ( Rectangle t_rect in text_rects ) {
2458 if ( item.Selected )
2459 dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2460 ( this.ColorHighlightText ), t_rect, format );
2462 dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2463 ( item.ForeColor ), t_rect, format );
2469 if ( control.View == View.Details && control.Columns.Count > 0 ) {
2470 // draw subitems for details view
2471 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
2472 int count = ( control.Columns.Count < subItems.Count ?
2473 control.Columns.Count : subItems.Count );
2477 ListViewItem.ListViewSubItem subItem;
2478 Rectangle sub_item_rect = text_rect;
2480 // set the format for subitems
2481 format.FormatFlags = StringFormatFlags.NoWrap;
2482 format.Alignment = StringAlignment.Near;
2484 // 0th subitem is the item already drawn
2485 for ( int index = 1; index < count; index++ ) {
2486 subItem = subItems[ index ];
2487 col = control.Columns[ index ];
2488 sub_item_rect.X = col.Rect.Left;
2489 sub_item_rect.Width = col.Wd;
2490 sub_item_rect.X -= control.h_marker;
2492 SolidBrush sub_item_back_br = null;
2493 SolidBrush sub_item_fore_br = null;
2494 Font sub_item_font = null;
2496 if ( item.UseItemStyleForSubItems ) {
2497 sub_item_back_br = this.ResPool.GetSolidBrush
2499 sub_item_fore_br = this.ResPool.GetSolidBrush
2501 sub_item_font = item.Font;
2503 sub_item_back_br = this.ResPool.GetSolidBrush
2504 ( subItem.BackColor );
2505 sub_item_fore_br = this.ResPool.GetSolidBrush
2506 ( subItem.ForeColor );
2507 sub_item_font = subItem.Font;
2510 // In case of fullrowselect, background is filled
2511 // for the entire rect above
2512 if ( item.Selected && control.FullRowSelect ) {
2513 if ( subItem.Text != null && subItem.Text.Length > 0 )
2514 dc.DrawString( subItem.Text, sub_item_font,
2515 this.ResPool.GetSolidBrush
2516 ( this.ColorHighlightText ),
2517 sub_item_rect, format );
2519 dc.FillRectangle( sub_item_back_br, sub_item_rect );
2520 if ( subItem.Text != null && subItem.Text.Length > 0 )
2521 dc.DrawString( subItem.Text, sub_item_font,
2523 sub_item_rect, format );
2525 sub_item_rect.X += col.Wd;
2530 if ( item.Focused ) {
2531 if ( item.Selected )
2532 CPDrawFocusRectangle( dc, text_rect, ColorHighlightText, ColorHighlight );
2534 CPDrawFocusRectangle( dc, text_rect, control.ForeColor, control.BackColor );
2541 #region DateTimePicker
2542 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
2543 // if not showing the numeric updown control then render border
2544 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
2545 // draw the outer border
2546 Rectangle button_bounds = dtp.ClientRectangle;
2547 CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
2549 // deflate by the border width
2550 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
2551 button_bounds.Inflate (-2,-2);
2552 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
2553 Rectangle button_rect = new Rectangle(dtp.drop_down_arrow_rect.X, dtp.drop_down_arrow_rect.Y + 1,
2554 dtp.drop_down_arrow_rect.Width - 1, dtp.drop_down_arrow_rect.Height - 2);
2555 this.CPDrawComboButton (
2562 // render the date part
2563 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
2564 // fill the background
2565 Rectangle date_area_rect = new Rectangle( dtp.date_area_rect.X + 1, dtp.date_area_rect.Y + 1,
2566 dtp.date_area_rect.Width - 2, dtp.date_area_rect.Height - 2);
2567 dc.FillRectangle (ResPool.GetSolidBrush (ColorWindow), date_area_rect);
2569 // fill the currently highlighted area
2570 if (dtp.hilight_date_area != Rectangle.Empty) {
2571 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), dtp.hilight_date_area);
2574 // draw the text part
2575 // TODO: if date format is CUstom then we need to draw the dates as separate parts
2576 StringFormat text_format = new StringFormat();
2577 text_format.LineAlignment = StringAlignment.Center;
2578 text_format.Alignment = StringAlignment.Near;
2579 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
2580 text_format.Dispose ();
2583 #endregion // DateTimePicker
2585 #region MonthCalendar
2586 // draw the month calendar
2587 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2589 Rectangle client_rectangle = mc.ClientRectangle;
2590 Size month_size = mc.SingleMonthSize;
2591 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2592 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2593 Size date_cell_size = (Size)((object)mc.date_cell_size);
2595 // draw the singlecalendars
2598 // adjust for the position of the specific month
2599 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2603 y_offset += month_size.Height + calendar_spacing.Height;
2605 // now adjust for x position
2606 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2610 x_offset += month_size.Width + calendar_spacing.Width;
2617 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2618 if (month_rect.IntersectsWith (clip_rectangle)) {
2630 Rectangle bottom_rect = new Rectangle (
2632 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2633 client_rectangle.Width,
2634 date_cell_size.Height + 2);
2635 // draw the today date if it's set
2636 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2638 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
2640 int today_offset = 5;
2641 if (mc.ShowTodayCircle)
2643 Rectangle today_circle_rect = new Rectangle (
2644 client_rectangle.X + 5,
2645 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2646 date_cell_size.Width,
2647 date_cell_size.Height);
2648 DrawTodayCircle (dc, today_circle_rect);
2649 today_offset += date_cell_size.Width + 5;
2651 // draw today's date
2652 StringFormat text_format = new StringFormat();
2653 text_format.LineAlignment = StringAlignment.Center;
2654 text_format.Alignment = StringAlignment.Near;
2655 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2656 Rectangle today_rect = new Rectangle (
2657 today_offset + client_rectangle.X,
2658 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2659 Math.Max(client_rectangle.Width - today_offset, 0),
2660 date_cell_size.Height);
2661 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
2662 text_format.Dispose ();
2663 bold_font.Dispose ();
2667 // finally paint the borders of the calendars as required
2668 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2669 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2670 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
2671 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2672 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
2674 Rectangle rect = new Rectangle (
2675 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2677 calendar_spacing.Width,
2678 client_rectangle.Height);
2679 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2680 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2684 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2685 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2686 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
2687 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2688 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
2690 Rectangle rect = new Rectangle (
2692 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2693 client_rectangle.Width,
2694 calendar_spacing.Height);
2695 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2696 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2701 // draw the drop down border if need
2702 if (mc.owner != null) {
2703 Rectangle bounds = mc.ClientRectangle;
2704 if (clip_rectangle.Contains (mc.Location)) {
2705 // find out if top or left line to draw
2706 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2708 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2710 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2711 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2714 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2715 // find out if bottom or right line to draw
2716 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2717 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2719 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2720 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2726 // darws a single part of the month calendar (with one month)
2727 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2729 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2730 Size title_size = (Size)((object)mc.title_size);
2731 Size date_cell_size = (Size)((object)mc.date_cell_size);
2732 DateTime current_month = (DateTime)((object)mc.current_month);
2734 // set up some standard string formating variables
2735 StringFormat text_format = new StringFormat();
2736 text_format.LineAlignment = StringAlignment.Center;
2737 text_format.Alignment = StringAlignment.Center;
2740 // draw the title back ground
2741 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2742 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2743 if (title_rect.IntersectsWith (clip_rectangle)) {
2744 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2746 string title_text = this_month.ToString ("MMMM yyyy");
2747 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2749 // draw previous and next buttons if it's time
2750 if (row == 0 && col == 0)
2752 // draw previous button
2753 DrawMonthCalendarButton (
2759 (System.Drawing.Size)((object)mc.button_size),
2762 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2765 DrawMonthCalendarButton (
2771 (System.Drawing.Size)((object)mc.button_size),
2776 // set the week offset and draw week nums if needed
2777 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2778 Rectangle day_name_rect = new Rectangle(
2780 rectangle.Y + title_size.Height,
2781 (7 + col_offset) * date_cell_size.Width,
2782 date_cell_size.Height);
2783 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2784 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
2785 // draw the day names
2786 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2787 for (int i=0; i < 7; i++)
2789 int position = i - (int) first_day_of_week;
2792 position = 7 + position;
2795 Rectangle day_rect = new Rectangle(
2796 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2798 date_cell_size.Width,
2799 date_cell_size.Height);
2800 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2803 // draw the vertical divider
2804 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2806 ResPool.GetPen (mc.ForeColor),
2807 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2808 rectangle.Y + vert_divider_y,
2809 rectangle.Right - mc.divider_line_offset,
2810 rectangle.Y + vert_divider_y);
2814 // draw the actual date items in the grid (including the week numbers)
2815 Rectangle date_rect = new Rectangle (
2817 rectangle.Y + title_size.Height + date_cell_size.Height,
2818 date_cell_size.Width,
2819 date_cell_size.Height);
2820 int month_row_count = 0;
2821 bool draw_week_num_divider = false;
2822 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2823 for (int i=0; i < 6; i++)
2825 // establish if this row is in our clip_area
2826 Rectangle row_rect = new Rectangle (
2828 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2829 date_cell_size.Width * 7,
2830 date_cell_size.Height);
2831 if (mc.ShowWeekNumbers) {
2832 row_rect.Width += date_cell_size.Width;
2835 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2837 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
2839 // establish if this is a valid week to draw
2840 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2841 month_row_count = i;
2844 // draw the week number if required
2845 if (mc.ShowWeekNumbers && month_row_count == i) {
2846 if (!draw_week_num_divider) {
2847 draw_week_num_divider = draw_row;
2849 // get the week for this row
2850 int week = mc.GetWeekOfYear (current_date);
2856 ResPool.GetSolidBrush (mc.TitleBackColor),
2860 date_rect.Offset(date_cell_size.Width, 0);
2863 // only draw the days if we have to
2864 if(month_row_count == i) {
2865 for (int j=0; j < 7; j++)
2868 DrawMonthCalendarDate (
2879 current_date = current_date.AddDays(1);
2880 date_rect.Offset(date_cell_size.Width, 0);
2883 // shift the rectangle down one row
2884 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2885 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2889 // month_row_count is zero based, so add one
2892 // draw week numbers if required
2893 if (draw_week_num_divider) {
2896 ResPool.GetPen (mc.ForeColor),
2897 rectangle.X + date_cell_size.Width - 1,
2898 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2899 rectangle.X + date_cell_size.Width - 1,
2900 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2902 text_format.Dispose ();
2905 // draws the pervious or next button
2906 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2908 bool is_clicked = false;
2909 Rectangle button_rect;
2910 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2911 Point[] arrow_path = new Point[3];
2912 // prepare the button
2915 is_clicked = mc.is_previous_clicked;
2916 button_rect = new Rectangle (
2917 rectangle.X + 1 + x_offset,
2918 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2919 Math.Max(button_size.Width - 1, 0),
2920 Math.Max(button_size.Height - 1, 0));
2921 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2922 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2924 arrow_rect.Offset(1,1);
2926 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2927 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2928 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2932 is_clicked = mc.is_next_clicked;
2933 button_rect = new Rectangle (
2934 rectangle.Right - 1 - x_offset - button_size.Width,
2935 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2936 Math.Max(button_size.Width - 1, 0),
2937 Math.Max(button_size.Height - 1, 0));
2938 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2939 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2941 arrow_rect.Offset(1,1);
2943 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2944 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2945 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2948 // fill the background
2949 dc.FillRectangle (ResPool.GetSolidBrush(mc.TitleBackColor), button_rect);
2952 Color first_gradient_color = is_clicked ? pressed_gradient_first_color : gradient_first_color;
2953 Color second_gradient_color = is_clicked ? pressed_gradient_second_color : gradient_second_color;
2955 CL_Draw_Button (dc, button_rect, FlatStyle.Standard,
2956 false, true, is_clicked,
2957 first_gradient_color, second_gradient_color,
2961 SmoothingMode old_smooting_mode = dc.SmoothingMode;
2962 dc.SmoothingMode = SmoothingMode.AntiAlias;
2963 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2964 dc.SmoothingMode = old_smooting_mode;
2968 // draws one day in the calendar grid
2969 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2970 Color date_color = mc.ForeColor;
2971 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2973 // find out if we are the lead of the first calendar or the trail of the last calendar
2974 if (date.Year != month.Year || date.Month != month.Month) {
2975 DateTime check_date = month.AddMonths (-1);
2976 // check if it's the month before
2977 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2978 date_color = mc.TrailingForeColor;
2980 // check if it's the month after
2981 check_date = month.AddMonths (1);
2982 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2983 date_color = mc.TrailingForeColor;
2989 date_color = mc.ForeColor;
2993 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2994 // see if the date is in the start of selection
2995 date_color = mc.BackColor;
2996 // draw the left hand of the back ground
2997 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2998 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2999 } else if (date == mc.SelectionStart) {
3000 // see if the date is in the start of selection
3001 date_color = mc.BackColor;
3002 // draw the left hand of the back ground
3003 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
3004 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
3005 // fill the other side as a straight rect
3006 if (date < mc.SelectionEnd)
3008 // use rectangle instead of rectangle to go all the way to edge of rect
3009 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
3010 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
3011 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3013 } else if (date == mc.SelectionEnd) {
3014 // see if it is the end of selection
3015 date_color = mc.BackColor;
3016 // draw the left hand of the back ground
3017 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
3018 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
3019 // fill the other side as a straight rect
3020 if (date > mc.SelectionStart) {
3021 selection_rect.X = rectangle.X;
3022 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
3023 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3025 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
3026 // now see if it's in the middle
3027 date_color = mc.BackColor;
3028 // draw the left hand of the back ground
3029 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
3030 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3033 // set up some standard string formating variables
3034 StringFormat text_format = new StringFormat();
3035 text_format.LineAlignment = StringAlignment.Center;
3036 text_format.Alignment = StringAlignment.Center;
3039 // establish if it's a bolded font
3041 if (mc.IsBoldedDate (date)) {
3042 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
3047 // just draw the date now
3048 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
3050 // today circle if needed
3051 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
3052 DrawTodayCircle (dc, interior);
3055 // draw the selection grid
3056 if (mc.is_date_clicked && mc.clicked_date == date) {
3057 using (Pen pen = new Pen (Color.Black, 1) ) {
3058 pen.DashStyle = DashStyle.Dot;
3059 dc.DrawRectangle (pen, interior);
3062 text_format.Dispose ();
3065 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
3066 Color circle_color = Color.FromArgb (248, 0, 0);
3067 // draw the left hand of the circle
3068 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
3069 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
3070 Point [] curve_points = new Point [3];
3071 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
3072 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
3073 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
3075 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
3076 dc.SmoothingMode = SmoothingMode.AntiAlias;
3078 using (Pen pen = new Pen (circle_color, 2)) {
3079 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
3080 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
3081 dc.DrawCurve (pen, curve_points);
3082 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
3085 dc.SmoothingMode = old_smoothing_mode;
3087 #endregion // MonthCalendar
3089 public override void CPDrawBorder3D( Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides ) {
3090 CPDrawBorder3D( graphics, rectangle, style, sides, ColorControl );
3093 public override void CPDrawBorder3D( Graphics dc, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color ) {
3094 // currently we don't take care of Border3DStyle or Border3DSide
3096 Pen tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
3097 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 2, rectangle.Y + 1 );
3098 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 2 );
3099 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 3 );
3100 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Bottom - 3, rectangle.X + 2, rectangle.Bottom - 2 );
3102 tmp_pen = ResPool.GetPen( theme_back_color );
3103 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 2, rectangle.Right - 3, rectangle.Y + 2 );
3104 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 3, rectangle.X + 2, rectangle.Bottom - 3 );
3106 tmp_pen = ResPool.GetPen( Color.White );
3107 dc.DrawLine( tmp_pen, rectangle.X + 3, rectangle.Bottom - 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3108 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3111 new Point( rectangle.X + 3, rectangle.Y + 1 ),
3112 new Point( rectangle.Right - 4, rectangle.Y + 1 ),
3113 new Point( rectangle.Right - 2, rectangle.Y + 3 ),
3114 new Point( rectangle.Right - 2, rectangle.Bottom - 4 ),
3115 new Point( rectangle.Right - 4, rectangle.Bottom - 2 ),
3116 new Point( rectangle.X + 3, rectangle.Bottom - 2 ),
3117 new Point( rectangle.X + 1, rectangle.Bottom - 4 ),
3118 new Point( rectangle.X + 1, rectangle.Y + 3 ),
3119 new Point( rectangle.X + 3, rectangle.Y + 1 )
3122 dc.DrawLines( ResPool.GetPen( combobox_border_color ), points );
3124 Point[] points_top_outer = {
3125 new Point( rectangle.X + 1, rectangle.Y + 1 ),
3126 new Point( rectangle.X + 2, rectangle.Y ),
3127 new Point( rectangle.Right - 3, rectangle.Y ),
3128 new Point( rectangle.Right - 2 , rectangle.Y + 1 )
3131 Point[] points_bottom_outer = {
3132 new Point( rectangle.X + 1, rectangle.Bottom - 2 ),
3133 new Point( rectangle.X + 2, rectangle.Bottom - 1 ),
3134 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
3135 new Point( rectangle.Right - 2, rectangle.Bottom - 2 )
3139 tmp_pen = ResPool.GetPen( button_outer_border_dark_color );
3140 dc.DrawLines( tmp_pen, points_top_outer );
3141 tmp_pen = ResPool.GetPen( button_outer_border_light_color );
3142 dc.DrawLines( tmp_pen, points_bottom_outer );
3144 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 3 ), button_outer_border_dark_color, button_outer_border_light_color ) ) {
3145 using (Pen lgbrpen = new Pen (lgbr)) {
3146 dc.DrawLine (lgbrpen, rectangle.X, rectangle.Y + 2, rectangle.X, rectangle.Bottom - 3 );
3147 dc.DrawLine (lgbrpen, rectangle.Right - 1, rectangle.Y + 2, rectangle.Right - 1, rectangle.Bottom - 3 );
3151 tmp_pen = ResPool.GetPen( button_edge_top_outer_color );
3152 dc.DrawLine( tmp_pen, rectangle.X, rectangle.Y + 1, rectangle.X + 1, rectangle.Y );
3153 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
3155 tmp_pen = ResPool.GetPen( button_edge_bottom_outer_color );
3156 dc.DrawLine( tmp_pen, rectangle.X, rectangle.Bottom - 2, rectangle.X + 1, rectangle.Bottom - 1 );
3157 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 1 );
3160 public override void CPDrawBorder( Graphics dc, Rectangle bounds, Color leftColor, int leftWidth,
3161 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3162 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3163 int bottomWidth, ButtonBorderStyle bottomStyle ) {
3164 dc.DrawRectangle( ResPool.GetPen( combobox_border_color ), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1 );
3167 // TODO: inactive...
3168 public override void CPDrawCheckBox( Graphics dc, Rectangle rectangle, ButtonState state ) {
3170 bool pushed = ( state & ButtonState.Pushed ) != 0;
3177 dc.FillRectangle( ResPool.GetSolidBrush( pushed ? checkbox_pressed_backcolor : Color.White ), rectangle );
3180 dc.DrawRectangle( ResPool.GetPen( scrollbar_border_color ), rectangle );
3182 Color inner_border_color = pushed ? checkbox_pressed_inner_boder_color : checkbox_inner_boder_color;
3184 Pen tmp_pen = ResPool.GetPen( inner_border_color );
3185 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 1, rectangle.Y + 1 );
3186 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 1, rectangle.Bottom - 1 );
3188 /* Make sure we've got at least a line width of 1 */
3189 lineWidth = Math.Max( 3, rectangle.Width / 6 );
3190 scale = Math.Max( 1, rectangle.Width / 12 );
3192 // define a rectangle inside the border area
3193 rect = new Rectangle( rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
3194 if ( ( state & ButtonState.Inactive ) != 0 ) {
3195 tmp_pen = SystemPens.ControlDark;
3197 tmp_pen = SystemPens.ControlText;
3200 if ( ( state & ButtonState.Checked ) != 0 ) {
3201 /* Need to draw a check-mark */
3202 for ( int i=0; i < lineWidth; i++ ) {
3203 dc.DrawLine( tmp_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * scale, rect.Top + lineWidth + 2 * scale + i );
3204 dc.DrawLine( tmp_pen, rect.Left + lineWidth / 2 + 2 * scale, rect.Top + lineWidth + 2 * scale + i, rect.Left + lineWidth / 2 + 6 * scale, rect.Top + lineWidth - 2 * scale + i );
3209 public override void CPDrawStringDisabled( Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
3210 StringFormat format ) {
3212 graphics.DrawString( s, font, ResPool.GetSolidBrush( ColorGrayText), layoutRectangle, format );
3216 public override void CPDrawButton (Graphics dc, Rectangle buttonRectangle, ButtonState state)
3218 bool is_enabled = true;
3219 FlatStyle flat_style = FlatStyle.Standard;
3220 bool is_pressed = false;
3222 if ((state & ButtonState.Pushed) != 0) {
3226 // if ((state & ButtonState.Checked)!=0) {
3227 // dfcs |= DrawFrameControlStates.Checked;
3230 if ((state & ButtonState.Flat) != 0) {
3231 flat_style = FlatStyle.Flat;
3234 if ((state & ButtonState.Inactive) != 0) {
3238 Color first_gradient_color = gradient_first_color;
3239 Color second_gradient_color = gradient_second_color;
3242 first_gradient_color = pressed_gradient_first_color;
3243 second_gradient_color = pressed_gradient_second_color;
3246 CL_Draw_Button (dc, buttonRectangle, flat_style,
3247 false, is_enabled, is_pressed,
3248 first_gradient_color, second_gradient_color,
3252 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
3254 bool is_checked = false;
3255 bool is_inactive = false;
3257 if ((state & ButtonState.Checked) != 0) {
3261 if ((state & ButtonState.Inactive) != 0) {
3265 SmoothingMode old_smooting_mode = dc.SmoothingMode;
3266 dc.SmoothingMode = SmoothingMode.AntiAlias;
3268 dc.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3270 dc.DrawArc (ResPool.GetPen (radio_button_border_circle_color), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3272 CL_Draw_RadioButton_Dot (dc, rectangle, is_checked, is_inactive);
3274 dc.SmoothingMode = old_smooting_mode;
3277 private void CL_Draw_RadioButton_Dot (Graphics dc, Rectangle rectangle, bool is_checked, bool is_inactive)
3280 int lineWidth = Math.Max (1, Math.Min (rectangle.Width, rectangle.Height) / 4);
3282 SolidBrush buttonBrush;
3285 buttonBrush = SystemBrushes.ControlDark as SolidBrush;
3287 buttonBrush = ResPool.GetSolidBrush (radio_button_dot_color);
3289 dc.FillPie (buttonBrush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
3291 // the white shiny dott
3292 buttonBrush = ResPool.GetSolidBrush (ColorWindow);
3293 dc.FillPie (buttonBrush, rectangle.X + lineWidth + lineWidth / 2, rectangle.Y + lineWidth + lineWidth / 2, (rectangle.Width - lineWidth * 2) / 3, (rectangle.Height - lineWidth * 2) / 3, 0, 359);
3298 public override void DrawToolTip (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
3300 dc.FillRectangle(ResPool.GetSolidBrush (ColorInfo), control.ClientRectangle);
3301 dc.DrawRectangle(ResPool.GetPen (info_border_color), 0, 0, control.Width-1, control.Height-1);
3302 dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.ClientRectangle, control.string_format);
3304 #endregion // ToolTip
3306 #region BalloonWindow
3308 NotifyIcon.BalloonWindow balloon_window;
3310 public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
3312 Control control = Control.FromHandle(handle);
3314 if (control == null)
3317 if (balloon_window != null) {
3318 balloon_window.Close ();
3319 balloon_window.Dispose ();
3322 balloon_window = new NotifyIcon.BalloonWindow (handle);
3323 balloon_window.Title = title;
3324 balloon_window.Text = text;
3325 balloon_window.Icon = icon;
3326 balloon_window.Timeout = timeout;
3327 balloon_window.Show ();
3330 private const int balloon_iconsize = 48;
3331 private const int balloon_bordersize = 8;
3333 public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control)
3335 Brush solidbrush = ResPool.GetSolidBrush(this.ColorInfoText);
3336 Rectangle rect = control.ClientRectangle;
3337 int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
3339 // Rectangle borders and background.
3340 dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
3341 dc.FillRectangle (ResPool.GetSolidBrush (info_second_color), new Rectangle (rect.X, rect.Y, (balloon_iconsize/2)+balloon_bordersize, rect.Height));
3342 dc.DrawRectangle (ResPool.GetPen (info_border_color), 0, 0, rect.Width - 1, rect.Height - 1);
3346 switch (control.Icon) {
3347 case ToolTipIcon.Info: {
3348 image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
3352 case ToolTipIcon.Warning: {
3353 image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
3357 case ToolTipIcon.Error: {
3358 image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
3368 if (control.Icon != ToolTipIcon.None)
3369 dc.DrawImage (image, new Rectangle (balloon_bordersize, (2*balloon_bordersize)+7, iconsize, iconsize));
3372 Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + (balloon_iconsize/2) + balloon_bordersize,
3373 rect.Y + balloon_bordersize,
3374 rect.Width - ((3 * balloon_bordersize) + (balloon_iconsize/2)),
3375 rect.Height - (2 * balloon_bordersize));
3377 Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
3378 dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
3381 Rectangle textrect = new Rectangle (rect.X + (2 * balloon_bordersize) + balloon_iconsize,
3382 rect.Y + balloon_bordersize,
3383 rect.Width - ((2 * balloon_bordersize) + balloon_iconsize),
3384 rect.Height - (2 * balloon_bordersize));
3386 StringFormat textformat = control.Format;
3387 textformat.LineAlignment = StringAlignment.Far;
3388 dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
3391 public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
3393 Rectangle deskrect = Screen.GetWorkingArea (control);
3394 SizeF maxsize = new SizeF (250, 200);
3396 SizeF titlesize = control.DeviceContext.MeasureString (control.Title, control.Font, maxsize, control.Format);
3397 SizeF textsize = control.DeviceContext.MeasureString (control.Text, control.Font, maxsize, control.Format);
3399 if (textsize.Height < balloon_iconsize)
3400 textsize.Height = balloon_iconsize;
3402 Rectangle rect = new Rectangle ();
3403 rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
3404 rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (3 * balloon_bordersize) + balloon_iconsize;
3405 rect.X = deskrect.Width - rect.Width - 2;
3406 rect.Y = deskrect.Height - rect.Height - 2;
3411 #endregion // BalloonWindow