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) 2004-2005 Novell, Inc.
23 // Alexander Olk, xenomorph2@onlinehome.de
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;
66 always_draw_hotkeys = true;
68 FlatBlend = new Blend ();
69 FlatBlend.Factors = new float []{0.0f, 0.992f, 1.0f};
70 FlatBlend.Positions = new float []{0.0f, 0.68f, 1.0f};
72 NormalBlend = new Blend ();
73 NormalBlend.Factors = new float []{0.0f, 0.008f, 1.0f};
74 NormalBlend.Positions = new float []{0.0f, 0.32f, 1.0f};
77 public override Color DefaultControlBackColor
79 get { return NiceBackColor; }
82 public override Color DefaultWindowBackColor
84 get { return NiceBackColor; }
87 public override Color ColorControl {
88 get { return NiceBackColor;}
91 static Bitmap CreateSizegripDot()
93 Bitmap bmp = new Bitmap( 4, 4 );
94 using ( Graphics dc = Graphics.FromImage( bmp ) )
96 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
97 dc.SmoothingMode = SmoothingMode.AntiAlias;
99 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 4, 4 ), PressedColor, Color.White ) ) {
100 Blend bl = new Blend ();
101 bl.Factors = new float []{0.0f, 0.992f, 1.0f};
102 bl.Positions = new float []{0.0f, 0.68f, 1.0f};
104 dc.FillEllipse( lgbr, new Rectangle( 0, 0, 4, 4 ) );
107 dc.SmoothingMode = old_smoothing_mode;
113 public override Image Images(UIIcon index, int size) {
115 case UIIcon.PlacesRecentDocuments:
116 if ((platform == 4) || (platform == 128))
117 return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
119 return base.Images (UIIcon.PlacesRecentDocuments, size);
120 case UIIcon.PlacesDesktop:
121 if ((platform == 4) || (platform == 128))
122 return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
124 return base.Images (UIIcon.PlacesDesktop, size);
125 case UIIcon.PlacesPersonal:
126 if ((platform == 4) || (platform == 128))
127 return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
129 return base.Images (UIIcon.PlacesPersonal, size);
130 case UIIcon.PlacesMyComputer:
131 if ((platform == 4) || (platform == 128))
132 return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
134 return base.Images (UIIcon.PlacesMyComputer, size);
135 case UIIcon.PlacesMyNetwork:
136 if ((platform == 4) || (platform == 128))
137 return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
139 return base.Images (UIIcon.PlacesMyNetwork, size);
141 // Icons for message boxes
142 case UIIcon.MessageBoxError: return base.Images (UIIcon.MessageBoxError, size);
143 case UIIcon.MessageBoxInfo: return base.Images (UIIcon.MessageBoxInfo, size);
144 case UIIcon.MessageBoxQuestion: return base.Images (UIIcon.MessageBoxQuestion, size);
145 case UIIcon.MessageBoxWarning: return base.Images (UIIcon.MessageBoxWarning, size);
148 case UIIcon.NormalFolder:
149 if ((platform == 4) || (platform == 128))
150 return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
152 return base.Images (UIIcon.NormalFolder, size);
155 throw new ArgumentException("Invalid Icon type requested", "index");
159 #endregion // Internal Methods
162 protected override void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
164 bool check_or_radio = false;
165 bool check_or_radio_checked = false;
167 Color use_color = NormalColor;
168 Color first_color = Color.White;
170 dc.FillRectangle (ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
172 if (button is CheckBox) {
173 check_or_radio = true;
174 check_or_radio_checked = ((CheckBox)button).Checked;
175 } else if (button is RadioButton) {
176 check_or_radio = true;
177 check_or_radio_checked = ((RadioButton)button).Checked;
180 if (button.has_focus && !check_or_radio && button.is_enabled)
181 first_color = FocusColorLight;
183 if (button.is_enabled) {
184 if (button.FlatStyle == FlatStyle.Popup) {
185 if (!button.is_pressed && button.is_entered && !check_or_radio_checked)
186 use_color = MouseOverColor;
187 } else if (button.FlatStyle == FlatStyle.Flat) {
188 if (button.is_entered && !button.is_pressed && !check_or_radio_checked)
189 use_color = MouseOverColor;
191 if (!button.is_pressed && button.is_entered && !check_or_radio_checked)
192 use_color = MouseOverColor;
196 Rectangle buttonRectangle;
198 int height = button.ClientSize.Height;
200 // set up the button rectangle
201 buttonRectangle = button.ClientRectangle;
203 // Fill button with a nice linear gradient brush
204 Rectangle lgbRectangle = Rectangle.Inflate (buttonRectangle, -1, -1);
206 if (button.flat_style != FlatStyle.Popup || ((button.flat_style == FlatStyle.Popup) && button.is_entered)) {
207 LinearGradientBrush lgbr;
208 if (!button.is_pressed && !check_or_radio_checked) {
209 if (button.flat_style == FlatStyle.Flat) {
210 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), use_color, first_color);
211 lgbr.Blend = FlatBlend;
213 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), first_color, use_color);
214 lgbr.Blend = NormalBlend;
217 lgbr = new LinearGradientBrush (new Point (0, 0), new Point (0, height - 1), PressedColor, MouseOverColor);
219 dc.FillRectangle (lgbr, lgbRectangle);
222 if (button.has_focus && !check_or_radio)
225 Internal_DrawButton(dc, buttonRectangle, BorderColor);
229 private void Internal_DrawButton(Graphics dc, Rectangle area, Color border_color)
231 Point[] points = new Point [] {
232 new Point (area.X + 1, area.Y),
233 new Point (area.Right - 2, area.Y),
234 new Point (area.Right - 2, area.Y + 1),
235 new Point (area.Right - 1, area.Y + 1),
236 new Point (area.Right - 1, area.Bottom - 2),
237 new Point (area.Right - 2, area.Bottom - 2),
238 new Point (area.Right - 2, area.Bottom - 1),
239 new Point (area.X + 1, area.Bottom - 1),
240 new Point (area.X + 1, area.Bottom - 2),
241 new Point (area.X, area.Bottom - 2),
242 new Point (area.X, area.Y + 1),
243 new Point (area.X + 1, area.Y + 1),
244 new Point (area.X + 1, area.Y)
247 Pen pen = ResPool.GetPen (border_color);
248 dc.DrawPolygon (pen, points);
251 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc )
253 if ((button is RadioButton) || (button is CheckBox))
256 Internal_DrawButton(dc, button.ClientRectangle, FocusColor);
259 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc )
261 if ( !( button is CheckBox ) && !(button is RadioButton ) )
263 base.ButtonBase_DrawText( button, dc );
266 #endregion // ButtonBase
269 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
271 if (menu.Height == 0)
272 CalcMenuBarSize (dc, menu, rect.Width);
274 bool keynav = (menu as MainMenu).tracker.Navigating;
275 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
276 string_format_menu_menubar_text.HotkeyPrefix = hp;
277 string_format_menu_text.HotkeyPrefix = hp;
279 rect.Height = menu.Height;
280 dc.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rect);
282 for (int i = 0; i < menu.MenuItems.Count; i++) {
283 MenuItem item = menu.MenuItems [i];
284 Rectangle item_rect = item.bounds;
285 item_rect.X += rect.X;
286 item_rect.Y += rect.Y;
287 item.MenuHeight = menu.Height;
288 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
292 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
294 StringFormat string_format;
295 Rectangle rect_text = e.Bounds;
297 if (item.Visible == false)
301 string_format = string_format_menu_menubar_text;
303 string_format = string_format_menu_text;
305 if (item.Separator == true) {
306 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
307 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
309 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
310 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
316 rect_text.X += MenuCheckSize.Width;
318 if (item.BarBreak) { /* Draw vertical break bar*/
319 Rectangle rect = e.Bounds;
322 rect.Height = item.MenuHeight - 6;
324 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
325 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
327 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
328 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
331 Color color_text = ColorMenuText;
332 Color color_back = NiceBackColor;
334 /* Draw background */
335 Rectangle rect_back = e.Bounds;
339 if (((e.State & DrawItemState.Selected) == DrawItemState.Selected) || ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight)) {
340 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 ) )
341 e.Graphics.FillRectangle (lgbr, rect_back);
343 e.Graphics.DrawRectangle (ResPool.GetPen (BorderColor), rect_back.X, rect_back.Y, rect_back.Width, rect_back.Height - 1);
345 e.Graphics.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rect_back);
349 e.Graphics.DrawString (item.Text, e.Font,
350 ResPool.GetSolidBrush (color_text),
351 rect_text, string_format);
353 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
354 string str = item.GetShortCutText ();
355 Rectangle rect = rect_text;
357 rect.Width -= item.XTab;
359 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush (color_text),
360 rect, string_format_menu_shortcut);
364 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
365 Color.Black, rect_text, string_format);
369 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
371 int cx = MenuCheckSize.Width;
372 int cy = MenuCheckSize.Height;
373 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
376 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
377 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
379 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
380 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
386 /* Draw checked or radio */
387 if (item.MenuBar == false && item.Checked) {
389 Rectangle area = e.Bounds;
390 int cx = MenuCheckSize.Width;
391 int cy = MenuCheckSize.Height;
392 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
394 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
400 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
403 dc.FillRectangle (ResPool.GetSolidBrush
404 (NiceBackColor), cliparea);
406 /* Draw menu borders */
407 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
408 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
410 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
411 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
413 dc.DrawLine (ResPool.GetPen (ColorControlDark),
414 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
416 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
417 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
419 dc.DrawLine (ResPool.GetPen (ColorControlDark),
420 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
422 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
423 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
425 for (int i = 0; i < menu.MenuItems.Count; i++)
426 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
427 MenuItem item = menu.MenuItems [i];
428 item.MenuHeight = menu.Height;
429 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
430 item.bounds, i, item.Status));
436 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl )
438 Rectangle client_area = ctrl.client_area;
440 Rectangle bar = ctrl.client_area;
442 barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
444 bar.Width = barpos_pixels;
447 // Draw bar background
448 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( client_area.Left, client_area.Top ), new Point( client_area.Left, client_area.Bottom ), LightColor, Color.White ) )
450 lgbr.Blend = FlatBlend;
451 dc.FillRectangle( lgbr, client_area );
455 using ( LinearGradientBrush lgbr = new LinearGradientBrush( bar.Location, new Point( bar.X, bar.Bottom ), Color.White, PressedColor ) )
457 lgbr.Blend = NormalBlend;
458 dc.FillRectangle( lgbr, bar );
462 dc.DrawRectangle( ResPool.GetPen( BorderColor ), ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Width - 1, ctrl.ClientRectangle.Height - 1 );
463 dc.DrawRectangle( ResPool.GetPen( LightColor ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
465 #endregion // ProgressBar
468 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
470 if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
471 DrawScrollBarThumb( dc, thumb_pos, bar );
474 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
476 Rectangle r = new Rectangle( 0,
477 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
478 Rectangle intersect = Rectangle.Intersect( clip, r );
480 if ( intersect != Rectangle.Empty )
482 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
484 lgbr.Blend = FlatBlend;
485 dc.FillRectangle( lgbr, intersect );
490 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
492 Rectangle r = new Rectangle( 0, scrollbutton_height,
493 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
494 Rectangle intersect = Rectangle.Intersect( clip, r );
496 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
498 lgbr.Blend = FlatBlend;
500 if ( intersect != Rectangle.Empty )
501 dc.FillRectangle( lgbr, intersect );
504 r.Y = thumb_pos.Y + thumb_pos.Height;
505 r.Width = bar.ClientRectangle.Width;
506 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
508 intersect = Rectangle.Intersect( clip, r );
509 if ( intersect != Rectangle.Empty )
510 dc.FillRectangle( lgbr, intersect );
514 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
516 Rectangle r = new Rectangle( 0, scrollbutton_height,
517 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
518 Rectangle intersect = Rectangle.Intersect( clip, r );
520 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
522 lgbr.Blend = FlatBlend;
524 if ( intersect != Rectangle.Empty )
525 dc.FillRectangle( lgbr, intersect );
528 r.Y = thumb_pos.Y + thumb_pos.Height;
529 r.Width = bar.ClientRectangle.Width;
530 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
532 intersect = Rectangle.Intersect( clip, r );
533 if ( intersect != Rectangle.Empty )
534 dc.FillRectangle( lgbr, intersect );
538 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
540 Rectangle r = new Rectangle( scrollbutton_width,
541 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
542 Rectangle intersect = Rectangle.Intersect( clip, r );
544 if ( intersect != Rectangle.Empty )
546 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
548 lgbr.Blend = FlatBlend;
550 dc.FillRectangle( lgbr, intersect );
555 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
557 Rectangle r = new Rectangle( scrollbutton_width, 0,
558 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
559 Rectangle intersect = Rectangle.Intersect( clip, r );
561 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
563 lgbr.Blend = FlatBlend;
565 if ( intersect != Rectangle.Empty )
566 dc.FillRectangle( lgbr, intersect );
568 r.X = thumb_pos.X + thumb_pos.Width;
570 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
571 r.Height = bar.ClientRectangle.Height;
573 intersect = Rectangle.Intersect( clip, r );
574 if ( intersect != Rectangle.Empty )
575 dc.FillRectangle( lgbr, intersect );
579 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
581 Rectangle r = new Rectangle( scrollbutton_width, 0,
582 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
583 Rectangle intersect = Rectangle.Intersect( clip, r );
585 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
587 lgbr.Blend = FlatBlend;
589 if ( intersect != Rectangle.Empty )
590 dc.FillRectangle( lgbr, intersect );
592 r.X = thumb_pos.X + thumb_pos.Width;
594 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
595 r.Height = bar.ClientRectangle.Height;
597 intersect = Rectangle.Intersect( clip, r );
598 if ( intersect != Rectangle.Empty )
599 dc.FillRectangle( lgbr, intersect );
602 #endregion // ScrollBar
605 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
606 Brush br_forecolor, StatusBarPanel panel )
608 int border_size = 3; // this is actually const, even if the border style is none
610 area.Height -= border_size;
611 if ( panel.BorderStyle != StatusBarPanelBorderStyle.None )
613 Internal_DrawButton( dc, area, BorderColor );
616 if ( panel.Style == StatusBarPanelStyle.OwnerDraw )
618 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
619 dc, panel.Parent.Font, area, index, DrawItemState.Default,
620 panel, panel.Parent.ForeColor, panel.Parent.BackColor );
621 panel.Parent.OnDrawItemInternal( e );
625 int left = area.Left;
626 if ( panel.Icon != null )
629 dc.DrawIcon( panel.Icon, left, area.Top );
630 left += panel.Icon.Width;
633 if ( panel.Text == String.Empty )
636 string text = panel.Text;
637 StringFormat string_format = new StringFormat( );
638 string_format.Trimming = StringTrimming.Character;
639 string_format.FormatFlags = StringFormatFlags.NoWrap;
641 if ( text[ 0 ] == '\t' )
643 string_format.Alignment = StringAlignment.Center;
644 text = text.Substring( 1 );
645 if ( text[ 0 ] == '\t' )
647 string_format.Alignment = StringAlignment.Far;
648 text = text.Substring( 1 );
652 int x = left + border_size;
653 int y = border_size + 2;
654 Rectangle r = new Rectangle( x, y,
655 area.Right - x - border_size,
656 area.Bottom - y - border_size );
658 dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
660 #endregion // StatusBar
662 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab )
664 // Do we need to fill the back color? It can't be changed...
665 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
666 Rectangle panel_rect = GetTabPanelRectExt( tab );
668 if ( tab.Appearance == TabAppearance.Normal )
670 CPDrawBorder( dc, panel_rect, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid,
671 BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid );
674 if ( tab.Alignment == TabAlignment.Top )
676 for ( int r = tab.TabPages.Count; r > 0; r-- )
678 for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
680 if ( i == tab.SelectedIndex )
682 if ( r != tab.TabPages[ i ].Row )
684 Rectangle rect = tab.GetTabRect( i );
685 if ( !rect.IntersectsWith( area ) )
687 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
693 for ( int r = 0; r < tab.TabPages.Count; r++ )
695 for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
697 if ( i == tab.SelectedIndex )
699 if ( r != tab.TabPages[ i ].Row )
701 Rectangle rect = tab.GetTabRect( i );
702 if ( !rect.IntersectsWith( area ) )
704 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
709 if ( tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos )
711 Rectangle rect = tab.GetTabRect( tab.SelectedIndex );
712 if ( rect.IntersectsWith( area ) )
713 DrawTab( dc, tab.TabPages[ tab.SelectedIndex ], tab, rect, true );
716 if ( tab.ShowSlider )
718 Rectangle right = GetTabControlRightScrollRect( tab );
719 Rectangle left = GetTabControlLeftScrollRect( tab );
720 CPDrawScrollButton( dc, right, ScrollButton.Right, tab.RightSliderState );
721 CPDrawScrollButton( dc, left, ScrollButton.Left, tab.LeftSliderState );
725 protected override int DrawTab( Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected )
727 int FlatButtonSpacing = 8;
729 int res = bounds.Width;
731 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
733 if ( tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons )
735 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
738 if ( tab.Appearance == TabAppearance.FlatButtons )
740 int width = bounds.Width;
741 bounds.Width += ( FlatButtonSpacing - 2 );
743 CPDrawBorder3D( dc, bounds, Border3DStyle.Etched, Border3DSide.Right );
744 bounds.Width = width;
749 CPDrawBorder3D( dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
751 else if ( tab.Appearance != TabAppearance.FlatButtons )
753 CPDrawBorder3D( dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
756 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4 );
759 StringFormat string_format = new StringFormat( );
760 string_format.Alignment = StringAlignment.Center;
761 string_format.LineAlignment = StringAlignment.Center;
762 string_format.FormatFlags = StringFormatFlags.NoWrap;
765 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
770 Pen border_pen = ResPool.GetPen( BorderColor );
772 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
774 switch ( tab.Alignment )
776 case TabAlignment.Top:
780 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
782 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Left + 2, bounds.Bottom ), Color.White, LightColor ) )
784 lgbr.Blend = NormalBlend;
785 dc.FillRectangle( lgbr, interior );
789 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3 );
790 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top );
791 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top );
792 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
793 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom );
797 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Top, bounds.Right - 1, bounds.Top );
798 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 1, bounds.Right , bounds.Top + 1 );
799 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 2, bounds.Right , bounds.Top + 2 );
802 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
804 if ( page.Text != String.Empty )
806 StringFormat string_format = new StringFormat( );
807 string_format.Alignment = StringAlignment.Center;
808 string_format.LineAlignment = StringAlignment.Center;
809 string_format.FormatFlags = StringFormatFlags.NoWrap;
811 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
817 case TabAlignment.Bottom:
821 interior = new Rectangle( bounds.Left + 3, bounds.Top, bounds.Width - 3, bounds.Height );
823 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 3, bounds.Top ), new Point( bounds.Left + 3, bounds.Bottom ), Color.White, LightColor ) )
825 lgbr.Blend = NormalBlend;
826 dc.FillRectangle( lgbr, interior );
830 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3 );
831 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
832 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom );
833 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3 );
834 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top );
838 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Bottom, bounds.Right - 1, bounds.Bottom );
839 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 1, bounds.Right , bounds.Bottom - 1 );
840 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 2, bounds.Right , bounds.Bottom - 2 );
843 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
845 if ( page.Text != String.Empty )
847 StringFormat string_format = new StringFormat( );
848 string_format.Alignment = StringAlignment.Center;
849 string_format.LineAlignment = StringAlignment.Center;
850 string_format.FormatFlags = StringFormatFlags.NoWrap;
852 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
858 case TabAlignment.Left:
862 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
864 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Right, bounds.Top + 2 ), LightColor, Color.White ) )
866 lgbr.Blend = FlatBlend;
867 dc.FillRectangle( lgbr, interior );
871 dc.DrawLine( border_pen, bounds.Right, bounds.Top, bounds.Left + 3, bounds.Top );
872 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Left, bounds.Top + 3 );
873 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left, bounds.Bottom - 3 );
874 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
875 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right, bounds.Bottom );
879 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left , bounds.Top + 1, bounds.Left , bounds.Bottom - 1 );
880 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 1 , bounds.Top, bounds.Left + 1 , bounds.Bottom );
881 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 2 , bounds.Top, bounds.Left + 2 , bounds.Bottom );
884 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
886 if ( page.Text != String.Empty )
888 StringFormat string_format = new StringFormat( );
889 // Flip the text around
890 string_format.Alignment = StringAlignment.Center;
891 string_format.LineAlignment = StringAlignment.Center;
892 string_format.FormatFlags = StringFormatFlags.NoWrap;
893 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
894 int wo = interior.Width / 2;
895 int ho = interior.Height / 2;
896 dc.TranslateTransform( interior.X + wo, interior.Y + ho );
897 dc.RotateTransform( 180 );
898 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), 0, 0, string_format );
899 dc.ResetTransform( );
905 // TabAlignment.Right
909 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
911 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2 ), new Point( bounds.Right, bounds.Top + 2 ), Color.White, LightColor ) )
913 lgbr.Blend = NormalBlend;
914 dc.FillRectangle( lgbr, interior );
918 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top );
919 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
920 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3 );
921 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right - 3, bounds.Bottom );
922 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Left, bounds.Bottom );
926 dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Right , bounds.Top + 1, bounds.Right , bounds.Bottom - 1 );
927 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 1 , bounds.Top, bounds.Right - 1 , bounds.Bottom );
928 dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 2 , bounds.Top, bounds.Right - 2 , bounds.Bottom );
931 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
933 if ( page.Text != String.Empty )
935 StringFormat string_format = new StringFormat( );
936 string_format.Alignment = StringAlignment.Center;
937 string_format.LineAlignment = StringAlignment.Center;
938 string_format.FormatFlags = StringFormatFlags.NoWrap;
939 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
941 dc.DrawString( page.Text, page.Font, ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
953 public override bool ToolBarInvalidateEntireButton {
957 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
959 StringFormat format = new StringFormat ();
960 format.Trimming = StringTrimming.EllipsisWord;
961 format.LineAlignment = StringAlignment.Center;
962 if (control.TextAlign == ToolBarTextAlign.Underneath)
963 format.Alignment = StringAlignment.Center;
965 format.Alignment = StringAlignment.Near;
967 dc.FillRectangle (ResPool.GetSolidBrush( NiceBackColor ), clip_rectangle);
969 foreach (ToolBarButton button in control.Buttons)
970 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
971 DrawToolBarButton (dc, control, button, format);
976 protected override void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
978 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
980 if (button.Style != ToolBarButtonStyle.Separator)
981 DoDrawToolBarButton (dc, button, is_flat);
983 switch (button.Style) {
984 case ToolBarButtonStyle.DropDownButton:
985 if (control.DropDownArrows)
986 DrawToolBarDropDownArrow (dc, button, is_flat);
987 DrawToolBarButtonContents (dc, control, button, format);
990 case ToolBarButtonStyle.Separator:
992 DrawToolBarSeparator (dc, button);
995 case ToolBarButtonStyle.ToggleButton:
997 DrawToolBarButtonContents (dc, control, button, format);
1002 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
1004 void DoDrawToolBarButton (Graphics dc, ToolBarButton button, bool is_flat)
1006 Color use_color = NormalColor;
1007 Color first_color = Color.White;
1010 if (button.Pushed || button.Pressed) {
1011 first_color = PressedColor;
1012 use_color = MouseOverColor;
1015 use_color = MouseOverColor;
1019 if (button.Pushed || button.Pressed) {
1020 first_color = PressedColor;
1021 use_color = MouseOverColor;
1024 use_color = MouseOverColor;
1027 Rectangle buttonRectangle = button.Rectangle;
1029 Rectangle lgbRectangle = Rectangle.Inflate (buttonRectangle, -1, -1);
1031 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y), new Point (buttonRectangle.X, buttonRectangle.Bottom - 1), first_color, use_color)) {
1032 lgbr.Blend = NormalBlend;
1033 dc.FillRectangle (lgbr, lgbRectangle);
1036 Internal_DrawButton (dc, buttonRectangle, BorderColor);
1039 protected override void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
1041 Rectangle area = button.Rectangle;
1042 int offset = (int) ResPool.GetPen (ColorControl).Width + 1;
1043 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X + 1, area.Y, area.X + 1, area.Bottom);
1044 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + offset, area.Y, area.X + offset, area.Bottom);
1047 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
1049 Rectangle rect = button.Rectangle;
1050 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
1051 rect.Width = ToolBarDropDownWidth;
1053 if (button.dd_pressed) {
1054 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
1055 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
1056 } else if (button.Pushed || button.Pressed)
1057 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
1060 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
1062 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
1064 PointF [] vertices = new PointF [3];
1065 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
1066 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1067 vertices [0].Y = ddCenter.Y;
1068 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1069 vertices [1].Y = ddCenter.Y;
1070 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
1071 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
1072 dc.FillPolygon (SystemBrushes.ControlText, vertices);
1075 protected override void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
1077 if (button.Image != null) {
1078 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
1079 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
1081 dc.DrawImage (button.Image, x, y);
1083 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
1087 dc.DrawString (button.Text, control.Font, ResPool.GetSolidBrush (ColorControlText), button.TextRectangle, format);
1089 CPDrawStringDisabled (dc, button.Text, control.Font, ColorControlLight, button.TextRectangle, format);
1092 #endregion // ToolBar
1094 // public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
1095 // CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
1098 protected override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
1101 Pen penTopLeftInner;
1103 Pen penBottomRightInner;
1104 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
1106 if ((style & Border3DStyle.Adjust) != 0) {
1113 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = ResPool.GetPen (control_color);
1115 CPColor cpcolor = ResPool.GetCPColor (control_color);
1118 case Border3DStyle.Raised:
1119 penTopLeftInner = ResPool.GetPen (cpcolor.LightLight);
1120 penBottomRight = ResPool.GetPen (cpcolor.Dark);
1121 penBottomRightInner = ResPool.GetPen (BorderColor);
1123 case Border3DStyle.Sunken:
1124 penTopLeft = ResPool.GetPen (BorderColor);
1125 penTopLeftInner = ResPool.GetPen (cpcolor.Dark);
1126 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1128 case Border3DStyle.Etched:
1129 penTopLeft = penBottomRightInner = ResPool.GetPen (BorderColor);
1130 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1132 case Border3DStyle.RaisedOuter:
1133 penBottomRight = ResPool.GetPen (cpcolor.Dark);
1135 case Border3DStyle.SunkenOuter:
1136 penTopLeft = ResPool.GetPen (BorderColor);
1137 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
1139 case Border3DStyle.RaisedInner:
1140 penTopLeft = ResPool.GetPen (cpcolor.LightLight);
1141 penBottomRight = ResPool.GetPen (BorderColor);
1143 case Border3DStyle.SunkenInner:
1144 penTopLeft = ResPool.GetPen (cpcolor.Dark);
1146 case Border3DStyle.Flat:
1147 penTopLeft = penBottomRight = ResPool.GetPen (BorderColor);
1149 case Border3DStyle.Bump:
1150 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.Dark);
1156 if ((sides & Border3DSide.Middle) != 0) {
1157 graphics.FillRectangle (ResPool.GetSolidBrush (control_color), rect);
1160 if ((sides & Border3DSide.Left) != 0) {
1161 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
1162 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
1165 if ((sides & Border3DSide.Top) != 0) {
1166 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
1167 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
1170 if ((sides & Border3DSide.Right) != 0) {
1171 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
1172 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
1175 if ((sides & Border3DSide.Bottom) != 0) {
1176 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
1177 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
1181 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
1183 dc.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
1185 Color first_color = Color.White;
1186 Color second_color = NormalColor;
1188 if ((state & ButtonState.Flat) == ButtonState.Flat) {
1189 first_color = NormalColor;
1190 second_color = Color.White;
1192 if (((state & ButtonState.Flat) == ButtonState.Flat) &&
1193 (((state & ButtonState.Checked) == ButtonState.Checked) || ((state & ButtonState.Pushed) == ButtonState.Pushed))) {
1194 first_color = PressedColor;
1195 second_color = Color.White;
1197 if (((state & ButtonState.Checked) == ButtonState.Checked) || ((state & ButtonState.Pushed) == ButtonState.Pushed)) {
1198 second_color = PressedColor;
1201 Rectangle lgbRectangle = Rectangle.Inflate (rectangle, -1, -1);
1203 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (rectangle.X, rectangle.Y), new Point (rectangle.X, rectangle.Bottom - 1), first_color, second_color)) {
1204 if ((state & ButtonState.Flat) == ButtonState.Flat) {
1205 lgbr.Blend = FlatBlend;
1207 lgbr.Blend = NormalBlend;
1209 dc.FillRectangle (lgbr, lgbRectangle);
1212 Internal_DrawButton(dc, rectangle, BorderColor);
1215 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state )
1217 Point[] arrow = new Point[ 3 ];
1227 Color first_color = Color.White;
1228 Color second_color = NormalColor;
1230 // rectangle.Width += 1;
1232 if ( ( state & ButtonState.Checked ) != 0 )
1234 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControlLightLight, ColorControlLight ), rectangle );
1237 dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1239 if ( ( state & ButtonState.Flat ) != 0 )
1241 first_color = NormalColor;
1242 second_color = Color.White;
1246 if ( ( state & ( ButtonState.Pushed | ButtonState.Checked ) ) != 0 )
1248 first_color = Color.White;
1249 second_color = PressedColor;
1253 // CPDrawBorder3D( graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl );
1257 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 ) )
1259 lgbr.Blend = NormalBlend;
1260 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 1, rectangle.Width - 4, rectangle.Height - 3 );
1263 Internal_DrawButton(dc, new Rectangle(rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2), BorderColor);
1265 rect = new Rectangle( rectangle.X + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2, rectangle.Height / 2 );
1266 centerX = rect.Left + rect.Width / 2;
1267 centerY = rect.Top + rect.Height / 2;
1268 shiftX = Math.Max( 1, rect.Width / 8 );
1269 shiftY = Math.Max( 1, rect.Height / 8 );
1271 if ( ( state & ButtonState.Pushed ) != 0 )
1280 P1 = new Point( rect.Left, centerY );
1281 P2 = new Point( centerX, rect.Bottom );
1282 P3 = new Point( rect.Right, centerY );
1288 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1289 dc.SmoothingMode = SmoothingMode.AntiAlias;
1291 /* Draw the arrow */
1292 if ( ( state & ButtonState.Inactive ) != 0 )
1294 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) )
1296 dc.DrawLines( pen, arrow );
1299 /* Move away from the shadow */
1300 P1.X -= 1; P1.Y -= 1;
1301 P2.X -= 1; P2.Y -= 1;
1302 P3.X -= 1; P3.Y -= 1;
1308 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) )
1310 dc.DrawLines( pen, arrow );
1315 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) )
1317 dc.DrawLines( pen, arrow );
1321 dc.SmoothingMode = old_smoothing_mode;
1324 /* Scroll button: regular button + direction arrow */
1325 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state )
1327 bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1329 DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1334 pen = ResPool.GetSizedPen( arrow_color, 2 );
1336 pen = ResPool.GetSizedPen( ColorGrayText, 2 );
1340 int centerX = area.Left + area.Width / 2;
1341 int centerY = area.Top + area.Height / 2;
1345 if ( ( state & ButtonState.Pushed ) != 0 )
1350 if ( area.Width < 12 || area.Height < 12 ) {
1355 Point[] arrow = new Point [3];
1357 switch (scroll_button_type) {
1358 case ScrollButton.Down:
1360 arrow [0] = new Point (centerX - min_3, centerY - min_2);
1361 arrow [1] = new Point (centerX, centerY + min_2);
1362 arrow [2] = new Point (centerX + min_3, centerY - min_2);
1364 case ScrollButton.Up:
1366 arrow [0] = new Point (centerX - min_3, centerY + min_2);
1367 arrow [1] = new Point (centerX, centerY - min_2);
1368 arrow [2] = new Point (centerX + min_3, centerY + min_2);
1370 case ScrollButton.Left:
1372 arrow [0] = new Point (centerX + min_2, centerY - min_3);
1373 arrow [1] = new Point (centerX - min_2, centerY);
1374 arrow [2] = new Point (centerX + min_2, centerY + min_3);
1376 case ScrollButton.Right:
1378 arrow [0] = new Point (centerX - min_2, centerY - min_3);
1379 arrow [1] = new Point (centerX + min_2, centerY);
1380 arrow [2] = new Point (centerX - min_2, centerY + min_3);
1386 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1387 dc.SmoothingMode = SmoothingMode.AntiAlias;
1389 dc.DrawLines (pen, arrow);
1391 dc.SmoothingMode = old_smoothing_mode;
1394 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds )
1396 Point pt = new Point( bounds.Right - 4, bounds.Bottom - 4 );
1398 dc.DrawImage( size_grip_bmp, pt );
1399 dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 5 );
1400 dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 10 );
1401 dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y );
1402 dc.DrawImage( size_grip_bmp, pt.X - 10, pt.Y );
1403 dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y - 5 );
1406 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar )
1408 LinearGradientBrush lgbr = null;
1411 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right, area.Y ), Color.White, NormalColor );
1413 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom ), Color.White, NormalColor );
1415 lgbr.Blend = NormalBlend;
1419 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1420 Internal_DrawButton (dc, area, BorderColor);
1422 // draw grip lines only if stere is enough space
1423 if ( area.Height > 20 )
1425 int mid_y = area.Y + ( area.Height / 2 );
1426 int mid_x = area.X + ( area.Width / 2 );
1428 Pen lpen = ResPool.GetSizedPen( MouseOverColor, 2 );
1429 dc.DrawLine( lpen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1430 dc.DrawLine( lpen, mid_x - 3, mid_y - 4, mid_x + 3, mid_y - 4 );
1431 dc.DrawLine( lpen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1433 Pen spen = ResPool.GetPen( Color.White );
1434 dc.DrawLine( spen, mid_x - 3, mid_y - 1, mid_x + 3, mid_y - 1 );
1435 dc.DrawLine( spen, mid_x - 3, mid_y - 5, mid_x + 3, mid_y - 5 );
1436 dc.DrawLine( spen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1441 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1442 Internal_DrawButton (dc, area, BorderColor);
1444 // draw grip lines only if stere is enough space
1445 if ( area.Width > 20 )
1447 int mid_x = area.X + ( area.Width / 2 );
1448 int mid_y = area.Y + ( area.Height / 2 );
1450 Pen lpen = ResPool.GetSizedPen( MouseOverColor, 2 );
1451 dc.DrawLine( lpen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1452 dc.DrawLine( lpen, mid_x - 4, mid_y - 3, mid_x - 4, mid_y + 3 );
1453 dc.DrawLine( lpen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1455 Pen spen = ResPool.GetPen( Color.White );
1456 dc.DrawLine( spen, mid_x - 1, mid_y - 3, mid_x - 1, mid_y + 3 );
1457 dc.DrawLine( spen, mid_x - 5, mid_y - 3, mid_x - 5, mid_y + 3 );
1458 dc.DrawLine( spen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1465 /* Nice scroll button */
1466 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type )
1468 Pen pen = ResPool.GetPen( BorderColor );
1470 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
1474 if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed )
1475 use_color = PressedColor;
1477 use_color = NormalColor;
1479 Point[] points = null;
1481 LinearGradientBrush lgbr = null;
1483 switch ( scroll_button_type )
1485 case ScrollButton.Left:
1486 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 1, area.Y ), use_color, Color.White );
1487 lgbr.Blend = FlatBlend;
1488 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1490 points = new Point[] {
1491 new Point( area.X + 2, area.Y ),
1492 new Point( area.Right - 1, area.Y ),
1493 new Point( area.Right - 1, area.Bottom - 1 ),
1494 new Point( area.X + 2, area.Bottom - 1 ),
1495 new Point( area.X, area.Bottom - 3 ),
1496 new Point( area.X, area.Y + 2 ),
1497 new Point( area.X + 2, area.Y )
1499 dc.DrawPolygon( pen, points );
1501 case ScrollButton.Right:
1502 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 1, area.Y ), Color.White, use_color );
1503 lgbr.Blend = NormalBlend;
1504 dc.FillRectangle( lgbr, area.X, area.Y + 1, area.Width - 1, area.Height - 2 );
1506 points = new Point[] {
1507 new Point( area.X, area.Y ),
1508 new Point( area.Right - 3, area.Y ),
1509 new Point( area.Right - 1, area.Y + 2 ),
1510 new Point( area.Right - 1, area.Bottom - 3 ),
1511 new Point( area.Right - 3, area.Bottom - 1 ),
1512 new Point( area.X, area.Bottom - 1 ),
1513 new Point( area.X, area.Y ),
1515 dc.DrawPolygon( pen, points );
1517 case ScrollButton.Up:
1518 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), use_color, Color.White );
1519 lgbr.Blend = FlatBlend;
1520 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1522 points = new Point[] {
1523 new Point( area.X + 2, area.Y ),
1524 new Point( area.Right - 3, area.Y ),
1525 new Point( area.Right - 1, area.Y + 2 ),
1526 new Point( area.Right - 1, area.Bottom - 1 ),
1527 new Point( area.X, area.Bottom - 1 ),
1528 new Point( area.X, area.Y + 2 ),
1529 new Point( area.X + 2, area.Y )
1531 dc.DrawPolygon( pen, points );
1533 case ScrollButton.Down:
1534 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), Color.White, use_color );
1535 lgbr.Blend = NormalBlend;
1536 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1538 points = new Point[] {
1539 new Point( area.X, area.Y ),
1540 new Point( area.Right - 1, area.Y ),
1541 new Point( area.Right - 1, area.Bottom - 3 ),
1542 new Point( area.Right - 3, area.Bottom - 1 ),
1543 new Point( area.X + 2, area.Bottom - 1 ),
1544 new Point( area.X, area.Bottom - 3 ),
1545 new Point( area.X, area.Y )
1547 dc.DrawPolygon( pen, points );
1555 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
1557 StringFormat text_format;
1563 rect = box.ClientRectangle;
1565 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
1567 text_format = new StringFormat();
1568 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1570 size = dc.MeasureString (box.Text, box.Font);
1571 width = (int) size.Width;
1573 if (width > box.Width - 16)
1574 width = box.Width - 16;
1576 y = box.Font.Height / 2;
1578 Pen pen = ResPool.GetPen( BorderColor );
1581 Point[] points = new Point[] {
1582 new Point( 8 + width, y ),
1583 new Point( box.Width - 3, y ),
1584 new Point( box.Width - 1, y + 2 ),
1585 new Point( box.Width - 1, box.Height - 3 ),
1586 new Point( box.Width - 3, box.Height - 1 ),
1587 new Point( 2, box.Height - 1 ),
1588 new Point( 0, box.Height - 3 ),
1589 new Point( 0, y + 2 ),
1593 dc.DrawLines( pen, points );
1597 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1599 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
1600 new RectangleF (10, 0, width, box.Font.Height), text_format);
1602 text_format.Dispose ();