1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Alexander Olk
23 // Alexander Olk, alex.olk@googlemail.com
25 // based on ThemeWin32Classic
27 // - You can activate this Theme with export MONO_THEME=clearlooks
29 // This theme tries to match clearlooks theme
32 // - if an other control draws over a ScrollBar button you can see artefacts on the rounded edges
33 // (maybe use theme backcolor, but that looks ugly on a white background, need to find a way to get the backcolor of the parent control)
34 // - more correct drawing of disabled controls
37 using System.Drawing.Drawing2D;
38 using System.Drawing.Imaging;
39 using System.Drawing.Text;
41 namespace System.Windows.Forms {
42 internal class ThemeClearlooks : ThemeWin32Classic {
43 public override Version Version {
45 return new Version( 0, 0, 0, 2 );
49 static readonly Color theme_back_color = Color.FromArgb( 239, 235, 231 );
51 static readonly Color gradient_first_color = Color.FromArgb( 250, 248, 247 );
52 static readonly Color gradient_second_color = Color.FromArgb( 226, 219, 212 );
53 static readonly Color gradient_second_color_nr2 = Color.FromArgb( 234, 229, 224 );
54 static readonly Color pressed_gradient_first_color = Color.FromArgb( 217, 207, 202 );
55 static readonly Color pressed_gradient_second_color = Color.FromArgb( 199, 193, 187 );
56 static readonly Color border_normal_dark_color = Color.FromArgb( 129, 117, 106 );
57 static readonly Color border_normal_light_color = Color.FromArgb( 158, 145, 131 );
58 static readonly Color border_pressed_dark_color = Color.FromArgb( 109, 103, 98 );
59 static readonly Color border_pressed_light_color = Color.FromArgb( 120, 114, 107 );
60 static readonly Color button_outer_border_dark_color = Color.FromArgb( 232, 226, 220 );
61 static readonly Color button_outer_border_light_color = Color.FromArgb( 250, 248, 247 );
62 static readonly Color inner_border_dark_color = Color.FromArgb( 226, 219, 212 );
63 static readonly Color pressed_inner_border_dark_color = Color.FromArgb( 192, 181, 169 );
64 static readonly Color edge_top_inner_color = Color.FromArgb( 206, 200, 194 );
65 static readonly Color edge_bottom_inner_color = Color.FromArgb( 215, 209, 202 );
66 static readonly Color button_edge_top_outer_color = Color.FromArgb( 237, 233, 228 );
67 static readonly Color button_edge_bottom_outer_color = Color.FromArgb( 243, 239, 236 );
68 static readonly Color button_focus_color = Color.FromArgb( 101, 94, 86 );
69 static readonly Color button_mouse_entered_second_gradient_color = Color.FromArgb( 230, 226, 219 );
71 static readonly Color scrollbar_background_color = Color.FromArgb( 209, 200, 191 );
72 static readonly Color scrollbar_border_color = Color.FromArgb( 170, 156, 143 );
73 static readonly Color scrollbar_gradient_first_color = Color.FromArgb( 248, 247, 245 );
74 static readonly Color scrollbar_gradient_second_color = Color.FromArgb( 234, 229, 224 );
76 new static readonly Color arrow_color = Color.FromArgb( 16, 16, 16 );
78 static readonly Color tab_border_color = Color.FromArgb( 166, 151, 138 );
79 static readonly Color tab_not_selected_gradient_first_color = Color.FromArgb( 227, 223, 220 );
80 static readonly Color tab_not_selected_gradient_second_color = Color.FromArgb( 214, 209, 204 );
81 static readonly Color tab_selected_gradient_first_color = Color.FromArgb( 243, 239, 236 );
82 static readonly Color tab_selected_gradient_second_color = Color.FromArgb( 234, 228, 223 );
83 static readonly Color tab_edge_color = Color.FromArgb( 200, 196, 191 );
84 static readonly Color tab_inner_border_color = Color.FromArgb( 221, 212, 205 );
85 static readonly Color tab_top_border_focus_color = Color.FromArgb( 70, 91, 110 );
86 static readonly Color tab_focus_color = Color.FromArgb( 105, 147, 185 );
88 static readonly Color menuitem_gradient_first_color = Color.FromArgb( 98, 140, 178 );
89 static readonly Color menuitem_gradient_second_color = Color.FromArgb( 81, 113, 142 );
90 static readonly Color menuitem_border_color = Color.FromArgb( 80, 112, 141 );
91 static readonly Color menu_separator_color = Color.FromArgb( 219, 211, 203 );
92 static readonly Color menu_background_color = Color.FromArgb( 248, 245, 242 );
93 static readonly Color menu_border_color = Color.FromArgb( 141, 122, 104 );
94 static readonly Color menu_inner_border_color = Color.FromArgb( 236, 228, 221 );
96 static readonly Color combobox_border_color = Color.FromArgb( 159, 146, 132 );
97 static readonly Color combobox_focus_border_color = Color.FromArgb( 70, 91, 110 );
98 //static readonly Color combobox_focus_inner_border_color = Color.FromArgb( 167, 198, 225 );
99 static readonly Color combobox_button_second_gradient_color = Color.FromArgb( 226, 220, 213 );
101 static readonly Color progressbar_edge_dot_color = Color.FromArgb( 219, 212, 205 );
102 static readonly Color progressbar_inner_border_color = Color.FromArgb( 139, 176, 209 );
103 static readonly Color progressbar_first_gradient_color = Color.FromArgb( 104, 146, 184 );
104 static readonly Color progressbar_second_gradient_color = Color.FromArgb( 91, 133, 172 );
106 static readonly Color checkbox_inner_boder_color = Color.FromArgb( 237, 234, 231 );
107 static readonly Color checkbox_pressed_inner_boder_color = Color.FromArgb( 203, 196, 189 );
108 static readonly Color checkbox_pressed_backcolor = Color.FromArgb( 212, 207, 202 );
110 static readonly Color trackbar_second_gradient_color = Color.FromArgb( 114, 154, 190 );
111 static readonly Color trackbar_third_gradient_color = Color.FromArgb( 130, 168, 202 );
112 static readonly Color trackbar_inner_first_gradient_color = Color.FromArgb( 238, 233, 229 );
113 static readonly Color trackbar_inner_second_gradient_color = Color.FromArgb( 223, 215, 208 );
114 static readonly Color trackbar_inner_pressed_second_gradient_color = Color.FromArgb( 224, 217, 210 );
116 //static readonly Color disabled_color_foreground = Color.FromArgb( 182, 180, 173 );
118 static readonly Color active_caption = Color.FromArgb( 85, 152, 215 );
120 static readonly Color radio_button_border_circle_color = Color.FromArgb( 126, 118, 105 );
121 static readonly Color radio_button_dot_color = Color.FromArgb( 94, 160, 221 );
123 const int SEPARATOR_HEIGHT = 7;
124 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
125 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
127 static Color control_parent_backcolor;
129 #region Principal Theme Methods
130 public ThemeClearlooks( ) {
131 ColorControl = theme_back_color;
134 public override Color DefaultControlBackColor {
135 get { return theme_back_color; }
138 public override Color DefaultWindowBackColor {
139 get { return theme_back_color; }
142 public override Color ColorControl {
143 get { return theme_back_color;}
146 public override Color ColorHighlight {
147 get { return menuitem_gradient_first_color; }
150 public override Color ColorActiveCaption {
151 get { return active_caption; }
154 public override Size Border3DSize {
156 return new Size( 3, 3 );
160 public override Color ColorInfo {
161 get { return Color.FromArgb (255, 255, 191); }
164 static readonly Color info_border_color = Color.FromArgb (218, 178, 85);
166 static readonly Color info_second_color = Color.FromArgb (220, 220, 160);
168 public override Image Images(UIIcon index, int size) {
170 case UIIcon.PlacesRecentDocuments:
171 if (XplatUI.RunningOnUnix)
172 return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
174 return base.Images (UIIcon.PlacesRecentDocuments, size);
175 case UIIcon.PlacesDesktop:
176 if (XplatUI.RunningOnUnix)
177 return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
179 return base.Images (UIIcon.PlacesDesktop, size);
180 case UIIcon.PlacesPersonal:
181 if (XplatUI.RunningOnUnix)
182 return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
184 return base.Images (UIIcon.PlacesPersonal, size);
185 case UIIcon.PlacesMyComputer:
186 if (XplatUI.RunningOnUnix)
187 return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
189 return base.Images (UIIcon.PlacesMyComputer, size);
190 case UIIcon.PlacesMyNetwork:
191 if (XplatUI.RunningOnUnix)
192 return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
194 return base.Images (UIIcon.PlacesMyNetwork, size);
196 // Icons for message boxes
197 case UIIcon.MessageBoxError: return base.Images (UIIcon.MessageBoxError, size);
198 case UIIcon.MessageBoxInfo: return base.Images (UIIcon.MessageBoxInfo, size);
199 case UIIcon.MessageBoxQuestion: return base.Images (UIIcon.MessageBoxQuestion, size);
200 case UIIcon.MessageBoxWarning: return base.Images (UIIcon.MessageBoxWarning, size);
203 case UIIcon.NormalFolder:
204 if (XplatUI.RunningOnUnix)
205 return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
207 return base.Images (UIIcon.NormalFolder, size);
210 throw new ArgumentException("Invalid Icon type requested", "index");
214 #endregion // Internal Methods
217 protected override void ButtonBase_DrawButton( ButtonBase button, Graphics dc ) {
218 dc.FillRectangle( ResPool.GetSolidBrush( button.BackColor ), button.ClientRectangle );
220 Color first_gradient_color = gradient_first_color;
221 Color second_gradient_color = gradient_second_color;
223 if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
224 ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
225 first_gradient_color = button.is_entered ? gradient_second_color : pressed_gradient_first_color;
226 second_gradient_color = button.is_entered ? gradient_second_color : pressed_gradient_second_color;
228 if (!button.is_enabled) {
229 button.is_entered = false;
231 if (button.is_entered) {
232 if (!button.is_pressed) {
233 first_gradient_color = Color.White;
234 second_gradient_color = button_mouse_entered_second_gradient_color;
236 first_gradient_color = pressed_gradient_first_color;
237 second_gradient_color = pressed_gradient_second_color;
241 bool paint_acceptbutton_black_border = false;
242 Form form = button.TopLevelControl as Form;
244 if (form != null && (form.AcceptButton == button as IButtonControl))
245 paint_acceptbutton_black_border = true;
247 CL_Draw_Button(dc, button.ClientRectangle, button.FlatStyle,
248 button.is_entered, button.is_enabled, button.is_pressed,
249 first_gradient_color, second_gradient_color,
250 paint_acceptbutton_black_border);
253 private void CL_Draw_Button(Graphics dc, Rectangle buttonRectangle, FlatStyle flat_style,
254 bool is_entered, bool is_enabled, bool is_pressed,
255 Color first_gradient_color, Color second_gradient_color,
256 bool paint_acceptbutton_black_border)
258 Rectangle lgbRectangle = new Rectangle (buttonRectangle.X + 3, buttonRectangle.Y + 3,
259 is_pressed ? buttonRectangle.Width - 5 : buttonRectangle.Width - 6,
260 buttonRectangle.Height - 6);
262 if (flat_style != FlatStyle.Popup || ((flat_style == FlatStyle.Popup) && is_entered)) {
263 LinearGradientBrush lgbr;
264 if (flat_style == FlatStyle.Flat) {
265 lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
266 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
267 second_gradient_color, first_gradient_color);
269 lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
270 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
271 first_gradient_color, second_gradient_color);
273 dc.FillRectangle (lgbr, lgbRectangle);
276 Point[] points_top = {
277 new Point (buttonRectangle.X + 2, buttonRectangle.Y + 2),
278 new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
279 new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
280 new Point (buttonRectangle.Right - 3 , buttonRectangle.Y + 2)
283 Point[] points_bottom = {
284 new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 3),
285 new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
286 new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
287 new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 3)
290 Point[] points_top_outer = {
291 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 1),
292 new Point (buttonRectangle.X + 2, buttonRectangle.Y),
293 new Point (buttonRectangle.Right - 3, buttonRectangle.Y),
294 new Point (buttonRectangle.Right - 2 , buttonRectangle.Y + 1)
297 Point[] points_bottom_outer = {
298 new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 2),
299 new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 1),
300 new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 1),
301 new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 2)
308 Color top_color = Color.Black;
309 Color bottom_color = Color.Black;
311 if (!paint_acceptbutton_black_border) {
312 top_color = is_pressed ? border_pressed_dark_color : border_normal_dark_color;
313 bottom_color = is_pressed ? border_pressed_light_color : border_normal_light_color;
316 pen = ResPool.GetPen (top_color);
317 dc.DrawLines (pen, points_top);
318 pen = ResPool.GetPen (bottom_color);
319 dc.DrawLines (pen, points_bottom);
321 using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
322 new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
323 top_color, bottom_color)) {
324 using (Pen lgbrpen = new Pen (lgbr2)) {
325 dc.DrawLine (lgbrpen, buttonRectangle.X + 1, buttonRectangle.Y + 3, buttonRectangle.X + 1, buttonRectangle.Bottom - 3);
326 dc.DrawLine (lgbrpen, buttonRectangle.Right - 2, buttonRectangle.Y + 3, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3);
330 Point[] points_button_complete = {
331 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3),
332 new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
333 new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
334 new Point (buttonRectangle.Right - 2, buttonRectangle.Y + 3),
335 new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 4),
336 new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
337 new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
338 new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 4),
339 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3)
342 pen = ResPool.GetPen (pressed_inner_border_dark_color);
343 dc.DrawLines (pen, points_button_complete);
347 pen = ResPool.GetPen (button_outer_border_dark_color);
348 dc.DrawLines (pen, points_top_outer);
349 pen = ResPool.GetPen (button_outer_border_light_color);
350 dc.DrawLines (pen, points_bottom_outer);
352 using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 2),
353 new Point (buttonRectangle.X, buttonRectangle.Bottom - 1),
354 button_outer_border_dark_color, button_outer_border_light_color)) {
355 using (Pen lgbrpen = new Pen(lgbr2)) {
356 dc.DrawLine (lgbrpen, buttonRectangle.X, buttonRectangle.Y + 2, buttonRectangle.X, buttonRectangle.Bottom - 3);
357 dc.DrawLine (lgbrpen, buttonRectangle.Right - 1, buttonRectangle.Y + 2, buttonRectangle.Right - 1, buttonRectangle.Bottom - 3);
362 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : inner_border_dark_color);
364 dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 4);
366 dc.DrawLine (pen, buttonRectangle.X + 3, buttonRectangle.Bottom - 3, buttonRectangle.Right - 4, buttonRectangle.Bottom - 3);
367 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : Color.White);
368 dc.DrawLine (pen, buttonRectangle.X + 2, buttonRectangle.Y + 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 4);
369 dc.DrawLine (pen, buttonRectangle.X + 3 , buttonRectangle.Y + 2, buttonRectangle.Right - 4, buttonRectangle.Y + 2);
372 pen = ResPool.GetPen (edge_top_inner_color);
373 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Y + 2, buttonRectangle.X + 2, buttonRectangle.Y + 1);
374 dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 1, buttonRectangle.Right - 2, buttonRectangle.Y + 2);
376 pen = ResPool.GetPen (button_edge_top_outer_color);
377 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Y + 1, buttonRectangle.X + 1, buttonRectangle.Y);
378 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Y, buttonRectangle.Right - 1, buttonRectangle.Y + 1);
380 pen = ResPool.GetPen (edge_bottom_inner_color);
381 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Bottom - 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 2);
382 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 2);
384 pen = ResPool.GetPen (button_edge_bottom_outer_color);
385 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Bottom - 2, buttonRectangle.X + 1, buttonRectangle.Bottom - 1);
386 dc.DrawLine (pen, buttonRectangle.Right - 1, buttonRectangle.Bottom - 2, buttonRectangle.Right - 2, buttonRectangle.Bottom - 1);
390 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc ) {
392 if ( !button.is_enabled || button.FlatStyle == FlatStyle.Popup )
395 Pen pen = ResPool.GetPen( button_focus_color );
396 DashStyle old_dash_style = pen.DashStyle;
397 pen.DashStyle = DashStyle.Dot;
399 Rectangle focus_rect = new Rectangle( button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9 );
401 dc.DrawRectangle( pen, focus_rect );
403 pen.DashStyle = old_dash_style;
406 // FIXME: remove if libgdiplus DrawOrMeasureString is fixed
407 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc ) {
408 if ( !( button is CheckBox ) && !( button is RadioButton ) ) {
409 Rectangle buttonRectangle = button.ClientRectangle;
410 Rectangle text_rect = Rectangle.Inflate( buttonRectangle, -4, -4 );
412 string text = button.Text;
414 if ( text.Length > 1 ) {
415 SizeF sizef = dc.MeasureString( text, button.Font, text_rect.Width, button.text_format );
417 if ( (int)sizef.Width > text_rect.Width - 3 ) {
418 for ( int i = 1; i < text.Length + 1; i++ ) {
419 sizef = dc.MeasureString( text.Substring( 0, i ), button.Font, text_rect.Width, button.text_format );
421 if ( (int)sizef.Width > text_rect.Width - 3 ) {
422 text = text.Substring( 0, i - 1 );
429 if ( button.is_pressed ) {
434 if ( button.is_enabled ) {
435 dc.DrawString( text, button.Font, ResPool.GetSolidBrush( button.ForeColor ), text_rect, button.text_format );
437 if ( button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup ) {
438 dc.DrawString( text, button.Font, ResPool.GetSolidBrush( ControlPaint.DarkDark( this.ColorControl ) ), text_rect, button.text_format );
440 CPDrawStringDisabled( dc, text, button.Font, ColorControlText, text_rect, button.text_format );
445 #endregion // ButtonBase
448 public override void DrawMenuItem( MenuItem item, DrawItemEventArgs e ) {
449 StringFormat string_format;
450 Rectangle rect_text = e.Bounds;
452 if ( item.Visible == false )
455 if ( item.MenuBar ) {
456 string_format = string_format_menu_menubar_text;
458 string_format = string_format_menu_text;
461 if ( item.Separator ) {
462 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
463 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 1 );
465 e.Graphics.DrawLine( ResPool.GetPen( Color.White ),
466 e.Bounds.X, e.Bounds.Y + 2, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 2 );
472 rect_text.X += MenuCheckSize.Width;
474 if ( item.BarBreak ) { /* Draw vertical break bar*/
475 Rectangle rect = e.Bounds;
478 rect.Height = item.MenuHeight - 6;
480 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
481 rect.X, rect.Y , rect.X, rect.Y + rect.Height );
483 e.Graphics.DrawLine( ResPool.GetPen( ColorControlLight ),
484 rect.X + 1, rect.Y , rect.X + 1, rect.Y + rect.Height );
487 Color color_text = ColorMenuText;
490 /* Draw background */
491 Rectangle rect_back = e.Bounds;
493 rect_back.Width -= 2;
495 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected ) {
496 color_text = ColorHighlightText;
497 color_back = item.MenuBar ? theme_back_color : menu_background_color;
499 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rect_back.X, rect_back.Y + 1 ), new Point( rect_back.X, rect_back.Bottom - 1 ), menuitem_gradient_first_color, menuitem_gradient_second_color ) ) {
500 e.Graphics.FillRectangle( lgbr, rect_back.X + 1, rect_back.Y + 1, rect_back.Width - 1, rect_back.Height - 1 );
504 Pen tmp_pen = ResPool.GetPen( menuitem_border_color );
505 e.Graphics.DrawLine( tmp_pen, rect_back.X + 1, rect_back.Y, rect_back.Right - 1, rect_back.Y );
506 e.Graphics.DrawLine( tmp_pen, rect_back.Right, rect_back.Y + 1, rect_back.Right, rect_back.Bottom - 1 );
507 e.Graphics.DrawLine( tmp_pen, rect_back.Right - 1, rect_back.Bottom, rect_back.X + 1, rect_back.Bottom );
508 e.Graphics.DrawLine( tmp_pen, rect_back.X, rect_back.Bottom - 1, rect_back.X, rect_back.Y + 1 );
510 color_text = ColorMenuText;
511 color_back = item.MenuBar ? theme_back_color : menu_background_color;
513 e.Graphics.FillRectangle( ResPool.GetSolidBrush( color_back ), rect_back );
516 if ( item.Enabled ) {
517 e.Graphics.DrawString( item.Text, e.Font,
518 ResPool.GetSolidBrush( color_text ),
519 rect_text, string_format );
521 if ( !item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut ) {
522 string str = item.GetShortCutText( );
523 Rectangle rect = rect_text;
525 rect.Width -= item.XTab;
527 e.Graphics.DrawString( str, e.Font, ResPool.GetSolidBrush( color_text ),
528 rect, string_format_menu_shortcut );
531 ControlPaint.DrawStringDisabled( e.Graphics, item.Text, e.Font,
532 Color.Black, rect_text, string_format );
536 if ( item.MenuBar == false && item.IsPopup ) {
537 int cx = MenuCheckSize.Width;
538 int cy = MenuCheckSize.Height;
539 using ( Bitmap bmp = new Bitmap( cx, cy ) ) {
540 using ( Graphics dc = Graphics.FromImage( bmp ) ) {
541 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
542 dc.SmoothingMode = SmoothingMode.AntiAlias;
544 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
545 ControlPaint.DrawMenuGlyph( dc, rect_arrow, MenuGlyph.Arrow );
546 bmp.MakeTransparent( );
548 if ( item.Enabled ) {
549 e.Graphics.DrawImage( bmp, e.Bounds.X + e.Bounds.Width - cx,
550 e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
552 ControlPaint.DrawImageDisabled( e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
553 e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ), color_back );
556 dc.SmoothingMode = old_smoothing_mode;
561 /* Draw checked or radio */
562 if ( item.MenuBar == false && item.Checked ) {
564 Rectangle area = e.Bounds;
565 int cx = MenuCheckSize.Width;
566 int cy = MenuCheckSize.Height;
567 using ( Bitmap bmp = new Bitmap( cx, cy ) ) {
568 using ( Graphics gr = Graphics.FromImage( bmp ) ) {
569 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
571 if ( item.RadioCheck )
572 ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Bullet );
574 ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Checkmark );
576 bmp.MakeTransparent( );
577 e.Graphics.DrawImage( bmp, area.X, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
583 public override void DrawPopupMenu( Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect ) {
585 dc.FillRectangle( ResPool.GetSolidBrush
586 ( menu_background_color ), cliparea );
588 /* Draw menu borders */
589 dc.DrawRectangle( ResPool.GetPen( menu_border_color ), rect.X, rect.Y, rect.Width - 1, rect.Height - 1 );
592 Pen tmp_pen = ResPool.GetPen( Color.White );
593 dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 1, rect.Right - 2, rect.Y + 1 );
594 dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 2, rect.X + 1, rect.Bottom - 2 );
596 tmp_pen = ResPool.GetPen( menu_inner_border_color );
597 dc.DrawLine( tmp_pen, rect.Right - 2, rect.Y + 2, rect.Right - 2, rect.Bottom - 2 );
598 dc.DrawLine( tmp_pen, rect.Right - 3, rect.Bottom - 2, rect.X + 2, rect.Bottom - 2 );
600 for ( int i = 0; i < menu.MenuItems.Count; i++ )
601 if ( cliparea.IntersectsWith( menu.MenuItems[ i ].bounds ) ) {
602 MenuItem item = menu.MenuItems[ i ];
603 item.MenuHeight = menu.Height;
604 item.PerformDrawItem( new DrawItemEventArgs( dc, MenuFont,
605 item.bounds, i, item.Status ) );
611 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl ) {
612 Rectangle client_area = ctrl.client_area;
614 Rectangle bar = ctrl.client_area;
616 barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
618 bar.Width = barpos_pixels + 1;
620 // Draw bar background
621 dc.FillRectangle( ResPool.GetSolidBrush( menu_separator_color ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
624 Pen tmp_pen = ResPool.GetPen( progressbar_edge_dot_color );
625 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1 );
626 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
627 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1 );
628 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
630 tmp_pen = ResPool.GetPen( scrollbar_border_color );
631 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Y );
632 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
633 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Bottom - 1 );
634 dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
636 if ( barpos_pixels <= 0 )
639 if ((bar.Width - 2) <= 0 || (bar.Height - 1) <= 0)
643 dc.DrawRectangle( ResPool.GetPen( combobox_focus_border_color ), bar.X - 1, bar.Y - 1, bar.Width, bar.Height + 1 );
644 tmp_pen = ResPool.GetPen( progressbar_inner_border_color );
645 dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.Right - 2, bar.Y );
646 dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.X, bar.Bottom - 1 );
648 using ( Bitmap bmp = new Bitmap( bar.Width - 2, bar.Height - 1 ) ) {
649 using ( Graphics gr = Graphics.FromImage( bmp ) ) {
650 gr.FillRectangle( ResPool.GetSolidBrush( tab_focus_color ), 0, 0, bmp.Width, bmp.Height );
652 LinearGradientBrush lgbr = new LinearGradientBrush( new Rectangle( 0, 0, bmp.Height, bmp.Height ), progressbar_first_gradient_color, progressbar_second_gradient_color, 0.0f, true );
654 lgbr.RotateTransform( 45.0f, MatrixOrder.Append );
656 float pen_width = bmp.Height / 2;
658 Pen pen = new Pen( lgbr, pen_width );
660 int add = bmp.Height + (int)pen.Width / 2;
663 int x_bottom = - bmp.Height;
665 while ( x_bottom < bmp.Width ) {
666 gr.DrawLine( pen, x_top, 0, x_bottom, bmp.Height );
674 dc.DrawImage( bmp, bar.X + 1, bar.Y + 1 );
677 #endregion // ProgressBar
681 // renders a radio button with the Flat and Popup FlatStyle
682 protected override void DrawFlatStyleRadioButton (Graphics dc, Rectangle rectangle, RadioButton radio_button)
684 if (radio_button.Enabled) {
685 // draw the outer flatstyle arcs
686 if (radio_button.FlatStyle == FlatStyle.Flat) {
687 dc.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
689 // fill in the area depending on whether or not the mouse is hovering
690 if (radio_button.is_entered && radio_button.Capture) {
691 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
693 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
696 // must be a popup radio button
698 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
700 if (radio_button.is_entered || radio_button.Capture) {
701 // draw the popup 3d button knob
702 dc.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
704 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
705 dc.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
708 // just draw lighter flatstyle outer circle
709 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);
714 // fill control background color regardless of actual backcolor
715 dc.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
716 // draw the ark as control dark
717 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
721 if (radio_button.Checked) {
722 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
723 dc.SmoothingMode = SmoothingMode.AntiAlias;
725 CL_Draw_RadioButton_Dot (dc, rectangle, true, false);
727 dc.SmoothingMode = old_smoothing_mode;
730 #endregion // RadioButton
733 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
734 int scrollbutton_width = bar.scrollbutton_width;
735 int scrollbutton_height = bar.scrollbutton_height;
736 Rectangle first_arrow_area;
737 Rectangle second_arrow_area;
740 thumb_pos = bar.ThumbPos;
743 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
744 bar.FirstArrowArea = first_arrow_area;
746 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
747 bar.SecondArrowArea = second_arrow_area;
749 thumb_pos.Width = bar.Width;
750 bar.ThumbPos = thumb_pos;
753 switch ( bar.thumb_moving ) {
754 case ScrollBar.ThumbMoving.None: {
755 ScrollBar_Vertical_Draw_ThumbMoving_None( scrollbutton_height, bar, clip, dc );
758 case ScrollBar.ThumbMoving.Forward: {
759 ScrollBar_Vertical_Draw_ThumbMoving_Forward( scrollbutton_height, bar, thumb_pos, clip, dc );
763 case ScrollBar.ThumbMoving.Backwards: {
764 ScrollBar_Vertical_Draw_ThumbMoving_Backwards( scrollbutton_height, bar, thumb_pos, clip, dc );
773 if ( clip.IntersectsWith( first_arrow_area ) )
774 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
775 if ( clip.IntersectsWith( second_arrow_area ) )
776 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
778 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
779 bar.FirstArrowArea = first_arrow_area;
781 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
782 bar.SecondArrowArea = second_arrow_area;
784 thumb_pos.Height = bar.Height;
785 bar.ThumbPos = thumb_pos;
788 switch ( bar.thumb_moving ) {
789 case ScrollBar.ThumbMoving.None: {
790 ScrollBar_Horizontal_Draw_ThumbMoving_None( scrollbutton_width, bar, clip, dc );
794 case ScrollBar.ThumbMoving.Forward: {
795 ScrollBar_Horizontal_Draw_ThumbMoving_Forward( scrollbutton_width, thumb_pos, bar, clip, dc );
799 case ScrollBar.ThumbMoving.Backwards: {
800 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( scrollbutton_width, thumb_pos, bar, clip, dc );
806 if ( clip.IntersectsWith( first_arrow_area ) )
807 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
808 if ( clip.IntersectsWith( second_arrow_area ) )
809 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
813 ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
816 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
817 if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
818 DrawScrollBarThumb( dc, thumb_pos, bar );
821 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc ) {
822 Rectangle r = new Rectangle( 0,
823 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
824 Rectangle intersect = Rectangle.Intersect( clip, r );
826 if ( intersect != Rectangle.Empty ) {
827 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
828 Pen pen = ResPool.GetPen( scrollbar_border_color );
829 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
830 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
834 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
835 Rectangle r = new Rectangle( 0, scrollbutton_height,
836 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
837 Rectangle intersect = Rectangle.Intersect( clip, r );
839 if ( intersect != Rectangle.Empty ) {
840 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
841 Pen pen = ResPool.GetPen( scrollbar_border_color );
842 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
843 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
847 r.Y = thumb_pos.Y + thumb_pos.Height;
848 r.Width = bar.ClientRectangle.Width;
849 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
851 intersect = Rectangle.Intersect( clip, r );
852 if ( intersect != Rectangle.Empty ) {
853 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
854 Pen pen = ResPool.GetPen( scrollbar_border_color );
855 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
856 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
860 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
861 Rectangle r = new Rectangle( 0, scrollbutton_height,
862 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
863 Rectangle intersect = Rectangle.Intersect( clip, r );
865 if ( intersect != Rectangle.Empty ) {
866 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
867 Pen pen = ResPool.GetPen( scrollbar_border_color );
868 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
869 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
873 r.Y = thumb_pos.Y + thumb_pos.Height;
874 r.Width = bar.ClientRectangle.Width;
875 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
877 intersect = Rectangle.Intersect( clip, r );
878 if ( intersect != Rectangle.Empty ) {
879 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
880 Pen pen = ResPool.GetPen( scrollbar_border_color );
881 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
882 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
886 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc ) {
887 Rectangle r = new Rectangle( scrollbutton_width,
888 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
889 Rectangle intersect = Rectangle.Intersect( clip, r );
891 if ( intersect != Rectangle.Empty ) {
892 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
893 Pen pen = ResPool.GetPen( scrollbar_border_color );
894 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
895 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
899 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
900 Rectangle r = new Rectangle( scrollbutton_width, 0,
901 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
902 Rectangle intersect = Rectangle.Intersect( clip, r );
904 if ( intersect != Rectangle.Empty ) {
905 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
906 Pen pen = ResPool.GetPen( scrollbar_border_color );
907 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
908 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
911 r.X = thumb_pos.X + thumb_pos.Width;
913 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
914 r.Height = bar.ClientRectangle.Height;
916 intersect = Rectangle.Intersect( clip, r );
917 if ( intersect != Rectangle.Empty ) {
918 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
919 Pen pen = ResPool.GetPen( scrollbar_border_color );
920 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
921 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
925 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
926 Rectangle r = new Rectangle( scrollbutton_width, 0,
927 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
928 Rectangle intersect = Rectangle.Intersect( clip, r );
930 if ( intersect != Rectangle.Empty ) {
931 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
932 Pen pen = ResPool.GetPen( scrollbar_border_color );
933 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
934 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
937 r.X = thumb_pos.X + thumb_pos.Width;
939 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
940 r.Height = bar.ClientRectangle.Height;
942 intersect = Rectangle.Intersect( clip, r );
943 if ( intersect != Rectangle.Empty ) {
944 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
945 Pen pen = ResPool.GetPen( scrollbar_border_color );
946 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
947 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
950 #endregion // ScrollBar
953 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
954 Brush br_forecolor, StatusBarPanel panel ) {
955 int border_size = 3; // this is actually const, even if the border style is none
957 area.Height -= border_size;
958 if ( panel.BorderStyle != StatusBarPanelBorderStyle.None ) {
959 dc.DrawRectangle( ResPool.GetPen( pressed_inner_border_dark_color ), area );
962 if ( panel.Style == StatusBarPanelStyle.OwnerDraw ) {
963 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
964 dc, panel.Parent.Font, area, index, DrawItemState.Default,
965 panel, panel.Parent.ForeColor, panel.Parent.BackColor );
966 panel.Parent.OnDrawItemInternal( e );
970 int left = area.Left;
971 if ( panel.Icon != null ) {
973 dc.DrawIcon( panel.Icon, left, area.Top );
974 left += panel.Icon.Width;
977 if ( panel.Text == String.Empty )
980 string text = panel.Text;
981 StringFormat string_format = new StringFormat( );
982 string_format.Trimming = StringTrimming.Character;
983 string_format.FormatFlags = StringFormatFlags.NoWrap;
985 if ( text[ 0 ] == '\t' ) {
986 string_format.Alignment = StringAlignment.Center;
987 text = text.Substring( 1 );
988 if ( text[ 0 ] == '\t' ) {
989 string_format.Alignment = StringAlignment.Far;
990 text = text.Substring( 1 );
994 int x = left + border_size;
995 int y = border_size + 2;
996 Rectangle r = new Rectangle( x, y,
997 area.Right - x - border_size,
998 area.Bottom - y - border_size );
1000 dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
1002 #endregion // StatusBar
1004 // FIXME: regions near the borders don't get filled with the correct backcolor
1005 // TODO: TabAlignment.Left and TabAlignment.Bottom
1006 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) {
1007 if (tab.Parent != null)
1008 dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area );
1010 dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area );
1011 Rectangle panel_rect = TabControlGetPanelRect( tab );
1013 if ( tab.Appearance == TabAppearance.Normal ) {
1015 switch ( tab.Alignment ) {
1016 case TabAlignment.Top:
1018 Pen pen = ResPool.GetPen( Color.White );
1020 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1021 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top , panel_rect.Right - 2, panel_rect.Top );
1023 pen = ResPool.GetPen( tab_inner_border_color );
1024 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1025 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1028 pen = ResPool.GetPen( tab_border_color );
1030 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Top - 1 );
1031 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Bottom - 2 );
1032 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom - 2, panel_rect.Right - 3, panel_rect.Bottom );
1033 dc.DrawLine( pen, panel_rect.Right - 3, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1034 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1035 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top - 1 );
1038 // FIXME: the size of the tab page is to big to draw the upper inner white border
1039 case TabAlignment.Right:
1041 pen = ResPool.GetPen( Color.White );
1043 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top + 1, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1044 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top + 1 , panel_rect.Right - 2, panel_rect.Top + 1 );
1046 pen = ResPool.GetPen( tab_inner_border_color );
1047 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1048 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1051 pen = ResPool.GetPen( tab_border_color );
1053 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top, panel_rect.Right - 1, panel_rect.Top );
1054 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top, panel_rect.Right - 1, panel_rect.Bottom );
1055 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1056 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1057 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top + 2 );
1058 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top + 2, panel_rect.Left + 2, panel_rect.Top );
1063 if (tab.Alignment == TabAlignment.Top) {
1064 for (int r = tab.TabPages.Count; r > 0; r--) {
1065 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1066 if (i == tab.SelectedIndex)
1068 if (r != tab.TabPages [i].Row)
1070 Rectangle rect = tab.GetTabRect (i);
1071 if (!rect.IntersectsWith (area))
1073 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1077 for (int r = 0; r < tab.TabPages.Count; r++) {
1078 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1079 if (i == tab.SelectedIndex)
1081 if (r != tab.TabPages [i].Row)
1083 Rectangle rect = tab.GetTabRect (i);
1084 if (!rect.IntersectsWith (area))
1086 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1091 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
1092 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
1093 if (rect.IntersectsWith (area))
1094 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
1097 if (tab.ShowSlider) {
1098 Rectangle right = TabControlGetRightScrollRect (tab);
1099 Rectangle left = TabControlGetLeftScrollRect (tab);
1100 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
1101 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
1105 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
1107 int FlatButtonSpacing = 8;
1109 int res = bounds.Width;
1111 if (page.BackColor != tab_selected_gradient_second_color)
1112 page.BackColor = tab_selected_gradient_second_color;
1114 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
1116 StringFormat string_format = new StringFormat ();
1118 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
1119 dc.FillRectangle (ResPool.GetSolidBrush (tab_selected_gradient_second_color), bounds);
1122 if (tab.Appearance == TabAppearance.FlatButtons) {
1123 int width = bounds.Width;
1124 bounds.Width += (FlatButtonSpacing - 2);
1126 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
1127 bounds.Width = width;
1131 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1132 } else if (tab.Appearance != TabAppearance.FlatButtons) {
1133 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1136 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
1138 string_format.Alignment = StringAlignment.Center;
1139 string_format.LineAlignment = StringAlignment.Center;
1140 string_format.FormatFlags = StringFormatFlags.NoWrap;
1142 Color tab_first_color = is_selected ? tab_selected_gradient_first_color : tab_not_selected_gradient_first_color;
1143 Color tab_second_color = is_selected ? tab_selected_gradient_second_color : tab_not_selected_gradient_second_color;
1145 switch (tab.Alignment) {
1146 case TabAlignment.Top:
1148 Rectangle tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1150 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom), tab_first_color, tab_second_color)) {
1151 dc.FillRectangle (lgbr, tab_interior);
1155 Pen tmp_pen = ResPool.GetPen (tab_edge_color);
1156 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 1, bounds.Left + 1, bounds.Top);
1157 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top, bounds.Right, bounds.Top + 1);
1160 tmp_pen = ResPool.GetPen (Color.White);
1161 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 1);
1162 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 1);
1165 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1166 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1167 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1168 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1170 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_dark_color, border_pressed_light_color)) {
1171 int diff = is_selected ? 3 : 2;
1172 using (Pen lgbrpen = new Pen (lgbr)) {
1173 dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - diff);
1174 dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Right, bounds.Bottom - diff);
1179 tmp_pen = ResPool.GetPen (tab_focus_color);
1180 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Right - 1, bounds.Top + 2);
1181 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1183 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1184 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1185 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1186 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1189 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1191 string_format.Alignment = StringAlignment.Center;
1192 string_format.LineAlignment = StringAlignment.Center;
1193 string_format.FormatFlags = StringFormatFlags.NoWrap;
1197 case TabAlignment.Bottom:
1199 tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1201 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom - 1), tab_first_color, tab_second_color)) {
1202 dc.FillRectangle (lgbr, tab_interior);
1206 tmp_pen = ResPool.GetPen (tab_edge_color);
1207 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1208 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom, bounds.Right, bounds.Bottom - 1);
1211 tmp_pen = ResPool.GetPen (Color.White);
1212 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 2);
1213 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
1216 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1217 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1218 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1219 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1221 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_light_color, border_pressed_dark_color)) {
1222 int diff = is_selected ? 3 : 2;
1223 using (Pen lgbrpen = new Pen (lgbr)) {
1224 dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1225 dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1230 tmp_pen = ResPool.GetPen (tab_focus_color);
1231 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Bottom - 2);
1232 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
1234 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1235 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1236 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1237 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1240 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1242 string_format.Alignment = StringAlignment.Center;
1243 string_format.LineAlignment = StringAlignment.Center;
1244 string_format.FormatFlags = StringFormatFlags.NoWrap;
1248 case TabAlignment.Left:
1250 int w_diff = is_selected ? 2 : 0;
1252 tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2 - w_diff, bounds.Height - 2);
1254 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Right - w_diff, bounds.Top + 2), tab_first_color, tab_second_color)) {
1255 dc.FillRectangle (lgbr, tab_interior);
1259 tmp_pen = ResPool.GetPen (tab_edge_color);
1260 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top, bounds.Left, bounds.Top + 1);
1261 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1264 tmp_pen = ResPool.GetPen (Color.White);
1265 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 3, bounds.Top + 1);
1266 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1269 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1270 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Left, bounds.Top + 2);
1271 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);
1272 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1274 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_dark_color, border_pressed_light_color)) {
1275 int diff = is_selected ? 3 : 1;
1277 using (Pen lgbrpen = new Pen (lgbr)) {
1278 dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Top, bounds.Right - diff, bounds.Left + 2);
1279 dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Bottom, bounds.Right - diff, bounds.Left + 2);
1284 tmp_pen = ResPool.GetPen (tab_focus_color);
1285 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top + 1, bounds.Left + 3, bounds.Bottom - 1);
1286 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 2, bounds.Left + 2, bounds.Bottom - 2);
1288 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1289 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top, bounds.Left + 1, bounds.Top + 2);
1290 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1291 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
1294 interior = new Rectangle (bounds.Left + 2, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1296 string_format.Alignment = StringAlignment.Center;
1297 string_format.LineAlignment = StringAlignment.Center;
1298 string_format.FormatFlags = StringFormatFlags.NoWrap;
1299 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1304 // TabAlignment.Right
1306 tab_interior = new Rectangle (bounds.Left, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2);
1308 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right, bounds.Top + 2), tab_second_color, tab_first_color)) {
1309 dc.FillRectangle (lgbr, tab_interior);
1312 int l_diff = is_selected ? 2 : 0;
1315 tmp_pen = ResPool.GetPen (tab_edge_color);
1316 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right - 1, bounds.Top + 1);
1317 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom);
1320 tmp_pen = ResPool.GetPen (Color.White);
1321 dc.DrawLine (tmp_pen, bounds.Left + l_diff, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1322 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1325 tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1326 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1327 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1328 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1330 using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_light_color, border_pressed_dark_color)) {
1331 int diff = is_selected ? 3 : 1;
1333 using (Pen lgbrpen = new Pen (lgbr)) {
1334 dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Top, bounds.Right - diff, bounds.Top);
1335 dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Bottom, bounds.Right - diff, bounds.Bottom);
1340 tmp_pen = ResPool.GetPen (tab_focus_color);
1341 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top + 1, bounds.Right - 3, bounds.Bottom - 1);
1342 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1344 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1345 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1346 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1347 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1350 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1352 string_format.Alignment = StringAlignment.Center;
1353 string_format.LineAlignment = StringAlignment.Center;
1354 string_format.FormatFlags = StringFormatFlags.NoWrap;
1355 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1361 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
1362 if (tab.Alignment == TabAlignment.Left) {
1363 int wo = interior.Width / 2;
1364 int ho = interior.Height / 2;
1365 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
1366 dc.RotateTransform (180);
1367 dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
1368 dc.ResetTransform ();
1370 dc.DrawString (page.Text, page.Font,
1371 ResPool.GetSolidBrush (SystemColors.ControlText),
1372 interior, string_format);
1374 } else if (page.Text != null) {
1375 DrawItemState state = DrawItemState.None;
1376 if (page == tab.SelectedTab)
1377 state |= DrawItemState.Selected;
1378 DrawItemEventArgs e = new DrawItemEventArgs (dc,
1379 tab.Font, bounds, tab.IndexForTabPage (page),
1380 state, page.ForeColor, page.BackColor);
1381 tab.OnDrawItemInternal (e);
1388 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state ) {
1389 Point[] arrow = new Point[ 3 ];
1399 bool pushed = false;
1401 Color first_color = Color.White;
1402 Color second_color = combobox_button_second_gradient_color;
1404 dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1406 if ( state == ButtonState.Pushed ) {
1407 first_color = pressed_gradient_first_color;
1408 second_color = pressed_gradient_second_color;
1412 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 2 ), first_color, second_color ) ) {
1413 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
1417 Pen tmp_pen = ResPool.GetPen( !pushed ? Color.White : pressed_inner_border_dark_color );
1418 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 1 );
1419 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 2 );
1421 tmp_pen = ResPool.GetPen( !pushed ? inner_border_dark_color : pressed_inner_border_dark_color );
1422 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y + 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1423 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1426 Point[] points = new Point[] {
1427 new Point( rectangle.X, rectangle.Y ),
1428 new Point( rectangle.Right - 3, rectangle.Y ),
1429 new Point( rectangle.Right - 1, rectangle.Y + 2 ),
1430 new Point( rectangle.Right - 1, rectangle.Bottom - 3 ),
1431 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
1432 new Point( rectangle.X, rectangle.Bottom - 1 ),
1433 new Point( rectangle.X, rectangle.Y )
1436 dc.DrawPolygon( ResPool.GetPen( pushed ? border_pressed_dark_color : border_normal_dark_color ), points );
1438 // edges on right side
1439 tmp_pen = ResPool.GetPen( control_parent_backcolor );
1440 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1441 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1443 tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
1444 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1445 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1447 rect = new Rectangle( rectangle.X + 1 + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2 - 1, rectangle.Height / 2 );
1448 centerX = rect.Left + rect.Width / 2;
1449 centerY = rect.Top + rect.Height / 2;
1450 shiftX = Math.Max( 1, rect.Width / 8 );
1451 shiftY = Math.Max( 1, rect.Height / 8 );
1453 if ( ( state & ButtonState.Pushed ) != 0 ) {
1461 P1 = new Point( rect.Left, centerY );
1462 P2 = new Point( centerX, rect.Bottom );
1463 P3 = new Point( rect.Right - 1, centerY );
1469 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1470 dc.SmoothingMode = SmoothingMode.AntiAlias;
1472 /* Draw the arrow */
1473 if ( state == ButtonState.Inactive ) {
1474 /* Move away from the shadow */
1475 P1.X += 1; P1.Y += 1;
1476 P2.X += 1; P2.Y += 1;
1477 P3.X += 1; P3.Y += 1;
1483 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) ) {
1484 dc.DrawLines( pen, arrow );
1487 P1 = new Point( rect.Left, centerY );
1488 P2 = new Point( centerX, rect.Bottom );
1489 P3 = new Point( rect.Right - 1, centerY );
1495 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) ) {
1496 dc.DrawLines( pen, arrow );
1499 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) ) {
1500 dc.DrawLines( pen, arrow );
1504 dc.SmoothingMode = old_smoothing_mode;
1507 /* Scroll button: regular button + direction arrow */
1508 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state ) {
1509 bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1511 DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1516 color_arrow = arrow_color;
1518 color_arrow = ColorGrayText;
1522 int centerX = area.Left + area.Width / 2;
1523 int centerY = area.Top + area.Height / 2;
1527 if ( ( state & ButtonState.Pushed ) != 0 )
1532 if ( area.Width < 12 || area.Height < 12 ) {
1537 Point[] arrow = new Point[ 4 ];
1539 switch (scroll_button_type) {
1540 case ScrollButton.Down:
1541 centerY += shift + 1;
1542 arrow [0] = new Point (centerX - min_4, centerY - min_2);
1543 arrow [1] = new Point (centerX, centerY + min_2);
1544 arrow [2] = new Point (centerX + min_4, centerY - min_2);
1545 arrow [3] = new Point (centerX - min_4, centerY - min_2);
1547 case ScrollButton.Up:
1549 arrow [0] = new Point (centerX - min_4, centerY + min_2);
1550 arrow [1] = new Point (centerX, centerY - min_2);
1551 arrow [2] = new Point (centerX + min_4, centerY + min_2);
1552 arrow [3] = new Point (centerX - min_4, centerY + min_2);
1554 case ScrollButton.Left:
1556 arrow [0] = new Point (centerX + min_2, centerY - min_4);
1557 arrow [1] = new Point (centerX + min_2, centerY + min_4);
1558 arrow [2] = new Point (centerX - min_2, centerY);
1559 arrow [3] = new Point (centerX + min_2, centerY - min_4);
1561 case ScrollButton.Right:
1562 centerX += shift + 1;
1563 arrow [0] = new Point (centerX - min_2, centerY - min_4);
1564 arrow [1] = new Point (centerX + min_2, centerY);
1565 arrow [2] = new Point (centerX - min_2, centerY + min_4);
1566 arrow [3] = new Point (centerX - min_2, centerY - min_4);
1572 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1573 dc.SmoothingMode = SmoothingMode.AntiAlias;
1574 dc.FillPolygon( ResPool.GetSolidBrush( color_arrow ), arrow );
1575 dc.SmoothingMode = old_smoothing_mode;
1578 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds ) {
1579 Point pt1 = new Point( bounds.Right - 3, bounds.Bottom );
1580 Point pt2 = new Point( bounds.Right, bounds.Bottom - 3 );
1583 Pen tmp_pen = ResPool.GetPen( Color.White );
1584 for ( int i = 0; i < 4; i++ ) {
1585 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1591 tmp_pen = ResPool.GetPen( pressed_inner_border_dark_color );
1592 for ( int i = 0; i < 4; i++ ) {
1593 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1597 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
1598 LinearGradientBrush lgbr = null;
1601 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.Right - 2, area.Y + 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1603 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1605 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1610 Pen pen = ResPool.GetPen( border_normal_dark_color );
1612 dc.DrawRectangle( pen, area.X, area.Y, area.Width - 1, area.Height - 1 );
1615 pen = ResPool.GetPen( Color.White );
1616 dc.DrawLine( pen, area.X + 1, area.Bottom - 2, area.X + 1, area.Y + 1 );
1617 dc.DrawLine( pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1619 pen = ResPool.GetPen( inner_border_dark_color );
1620 dc.DrawLine( pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1621 dc.DrawLine( pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1624 if ( area.Height > 12 ) {
1625 int mid_y = area.Y + ( area.Height / 2 );
1626 int mid_x = area.X + ( area.Width / 2 );
1628 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1629 dc.DrawLine( pen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1630 dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x + 3, mid_y - 3 );
1631 dc.DrawLine( pen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1633 Pen spen = ResPool.GetPen( Color.White );
1634 dc.DrawLine( spen, mid_x - 3, mid_y + 1, mid_x + 3, mid_y + 1 );
1635 dc.DrawLine( spen, mid_x - 3, mid_y - 2, mid_x + 3, mid_y - 2 );
1636 dc.DrawLine( spen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1639 // draw grip lines only if there is enough space
1640 if ( area.Width > 12 ) {
1641 int mid_x = area.X + ( area.Width / 2 );
1642 int mid_y = area.Y + ( area.Height / 2 );
1644 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1645 dc.DrawLine( pen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1646 dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x - 3, mid_y + 3 );
1647 dc.DrawLine( pen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1649 Pen spen = ResPool.GetPen( Color.White );
1650 dc.DrawLine( spen, mid_x + 1, mid_y - 3, mid_x + 1, mid_y + 3 );
1651 dc.DrawLine( spen, mid_x - 2, mid_y - 3, mid_x - 2, mid_y + 3 );
1652 dc.DrawLine( spen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1657 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type ) {
1658 Pen pen = ResPool.GetPen( border_normal_dark_color );
1660 Color first_gradient_color = gradient_first_color;
1661 Color second_gradient_color = gradient_second_color_nr2;
1663 bool pushed = false;
1665 if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed ) {
1666 first_gradient_color = pressed_gradient_first_color;
1667 second_gradient_color = pressed_gradient_second_color;
1671 Point[] points = null;
1673 LinearGradientBrush lgbr = null;
1675 switch ( scroll_button_type ) {
1676 case ScrollButton.Left:
1677 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1678 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.X, area.Bottom - 1 );
1680 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1681 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1683 Pen tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1684 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 2, area.X + 1, area.Bottom - 2 );
1685 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1687 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1688 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1689 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1691 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1692 dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1693 dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1695 points = new Point[] {
1696 new Point( area.X + 2, area.Y ),
1697 new Point( area.Right - 1, area.Y ),
1698 new Point( area.Right - 1, area.Bottom - 1 ),
1699 new Point( area.X + 2, area.Bottom - 1 ),
1700 new Point( area.X, area.Bottom - 3 ),
1701 new Point( area.X, area.Y + 2 ),
1702 new Point( area.X + 2, area.Y )
1704 dc.DrawPolygon( pen, points );
1706 case ScrollButton.Right:
1707 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1708 dc.DrawLine( ResPool.GetPen( ColorControl ), area.Right - 1, area.Y, area.Right - 1, area.Bottom - 1 );
1710 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1711 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1713 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1714 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1715 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1717 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1718 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1719 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1721 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1722 dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1723 dc.DrawLine( tmp_pen, area.Right - 1, area.Bottom - 2, area.Right - 2, area.Bottom - 1 );
1725 points = new Point[] {
1726 new Point( area.X, area.Y ),
1727 new Point( area.Right - 3, area.Y ),
1728 new Point( area.Right - 1, area.Y + 2 ),
1729 new Point( area.Right - 1, area.Bottom - 3 ),
1730 new Point( area.Right - 3, area.Bottom - 1 ),
1731 new Point( area.X, area.Bottom - 1 ),
1732 new Point( area.X, area.Y ),
1734 dc.DrawPolygon( pen, points );
1736 case ScrollButton.Up:
1737 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1738 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.Right - 1, area.Y );
1740 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1741 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1743 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1744 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1745 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1747 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1748 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1749 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1751 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1752 dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1753 dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1755 points = new Point[] {
1756 new Point( area.X + 2, area.Y ),
1757 new Point( area.Right - 3, area.Y ),
1758 new Point( area.Right - 1, area.Y + 2 ),
1759 new Point( area.Right - 1, area.Bottom - 1 ),
1760 new Point( area.X, area.Bottom - 1 ),
1761 new Point( area.X, area.Y + 2 ),
1762 new Point( area.X + 2, area.Y )
1764 dc.DrawPolygon( pen, points );
1766 case ScrollButton.Down:
1767 // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1768 dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Bottom - 1, area.Right - 1, area.Bottom - 1 );
1770 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1771 dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1773 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1774 dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1775 dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1777 tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1778 dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1779 dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1781 tmp_pen = ResPool.GetPen( edge_top_inner_color );
1782 dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1783 dc.DrawLine( tmp_pen, area.Right - 2, area.Bottom - 1, area.Right - 1, area.Bottom - 2 );
1785 points = new Point[] {
1786 new Point( area.X, area.Y ),
1787 new Point( area.Right - 1, area.Y ),
1788 new Point( area.Right - 1, area.Bottom - 3 ),
1789 new Point( area.Right - 3, area.Bottom - 1 ),
1790 new Point( area.X + 2, area.Bottom - 1 ),
1791 new Point( area.X, area.Bottom - 3 ),
1792 new Point( area.X, area.Y )
1794 dc.DrawPolygon( pen, points );
1803 #endregion // ToolBar
1806 public override void DrawGroupBox( Graphics dc, Rectangle area, GroupBox box ) {
1807 StringFormat text_format;
1813 rect = box.ClientRectangle;
1815 dc.FillRectangle( ResPool.GetSolidBrush( box.BackColor ), rect );
1817 text_format = new StringFormat( );
1818 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1820 size = dc.MeasureString( box.Text, box.Font );
1821 width = (int) size.Width;
1823 if ( width > box.Width - 16 )
1824 width = box.Width - 16;
1826 y = box.Font.Height / 2;
1828 Pen pen = ResPool.GetPen( pressed_inner_border_dark_color );
1832 new Point( 8 + width, y ),
1833 new Point( box.Width - 3, y ),
1834 new Point( box.Width - 1, y + 2 ),
1835 new Point( box.Width - 1, box.Height - 3 ),
1836 new Point( box.Width - 3, box.Height - 1 ),
1837 new Point( 2, box.Height - 1 ),
1838 new Point( 0, box.Height - 3 ),
1839 new Point( 0, y + 2 ),
1843 dc.DrawLines( pen, points );
1846 if ( box.Enabled ) {
1847 dc.DrawString( box.Text, box.Font, ResPool.GetSolidBrush( box.ForeColor ), 10, 0, text_format );
1849 CPDrawStringDisabled( dc, box.Text, box.Font, box.ForeColor,
1850 new RectangleF( 10, 0, width, box.Font.Height ), text_format );
1852 text_format.Dispose( );
1857 private void DrawTrackBar_Vertical( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1858 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1859 float ticks, int value_pos, bool mouse_value ) {
1861 Point toptick_startpoint = new Point( );
1862 Point bottomtick_startpoint = new Point( );
1863 Point channel_startpoint = new Point( );
1865 float pixels_betweenticks;
1866 const int space_from_right = 8;
1867 const int space_from_left = 8;
1868 Rectangle area = tb.ClientRectangle;
1870 switch ( tb.TickStyle ) {
1871 case TickStyle.BottomRight:
1872 case TickStyle.None:
1873 channel_startpoint.Y = 8;
1874 channel_startpoint.X = 9;
1875 bottomtick_startpoint.Y = 13;
1876 bottomtick_startpoint.X = 24;
1878 case TickStyle.TopLeft:
1879 channel_startpoint.Y = 8;
1880 channel_startpoint.X = 19;
1881 toptick_startpoint.Y = 13;
1882 toptick_startpoint.X = 8;
1884 case TickStyle.Both:
1885 channel_startpoint.Y = 8;
1886 channel_startpoint.X = 18;
1887 bottomtick_startpoint.Y = 13;
1888 bottomtick_startpoint.X = 32;
1889 toptick_startpoint.Y = 13;
1890 toptick_startpoint.X = 8;
1896 thumb_area.X = area.X + channel_startpoint.X;
1897 thumb_area.Y = area.Y + channel_startpoint.Y;
1898 thumb_area.Height = area.Height - space_from_right - space_from_left;
1899 thumb_area.Width = 4;
1901 pixel_len = thumb_area.Height - 11;
1902 pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
1904 /* Convert thumb position from mouse position to value*/
1905 if ( mouse_value ) {
1907 if ( value_pos >= channel_startpoint.Y )
1908 value_pos = (int)( ( (float) ( value_pos - channel_startpoint.Y ) ) / pixels_betweenticks );
1912 if ( value_pos + tb.Minimum > tb.Maximum )
1913 value_pos = tb.Maximum - tb.Minimum;
1915 tb.Value = value_pos + tb.Minimum;
1918 thumb_pos.Width = 13;
1919 thumb_pos.Height = 29;
1921 thumb_pos.Y = channel_startpoint.Y + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Height / 3 );
1923 if ( thumb_pos.Y < channel_startpoint.Y )
1924 thumb_pos.Y = channel_startpoint.Y;
1926 if ( thumb_pos.Y > thumb_area.Bottom - 29 )
1927 thumb_pos.Y = thumb_area.Bottom - 29;
1931 Pen pen = ResPool.GetPen( tab_top_border_focus_color );
1932 dc.DrawLine( pen, channel_startpoint.X, thumb_pos.Y + 29, channel_startpoint.X, thumb_area.Bottom );
1933 dc.DrawLine( pen, channel_startpoint.X, thumb_area.Bottom, channel_startpoint.X + 4, thumb_area.Bottom );
1934 dc.DrawLine( pen, channel_startpoint.X + 4, thumb_pos.Y + 29, channel_startpoint.X + 4, thumb_area.Bottom );
1936 pen = ResPool.GetPen( menuitem_gradient_first_color );
1937 dc.DrawLine( pen, channel_startpoint.X + 1, thumb_pos.Y + 28, channel_startpoint.X + 1, thumb_area.Bottom - 1 );
1938 pen = ResPool.GetPen( trackbar_second_gradient_color );
1939 dc.DrawLine( pen, channel_startpoint.X + 2, thumb_pos.Y + 28, channel_startpoint.X + 2, thumb_area.Bottom - 1 );
1940 pen = ResPool.GetPen( trackbar_third_gradient_color );
1941 dc.DrawLine( pen, channel_startpoint.X + 3, thumb_pos.Y + 28, channel_startpoint.X + 3, thumb_area.Bottom - 1 );
1944 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1945 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, channel_startpoint.X + 1, thumb_pos.Y );
1946 dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), channel_startpoint.X + 2, channel_startpoint.Y + 1, 1, thumb_pos.Y );
1948 pen = ResPool.GetPen( scrollbar_border_color );
1949 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, thumb_pos.Y );
1950 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X + 4, channel_startpoint.Y );
1951 dc.DrawLine( pen, channel_startpoint.X + 4, channel_startpoint.Y, channel_startpoint.X + 4, thumb_pos.Y );
1954 thumb_pos.X = channel_startpoint.X - 4;
1957 pen = ResPool.GetPen( Color.White );
1958 dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
1959 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
1961 pen = ResPool.GetPen( menu_separator_color );
1962 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1963 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1967 new Point( thumb_pos.X + 2, thumb_pos.Y ),
1968 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
1969 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
1970 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
1971 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
1972 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
1973 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
1974 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
1975 new Point( thumb_pos.X + 2, thumb_pos.Y )
1978 dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
1980 Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
1981 Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
1983 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
1984 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
1988 pen = ResPool.GetPen( edge_top_inner_color );
1989 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
1990 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
1992 pen = ResPool.GetPen( edge_bottom_inner_color );
1993 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
1994 dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
1997 pen = ResPool.GetPen( pressed_inner_border_dark_color );
1998 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 11, thumb_pos.X + 8, thumb_pos.Y + 11 );
1999 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 14, thumb_pos.X + 8, thumb_pos.Y + 14 );
2000 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 17, thumb_pos.X + 8, thumb_pos.Y + 17 );
2002 pen = ResPool.GetPen( Color.White );
2003 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 12, thumb_pos.X + 8, thumb_pos.Y + 12 );
2004 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 15, thumb_pos.X + 8, thumb_pos.Y + 15 );
2005 dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 18, thumb_pos.X + 8, thumb_pos.Y + 18 );
2007 pixel_len = thumb_area.Height - 11;
2008 pixels_betweenticks = pixel_len / ticks;
2011 thumb_area.X = thumb_pos.X;
2012 thumb_area.Y = channel_startpoint.Y;
2013 thumb_area.Width = thumb_pos.Width;
2015 Region outside = new Region( area );
2016 outside.Exclude( thumb_area );
2018 if ( outside.IsVisible( clip_rectangle ) ) {
2019 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2020 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2022 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2023 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2024 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
2025 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc );
2027 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
2028 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc );
2032 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2033 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2035 pixel_len = thumb_area.Height - 11;
2036 pixels_betweenticks = pixel_len / ticks;
2038 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2039 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2040 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
2041 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc );
2043 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
2044 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc );
2053 private void DrawTrackBar_Horizontal( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
2054 ref Rectangle thumb_pos, ref Rectangle thumb_area,
2055 float ticks, int value_pos, bool mouse_value ) {
2056 Point toptick_startpoint = new Point( );
2057 Point bottomtick_startpoint = new Point( );
2058 Point channel_startpoint = new Point( );
2060 float pixels_betweenticks;
2061 const int space_from_right = 8;
2062 const int space_from_left = 8;
2063 Rectangle area = tb.ClientRectangle;
2065 switch ( tb.TickStyle ) {
2066 case TickStyle.BottomRight:
2067 case TickStyle.None:
2068 channel_startpoint.X = 8;
2069 channel_startpoint.Y = 9;
2070 bottomtick_startpoint.X = 13;
2071 bottomtick_startpoint.Y = 24;
2073 case TickStyle.TopLeft:
2074 channel_startpoint.X = 8;
2075 channel_startpoint.Y = 19;
2076 toptick_startpoint.X = 13;
2077 toptick_startpoint.Y = 8;
2079 case TickStyle.Both:
2080 channel_startpoint.X = 8;
2081 channel_startpoint.Y = 18;
2082 bottomtick_startpoint.X = 13;
2083 bottomtick_startpoint.Y = 32;
2084 toptick_startpoint.X = 13;
2085 toptick_startpoint.Y = 8;
2091 thumb_area.X = area.X + channel_startpoint.X;
2092 thumb_area.Y = area.Y + channel_startpoint.Y;
2093 thumb_area.Width = area.Width - space_from_right - space_from_left;
2094 thumb_area.Height = 4;
2096 pixel_len = thumb_area.Width - 11;
2097 pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
2099 /* Convert thumb position from mouse position to value*/
2100 if ( mouse_value ) {
2101 if ( value_pos >= channel_startpoint.X )
2102 value_pos = (int)( ( (float) ( value_pos - channel_startpoint.X ) ) / pixels_betweenticks );
2106 if ( value_pos + tb.Minimum > tb.Maximum )
2107 value_pos = tb.Maximum - tb.Minimum;
2109 tb.Value = value_pos + tb.Minimum;
2112 thumb_pos.Width = 29;
2113 thumb_pos.Height = 13;
2115 thumb_pos.X = channel_startpoint.X + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Width / 3 );
2117 if ( thumb_pos.X < channel_startpoint.X )
2118 thumb_pos.X = channel_startpoint.X;
2120 if ( thumb_pos.X > thumb_area.Right - 29 )
2121 thumb_pos.X = thumb_area.Right - 29;
2125 Pen pen = ResPool.GetPen( tab_top_border_focus_color );
2126 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, thumb_pos.X, channel_startpoint.Y );
2127 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, channel_startpoint.Y + 4 );
2128 dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y + 4, thumb_pos.X, channel_startpoint.Y + 4 );
2130 pen = ResPool.GetPen( menuitem_gradient_first_color );
2131 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, thumb_pos.X, channel_startpoint.Y + 1 );
2132 pen = ResPool.GetPen( trackbar_second_gradient_color );
2133 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 2, thumb_pos.X, channel_startpoint.Y + 2 );
2134 pen = ResPool.GetPen( trackbar_third_gradient_color );
2135 dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 3, thumb_pos.X, channel_startpoint.Y + 3 );
2138 pen = ResPool.GetPen( pressed_inner_border_dark_color );
2139 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 1, thumb_area.Right - 1, channel_startpoint.Y + 1 );
2140 dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), thumb_pos.X + 29, channel_startpoint.Y + 2, thumb_area.Right - thumb_pos.X - 30, 1 );
2142 pen = ResPool.GetPen( scrollbar_border_color );
2143 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y );
2144 dc.DrawLine( pen, thumb_area.Right, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y + 4 );
2145 dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 4, thumb_area.Right, channel_startpoint.Y + 4 );
2149 thumb_pos.Y = channel_startpoint.Y - 4;
2152 pen = ResPool.GetPen( Color.White );
2153 dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
2154 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
2156 pen = ResPool.GetPen( menu_separator_color );
2157 dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2158 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2162 new Point( thumb_pos.X + 2, thumb_pos.Y ),
2163 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
2164 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
2165 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
2166 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
2167 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
2168 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
2169 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
2170 new Point( thumb_pos.X + 2, thumb_pos.Y )
2173 dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
2175 Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
2176 Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
2178 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
2179 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
2183 pen = ResPool.GetPen( edge_top_inner_color );
2184 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
2185 dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
2187 pen = ResPool.GetPen( edge_bottom_inner_color );
2188 dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
2189 dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
2192 pen = ResPool.GetPen( pressed_inner_border_dark_color );
2193 dc.DrawLine( pen, thumb_pos.X + 11, thumb_pos.Y + 4, thumb_pos.X + 11, thumb_pos.Y + 8 );
2194 dc.DrawLine( pen, thumb_pos.X + 14, thumb_pos.Y + 4, thumb_pos.X + 14, thumb_pos.Y + 8 );
2195 dc.DrawLine( pen, thumb_pos.X + 17, thumb_pos.Y + 4, thumb_pos.X + 17, thumb_pos.Y + 8 );
2197 pen = ResPool.GetPen( Color.White );
2198 dc.DrawLine( pen, thumb_pos.X + 12, thumb_pos.Y + 4, thumb_pos.X + 12, thumb_pos.Y + 8 );
2199 dc.DrawLine( pen, thumb_pos.X + 15, thumb_pos.Y + 4, thumb_pos.X + 15, thumb_pos.Y + 8 );
2200 dc.DrawLine( pen, thumb_pos.X + 18, thumb_pos.Y + 4, thumb_pos.X + 18, thumb_pos.Y + 8 );
2202 pixel_len = thumb_area.Width - 11;
2203 pixels_betweenticks = pixel_len / ticks;
2206 thumb_area.Y = thumb_pos.Y;
2207 thumb_area.X = channel_startpoint.X;
2208 thumb_area.Height = thumb_pos.Height;
2209 Region outside = new Region( area );
2210 outside.Exclude( thumb_area );
2212 if ( outside.IsVisible( clip_rectangle ) ) {
2213 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2214 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2216 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2217 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2218 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
2219 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3 );
2221 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
2222 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2 );
2226 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2227 ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2229 for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {
2230 if ( inc == 0 || ( inc + pixels_betweenticks ) >= pixel_len + 1 )
2231 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
2232 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y );
2234 dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
2235 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2243 public override void DrawTrackBar( Graphics dc, Rectangle clip_rectangle, TrackBar tb ) {
2246 float ticks = ( tb.Maximum - tb.Minimum ) / tb.tickFrequency; /* N of ticks draw*/
2248 Rectangle thumb_pos = tb.ThumbPos;
2249 Rectangle thumb_area = tb.ThumbArea;
2251 if ( tb.thumb_pressed ) {
2252 value_pos = tb.thumb_mouseclick;
2255 value_pos = tb.Value - tb.Minimum;
2256 mouse_value = false;
2259 area = tb.ClientRectangle;
2261 /* Control Background */
2262 if ( tb.BackColor == DefaultControlBackColor ) {
2263 dc.FillRectangle( ResPool.GetSolidBrush( ColorControl ), clip_rectangle );
2265 dc.FillRectangle( ResPool.GetSolidBrush( tb.BackColor ), clip_rectangle );
2268 if ( tb.Orientation == Orientation.Vertical ) {
2269 DrawTrackBar_Vertical( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2270 ticks, value_pos, mouse_value );
2273 DrawTrackBar_Horizontal( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2274 ticks, value_pos, mouse_value );
2277 // TODO: draw better focus rectangle
2279 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, area.Width - 1, 1 );
2280 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y + area.Height - 1, area.Width - 1, 1 );
2281 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, 1, area.Height - 1 );
2282 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X + area.Width - 1, area.Y, 1, area.Height - 1 );
2285 tb.ThumbPos = thumb_pos;
2286 tb.ThumbArea = thumb_area;
2288 #endregion // TrackBar
2291 // draws the ListViewItem of the given index
2292 protected override void DrawListViewItem( Graphics dc, ListView control, ListViewItem item ) {
2293 Rectangle rect_checkrect = item.CheckRectReal;
2294 Rectangle rect_iconrect = item.GetBounds( ItemBoundsPortion.Icon );
2295 Rectangle full_rect = item.GetBounds( ItemBoundsPortion.Entire );
2296 Rectangle text_rect = item.GetBounds( ItemBoundsPortion.Label );
2298 if ( control.CheckBoxes ) {
2299 if ( control.StateImageList == null ) {
2300 // Make sure we've got at least a line width of 1
2301 int check_wd = Math.Max( 3, rect_checkrect.Width / 6 );
2302 int scale = Math.Max( 1, rect_checkrect.Width / 12 );
2304 // set the checkbox background
2305 dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorWindow ),
2307 // define a rectangle inside the border area
2308 Rectangle rect = new Rectangle( rect_checkrect.X + 2,
2309 rect_checkrect.Y + 2,
2310 rect_checkrect.Width - 4,
2311 rect_checkrect.Height - 4 );
2312 Pen pen = new Pen( this.ColorWindowText, 2 );
2313 dc.DrawRectangle( pen, rect );
2315 // Need to draw a check-mark
2316 if ( item.Checked ) {
2318 // adjustments to get the check-mark at the right place
2319 rect.X ++; rect.Y ++;
2320 // following logic is taken from DrawFrameControl method
2321 for ( int i = 0; i < check_wd; i++ ) {
2322 dc.DrawLine( pen, rect.Left + check_wd / 2,
2323 rect.Top + check_wd + i,
2324 rect.Left + check_wd / 2 + 2 * scale,
2325 rect.Top + check_wd + 2 * scale + i );
2327 rect.Left + check_wd / 2 + 2 * scale,
2328 rect.Top + check_wd + 2 * scale + i,
2329 rect.Left + check_wd / 2 + 6 * scale,
2330 rect.Top + check_wd - 2 * scale + i );
2334 if ( item.Checked && control.StateImageList.Images.Count > 1 )
2335 control.StateImageList.Draw( dc,
2336 rect_checkrect.Location, 1 );
2337 else if ( ! item.Checked && control.StateImageList.Images.Count > 0 )
2338 control.StateImageList.Draw( dc,
2339 rect_checkrect.Location, 0 );
2343 // Item is drawn as a special case, as it is not just text
2344 if ( control.View == View.LargeIcon ) {
2345 if ( item.ImageIndex > -1 &&
2346 control.LargeImageList != null &&
2347 item.ImageIndex < control.LargeImageList.Images.Count ) {
2349 Point image_location = rect_iconrect.Location;
2350 Image image = control.LargeImageList.Images[ item.ImageIndex ];
2351 if ( image.Width < rect_iconrect.Width ) {
2352 int icon_rect_middle = rect_iconrect.Width / 2;
2353 int image_middle = image.Width / 2;
2354 image_location.X = image_location.X + icon_rect_middle - image_middle;
2356 control.LargeImageList.Draw( dc, image_location,
2360 if ( item.ImageIndex > -1 &&
2361 control.SmallImageList != null &&
2362 item.ImageIndex < control.SmallImageList.Images.Count )
2363 control.SmallImageList.Draw( dc, rect_iconrect.Location,
2367 // draw the item text
2368 // format for the item text
2369 StringFormat format = new StringFormat( );
2370 format.LineAlignment = StringAlignment.Center;
2371 if ( control.View == View.LargeIcon )
2372 format.Alignment = StringAlignment.Center;
2374 format.Alignment = StringAlignment.Near;
2376 if ( !control.LabelWrap )
2377 format.FormatFlags = StringFormatFlags.NoWrap;
2379 if ( item.Selected ) {
2380 if ( control.View == View.Details ) {
2381 if ( control.FullRowSelect ) {
2382 // fill the entire rect excluding the checkbox
2383 full_rect.Location = item.GetBounds (ItemBoundsPortion.Label).Location;
2384 dc.FillRectangle( this.ResPool.GetSolidBrush
2385 ( this.ColorHighlight ), full_rect );
2387 Size text_size = Size.Ceiling( dc.MeasureString( item.Text,
2389 text_rect.Width = text_size.Width;
2390 dc.FillRectangle( this.ResPool.GetSolidBrush
2391 ( this.ColorHighlight ), text_rect );
2394 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
2396 Point loc = text_rect.Location;
2397 loc.X += (text_rect.Width - text_size.Width) / 2;
2398 text_rect.Width = text_size.Width;*/
2399 dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorHighlight ),
2403 dc.FillRectangle( ResPool.GetSolidBrush( item.BackColor ), text_rect );
2405 if ( item.Text != null && item.Text.Length > 0 ) {
2407 if ( control.View != View.LargeIcon ) {
2408 if ( item.Selected )
2409 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2410 ( this.ColorHighlightText ), text_rect, format );
2412 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2413 ( item.ForeColor ), text_rect, format );
2415 // ListView CalcTextSize says wrapping is done for two lines only !?!
2416 // text is centered for the complete text_rect but it should be centered per available row/line
2418 // calculate how much lines we get out of text_rect and current item.Font
2419 int nr_lines = text_rect.Height / item.Font.Height;
2420 int rest = text_rect.Height % item.Font.Height;
2421 int line_height = item.Font.Height + ( rest > 1 ? 2 : 0 );
2423 Rectangle[] text_rects = new Rectangle[ nr_lines ];
2425 for ( int i = 0; i < nr_lines; i++ ) {
2426 text_rects[ i ].X = text_rect.X;
2427 text_rects[ i ].Y = text_rect.Y + i * line_height;
2428 text_rects[ i ].Width = text_rect.Width;
2429 text_rects[ i ].Height = line_height;
2432 string[] lines = new string[ nr_lines ];
2434 string text = item.Text;
2437 int current_pos = 0;
2438 for ( int k = 1; k <= text.Length; k++ ) {
2439 lines[ line_nr ] = text.Substring( current_pos, k - current_pos );
2441 // FIXME: Graphics.MeasureString returns wrong results if there is a
2442 // space char in the string
2443 SizeF sizef = dc.MeasureString( lines[ line_nr ], item.Font, text_rect.Width, format );
2445 if ( (int)sizef.Width > text_rect.Width - 3 ) {
2446 lines[ line_nr ] = lines[ line_nr ].Remove( lines[ line_nr ].Length - 1, 1 );
2450 if ( line_nr == nr_lines )
2456 foreach ( Rectangle t_rect in text_rects ) {
2457 if ( item.Selected )
2458 dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2459 ( this.ColorHighlightText ), t_rect, format );
2461 dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2462 ( item.ForeColor ), t_rect, format );
2468 if ( control.View == View.Details && control.Columns.Count > 0 ) {
2469 // draw subitems for details view
2470 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
2471 int count = ( control.Columns.Count < subItems.Count ?
2472 control.Columns.Count : subItems.Count );
2476 ListViewItem.ListViewSubItem subItem;
2477 Rectangle sub_item_rect = text_rect;
2479 // set the format for subitems
2480 format.FormatFlags = StringFormatFlags.NoWrap;
2481 format.Alignment = StringAlignment.Near;
2483 // 0th subitem is the item already drawn
2484 for ( int index = 1; index < count; index++ ) {
2485 subItem = subItems[ index ];
2486 col = control.Columns[ index ];
2487 sub_item_rect.X = col.Rect.Left;
2488 sub_item_rect.Width = col.Wd;
2489 sub_item_rect.X -= control.h_marker;
2491 SolidBrush sub_item_back_br = null;
2492 SolidBrush sub_item_fore_br = null;
2493 Font sub_item_font = null;
2495 if ( item.UseItemStyleForSubItems ) {
2496 sub_item_back_br = this.ResPool.GetSolidBrush
2498 sub_item_fore_br = this.ResPool.GetSolidBrush
2500 sub_item_font = item.Font;
2502 sub_item_back_br = this.ResPool.GetSolidBrush
2503 ( subItem.BackColor );
2504 sub_item_fore_br = this.ResPool.GetSolidBrush
2505 ( subItem.ForeColor );
2506 sub_item_font = subItem.Font;
2509 // In case of fullrowselect, background is filled
2510 // for the entire rect above
2511 if ( item.Selected && control.FullRowSelect ) {
2512 if ( subItem.Text != null && subItem.Text.Length > 0 )
2513 dc.DrawString( subItem.Text, sub_item_font,
2514 this.ResPool.GetSolidBrush
2515 ( this.ColorHighlightText ),
2516 sub_item_rect, format );
2518 dc.FillRectangle( sub_item_back_br, sub_item_rect );
2519 if ( subItem.Text != null && subItem.Text.Length > 0 )
2520 dc.DrawString( subItem.Text, sub_item_font,
2522 sub_item_rect, format );
2524 sub_item_rect.X += col.Wd;
2529 if ( item.Focused ) {
2530 if ( item.Selected )
2531 CPDrawFocusRectangle( dc, text_rect, ColorHighlightText, ColorHighlight );
2533 CPDrawFocusRectangle( dc, text_rect, control.ForeColor, control.BackColor );
2540 #region DateTimePicker
2541 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
2542 // if not showing the numeric updown control then render border
2543 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
2544 // draw the outer border
2545 Rectangle button_bounds = dtp.ClientRectangle;
2546 CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
2548 // deflate by the border width
2549 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
2550 button_bounds.Inflate (-2,-2);
2551 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
2552 Rectangle button_rect = new Rectangle(dtp.drop_down_arrow_rect.X, dtp.drop_down_arrow_rect.Y + 1,
2553 dtp.drop_down_arrow_rect.Width - 1, dtp.drop_down_arrow_rect.Height - 2);
2554 this.CPDrawComboButton (
2561 // render the date part
2562 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
2563 // fill the background
2564 Rectangle date_area_rect = new Rectangle( dtp.date_area_rect.X + 1, dtp.date_area_rect.Y + 1,
2565 dtp.date_area_rect.Width - 2, dtp.date_area_rect.Height - 2);
2566 dc.FillRectangle (ResPool.GetSolidBrush (ColorWindow), date_area_rect);
2568 // fill the currently highlighted area
2569 if (dtp.hilight_date_area != Rectangle.Empty) {
2570 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), dtp.hilight_date_area);
2573 // draw the text part
2574 // TODO: if date format is CUstom then we need to draw the dates as separate parts
2575 StringFormat text_format = new StringFormat();
2576 text_format.LineAlignment = StringAlignment.Center;
2577 text_format.Alignment = StringAlignment.Near;
2578 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
2579 text_format.Dispose ();
2582 #endregion // DateTimePicker
2584 #region MonthCalendar
2585 // draw the month calendar
2586 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2588 Rectangle client_rectangle = mc.ClientRectangle;
2589 Size month_size = mc.SingleMonthSize;
2590 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2591 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2592 Size date_cell_size = (Size)((object)mc.date_cell_size);
2594 // draw the singlecalendars
2597 // adjust for the position of the specific month
2598 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2602 y_offset += month_size.Height + calendar_spacing.Height;
2604 // now adjust for x position
2605 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2609 x_offset += month_size.Width + calendar_spacing.Width;
2616 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2617 if (month_rect.IntersectsWith (clip_rectangle)) {
2629 Rectangle bottom_rect = new Rectangle (
2631 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2632 client_rectangle.Width,
2633 date_cell_size.Height + 2);
2634 // draw the today date if it's set
2635 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2637 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
2639 int today_offset = 5;
2640 if (mc.ShowTodayCircle)
2642 Rectangle today_circle_rect = new Rectangle (
2643 client_rectangle.X + 5,
2644 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2645 date_cell_size.Width,
2646 date_cell_size.Height);
2647 DrawTodayCircle (dc, today_circle_rect);
2648 today_offset += date_cell_size.Width + 5;
2650 // draw today's date
2651 StringFormat text_format = new StringFormat();
2652 text_format.LineAlignment = StringAlignment.Center;
2653 text_format.Alignment = StringAlignment.Near;
2654 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2655 Rectangle today_rect = new Rectangle (
2656 today_offset + client_rectangle.X,
2657 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2658 Math.Max(client_rectangle.Width - today_offset, 0),
2659 date_cell_size.Height);
2660 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
2661 text_format.Dispose ();
2662 bold_font.Dispose ();
2666 // finally paint the borders of the calendars as required
2667 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2668 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2669 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
2670 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2671 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
2673 Rectangle rect = new Rectangle (
2674 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2676 calendar_spacing.Width,
2677 client_rectangle.Height);
2678 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2679 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2683 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2684 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2685 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
2686 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2687 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
2689 Rectangle rect = new Rectangle (
2691 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2692 client_rectangle.Width,
2693 calendar_spacing.Height);
2694 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2695 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2700 // draw the drop down border if need
2701 if (mc.owner != null) {
2702 Rectangle bounds = mc.ClientRectangle;
2703 if (clip_rectangle.Contains (mc.Location)) {
2704 // find out if top or left line to draw
2705 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2707 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2709 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2710 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2713 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2714 // find out if bottom or right line to draw
2715 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2716 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2718 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2719 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2725 // darws a single part of the month calendar (with one month)
2726 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2728 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2729 Size title_size = (Size)((object)mc.title_size);
2730 Size date_cell_size = (Size)((object)mc.date_cell_size);
2731 DateTime current_month = (DateTime)((object)mc.current_month);
2733 // set up some standard string formating variables
2734 StringFormat text_format = new StringFormat();
2735 text_format.LineAlignment = StringAlignment.Center;
2736 text_format.Alignment = StringAlignment.Center;
2739 // draw the title back ground
2740 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2741 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2742 if (title_rect.IntersectsWith (clip_rectangle)) {
2743 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2745 string title_text = this_month.ToString ("MMMM yyyy");
2746 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2748 // draw previous and next buttons if it's time
2749 if (row == 0 && col == 0)
2751 // draw previous button
2752 DrawMonthCalendarButton (
2758 (System.Drawing.Size)((object)mc.button_size),
2761 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2764 DrawMonthCalendarButton (
2770 (System.Drawing.Size)((object)mc.button_size),
2775 // set the week offset and draw week nums if needed
2776 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2777 Rectangle day_name_rect = new Rectangle(
2779 rectangle.Y + title_size.Height,
2780 (7 + col_offset) * date_cell_size.Width,
2781 date_cell_size.Height);
2782 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2783 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
2784 // draw the day names
2785 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2786 for (int i=0; i < 7; i++)
2788 int position = i - (int) first_day_of_week;
2791 position = 7 + position;
2794 Rectangle day_rect = new Rectangle(
2795 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2797 date_cell_size.Width,
2798 date_cell_size.Height);
2799 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2802 // draw the vertical divider
2803 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2805 ResPool.GetPen (mc.ForeColor),
2806 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2807 rectangle.Y + vert_divider_y,
2808 rectangle.Right - mc.divider_line_offset,
2809 rectangle.Y + vert_divider_y);
2813 // draw the actual date items in the grid (including the week numbers)
2814 Rectangle date_rect = new Rectangle (
2816 rectangle.Y + title_size.Height + date_cell_size.Height,
2817 date_cell_size.Width,
2818 date_cell_size.Height);
2819 int month_row_count = 0;
2820 bool draw_week_num_divider = false;
2821 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2822 for (int i=0; i < 6; i++)
2824 // establish if this row is in our clip_area
2825 Rectangle row_rect = new Rectangle (
2827 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2828 date_cell_size.Width * 7,
2829 date_cell_size.Height);
2830 if (mc.ShowWeekNumbers) {
2831 row_rect.Width += date_cell_size.Width;
2834 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2836 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
2838 // establish if this is a valid week to draw
2839 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2840 month_row_count = i;
2843 // draw the week number if required
2844 if (mc.ShowWeekNumbers && month_row_count == i) {
2845 if (!draw_week_num_divider) {
2846 draw_week_num_divider = draw_row;
2848 // get the week for this row
2849 int week = mc.GetWeekOfYear (current_date);
2855 ResPool.GetSolidBrush (mc.TitleBackColor),
2859 date_rect.Offset(date_cell_size.Width, 0);
2862 // only draw the days if we have to
2863 if(month_row_count == i) {
2864 for (int j=0; j < 7; j++)
2867 DrawMonthCalendarDate (
2878 current_date = current_date.AddDays(1);
2879 date_rect.Offset(date_cell_size.Width, 0);
2882 // shift the rectangle down one row
2883 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2884 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2888 // month_row_count is zero based, so add one
2891 // draw week numbers if required
2892 if (draw_week_num_divider) {
2895 ResPool.GetPen (mc.ForeColor),
2896 rectangle.X + date_cell_size.Width - 1,
2897 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2898 rectangle.X + date_cell_size.Width - 1,
2899 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2901 text_format.Dispose ();
2904 // draws the pervious or next button
2905 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2907 bool is_clicked = false;
2908 Rectangle button_rect;
2909 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2910 Point[] arrow_path = new Point[3];
2911 // prepare the button
2914 is_clicked = mc.is_previous_clicked;
2915 button_rect = new Rectangle (
2916 rectangle.X + 1 + x_offset,
2917 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2918 Math.Max(button_size.Width - 1, 0),
2919 Math.Max(button_size.Height - 1, 0));
2920 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2921 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2923 arrow_rect.Offset(1,1);
2925 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2926 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2927 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2931 is_clicked = mc.is_next_clicked;
2932 button_rect = new Rectangle (
2933 rectangle.Right - 1 - x_offset - button_size.Width,
2934 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2935 Math.Max(button_size.Width - 1, 0),
2936 Math.Max(button_size.Height - 1, 0));
2937 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2938 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2940 arrow_rect.Offset(1,1);
2942 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2943 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2944 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2947 // fill the background
2948 dc.FillRectangle (ResPool.GetSolidBrush(mc.TitleBackColor), button_rect);
2951 Color first_gradient_color = is_clicked ? pressed_gradient_first_color : gradient_first_color;
2952 Color second_gradient_color = is_clicked ? pressed_gradient_second_color : gradient_second_color;
2954 CL_Draw_Button (dc, button_rect, FlatStyle.Standard,
2955 false, true, is_clicked,
2956 first_gradient_color, second_gradient_color,
2960 SmoothingMode old_smooting_mode = dc.SmoothingMode;
2961 dc.SmoothingMode = SmoothingMode.AntiAlias;
2962 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2963 dc.SmoothingMode = old_smooting_mode;
2967 // draws one day in the calendar grid
2968 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2969 Color date_color = mc.ForeColor;
2970 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2972 // find out if we are the lead of the first calendar or the trail of the last calendar
2973 if (date.Year != month.Year || date.Month != month.Month) {
2974 DateTime check_date = month.AddMonths (-1);
2975 // check if it's the month before
2976 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2977 date_color = mc.TrailingForeColor;
2979 // check if it's the month after
2980 check_date = month.AddMonths (1);
2981 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2982 date_color = mc.TrailingForeColor;
2988 date_color = mc.ForeColor;
2992 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2993 // see if the date is in the start of selection
2994 date_color = mc.BackColor;
2995 // draw the left hand of the back ground
2996 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2997 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2998 } else if (date == mc.SelectionStart) {
2999 // see if the date is in the start of selection
3000 date_color = mc.BackColor;
3001 // draw the left hand of the back ground
3002 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
3003 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
3004 // fill the other side as a straight rect
3005 if (date < mc.SelectionEnd)
3007 // use rectangle instead of rectangle to go all the way to edge of rect
3008 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
3009 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
3010 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3012 } else if (date == mc.SelectionEnd) {
3013 // see if it is the end of selection
3014 date_color = mc.BackColor;
3015 // draw the left hand of the back ground
3016 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
3017 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
3018 // fill the other side as a straight rect
3019 if (date > mc.SelectionStart) {
3020 selection_rect.X = rectangle.X;
3021 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
3022 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3024 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
3025 // now see if it's in the middle
3026 date_color = mc.BackColor;
3027 // draw the left hand of the back ground
3028 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
3029 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3032 // set up some standard string formating variables
3033 StringFormat text_format = new StringFormat();
3034 text_format.LineAlignment = StringAlignment.Center;
3035 text_format.Alignment = StringAlignment.Center;
3038 // establish if it's a bolded font
3040 if (mc.IsBoldedDate (date)) {
3041 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
3046 // just draw the date now
3047 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
3049 // today circle if needed
3050 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
3051 DrawTodayCircle (dc, interior);
3054 // draw the selection grid
3055 if (mc.is_date_clicked && mc.clicked_date == date) {
3056 using (Pen pen = new Pen (Color.Black, 1) ) {
3057 pen.DashStyle = DashStyle.Dot;
3058 dc.DrawRectangle (pen, interior);
3061 text_format.Dispose ();
3064 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
3065 Color circle_color = Color.FromArgb (248, 0, 0);
3066 // draw the left hand of the circle
3067 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
3068 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
3069 Point [] curve_points = new Point [3];
3070 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
3071 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
3072 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
3074 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
3075 dc.SmoothingMode = SmoothingMode.AntiAlias;
3077 using (Pen pen = new Pen (circle_color, 2)) {
3078 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
3079 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
3080 dc.DrawCurve (pen, curve_points);
3081 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
3084 dc.SmoothingMode = old_smoothing_mode;
3086 #endregion // MonthCalendar
3088 public override void CPDrawBorder3D( Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides ) {
3089 CPDrawBorder3D( graphics, rectangle, style, sides, ColorControl );
3092 public override void CPDrawBorder3D( Graphics dc, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color ) {
3093 // currently we don't take care of Border3DStyle or Border3DSide
3095 Pen tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
3096 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 2, rectangle.Y + 1 );
3097 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 2 );
3098 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 3 );
3099 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Bottom - 3, rectangle.X + 2, rectangle.Bottom - 2 );
3101 tmp_pen = ResPool.GetPen( theme_back_color );
3102 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 2, rectangle.Right - 3, rectangle.Y + 2 );
3103 dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 3, rectangle.X + 2, rectangle.Bottom - 3 );
3105 tmp_pen = ResPool.GetPen( Color.White );
3106 dc.DrawLine( tmp_pen, rectangle.X + 3, rectangle.Bottom - 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3107 dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3110 new Point( rectangle.X + 3, rectangle.Y + 1 ),
3111 new Point( rectangle.Right - 4, rectangle.Y + 1 ),
3112 new Point( rectangle.Right - 2, rectangle.Y + 3 ),
3113 new Point( rectangle.Right - 2, rectangle.Bottom - 4 ),
3114 new Point( rectangle.Right - 4, rectangle.Bottom - 2 ),
3115 new Point( rectangle.X + 3, rectangle.Bottom - 2 ),
3116 new Point( rectangle.X + 1, rectangle.Bottom - 4 ),
3117 new Point( rectangle.X + 1, rectangle.Y + 3 ),
3118 new Point( rectangle.X + 3, rectangle.Y + 1 )
3121 dc.DrawLines( ResPool.GetPen( combobox_border_color ), points );
3123 Point[] points_top_outer = {
3124 new Point( rectangle.X + 1, rectangle.Y + 1 ),
3125 new Point( rectangle.X + 2, rectangle.Y ),
3126 new Point( rectangle.Right - 3, rectangle.Y ),
3127 new Point( rectangle.Right - 2 , rectangle.Y + 1 )
3130 Point[] points_bottom_outer = {
3131 new Point( rectangle.X + 1, rectangle.Bottom - 2 ),
3132 new Point( rectangle.X + 2, rectangle.Bottom - 1 ),
3133 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
3134 new Point( rectangle.Right - 2, rectangle.Bottom - 2 )
3138 tmp_pen = ResPool.GetPen( button_outer_border_dark_color );
3139 dc.DrawLines( tmp_pen, points_top_outer );
3140 tmp_pen = ResPool.GetPen( button_outer_border_light_color );
3141 dc.DrawLines( tmp_pen, points_bottom_outer );
3143 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 3 ), button_outer_border_dark_color, button_outer_border_light_color ) ) {
3144 using (Pen lgbrpen = new Pen (lgbr)) {
3145 dc.DrawLine (lgbrpen, rectangle.X, rectangle.Y + 2, rectangle.X, rectangle.Bottom - 3 );
3146 dc.DrawLine (lgbrpen, rectangle.Right - 1, rectangle.Y + 2, rectangle.Right - 1, rectangle.Bottom - 3 );
3150 tmp_pen = ResPool.GetPen( button_edge_top_outer_color );
3151 dc.DrawLine( tmp_pen, rectangle.X, rectangle.Y + 1, rectangle.X + 1, rectangle.Y );
3152 dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
3154 tmp_pen = ResPool.GetPen( button_edge_bottom_outer_color );
3155 dc.DrawLine( tmp_pen, rectangle.X, rectangle.Bottom - 2, rectangle.X + 1, rectangle.Bottom - 1 );
3156 dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 1 );
3159 public override void CPDrawBorder( Graphics dc, Rectangle bounds, Color leftColor, int leftWidth,
3160 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3161 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3162 int bottomWidth, ButtonBorderStyle bottomStyle ) {
3163 dc.DrawRectangle( ResPool.GetPen( combobox_border_color ), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1 );
3166 // TODO: inactive...
3167 public override void CPDrawCheckBox( Graphics dc, Rectangle rectangle, ButtonState state ) {
3169 bool pushed = ( state & ButtonState.Pushed ) != 0;
3176 dc.FillRectangle( ResPool.GetSolidBrush( pushed ? checkbox_pressed_backcolor : Color.White ), rectangle );
3179 dc.DrawRectangle( ResPool.GetPen( scrollbar_border_color ), rectangle );
3181 Color inner_border_color = pushed ? checkbox_pressed_inner_boder_color : checkbox_inner_boder_color;
3183 Pen tmp_pen = ResPool.GetPen( inner_border_color );
3184 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 1, rectangle.Y + 1 );
3185 dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 1, rectangle.Bottom - 1 );
3187 /* Make sure we've got at least a line width of 1 */
3188 lineWidth = Math.Max( 3, rectangle.Width / 6 );
3189 scale = Math.Max( 1, rectangle.Width / 12 );
3191 // define a rectangle inside the border area
3192 rect = new Rectangle( rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
3193 if ( ( state & ButtonState.Inactive ) != 0 ) {
3194 tmp_pen = SystemPens.ControlDark;
3196 tmp_pen = SystemPens.ControlText;
3199 if ( ( state & ButtonState.Checked ) != 0 ) {
3200 /* Need to draw a check-mark */
3201 for ( int i=0; i < lineWidth; i++ ) {
3202 dc.DrawLine( tmp_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * scale, rect.Top + lineWidth + 2 * scale + i );
3203 dc.DrawLine( tmp_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 );
3208 public override void CPDrawStringDisabled( Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
3209 StringFormat format ) {
3211 graphics.DrawString( s, font, ResPool.GetSolidBrush( ColorGrayText), layoutRectangle, format );
3215 public override void CPDrawButton (Graphics dc, Rectangle buttonRectangle, ButtonState state)
3217 bool is_enabled = true;
3218 FlatStyle flat_style = FlatStyle.Standard;
3219 bool is_pressed = false;
3221 if ((state & ButtonState.Pushed) != 0) {
3225 // if ((state & ButtonState.Checked)!=0) {
3226 // dfcs |= DrawFrameControlStates.Checked;
3229 if ((state & ButtonState.Flat) != 0) {
3230 flat_style = FlatStyle.Flat;
3233 if ((state & ButtonState.Inactive) != 0) {
3237 Color first_gradient_color = gradient_first_color;
3238 Color second_gradient_color = gradient_second_color;
3241 first_gradient_color = pressed_gradient_first_color;
3242 second_gradient_color = pressed_gradient_second_color;
3245 CL_Draw_Button (dc, buttonRectangle, flat_style,
3246 false, is_enabled, is_pressed,
3247 first_gradient_color, second_gradient_color,
3251 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
3253 bool is_checked = false;
3254 bool is_inactive = false;
3256 if ((state & ButtonState.Checked) != 0) {
3260 if ((state & ButtonState.Inactive) != 0) {
3264 SmoothingMode old_smooting_mode = dc.SmoothingMode;
3265 dc.SmoothingMode = SmoothingMode.AntiAlias;
3267 dc.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3269 dc.DrawArc (ResPool.GetPen (radio_button_border_circle_color), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3271 CL_Draw_RadioButton_Dot (dc, rectangle, is_checked, is_inactive);
3273 dc.SmoothingMode = old_smooting_mode;
3276 private void CL_Draw_RadioButton_Dot (Graphics dc, Rectangle rectangle, bool is_checked, bool is_inactive)
3279 int lineWidth = Math.Max (1, Math.Min (rectangle.Width, rectangle.Height) / 4);
3281 SolidBrush buttonBrush;
3284 buttonBrush = SystemBrushes.ControlDark as SolidBrush;
3286 buttonBrush = ResPool.GetSolidBrush (radio_button_dot_color);
3288 dc.FillPie (buttonBrush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
3290 // the white shiny dott
3291 buttonBrush = ResPool.GetSolidBrush (ColorWindow);
3292 dc.FillPie (buttonBrush, rectangle.X + lineWidth + lineWidth / 2, rectangle.Y + lineWidth + lineWidth / 2, (rectangle.Width - lineWidth * 2) / 3, (rectangle.Height - lineWidth * 2) / 3, 0, 359);
3297 public override void DrawToolTip (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
3299 dc.FillRectangle(ResPool.GetSolidBrush (ColorInfo), control.ClientRectangle);
3300 dc.DrawRectangle(ResPool.GetPen (info_border_color), 0, 0, control.Width-1, control.Height-1);
3302 TextFormatFlags flags = TextFormatFlags.HidePrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
3303 TextRenderer.DrawTextInternal (dc, control.Text, control.Font, control.ClientRectangle, this.ColorInfoText, flags, false);
3305 #endregion // ToolTip
3307 #region BalloonWindow
3309 NotifyIcon.BalloonWindow balloon_window;
3311 public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
3313 Control control = Control.FromHandle(handle);
3315 if (control == null)
3318 if (balloon_window != null) {
3319 balloon_window.Close ();
3320 balloon_window.Dispose ();
3323 balloon_window = new NotifyIcon.BalloonWindow (handle);
3324 balloon_window.Title = title;
3325 balloon_window.Text = text;
3326 balloon_window.Icon = icon;
3327 balloon_window.Timeout = timeout;
3328 balloon_window.Show ();
3331 private const int balloon_iconsize = 48;
3332 private const int balloon_bordersize = 8;
3334 public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control)
3336 Brush solidbrush = ResPool.GetSolidBrush(this.ColorInfoText);
3337 Rectangle rect = control.ClientRectangle;
3338 int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
3340 // Rectangle borders and background.
3341 dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
3342 dc.FillRectangle (ResPool.GetSolidBrush (info_second_color), new Rectangle (rect.X, rect.Y, (balloon_iconsize/2)+balloon_bordersize, rect.Height));
3343 dc.DrawRectangle (ResPool.GetPen (info_border_color), 0, 0, rect.Width - 1, rect.Height - 1);
3347 switch (control.Icon) {
3348 case ToolTipIcon.Info: {
3349 image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
3353 case ToolTipIcon.Warning: {
3354 image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
3358 case ToolTipIcon.Error: {
3359 image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
3369 if (control.Icon != ToolTipIcon.None)
3370 dc.DrawImage (image, new Rectangle (balloon_bordersize, (2*balloon_bordersize)+7, iconsize, iconsize));
3373 Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + (balloon_iconsize/2) + balloon_bordersize,
3374 rect.Y + balloon_bordersize,
3375 rect.Width - ((3 * balloon_bordersize) + (balloon_iconsize/2)),
3376 rect.Height - (2 * balloon_bordersize));
3378 Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
3379 dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
3382 Rectangle textrect = new Rectangle (rect.X + (2 * balloon_bordersize) + balloon_iconsize,
3383 rect.Y + balloon_bordersize,
3384 rect.Width - ((2 * balloon_bordersize) + balloon_iconsize),
3385 rect.Height - (2 * balloon_bordersize));
3387 StringFormat textformat = control.Format;
3388 textformat.LineAlignment = StringAlignment.Far;
3389 dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
3392 public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
3394 Rectangle deskrect = Screen.GetWorkingArea (control);
3395 SizeF maxsize = new SizeF (250, 200);
3397 SizeF titlesize = TextRenderer.MeasureString (control.Title, control.Font, maxsize, control.Format);
3398 SizeF textsize = TextRenderer.MeasureString (control.Text, control.Font, maxsize, control.Format);
3400 if (textsize.Height < balloon_iconsize)
3401 textsize.Height = balloon_iconsize;
3403 Rectangle rect = new Rectangle ();
3404 rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
3405 rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (3 * balloon_bordersize) + balloon_iconsize;
3406 rect.X = deskrect.Width - rect.Width - 2;
3407 rect.Y = deskrect.Height - rect.Height - 2;
3412 #endregion // BalloonWindow