home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / win32 / MComponentPeer.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  9.0 KB  |  305 lines

  1. /*
  2.  * @(#)MComponentPeer.java    1.28 96/03/31 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package sun.awt.win32;
  20.  
  21. import java.awt.*;
  22. import java.awt.peer.*;
  23. import sun.awt.ScreenUpdater;
  24. import sun.awt.UpdateClient;
  25. import sun.awt.image.ImageRepresentation;
  26. import java.awt.image.ImageProducer;
  27. import java.awt.image.ImageObserver;
  28. import java.awt.image.ColorModel;
  29. import java.awt.image.DirectColorModel;
  30. import com.ms.awt.peer.ComponentPeerX;
  31. import com.ms.awt.GraphicsX;
  32.  
  33. public /* REMIND: should not be public */
  34. abstract class MComponentPeer implements ComponentPeerX, UpdateClient, ComponentPeer{
  35.     Component    target;
  36.     int     pData;
  37.     int        pWinMsg;
  38.  
  39.     abstract void create(MComponentPeer parent);
  40.     void create(MComponentPeer parent, Object arg) {
  41.     create(parent);
  42.     }
  43.     native void pInitialize();
  44.     native void pShow();
  45.     native void pHide();
  46.     native void pEnable();
  47.     native void pDisable();
  48.     native void pReshape(int x, int y, int width, int height);
  49.     native void pRepaint(int x, int y, int width, int height);
  50.     native void pDispose();
  51.     native int  pGethwnd();
  52.     native void pGetPlaceOnScreen(Rectangle r);
  53.     
  54.     public int gethwnd()
  55.     {
  56.         return pGethwnd();
  57.     }
  58.  
  59.     public void GetPlaceOnScreen(Rectangle r)
  60.     {
  61.         pGetPlaceOnScreen(r);
  62.     }
  63.     
  64.     void initialize() {
  65.     if (target.isVisible()) {
  66.         show();
  67.     } else {
  68.         hide();
  69.     }
  70.     Color c;
  71.     Font  f;
  72.  
  73.     if ((c = target.getForeground()) != null) {
  74.         setForeground(c);
  75.     }
  76.     if ((c = target.getBackground()) != null) {
  77.         setBackground(c);
  78.     }
  79.     if ((f = target.getFont()) != null) {
  80.         setFont(f);
  81.     }
  82.     if (! target.isEnabled()) {
  83.         disable();
  84.     }
  85.     Rectangle r = target.bounds();
  86.     reshape(r.x, r.y, r.width, r.height);
  87.     pInitialize();
  88.     }
  89.  
  90.     MComponentPeer(Component target, Object arg) {
  91.     this.target = target;
  92.     Container parent = target.getParent();
  93.     create((MComponentPeer)((parent != null) ? parent.getPeer() : null), arg);
  94.     initialize();
  95.     }
  96.  
  97.     MComponentPeer(Component target) {
  98.     this.target = target;
  99.     Container parent = target.getParent();
  100.     create((MComponentPeer)((parent != null) ? parent.getPeer() : null));
  101.     initialize();
  102.     }
  103.  
  104.     public native void setForeground(Color c);
  105.     public native void setBackground(Color c);
  106.     public native void setFont(Font f);
  107.  
  108.     public ColorModel getColorModel() {
  109.     return MToolkit.getStaticColorModel();
  110.     }
  111.  
  112.     public void show() {
  113.     pShow();
  114.     }
  115.     public void hide() {
  116.     pHide();
  117.     }
  118.     public void enable() {
  119.     pEnable();
  120.     }
  121.     public void disable() {
  122.     pDisable();
  123.     }
  124.     private int updateX1, updateY1, updateX2, updateY2;
  125.     public int updatePriority() {
  126.     return Thread.NORM_PRIORITY;
  127.     }
  128.     public void updateClient(Object arg) {
  129.     int x1, y1, x2, y2;
  130.     synchronized (this) {
  131.         x1 = updateX1;
  132.         y1 = updateY1;
  133.         x2 = updateX2;
  134.         y2 = updateY2;
  135.         updateX1 = updateX2;
  136.     }
  137.     if (x1 != x2) {
  138.         pRepaint(x1, y1, x2 - x1, y2 - y1);
  139.     }
  140.     }
  141.     private synchronized void addRepaintArea(int x, int y, int w, int h) {
  142.     if (updateX1 == updateX2) {
  143.         updateX1 = x;
  144.         updateY1 = y;
  145.         updateX2 = x + w;
  146.         updateY2 = y + h;
  147.     } else {
  148.         if (x < updateX1) updateX1 = x;
  149.         if (y < updateY1) updateY1 = y;
  150.         if (x + w > updateX2) updateX2 = x + w;
  151.         if (y + h > updateY2) updateY2 = y + h;
  152.     }
  153.     }
  154.     public void repaint(long tm, int x, int y, int width, int height) {
  155.     addRepaintArea(x, y, width, height);
  156.     ScreenUpdater.updater.notify(this, tm);
  157.     }
  158.     public void paint(Graphics g) {
  159.     g.setColor(target.getForeground());
  160.     g.setFont(target.getFont());
  161.     target.paint(g);
  162.     }
  163.     public void update(Graphics g) {
  164.     g.setColor(target.getForeground());
  165.     g.setFont(target.getFont());
  166.     target.update(g);
  167.     }
  168.     public void print(Graphics g) {
  169.     Dimension d = target.size();
  170.     g.setColor(target.getForeground());
  171.     g.setFont(target.getFont());
  172.     g.drawRect(0, 0, d.width - 1, d.height - 1);
  173.     target.print(g);
  174.     }
  175.     public void reshape(int x, int y, int width, int height) {
  176.     pReshape(x, y, width, height);
  177.     }
  178.     public native boolean handleEvent(Event e);
  179.  
  180.     public Dimension minimumSize() {
  181.     return target.size();
  182.     }
  183.     public Dimension preferredSize() {
  184.     return minimumSize();
  185.     }
  186.     public java.awt.Toolkit getToolkit() {
  187.     // XXX: bogus
  188.     return Toolkit.getDefaultToolkit();
  189.     }
  190.     public Graphics getGraphics() 
  191.     {
  192.         // Change this to allow com.ms.awt.GrapicsX to come into play
  193. //        System.out.println("MComponentPeer::getGraphics() --> Asking for GraphicsX");
  194.         Graphics g = new GraphicsX(this);
  195.         g.setColor(target.getForeground());
  196.         g.setFont(target.getFont());
  197.         return g;
  198.     }
  199.     public Image createImage(ImageProducer producer) {
  200.     return new Win32Image(producer);
  201.     }
  202.     public Image createImage(int width, int height) {
  203.     return new Win32Image(target, width, height);
  204.     }
  205.     public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
  206.     return MToolkit.prepareScrImage(img, w, h, o);
  207.     }
  208.     public int checkImage(Image img, int w, int h, ImageObserver o) {
  209.     return MToolkit.checkScrImage(img, w, h, o);
  210.     }
  211.     public FontMetrics getFontMetrics(Font font) {
  212.     return Win32FontMetrics.getFontMetrics(font);
  213.     }
  214.     public void dispose() {
  215.     pDispose();
  216.     }
  217.     public native void requestFocus();
  218.  
  219.     public native void nextFocus();
  220.  
  221.     protected void gotFocus(int data) {
  222.     target.postEvent(setData(data, 
  223.                                  new Event(target, Event.GOT_FOCUS, null)));
  224.     }
  225.  
  226.     protected void lostFocus(int data) {
  227.     target.postEvent(setData(data,
  228.                                  new Event(target, Event.LOST_FOCUS, null)));
  229.     }
  230.  
  231.     protected void handleActionKey(long when, int data,
  232.                    int x, int y, int key, int flags) {
  233.     target.postEvent(setData(data, new Event(target, when, Event.KEY_ACTION, x, y, key, flags, null)));
  234.     }
  235.  
  236.     protected void handleActionKeyRelease(long when, int data, int x, int y, int key, int flags) {
  237.     target.postEvent(setData(data, new Event(target, when, Event.KEY_ACTION_RELEASE, x, y, key, flags, null)));
  238.     }
  239.  
  240.     protected void handleKeyPress(long when, int data,
  241.                   int x, int y, int key, int flags) {
  242.     target.postEvent(setData(data, new Event(target, when, Event.KEY_PRESS, x, y, key, flags, null)));
  243.     }
  244.  
  245.     protected void handleKeyRelease(long when, int data,
  246.                     int x, int y, int key, int flags) {
  247.     target.postEvent(setData(data, new Event(target, when, Event.KEY_RELEASE, x, y, key, flags, null)));
  248.     }
  249.  
  250.     protected void handleMouseEnter(long when, int x, int y) {
  251.     target.postEvent(new Event(target, when, Event.MOUSE_ENTER, x, y, 0, 0, null));
  252.     }
  253.  
  254.     protected void handleMouseExit(long when, int x, int y) {
  255.     target.postEvent(new Event(target, when, Event.MOUSE_EXIT, x, y, 0, 0, null));
  256.     }
  257.  
  258.     protected void handleMouseDown(long when, int data, int x, int y, int
  259.                    clickCount, int flags) {
  260.     Event e = setData(data, new Event(target, when, Event.MOUSE_DOWN, x, y, 0, flags, null));
  261.  
  262.     e.clickCount = clickCount;
  263.     target.postEvent(e);
  264.     }
  265.  
  266.     protected void handleMouseUp(long when, int data, int x, int y, int flags) {
  267.     target.postEvent(setData(data, new Event(target, when, Event.MOUSE_UP, x, y, 0, flags, null)));
  268.     }
  269.  
  270.     protected void handleMouseMoved(long when, int data, int x, int y, int flags) {
  271.     target.postEvent(setData(data, new Event(target, when, Event.MOUSE_MOVE, x, y, 0, flags, null)));
  272.     }
  273.  
  274.     protected void handleMouseDrag(long when, int data, int x, int y, int flags) {
  275.     target.postEvent(setData(data, new Event(target, when, Event.MOUSE_DRAG, x, y, 0, flags, null)));
  276.     }
  277.  
  278.     native Event setData(int data, Event ev);
  279.  
  280.     /* Callbacks for window-system events to the frame */
  281.     void handleExpose(int x, int y, int w, int h) {
  282.     Graphics g = getGraphics();
  283.     try {
  284.         g.clipRect(x, y, w, h);
  285.         paint(g);
  286.     } finally {
  287.         g.dispose();
  288.     }
  289.     }
  290.     /* Callbacks for window-system events to the frame */
  291.     void handleRepaint(int x, int y, int w, int h) {
  292.     Graphics g = getGraphics();
  293.     try {
  294.         g.clipRect(x, y, w, h);
  295.         update(g);
  296.     } finally {
  297.         g.dispose();
  298.     }
  299.     }
  300.  
  301.     public String toString() {
  302.     return getClass().getName() + "[" + target + "]";
  303.     }
  304. }
  305.