diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index 92056be90c..f9f75ef205 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -1581,6 +1581,26 @@ public Point getSize () { } /** + * Returns the text direction of the receiver, which will be one of the + * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. + * + * @return the text direction style + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.102 + */ +public int getTextDirection() { + checkWidget (); + int flags = OS.WS_EX_LAYOUTRTL | OS.WS_EX_RTLREADING; + int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE) & flags; + return bits == 0 || bits == flags ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT; +} + +/** * Returns the receiver's tool tip text, or null if it has * not been set. * @@ -3488,6 +3508,7 @@ public void setOrientation (int orientation) { style &= ~SWT.MIRRORED; style &= ~flags; style |= orientation & flags; + style &= ~SWT.FLIP_TEXT_DIRECTION; updateOrientation (); checkMirrored (); } @@ -3651,6 +3672,35 @@ boolean setTabItemFocus () { } /** + * Sets the base text direction (a.k.a. "paragraph direction") of the receiver, + * which must be one of the constants <code>SWT.LEFT_TO_RIGHT</code> or + * <code>SWT.RIGHT_TO_LEFT</code>. + * <p> + * <code>setOrientation</code> would override this value with the text direction + * that is consistent with the new orientation. + * + * @param textDirection the base text direction style + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.102 + */ +public void setTextDirection(int textDirection) { + checkWidget (); + if (OS.IsWinCE) return; + if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return; + int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; + textDirection &= flags; + if (textDirection == 0 || textDirection == flags) return; + if (updateTextDirection(textDirection)) { + OS.InvalidateRect (handle, null, true); + } +} + +/** * Sets the receiver's tool tip text to the argument, which * may be null indicating that the default tool tip for the * control will be shown. For a control that has a default @@ -4420,10 +4470,35 @@ void updateOrientation () { } else { bits &= ~OS.WS_EX_LAYOUTRTL; } + bits &= ~OS.WS_EX_RTLREADING; OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits); OS.InvalidateRect (handle, null, true); } +boolean updateTextDirection (int textDirection) { + int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); + /* + * OS.WS_EX_RTLREADING means that the text direction is opposite to the + * natural one for the current layout. So text direction would be RTL when + * one and only one of the flags OS.WS_EX_LAYOUTRTL | OS.WS_EX_RTLREADING is + * on. + */ + int flags = OS.WS_EX_LAYOUTRTL | OS.WS_EX_RTLREADING; + boolean oldRtl = ((bits & flags) != 0 && (bits & flags) != flags); + boolean newRtl = textDirection == SWT.RIGHT_TO_LEFT; + if (newRtl == oldRtl) return false; + oldRtl = (bits & OS.WS_EX_LAYOUTRTL) != 0; + if (newRtl != oldRtl) { + bits |= OS.WS_EX_RTLREADING; + style |= SWT.FLIP_TEXT_DIRECTION; + } else { + bits &= ~OS.WS_EX_RTLREADING; + style &= ~SWT.FLIP_TEXT_DIRECTION; + } + OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits); + return true; +} + CREATESTRUCT widgetCreateStruct () { return null; } @@ -4446,6 +4521,7 @@ int widgetExtStyle () { } bits |= OS.WS_EX_NOINHERITLAYOUT; if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL; + if ((style & SWT.FLIP_TEXT_DIRECTION) != 0) bits |= OS.WS_EX_RTLREADING; return bits; } |