import com.tigervnc.rfb.Point;
import com.tigervnc.rfb.Rect;
-class ViewportFrame extends JFrame implements ComponentListener
+class ViewportFrame extends JFrame
{
public ViewportFrame(String name, CConn cc_) {
cc = cc_;
cc.close();
}
});
- addComponentListener(this);
- }
-
- public void componentResized(ComponentEvent e) {
- if (cc.options.autoScale || cc.options.fixedRatioScale) {
- if (sp.getSize().width != cc.desktop.scaledWidth ||
- sp.getSize().height != cc.desktop.scaledHeight) {
- cc.reconfigureViewport();
- if (cc.desktop.cursor != null) {
- Cursor cursor = cc.desktop.cursor;
- cc.setCursor(cursor.width(),cursor.height(),cursor.hotspot,
- cursor.data, cursor.mask);
- }
+ addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent e) {
+ if (cc.options.autoScale || cc.options.fixedRatioScale) {
+ if (sp.getSize().width != cc.desktop.scaledWidth ||
+ sp.getSize().height != cc.desktop.scaledHeight) {
+ cc.desktop.setScaledSize();
+ sp.setSize(new Dimension(cc.desktop.scaledWidth,
+ cc.desktop.scaledHeight));
+ sp.validate();
+ pack();
+ update(g);
+ if (cc.desktop.cursor != null) {
+ Cursor cursor = cc.desktop.cursor;
+ cc.setCursor(cursor.width(),cursor.height(),cursor.hotspot,
+ cursor.data, cursor.mask);
+ }
+ }
+ }
}
- }
- }
-
- public void componentHidden(ComponentEvent e) {
- }
-
- public void componentShown(ComponentEvent e) {
- }
-
- public void componentMoved(ComponentEvent e) {
+ });
}
public void addChild(DesktopWindow child) {
desktop.requestFocusInWindow();
}
- public void reconfigureViewport()
+ private void reconfigureViewport()
{
//viewport.setMaxSize(cp.width, cp.height);
boolean pack = true;
viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
viewport.setGeometry(0, 0, dpySize.width, dpySize.height, false);
} else {
- int wmDecorationWidth = 0;
- int wmDecorationHeight = 24;
+ int wmDecorationWidth = viewport.getInsets().left + viewport.getInsets().right;
+ int wmDecorationHeight = viewport.getInsets().top + viewport.getInsets().bottom;
if (w + wmDecorationWidth >= dpySize.width) {
w = dpySize.width - wmDecorationWidth;
pack = false;
String scaleString = viewer.scalingFactor.getValue();
if (scaleString.equals("Auto")) {
options.autoScale = true;
+ options.scalingFactor.setSelectedItem("Auto");
// FIXME: set scaleFactor?
- } else if( scaleString.equals("FixedRatio")) {
+ } else if(scaleString.equals("FixedRatio")) {
options.fixedRatioScale = true;
+ options.scalingFactor.setSelectedItem("Fixed Aspect Ratio");
// FIXME: set scaleFactor?
} else {
digit = Integer.parseInt(scaleString);
scaledWidth = cc.cp.width;
scaledHeight = cc.cp.height;
} else {
- Dimension availableSize = cc.viewport.sp.getSize();
+ Dimension vpSize = cc.viewport.getSize();
+ Insets vpInsets = cc.viewport.getInsets();
+ Dimension availableSize =
+ new Dimension(vpSize.width - vpInsets.left - vpInsets.right,
+ vpSize.height - vpInsets.top - vpInsets.bottom);
if (availableSize.width == 0 || availableSize.height == 0)
availableSize = new Dimension(cc.cp.width, cc.cp.height);
if (cc.options.fixedRatioScale) {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() ==
(KeyEvent.VK_F1+cc.menuKey-Keysyms.F1)) {
- cc.showMenu(lastX, lastY);
+ int sx = (scaleWidthRatio == 1.00)
+ ? lastX : (int)Math.floor(lastX*scaleWidthRatio);
+ int sy = (scaleHeightRatio == 1.00)
+ ? lastY : (int)Math.floor(lastY*scaleHeightRatio);
+ java.awt.Point ev = new java.awt.Point(lastX, lastY);
+ ev.translate(sx - lastX, sy - lastY);
+ cc.showMenu((int)ev.getX(), (int)ev.getY());
return;
}
if (!cc.viewer.viewOnly.getValue())