1*cdf0e10cSrcweir package embeddedobj.test; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import java.awt.*; 4*cdf0e10cSrcweir import java.applet.*; 5*cdf0e10cSrcweir import java.awt.event.*; 6*cdf0e10cSrcweir import java.net.*; 7*cdf0e10cSrcweir import java.io.*; 8*cdf0e10cSrcweir import java.lang.Thread; 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir import com.sun.star.awt.XBitmap; 11*cdf0e10cSrcweir import com.sun.star.awt.XDevice; 12*cdf0e10cSrcweir import com.sun.star.awt.XDisplayBitmap; 13*cdf0e10cSrcweir import com.sun.star.awt.XGraphics; 14*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 15*cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 16*cdf0e10cSrcweir import com.sun.star.awt.XToolkit; 17*cdf0e10cSrcweir import com.sun.star.awt.XSystemChildFactory; 18*cdf0e10cSrcweir import com.sun.star.awt.WindowDescriptor; 19*cdf0e10cSrcweir import com.sun.star.awt.WindowClass; 20*cdf0e10cSrcweir import com.sun.star.awt.WindowAttribute; 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 23*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 24*cdf0e10cSrcweir 25*cdf0e10cSrcweir class PaintThread extends java.lang.Thread 26*cdf0e10cSrcweir { 27*cdf0e10cSrcweir private XWindow m_xWindow; 28*cdf0e10cSrcweir private XBitmap m_xBitmap; 29*cdf0e10cSrcweir private com.sun.star.awt.Rectangle m_aRect; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir private Object m_oRequestsLock; 32*cdf0e10cSrcweir private boolean m_bToPaint = false; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir private boolean m_bDisposed = false; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir public static boolean interceptedRects( com.sun.star.awt.Rectangle aRect1, com.sun.star.awt.Rectangle aRect2 ) 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir return ( ( aRect1.X <= aRect2.X && aRect2.X <= aRect1.X + aRect1.Width 39*cdf0e10cSrcweir || aRect1.X <= aRect2.X + aRect2.Width && aRect2.X + aRect2.Width <= aRect1.X + aRect1.Width 40*cdf0e10cSrcweir || aRect2.X <= aRect1.X && aRect1.X <= aRect2.X + aRect2.Width 41*cdf0e10cSrcweir || aRect2.X <= aRect1.X + aRect1.Width && aRect1.X + aRect1.Width <= aRect2.X + aRect2.Width ) 42*cdf0e10cSrcweir && ( aRect1.Y <= aRect2.Y && aRect2.Y <= aRect1.Y + aRect1.Height 43*cdf0e10cSrcweir || aRect1.Y <= aRect2.Y + aRect2.Height && aRect2.Y + aRect2.Height <= aRect1.Y + aRect1.Height 44*cdf0e10cSrcweir || aRect2.Y <= aRect1.Y && aRect1.Y <= aRect2.Y + aRect2.Height 45*cdf0e10cSrcweir || aRect2.Y <= aRect1.Y + aRect1.Height && aRect1.Y + aRect1.Height <= aRect2.Y + aRect2.Height ) ); 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir public PaintThread( XWindow xWindow ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir m_oRequestsLock = new Object(); 51*cdf0e10cSrcweir m_xWindow = xWindow; 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir public void setPaintRequest( XBitmap xBitmap, com.sun.star.awt.Rectangle aRect, com.sun.star.awt.Rectangle aClip ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir synchronized( m_oRequestsLock ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir /* 59*cdf0e10cSrcweir System.out.println( "Paint request Pos( " 60*cdf0e10cSrcweir + aRect.X + ", " 61*cdf0e10cSrcweir + aRect.Y + ", " 62*cdf0e10cSrcweir + aRect.Width + ", " 63*cdf0e10cSrcweir + aRect.Height + " ), Clip ( " 64*cdf0e10cSrcweir + aClip.X + ", " 65*cdf0e10cSrcweir + aClip.Y + ", " 66*cdf0e10cSrcweir + aClip.Width + ", " 67*cdf0e10cSrcweir + aClip.Height + " )" ); 68*cdf0e10cSrcweir */ 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir if ( PaintThread.interceptedRects( aRect, aClip ) ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir m_xBitmap = xBitmap; 73*cdf0e10cSrcweir m_aRect = aRect; 74*cdf0e10cSrcweir m_bToPaint = true; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // System.out.println( "Paint request to paint thread is done! xBitmap = " + xBitmap ); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir public void disposeThread() 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir m_bDisposed = true; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir public void run() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir while( !m_bDisposed ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir try { 91*cdf0e10cSrcweir Thread.sleep( 200 ); 92*cdf0e10cSrcweir } catch( Exception e ) {} 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir XBitmap xBitmap = null; 95*cdf0e10cSrcweir com.sun.star.awt.Rectangle aRect = null; 96*cdf0e10cSrcweir boolean bPaint = false; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir synchronized( m_oRequestsLock ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir if ( m_bToPaint ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir xBitmap = m_xBitmap; 103*cdf0e10cSrcweir aRect = m_aRect; 104*cdf0e10cSrcweir m_bToPaint = false; 105*cdf0e10cSrcweir bPaint = true; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if ( bPaint ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir // System.out.println( "The bitmap is going to be painted!" ); 112*cdf0e10cSrcweir XDevice xDevice = (XDevice)UnoRuntime.queryInterface( XDevice.class, m_xWindow ); 113*cdf0e10cSrcweir if ( xDevice != null ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir // System.out.println( "Step1" ); 116*cdf0e10cSrcweir XGraphics xGraphics = xDevice.createGraphics(); 117*cdf0e10cSrcweir if ( xBitmap != null ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir // System.out.println( "Step2" ); 120*cdf0e10cSrcweir XDisplayBitmap xDisplayBitmap = xDevice.createDisplayBitmap( xBitmap ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir com.sun.star.awt.Size aSize = xBitmap.getSize(); 123*cdf0e10cSrcweir xGraphics.draw( xDisplayBitmap, 0, 0, aSize.Width, aSize.Height, 124*cdf0e10cSrcweir aRect.X, aRect.Y, aRect.Width, aRect.Height ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // System.out.println( "Step3" ); 128*cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 1, aRect.Y - 1, aRect.Width + 2, aRect.Height + 2 ); 129*cdf0e10cSrcweir xGraphics.drawLine( aRect.X - 1, aRect.Y - 1, 130*cdf0e10cSrcweir aRect.X + aRect.Width + 1, aRect.Y - 1 ); 131*cdf0e10cSrcweir xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y - 1, 132*cdf0e10cSrcweir aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1 ); 133*cdf0e10cSrcweir xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1, 134*cdf0e10cSrcweir aRect.X - 1, aRect.Y + aRect.Height + 1 ); 135*cdf0e10cSrcweir xGraphics.drawLine( aRect.X - 1, aRect.Y + aRect.Height + 1, 136*cdf0e10cSrcweir aRect.X - 1, aRect.Y - 1 ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // draw resize squares 139*cdf0e10cSrcweir // System.out.println( "Step4" ); 140*cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 2, aRect.Y - 2, 4, 4 ); 141*cdf0e10cSrcweir // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y - 2, 4, 4 ); 142*cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 2, aRect.Y + aRect.Height - 2, 4, 4 ); 143*cdf0e10cSrcweir // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y + aRect.Height - 2, 4, 4 ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // System.out.println( "Step5" ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // System.out.println( "The bitmap is painted by paint thread!" ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir }; 153*cdf0e10cSrcweir 154