2 // GtkPlus.cs: Wraps GTK+, exposing its control painting features to code
3 // that uses System.Drawing types (such as IDeviceContext, Rectangle).
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 // Copyright (c) 2008 George Giolfan
27 // George Giolfan (georgegiolfan@yahoo.com)
30 using gpointer
= System
.IntPtr
;
31 using gboolean
= System
.Boolean
;
32 using gint
= System
.Int32
;
33 using guint
= System
.UInt32
;
34 using guint8
= System
.Byte
;
35 using guint16
= System
.UInt16
;
36 using guint32
= System
.UInt32
;
37 using gfloat
= System
.Single
;
38 using gdouble
= System
.Double
;
40 using PangoFontDescriptionPointer
= System
.IntPtr
;
42 using GDataPointer
= System
.IntPtr
;
43 using GObjectPointer
= System
.IntPtr
;
44 using GSListPointer
= System
.IntPtr
;
45 using GType
= System
.IntPtr
;
46 using GTypeClassPointer
= System
.IntPtr
;
47 using GTypeInstancePointer
= System
.IntPtr
;
49 using GdkColormapPointer
= System
.IntPtr
;
50 using GdkDrawablePointer
= System
.IntPtr
;
51 using GdkGCPointer
= System
.IntPtr
;
52 using GdkNativeWindowPointer
= System
.IntPtr
;
53 using GdkPixbufPointer
= System
.IntPtr
;
54 using GdkPixmapPointer
= System
.IntPtr
;
55 using GdkWindowPointer
= System
.IntPtr
;
57 using GtkAdjustmentPointer
= System
.IntPtr
;
58 using GtkBinPointer
= System
.IntPtr
;
59 using GtkContainerPointer
= System
.IntPtr
;
60 using GtkObjectPointer
= System
.IntPtr
;
61 using GtkStylePointer
= System
.IntPtr
;
62 using GtkToolbarPointer
= System
.IntPtr
;
63 using GtkToolItemPointer
= System
.IntPtr
;
64 using GtkTreeViewPointer
= System
.IntPtr
;
65 using GtkTreeViewColumnPointer
= System
.IntPtr
;
66 using GtkWidgetPointer
= System
.IntPtr
;
67 using GtkWindowPointer
= System
.IntPtr
;
69 using GtkAllocation
= System
.Windows
.Forms
.VisualStyles
.GtkPlus
.GdkRectangle
;
70 using GInitiallyUnowned
= System
.Windows
.Forms
.VisualStyles
.GtkPlus
.GObject
;
72 using System
.Collections
;
74 using System
.Drawing
.Imaging
;
75 using System
.Reflection
;
76 using System
.Reflection
.Emit
;
77 using System
.Runtime
.CompilerServices
;
78 using System
.Runtime
.InteropServices
;
80 namespace System
.Windows
.Forms
.VisualStyles
85 /// Inspired by ThemeGtk and QGtkStyle (http://labs.trolltech.com/page/Projects/Styles/GtkStyle). Tries to use the exact GTK+ logic in order to be compatible with all its themes.
90 static GtkPlus instance
;
91 public static GtkPlus Instance
{
92 get { return instance; }
95 #region GTK+ initialization
96 public static bool Initialize ()
99 if (gtk_check_version (2, 10, 0) != IntPtr
.Zero
)
101 //TODO: If we need to pass the actual arguments, duplicate the required code from GTK#.
103 string [] argv
= new string [1];
104 bool result
= gtk_init_check (ref argc
, ref argv
);
106 instance
= new GtkPlus ();
108 } catch (DllNotFoundException
) {
115 readonly int WidgetTypeCount
= Enum
.GetNames (typeof (WidgetType
)).Length
;
116 readonly GtkWidgetPointer
[] widgets
;
117 readonly GtkWidgetPointer window
;
118 readonly GtkWidgetPointer
@fixed;
119 readonly GtkStylePointer
[] styles
;
122 readonly GtkWidgetPointer combo_box_drop_down_toggle_button
;
123 readonly GtkWidgetPointer combo_box_drop_down_arrow
;
124 GtkStylePointer combo_box_drop_down_toggle_button_style
;
125 GtkStylePointer combo_box_drop_down_arrow_style
;
129 readonly GtkWidgetPointer tool_bar_button
;
130 readonly GtkWidgetPointer tool_bar_toggle_button
;
131 GtkStylePointer tool_bar_button_style
;
132 GtkStylePointer tool_bar_toggle_button_style
;
135 readonly GtkTreeViewColumnPointer tree_view_column
;
136 readonly GtkWidgetPointer tree_view_column_button
;
137 GtkStylePointer tree_view_column_button_style
;
140 readonly ButtonPainter button_painter
= new ButtonPainter ();
141 readonly CheckBoxPainter check_box_painter
= new CheckBoxPainter ();
142 readonly RadioButtonPainter radio_button_painter
= new RadioButtonPainter ();
145 readonly ComboBoxDropDownButtonPainter combo_box_drop_down_button_painter
= new ComboBoxDropDownButtonPainter ();
146 readonly ComboBoxBorderPainter combo_box_border_painter
= new ComboBoxBorderPainter ();
150 readonly GroupBoxPainter group_box_painter
= new GroupBoxPainter ();
153 readonly HeaderPainter header_painter
= new HeaderPainter ();
156 readonly ProgressBarBarPainter progress_bar_bar_painter
= new ProgressBarBarPainter ();
157 readonly ProgressBarChunkPainter progress_bar_chunk_painter
= new ProgressBarChunkPainter ();
160 readonly ScrollBarArrowButtonPainter scroll_bar_arrow_button_painter
= new ScrollBarArrowButtonPainter ();
161 readonly ScrollBarThumbButtonPainter scroll_bar_thumb_button_painter
= new ScrollBarThumbButtonPainter ();
162 readonly ScrollBarTrackPainter scroll_bar_track_painter
= new ScrollBarTrackPainter ();
165 readonly StatusBarGripperPainter status_bar_gripper_painter
= new StatusBarGripperPainter ();
168 readonly TabControlPanePainter tab_control_pane_painter
= new TabControlPanePainter ();
169 readonly TabControlTabItemPainter tab_control_tab_item_painter
= new TabControlTabItemPainter ();
171 readonly TextBoxPainter text_box_painter
= new TextBoxPainter ();
173 readonly ToolBarPainter tool_bar_painter
= new ToolBarPainter ();
174 readonly ToolBarButtonPainter tool_bar_button_painter
= new ToolBarButtonPainter ();
175 readonly ToolBarCheckedButtonPainter tool_bar_checked_button_painter
= new ToolBarCheckedButtonPainter ();
178 readonly TrackBarTrackPainter track_bar_track_painter
= new TrackBarTrackPainter ();
179 readonly TrackBarThumbPainter track_bar_thumb_painter
= new TrackBarThumbPainter ();
181 readonly TreeViewGlyphPainter tree_view_glyph_painter
= new TreeViewGlyphPainter ();
182 readonly UpDownPainter up_down_painter
= new UpDownPainter ();
185 #region Constructor and finalizer
188 widgets
= new GtkWidgetPointer
[WidgetTypeCount
];
189 styles
= new GtkStylePointer
[WidgetTypeCount
];
190 window
= gtk_window_new (GtkWindowType
.GTK_WINDOW_TOPLEVEL
);
191 @fixed = gtk_fixed_new ();
192 gtk_container_add (window
, @fixed);
195 gtk_container_add (@fixed, widgets
[(int)WidgetType
.Button
] = gtk_button_new ());
196 GTK_WIDGET_SET_FLAGS (widgets
[(int)WidgetType
.Button
], GtkWidgetFlags
.GTK_CAN_DEFAULT
);
199 gtk_container_add (@fixed, widgets
[(int)WidgetType
.CheckBox
] = gtk_check_button_new ());
203 gtk_container_add (@fixed, widgets
[(int)WidgetType
.ComboBox
] = gtk_combo_box_entry_new ());
204 gtk_widget_realize (widgets
[(int)WidgetType
.ComboBox
]);
205 combo_box_drop_down_toggle_button
= GetFirstChildWidgetOfType
.Get (widgets
[(int)WidgetType
.ComboBox
], gtk_toggle_button_get_type ());
206 gtk_widget_realize (combo_box_drop_down_toggle_button
);
207 combo_box_drop_down_arrow
= GetFirstChildWidgetOfType
.Get (combo_box_drop_down_toggle_button
, gtk_arrow_get_type ());
208 g_object_ref (combo_box_drop_down_toggle_button_style
= GetWidgetStyle (combo_box_drop_down_toggle_button
));
209 g_object_ref (combo_box_drop_down_arrow_style
= GetWidgetStyle (combo_box_drop_down_arrow
));
213 gtk_container_add (@fixed, widgets
[(int)WidgetType
.GroupBox
] = gtk_frame_new (null));
216 gtk_container_add (@fixed, widgets
[(int)WidgetType
.ProgressBar
] = gtk_progress_bar_new ());
219 gtk_container_add (@fixed, widgets
[(int)WidgetType
.RadioButton
] = gtk_radio_button_new (IntPtr
.Zero
));
222 gtk_container_add (@fixed, widgets
[(int)WidgetType
.HScrollBar
] = gtk_hscrollbar_new (IntPtr
.Zero
));
223 gtk_container_add (@fixed, widgets
[(int)WidgetType
.VScrollBar
] = gtk_vscrollbar_new (IntPtr
.Zero
));
226 gtk_container_add (@fixed, widgets
[(int)WidgetType
.StatusBar
] = gtk_statusbar_new ());
229 gtk_container_add (@fixed, widgets
[(int)WidgetType
.TabControl
] = gtk_notebook_new ());
232 gtk_container_add (@fixed, widgets
[(int)WidgetType
.TextBox
] = gtk_entry_new ());
235 gtk_container_add (@fixed, widgets
[(int)WidgetType
.ToolBar
] = gtk_toolbar_new ());
237 GtkToolItemPointer tool_button
= gtk_tool_button_new (IntPtr
.Zero
, null);
238 gtk_toolbar_insert (widgets
[(int)WidgetType
.ToolBar
], tool_button
, -1);
239 tool_bar_button
= gtk_bin_get_child (tool_button
);
240 g_object_ref (tool_bar_button_style
= GetWidgetStyle (tool_bar_button
));
242 GtkToolItemPointer toggle_tool_button
= gtk_toggle_tool_button_new ();
243 gtk_toolbar_insert (widgets
[(int)WidgetType
.ToolBar
], toggle_tool_button
, -1);
244 tool_bar_toggle_button
= gtk_bin_get_child (toggle_tool_button
);
245 g_object_ref (tool_bar_toggle_button_style
= GetWidgetStyle (tool_bar_toggle_button
));
248 gtk_container_add (@fixed, widgets
[(int)WidgetType
.HorizontalTrackBar
] = gtk_hscale_new_with_range (0, 1, 1));
249 gtk_container_add (@fixed, widgets
[(int)WidgetType
.VerticalTrackBar
] = gtk_vscale_new_with_range (0, 1, 1));
252 gtk_container_add (@fixed, widgets
[(int)WidgetType
.TreeView
] = gtk_tree_view_new ());
253 tree_view_column
= gtk_tree_view_column_new ();
254 gtk_tree_view_insert_column (widgets
[(int)WidgetType
.TreeView
], tree_view_column
, -1);
255 GtkTreeViewColumn column_structure
= (GtkTreeViewColumn
)Marshal
.PtrToStructure (tree_view_column
, typeof (GtkTreeViewColumn
));
256 tree_view_column_button
= column_structure
.button
;
257 g_object_ref (tree_view_column_button_style
= GetWidgetStyle (tree_view_column_button
));
260 GtkAdjustmentPointer adjustment
= gtk_adjustment_new (0, 0, 0, 0, 0, 0);
261 gtk_container_add (@fixed, widgets
[(int)WidgetType
.UpDown
] = gtk_spin_button_new (adjustment
, 0, 0));
264 for (int widget_index
= 0; widget_index
< WidgetTypeCount
; widget_index
++)
265 g_object_ref (styles
[widget_index
] = GetWidgetStyle (widgets
[widget_index
]));
269 gtk_object_destroy (window
);
270 for (int widget_index
= 0; widget_index
< WidgetTypeCount
; widget_index
++)
271 g_object_unref (styles
[widget_index
]);
274 g_object_unref (combo_box_drop_down_toggle_button_style
);
275 g_object_unref (combo_box_drop_down_arrow_style
);
279 g_object_unref (tool_bar_button_style
);
280 g_object_unref (tool_bar_toggle_button_style
);
283 g_object_unref (tree_view_column_button_style
);
289 public void ButtonPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, bool @default, GtkPlusState state
)
291 button_painter
.Configure (@default, state
);
292 Paint (WidgetType
.Button
, bounds
, dc
, clippingArea
, button_painter
);
296 public void CheckBoxPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, GtkPlusToggleButtonValue
value)
298 check_box_painter
.Configure (state
, value);
299 Paint (WidgetType
.CheckBox
, bounds
, dc
, clippingArea
, check_box_painter
);
301 Size
GetGtkCheckButtonIndicatorSize (WidgetType widgetType
)
303 int indicator_size
= GetWidgetStyleInteger (widgets
[(int)widgetType
], "indicator-size");
304 return new Size (indicator_size
, indicator_size
);
306 public Size
CheckBoxGetSize ()
308 return GetGtkCheckButtonIndicatorSize (WidgetType
.CheckBox
);
313 public void ComboBoxPaintDropDownButton (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
)
315 combo_box_drop_down_button_painter
.Configure (state
);
316 Paint (WidgetType
.ComboBox
, bounds
, dc
, clippingArea
, combo_box_drop_down_button_painter
);
318 public void ComboBoxPaintBorder (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
320 Paint (WidgetType
.ComboBox
, bounds
, dc
, clippingArea
, combo_box_border_painter
);
325 public void GroupBoxPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle excludedArea
, GtkPlusState state
)
327 group_box_painter
.Configure (state
);
328 PaintExcludingArea (WidgetType
.GroupBox
, bounds
, dc
, excludedArea
, group_box_painter
);
332 public void HeaderPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
)
334 header_painter
.Configure (state
);
335 Paint (WidgetType
.TreeView
, bounds
, dc
, clippingArea
, header_painter
);
339 public void ProgressBarPaintBar (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
341 Paint (WidgetType
.ProgressBar
, bounds
, dc
, clippingArea
, progress_bar_bar_painter
);
343 public void ProgressBarPaintChunk (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
345 Paint (WidgetType
.ProgressBar
, bounds
, dc
, clippingArea
, progress_bar_chunk_painter
);
347 public Rectangle
ProgressBarGetBackgroundContentRectagle (Rectangle bounds
)
349 GtkStyle style
= (GtkStyle
)Marshal
.PtrToStructure (gtk_widget_get_style (widgets
[(int)WidgetType
.ProgressBar
]), typeof(GtkStyle
));
350 bounds
.Inflate (-style
.xthickness
, -style
.ythickness
);
355 public void RadioButtonPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, GtkPlusToggleButtonValue
value)
357 radio_button_painter
.Configure (state
, value);
358 Paint (WidgetType
.RadioButton
, bounds
, dc
, clippingArea
, radio_button_painter
);
360 public Size
RadioButtonGetSize ()
362 return GetGtkCheckButtonIndicatorSize (WidgetType
.RadioButton
);
366 public void ScrollBarPaintArrowButton (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, bool horizontal
, bool upOrLeft
)
368 scroll_bar_arrow_button_painter
.Configure (state
, horizontal
, upOrLeft
);
369 Paint (horizontal
? WidgetType
.HScrollBar
: WidgetType
.VScrollBar
, bounds
, dc
, clippingArea
, scroll_bar_arrow_button_painter
);
371 public void ScrollBarPaintThumbButton (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, bool horizontal
)
373 scroll_bar_thumb_button_painter
.Configure (state
, horizontal
);
374 Paint (horizontal
? WidgetType
.HScrollBar
: WidgetType
.VScrollBar
, bounds
, dc
, clippingArea
, scroll_bar_thumb_button_painter
);
376 public void ScrollBarPaintTrack (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, bool horizontal
, bool upOrLeft
)
378 scroll_bar_track_painter
.Configure (state
, upOrLeft
);
379 Paint (horizontal
? WidgetType
.HScrollBar
: WidgetType
.VScrollBar
, bounds
, dc
, clippingArea
, scroll_bar_track_painter
);
383 public void StatusBarPaintGripper (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
385 Paint (WidgetType
.StatusBar
, bounds
, dc
, clippingArea
, status_bar_gripper_painter
);
389 public void TabControlPaintPane (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
391 Paint (WidgetType
.TabControl
, bounds
, dc
, clippingArea
, tab_control_pane_painter
);
393 public void TabControlPaintTabItem (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
)
395 tab_control_tab_item_painter
.Configure (state
);
396 Paint (WidgetType
.TabControl
, bounds
, dc
, clippingArea
, tab_control_tab_item_painter
);
400 public void TextBoxPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle excludedArea
, GtkPlusState state
)
402 text_box_painter
.Configure (state
);
403 PaintExcludingArea (WidgetType
.TextBox
, bounds
, dc
, excludedArea
, text_box_painter
);
407 public void ToolBarPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
409 Paint (WidgetType
.ToolBar
, bounds
, dc
, clippingArea
, tool_bar_painter
);
411 public void ToolBarPaintButton (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
)
413 tool_bar_button_painter
.Configure (state
);
414 Paint (WidgetTypeNotNeeded
, bounds
, dc
, clippingArea
, tool_bar_button_painter
);
416 public void ToolBarPaintCheckedButton (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
)
418 Paint (WidgetTypeNotNeeded
, bounds
, dc
, clippingArea
, tool_bar_checked_button_painter
);
422 public void TrackBarPaintTrack (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, bool horizontal
)
424 Paint (horizontal
? WidgetType
.HorizontalTrackBar
: WidgetType
.VerticalTrackBar
, bounds
, dc
, clippingArea
, track_bar_track_painter
);
426 public void TrackBarPaintThumb (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, GtkPlusState state
, bool horizontal
)
428 track_bar_thumb_painter
.Configure (state
, horizontal
);
429 Paint (horizontal
? WidgetType
.HorizontalTrackBar
: WidgetType
.VerticalTrackBar
, bounds
, dc
, clippingArea
, track_bar_thumb_painter
);
433 public void TreeViewPaintGlyph (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, bool closed
)
435 tree_view_glyph_painter
.Configure (closed
);
436 Paint (WidgetType
.TreeView
, bounds
, dc
, clippingArea
, tree_view_glyph_painter
);
440 public void UpDownPaint (IDeviceContext dc
, Rectangle bounds
, Rectangle clippingArea
, bool up
, GtkPlusState state
)
442 up_down_painter
.Configure (up
, state
);
443 Paint (WidgetType
.UpDown
, bounds
, dc
, clippingArea
, up_down_painter
);
448 void Paint (WidgetType widgetType
, Rectangle bounds
, IDeviceContext dc
, Rectangle clippingArea
, Painter painter
)
450 Paint (widgetType
, bounds
, dc
, TransparencyType
.Alpha
, Color
.Black
, DeviceContextType
.Native
, clippingArea
, painter
, Rectangle
.Empty
);
452 void PaintExcludingArea (WidgetType widgetType
, Rectangle bounds
, IDeviceContext dc
, Rectangle excludedArea
, Painter painter
)
454 Paint (widgetType
, bounds
, dc
, TransparencyType
.Alpha
, Color
.Black
, DeviceContextType
.Native
, bounds
, painter
, excludedArea
);
456 void Paint (WidgetType widgetType
, Rectangle bounds
, IDeviceContext dc
, TransparencyType transparencyType
, Color background
, DeviceContextType deviceContextType
, Rectangle clippingArea
, Painter painter
, Rectangle excludedArea
)
458 Rectangle painted_area
= Rectangle
.Intersect (bounds
, clippingArea
);
459 if (painted_area
.Width
== 0 || painted_area
.Height
== 0)
461 painted_area
.Offset (-bounds
.X
, -bounds
.Y
);
462 excludedArea
.Offset (-bounds
.X
, -bounds
.Y
);
463 GdkDrawablePointer drawable
= gdk_pixmap_new (IntPtr
.Zero
, bounds
.Width
, bounds
.Height
, 24);
464 painter
.AttachStyle (widgetType
, drawable
, this);
465 GdkPixbufPointer pixbuf
;
468 GdkGCPointer gc
= gdk_gc_new (drawable
);
469 GdkColor color
= new GdkColor (background
);
470 gdk_gc_set_rgb_fg_color (gc
, ref color
);
471 Paint (drawable
, gc
, bounds
, widgetType
, out pixbuf
, out pixel_data
, out rowstride
, painted_area
, painter
, excludedArea
);
472 GdkPixbufPointer white_pixbuf
= IntPtr
.Zero
;
473 IntPtr white_pixel_data
= IntPtr
.Zero
;
474 int white_rowstride
= 0;
475 GdkColor white_color
= new GdkColor();
476 if (transparencyType
== TransparencyType
.Alpha
) {
477 white_color
.red
= guint16
.MaxValue
;
478 white_color
.green
= guint16
.MaxValue
;
479 white_color
.blue
= guint16
.MaxValue
;
480 gdk_gc_set_rgb_fg_color (gc
, ref white_color
);
481 Paint (drawable
, gc
, bounds
, widgetType
, out white_pixbuf
, out white_pixel_data
, out white_rowstride
, painted_area
, painter
, excludedArea
);
485 byte* row
= (byte*)pixel_data
;
487 byte* white_row
= (byte*)white_pixel_data
;
490 for (int row_index
= 0; row_index
< painted_area
.Height
; row_index
++) {
492 white_pixel
= white_row
;
493 for (int pixel_index
= 0; pixel_index
< painted_area
.Width
; pixel_index
++) {
494 const int GdkRedOffset
= 0;
495 const int GdkGreenOffset
= 1;
496 const int GdkBlueOffset
= 2;
497 const int BitmapAlphaOffset
= 3;
498 const int BitmapRedOffset
= 2;
499 const int BitmapBlueOffset
= 0;
500 switch (transparencyType
) {
501 case TransparencyType
.Alpha
:
502 pixel
[BitmapAlphaOffset
] = (byte)(pixel
[GdkRedOffset
] - white_pixel
[GdkRedOffset
] + byte.MaxValue
);
504 case TransparencyType
.Color
:
506 pixel
[GdkRedOffset
] == background
.R
&&
507 pixel
[GdkGreenOffset
] == background
.G
&&
508 pixel
[GdkBlueOffset
] == background
.B
) {
509 const int AlphaFullyTransparent
= 0;
510 pixel
[BitmapAlphaOffset
] = AlphaFullyTransparent
;
515 byte temporary
= pixel
[GdkRedOffset
];
516 pixel
[BitmapBlueOffset
] = pixel
[GdkBlueOffset
];
517 pixel
[BitmapRedOffset
] = temporary
;
519 const int PixelSize
= 4;
521 white_pixel
+= PixelSize
;
524 white_row
+= white_rowstride
;
527 if (transparencyType
== TransparencyType
.Alpha
)
528 g_object_unref (white_pixbuf
);
529 g_object_unref (drawable
);
530 Bitmap bitmap
= new Bitmap (painted_area
.Width
, painted_area
.Height
, rowstride
, PixelFormat
.Format32bppPArgb
, pixel_data
);
533 bool graphics_is_from_hdc
= false;
535 switch (deviceContextType
) {
536 case DeviceContextType
.Graphics
:
539 case DeviceContextType
.Native
:
540 g
= Graphics
.FromHdc (dc
.GetHdc ());
546 graphics_is_from_hdc
= true;
547 g
= Graphics
.FromHdc (dc
.GetHdc ());
549 graphics_is_from_hdc
= false;
555 painted_area
.Offset (bounds
.X
, bounds
.Y
);
556 g
.DrawImage (bitmap
, painted_area
.Location
);
557 switch (deviceContextType
) {
558 case DeviceContextType
.Graphics
:
560 case DeviceContextType
.Native
:
566 if (graphics_is_from_hdc
) {
574 g_object_unref (pixbuf
);
576 void Paint (GdkDrawablePointer drawable
, GdkGCPointer gc
, Rectangle rectangle
, WidgetType widgetType
, out GdkPixbufPointer pixbuf
, out IntPtr pixelData
, out int rowstride
, Rectangle clippingArea
, Painter painter
, Rectangle excludedArea
)
578 gdk_draw_rectangle (drawable
, gc
, true, clippingArea
.X
, clippingArea
.Y
, clippingArea
.Width
, clippingArea
.Height
);
579 painter
.Paint (styles
[(int)widgetType
], drawable
, new GdkRectangle(clippingArea
), widgets
[(int)widgetType
], 0, 0, rectangle
.Width
, rectangle
.Height
, this);
580 if (excludedArea
.Width
!= 0)
581 gdk_draw_rectangle (drawable
, gc
, true, excludedArea
.X
, excludedArea
.Y
, excludedArea
.Width
, excludedArea
.Height
);
583 (pixbuf
= gdk_pixbuf_new (GdkColorspace
.GDK_COLORSPACE_RGB
, true, 8, clippingArea
.Width
, clippingArea
.Height
)) == IntPtr
.Zero
||
584 gdk_pixbuf_get_from_drawable (pixbuf
, drawable
, IntPtr
.Zero
, clippingArea
.X
, clippingArea
.Y
, 0, 0, clippingArea
.Width
, clippingArea
.Height
) == IntPtr
.Zero
)
585 throw new OutOfMemoryException ();
586 pixelData
= gdk_pixbuf_get_pixels (pixbuf
);
587 rowstride
= gdk_pixbuf_get_rowstride (pixbuf
);
589 abstract class Painter
591 public virtual void AttachStyle (WidgetType widgetType
, GdkDrawablePointer drawable
, GtkPlus gtkPlus
)
593 gtkPlus
.styles
[(int)widgetType
] = gtk_style_attach (gtkPlus
.styles
[(int)widgetType
], drawable
);
595 public abstract void Paint (GtkStylePointer style
, GdkWindowPointer window
, GdkRectangle area
, GtkWidgetPointer widget
, gint x
, gint y
, gint width
, gint height
, GtkPlus gtkPlus
);
597 enum TransparencyType
603 enum DeviceContextType
612 class ButtonPainter
: Painter
616 public void Configure (bool @default, GtkPlusState state
) {
617 this.@default = @default;
620 public override void Paint (GtkStylePointer style
, GdkWindowPointer window
, GdkRectangle area
, GtkWidgetPointer widget
, gint x
, gint y
, gint width
, gint height
, GtkPlus gtkPlus
)
623 gtk_window_set_default (gtkPlus
.window
, widget
);
627 GtkStateType
.GTK_STATE_NORMAL
,
628 GtkShadowType
.GTK_SHADOW_IN
,
632 x
, y
, width
, height
);
633 gtk_window_set_default (gtkPlus
.window
, IntPtr
.Zero
);
639 state
== GtkPlusState
.Pressed
? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
,
643 x
, y
, width
, height
);
647 #region CheckBox, RadioButton
648 abstract class ToggleButtonPainter
: Painter
651 GtkPlusToggleButtonValue
value;
652 public void Configure (GtkPlusState state
, GtkPlusToggleButtonValue
value)
657 public override void Paint (GtkStylePointer style
, GdkWindowPointer window
, GdkRectangle area
, GtkWidgetPointer widget
, gint x
, gint y
, gint width
, gint height
, GtkPlus gtkPlus
)
663 (GtkShadowType
)value,
669 protected abstract string Detail { get; }
670 protected abstract ToggleButtonPaintFunction PaintFunction { get; }
672 delegate void ToggleButtonPaintFunction (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, gint x
, gint y
, gint width
, gint height
);
673 class CheckBoxPainter
: ToggleButtonPainter
675 protected override string Detail
{
677 return "checkbutton";
680 protected override ToggleButtonPaintFunction PaintFunction
{
682 return gtk_paint_check
;
686 class RadioButtonPainter
: ToggleButtonPainter
688 protected override string Detail
{
690 return "radiobutton";
693 protected override ToggleButtonPaintFunction PaintFunction
{
695 return gtk_paint_option
;
702 class ComboBoxDropDownButtonPainter
: Painter
705 public void Configure (GtkPlusState state
)
709 public override void AttachStyle (WidgetType widgetType
, IntPtr drawable
, GtkPlus gtkPlus
)
711 gtkPlus
.combo_box_drop_down_toggle_button_style
= gtk_style_attach (gtkPlus
.combo_box_drop_down_toggle_button_style
, drawable
);
712 gtkPlus
.combo_box_drop_down_arrow_style
= gtk_style_attach (gtkPlus
.combo_box_drop_down_arrow_style
, drawable
);
714 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
716 GtkShadowType shadow_type
;
718 case GtkPlusState
.Disabled
:
719 shadow_type
= GtkShadowType
.GTK_SHADOW_ETCHED_IN
;
721 case GtkPlusState
.Pressed
:
722 shadow_type
= GtkShadowType
.GTK_SHADOW_IN
;
725 shadow_type
= GtkShadowType
.GTK_SHADOW_OUT
;
729 gtkPlus
.combo_box_drop_down_toggle_button_style
,
734 gtkPlus
.combo_box_drop_down_toggle_button
,
736 x
, y
, width
, height
);
737 GtkMisc misc
= (GtkMisc
)Marshal
.PtrToStructure (gtkPlus
.combo_box_drop_down_arrow
, typeof (GtkMisc
));
738 int extent
= (int)(Math
.Min (width
- misc
.xpad
* 2, height
- misc
.ypad
* 2) * GetWidgetStyleSingle (gtkPlus
.combo_box_drop_down_arrow
, "arrow-scaling"));
740 gtkPlus
.combo_box_drop_down_arrow_style
,
743 GtkShadowType
.GTK_SHADOW_NONE
,
745 gtkPlus
.combo_box_drop_down_arrow
,
747 GtkArrowType
.GTK_ARROW_DOWN
,
749 (int)Math
.Floor (x
+ misc
.xpad
+ (width
- extent
) * misc
.xalign
),
750 (int)Math
.Floor (y
+ misc
.ypad
+ (height
- extent
) * misc
.yalign
),
754 class ComboBoxBorderPainter
: Painter
756 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
761 GtkStateType
.GTK_STATE_NORMAL
,
762 GtkShadowType
.GTK_SHADOW_IN
,
766 x
, y
, width
, height
);
772 class GroupBoxPainter
: Painter
775 public void Configure (GtkPlusState state
)
779 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
785 GtkShadowType
.GTK_SHADOW_ETCHED_IN
,
789 x
, y
, width
, height
);
795 class HeaderPainter
: Painter
798 public void Configure (GtkPlusState state
)
802 public override void AttachStyle (WidgetType widgetType
, IntPtr drawable
, GtkPlus gtkPlus
)
804 gtkPlus
.tree_view_column_button_style
= gtk_style_attach (gtkPlus
.tree_view_column_button_style
, drawable
);
806 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
809 gtkPlus
.tree_view_column_button_style
,
812 state
== GtkPlusState
.Pressed
? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
,
814 gtkPlus
.tree_view_column_button
,
816 x
, y
, width
, height
);
821 class ProgressBarBarPainter
: Painter
823 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
828 GtkStateType
.GTK_STATE_NORMAL
,
829 GtkShadowType
.GTK_SHADOW_IN
,
833 x
, y
, width
, height
);
836 class ProgressBarChunkPainter
: Painter
838 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
843 GtkStateType
.GTK_STATE_PRELIGHT
,
844 GtkShadowType
.GTK_SHADOW_OUT
,
848 x
, y
, width
, height
);
853 class ScrollBarArrowButtonPainter
: Painter
858 public void Configure (GtkPlusState state
, bool horizontal
, bool upOrLeft
)
861 this.horizontal
= horizontal
;
862 up_or_left
= upOrLeft
;
864 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
867 g_object_get (widget
, "can-focus", out can_focus
, IntPtr
.Zero
);
869 int focus_line_width
;
871 gtk_widget_style_get (widget
,
872 "focus-line-width", out focus_line_width
,
873 "focus-padding", out focus_padding
,
875 int focus_width
= focus_line_width
+ focus_padding
;
878 height
-= 2 * focus_width
;
881 width
-= 2 * focus_width
;
884 GtkShadowType shadow_type
= state
== GtkPlusState
.Pressed
? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
;
885 string detail
= horizontal
? "hscrollbar" : "vscrollbar";
894 x
, y
, width
, height
);
899 if (state
== GtkPlusState
.Pressed
) {
900 int arrow_displacement_x
;
901 int arrow_displacement_y
;
902 gtk_widget_style_get (widget
,
903 "arrow-displacement-x", out arrow_displacement_x
,
904 "arrow-displacement-y", out arrow_displacement_y
,
906 x
+= arrow_displacement_x
;
907 y
+= arrow_displacement_y
;
917 horizontal
? up_or_left
? GtkArrowType
.GTK_ARROW_LEFT
: GtkArrowType
.GTK_ARROW_RIGHT
: up_or_left
? GtkArrowType
.GTK_ARROW_UP
: GtkArrowType
.GTK_ARROW_DOWN
,
919 x
, y
, width
, height
);
922 abstract class RangeThumbButtonPainter
: Painter
926 protected bool Horizontal
{
927 get { return horizontal; }
929 public void Configure (GtkPlusState state
, bool horizontal
)
932 this.horizontal
= horizontal
;
934 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
940 state
== GtkPlusState
.Pressed
&& GetWidgetStyleBoolean (widget
, "activate-slider") ? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
,
945 horizontal
? GtkOrientation
.GTK_ORIENTATION_HORIZONTAL
: GtkOrientation
.GTK_ORIENTATION_VERTICAL
);
947 protected abstract string Detail { get; }
949 class ScrollBarThumbButtonPainter
: RangeThumbButtonPainter
951 protected override string Detail
{
957 class ScrollBarTrackPainter
: Painter
961 public void Configure (GtkPlusState state
, bool upOrLeft
)
964 up_or_left
= upOrLeft
;
966 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
971 state
== GtkPlusState
.Pressed
? GtkStateType
.GTK_STATE_ACTIVE
: GtkStateType
.GTK_STATE_INSENSITIVE
,
972 GtkShadowType
.GTK_SHADOW_IN
,
975 GetWidgetStyleBoolean (widget
, "trough-side-details") ?
976 up_or_left
? "trough-upper" : "trough-lower" :
978 x
, y
, width
, height
);
983 class StatusBarGripperPainter
: Painter
985 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
987 gtk_paint_resize_grip (
990 GtkStateType
.GTK_STATE_NORMAL
,
994 GdkWindowEdge
.GDK_WINDOW_EDGE_SOUTH_EAST
,
995 x
, y
, width
, height
);
1000 class TabControlPanePainter
: Painter
1002 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1007 GtkStateType
.GTK_STATE_NORMAL
,
1008 GtkShadowType
.GTK_SHADOW_OUT
,
1012 x
, y
, width
, height
,
1013 GtkPositionType
.GTK_POS_TOP
,
1018 class TabControlTabItemPainter
: Painter
1021 public void Configure (GtkPlusState state
)
1025 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1027 gtk_paint_extension (
1030 (GtkStateType
)state
,
1031 GtkShadowType
.GTK_SHADOW_OUT
,
1035 x
, y
, width
, height
,
1036 GtkPositionType
.GTK_POS_BOTTOM
);
1041 class TextBoxPainter
: Painter
1044 public void Configure (GtkPlusState state
)
1048 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1053 GtkStateType
.GTK_STATE_NORMAL
,
1054 GtkShadowType
.GTK_SHADOW_IN
,
1058 x
, y
, width
, height
);
1059 GtkStyle style_structure
= (GtkStyle
)Marshal
.PtrToStructure (style
, typeof (GtkStyle
));
1060 x
+= style_structure
.xthickness
;
1061 y
+= style_structure
.ythickness
;
1062 width
-= 2 * style_structure
.xthickness
;
1063 height
-= 2 * style_structure
.ythickness
;
1064 gtk_paint_flat_box (
1067 (GtkStateType
)state
,
1068 GtkShadowType
.GTK_SHADOW_NONE
,
1072 x
, y
, width
, height
);
1077 class ToolBarPainter
: Painter
1079 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1084 GtkStateType
.GTK_STATE_NORMAL
,
1085 GetWidgetStyleShadowType (widget
),
1089 x
, y
, width
, height
);
1092 class ToolBarButtonPainter
: Painter
1095 public void Configure (GtkPlusState state
) {
1098 public override void AttachStyle (WidgetType widgetType
, IntPtr drawable
, GtkPlus gtkPlus
)
1100 gtkPlus
.tool_bar_button_style
= gtk_style_attach (gtkPlus
.tool_bar_button_style
, drawable
);
1102 public override void Paint (GtkStylePointer style
, GdkWindowPointer window
, GdkRectangle area
, GtkWidgetPointer widget
, gint x
, gint y
, gint width
, gint height
, GtkPlus gtkPlus
)
1105 gtkPlus
.tool_bar_button_style
,
1107 (GtkStateType
)state
,
1108 state
== GtkPlusState
.Pressed
? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
,
1110 gtkPlus
.tool_bar_button
,
1112 x
, y
, width
, height
);
1115 class ToolBarCheckedButtonPainter
: Painter
1117 public override void AttachStyle (WidgetType widgetType
, IntPtr drawable
, GtkPlus gtkPlus
)
1119 gtkPlus
.tool_bar_toggle_button_style
= gtk_style_attach (gtkPlus
.tool_bar_toggle_button_style
, drawable
);
1121 public override void Paint (GtkStylePointer style
, GdkWindowPointer window
, GdkRectangle area
, GtkWidgetPointer widget
, gint x
, gint y
, gint width
, gint height
, GtkPlus gtkPlus
)
1124 gtkPlus
.tool_bar_toggle_button_style
,
1126 GtkStateType
.GTK_STATE_ACTIVE
,
1127 GtkShadowType
.GTK_SHADOW_IN
,
1129 gtkPlus
.tool_bar_toggle_button
,
1131 x
, y
, width
, height
);
1136 class TrackBarTrackPainter
: Painter
1138 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1143 GtkStateType
.GTK_STATE_ACTIVE
,
1144 GtkShadowType
.GTK_SHADOW_IN
,
1148 x
, y
, width
, height
);
1151 class TrackBarThumbPainter
: RangeThumbButtonPainter
1153 protected override string Detail
{
1155 return Horizontal
? "hscale" : "vscale";
1161 class TreeViewGlyphPainter
: Painter
1164 public void Configure (bool closed
)
1166 this.closed
= closed
;
1168 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1170 gtk_paint_expander (
1173 GtkStateType
.GTK_STATE_NORMAL
,
1179 closed
? GtkExpanderStyle
.GTK_EXPANDER_COLLAPSED
: GtkExpanderStyle
.GTK_EXPANDER_EXPANDED
);
1184 class UpDownPainter
: Painter
1188 public void Configure (bool up
, GtkPlusState state
)
1193 public override void Paint (IntPtr style
, IntPtr window
, GdkRectangle area
, IntPtr widget
, int x
, int y
, int width
, int height
, GtkPlus gtkPlus
)
1195 GtkShadowType shadow_type
= GetWidgetStyleShadowType (widget
);
1196 if (shadow_type
!= GtkShadowType
.GTK_SHADOW_NONE
)
1200 GtkStateType
.GTK_STATE_NORMAL
,
1205 x
, y
- (up
? 0 : height
), width
, height
* 2);
1206 shadow_type
= state
== GtkPlusState
.Pressed
? GtkShadowType
.GTK_SHADOW_IN
: GtkShadowType
.GTK_SHADOW_OUT
;
1210 (GtkStateType
)state
,
1214 up
? "spinbutton_up" : "spinbutton_down",
1215 x
, y
, width
, height
);
1223 int h
= (w
+ 1) / 2;
1224 x
+= (width
- w
) / 2;
1225 y
+= (height
- h
) / 2;
1231 (GtkStateType
)state
,
1236 up
? GtkArrowType
.GTK_ARROW_UP
: GtkArrowType
.GTK_ARROW_DOWN
,
1238 x
, y
, width
, height
);
1243 #region Widget types
1244 const WidgetType WidgetTypeNotNeeded
= (WidgetType
)0;
1271 #region GTK+ utility methods
1272 static GtkShadowType
GetWidgetStyleShadowType (GtkWidgetPointer widget
)
1274 GtkShadowType result
;
1275 gtk_widget_style_get (widget
, "shadow-type", out result
, IntPtr
.Zero
);
1278 static int GetWidgetStyleInteger (GtkWidgetPointer widget
, string propertyName
)
1281 gtk_widget_style_get (widget
, propertyName
, out result
, IntPtr
.Zero
);
1285 static float GetWidgetStyleSingle (GtkWidgetPointer widget
, string propertyName
)
1288 gtk_widget_style_get (widget
, propertyName
, out result
, IntPtr
.Zero
);
1292 static bool GetWidgetStyleBoolean (GtkWidgetPointer widget
, string propertyName
)
1295 gtk_widget_style_get (widget
, propertyName
, out result
, IntPtr
.Zero
);
1298 #region GetFirstChildWidgetOfType
1300 static class GetFirstChildWidgetOfType
1302 public static GtkWidgetPointer
Get (GtkContainerPointer parent
, GType childType
)
1305 Result
= GtkWidgetPointer
.Zero
;
1306 ContainersToSearch
= new ArrayList ();
1307 ContainersToSearch
.Add (parent
);
1309 ArrayList containers_to_search
= ContainersToSearch
;
1310 ContainersToSearch
= new ArrayList ();
1311 foreach (GtkContainerPointer container
in containers_to_search
) {
1312 gtk_widget_realize (container
);
1313 gtk_container_forall (container
, Callback
, gpointer
.Zero
);
1314 if (Result
!= GtkWidgetPointer
.Zero
)
1317 if (ContainersToSearch
.Count
== 0)
1318 return GtkWidgetPointer
.Zero
;
1321 static void Callback (GtkWidgetPointer widget
, gpointer data
)
1323 if (Result
!= IntPtr
.Zero
)
1325 if (g_type_check_instance_is_a (widget
, Type
))
1327 else if (g_type_check_instance_is_a (widget
, gtk_container_get_type ()))
1328 ContainersToSearch
.Add (widget
);
1331 static GtkWidgetPointer Result
;
1332 static ArrayList ContainersToSearch
;
1336 static GtkStylePointer
GetWidgetStyle (GtkWidgetPointer widget
)
1338 return gtk_rc_get_style (widget
);
1341 #region Platform Invoke
1342 #region Library names
1343 #if VISUAL_STYLES_USE_GTKPLUS_ON_WINDOWS
1344 const string GobjectLibraryName
= "libgobject-2.0-0.dll";
1345 const string GdkLibraryName
= "libgdk-win32-2.0-0.dll";
1346 const string GdkPixbufLibraryName
= "libgdk_pixbuf-2.0-0.dll";
1347 const string GtkLibraryName
= "libgtk-win32-2.0-0.dll";
1349 const string GobjectLibraryName
= "libgobject-2.0.so";
1350 const string GdkLibraryName
= "libgdk-x11-2.0.so";
1351 const string GdkPixbufLibraryName
= "libgdk_pixbuf-2.0.so";
1352 const string GtkLibraryName
= "libgtk-x11-2.0.so";
1356 [DllImport (GdkLibraryName
)]
1357 static extern void gdk_draw_rectangle (GdkDrawablePointer drawable
, GdkGCPointer gc
, gboolean filled
, gint x
, gint y
, gint width
, gint height
);
1358 [DllImport (GdkLibraryName
)]
1359 static extern GdkGCPointer
gdk_gc_new (GdkDrawablePointer drawable
);
1360 [DllImport (GdkLibraryName
)]
1361 static extern void gdk_gc_set_rgb_fg_color (GdkGCPointer gc
, ref GdkColor color
);
1362 [DllImport (GdkLibraryName
)]
1363 static extern GdkPixbufPointer
gdk_pixbuf_get_from_drawable (GdkPixbufPointer dest
, GdkDrawablePointer src
, GdkColormapPointer cmap
, int src_x
, int src_y
, int dest_x
, int dest_y
, int width
, int height
);
1364 [DllImport (GdkLibraryName
)]
1365 static extern GdkPixmapPointer
gdk_pixmap_new (GdkDrawablePointer drawable
, gint width
, gint height
, gint depth
);
1367 public guint32 pixel
;
1369 public guint16 green
;
1370 public guint16 blue
;
1371 public GdkColor (Color
value)
1374 red
= (guint16
)(value.R
<< 8);
1375 green
= (guint16
)(value.G
<< 8);
1376 blue
= (guint16
)(value.B
<< 8);
1379 internal struct GdkRectangle
{
1384 public GdkRectangle (Rectangle
value)
1388 width
= value.Width
;
1389 height
= value.Height
;
1394 [DllImport (GdkPixbufLibraryName
)]
1395 static extern IntPtr
gdk_pixbuf_get_pixels (GdkPixbufPointer pixbuf
);
1396 [DllImport (GdkPixbufLibraryName
)]
1397 static extern int gdk_pixbuf_get_rowstride (GdkPixbufPointer pixbuf
);
1398 [DllImport (GdkPixbufLibraryName
)]
1399 static extern GdkPixbufPointer
gdk_pixbuf_new (GdkColorspace colorspace
, gboolean has_alpha
, int bits_per_sample
, int width
, int height
);
1407 [DllImport (GtkLibraryName
)]
1408 static extern gboolean
gtk_init_check (ref int argc
, ref string[] argv
);
1409 [DllImport (GtkLibraryName
)]
1410 static extern IntPtr
gtk_check_version (guint required_major
, guint required_minor
, guint required_micro
);
1411 [DllImport (GtkLibraryName
)]
1412 static extern void gtk_container_add (GtkContainerPointer container
, GtkWidgetPointer widget
);
1414 [DllImport (GtkLibraryName
)]
1415 static extern void gtk_container_forall (GtkContainerPointer container
, GtkCallback callback
, gpointer callback_data
);
1416 [UnmanagedFunctionPointer (CallingConvention
.Cdecl
)]
1417 delegate void GtkCallback (GtkWidgetPointer widget
, gpointer data
);
1419 [DllImport (GtkLibraryName
)]
1420 static extern void gtk_object_destroy (GtkObjectPointer
@object);
1421 [DllImport (GtkLibraryName
)]
1422 static extern GtkStylePointer
gtk_rc_get_style (GtkWidgetPointer widget
);
1423 [DllImport (GtkLibraryName
)]
1424 static extern GtkStylePointer
gtk_style_attach (GtkStylePointer style
, GdkWindowPointer window
);
1426 [DllImport (GtkLibraryName
)]
1427 static extern void gtk_widget_realize (GtkWidgetPointer widget
);
1429 [DllImport (GtkLibraryName
)]
1430 static extern void gtk_widget_style_get (GtkWidgetPointer widget
, string property
, out gint
value, IntPtr nullTerminator
);
1432 [DllImport (GtkLibraryName
)]
1433 static extern void gtk_widget_style_get (GtkWidgetPointer widget
, string property
, out gfloat
value, IntPtr nullTerminator
);
1435 [DllImport (GtkLibraryName
)]
1436 static extern void gtk_widget_style_get (GtkWidgetPointer widget
, string property1
, out gint value1
, string property2
, out gint value2
, IntPtr nullTerminator
);
1437 [DllImport (GtkLibraryName
)]
1438 static extern void gtk_widget_style_get (GtkWidgetPointer widget
, string property
, out GtkShadowType
value, IntPtr nullTerminator
);
1439 [DllImport (GtkLibraryName
)]
1440 static extern void gtk_widget_style_get (GtkWidgetPointer widget
, string property
, out gboolean
value, IntPtr nullTerminator
);
1441 [DllImport (GtkLibraryName
)]
1442 static extern GtkWidgetPointer
gtk_window_new (GtkWindowType type
);
1443 [DllImport (GtkLibraryName
)]
1444 static extern void gtk_window_set_default (GtkWindowPointer window
, GtkWidgetPointer default_widget
);
1445 [DllImport (GtkLibraryName
)]
1446 static extern GtkObjectPointer
gtk_adjustment_new (gdouble
value, gdouble lower
, gdouble upper
, gdouble step_increment
, gdouble page_increment
, gdouble page_size
);
1447 [DllImport (GtkLibraryName
)]
1448 static extern GtkStylePointer
gtk_widget_get_style (GtkWidgetPointer widget
);
1449 [DllImport (GtkLibraryName
)]
1450 static extern GtkTreeViewColumnPointer
gtk_tree_view_column_new ();
1451 [DllImport (GtkLibraryName
)]
1452 static extern gint
gtk_tree_view_insert_column (
1453 GtkTreeViewPointer tree_view
,
1454 GtkTreeViewColumnPointer column
,
1456 [DllImport (GtkLibraryName
)]
1457 static extern void gtk_toolbar_insert (
1458 GtkToolbarPointer toolbar
,
1459 GtkToolItemPointer item
,
1461 [DllImport (GtkLibraryName
)]
1462 static extern GtkWidgetPointer
gtk_bin_get_child (GtkBinPointer bin
);
1465 [DllImport (GtkLibraryName
)]
1466 static extern GType
gtk_arrow_get_type ();
1467 [DllImport (GtkLibraryName
)]
1468 static extern GType
gtk_container_get_type ();
1469 [DllImport (GtkLibraryName
)]
1470 static extern GType
gtk_toggle_button_get_type ();
1473 #region Widget creation
1474 [DllImport (GtkLibraryName
)]
1475 static extern GtkWidgetPointer
gtk_button_new ();
1476 [DllImport (GtkLibraryName
)]
1477 static extern GtkWidgetPointer
gtk_check_button_new ();
1479 [DllImport (GtkLibraryName
)]
1480 static extern GtkWidgetPointer
gtk_combo_box_entry_new ();
1482 [DllImport (GtkLibraryName
)]
1483 static extern GtkWidgetPointer
gtk_entry_new ();
1484 [DllImport (GtkLibraryName
)]
1485 static extern GtkWidgetPointer
gtk_fixed_new ();
1486 [DllImport (GtkLibraryName
)]
1487 static extern GtkWidgetPointer
gtk_frame_new (string label
);
1488 [DllImport (GtkLibraryName
)]
1489 static extern GtkWidgetPointer
gtk_hscale_new_with_range (gdouble min
, gdouble max
, gdouble step
);
1490 [DllImport (GtkLibraryName
)]
1491 static extern GtkWidgetPointer
gtk_hscrollbar_new (GtkAdjustmentPointer adjustment
);
1492 [DllImport (GtkLibraryName
)]
1493 static extern GtkWidgetPointer
gtk_notebook_new ();
1494 [DllImport (GtkLibraryName
)]
1495 static extern GtkWidgetPointer
gtk_progress_bar_new ();
1496 [DllImport (GtkLibraryName
)]
1497 static extern GtkWidgetPointer
gtk_radio_button_new (GSListPointer
group);
1498 [DllImport (GtkLibraryName
)]
1499 static extern GtkWidgetPointer
gtk_spin_button_new (GtkAdjustmentPointer adjustment
, gdouble climb_rate
, guint digits
);
1500 [DllImport (GtkLibraryName
)]
1501 static extern GtkWidgetPointer
gtk_statusbar_new ();
1502 [DllImport (GtkLibraryName
)]
1503 static extern GtkToolItemPointer
gtk_toggle_tool_button_new ();
1504 [DllImport (GtkLibraryName
)]
1505 static extern GtkWidgetPointer
gtk_toolbar_new ();
1506 [DllImport (GtkLibraryName
)]
1507 static extern GtkToolItemPointer
gtk_tool_button_new (
1508 GtkWidgetPointer icon_widget
,
1510 [DllImport (GtkLibraryName
)]
1511 static extern GtkWidgetPointer
gtk_tree_view_new ();
1512 [DllImport (GtkLibraryName
)]
1513 static extern GtkWidgetPointer
gtk_vscale_new_with_range (gdouble min
, gdouble max
, gdouble step
);
1514 [DllImport (GtkLibraryName
)]
1515 static extern GtkWidgetPointer
gtk_vscrollbar_new (GtkAdjustmentPointer adjustment
);
1518 [DllImport (GtkLibraryName
)]
1519 static extern void gtk_paint_arrow (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, GtkArrowType arrow_type
, gboolean fill
, gint x
, gint y
, gint width
, gint height
);
1520 [DllImport (GtkLibraryName
)]
1521 static extern void gtk_paint_box (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, gint x
, gint y
, gint width
, gint height
);
1522 [DllImport (GtkLibraryName
)]
1523 static extern void gtk_paint_box_gap (
1524 GtkStylePointer style
,
1525 GdkWindowPointer window
,
1526 GtkStateType state_type
,
1527 GtkShadowType shadow_type
,
1528 ref GdkRectangle area
,
1529 GtkWidgetPointer widget
,
1535 GtkPositionType gap_side
,
1538 [DllImport (GtkLibraryName
)]
1539 static extern void gtk_paint_check (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, gint x
, gint y
, gint width
, gint height
);
1540 [DllImport (GtkLibraryName
)]
1541 static extern void gtk_paint_expander (
1542 GtkStylePointer style
,
1543 GdkWindowPointer window
,
1544 GtkStateType state_type
,
1545 ref GdkRectangle area
,
1546 GtkWidgetPointer widget
,
1550 GtkExpanderStyle expander_style
);
1551 [DllImport (GtkLibraryName
)]
1552 static extern void gtk_paint_extension (
1553 GtkStylePointer style
,
1554 GdkWindowPointer window
,
1555 GtkStateType state_type
,
1556 GtkShadowType shadow_type
,
1557 ref GdkRectangle area
,
1558 GtkWidgetPointer widget
,
1564 GtkPositionType gap_side
);
1565 [DllImport (GtkLibraryName
)]
1566 static extern void gtk_paint_flat_box (
1567 GtkStylePointer style
,
1568 GdkWindowPointer window
,
1569 GtkStateType state_type
,
1570 GtkShadowType shadow_type
,
1571 ref GdkRectangle area
,
1572 GtkWidgetPointer widget
,
1578 [DllImport (GtkLibraryName
)]
1579 static extern void gtk_paint_option (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, gint x
, gint y
, gint width
, gint height
);
1580 [DllImport (GtkLibraryName
)]
1581 static extern void gtk_paint_resize_grip (
1582 GtkStylePointer style
,
1583 GdkWindowPointer window
,
1584 GtkStateType state_type
,
1585 ref GdkRectangle area
,
1586 GtkWidgetPointer widget
,
1593 [DllImport (GtkLibraryName
)]
1594 static extern void gtk_paint_shadow (GtkStylePointer style
, GdkWindowPointer window
, GtkStateType state_type
, GtkShadowType shadow_type
, ref GdkRectangle area
, GtkWidgetPointer widget
, string detail
, gint x
, gint y
, gint width
, gint height
);
1595 [DllImport (GtkLibraryName
)]
1596 static extern void gtk_paint_slider (
1597 GtkStylePointer style
,
1598 GdkWindowPointer window
,
1599 GtkStateType state_type
,
1600 GtkShadowType shadow_type
,
1601 ref GdkRectangle area
,
1602 GtkWidgetPointer widget
,
1608 GtkOrientation orientation
);
1611 #region Enumerations
1612 internal enum GtkShadowType
1617 GTK_SHADOW_ETCHED_IN
,
1618 GTK_SHADOW_ETCHED_OUT
1626 GTK_STATE_INSENSITIVE
1630 GTK_WINDOW_TOPLEVEL
,
1643 GTK_ORIENTATION_HORIZONTAL
,
1644 GTK_ORIENTATION_VERTICAL
1646 enum GtkExpanderStyle
1648 GTK_EXPANDER_COLLAPSED
,
1649 GTK_EXPANDER_SEMI_COLLAPSED
,
1650 GTK_EXPANDER_SEMI_EXPANDED
,
1651 GTK_EXPANDER_EXPANDED
1653 enum GtkPositionType
1660 enum GtkWidgetFlags
: uint
1662 GTK_CAN_DEFAULT
= 1 << 13,
1666 GDK_WINDOW_EDGE_NORTH_WEST
,
1667 GDK_WINDOW_EDGE_NORTH
,
1668 GDK_WINDOW_EDGE_NORTH_EAST
,
1669 GDK_WINDOW_EDGE_WEST
,
1670 GDK_WINDOW_EDGE_EAST
,
1671 GDK_WINDOW_EDGE_SOUTH_WEST
,
1672 GDK_WINDOW_EDGE_SOUTH
,
1673 GDK_WINDOW_EDGE_SOUTH_EAST
1679 #pragma warning disable 169
1680 GObject parent_instance
;
1681 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1683 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1685 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1687 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1689 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1691 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1693 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1695 [MarshalAs(UnmanagedType
.ByValArray
, SizeConst
=5)]
1699 PangoFontDescriptionPointer font_desc
;
1700 #pragma warning restore 169
1701 public gint xthickness
;
1702 public gint ythickness
;
1706 #pragma warning disable 169
1708 guint16 private_flags
;
1712 GtkStylePointer style
;
1713 GtkRequisition requisition
;
1714 #pragma warning restore 169
1715 public GtkAllocation allocation
;
1716 #pragma warning disable 169
1717 GdkWindowPointer window
;
1718 GtkWidgetPointer parent
;
1719 #pragma warning restore 169
1723 #pragma warning disable 169
1724 GInitiallyUnowned parent_instance
;
1725 #pragma warning restore 169
1726 public guint32 flags
;
1728 struct GtkRequisition
1730 #pragma warning disable 169
1733 #pragma warning restore 169
1737 #pragma warning disable 169
1739 #pragma warning restore 169
1740 public gfloat xalign
;
1741 public gfloat yalign
;
1742 public guint16 xpad
;
1743 public guint16 ypad
;
1745 struct GtkTreeViewColumn
1747 #pragma warning disable 169
1749 GtkWidgetPointer tree_view
;
1750 #pragma warning restore 169
1751 public GtkWidgetPointer button
;
1755 static void GTK_WIDGET_SET_FLAGS (GtkWidgetPointer wid
, GtkWidgetFlags flag
)
1757 GtkObject
@object = (GtkObject
)Marshal
.PtrToStructure (wid
, typeof (GtkObject
));
1758 @object.flags
|= (guint32
)flag
;
1759 Marshal
.StructureToPtr (@object, wid
, false);
1764 [DllImport (GobjectLibraryName
)]
1765 static extern gpointer
g_object_ref (gpointer
@object);
1766 [DllImport (GobjectLibraryName
)]
1767 static extern void g_object_unref (gpointer
@object);
1769 [DllImport (GobjectLibraryName
)]
1770 static extern gboolean
g_type_check_instance_is_a (GTypeInstancePointer type_instance
, GType iface_type
);
1772 [DllImport (GobjectLibraryName
)]
1773 static extern void g_object_get (gpointer
@object, string property_name
, out gboolean
value, IntPtr nullTerminator
);
1774 const int G_TYPE_FUNDAMENTAL_SHIFT
= 2;
1778 struct GTypeInstance
1780 #pragma warning disable 169
1781 GTypeClassPointer g_class
;
1782 #pragma warning restore 169
1784 internal struct GObject
1786 #pragma warning disable 169
1787 GTypeInstance g_type_instance
;
1790 #pragma warning restore 169
1795 #region Exposed constants
1796 enum GtkPlusToggleButtonValue
1798 Unchecked
= GtkPlus
.GtkShadowType
.GTK_SHADOW_OUT
,
1799 Mixed
= GtkPlus
.GtkShadowType
.GTK_SHADOW_ETCHED_IN
,
1800 Checked
= GtkPlus
.GtkShadowType
.GTK_SHADOW_IN