1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "ctp_panel.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XPane.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/WindowClass.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
35cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/XGraphics.hpp>
38cdf0e10cSrcweir /** === end UNO includes === **/
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <tools/diagnose_ex.h>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //......................................................................................................................
43cdf0e10cSrcweir namespace sd { namespace colortoolpanel
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //......................................................................................................................
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	/** === begin UNO using === **/
48cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
54cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
55cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
56cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
57cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
58cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
59cdf0e10cSrcweir     using ::com::sun::star::drawing::framework::XConfigurationController;
60cdf0e10cSrcweir     using ::com::sun::star::drawing::framework::XResourceId;
61cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
62cdf0e10cSrcweir     using ::com::sun::star::drawing::framework::XPane;
63cdf0e10cSrcweir     using ::com::sun::star::awt::XWindow;
64cdf0e10cSrcweir     using ::com::sun::star::rendering::XCanvas;
65cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
66cdf0e10cSrcweir     using ::com::sun::star::awt::XWindowPeer;
67cdf0e10cSrcweir     using ::com::sun::star::lang::XMultiComponentFactory;
68cdf0e10cSrcweir     using ::com::sun::star::awt::XToolkit;
69cdf0e10cSrcweir     using ::com::sun::star::awt::WindowDescriptor;
70cdf0e10cSrcweir     using ::com::sun::star::awt::WindowClass_SIMPLE;
71cdf0e10cSrcweir     using ::com::sun::star::awt::Rectangle;
72cdf0e10cSrcweir     using ::com::sun::star::awt::PaintEvent;
73cdf0e10cSrcweir     using ::com::sun::star::lang::EventObject;
74cdf0e10cSrcweir     using ::com::sun::star::awt::XDevice;
75cdf0e10cSrcweir     using ::com::sun::star::awt::XGraphics;
76cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessible;
77cdf0e10cSrcweir 	/** === end UNO using === **/
78cdf0e10cSrcweir     namespace WindowAttribute = ::com::sun::star::awt::WindowAttribute;
79cdf0e10cSrcweir     namespace PosSize = ::com::sun::star::awt::PosSize;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	//==================================================================================================================
82cdf0e10cSrcweir 	//= helpers
83cdf0e10cSrcweir 	//==================================================================================================================
84cdf0e10cSrcweir     namespace
85cdf0e10cSrcweir     {
lcl_createPlainWindow_nothrow(const Reference<XComponentContext> & i_rContext,const Reference<XWindowPeer> & i_rParentWindow)86cdf0e10cSrcweir         Reference< XWindow > lcl_createPlainWindow_nothrow( const Reference< XComponentContext >& i_rContext,
87cdf0e10cSrcweir             const Reference< XWindowPeer >& i_rParentWindow )
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             try
90cdf0e10cSrcweir             {
91cdf0e10cSrcweir                 ENSURE_OR_THROW( i_rContext.is(), "illegal component context" );
92cdf0e10cSrcweir                 Reference< XMultiComponentFactory > xFactory( i_rContext->getServiceManager(), UNO_SET_THROW );
93cdf0e10cSrcweir                 Reference< XToolkit > xToolkit( xFactory->createInstanceWithContext(
94cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ),
95cdf0e10cSrcweir                     i_rContext
96cdf0e10cSrcweir                 ), UNO_QUERY_THROW );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir                 WindowDescriptor aWindow;
99cdf0e10cSrcweir                 aWindow.Type = WindowClass_SIMPLE;
100cdf0e10cSrcweir                 aWindow.WindowServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "window" ) );
101cdf0e10cSrcweir                 aWindow.Parent = i_rParentWindow;
102cdf0e10cSrcweir                 aWindow.WindowAttributes = WindowAttribute::BORDER;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir                 Reference< XWindowPeer > xWindow( xToolkit->createWindow( aWindow ), UNO_SET_THROW );
105cdf0e10cSrcweir                 return Reference< XWindow >( xWindow, UNO_QUERY_THROW );
106cdf0e10cSrcweir             }
107cdf0e10cSrcweir             catch( const Exception& )
108cdf0e10cSrcweir             {
109cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
110cdf0e10cSrcweir             }
111cdf0e10cSrcweir             return NULL;
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 	//==================================================================================================================
115cdf0e10cSrcweir 	//= class SingleColorPanel
116cdf0e10cSrcweir 	//==================================================================================================================
117cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
SingleColorPanel(const Reference<XComponentContext> & i_rContext,const Reference<XConfigurationController> & i_rConfigController,const Reference<XResourceId> & i_rResourceId)118cdf0e10cSrcweir     SingleColorPanel::SingleColorPanel( const Reference< XComponentContext >& i_rContext,
119cdf0e10cSrcweir             const Reference< XConfigurationController >& i_rConfigController, const Reference< XResourceId >& i_rResourceId )
120cdf0e10cSrcweir         :SingleColorPanel_Base( m_aMutex )
121cdf0e10cSrcweir         ,m_xContext( i_rContext )
122cdf0e10cSrcweir         ,m_xResourceId( i_rResourceId )
123cdf0e10cSrcweir         ,m_xWindow()
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         ENSURE_OR_THROW( i_rConfigController.is(), "invalid configuration controller" );
126cdf0e10cSrcweir         ENSURE_OR_THROW( m_xResourceId.is(), "invalid resource id" );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         // retrieve the parent window for our to-be-created pane window
129cdf0e10cSrcweir         Reference< XWindow > xParentWindow;
130cdf0e10cSrcweir         Reference< XWindowPeer > xParentPeer;
131cdf0e10cSrcweir         try
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             Reference< XResource > xAnchor( i_rConfigController->getResource( m_xResourceId->getAnchor() ), UNO_SET_THROW );
134cdf0e10cSrcweir             Reference< XPane > xAnchorPane( xAnchor, UNO_QUERY_THROW );
135cdf0e10cSrcweir             xParentWindow.set( xAnchorPane->getWindow(), UNO_SET_THROW );
136cdf0e10cSrcweir             xParentPeer.set( xParentWindow, UNO_QUERY_THROW );
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir         catch( const Exception& )
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
143cdf0e10cSrcweir         if ( xParentWindow.is() )
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir             m_xWindow = lcl_createPlainWindow_nothrow( m_xContext, xParentPeer );
146cdf0e10cSrcweir             m_xWindow->addPaintListener( this );
147cdf0e10cSrcweir             if ( m_xWindow.is() )
148cdf0e10cSrcweir             {
149cdf0e10cSrcweir                 const Rectangle aPanelAnchorSize( xParentWindow->getPosSize() );
150cdf0e10cSrcweir                 m_xWindow->setPosSize( 0, 0, aPanelAnchorSize.Width, aPanelAnchorSize.Height, PosSize::POSSIZE );
151cdf0e10cSrcweir                 m_xWindow->setVisible( sal_True );
152cdf0e10cSrcweir             }
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir         osl_decrementInterlockedCount( &m_refCount );
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~SingleColorPanel()158cdf0e10cSrcweir     SingleColorPanel::~SingleColorPanel()
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getWindow()163cdf0e10cSrcweir     Reference< XWindow > SAL_CALL SingleColorPanel::getWindow(  ) throw (RuntimeException)
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
166cdf0e10cSrcweir         if ( !m_xWindow.get() )
167cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *this );
168cdf0e10cSrcweir         return m_xWindow;
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
createAccessible(const Reference<XAccessible> & i_rParentAccessible)172cdf0e10cSrcweir     Reference< XAccessible > SAL_CALL SingleColorPanel::createAccessible( const Reference< XAccessible >& i_rParentAccessible ) throw (RuntimeException)
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         (void)i_rParentAccessible;
175cdf0e10cSrcweir         return Reference< XAccessible >( m_xWindow, UNO_QUERY );
176cdf0e10cSrcweir         // TODO: this is, strictly, not correct, as we ignore i_ParentAccessible here. If you are not doing a sample
177cdf0e10cSrcweir         // extension only, you'll want to do this correctly ....
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getResourceId()181cdf0e10cSrcweir     Reference< XResourceId > SAL_CALL SingleColorPanel::getResourceId(  ) throw (RuntimeException)
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
184cdf0e10cSrcweir         if ( !m_xWindow.is() )
185cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *this );
186cdf0e10cSrcweir         return m_xResourceId;
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
isAnchorOnly()190cdf0e10cSrcweir     ::sal_Bool SAL_CALL SingleColorPanel::isAnchorOnly(  ) throw (RuntimeException)
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
193cdf0e10cSrcweir         if ( !m_xWindow.is() )
194cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *this );
195cdf0e10cSrcweir         return sal_False;
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
windowPaint(const PaintEvent & i_rEvent)199cdf0e10cSrcweir     void SAL_CALL SingleColorPanel::windowPaint( const PaintEvent& i_rEvent ) throw (RuntimeException)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         try
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             const Reference< XDevice > xDevice( i_rEvent.Source, UNO_QUERY_THROW );
204cdf0e10cSrcweir             const Reference< XGraphics > xGraphics( xDevice->createGraphics(), UNO_SET_THROW );
205cdf0e10cSrcweir             xGraphics->setFillColor( 0x80 << 8 );
206cdf0e10cSrcweir             xGraphics->setLineColor( 0x80 << 16 );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir             const Reference< XWindow > xWindow( i_rEvent.Source, UNO_QUERY_THROW );
209cdf0e10cSrcweir             const Rectangle aWindowRect( xWindow->getPosSize() );
210cdf0e10cSrcweir             xGraphics->drawRect( 0, 0, aWindowRect.Width - 1, aWindowRect.Height - 1 );
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir         catch( const Exception& )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
disposing(const EventObject & i_rSource)219cdf0e10cSrcweir     void SAL_CALL SingleColorPanel::disposing( const EventObject& i_rSource ) throw (RuntimeException)
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         (void)i_rSource;
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
disposing()225cdf0e10cSrcweir     void SAL_CALL SingleColorPanel::disposing()
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
228cdf0e10cSrcweir         if ( !m_xWindow.is() )
229cdf0e10cSrcweir             // already disposed
230cdf0e10cSrcweir             return;
231cdf0e10cSrcweir         m_xWindow->removePaintListener( this );
232cdf0e10cSrcweir         try
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             Reference< XComponent > xWindowComp( m_xWindow, UNO_QUERY_THROW );
235cdf0e10cSrcweir             xWindowComp->dispose();
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir         catch( const Exception& )
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir         m_xWindow.clear();
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir //......................................................................................................................
245cdf0e10cSrcweir } } // namespace sd::colortoolpanel
246cdf0e10cSrcweir //......................................................................................................................
247