home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
- import netscape.util.Vector;
-
- public class ScrollView extends View implements Scrollable {
- View contentView;
- Color backgroundColor;
- Rect clipRect;
- Vector scrollBars;
- boolean transparent;
- private boolean scrollBarUpdatesEnabled;
- static final String CONTENTVIEW_KEY = "contentView";
- static final String BACKGROUNDC_KEY = "backgroundColor";
- static final String SCROLLERS_KEY = "scrollBars";
- static final String SCROLLERUPDATES_KEY = "scrollBarUpdatesEnabed";
- static final String TRANSPARENT_KEY = "transparent";
-
- public ScrollView() {
- this(0, 0, 0, 0);
- }
-
- public ScrollView(Rect var1) {
- this(var1.x, var1.y, var1.width, var1.height);
- }
-
- public ScrollView(int var1, int var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this.transparent = false;
- this.scrollBarUpdatesEnabled = true;
- this.scrollBars = new Vector();
- this.backgroundColor = Color.lightGray;
- ((View)this).setHorizResizeInstruction(2);
- ((View)this).setVertResizeInstruction(16);
- }
-
- public void addSubview(View var1) {
- ((View)this).subviews().removeAllElements();
- super.addSubview(var1);
- }
-
- public void setContentView(View var1) {
- if (this.contentView != null) {
- this.contentView.removeFromSuperview();
- }
-
- this.contentView = var1;
- if (this.contentView != null) {
- this.contentView.moveTo(0, 0);
- this.addSubview(this.contentView);
- }
-
- this.updateScrollBars();
- }
-
- public View contentView() {
- return this.contentView;
- }
-
- public int cursorForPoint(int var1, int var2) {
- if (this.contentView == null) {
- return 0;
- } else {
- Point var3 = Point.newPoint(var1, var2);
- ((View)this).convertPointToView(this.contentView, var3, var3);
- int var4 = this.contentView.cursorForPoint(var3.x, var3.y);
- Point.returnPoint(var3);
- return var4;
- }
- }
-
- public void setBackgroundColor(Color var1) {
- if (var1 != null) {
- this.backgroundColor = var1;
- }
-
- }
-
- public Color backgroundColor() {
- return this.backgroundColor;
- }
-
- public void setTransparent(boolean var1) {
- this.transparent = var1;
- }
-
- public boolean isTransparent() {
- return this.transparent;
- }
-
- public void addScrollBar(Target var1) {
- this.scrollBars.addElementIfAbsent(var1);
- }
-
- public void removeScrollBar(Target var1) {
- this.scrollBars.removeElement(var1);
- }
-
- public void setScrollBarUpdatesEnabled(boolean var1) {
- this.scrollBarUpdatesEnabled = var1;
- }
-
- public boolean scrollBarUpdatesEnabled() {
- return this.scrollBarUpdatesEnabled;
- }
-
- public void updateScrollBars() {
- if (this.scrollBarUpdatesEnabled) {
- int var3 = this.scrollBars.count();
-
- for(int var2 = 0; var2 < var3; ++var2) {
- Target var1 = (Target)this.scrollBars.elementAt(var2);
- var1.performCommand("updateScrollValue", this);
- }
-
- }
- }
-
- View scrollingView() {
- return this;
- }
-
- public void scrollRectToVisible(Rect var1) {
- int var2 = 0;
- int var3 = 0;
- if (var1 != null && this.contentView != null) {
- var2 = this.positionAdjustment(super.bounds.width, var1.width, var1.x);
- var3 = this.positionAdjustment(super.bounds.height, var1.height, var1.y);
- if (var2 != 0 || var3 != 0) {
- this.scrollBy(var2, var3);
- }
-
- }
- }
-
- private int positionAdjustment(int var1, int var2, int var3) {
- if (var3 >= 0 && var2 + var3 <= var1) {
- return 0;
- } else if (var3 <= 0 && var2 + var3 >= var1) {
- return 0;
- } else if (var3 > 0 && var2 <= var1) {
- return -var3 + var1 - var2;
- } else if (var3 >= 0 && var2 >= var1) {
- return -var3;
- } else if (var3 <= 0 && var2 <= var1) {
- return -var3;
- } else {
- return var3 < 0 && var2 >= var1 ? -var3 + var1 - var2 : 0;
- }
- }
-
- public void scrollTo(int var1, int var2) {
- Rect var3 = null;
- if (this.contentView != null) {
- this.setClipRect((Rect)null);
- if (var1 <= 0 && super.bounds.width < this.contentView.bounds.width) {
- if (var1 < super.bounds.width - this.contentView.bounds.width) {
- var1 = super.bounds.width - this.contentView.bounds.width;
- }
- } else {
- var1 = 0;
- }
-
- if (var2 <= 0 && super.bounds.height < this.contentView.bounds.height) {
- if (var2 < super.bounds.height - this.contentView.bounds.height) {
- var2 = super.bounds.height - this.contentView.bounds.height;
- }
- } else {
- var2 = 0;
- }
-
- int var4 = var1 - this.contentView.bounds.x;
- int var5 = var2 - this.contentView.bounds.y;
- if (var4 == 0 && var5 == 0) {
- this.updateScrollBars();
- } else {
- boolean var6 = ((View)this).isBuffered() && super.drawingBufferValid;
- if (var6) {
- if (var4 != 0 && var5 == 0 && Math.abs(var4) < super.bounds.width) {
- if (var4 < 0) {
- var3 = Rect.newRect(super.bounds.width + var4, 0, -var4, super.bounds.height);
- } else {
- var3 = Rect.newRect(0, 0, var4, super.bounds.height);
- }
- } else if (var4 == 0 && var5 != 0 && Math.abs(var5) < super.bounds.height) {
- if (var5 < 0) {
- var3 = Rect.newRect(0, super.bounds.height + var5, super.bounds.width, -var5);
- } else {
- var3 = Rect.newRect(0, 0, super.bounds.width, var5);
- }
- }
-
- if (var3 != null) {
- this.contentView.moveTo(var1, var2);
- this.setClipRect(var3);
- Rect.returnRect(var3);
- } else {
- this.contentView.moveTo(var1, var2);
- }
- } else {
- this.contentView.moveTo(var1, var2);
- }
-
- if (this.scrollBarUpdatesEnabled) {
- this.updateScrollBars();
- }
-
- ((View)this).setDirty(true);
- }
- }
- }
-
- public void scrollBy(int var1, int var2) {
- if (this.contentView != null) {
- this.scrollTo(this.contentView.bounds.x + var1, this.contentView.bounds.y + var2);
- }
-
- }
-
- public void subviewDidResize(View var1) {
- if (var1 == this.contentView) {
- this.scrollBy(0, 0);
- this.drawBackground();
- }
- }
-
- public void didSizeBy(int var1, int var2) {
- super.didSizeBy(var1, var2);
- this.scrollBy(0, 0);
- }
-
- void setClipRect(Rect var1) {
- if (this.clipRect != null) {
- Rect.returnRect(this.clipRect);
- }
-
- if (var1 != null) {
- this.clipRect = Rect.newRect(var1);
- } else {
- this.clipRect = null;
- }
- }
-
- void updateDrawingBuffer(Rect var1) {
- if (this.clipRect != null && ((View)this).isBuffered() && !this.isTransparent()) {
- Graphics var2 = super.drawingBuffer.createGraphics();
- var2.setDebugOptions(((View)this).shouldDebugGraphics());
- if (this.clipRect.height != super.bounds.height) {
- if (this.clipRect.y == 0) {
- var2.copyArea(this.clipRect.x, this.clipRect.y, this.clipRect.width, super.bounds.height - this.clipRect.height, this.clipRect.x, this.clipRect.maxY());
- } else {
- var2.copyArea(0, this.clipRect.height, this.clipRect.width, super.bounds.height - this.clipRect.height, 0, 0);
- }
- } else if (this.clipRect.x == 0) {
- var2.copyArea(this.clipRect.x, this.clipRect.y, super.bounds.width - this.clipRect.width, this.clipRect.height, this.clipRect.maxX(), this.clipRect.y);
- } else {
- var2.copyArea(this.clipRect.width, 0, super.bounds.width - this.clipRect.width, this.clipRect.height, 0, 0);
- }
-
- var2.dispose();
- Object var4 = null;
- var1 = new Rect(var1);
- Rect var3 = new Rect(0, 0, 0, 0);
- this.contentView.getDirtyRect(var3);
- if (var3.isEmpty()) {
- var1.intersectWith(this.clipRect);
- } else {
- var3.unionWith(this.clipRect);
- var1.intersectWith(var3);
- }
-
- this.setClipRect((Rect)null);
- }
-
- super.updateDrawingBuffer(var1);
- }
-
- public void computeVisibleRect(Rect var1) {
- super.computeVisibleRect(var1);
- if (this.clipRect != null) {
- var1.intersectWith(this.clipRect);
- }
-
- }
-
- public void drawView(Graphics var1) {
- if (!this.isTransparent()) {
- if (this.contentView != null && this.contentView.isTransparent()) {
- var1.setColor(this.backgroundColor);
- Rect var2 = var1.clipRect();
- var1.fillRect(var2.x, var2.y, var2.width, var2.height);
- } else {
- int var3;
- int var4;
- if (this.contentView != null) {
- var3 = super.bounds.width - this.contentView.bounds.width;
- var4 = super.bounds.height - this.contentView.bounds.height;
- } else {
- var3 = super.bounds.width;
- var4 = super.bounds.height;
- }
-
- if (var3 > 0) {
- var1.setColor(this.backgroundColor);
- var1.fillRect(super.bounds.width - var3, 0, var3, super.bounds.height);
- }
-
- if (var4 > 0) {
- var1.setColor(this.backgroundColor);
- var1.fillRect(0, super.bounds.height - var4, super.bounds.width, var4);
- }
-
- if (this.clipRect != null && ((View)this).isBuffered()) {
- if (this.clipRect.y == super.bounds.y) {
- super.drawingBuffer.drawAt(var1, this.clipRect.x, this.clipRect.maxY());
- return;
- }
-
- super.drawingBuffer.drawAt(var1, this.clipRect.x, -this.clipRect.height);
- }
-
- }
- }
- }
-
- public void drawSubviews(Graphics var1) {
- super.drawSubviews(var1);
- this.setClipRect((Rect)null);
- }
-
- void drawBackground() {
- int var2;
- int var3;
- if (this.contentView != null) {
- var2 = super.bounds.width - this.contentView.bounds.width;
- var3 = super.bounds.height - this.contentView.bounds.height;
- } else {
- var2 = super.bounds.width;
- var3 = super.bounds.height;
- }
-
- Rect var1 = Rect.newRect();
- if (var2 > 0) {
- var1.setBounds(super.bounds.width - var2, 0, var2, super.bounds.height);
- ((View)this).addDirtyRect(var1);
- }
-
- if (var3 > 0) {
- var1.setBounds(0, super.bounds.height - var3, super.bounds.width, var3);
- ((View)this).addDirtyRect(var1);
- }
-
- Rect.returnRect(var1);
- }
-
- public boolean mouseDown(MouseEvent var1) {
- if (this.contentView != null) {
- boolean var2 = this.contentView.mouseDown(((View)this).convertEventToView(this.contentView, var1));
- if (var2) {
- ((View)this).rootView().setMouseView(this.contentView);
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public DragDestination acceptsDrag(DragSession var1, int var2, int var3) {
- return this.contentView != null ? this.contentView.acceptsDrag(var1, var2 - this.contentView.bounds.x, var3 - this.contentView.bounds.y) : null;
- }
-
- public int lengthOfScrollViewForAxis(int var1) {
- return var1 == 0 ? super.bounds.width : super.bounds.height;
- }
-
- public int lengthOfContentViewForAxis(int var1) {
- if (this.contentView == null) {
- return 0;
- } else {
- return var1 == 0 ? this.contentView.bounds.width : this.contentView.bounds.height;
- }
- }
-
- public int positionOfContentViewForAxis(int var1) {
- if (this.contentView == null) {
- return 0;
- } else {
- return var1 == 0 ? this.contentView.bounds.x : this.contentView.bounds.y;
- }
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.ScrollView", 1);
- var1.addField("contentView", (byte)18);
- var1.addField("backgroundColor", (byte)18);
- var1.addField("scrollBars", (byte)18);
- var1.addField("scrollBarUpdatesEnabed", (byte)0);
- var1.addField("transparent", (byte)0);
- }
-
- public void encode(Encoder var1) throws CodingException {
- super.encode(var1);
- var1.encodeObject("contentView", this.contentView);
- var1.encodeObject("backgroundColor", this.backgroundColor);
- var1.encodeObject("scrollBars", this.scrollBars);
- var1.encodeBoolean("scrollBarUpdatesEnabed", this.scrollBarUpdatesEnabled);
- var1.encodeBoolean("transparent", this.transparent);
- }
-
- public void decode(Decoder var1) throws CodingException {
- super.decode(var1);
- this.contentView = (View)var1.decodeObject("contentView");
- this.backgroundColor = (Color)var1.decodeObject("backgroundColor");
- this.scrollBars = (Vector)var1.decodeObject("scrollBars");
- this.scrollBarUpdatesEnabled = var1.decodeBoolean("scrollBarUpdatesEnabed");
- this.transparent = var1.decodeBoolean("transparent");
- }
- }
-