comparison dwt/widgets/Label.d @ 259:c0d810de7093

Update SWT 3.4M7 to 3.4
author Frank Benoit <benoit@tionex.de>
date Sun, 29 Jun 2008 14:33:38 +0200
parents 5a30aa9820f3
children bfafc891369e
comparison
equal deleted inserted replaced
257:cc1d3de0e80b 259:c0d810de7093
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
26 /** 26 /**
27 * Instances of this class represent a non-selectable 27 * Instances of this class represent a non-selectable
28 * user interface object that displays a string or image. 28 * user interface object that displays a string or image.
29 * When SEPARATOR is specified, displays a single 29 * When SEPARATOR is specified, displays a single
30 * vertical or horizontal line. 30 * vertical or horizontal line.
31 * <p>
32 * Shadow styles are hints and may not be honoured
33 * by the platform. To create a separator label
34 * with the default shadow style for the platform,
35 * do not specify a shadow style.
36 * </p>
31 * <dl> 37 * <dl>
32 * <dt><b>Styles:</b></dt> 38 * <dt><b>Styles:</b></dt>
33 * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd> 39 * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
34 * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> 40 * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
35 * <dd>CENTER, LEFT, RIGHT, WRAP</dd> 41 * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
42 * Only one of CENTER, LEFT and RIGHT may be specified. 48 * Only one of CENTER, LEFT and RIGHT may be specified.
43 * </p><p> 49 * </p><p>
44 * IMPORTANT: This class is intended to be subclassed <em>only</em> 50 * IMPORTANT: This class is intended to be subclassed <em>only</em>
45 * within the DWT implementation. 51 * within the DWT implementation.
46 * </p> 52 * </p>
53 *
54 * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
55 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a>
56 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
47 */ 57 */
48 public class Label : Control { 58 public class Label : Control {
49 59
50 alias Control.computeSize computeSize; 60 alias Control.computeSize computeSize;
51 alias Control.mnemonicHit mnemonicHit; 61 alias Control.mnemonicHit mnemonicHit;
218 OS.gtk_label_set_line_wrap (labelHandle, true); 228 OS.gtk_label_set_line_wrap (labelHandle, true);
219 if (OS.GTK_VERSION >= OS.buildVERSION (2, 10, 0)) { 229 if (OS.GTK_VERSION >= OS.buildVERSION (2, 10, 0)) {
220 OS.gtk_label_set_line_wrap_mode (labelHandle, OS.PANGO_WRAP_WORD_CHAR); 230 OS.gtk_label_set_line_wrap_mode (labelHandle, OS.PANGO_WRAP_WORD_CHAR);
221 } 231 }
222 } 232 }
223 if ((style & DWT.LEFT) !is 0) { 233 setAlignment ();
224 OS.gtk_misc_set_alignment (cast(GtkMisc*)labelHandle, 0.0f, 0.0f);
225 OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, OS.GTK_JUSTIFY_LEFT);
226 OS.gtk_misc_set_alignment (cast(GtkMisc*)imageHandle, 0.0f, 0.5f);
227 return;
228 }
229 if ((style & DWT.CENTER) !is 0) {
230 OS.gtk_misc_set_alignment (cast(GtkMisc*)labelHandle, 0.5f, 0.0f);
231 OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, OS.GTK_JUSTIFY_CENTER);
232 OS.gtk_misc_set_alignment (cast(GtkMisc*)imageHandle, 0.5f, 0.5f);
233 return;
234 }
235 if ((style & DWT.RIGHT) !is 0) {
236 OS.gtk_misc_set_alignment (cast(GtkMisc*)labelHandle, 1.0f, 0.0f);
237 OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, OS.GTK_JUSTIFY_RIGHT);
238 OS.gtk_misc_set_alignment (cast(GtkMisc*)imageHandle, 1.0f, 0.5f);
239 return;
240 }
241 } 234 }
242 235
243 override void createWidget (int index) { 236 override void createWidget (int index) {
244 super.createWidget (index); 237 super.createWidget (index);
245 text = ""; 238 text = "";
405 checkWidget (); 398 checkWidget ();
406 if ((style & DWT.SEPARATOR) !is 0) return; 399 if ((style & DWT.SEPARATOR) !is 0) return;
407 if ((alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER)) is 0) return; 400 if ((alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER)) is 0) return;
408 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); 401 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER);
409 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); 402 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER);
403 setAlignment ();
404 }
405
406 void setAlignment () {
410 bool isRTL = (style & DWT.RIGHT_TO_LEFT) !is 0; 407 bool isRTL = (style & DWT.RIGHT_TO_LEFT) !is 0;
408 if (text !is null && text.length () !is 0) {
409 if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
410 auto layout = OS.gtk_label_get_layout (labelHandle);
411 auto linePtr = OS.pango_layout_get_line (layout, 0);
412 int resolved_dir = OS.pango_layout_line_get_resolved_dir (linePtr);
413 if (resolved_dir is OS.PANGO_DIRECTION_RTL) {
414 isRTL = !isRTL;
415 }
416 }
417 }
411 if ((style & DWT.LEFT) !is 0) { 418 if ((style & DWT.LEFT) !is 0) {
412 OS.gtk_misc_set_alignment (cast(GtkMisc*)labelHandle, 0.0f, 0.0f); 419 OS.gtk_misc_set_alignment (cast(GtkMisc*)labelHandle, 0.0f, 0.0f);
413 OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, isRTL ? OS.GTK_JUSTIFY_RIGHT : OS.GTK_JUSTIFY_LEFT); 420 OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, isRTL ? OS.GTK_JUSTIFY_RIGHT : OS.GTK_JUSTIFY_LEFT);
414 OS.gtk_misc_set_alignment (cast(GtkMisc*)imageHandle, 0.0f, 0.5f); 421 OS.gtk_misc_set_alignment (cast(GtkMisc*)imageHandle, 0.0f, 0.5f);
415 return; 422 return;
498 override void setOrientation () { 505 override void setOrientation () {
499 super.setOrientation (); 506 super.setOrientation ();
500 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { 507 if ((style & DWT.RIGHT_TO_LEFT) !is 0) {
501 if (labelHandle !is null) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); 508 if (labelHandle !is null) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
502 if (imageHandle !is null) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); 509 if (imageHandle !is null) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL);
503 if ((style & DWT.LEAD) !is 0) {
504 if (labelHandle !is null) OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, OS.GTK_JUSTIFY_RIGHT);
505 }
506 if ((style & DWT.TRAIL) !is 0) {
507 if (labelHandle !is null) OS.gtk_label_set_justify (cast(GtkLabel*)labelHandle, OS.GTK_JUSTIFY_LEFT);
508 }
509 } 510 }
510 } 511 }
511 512
512 /** 513 /**
513 * Sets the receiver's image to the argument, which may be 514 * Sets the receiver's image to the argument, which may be
575 text = string; 576 text = string;
576 char [] chars = fixMnemonic (string); 577 char [] chars = fixMnemonic (string);
577 OS.gtk_label_set_text_with_mnemonic (cast(GtkLabel*)labelHandle, chars.toStringzValidPtr()); 578 OS.gtk_label_set_text_with_mnemonic (cast(GtkLabel*)labelHandle, chars.toStringzValidPtr());
578 OS.gtk_widget_hide (imageHandle); 579 OS.gtk_widget_hide (imageHandle);
579 OS.gtk_widget_show (labelHandle); 580 OS.gtk_widget_show (labelHandle);
581 setAlignment ();
580 } 582 }
581 583
582 override void showWidget () { 584 override void showWidget () {
583 super.showWidget (); 585 super.showWidget ();
584 if (frameHandle !is null) OS.gtk_widget_show (frameHandle); 586 if (frameHandle !is null) OS.gtk_widget_show (frameHandle);