Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Conversion.cs « Xwt.GtkBackend « Xwt.Gtk - github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6168ee7b142c7852783fe7172fdbcc95d8bf473 (plain)
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
using System;
using Xwt.Drawing;

namespace Xwt.GtkBackend
{
	public static class Conversion
	{
		public static Gtk.IconSize ToGtkValue (Xwt.IconSize size)
		{
			switch (size) {
			case IconSize.Small:
				return Gtk.IconSize.Menu;
			case IconSize.Medium:
				return Gtk.IconSize.Button;
			case IconSize.Large:
				return Gtk.IconSize.Dialog;
			}
			return Gtk.IconSize.Dialog;
		}

		public static Gdk.Color ToGtkValue (this Xwt.Drawing.Color color)
		{
			return new Gdk.Color ((byte)(color.Red * 255), (byte)(color.Green * 255), (byte)(color.Blue * 255));
		}

		public static Color ToXwtValue (this Gdk.Color color)
		{
			return new Color ((double)color.Red / (double)ushort.MaxValue, (double)color.Green / (double)ushort.MaxValue, (double)color.Blue / (double)ushort.MaxValue);
		}

		#if XWT_GTK3
		public static Gdk.RGBA ToGtkRgbaValue (this Xwt.Drawing.Color color)
		{
			var rgba = new Gdk.RGBA ();
			rgba.Red = color.Red;
			rgba.Green = color.Green;
			rgba.Blue = color.Blue;
			rgba.Alpha = color.Alpha;
			return rgba;
		}

		public static Color ToXwtValue (this Gdk.RGBA color)
		{
			return new Color (color.Red, color.Green, color.Blue, color.Alpha);
		}
		#endif

		public static Pango.EllipsizeMode ToGtkValue (this EllipsizeMode value)
		{
			switch (value) {
			case Xwt.EllipsizeMode.None: return Pango.EllipsizeMode.None;
			case Xwt.EllipsizeMode.Start: return Pango.EllipsizeMode.Start;
			case Xwt.EllipsizeMode.Middle: return Pango.EllipsizeMode.Middle;
			case Xwt.EllipsizeMode.End: return Pango.EllipsizeMode.End;
			}
			throw new NotSupportedException ();
		}

		public static EllipsizeMode ToXwtValue (this Pango.EllipsizeMode value)
		{
			switch (value) {
			case Pango.EllipsizeMode.None: return Xwt.EllipsizeMode.None;
			case Pango.EllipsizeMode.Start: return Xwt.EllipsizeMode.Start;
			case Pango.EllipsizeMode.Middle: return Xwt.EllipsizeMode.Middle;
			case Pango.EllipsizeMode.End: return Xwt.EllipsizeMode.End;
			}
			throw new NotSupportedException ();
		}

		public static ScrollPolicy ToXwtValue (this Gtk.PolicyType p)
		{
			switch (p) {
			case Gtk.PolicyType.Always:
				return ScrollPolicy.Always;
			case Gtk.PolicyType.Automatic:
				return ScrollPolicy.Automatic;
			case Gtk.PolicyType.Never:
				return ScrollPolicy.Never;
			}
			throw new InvalidOperationException ("Invalid policy value:" + p);
		}

		public static Gtk.PolicyType ToGtkValue (this ScrollPolicy p)
		{
			switch (p) {
			case ScrollPolicy.Always:
				return Gtk.PolicyType.Always;
			case ScrollPolicy.Automatic:
				return Gtk.PolicyType.Automatic;
			case ScrollPolicy.Never:
				return Gtk.PolicyType.Never;
			}
			throw new InvalidOperationException ("Invalid policy value:" + p);
		}

