提交 3e96b323 编写于 作者: M mlapshin

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

Summary: Added right-to-left code branches to WindowsInternalFrameTitlePane and Metacity classes
Reviewed-by: alexp
上级 b1d4d370
...@@ -770,13 +770,12 @@ class Metacity implements SynthConstants { ...@@ -770,13 +770,12 @@ class Metacity implements SynthConstants {
JComponent maximizeButton = findChild(titlePane, "InternalFrameTitlePane.maximizeButton"); JComponent maximizeButton = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
JComponent closeButton = findChild(titlePane, "InternalFrameTitlePane.closeButton"); JComponent closeButton = findChild(titlePane, "InternalFrameTitlePane.closeButton");
int buttonGap = 0;
Insets button_border = (Insets)gm.get("button_border"); Insets button_border = (Insets)gm.get("button_border");
Dimension buttonDim = calculateButtonSize(titlePane); Dimension buttonDim = calculateButtonSize(titlePane);
int x = getInt("left_titlebar_edge");
int y = (button_border != null) ? button_border.top : 0; 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);
...@@ -787,18 +786,42 @@ class Metacity implements SynthConstants { ...@@ -787,18 +786,42 @@ class Metacity implements SynthConstants {
if (frame.isClosable()) { if (frame.isClosable()) {
closeButton.setBounds(x, y, buttonDim.width, buttonDim.height); closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= (buttonDim.width + buttonGap); 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);
}
} 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()) { if (frame.isMaximizable()) {
maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height); maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
x -= (buttonDim.width + buttonGap); x += buttonDim.width;
} }
if (frame.isIconifiable()) { if (frame.isIconifiable()) {
minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height); minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
} }
} }
}
} // end TitlePaneLayout } // end TitlePaneLayout
protected Map getFrameGeometry() { protected Map getFrameGeometry() {
...@@ -973,10 +996,8 @@ class Metacity implements SynthConstants { ...@@ -973,10 +996,8 @@ class Metacity implements SynthConstants {
String title = jif.getTitle(); String title = jif.getTitle();
if (title != null) { if (title != null) {
FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g); FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
if (jif.getComponentOrientation().isLeftToRight()) {
title = SwingUtilities2.clipStringIfNecessary(jif, fm, title, title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
calculateTitleTextWidth(g, jif)); calculateTitleArea(jif).width);
}
g.setColor(color); g.setColor(color);
SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent()); SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());
} }
...@@ -1010,9 +1031,10 @@ class Metacity implements SynthConstants { ...@@ -1010,9 +1031,10 @@ class Metacity implements SynthConstants {
JComponent titlePane = findChild(jif, "InternalFrame.northPane"); JComponent titlePane = findChild(jif, "InternalFrame.northPane");
Dimension buttonDim = calculateButtonSize(titlePane); Dimension buttonDim = calculateButtonSize(titlePane);
Insets title_border = (Insets)frameGeometry.get("title_border"); 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.y = 0;
r.height = titlePane.getHeight(); r.height = titlePane.getHeight();
if (title_border != null) { if (title_border != null) {
...@@ -1021,6 +1043,11 @@ class Metacity implements SynthConstants { ...@@ -1021,6 +1043,11 @@ class Metacity implements SynthConstants {
r.height -= (title_border.top + title_border.bottom); r.height -= (title_border.top + title_border.bottom);
} }
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"); r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");
if (jif.isClosable()) { if (jif.isClosable()) {
r.width -= buttonDim.width; r.width -= buttonDim.width;
...@@ -1031,6 +1058,22 @@ class Metacity implements SynthConstants { ...@@ -1031,6 +1058,22 @@ class Metacity implements SynthConstants {
if (jif.isIconifiable()) { if (jif.isIconifiable()) {
r.width -= buttonDim.width; 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) { if (title_border != null) {
r.width -= title_border.right; r.width -= title_border.right;
} }
......
...@@ -137,25 +137,46 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane { ...@@ -137,25 +137,46 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
fm.getDescent()) / 2; fm.getDescent()) / 2;
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 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; int titleW;
int gap = 2;
if(WindowsGraphicsUtils.isLeftToRight(frame) ) { if (WindowsGraphicsUtils.isLeftToRight(frame)) {
if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right; if (lastIconBounds.x == 0) { // There are no icons
titleX = systemLabel.getX() + systemLabel.getWidth() + 2; lastIconBounds.x = frame.getWidth() - frame.getInsets().right;
}
titleX = systemLabel.getX() + systemLabel.getWidth() + gap;
if (xp != null) { if (xp != null) {
titleX += 2; titleX += 2;
} }
titleW = r.x - titleX - 3; titleW = lastIconBounds.x - titleX - gap;
title = getTitle(frame.getTitle(), fm, titleW); } 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 { } else {
titleX = systemLabel.getX() - 2 titleX = minTitleX;
- SwingUtilities2.stringWidth(frame,fm,title); titleW = availableWidth;
} }
}
title = getTitle(frame.getTitle(), fm, titleW);
if (xp != null) { if (xp != null) {
String shadowType = null; String shadowType = null;
if (isSelected) { if (isSelected) {
......
...@@ -215,7 +215,7 @@ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane ...@@ -215,7 +215,7 @@ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane
protected void showSystemMenu() { protected void showSystemMenu() {
Insets insets = frame.getInsets(); Insets insets = frame.getInsets();
if (!frame.isIcon()) { if (!frame.isIcon()) {
systemPopupMenu.show(frame, insets.left, getY() + getHeight()); systemPopupMenu.show(frame, menuButton.getX(), getY() + getHeight());
} else { } else {
systemPopupMenu.show(menuButton, systemPopupMenu.show(menuButton,
getX() - insets.left - insets.right, getX() - insets.left - insets.right,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册