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 {
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");
386 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
388 LoadSysDefaultColors ();
390 always_draw_hotkeys = true;
393 public override bool DoubleBufferingSupported {
401 private void SetDrawableAndStyle (Control control)
404 if (current_gdk_drawable != IntPtr.Zero) {
405 g_object_unref (current_gdk_drawable);
406 current_gdk_drawable = IntPtr.Zero;
408 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, control.ClientRectangle.Width, control.ClientRectangle.Height, 24);
410 current_gdk_drawable = gdk_window_foreign_new_for_display (gdkdisplay, (uint) control.Handle);
413 IntPtr tmp_style = IntPtr.Zero;
415 if (control is ButtonBase) {
416 tmp_style = global_gtk_button_style;
417 current_widget = global_gtk_button;
419 if (control is ScrollBar) {
420 ScrollBar bar = control as ScrollBar;
422 tmp_style = global_gtk_vscrollbar_style;
423 current_widget = global_gtk_vscrollbar;
425 tmp_style = global_gtk_hscrollbar_style;
426 current_widget = global_gtk_hscrollbar;
429 if (control is ProgressBar) {
430 tmp_style = global_gtk_progress_bar_style;
431 current_widget = global_gtk_progress_bar;
433 if (control is RadioButton) {
434 tmp_style = global_gtk_radio_button_style;
435 current_widget = global_gtk_radio_button;
437 if (control is CheckBox) {
438 tmp_style = global_gtk_check_button_style;
439 current_widget = global_gtk_check_button;
441 if (control is TrackBar) {
442 TrackBar bar = control as TrackBar;
443 if (bar.Orientation == Orientation.Vertical) {
444 tmp_style = global_gtk_vscale_style;
445 current_widget = global_gtk_vscale;
447 tmp_style = global_gtk_hscale_style;
448 current_widget = global_gtk_hscale;
451 tmp_style = global_style;
453 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
457 private void SetDrawableAndStyle (Rectangle area, Type type, Orientation orientation)
459 if (current_gdk_drawable != IntPtr.Zero) {
460 g_object_unref (current_gdk_drawable);
461 current_gdk_drawable = IntPtr.Zero;
463 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, area.Width, area.Height, 24);
465 IntPtr tmp_style = IntPtr.Zero;
467 if (type == typeof(ButtonBase)) {
468 tmp_style = global_gtk_button_style;
469 current_widget = global_gtk_button;
471 if (type == typeof(ScrollBar)) {
472 if (orientation == Orientation.Vertical) {
473 tmp_style = global_gtk_vscrollbar_style;
474 current_widget = global_gtk_vscrollbar;
476 tmp_style = global_gtk_hscrollbar_style;
477 current_widget = global_gtk_hscrollbar;
480 if (type == typeof(ProgressBar)) {
481 tmp_style = global_gtk_progress_bar_style;
482 current_widget = global_gtk_progress_bar;
484 if (type == typeof(RadioButton)) {
485 tmp_style = global_gtk_radio_button_style;
486 current_widget = global_gtk_radio_button;
488 if (type == typeof(CheckBox)) {
489 tmp_style = global_gtk_check_button_style;
490 current_widget = global_gtk_check_button;
492 if (type == typeof(TrackBar)) {
493 if (orientation == Orientation.Vertical) {
494 tmp_style = global_gtk_vscale_style;
495 current_widget = global_gtk_vscale;
497 tmp_style = global_gtk_hscale_style;
498 current_widget = global_gtk_hscale;
501 tmp_style = global_style;
503 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
508 private void DrawDrawableToDC (Graphics dc, Control control)
510 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, control.ClientRectangle.Width, control.ClientRectangle.Height);
512 gdk_pixbuf_get_from_drawable (new_pixbuf,
513 current_gdk_drawable,
522 IntPtr error = IntPtr.Zero;
524 UIntPtr buffer_size_as_ptr;
527 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
532 int buffer_size = (int) (uint) buffer_size_as_ptr;
533 byte[] result = new byte [buffer_size];
534 Marshal.Copy (buffer, result, 0, (int) buffer_size);
536 g_object_unref (new_pixbuf);
539 using (MemoryStream s = new MemoryStream (result))
540 image = Image.FromStream (s);
542 dc.DrawImage (image, control.ClientRectangle);
545 private void DrawDrawableToDC (Graphics dc, Rectangle area)
547 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, area.Width, area.Height);
549 gdk_pixbuf_get_from_drawable (new_pixbuf,
550 current_gdk_drawable,
559 IntPtr error = IntPtr.Zero;
561 UIntPtr buffer_size_as_ptr;
564 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
569 int buffer_size = (int) (uint) buffer_size_as_ptr;
570 byte[] result = new byte [buffer_size];
571 Marshal.Copy (buffer, result, 0, (int) buffer_size);
573 g_object_unref (new_pixbuf);
576 using (MemoryStream s = new MemoryStream (result))
577 image = Image.FromStream (s);
579 dc.DrawImage (image, area);
583 public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
585 SetDrawableAndStyle (button);
587 // Draw the button: fill rectangle, draw border, etc.
588 ButtonBase_DrawButton (button, dc);
590 // First, draw the image
591 if ((button.image != null) || (button.image_list != null))
592 ButtonBase_DrawImage (button, dc);
594 // Draw the focus rectangle
595 if (button.has_focus)
596 ButtonBase_DrawFocus (button, dc);
599 DrawDrawableToDC (dc, button);
603 if (button.text != null && button.text != String.Empty)
604 ButtonBase_DrawText (button, dc);
607 protected override void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
609 Rectangle buttonRectangle = button.ClientRectangle;
611 StateType state_type = StateType.Normal;
612 ShadowType shadow_type = button.flat_style == FlatStyle.Flat ? ShadowType.In : ShadowType.Out;
613 string detail = "buttondefault";
615 if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
616 ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
617 state_type = StateType.Active;
618 shadow_type = ShadowType.In;
621 if (!button.is_enabled) {
622 state_type = StateType.Insensitive;
624 if (button.is_pressed) {
625 state_type = StateType.Active;
626 shadow_type = ShadowType.In;
629 if (button.is_entered) {
630 state_type = StateType.Prelight;
634 gtk_widget_grab_focus (global_gtk_button);
636 if (button.flat_style == FlatStyle.Flat)
637 gtk_paint_flat_box (current_style,
638 current_gdk_drawable,
644 buttonRectangle.X, buttonRectangle.Y,
645 buttonRectangle.Width, buttonRectangle.Height);
647 if (button.flat_style != FlatStyle.Popup || (button.flat_style == FlatStyle.Popup && button.is_entered))
648 gtk_paint_box (current_style,
649 current_gdk_drawable,
655 buttonRectangle.X, buttonRectangle.Y,
656 buttonRectangle.Width, buttonRectangle.Height);
659 protected override void ButtonBase_DrawFocus (ButtonBase button, Graphics dc)
661 if (!button.is_enabled)
664 Rectangle focus_rect = new Rectangle (button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9);
666 gtk_widget_grab_focus (global_gtk_button);
668 gtk_paint_focus (current_style,
669 current_gdk_drawable,
670 (int) StateType.Active,
681 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
682 int scrollbutton_width = bar.scrollbutton_width;
683 int scrollbutton_height = bar.scrollbutton_height;
684 Rectangle first_arrow_area;
685 Rectangle second_arrow_area;
688 SetDrawableAndStyle (bar);
690 Rectangle allocation = new Rectangle (bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, bar.ClientRectangle.Height);
693 Color fix_color = bar.Parent != null ? bar.Parent.BackColor : ColorControl;
696 gtk_widget_size_allocate (global_gtk_vscrollbar, ref allocation);
699 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
700 bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, 3);
701 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
702 bar.ClientRectangle.X, bar.ClientRectangle.Bottom - 4, bar.ClientRectangle.Width, 3);
704 gtk_widget_size_allocate (global_gtk_hscrollbar, ref allocation);
707 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
708 bar.ClientRectangle.X, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
709 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
710 bar.ClientRectangle.Right - 4, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
713 thumb_pos = bar.ThumbPos;
716 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
717 bar.FirstArrowArea = first_arrow_area;
719 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
720 bar.SecondArrowArea = second_arrow_area;
722 thumb_pos.Width = bar.Width;
723 bar.ThumbPos = thumb_pos;
725 ScrollBar_Vertical_Draw_ThumbMoving_None (scrollbutton_height, bar, clip, dc);
728 if ( clip.IntersectsWith( first_arrow_area ) )
729 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
730 if ( clip.IntersectsWith( second_arrow_area ) )
731 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
733 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
734 bar.FirstArrowArea = first_arrow_area;
736 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
737 bar.SecondArrowArea = second_arrow_area;
739 thumb_pos.Height = bar.Height;
740 bar.ThumbPos = thumb_pos;
743 ScrollBar_Horizontal_Draw_ThumbMoving_None (scrollbutton_width, bar, clip, dc);
746 if ( clip.IntersectsWith( first_arrow_area ) )
747 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
748 if ( clip.IntersectsWith( second_arrow_area ) )
749 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
753 ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
756 DrawDrawableToDC (dc, bar);
760 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
762 DrawScrollBarThumb( dc, thumb_pos, bar );
765 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None (int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc)
767 Rectangle r = new Rectangle (0,
768 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
769 gtk_paint_box (current_style,
770 current_gdk_drawable,
771 (int) StateType.Active,
774 global_gtk_vscrollbar,
780 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None (int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc)
782 Rectangle r = new Rectangle (scrollbutton_width,
783 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
785 gtk_paint_box (current_style,
786 current_gdk_drawable,
787 (int) StateType.Active,
790 global_gtk_hscrollbar,
796 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
797 IntPtr gtk_scrollbar = bar.vert ? global_gtk_vscrollbar : global_gtk_hscrollbar;
799 gtk_paint_box (current_style,
800 current_gdk_drawable,
801 (int) StateType.Active,
802 (int) ShadowType.Out,
807 area.Width, area.Height);
809 #endregion // ScrollBar
812 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
814 Rectangle client_area = ctrl.client_area;
817 SetDrawableAndStyle (ctrl);
820 gtk_paint_box (current_style,
821 current_gdk_drawable,
822 (int) StateType.Normal,
825 global_gtk_progress_bar,
827 ctrl.ClientRectangle.X,
828 ctrl.ClientRectangle.Y,
829 ctrl.ClientRectangle.Width,
830 ctrl.ClientRectangle.Height);
832 // don't draw the bar if Value is = 0
836 int value = ctrl.Value;
838 if (value > ctrl.Maximum)
839 value = ctrl.Maximum;
841 if (value == ctrl.Maximum)
842 barpos_pixels = client_area.Width + 2;
844 barpos_pixels = (((value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum)) + 1;
846 gtk_paint_box (current_style,
847 current_gdk_drawable,
848 (int) StateType.Prelight,
849 (int) ShadowType.Out,
851 global_gtk_progress_bar,
853 client_area.X - 1, client_area.Y - 1,
854 barpos_pixels, client_area.Height + 2);
857 DrawDrawableToDC (dc, ctrl);
860 #endregion // ProgressBar
863 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
865 // we currently don't care for flat or popup radio buttons
866 if (radio_button.appearance == Appearance.Button) {
867 DrawButtonBase (dc, radio_button.ClientRectangle, radio_button);
869 DrawRadioButton (dc, radio_button, state, radiobutton_rectangle);
873 private void DrawRadioButton (Graphics dc, RadioButton radio_button, ButtonState state, Rectangle radiobutton_rectangle)
875 SetDrawableAndStyle (radio_button);
877 ShadowType shadow_type;
879 if (!radio_button.Enabled)
880 shadow_type = ShadowType.Out;
882 shadow_type = radio_button.Checked ? ShadowType.In : ShadowType.EtchedIn;
884 StateType state_type = StateType.Normal;
886 if (!radio_button.Enabled)
887 state_type = StateType.Insensitive;
889 if (radio_button.is_pressed)
890 state_type = StateType.Active;
892 if (radio_button.is_entered)
893 state_type = StateType.Prelight;
895 gtk_paint_option (current_style,
896 current_gdk_drawable,
900 global_gtk_radio_button,
902 radiobutton_rectangle.X,
903 radiobutton_rectangle.Y,
904 radiobutton_rectangle.Width,
905 radiobutton_rectangle.Height);
908 DrawDrawableToDC (dc, radio_button);
912 protected override void RadioButton_DrawText (RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
914 if (radio_button.Appearance != Appearance.Button)
915 base.RadioButton_DrawText (radio_button, text_rectangle, dc, text_format);
918 protected override void RadioButton_DrawFocus (RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
920 if (radio_button.Focused && radio_button.appearance != Appearance.Button) {
921 gtk_paint_focus (current_style,
922 current_gdk_drawable,
923 (int) StateType.Active,
925 global_gtk_radio_button,
929 text_rectangle.Width,
930 text_rectangle.Height);
934 DrawDrawableToDC (dc, radio_button);
937 #endregion // RadioButton
940 protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
942 // render as per normal button
943 if (checkbox.appearance == Appearance.Button) {
944 DrawButtonBase (dc, checkbox.ClientRectangle, checkbox);
946 InternalDrawCheckBox (dc, checkbox, state, checkbox_rectangle);
950 private void InternalDrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
952 SetDrawableAndStyle (checkbox);
954 ShadowType shadow_type;
956 if (!checkbox.Enabled)
957 shadow_type = ShadowType.Out;
959 shadow_type = checkbox.Checked ? ShadowType.In : ShadowType.EtchedIn;
961 StateType state_type = StateType.Normal;
963 if (!checkbox.Enabled)
964 state_type = StateType.Insensitive;
966 if (checkbox.is_pressed)
967 state_type = StateType.Active;
969 if (checkbox.is_entered)
970 state_type = StateType.Prelight;
972 gtk_paint_check (current_style,
973 current_gdk_drawable,
977 global_gtk_check_button,
979 checkbox_rectangle.X,
980 checkbox_rectangle.Y,
981 checkbox_rectangle.Width,
982 checkbox_rectangle.Height);
985 DrawDrawableToDC (dc, checkbox);
989 protected override void CheckBox_DrawText (CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
991 if (checkbox.Appearance != Appearance.Button)
992 base.CheckBox_DrawText (checkbox, text_rectangle, dc, text_format);
995 protected override void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
997 if (checkbox.Focused && checkbox.appearance != Appearance.Button) {
998 gtk_paint_focus (current_style,
999 current_gdk_drawable,
1000 (int) StateType.Active,
1002 global_gtk_check_button,
1006 text_rectangle.Width,
1007 text_rectangle.Height);
1011 DrawDrawableToDC (dc, checkbox);
1014 #endregion // CheckBox
1017 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1018 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1019 float ticks, int value_pos, bool mouse_value)
1021 Point toptick_startpoint = new Point ();
1022 Point bottomtick_startpoint = new Point ();
1023 Point channel_startpoint = new Point ();
1025 float pixels_betweenticks;
1026 const int space_from_right = 8;
1027 const int space_from_left = 8;
1028 Rectangle area = tb.ClientRectangle;
1030 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1032 gtk_widget_size_allocate (current_widget, ref allocation);
1034 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1035 gtk_range_set_value (current_widget, tb.Value);
1037 ShadowType shadow_type = ShadowType.In;
1040 shadow_type = ShadowType.Out;
1042 StateType state_type = StateType.Normal;
1045 state_type = StateType.Insensitive;
1048 state_type = StateType.Prelight;
1050 switch (tb.TickStyle) {
1051 case TickStyle.BottomRight:
1052 case TickStyle.None:
1053 channel_startpoint.Y = 8;
1054 channel_startpoint.X = 9;
1055 bottomtick_startpoint.Y = 13;
1056 bottomtick_startpoint.X = 24;
1058 case TickStyle.TopLeft:
1059 channel_startpoint.Y = 8;
1060 channel_startpoint.X = 19;
1061 toptick_startpoint.Y = 13;
1062 toptick_startpoint.X = 8;
1064 case TickStyle.Both:
1065 channel_startpoint.Y = 8;
1066 channel_startpoint.X = 18;
1067 bottomtick_startpoint.Y = 13;
1068 bottomtick_startpoint.X = 32;
1069 toptick_startpoint.Y = 13;
1070 toptick_startpoint.X = 8;
1076 thumb_area.X = area.X + channel_startpoint.X;
1077 thumb_area.Y = area.Y + channel_startpoint.Y;
1078 thumb_area.Height = area.Height - space_from_right - space_from_left;
1079 thumb_area.Width = 4;
1081 pixel_len = thumb_area.Height - 11;
1082 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1084 /* Convert thumb position from mouse position to value*/
1087 if (value_pos >= channel_startpoint.Y)
1088 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
1092 if (value_pos + tb.Minimum > tb.Maximum)
1093 value_pos = tb.Maximum - tb.Minimum;
1095 tb.Value = value_pos + tb.Minimum;
1098 thumb_pos.Width = 13;
1099 thumb_pos.Height = 29;
1101 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Height / 3);
1103 if (thumb_pos.Y < channel_startpoint.Y)
1104 thumb_pos.Y = channel_startpoint.Y;
1106 if (thumb_pos.Y > thumb_area.Bottom - 29)
1107 thumb_pos.Y = thumb_area.Bottom - 29;
1110 gtk_paint_box (current_style,
1111 current_gdk_drawable,
1123 thumb_pos.X = channel_startpoint.X + 2 - thumb_pos.Width / 2;
1125 shadow_type = ShadowType.Out;
1127 gtk_paint_slider (current_style,
1128 current_gdk_drawable,
1140 pixel_len = thumb_area.Height - 11;
1141 pixels_betweenticks = pixel_len / ticks;
1144 thumb_area.X = thumb_pos.X;
1145 thumb_area.Y = channel_startpoint.Y;
1146 thumb_area.Width = thumb_pos.Width;
1148 Region outside = new Region (area);
1149 outside.Exclude (thumb_area);
1151 if (outside.IsVisible (clip_rectangle)) {
1152 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1153 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1155 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1156 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1157 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
1158 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
1160 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
1161 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
1165 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1166 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1168 pixel_len = thumb_area.Height - 11;
1169 pixels_betweenticks = pixel_len / ticks;
1171 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1172 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1173 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
1174 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1176 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
1177 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1185 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1186 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1187 float ticks, int value_pos, bool mouse_value)
1189 Point toptick_startpoint = new Point ();
1190 Point bottomtick_startpoint = new Point ();
1191 Point channel_startpoint = new Point ();
1193 float pixels_betweenticks;
1194 const int space_from_right = 8;
1195 const int space_from_left = 8;
1196 Rectangle area = tb.ClientRectangle;
1198 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1200 gtk_widget_size_allocate (current_widget, ref allocation);
1202 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1203 gtk_range_set_value (current_widget, tb.Value);
1205 ShadowType shadow_type = ShadowType.In;
1208 shadow_type = ShadowType.Out;
1210 StateType state_type = StateType.Normal;
1213 state_type = StateType.Insensitive;
1216 state_type = StateType.Prelight;
1218 switch (tb.TickStyle) {
1219 case TickStyle.BottomRight:
1220 case TickStyle.None:
1221 channel_startpoint.X = 8;
1222 channel_startpoint.Y = 9;
1223 bottomtick_startpoint.X = 13;
1224 bottomtick_startpoint.Y = 24;
1226 case TickStyle.TopLeft:
1227 channel_startpoint.X = 8;
1228 channel_startpoint.Y = 19;
1229 toptick_startpoint.X = 13;
1230 toptick_startpoint.Y = 8;
1232 case TickStyle.Both:
1233 channel_startpoint.X = 8;
1234 channel_startpoint.Y = 18;
1235 bottomtick_startpoint.X = 13;
1236 bottomtick_startpoint.Y = 32;
1237 toptick_startpoint.X = 13;
1238 toptick_startpoint.Y = 8;
1244 thumb_area.X = area.X + channel_startpoint.X;
1245 thumb_area.Y = area.Y + channel_startpoint.Y;
1246 thumb_area.Width = area.Width - space_from_right - space_from_left;
1247 thumb_area.Height = 4;
1249 pixel_len = thumb_area.Width - 11;
1250 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1252 /* Convert thumb position from mouse position to value*/
1254 if (value_pos >= channel_startpoint.X)
1255 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
1259 if (value_pos + tb.Minimum > tb.Maximum)
1260 value_pos = tb.Maximum - tb.Minimum;
1262 tb.Value = value_pos + tb.Minimum;
1265 thumb_pos.Width = 29;
1266 thumb_pos.Height = 13;
1268 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Width / 3);
1271 if (thumb_pos.X < channel_startpoint.X)
1272 thumb_pos.X = channel_startpoint.X;
1274 if (thumb_pos.X > thumb_area.Right - 29)
1275 thumb_pos.X = thumb_area.Right - 29;
1278 gtk_paint_box (current_style,
1279 current_gdk_drawable,
1292 thumb_pos.Y = channel_startpoint.Y + 2 - thumb_pos.Height / 2;
1294 shadow_type = ShadowType.Out;
1296 gtk_paint_slider (current_style,
1297 current_gdk_drawable,
1309 pixel_len = thumb_area.Width - 11;
1310 pixels_betweenticks = pixel_len / ticks;
1313 thumb_area.Y = thumb_pos.Y;
1314 thumb_area.X = channel_startpoint.X;
1315 thumb_area.Height = thumb_pos.Height;
1316 Region outside = new Region (area);
1317 outside.Exclude (thumb_area);
1319 if (outside.IsVisible (clip_rectangle)) {
1320 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1321 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1323 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1324 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1325 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
1326 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
1328 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
1329 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
1333 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1334 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1336 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1337 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1338 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
1339 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
1341 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
1342 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y);
1350 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
1354 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
1356 Rectangle thumb_pos = tb.ThumbPos;
1357 Rectangle thumb_area = tb.ThumbArea;
1359 if (tb.thumb_pressed) {
1360 value_pos = tb.thumb_mouseclick;
1363 value_pos = tb.Value - tb.Minimum;
1364 mouse_value = false;
1367 area = tb.ClientRectangle;
1369 SetDrawableAndStyle (tb);
1371 /* Control Background */
1372 if (tb.BackColor == DefaultControlBackColor) {
1373 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
1375 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
1378 if (tb.Orientation == Orientation.Vertical) {
1379 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1380 ticks, value_pos, mouse_value);
1383 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1384 ticks, value_pos, mouse_value);
1387 if (tb.Enabled && tb.Focused)
1388 gtk_paint_focus (current_style,
1389 current_gdk_drawable,
1390 (int)StateType.Normal,
1399 tb.ThumbPos = thumb_pos;
1400 tb.ThumbArea = thumb_area;
1403 DrawDrawableToDC (dc, tb);
1406 #endregion // TrackBar
1408 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
1411 SetDrawableAndStyle (rectangle, typeof(ButtonBase), Orientation.Horizontal);
1414 bool is_pushed = false;
1415 // bool is_checked = false;
1416 // bool is_flat = false;
1417 bool is_inactive = false;
1419 if ((state & ButtonState.Pushed) != 0) {
1423 // if ((state & ButtonState.Checked) != 0) {
1424 // is_checked = true;
1427 // if ((state & ButtonState.Flat) != 0) {
1431 if ((state & ButtonState.Inactive) != 0) {
1435 IntPtr drawbutton_style = gtk_style_attach (global_gtk_button_style, current_gdk_drawable); // need it
1437 StateType state_type = StateType.Normal;
1438 ShadowType shadow_type = ShadowType.Out;
1439 string detail = "buttondefault";
1442 state_type = StateType.Insensitive;
1445 state_type = StateType.Active;
1446 shadow_type = ShadowType.In;
1450 gtk_paint_box (drawbutton_style, current_gdk_drawable,
1456 rectangle.X, rectangle.Y,
1457 rectangle.Width, rectangle.Height);
1460 DrawDrawableToDC (dc, rectangle);
1464 /* Scroll button: regular button + direction arrow */
1465 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state)
1468 Orientation orientation = Orientation.Vertical;
1469 if (scroll_button_type == ScrollButton.Left || scroll_button_type == ScrollButton.Right)
1470 orientation = Orientation.Horizontal;
1471 SetDrawableAndStyle (area, typeof(ScrollBar), orientation);
1474 bool enabled = (state == ButtonState.Inactive) ? false: true;
1476 StateType state_type = enabled ? StateType.Normal : StateType.Insensitive;
1478 DrawScrollButtonPrimitive (dc, area, state, scroll_button_type);
1480 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
1483 ArrowType arrow_type = 0;
1485 switch (scroll_button_type) {
1486 case ScrollButton.Up:
1487 arrow_type = ArrowType.Up;
1489 case ScrollButton.Down:
1490 arrow_type = ArrowType.Down;
1492 case ScrollButton.Right:
1493 arrow_type = ArrowType.Right;
1495 case ScrollButton.Left:
1496 arrow_type = ArrowType.Left;
1502 int centerX = area.Left + area.Width / 2;
1503 int centerY = area.Top + area.Height / 2;
1504 int arrow_x = 0, arrow_y = 0, arrow_height = 0, arrow_width = 0;
1506 switch (scroll_button_type) {
1507 case ScrollButton.Down:
1508 case ScrollButton.Up:
1509 arrow_x = centerX - 4;
1510 arrow_y = centerY - 2;
1514 case ScrollButton.Left:
1515 case ScrollButton.Right:
1516 arrow_x = centerX - 2;
1517 arrow_y = centerY - 4;
1525 gtk_paint_arrow (current_style,
1526 current_gdk_drawable,
1528 (int) ShadowType.Out,
1532 (int) arrow_type, true,
1535 arrow_width, arrow_height);
1537 current_widget = IntPtr.Zero;
1540 DrawDrawableToDC (dc, area);
1544 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type)
1546 StateType state_type = StateType.Normal;
1547 ShadowType shadow_type = ShadowType.Out;
1549 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
1550 state_type = StateType.Active;
1551 shadow_type = ShadowType.In;
1554 switch (scroll_button_type) {
1555 case ScrollButton.Left:
1556 case ScrollButton.Right:
1557 gtk_paint_box (current_style,
1558 current_gdk_drawable,
1562 global_gtk_hscrollbar,
1565 area.Width, area.Height);
1567 case ScrollButton.Up:
1568 case ScrollButton.Down:
1569 gtk_paint_box (current_style,
1570 current_gdk_drawable,
1574 global_gtk_vscrollbar,
1577 area.Width, area.Height);
1582 private static Color ColorFromGdkColor (GdkColorStruct gtkcolor)
1584 return Color.FromArgb (255,
1585 (gtkcolor.red >> 8) & 0xff,
1586 (gtkcolor.green >> 8) & 0xff,
1587 (gtkcolor.blue >> 8) & 0xff );