1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dx_surfacegraphics.hxx"
28cdf0e10cSrcweir #include "dx_impltools.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace dxcanvas
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     namespace
35cdf0e10cSrcweir     {
36cdf0e10cSrcweir         struct GraphicsDeleter
37cdf0e10cSrcweir         {
38cdf0e10cSrcweir             COMReference<surface_type> mpSurface;
39cdf0e10cSrcweir             HDC                        maHDC;
40cdf0e10cSrcweir 
GraphicsDeleterdxcanvas::__anonc73e6d910111::GraphicsDeleter41cdf0e10cSrcweir             GraphicsDeleter(const COMReference<surface_type>& rSurface, HDC hdc) :
42cdf0e10cSrcweir                 mpSurface(rSurface),
43cdf0e10cSrcweir                 maHDC(hdc)
44cdf0e10cSrcweir             {}
45cdf0e10cSrcweir 
operator ()dxcanvas::__anonc73e6d910111::GraphicsDeleter46cdf0e10cSrcweir             void operator()( Gdiplus::Graphics* pGraphics )
47cdf0e10cSrcweir             {
48cdf0e10cSrcweir                 if(!pGraphics)
49cdf0e10cSrcweir                     return;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir                 pGraphics->Flush(Gdiplus::FlushIntentionSync);
52cdf0e10cSrcweir                 delete pGraphics;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir                 if(mpSurface.is())
55cdf0e10cSrcweir                     mpSurface->ReleaseDC( maHDC );
56cdf0e10cSrcweir             }
57cdf0e10cSrcweir         };
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir 
createSurfaceGraphics(const COMReference<surface_type> & rSurface)60cdf0e10cSrcweir     GraphicsSharedPtr createSurfaceGraphics(const COMReference<surface_type>& rSurface )
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         Gdiplus::Graphics* pGraphics;
63cdf0e10cSrcweir         GraphicsSharedPtr  pRet;
64cdf0e10cSrcweir         HDC aHDC;
65cdf0e10cSrcweir 		if( SUCCEEDED(rSurface->GetDC( &aHDC )) )
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir 			pGraphics = Gdiplus::Graphics::FromHDC( aHDC );
68cdf0e10cSrcweir 			if(pGraphics)
69cdf0e10cSrcweir 			{
70cdf0e10cSrcweir 	            tools::setupGraphics( *pGraphics );
71cdf0e10cSrcweir 				pRet.reset(pGraphics,
72cdf0e10cSrcweir                            GraphicsDeleter(rSurface, aHDC));
73cdf0e10cSrcweir                 return pRet;
74cdf0e10cSrcweir 			}
75cdf0e10cSrcweir             else
76cdf0e10cSrcweir                 rSurface->ReleaseDC( aHDC );
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         throw uno::RuntimeException();
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir }
82