ThemeWin32Classic.cs 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526
  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.37 $
  29. // $Modtime: $
  30. // $Log: ThemeWin32Classic.cs,v $
  31. // Revision 1.37 2004/09/09 08:28:11 pbartok
  32. // - Improve disabled string look
  33. //
  34. // Revision 1.36 2004/09/09 03:03:49 ravindra
  35. // PictureBox would not draw a null image to avoid crash.
  36. //
  37. // Revision 1.35 2004/09/07 17:12:26 jordi
  38. // GroupBox control
  39. //
  40. // Revision 1.34 2004/09/07 09:40:15 jordi
  41. // LinkLabel fixes, methods, multiple links
  42. //
  43. // Revision 1.33 2004/09/05 08:03:51 jordi
  44. // fixes bugs, adds flashing on certain situations
  45. //
  46. // Revision 1.32 2004/09/02 16:32:54 jordi
  47. // implements resource pool for pens, brushes, and hatchbruses
  48. //
  49. // Revision 1.31 2004/08/25 20:04:40 ravindra
  50. // Added the missing divider code and grip for ToolBar Control.
  51. //
  52. // Revision 1.30 2004/08/25 18:29:14 jordi
  53. // new methods, properties, and fixes for progressbar
  54. //
  55. // Revision 1.29 2004/08/25 00:43:13 ravindra
  56. // Fixed wrapping related issues in ToolBar control.
  57. //
  58. // Revision 1.28 2004/08/24 18:37:02 jordi
  59. // fixes formmating, methods signature, and adds missing events
  60. //
  61. // Revision 1.27 2004/08/24 16:16:46 jackson
  62. // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
  63. //
  64. // Revision 1.26 2004/08/21 01:52:08 ravindra
  65. // Improvments in mouse event handling in the ToolBar control.
  66. //
  67. // Revision 1.25 2004/08/20 00:12:51 jordi
  68. // fixes methods signature
  69. //
  70. // Revision 1.24 2004/08/19 22:25:31 jordi
  71. // theme enhancaments
  72. //
  73. // Revision 1.23 2004/08/18 19:16:53 jordi
  74. // Move colors to a table
  75. //
  76. // Revision 1.22 2004/08/17 19:29:11 jackson
  77. // Don't use KnownColor to create colours. It has a large startup time.
  78. //
  79. // Revision 1.21 2004/08/15 23:20:54 ravindra
  80. // Changes to Theme for ToolBar control and also dos2unix format.
  81. //
  82. // Revision 1.20 2004/08/13 21:22:18 jordi
  83. // removes redundant code and fixes issues with tickposition
  84. //
  85. // Revision 1.19 2004/08/12 20:29:01 jordi
  86. // Trackbar enhancement, fix mouse problems, highli thumb, etc
  87. //
  88. // Revision 1.18 2004/08/12 18:54:37 jackson
  89. // Handle owner draw status bars
  90. //
  91. // Revision 1.17 2004/08/11 01:31:35 jackson
  92. // Create Brushes as little as possible
  93. //
  94. // Revision 1.16 2004/08/10 19:21:27 jordi
  95. // scrollbar enhancements and standarize on win colors defaults
  96. //
  97. // Revision 1.15 2004/08/10 18:52:30 jackson
  98. // Implement DrawItem functionality
  99. //
  100. // Revision 1.14 2004/08/09 21:34:54 jackson
  101. // Add support for drawing status bar and get status bar item sizes
  102. //
  103. // Revision 1.13 2004/08/09 21:21:49 jackson
  104. // Use known colors for default control colours
  105. //
  106. // Revision 1.12 2004/08/09 21:12:15 jackson
  107. // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
  108. //
  109. // Revision 1.11 2004/08/09 17:31:13 jackson
  110. // New names for control properties
  111. //
  112. // Revision 1.10 2004/08/09 17:00:00 jackson
  113. // Add default window color properties
  114. //
  115. // Revision 1.9 2004/08/09 16:17:19 jackson
  116. // Use correct default back color
  117. //
  118. // Revision 1.8 2004/08/09 15:53:12 jackson
  119. // Themes now handle default control properties so coloring will be consistent
  120. //
  121. // Revision 1.7 2004/08/08 22:54:21 jordi
  122. // Label BorderStyles
  123. //
  124. // Revision 1.6 2004/08/08 18:09:53 jackson
  125. // Add pen_buttonface
  126. //
  127. // Revision 1.5 2004/08/08 17:34:28 jordi
  128. // Use Windows Standard Colours
  129. //
  130. // Revision 1.4 2004/08/07 23:31:15 jordi
  131. // fixes label bug and draw method name
  132. //
  133. // Revision 1.3 2004/08/07 19:05:44 jordi
  134. // Theme colour support and GetSysColor defines
  135. //
  136. // Revision 1.2 2004/08/07 00:01:39 pbartok
  137. // - Fixed some rounding issues with float/int
  138. //
  139. // Revision 1.1 2004/07/26 17:42:03 jordi
  140. // Theme support
  141. //
  142. //
  143. using System.Drawing;
  144. using System.Drawing.Drawing2D;
  145. using System.Drawing.Imaging;
  146. namespace System.Windows.Forms
  147. {
  148. internal class ThemeWin32Classic : Theme
  149. {
  150. /* Default colors for Win32 classic theme */
  151. uint [] theme_colors = { /* AARRGGBB */
  152. (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR, 0xffc0c0c0,
  153. (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND, 0xff008080,
  154. (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION, 0xff000080,
  155. (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION, 0xff808080,
  156. (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU, 0xffc0c0c0,
  157. (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW, 0xffffffff,
  158. (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME, 0xff000000,
  159. (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT, 0xff000000,
  160. (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT, 0xff000000,
  161. (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT, 0xffffffff,
  162. (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER, 0xffc0c0c0,
  163. (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER, 0xffc0c0c0,
  164. (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE, 0xff808080,
  165. (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT, 0xff000080,
  166. (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT, 0xffffffff,
  167. (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE, 0xffc0c0c0,
  168. (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW, 0xff808080,
  169. (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT, 0xff808080,
  170. (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT, 0xff000000,
  171. (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, 0xffc0c0c0,
  172. (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT, 0xffffffff,
  173. (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW, 0xff000000,
  174. (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT, 0xffe0e0e0,
  175. (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT, 0xff000000,
  176. (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK, 0xffffffff,
  177. };
  178. static protected Pen pen_ticks;
  179. static protected SolidBrush br_arrow;
  180. static protected SolidBrush br_progressbarblock;
  181. static protected Pen pen_arrow;
  182. /* Cache */
  183. protected SolidBrush label_br_fore_color;
  184. protected SolidBrush label_br_back_color;
  185. public ThemeWin32Classic ()
  186. {
  187. label_br_fore_color = null;
  188. label_br_back_color = null;
  189. /* Init Default colour array*/
  190. syscolors = Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
  191. for (int i = 0; i < theme_colors.Length; i +=2)
  192. syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
  193. pen_ticks = new Pen (Color.Black);
  194. br_arrow = new SolidBrush (Color.Black);
  195. pen_arrow = new Pen (Color.Black);
  196. br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128));
  197. defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10);
  198. defaultWindowForeColor = ColorButtonText;
  199. default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
  200. }
  201. public override bool WriteToWindow {
  202. get {return false; }
  203. }
  204. public override int SizeGripWidth {
  205. get { return 15; }
  206. }
  207. public override int StatusBarHorzGapWidth {
  208. get { return 3; }
  209. }
  210. public override int ScrollBarButtonSize {
  211. get { return 16; }
  212. }
  213. /*
  214. * ToolBar Control properties
  215. */
  216. // Grip width for the ToolBar
  217. public override int ToolBarGripWidth
  218. {
  219. get { return 2;}
  220. }
  221. // Grip width for the Image on the ToolBarButton
  222. public override int ToolBarImageGripWidth
  223. {
  224. get { return 2;}
  225. }
  226. // width of the separator
  227. public override int ToolBarSeparatorWidth {
  228. get { return 4; }
  229. }
  230. // width of the dropdown arrow rect
  231. public override int ToolBarDropDownWidth {
  232. get { return 13; }
  233. }
  234. // width for the dropdown arrow on the ToolBarButton
  235. public override int ToolBarDropDownArrowWidth {
  236. get { return 5;}
  237. }
  238. // height for the dropdown arrow on the ToolBarButton
  239. public override int ToolBarDropDownArrowHeight {
  240. get { return 3;}
  241. }
  242. private enum DrawFrameControlStates
  243. {
  244. ButtonCheck = 0x0000,
  245. ButtonRadioImage = 0x0001,
  246. ButtonRadioMask = 0x0002,
  247. ButtonRadio = 0x0004,
  248. Button3State = 0x0008,
  249. ButtonPush = 0x0010,
  250. CaptionClose = 0x0000,
  251. CaptionMin = 0x0001,
  252. CaptionMax = 0x0002,
  253. CaptionRestore = 0x0004,
  254. CaptionHelp = 0x0008,
  255. MenuArrow = 0x0000,
  256. MenuCheck = 0x0001,
  257. MenuBullet = 0x0002,
  258. MenuArrowRight = 0x0004,
  259. ScrollUp = 0x0000,
  260. ScrollDown = 0x0001,
  261. ScrollLeft = 0x0002,
  262. ScrollRight = 0x0003,
  263. ScrollComboBox = 0x0005,
  264. ScrollSizeGrip = 0x0008,
  265. ScrollSizeGripRight = 0x0010,
  266. Inactive = 0x0100,
  267. Pushed = 0x0200,
  268. Checked = 0x0400,
  269. Transparent = 0x0800,
  270. Hot = 0x1000,
  271. AdjustRect = 0x2000,
  272. Flat = 0x4000,
  273. Mono = 0x8000
  274. }
  275. private enum DrawFrameControlTypes
  276. {
  277. Caption = 1,
  278. Menu = 2,
  279. Scroll = 3,
  280. Button = 4
  281. }
  282. /*
  283. Methods that mimic ControlPaint signature and draw basic objects
  284. */
  285. public override void DrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
  286. ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
  287. Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
  288. int bottomWidth, ButtonBorderStyle bottomStyle)
  289. {
  290. DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
  291. DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
  292. DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
  293. DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
  294. }
  295. public override void DrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides)
  296. {
  297. Pen penTopLeft;
  298. Pen penTopLeftInner;
  299. Pen penBottomRight;
  300. Pen penBottomRightInner;
  301. Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
  302. bool doInner = false;
  303. if ((style & Border3DStyle.Adjust)!=0) {
  304. rect.Y-=2;
  305. rect.X-=2;
  306. rect.Width+=4;
  307. rect.Height+=4;
  308. }
  309. /* default to flat */
  310. penTopLeft=SystemPens.ControlDark;
  311. penTopLeftInner=SystemPens.ControlDark;
  312. penBottomRight=SystemPens.ControlDark;
  313. penBottomRightInner=SystemPens.ControlDark;
  314. if ((style & Border3DStyle.RaisedOuter)!=0) {
  315. penTopLeft=SystemPens.ControlLightLight;
  316. penBottomRight=SystemPens.ControlDarkDark;
  317. if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
  318. doInner=true;
  319. }
  320. } else if ((style & Border3DStyle.SunkenOuter)!=0) {
  321. penTopLeft=SystemPens.ControlDarkDark;
  322. penBottomRight=SystemPens.ControlLightLight;
  323. if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
  324. doInner=true;
  325. }
  326. }
  327. if ((style & Border3DStyle.RaisedInner)!=0) {
  328. if (doInner) {
  329. penTopLeftInner=SystemPens.ControlLight;
  330. penBottomRightInner=SystemPens.ControlDark;
  331. } else {
  332. penTopLeft=SystemPens.ControlLightLight;
  333. penBottomRight=SystemPens.ControlDarkDark;
  334. }
  335. } else if ((style & Border3DStyle.SunkenInner)!=0) {
  336. if (doInner) {
  337. penTopLeftInner=SystemPens.ControlDark;
  338. penBottomRightInner=SystemPens.ControlLight;
  339. } else {
  340. penTopLeft=SystemPens.ControlDarkDark;
  341. penBottomRight=SystemPens.ControlLightLight;
  342. }
  343. }
  344. if ((sides & Border3DSide.Middle)!=0) {
  345. graphics.FillRectangle(SystemBrushes.Control, rect);
  346. }
  347. if ((sides & Border3DSide.Left)!=0) {
  348. graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-1, rect.Left, rect.Top);
  349. if (doInner) {
  350. graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-1, rect.Left+1, rect.Top);
  351. }
  352. }
  353. if ((sides & Border3DSide.Top)!=0) {
  354. graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-1, rect.Top);
  355. if (doInner) {
  356. if ((sides & Border3DSide.Left)!=0) {
  357. graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-1, rect.Top+1);
  358. } else {
  359. graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-1, rect.Top+1);
  360. }
  361. }
  362. }
  363. if ((sides & Border3DSide.Right)!=0) {
  364. graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
  365. if (doInner) {
  366. if ((sides & Border3DSide.Top)!=0) {
  367. graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-1);
  368. } else {
  369. graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-1);
  370. }
  371. }
  372. }
  373. if ((sides & Border3DSide.Bottom)!=0) {
  374. int left=rect.Left;
  375. if ((sides & Border3DSide.Left)!=0) {
  376. left+=1;
  377. }
  378. graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
  379. if (doInner) {
  380. if ((sides & Border3DSide.Right)!=0) {
  381. graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
  382. } else {
  383. graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-1, rect.Bottom-2);
  384. }
  385. }
  386. }
  387. }
  388. public override void DrawButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  389. {
  390. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
  391. if ((state & ButtonState.Pushed)!=0) {
  392. dfcs |= DrawFrameControlStates.Pushed;
  393. }
  394. if ((state & ButtonState.Checked)!=0) {
  395. dfcs |= DrawFrameControlStates.Checked;
  396. }
  397. if ((state & ButtonState.Flat)!=0) {
  398. dfcs |= DrawFrameControlStates.Flat;
  399. }
  400. if ((state & ButtonState.Inactive)!=0) {
  401. dfcs |= DrawFrameControlStates.Inactive;
  402. }
  403. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  404. }
  405. public override void DrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
  406. {
  407. Rectangle captionRect;
  408. int lineWidth;
  409. DrawButton(graphics, rectangle, state);
  410. if (rectangle.Width<rectangle.Height) {
  411. captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
  412. } else {
  413. captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
  414. }
  415. if ((state & ButtonState.Pushed)!=0) {
  416. captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
  417. }
  418. /* Make sure we've got at least a line width of 1 */
  419. lineWidth=Math.Max(1, captionRect.Width/7);
  420. switch(button) {
  421. case CaptionButton.Close: {
  422. Pen pen;
  423. if ((state & ButtonState.Inactive)!=0) {
  424. pen=new Pen(ColorButtonHilight, lineWidth);
  425. DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
  426. pen.Dispose();
  427. pen=new Pen(ColorButtonShadow, lineWidth);
  428. DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
  429. pen.Dispose();
  430. return;
  431. } else {
  432. pen=new Pen(SystemColors.ControlText, lineWidth);
  433. DrawCaptionHelper(graphics, SystemColors.ControlText, pen, lineWidth, 0, captionRect, button);
  434. pen.Dispose();
  435. return;
  436. }
  437. }
  438. case CaptionButton.Help:
  439. case CaptionButton.Maximize:
  440. case CaptionButton.Minimize:
  441. case CaptionButton.Restore: {
  442. if ((state & ButtonState.Inactive)!=0) {
  443. DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
  444. DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
  445. return;
  446. } else {
  447. DrawCaptionHelper(graphics, SystemColors.ControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
  448. return;
  449. }
  450. }
  451. }
  452. }
  453. public override void DrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
  454. {
  455. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
  456. if ((state & ButtonState.Pushed)!=0) {
  457. dfcs |= DrawFrameControlStates.Pushed;
  458. }
  459. if ((state & ButtonState.Checked)!=0) {
  460. dfcs |= DrawFrameControlStates.Checked;
  461. }
  462. if ((state & ButtonState.Flat)!=0) {
  463. dfcs |= DrawFrameControlStates.Flat;
  464. }
  465. if ((state & ButtonState.Inactive)!=0) {
  466. dfcs |= DrawFrameControlStates.Inactive;
  467. }
  468. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  469. }
  470. public override void DrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  471. {
  472. Point[] arrow = new Point[3];
  473. Point P1;
  474. Point P2;
  475. Point P3;
  476. int centerX;
  477. int centerY;
  478. int shiftX;
  479. int shiftY;
  480. Rectangle rect;
  481. if ((state & ButtonState.Checked)!=0) {
  482. graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, SystemColors.ControlLight, ColorButtonHilight),rectangle);
  483. }
  484. if ((state & ButtonState.Flat)!=0) {
  485. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  486. } else {
  487. if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
  488. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  489. } else {
  490. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  491. }
  492. }
  493. rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
  494. centerX=rect.Left+rect.Width/2;
  495. centerY=rect.Top+rect.Height/2;
  496. shiftX=Math.Max(1, rect.Width/8);
  497. shiftY=Math.Max(1, rect.Height/8);
  498. if ((state & ButtonState.Pushed)!=0) {
  499. shiftX++;
  500. shiftY++;
  501. }
  502. rect.Y-=shiftY;
  503. centerY-=shiftY;
  504. P1=new Point(rect.Left, centerY);
  505. P2=new Point(rect.Right, centerY);
  506. P3=new Point(centerX, rect.Bottom);
  507. arrow[0]=P1;
  508. arrow[1]=P2;
  509. arrow[2]=P3;
  510. /* Draw the arrow */
  511. if ((state & ButtonState.Inactive)!=0) {
  512. graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
  513. /* Move away from the shadow */
  514. P1.X-=1; P1.Y-=1;
  515. P2.X-=1; P2.Y-=1;
  516. P3.X-=1; P3.Y-=1;
  517. arrow[0]=P1;
  518. arrow[1]=P2;
  519. arrow[2]=P3;
  520. graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
  521. } else {
  522. graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
  523. }
  524. }
  525. public override void DrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
  526. {
  527. Pen pen = new Pen(Color.Black, 1);
  528. Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
  529. int X;
  530. int Y;
  531. graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
  532. graphics.DrawRectangle(pen, rect);
  533. X=rect.X+rect.Width/2;
  534. Y=rect.Y+rect.Height/2;
  535. /* Draw the cross */
  536. graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
  537. graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
  538. /* Draw 'arrows' for vertical lines */
  539. graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
  540. graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
  541. /* Draw 'arrows' for horizontal lines */
  542. graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
  543. graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
  544. }
  545. public override void DrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
  546. {
  547. //Color colorForeInverted;
  548. Color colorBackInverted;
  549. Pen pen;
  550. //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
  551. //pen=new Pen(colorForeInverted, 1);
  552. // MS seems to always use black
  553. pen=new Pen(Color.Black, 1);
  554. graphics.DrawRectangle(pen, rectangle);
  555. pen.Dispose();
  556. colorBackInverted=Color.FromArgb(Math.Abs(backColor.R-255), Math.Abs(backColor.G-255), Math.Abs(backColor.B-255));
  557. pen=new Pen(colorBackInverted, 1);
  558. pen.DashStyle=DashStyle.Dot;
  559. graphics.DrawRectangle(pen, rectangle);
  560. pen.Dispose();
  561. }
  562. public override void DrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
  563. {
  564. SolidBrush sb;
  565. Pen pen;
  566. if (primary==true) {
  567. pen=new Pen(Color.Black, 1);
  568. if (enabled==true) {
  569. sb=ResPool.GetSolidBrush (ColorButtonText);
  570. } else {
  571. sb=ResPool.GetSolidBrush (ColorButtonFace);
  572. }
  573. } else {
  574. pen=new Pen(Color.White, 1);
  575. if (enabled==true) {
  576. sb=new SolidBrush(Color.Black);
  577. } else {
  578. sb=ResPool.GetSolidBrush (ColorButtonFace);
  579. }
  580. }
  581. graphics.FillRectangle(sb, rectangle);
  582. graphics.DrawRectangle(pen, rectangle);
  583. sb.Dispose();
  584. pen.Dispose();
  585. }
  586. public override void DrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor)
  587. {
  588. Color foreColor;
  589. int h;
  590. int b;
  591. int s;
  592. ControlPaint.Color2HBS(backColor, out h, out b, out s);
  593. if (b>127) {
  594. foreColor=Color.Black;
  595. } else {
  596. foreColor=Color.White;
  597. }
  598. #if false
  599. /* Commented out until I take the time and figure out
  600. which HatchStyle will match requirements. The code below
  601. is only correct for Percent50.
  602. */
  603. if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
  604. HatchBrush brush=null;
  605. switch(pixelsBetweenDots.Width) {
  606. case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
  607. case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
  608. case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
  609. default: {
  610. /* Have to do it the slow way */
  611. break;
  612. }
  613. }
  614. if (brush!=null) {
  615. graphics.FillRectangle(brush, area);
  616. pen.Dispose();
  617. brush.Dispose();
  618. return;
  619. }
  620. }
  621. #endif
  622. /* Slow method */
  623. Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
  624. for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
  625. for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
  626. bitmap.SetPixel(x, y, foreColor);
  627. }
  628. }
  629. graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
  630. bitmap.Dispose();
  631. }
  632. public override void DrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background)
  633. {
  634. /*
  635. Microsoft seems to ignore the background and simply make
  636. the image grayscale. At least when having > 256 colors on
  637. the display.
  638. */
  639. ImageAttributes imageAttributes=new ImageAttributes();
  640. ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
  641. // This table would create a perfect grayscale image, based on luminance
  642. // new float[]{0.3f,0.3f,0.3f,0,0},
  643. // new float[]{0.59f,0.59f,0.59f,0,0},
  644. // new float[]{0.11f,0.11f,0.11f,0,0},
  645. // new float[]{0,0,0,1,0,0},
  646. // new float[]{0,0,0,0,1,0},
  647. // new float[]{0,0,0,0,0,1}
  648. // This table generates a image that is grayscaled and then
  649. // brightened up. Seems to match MS close enough.
  650. new float[]{0.2f,0.2f,0.2f,0,0},
  651. new float[]{0.41f,0.41f,0.41f,0,0},
  652. new float[]{0.11f,0.11f,0.11f,0,0},
  653. new float[]{0.15f,0.15f,0.15f,1,0,0},
  654. new float[]{0.15f,0.15f,0.15f,0,1,0},
  655. new float[]{0.15f,0.15f,0.15f,0,0,1}
  656. });
  657. imageAttributes.SetColorMatrix(colorMatrix);
  658. graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
  659. imageAttributes.Dispose();
  660. }
  661. public override void DrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary)
  662. {
  663. Pen penBorder;
  664. Pen penInside;
  665. if (primary) {
  666. penBorder=new Pen(Color.White, 2);
  667. penInside=new Pen(Color.Black, 1);
  668. } else {
  669. penBorder=new Pen(Color.Black, 2);
  670. penInside=new Pen(Color.White, 1);
  671. }
  672. penBorder.Alignment=PenAlignment.Inset;
  673. penInside.Alignment=PenAlignment.Inset;
  674. graphics.DrawRectangle(penBorder, rectangle);
  675. graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
  676. penBorder.Dispose();
  677. penInside.Dispose();
  678. }
  679. public override void DrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph)
  680. {
  681. Rectangle rect;
  682. int lineWidth;
  683. // MS seems to draw the background white
  684. graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rectangle);
  685. switch(glyph) {
  686. case MenuGlyph.Arrow: {
  687. Point[] arrow = new Point[3];
  688. Point P1;
  689. Point P2;
  690. Point P3;
  691. int centerX;
  692. int centerY;
  693. int shiftX;
  694. int shiftY;
  695. rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
  696. centerX=rect.Left+rect.Width/2;
  697. centerY=rect.Top+rect.Height/2;
  698. shiftX=Math.Max(1, rect.Width/8);
  699. shiftY=Math.Max(1, rect.Height/8);
  700. rect.X-=shiftX;
  701. centerX-=shiftX;
  702. P1=new Point(centerX, rect.Top-1);
  703. P2=new Point(centerX, rect.Bottom);
  704. P3=new Point(rect.Right, centerY);
  705. arrow[0]=P1;
  706. arrow[1]=P2;
  707. arrow[2]=P3;
  708. graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
  709. return;
  710. }
  711. case MenuGlyph.Bullet: {
  712. SolidBrush sb;
  713. lineWidth=Math.Max(2, rectangle.Width/3);
  714. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  715. sb=ResPool.GetSolidBrush (ColorButtonText);
  716. graphics.FillEllipse(sb, rect);
  717. sb.Dispose();
  718. return;
  719. }
  720. case MenuGlyph.Checkmark: {
  721. int Scale;
  722. lineWidth=Math.Max(2, rectangle.Width/6);
  723. Scale=Math.Max(1, rectangle.Width/12);
  724. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  725. for (int i=0; i<lineWidth; i++) {
  726. graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
  727. 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);
  728. }
  729. return;
  730. }
  731. }
  732. }
  733. public override void DrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state)
  734. {
  735. DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
  736. if ((state & ButtonState.Pushed)!=0) {
  737. dfcs |= DrawFrameControlStates.Pushed;
  738. }
  739. if ((state & ButtonState.Checked)!=0) {
  740. dfcs |= DrawFrameControlStates.Checked;
  741. }
  742. if ((state & ButtonState.Flat)!=0) {
  743. dfcs |= DrawFrameControlStates.Flat;
  744. }
  745. if ((state & ButtonState.Inactive)!=0) {
  746. dfcs |= DrawFrameControlStates.Inactive;
  747. }
  748. DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
  749. }
  750. public override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
  751. {
  752. }
  753. public override void DrawReversibleLine (Point start, Point end, Color backColor)
  754. {
  755. }
  756. /* Scroll button: regular button + direction arrow */
  757. public override void DrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
  758. {
  759. bool enabled = (state == ButtonState.Inactive) ? false: true;
  760. DrawScrollButtonPrimitive (dc, area, state);
  761. /* Paint arrows */
  762. switch (type) {
  763. case ScrollButton.Up:
  764. {
  765. int x = area.X + (area.Width / 2) - 4;
  766. int y = area.Y + 9;
  767. for (int i = 0; i < 3; i++)
  768. if (enabled)
  769. dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
  770. else
  771. dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
  772. dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);
  773. break;
  774. }
  775. case ScrollButton.Down:
  776. {
  777. int x = area.X + (area.Width / 2) - 4;
  778. int y = area.Y + 5;
  779. for (int i = 4; i != 0; i--)
  780. if (enabled)
  781. dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
  782. else
  783. dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
  784. dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
  785. break;
  786. }
  787. case ScrollButton.Left:
  788. {
  789. int y = area.Y + (area.Height / 2) - 4;
  790. int x = area.X + 9;
  791. for (int i = 0; i < 3; i++)
  792. if (enabled)
  793. dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
  794. else
  795. dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
  796. dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
  797. break;
  798. }
  799. case ScrollButton.Right:
  800. {
  801. int y = area.Y + (area.Height / 2) - 4;
  802. int x = area.X + 5;
  803. for (int i = 4; i != 0; i--)
  804. if (enabled)
  805. dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
  806. else
  807. dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
  808. dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
  809. break;
  810. }
  811. default:
  812. break;
  813. }
  814. }
  815. public override void DrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
  816. Color backColor)
  817. {
  818. }
  819. public override void DrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
  820. {
  821. Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
  822. dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
  823. dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
  824. // diagonals
  825. for (int i = 0; i < 11; i += 4) {
  826. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
  827. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
  828. }
  829. for (int i = 3; i < 13; i += 4)
  830. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
  831. }
  832. public override void DrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
  833. StringFormat format)
  834. {
  835. SolidBrush brush;
  836. brush=new SolidBrush(ControlPaint.Light(color, 95));
  837. layoutRectangle.Offset(1.0f, 1.0f);
  838. graphics.DrawString(s, font, brush, layoutRectangle, format);
  839. brush.Color=ControlPaint.Light(color, 50);
  840. layoutRectangle.Offset(-1.0f, -1.0f);
  841. graphics.DrawString(s, font, brush, layoutRectangle, format);
  842. brush.Dispose();
  843. }
  844. /*
  845. Methods that draw complex controls
  846. */
  847. public override void DrawScrollBar (Graphics dc, Rectangle area, ScrollBar bar,
  848. ref Rectangle thumb_pos, ref Rectangle first_arrow_area, ref Rectangle second_arrow_area,
  849. ButtonState first_arrow, ButtonState second_arrow, ref int scrollbutton_width,
  850. ref int scrollbutton_height, bool vert)
  851. {
  852. if (vert) {
  853. first_arrow_area.X = first_arrow_area. Y = 0;
  854. first_arrow_area.Width = bar.Width;
  855. first_arrow_area.Height = scrollbutton_height;
  856. second_arrow_area.X = 0;
  857. second_arrow_area.Y = area.Height - scrollbutton_height;
  858. second_arrow_area.Width = bar.Width;
  859. second_arrow_area.Height = scrollbutton_height;
  860. thumb_pos.Width = bar.Width;
  861. /* Buttons */
  862. DrawScrollButton (dc, first_arrow_area, ScrollButton.Up, first_arrow);
  863. DrawScrollButton (dc, second_arrow_area, ScrollButton.Down, second_arrow);
  864. /* Background */
  865. switch (bar.thumb_moving) {
  866. case ScrollBar.ThumbMoving.None:
  867. {
  868. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), 0,
  869. scrollbutton_height, area.Width, area.Height - (scrollbutton_height * 2));
  870. break;
  871. }
  872. case ScrollBar.ThumbMoving.Forward: {
  873. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
  874. 0, scrollbutton_height,
  875. area.Width, thumb_pos.Y - scrollbutton_height);
  876. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
  877. 0, thumb_pos.Y + thumb_pos.Height,
  878. area.Width, area.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
  879. break;
  880. }
  881. case ScrollBar.ThumbMoving.Backwards: {
  882. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
  883. 0, scrollbutton_height,
  884. area.Width, thumb_pos.Y - scrollbutton_height);
  885. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
  886. 0, thumb_pos.Y + thumb_pos.Height,
  887. area.Width, area.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
  888. break;
  889. }
  890. default:
  891. break;
  892. }
  893. }
  894. else {
  895. first_arrow_area.X = first_arrow_area. Y = 0;
  896. first_arrow_area.Width = scrollbutton_width;
  897. first_arrow_area.Height = bar.Height;
  898. second_arrow_area.Y = 0;
  899. second_arrow_area.X = area.Width - scrollbutton_width;
  900. second_arrow_area.Width = scrollbutton_width;
  901. second_arrow_area.Height = bar.Height;
  902. thumb_pos.Height = bar.Height;
  903. /* Buttons */
  904. DrawScrollButton (dc, first_arrow_area, ScrollButton.Left, first_arrow );
  905. DrawScrollButton (dc, second_arrow_area, ScrollButton.Right, second_arrow);
  906. /* Background */
  907. //dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
  908. // 0, area.Width - (scrollbutton_width * 2), area.Height);
  909. switch (bar.thumb_moving) {
  910. case ScrollBar.ThumbMoving.None:
  911. {
  912. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
  913. 0, area.Width - (scrollbutton_width * 2), area.Height);
  914. break;
  915. }
  916. case ScrollBar.ThumbMoving.Forward: {
  917. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
  918. scrollbutton_width, 0,
  919. thumb_pos.X - scrollbutton_width, area.Height);
  920. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
  921. thumb_pos.X + thumb_pos.Width, 0,
  922. area.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, area.Height);
  923. break;
  924. }
  925. case ScrollBar.ThumbMoving.Backwards: {
  926. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
  927. scrollbutton_width, 0,
  928. thumb_pos.X - scrollbutton_width, area.Height);
  929. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
  930. thumb_pos.X + thumb_pos.Width, 0,
  931. area.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, area.Height);
  932. break;
  933. }
  934. default:
  935. break;
  936. }
  937. }
  938. /* Thumb */
  939. if (bar.Enabled)
  940. DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
  941. }
  942. /*
  943. DrawTrackBar
  944. */
  945. /* Vertical trackbar */
  946. private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
  947. ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
  948. float ticks, int value_pos, bool mouse_value)
  949. {
  950. Point toptick_startpoint = new Point ();
  951. Point bottomtick_startpoint = new Point ();
  952. Point channel_startpoint = new Point ();
  953. float pixel_len;
  954. float pixels_betweenticks;
  955. const int space_from_right = 8;
  956. const int space_from_left = 8;
  957. switch (tb.TickStyle) {
  958. case TickStyle.BottomRight:
  959. case TickStyle.None:
  960. channel_startpoint.Y = 8;
  961. channel_startpoint.X = 9;
  962. bottomtick_startpoint.Y = 13;
  963. bottomtick_startpoint.X = 24;
  964. break;
  965. case TickStyle.TopLeft:
  966. channel_startpoint.Y = 8;
  967. channel_startpoint.X = 19;
  968. toptick_startpoint.Y = 13;
  969. toptick_startpoint.X = 8;
  970. break;
  971. case TickStyle.Both:
  972. channel_startpoint.Y = 8;
  973. channel_startpoint.X = 18;
  974. bottomtick_startpoint.Y = 13;
  975. bottomtick_startpoint.X = 32;
  976. toptick_startpoint.Y = 13;
  977. toptick_startpoint.X = 8;
  978. break;
  979. default:
  980. break;
  981. }
  982. thumb_area.X = area.X + channel_startpoint.X;
  983. thumb_area.Y = area.Y + channel_startpoint.Y;
  984. thumb_area.Height = area.Height - space_from_right - space_from_left;
  985. thumb_area.Width = 4;
  986. /* Draw channel */
  987. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
  988. 1, thumb_area.Height);
  989. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
  990. 1, thumb_area.Height);
  991. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
  992. 1, thumb_area.Height);
  993. pixel_len = thumb_area.Height - 11;
  994. pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
  995. /* Convert thumb position from mouse position to value*/
  996. if (mouse_value) {
  997. if (value_pos >= channel_startpoint.Y)
  998. value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
  999. else
  1000. value_pos = 0;
  1001. if (value_pos + tb.Minimum > tb.Maximum)
  1002. value_pos = tb.Maximum - tb.Minimum;
  1003. tb.Value = value_pos + tb.Minimum;
  1004. }
  1005. thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
  1006. /* Draw thumb fixed 10x22 size */
  1007. thumb_pos.Width = 10;
  1008. thumb_pos.Height = 22;
  1009. switch (tb.TickStyle) {
  1010. case TickStyle.BottomRight:
  1011. case TickStyle.None:
  1012. {
  1013. thumb_pos.X = channel_startpoint.X - 8;
  1014. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
  1015. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
  1016. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
  1017. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
  1018. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
  1019. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
  1020. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
  1021. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
  1022. dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
  1023. dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
  1024. dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
  1025. break;
  1026. }
  1027. case TickStyle.TopLeft:
  1028. {
  1029. thumb_pos.X = channel_startpoint.X - 10;
  1030. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
  1031. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
  1032. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
  1033. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
  1034. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
  1035. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
  1036. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
  1037. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
  1038. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
  1039. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
  1040. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
  1041. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
  1042. break;
  1043. }
  1044. case TickStyle.Both:
  1045. {
  1046. thumb_pos.X = area.X + 10;
  1047. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
  1048. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
  1049. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
  1050. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
  1051. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
  1052. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
  1053. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
  1054. break;
  1055. }
  1056. default:
  1057. break;
  1058. }
  1059. pixel_len = thumb_area.Height - 11;
  1060. pixels_betweenticks = pixel_len / ticks;
  1061. /* Draw ticks*/
  1062. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
  1063. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1064. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1065. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1066. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
  1067. area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
  1068. else
  1069. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
  1070. area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
  1071. }
  1072. }
  1073. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
  1074. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1075. pixel_len = thumb_area.Height - 11;
  1076. pixels_betweenticks = pixel_len / ticks;
  1077. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks)
  1078. {
  1079. //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
  1080. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1081. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
  1082. area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
  1083. else
  1084. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
  1085. area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
  1086. }
  1087. }
  1088. }
  1089. /*
  1090. Horizontal trackbar
  1091. Does not matter the size of the control, Win32 always draws:
  1092. - Ticks starting from pixel 13, 8
  1093. - Channel starting at pos 8, 19 and ends at Width - 8
  1094. - Autosize makes always the control 40 pixels height
  1095. - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
  1096. */
  1097. private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
  1098. ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
  1099. float ticks, int value_pos, bool mouse_value)
  1100. {
  1101. Point toptick_startpoint = new Point ();
  1102. Point bottomtick_startpoint = new Point ();
  1103. Point channel_startpoint = new Point ();
  1104. float pixel_len;
  1105. float pixels_betweenticks;
  1106. const int space_from_right = 8;
  1107. const int space_from_left = 8;
  1108. switch (tb.TickStyle) {
  1109. case TickStyle.BottomRight:
  1110. case TickStyle.None:
  1111. channel_startpoint.X = 8;
  1112. channel_startpoint.Y = 9;
  1113. bottomtick_startpoint.X = 13;
  1114. bottomtick_startpoint.Y = 24;
  1115. break;
  1116. case TickStyle.TopLeft:
  1117. channel_startpoint.X = 8;
  1118. channel_startpoint.Y = 19;
  1119. toptick_startpoint.X = 13;
  1120. toptick_startpoint.Y = 8;
  1121. break;
  1122. case TickStyle.Both:
  1123. channel_startpoint.X = 8;
  1124. channel_startpoint.Y = 18;
  1125. bottomtick_startpoint.X = 13;
  1126. bottomtick_startpoint.Y = 32;
  1127. toptick_startpoint.X = 13;
  1128. toptick_startpoint.Y = 8;
  1129. break;
  1130. default:
  1131. break;
  1132. }
  1133. thumb_area.X = area.X + channel_startpoint.X;
  1134. thumb_area.Y = area.Y + channel_startpoint.Y;
  1135. thumb_area.Width = area.Width - space_from_right - space_from_left;
  1136. thumb_area.Height = 4;
  1137. /* Draw channel */
  1138. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
  1139. thumb_area.Width, 1);
  1140. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
  1141. thumb_area.Width, 1);
  1142. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
  1143. thumb_area.Width, 1);
  1144. pixel_len = thumb_area.Width - 11;
  1145. pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
  1146. /* Convert thumb position from mouse position to value*/
  1147. if (mouse_value) {
  1148. if (value_pos >= channel_startpoint.X)
  1149. value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
  1150. else
  1151. value_pos = 0;
  1152. if (value_pos + tb.Minimum > tb.Maximum)
  1153. value_pos = tb.Maximum - tb.Minimum;
  1154. tb.Value = value_pos + tb.Minimum;
  1155. }
  1156. thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
  1157. /* Draw thumb fixed 10x22 size */
  1158. thumb_pos.Width = 10;
  1159. thumb_pos.Height = 22;
  1160. switch (tb.TickStyle) {
  1161. case TickStyle.BottomRight:
  1162. case TickStyle.None:
  1163. {
  1164. thumb_pos.Y = channel_startpoint.Y - 8;
  1165. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
  1166. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
  1167. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
  1168. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
  1169. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
  1170. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
  1171. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
  1172. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
  1173. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
  1174. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
  1175. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
  1176. break;
  1177. }
  1178. case TickStyle.TopLeft: {
  1179. thumb_pos.Y = channel_startpoint.Y - 10;
  1180. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
  1181. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
  1182. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
  1183. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
  1184. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
  1185. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
  1186. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
  1187. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
  1188. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
  1189. dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
  1190. dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
  1191. dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
  1192. break;
  1193. }
  1194. case TickStyle.Both: {
  1195. thumb_pos.Y = area.Y + 10;
  1196. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
  1197. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
  1198. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
  1199. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
  1200. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
  1201. dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
  1202. dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
  1203. break;
  1204. }
  1205. default:
  1206. break;
  1207. }
  1208. pixel_len = thumb_area.Width - 11;
  1209. pixels_betweenticks = pixel_len / ticks;
  1210. /* Draw ticks*/
  1211. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
  1212. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1213. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1214. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1215. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
  1216. area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
  1217. else
  1218. dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
  1219. area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
  1220. }
  1221. }
  1222. if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
  1223. ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
  1224. for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
  1225. if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
  1226. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
  1227. area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
  1228. else
  1229. dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
  1230. area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
  1231. }
  1232. }
  1233. }
  1234. public override void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
  1235. ref Rectangle thumb_pos, ref Rectangle thumb_area, bool highli_thumb,
  1236. float ticks, int value_pos, bool mouse_value)
  1237. {
  1238. Brush br_thumb;
  1239. if (highli_thumb == true)
  1240. br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
  1241. else
  1242. br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
  1243. /* Control Background */
  1244. if (tb.BackColor == DefaultControlBackColor)
  1245. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
  1246. else
  1247. dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
  1248. if (tb.Focused) {
  1249. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
  1250. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
  1251. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
  1252. dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
  1253. }
  1254. if (tb.Orientation == Orientation.Vertical)
  1255. DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
  1256. br_thumb, ticks, value_pos, mouse_value);
  1257. else
  1258. DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
  1259. br_thumb, ticks, value_pos, mouse_value);
  1260. }
  1261. public override void DrawProgressBar (Graphics dc, Rectangle area, Rectangle client_area,
  1262. int barpos_pixels, int block_width)
  1263. {
  1264. int space_betweenblocks = 2;
  1265. int increment = block_width + space_betweenblocks;
  1266. int x = client_area.X;
  1267. /* Draw border */
  1268. DrawBorder3D (dc, area, Border3DStyle.SunkenInner, Border3DSide.All);
  1269. /* Draw Blocks */
  1270. while ((x - client_area.X) < barpos_pixels) {
  1271. dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
  1272. x = x + increment;
  1273. }
  1274. }
  1275. public override void DrawLabel (Graphics dc, Rectangle area, BorderStyle border_style, string text,
  1276. Color fore_color, Color back_color, Font font, StringFormat string_format, bool Enabled)
  1277. {
  1278. if (label_br_fore_color == null || label_br_fore_color.Color != fore_color)
  1279. label_br_fore_color = GetControlForeBrush (fore_color);
  1280. if (label_br_back_color == null || label_br_back_color.Color != back_color)
  1281. label_br_back_color = GetControlBackBrush (back_color);
  1282. dc.FillRectangle (label_br_back_color, area);
  1283. DrawBorderStyle (dc, area, border_style);
  1284. if (Enabled)
  1285. dc.DrawString (text, font, label_br_fore_color, area, string_format);
  1286. else
  1287. ControlPaint.DrawStringDisabled (dc, text, font, fore_color, area, string_format);
  1288. }
  1289. public override void DrawStatusBar (Graphics dc, Rectangle area, StatusBar sb)
  1290. {
  1291. int horz_border = 2;
  1292. int vert_border = 2;
  1293. dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
  1294. if (sb.ShowPanels && sb.Panels.Count == 0) {
  1295. // Create a default panel.
  1296. SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
  1297. StatusBarPanel panel = new StatusBarPanel ();
  1298. Rectangle new_area = new Rectangle (area.X + horz_border,
  1299. area.Y + horz_border,
  1300. area.Width - SizeGripWidth - horz_border,
  1301. area.Height - horz_border);
  1302. DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
  1303. } else if (sb.ShowPanels) {
  1304. SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
  1305. int prev_x = area.X + horz_border;
  1306. int y = area.Y + vert_border;
  1307. for (int i = 0; i < sb.Panels.Count; i++) {
  1308. Rectangle pr = new Rectangle (prev_x, y,
  1309. sb.Panels [i].Width, area.Height);
  1310. prev_x += pr.Width + StatusBarHorzGapWidth;
  1311. DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
  1312. }
  1313. }
  1314. if (sb.SizingGrip)
  1315. DrawSizeGrip (dc, ColorButtonFace, area);
  1316. }
  1317. public override void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
  1318. SolidBrush br_forecolor, StatusBarPanel panel)
  1319. {
  1320. int border_size = 3; // this is actually const, even if the border style is none
  1321. area.Height -= border_size;
  1322. if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
  1323. Border3DStyle border_style = Border3DStyle.SunkenInner;
  1324. if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
  1325. border_style = Border3DStyle.RaisedOuter;
  1326. DrawBorder3D(dc, area, border_style, Border3DSide.All);
  1327. }
  1328. if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
  1329. StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
  1330. dc, panel.Parent.Font, area, index, DrawItemState.Default,
  1331. panel, panel.Parent.ForeColor, panel.Parent.BackColor);
  1332. panel.Parent.OnDrawItemInternal (e);
  1333. return;
  1334. }
  1335. int left = area.Left;
  1336. if (panel.Icon != null) {
  1337. left += 2;
  1338. int size = area.Height - border_size;
  1339. Rectangle ia = new Rectangle (left, border_size, size, size);
  1340. dc.DrawIcon (panel.Icon, left, area.Top);
  1341. left += panel.Icon.Width;
  1342. }
  1343. if (panel.Text == String.Empty)
  1344. return;
  1345. string text = panel.Text;
  1346. StringFormat string_format = new StringFormat ();
  1347. string_format.LineAlignment = StringAlignment.Center;
  1348. string_format.Alignment = StringAlignment.Near;
  1349. string_format.FormatFlags = StringFormatFlags.NoWrap;
  1350. if (text [0] == '\t') {
  1351. string_format.Alignment = StringAlignment.Center;
  1352. text = text.Substring (1);
  1353. if (text [0] == '\t') {
  1354. string_format.Alignment = StringAlignment.Far;
  1355. text = text.Substring (1);
  1356. }
  1357. }
  1358. float x = left + border_size;
  1359. float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
  1360. dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
  1361. }
  1362. public override void DrawPictureBox (Graphics dc, PictureBox pb)
  1363. {
  1364. Rectangle client = pb.ClientRectangle;
  1365. int x, y, width, height;
  1366. dc.FillRectangle (new SolidBrush (pb.BackColor), client);
  1367. x = y = 0;
  1368. if (pb.Image != null) {
  1369. switch (pb.SizeMode) {
  1370. case PictureBoxSizeMode.StretchImage:
  1371. width = client.Width;
  1372. height = client.Height;
  1373. break;
  1374. case PictureBoxSizeMode.CenterImage:
  1375. width = client.Width;
  1376. height = client.Height;
  1377. x = width / 2;
  1378. y = (height - pb.Image.Height) / 2;
  1379. break;
  1380. default:
  1381. // Normal, AutoSize
  1382. width = client.Width;
  1383. height = client.Height;
  1384. break;
  1385. }
  1386. dc.DrawImage (pb.Image, x, y, width, height);
  1387. }
  1388. DrawBorderStyle (dc, client, pb.BorderStyle);
  1389. }
  1390. public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
  1391. {
  1392. if (e.State == DrawItemState.Selected) {
  1393. e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
  1394. return;
  1395. }
  1396. e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
  1397. }
  1398. public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
  1399. {
  1400. if (e.State == DrawItemState.Focus)
  1401. DrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
  1402. }
  1403. public override void DrawToolBar (Graphics dc, ToolBar control, StringFormat format)
  1404. {
  1405. // Exclude the area for divider
  1406. Rectangle paint_area = new Rectangle (0, ThemeEngine.Current.ToolBarGripWidth / 2,
  1407. control.Width, control.Height - ThemeEngine.Current.ToolBarGripWidth / 2);
  1408. bool flat = (control.Appearance == ToolBarAppearance.Flat);
  1409. dc.FillRectangle (SystemBrushes.Control, paint_area);
  1410. DrawBorderStyle (dc, paint_area, control.BorderStyle);
  1411. if (control.Divider)
  1412. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
  1413. foreach (ToolBarButton button in control.Buttons) {
  1414. Image image = null;
  1415. Rectangle buttonArea = button.Rectangle;
  1416. Rectangle imgRect = Rectangle.Empty; // rect to draw the image
  1417. Rectangle txtRect = buttonArea; // rect to draw the text
  1418. Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
  1419. // calculate different rects and draw the frame if its not separator button
  1420. if (button.Style != ToolBarButtonStyle.Separator) {
  1421. /* Adjustment for drop down arrow */
  1422. if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
  1423. ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
  1424. ddRect.Y = buttonArea.Y;
  1425. ddRect.Width = this.ToolBarDropDownWidth;
  1426. ddRect.Height = buttonArea.Height;
  1427. }
  1428. // calculate txtRect and imgRect, if imageIndex and imageList are present
  1429. if (button.ImageIndex > -1 && control.ImageList != null) {
  1430. if (button.ImageIndex < control.ImageList.Images.Count)
  1431. image = control.ImageList.Images [button.ImageIndex];
  1432. // draw the image at the centre if textalignment is underneath
  1433. if (control.TextAlign == ToolBarTextAlign.Underneath) {
  1434. imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
  1435. - control.ImageSize.Width) / 2)
  1436. + this.ToolBarImageGripWidth;
  1437. imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
  1438. imgRect.Width = control.ImageSize.Width;
  1439. imgRect.Height = control.ImageSize.Height;
  1440. txtRect.X = buttonArea.X;
  1441. txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
  1442. txtRect.Width = buttonArea.Width - ddRect.Width;
  1443. txtRect.Height = buttonArea.Height - imgRect.Height
  1444. - 2 * this.ToolBarImageGripWidth;
  1445. }
  1446. else {
  1447. imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
  1448. imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
  1449. imgRect.Width = control.ImageSize.Width;
  1450. imgRect.Height = control.ImageSize.Height;
  1451. txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
  1452. txtRect.Y = buttonArea.Y;
  1453. txtRect.Width = buttonArea.Width - imgRect.Width
  1454. - 2 * this.ToolBarImageGripWidth - ddRect.Width;
  1455. txtRect.Height = buttonArea.Height;
  1456. }
  1457. }
  1458. /* Draw the button frame, only if it is not a separator */
  1459. if (flat) {
  1460. if (button.Pushed || button.Pressed)
  1461. ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter,
  1462. Border3DSide.All);
  1463. else if (button.Hilight) {
  1464. dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
  1465. if (! ddRect.IsEmpty) {
  1466. dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
  1467. ddRect.Y + ddRect.Height);
  1468. buttonArea.Width -= this.ToolBarDropDownWidth;
  1469. }
  1470. }
  1471. }
  1472. else { // normal toolbar
  1473. if (button.Pushed || button.Pressed) {
  1474. ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
  1475. Border3DSide.All);
  1476. if (! ddRect.IsEmpty) {
  1477. ControlPaint.DrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
  1478. Border3DSide.Left);
  1479. buttonArea.Width -= this.ToolBarDropDownWidth;
  1480. }
  1481. }
  1482. else {
  1483. ControlPaint.DrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
  1484. Border3DSide.All);
  1485. if (! ddRect.IsEmpty) {
  1486. ControlPaint.DrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
  1487. Border3DSide.Left);
  1488. buttonArea.Width -= this.ToolBarDropDownWidth;
  1489. }
  1490. }
  1491. }
  1492. }
  1493. DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
  1494. imgRect, image, txtRect, ddRect, flat);
  1495. }
  1496. }
  1497. public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
  1498. {
  1499. SizeF size;
  1500. int width, y;
  1501. Rectangle rect = box.ClientRectangle;
  1502. Color disabled = ThemeEngine.Current.ColorGrayText;
  1503. Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
  1504. Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
  1505. // TODO: When the Light and Dark methods work this code should be activate it
  1506. //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
  1507. //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
  1508. dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
  1509. size = dc.MeasureString (box.Text, box.Font);
  1510. width = (int) size.Width;
  1511. if (width > box.Width - 16)
  1512. width = box.Width - 16;
  1513. y = box.Font.Height / 2;
  1514. /* Draw group box*/
  1515. dc.DrawLine (pen_dark, 0, y, 8, y); // top
  1516. dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
  1517. dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
  1518. dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
  1519. dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
  1520. dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
  1521. dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
  1522. dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
  1523. dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
  1524. dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
  1525. /* Text */
  1526. if (box.Enabled)
  1527. dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0);
  1528. else
  1529. DrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
  1530. new RectangleF (10, 0, width, box.Font.Height), new StringFormat ());
  1531. }
  1532. /*
  1533. * Private methods
  1534. */
  1535. private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
  1536. Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
  1537. Image image, Rectangle txtRect, Rectangle ddRect, bool flat)
  1538. {
  1539. if (! button.Visible)
  1540. return;
  1541. switch (button.Style) {
  1542. case ToolBarButtonStyle.Separator:
  1543. // separator is drawn only in the case of flat appearance
  1544. if (flat) {
  1545. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
  1546. buttonArea.X + 1, buttonArea.Height);
  1547. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
  1548. buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
  1549. /* draw a horizontal separator */
  1550. if (button.Wrapper) {
  1551. int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
  1552. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
  1553. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
  1554. y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
  1555. }
  1556. }
  1557. break;
  1558. case ToolBarButtonStyle.ToggleButton:
  1559. Rectangle toggleArea = Rectangle.Empty;
  1560. toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
  1561. toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
  1562. toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
  1563. toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
  1564. if (button.PartialPush && button.Pushed) {
  1565. dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
  1566. if (! imgRect.IsEmpty) {
  1567. if (button.Enabled && image != null)
  1568. button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
  1569. imgRect.Height, button.ImageIndex);
  1570. else {
  1571. dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
  1572. ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
  1573. Border3DSide.Right | Border3DSide.Bottom);
  1574. }
  1575. }
  1576. if (button.Enabled)
  1577. dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
  1578. else
  1579. ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight,
  1580. txtRect, format);
  1581. }
  1582. else if (button.PartialPush) {
  1583. dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
  1584. if (! imgRect.IsEmpty) {
  1585. if (button.Enabled && image != null)
  1586. button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
  1587. imgRect.Height, button.ImageIndex);
  1588. else {
  1589. dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
  1590. ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
  1591. Border3DSide.Right | Border3DSide.Bottom);
  1592. }
  1593. }
  1594. if (button.Enabled)
  1595. dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
  1596. else
  1597. ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight,
  1598. txtRect, format);
  1599. }
  1600. else if (button.Pushed) {
  1601. dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
  1602. if (! imgRect.IsEmpty) {
  1603. if (button.Enabled && image != null)
  1604. button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
  1605. imgRect.Height, button.ImageIndex);
  1606. else {
  1607. dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
  1608. ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
  1609. Border3DSide.Right | Border3DSide.Bottom);
  1610. }
  1611. }
  1612. if (button.Enabled)
  1613. dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
  1614. else
  1615. ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight,
  1616. txtRect, format);
  1617. }
  1618. else {
  1619. dc.FillRectangle (SystemBrushes.Control, toggleArea);
  1620. //dc.FillRectangle (new SolidBrush (Color.FromArgb(255, 180, 190, 214)), toggleArea);
  1621. if (! imgRect.IsEmpty) {
  1622. if (button.Enabled && image != null)
  1623. button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
  1624. imgRect.Height, button.ImageIndex);
  1625. else {
  1626. dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
  1627. ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
  1628. Border3DSide.Right | Border3DSide.Bottom);
  1629. }
  1630. }
  1631. if (button.Enabled)
  1632. dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
  1633. else
  1634. ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight,
  1635. txtRect, format);
  1636. }
  1637. break;
  1638. case ToolBarButtonStyle.DropDownButton:
  1639. // draw the dropdown arrow
  1640. if (! ddRect.IsEmpty) {
  1641. PointF [] vertices = new PointF [3];
  1642. PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
  1643. vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
  1644. vertices [0].Y = ddCenter.Y;
  1645. vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
  1646. vertices [1].Y = ddCenter.Y;
  1647. vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
  1648. vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
  1649. dc.FillPolygon (SystemBrushes.ControlText, vertices);
  1650. }
  1651. goto case ToolBarButtonStyle.PushButton;
  1652. case ToolBarButtonStyle.PushButton:
  1653. if (! imgRect.IsEmpty){
  1654. if (button.Enabled && image != null)
  1655. button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
  1656. button.ImageIndex);
  1657. else {
  1658. dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
  1659. ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
  1660. Border3DSide.Right | Border3DSide.Bottom);
  1661. }
  1662. }
  1663. if (button.Enabled)
  1664. dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
  1665. else
  1666. ControlPaint.DrawStringDisabled (dc, button.Text, font, SystemColors.ControlLightLight,
  1667. txtRect, format);
  1668. break;
  1669. }
  1670. }
  1671. private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
  1672. int width, Color color, ButtonBorderStyle style, Border3DSide side) {
  1673. Pen pen=new Pen(color, 1);
  1674. switch(style) {
  1675. case ButtonBorderStyle.Solid: {
  1676. pen.DashStyle=DashStyle.Solid;
  1677. break;
  1678. }
  1679. case ButtonBorderStyle.Dashed: {
  1680. pen.DashStyle=DashStyle.Dash;
  1681. break;
  1682. }
  1683. case ButtonBorderStyle.Dotted: {
  1684. pen.DashStyle=DashStyle.Dot;
  1685. break;
  1686. }
  1687. case ButtonBorderStyle.Inset: {
  1688. pen.DashStyle=DashStyle.Solid;
  1689. break;
  1690. }
  1691. case ButtonBorderStyle.Outset: {
  1692. pen.DashStyle=DashStyle.Solid;
  1693. break;
  1694. }
  1695. default:
  1696. case ButtonBorderStyle.None: {
  1697. pen.Dispose();
  1698. return;
  1699. }
  1700. }
  1701. switch(style) {
  1702. case ButtonBorderStyle.Outset: {
  1703. Color colorGrade;
  1704. int hue, brightness, saturation;
  1705. int brightnessSteps;
  1706. int brightnessDownSteps;
  1707. ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
  1708. brightnessDownSteps=brightness/width;
  1709. if (brightness>127) {
  1710. brightnessSteps=Math.Max(6, (160-brightness)/width);
  1711. } else {
  1712. brightnessSteps=(127-brightness)/width;
  1713. }
  1714. for (int i=0; i<width; i++) {
  1715. switch(side) {
  1716. case Border3DSide.Left: {
  1717. pen.Dispose();
  1718. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1719. pen=new Pen(colorGrade, 1);
  1720. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1721. break;
  1722. }
  1723. case Border3DSide.Right: {
  1724. pen.Dispose();
  1725. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1726. pen=new Pen(colorGrade, 1);
  1727. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1728. break;
  1729. }
  1730. case Border3DSide.Top: {
  1731. pen.Dispose();
  1732. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1733. pen=new Pen(colorGrade, 1);
  1734. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1735. break;
  1736. }
  1737. case Border3DSide.Bottom: {
  1738. pen.Dispose();
  1739. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1740. pen=new Pen(colorGrade, 1);
  1741. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1742. break;
  1743. }
  1744. }
  1745. }
  1746. break;
  1747. }
  1748. case ButtonBorderStyle.Inset: {
  1749. Color colorGrade;
  1750. int hue, brightness, saturation;
  1751. int brightnessSteps;
  1752. int brightnessDownSteps;
  1753. ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
  1754. brightnessDownSteps=brightness/width;
  1755. if (brightness>127) {
  1756. brightnessSteps=Math.Max(6, (160-brightness)/width);
  1757. } else {
  1758. brightnessSteps=(127-brightness)/width;
  1759. }
  1760. for (int i=0; i<width; i++) {
  1761. switch(side) {
  1762. case Border3DSide.Left: {
  1763. pen.Dispose();
  1764. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1765. pen=new Pen(colorGrade, 1);
  1766. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1767. break;
  1768. }
  1769. case Border3DSide.Right: {
  1770. pen.Dispose();
  1771. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1772. pen=new Pen(colorGrade, 1);
  1773. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1774. break;
  1775. }
  1776. case Border3DSide.Top: {
  1777. pen.Dispose();
  1778. colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
  1779. pen=new Pen(colorGrade, 1);
  1780. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1781. break;
  1782. }
  1783. case Border3DSide.Bottom: {
  1784. pen.Dispose();
  1785. colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
  1786. pen=new Pen(colorGrade, 1);
  1787. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1788. break;
  1789. }
  1790. }
  1791. }
  1792. break;
  1793. }
  1794. /*
  1795. I decided to have the for-loop duplicated for speed reasons;
  1796. that way we only have to switch once (as opposed to have the
  1797. for-loop around the switch)
  1798. */
  1799. default: {
  1800. switch(side) {
  1801. case Border3DSide.Left: {
  1802. for (int i=0; i<width; i++) {
  1803. graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
  1804. }
  1805. break;
  1806. }
  1807. case Border3DSide.Right: {
  1808. for (int i=0; i<width; i++) {
  1809. graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
  1810. }
  1811. break;
  1812. }
  1813. case Border3DSide.Top: {
  1814. for (int i=0; i<width; i++) {
  1815. graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
  1816. }
  1817. break;
  1818. }
  1819. case Border3DSide.Bottom: {
  1820. for (int i=0; i<width; i++) {
  1821. graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
  1822. }
  1823. break;
  1824. }
  1825. }
  1826. break;
  1827. }
  1828. }
  1829. pen.Dispose();
  1830. }
  1831. /*
  1832. This function actually draws the various caption elements.
  1833. This way we can scale them nicely, no matter what size, and they
  1834. still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
  1835. */
  1836. private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
  1837. switch(button) {
  1838. case CaptionButton.Close: {
  1839. pen.StartCap=LineCap.Triangle;
  1840. pen.EndCap=LineCap.Triangle;
  1841. if (lineWidth<2) {
  1842. 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);
  1843. 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);
  1844. }
  1845. graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
  1846. graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
  1847. return;
  1848. }
  1849. case CaptionButton.Help: {
  1850. StringFormat sf = new StringFormat();
  1851. SolidBrush sb = new SolidBrush(color);
  1852. Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
  1853. sf.Alignment=StringAlignment.Center;
  1854. sf.LineAlignment=StringAlignment.Center;
  1855. graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
  1856. sf.Dispose();
  1857. sb.Dispose();
  1858. font.Dispose();
  1859. return;
  1860. }
  1861. case CaptionButton.Maximize: {
  1862. /* Top 'caption bar' line */
  1863. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1864. 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);
  1865. }
  1866. /* Left side line */
  1867. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1868. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
  1869. }
  1870. /* Right side line */
  1871. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1872. 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);
  1873. }
  1874. /* Bottom line */
  1875. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1876. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
  1877. }
  1878. return;
  1879. }
  1880. case CaptionButton.Minimize: {
  1881. /* Bottom line */
  1882. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1883. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
  1884. }
  1885. return;
  1886. }
  1887. case CaptionButton.Restore: {
  1888. /** First 'window' **/
  1889. /* Top 'caption bar' line */
  1890. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1891. 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);
  1892. }
  1893. /* Left side line */
  1894. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1895. 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);
  1896. }
  1897. /* Right side line */
  1898. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1899. 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);
  1900. }
  1901. /* Bottom line */
  1902. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1903. 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);
  1904. }
  1905. /** Second 'window' **/
  1906. /* Top 'caption bar' line */
  1907. for (int i=0; i<Math.Max(2, lineWidth); i++) {
  1908. 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);
  1909. }
  1910. /* Left side line */
  1911. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1912. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
  1913. }
  1914. /* Right side line */
  1915. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1916. 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);
  1917. }
  1918. /* Bottom line */
  1919. for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
  1920. graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
  1921. }
  1922. return;
  1923. }
  1924. }
  1925. }
  1926. [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
  1927. private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State)
  1928. {
  1929. switch(Type) {
  1930. case DrawFrameControlTypes.Button: {
  1931. if ((State & DrawFrameControlStates.ButtonPush)!=0) {
  1932. /* Goes first, affects the background */
  1933. if ((State & DrawFrameControlStates.Checked)!=0) {
  1934. HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
  1935. graphics.FillRectangle(hatchBrush,rectangle);
  1936. hatchBrush.Dispose();
  1937. }
  1938. if ((State & DrawFrameControlStates.Pushed)!=0) {
  1939. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1940. } else if ((State & DrawFrameControlStates.Flat)!=0) {
  1941. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  1942. } else if ((State & DrawFrameControlStates.Inactive)!=0) {
  1943. /* Same as normal, it would seem */
  1944. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1945. } else {
  1946. DrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1947. }
  1948. } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
  1949. Pen penFatDark = new Pen(ColorButtonShadow, 2);
  1950. Pen penFatLight = new Pen(SystemColors.ControlLight, 2);
  1951. int lineWidth;
  1952. graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
  1953. graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
  1954. graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
  1955. graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
  1956. lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
  1957. if ((State & DrawFrameControlStates.Checked)!=0) {
  1958. SolidBrush buttonBrush;
  1959. if ((State & DrawFrameControlStates.Inactive)!=0) {
  1960. buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
  1961. } else {
  1962. buttonBrush=(SolidBrush)SystemBrushes.ControlText;
  1963. }
  1964. graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
  1965. }
  1966. penFatDark.Dispose();
  1967. penFatLight.Dispose();
  1968. } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
  1969. throw new NotImplementedException () ;
  1970. } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
  1971. throw new NotImplementedException ();
  1972. } else { /* Must be Checkbox */
  1973. Pen pen;
  1974. int lineWidth;
  1975. Rectangle rect;
  1976. int Scale;
  1977. /* FIXME: I'm sure there's an easier way to calculate all this, but it should do for now */
  1978. /* Goes first, affects the background */
  1979. if ((State & DrawFrameControlStates.Pushed)!=0) {
  1980. HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
  1981. graphics.FillRectangle(hatchBrush,rectangle);
  1982. hatchBrush.Dispose();
  1983. }
  1984. /* Draw the sunken frame */
  1985. if ((State & DrawFrameControlStates.Flat)!=0) {
  1986. ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
  1987. } else {
  1988. DrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
  1989. }
  1990. /* Make sure we've got at least a line width of 1 */
  1991. lineWidth=Math.Max(3, rectangle.Width/6);
  1992. Scale=Math.Max(1, rectangle.Width/12);
  1993. rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
  1994. if ((State & DrawFrameControlStates.Inactive)!=0) {
  1995. pen=SystemPens.ControlDark;
  1996. } else {
  1997. pen=SystemPens.ControlText;
  1998. }
  1999. if ((State & DrawFrameControlStates.Checked)!=0) {
  2000. /* Need to draw a check-mark */
  2001. for (int i=0; i<lineWidth; i++) {
  2002. graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
  2003. 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);
  2004. }
  2005. }
  2006. }
  2007. return;
  2008. }
  2009. case DrawFrameControlTypes.Caption: {
  2010. // FIXME:
  2011. break;
  2012. }
  2013. case DrawFrameControlTypes.Menu: {
  2014. // FIXME:
  2015. break;
  2016. }
  2017. case DrawFrameControlTypes.Scroll: {
  2018. // FIXME:
  2019. break;
  2020. }
  2021. }
  2022. }
  2023. /* Generic scroll button */
  2024. public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state)
  2025. {
  2026. if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
  2027. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
  2028. area.Y + 1, area.Width - 2 , area.Height - 2);
  2029. dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
  2030. area.Y, area.Width, area.Height);
  2031. return;
  2032. }
  2033. dc.FillRectangle (new SolidBrush (Color.Blue), area);
  2034. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
  2035. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
  2036. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
  2037. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
  2038. area.Height - 4);
  2039. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
  2040. area.Width - 2, 1);
  2041. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
  2042. area.Width , 1);
  2043. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
  2044. area.Y + 1, 1, area.Height -3);
  2045. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
  2046. area.Y, 1, area.Height - 1);
  2047. dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
  2048. area.Y + 2, area.Width - 4, area.Height - 4);
  2049. }
  2050. public override void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style)
  2051. {
  2052. switch (border_style){
  2053. case BorderStyle.Fixed3D:
  2054. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
  2055. dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
  2056. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
  2057. area.Y + area.Height - 1);
  2058. dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
  2059. area.Y + area.Height);
  2060. break;
  2061. case BorderStyle.FixedSingle:
  2062. dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
  2063. break;
  2064. case BorderStyle.None:
  2065. default:
  2066. break;
  2067. }
  2068. }
  2069. protected SolidBrush GetControlBackBrush (Color c)
  2070. {
  2071. if (c == DefaultControlBackColor)
  2072. return ResPool.GetSolidBrush (ColorButtonFace);
  2073. return new SolidBrush (c);
  2074. }
  2075. protected SolidBrush GetControlForeBrush (Color c)
  2076. {
  2077. if (c == DefaultControlForeColor)
  2078. return ResPool.GetSolidBrush (ColorButtonText);
  2079. return new SolidBrush (c);
  2080. }
  2081. } //class
  2082. }