1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2006 Novell, Inc.
//
// Authors:
// Jordi Mas i Hernandez, jordi@ximian.com
// Alexander Olk, alex.olk@googlemail.com
//
// This is an experimental GTK theme.
//
// Comments:
// - For now we would keep all the themes in the same assembly to have
// handy the internals methods.
// - We are using Pinovoke for now to access GTK/GDK to avoid adding
// gtk-sharp as a SWF dependency
// - The ThemeGtk comes from ThemeWin32Classic, we use it as the default
// implementation for the methods that we are not taking care of.
// - When GDK is initialised it opens its own display. There is not way of changing it,
// then we use that display as SWF display
// - You can activate this Theme in Linux doing export MONO_THEME=gtk
// - GTK paints controls into a window not a device context. We should inverstigate if we
// we can encapsulate a dc in a gtkwindow.
// NOT COMPLETE
// TODO: fix position of button focus rectangle
//
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Reflection;
using System.Runtime.InteropServices;
namespace System.Windows.Forms
{
internal class ThemeGtk : ThemeWin32Classic
{
/* GTK enums */
internal enum StateType
{
Normal,
Active,
Prelight,
Selected,
Insensitive,
}
internal enum ShadowType
{
None,
In,
Out,
EtchedIn,
EtchedOut,
}
internal enum ArrowType
{
Up,
Down,
Left,
Right,
}
/* Structs */
[StructLayout(LayoutKind.Sequential)]
internal struct GdkColorStruct
{
internal int pixel;
internal short red;
internal short green;
internal short blue;
}
[StructLayout(LayoutKind.Sequential)]
internal struct GtkStyleStruct
{
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=12)]
internal byte[] obj; /* GObject is 12 bytes*/
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] fg;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] bg;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] light;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] dark;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] mid;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] text;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] baseclr;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5)]
internal GdkColorStruct[] text_aa; /* Halfway between text/base */
internal GdkColorStruct black;
internal GdkColorStruct white;
/* TODO: There is more stuff that we will add when we need it*/
}
/* GDK imports */
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_display_manager_get ();
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_display_manager_get_default_display (IntPtr display_manager);
[DllImport("libgdk-x11-2.0.so")]
internal static extern void gdk_display_manager_set_default_display (IntPtr display_manager, IntPtr display);
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_x11_display_get_xdisplay (IntPtr display);
[DllImport("libgdk-x11-2.0.so")]
static extern IntPtr gdk_window_foreign_new_for_display (IntPtr display, uint anid);
[DllImport("libgdk-x11-2.0.so")]
static extern bool gdk_init_check(out int argc, string argv);
/* GTK imports */
[DllImport("libgtk-x11-2.0.so")]
static extern bool gtk_init_check (out int argc, string argv);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_adjustment_new (double value, double lower, double upper, double step_increment, double page_increment, double page_size);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_rc_get_style (IntPtr widget);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_vscrollbar_new(IntPtr adjustment);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_hscrollbar_new(IntPtr adjustment);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_style_attach (IntPtr raw, IntPtr window);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_rc_style_new ();
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_invisible_new ();
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_widget_ensure_style (IntPtr raw);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_widget_get_style (IntPtr raw);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_style_detach (IntPtr raw);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_button_new ();
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_progress_bar_new ();
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_radio_button_new (IntPtr group);
[DllImport("libgtk-x11-2.0.so")]
static extern IntPtr gtk_check_button_new ();
/* GTK Drawing */
[DllImport("libgtk-x11-2.0.so")]
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);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_paint_arrow (IntPtr style, IntPtr window, int state_type, int shadow_type,
IntPtr area, IntPtr widget, string detail, int arrow_type, bool fill, int x, int y, int width, int height);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_paint_slider (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);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_paint_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_paint_flat_box (IntPtr style, IntPtr window, int state_type, int shadow_type,
IntPtr area, IntPtr widget, string detail, int x, int y, int width, int height);
[DllImport("libgtk-x11-2.0.so")]
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);
[DllImport("libgtk-x11-2.0.so")]
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);
[DllImport("libgtk-x11-2.0.so")]
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);
[DllImport("libgtk-x11-2.0.so")]
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);
[DllImport("libgtk-x11-2.0.so")]
static extern void gtk_widget_size_allocate (IntPtr widget, ref Rectangle allocation);
[DllImport("libgtk-x11-2.0.so")]
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);
/* Data */
static protected IntPtr dispmgr;
static protected IntPtr gdkdisplay;
static protected IntPtr widget;
static protected IntPtr style;
IntPtr global_gtk_button = IntPtr.Zero;
IntPtr global_gtk_button_style = IntPtr.Zero;
IntPtr global_gtk_vscrollbar = IntPtr.Zero;
IntPtr global_gtk_vscrollbar_style = IntPtr.Zero;
IntPtr global_gtk_hscrollbar = IntPtr.Zero;
IntPtr global_gtk_hscrollbar_style = IntPtr.Zero;
IntPtr global_gtk_progress_bar = IntPtr.Zero;
IntPtr global_gtk_progress_bar_style = IntPtr.Zero;
IntPtr global_gtk_radio_button = IntPtr.Zero;
IntPtr global_gtk_radio_button_style = IntPtr.Zero;
IntPtr global_gtk_check_button = IntPtr.Zero;
IntPtr global_gtk_check_button_style = IntPtr.Zero;
IntPtr current_gdk_window = IntPtr.Zero;
IntPtr current_style = IntPtr.Zero;
public static void InitGtk ()
{
Console.WriteLine ("ThemeGtk Init");
int argc = 0;
string argv = "";
gdk_init_check (out argc, argv);
dispmgr = gdk_display_manager_get ();
gdkdisplay = gdk_display_manager_get_default_display (dispmgr);
gtk_init_check (out argc, argv);
widget = gtk_invisible_new ();
gtk_widget_ensure_style (widget);
style = gtk_widget_get_style (widget);
XplatUIX11.GetInstance().SetDisplay (gdk_x11_display_get_xdisplay (gdkdisplay));
}
public void LoadSysDefaultColors ()
{
GtkStyleStruct style_struct;
style_struct = (GtkStyleStruct) Marshal.PtrToStructure (style, typeof (GtkStyleStruct));
defaultWindowBackColor = ColorFromGdkColor (style_struct.bg[0]);
defaultWindowForeColor = ColorFromGdkColor (style_struct.fg[0]);
}
public ThemeGtk () : base ()
{
Console.WriteLine ("ThemeGtk constructor");
InitGtk ();
default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
LoadSysDefaultColors ();
always_draw_hotkeys = true;
global_gtk_button = gtk_button_new();
gtk_widget_ensure_style (global_gtk_button);
global_gtk_button_style = gtk_rc_get_style (global_gtk_button);
IntPtr adj = gtk_adjustment_new (0, 0, 0, 0, 0, 0);
global_gtk_vscrollbar = gtk_vscrollbar_new (adj);
gtk_widget_ensure_style (global_gtk_vscrollbar);
global_gtk_vscrollbar_style = gtk_rc_get_style (global_gtk_vscrollbar);
global_gtk_hscrollbar = gtk_hscrollbar_new (adj);
gtk_widget_ensure_style (global_gtk_hscrollbar);
global_gtk_hscrollbar_style = gtk_rc_get_style (global_gtk_hscrollbar);
global_gtk_progress_bar = gtk_progress_bar_new ();
gtk_widget_ensure_style (global_gtk_progress_bar);
global_gtk_progress_bar_style = gtk_rc_get_style (global_gtk_progress_bar);
global_gtk_radio_button = gtk_radio_button_new (IntPtr.Zero);
gtk_widget_ensure_style (global_gtk_radio_button);
global_gtk_radio_button_style = gtk_rc_get_style (global_gtk_radio_button);
global_gtk_check_button = gtk_check_button_new ();
gtk_widget_ensure_style (global_gtk_check_button);
global_gtk_check_button_style = gtk_rc_get_style (global_gtk_check_button);
}
public override bool DoubleBufferingSupported {
get {return false; }
}
protected override void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
{
Rectangle buttonRectangle = button.ClientRectangle;
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) button.Handle);
IntPtr button_style = gtk_style_attach (global_gtk_button_style, gdkwindow); // need it
StateType state_type = StateType.Normal;
ShadowType shadow_type = button.flat_style == FlatStyle.Flat ? ShadowType.In : ShadowType.Out;
string detail = "buttondefault";
if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
state_type = StateType.Active;
shadow_type = ShadowType.In;
detail = "button";
} else
if (!button.is_enabled) {
state_type = StateType.Insensitive;
} else
if (button.is_pressed) {
state_type = StateType.Active;
shadow_type = ShadowType.In;
detail = "button";
} else
if (button.is_entered) {
state_type = StateType.Prelight;
}
if (button.flat_style == FlatStyle.Flat)
gtk_paint_flat_box (button_style, gdkwindow,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
IntPtr.Zero,
detail,
buttonRectangle.X, buttonRectangle.Y,
buttonRectangle.Width, buttonRectangle.Height);
else
if (button.flat_style != FlatStyle.Popup || (button.flat_style == FlatStyle.Popup && button.is_entered))
gtk_paint_box (button_style, gdkwindow,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
IntPtr.Zero,
detail,
buttonRectangle.X, buttonRectangle.Y,
buttonRectangle.Width, buttonRectangle.Height);
}
protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc ) {
if ( !button.is_enabled)
return;
Rectangle focus_rect = new Rectangle( button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9 );
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) button.Handle);
IntPtr button_style = gtk_style_attach (global_gtk_button_style, gdkwindow); // need it
gtk_paint_focus (button_style,
gdkwindow,
(int) StateType.Active,
IntPtr.Zero,
IntPtr.Zero,
"button",
focus_rect.X,
focus_rect.Y,
focus_rect.Width,
focus_rect.Height);
}
#region ScrollBar
public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
int scrollbutton_width = bar.scrollbutton_width;
int scrollbutton_height = bar.scrollbutton_height;
Rectangle first_arrow_area;
Rectangle second_arrow_area;
Rectangle thumb_pos;
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) bar.Handle);
IntPtr scrollbar_style;
Rectangle allocation = new Rectangle (bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, bar.ClientRectangle.Height);
// fix for artefacts
Color fix_color = bar.Parent != null ? bar.Parent.BackColor : ColorControl;
if (bar.vert) {
scrollbar_style = global_gtk_vscrollbar_style;
gtk_widget_size_allocate (global_gtk_vscrollbar, ref allocation);
// fix for artefacts
dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
bar.ClientRectangle.X, bar.ClientRectangle.Y, bar.ClientRectangle.Width, 3);
dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
bar.ClientRectangle.X, bar.ClientRectangle.Bottom - 4, bar.ClientRectangle.Width, 3);
} else {
scrollbar_style = global_gtk_hscrollbar_style;
gtk_widget_size_allocate (global_gtk_hscrollbar, ref allocation);
// fix for artefacts
dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
bar.ClientRectangle.X, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
dc.FillRectangle (ResPool.GetSolidBrush (fix_color),
bar.ClientRectangle.Right - 4, bar.ClientRectangle.Y, 3, bar.ClientRectangle.Height);
}
scrollbar_style = gtk_style_attach (scrollbar_style, gdkwindow); // need it
current_gdk_window = gdkwindow;
current_style = scrollbar_style;
thumb_pos = bar.ThumbPos;
if ( bar.vert ) {
first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
bar.FirstArrowArea = first_arrow_area;
second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
bar.SecondArrowArea = second_arrow_area;
thumb_pos.Width = bar.Width;
bar.ThumbPos = thumb_pos;
ScrollBar_Vertical_Draw_ThumbMoving_None (scrollbutton_height, bar, clip, dc);
/* Buttons */
if ( clip.IntersectsWith( first_arrow_area ) )
CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
if ( clip.IntersectsWith( second_arrow_area ) )
CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
} else {
first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
bar.FirstArrowArea = first_arrow_area;
second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
bar.SecondArrowArea = second_arrow_area;
thumb_pos.Height = bar.Height;
bar.ThumbPos = thumb_pos;
/* Background */
ScrollBar_Horizontal_Draw_ThumbMoving_None (scrollbutton_width, bar, clip, dc);
/* Buttons */
if ( clip.IntersectsWith( first_arrow_area ) )
CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
if ( clip.IntersectsWith( second_arrow_area ) )
CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
}
/* Thumb */
ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );
}
protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
if ( bar.Enabled)
DrawScrollBarThumb( dc, thumb_pos, bar );
}
protected override void ScrollBar_Vertical_Draw_ThumbMoving_None (int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc)
{
Rectangle r = new Rectangle (0,
scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
gtk_paint_box (current_style,
current_gdk_window,
(int) StateType.Active,
(int) ShadowType.In,
IntPtr.Zero,
global_gtk_vscrollbar,
"vscrollbar",
r.X, r.Y,
r.Width, r.Height);
}
protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None (int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc)
{
Rectangle r = new Rectangle (scrollbutton_width,
0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
gtk_paint_box (current_style,
current_gdk_window,
(int) StateType.Active,
(int) ShadowType.In,
IntPtr.Zero,
global_gtk_hscrollbar,
"hscrollbar",
r.X, r.Y,
r.Width, r.Height);
}
private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
IntPtr gtk_scrollbar = bar.vert ? global_gtk_vscrollbar : global_gtk_hscrollbar;
gtk_paint_box (current_style,
current_gdk_window,
(int) StateType.Active,
(int) ShadowType.Out,
IntPtr.Zero,
gtk_scrollbar,
"slider",
area.X, area.Y,
area.Width, area.Height);
}
#endregion // ScrollBar
#region ProgressBar
public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
{
Rectangle client_area = ctrl.client_area;
int barpos_pixels;
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) ctrl.Handle);
IntPtr progressbar_style = gtk_style_attach (global_gtk_progress_bar_style, gdkwindow); // need it
// draw background
gtk_paint_box (progressbar_style,
gdkwindow,
(int) StateType.Normal,
(int) ShadowType.In,
IntPtr.Zero,
global_gtk_progress_bar,
"trough",
ctrl.ClientRectangle.X,
ctrl.ClientRectangle.Y,
ctrl.ClientRectangle.Width,
ctrl.ClientRectangle.Height);
// don't draw the bar if Value is = 0
if (ctrl.Value == 0)
return;
if (ctrl.Value == ctrl.Maximum)
barpos_pixels = client_area.Width + 2;
else
barpos_pixels = (((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum)) + 1;
gtk_paint_box (progressbar_style,
gdkwindow,
(int) StateType.Prelight,
(int) ShadowType.Out,
IntPtr.Zero,
global_gtk_vscrollbar,
"bar",
client_area.X - 1, client_area.Y - 1,
barpos_pixels, client_area.Height + 2);
}
#endregion // ProgressBar
#region RadioButton
protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
{
// we currently don't care for flat or popup radio buttons
if (radio_button.appearance == Appearance.Button) {
DrawButtonBase (dc, radio_button.ClientRectangle, radio_button);
} else {
DrawRadioButton (dc, radio_button, state, radiobutton_rectangle);
}
}
private void DrawRadioButton (Graphics dc, RadioButton radio_button, ButtonState state, Rectangle radiobutton_rectangle)
{
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) radio_button.Handle);
IntPtr radiobutton_style = gtk_style_attach (global_gtk_radio_button_style, gdkwindow);
current_gdk_window = gdkwindow;
current_style = radiobutton_style;
ShadowType shadow_type;
if (!radio_button.Enabled)
shadow_type = ShadowType.Out;
else
shadow_type = radio_button.Checked ? ShadowType.In : ShadowType.EtchedIn;
StateType state_type = StateType.Normal;
if (!radio_button.Enabled)
state_type = StateType.Insensitive;
else
if (radio_button.is_pressed)
state_type = StateType.Active;
else
if (radio_button.is_entered)
state_type = StateType.Prelight;
gtk_paint_option (radiobutton_style,
gdkwindow,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
global_gtk_radio_button,
"radiobutton",
radiobutton_rectangle.X,
radiobutton_rectangle.Y,
radiobutton_rectangle.Width,
radiobutton_rectangle.Height);
}
protected override void RadioButton_DrawText (RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
{
if (radio_button.Appearance != Appearance.Button)
base.RadioButton_DrawText (radio_button, text_rectangle, dc, text_format);
}
protected override void RadioButton_DrawFocus (RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
{
if (radio_button.Focused && radio_button.appearance != Appearance.Button) {
gtk_paint_focus (current_style,
current_gdk_window,
(int) StateType.Active,
IntPtr.Zero,
IntPtr.Zero,
"radiobutton",
text_rectangle.X,
text_rectangle.Y,
text_rectangle.Width,
text_rectangle.Height);
}
}
#endregion // RadioButton
#region CheckBox
protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
{
// render as per normal button
if (checkbox.appearance == Appearance.Button) {
DrawButtonBase (dc, checkbox.ClientRectangle, checkbox);
} else {
InternalDrawCheckBox (dc, checkbox, state, checkbox_rectangle);
}
}
private void InternalDrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
{
IntPtr gdkwindow = gdk_window_foreign_new_for_display (gdkdisplay, (uint) checkbox.Handle);
IntPtr checkbox_style = gtk_style_attach (global_gtk_check_button_style, gdkwindow);
current_gdk_window = gdkwindow;
current_style = checkbox_style;
ShadowType shadow_type;
if (!checkbox.Enabled)
shadow_type = ShadowType.Out;
else
shadow_type = checkbox.Checked ? ShadowType.In : ShadowType.EtchedIn;
StateType state_type = StateType.Normal;
if (!checkbox.Enabled)
state_type = StateType.Insensitive;
else
if (checkbox.is_pressed)
state_type = StateType.Active;
else
if (checkbox.is_entered)
state_type = StateType.Prelight;
gtk_paint_check (checkbox_style,
gdkwindow,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
global_gtk_radio_button,
"checkbutton",
checkbox_rectangle.X,
checkbox_rectangle.Y,
checkbox_rectangle.Width,
checkbox_rectangle.Height);
}
protected override void CheckBox_DrawText (CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
{
if (checkbox.Appearance != Appearance.Button)
base.CheckBox_DrawText (checkbox, text_rectangle, dc, text_format);
}
protected override void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
{
if (checkbox.Focused && checkbox.appearance != Appearance.Button) {
gtk_paint_focus (current_style,
current_gdk_window,
(int) StateType.Active,
IntPtr.Zero,
IntPtr.Zero,
"checkbutton",
text_rectangle.X,
text_rectangle.Y,
text_rectangle.Width,
text_rectangle.Height);
}
}
#endregion // CheckBox
public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state)
{
bool is_pushed = false;
// bool is_checked = false;
// bool is_flat = false;
bool is_inactive = false;
if ((state & ButtonState.Pushed) != 0) {
is_pushed = true;
}
// if ((state & ButtonState.Checked) != 0) {
// is_checked = true;
// }
//
// if ((state & ButtonState.Flat) != 0) {
// is_flat = true;
// }
if ((state & ButtonState.Inactive) != 0) {
is_inactive = true;
}
IntPtr drawbutton_style = gtk_style_attach (global_gtk_button_style, current_gdk_window); // need it
StateType state_type = StateType.Normal;
ShadowType shadow_type = ShadowType.Out;
string detail = "buttondefault";
if (is_inactive) {
state_type = StateType.Insensitive;
} else
if (is_pushed) {
state_type = StateType.Active;
shadow_type = ShadowType.In;
detail = "button";
}
gtk_paint_box (drawbutton_style, current_gdk_window,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
IntPtr.Zero,
detail,
rectangle.X, rectangle.Y,
rectangle.Width, rectangle.Height);
}
/* Scroll button: regular button + direction arrow */
public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state)
{
bool enabled = (state == ButtonState.Inactive) ? false: true;
StateType state_type = enabled ? StateType.Normal : StateType.Insensitive;
DrawScrollButtonPrimitive (dc, area, state, scroll_button_type);
if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
return;
ArrowType arrow_type = 0;
switch (scroll_button_type) {
case ScrollButton.Up:
arrow_type = ArrowType.Up;
break;
case ScrollButton.Down:
arrow_type = ArrowType.Down;
break;
case ScrollButton.Right:
arrow_type = ArrowType.Right;
break;
case ScrollButton.Left:
arrow_type = ArrowType.Left;
break;
default:
break;
}
int centerX = area.Left + area.Width / 2;
int centerY = area.Top + area.Height / 2;
int arrow_x = 0, arrow_y = 0, arrow_height = 0, arrow_width = 0;
switch (scroll_button_type) {
case ScrollButton.Down:
case ScrollButton.Up:
arrow_x = centerX - 4;
arrow_y = centerY - 2;
arrow_width = 8;
arrow_height = 4;
break;
case ScrollButton.Left:
case ScrollButton.Right:
arrow_x = centerX - 2;
arrow_y = centerY - 4;
arrow_width = 4;
arrow_height = 8;
break;
default:
break;
}
gtk_paint_arrow (current_style,
current_gdk_window,
(int) state_type,
(int) ShadowType.Out,
IntPtr.Zero,
IntPtr.Zero,
"",
(int) arrow_type, true,
arrow_x,
arrow_y,
arrow_width, arrow_height);
}
public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type)
{
StateType state_type = StateType.Normal;
ShadowType shadow_type = ShadowType.Out;
if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
state_type = StateType.Active;
shadow_type = ShadowType.In;
}
switch (scroll_button_type) {
case ScrollButton.Left:
case ScrollButton.Right:
gtk_paint_box (current_style,
current_gdk_window,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
global_gtk_hscrollbar,
"stepper",
area.X, area.Y,
area.Width, area.Height);
break;
case ScrollButton.Up:
case ScrollButton.Down:
gtk_paint_box (current_style,
current_gdk_window,
(int) state_type,
(int) shadow_type,
IntPtr.Zero,
global_gtk_vscrollbar,
"stepper",
area.X, area.Y,
area.Width, area.Height);
break;
}
}
private static Color ColorFromGdkColor (GdkColorStruct gtkcolor)
{
return Color.FromArgb (255,
(gtkcolor.red >> 8) & 0xff,
(gtkcolor.green >> 8) & 0xff,
(gtkcolor.blue >> 8) & 0xff );
}
} //class
}
|