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) 2004-2006 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Alexander Olk, alex.olk@googlemail.com
26 // This is an experimental GTK theme.
29 // - For now we would keep all the themes in the same assembly to have
30 // handy the internals methods.
31 // - We are using Pinovoke for now to access GTK/GDK to avoid adding
32 // gtk-sharp as a SWF dependency
33 // - The ThemeGtk comes from ThemeWin32Classic, we use it as the default
34 // implementation for the methods that we are not taking care of.
35 // - When GDK is initialised it opens its own display. There is not way of changing it,
36 // then we use that display as SWF display
37 // - You can activate this Theme in Linux doing export MONO_THEME=gtk
38 // - GTK paints controls into a window not a device context. We should inverstigate if we
39 // we can encapsulate a dc in a gtkwindow.
44 // TODO: - fix position of button focus rectangle
45 // - fix TrackBar drawing location
48 //#define _EXPERIMENTAL_
52 using System.Drawing.Drawing2D;
53 using System.Drawing.Imaging;
54 using System.Reflection;
55 using System.Runtime.InteropServices;
58 namespace System.Windows.Forms
60 internal class ThemeGtk : ThemeWin32Classic
63 internal enum StateType
72 internal enum ShadowType
81 internal enum ArrowType
90 [StructLayout(LayoutKind.Sequential)]
91 internal struct GdkColorStruct
99 [StructLayout(LayoutKind.Sequential)]
100 internal struct GObjectStruct {
101 public IntPtr Instance;
102 public IntPtr ref_count;
107 [StructLayout(LayoutKind.Sequential)]
108 internal struct GtkStyleStruct
110 internal GObjectStruct obj;
111 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
112 internal GdkColorStruct[] fg;
113 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
114 internal GdkColorStruct[] bg;
115 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
116 internal GdkColorStruct[] light;
117 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
118 internal GdkColorStruct[] dark;
119 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
120 internal GdkColorStruct[] mid;
121 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
122 internal GdkColorStruct[] text;
123 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
124 internal GdkColorStruct[] baseclr;
125 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
126 internal GdkColorStruct[] text_aa; /* Halfway between text/base */
128 internal GdkColorStruct black;
129 internal GdkColorStruct white;
131 /* TODO: There is more stuff that we will add when we need it*/
135 [DllImport("libgdk-x11-2.0.so")]
136 internal static extern IntPtr gdk_display_manager_get ();
138 [DllImport("libgdk-x11-2.0.so")]
139 internal static extern IntPtr gdk_display_manager_get_default_display (IntPtr display_manager);
141 [DllImport("libgdk-x11-2.0.so")]
142 internal static extern void gdk_display_manager_set_default_display (IntPtr display_manager, IntPtr display);
144 [DllImport("libgdk-x11-2.0.so")]
145 internal static extern IntPtr gdk_x11_display_get_xdisplay (IntPtr display);
147 [DllImport("libgdk-x11-2.0.so")]
148 static extern IntPtr gdk_window_foreign_new_for_display (IntPtr display, uint anid);
150 [DllImport("libgdk-x11-2.0.so")]
151 static extern bool gdk_init_check(IntPtr argc, IntPtr argv);
153 //[DllImport("libgdk-x11-2.0.so")]
154 //static extern IntPtr gdk_pixmap_new (IntPtr drawable, int width, int height, int depth);
156 //[DllImport("libgdk-x11-2.0.so")]
157 //static extern IntPtr gdk_pixbuf_get_from_drawable (IntPtr dest, IntPtr drawable_src, IntPtr cmap,
158 // int src_x, int src_y, int dest_x, int dest_y, int width, int height);
160 //[DllImport("libgdk-x11-2.0.so")]
161 //static extern bool gdk_pixbuf_save_to_buffer (IntPtr pixbuf, out IntPtr buffer, out UIntPtr buffer_size, string type, out IntPtr error, IntPtr option_dummy);
163 //[DllImport("libgdk-x11-2.0.so")]
164 //static extern IntPtr gdk_drawable_get_colormap (IntPtr drawable);
166 //[DllImport("libgdk-x11-2.0.so")]
167 //static extern IntPtr gdk_colormap_get_system ();
169 //[DllImport("libgdk-x11-2.0.so")]
170 //static extern IntPtr gdk_pixbuf_new (int colorspace, bool has_alpha, int bits_per_sample, int width, int height);
172 //[DllImport("libgdk-x11-2.0.so")]
173 //static extern IntPtr gdk_gc_new (IntPtr drawable);
176 //[DllImport("libglib-2.0.so")]
177 //static extern void g_free (IntPtr mem);
179 //[DllImport("libgobject-2.0.so")]
180 //static extern void g_object_unref (IntPtr nativeObject);
183 [DllImport("libgtk-x11-2.0.so")]
184 static extern bool gtk_init_check (IntPtr argc, IntPtr argv);
186 [DllImport("libgtk-x11-2.0.so")]
187 static extern IntPtr gtk_adjustment_new (double value, double lower, double upper, double step_increment, double page_increment, double page_size);
189 [DllImport("libgtk-x11-2.0.so")]
190 static extern IntPtr gtk_rc_get_style (IntPtr widget);
192 [DllImport("libgtk-x11-2.0.so")]
193 static extern IntPtr gtk_vscrollbar_new(IntPtr adjustment);
195 [DllImport("libgtk-x11-2.0.so")]
196 static extern IntPtr gtk_hscrollbar_new(IntPtr adjustment);
198 [DllImport("libgtk-x11-2.0.so")]
199 static extern IntPtr gtk_style_attach (IntPtr raw, IntPtr window);
201 //[DllImport("libgtk-x11-2.0.so")]
202 //static extern IntPtr gtk_rc_style_new ();
204 [DllImport("libgtk-x11-2.0.so")]
205 static extern IntPtr gtk_invisible_new ();
207 [DllImport("libgtk-x11-2.0.so")]
208 static extern void gtk_widget_ensure_style (IntPtr raw);
210 [DllImport("libgtk-x11-2.0.so")]
211 static extern IntPtr gtk_widget_get_style (IntPtr raw);
213 //[DllImport("libgtk-x11-2.0.so")]
214 //static extern void gtk_style_detach (IntPtr raw);
216 [DllImport("libgtk-x11-2.0.so")]
217 static extern IntPtr gtk_button_new ();
219 [DllImport("libgtk-x11-2.0.so")]
220 static extern IntPtr gtk_progress_bar_new ();
222 [DllImport("libgtk-x11-2.0.so")]
223 static extern IntPtr gtk_radio_button_new (IntPtr group);
225 [DllImport("libgtk-x11-2.0.so")]
226 static extern IntPtr gtk_check_button_new ();
228 [DllImport("libgtk-x11-2.0.so")]
229 static extern IntPtr gtk_hscale_new (IntPtr adjustment);
231 [DllImport("libgtk-x11-2.0.so")]
232 static extern IntPtr gtk_vscale_new (IntPtr adjustment);
234 [DllImport("libgtk-x11-2.0.so")]
235 static extern void gtk_range_set_range (IntPtr range, double min, double max);
237 [DllImport("libgtk-x11-2.0.so")]
238 static extern void gtk_range_set_value (IntPtr range, double value);
241 //[DllImport("libgtk-x11-2.0.so")]
242 //static extern void gtk_paint_handle (IntPtr style, IntPtr window, int state_type, int shadow_type, IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height, int orientation);
244 [DllImport("libgtk-x11-2.0.so")]
245 static extern void gtk_paint_arrow (IntPtr style, IntPtr window, int state_type, int shadow_type,
246 IntPtr area, IntPtr widget, string detail, int arrow_type, bool fill, int x, int y, int width, int height);
248 [DllImport("libgtk-x11-2.0.so")]
249 static extern void gtk_paint_slider (IntPtr style, IntPtr window, int state_type, int shadow_type,
250 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height, int orientation);
252 [DllImport("libgtk-x11-2.0.so")]
253 static extern void gtk_paint_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
254 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
256 [DllImport("libgtk-x11-2.0.so")]
257 static extern void gtk_paint_flat_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
258 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
260 //[DllImport("libgtk-x11-2.0.so")]
261 //static extern void gtk_paint_hline(IntPtr style, IntPtr window, int state_type, IntPtr area, IntPtr widget, string detail, int x1, int x2, int y);
263 //[DllImport("libgtk-x11-2.0.so")]
264 //static extern void gtk_paint_vline(IntPtr style, IntPtr window, int state_type, IntPtr area, IntPtr widget, string detail, int y1, int y2, int x);
266 [DllImport("libgtk-x11-2.0.so")]
267 static extern void gtk_paint_check(IntPtr style, IntPtr window, int state_type, int shadow_type, IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
269 [DllImport("libgtk-x11-2.0.so")]
270 static extern void gtk_paint_focus(IntPtr style, IntPtr window, int state_type, IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
272 [DllImport("libgtk-x11-2.0.so")]
273 static extern void gtk_widget_size_allocate (IntPtr widget, ref Rectangle allocation);
275 [DllImport("libgtk-x11-2.0.so")]
276 static extern void gtk_paint_option (IntPtr style, IntPtr window, int state_type, int shadow_type, IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
278 [DllImport("libgtk-x11-2.0.so")]
279 static extern void gtk_widget_grab_focus (IntPtr widget);
282 static protected IntPtr dispmgr;
283 static protected IntPtr gdkdisplay;
284 static protected IntPtr widget;
285 static protected IntPtr global_style;
288 static protected IntPtr global_color_map = IntPtr.Zero;
291 static protected IntPtr global_gtk_button = IntPtr.Zero;
292 static protected IntPtr global_gtk_button_style = IntPtr.Zero;
294 static protected IntPtr global_gtk_vscrollbar = IntPtr.Zero;
295 static protected IntPtr global_gtk_vscrollbar_style = IntPtr.Zero;
297 static protected IntPtr global_gtk_hscrollbar = IntPtr.Zero;
298 static protected IntPtr global_gtk_hscrollbar_style = IntPtr.Zero;
300 static protected IntPtr global_gtk_progress_bar = IntPtr.Zero;
301 static protected IntPtr global_gtk_progress_bar_style = IntPtr.Zero;
303 static protected IntPtr global_gtk_radio_button = IntPtr.Zero;
304 static protected IntPtr global_gtk_radio_button_style = IntPtr.Zero;
306 static protected IntPtr global_gtk_check_button = IntPtr.Zero;
307 static protected IntPtr global_gtk_check_button_style = IntPtr.Zero;
309 static protected IntPtr global_gtk_hscale = IntPtr.Zero;
310 static protected IntPtr global_gtk_hscale_style = IntPtr.Zero;
312 static protected IntPtr global_gtk_vscale = IntPtr.Zero;
313 static protected IntPtr global_gtk_vscale_style = IntPtr.Zero;
315 static protected IntPtr current_gdk_drawable = IntPtr.Zero;
316 static protected IntPtr current_style = IntPtr.Zero;
317 static protected IntPtr current_widget = IntPtr.Zero;
319 public static void InitGtk ()
321 Console.WriteLine ("ThemeGtk Init");
323 gdk_init_check (IntPtr.Zero, IntPtr.Zero);
325 dispmgr = gdk_display_manager_get ();
326 gdkdisplay = gdk_display_manager_get_default_display (dispmgr);
327 gtk_init_check (IntPtr.Zero, IntPtr.Zero);
329 widget = gtk_invisible_new ();
330 gtk_widget_ensure_style (widget);
331 global_style = gtk_widget_get_style (widget);
333 XplatUIX11.GetInstance().SetDisplay (gdk_x11_display_get_xdisplay (gdkdisplay));
335 global_gtk_button = gtk_button_new();
336 gtk_widget_ensure_style (global_gtk_button);
337 global_gtk_button_style = gtk_rc_get_style (global_gtk_button);
339 IntPtr adj = gtk_adjustment_new (0, 0, 0, 0, 0, 0);
340 global_gtk_vscrollbar = gtk_vscrollbar_new (adj);
341 gtk_widget_ensure_style (global_gtk_vscrollbar);
342 global_gtk_vscrollbar_style = gtk_rc_get_style (global_gtk_vscrollbar);
344 global_gtk_hscrollbar = gtk_hscrollbar_new (adj);
345 gtk_widget_ensure_style (global_gtk_hscrollbar);
346 global_gtk_hscrollbar_style = gtk_rc_get_style (global_gtk_hscrollbar);
348 global_gtk_progress_bar = gtk_progress_bar_new ();
349 gtk_widget_ensure_style (global_gtk_progress_bar);
350 global_gtk_progress_bar_style = gtk_rc_get_style (global_gtk_progress_bar);
352 global_gtk_radio_button = gtk_radio_button_new (IntPtr.Zero);
353 gtk_widget_ensure_style (global_gtk_radio_button);
354 global_gtk_radio_button_style = gtk_rc_get_style (global_gtk_radio_button);
356 global_gtk_check_button = gtk_check_button_new ();
357 gtk_widget_ensure_style (global_gtk_check_button);
358 global_gtk_check_button_style = gtk_rc_get_style (global_gtk_check_button);
360 global_gtk_hscale = gtk_hscale_new (adj);
361 gtk_widget_ensure_style (global_gtk_hscale);
362 global_gtk_hscale_style = gtk_rc_get_style (global_gtk_hscale);
364 global_gtk_vscale = gtk_vscale_new (adj);
365 gtk_widget_ensure_style (global_gtk_vscale);
366 global_gtk_vscale_style = gtk_rc_get_style (global_gtk_vscale);
369 global_color_map = gdk_colormap_get_system ();
373 public void LoadSysDefaultColors ()
375 GtkStyleStruct style_struct;
377 style_struct = (GtkStyleStruct) Marshal.PtrToStructure (global_style, typeof (GtkStyleStruct));
378 defaultWindowBackColor = ColorFromGdkColor (style_struct.bg[0]);
379 defaultWindowForeColor = ColorFromGdkColor (style_struct.fg[0]);
382 public ThemeGtk () : base ()
384 Console.WriteLine ("ThemeGtk constructor");
387 LoadSysDefaultColors ();
389 always_draw_hotkeys = true;
392 public override bool DoubleBufferingSupported {
400 private void SetDrawableAndStyle (Control control)
403 if (current_gdk_drawable != IntPtr.Zero) {
404 g_object_unref (current_gdk_drawable);
405 current_gdk_drawable = IntPtr.Zero;
407 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, control.ClientRectangle.Width, control.ClientRectangle.Height, 24);
409 current_gdk_drawable = gdk_window_foreign_new_for_display (gdkdisplay, (uint) control.Handle);
412 IntPtr tmp_style = IntPtr.Zero;
414 if (control is ButtonBase) {
415 tmp_style = global_gtk_button_style;
416 current_widget = global_gtk_button;
418 if (control is ScrollBar) {
419 ScrollBar bar = control as ScrollBar;
421 tmp_style = global_gtk_vscrollbar_style;
422 current_widget = global_gtk_vscrollbar;
424 tmp_style = global_gtk_hscrollbar_style;
425 current_widget = global_gtk_hscrollbar;
428 if (control is ProgressBar) {
429 tmp_style = global_gtk_progress_bar_style;
430 current_widget = global_gtk_progress_bar;
432 if (control is RadioButton) {
433 tmp_style = global_gtk_radio_button_style;
434 current_widget = global_gtk_radio_button;
436 if (control is CheckBox) {
437 tmp_style = global_gtk_check_button_style;
438 current_widget = global_gtk_check_button;
440 if (control is TrackBar) {
441 TrackBar bar = control as TrackBar;
442 if (bar.Orientation == Orientation.Vertical) {
443 tmp_style = global_gtk_vscale_style;
444 current_widget = global_gtk_vscale;
446 tmp_style = global_gtk_hscale_style;
447 current_widget = global_gtk_hscale;
450 tmp_style = global_style;
452 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
456 private void SetDrawableAndStyle (Rectangle area, Type type, Orientation orientation)
458 if (current_gdk_drawable != IntPtr.Zero) {
459 g_object_unref (current_gdk_drawable);
460 current_gdk_drawable = IntPtr.Zero;
462 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, area.Width, area.Height, 24);
464 IntPtr tmp_style = IntPtr.Zero;
466 if (type == typeof(ButtonBase)) {
467 tmp_style = global_gtk_button_style;
468 current_widget = global_gtk_button;
470 if (type == typeof(ScrollBar)) {
471 if (orientation == Orientation.Vertical) {
472 tmp_style = global_gtk_vscrollbar_style;
473 current_widget = global_gtk_vscrollbar;
475 tmp_style = global_gtk_hscrollbar_style;
476 current_widget = global_gtk_hscrollbar;
479 if (type == typeof(ProgressBar)) {
480 tmp_style = global_gtk_progress_bar_style;
481 current_widget = global_gtk_progress_bar;
483 if (type == typeof(RadioButton)) {
484 tmp_style = global_gtk_radio_button_style;
485 current_widget = global_gtk_radio_button;
487 if (type == typeof(CheckBox)) {
488 tmp_style = global_gtk_check_button_style;
489 current_widget = global_gtk_check_button;
491 if (type == typeof(TrackBar)) {
492 if (orientation == Orientation.Vertical) {
493 tmp_style = global_gtk_vscale_style;
494 current_widget = global_gtk_vscale;
496 tmp_style = global_gtk_hscale_style;
497 current_widget = global_gtk_hscale;
500 tmp_style = global_style;
502 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
507 private void DrawDrawableToDC (Graphics dc, Control control)
509 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, control.ClientRectangle.Width, control.ClientRectangle.Height);
511 gdk_pixbuf_get_from_drawable (new_pixbuf,
512 current_gdk_drawable,
521 IntPtr error = IntPtr.Zero;
523 UIntPtr buffer_size_as_ptr;
526 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
531 int buffer_size = (int) (uint) buffer_size_as_ptr;
532 byte[] result = new byte [buffer_size];
533 Marshal.Copy (buffer, result, 0, (int) buffer_size);
535 g_object_unref (new_pixbuf);
538 using (MemoryStream s = new MemoryStream (result))
539 image = Image.FromStream (s);
541 dc.DrawImage (image, control.ClientRectangle);
544 private void DrawDrawableToDC (Graphics dc, Rectangle area)
546 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, area.Width, area.Height);
548 gdk_pixbuf_get_from_drawable (new_pixbuf,
549 current_gdk_drawable,
558 IntPtr error = IntPtr.Zero;
560 UIntPtr buffer_size_as_ptr;
563 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
568 int buffer_size = (int) (uint) buffer_size_as_ptr;
569 byte[] result = new byte [buffer_size];
570 Marshal.Copy (buffer, result, 0, (int) buffer_size);
572 g_object_unref (new_pixbuf);
575 using (MemoryStream s = new MemoryStream (result))
576 image = Image.FromStream (s);
578 dc.DrawImage (image, area);
582 public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
584 SetDrawableAndStyle (button);
586 // Draw the button: fill rectangle, draw border, etc.
587 ButtonBase_DrawButton (button, dc);
589 // First, draw the image
590 if ((button.image != null) || (button.image_list != null))
591 ButtonBase_DrawImage (button, dc);
593 // Draw the focus rectangle
594 if (button.has_focus)
595 ButtonBase_DrawFocus (button, dc);
598 DrawDrawableToDC (dc, button);
602 if (button.Text != null && button.Text != String.Empty)
603 ButtonBase_DrawText (button, dc);
606 protected override void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
608 Rectangle buttonRectangle = button.ClientRectangle;
610 StateType state_type = StateType.Normal;
611 ShadowType shadow_type = button.FlatStyle == FlatStyle.Flat ? ShadowType.In : ShadowType.Out;
612 string detail = "buttondefault";
614 if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
615 ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
616 state_type = StateType.Active;
617 shadow_type = ShadowType.In;
620 if (!button.is_enabled) {
621 state_type = StateType.Insensitive;
623 if (button.is_pressed) {
624 state_type = StateType.Active;
625 shadow_type = ShadowType.In;
628 if (button.is_entered) {
629 state_type = StateType.Prelight;
633 gtk_widget_grab_focus (global_gtk_button);
635 if (button.FlatStyle == FlatStyle.Flat)
636 gtk_paint_flat_box (current_style,
637 current_gdk_drawable,
643 buttonRectangle.X, buttonRectangle.Y,
644 buttonRectangle.Width, buttonRectangle.Height);
646 if (button.FlatStyle != FlatStyle.Popup || (button.FlatStyle == FlatStyle.Popup && button.is_entered))
647 gtk_paint_box (current_style,
648 current_gdk_drawable,
654 buttonRectangle.X, buttonRectangle.Y,
655 buttonRectangle.Width, buttonRectangle.Height);
658 protected override void ButtonBase_DrawFocus (ButtonBase button, Graphics dc)
660 if (!button.is_enabled)
663 Rectangle focus_rect = new Rectangle (button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9);
665 gtk_widget_grab_focus (global_gtk_button);
667 gtk_paint_focus (current_style,
668 current_gdk_drawable,
669 (int) StateType.Active,
680 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
681 int scrollbutton_width = bar.scrollbutton_width;
682 int scrollbutton_height = bar.scrollbutton_height;
683 Rectangle first_arrow_area;
684 Rectangle second_arrow_area;
687 SetDrawableAndStyle (bar);
689 Rectangle allocation = new Rectangle (bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, bar.ClientRectangle.Height);
692 Color fix_color = bar.Parent != null ? bar.Parent.BackColor : ColorControl;
695 gtk_widget_size_allocate (global_gtk_vscrollbar, ref allocation);
698 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
699 bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, 3);
700 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
701 bar.ClientRectangle.X, bar.ClientRectangle.Bottom - 4, bar.ClientRectangle.Width, 3);
703 gtk_widget_size_allocate (global_gtk_hscrollbar, ref allocation);
706 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
707 bar.ClientRectangle.X, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
708 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
709 bar.ClientRectangle.Right - 4, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
712 thumb_pos = bar.ThumbPos;
715 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
716 bar.FirstArrowArea = first_arrow_area;
718 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
719 bar.SecondArrowArea = second_arrow_area;
721 thumb_pos.Width = bar.Width;
722 bar.ThumbPos = thumb_pos;
724 ScrollBar_Vertical_Draw_ThumbMoving_None (scrollbutton_height, bar, clip, dc);
727 if ( clip.IntersectsWith( first_arrow_area ) )
728 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
729 if ( clip.IntersectsWith( second_arrow_area ) )
730 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
732 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
733 bar.FirstArrowArea = first_arrow_area;
735 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
736 bar.SecondArrowArea = second_arrow_area;
738 thumb_pos.Height = bar.Height;
739 bar.ThumbPos = thumb_pos;
742 ScrollBar_Horizontal_Draw_ThumbMoving_None (scrollbutton_width, bar, clip, dc);
745 if ( clip.IntersectsWith( first_arrow_area ) )
746 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
747 if ( clip.IntersectsWith( second_arrow_area ) )
748 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
752 ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
755 DrawDrawableToDC (dc, bar);
759 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
761 DrawScrollBarThumb( dc, thumb_pos, bar );
764 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None (int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc)
766 Rectangle r = new Rectangle (0,
767 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
768 gtk_paint_box (current_style,
769 current_gdk_drawable,
770 (int) StateType.Active,
773 global_gtk_vscrollbar,
779 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None (int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc)
781 Rectangle r = new Rectangle (scrollbutton_width,
782 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
784 gtk_paint_box (current_style,
785 current_gdk_drawable,
786 (int) StateType.Active,
789 global_gtk_hscrollbar,
795 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
796 IntPtr gtk_scrollbar = bar.vert ? global_gtk_vscrollbar : global_gtk_hscrollbar;
798 gtk_paint_box (current_style,
799 current_gdk_drawable,
800 (int) StateType.Active,
801 (int) ShadowType.Out,
806 area.Width, area.Height);
808 #endregion // ScrollBar
811 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
813 Rectangle client_area = ctrl.client_area;
816 SetDrawableAndStyle (ctrl);
819 gtk_paint_box (current_style,
820 current_gdk_drawable,
821 (int) StateType.Normal,
824 global_gtk_progress_bar,
826 ctrl.ClientRectangle.X,
827 ctrl.ClientRectangle.Y,
828 ctrl.ClientRectangle.Width,
829 ctrl.ClientRectangle.Height);
831 // don't draw the bar if Value is = 0
835 int value = ctrl.Value;
837 if (value > ctrl.Maximum)
838 value = ctrl.Maximum;
840 if (value == ctrl.Maximum)
841 barpos_pixels = client_area.Width + 2;
843 barpos_pixels = (((value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum)) + 1;
845 gtk_paint_box (current_style,
846 current_gdk_drawable,
847 (int) StateType.Prelight,
848 (int) ShadowType.Out,
850 global_gtk_progress_bar,
852 client_area.X - 1, client_area.Y - 1,
853 barpos_pixels, client_area.Height + 2);
856 DrawDrawableToDC (dc, ctrl);
859 #endregion // ProgressBar
862 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
864 // we currently don't care for flat or popup radio buttons
865 if (radio_button.appearance == Appearance.Button) {
866 DrawButtonBase (dc, radio_button.ClientRectangle, radio_button);
868 DrawRadioButton (dc, radio_button, state, radiobutton_rectangle);
872 private void DrawRadioButton (Graphics dc, RadioButton radio_button, ButtonState state, Rectangle radiobutton_rectangle)
874 SetDrawableAndStyle (radio_button);
876 ShadowType shadow_type;
878 if (!radio_button.Enabled)
879 shadow_type = ShadowType.Out;
881 shadow_type = radio_button.Checked ? ShadowType.In : ShadowType.EtchedIn;
883 StateType state_type = StateType.Normal;
885 if (!radio_button.Enabled)
886 state_type = StateType.Insensitive;
888 if (radio_button.is_pressed)
889 state_type = StateType.Active;
891 if (radio_button.is_entered)
892 state_type = StateType.Prelight;
894 gtk_paint_option (current_style,
895 current_gdk_drawable,
899 global_gtk_radio_button,
901 radiobutton_rectangle.X,
902 radiobutton_rectangle.Y,
903 radiobutton_rectangle.Width,
904 radiobutton_rectangle.Height);
907 DrawDrawableToDC (dc, radio_button);
911 protected override void RadioButton_DrawText (RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
913 if (radio_button.Appearance != Appearance.Button)
914 base.RadioButton_DrawText (radio_button, text_rectangle, dc, text_format);
917 protected override void RadioButton_DrawFocus (RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
919 if (radio_button.Focused && radio_button.appearance != Appearance.Button) {
920 gtk_paint_focus (current_style,
921 current_gdk_drawable,
922 (int) StateType.Active,
924 global_gtk_radio_button,
928 text_rectangle.Width,
929 text_rectangle.Height);
933 DrawDrawableToDC (dc, radio_button);
936 #endregion // RadioButton
939 protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
941 // render as per normal button
942 if (checkbox.appearance == Appearance.Button) {
943 DrawButtonBase (dc, checkbox.ClientRectangle, checkbox);
945 InternalDrawCheckBox (dc, checkbox, state, checkbox_rectangle);
949 private void InternalDrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
951 SetDrawableAndStyle (checkbox);
953 ShadowType shadow_type;
955 if (!checkbox.Enabled)
956 shadow_type = ShadowType.Out;
958 shadow_type = checkbox.Checked ? ShadowType.In : ShadowType.EtchedIn;
960 StateType state_type = StateType.Normal;
962 if (!checkbox.Enabled)
963 state_type = StateType.Insensitive;
965 if (checkbox.is_pressed)
966 state_type = StateType.Active;
968 if (checkbox.is_entered)
969 state_type = StateType.Prelight;
971 gtk_paint_check (current_style,
972 current_gdk_drawable,
976 global_gtk_check_button,
978 checkbox_rectangle.X,
979 checkbox_rectangle.Y,
980 checkbox_rectangle.Width,
981 checkbox_rectangle.Height);
984 DrawDrawableToDC (dc, checkbox);
988 protected override void CheckBox_DrawText (CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
990 if (checkbox.Appearance != Appearance.Button)
991 base.CheckBox_DrawText (checkbox, text_rectangle, dc, text_format);
994 protected override void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
996 if (checkbox.Focused && checkbox.appearance != Appearance.Button) {
997 gtk_paint_focus (current_style,
998 current_gdk_drawable,
999 (int) StateType.Active,
1001 global_gtk_check_button,
1005 text_rectangle.Width,
1006 text_rectangle.Height);
1010 DrawDrawableToDC (dc, checkbox);
1013 #endregion // CheckBox
1016 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1017 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1018 float ticks, int value_pos, bool mouse_value)
1020 Point toptick_startpoint = new Point ();
1021 Point bottomtick_startpoint = new Point ();
1022 Point channel_startpoint = new Point ();
1024 float pixels_betweenticks;
1025 const int space_from_right = 8;
1026 const int space_from_left = 8;
1027 Rectangle area = tb.ClientRectangle;
1029 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1031 gtk_widget_size_allocate (current_widget, ref allocation);
1033 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1034 gtk_range_set_value (current_widget, tb.Value);
1036 ShadowType shadow_type = ShadowType.In;
1039 shadow_type = ShadowType.Out;
1041 StateType state_type = StateType.Normal;
1044 state_type = StateType.Insensitive;
1047 state_type = StateType.Prelight;
1049 switch (tb.TickStyle) {
1050 case TickStyle.BottomRight:
1051 case TickStyle.None:
1052 channel_startpoint.Y = 8;
1053 channel_startpoint.X = 9;
1054 bottomtick_startpoint.Y = 13;
1055 bottomtick_startpoint.X = 24;
1057 case TickStyle.TopLeft:
1058 channel_startpoint.Y = 8;
1059 channel_startpoint.X = 19;
1060 toptick_startpoint.Y = 13;
1061 toptick_startpoint.X = 8;
1063 case TickStyle.Both:
1064 channel_startpoint.Y = 8;
1065 channel_startpoint.X = 18;
1066 bottomtick_startpoint.Y = 13;
1067 bottomtick_startpoint.X = 32;
1068 toptick_startpoint.Y = 13;
1069 toptick_startpoint.X = 8;
1075 thumb_area.X = area.X + channel_startpoint.X;
1076 thumb_area.Y = area.Y + channel_startpoint.Y;
1077 thumb_area.Height = area.Height - space_from_right - space_from_left;
1078 thumb_area.Width = 4;
1080 pixel_len = thumb_area.Height - 11;
1081 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1083 /* Convert thumb position from mouse position to value*/
1086 if (value_pos >= channel_startpoint.Y)
1087 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
1091 if (value_pos + tb.Minimum > tb.Maximum)
1092 value_pos = tb.Maximum - tb.Minimum;
1094 tb.Value = value_pos + tb.Minimum;
1097 thumb_pos.Width = 13;
1098 thumb_pos.Height = 29;
1100 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Height / 3);
1102 if (thumb_pos.Y < channel_startpoint.Y)
1103 thumb_pos.Y = channel_startpoint.Y;
1105 if (thumb_pos.Y > thumb_area.Bottom - 29)
1106 thumb_pos.Y = thumb_area.Bottom - 29;
1109 gtk_paint_box (current_style,
1110 current_gdk_drawable,
1122 thumb_pos.X = channel_startpoint.X + 2 - thumb_pos.Width / 2;
1124 shadow_type = ShadowType.Out;
1126 gtk_paint_slider (current_style,
1127 current_gdk_drawable,
1139 pixel_len = thumb_area.Height - 11;
1140 pixels_betweenticks = pixel_len / ticks;
1143 thumb_area.X = thumb_pos.X;
1144 thumb_area.Y = channel_startpoint.Y;
1145 thumb_area.Width = thumb_pos.Width;
1147 Region outside = new Region (area);
1148 outside.Exclude (thumb_area);
1150 if (outside.IsVisible (clip_rectangle)) {
1151 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1152 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1154 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1155 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1156 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
1157 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
1159 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
1160 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
1164 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1165 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1167 pixel_len = thumb_area.Height - 11;
1168 pixels_betweenticks = pixel_len / ticks;
1170 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1171 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1172 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
1173 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1175 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
1176 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1184 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1185 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1186 float ticks, int value_pos, bool mouse_value)
1188 Point toptick_startpoint = new Point ();
1189 Point bottomtick_startpoint = new Point ();
1190 Point channel_startpoint = new Point ();
1192 float pixels_betweenticks;
1193 const int space_from_right = 8;
1194 const int space_from_left = 8;
1195 Rectangle area = tb.ClientRectangle;
1197 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1199 gtk_widget_size_allocate (current_widget, ref allocation);
1201 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1202 gtk_range_set_value (current_widget, tb.Value);
1204 ShadowType shadow_type = ShadowType.In;
1207 shadow_type = ShadowType.Out;
1209 StateType state_type = StateType.Normal;
1212 state_type = StateType.Insensitive;
1215 state_type = StateType.Prelight;
1217 switch (tb.TickStyle) {
1218 case TickStyle.BottomRight:
1219 case TickStyle.None:
1220 channel_startpoint.X = 8;
1221 channel_startpoint.Y = 9;
1222 bottomtick_startpoint.X = 13;
1223 bottomtick_startpoint.Y = 24;
1225 case TickStyle.TopLeft:
1226 channel_startpoint.X = 8;
1227 channel_startpoint.Y = 19;
1228 toptick_startpoint.X = 13;
1229 toptick_startpoint.Y = 8;
1231 case TickStyle.Both:
1232 channel_startpoint.X = 8;
1233 channel_startpoint.Y = 18;
1234 bottomtick_startpoint.X = 13;
1235 bottomtick_startpoint.Y = 32;
1236 toptick_startpoint.X = 13;
1237 toptick_startpoint.Y = 8;
1243 thumb_area.X = area.X + channel_startpoint.X;
1244 thumb_area.Y = area.Y + channel_startpoint.Y;
1245 thumb_area.Width = area.Width - space_from_right - space_from_left;
1246 thumb_area.Height = 4;
1248 pixel_len = thumb_area.Width - 11;
1249 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1251 /* Convert thumb position from mouse position to value*/
1253 if (value_pos >= channel_startpoint.X)
1254 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
1258 if (value_pos + tb.Minimum > tb.Maximum)
1259 value_pos = tb.Maximum - tb.Minimum;
1261 tb.Value = value_pos + tb.Minimum;
1264 thumb_pos.Width = 29;
1265 thumb_pos.Height = 13;
1267 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Width / 3);
1270 if (thumb_pos.X < channel_startpoint.X)
1271 thumb_pos.X = channel_startpoint.X;
1273 if (thumb_pos.X > thumb_area.Right - 29)
1274 thumb_pos.X = thumb_area.Right - 29;
1277 gtk_paint_box (current_style,
1278 current_gdk_drawable,
1291 thumb_pos.Y = channel_startpoint.Y + 2 - thumb_pos.Height / 2;
1293 shadow_type = ShadowType.Out;
1295 gtk_paint_slider (current_style,
1296 current_gdk_drawable,
1308 pixel_len = thumb_area.Width - 11;
1309 pixels_betweenticks = pixel_len / ticks;
1312 thumb_area.Y = thumb_pos.Y;
1313 thumb_area.X = channel_startpoint.X;
1314 thumb_area.Height = thumb_pos.Height;
1315 Region outside = new Region (area);
1316 outside.Exclude (thumb_area);
1318 if (outside.IsVisible (clip_rectangle)) {
1319 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1320 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1322 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1323 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1324 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
1325 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
1327 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
1328 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
1332 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1333 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1335 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1336 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1337 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
1338 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
1340 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
1341 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y);
1349 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
1353 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
1355 Rectangle thumb_pos = tb.ThumbPos;
1356 Rectangle thumb_area = tb.ThumbArea;
1358 if (tb.thumb_pressed) {
1359 value_pos = tb.thumb_mouseclick;
1362 value_pos = tb.Value - tb.Minimum;
1363 mouse_value = false;
1366 area = tb.ClientRectangle;
1368 SetDrawableAndStyle (tb);
1370 /* Control Background */
1371 if (tb.BackColor == DefaultControlBackColor) {
1372 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
1374 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
1377 if (tb.Orientation == Orientation.Vertical) {
1378 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1379 ticks, value_pos, mouse_value);
1382 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1383 ticks, value_pos, mouse_value);
1386 if (tb.Enabled && tb.Focused)
1387 gtk_paint_focus (current_style,
1388 current_gdk_drawable,
1389 (int)StateType.Normal,
1398 tb.ThumbPos = thumb_pos;
1399 tb.ThumbArea = thumb_area;
1402 DrawDrawableToDC (dc, tb);
1405 #endregion // TrackBar
1407 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
1410 SetDrawableAndStyle (rectangle, typeof(ButtonBase), Orientation.Horizontal);
1413 bool is_pushed = false;
1414 // bool is_checked = false;
1415 // bool is_flat = false;
1416 bool is_inactive = false;
1418 if ((state & ButtonState.Pushed) != 0) {
1422 // if ((state & ButtonState.Checked) != 0) {
1423 // is_checked = true;
1426 // if ((state & ButtonState.Flat) != 0) {
1430 if ((state & ButtonState.Inactive) != 0) {
1434 IntPtr drawbutton_style = gtk_style_attach (global_gtk_button_style, current_gdk_drawable); // need it
1436 StateType state_type = StateType.Normal;
1437 ShadowType shadow_type = ShadowType.Out;
1438 string detail = "buttondefault";
1441 state_type = StateType.Insensitive;
1444 state_type = StateType.Active;
1445 shadow_type = ShadowType.In;
1449 gtk_paint_box (drawbutton_style, current_gdk_drawable,
1455 rectangle.X, rectangle.Y,
1456 rectangle.Width, rectangle.Height);
1459 DrawDrawableToDC (dc, rectangle);
1463 /* Scroll button: regular button + direction arrow */
1464 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state)
1467 Orientation orientation = Orientation.Vertical;
1468 if (scroll_button_type == ScrollButton.Left || scroll_button_type == ScrollButton.Right)
1469 orientation = Orientation.Horizontal;
1470 SetDrawableAndStyle (area, typeof(ScrollBar), orientation);
1473 bool enabled = (state == ButtonState.Inactive) ? false: true;
1475 StateType state_type = enabled ? StateType.Normal : StateType.Insensitive;
1477 DrawScrollButtonPrimitive (dc, area, state, scroll_button_type);
1479 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
1482 ArrowType arrow_type = 0;
1484 switch (scroll_button_type) {
1485 case ScrollButton.Up:
1486 arrow_type = ArrowType.Up;
1488 case ScrollButton.Down:
1489 arrow_type = ArrowType.Down;
1491 case ScrollButton.Right:
1492 arrow_type = ArrowType.Right;
1494 case ScrollButton.Left:
1495 arrow_type = ArrowType.Left;
1501 int centerX = area.Left + area.Width / 2;
1502 int centerY = area.Top + area.Height / 2;
1503 int arrow_x = 0, arrow_y = 0, arrow_height = 0, arrow_width = 0;
1505 switch (scroll_button_type) {
1506 case ScrollButton.Down:
1507 case ScrollButton.Up:
1508 arrow_x = centerX - 4;
1509 arrow_y = centerY - 2;
1513 case ScrollButton.Left:
1514 case ScrollButton.Right:
1515 arrow_x = centerX - 2;
1516 arrow_y = centerY - 4;
1524 gtk_paint_arrow (current_style,
1525 current_gdk_drawable,
1527 (int) ShadowType.Out,
1531 (int) arrow_type, true,
1534 arrow_width, arrow_height);
1536 current_widget = IntPtr.Zero;
1539 DrawDrawableToDC (dc, area);
1543 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type)
1545 StateType state_type = StateType.Normal;
1546 ShadowType shadow_type = ShadowType.Out;
1548 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
1549 state_type = StateType.Active;
1550 shadow_type = ShadowType.In;
1553 switch (scroll_button_type) {
1554 case ScrollButton.Left:
1555 case ScrollButton.Right:
1556 gtk_paint_box (current_style,
1557 current_gdk_drawable,
1561 global_gtk_hscrollbar,
1564 area.Width, area.Height);
1566 case ScrollButton.Up:
1567 case ScrollButton.Down:
1568 gtk_paint_box (current_style,
1569 current_gdk_drawable,
1573 global_gtk_vscrollbar,
1576 area.Width, area.Height);
1581 private static Color ColorFromGdkColor (GdkColorStruct gtkcolor)
1583 return Color.FromArgb (255,
1584 (gtkcolor.red >> 8) & 0xff,
1585 (gtkcolor.green >> 8) & 0xff,
1586 (gtkcolor.blue >> 8) & 0xff );