6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation

Added right-to-left code branches to WindowsInternalFrameTitlePane and Metacity classes

Reviewed-by: alexp
This commit is contained in:
Mikhail Lapshin 2008-08-11 16:49:46 +04:00
parent 3b50ea9003
commit aeb1b5f21c
3 changed files with 116 additions and 52 deletions
jdk/src/share/classes
com/sun/java/swing/plaf
javax/swing/plaf/synth

@ -770,33 +770,56 @@ class Metacity implements SynthConstants {
JComponent maximizeButton = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
JComponent closeButton = findChild(titlePane, "InternalFrameTitlePane.closeButton");
int buttonGap = 0;
Insets button_border = (Insets)gm.get("button_border");
Dimension buttonDim = calculateButtonSize(titlePane);
int x = getInt("left_titlebar_edge");
int y = (button_border != null) ? button_border.top : 0;
if (titlePaneParent.getComponentOrientation().isLeftToRight()) {
int x = getInt("left_titlebar_edge");
menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x = w - buttonDim.width - getInt("right_titlebar_edge");
if (button_border != null) {
x -= button_border.right;
}
x = w - buttonDim.width - getInt("right_titlebar_edge");
if (button_border != null) {
x -= button_border.right;
}
if (frame.isClosable()) {
closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= (buttonDim.width + buttonGap);
}
if (frame.isClosable()) {
closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= buttonDim.width;
}
if (frame.isMaximizable()) {
maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= (buttonDim.width + buttonGap);
}
if (frame.isMaximizable()) {
maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= buttonDim.width;
}
if (frame.isIconifiable()) {
minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
if (frame.isIconifiable()) {
minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
}
} else {
int x = w - buttonDim.width - getInt("right_titlebar_edge");
menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x = getInt("left_titlebar_edge");
if (button_border != null) {
x += button_border.left;
}
if (frame.isClosable()) {
closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x += buttonDim.width;
}
if (frame.isMaximizable()) {
maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x += buttonDim.width;
}
if (frame.isIconifiable()) {
minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
}
}
}
} // end TitlePaneLayout
@ -973,10 +996,8 @@ class Metacity implements SynthConstants {
String title = jif.getTitle();
if (title != null) {
FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
if (jif.getComponentOrientation().isLeftToRight()) {
title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
calculateTitleTextWidth(g, jif));
}
title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
calculateTitleArea(jif).width);
g.setColor(color);
SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());
}
@ -1010,9 +1031,10 @@ class Metacity implements SynthConstants {
JComponent titlePane = findChild(jif, "InternalFrame.northPane");
Dimension buttonDim = calculateButtonSize(titlePane);
Insets title_border = (Insets)frameGeometry.get("title_border");
Rectangle r = new Rectangle();
Insets button_border = (Insets)getFrameGeometry().get("button_border");
r.x = getInt("left_titlebar_edge") + buttonDim.width;
Rectangle r = new Rectangle();
r.x = getInt("left_titlebar_edge");
r.y = 0;
r.height = titlePane.getHeight();
if (title_border != null) {
@ -1021,15 +1043,36 @@ class Metacity implements SynthConstants {
r.height -= (title_border.top + title_border.bottom);
}
r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");
if (jif.isClosable()) {
r.width -= buttonDim.width;
}
if (jif.isMaximizable()) {
r.width -= buttonDim.width;
}
if (jif.isIconifiable()) {
r.width -= buttonDim.width;
if (titlePane.getParent().getComponentOrientation().isLeftToRight()) {
r.x += buttonDim.width;
if (button_border != null) {
r.x += button_border.left;
}
r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");
if (jif.isClosable()) {
r.width -= buttonDim.width;
}
if (jif.isMaximizable()) {
r.width -= buttonDim.width;
}
if (jif.isIconifiable()) {
r.width -= buttonDim.width;
}
} else {
if (jif.isClosable()) {
r.x += buttonDim.width;
}
if (jif.isMaximizable()) {
r.x += buttonDim.width;
}
if (jif.isIconifiable()) {
r.x += buttonDim.width;
}
r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge")
- buttonDim.width;
if (button_border != null) {
r.x -= button_border.right;
}
}
if (title_border != null) {
r.width -= title_border.right;

@ -137,25 +137,46 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
fm.getDescent()) / 2;
int titleX;
Rectangle r = new Rectangle(0, 0, 0, 0);
if (frame.isIconifiable()) r = iconButton.getBounds();
else if (frame.isMaximizable()) r = maxButton.getBounds();
else if (frame.isClosable()) r = closeButton.getBounds();
int titleW;
if(WindowsGraphicsUtils.isLeftToRight(frame) ) {
if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right;
titleX = systemLabel.getX() + systemLabel.getWidth() + 2;
if (xp != null) {
titleX += 2;
}
titleW = r.x - titleX - 3;
title = getTitle(frame.getTitle(), fm, titleW);
} else {
titleX = systemLabel.getX() - 2
- SwingUtilities2.stringWidth(frame,fm,title);
Rectangle lastIconBounds = new Rectangle(0, 0, 0, 0);
if (frame.isIconifiable()) {
lastIconBounds = iconButton.getBounds();
} else if (frame.isMaximizable()) {
lastIconBounds = maxButton.getBounds();
} else if (frame.isClosable()) {
lastIconBounds = closeButton.getBounds();
}
int titleX;
int titleW;
int gap = 2;
if (WindowsGraphicsUtils.isLeftToRight(frame)) {
if (lastIconBounds.x == 0) { // There are no icons
lastIconBounds.x = frame.getWidth() - frame.getInsets().right;
}
titleX = systemLabel.getX() + systemLabel.getWidth() + gap;
if (xp != null) {
titleX += 2;
}
titleW = lastIconBounds.x - titleX - gap;
} else {
if (lastIconBounds.x == 0) { // There are no icons
lastIconBounds.x = frame.getInsets().left;
}
titleW = SwingUtilities2.stringWidth(frame, fm, title);
int minTitleX = lastIconBounds.x + lastIconBounds.width + gap;
if (xp != null) {
minTitleX += 2;
}
int availableWidth = systemLabel.getX() - gap - minTitleX;
if (availableWidth > titleW) {
titleX = systemLabel.getX() - gap - titleW;
} else {
titleX = minTitleX;
titleW = availableWidth;
}
}
title = getTitle(frame.getTitle(), fm, titleW);
if (xp != null) {
String shadowType = null;
if (isSelected) {

@ -215,7 +215,7 @@ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane
protected void showSystemMenu() {
Insets insets = frame.getInsets();
if (!frame.isIcon()) {
systemPopupMenu.show(frame, insets.left, getY() + getHeight());
systemPopupMenu.show(frame, menuButton.getX(), getY() + getHeight());
} else {
systemPopupMenu.show(menuButton,
getX() - insets.left - insets.right,