Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / embeddedobj / test / Container1 / PaintThread.java
blobf7eb63ef27353aa86d973de969fe3f25c1392051
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package embeddedobj.test;
21 import java.awt.*;
22 import java.applet.*;
23 import java.awt.event.*;
24 import java.net.*;
25 import java.io.*;
26 import java.lang.Thread;
28 import com.sun.star.awt.XBitmap;
29 import com.sun.star.awt.XDevice;
30 import com.sun.star.awt.XDisplayBitmap;
31 import com.sun.star.awt.XGraphics;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.awt.XWindowPeer;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XSystemChildFactory;
36 import com.sun.star.awt.WindowDescriptor;
37 import com.sun.star.awt.WindowClass;
38 import com.sun.star.awt.WindowAttribute;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.lang.XMultiServiceFactory;
43 class PaintThread extends java.lang.Thread
45 private XWindow m_xWindow;
46 private XBitmap m_xBitmap;
47 private com.sun.star.awt.Rectangle m_aRect;
49 private Object m_oRequestsLock;
50 private boolean m_bToPaint = false;
52 private boolean m_bDisposed = false;
54 public static boolean interceptedRects( com.sun.star.awt.Rectangle aRect1, com.sun.star.awt.Rectangle aRect2 )
56 return ( ( aRect1.X <= aRect2.X && aRect2.X <= aRect1.X + aRect1.Width
57 || aRect1.X <= aRect2.X + aRect2.Width && aRect2.X + aRect2.Width <= aRect1.X + aRect1.Width
58 || aRect2.X <= aRect1.X && aRect1.X <= aRect2.X + aRect2.Width
59 || aRect2.X <= aRect1.X + aRect1.Width && aRect1.X + aRect1.Width <= aRect2.X + aRect2.Width )
60 && ( aRect1.Y <= aRect2.Y && aRect2.Y <= aRect1.Y + aRect1.Height
61 || aRect1.Y <= aRect2.Y + aRect2.Height && aRect2.Y + aRect2.Height <= aRect1.Y + aRect1.Height
62 || aRect2.Y <= aRect1.Y && aRect1.Y <= aRect2.Y + aRect2.Height
63 || aRect2.Y <= aRect1.Y + aRect1.Height && aRect1.Y + aRect1.Height <= aRect2.Y + aRect2.Height ) );
66 public PaintThread( XWindow xWindow )
68 m_oRequestsLock = new Object();
69 m_xWindow = xWindow;
72 public void setPaintRequest( XBitmap xBitmap, com.sun.star.awt.Rectangle aRect, com.sun.star.awt.Rectangle aClip )
74 synchronized( m_oRequestsLock )
76 if ( PaintThread.interceptedRects( aRect, aClip ) )
78 m_xBitmap = xBitmap;
79 m_aRect = aRect;
80 m_bToPaint = true;
85 public void disposeThread()
87 m_bDisposed = true;
90 public void run()
92 while( !m_bDisposed )
94 try {
95 Thread.sleep( 200 );
96 } catch( Exception e ) {}
98 XBitmap xBitmap = null;
99 com.sun.star.awt.Rectangle aRect = null;
100 boolean bPaint = false;
102 synchronized( m_oRequestsLock )
104 if ( m_bToPaint )
106 xBitmap = m_xBitmap;
107 aRect = m_aRect;
108 m_bToPaint = false;
109 bPaint = true;
113 if ( bPaint )
115 XDevice xDevice = (XDevice)UnoRuntime.queryInterface( XDevice.class, m_xWindow );
116 if ( xDevice != null )
118 XGraphics xGraphics = xDevice.createGraphics();
119 if ( xBitmap != null )
121 XDisplayBitmap xDisplayBitmap = xDevice.createDisplayBitmap( xBitmap );
123 com.sun.star.awt.Size aSize = xBitmap.getSize();
124 xGraphics.draw( xDisplayBitmap, 0, 0, aSize.Width, aSize.Height,
125 aRect.X, aRect.Y, aRect.Width, aRect.Height );
128 xGraphics.drawLine( aRect.X - 1, aRect.Y - 1,
129 aRect.X + aRect.Width + 1, aRect.Y - 1 );
130 xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y - 1,
131 aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1 );
132 xGraphics.drawLine( aRect.X + aRect.Width + 1, aRect.Y + aRect.Height + 1,
133 aRect.X - 1, aRect.Y + aRect.Height + 1 );
134 xGraphics.drawLine( aRect.X - 1, aRect.Y + aRect.Height + 1,
135 aRect.X - 1, aRect.Y - 1 );