1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

bug 205443: [terminal] Workbench terminal view refresh problem between perspectives

https://bugs.eclipse.org/bugs/show_bug.cgi?id=205443
This commit is contained in:
Michael Scharf 2007-10-08 04:15:46 +00:00
parent a26aaa1e71
commit 384a4bd15b
5 changed files with 107 additions and 40 deletions

View file

@ -148,15 +148,12 @@ public class VT100Emulator implements ControlListener {
else
text=new VT100EmulatorBackend(data);
text.setDimensions(24, 80);
// text.setDimensions(24, 80);
Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
text.setDefaultStyle(style);
text.setStyle(style);
}
public void setDimensions(int lines,int cols) {
// TODO allow to set the dimension in the UI and or prefs
lines=Math.max(3, lines);
cols=Math.max(10, cols);
text.setDimensions(lines, cols);
ITerminalConnector telnetConnection = getConnector();
if (telnetConnection != null) {

View file

@ -37,14 +37,12 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
@ -114,7 +112,6 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
fConnectors=connectors;
fTerminalListener=target;
fTerminalModel=TerminalTextDataFactory.makeTerminalTextData();
fTerminalModel.setDimensions(24, 80);
fTerminalModel.setMaxHeight(1000);
fInputStream=new PipedInputStream(8*1024);
fTerminalText=new VT100Emulator(fTerminalModel,this,fInputStream);
@ -494,11 +491,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
fCtlText.setLayoutData(new GridData(GridData.FILL_BOTH));
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
fCtlText.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
Rectangle bonds=fCtlText.getClientArea();
int lines=bonds.height/fCtlText.getCellHeight();
int columns=bonds.width/fCtlText.getCellWidth();
fCtlText.addResizeHandler(new TextCanvas.ResizeListener() {
public void sizeChanged(int lines, int columns) {
fTerminalText.setDimensions(lines, columns);
}
});

View file

@ -39,6 +39,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
* do not update while update is running
*/
boolean fInUpdate;
private int fCols;
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
fSnapshot=snapshot;
@ -72,6 +73,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
}
}
public ITerminalTextDataReadOnly getTerminalText() {
return fSnapshot;
}
@ -88,9 +90,10 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
// TODO why does hasDimensionsChanged not work??????
// if(fSnapshot.hasDimensionsChanged())
// fireDimensionsChanged();
if(fLines!=fSnapshot.getHeight()) {
if(fLines!=fSnapshot.getHeight() || fCols!=fSnapshot.getWidth()) {
fireDimensionsChanged(fSnapshot.getWidth(),fSnapshot.getHeight());
fLines=fSnapshot.getHeight();
fCols=fSnapshot.getWidth();
}
int y=fSnapshot.getFirstChangedLine();
// has any line changed?

View file

@ -24,8 +24,6 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
/**
* A cell oriented Canvas. Maintains a list of "cells".
@ -39,6 +37,9 @@ public class TextCanvas extends GridCanvas {
private boolean fScrollLock;
private Point fDraggingStart;
private Point fDraggingEnd;
private ResizeListener fResizeListener;
private int fMinColumns=20;
private int fMinLines=4;
/**
* Create a new CellCanvas with the given SWT style bits.
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
@ -58,6 +59,7 @@ public class TextCanvas extends GridCanvas {
repaintRange(col,line,width,height);
}
public void dimensionsChanged(int cols, int rows) {
setVirtualExtend(cols+getCellWidth(), rows+getCellHeight());
calculateGrid();
}
public void terminalDataChanged() {
@ -66,11 +68,6 @@ public class TextCanvas extends GridCanvas {
scrollToEnd();
}
});
addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
calculateGrid();
}
});
addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
fCellCanvasModel.setCursorEnabled(true);
@ -109,6 +106,8 @@ public class TextCanvas extends GridCanvas {
}
}
});
serVerticalBarVisible(true);
setHorizontalBarVisible(false);
}
void setSelection(Point p) {
@ -146,6 +145,55 @@ public class TextCanvas extends GridCanvas {
public ILinelRenderer getCellRenderer() {
return fCellRenderer;
}
public int getMinColumns() {
return fMinColumns;
}
public void setMinColumns(int minColumns) {
fMinColumns = minColumns;
}
public int getMinLines() {
return fMinLines;
}
public void setMinLines(int minLines) {
fMinLines = minLines;
}
protected void onResize() {
// if(!isShowHScrollBar()) {
if(fResizeListener!=null) {
Rectangle bonds=getClientArea();
int lines=bonds.height/getCellHeight();
int columns=bonds.width/getCellWidth();
if(columns<fMinColumns) {
if(!isHorizontalBarVisble()) {
setHorizontalBarVisible(true);
bonds=getClientArea();
lines=bonds.height/getCellHeight();
}
columns=fMinColumns;
} else if(columns>=fMinColumns && isHorizontalBarVisble()) {
setHorizontalBarVisible(false);
bonds=getClientArea();
lines=bonds.height/getCellHeight();
columns=bonds.width/getCellWidth();
}
if(lines<fMinLines)
lines=fMinLines;
// if(lines>0 && columns>0 && (lines!=getRows()||columns!=getCols())) {
if(lines>0 && columns>0) {
fResizeListener.sizeChanged(lines, columns);
}
}
// }
super.onResize();
calculateGrid();
}
private void calculateGrid() {
setVirtualExtend(getCols()*getCellWidth(),getRows()*getCellHeight());
// scroll to end
@ -154,7 +202,6 @@ public class TextCanvas extends GridCanvas {
scrollY(getVerticalBar());
scrollX(getHorizontalBar());
updateViewRectangle();
getParent().layout();
redraw();
}
@ -163,7 +210,7 @@ public class TextCanvas extends GridCanvas {
int y=-(getRows()*getCellHeight()-getClientArea().height);
Rectangle v=getViewRectangle();
if(v.y!=y) {
setVirtualOrigin(0,y);
setVirtualOrigin(v.x,y);
}
}
}
@ -216,5 +263,24 @@ public class TextCanvas extends GridCanvas {
public boolean isEmpty() {
return false;
}
/**
* Gets notified when the visible size of the terminal changes.
* This should update the model!
*
*/
public interface ResizeListener {
void sizeChanged(int lines, int columns);
}
/**
* @param listener this listener gets notified, when the size of
* the widget changed. It should change the dimensions of the underlying
* terminaldata
*/
public void addResizeHandler(ResizeListener listener) {
if(fResizeListener!=null)
throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$
fResizeListener=listener;
}
}

