| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396 |
- // 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, [email protected]
- // Peter Bartok, [email protected]
- //
- //
- //
- // $Revision: 1.26 $
- // $Modtime: $
- // $Log: ThemeWin32Classic.cs,v $
- // 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 Pen pen_disabled;
- static protected SolidBrush br_arrow;
- static protected SolidBrush br_disabled;
- static protected HatchBrush br_focus;
- static protected SolidBrush br_progressbarblock;
- static protected Pen pen_arrow;
- static protected SolidBrush br_buttonface;
- static protected SolidBrush br_buttonshadow;
- static protected SolidBrush br_buttondkshadow;
- static protected SolidBrush br_buttonhilight;
- static protected SolidBrush br_buttontext;
- static protected SolidBrush br_menutext;
- static protected Pen pen_buttonshadow;
- static protected Pen pen_buttondkshadow;
- static protected Pen pen_buttonhilight;
- static protected Pen pen_buttonface;
- static protected Pen pen_buttontext;
- static protected Pen pen_windowframe;
-
- /* Cache */
- protected SolidBrush label_br_fore_color;
- protected SolidBrush label_br_back_color;
- protected HatchBrush br_scrollbar_backgr;
- protected HatchBrush br_trackbar_thumbhili;
- protected SolidBrush br_trackbarbg;
- public ThemeWin32Classic ()
- {
- label_br_fore_color = null;
- label_br_back_color = null;
- br_scrollbar_backgr = null;
- br_trackbarbg = null;
- br_trackbar_thumbhili = 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);
- br_focus = new HatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black);
- pen_arrow = new Pen (Color.Black);
- br_progressbarblock = new SolidBrush (Color.FromArgb (255, 49, 106, 197));
- br_buttonface = new SolidBrush (ColorButtonFace);
- br_buttonshadow = new SolidBrush (ColorButtonShadow);
- br_buttondkshadow = new SolidBrush (ColorButtonDkShadow);
- br_buttonhilight = new SolidBrush (ColorButtonHilight);
- br_buttontext = new SolidBrush (ColorButtonText);
- pen_buttonshadow = new Pen (ColorButtonShadow);
- pen_buttondkshadow = new Pen (ColorButtonDkShadow);
- pen_buttonhilight = new Pen (ColorButtonHilight);
- pen_buttonface = new Pen (ColorButtonFace);
- pen_buttontext = new Pen (ColorButtonText);
- pen_windowframe = new Pen (ColorWindowFrame);
- 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 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.Width<rectangle.Height) {
- captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
- } else {
- captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
- }
- if ((state & ButtonState.Pushed)!=0) {
- captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
- }
- /* Make sure we've got at least a line width of 1 */
- lineWidth=Math.Max(1, captionRect.Width/7);
- switch(button) {
- case CaptionButton.Close: {
- Pen pen;
- if ((state & ButtonState.Inactive)!=0) {
- pen=new Pen(ColorButtonHilight, lineWidth);
- DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
- pen.Dispose();
- pen=new Pen(ColorButtonShadow, lineWidth);
- DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
- pen.Dispose();
- return;
- } else {
- pen=new Pen(SystemColors.ControlText, lineWidth);
- DrawCaptionHelper(graphics, SystemColors.ControlText, pen, lineWidth, 0, captionRect, button);
- pen.Dispose();
- return;
- }
- }
- case CaptionButton.Help:
- case CaptionButton.Maximize:
- case CaptionButton.Minimize:
- case CaptionButton.Restore: {
- if ((state & ButtonState.Inactive)!=0) {
- DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
- DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
- return;
- } else {
- DrawCaptionHelper(graphics, SystemColors.ControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
- return;
- }
- }
- }
- }
- public override void DrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
- {
- DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
- 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 DrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
- {
- Point[] arrow = new Point[3];
- Point P1;
- Point P2;
- Point P3;
- int centerX;
- int centerY;
- int shiftX;
- int shiftY;
- Rectangle rect;
- if ((state & ButtonState.Checked)!=0) {
- HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, ColorButtonHilight);
- graphics.FillRectangle(hatchBrush,rectangle);
- hatchBrush.Dispose();
- }
- if ((state & ButtonState.Flat)!=0) {
- ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
- } else {
- if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
- DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- } else {
- DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- }
- }
- 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);
- if ((state & ButtonState.Pushed)!=0) {
- shiftX++;
- shiftY++;
- }
- rect.Y-=shiftY;
- centerY-=shiftY;
- P1=new Point(rect.Left, centerY);
- P2=new Point(rect.Right, centerY);
- P3=new Point(centerX, rect.Bottom);
- arrow[0]=P1;
- arrow[1]=P2;
- arrow[2]=P3;
- /* Draw the arrow */
- if ((state & ButtonState.Inactive)!=0) {
- graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
- /* Move away from the shadow */
- P1.X-=1; P1.Y-=1;
- P2.X-=1; P2.Y-=1;
- P3.X-=1; P3.Y-=1;
- arrow[0]=P1;
- arrow[1]=P2;
- arrow[2]=P3;
- graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
- } else {
- graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
- }
- }
- public override void DrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
- {
- SolidBrush sb = br_buttontext;
- Pen pen = new Pen(Color.Black, 1);
- Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
- int X;
- int Y;
- graphics.FillRectangle(sb, rect);
- graphics.DrawRectangle(pen, rect);
- X=rect.X+rect.Width/2;
- Y=rect.Y+rect.Height/2;
- /* Draw the cross */
- graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
- graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
- /* Draw 'arrows' for vertical lines */
- graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
- graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
- /* Draw 'arrows' for horizontal lines */
- graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
- graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
- }
- public override void DrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
- {
- //Color colorForeInverted;
- Color colorBackInverted;
- Pen pen;
- //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
- //pen=new Pen(colorForeInverted, 1);
- // MS seems to always use black
- pen=new Pen(Color.Black, 1);
- graphics.DrawRectangle(pen, rectangle);
- pen.Dispose();
- colorBackInverted=Color.FromArgb(Math.Abs(backColor.R-255), Math.Abs(backColor.G-255), Math.Abs(backColor.B-255));
- pen=new Pen(colorBackInverted, 1);
- pen.DashStyle=DashStyle.Dot;
- graphics.DrawRectangle(pen, rectangle);
- pen.Dispose();
- }
- public override void DrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
- {
- SolidBrush sb;
- Pen pen;
- if (primary==true) {
- pen=new Pen(Color.Black, 1);
- if (enabled==true) {
- sb=br_buttontext;
- } else {
- sb=br_buttonface;
- }
- } else {
- pen=new Pen(Color.White, 1);
- if (enabled==true) {
- sb=new SolidBrush(Color.Black);
- } else {
- sb=br_buttonface;
- }
- }
- graphics.FillRectangle(sb, rectangle);
- graphics.DrawRectangle(pen, rectangle);
- sb.Dispose();
- pen.Dispose();
- }
- public override void DrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor)
- {
- Color foreColor;
- int h;
- int b;
- int s;
- ControlPaint.Color2HBS(backColor, out h, out b, out s);
- if (b>127) {
- 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<area.Width; x+=pixelsBetweenDots.Width) {
- for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
- bitmap.SetPixel(x, y, foreColor);
- }
- }
- graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
- bitmap.Dispose();
- }
- public override void DrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background)
- {
- /*
- Microsoft seems to ignore the background and simply make
- the image grayscale. At least when having > 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(br_buttontext, 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=br_buttontext;
- 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<lineWidth; i++) {
- graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
- graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
- }
- return;
- }
- }
- }
- public override void DrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state)
- {
- DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
- 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 DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
- {
- }
- public override void DrawReversibleLine (Point start, Point end, Color backColor)
- {
- }
- /* Scroll button: regular button + direction arrow */
- public override void DrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
- {
- bool enabled = (state == ButtonState.Inactive) ? false: true;
-
- DrawScrollButtonPrimitive (dc, area, state);
- /* Paint arrows */
- switch (type) {
- case ScrollButton.Up:
- {
- int x = area.X + (area.Width / 2) - 4;
- int y = area.Y + 9;
- for (int i = 0; i < 3; i++)
- if (enabled)
- dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
- else
- dc.DrawLine (pen_disabled, x + i, y - i, x + i + 6 - 2*i, y - i);
- if (enabled)
- dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);
- else
- dc.FillRectangle (br_disabled, x + 3, area.Y + 6, 1, 1);
- break;
- }
- case ScrollButton.Down:
- {
- int x = area.X + (area.Width / 2) - 4;
- int y = area.Y + 5;
- for (int i = 4; i != 0; i--)
- if (enabled)
- dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
- else
- dc.DrawLine (pen_disabled, x + i, y + i, x + i + 8 - 2*i, y + i);
- if (enabled)
- dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
- else
- dc.FillRectangle (br_disabled, x + 4, y + 4, 1, 1);
- break;
- }
- case ScrollButton.Left:
- {
- int y = area.Y + (area.Height / 2) - 4;
- int x = area.X + 9;
- for (int i = 0; i < 3; i++)
- if (enabled)
- dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
- else
- dc.DrawLine (pen_disabled, x - i, y + i, x - i, y + i + 6 - 2*i);
- if (enabled)
- dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
- else
- dc.FillRectangle (br_disabled, x - 3, y + 3, 1, 1);
- break;
- }
- case ScrollButton.Right:
- {
- int y = area.Y + (area.Height / 2) - 4;
- int x = area.X + 5;
- for (int i = 4; i != 0; i--)
- if (enabled)
- dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
- else
- dc.DrawLine (pen_disabled, x + i, y + i, x + i, y + i + 8 - 2*i);
- if (enabled)
- dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
- else
- dc.FillRectangle (br_disabled, x + 3, y + 3, 1, 1);
- break;
- }
- default:
- break;
- }
- }
- public override void DrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
- Color backColor)
- {
- }
- public override void DrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
- {
- Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
- dc.DrawLine (pen_buttonface, pt.X - 12, pt.Y, pt.X, pt.Y);
- dc.DrawLine (pen_buttonface, pt.X, pt.Y, pt.X, pt.Y - 13);
- // diagonals
- for (int i = 0; i < 11; i += 4) {
- dc.DrawLine (pen_buttonshadow, pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
- dc.DrawLine (pen_buttonshadow, pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
- }
- for (int i = 3; i < 13; i += 4)
- dc.DrawLine (pen_buttonhilight, pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
- }
- public override void DrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
- StringFormat format)
- {
- SolidBrush brush;
- brush=new SolidBrush(ControlPaint.Light(color, 25));
- layoutRectangle.Offset(1.0f, 1.0f);
- graphics.DrawString(s, font, brush, layoutRectangle, format);
- brush.Color=ControlPaint.Dark(color, 35);
- layoutRectangle.Offset(-1.0f, -1.0f);
- graphics.DrawString(s, font, brush, layoutRectangle, format);
- brush.Dispose();
- }
-
- /*
- Methods that draw complex controls
- */
- public override void DrawScrollBar (Graphics dc, Rectangle area, ScrollBar bar,
- Rectangle thumb_pos, ref Rectangle first_arrow_area, ref Rectangle second_arrow_area,
- ButtonState first_arrow, ButtonState second_arrow, ref int scrollbutton_width,
- ref int scrollbutton_height, bool vert)
- {
- if (br_scrollbar_backgr == null)
- br_scrollbar_backgr = new HatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
- if (vert) {
- first_arrow_area.X = first_arrow_area. Y = 0;
- first_arrow_area.Width = scrollbutton_width;
- first_arrow_area.Height = scrollbutton_height;
- second_arrow_area.X = 0;
- second_arrow_area.Y = area.Height - scrollbutton_height;
- second_arrow_area.Width = scrollbutton_width;
- second_arrow_area.Height = scrollbutton_height;
- /* Buttons */
- DrawScrollButton (dc, first_arrow_area, ScrollButton.Up, first_arrow);
- DrawScrollButton (dc, second_arrow_area, ScrollButton.Down, second_arrow);
- /* Background */
- dc.FillRectangle (br_scrollbar_backgr, 0, scrollbutton_height, area.Width,
- area.Height - (scrollbutton_height * 2));
- }
- else {
-
- first_arrow_area.X = first_arrow_area. Y = 0;
- first_arrow_area.Width = scrollbutton_width;
- first_arrow_area.Height = scrollbutton_height;
- second_arrow_area.Y = 0;
- second_arrow_area.X = area.Width - scrollbutton_width;
- second_arrow_area.Width = scrollbutton_width;
- second_arrow_area.Height = scrollbutton_height;
- /* Buttons */
- DrawScrollButton (dc, first_arrow_area, ScrollButton.Left, first_arrow );
- DrawScrollButton (dc, second_arrow_area, ScrollButton.Right, second_arrow);
- /* Background */
- dc.FillRectangle (br_scrollbar_backgr, scrollbutton_width, 0, area.Width - (scrollbutton_width * 2),
- area.Height);
- }
- /* Thumbail */
- if (bar.Enabled)
- DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
- }
- /*
- DrawTrackBar
- */
- /* Vertical trackbar */
- private void DrawTrackBar_Vertical (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.Y = 8;
- channel_startpoint.X = 9;
- bottomtick_startpoint.Y = 13;
- bottomtick_startpoint.X = 24;
- break;
- case TickStyle.TopLeft:
- channel_startpoint.Y = 8;
- channel_startpoint.X = 19;
- toptick_startpoint.Y = 13;
- toptick_startpoint.X = 8;
- break;
- case TickStyle.Both:
- channel_startpoint.Y = 8;
- channel_startpoint.X = 18;
- bottomtick_startpoint.Y = 13;
- bottomtick_startpoint.X = 32;
- toptick_startpoint.Y = 13;
- toptick_startpoint.X = 8;
- break;
- default:
- break;
- }
-
- thumb_area.X = area.X + channel_startpoint.X;
- thumb_area.Y = area.Y + channel_startpoint.Y;
- thumb_area.Height = area.Height - space_from_right - space_from_left;
- thumb_area.Width = 4;
- /* Draw channel */
- dc.FillRectangle (br_buttonshadow, channel_startpoint.X, channel_startpoint.Y,
- 1, thumb_area.Height);
-
- dc.FillRectangle (br_buttondkshadow, channel_startpoint.X + 1, channel_startpoint.Y,
- 1, thumb_area.Height);
- dc.FillRectangle (br_buttonhilight, channel_startpoint.X + 3, channel_startpoint.Y,
- 1, thumb_area.Height);
- pixel_len = thumb_area.Height - 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.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 (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
-
- dc.DrawLine (pen_buttonshadow, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
- dc.DrawLine (pen_buttondkshadow, 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 (pen_buttonhilight, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
- dc.DrawLine (pen_buttondkshadow, 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 (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
- dc.DrawLine (pen_buttondkshadow, 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 (br_buttonshadow, channel_startpoint.X, channel_startpoint.Y,
- thumb_area.Width, 1);
-
- dc.FillRectangle (br_buttondkshadow, channel_startpoint.X, channel_startpoint.Y + 1,
- thumb_area.Width, 1);
- dc.FillRectangle (br_buttonhilight, 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 (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
- dc.DrawLine (pen_buttondkshadow, 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 (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
- dc.DrawLine (pen_buttondkshadow, 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 (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
- dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
- dc.DrawLine (pen_buttonshadow, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
- dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
- dc.DrawLine (pen_buttondkshadow, 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) {
- if (br_trackbar_thumbhili == null)
- br_trackbar_thumbhili = new HatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
- br_thumb = (Brush) br_trackbar_thumbhili;
- }
- else
- br_thumb = br_buttonface;
-
- /* Control Background */
- if (tb.BackColor == DefaultControlBackColor)
- dc.FillRectangle (br_buttonface, area);
- else {
- if (br_trackbarbg == null || br_trackbarbg.Color != tb.BackColor)
- br_trackbarbg = new SolidBrush (tb.BackColor);
- dc.FillRectangle (br_trackbarbg, area);
- }
- if (tb.Focused) {
- dc.FillRectangle (br_focus, area.X, area.Y, area.Width - 1, 1);
- dc.FillRectangle (br_focus, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
- dc.FillRectangle (br_focus, area.X, area.Y, 1, area.Height - 1);
- dc.FillRectangle (br_focus, 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;
- /* Background*/
- dc.FillRectangle (br_buttonface, area);
- /* Draw background*/
- while ((x - client_area.X) < barpos_pixels) {
- dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
- x = x + increment;
- }
- /* Draw border */
- DrawBorder3D (dc, area, Border3DStyle.SunkenInner, Border3DSide.All);
-
- }
-
- 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 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)
- {
- Rectangle paint_area = control.ClientRectangle;
- dc.FillRectangle (SystemBrushes.Control, paint_area);
- DrawBorderStyle (dc, paint_area, control.BorderStyle);
- bool flat = (control.Appearance == ToolBarAppearance.Flat);
- 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 (pen_buttontext, buttonArea);
- if (! ddRect.IsEmpty) {
- dc.DrawLine (pen_buttontext, 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);
- }
- }
- /*
- * 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 (pen_buttonshadow, buttonArea.X + 1, buttonArea.Y,
- buttonArea.X + 1, buttonArea.Height);
- dc.DrawLine (pen_buttonhilight, buttonArea.X + 1 + (int) pen_buttonface.Width,
- buttonArea.Y, buttonArea.X + 1 + (int) pen_buttonface.Width, buttonArea.Height);
- /* draw a horizontal separator */
- if (button.Wrapper) {
- int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
- dc.DrawLine (pen_buttonshadow, 0, y, controlArea.Width, y);
- dc.DrawLine (pen_buttonhilight, 0, y + 1 + (int) pen_buttonface.Width, controlArea.Width,
- y + 1 + (int) pen_buttonface.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; i<width; i++) {
- switch(side) {
- case Border3DSide.Left: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
- break;
- }
- case Border3DSide.Right: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
- break;
- }
- case Border3DSide.Top: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
- break;
- }
- case Border3DSide.Bottom: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
- break;
- }
- }
- }
- break;
- }
- case ButtonBorderStyle.Inset: {
- 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; i<width; i++) {
- switch(side) {
- case Border3DSide.Left: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
- break;
- }
- case Border3DSide.Right: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
- break;
- }
- case Border3DSide.Top: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
- break;
- }
- case Border3DSide.Bottom: {
- pen.Dispose();
- colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
- pen=new Pen(colorGrade, 1);
- graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
- break;
- }
- }
- }
- break;
- }
- /*
- I decided to have the for-loop duplicated for speed reasons;
- that way we only have to switch once (as opposed to have the
- for-loop around the switch)
- */
- default: {
- switch(side) {
- case Border3DSide.Left: {
- for (int i=0; i<width; i++) {
- graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
- }
- break;
- }
- case Border3DSide.Right: {
- for (int i=0; i<width; i++) {
- graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
- }
- break;
- }
- case Border3DSide.Top: {
- for (int i=0; i<width; i++) {
- graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
- }
- break;
- }
- case Border3DSide.Bottom: {
- for (int i=0; i<width; i++) {
- graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
- }
- break;
- }
- }
- break;
- }
- }
- pen.Dispose();
- }
- /*
- This function actually draws the various caption elements.
- This way we can scale them nicely, no matter what size, and they
- still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
- */
- private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
- switch(button) {
- case CaptionButton.Close: {
- pen.StartCap=LineCap.Triangle;
- pen.EndCap=LineCap.Triangle;
- if (lineWidth<2) {
- graphics.DrawLine(pen, captionRect.Left+2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
- graphics.DrawLine(pen, captionRect.Right-2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
- }
- graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
- graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
- return;
- }
- case CaptionButton.Help: {
- StringFormat sf = new StringFormat();
- SolidBrush sb = new SolidBrush(color);
- Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
- sf.Alignment=StringAlignment.Center;
- sf.LineAlignment=StringAlignment.Center;
- graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
- sf.Dispose();
- sb.Dispose();
- font.Dispose();
- return;
- }
- case CaptionButton.Maximize: {
- /* Top 'caption bar' line */
- for (int i=0; i<Math.Max(2, lineWidth); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Top+2*lineWidth+shift+i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+2*lineWidth+shift+i);
- }
- /* Left side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
- }
- /* Right side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Right-lineWidth-lineWidth/2+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Right-lineWidth-lineWidth/2+shift+i, captionRect.Bottom-lineWidth+shift);
- }
- /* Bottom line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
- }
- return;
- }
- case CaptionButton.Minimize: {
- /* Bottom line */
- for (int i=0; i<Math.Max(2, lineWidth); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
- }
- return;
- }
- case CaptionButton.Restore: {
- /** First 'window' **/
- /* Top 'caption bar' line */
- for (int i=0; i<Math.Max(2, lineWidth); i++) {
- graphics.DrawLine(pen, captionRect.Left+3*lineWidth+shift, captionRect.Top+2*lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+2*lineWidth+shift-i);
- }
- /* Left side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Left+3*lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+3*lineWidth+shift+i, captionRect.Top+4*lineWidth+shift);
- }
- /* Right side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Right-lineWidth-lineWidth/2+shift-i, captionRect.Top+2*lineWidth+shift, captionRect.Right-lineWidth-lineWidth/2+shift-i, captionRect.Top+5*lineWidth-lineWidth/2+shift);
- }
- /* Bottom line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Top+5*lineWidth-lineWidth/2+shift+1+i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+5*lineWidth-lineWidth/2+shift+1+i);
- }
- /** Second 'window' **/
- /* Top 'caption bar' line */
- for (int i=0; i<Math.Max(2, lineWidth); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Top+4*lineWidth+shift+1-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Top+4*lineWidth+shift+1-i);
- }
- /* Left side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
- }
- /* Right side line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Right-3*lineWidth-lineWidth/2+shift-i, captionRect.Top+4*lineWidth+shift+1, captionRect.Right-3*lineWidth-lineWidth/2+shift-i, captionRect.Bottom-lineWidth+shift);
- }
- /* Bottom line */
- for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
- graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
- }
- return;
- }
- }
- }
- [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
- private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State)
- {
- switch(Type) {
- case DrawFrameControlTypes.Button: {
- if ((State & DrawFrameControlStates.ButtonPush)!=0) {
- /* Goes first, affects the background */
- if ((State & DrawFrameControlStates.Checked)!=0) {
- HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
- graphics.FillRectangle(hatchBrush,rectangle);
- hatchBrush.Dispose();
- }
- if ((State & DrawFrameControlStates.Pushed)!=0) {
- DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- } else if ((State & DrawFrameControlStates.Flat)!=0) {
- ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
- } else if ((State & DrawFrameControlStates.Inactive)!=0) {
- /* Same as normal, it would seem */
- DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- } else {
- DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- }
- } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
- Pen penFatDark = new Pen(ColorButtonShadow, 2);
- Pen penFatLight = new Pen(SystemColors.ControlLight, 2);
- int lineWidth;
- graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
- graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
- graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
- graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
- lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
- if ((State & DrawFrameControlStates.Checked)!=0) {
- SolidBrush buttonBrush;
- if ((State & DrawFrameControlStates.Inactive)!=0) {
- buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
- } else {
- buttonBrush=(SolidBrush)SystemBrushes.ControlText;
- }
- graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
- }
- penFatDark.Dispose();
- penFatLight.Dispose();
- } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
- throw new NotImplementedException () ;
- } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
- throw new NotImplementedException ();
- } else { /* Must be Checkbox */
- Pen pen;
- int lineWidth;
- Rectangle rect;
- int Scale;
- /* FIXME: I'm sure there's an easier way to calculate all this, but it should do for now */
- /* Goes first, affects the background */
- if ((State & DrawFrameControlStates.Pushed)!=0) {
- HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
- graphics.FillRectangle(hatchBrush,rectangle);
- hatchBrush.Dispose();
- }
- /* Draw the sunken frame */
- if ((State & DrawFrameControlStates.Flat)!=0) {
- ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
- } else {
- DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
- }
- /* Make sure we've got at least a line width of 1 */
- lineWidth=Math.Max(3, 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);
- if ((State & DrawFrameControlStates.Inactive)!=0) {
- pen=SystemPens.ControlDark;
- } else {
- pen=SystemPens.ControlText;
- }
- if ((State & DrawFrameControlStates.Checked)!=0) {
- /* Need to draw a check-mark */
- for (int i=0; i<lineWidth; i++) {
- graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
- graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
- }
- }
- }
- return;
- }
- case DrawFrameControlTypes.Caption: {
- // FIXME:
- break;
- }
- case DrawFrameControlTypes.Menu: {
- // FIXME:
- break;
- }
- case DrawFrameControlTypes.Scroll: {
- // FIXME:
- break;
- }
- }
- }
- /* Generic scroll button */
- static public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state)
- {
- if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
- dc.FillRectangle (br_buttonface, area.X + 1,
- area.Y + 1, area.Width - 2 , area.Height - 2);
- dc.DrawRectangle (pen_buttonshadow, area.X,
- area.Y, area.Width, area.Height);
- }
- if (state == ButtonState.Normal) {
- dc.FillRectangle (new SolidBrush (Color.Blue), area);
-
- dc.FillRectangle (br_buttonface, area.X, area.Y, area.Width, 1);
- dc.FillRectangle (br_buttonface, area.X, area.Y, 1, area.Height);
- dc.FillRectangle (br_buttonhilight, area.X + 1, area.Y + 1, area.Width - 1, 1);
- dc.FillRectangle (br_buttonhilight, area.X + 1, area.Y + 2, 1,
- area.Height - 4);
- dc.FillRectangle (br_buttonshadow, area.X + 1, area.Y + area.Height - 2,
- area.Width - 2, 1);
- dc.FillRectangle (br_buttondkshadow, area.X, area.Y + area.Height -1,
- area.Width , 1);
- dc.FillRectangle (br_buttonshadow, area.X + area.Width - 2,
- area.Y + 1, 1, area.Height -3);
- dc.FillRectangle (br_buttondkshadow, area.X + area.Width -1,
- area.Y, 1, area.Height - 1);
- dc.FillRectangle (br_buttonface, area.X + 2,
- area.Y + 2, area.Width - 4, area.Height - 4);
- }
- }
-
- private void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style)
- {
- switch (border_style){
- case BorderStyle.Fixed3D:
- dc.DrawLine (pen_buttonshadow, area.X, area.Y, area.X +area.Width, area.Y);
- dc.DrawLine (pen_buttonshadow, area.X, area.Y, area.X, area.Y + area.Height);
- dc.DrawLine (pen_buttonhilight, area.X , area.Y + area.Height - 1, area.X + area.Width ,
- area.Y + area.Height - 1);
- dc.DrawLine (pen_buttonhilight, area.X + area.Width -1 , area.Y, area.X + area.Width -1,
- area.Y + area.Height);
- break;
- case BorderStyle.FixedSingle:
- dc.DrawRectangle (pen_windowframe, area.X, area.Y, area.Width - 1, area.Height - 1);
- break;
- case BorderStyle.None:
- default:
- break;
- }
-
- }
- protected SolidBrush GetControlBackBrush (Color c)
- {
- if (c == DefaultControlBackColor)
- return br_buttonface;
- return new SolidBrush (c);
- }
- protected SolidBrush GetControlForeBrush (Color c)
- {
- if (c == DefaultControlForeColor)
- return br_buttontext;
- return new SolidBrush (c);
- }
- } //class
- }
|