// Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Copyright (c) 2004 Novell, Inc. // // Authors: // Jordi Mas i Hernandez, jordi@ximian.com // Peter Bartok, pbartok@novell.com // // // // $Revision: 1.35 $ // $Modtime: $ // $Log: ThemeWin32Classic.cs,v $ // Revision 1.35 2004/09/07 17:12:26 jordi // GroupBox control // // Revision 1.34 2004/09/07 09:40:15 jordi // LinkLabel fixes, methods, multiple links // // Revision 1.33 2004/09/05 08:03:51 jordi // fixes bugs, adds flashing on certain situations // // Revision 1.32 2004/09/02 16:32:54 jordi // implements resource pool for pens, brushes, and hatchbruses // // Revision 1.31 2004/08/25 20:04:40 ravindra // Added the missing divider code and grip for ToolBar Control. // // Revision 1.30 2004/08/25 18:29:14 jordi // new methods, properties, and fixes for progressbar // // Revision 1.29 2004/08/25 00:43:13 ravindra // Fixed wrapping related issues in ToolBar control. // // Revision 1.28 2004/08/24 18:37:02 jordi // fixes formmating, methods signature, and adds missing events // // Revision 1.27 2004/08/24 16:16:46 jackson // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes // // Revision 1.26 2004/08/21 01:52:08 ravindra // Improvments in mouse event handling in the ToolBar control. // // Revision 1.25 2004/08/20 00:12:51 jordi // fixes methods signature // // Revision 1.24 2004/08/19 22:25:31 jordi // theme enhancaments // // Revision 1.23 2004/08/18 19:16:53 jordi // Move colors to a table // // Revision 1.22 2004/08/17 19:29:11 jackson // Don't use KnownColor to create colours. It has a large startup time. // // Revision 1.21 2004/08/15 23:20:54 ravindra // Changes to Theme for ToolBar control and also dos2unix format. // // Revision 1.20 2004/08/13 21:22:18 jordi // removes redundant code and fixes issues with tickposition // // Revision 1.19 2004/08/12 20:29:01 jordi // Trackbar enhancement, fix mouse problems, highli thumb, etc // // Revision 1.18 2004/08/12 18:54:37 jackson // Handle owner draw status bars // // Revision 1.17 2004/08/11 01:31:35 jackson // Create Brushes as little as possible // // Revision 1.16 2004/08/10 19:21:27 jordi // scrollbar enhancements and standarize on win colors defaults // // Revision 1.15 2004/08/10 18:52:30 jackson // Implement DrawItem functionality // // Revision 1.14 2004/08/09 21:34:54 jackson // Add support for drawing status bar and get status bar item sizes // // Revision 1.13 2004/08/09 21:21:49 jackson // Use known colors for default control colours // // Revision 1.12 2004/08/09 21:12:15 jackson // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow. // // Revision 1.11 2004/08/09 17:31:13 jackson // New names for control properties // // Revision 1.10 2004/08/09 17:00:00 jackson // Add default window color properties // // Revision 1.9 2004/08/09 16:17:19 jackson // Use correct default back color // // Revision 1.8 2004/08/09 15:53:12 jackson // Themes now handle default control properties so coloring will be consistent // // Revision 1.7 2004/08/08 22:54:21 jordi // Label BorderStyles // // Revision 1.6 2004/08/08 18:09:53 jackson // Add pen_buttonface // // Revision 1.5 2004/08/08 17:34:28 jordi // Use Windows Standard Colours // // Revision 1.4 2004/08/07 23:31:15 jordi // fixes label bug and draw method name // // Revision 1.3 2004/08/07 19:05:44 jordi // Theme colour support and GetSysColor defines // // Revision 1.2 2004/08/07 00:01:39 pbartok // - Fixed some rounding issues with float/int // // Revision 1.1 2004/07/26 17:42:03 jordi // Theme support // // using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; namespace System.Windows.Forms { internal class ThemeWin32Classic : Theme { /* Default colors for Win32 classic theme */ uint [] theme_colors = { /* AARRGGBB */ (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND, 0xff008080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION, 0xff000080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION, 0xff808080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW, 0xffffffff, (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT, 0xffffffff, (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE, 0xff808080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT, 0xff000080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT, 0xffffffff, (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW, 0xff808080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT, 0xff808080, (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, 0xffc0c0c0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT, 0xffffffff, (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT, 0xffe0e0e0, (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT, 0xff000000, (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK, 0xffffffff, }; static protected Pen pen_ticks; static protected SolidBrush br_arrow; static protected SolidBrush br_progressbarblock; static protected Pen pen_arrow; /* Cache */ protected SolidBrush label_br_fore_color; protected SolidBrush label_br_back_color; public ThemeWin32Classic () { label_br_fore_color = null; label_br_back_color = null; /* Init Default colour array*/ syscolors = Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1); for (int i = 0; i < theme_colors.Length; i +=2) syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]); pen_ticks = new Pen (Color.Black); br_arrow = new SolidBrush (Color.Black); pen_arrow = new Pen (Color.Black); br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128)); defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10); defaultWindowForeColor = ColorButtonText; default_font = new Font (FontFamily.GenericSansSerif, 8.25f); } public override bool WriteToWindow { get {return false; } } public override int SizeGripWidth { get { return 15; } } public override int StatusBarHorzGapWidth { get { return 3; } } public override int ScrollBarButtonSize { get { return 16; } } /* * ToolBar Control properties */ // Grip width for the ToolBar public override int ToolBarGripWidth { get { return 2;} } // Grip width for the Image on the ToolBarButton public override int ToolBarImageGripWidth { get { return 2;} } // width of the separator public override int ToolBarSeparatorWidth { get { return 4; } } // width of the dropdown arrow rect public override int ToolBarDropDownWidth { get { return 13; } } // width for the dropdown arrow on the ToolBarButton public override int ToolBarDropDownArrowWidth { get { return 5;} } // height for the dropdown arrow on the ToolBarButton public override int ToolBarDropDownArrowHeight { get { return 3;} } private enum DrawFrameControlStates { ButtonCheck = 0x0000, ButtonRadioImage = 0x0001, ButtonRadioMask = 0x0002, ButtonRadio = 0x0004, Button3State = 0x0008, ButtonPush = 0x0010, CaptionClose = 0x0000, CaptionMin = 0x0001, CaptionMax = 0x0002, CaptionRestore = 0x0004, CaptionHelp = 0x0008, MenuArrow = 0x0000, MenuCheck = 0x0001, MenuBullet = 0x0002, MenuArrowRight = 0x0004, ScrollUp = 0x0000, ScrollDown = 0x0001, ScrollLeft = 0x0002, ScrollRight = 0x0003, ScrollComboBox = 0x0005, ScrollSizeGrip = 0x0008, ScrollSizeGripRight = 0x0010, Inactive = 0x0100, Pushed = 0x0200, Checked = 0x0400, Transparent = 0x0800, Hot = 0x1000, AdjustRect = 0x2000, Flat = 0x4000, Mono = 0x8000 } private enum DrawFrameControlTypes { Caption = 1, Menu = 2, Scroll = 3, Button = 4 } /* Methods that mimic ControlPaint signature and draw basic objects */ public override void DrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth, ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle, Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor, int bottomWidth, ButtonBorderStyle bottomStyle) { DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left); DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top); DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right); DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom); } public override void DrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) { Pen penTopLeft; Pen penTopLeftInner; Pen penBottomRight; Pen penBottomRightInner; Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); bool doInner = false; if ((style & Border3DStyle.Adjust)!=0) { rect.Y-=2; rect.X-=2; rect.Width+=4; rect.Height+=4; } /* default to flat */ penTopLeft=SystemPens.ControlDark; penTopLeftInner=SystemPens.ControlDark; penBottomRight=SystemPens.ControlDark; penBottomRightInner=SystemPens.ControlDark; if ((style & Border3DStyle.RaisedOuter)!=0) { penTopLeft=SystemPens.ControlLightLight; penBottomRight=SystemPens.ControlDarkDark; if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) { doInner=true; } } else if ((style & Border3DStyle.SunkenOuter)!=0) { penTopLeft=SystemPens.ControlDarkDark; penBottomRight=SystemPens.ControlLightLight; if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) { doInner=true; } } if ((style & Border3DStyle.RaisedInner)!=0) { if (doInner) { penTopLeftInner=SystemPens.ControlLight; penBottomRightInner=SystemPens.ControlDark; } else { penTopLeft=SystemPens.ControlLightLight; penBottomRight=SystemPens.ControlDarkDark; } } else if ((style & Border3DStyle.SunkenInner)!=0) { if (doInner) { penTopLeftInner=SystemPens.ControlDark; penBottomRightInner=SystemPens.ControlLight; } else { penTopLeft=SystemPens.ControlDarkDark; penBottomRight=SystemPens.ControlLightLight; } } if ((sides & Border3DSide.Middle)!=0) { graphics.FillRectangle(SystemBrushes.Control, rect); } if ((sides & Border3DSide.Left)!=0) { graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-1, rect.Left, rect.Top); if (doInner) { graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-1, rect.Left+1, rect.Top); } } if ((sides & Border3DSide.Top)!=0) { graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-1, rect.Top); if (doInner) { if ((sides & Border3DSide.Left)!=0) { graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-1, rect.Top+1); } else { graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-1, rect.Top+1); } } } if ((sides & Border3DSide.Right)!=0) { graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1); if (doInner) { if ((sides & Border3DSide.Top)!=0) { graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-1); } else { graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-1); } } } if ((sides & Border3DSide.Bottom)!=0) { int left=rect.Left; if ((sides & Border3DSide.Left)!=0) { left+=1; } graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1); if (doInner) { if ((sides & Border3DSide.Right)!=0) { graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2); } else { graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-1, rect.Bottom-2); } } } } public override void DrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) { DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush; if ((state & ButtonState.Pushed)!=0) { dfcs |= DrawFrameControlStates.Pushed; } if ((state & ButtonState.Checked)!=0) { dfcs |= DrawFrameControlStates.Checked; } if ((state & ButtonState.Flat)!=0) { dfcs |= DrawFrameControlStates.Flat; } if ((state & ButtonState.Inactive)!=0) { dfcs |= DrawFrameControlStates.Inactive; } DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs); } public override void DrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) { Rectangle captionRect; int lineWidth; DrawButton(graphics, rectangle, state); if (rectangle.Width127) { foreColor=Color.Black; } else { foreColor=Color.White; } #if false /* Commented out until I take the time and figure out which HatchStyle will match requirements. The code below is only correct for Percent50. */ if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) { HatchBrush brush=null; switch(pixelsBetweenDots.Width) { case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break; case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break; case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break; default: { /* Have to do it the slow way */ break; } } if (brush!=null) { graphics.FillRectangle(brush, area); pen.Dispose(); brush.Dispose(); return; } } #endif /* Slow method */ Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics); for (int x=0; x 256 colors on the display. */ ImageAttributes imageAttributes=new ImageAttributes(); ColorMatrix colorMatrix=new ColorMatrix(new float[][] { // This table would create a perfect grayscale image, based on luminance // new float[]{0.3f,0.3f,0.3f,0,0}, // new float[]{0.59f,0.59f,0.59f,0,0}, // new float[]{0.11f,0.11f,0.11f,0,0}, // new float[]{0,0,0,1,0,0}, // new float[]{0,0,0,0,1,0}, // new float[]{0,0,0,0,0,1} // This table generates a image that is grayscaled and then // brightened up. Seems to match MS close enough. new float[]{0.2f,0.2f,0.2f,0,0}, new float[]{0.41f,0.41f,0.41f,0,0}, new float[]{0.11f,0.11f,0.11f,0,0}, new float[]{0.15f,0.15f,0.15f,1,0,0}, new float[]{0.15f,0.15f,0.15f,0,1,0}, new float[]{0.15f,0.15f,0.15f,0,0,1} }); imageAttributes.SetColorMatrix(colorMatrix); graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes); imageAttributes.Dispose(); } public override void DrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) { Pen penBorder; Pen penInside; if (primary) { penBorder=new Pen(Color.White, 2); penInside=new Pen(Color.Black, 1); } else { penBorder=new Pen(Color.Black, 2); penInside=new Pen(Color.White, 1); } penBorder.Alignment=PenAlignment.Inset; penInside.Alignment=PenAlignment.Inset; graphics.DrawRectangle(penBorder, rectangle); graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5); penBorder.Dispose(); penInside.Dispose(); } public override void DrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) { Rectangle rect; int lineWidth; // MS seems to draw the background white graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rectangle); switch(glyph) { case MenuGlyph.Arrow: { Point[] arrow = new Point[3]; Point P1; Point P2; Point P3; int centerX; int centerY; int shiftX; int shiftY; rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2); centerX=rect.Left+rect.Width/2; centerY=rect.Top+rect.Height/2; shiftX=Math.Max(1, rect.Width/8); shiftY=Math.Max(1, rect.Height/8); rect.X-=shiftX; centerX-=shiftX; P1=new Point(centerX, rect.Top-1); P2=new Point(centerX, rect.Bottom); P3=new Point(rect.Right, centerY); arrow[0]=P1; arrow[1]=P2; arrow[2]=P3; graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding); return; } case MenuGlyph.Bullet: { SolidBrush sb; lineWidth=Math.Max(2, rectangle.Width/3); rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2); sb=ResPool.GetSolidBrush (ColorButtonText); graphics.FillEllipse(sb, rect); sb.Dispose(); return; } case MenuGlyph.Checkmark: { int Scale; lineWidth=Math.Max(2, rectangle.Width/6); Scale=Math.Max(1, rectangle.Width/12); rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2); for (int i=0; i= channel_startpoint.Y) value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks); else value_pos = 0; if (value_pos + tb.Minimum > tb.Maximum) value_pos = tb.Maximum - tb.Minimum; tb.Value = value_pos + tb.Minimum; } thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos); /* Draw thumb fixed 10x22 size */ thumb_pos.Width = 10; thumb_pos.Height = 22; switch (tb.TickStyle) { case TickStyle.BottomRight: case TickStyle.None: { thumb_pos.X = channel_startpoint.X - 8; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8); dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6); dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4); dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2); break; } case TickStyle.TopLeft: { thumb_pos.X = channel_startpoint.X - 10; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10); dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8); dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6); dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2); break; } case TickStyle.Both: { thumb_pos.X = area.X + 10; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8); break; } default: break; } pixel_len = thumb_area.Height - 11; pixels_betweenticks = pixel_len / ticks; /* Draw ticks*/ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight || ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) { if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1) dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc, area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc); else dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc, area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc); } } if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft || ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { pixel_len = thumb_area.Height - 11; pixels_betweenticks = pixel_len / ticks; for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) { //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks ); if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1) dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc, area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc); else dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc, area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc); } } } /* Horizontal trackbar Does not matter the size of the control, Win32 always draws: - Ticks starting from pixel 13, 8 - Channel starting at pos 8, 19 and ends at Width - 8 - Autosize makes always the control 40 pixels height - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum) */ private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb, ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb, float ticks, int value_pos, bool mouse_value) { Point toptick_startpoint = new Point (); Point bottomtick_startpoint = new Point (); Point channel_startpoint = new Point (); float pixel_len; float pixels_betweenticks; const int space_from_right = 8; const int space_from_left = 8; switch (tb.TickStyle) { case TickStyle.BottomRight: case TickStyle.None: channel_startpoint.X = 8; channel_startpoint.Y = 9; bottomtick_startpoint.X = 13; bottomtick_startpoint.Y = 24; break; case TickStyle.TopLeft: channel_startpoint.X = 8; channel_startpoint.Y = 19; toptick_startpoint.X = 13; toptick_startpoint.Y = 8; break; case TickStyle.Both: channel_startpoint.X = 8; channel_startpoint.Y = 18; bottomtick_startpoint.X = 13; bottomtick_startpoint.Y = 32; toptick_startpoint.X = 13; toptick_startpoint.Y = 8; break; default: break; } thumb_area.X = area.X + channel_startpoint.X; thumb_area.Y = area.Y + channel_startpoint.Y; thumb_area.Width = area.Width - space_from_right - space_from_left; thumb_area.Height = 4; /* Draw channel */ dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y, thumb_area.Width, 1); dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1, thumb_area.Width, 1); dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3, thumb_area.Width, 1); pixel_len = thumb_area.Width - 11; pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum); /* Convert thumb position from mouse position to value*/ if (mouse_value) { if (value_pos >= channel_startpoint.X) value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks); else value_pos = 0; if (value_pos + tb.Minimum > tb.Maximum) value_pos = tb.Maximum - tb.Minimum; tb.Value = value_pos + tb.Minimum; } thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos); /* Draw thumb fixed 10x22 size */ thumb_pos.Width = 10; thumb_pos.Height = 22; switch (tb.TickStyle) { case TickStyle.BottomRight: case TickStyle.None: { thumb_pos.Y = channel_startpoint.Y - 8; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16); dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1); dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1); dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1); break; } case TickStyle.TopLeft: { thumb_pos.Y = channel_startpoint.Y - 10; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15); dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1); dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1); dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1); break; } case TickStyle.Both: { thumb_pos.Y = area.Y + 10; dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19); dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20); dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20); dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18); break; } default: break; } pixel_len = thumb_area.Width - 11; pixels_betweenticks = pixel_len / ticks; /* Draw ticks*/ if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight || ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) { if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1) dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3); else dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2); } } if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft || ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) { if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1) dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y); else dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y ); } } } public override void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb, ref Rectangle thumb_pos, ref Rectangle thumb_area, bool highli_thumb, float ticks, int value_pos, bool mouse_value) { Brush br_thumb; if (highli_thumb == true) br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace); else br_thumb = ResPool.GetSolidBrush (ColorButtonFace); /* Control Background */ if (tb.BackColor == DefaultControlBackColor) dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area); else dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area); if (tb.Focused) { dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1); dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1); dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1); dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1); } if (tb.Orientation == Orientation.Vertical) DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area, br_thumb, ticks, value_pos, mouse_value); else DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area, br_thumb, ticks, value_pos, mouse_value); } public override void DrawProgressBar (Graphics dc, Rectangle area, Rectangle client_area, int barpos_pixels, int block_width) { int space_betweenblocks = 2; int increment = block_width + space_betweenblocks; int x = client_area.X; /* Draw border */ DrawBorder3D (dc, area, Border3DStyle.SunkenInner, Border3DSide.All); /* Draw Blocks */ while ((x - client_area.X) < barpos_pixels) { dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height); x = x + increment; } } public override void DrawLabel (Graphics dc, Rectangle area, BorderStyle border_style, string text, Color fore_color, Color back_color, Font font, StringFormat string_format, bool Enabled) { if (label_br_fore_color == null || label_br_fore_color.Color != fore_color) label_br_fore_color = GetControlForeBrush (fore_color); if (label_br_back_color == null || label_br_back_color.Color != back_color) label_br_back_color = GetControlBackBrush (back_color); dc.FillRectangle (label_br_back_color, area); DrawBorderStyle (dc, area, border_style); if (Enabled) dc.DrawString (text, font, label_br_fore_color, area, string_format); else ControlPaint.DrawStringDisabled (dc, text, font, fore_color, area, string_format); } public override void DrawStatusBar (Graphics dc, Rectangle area, StatusBar sb) { int horz_border = 2; int vert_border = 2; dc.FillRectangle (GetControlBackBrush (sb.BackColor), area); if (sb.ShowPanels && sb.Panels.Count == 0) { // Create a default panel. SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor); StatusBarPanel panel = new StatusBarPanel (); Rectangle new_area = new Rectangle (area.X + horz_border, area.Y + horz_border, area.Width - SizeGripWidth - horz_border, area.Height - horz_border); DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel); } else if (sb.ShowPanels) { SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor); int prev_x = area.X + horz_border; int y = area.Y + vert_border; for (int i = 0; i < sb.Panels.Count; i++) { Rectangle pr = new Rectangle (prev_x, y, sb.Panels [i].Width, area.Height); prev_x += pr.Width + StatusBarHorzGapWidth; DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]); } } if (sb.SizingGrip) DrawSizeGrip (dc, ColorButtonFace, area); } public override void DrawStatusBarPanel (Graphics dc, Rectangle area, int index, SolidBrush br_forecolor, StatusBarPanel panel) { int border_size = 3; // this is actually const, even if the border style is none area.Height -= border_size; if (panel.BorderStyle != StatusBarPanelBorderStyle.None) { Border3DStyle border_style = Border3DStyle.SunkenInner; if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised) border_style = Border3DStyle.RaisedOuter; DrawBorder3D(dc, area, border_style, Border3DSide.All); } if (panel.Style == StatusBarPanelStyle.OwnerDraw) { StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs ( dc, panel.Parent.Font, area, index, DrawItemState.Default, panel, panel.Parent.ForeColor, panel.Parent.BackColor); panel.Parent.OnDrawItemInternal (e); return; } int left = area.Left; if (panel.Icon != null) { left += 2; int size = area.Height - border_size; Rectangle ia = new Rectangle (left, border_size, size, size); dc.DrawIcon (panel.Icon, left, area.Top); left += panel.Icon.Width; } if (panel.Text == String.Empty) return; string text = panel.Text; StringFormat string_format = new StringFormat (); string_format.LineAlignment = StringAlignment.Center; string_format.Alignment = StringAlignment.Near; string_format.FormatFlags = StringFormatFlags.NoWrap; if (text [0] == '\t') { string_format.Alignment = StringAlignment.Center; text = text.Substring (1); if (text [0] == '\t') { string_format.Alignment = StringAlignment.Far; text = text.Substring (1); } } float x = left + border_size; float y = ((area.Bottom - area.Top) / 2.0F) + border_size; dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format); } public override void DrawPictureBox (Graphics dc, PictureBox pb) { Rectangle client = pb.ClientRectangle; int x, y, width, height; dc.FillRectangle (new SolidBrush (pb.BackColor), client); DrawBorderStyle (dc, client, pb.BorderStyle); x = y = 0; switch (pb.SizeMode) { case PictureBoxSizeMode.StretchImage: width = client.Width; height = client.Height; break; case PictureBoxSizeMode.CenterImage: width = client.Width; height = client.Height; x = width / 2; y = (height - pb.Image.Height) / 2; break; default: // Normal, AutoSize width = client.Width; height = client.Height; break; } dc.DrawImage (pb.Image, x, y, width, height); } public override void DrawOwnerDrawBackground (DrawItemEventArgs e) { if (e.State == DrawItemState.Selected) { e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds); return; } e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds); } public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e) { if (e.State == DrawItemState.Focus) DrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor); } public override void DrawToolBar (Graphics dc, ToolBar control, StringFormat format) { // Exclude the area for divider Rectangle paint_area = new Rectangle (0, ThemeEngine.Current.ToolBarGripWidth / 2, control.Width, control.Height - ThemeEngine.Current.ToolBarGripWidth / 2); bool flat = (control.Appearance == ToolBarAppearance.Flat); dc.FillRectangle (SystemBrushes.Control, paint_area); DrawBorderStyle (dc, paint_area, control.BorderStyle); if (control.Divider) dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0); foreach (ToolBarButton button in control.Buttons) { Image image = null; Rectangle buttonArea = button.Rectangle; Rectangle imgRect = Rectangle.Empty; // rect to draw the image Rectangle txtRect = buttonArea; // rect to draw the text Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow // calculate different rects and draw the frame if its not separator button if (button.Style != ToolBarButtonStyle.Separator) { /* Adjustment for drop down arrow */ if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) { ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth; ddRect.Y = buttonArea.Y; ddRect.Width = this.ToolBarDropDownWidth; ddRect.Height = buttonArea.Height; } // calculate txtRect and imgRect, if imageIndex and imageList are present if (button.ImageIndex > -1 && control.ImageList != null) { if (button.ImageIndex < control.ImageList.Images.Count) image = control.ImageList.Images [button.ImageIndex]; // draw the image at the centre if textalignment is underneath if (control.TextAlign == ToolBarTextAlign.Underneath) { imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width - control.ImageSize.Width) / 2) + this.ToolBarImageGripWidth; imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth; imgRect.Width = control.ImageSize.Width; imgRect.Height = control.ImageSize.Height; txtRect.X = buttonArea.X; txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth; txtRect.Width = buttonArea.Width - ddRect.Width; txtRect.Height = buttonArea.Height - imgRect.Height - 2 * this.ToolBarImageGripWidth; } else { imgRect.X = buttonArea.X + this.ToolBarImageGripWidth; imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth; imgRect.Width = control.ImageSize.Width; imgRect.Height = control.ImageSize.Height; txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth; txtRect.Y = buttonArea.Y; txtRect.Width = buttonArea.Width - imgRect.Width - 2 * this.ToolBarImageGripWidth - ddRect.Width; txtRect.Height = buttonArea.Height; } } /* Draw the button frame, only if it is not a separator */ if (flat) { if (button.Pushed || button.Pressed) ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All); else if (button.Hilight) { dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea); if (! ddRect.IsEmpty) { dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X, ddRect.Y + ddRect.Height); buttonArea.Width -= this.ToolBarDropDownWidth; } } } else { // normal toolbar if (button.Pushed || button.Pressed) { ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner, Border3DSide.All); if (! ddRect.IsEmpty) { ControlPaint.DrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner, Border3DSide.Left); buttonArea.Width -= this.ToolBarDropDownWidth; } } else { ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner, Border3DSide.All); if (! ddRect.IsEmpty) { ControlPaint.DrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner, Border3DSide.Left); buttonArea.Width -= this.ToolBarDropDownWidth; } } } } DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea, imgRect, image, txtRect, ddRect, flat); } } public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) { SizeF size; int width, y; Rectangle rect = box.ClientRectangle; Color disabled = ThemeEngine.Current.ColorGrayText; Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255)); Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128)); // TODO: When the Light and Dark methods work this code should be activate it //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1)); //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0)); dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect); size = dc.MeasureString (box.Text, box.Font); width = (int) size.Width; if (width > box.Width - 16) width = box.Width - 16; y = box.Font.Height / 2; /* Draw group box*/ dc.DrawLine (pen_dark, 0, y, 8, y); // top dc.DrawLine (pen_light, 0, y + 1, 8, y + 1); dc.DrawLine (pen_dark, 8 + width, y, box.Width, y); dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1); dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left dc.DrawLine (pen_light, 1, y + 1, 1, box.Height); dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1); dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2); /* Text */ if (box.Enabled) dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0); else DrawStringDisabled (dc, box.Text, box.Font, box.ForeColor, new RectangleF (10, 0, width, box.Font.Height), new StringFormat ()); } /* * Private methods */ private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format, Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect, Image image, Rectangle txtRect, Rectangle ddRect, bool flat) { if (! button.Visible) return; switch (button.Style) { case ToolBarButtonStyle.Separator: // separator is drawn only in the case of flat appearance if (flat) { dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y, buttonArea.X + 1, buttonArea.Height); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height); /* draw a horizontal separator */ if (button.Wrapper) { int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2; dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y); dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width); } } break; case ToolBarButtonStyle.ToggleButton: Rectangle toggleArea = Rectangle.Empty; toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth; toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth; toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth; toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth; if (button.PartialPush && button.Pushed) { dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea); if (! imgRect.IsEmpty) { if (button.Enabled && image != null) button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, button.ImageIndex); else { dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect); ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter, Border3DSide.Right | Border3DSide.Bottom); } } if (button.Enabled) dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format); else ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight, txtRect, format); } else if (button.PartialPush) { dc.FillRectangle (SystemBrushes.ControlLight, toggleArea); if (! imgRect.IsEmpty) { if (button.Enabled && image != null) button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, button.ImageIndex); else { dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect); ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter, Border3DSide.Right | Border3DSide.Bottom); } } if (button.Enabled) dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format); else ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight, txtRect, format); } else if (button.Pushed) { dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea); if (! imgRect.IsEmpty) { if (button.Enabled && image != null) button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, button.ImageIndex); else { dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect); ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter, Border3DSide.Right | Border3DSide.Bottom); } } if (button.Enabled) dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format); else ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight, txtRect, format); } else { dc.FillRectangle (SystemBrushes.Control, toggleArea); //dc.FillRectangle (new SolidBrush (Color.FromArgb(255, 180, 190, 214)), toggleArea); if (! imgRect.IsEmpty) { if (button.Enabled && image != null) button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, button.ImageIndex); else { dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect); ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter, Border3DSide.Right | Border3DSide.Bottom); } } if (button.Enabled) dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format); else ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight, txtRect, format); } break; case ToolBarButtonStyle.DropDownButton: // draw the dropdown arrow if (! ddRect.IsEmpty) { PointF [] vertices = new PointF [3]; PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f)); vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f; vertices [0].Y = ddCenter.Y; vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f; vertices [1].Y = ddCenter.Y; vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight; dc.FillPolygon (SystemBrushes.ControlText, vertices); } goto case ToolBarButtonStyle.PushButton; case ToolBarButtonStyle.PushButton: if (! imgRect.IsEmpty){ if (button.Enabled && image != null) button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height, button.ImageIndex); else { dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect); ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter, Border3DSide.Right | Border3DSide.Bottom); } } if (button.Enabled) dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format); else ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight, txtRect, format); break; } } private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY, int width, Color color, ButtonBorderStyle style, Border3DSide side) { Pen pen=new Pen(color, 1); switch(style) { case ButtonBorderStyle.Solid: { pen.DashStyle=DashStyle.Solid; break; } case ButtonBorderStyle.Dashed: { pen.DashStyle=DashStyle.Dash; break; } case ButtonBorderStyle.Dotted: { pen.DashStyle=DashStyle.Dot; break; } case ButtonBorderStyle.Inset: { pen.DashStyle=DashStyle.Solid; break; } case ButtonBorderStyle.Outset: { pen.DashStyle=DashStyle.Solid; break; } default: case ButtonBorderStyle.None: { pen.Dispose(); return; } } switch(style) { case ButtonBorderStyle.Outset: { Color colorGrade; int hue, brightness, saturation; int brightnessSteps; int brightnessDownSteps; ControlPaint.Color2HBS(color, out hue, out brightness, out saturation); brightnessDownSteps=brightness/width; if (brightness>127) { brightnessSteps=Math.Max(6, (160-brightness)/width); } else { brightnessSteps=(127-brightness)/width; } for (int i=0; i127) { brightnessSteps=Math.Max(6, (160-brightness)/width); } else { brightnessSteps=(127-brightness)/width; } for (int i=0; i