View file

@ -51,7 +51,7 @@ public abstract class VirtualCanvas extends Canvas {
addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
fClientArea=getClientArea();
updateViewRectangle();
onResize();
}
});
getVerticalBar().addListener(SWT.Selection, new Listener() {
@ -77,6 +77,9 @@ public abstract class VirtualCanvas extends Canvas {
});
}
protected void onResize() {
updateViewRectangle();
}
protected void scrollX(ScrollBar hBar) {
int hSelection = hBar.getSelection ();
int destX = -hSelection - fVirtualBounds.x;
@ -209,7 +212,7 @@ public abstract class VirtualCanvas extends Canvas {
}
/**
* Sets the extend of the virtual dieplay ares
* Sets the extend of the virtual display ares
* @param width
* @param height
*/
@ -255,7 +258,7 @@ public abstract class VirtualCanvas extends Canvas {
}
/** called when the viewed part is changing */
private Rectangle fViewRectangle=new Rectangle(0,0,0,0);
void updateViewRectangle() {
protected void updateViewRectangle() {
if(
fViewRectangle.x==-fVirtualBounds.x
&& fViewRectangle.y==-fVirtualBounds.y
@ -303,32 +306,36 @@ public abstract class VirtualCanvas extends Canvas {
private void doUpdateScrollbar() {
Point size= getSize();
Rectangle clientArea= getClientArea();
ScrollBar horizontal= getHorizontalBar();
if (fVirtualBounds.width <= clientArea.width) {
// TODO IMPORTANT in ScrollBar.setVisible comment out the line
// that checks 'isvisible' and returns (at the beginning)
horizontal.setVisible(false);
horizontal.setSelection(0);
} else {
if(horizontal.isVisible()) {
horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement());
int max= fVirtualBounds.width + (size.x - clientArea.width);
horizontal.setMaximum(max);
horizontal.setThumb(size.x > max ? max : size.x);
horizontal.setVisible(true);
}
ScrollBar vertical= getVerticalBar();
if (fVirtualBounds.height <= clientArea.height) {
vertical.setVisible(false);
vertical.setSelection(0);
} else {
if(vertical.isVisible()) {
vertical.setPageIncrement(clientArea.height - vertical.getIncrement());
int max= fVirtualBounds.height + (size.y - clientArea.height);
vertical.setMaximum(max);
vertical.setThumb(size.y > max ? max : size.y);
vertical.setVisible(true);
}
}
protected boolean isVertialBarVisible() {
return getVerticalBar().isVisible();
}
protected void serVerticalBarVisible(boolean showVScrollBar) {
ScrollBar vertical= getVerticalBar();
vertical.setVisible(showVScrollBar);
vertical.setSelection(0);
}
protected boolean isHorizontalBarVisble() {
return getHorizontalBar().isVisible();
}
protected void setHorizontalBarVisible(boolean showHScrollBar) {
ScrollBar horizontal= getHorizontalBar();
horizontal.setVisible(showHScrollBar);
horizontal.setSelection(0);
}
}