		public static ScrollDirection ToXwtValue(this Gdk.ScrollDirection d)
		{
			switch(d) {
			case Gdk.ScrollDirection.Up:
				return Xwt.ScrollDirection.Up;
			case Gdk.ScrollDirection.Down:
				return Xwt.ScrollDirection.Down;
			case Gdk.ScrollDirection.Left:
				return Xwt.ScrollDirection.Left;
			case Gdk.ScrollDirection.Right:
				return Xwt.ScrollDirection.Right;
			}
			throw new InvalidOperationException("Invalid mouse scroll direction value: " + d);
		}

		public static Gdk.ScrollDirection ToGtkValue(this ScrollDirection d)
		{
			switch (d) {
			case ScrollDirection.Up:
				return Gdk.ScrollDirection.Up;
			case ScrollDirection.Down:
				return Gdk.ScrollDirection.Down;
			case ScrollDirection.Left:
				return Gdk.ScrollDirection.Left;
			case ScrollDirection.Right:
				return Gdk.ScrollDirection.Right;
			}
			throw new InvalidOperationException("Invalid mouse scroll direction value: " + d);
		}

		public static ModifierKeys ToXwtValue (this Gdk.ModifierType s)
		{
			ModifierKeys m = ModifierKeys.None;
			if ((s & Gdk.ModifierType.ShiftMask) != 0)
				m |= ModifierKeys.Shift;
			if ((s & Gdk.ModifierType.ControlMask) != 0)
				m |= ModifierKeys.Control;
			if ((s & Gdk.ModifierType.Mod1Mask) != 0)
				m |= ModifierKeys.Alt;
			if ((s & Gdk.ModifierType.Mod2Mask) != 0)
				m |= ModifierKeys.Command;
			return m;
		}

		public static Gtk.Requisition ToGtkRequisition (this Size size)
		{
			var req = new Gtk.Requisition ();
			req.Height = (int)size.Height;
			req.Width = (int)size.Width;
			return req;
		}

		public static Gtk.TreeViewGridLines ToGtkValue (this GridLines value)
		{
			switch (value)
			{
				case GridLines.Both:
					return Gtk.TreeViewGridLines.Both;
				case GridLines.Horizontal:
					return Gtk.TreeViewGridLines.Horizontal;
				case GridLines.Vertical:
					return Gtk.TreeViewGridLines.Vertical;
				case GridLines.None:
					return Gtk.TreeViewGridLines.None;
			}
			throw new InvalidOperationException("Invalid GridLines value: " + value);
		}

		public static GridLines ToXwtValue (this Gtk.TreeViewGridLines value)
		{
			switch (value)
			{
				case Gtk.TreeViewGridLines.Both:
					return GridLines.Both;
				case Gtk.TreeViewGridLines.Horizontal:
					return GridLines.Horizontal;
				case Gtk.TreeViewGridLines.Vertical:
					return GridLines.Vertical;
				case Gtk.TreeViewGridLines.None:
					return GridLines.None;
			}
			throw new InvalidOperationException("Invalid TreeViewGridLines value: " + value);
		}

		public static float ToGtkAlignment(this Alignment alignment)
		{
			switch(alignment) {
				case Alignment.Start: return 0.0f;
				case Alignment.Center: return 0.5f;
				case Alignment.End: return 1.0f;
			}
			throw new InvalidOperationException("Invalid alignment value: " + alignment);
		}

		public static Pango.Alignment ToPangoAlignment (this Alignment alignment)
		{
			switch(alignment) {
				case Alignment.Start: return Pango.Alignment.Left;
				case Alignment.Center: return Pango.Alignment.Center;
				case Alignment.End: return Pango.Alignment.Right;
			}
			throw new InvalidOperationException("Invalid alignment value: " + alignment);
		}

