home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / marquee / TextElement.class (.txt) < prev   
Encoding:
Java Class File  |  1998-01-08  |  4.2 KB  |  126 lines

  1. package icontrols.marquee;
  2.  
  3. import com.ms.wd.ui.Bitmap;
  4. import com.ms.wd.ui.Brush;
  5. import com.ms.wd.ui.Color;
  6. import com.ms.wd.ui.Control;
  7. import com.ms.wd.ui.Font;
  8. import com.ms.wd.ui.Graphics;
  9. import com.ms.wd.ui.Point;
  10. import com.ms.wd.ui.Rectangle;
  11. import com.ms.wd.win32.RECT;
  12. import com.ms.wd.win32.Windows;
  13.  
  14. public class TextElement implements IMarqueeElement {
  15.    String m_text;
  16.    Font m_font;
  17.    Color m_colorBack;
  18.    Color m_colorFore;
  19.    Bitmap m_bitmapCached;
  20.    Graphics m_graphicsCached;
  21.    Rectangle m_location = new Rectangle();
  22.    Object m_tag;
  23.    int m_wrapCount = 0;
  24.  
  25.    public void create(Control ctl, int width, int height) {
  26.       Graphics g = ctl.createGraphics();
  27.       if (this.m_font == null) {
  28.          this.m_font = g.getFont();
  29.       } else {
  30.          g.setFont(this.m_font);
  31.       }
  32.  
  33.       if (this.m_colorBack == null) {
  34.          this.m_colorBack = g.getBackColor();
  35.       }
  36.  
  37.       if (this.m_colorFore == null) {
  38.          this.m_colorFore = g.getTextColor();
  39.       }
  40.  
  41.       Point extents;
  42.       if (width == 0) {
  43.          extents = g.getTextSize(this.m_text);
  44.       } else {
  45.          extents = g.getTextSize(this.m_text, width, 16);
  46.       }
  47.  
  48.       this.m_location.width = width > extents.x | width == 0 ? extents.x : width;
  49.       this.m_location.height = height > extents.y | height == 0 ? extents.y : height;
  50.       this.m_bitmapCached = new Bitmap(extents.x, extents.y);
  51.       this.m_graphicsCached = this.m_bitmapCached.getGraphics();
  52.       this.m_graphicsCached.setFont(this.m_font);
  53.       this.m_graphicsCached.setBackColor(this.m_colorBack);
  54.       this.m_graphicsCached.setTextColor(this.m_colorFore);
  55.       if (width == 0) {
  56.          this.m_graphicsCached.drawString(this.m_text, 0, 0);
  57.       } else {
  58.          this.m_graphicsCached.setBrush(new Brush(this.m_colorBack));
  59.          this.m_graphicsCached.drawRect(0, 0, extents.x, extents.y);
  60.          this.m_graphicsCached.drawString(this.m_text, 0, 0, extents.x, extents.y, 16);
  61.       }
  62.  
  63.       g.dispose();
  64.    }
  65.  
  66.    public TextElement(Object tag, String text, Font font, Color fore, Color back) {
  67.       this.m_tag = tag;
  68.       this.m_text = text;
  69.       this.m_font = font;
  70.       this.m_colorBack = back;
  71.       this.m_colorFore = fore;
  72.    }
  73.  
  74.    public Object getTag() {
  75.       return this.m_tag;
  76.    }
  77.  
  78.    public Object getTag(int x, int y) {
  79.       return this.m_location.contains(x, y) ? this.m_tag : null;
  80.    }
  81.  
  82.    public void paintIn(Rectangle rec, Graphics g) {
  83.       if (this.m_graphicsCached != null) {
  84.          RECT recIntersect = new RECT();
  85.          RECT recPaint = rec.toRECT();
  86.          RECT recLocation = this.m_location.toRECT();
  87.          if (Windows.IntersectRect(recIntersect, recPaint, recLocation)) {
  88.             Windows.BitBlt(g.getHandle(), recIntersect.left, recIntersect.top, recIntersect.right - recIntersect.left, recIntersect.bottom - recIntersect.top, this.m_graphicsCached.getHandle(), recIntersect.left - this.m_location.x, recIntersect.top - this.m_location.y, 13369376);
  89.          }
  90.       }
  91.  
  92.    }
  93.  
  94.    public void scroll(int x, int y) {
  95.       Rectangle var10000 = this.m_location;
  96.       var10000.x += x;
  97.       var10000 = this.m_location;
  98.       var10000.y += y;
  99.    }
  100.  
  101.    public int getWrapCount() {
  102.       return this.m_wrapCount;
  103.    }
  104.  
  105.    public void setWrapCount(int i) {
  106.       this.m_wrapCount = i;
  107.    }
  108.  
  109.    public void finalize() {
  110.       if (this.m_graphicsCached != null) {
  111.          this.m_graphicsCached.dispose();
  112.          this.m_graphicsCached = null;
  113.       }
  114.  
  115.    }
  116.  
  117.    public Rectangle getBounds() {
  118.       return this.m_location;
  119.    }
  120.  
  121.    public void setLocation(int x, int y) {
  122.       this.m_location.x = x;
  123.       this.m_location.y = y;
  124.    }
  125. }
  126.