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=nice
31 using System.Drawing.Drawing2D;
32 using System.Drawing.Imaging;
33 using System.Drawing.Text;
35 namespace System.Windows.Forms
37 internal class ThemeNice : ThemeWin32Classic
39 public override Version Version
42 return new Version( 0, 0, 0, 3 );
46 static readonly Color NormalColor = Color.LightGray;
47 static readonly Color MouseOverColor = Color.DarkGray;
48 static readonly Color PressedColor = Color.Gray;
49 static readonly Color FocusColor = Color.FromArgb( System.Convert.ToInt32( "0xff00c0ff", 16 ) );
50 static readonly Color FocusColorLight = Color.FromArgb(250, 253, 255);
51 static readonly Color LightColor = Color.LightGray;
52 static readonly Color BorderColor = MouseOverColor;
53 static readonly Color NiceBackColor = Color.FromArgb( System.Convert.ToInt32( "0xffefebe7", 16 ) );
55 static Bitmap size_grip_bmp = CreateSizegripDot();
57 static Blend NormalBlend;
58 static Blend FlatBlend;
60 int platform = (int) Environment.OSVersion.Platform;
62 #region Principal Theme Methods
65 ColorControl = NiceBackColor;
67 FlatBlend = new Blend ();
68 FlatBlend.Factors = new float []{0.0f, 0.992f, 1.0f};
69 FlatBlend.Positions = new float []{0.0f, 0.68f, 1.0f};
71 NormalBlend = new Blend ();
72 NormalBlend.Factors = new float []{0.0f, 0.008f, 1.0f};
73 NormalBlend.Positions = new float []{0.0f, 0.32f, 1.0f};
76 public override Color DefaultControlBackColor
78 get { return NiceBackColor; }
81 public override Color DefaultWindowBackColor
83 get { return NiceBackColor; }
86 public override Color ColorControl {
87 get { return NiceBackColor;}
90 static Bitmap CreateSizegripDot()
92 Bitmap bmp = new Bitmap( 4, 4 );
93 using ( Graphics dc = Graphics.FromImage( bmp ) )
95 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
96 dc.SmoothingMode = SmoothingMode.AntiAlias;
98 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 4, 4 ), PressedColor, Color.White ) ) {
99 Blend bl = new Blend ();
100 bl.Factors = new float []{0.0f, 0.992f, 1.0f};
101 bl.Positions = new float []{0.0f, 0.68f, 1.0f};
103 dc.FillEllipse( lgbr, new Rectangle( 0, 0, 4, 4 ) );
106 dc.SmoothingMode = old_smoothing_mode;
112 public override Image Images(UIIcon index, int size) {
114 case UIIcon.PlacesRecentDocuments:
115 if ((platform == 4) || (platform == 128))
116 return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
118 return base.Images (UIIcon.PlacesRecentDocuments, size);
119 case UIIcon.PlacesDesktop:
120 if ((platform == 4) || (platform == 128))
121 return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
123 return base.Images (UIIcon.PlacesDesktop, size);
124 case UIIcon.PlacesPersonal:
125 if ((platform == 4) || (platform == 128))
126 return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
128 return base.Images (UIIcon.PlacesPersonal, size);
129 case UIIcon.PlacesMyComputer:
130 if ((platform == 4) || (platform == 128))
131 return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
133 return base.Images (UIIcon.PlacesMyComputer, size);
134 case UIIcon.PlacesMyNetwork:
135 if ((platform == 4) || (platform == 128))
136 return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
138 return base.Images (UIIcon.PlacesMyNetwork, size);
140 // Icons for message boxes
141 case UIIcon.MessageBoxError: return base.Images (UIIcon.MessageBoxError, size);
142 case UIIcon.MessageBoxInfo: return base.Images (UIIcon.MessageBoxInfo, size);
143 case UIIcon.MessageBoxQuestion: return base.Images (UIIcon.MessageBoxQuestion, size);
144 case UIIcon.MessageBoxWarning: return base.Images (UIIcon.MessageBoxWarning, size);
147 case UIIcon.NormalFolder:
148 if ((platform == 4) || (platform == 128))
149 return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
151 return base.Images (UIIcon.NormalFolder, size);
154 throw new ArgumentException("Invalid Icon type requested", "index");
158 #endregion // Internal Methods
161 protected override void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
163 bool check_or_radio = false;
164 bool check_or_radio_checked = false;
166 Color use_color = NormalColor;
167 Color first_color = Color.White;
169 dc.FillRectangle (ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
171 if (button is CheckBox) {
172 check_or_radio = true;
173 check_or_radio_checked = ((CheckBox)button).Checked;
174 } else if (button is RadioButton) {
175 check_or_radio = true;
176 check_or_radio_checked = ((RadioButton)button).Checked;
179 if (button.has_focus && !check_or_radio && button.is_enabled)
180 first_color = FocusColorLight;
182 if (button.is_enabled) {
183 if (button.FlatStyle == FlatStyle.Popup) {
184 if (!button.is_pressed && button.is_entered && !check_or_radio_checked)
185 use_color = MouseOverColor;
186 } else if (button.FlatStyle == FlatStyle.Flat) {
187 if (button.is_entered && !button.is_pressed && !check_or_radio_checked)
188 use_color = MouseOverColor;
190 if (!button.is_pressed && button.is_entered && !check_or_radio_checked)
191 use_color = MouseOverColor;
195 Rectangle buttonRectangle;
197 int height = button.ClientSize.Height;
199 // set up the button rectangle
200 buttonRectangle = button.ClientRectangle;
202 // Fill button with a nice linear gradient brush
203 Rectangle lgbRectangle = Rectangle.Inflate (buttonRectangle, -1, -1);
205 if (button.FlatStyle != FlatStyle.Popup || ((button.FlatStyle == FlatStyle.Popup) && button.is_entered)) {
206 LinearGradientBrush lgbr;
207 if (!button.is_pressed && !check_or_radio_checked) {
208 if (button.FlatStyle == FlatStyle.Flat) {
209 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), use_color, first_color);
210 lgbr.Blend = FlatBlend;
212 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), first_color, use_color);
213 lgbr.Blend = NormalBlend;
216 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), PressedColor, MouseOverColor);
218 dc.FillRectangle (lgbr, lgbRectangle);
221 if (button.has_focus && !check_or_radio)
224 Internal_DrawButton(dc, buttonRectangle, BorderColor);
228 private void Internal_DrawButton(Graphics dc, Rectangle area, Color border_color)
230 Point[] points = new Point [] {
231 new Point (area.X + 1, area.Y),
232 new Point (area.Right - 2, area.Y),
233 new Point (area.Right - 2, area.Y + 1),
234 new Point (area.Right - 1, area.Y + 1),
235 new Point (area.Right - 1, area.Bottom - 2),
236 new Point (area.Right - 2, area.Bottom - 2),
237 new Point (area.Right - 2, area.Bottom - 1),
238 new Point (area.X + 1, area.Bottom - 1),
239 new Point (area.X + 1, area.Bottom - 2),
240 new Point (area.X, area.Bottom - 2),
241 new Point (area.X, area.Y + 1),
242 new Point (area.X + 1, area.Y + 1),
243 new Point (area.X + 1, area.Y)
246 Pen pen = ResPool.GetPen (border_color);
247 dc.DrawPolygon (pen, points);
250 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc )
252 if ((button is RadioButton) || (button is CheckBox))
255 Internal_DrawButton(dc, button.ClientRectangle, FocusColor);
258 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc )
260 if ( !( button is CheckBox ) && !(button is RadioButton ) )
262 base.ButtonBase_DrawText( button, dc );
265 #endregion // ButtonBase
268 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
270 if (menu.Height == 0)
271 CalcMenuBarSize (dc, menu, rect.Width);
273 bool keynav = (menu as MainMenu).tracker.Navigating;
274 HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
275 string_format_menu_menubar_text.HotkeyPrefix = hp;
276 string_format_menu_text.HotkeyPrefix = hp;
278 rect.Height = menu.Height;
279 dc.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rect);
281 for (int i = 0; i < menu.MenuItems.Count; i++) {
282 MenuItem item = menu.MenuItems [i];
283 Rectangle item_rect = item.bounds;
284 item_rect.X += rect.X;
285 item_rect.Y += rect.Y;
286 item.MenuHeight = menu.Height;
287 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
291 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
293 StringFormat string_format;
294 Rectangle rect_text = e.Bounds;
296 if (item.Visible == false)
300 string_format = string_format_menu_menubar_text;
302 string_format = string_format_menu_text;
304 if (item.Separator == true) {
305 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
306 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
308 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
309 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
315 rect_text.X += MenuCheckSize.Width;
317 if (item.BarBreak) { /* Draw vertical break bar*/
318 Rectangle rect = e.Bounds;
321 rect.Height = item.MenuHeight - 6;
323 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
324 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
326 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
327 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
330 Color color_text = ColorMenuText;
331 Color color_back = NiceBackColor;
333 /* Draw background */
334 Rectangle rect_back = e.Bounds;
338 if (((e.State & DrawItemState.Selected) == DrawItemState.Selected) || ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight)) {
339 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (rect_back.X, rect_back.Y), new Point (rect_back.Right, rect_back.Y), Color.White, NormalColor))//NormalColor, Color.White ) )
340 e.Graphics.FillRectangle (lgbr, rect_back);
342 e.Graphics.DrawRectangle (ResPool.GetPen (BorderColor), rect_back.X, rect_back.Y, rect_back.Width, rect_back.Height - 1);
344 e.Graphics.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rect_back);
348 e.Graphics.DrawString (item.Text, e.Font,
349 ResPool.GetSolidBrush (color_text),
350 rect_text, string_format);
352 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
353 string str = item.GetShortCutText ();
354 Rectangle rect = rect_text;
356 rect.Width -= item.XTab;
358 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush (color_text),
359 rect, string_format_menu_shortcut);
363 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
364 Color.Black, rect_text, string_format);
368 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
370 int cx = MenuCheckSize.Width;
371 int cy = MenuCheckSize.Height;
372 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
375 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
376 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
378 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
379 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
385 /* Draw checked or radio */
386 if (item.MenuBar == false && item.Checked) {
388 Rectangle area = e.Bounds;
389 int cx = MenuCheckSize.Width;
390 int cy = MenuCheckSize.Height;
391 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
393 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
399 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
402 dc.FillRectangle (ResPool.GetSolidBrush
403 (NiceBackColor), cliparea);
405 /* Draw menu borders */
406 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
407 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
409 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
410 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
412 dc.DrawLine (ResPool.GetPen (ColorControlDark),
413 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
415 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
416 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
418 dc.DrawLine (ResPool.GetPen (ColorControlDark),
419 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
421 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
422 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
424 for (int i = 0; i < menu.MenuItems.Count; i++)
425 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
426 MenuItem item = menu.MenuItems [i];
427 item.MenuHeight = menu.Height;
428 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
429 item.bounds, i, item.Status));
435 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl )
437 Rectangle client_area = ctrl.client_area;
439 Rectangle bar = ctrl.client_area;
441 barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
443 bar.Width = barpos_pixels;
446 // Draw bar background
447 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( client_area.Left, client_area.Top ), new Point( client_area.Left, client_area.Bottom ), LightColor, Color.White ) )
449 lgbr.Blend = FlatBlend;
450 dc.FillRectangle( lgbr, client_area );
454 using ( LinearGradientBrush lgbr = new LinearGradientBrush( bar.Location, new Point( bar.X, bar.Bottom ), Color.White, PressedColor ) )
456 lgbr.Blend = NormalBlend;
457 dc.FillRectangle( lgbr, bar );
461 dc.DrawRectangle( ResPool.GetPen( BorderColor ), ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Width - 1, ctrl.ClientRectangle.Height - 1 );
462 dc.DrawRectangle( ResPool.GetPen( LightColor ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
464 #endregion // ProgressBar
467 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
469 if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
470 DrawScrollBarThumb( dc, thumb_pos, bar );
473 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
475 Rectangle r = new Rectangle( 0,
476 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
477 Rectangle intersect = Rectangle.Intersect( clip, r );
479 if ( intersect != Rectangle.Empty )
481 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
483 lgbr.Blend = FlatBlend;
484 dc.FillRectangle( lgbr, intersect );
489 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
491 Rectangle r = new Rectangle( 0, scrollbutton_height,
492 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
493 Rectangle intersect = Rectangle.Intersect( clip, r );
495 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
497 lgbr.Blend = FlatBlend;
499 if ( intersect != Rectangle.Empty )
500 dc.FillRectangle( lgbr, intersect );
503 r.Y = thumb_pos.Y + thumb_pos.Height;
504 r.Width = bar.ClientRectangle.Width;
505 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
507 intersect = Rectangle.Intersect( clip, r );
508 if ( intersect != Rectangle.Empty )
509 dc.FillRectangle( lgbr, intersect );
513 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
515 Rectangle r = new Rectangle( 0, scrollbutton_height,
516 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
517 Rectangle intersect = Rectangle.Intersect( clip, r );
519 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
521 lgbr.Blend = FlatBlend;
523 if ( intersect != Rectangle.Empty )
524 dc.FillRectangle( lgbr, intersect );
527 r.Y = thumb_pos.Y + thumb_pos.Height;
528 r.Width = bar.ClientRectangle.Width;
529 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
531 intersect = Rectangle.Intersect( clip, r );
532 if ( intersect != Rectangle.Empty )
533 dc.FillRectangle( lgbr, intersect );
537 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
539 Rectangle r = new Rectangle( scrollbutton_width,
540 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
541 Rectangle intersect = Rectangle.Intersect( clip, r );
543 if ( intersect != Rectangle.Empty )
545 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
547 lgbr.Blend = FlatBlend;
549 dc.FillRectangle( lgbr, intersect );
554 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
556 Rectangle r = new Rectangle( scrollbutton_width, 0,
557 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
558 Rectangle intersect = Rectangle.Intersect( clip, r );
560 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
562 lgbr.Blend = FlatBlend;
564 if ( intersect != Rectangle.Empty )
565 dc.FillRectangle( lgbr, intersect );
567 r.X = thumb_pos.X + thumb_pos.Width;
569 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
570 r.Height = bar.ClientRectangle.Height;
572 intersect = Rectangle.Intersect( clip, r );
573 if ( intersect != Rectangle.Empty )
574 dc.FillRectangle( lgbr, intersect );
578 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
580 Rectangle r = new Rectangle( scrollbutton_width, 0,
581 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
582 Rectangle intersect = Rectangle.Intersect( clip, r );
584 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
586 lgbr.Blend = FlatBlend;
588 if ( intersect != Rectangle.Empty )
589 dc.FillRectangle( lgbr, intersect );
591 r.X = thumb_pos.X + thumb_pos.Width;
593 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
594 r.Height = bar.ClientRectangle.Height;
596 intersect = Rectangle.Intersect( clip, r );
597 if ( intersect != Rectangle.Empty )
598 dc.FillRectangle( lgbr, intersect );
601 #endregion // ScrollBar
604 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
605 Brush br_forecolor, StatusBarPanel panel )
607 int border_size = 3; // this is actually const, even if the border style is none
609 area.Height -= border_size;
610 if ( panel.BorderStyle != StatusBarPanelBorderStyle.None )
612 Internal_DrawButton( dc, area, BorderColor );
615 if ( panel.Style == StatusBarPanelStyle.OwnerDraw )
617 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
618 dc, panel.Parent.Font, area, index, DrawItemState.Default,
619 panel, panel.Parent.ForeColor, panel.Parent.BackColor );
620 panel.Parent.OnDrawItemInternal( e );
624 int left = area.Left;
625 if ( panel.Icon != null )
628 dc.DrawIcon( panel.Icon, left, area.Top );
629 left += panel.Icon.Width;
632 if ( panel.Text == String.Empty )
635 string text = panel.Text;
636 StringFormat string_format = new StringFormat( );
637 string_format.Trimming = StringTrimming.Character;
638 string_format.FormatFlags = StringFormatFlags.NoWrap;
640 if ( text[ 0 ] == '\t' )
642 string_format.Alignment = StringAlignment.Center;
643 text = text.Substring( 1 );
644 if ( text[ 0 ] == '\t' )
646 string_format.Alignment = StringAlignment.Far;
647 text = text.Substring( 1 );
651 int x = left + border_size;
652 int y = border_size + 2;
653 Rectangle r = new Rectangle( x, y,
654 area.Right - x - border_size,
655 area.Bottom - y - border_size );
657 dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
659 #endregion // StatusBar
661 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab )
663 // Do we need to fill the back color? It can't be changed...
664 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
665 Rectangle panel_rect = GetTabPanelRectExt( tab );
667 if ( tab.Appearance == TabAppearance.Normal )
669 CPDrawBorder( dc, panel_rect, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid,
670 BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid );
673 if ( tab.Alignment == TabAlignment.Top )
675 for ( int r = tab.TabPages.Count; r > 0; r-- )
677 for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
679 if ( i == tab.SelectedIndex )
681 if ( r != tab.TabPages[ i ].Row )
683 Rectangle rect = tab.GetTabRect( i );
684 if ( !rect.IntersectsWith( area ) )
686 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
692 for ( int r = 0; r < tab.TabPages.Count; r++ )
694 for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
696 if ( i == tab.SelectedIndex )
698 if ( r != tab.TabPages[ i ].Row )
700 Rectangle rect = tab.GetTabRect( i );
701 if ( !rect.IntersectsWith( area ) )
703 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
708 if ( tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos )
710 Rectangle rect = tab.GetTabRect( tab.SelectedIndex );
711 if ( rect.IntersectsWith( area ) )
712 DrawTab( dc, tab.TabPages[ tab.SelectedIndex ], tab, rect, true );
715 if ( tab.ShowSlider )
717 Rectangle right = GetTabControlRightScrollRect( tab );
718 Rectangle left = GetTabControlLeftScrollRect( tab );
719 CPDrawScrollButton( dc, right, ScrollButton.Right, tab.RightSliderState );
720 CPDrawScrollButton( dc, left, ScrollButton.Left, tab.LeftSliderState );
724 protected override int DrawTab( Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected )
726 int FlatButtonSpacing = 8;
728 int res = bounds.Width;
730 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
732 if ( tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons )
734 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
737 if ( tab.Appearance == TabAppearance.FlatButtons )
739 int width = bounds.Width;
740 bounds.Width += ( FlatButtonSpacing - 2 );
742 CPDrawBorder3D( dc, bounds, Border3DStyle.Etched, Border3DSide.Right );
743 bounds.Width = width;
748 CPDrawBorder3D( dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
750 else if ( tab.Appearance != TabAppearance.FlatButtons )
752 CPDrawBorder3D( dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
755 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4 );
758 StringFormat string_format = new StringFormat( );
759 string_format.Alignment = StringAlignment.Center;
760 string_format.LineAlignment = StringAlignment.Center;
761 string_format.FormatFlags = StringFormatFlags.NoWrap;
764 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
769 Pen border_pen = ResPool.GetPen( BorderColor );
771 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
773 switch ( tab.Alignment )
775 case TabAlignment.Top:
779 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
781 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Left + 2, bounds.Bottom ), Color.White, LightColor ) )
783 lgbr.Blend = NormalBlend;
784 dc.FillRectangle( lgbr, interior );
788 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3 );
789 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top );
790 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top );
791 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
792 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom );
796 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Top, bounds.Right - 1, bounds.Top );
797 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 1, bounds.Right , bounds.Top + 1 );
798 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 2, bounds.Right , bounds.Top + 2 );
801 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
803 if ( page.Text != String.Empty )
805 StringFormat string_format = new StringFormat( );
806 string_format.Alignment = StringAlignment.Center;
807 string_format.LineAlignment = StringAlignment.Center;
808 string_format.FormatFlags = StringFormatFlags.NoWrap;
810 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
816 case TabAlignment.Bottom:
820 interior = new Rectangle( bounds.Left + 3, bounds.Top, bounds.Width - 3, bounds.Height );
822 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 3, bounds.Top ), new Point( bounds.Left + 3, bounds.Bottom ), Color.White, LightColor ) )
824 lgbr.Blend = NormalBlend;
825 dc.FillRectangle( lgbr, interior );
829 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3 );
830 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
831 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom );
832 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3 );
833 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top );
837 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Bottom, bounds.Right - 1, bounds.Bottom );
838 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 1, bounds.Right , bounds.Bottom - 1 );
839 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 2, bounds.Right , bounds.Bottom - 2 );
842 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
844 if ( page.Text != String.Empty )
846 StringFormat string_format = new StringFormat( );
847 string_format.Alignment = StringAlignment.Center;
848 string_format.LineAlignment = StringAlignment.Center;
849 string_format.FormatFlags = StringFormatFlags.NoWrap;
851 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
857 case TabAlignment.Left:
861 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
863 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Right, bounds.Top + 2 ), LightColor, Color.White ) )
865 lgbr.Blend = FlatBlend;
866 dc.FillRectangle( lgbr, interior );
870 dc.DrawLine( border_pen, bounds.Right, bounds.Top, bounds.Left + 3, bounds.Top );
871 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Left, bounds.Top + 3 );
872 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left, bounds.Bottom - 3 );
873 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
874 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right, bounds.Bottom );
878 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left , bounds.Top + 1, bounds.Left , bounds.Bottom - 1 );
879 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 1 , bounds.Top, bounds.Left + 1 , bounds.Bottom );
880 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 2 , bounds.Top, bounds.Left + 2 , bounds.Bottom );
883 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
885 if ( page.Text != String.Empty )
887 StringFormat string_format = new StringFormat( );
888 // Flip the text around
889 string_format.Alignment = StringAlignment.Center;
890 string_format.LineAlignment = StringAlignment.Center;
891 string_format.FormatFlags = StringFormatFlags.NoWrap;
892 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
893 int wo = interior.Width / 2;
894 int ho = interior.Height / 2;
895 dc.TranslateTransform( interior.X + wo, interior.Y + ho );
896 dc.RotateTransform( 180 );
897 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), 0, 0, string_format );
898 dc.ResetTransform( );
904 // TabAlignment.Right
908 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
910 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Right, bounds.Top + 2 ), Color.White, LightColor ) )
912 lgbr.Blend = NormalBlend;
913 dc.FillRectangle( lgbr, interior );
917 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top );
918 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
919 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3 );
920 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right - 3, bounds.Bottom );
921 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Left, bounds.Bottom );
925 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Right , bounds.Top + 1, bounds.Right , bounds.Bottom - 1 );
926 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 1 , bounds.Top, bounds.Right - 1 , bounds.Bottom );
927 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 2 , bounds.Top, bounds.Right - 2 , bounds.Bottom );
930 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
932 if ( page.Text != String.Empty )
934 StringFormat string_format = new StringFormat( );
935 string_format.Alignment = StringAlignment.Center;
936 string_format.LineAlignment = StringAlignment.Center;
937 string_format.FormatFlags = StringFormatFlags.NoWrap;
938 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
940 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
952 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
954 StringFormat format = new StringFormat ();
955 format.Trimming = StringTrimming.EllipsisWord;
956 format.LineAlignment = StringAlignment.Center;
957 if (control.TextAlign == ToolBarTextAlign.Underneath)
958 format.Alignment = StringAlignment.Center;
960 format.Alignment = StringAlignment.Near;
962 dc.FillRectangle (ResPool.GetSolidBrush( NiceBackColor ), clip_rectangle);
964 foreach (ToolBarButton button in control.Buttons)
965 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
966 DrawToolBarButton (dc, control, button, format);
971 protected override void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
973 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
975 if (button.Style != ToolBarButtonStyle.Separator)
976 DoDrawToolBarButton (dc, button, is_flat);
978 switch (button.Style) {
979 case ToolBarButtonStyle.DropDownButton:
980 if (control.DropDownArrows)
981 DrawToolBarDropDownArrow (dc, button, is_flat);
982 DrawToolBarButtonContents (dc, control, button, format);
985 case ToolBarButtonStyle.Separator:
987 DrawToolBarSeparator (dc, button);
990 case ToolBarButtonStyle.ToggleButton:
992 DrawToolBarButtonContents (dc, control, button, format);
997 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
999 void DoDrawToolBarButton (Graphics dc, ToolBarButton button, bool is_flat)
1001 Color use_color = NormalColor;
1002 Color first_color = Color.White;
1005 if (button.Pushed || button.Pressed) {
1006 first_color = PressedColor;
1007 use_color = MouseOverColor;
1010 use_color = MouseOverColor;
1014 if (button.Pushed || button.Pressed) {
1015 first_color = PressedColor;
1016 use_color = MouseOverColor;
1019 use_color = MouseOverColor;
1022 Rectangle buttonRectangle = button.Rectangle;
1024 Rectangle lgbRectangle = Rectangle.Inflate (buttonRectangle, -1, -1);
1026 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y), new Point (buttonRectangle.X, buttonRectangle.Bottom - 1), first_color, use_color)) {
1027 lgbr.Blend = NormalBlend;
1028 dc.FillRectangle (lgbr, lgbRectangle);
1031 Internal_DrawButton (dc, buttonRectangle, BorderColor);
1034 protected override void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
1036 Rectangle area = button.Rectangle;
1037 int offset = (int) ResPool.GetPen (ColorControl).Width + 1;
1038 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X + 1, area.Y, area.X + 1, area.Bottom);
1039 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + offset, area.Y, area.X + offset, area.Bottom);
1042 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
1044 Rectangle rect = button.Rectangle;
1045 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
1046 rect.Width = ToolBarDropDownWidth;
1048 if (button.dd_pressed) {
1049 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
1050 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
1051 } else if (button.Pushed || button.Pressed)
1052 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
1055 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
1057 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
1059 PointF [] vertices = new PointF [3];
1060 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
1061 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1062 vertices [0].Y = ddCenter.Y;
1063 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1064 vertices [1].Y = ddCenter.Y;
1065 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
1066 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
1067 dc.FillPolygon (SystemBrushes.ControlText, vertices);
1070 protected override void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
1072 if (button.Image != null) {
1073 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
1074 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
1076 dc.DrawImage (button.Image, x, y);
1078 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
1082 dc.DrawString (button.Text, control.Font, ResPool.GetSolidBrush (ColorControlText), button.TextRectangle, format);
1084 CPDrawStringDisabled (dc, button.Text, control.Font, ColorControlLight, button.TextRectangle, format);
1087 #endregion // ToolBar
1089 // public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
1090 // CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
1093 protected override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
1096 Pen penTopLeftInner;
1098 Pen penBottomRightInner;
1099 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
1101 if ((style & Border3DStyle.Adjust) != 0) {
1108 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = ResPool.GetPen (control_color);
1110 CPColor cpcolor = ResPool.GetCPColor (control_color);
1113 case Border3DStyle.Raised:
1114 penTopLeftInner = ResPool.GetPen (cpcolor.LightLight);
1115 penBottomRight = ResPool.GetPen (cpcolor.Dark);
1116 penBottomRightInner = ResPool.GetPen (BorderColor);
1118 case Border3DStyle.Sunken:
1119 penTopLeft = ResPool.GetPen (BorderColor);
1120 penTopLeftInner = ResPool.GetPen (cpcolor.Dark);
1121 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1123 case Border3DStyle.Etched:
1124 penTopLeft = penBottomRightInner = ResPool.GetPen (BorderColor);
1125 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1127 case Border3DStyle.RaisedOuter:
1128 penBottomRight = ResPool.GetPen (cpcolor.Dark);
1130 case Border3DStyle.SunkenOuter:
1131 penTopLeft = ResPool.GetPen (BorderColor);
1132 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1134 case Border3DStyle.RaisedInner:
1135 penTopLeft = ResPool.GetPen (cpcolor.LightLight);
1136 penBottomRight = ResPool.GetPen (BorderColor);
1138 case Border3DStyle.SunkenInner:
1139 penTopLeft = ResPool.GetPen (cpcolor.Dark);
1141 case Border3DStyle.Flat:
1142 penTopLeft = penBottomRight = ResPool.GetPen (BorderColor);
1144 case Border3DStyle.Bump:
1145 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.Dark);
1151 if ((sides & Border3DSide.Middle) != 0) {
1152 graphics.FillRectangle (ResPool.GetSolidBrush (control_color), rect);
1155 if ((sides & Border3DSide.Left) != 0) {
1156 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
1157 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
1160 if ((sides & Border3DSide.Top) != 0) {
1161 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
1162 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
1165 if ((sides & Border3DSide.Right) != 0) {
1166 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
1167 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
1170 if ((sides & Border3DSide.Bottom) != 0) {
1171 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
1172 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
1176 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
1178 dc.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
1180 Color first_color = Color.White;
1181 Color second_color = NormalColor;
1183 if ((state & ButtonState.Flat) == ButtonState.Flat) {
1184 first_color = NormalColor;
1185 second_color = Color.White;
1187 if (((state & ButtonState.Flat) == ButtonState.Flat) &&
1188 (((state & ButtonState.Checked) == ButtonState.Checked) || ((state & ButtonState.Pushed) == ButtonState.Pushed))) {
1189 first_color = PressedColor;
1190 second_color = Color.White;
1192 if (((state & ButtonState.Checked) == ButtonState.Checked) || ((state & ButtonState.Pushed) == ButtonState.Pushed)) {
1193 second_color = PressedColor;
1196 Rectangle lgbRectangle = Rectangle.Inflate (rectangle, -1, -1);
1198 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (rectangle.X, rectangle.Y), new Point (rectangle.X, rectangle.Bottom - 1), first_color, second_color)) {
1199 if ((state & ButtonState.Flat) == ButtonState.Flat) {
1200 lgbr.Blend = FlatBlend;
1202 lgbr.Blend = NormalBlend;
1204 dc.FillRectangle (lgbr, lgbRectangle);
1207 Internal_DrawButton(dc, rectangle, BorderColor);
1210 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state )
1212 Point[] arrow = new Point[ 3 ];
1222 Color first_color = Color.White;
1223 Color second_color = NormalColor;
1225 // rectangle.Width += 1;
1227 if ( ( state & ButtonState.Checked ) != 0 )
1229 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControlLightLight, ColorControlLight ), rectangle );
1232 dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1234 if ( ( state & ButtonState.Flat ) != 0 )
1236 first_color = NormalColor;
1237 second_color = Color.White;
1241 if ( ( state & ( ButtonState.Pushed | ButtonState.Checked ) ) != 0 )
1243 first_color = Color.White;
1244 second_color = PressedColor;
1248 // CPDrawBorder3D( graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl );
1252 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X + 1, rectangle.Y + 1 ), new Point( rectangle.X + 1, rectangle.Bottom - 2 ), first_color, second_color ) )
1254 lgbr.Blend = NormalBlend;
1255 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 1, rectangle.Width - 4, rectangle.Height - 3 );
1258 Internal_DrawButton(dc, new Rectangle(rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2), BorderColor);
1260 rect = new Rectangle( rectangle.X + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2, rectangle.Height / 2 );
1261 centerX = rect.Left + rect.Width / 2;
1262 centerY = rect.Top + rect.Height / 2;
1263 shiftX = Math.Max( 1, rect.Width / 8 );
1264 shiftY = Math.Max( 1, rect.Height / 8 );
1266 if ( ( state & ButtonState.Pushed ) != 0 )
1275 P1 = new Point( rect.Left, centerY );
1276 P2 = new Point( centerX, rect.Bottom );
1277 P3 = new Point( rect.Right, centerY );
1283 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1284 dc.SmoothingMode = SmoothingMode.AntiAlias;
1286 /* Draw the arrow */
1287 if ( ( state & ButtonState.Inactive ) != 0 )
1289 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) )
1291 dc.DrawLines( pen, arrow );
1294 /* Move away from the shadow */
1295 P1.X -= 1; P1.Y -= 1;
1296 P2.X -= 1; P2.Y -= 1;
1297 P3.X -= 1; P3.Y -= 1;
1303 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) )
1305 dc.DrawLines( pen, arrow );
1310 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) )
1312 dc.DrawLines( pen, arrow );
1316 dc.SmoothingMode = old_smoothing_mode;
1319 /* Scroll button: regular button + direction arrow */
1320 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state )
1322 bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1324 DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1329 pen = ResPool.GetSizedPen( arrow_color, 2 );
1331 pen = ResPool.GetSizedPen( ColorGrayText, 2 );
1335 int centerX = area.Left + area.Width / 2;
1336 int centerY = area.Top + area.Height / 2;
1340 if ( ( state & ButtonState.Pushed ) != 0 )
1345 if ( area.Width < 12 || area.Height < 12 ) {
1350 Point[] arrow = new Point [3];
1352 switch (scroll_button_type) {
1353 case ScrollButton.Down:
1355 arrow [0] = new Point (centerX - min_3, centerY - min_2);
1356 arrow [1] = new Point (centerX, centerY + min_2);
1357 arrow [2] = new Point (centerX + min_3, centerY - min_2);
1359 case ScrollButton.Up:
1361 arrow [0] = new Point (centerX - min_3, centerY + min_2);
1362 arrow [1] = new Point (centerX, centerY - min_2);
1363 arrow [2] = new Point (centerX + min_3, centerY + min_2);
1365 case ScrollButton.Left:
1367 arrow [0] = new Point (centerX + min_2, centerY - min_3);
1368 arrow [1] = new Point (centerX - min_2, centerY);
1369 arrow [2] = new Point (centerX + min_2, centerY + min_3);
1371 case ScrollButton.Right:
1373 arrow [0] = new Point (centerX - min_2, centerY - min_3);
1374 arrow [1] = new Point (centerX + min_2, centerY);
1375 arrow [2] = new Point (centerX - min_2, centerY + min_3);
1381 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1382 dc.SmoothingMode = SmoothingMode.AntiAlias;
1384 dc.DrawLines (pen, arrow);
1386 dc.SmoothingMode = old_smoothing_mode;
1389 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds )
1391 Point pt = new Point( bounds.Right - 4, bounds.Bottom - 4 );
1393 dc.DrawImage( size_grip_bmp, pt );
1394 dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 5 );
1395 dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 10 );
1396 dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y );
1397 dc.DrawImage( size_grip_bmp, pt.X - 10, pt.Y );
1398 dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y - 5 );
1401 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar )
1403 LinearGradientBrush lgbr = null;
1406 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right, area.Y ), Color.White, NormalColor );
1408 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom ), Color.White, NormalColor );
1410 lgbr.Blend = NormalBlend;
1414 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1415 Internal_DrawButton (dc, area, BorderColor);
1417 // draw grip lines only if stere is enough space
1418 if ( area.Height > 20 )
1420 int mid_y = area.Y + ( area.Height / 2 );
1421 int mid_x = area.X + ( area.Width / 2 );
1423 Pen lpen = ResPool.GetSizedPen( MouseOverColor, 2 );
1424 dc.DrawLine( lpen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1425 dc.DrawLine( lpen, mid_x - 3, mid_y - 4, mid_x + 3, mid_y - 4 );
1426 dc.DrawLine( lpen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1428 Pen spen = ResPool.GetPen( Color.White );
1429 dc.DrawLine( spen, mid_x - 3, mid_y - 1, mid_x + 3, mid_y - 1 );
1430 dc.DrawLine( spen, mid_x - 3, mid_y - 5, mid_x + 3, mid_y - 5 );
1431 dc.DrawLine( spen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1436 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1437 Internal_DrawButton (dc, area, BorderColor);
1439 // draw grip lines only if stere is enough space
1440 if ( area.Width > 20 )
1442 int mid_x = area.X + ( area.Width / 2 );
1443 int mid_y = area.Y + ( area.Height / 2 );
1445 Pen lpen = ResPool.GetSizedPen( MouseOverColor, 2 );
1446 dc.DrawLine( lpen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1447 dc.DrawLine( lpen, mid_x - 4, mid_y - 3, mid_x - 4, mid_y + 3 );
1448 dc.DrawLine( lpen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1450 Pen spen = ResPool.GetPen( Color.White );
1451 dc.DrawLine( spen, mid_x - 1, mid_y - 3, mid_x - 1, mid_y + 3 );
1452 dc.DrawLine( spen, mid_x - 5, mid_y - 3, mid_x - 5, mid_y + 3 );
1453 dc.DrawLine( spen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1460 /* Nice scroll button */
1461 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type )
1463 Pen pen = ResPool.GetPen( BorderColor );
1465 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
1469 if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed )
1470 use_color = PressedColor;
1472 use_color = NormalColor;
1474 Point[] points = null;
1476 LinearGradientBrush lgbr = null;
1478 switch ( scroll_button_type )
1480 case ScrollButton.Left:
1481 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 1, area.Y ), use_color, Color.White );
1482 lgbr.Blend = FlatBlend;
1483 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1485 points = new Point[] {
1486 new Point( area.X + 2, area.Y ),
1487 new Point( area.Right - 1, area.Y ),
1488 new Point( area.Right - 1, area.Bottom - 1 ),
1489 new Point( area.X + 2, area.Bottom - 1 ),
1490 new Point( area.X, area.Bottom - 3 ),
1491 new Point( area.X, area.Y + 2 ),
1492 new Point( area.X + 2, area.Y )
1494 dc.DrawPolygon( pen, points );
1496 case ScrollButton.Right:
1497 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 1, area.Y ), Color.White, use_color );
1498 lgbr.Blend = NormalBlend;
1499 dc.FillRectangle( lgbr, area.X, area.Y + 1, area.Width - 1, area.Height - 2 );
1501 points = new Point[] {
1502 new Point( area.X, area.Y ),
1503 new Point( area.Right - 3, area.Y ),
1504 new Point( area.Right - 1, area.Y + 2 ),
1505 new Point( area.Right - 1, area.Bottom - 3 ),
1506 new Point( area.Right - 3, area.Bottom - 1 ),
1507 new Point( area.X, area.Bottom - 1 ),
1508 new Point( area.X, area.Y ),
1510 dc.DrawPolygon( pen, points );
1512 case ScrollButton.Up:
1513 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), use_color, Color.White );
1514 lgbr.Blend = FlatBlend;
1515 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1517 points = new Point[] {
1518 new Point( area.X + 2, area.Y ),
1519 new Point( area.Right - 3, area.Y ),
1520 new Point( area.Right - 1, area.Y + 2 ),
1521 new Point( area.Right - 1, area.Bottom - 1 ),
1522 new Point( area.X, area.Bottom - 1 ),
1523 new Point( area.X, area.Y + 2 ),
1524 new Point( area.X + 2, area.Y )
1526 dc.DrawPolygon( pen, points );
1528 case ScrollButton.Down:
1529 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), Color.White, use_color );
1530 lgbr.Blend = NormalBlend;
1531 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1533 points = new Point[] {
1534 new Point( area.X, area.Y ),
1535 new Point( area.Right - 1, area.Y ),
1536 new Point( area.Right - 1, area.Bottom - 3 ),
1537 new Point( area.Right - 3, area.Bottom - 1 ),
1538 new Point( area.X + 2, area.Bottom - 1 ),
1539 new Point( area.X, area.Bottom - 3 ),
1540 new Point( area.X, area.Y )
1542 dc.DrawPolygon( pen, points );
1550 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
1552 StringFormat text_format;
1558 rect = box.ClientRectangle;
1560 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
1562 text_format = new StringFormat();
1563 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1565 size = dc.MeasureString (box.Text, box.Font);
1566 width = (int) size.Width;
1568 if (width > box.Width - 16)
1569 width = box.Width - 16;
1571 y = box.Font.Height / 2;
1573 Pen pen = ResPool.GetPen( BorderColor );
1576 Point[] points = new Point[] {
1577 new Point( 8 + width, y ),
1578 new Point( box.Width - 3, y ),
1579 new Point( box.Width - 1, y + 2 ),
1580 new Point( box.Width - 1, box.Height - 3 ),
1581 new Point( box.Width - 3, box.Height - 1 ),
1582 new Point( 2, box.Height - 1 ),
1583 new Point( 0, box.Height - 3 ),
1584 new Point( 0, y + 2 ),
1588 dc.DrawLines( pen, points );
1592 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1594 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
1595 new RectangleF (10, 0, width, box.Font.Height), text_format);
1597 text_format.Dispose ();