1*113d1ee9SAndrew Rist /************************************************************** 2*113d1ee9SAndrew Rist * 3*113d1ee9SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*113d1ee9SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*113d1ee9SAndrew Rist * distributed with this work for additional information 6*113d1ee9SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*113d1ee9SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*113d1ee9SAndrew Rist * "License"); you may not use this file except in compliance 9*113d1ee9SAndrew Rist * with the License. You may obtain a copy of the License at 10*113d1ee9SAndrew Rist * 11*113d1ee9SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*113d1ee9SAndrew Rist * 13*113d1ee9SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*113d1ee9SAndrew Rist * software distributed under the License is distributed on an 15*113d1ee9SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*113d1ee9SAndrew Rist * KIND, either express or implied. See the License for the 17*113d1ee9SAndrew Rist * specific language governing permissions and limitations 18*113d1ee9SAndrew Rist * under the License. 19*113d1ee9SAndrew Rist * 20*113d1ee9SAndrew Rist *************************************************************/ 21*113d1ee9SAndrew Rist 22cdf0e10cSrcweir package embeddedobj.test; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import java.awt.*; 25cdf0e10cSrcweir import java.applet.*; 26cdf0e10cSrcweir import java.awt.event.*; 27cdf0e10cSrcweir import java.net.*; 28cdf0e10cSrcweir import java.io.*; 29cdf0e10cSrcweir import java.lang.Thread; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import com.sun.star.awt.XBitmap; 32cdf0e10cSrcweir import com.sun.star.awt.XDevice; 33cdf0e10cSrcweir import com.sun.star.awt.XDisplayBitmap; 34cdf0e10cSrcweir import com.sun.star.awt.XGraphics; 35cdf0e10cSrcweir import com.sun.star.awt.XWindow; 36cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 37cdf0e10cSrcweir import com.sun.star.awt.XToolkit; 38cdf0e10cSrcweir import com.sun.star.awt.XSystemChildFactory; 39cdf0e10cSrcweir import com.sun.star.awt.WindowDescriptor; 40cdf0e10cSrcweir import com.sun.star.awt.WindowClass; 41cdf0e10cSrcweir import com.sun.star.awt.WindowAttribute; 42cdf0e10cSrcweir 43cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 44cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 45cdf0e10cSrcweir 46cdf0e10cSrcweir class PaintThread extends java.lang.Thread 47cdf0e10cSrcweir { 48cdf0e10cSrcweir private XWindow m_xWindow; 49cdf0e10cSrcweir private XBitmap m_xBitmap; 50cdf0e10cSrcweir private com.sun.star.awt.Rectangle m_aRect; 51cdf0e10cSrcweir 52cdf0e10cSrcweir private Object m_oRequestsLock; 53cdf0e10cSrcweir private boolean m_bToPaint = false; 54cdf0e10cSrcweir 55cdf0e10cSrcweir private boolean m_bDisposed = false; 56cdf0e10cSrcweir interceptedRects( com.sun.star.awt.Rectangle aRect1, com.sun.star.awt.Rectangle aRect2 )57cdf0e10cSrcweir public static boolean interceptedRects( com.sun.star.awt.Rectangle aRect1, com.sun.star.awt.Rectangle aRect2 ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir return ( ( aRect1.X <= aRect2.X && aRect2.X <= aRect1.X + aRect1.Width 60cdf0e10cSrcweir || aRect1.X <= aRect2.X + aRect2.Width && aRect2.X + aRect2.Width <= aRect1.X + aRect1.Width 61cdf0e10cSrcweir || aRect2.X <= aRect1.X && aRect1.X <= aRect2.X + aRect2.Width 62cdf0e10cSrcweir || aRect2.X <= aRect1.X + aRect1.Width && aRect1.X + aRect1.Width <= aRect2.X + aRect2.Width ) 63cdf0e10cSrcweir && ( aRect1.Y <= aRect2.Y && aRect2.Y <= aRect1.Y + aRect1.Height 64cdf0e10cSrcweir || aRect1.Y <= aRect2.Y + aRect2.Height && aRect2.Y + aRect2.Height <= aRect1.Y + aRect1.Height 65cdf0e10cSrcweir || aRect2.Y <= aRect1.Y && aRect1.Y <= aRect2.Y + aRect2.Height 66cdf0e10cSrcweir || aRect2.Y <= aRect1.Y + aRect1.Height && aRect1.Y + aRect1.Height <= aRect2.Y + aRect2.Height ) ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir PaintThread( XWindow xWindow )69cdf0e10cSrcweir public PaintThread( XWindow xWindow ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir m_oRequestsLock = new Object(); 72cdf0e10cSrcweir m_xWindow = xWindow; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir setPaintRequest( XBitmap xBitmap, com.sun.star.awt.Rectangle aRect, com.sun.star.awt.Rectangle aClip )75cdf0e10cSrcweir public void setPaintRequest( XBitmap xBitmap, com.sun.star.awt.Rectangle aRect, com.sun.star.awt.Rectangle aClip ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir synchronized( m_oRequestsLock ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir /* 80cdf0e10cSrcweir System.out.println( "Paint request Pos( " 81cdf0e10cSrcweir + aRect.X + ", " 82cdf0e10cSrcweir + aRect.Y + ", " 83cdf0e10cSrcweir + aRect.Width + ", " 84cdf0e10cSrcweir + aRect.Height + " ), Clip ( " 85cdf0e10cSrcweir + aClip.X + ", " 86cdf0e10cSrcweir + aClip.Y + ", " 87cdf0e10cSrcweir + aClip.Width + ", " 88cdf0e10cSrcweir + aClip.Height + " )" ); 89cdf0e10cSrcweir */ 90cdf0e10cSrcweir 91cdf0e10cSrcweir if ( PaintThread.interceptedRects( aRect, aClip ) ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir m_xBitmap = xBitmap; 94cdf0e10cSrcweir m_aRect = aRect; 95cdf0e10cSrcweir m_bToPaint = true; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir // System.out.println( "Paint request to paint thread is done! xBitmap = " + xBitmap ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir disposeThread()102cdf0e10cSrcweir public void disposeThread() 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_bDisposed = true; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir run()107cdf0e10cSrcweir public void run() 108cdf0e10cSrcweir { 109cdf0e10cSrcweir while( !m_bDisposed ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir try { 112cdf0e10cSrcweir Thread.sleep( 200 ); 113cdf0e10cSrcweir } catch( Exception e ) {} 114cdf0e10cSrcweir 115cdf0e10cSrcweir XBitmap xBitmap = null; 116cdf0e10cSrcweir com.sun.star.awt.Rectangle aRect = null; 117cdf0e10cSrcweir boolean bPaint = false; 118cdf0e10cSrcweir 119cdf0e10cSrcweir synchronized( m_oRequestsLock ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir if ( m_bToPaint ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir xBitmap = m_xBitmap; 124cdf0e10cSrcweir aRect = m_aRect; 125cdf0e10cSrcweir m_bToPaint = false; 126cdf0e10cSrcweir bPaint = true; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir if ( bPaint ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // System.out.println( "The bitmap is going to be painted!" ); 133cdf0e10cSrcweir XDevice xDevice = (XDevice)UnoRuntime.queryInterface( XDevice.class, m_xWindow ); 134cdf0e10cSrcweir if ( xDevice != null ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir // System.out.println( "Step1" ); 137cdf0e10cSrcweir XGraphics xGraphics = xDevice.createGraphics(); 138cdf0e10cSrcweir if ( xBitmap != null ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir // System.out.println( "Step2" ); 141cdf0e10cSrcweir XDisplayBitmap xDisplayBitmap = xDevice.createDisplayBitmap( xBitmap ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir com.sun.star.awt.Size aSize = xBitmap.getSize(); 144cdf0e10cSrcweir xGraphics.draw( xDisplayBitmap, 0, 0, aSize.Width, aSize.Height, 145cdf0e10cSrcweir aRect.X, aRect.Y, aRect.Width, aRect.Height ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir // System.out.println( "Step3" ); 149cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 1, aRect.Y - 1, aRect.Width + 2, aRect.Height + 2 ); 150cdf0e10cSrcweir xGraphics.drawLine( aRect.X - 1, aRect.Y - 1, 151cdf0e10cSrcweir aRect.X + aRect.Width + 1, aRect.Y - 1 ); 152cdf0e10cSrcweir xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y - 1, 153cdf0e10cSrcweir aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1 ); 154cdf0e10cSrcweir xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1, 155cdf0e10cSrcweir aRect.X - 1, aRect.Y + aRect.Height + 1 ); 156cdf0e10cSrcweir xGraphics.drawLine( aRect.X - 1, aRect.Y + aRect.Height + 1, 157cdf0e10cSrcweir aRect.X - 1, aRect.Y - 1 ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir // draw resize squares 160cdf0e10cSrcweir // System.out.println( "Step4" ); 161cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 2, aRect.Y - 2, 4, 4 ); 162cdf0e10cSrcweir // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y - 2, 4, 4 ); 163cdf0e10cSrcweir // xGraphics.drawRect( aRect.X - 2, aRect.Y + aRect.Height - 2, 4, 4 ); 164cdf0e10cSrcweir // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y + aRect.Height - 2, 4, 4 ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir // System.out.println( "Step5" ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir // System.out.println( "The bitmap is painted by paint thread!" ); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir }; 174cdf0e10cSrcweir 175