Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 467328
Collapse All | Expand All

(-)a/bundles/org.eclipse.jface/src/org/eclipse/jface/util/BidiUtils.java (-22 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2012, 2014 IBM Corporation and others.
2
 * Copyright (c) 2012, 2015 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
Lines 474-480 Link Here
474
	}
474
	}
475
475
476
	/**
476
	/**
477
	 * Applies a Base Text Direction to the given control (and its descendants, if it's a {@link Composite}).
477
	 * Applies a Base Text Direction to the given control (and its descendants,
478
	 * if it's a {@link Composite}).
478
	 *
479
	 *
479
	 * <p>
480
	 * <p>
480
	 * Possible values for <code>textDirection</code> are:
481
	 * Possible values for <code>textDirection</code> are:
Lines 485-537 Link Here
485
	 * <li>{@link BidiUtils#BTD_DEFAULT}</li>
486
	 * <li>{@link BidiUtils#BTD_DEFAULT}</li>
486
	 * </ul>
487
	 * </ul>
487
	 * <p>
488
	 * <p>
488
	 * The 3 values {@link #LEFT_TO_RIGHT}, {@link #RIGHT_TO_LEFT}, and {@link BidiUtils#AUTO} are
489
	 * The 3 values {@link #LEFT_TO_RIGHT}, {@link #RIGHT_TO_LEFT}, and
489
	 * usable whether {@link #getBidiSupport() bidi support} is enabled or disabled.
490
	 * {@link BidiUtils#AUTO} are usable whether {@link #getBidiSupport() bidi
491
	 * support} is enabled or disabled.
490
	 * <p>
492
	 * <p>
491
	 * {@link BidiUtils#AUTO} currently only works for {@link Text}, {@link StyledText}, and {@link Combo} controls.
493
	 * The remaining value {@link BidiUtils#BTD_DEFAULT} only has an effect if
492
	 * <p>
494
	 * bidi support is enabled.
493
	 * The remaining value {@link BidiUtils#BTD_DEFAULT} only has an effect if bidi support is enabled.
494
	 *
495
	 *
495
	 * <p>
496
	 * <p>
496
	 * <strong>Note:</strong>
497
	 * <strong>Note:</strong> If this method is called on a control, then no
497
	 * If this method is called on a control, then no <code>applyBidiProcessing</code> method must be called on the same control.
498
	 * <code>applyBidiProcessing</code> method must be called on the same
499
	 * control.
498
	 * <p>
500
	 * <p>
499
	 * <strong>Note:</strong>
501
	 * <strong>Note:</strong>
500
	 * {@link org.eclipse.swt.widgets.Control#setTextDirection(int)}
502
	 * {@link org.eclipse.swt.widgets.Control#setTextDirection(int)} is
501
	 * is currently only implemented on Windows, so the direction won't be inherited by descendants on GTK and Cocoa.
503
	 * currently only implemented on Windows, so the direction won't be
504
	 * inherited by descendants on GTK and Cocoa.
502
	 * <p>
505
	 * <p>
503
	 * <strong>Note:</strong>
504
	 * {@link BidiUtils#BTD_DEFAULT} is currently not inherited by descendants of the control if
505
	 * {@link BidiUtils#getTextDirection()} is {@link BidiUtils#AUTO}.
506
	 *
506
	 *
507
	 * @param control the control
507
	 * @param control
508
	 * @param textDirection the text direction
508
	 *            the control
509
	 * @param textDirection
510
	 *            the text direction
509
	 */
511
	 */
510
	public static void applyTextDirection(Control control, String textDirection) {
512
	public static void applyTextDirection(Control control, String textDirection) {
511
		int textDir = 0;
513
		int textDir = 0;
512
		boolean auto = false;
513
514
514
		if (LEFT_TO_RIGHT.equals(textDirection)) {
515
		if (LEFT_TO_RIGHT.equals(textDirection)) {
515
			textDir = SWT.LEFT_TO_RIGHT;
516
			textDir = SWT.LEFT_TO_RIGHT;
516
		} else if (RIGHT_TO_LEFT.equals(textDirection)) {
517
		} else if (RIGHT_TO_LEFT.equals(textDirection)) {
517
			textDir = SWT.RIGHT_TO_LEFT;
518
			textDir = SWT.RIGHT_TO_LEFT;
518
		} else if (AUTO.equals(textDirection)) {
519
		} else if (AUTO.equals(textDirection)) {
519
			auto = true;
520
			textDir = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
520
		} else if (getBidiSupport() && BTD_DEFAULT.equals(textDirection)) {
521
		} else if (getBidiSupport() && BTD_DEFAULT.equals(textDirection)) {
521
			if (LEFT_TO_RIGHT.equals(getTextDirection())) {
522
			if (LEFT_TO_RIGHT.equals(getTextDirection())) {
522
				textDir = SWT.LEFT_TO_RIGHT;
523
				textDir = SWT.LEFT_TO_RIGHT;
523
			} else if (RIGHT_TO_LEFT.equals(getTextDirection())) {
524
			} else if (RIGHT_TO_LEFT.equals(getTextDirection())) {
524
				textDir = SWT.RIGHT_TO_LEFT;
525
				textDir = SWT.RIGHT_TO_LEFT;
525
			} else if (AUTO.equals(getTextDirection())) {
526
			} else if (AUTO.equals(getTextDirection())) {
526
				auto = true;
527
				textDir = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
527
			}
528
			}
528
		}
529
		}
529
530
530
		if (control instanceof Text && (auto || textDir != 0)) {
531
		if (control instanceof Text && textDir != 0) {
531
			applyBidiProcessing((Text) control, textDirection);
532
			applyBidiProcessing((Text) control, textDirection);
532
		} else if (control instanceof StyledText && (auto || textDir != 0)) {
533
		} else if (control instanceof StyledText && textDir != 0) {
533
			applyBidiProcessing((StyledText) control, textDirection);
534
			applyBidiProcessing((StyledText) control, textDirection);
534
		} else if (control instanceof Combo && (auto || textDir != 0)) {
535
		} else if (control instanceof Combo && textDir != 0) {
535
			applyBidiProcessing((Combo) control, textDirection);
536
			applyBidiProcessing((Combo) control, textDirection);
536
		} else if (textDir != 0) {
537
		} else if (textDir != 0) {
537
			control.setTextDirection(textDir);
538
			control.setTextDirection(textDir);

Return to bug 467328