ThemeWin32Classic.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jordi Mas i Hernandez, [email protected]
  24. // Peter Bartok, [email protected]
  25. //
  26. //
  27. //
  28. // $Revision: 1.20 $
  29. // $Modtime: $
  30. // $Log: ThemeWin32Classic.cs,v $
  31. // Revision 1.20 2004/08/13 21:22:18 jordi
  32. // removes redundant code and fixes issues with tickposition
  33. //
  34. // Revision 1.19 2004/08/12 20:29:01 jordi
  35. // Trackbar enhancement, fix mouse problems, highli thumb, etc
  36. //
  37. // Revision 1.18 2004/08/12 18:54:37 jackson
  38. // Handle owner draw status bars
  39. //
  40. // Revision 1.17 2004/08/11 01:31:35 jackson
  41. // Create Brushes as little as possible
  42. //
  43. // Revision 1.16 2004/08/10 19:21:27 jordi
  44. // scrollbar enhancements and standarize on win colors defaults
  45. //
  46. // Revision 1.15 2004/08/10 18:52:30 jackson
  47. // Implement DrawItem functionality
  48. //
  49. // Revision 1.14 2004/08/09 21:34:54 jackson
  50. // Add support for drawing status bar and get status bar item sizes
  51. //
  52. // Revision 1.13 2004/08/09 21:21:49 jackson
  53. // Use known colors for default control colours
  54. //
  55. // Revision 1.12 2004/08/09 21:12:15 jackson
  56. // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
  57. //
  58. // Revision 1.11 2004/08/09 17:31:13 jackson
  59. // New names for control properties
  60. //
  61. // Revision 1.10 2004/08/09 17:00:00 jackson
  62. // Add default window color properties
  63. //
  64. // Revision 1.9 2004/08/09 16:17:19 jackson
  65. // Use correct default back color
  66. //
  67. // Revision 1.8 2004/08/09 15:53:12 jackson
  68. // Themes now handle default control properties so coloring will be consistent
  69. //
  70. // Revision 1.7 2004/08/08 22:54:21 jordi
  71. // Label BorderStyles
  72. //
  73. // Revision 1.6 2004/08/08 18:09:53 jackson
  74. // Add pen_buttonface
  75. //
  76. // Revision 1.5 2004/08/08 17:34:28 jordi
  77. // Use Windows Standard Colours
  78. //
  79. // Revision 1.4 2004/08/07 23:31:15 jordi
  80. // fixes label bug and draw method name
  81. //
  82. // Revision 1.3 2004/08/07 19:05:44 jordi
  83. // Theme colour support and GetSysColor defines
  84. //
  85. // Revision 1.2 2004/08/07 00:01:39 pbartok
  86. // - Fixed some rounding issues with float/int
  87. //
  88. // Revision 1.1 2004/07/26 17:42:03 jordi
  89. // Theme support
  90. //
  91. //
  92. using System.Drawing;
  93. using System.Drawing.Drawing2D;
  94. using System.Drawing.Imaging;
  95. namespace System.Windows.Forms
  96. {
  97. internal class ThemeWin32Classic : ITheme
  98. {
  99. static private Pen pen_ticks;
  100. static private Pen pen_disabled;
  101. static private SolidBrush br_arrow;
  102. static private SolidBrush br_disabled;
  103. static private HatchBrush br_focus;
  104. static private SolidBrush br_progressbarblock;
  105. static private Pen pen_arrow;
  106. static private SolidBrush br_buttonface;
  107. static private SolidBrush br_buttonshadow;
  108. static private SolidBrush br_buttondkshadow;
  109. static private SolidBrush br_buttonhilight;
  110. static private SolidBrush br_buttontext;
  111. static private SolidBrush br_menutext;
  112. static private Pen pen_buttonshadow;
  113. static private Pen pen_buttondkshadow;
  114. static private Pen pen_buttonhilight;
  115. static private Pen pen_buttonface;
  116. static private Pen pen_windowframe;
  117. static private Font default_font;
  118. /* Cache */
  119. private SolidBrush label_br_fore_color;
  120. private SolidBrush label_br_back_color;
  121. private HatchBrush br_scrollbar_backgr;
  122. private HatchBrush br_trackbar_thumbhili;
  123. private SolidBrush br_trackbarbg;
  124. public ThemeWin32Classic ()
  125. {
  126. label_br_fore_color = null;
  127. label_br_back_color = null;
  128. br_scrollbar_backgr = null;
  129. br_trackbarbg = null;
  130. br_trackbar_thumbhili = null;
  131. pen_ticks = new Pen (Color.Black);
  132. br_arrow = new SolidBrush (Color.Black);
  133. br_focus = new HatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black);
  134. pen_arrow = new Pen (Color.Black);
  135. br_progressbarblock = new SolidBrush (Color.FromArgb (255, 49, 106, 197));
  136. br_buttonface = new SolidBrush (ColorButtonFace);
  137. br_buttonshadow = new SolidBrush (ColorButtonShadow);
  138. br_buttondkshadow = new SolidBrush (ColorButtonDkShadow);
  139. br_buttonhilight = new SolidBrush (ColorButtonHilight);
  140. br_buttontext = new SolidBrush (ColorButtonText);
  141. pen_buttonshadow = new Pen (ColorButtonShadow);
  142. pen_buttondkshadow = new Pen (ColorButtonDkShadow);
  143. pen_buttonhilight = new Pen (ColorButtonHilight);
  144. pen_buttonface = new Pen (ColorButtonFace);
  145. pen_windowframe = new Pen (ColorWindowFrame);
  146. default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
  147. }
  148. /* Windows System Colors. Based on Wine */
  149. public Color ColorScrollbar {
  150. get {return Color.FromArgb (255, 192, 192, 192);}
  151. }
  152. public Color ColorBackground{
  153. get {return Color.FromArgb (255, 0, 128, 128);}
  154. }
  155. public Color ColorActiveTitle{
  156. get {return Color.FromArgb (255, 0, 0, 128);}
  157. }
  158. public Color ColorInactiveTitle{
  159. get {return Color.FromArgb (255, 128, 128, 128);}
  160. }
  161. public Color ColorMenu{
  162. get {return Color.FromArgb (255, 192, 192, 192);}
  163. }
  164. public Color ColorWindow{
  165. get {return Color.FromArgb (255, 255, 255, 255);}
  166. }
  167. public Color ColorWindowFrame{
  168. get {return Color.FromArgb (255, 0, 0, 0);}
  169. }
  170. public Color ColorMenuText{
  171. get {return Color.FromArgb (255, 0, 0, 0);}
  172. }
  173. public Color ColorWindowText{
  174. get {return Color.FromArgb (255, 0, 0, 0);}
  175. }
  176. public Color ColorTitleText{
  177. get {return Color.FromArgb (255, 255, 255, 255);}
  178. }
  179. public Color ColorActiveBorder{
  180. get {return Color.FromArgb (255, 192, 192, 192);}
  181. }
  182. public Color ColorInactiveBorder{
  183. get {return Color.FromArgb (255, 192, 192, 192);}
  184. }
  185. public Color ColorAppWorkSpace{
  186. get {return Color.FromArgb (255, 128, 128, 128);}
  187. }
  188. public Color ColorHilight{
  189. get {return Color.FromArgb (255, 0, 0, 128);}
  190. }
  191. public Color ColorHilightText{
  192. get {return Color.FromArgb (255, 255, 255, 255);}
  193. }
  194. public Color ColorButtonFace{
  195. get {return Color.FromKnownColor (KnownColor.Control);}
  196. }
  197. public Color ColorButtonShadow{
  198. get {return Color.FromArgb (255, 128, 128, 128);}
  199. }
  200. public Color ColorGrayText{
  201. get {return Color.FromArgb (255, 128, 128, 128);}
  202. }
  203. public Color ColorButtonText{
  204. get {return Color.FromKnownColor (KnownColor.ControlText);}
  205. }
  206. public Color ColorInactiveTitleText{
  207. get {return Color.FromArgb (255, 192, 192, 192);}
  208. }
  209. public Color ColorButtonHilight{
  210. get {return Color.FromArgb (255, 255, 255, 255);}
  211. }
  212. public Color ColorButtonDkShadow{
  213. get {return Color.FromArgb (255, 0, 0, 0);}
  214. }
  215. public Color ColorButtonLight{
  216. get {return Color.FromArgb (255, 224, 224, 224);}
  217. }
  218. public Color ColorInfoText{
  219. get {return Color.FromArgb (255, 0, 0, 0);}
  220. }
  221. public Color ColorInfoWindow{
  222. get {return Color.FromArgb (255, 255, 255, 225);}
  223. }
  224. public Color ColorButtonAlternateFace{
  225. get {return Color.FromArgb (255, 180, 180, 180);}
  226. }
  227. public Color ColorHotTrackingColor{
  228. get {return Color.FromArgb (255, 0, 0, 255);}
  229. }
  230. public Color ColorGradientActiveTitle{
  231. get {return Color.FromArgb (255, 16, 132, 208);}
  232. }
  233. public Color ColorGradientInactiveTitle {
  234. get {return Color.FromArgb (255, 181, 181, 181);}
  235. }
  236. public Color DefaultControlBackColor {
  237. get { return Color.FromKnownColor (KnownColor.Control); }
  238. }
  239. public Color DefaultControlForeColor {
  240. get { return Color.FromKnownColor (KnownColor.ControlText); }
  241. }
  242. public Font DefaultFont {
  243. get { return default_font; }
  244. }
  245. public Color DefaultWindowBackColor {
  246. get { return Color.FromArgb (255, 10, 10, 10); }
  247. }
  248. public Color DefaultWindowForeColor {
  249. get { return Color.FromKnownColor (KnownColor.ControlText); }
  250. }
  251. public int SizeGripWidth {
  252. get { return 15; }
  253. }
  254. public int StatusBarHorzGapWidth {
  255. get { return 3; }
  256. }
  257. public int ScrollBarButtonSize {
  258. get { return 16; }
  259. }
  260. private enum DrawFrameControlStates
  261. {
  262. ButtonCheck = 0x0000,
  263. ButtonRadioImage = 0x0001,
  264. ButtonRadioMask = 0x0002,
  265. ButtonRadio = 0x0004,
  266. Button3State = 0x0008,
  267. ButtonPush = 0x0010,
  268. CaptionClose = 0x0000,
  269. CaptionMin = 0x0001,
  270. CaptionMax = 0x0002,
  271. CaptionRestore = 0x0004,
  272. CaptionHelp = 0x0008,
  273. MenuArrow = 0x0000,
  274. MenuCheck = 0x0001,
  275. MenuBullet = 0x0002,
  276. MenuArrowRight = 0x0004,
  277. ScrollUp = 0x0000,
  278. ScrollDown = 0x0001,
  279. ScrollLeft = 0x0002,
  280. ScrollRight = 0x0003,
  281. ScrollComboBox = 0x0005,
  282. ScrollSizeGrip = 0x0008,
  283. ScrollSizeGripRight = 0x0010,
  284. Inactive = 0x0100,
  285. Pushed = 0x0200,
  286. Checked = 0x0400,
  287. Transparent = 0x0800,
  288. Hot = 0x1000,
  289. AdjustRect = 0x2000,
  290. Flat = 0x4000,
  291. Mono = 0x8000
  292. }
  293. private enum DrawFrameControlTypes
  294. {
  295. Caption = 1,
  296. Menu = 2,
  297. Scroll = 3,
  298. Button = 4
  299. }
  300. /*
  301. Methods that mimic ControlPaint signature and draw basic objects
  302. */
  303. public void DrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
  304. ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
  305. Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
  306. int bottomWidth, ButtonBorderStyle bottomStyle)
  307. {
  308. DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
  309. DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
  310. DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
  311. DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
  312. }
  313. public void DrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides)
  314. {
  315. Pen penTopLeft;
  316. Pen penTopLeftInner;
  317. Pen penBottomRight;
  318. Pen penBottomRightInner;
  319. Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
  320. bool doInner = false;
  321. if ((style & Border3DStyle.Adjust)!=0) {
  322. rect.Y-=2;
  323. rect.X-=2;
  324. rect.Width+=4;
  325. rect.Height+=4;
  326. }
  327. /* default to flat */
  328. penTopLeft=SystemPens.ControlDark;
  329. penTopLeftInner=SystemPens.ControlDark;
  330. penBottomRight=SystemPens.ControlDark;
  331. penBottomRightInner=SystemPens.ControlDark;
  332. if ((style & Border3DStyle.RaisedOuter)!=0) {
  333. penTopLeft=SystemPens.ControlLightLight;
  334. penBottomRight=SystemPens.ControlDarkDark;
  335. if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
  336. doInner=true;
  337. }
  338. } else if ((style & Border3DStyle.SunkenOuter)!=0) {
  339. penTopLeft=SystemPens.ControlDarkDark;
  340. penBottomRight=SystemPens.ControlLightLight;
  341. if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
  342. doInner=true;
  343. }
  344. }
  345. if ((style & Border3DStyle.RaisedInner)!=0) {
  346. if (doInner) {
  347. penTopLeftInner=SystemPens.ControlLight;
  348. penBottomRightInner=SystemPens.ControlDark;
  349. } else {
  350. penTopLeft=SystemPens.ControlLightLight;
  351. penBottomRight=SystemPens.ControlDarkDark;
  352. }
  353. } else if ((style & Border3DStyle.SunkenInner)!=0) {
  354. if (doInner) {
  355. penTopLeftInner=SystemPens.ControlDark;
  356. penBottomRightInner=SystemPens.ControlLight;
  357. } else {
  358. penTopLeft=SystemPens.ControlDarkDark;
  359. penBottomRight=SystemPens.ControlLightLight;
  360. }
  361. }
  362. if ((sides & Border3DSide.Middle)!=0) {
  363. graphics.FillRectangle(SystemBrushes.Control, rect);
  364. }
  365. if ((sides & Border3DSide.Left)!=0) {
  366. graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-1, rect.Left, rect.Top);
  367. if (doInner) {
  368. graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-1, rect.Left+1, rect.Top);
  369. }
  370. }
  371. if ((sides & Border3DSide.Top)!=0) {
  372. graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-1, rect.Top);
  373. if (doInner) {
  374. if ((sides & Border3DSide.Left)!=0) {
  375. graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-1, rect.Top+1);
  376. } else {
  377. graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-1, rect.Top+1);
  378. }
  379. }
  380. }
  381. if ((sides & Border3DSide.Right)!=0) {
  382. graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
  383. if (doInner) {
  384. if ((sides & Border3DSide.Top)!=0) {
  385. graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-1);
  386. } else {
  387. graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-1);
  388. }
  389. }
  390. }
  391. if ((sides & Border3DSide.Bottom)!=0) {
  392. int left=rect.Left;
  393. if ((sides & Border3DSide.Left)!=0) {
  394. left+=1;
  395. }
  396. graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
  397. if (doInner) {
  398. if ((sides & Border3DSide.Right)!=0) {
  399. graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
  400. } else {
  401. graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-1, rect.Bottom-2);
  402. }
  403. }
  404. }
  405. }
  406. public void DrawButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  407. {
  408. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
  409. if ((state & ButtonState.Pushed)!=0) {
  410. dfcs |= DrawFrameControlStates.Pushed;
  411. }
  412. if ((state & ButtonState.Checked)!=0) {
  413. dfcs |= DrawFrameControlStates.Checked;
  414. }
  415. if ((state & ButtonState.Flat)!=0) {
  416. dfcs |= DrawFrameControlStates.Flat;
  417. }
  418. if ((state & ButtonState.Inactive)!=0) {
  419. dfcs |= DrawFrameControlStates.Inactive;
  420. }
  421. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  422. }
  423. public void DrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
  424. {
  425. Rectangle captionRect;
  426. int lineWidth;
  427. DrawButton(graphics, rectangle, state);
  428. if (rectangle.Width<rectangle.Height) {
  429. captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
  430. } else {
  431. captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
  432. }
  433. if ((state & ButtonState.Pushed)!=0) {
  434. captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
  435. }
  436. /* Make sure we've got at least a line width of 1 */
  437. lineWidth=Math.Max(1, captionRect.Width/7);
  438. switch(button) {
  439. case CaptionButton.Close: {
  440. Pen pen;
  441. if ((state & ButtonState.Inactive)!=0) {
  442. pen=new Pen(ColorButtonHilight, lineWidth);
  443. DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
  444. pen.Dispose();
  445. pen=new Pen(ColorButtonShadow, lineWidth);
  446. DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
  447. pen.Dispose();
  448. return;
  449. } else {
  450. pen=new Pen(SystemColors.ControlText, lineWidth);
  451. DrawCaptionHelper(graphics, SystemColors.ControlText, pen, lineWidth, 0, captionRect, button);
  452. pen.Dispose();
  453. return;
  454. }
  455. }
  456. case CaptionButton.Help:
  457. case CaptionButton.Maximize:
  458. case CaptionButton.Minimize:
  459. case CaptionButton.Restore: {
  460. if ((state & ButtonState.Inactive)!=0) {
  461. DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
  462. DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
  463. return;
  464. } else {
  465. DrawCaptionHelper(graphics, SystemColors.ControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
  466. return;
  467. }
  468. }
  469. }
  470. }
  471. public void DrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
  472. {
  473. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
  474. if ((state & ButtonState.Pushed)!=0) {
  475. dfcs |= DrawFrameControlStates.Pushed;
  476. }
  477. if ((state & ButtonState.Checked)!=0) {
  478. dfcs |= DrawFrameControlStates.Checked;
  479. }
  480. if ((state & ButtonState.Flat)!=0) {
  481. dfcs |= DrawFrameControlStates.Flat;
  482. }
  483. if ((state & ButtonState.Inactive)!=0) {
  484. dfcs |= DrawFrameControlStates.Inactive;
  485. }
  486. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  487. }
  488. public void DrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  489. {
  490. Point[] arrow = new Point[3];
  491. Point P1;
  492. Point P2;
  493. Point P3;
  494. int centerX;
  495. int centerY;
  496. int shiftX;
  497. int shiftY;
  498. Rectangle rect;
  499. if ((state & ButtonState.Checked)!=0) {
  500. HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, ColorButtonHilight);
  501. graphics.FillRectangle(hatchBrush,rectangle);
  502. hatchBrush.Dispose();
  503. }
  504. if ((state & ButtonState.Flat)!=0) {
  505. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  506. } else {
  507. if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
  508. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  509. } else {
  510. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  511. }
  512. }
  513. rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
  514. centerX=rect.Left+rect.Width/2;
  515. centerY=rect.Top+rect.Height/2;
  516. shiftX=Math.Max(1, rect.Width/8);
  517. shiftY=Math.Max(1, rect.Height/8);
  518. if ((state & ButtonState.Pushed)!=0) {
  519. shiftX++;
  520. shiftY++;
  521. }
  522. rect.Y-=shiftY;
  523. centerY-=shiftY;
  524. P1=new Point(rect.Left, centerY);
  525. P2=new Point(rect.Right, centerY);
  526. P3=new Point(centerX, rect.Bottom);
  527. arrow[0]=P1;
  528. arrow[1]=P2;
  529. arrow[2]=P3;
  530. /* Draw the arrow */
  531. if ((state & ButtonState.Inactive)!=0) {
  532. graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
  533. /* Move away from the shadow */
  534. P1.X-=1; P1.Y-=1;
  535. P2.X-=1; P2.Y-=1;
  536. P3.X-=1; P3.Y-=1;
  537. arrow[0]=P1;
  538. arrow[1]=P2;
  539. arrow[2]=P3;
  540. graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
  541. } else {
  542. graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
  543. }
  544. }
  545. public void DrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
  546. {
  547. SolidBrush sb = br_buttontext;
  548. Pen pen = new Pen(Color.Black, 1);
  549. Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
  550. int X;
  551. int Y;
  552. graphics.FillRectangle(sb, rect);
  553. graphics.DrawRectangle(pen, rect);
  554. X=rect.X+rect.Width/2;
  555. Y=rect.Y+rect.Height/2;
  556. /* Draw the cross */
  557. graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
  558. graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
  559. /* Draw 'arrows' for vertical lines */
  560. graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
  561. graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
  562. /* Draw 'arrows' for horizontal lines */
  563. graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
  564. graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
  565. }
  566. public void DrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
  567. {
  568. //Color colorForeInverted;
  569. Color colorBackInverted;
  570. Pen pen;
  571. //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
  572. //pen=new Pen(colorForeInverted, 1);
  573. // MS seems to always use black
  574. pen=new Pen(Color.Black, 1);
  575. graphics.DrawRectangle(pen, rectangle);
  576. pen.Dispose();
  577. colorBackInverted=Color.FromArgb(Math.Abs(backColor.R-255), Math.Abs(backColor.G-255), Math.Abs(backColor.B-255));
  578. pen=new Pen(colorBackInverted, 1);
  579. pen.DashStyle=DashStyle.Dot;
  580. graphics.DrawRectangle(pen, rectangle);
  581. pen.Dispose();
  582. }
  583. public void DrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
  584. {
  585. SolidBrush sb;
  586. Pen pen;
  587. if (primary==true) {
  588. pen=new Pen(Color.Black, 1);
  589. if (enabled==true) {
  590. sb=br_buttontext;
  591. } else {
  592. sb=br_buttonface;
  593. }
  594. } else {
  595. pen=new Pen(Color.White, 1);
  596. if (enabled==true) {
  597. sb=new SolidBrush(Color.Black);
  598. } else {
  599. sb=br_buttonface;
  600. }
  601. }
  602. graphics.FillRectangle(sb, rectangle);
  603. graphics.DrawRectangle(pen, rectangle);
  604. sb.Dispose();
  605. pen.Dispose();
  606. }
  607. public void DrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor)
  608. {
  609. Color foreColor;
  610. int h;
  611. int b;
  612. int s;
  613. ControlPaint.Color2HBS(backColor, out h, out b, out s);
  614. if (b>127) {
  615. foreColor=Color.Black;
  616. } else {
  617. foreColor=Color.White;
  618. }
  619. #if false
  620. /* Commented out until I take the time and figure out
  621. which HatchStyle will match requirements. The code below
  622. is only correct for Percent50.
  623. */
  624. if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
  625. HatchBrush brush=null;
  626. switch(pixelsBetweenDots.Width) {
  627. case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
  628. case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
  629. case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
  630. default: {
  631. /* Have to do it the slow way */
  632. break;
  633. }
  634. }
  635. if (brush!=null) {
  636. graphics.FillRectangle(brush, area);
  637. pen.Dispose();
  638. brush.Dispose();
  639. return;
  640. }
  641. }
  642. #endif
  643. /* Slow method */
  644. Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
  645. for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
  646. for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
  647. bitmap.SetPixel(x, y, foreColor);
  648. }
  649. }
  650. graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
  651. bitmap.Dispose();
  652. }
  653. public void DrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background)
  654. {
  655. /*
  656. Microsoft seems to ignore the background and simply make
  657. the image grayscale. At least when having > 256 colors on
  658. the display.
  659. */
  660. ImageAttributes imageAttributes=new ImageAttributes();
  661. ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
  662. // This table would create a perfect grayscale image, based on luminance
  663. // new float[]{0.3f,0.3f,0.3f,0,0},
  664. // new float[]{0.59f,0.59f,0.59f,0,0},
  665. // new float[]{0.11f,0.11f,0.11f,0,0},
  666. // new float[]{0,0,0,1,0,0},
  667. // new float[]{0,0,0,0,1,0},
  668. // new float[]{0,0,0,0,0,1}
  669. // This table generates a image that is grayscaled and then
  670. // brightened up. Seems to match MS close enough.
  671. new float[]{0.2f,0.2f,0.2f,0,0},
  672. new float[]{0.41f,0.41f,0.41f,0,0},
  673. new float[]{0.11f,0.11f,0.11f,0,0},
  674. new float[]{0.15f,0.15f,0.15f,1,0,0},
  675. new float[]{0.15f,0.15f,0.15f,0,1,0},
  676. new float[]{0.15f,0.15f,0.15f,0,0,1}
  677. });
  678. imageAttributes.SetColorMatrix(colorMatrix);
  679. graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
  680. imageAttributes.Dispose();
  681. }
  682. public void DrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary)
  683. {
  684. Pen penBorder;
  685. Pen penInside;
  686. if (primary) {
  687. penBorder=new Pen(Color.White, 2);
  688. penInside=new Pen(Color.Black, 1);
  689. } else {
  690. penBorder=new Pen(Color.Black, 2);
  691. penInside=new Pen(Color.White, 1);
  692. }
  693. penBorder.Alignment=PenAlignment.Inset;
  694. penInside.Alignment=PenAlignment.Inset;
  695. graphics.DrawRectangle(penBorder, rectangle);
  696. graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
  697. penBorder.Dispose();
  698. penInside.Dispose();
  699. }
  700. public void DrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph)
  701. {
  702. Rectangle rect;
  703. int lineWidth;
  704. // MS seems to draw the background white
  705. graphics.FillRectangle(br_buttontext, rectangle);
  706. switch(glyph) {
  707. case MenuGlyph.Arrow: {
  708. Point[] arrow = new Point[3];
  709. Point P1;
  710. Point P2;
  711. Point P3;
  712. int centerX;
  713. int centerY;
  714. int shiftX;
  715. int shiftY;
  716. rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
  717. centerX=rect.Left+rect.Width/2;
  718. centerY=rect.Top+rect.Height/2;
  719. shiftX=Math.Max(1, rect.Width/8);
  720. shiftY=Math.Max(1, rect.Height/8);
  721. rect.X-=shiftX;
  722. centerX-=shiftX;
  723. P1=new Point(centerX, rect.Top-1);
  724. P2=new Point(centerX, rect.Bottom);
  725. P3=new Point(rect.Right, centerY);
  726. arrow[0]=P1;
  727. arrow[1]=P2;
  728. arrow[2]=P3;
  729. graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
  730. return;
  731. }
  732. case MenuGlyph.Bullet: {
  733. SolidBrush sb;
  734. lineWidth=Math.Max(2, rectangle.Width/3);
  735. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  736. sb=br_buttontext;
  737. graphics.FillEllipse(sb, rect);
  738. sb.Dispose();
  739. return;
  740. }
  741. case MenuGlyph.Checkmark: {
  742. int Scale;
  743. lineWidth=Math.Max(2, rectangle.Width/6);
  744. Scale=Math.Max(1, rectangle.Width/12);
  745. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  746. for (int i=0; i<lineWidth; i++) {
  747. graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
  748. 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);
  749. }
  750. return;
  751. }
  752. }
  753. }
  754. public void DrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  755. {
  756. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
  757. if ((state & ButtonState.Pushed)!=0) {
  758. dfcs |= DrawFrameControlStates.Pushed;
  759. }
  760. if ((state & ButtonState.Checked)!=0) {
  761. dfcs |= DrawFrameControlStates.Checked;
  762. }
  763. if ((state & ButtonState.Flat)!=0) {
  764. dfcs |= DrawFrameControlStates.Flat;
  765. }
  766. if ((state & ButtonState.Inactive)!=0) {
  767. dfcs |= DrawFrameControlStates.Inactive;
  768. }
  769. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  770. }
  771. public void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
  772. {
  773. }
  774. public void DrawReversibleLine (Point start, Point end, Color backColor)
  775. {
  776. }
  777. /* Scroll button: regular button + direction arrow */
  778. public void DrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
  779. {
  780. bool enabled = (state == ButtonState.Inactive) ? false: true;
  781. DrawScrollButtonPrimitive (dc, area, state);
  782. /* Paint arrows */
  783. switch (type) {
  784. case ScrollButton.Up:
  785. {
  786. int x = area.X + (area.Width / 2) - 4;
  787. int y = area.Y + 9;
  788. for (int i = 0; i < 3; i++)
  789. if (enabled)
  790. dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
  791. else
  792. dc.DrawLine (pen_disabled, x + i, y - i, x + i + 6 - 2*i, y - i);
  793. if (enabled)
  794. dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);
  795. else
  796. dc.FillRectangle (br_disabled, x + 3, area.Y + 6, 1, 1);
  797. break;
  798. }
  799. case ScrollButton.Down:
  800. {
  801. int x = area.X + (area.Width / 2) - 4;
  802. int y = area.Y + 5;
  803. for (int i = 4; i != 0; i--)
  804. if (enabled)
  805. dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
  806. else
  807. dc.DrawLine (pen_disabled, x + i, y + i, x + i + 8 - 2*i, y + i);
  808. if (enabled)
  809. dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
  810. else
  811. dc.FillRectangle (br_disabled, x + 4, y + 4, 1, 1);
  812. break;
  813. }
  814. case ScrollButton.Left:
  815. {
  816. int y = area.Y + (area.Height / 2) - 4;
  817. int x = area.X + 9;
  818. for (int i = 0; i < 3; i++)
  819. if (enabled)
  820. dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
  821. else
  822. dc.DrawLine (pen_disabled, x - i, y + i, x - i, y + i + 6 - 2*i);
  823. if (enabled)
  824. dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
  825. else
  826. dc.FillRectangle (br_disabled, x - 3, y + 3, 1, 1);
  827. break;
  828. }
  829. case ScrollButton.Right:
  830. {
  831. int y = area.Y + (area.Height / 2) - 4;
  832. int x = area.X + 5;
  833. for (int i = 4; i != 0; i--)
  834. if (enabled)
  835. dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
  836. else
  837. dc.DrawLine (pen_disabled, x + i, y + i, x + i, y + i + 8 - 2*i);
  838. if (enabled)
  839. dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
  840. else
  841. dc.FillRectangle (br_disabled, x + 3, y + 3, 1, 1);
  842. break;
  843. }
  844. default:
  845. break;
  846. }
  847. }
  848. public void DrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
  849. Color backColor)
  850. {
  851. }
  852. public void DrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
  853. {
  854. Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
  855. dc.DrawLine (pen_buttonface, pt.X - 12, pt.Y, pt.X, pt.Y);
  856. dc.DrawLine (pen_buttonface, pt.X, pt.Y, pt.X, pt.Y - 13);
  857. // diagonals
  858. for (int i = 0; i < 11; i += 4) {
  859. dc.DrawLine (pen_buttonshadow, pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
  860. dc.DrawLine (pen_buttonshadow, pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
  861. }
  862. for (int i = 3; i < 13; i += 4)
  863. dc.DrawLine (pen_buttonhilight, pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
  864. }
  865. public void DrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
  866. StringFormat format)
  867. {
  868. SolidBrush brush;
  869. brush=new SolidBrush(ControlPaint.Light(color, 25));
  870. layoutRectangle.Offset(1.0f, 1.0f);
  871. graphics.DrawString(s, font, brush, layoutRectangle, format);
  872. brush.Color=ControlPaint.Dark(color, 35);
  873. layoutRectangle.Offset(-1.0f, -1.0f);
  874. graphics.DrawString(s, font, brush, layoutRectangle, format);
  875. brush.Dispose();
  876. }
  877. /*
  878. Methods that draw complex controls
  879. */
  880. public void DrawScrollBar (Graphics dc, Rectangle area, Rectangle thumb_pos,
  881. ref Rectangle first_arrow_area, ref Rectangle second_arrow_area,
  882. ButtonState first_arrow, ButtonState second_arrow,
  883. ref int scrollbutton_width, ref int scrollbutton_height,
  884. bool enabled, bool vertical)
  885. {
  886. if (br_scrollbar_backgr == null)
  887. br_scrollbar_backgr = new HatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
  888. if (vertical) {
  889. first_arrow_area.X = first_arrow_area. Y = 0;
  890. first_arrow_area.Width = scrollbutton_width;
  891. first_arrow_area.Height = scrollbutton_height;
  892. second_arrow_area.X = 0;
  893. second_arrow_area.Y = area.Height - scrollbutton_height;
  894. second_arrow_area.Width = scrollbutton_width;
  895. second_arrow_area.Height = scrollbutton_height;
  896. /* Buttons */
  897. DrawScrollButton (dc, first_arrow_area, ScrollButton.Up, first_arrow);
  898. DrawScrollButton (dc, second_arrow_area, ScrollButton.Down, second_arrow);
  899. /* Background */
  900. dc.FillRectangle (br_scrollbar_backgr, 0, scrollbutton_height, area.Width,
  901. area.Height - (scrollbutton_height * 2));
  902. }
  903. else {
  904. first_arrow_area.X = first_arrow_area. Y = 0;
  905. first_arrow_area.Width = scrollbutton_width;
  906. first_arrow_area.Height = scrollbutton_height;
  907. second_arrow_area.Y = 0;
  908. second_arrow_area.X = area.Width - scrollbutton_width;
  909. second_arrow_area.Width = scrollbutton_width;
  910. second_arrow_area.Height = scrollbutton_height;
  911. /* Buttons */
  912. DrawScrollButton (dc, first_arrow_area, ScrollButton.Left, first_arrow );
  913. DrawScrollButton (dc, second_arrow_area, ScrollButton.Right, second_arrow);
  914. /* Background */
  915. dc.FillRectangle (br_scrollbar_backgr, scrollbutton_width, 0, area.Width - (scrollbutton_width * 2),
  916. area.Height);
  917. }
  918. /* Thumbail */
  919. if (enabled)
  920. DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
  921. }
  922. /*
  923. DrawTrackBar
  924. */
  925. /* Vertical trackbar */
  926. private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
  927. ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
  928. float ticks, int value_pos, bool mouse_value)
  929. {
  930. Point toptick_startpoint = new Point ();
  931. Point bottomtick_startpoint = new Point ();
  932. Point channel_startpoint = new Point ();
  933. float pixel_len;
  934. float pixels_betweenticks;
  935. const int space_from_right = 8;
  936. const int space_from_left = 8;
  937. switch (tb.TickStyle) {
  938. case TickStyle.BottomRight:
  939. case TickStyle.None:
  940. channel_startpoint.Y = 8;
  941. channel_startpoint.X = 9;
  942. bottomtick_startpoint.Y = 13;
  943. bottomtick_startpoint.X = 24;
  944. break;
  945. case TickStyle.TopLeft:
  946. channel_startpoint.Y = 8;
  947. channel_startpoint.X = 19;
  948. toptick_startpoint.Y = 13;
  949. toptick_startpoint.X = 8;
  950. break;
  951. case TickStyle.Both:
  952. channel_startpoint.Y = 8;
  953. channel_startpoint.X = 18;
  954. bottomtick_startpoint.Y = 13;
  955. bottomtick_startpoint.X = 32;
  956. toptick_startpoint.Y = 13;
  957. toptick_startpoint.X = 8;
  958. break;
  959. default:
  960. break;
  961. }
  962. thumb_area.X = area.X + channel_startpoint.X;
  963. thumb_area.Y = area.Y + channel_startpoint.Y;
  964. thumb_area.Height = area.Height - space_from_right - space_from_left;
  965. thumb_area.Width = 4;
  966. /* Draw channel */
  967. dc.FillRectangle (br_buttonshadow, channel_startpoint.X, channel_startpoint.Y,
  968. 1, thumb_area.Height);
  969. dc.FillRectangle (br_buttondkshadow, channel_startpoint.X + 1, channel_startpoint.Y,
  970. 1, thumb_area.Height);
  971. dc.FillRectangle (br_buttonhilight, channel_startpoint.X + 3, channel_startpoint.Y,
  972. 1, thumb_area.Height);
  973. pixel_len = thumb_area.Height - 11;
  974. pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
  975. /* Convert thumb position from mouse position to value*/
  976. if (mouse_value) {
  977. if (value_pos >= channel_startpoint.Y)
  978. value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
  979. else
  980. value_pos = 0;
  981. if (value_pos + tb.Minimum > tb.Maximum)
  982. value_pos = tb.Maximum - tb.Minimum;
  983. tb.Value = value_pos + tb.Minimum;
  984. }
  985. thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
  986. /* Draw thumb fixed 10x22 size */
  987. thumb_pos.Width = 10;
  988. thumb_pos.Height = 22;
  989. switch (tb.TickStyle) {
  990. case TickStyle.BottomRight:
  991. case TickStyle.None:
  992. {
  993. thumb_pos.X = channel_startpoint.X - 8;
  994. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
  995. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
  996. dc.DrawLine (pen_buttonhilight, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
  997. dc.DrawLine (pen_buttonshadow, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
  998. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
  999. dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
  1000. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
  1001. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
  1002. dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
  1003. dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
  1004. dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
  1005. break;
  1006. }
  1007. case TickStyle.TopLeft:
  1008. {
  1009. thumb_pos.X = channel_startpoint.X - 10;
  1010. dc.DrawLine (pen_buttonhilight, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
  1011. dc.DrawLine (pen_buttonhilight, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
  1012. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
  1013. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
  1014. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
  1015. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
  1016. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
  1017. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
  1018. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
  1019. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
  1020. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
  1021. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
  1022. break;
  1023. }
  1024. case TickStyle.Both:
  1025. {
  1026. thumb_pos.X = area.X + 10;
  1027. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
  1028. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
  1029. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
  1030. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
  1031. dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
  1032. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
  1033. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
  1034. break;
  1035. }
  1036. default:
  1037. break;
  1038. }
  1039. pixel_len = thumb_area.Height - 11;
  1040. pixels_betweenticks = pixel_len / ticks;
  1041. /* Draw ticks*/
  1042. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
  1043. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1044. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1045. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1046. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
  1047. area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
  1048. else
  1049. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
  1050. area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
  1051. }
  1052. }
  1053. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
  1054. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1055. pixel_len = thumb_area.Height - 11;
  1056. pixels_betweenticks = pixel_len / ticks;
  1057. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks)
  1058. {
  1059. //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
  1060. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1061. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
  1062. area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
  1063. else
  1064. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
  1065. area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
  1066. }
  1067. }
  1068. }
  1069. /*
  1070. Horizontal trackbar
  1071. Does not matter the size of the control, Win32 always draws:
  1072. - Ticks starting from pixel 13, 8
  1073. - Channel starting at pos 8, 19 and ends at Width - 8
  1074. - Autosize makes always the control 40 pixels height
  1075. - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
  1076. */
  1077. private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
  1078. ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
  1079. float ticks, int value_pos, bool mouse_value)
  1080. {
  1081. Point toptick_startpoint = new Point ();
  1082. Point bottomtick_startpoint = new Point ();
  1083. Point channel_startpoint = new Point ();
  1084. float pixel_len;
  1085. float pixels_betweenticks;
  1086. const int space_from_right = 8;
  1087. const int space_from_left = 8;
  1088. switch (tb.TickStyle) {
  1089. case TickStyle.BottomRight:
  1090. case TickStyle.None:
  1091. channel_startpoint.X = 8;
  1092. channel_startpoint.Y = 9;
  1093. bottomtick_startpoint.X = 13;
  1094. bottomtick_startpoint.Y = 24;
  1095. break;
  1096. case TickStyle.TopLeft:
  1097. channel_startpoint.X = 8;
  1098. channel_startpoint.Y = 19;
  1099. toptick_startpoint.X = 13;
  1100. toptick_startpoint.Y = 8;
  1101. break;
  1102. case TickStyle.Both:
  1103. channel_startpoint.X = 8;
  1104. channel_startpoint.Y = 18;
  1105. bottomtick_startpoint.X = 13;
  1106. bottomtick_startpoint.Y = 32;
  1107. toptick_startpoint.X = 13;
  1108. toptick_startpoint.Y = 8;
  1109. break;
  1110. default:
  1111. break;
  1112. }
  1113. thumb_area.X = area.X + channel_startpoint.X;
  1114. thumb_area.Y = area.Y + channel_startpoint.Y;
  1115. thumb_area.Width = area.Width - space_from_right - space_from_left;
  1116. thumb_area.Height = 4;
  1117. /* Draw channel */
  1118. dc.FillRectangle (br_buttonshadow, channel_startpoint.X, channel_startpoint.Y,
  1119. thumb_area.Width, 1);
  1120. dc.FillRectangle (br_buttondkshadow, channel_startpoint.X, channel_startpoint.Y + 1,
  1121. thumb_area.Width, 1);
  1122. dc.FillRectangle (br_buttonhilight, channel_startpoint.X, channel_startpoint.Y +3,
  1123. thumb_area.Width, 1);
  1124. pixel_len = thumb_area.Width - 11;
  1125. pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
  1126. /* Convert thumb position from mouse position to value*/
  1127. if (mouse_value) {
  1128. if (value_pos >= channel_startpoint.X)
  1129. value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
  1130. else
  1131. value_pos = 0;
  1132. if (value_pos + tb.Minimum > tb.Maximum)
  1133. value_pos = tb.Maximum - tb.Minimum;
  1134. tb.Value = value_pos + tb.Minimum;
  1135. }
  1136. thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
  1137. /* Draw thumb fixed 10x22 size */
  1138. thumb_pos.Width = 10;
  1139. thumb_pos.Height = 22;
  1140. switch (tb.TickStyle) {
  1141. case TickStyle.BottomRight:
  1142. case TickStyle.None:
  1143. {
  1144. thumb_pos.Y = channel_startpoint.Y - 8;
  1145. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
  1146. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
  1147. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
  1148. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
  1149. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
  1150. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
  1151. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
  1152. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
  1153. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
  1154. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
  1155. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
  1156. break;
  1157. }
  1158. case TickStyle.TopLeft: {
  1159. thumb_pos.Y = channel_startpoint.Y - 10;
  1160. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
  1161. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
  1162. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
  1163. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
  1164. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
  1165. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
  1166. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
  1167. dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
  1168. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
  1169. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
  1170. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
  1171. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
  1172. break;
  1173. }
  1174. case TickStyle.Both: {
  1175. thumb_pos.Y = area.Y + 10;
  1176. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
  1177. dc.DrawLine (pen_buttonhilight, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
  1178. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
  1179. dc.DrawLine (pen_buttonshadow, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
  1180. dc.DrawLine (pen_buttondkshadow, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
  1181. dc.DrawLine (pen_buttondkshadow, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
  1182. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
  1183. break;
  1184. }
  1185. default:
  1186. break;
  1187. }
  1188. pixel_len = thumb_area.Width - 11;
  1189. pixels_betweenticks = pixel_len / ticks;
  1190. /* Draw ticks*/
  1191. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
  1192. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1193. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1194. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1195. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
  1196. area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
  1197. else
  1198. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
  1199. area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
  1200. }
  1201. }
  1202. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
  1203. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1204. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1205. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1206. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
  1207. area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
  1208. else
  1209. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
  1210. area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
  1211. }
  1212. }
  1213. }
  1214. public void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
  1215. ref Rectangle thumb_pos, ref Rectangle thumb_area, bool highli_thumb,
  1216. float ticks, int value_pos, bool mouse_value)
  1217. {
  1218. Brush br_thumb;
  1219. if (highli_thumb == true) {
  1220. if (br_trackbar_thumbhili == null)
  1221. br_trackbar_thumbhili = new HatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
  1222. br_thumb = (Brush) br_trackbar_thumbhili;
  1223. }
  1224. else
  1225. br_thumb = br_buttonface;
  1226. /* Control Background */
  1227. if (tb.BackColor == DefaultControlBackColor)
  1228. dc.FillRectangle (br_buttonface, area);
  1229. else {
  1230. if (br_trackbarbg == null || br_trackbarbg.Color != tb.BackColor)
  1231. br_trackbarbg = new SolidBrush (tb.BackColor);
  1232. dc.FillRectangle (br_trackbarbg, area);
  1233. }
  1234. if (tb.Focused) {
  1235. dc.FillRectangle (br_focus, area.X, area.Y, area.Width - 1, 1);
  1236. dc.FillRectangle (br_focus, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
  1237. dc.FillRectangle (br_focus, area.X, area.Y, 1, area.Height - 1);
  1238. dc.FillRectangle (br_focus, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
  1239. }
  1240. if (tb.Orientation == Orientation.Vertical)
  1241. DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
  1242. br_thumb, ticks, value_pos, mouse_value);
  1243. else
  1244. DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
  1245. br_thumb, ticks, value_pos, mouse_value);
  1246. }
  1247. public void DrawProgressBar (Graphics dc, Rectangle area, Rectangle client_area,
  1248. int barpos_pixels, int block_width)
  1249. {
  1250. int space_betweenblocks = 2;
  1251. int increment = block_width + space_betweenblocks;
  1252. int x = client_area.X;
  1253. /* Background*/
  1254. dc.FillRectangle (br_buttonface, area);
  1255. /* Draw background*/
  1256. while ((x - client_area.X) < barpos_pixels) {
  1257. dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
  1258. x = x + increment;
  1259. }
  1260. /* Draw border */
  1261. DrawBorder3D (dc, area, Border3DStyle.SunkenInner, Border3DSide.All);
  1262. }
  1263. public void DrawLabel (Graphics dc, Rectangle area, BorderStyle border_style, string text,
  1264. Color fore_color, Color back_color, Font font, StringFormat string_format, bool Enabled)
  1265. {
  1266. if (label_br_fore_color == null || label_br_fore_color.Color != fore_color)
  1267. label_br_fore_color = GetControlForeBrush (fore_color);
  1268. if (label_br_back_color == null || label_br_back_color.Color != back_color)
  1269. label_br_back_color = GetControlBackBrush (back_color);
  1270. dc.FillRectangle (label_br_back_color, area);
  1271. DrawBorderStyle (dc, area, border_style);
  1272. if (Enabled)
  1273. dc.DrawString (text, font, label_br_fore_color, area, string_format);
  1274. else
  1275. ControlPaint.DrawStringDisabled (dc, text, font, fore_color, area, string_format);
  1276. }
  1277. public void DrawStatusBar (Graphics dc, Rectangle area, StatusBar sb)
  1278. {
  1279. int horz_border = 2;
  1280. int vert_border = 2;
  1281. dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
  1282. if (sb.ShowPanels && sb.Panels.Count == 0) {
  1283. // Create a default panel.
  1284. SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
  1285. StatusBarPanel panel = new StatusBarPanel ();
  1286. Rectangle new_area = new Rectangle (area.X + horz_border,
  1287. area.Y + horz_border,
  1288. area.Width - SizeGripWidth - horz_border,
  1289. area.Height - horz_border);
  1290. DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
  1291. } else if (sb.ShowPanels) {
  1292. SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
  1293. int prev_x = area.X + horz_border;
  1294. int y = area.Y + vert_border;
  1295. for (int i = 0; i < sb.Panels.Count; i++) {
  1296. Rectangle pr = new Rectangle (prev_x, y,
  1297. sb.Panels [i].Width, area.Height);
  1298. prev_x += pr.Width + StatusBarHorzGapWidth;
  1299. DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
  1300. }
  1301. }
  1302. if (sb.SizingGrip)
  1303. DrawSizeGrip (dc, ColorButtonFace, area);
  1304. }
  1305. public void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
  1306. SolidBrush br_forecolor, StatusBarPanel panel)
  1307. {
  1308. int border_size = 3; // this is actually const, even if the border style is none
  1309. area.Height -= border_size;
  1310. if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
  1311. Border3DStyle border_style = Border3DStyle.SunkenInner;
  1312. if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
  1313. border_style = Border3DStyle.RaisedOuter;
  1314. DrawBorder3D(dc, area, border_style, Border3DSide.All);
  1315. }
  1316. if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
  1317. StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
  1318. dc, panel.Parent.Font, area, index, DrawItemState.Default,
  1319. panel, panel.Parent.ForeColor, panel.Parent.BackColor);
  1320. panel.Parent.OnDrawItemInternal (e);
  1321. return;
  1322. }
  1323. int left = area.Left;
  1324. if (panel.Icon != null) {
  1325. left += 2;
  1326. int size = area.Height - border_size;
  1327. Rectangle ia = new Rectangle (left, border_size, size, size);
  1328. dc.DrawIcon (panel.Icon, left, area.Top);
  1329. left += panel.Icon.Width;
  1330. }
  1331. if (panel.Text == String.Empty)
  1332. return;
  1333. string text = panel.Text;
  1334. StringFormat string_format = new StringFormat ();
  1335. string_format.LineAlignment = StringAlignment.Center;
  1336. string_format.Alignment = StringAlignment.Near;
  1337. string_format.FormatFlags = StringFormatFlags.NoWrap;
  1338. if (text [0] == '\t') {
  1339. string_format.Alignment = StringAlignment.Center;
  1340. text = text.Substring (1);
  1341. if (text [0] == '\t') {
  1342. string_format.Alignment = StringAlignment.Far;
  1343. text = text.Substring (1);
  1344. }
  1345. }
  1346. float x = left + border_size;
  1347. float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
  1348. dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
  1349. }
  1350. public void DrawOwnerDrawBackground (DrawItemEventArgs e)
  1351. {
  1352. if (e.State == DrawItemState.Selected) {
  1353. e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
  1354. return;
  1355. }
  1356. e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
  1357. }
  1358. public void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
  1359. {
  1360. if (e.State == DrawItemState.Focus)
  1361. DrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
  1362. }
  1363. /*
  1364. Private methods
  1365. */
  1366. private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
  1367. int width, Color color, ButtonBorderStyle style, Border3DSide side) {
  1368. Pen pen=new Pen(color, 1);
  1369. switch(style) {
  1370. case ButtonBorderStyle.Solid: {
  1371. pen.DashStyle=DashStyle.Solid;
  1372. break;
  1373. }
  1374. case ButtonBorderStyle.Dashed: {
  1375. pen.DashStyle=DashStyle.Dash;
  1376. break;
  1377. }
  1378. case ButtonBorderStyle.Dotted: {
  1379. pen.DashStyle=DashStyle.Dot;
  1380. break;
  1381. }
  1382. case ButtonBorderStyle.Inset: {
  1383. pen.DashStyle=DashStyle.Solid;
  1384. break;
  1385. }
  1386. case ButtonBorderStyle.Outset: {
  1387. pen.DashStyle=DashStyle.Solid;
  1388. break;
  1389. }
  1390. default:
  1391. case ButtonBorderStyle.None: {
  1392. pen.Dispose();
  1393. return;
  1394. }
  1395. }
  1396. switch(style) {
  1397. case ButtonBorderStyle.Outset: {
  1398. Color colorGrade;
  1399. int hue, brightness, saturation;
  1400. int brightnessSteps;
  1401. int brightnessDownSteps;
  1402. ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
  1403. brightnessDownSteps=brightness/width;
  1404. if (brightness>127) {
  1405. brightnessSteps=Math.Max(6, (160-brightness)/width);
  1406. } else {
  1407. brightnessSteps=(127-brightness)/width;
  1408. }
  1409. for (int i=0; i<width; i++) {
  1410. switch(side) {
  1411. case Border3DSide.Left: {
  1412. pen.Dispose();
  1413. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1414. pen=new Pen(colorGrade, 1);
  1415. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1416. break;
  1417. }
  1418. case Border3DSide.Right: {
  1419. pen.Dispose();
  1420. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1421. pen=new Pen(colorGrade, 1);
  1422. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1423. break;
  1424. }
  1425. case Border3DSide.Top: {
  1426. pen.Dispose();
  1427. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1428. pen=new Pen(colorGrade, 1);
  1429. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1430. break;
  1431. }
  1432. case Border3DSide.Bottom: {
  1433. pen.Dispose();
  1434. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1435. pen=new Pen(colorGrade, 1);
  1436. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1437. break;
  1438. }
  1439. }
  1440. }
  1441. break;
  1442. }
  1443. case ButtonBorderStyle.Inset: {
  1444. Color colorGrade;
  1445. int hue, brightness, saturation;
  1446. int brightnessSteps;
  1447. int brightnessDownSteps;
  1448. ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
  1449. brightnessDownSteps=brightness/width;
  1450. if (brightness>127) {
  1451. brightnessSteps=Math.Max(6, (160-brightness)/width);
  1452. } else {
  1453. brightnessSteps=(127-brightness)/width;
  1454. }
  1455. for (int i=0; i<width; i++) {
  1456. switch(side) {
  1457. case Border3DSide.Left: {
  1458. pen.Dispose();
  1459. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1460. pen=new Pen(colorGrade, 1);
  1461. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1462. break;
  1463. }
  1464. case Border3DSide.Right: {
  1465. pen.Dispose();
  1466. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1467. pen=new Pen(colorGrade, 1);
  1468. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1469. break;
  1470. }
  1471. case Border3DSide.Top: {
  1472. pen.Dispose();
  1473. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1474. pen=new Pen(colorGrade, 1);
  1475. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1476. break;
  1477. }
  1478. case Border3DSide.Bottom: {
  1479. pen.Dispose();
  1480. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1481. pen=new Pen(colorGrade, 1);
  1482. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1483. break;
  1484. }
  1485. }
  1486. }
  1487. break;
  1488. }
  1489. /*
  1490. I decided to have the for-loop duplicated for speed reasons;
  1491. that way we only have to switch once (as opposed to have the
  1492. for-loop around the switch)
  1493. */
  1494. default: {
  1495. switch(side) {
  1496. case Border3DSide.Left: {
  1497. for (int i=0; i<width; i++) {
  1498. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1499. }
  1500. break;
  1501. }
  1502. case Border3DSide.Right: {
  1503. for (int i=0; i<width; i++) {
  1504. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1505. }
  1506. break;
  1507. }
  1508. case Border3DSide.Top: {
  1509. for (int i=0; i<width; i++) {
  1510. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1511. }
  1512. break;
  1513. }
  1514. case Border3DSide.Bottom: {
  1515. for (int i=0; i<width; i++) {
  1516. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1517. }
  1518. break;
  1519. }
  1520. }
  1521. break;
  1522. }
  1523. }
  1524. pen.Dispose();
  1525. }
  1526. /*
  1527. This function actually draws the various caption elements.
  1528. This way we can scale them nicely, no matter what size, and they
  1529. still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
  1530. */
  1531. private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
  1532. switch(button) {
  1533. case CaptionButton.Close: {
  1534. pen.StartCap=LineCap.Triangle;
  1535. pen.EndCap=LineCap.Triangle;
  1536. if (lineWidth<2) {
  1537. 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);
  1538. 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);
  1539. }
  1540. graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
  1541. graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
  1542. return;
  1543. }
  1544. case CaptionButton.Help: {
  1545. StringFormat sf = new StringFormat();
  1546. SolidBrush sb = new SolidBrush(color);
  1547. Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
  1548. sf.Alignment=StringAlignment.Center;
  1549. sf.LineAlignment=StringAlignment.Center;
  1550. graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
  1551. sf.Dispose();
  1552. sb.Dispose();
  1553. font.Dispose();
  1554. return;
  1555. }
  1556. case CaptionButton.Maximize: {
  1557. /* Top 'caption bar' line */
  1558. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1559. 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);
  1560. }
  1561. /* Left side line */
  1562. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1563. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
  1564. }
  1565. /* Right side line */
  1566. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1567. 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);
  1568. }
  1569. /* Bottom line */
  1570. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1571. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
  1572. }
  1573. return;
  1574. }
  1575. case CaptionButton.Minimize: {
  1576. /* Bottom line */
  1577. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1578. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
  1579. }
  1580. return;
  1581. }
  1582. case CaptionButton.Restore: {
  1583. /** First 'window' **/
  1584. /* Top 'caption bar' line */
  1585. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1586. 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);
  1587. }
  1588. /* Left side line */
  1589. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1590. 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);
  1591. }
  1592. /* Right side line */
  1593. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1594. 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);
  1595. }
  1596. /* Bottom line */
  1597. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1598. 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);
  1599. }
  1600. /** Second 'window' **/
  1601. /* Top 'caption bar' line */
  1602. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1603. 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);
  1604. }
  1605. /* Left side line */
  1606. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1607. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
  1608. }
  1609. /* Right side line */
  1610. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1611. 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);
  1612. }
  1613. /* Bottom line */
  1614. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1615. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
  1616. }
  1617. return;
  1618. }
  1619. }
  1620. }
  1621. [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
  1622. private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State)
  1623. {
  1624. switch(Type) {
  1625. case DrawFrameControlTypes.Button: {
  1626. if ((State & DrawFrameControlStates.ButtonPush)!=0) {
  1627. /* Goes first, affects the background */
  1628. if ((State & DrawFrameControlStates.Checked)!=0) {
  1629. HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
  1630. graphics.FillRectangle(hatchBrush,rectangle);
  1631. hatchBrush.Dispose();
  1632. }
  1633. if ((State & DrawFrameControlStates.Pushed)!=0) {
  1634. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1635. } else if ((State & DrawFrameControlStates.Flat)!=0) {
  1636. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  1637. } else if ((State & DrawFrameControlStates.Inactive)!=0) {
  1638. /* Same as normal, it would seem */
  1639. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1640. } else {
  1641. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1642. }
  1643. } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
  1644. Pen penFatDark = new Pen(ColorButtonShadow, 2);
  1645. Pen penFatLight = new Pen(SystemColors.ControlLight, 2);
  1646. int lineWidth;
  1647. graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
  1648. graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
  1649. graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
  1650. graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
  1651. lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
  1652. if ((State & DrawFrameControlStates.Checked)!=0) {
  1653. SolidBrush buttonBrush;
  1654. if ((State & DrawFrameControlStates.Inactive)!=0) {
  1655. buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
  1656. } else {
  1657. buttonBrush=(SolidBrush)SystemBrushes.ControlText;
  1658. }
  1659. graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
  1660. }
  1661. penFatDark.Dispose();
  1662. penFatLight.Dispose();
  1663. } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
  1664. throw new NotImplementedException () ;
  1665. } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
  1666. throw new NotImplementedException ();
  1667. } else { /* Must be Checkbox */
  1668. Pen pen;
  1669. int lineWidth;
  1670. Rectangle rect;
  1671. int Scale;
  1672. /* FIXME: I'm sure there's an easier way to calculate all this, but it should do for now */
  1673. /* Goes first, affects the background */
  1674. if ((State & DrawFrameControlStates.Pushed)!=0) {
  1675. HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
  1676. graphics.FillRectangle(hatchBrush,rectangle);
  1677. hatchBrush.Dispose();
  1678. }
  1679. /* Draw the sunken frame */
  1680. if ((State & DrawFrameControlStates.Flat)!=0) {
  1681. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  1682. } else {
  1683. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1684. }
  1685. /* Make sure we've got at least a line width of 1 */
  1686. lineWidth=Math.Max(3, rectangle.Width/6);
  1687. Scale=Math.Max(1, rectangle.Width/12);
  1688. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  1689. if ((State & DrawFrameControlStates.Inactive)!=0) {
  1690. pen=SystemPens.ControlDark;
  1691. } else {
  1692. pen=SystemPens.ControlText;
  1693. }
  1694. if ((State & DrawFrameControlStates.Checked)!=0) {
  1695. /* Need to draw a check-mark */
  1696. for (int i=0; i<lineWidth; i++) {
  1697. graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
  1698. 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);
  1699. }
  1700. }
  1701. }
  1702. return;
  1703. }
  1704. case DrawFrameControlTypes.Caption: {
  1705. // FIXME:
  1706. break;
  1707. }
  1708. case DrawFrameControlTypes.Menu: {
  1709. // FIXME:
  1710. break;
  1711. }
  1712. case DrawFrameControlTypes.Scroll: {
  1713. // FIXME:
  1714. break;
  1715. }
  1716. }
  1717. }
  1718. /* Generic scroll button */
  1719. static public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state)
  1720. {
  1721. if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
  1722. dc.FillRectangle (br_buttonface, area.X + 1,
  1723. area.Y + 1, area.Width - 2 , area.Height - 2);
  1724. dc.DrawRectangle (pen_buttonshadow, area.X,
  1725. area.Y, area.Width, area.Height);
  1726. }
  1727. if (state == ButtonState.Normal) {
  1728. dc.FillRectangle (new SolidBrush (Color.Blue), area);
  1729. dc.FillRectangle (br_buttonface, area.X, area.Y, area.Width, 1);
  1730. dc.FillRectangle (br_buttonface, area.X, area.Y, 1, area.Height);
  1731. dc.FillRectangle (br_buttonhilight, area.X + 1, area.Y + 1, area.Width - 1, 1);
  1732. dc.FillRectangle (br_buttonhilight, area.X + 1, area.Y + 2, 1,
  1733. area.Height - 4);
  1734. dc.FillRectangle (br_buttonshadow, area.X + 1, area.Y + area.Height - 2,
  1735. area.Width - 2, 1);
  1736. dc.FillRectangle (br_buttondkshadow, area.X, area.Y + area.Height -1,
  1737. area.Width , 1);
  1738. dc.FillRectangle (br_buttonshadow, area.X + area.Width - 2,
  1739. area.Y + 1, 1, area.Height -3);
  1740. dc.FillRectangle (br_buttondkshadow, area.X + area.Width -1,
  1741. area.Y, 1, area.Height - 1);
  1742. dc.FillRectangle (br_buttonface, area.X + 2,
  1743. area.Y + 2, area.Width - 4, area.Height - 4);
  1744. }
  1745. }
  1746. private void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style)
  1747. {
  1748. switch (border_style){
  1749. case BorderStyle.Fixed3D:
  1750. dc.DrawLine (pen_buttonshadow, area.X, area.Y, area.X +area.Width, area.Y);
  1751. dc.DrawLine (pen_buttonshadow, area.X, area.Y, area.X, area.Y + area.Height);
  1752. dc.DrawLine (pen_buttonhilight, area.X , area.Y + area.Height - 1, area.X + area.Width ,
  1753. area.Y + area.Height - 1);
  1754. dc.DrawLine (pen_buttonhilight, area.X + area.Width -1 , area.Y, area.X + area.Width -1,
  1755. area.Y + area.Height);
  1756. break;
  1757. case BorderStyle.FixedSingle:
  1758. dc.DrawRectangle (pen_windowframe, area.X, area.Y, area.Width - 1, area.Height - 1);
  1759. break;
  1760. case BorderStyle.None:
  1761. default:
  1762. break;
  1763. }
  1764. }
  1765. private SolidBrush GetControlBackBrush (Color c)
  1766. {
  1767. if (c == DefaultControlBackColor)
  1768. return br_buttonface;
  1769. return new SolidBrush (c);
  1770. }
  1771. private SolidBrush GetControlForeBrush (Color c)
  1772. {
  1773. if (c == DefaultControlForeColor)
  1774. return br_buttontext;
  1775. return new SolidBrush (c);
  1776. }
  1777. } //class
  1778. }