		public static Gtk.ResponseType ToResponseType (this Xwt.Command command)
		{
			if (command.Id == Command.Ok.Id)
				return Gtk.ResponseType.Ok;
			if (command.Id == Command.Cancel.Id)
				return Gtk.ResponseType.Cancel;
			if (command.Id == Command.Yes.Id)
				return Gtk.ResponseType.Yes;
			if (command.Id == Command.No.Id)
				return Gtk.ResponseType.No;
			if (command.Id == Command.Close.Id)
				return Gtk.ResponseType.Close;
			if (command.Id == Command.Delete.Id)
				return Gtk.ResponseType.DeleteEvent;
			if (command.Id == Command.Apply.Id)
				return Gtk.ResponseType.Accept;
			if (command.Id == Command.Stop.Id)
				return Gtk.ResponseType.Reject;
			return Gtk.ResponseType.None;
		}

		public static Atk.Role ToAtkRole (this Accessibility.Role role)
		{
			switch (role) {
			case Accessibility.Role.Button:
				return Atk.Role.PushButton;
			case Accessibility.Role.ButtonClose:
				return Atk.Role.PushButton;
			case Accessibility.Role.ButtonMinimize:
				return Atk.Role.PushButton;
			case Accessibility.Role.ButtonMaximize:
				return Atk.Role.PushButton;
			case Accessibility.Role.ButtonFullscreen:
				return Atk.Role.PushButton;
			case Accessibility.Role.Calendar:
				return Atk.Role.Calendar;
			case Accessibility.Role.Cell:
				return Atk.Role.TableCell;
			case Accessibility.Role.CheckBox:
				return Atk.Role.CheckBox;
			case Accessibility.Role.ColorChooser:
				return Atk.Role.ColorChooser;
			case Accessibility.Role.Column:
				return Atk.Role.TableColumnHeader;
			case Accessibility.Role.ComboBox:
				return Atk.Role.ComboBox;
			case Accessibility.Role.Custom:
				return Atk.Role.Unknown;
			case Accessibility.Role.Disclosure:
				return Atk.Role.Arrow;
			case Accessibility.Role.Filler:
				return Atk.Role.Filler;
			case Accessibility.Role.Group:
				return Atk.Role.Panel;
			case Accessibility.Role.Image:
				return Atk.Role.Image;
			case Accessibility.Role.Label:
				return Atk.Role.Label;
			case Accessibility.Role.LevelIndicator:
				return (Atk.Role)101; // ATK_ROLE_LEVEL_BAR
			case Accessibility.Role.Link:
				return Atk.Role.Link;
			case Accessibility.Role.List:
				return Atk.Role.List;
			case Accessibility.Role.Menu:
				return Atk.Role.Menu;
			case Accessibility.Role.MenuBar:
				return Atk.Role.MenuBar;
			case Accessibility.Role.MenuBarItem:
				return Atk.Role.MenuItem; // no difference between item and bar item
			case Accessibility.Role.MenuButton:
				return Atk.Role.PushButton;
			case Accessibility.Role.MenuItem:
				return Atk.Role.MenuItem;
			case Accessibility.Role.MenuItemCheckBox:
				return Atk.Role.CheckMenuItem;
			case Accessibility.Role.MenuItemRadio:
				return Atk.Role.RadioMenuItem;
			case Accessibility.Role.Notebook:
				return Atk.Role.PageTabList;
			case Accessibility.Role.NotebookTab:
				return Atk.Role.PageTab;
			case Accessibility.Role.Paned:
				return Atk.Role.SplitPane;
			case Accessibility.Role.PanedSplitter:
				return (Atk.Role)int.MaxValue; // no matching role > Atk.Role.LastDefined
			case Accessibility.Role.Popup:
				return Atk.Role.PopupMenu;
			case Accessibility.Role.ProgressBar:
				return Atk.Role.ProgressBar;
			case Accessibility.Role.RadioButton:
				return Atk.Role.RadioButton;
			case Accessibility.Role.RadioGroup:
				return (Atk.Role)97; // ATK_ROLE_GROUPING
			case Accessibility.Role.Row:
				return Atk.Role.TableRowHeader;
			case Accessibility.Role.ScrollBar:
				return Atk.Role.ScrollBar;
			case Accessibility.Role.ScrollView:
				return Atk.Role.ScrollPane;
			case Accessibility.Role.Separator:
				return Atk.Role.Separator;
			case Accessibility.Role.Slider:
				return Atk.Role.Slider;
			case Accessibility.Role.SpinButton:
				return Atk.Role.SpinButton;
			case Accessibility.Role.Table:
				return Atk.Role.Table;
			case Accessibility.Role.TextArea:
				return Atk.Role.Text;
			case Accessibility.Role.TextEntry:
				return Atk.Role.Entry;
			case Accessibility.Role.TextEntryPassword:
				return Atk.Role.PasswordText;
			case Accessibility.Role.TextEntrySearch:
				return Atk.Role.Entry;
			case Accessibility.Role.ToggleButton:
				return Atk.Role.ToggleButton;
			case Accessibility.Role.ToolBar:
				return Atk.Role.ToolBar;
			case Accessibility.Role.ToolTip:
				return Atk.Role.ToolTip;
			case Accessibility.Role.Tree:
				return Atk.Role.TreeTable;
			case Accessibility.Role.None:
				return (Atk.Role)int.MaxValue; // no matching role > Atk.Role.LastDefined
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}

		public static Accessibility.Role ToXwtRole (this Atk.Role role)
		{
			switch (role) {
			//case Atk.Role.Invalid:
			//	break;
			//case Atk.Role.AccelLabel:
			//	break;
			//case Atk.Role.Alert:
			//	break;
			//case Atk.Role.Animation:
			//	break;
			case Atk.Role.Arrow:
				return Accessibility.Role.Disclosure;
			case Atk.Role.Calendar:
				return Accessibility.Role.Calendar;
			//case Atk.Role.Canvas:
			//	break;
			case Atk.Role.CheckBox:
				return Accessibility.Role.CheckBox;
			case Atk.Role.CheckMenuItem:
				return Accessibility.Role.MenuItemCheckBox;
			case Atk.Role.ColorChooser:
				return Accessibility.Role.ColorChooser;
			case Atk.Role.ColumnHeader:
				return Accessibility.Role.Column;
			case Atk.Role.ComboBox:
				return Accessibility.Role.ComboBox;
			case Atk.Role.DateEditor:
				return Accessibility.Role.Calendar;
			//case Atk.Role.DesktopIcon:
			//	break;
			//case Atk.Role.DesktopFrame:
			//	break;
			//case Atk.Role.Dial:
			//	break;
			//case Atk.Role.Dialog:
			//	break;
			//case Atk.Role.DirectoryPane:
			//	break;
			//case Atk.Role.DrawingArea:
			//	break;
			//case Atk.Role.FileChooser:
			//	break;
			case Atk.Role.Filler:
				return Accessibility.Role.Filler;
			//case Atk.Role.FontChooser:
			//	break;
			//case Atk.Role.Frame:
			//	break;
			//case Atk.Role.GlassPane:
			//	break;
			//case Atk.Role.HtmlContainer:
			//	break;
			//case Atk.Role.Icon:
			//	break;
			case Atk.Role.Image:
				return Accessibility.Role.Image;
			//case Atk.Role.InternalFrame:
			//	break;
			case Atk.Role.Label:
				return Accessibility.Role.Label;
			//case Atk.Role.LayeredPane:
			//	break;
			case Atk.Role.List:
				return Accessibility.Role.List;
			case Atk.Role.ListItem:
				return Accessibility.Role.Cell;
			case Atk.Role.Menu:
				return Accessibility.Role.Menu;
			case Atk.Role.MenuBar:
				return Accessibility.Role.MenuBar;
			case Atk.Role.MenuItem:
				return Accessibility.Role.MenuItem;
			//case Atk.Role.OptionPane:
			//	break;
			case Atk.Role.PageTab:
				return Accessibility.Role.NotebookTab;
			case Atk.Role.PageTabList:
				return Accessibility.Role.Notebook;
			case Atk.Role.Panel:
				return Accessibility.Role.Group;
			case Atk.Role.PasswordText:
				return Accessibility.Role.TextEntryPassword;
			case Atk.Role.PopupMenu:
				return Accessibility.Role.Popup;
			case Atk.Role.ProgressBar:
				return Accessibility.Role.ProgressBar;
			case Atk.Role.PushButton:
				return Accessibility.Role.Button;
			case Atk.Role.RadioButton:
				return Accessibility.Role.RadioButton;
			case Atk.Role.RadioMenuItem:
				return Accessibility.Role.MenuItemRadio;
			//case Atk.Role.RootPane:
			//	break;
			case Atk.Role.RowHeader:
				return Accessibility.Role.Row;
			case Atk.Role.ScrollBar:
				return Accessibility.Role.ScrollBar;
			case Atk.Role.ScrollPane:
				return Accessibility.Role.ScrollView;
			case Atk.Role.Separator:
				return Accessibility.Role.Separator;
			case Atk.Role.Slider:
				return Accessibility.Role.Slider;
			case Atk.Role.SplitPane:
				return Accessibility.Role.Paned;
			case Atk.Role.SpinButton:
				return Accessibility.Role.SpinButton;
			//case Atk.Role.Statusbar:
			//	break;
			case Atk.Role.Table:
				return Accessibility.Role.Table;
			case Atk.Role.TableCell:
				return Accessibility.Role.Cell;
			case Atk.Role.TableColumnHeader:
				return Accessibility.Role.Column;
			case Atk.Role.TableRowHeader:
				return Accessibility.Role.Row;
			//case Atk.Role.TearOffMenuItem:
			//	break;
			//case Atk.Role.Terminal:
			//	break;
			case Atk.Role.Text:
				return Accessibility.Role.TextArea;
			case Atk.Role.ToggleButton:
				return Accessibility.Role.ToggleButton;
			case Atk.Role.ToolBar:
				return Accessibility.Role.ToolBar;
			case Atk.Role.ToolTip:
				return Accessibility.Role.ToolTip;
			case Atk.Role.Tree:
				return Accessibility.Role.Table;
			case Atk.Role.TreeTable:
				return Accessibility.Role.Table;
			case Atk.Role.Unknown:
				return Accessibility.Role.Custom;
			//case Atk.Role.Viewport:
			//	break;
			//case Atk.Role.Window:
			//	break;
			//case Atk.Role.Header:
			//	break;
			//case Atk.Role.Footer:
			//	break;
			//case Atk.Role.Paragraph:
			//	break;
			//case Atk.Role.Ruler:
			//	break;
			//case Atk.Role.Application:
			//	break;
			//case Atk.Role.Autocomplete:
			//	break;
			//case Atk.Role.Editbar:
			//	break;
			//case Atk.Role.Embedded:
			//	break;
			case Atk.Role.Entry:
				return Accessibility.Role.TextEntry;
			//case Atk.Role.Chart:
			//	break;
			//case Atk.Role.Caption:
			//	break;
			//case Atk.Role.DocumentFrame:
			//	break;
			//case Atk.Role.Heading:
			//	break;
			//case Atk.Role.Page:
			//	break;
			//case Atk.Role.Section:
			//	break;
			//case Atk.Role.RedundantObject:
			//	break;
			//case Atk.Role.Form:
			//	break;
			case Atk.Role.Link:
				return Accessibility.Role.Link;
			//case Atk.Role.InputMethodWindow:
			//	break;
			//case Atk.Role.LastDefined:
			//	break;
			case (Atk.Role)97: // ATK_ROLE_GROUPING
				return Accessibility.Role.RadioGroup;
			case (Atk.Role)101: // ATK_ROLE_LEVEL_BAR
				return Accessibility.Role.LevelIndicator;
			default:
				return Accessibility.Role.None;
			}
		}
	}
}