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 GtkStyleStruct
102 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=12)]
103 internal byte[] obj; /* GObject is 12 bytes*/
104 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
105 internal GdkColorStruct[] fg;
106 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
107 internal GdkColorStruct[] bg;
108 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
109 internal GdkColorStruct[] light;
110 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
111 internal GdkColorStruct[] dark;
112 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
113 internal GdkColorStruct[] mid;
114 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
115 internal GdkColorStruct[] text;
116 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
117 internal GdkColorStruct[] baseclr;
118 [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
119 internal GdkColorStruct[] text_aa; /* Halfway between text/base */
121 internal GdkColorStruct black;
122 internal GdkColorStruct white;
124 /* TODO: There is more stuff that we will add when we need it*/
128 [DllImport("libgdk-x11-2.0.so")]
129 internal static extern IntPtr gdk_display_manager_get ();
131 [DllImport("libgdk-x11-2.0.so")]
132 internal static extern IntPtr gdk_display_manager_get_default_display (IntPtr display_manager);
134 [DllImport("libgdk-x11-2.0.so")]
135 internal static extern void gdk_display_manager_set_default_display (IntPtr display_manager, IntPtr display);
137 [DllImport("libgdk-x11-2.0.so")]
138 internal static extern IntPtr gdk_x11_display_get_xdisplay (IntPtr display);
140 [DllImport("libgdk-x11-2.0.so")]
141 static extern IntPtr gdk_window_foreign_new_for_display (IntPtr display, uint anid);
143 [DllImport("libgdk-x11-2.0.so")]
144 static extern bool gdk_init_check(out int argc, string argv);
146 [DllImport("libgdk-x11-2.0.so")]
147 static extern IntPtr gdk_pixmap_new (IntPtr drawable, int width, int height, int depth);
149 [DllImport("libgdk-x11-2.0.so")]
150 static extern IntPtr gdk_pixbuf_get_from_drawable (IntPtr dest, IntPtr drawable_src, IntPtr cmap,
151 int src_x, int src_y, int dest_x, int dest_y, int width, int height);
153 [DllImport("libgdk-x11-2.0.so")]
154 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);
156 [DllImport("libgdk-x11-2.0.so")]
157 static extern IntPtr gdk_drawable_get_colormap (IntPtr drawable);
159 [DllImport("libgdk-x11-2.0.so")]
160 static extern IntPtr gdk_colormap_get_system ();
162 [DllImport("libgdk-x11-2.0.so")]
163 static extern IntPtr gdk_pixbuf_new (int colorspace, bool has_alpha, int bits_per_sample, int width, int height);
165 [DllImport("libgdk-x11-2.0.so")]
166 static extern IntPtr gdk_gc_new (IntPtr drawable);
169 [DllImport("libglib-2.0.so")]
170 static extern void g_free (IntPtr mem);
172 [DllImport("libgobject-2.0.so")]
173 static extern void g_object_unref (IntPtr nativeObject);
176 [DllImport("libgtk-x11-2.0.so")]
177 static extern bool gtk_init_check (out int argc, string argv);
179 [DllImport("libgtk-x11-2.0.so")]
180 static extern IntPtr gtk_adjustment_new (double value, double lower, double upper, double step_increment, double page_increment, double page_size);
182 [DllImport("libgtk-x11-2.0.so")]
183 static extern IntPtr gtk_rc_get_style (IntPtr widget);
185 [DllImport("libgtk-x11-2.0.so")]
186 static extern IntPtr gtk_vscrollbar_new(IntPtr adjustment);
188 [DllImport("libgtk-x11-2.0.so")]
189 static extern IntPtr gtk_hscrollbar_new(IntPtr adjustment);
191 [DllImport("libgtk-x11-2.0.so")]
192 static extern IntPtr gtk_style_attach (IntPtr raw, IntPtr window);
194 [DllImport("libgtk-x11-2.0.so")]
195 static extern IntPtr gtk_rc_style_new ();
197 [DllImport("libgtk-x11-2.0.so")]
198 static extern IntPtr gtk_invisible_new ();
200 [DllImport("libgtk-x11-2.0.so")]
201 static extern void gtk_widget_ensure_style (IntPtr raw);
203 [DllImport("libgtk-x11-2.0.so")]
204 static extern IntPtr gtk_widget_get_style (IntPtr raw);
206 [DllImport("libgtk-x11-2.0.so")]
207 static extern void gtk_style_detach (IntPtr raw);
209 [DllImport("libgtk-x11-2.0.so")]
210 static extern IntPtr gtk_button_new ();
212 [DllImport("libgtk-x11-2.0.so")]
213 static extern IntPtr gtk_progress_bar_new ();
215 [DllImport("libgtk-x11-2.0.so")]
216 static extern IntPtr gtk_radio_button_new (IntPtr group);
218 [DllImport("libgtk-x11-2.0.so")]
219 static extern IntPtr gtk_check_button_new ();
221 [DllImport("libgtk-x11-2.0.so")]
222 static extern IntPtr gtk_hscale_new (IntPtr adjustment);
224 [DllImport("libgtk-x11-2.0.so")]
225 static extern IntPtr gtk_vscale_new (IntPtr adjustment);
227 [DllImport("libgtk-x11-2.0.so")]
228 static extern void gtk_range_set_range (IntPtr range, double min, double max);
230 [DllImport("libgtk-x11-2.0.so")]
231 static extern void gtk_range_set_value (IntPtr range, double value);
234 [DllImport("libgtk-x11-2.0.so")]
235 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);
237 [DllImport("libgtk-x11-2.0.so")]
238 static extern void gtk_paint_arrow (IntPtr style, IntPtr window, int state_type, int shadow_type,
239 IntPtr area, IntPtr widget, string detail, int arrow_type, bool fill, int x, int y, int width, int height);
241 [DllImport("libgtk-x11-2.0.so")]
242 static extern void gtk_paint_slider (IntPtr style, IntPtr window, int state_type, int shadow_type,
243 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height, int orientation);
245 [DllImport("libgtk-x11-2.0.so")]
246 static extern void gtk_paint_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
247 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
249 [DllImport("libgtk-x11-2.0.so")]
250 static extern void gtk_paint_flat_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
251 IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
253 [DllImport("libgtk-x11-2.0.so")]
254 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);
256 [DllImport("libgtk-x11-2.0.so")]
257 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);
259 [DllImport("libgtk-x11-2.0.so")]
260 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);
262 [DllImport("libgtk-x11-2.0.so")]
263 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);
265 [DllImport("libgtk-x11-2.0.so")]
266 static extern void gtk_widget_size_allocate (IntPtr widget, ref Rectangle allocation);
268 [DllImport("libgtk-x11-2.0.so")]
269 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);
271 [DllImport("libgtk-x11-2.0.so")]
272 static extern void gtk_widget_grab_focus (IntPtr widget);
275 static protected IntPtr dispmgr;
276 static protected IntPtr gdkdisplay;
277 static protected IntPtr widget;
278 static protected IntPtr global_style;
281 static protected IntPtr global_color_map = IntPtr.Zero;
284 static protected IntPtr global_gtk_button = IntPtr.Zero;
285 static protected IntPtr global_gtk_button_style = IntPtr.Zero;
287 static protected IntPtr global_gtk_vscrollbar = IntPtr.Zero;
288 static protected IntPtr global_gtk_vscrollbar_style = IntPtr.Zero;
290 static protected IntPtr global_gtk_hscrollbar = IntPtr.Zero;
291 static protected IntPtr global_gtk_hscrollbar_style = IntPtr.Zero;
293 static protected IntPtr global_gtk_progress_bar = IntPtr.Zero;
294 static protected IntPtr global_gtk_progress_bar_style = IntPtr.Zero;
296 static protected IntPtr global_gtk_radio_button = IntPtr.Zero;
297 static protected IntPtr global_gtk_radio_button_style = IntPtr.Zero;
299 static protected IntPtr global_gtk_check_button = IntPtr.Zero;
300 static protected IntPtr global_gtk_check_button_style = IntPtr.Zero;
302 static protected IntPtr global_gtk_hscale = IntPtr.Zero;
303 static protected IntPtr global_gtk_hscale_style = IntPtr.Zero;
305 static protected IntPtr global_gtk_vscale = IntPtr.Zero;
306 static protected IntPtr global_gtk_vscale_style = IntPtr.Zero;
308 static protected IntPtr current_gdk_drawable = IntPtr.Zero;
309 static protected IntPtr current_style = IntPtr.Zero;
310 static protected IntPtr current_widget = IntPtr.Zero;
312 public static void InitGtk ()
314 Console.WriteLine ("ThemeGtk Init");
318 gdk_init_check (out argc, argv);
320 dispmgr = gdk_display_manager_get ();
321 gdkdisplay = gdk_display_manager_get_default_display (dispmgr);
322 gtk_init_check (out argc, argv);
324 widget = gtk_invisible_new ();
325 gtk_widget_ensure_style (widget);
326 global_style = gtk_widget_get_style (widget);
328 XplatUIX11.GetInstance().SetDisplay (gdk_x11_display_get_xdisplay (gdkdisplay));
330 global_gtk_button = gtk_button_new();
331 gtk_widget_ensure_style (global_gtk_button);
332 global_gtk_button_style = gtk_rc_get_style (global_gtk_button);
334 IntPtr adj = gtk_adjustment_new (0, 0, 0, 0, 0, 0);
335 global_gtk_vscrollbar = gtk_vscrollbar_new (adj);
336 gtk_widget_ensure_style (global_gtk_vscrollbar);
337 global_gtk_vscrollbar_style = gtk_rc_get_style (global_gtk_vscrollbar);
339 global_gtk_hscrollbar = gtk_hscrollbar_new (adj);
340 gtk_widget_ensure_style (global_gtk_hscrollbar);
341 global_gtk_hscrollbar_style = gtk_rc_get_style (global_gtk_hscrollbar);
343 global_gtk_progress_bar = gtk_progress_bar_new ();
344 gtk_widget_ensure_style (global_gtk_progress_bar);
345 global_gtk_progress_bar_style = gtk_rc_get_style (global_gtk_progress_bar);
347 global_gtk_radio_button = gtk_radio_button_new (IntPtr.Zero);
348 gtk_widget_ensure_style (global_gtk_radio_button);
349 global_gtk_radio_button_style = gtk_rc_get_style (global_gtk_radio_button);
351 global_gtk_check_button = gtk_check_button_new ();
352 gtk_widget_ensure_style (global_gtk_check_button);
353 global_gtk_check_button_style = gtk_rc_get_style (global_gtk_check_button);
355 global_gtk_hscale = gtk_hscale_new (adj);
356 gtk_widget_ensure_style (global_gtk_hscale);
357 global_gtk_hscale_style = gtk_rc_get_style (global_gtk_hscale);
359 global_gtk_vscale = gtk_vscale_new (adj);
360 gtk_widget_ensure_style (global_gtk_vscale);
361 global_gtk_vscale_style = gtk_rc_get_style (global_gtk_vscale);
364 global_color_map = gdk_colormap_get_system ();
368 public void LoadSysDefaultColors ()
370 GtkStyleStruct style_struct;
372 style_struct = (GtkStyleStruct) Marshal.PtrToStructure (global_style, typeof (GtkStyleStruct));
373 defaultWindowBackColor = ColorFromGdkColor (style_struct.bg[0]);
374 defaultWindowForeColor = ColorFromGdkColor (style_struct.fg[0]);
377 public ThemeGtk () : base ()
379 Console.WriteLine ("ThemeGtk constructor");
381 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
383 LoadSysDefaultColors ();
385 always_draw_hotkeys = true;
388 public override bool DoubleBufferingSupported {
396 private void SetDrawableAndStyle (Control control)
399 if (current_gdk_drawable != IntPtr.Zero) {
400 g_object_unref (current_gdk_drawable);
401 current_gdk_drawable = IntPtr.Zero;
403 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, control.ClientRectangle.Width, control.ClientRectangle.Height, 24);
405 current_gdk_drawable = gdk_window_foreign_new_for_display (gdkdisplay, (uint) control.Handle);
408 IntPtr tmp_style = IntPtr.Zero;
410 if (control is ButtonBase) {
411 tmp_style = global_gtk_button_style;
412 current_widget = global_gtk_button;
414 if (control is ScrollBar) {
415 ScrollBar bar = control as ScrollBar;
417 tmp_style = global_gtk_vscrollbar_style;
418 current_widget = global_gtk_vscrollbar;
420 tmp_style = global_gtk_hscrollbar_style;
421 current_widget = global_gtk_hscrollbar;
424 if (control is ProgressBar) {
425 tmp_style = global_gtk_progress_bar_style;
426 current_widget = global_gtk_progress_bar;
428 if (control is RadioButton) {
429 tmp_style = global_gtk_radio_button_style;
430 current_widget = global_gtk_radio_button;
432 if (control is CheckBox) {
433 tmp_style = global_gtk_check_button_style;
434 current_widget = global_gtk_check_button;
436 if (control is TrackBar) {
437 TrackBar bar = control as TrackBar;
438 if (bar.Orientation == Orientation.Vertical) {
439 tmp_style = global_gtk_vscale_style;
440 current_widget = global_gtk_vscale;
442 tmp_style = global_gtk_hscale_style;
443 current_widget = global_gtk_hscale;
446 tmp_style = global_style;
448 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
452 private void SetDrawableAndStyle (Rectangle area, Type type, Orientation orientation)
454 if (current_gdk_drawable != IntPtr.Zero) {
455 g_object_unref (current_gdk_drawable);
456 current_gdk_drawable = IntPtr.Zero;
458 current_gdk_drawable = gdk_pixmap_new (IntPtr.Zero, area.Width, area.Height, 24);
460 IntPtr tmp_style = IntPtr.Zero;
462 if (type == typeof(ButtonBase)) {
463 tmp_style = global_gtk_button_style;
464 current_widget = global_gtk_button;
466 if (type == typeof(ScrollBar)) {
467 if (orientation == Orientation.Vertical) {
468 tmp_style = global_gtk_vscrollbar_style;
469 current_widget = global_gtk_vscrollbar;
471 tmp_style = global_gtk_hscrollbar_style;
472 current_widget = global_gtk_hscrollbar;
475 if (type == typeof(ProgressBar)) {
476 tmp_style = global_gtk_progress_bar_style;
477 current_widget = global_gtk_progress_bar;
479 if (type == typeof(RadioButton)) {
480 tmp_style = global_gtk_radio_button_style;
481 current_widget = global_gtk_radio_button;
483 if (type == typeof(CheckBox)) {
484 tmp_style = global_gtk_check_button_style;
485 current_widget = global_gtk_check_button;
487 if (type == typeof(TrackBar)) {
488 if (orientation == Orientation.Vertical) {
489 tmp_style = global_gtk_vscale_style;
490 current_widget = global_gtk_vscale;
492 tmp_style = global_gtk_hscale_style;
493 current_widget = global_gtk_hscale;
496 tmp_style = global_style;
498 current_style = gtk_style_attach (tmp_style, current_gdk_drawable); // need it
503 private void DrawDrawableToDC (Graphics dc, Control control)
505 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, control.ClientRectangle.Width, control.ClientRectangle.Height);
507 gdk_pixbuf_get_from_drawable (new_pixbuf,
508 current_gdk_drawable,
517 IntPtr error = IntPtr.Zero;
519 UIntPtr buffer_size_as_ptr;
522 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
527 int buffer_size = (int) (uint) buffer_size_as_ptr;
528 byte[] result = new byte [buffer_size];
529 Marshal.Copy (buffer, result, 0, (int) buffer_size);
531 g_object_unref (new_pixbuf);
534 using (MemoryStream s = new MemoryStream (result))
535 image = Image.FromStream (s);
537 dc.DrawImage (image, control.ClientRectangle);
540 private void DrawDrawableToDC (Graphics dc, Rectangle area)
542 IntPtr new_pixbuf = gdk_pixbuf_new (0, true, 8, area.Width, area.Height);
544 gdk_pixbuf_get_from_drawable (new_pixbuf,
545 current_gdk_drawable,
554 IntPtr error = IntPtr.Zero;
556 UIntPtr buffer_size_as_ptr;
559 bool saved = gdk_pixbuf_save_to_buffer (new_pixbuf, out buffer, out buffer_size_as_ptr, type, out error, IntPtr.Zero);
564 int buffer_size = (int) (uint) buffer_size_as_ptr;
565 byte[] result = new byte [buffer_size];
566 Marshal.Copy (buffer, result, 0, (int) buffer_size);
568 g_object_unref (new_pixbuf);
571 using (MemoryStream s = new MemoryStream (result))
572 image = Image.FromStream (s);
574 dc.DrawImage (image, area);
578 public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
580 SetDrawableAndStyle (button);
582 // Draw the button: fill rectangle, draw border, etc.
583 ButtonBase_DrawButton (button, dc);
585 // First, draw the image
586 if ((button.image != null) || (button.image_list != null))
587 ButtonBase_DrawImage (button, dc);
589 // Draw the focus rectangle
590 if (button.has_focus)
591 ButtonBase_DrawFocus (button, dc);
594 DrawDrawableToDC (dc, button);
598 if (button.text != null && button.text != String.Empty)
599 ButtonBase_DrawText (button, dc);
602 protected override void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
604 Rectangle buttonRectangle = button.ClientRectangle;
606 StateType state_type = StateType.Normal;
607 ShadowType shadow_type = button.flat_style == FlatStyle.Flat ? ShadowType.In : ShadowType.Out;
608 string detail = "buttondefault";
610 if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
611 ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
612 state_type = StateType.Active;
613 shadow_type = ShadowType.In;
616 if (!button.is_enabled) {
617 state_type = StateType.Insensitive;
619 if (button.is_pressed) {
620 state_type = StateType.Active;
621 shadow_type = ShadowType.In;
624 if (button.is_entered) {
625 state_type = StateType.Prelight;
629 gtk_widget_grab_focus (global_gtk_button);
631 if (button.flat_style == FlatStyle.Flat)
632 gtk_paint_flat_box (current_style,
633 current_gdk_drawable,
639 buttonRectangle.X, buttonRectangle.Y,
640 buttonRectangle.Width, buttonRectangle.Height);
642 if (button.flat_style != FlatStyle.Popup || (button.flat_style == FlatStyle.Popup && button.is_entered))
643 gtk_paint_box (current_style,
644 current_gdk_drawable,
650 buttonRectangle.X, buttonRectangle.Y,
651 buttonRectangle.Width, buttonRectangle.Height);
654 protected override void ButtonBase_DrawFocus (ButtonBase button, Graphics dc)
656 if (!button.is_enabled)
659 Rectangle focus_rect = new Rectangle (button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9);
661 gtk_widget_grab_focus (global_gtk_button);
663 gtk_paint_focus (current_style,
664 current_gdk_drawable,
665 (int) StateType.Active,
676 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
677 int scrollbutton_width = bar.scrollbutton_width;
678 int scrollbutton_height = bar.scrollbutton_height;
679 Rectangle first_arrow_area;
680 Rectangle second_arrow_area;
683 SetDrawableAndStyle (bar);
685 Rectangle allocation = new Rectangle (bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, bar.ClientRectangle.Height);
688 Color fix_color = bar.Parent != null ? bar.Parent.BackColor : ColorControl;
691 gtk_widget_size_allocate (global_gtk_vscrollbar, ref allocation);
694 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
695 bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, 3);
696 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
697 bar.ClientRectangle.X, bar.ClientRectangle.Bottom - 4, bar.ClientRectangle.Width, 3);
699 gtk_widget_size_allocate (global_gtk_hscrollbar, ref allocation);
702 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
703 bar.ClientRectangle.X, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
704 dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
705 bar.ClientRectangle.Right - 4, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
708 thumb_pos = bar.ThumbPos;
711 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
712 bar.FirstArrowArea = first_arrow_area;
714 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
715 bar.SecondArrowArea = second_arrow_area;
717 thumb_pos.Width = bar.Width;
718 bar.ThumbPos = thumb_pos;
720 ScrollBar_Vertical_Draw_ThumbMoving_None (scrollbutton_height, bar, clip, dc);
723 if ( clip.IntersectsWith( first_arrow_area ) )
724 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
725 if ( clip.IntersectsWith( second_arrow_area ) )
726 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
728 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
729 bar.FirstArrowArea = first_arrow_area;
731 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
732 bar.SecondArrowArea = second_arrow_area;
734 thumb_pos.Height = bar.Height;
735 bar.ThumbPos = thumb_pos;
738 ScrollBar_Horizontal_Draw_ThumbMoving_None (scrollbutton_width, bar, clip, dc);
741 if ( clip.IntersectsWith( first_arrow_area ) )
742 CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
743 if ( clip.IntersectsWith( second_arrow_area ) )
744 CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
748 ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
751 DrawDrawableToDC (dc, bar);
755 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
757 DrawScrollBarThumb( dc, thumb_pos, bar );
760 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None (int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc)
762 Rectangle r = new Rectangle (0,
763 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
764 gtk_paint_box (current_style,
765 current_gdk_drawable,
766 (int) StateType.Active,
769 global_gtk_vscrollbar,
775 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None (int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc)
777 Rectangle r = new Rectangle (scrollbutton_width,
778 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
780 gtk_paint_box (current_style,
781 current_gdk_drawable,
782 (int) StateType.Active,
785 global_gtk_hscrollbar,
791 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
792 IntPtr gtk_scrollbar = bar.vert ? global_gtk_vscrollbar : global_gtk_hscrollbar;
794 gtk_paint_box (current_style,
795 current_gdk_drawable,
796 (int) StateType.Active,
797 (int) ShadowType.Out,
802 area.Width, area.Height);
804 #endregion // ScrollBar
807 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
809 Rectangle client_area = ctrl.client_area;
812 SetDrawableAndStyle (ctrl);
815 gtk_paint_box (current_style,
816 current_gdk_drawable,
817 (int) StateType.Normal,
820 global_gtk_progress_bar,
822 ctrl.ClientRectangle.X,
823 ctrl.ClientRectangle.Y,
824 ctrl.ClientRectangle.Width,
825 ctrl.ClientRectangle.Height);
827 // don't draw the bar if Value is = 0
831 int value = ctrl.Value;
833 if (value > ctrl.Maximum)
834 value = ctrl.Maximum;
836 if (value == ctrl.Maximum)
837 barpos_pixels = client_area.Width + 2;
839 barpos_pixels = (((value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum)) + 1;
841 gtk_paint_box (current_style,
842 current_gdk_drawable,
843 (int) StateType.Prelight,
844 (int) ShadowType.Out,
846 global_gtk_progress_bar,
848 client_area.X - 1, client_area.Y - 1,
849 barpos_pixels, client_area.Height + 2);
852 DrawDrawableToDC (dc, ctrl);
855 #endregion // ProgressBar
858 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
860 // we currently don't care for flat or popup radio buttons
861 if (radio_button.appearance == Appearance.Button) {
862 DrawButtonBase (dc, radio_button.ClientRectangle, radio_button);
864 DrawRadioButton (dc, radio_button, state, radiobutton_rectangle);
868 private void DrawRadioButton (Graphics dc, RadioButton radio_button, ButtonState state, Rectangle radiobutton_rectangle)
870 SetDrawableAndStyle (radio_button);
872 ShadowType shadow_type;
874 if (!radio_button.Enabled)
875 shadow_type = ShadowType.Out;
877 shadow_type = radio_button.Checked ? ShadowType.In : ShadowType.EtchedIn;
879 StateType state_type = StateType.Normal;
881 if (!radio_button.Enabled)
882 state_type = StateType.Insensitive;
884 if (radio_button.is_pressed)
885 state_type = StateType.Active;
887 if (radio_button.is_entered)
888 state_type = StateType.Prelight;
890 gtk_paint_option (current_style,
891 current_gdk_drawable,
895 global_gtk_radio_button,
897 radiobutton_rectangle.X,
898 radiobutton_rectangle.Y,
899 radiobutton_rectangle.Width,
900 radiobutton_rectangle.Height);
903 DrawDrawableToDC (dc, radio_button);
907 protected override void RadioButton_DrawText (RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
909 if (radio_button.Appearance != Appearance.Button)
910 base.RadioButton_DrawText (radio_button, text_rectangle, dc, text_format);
913 protected override void RadioButton_DrawFocus (RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
915 if (radio_button.Focused && radio_button.appearance != Appearance.Button) {
916 gtk_paint_focus (current_style,
917 current_gdk_drawable,
918 (int) StateType.Active,
920 global_gtk_radio_button,
924 text_rectangle.Width,
925 text_rectangle.Height);
929 DrawDrawableToDC (dc, radio_button);
932 #endregion // RadioButton
935 protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
937 // render as per normal button
938 if (checkbox.appearance == Appearance.Button) {
939 DrawButtonBase (dc, checkbox.ClientRectangle, checkbox);
941 InternalDrawCheckBox (dc, checkbox, state, checkbox_rectangle);
945 private void InternalDrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
947 SetDrawableAndStyle (checkbox);
949 ShadowType shadow_type;
951 if (!checkbox.Enabled)
952 shadow_type = ShadowType.Out;
954 shadow_type = checkbox.Checked ? ShadowType.In : ShadowType.EtchedIn;
956 StateType state_type = StateType.Normal;
958 if (!checkbox.Enabled)
959 state_type = StateType.Insensitive;
961 if (checkbox.is_pressed)
962 state_type = StateType.Active;
964 if (checkbox.is_entered)
965 state_type = StateType.Prelight;
967 gtk_paint_check (current_style,
968 current_gdk_drawable,
972 global_gtk_check_button,
974 checkbox_rectangle.X,
975 checkbox_rectangle.Y,
976 checkbox_rectangle.Width,
977 checkbox_rectangle.Height);
980 DrawDrawableToDC (dc, checkbox);
984 protected override void CheckBox_DrawText (CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
986 if (checkbox.Appearance != Appearance.Button)
987 base.CheckBox_DrawText (checkbox, text_rectangle, dc, text_format);
990 protected override void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
992 if (checkbox.Focused && checkbox.appearance != Appearance.Button) {
993 gtk_paint_focus (current_style,
994 current_gdk_drawable,
995 (int) StateType.Active,
997 global_gtk_check_button,
1001 text_rectangle.Width,
1002 text_rectangle.Height);
1006 DrawDrawableToDC (dc, checkbox);
1009 #endregion // CheckBox
1012 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1013 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1014 float ticks, int value_pos, bool mouse_value)
1016 Point toptick_startpoint = new Point ();
1017 Point bottomtick_startpoint = new Point ();
1018 Point channel_startpoint = new Point ();
1020 float pixels_betweenticks;
1021 const int space_from_right = 8;
1022 const int space_from_left = 8;
1023 Rectangle area = tb.ClientRectangle;
1025 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1027 gtk_widget_size_allocate (current_widget, ref allocation);
1029 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1030 gtk_range_set_value (current_widget, tb.Value);
1032 ShadowType shadow_type = ShadowType.In;
1035 shadow_type = ShadowType.Out;
1037 StateType state_type = StateType.Normal;
1040 state_type = StateType.Insensitive;
1043 state_type = StateType.Prelight;
1045 switch (tb.TickStyle) {
1046 case TickStyle.BottomRight:
1047 case TickStyle.None:
1048 channel_startpoint.Y = 8;
1049 channel_startpoint.X = 9;
1050 bottomtick_startpoint.Y = 13;
1051 bottomtick_startpoint.X = 24;
1053 case TickStyle.TopLeft:
1054 channel_startpoint.Y = 8;
1055 channel_startpoint.X = 19;
1056 toptick_startpoint.Y = 13;
1057 toptick_startpoint.X = 8;
1059 case TickStyle.Both:
1060 channel_startpoint.Y = 8;
1061 channel_startpoint.X = 18;
1062 bottomtick_startpoint.Y = 13;
1063 bottomtick_startpoint.X = 32;
1064 toptick_startpoint.Y = 13;
1065 toptick_startpoint.X = 8;
1071 thumb_area.X = area.X + channel_startpoint.X;
1072 thumb_area.Y = area.Y + channel_startpoint.Y;
1073 thumb_area.Height = area.Height - space_from_right - space_from_left;
1074 thumb_area.Width = 4;
1076 pixel_len = thumb_area.Height - 11;
1077 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1079 /* Convert thumb position from mouse position to value*/
1082 if (value_pos >= channel_startpoint.Y)
1083 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
1087 if (value_pos + tb.Minimum > tb.Maximum)
1088 value_pos = tb.Maximum - tb.Minimum;
1090 tb.Value = value_pos + tb.Minimum;
1093 thumb_pos.Width = 13;
1094 thumb_pos.Height = 29;
1096 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Height / 3);
1098 if (thumb_pos.Y < channel_startpoint.Y)
1099 thumb_pos.Y = channel_startpoint.Y;
1101 if (thumb_pos.Y > thumb_area.Bottom - 29)
1102 thumb_pos.Y = thumb_area.Bottom - 29;
1105 gtk_paint_box (current_style,
1106 current_gdk_drawable,
1118 thumb_pos.X = channel_startpoint.X + 2 - thumb_pos.Width / 2;
1120 shadow_type = ShadowType.Out;
1122 gtk_paint_slider (current_style,
1123 current_gdk_drawable,
1135 pixel_len = thumb_area.Height - 11;
1136 pixels_betweenticks = pixel_len / ticks;
1139 thumb_area.X = thumb_pos.X;
1140 thumb_area.Y = channel_startpoint.Y;
1141 thumb_area.Width = thumb_pos.Width;
1143 Region outside = new Region (area);
1144 outside.Exclude (thumb_area);
1146 if (outside.IsVisible (clip_rectangle)) {
1147 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1148 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1150 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1151 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1152 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
1153 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
1155 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
1156 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
1160 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1161 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1163 pixel_len = thumb_area.Height - 11;
1164 pixels_betweenticks = pixel_len / ticks;
1166 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1167 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1168 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
1169 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1171 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
1172 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1180 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1181 ref Rectangle thumb_pos, ref Rectangle thumb_area,
1182 float ticks, int value_pos, bool mouse_value)
1184 Point toptick_startpoint = new Point ();
1185 Point bottomtick_startpoint = new Point ();
1186 Point channel_startpoint = new Point ();
1188 float pixels_betweenticks;
1189 const int space_from_right = 8;
1190 const int space_from_left = 8;
1191 Rectangle area = tb.ClientRectangle;
1193 Rectangle allocation = new Rectangle (area.X, area.Y, area.Width, area.Height);
1195 gtk_widget_size_allocate (current_widget, ref allocation);
1197 gtk_range_set_range (current_widget, tb.Minimum, tb.Maximum);
1198 gtk_range_set_value (current_widget, tb.Value);
1200 ShadowType shadow_type = ShadowType.In;
1203 shadow_type = ShadowType.Out;
1205 StateType state_type = StateType.Normal;
1208 state_type = StateType.Insensitive;
1211 state_type = StateType.Prelight;
1213 switch (tb.TickStyle) {
1214 case TickStyle.BottomRight:
1215 case TickStyle.None:
1216 channel_startpoint.X = 8;
1217 channel_startpoint.Y = 9;
1218 bottomtick_startpoint.X = 13;
1219 bottomtick_startpoint.Y = 24;
1221 case TickStyle.TopLeft:
1222 channel_startpoint.X = 8;
1223 channel_startpoint.Y = 19;
1224 toptick_startpoint.X = 13;
1225 toptick_startpoint.Y = 8;
1227 case TickStyle.Both:
1228 channel_startpoint.X = 8;
1229 channel_startpoint.Y = 18;
1230 bottomtick_startpoint.X = 13;
1231 bottomtick_startpoint.Y = 32;
1232 toptick_startpoint.X = 13;
1233 toptick_startpoint.Y = 8;
1239 thumb_area.X = area.X + channel_startpoint.X;
1240 thumb_area.Y = area.Y + channel_startpoint.Y;
1241 thumb_area.Width = area.Width - space_from_right - space_from_left;
1242 thumb_area.Height = 4;
1244 pixel_len = thumb_area.Width - 11;
1245 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1247 /* Convert thumb position from mouse position to value*/
1249 if (value_pos >= channel_startpoint.X)
1250 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
1254 if (value_pos + tb.Minimum > tb.Maximum)
1255 value_pos = tb.Maximum - tb.Minimum;
1257 tb.Value = value_pos + tb.Minimum;
1260 thumb_pos.Width = 29;
1261 thumb_pos.Height = 13;
1263 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos) - (thumb_pos.Width / 3);
1266 if (thumb_pos.X < channel_startpoint.X)
1267 thumb_pos.X = channel_startpoint.X;
1269 if (thumb_pos.X > thumb_area.Right - 29)
1270 thumb_pos.X = thumb_area.Right - 29;
1273 gtk_paint_box (current_style,
1274 current_gdk_drawable,
1287 thumb_pos.Y = channel_startpoint.Y + 2 - thumb_pos.Height / 2;
1289 shadow_type = ShadowType.Out;
1291 gtk_paint_slider (current_style,
1292 current_gdk_drawable,
1304 pixel_len = thumb_area.Width - 11;
1305 pixels_betweenticks = pixel_len / ticks;
1308 thumb_area.Y = thumb_pos.Y;
1309 thumb_area.X = channel_startpoint.X;
1310 thumb_area.Height = thumb_pos.Height;
1311 Region outside = new Region (area);
1312 outside.Exclude (thumb_area);
1314 if (outside.IsVisible (clip_rectangle)) {
1315 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1316 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1318 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1319 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1320 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
1321 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
1323 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
1324 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
1328 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1329 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1331 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1332 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1)
1333 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
1334 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
1336 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
1337 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y);
1345 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
1349 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
1351 Rectangle thumb_pos = tb.ThumbPos;
1352 Rectangle thumb_area = tb.ThumbArea;
1354 if (tb.thumb_pressed) {
1355 value_pos = tb.thumb_mouseclick;
1358 value_pos = tb.Value - tb.Minimum;
1359 mouse_value = false;
1362 area = tb.ClientRectangle;
1364 SetDrawableAndStyle (tb);
1366 /* Control Background */
1367 if (tb.BackColor == DefaultControlBackColor) {
1368 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
1370 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
1373 if (tb.Orientation == Orientation.Vertical) {
1374 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1375 ticks, value_pos, mouse_value);
1378 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
1379 ticks, value_pos, mouse_value);
1382 if (tb.Enabled && tb.Focused)
1383 gtk_paint_focus (current_style,
1384 current_gdk_drawable,
1385 (int)StateType.Normal,
1394 tb.ThumbPos = thumb_pos;
1395 tb.ThumbArea = thumb_area;
1398 DrawDrawableToDC (dc, tb);
1401 #endregion // TrackBar
1403 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
1406 SetDrawableAndStyle (rectangle, typeof(ButtonBase), Orientation.Horizontal);
1409 bool is_pushed = false;
1410 // bool is_checked = false;
1411 // bool is_flat = false;
1412 bool is_inactive = false;
1414 if ((state & ButtonState.Pushed) != 0) {
1418 // if ((state & ButtonState.Checked) != 0) {
1419 // is_checked = true;
1422 // if ((state & ButtonState.Flat) != 0) {
1426 if ((state & ButtonState.Inactive) != 0) {
1430 IntPtr drawbutton_style = gtk_style_attach (global_gtk_button_style, current_gdk_drawable); // need it
1432 StateType state_type = StateType.Normal;
1433 ShadowType shadow_type = ShadowType.Out;
1434 string detail = "buttondefault";
1437 state_type = StateType.Insensitive;
1440 state_type = StateType.Active;
1441 shadow_type = ShadowType.In;
1445 gtk_paint_box (drawbutton_style, current_gdk_drawable,
1451 rectangle.X, rectangle.Y,
1452 rectangle.Width, rectangle.Height);
1455 DrawDrawableToDC (dc, rectangle);
1459 /* Scroll button: regular button + direction arrow */
1460 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state)
1463 Orientation orientation = Orientation.Vertical;
1464 if (scroll_button_type == ScrollButton.Left || scroll_button_type == ScrollButton.Right)
1465 orientation = Orientation.Horizontal;
1466 SetDrawableAndStyle (area, typeof(ScrollBar), orientation);
1469 bool enabled = (state == ButtonState.Inactive) ? false: true;
1471 StateType state_type = enabled ? StateType.Normal : StateType.Insensitive;
1473 DrawScrollButtonPrimitive (dc, area, state, scroll_button_type);
1475 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
1478 ArrowType arrow_type = 0;
1480 switch (scroll_button_type) {
1481 case ScrollButton.Up:
1482 arrow_type = ArrowType.Up;
1484 case ScrollButton.Down:
1485 arrow_type = ArrowType.Down;
1487 case ScrollButton.Right:
1488 arrow_type = ArrowType.Right;
1490 case ScrollButton.Left:
1491 arrow_type = ArrowType.Left;
1497 int centerX = area.Left + area.Width / 2;
1498 int centerY = area.Top + area.Height / 2;
1499 int arrow_x = 0, arrow_y = 0, arrow_height = 0, arrow_width = 0;
1501 switch (scroll_button_type) {
1502 case ScrollButton.Down:
1503 case ScrollButton.Up:
1504 arrow_x = centerX - 4;
1505 arrow_y = centerY - 2;
1509 case ScrollButton.Left:
1510 case ScrollButton.Right:
1511 arrow_x = centerX - 2;
1512 arrow_y = centerY - 4;
1520 gtk_paint_arrow (current_style,
1521 current_gdk_drawable,
1523 (int) ShadowType.Out,
1527 (int) arrow_type, true,
1530 arrow_width, arrow_height);
1532 current_widget = IntPtr.Zero;
1535 DrawDrawableToDC (dc, area);
1539 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type)
1541 StateType state_type = StateType.Normal;
1542 ShadowType shadow_type = ShadowType.Out;
1544 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
1545 state_type = StateType.Active;
1546 shadow_type = ShadowType.In;
1549 switch (scroll_button_type) {
1550 case ScrollButton.Left:
1551 case ScrollButton.Right:
1552 gtk_paint_box (current_style,
1553 current_gdk_drawable,
1557 global_gtk_hscrollbar,
1560 area.Width, area.Height);
1562 case ScrollButton.Up:
1563 case ScrollButton.Down:
1564 gtk_paint_box (current_style,
1565 current_gdk_drawable,
1569 global_gtk_vscrollbar,
1572 area.Width, area.Height);
1577 private static Color ColorFromGdkColor (GdkColorStruct gtkcolor)
1579 return Color.FromArgb (255,
1580 (gtkcolor.red >> 8) & 0xff,
1581 (gtkcolor.green >> 8) & 0xff,
1582 (gtkcolor.blue >> 8) & 0xff );