comparison dwt/graphics/TextLayout.d @ 33:27324bbbac70

changed to regenerated BCD bindings
author Frank Benoit <benoit@tionex.de>
date Thu, 10 Jan 2008 02:18:07 +0100
parents fc2b263b8a3f
children 93981635e709
comparison
equal deleted inserted replaced
32:b7c28480e3e0 33:27324bbbac70
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/ 10 *******************************************************************************/
11 module dwt.graphics.TextLayout; 11 module dwt.graphics.TextLayout;
12 12
13 import dwt.internal.cairo.Cairo; 13 import dwt.internal.cairo.Cairo;
14 import dwt.internal.gtk.c.cairotypes;
15 import dwt.internal.gtk.c.pangotypes;
16 import dwt.internal.gtk.c.gdktypes;
17 import dwt.internal.gtk.OS; 14 import dwt.internal.gtk.OS;
18 import dwt.internal.Converter; 15 import dwt.internal.Converter;
19 import dwt.SWT; 16 import dwt.SWT;
20 import dwt.graphics.Color; 17 import dwt.graphics.Color;
21 import dwt.graphics.Device; 18 import dwt.graphics.Device;
93 if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 90 if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
94 this.device = device; 91 this.device = device;
95 context = OS.gdk_pango_context_get(); 92 context = OS.gdk_pango_context_get();
96 if (context is null) SWT.error(SWT.ERROR_NO_HANDLES); 93 if (context is null) SWT.error(SWT.ERROR_NO_HANDLES);
97 OS.pango_context_set_language(context, OS.gtk_get_default_language()); 94 OS.pango_context_set_language(context, OS.gtk_get_default_language());
98 OS.pango_context_set_base_dir(context, cast(PangoDirection) OS.PANGO_DIRECTION_LTR); 95 OS.pango_context_set_base_dir(context, OS.PANGO_DIRECTION_LTR);
99 OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system()); 96 OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system());
100 layout = OS.pango_layout_new(context); 97 layout = OS.pango_layout_new(context);
101 if (layout is null) SWT.error(SWT.ERROR_NO_HANDLES); 98 if (layout is null) SWT.error(SWT.ERROR_NO_HANDLES);
102 OS.pango_layout_set_wrap(layout, cast(PangoWrapMode)OS.PANGO_WRAP_WORD_CHAR); 99 OS.pango_layout_set_wrap(layout, OS.PANGO_WRAP_WORD_CHAR);
103 OS.pango_layout_set_tabs(layout, device.emptyTab); 100 OS.pango_layout_set_tabs(layout, device.emptyTab);
104 if (OS.GTK_VERSION >= OS.buildVERSION(2, 4, 0)) { 101 if (OS.GTK_VERSION >= OS.buildVERSION(2, 4, 0)) {
105 OS.pango_layout_set_auto_dir(layout, false); 102 OS.pango_layout_set_auto_dir(layout, false);
106 } 103 }
107 text = ""; 104 text = "";
199 attr.start_index = byteStart; 196 attr.start_index = byteStart;
200 attr.end_index = byteEnd; 197 attr.end_index = byteEnd;
201 OS.pango_attr_list_insert(attrList, attr); 198 OS.pango_attr_list_insert(attrList, attr);
202 } 199 }
203 if (style.underline) { 200 if (style.underline) {
204 auto attr = OS.pango_attr_underline_new(cast(PangoUnderline)OS.PANGO_UNDERLINE_SINGLE); 201 auto attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_SINGLE);
205 attr.start_index = byteStart; 202 attr.start_index = byteStart;
206 attr.end_index = byteEnd; 203 attr.end_index = byteEnd;
207 OS.pango_attr_list_insert(attrList, attr); 204 OS.pango_attr_list_insert(attrList, attr);
208 } 205 }
209 if (style.strikeout) { 206 if (style.strikeout) {
379 if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) { 376 if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
380 extent = true; 377 extent = true;
381 } else { 378 } else {
382 if (attrs is null) OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs); 379 if (attrs is null) OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs);
383 *logAttr = attrs[lineEnd]; 380 *logAttr = attrs[lineEnd];
384 if (!logAttr.is_line_break) { 381 if (!( logAttr.bitfield0 & 0x01 /* PangoLogAttr.is_line_break is Bit0 */)) {
385 if (selectionStart <= lineEnd && lineEnd <= selectionEnd) extent = true; 382 if (selectionStart <= lineEnd && lineEnd <= selectionEnd) extent = true;
386 } else { 383 } else {
387 if (selectionStart <= lineEnd && lineEnd < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) { 384 if (selectionStart <= lineEnd && lineEnd < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
388 extent = true; 385 extent = true;
389 } 386 }
966 offset = translateOffset(offset); 963 offset = translateOffset(offset);
967 PangoLogAttr* logAttr = new PangoLogAttr(); 964 PangoLogAttr* logAttr = new PangoLogAttr();
968 offset = validateOffset(offset, step); 965 offset = validateOffset(offset, step);
969 while (0 < offset && offset < length) { 966 while (0 < offset && offset < length) {
970 *logAttr = attrs[ offset ]; 967 *logAttr = attrs[ offset ];
971 if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break; 968 if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && ( logAttr.bitfield0 & (1<<4/*is_cursor_position*/))) break;
972 if ((movement & SWT.MOVEMENT_WORD) != 0) { 969 if ((movement & SWT.MOVEMENT_WORD) != 0) {
973 if (forward) { 970 if (forward) {
974 if (logAttr.is_word_end) break; 971 if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
975 } else { 972 } else {
976 if (logAttr.is_word_start) break; 973 if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
977 } 974 }
978 } 975 }
979 if ((movement & SWT.MOVEMENT_WORD_START) != 0) { 976 if ((movement & SWT.MOVEMENT_WORD_START) != 0) {
980 if (logAttr.is_word_start) break; 977 if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
981 } 978 }
982 if ((movement & SWT.MOVEMENT_WORD_END) != 0) { 979 if ((movement & SWT.MOVEMENT_WORD_END) != 0) {
983 if (logAttr.is_word_end) break; 980 if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
984 } 981 }
985 offset = validateOffset(offset, step); 982 offset = validateOffset(offset, step);
986 } 983 }
987 OS.g_free(attrs); 984 OS.g_free(attrs);
988 return Math.min(Math.max(0, untranslateOffset(offset)), text.length); 985 return Math.min(Math.max(0, untranslateOffset(offset)), text.length);
1346 int al = OS.PANGO_ALIGN_LEFT; 1343 int al = OS.PANGO_ALIGN_LEFT;
1347 switch (alignment) { 1344 switch (alignment) {
1348 case SWT.CENTER: al = OS.PANGO_ALIGN_CENTER; break; 1345 case SWT.CENTER: al = OS.PANGO_ALIGN_CENTER; break;
1349 case SWT.RIGHT: al = OS.PANGO_ALIGN_RIGHT; break; 1346 case SWT.RIGHT: al = OS.PANGO_ALIGN_RIGHT; break;
1350 } 1347 }
1351 OS.pango_layout_set_alignment(layout, cast(PangoAlignment) al); 1348 OS.pango_layout_set_alignment(layout, al);
1352 } 1349 }
1353 1350
1354 /** 1351 /**
1355 * Sets the ascent of the receiver. The ascent is distance in pixels 1352 * Sets the ascent of the receiver. The ascent is distance in pixels
1356 * from the baseline to the top of the line and it is applied to all 1353 * from the baseline to the top of the line and it is applied to all
1480 orientation &= mask; 1477 orientation &= mask;
1481 if (orientation == 0) return; 1478 if (orientation == 0) return;
1482 if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT; 1479 if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
1483 int baseDir = orientation == SWT.RIGHT_TO_LEFT ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR; 1480 int baseDir = orientation == SWT.RIGHT_TO_LEFT ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR;
1484 if (OS.pango_context_get_base_dir(context) == baseDir) return; 1481 if (OS.pango_context_get_base_dir(context) == baseDir) return;
1485 OS.pango_context_set_base_dir(context,cast(PangoDirection) baseDir); 1482 OS.pango_context_set_base_dir(context, baseDir);
1486 OS.pango_layout_context_changed(layout); 1483 OS.pango_layout_context_changed(layout);
1487 } 1484 }
1488 1485
1489 /** 1486 /**
1490 * Sets the line spacing of the receiver. The line spacing 1487 * Sets the line spacing of the receiver. The line spacing
1666 OS.pango_layout_set_tabs(layout, device.emptyTab); 1663 OS.pango_layout_set_tabs(layout, device.emptyTab);
1667 } else { 1664 } else {
1668 auto tabArray = OS.pango_tab_array_new(tabs.length, true); 1665 auto tabArray = OS.pango_tab_array_new(tabs.length, true);
1669 if (tabArray !is null) { 1666 if (tabArray !is null) {
1670 for (int i = 0; i < tabs.length; i++) { 1667 for (int i = 0; i < tabs.length; i++) {
1671 OS.pango_tab_array_set_tab(tabArray, i,cast(PangoTabAlign)OS.PANGO_TAB_LEFT, tabs[i]); 1668 OS.pango_tab_array_set_tab(tabArray, i, OS.PANGO_TAB_LEFT, tabs[i]);
1672 } 1669 }
1673 OS.pango_layout_set_tabs(layout, tabArray); 1670 OS.pango_layout_set_tabs(layout, tabArray);
1674 OS.pango_tab_array_free(tabArray); 1671 OS.pango_tab_array_free(tabArray);
1675 } 1672 }
1676 } 1673 }