xref: /AOO41X/main/svtools/source/dialogs/colrdlg.cxx (revision b2b569f2af4b60c04ac642f99523a1bfe3986a72)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #ifndef GCC
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir 
29*b2b569f2SArmin Le Grand #include <com/sun/star/awt/XWindow.hpp>
30*b2b569f2SArmin Le Grand #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31*b2b569f2SArmin Le Grand #include <com/sun/star/beans/XPropertyAccess.hpp>
32*b2b569f2SArmin Le Grand #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33*b2b569f2SArmin Le Grand #include <comphelper/processfactory.hxx>
34*b2b569f2SArmin Le Grand #include <toolkit/helper/vclunohelper.hxx>
35cdf0e10cSrcweir #include <svtools/colrdlg.hxx>
36cdf0e10cSrcweir 
37*b2b569f2SArmin Le Grand using rtl::OUString;
38*b2b569f2SArmin Le Grand using namespace ::com::sun::star::uno;
39*b2b569f2SArmin Le Grand using namespace ::com::sun::star::lang;
40*b2b569f2SArmin Le Grand using namespace ::com::sun::star::beans;
41*b2b569f2SArmin Le Grand using namespace ::com::sun::star::ui::dialogs;
42*b2b569f2SArmin Le Grand 
43cdf0e10cSrcweir // ---------------
44cdf0e10cSrcweir // - ColorDialog -
45cdf0e10cSrcweir // ---------------
46cdf0e10cSrcweir 
SvColorDialog(Window * pWindow)47*b2b569f2SArmin Le Grand SvColorDialog::SvColorDialog( Window* pWindow )
48*b2b569f2SArmin Le Grand : mpParent( pWindow )
49*b2b569f2SArmin Le Grand , meMode( svtools::ColorPickerMode_SELECT )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // -----------------------------------------------------------------------
54cdf0e10cSrcweir 
SetColor(const Color & rColor)55cdf0e10cSrcweir void SvColorDialog::SetColor( const Color& rColor )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	maColor = rColor;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // -----------------------------------------------------------------------
61*b2b569f2SArmin Le Grand 
GetColor() const62cdf0e10cSrcweir const Color& SvColorDialog::GetColor() const
63cdf0e10cSrcweir {
64*b2b569f2SArmin Le Grand 	return maColor;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------------
68cdf0e10cSrcweir 
SetMode(sal_Int16 eMode)69*b2b569f2SArmin Le Grand void SvColorDialog::SetMode( sal_Int16 eMode )
70cdf0e10cSrcweir {
71*b2b569f2SArmin Le Grand     meMode = eMode;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // -----------------------------------------------------------------------
75cdf0e10cSrcweir 
Execute()76cdf0e10cSrcweir short SvColorDialog::Execute()
77cdf0e10cSrcweir {
78*b2b569f2SArmin Le Grand     short ret = 0;
79*b2b569f2SArmin Le Grand     try
80*b2b569f2SArmin Le Grand 	{
81*b2b569f2SArmin Le Grand         const OUString sColor( RTL_CONSTASCII_USTRINGPARAM( "Color" ) );
82*b2b569f2SArmin Le Grand         Reference< XMultiServiceFactory > xSMGR( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
83cdf0e10cSrcweir 
84*b2b569f2SArmin Le Grand         Reference< com::sun::star::awt::XWindow > xParent( VCLUnoHelper::GetInterface( mpParent ) );
85cdf0e10cSrcweir 
86*b2b569f2SArmin Le Grand         Sequence< Any > args(1);
87*b2b569f2SArmin Le Grand         args[0] = Any( xParent );
88*b2b569f2SArmin Le Grand 
89*b2b569f2SArmin Le Grand         Reference< XExecutableDialog > xDialog( xSMGR->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.cui.ColorPicker"), args), UNO_QUERY_THROW );
90*b2b569f2SArmin Le Grand         Reference< XPropertyAccess > xPropertyAccess( xDialog, UNO_QUERY_THROW );
91*b2b569f2SArmin Le Grand 
92*b2b569f2SArmin Le Grand         Sequence< PropertyValue > props( 2 );
93*b2b569f2SArmin Le Grand         props[0].Name = sColor;
94*b2b569f2SArmin Le Grand         props[0].Value <<= (sal_Int32) maColor.GetColor();
95*b2b569f2SArmin Le Grand         props[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Mode" ) );
96*b2b569f2SArmin Le Grand         props[1].Value <<= (sal_Int16) meMode;
97*b2b569f2SArmin Le Grand 
98*b2b569f2SArmin Le Grand         xPropertyAccess->setPropertyValues( props );
99*b2b569f2SArmin Le Grand 
100*b2b569f2SArmin Le Grand         ret = xDialog->execute();
101*b2b569f2SArmin Le Grand 
102*b2b569f2SArmin Le Grand         if( ret )
103*b2b569f2SArmin Le Grand         {
104*b2b569f2SArmin Le Grand             props = xPropertyAccess->getPropertyValues();
105*b2b569f2SArmin Le Grand             for( sal_Int32 n = 0; n < props.getLength(); n++ )
106*b2b569f2SArmin Le Grand             {
107*b2b569f2SArmin Le Grand                 if( props[n].Name.equals( sColor ) )
108*b2b569f2SArmin Le Grand                 {
109*b2b569f2SArmin Le Grand                     sal_Int32 nColor = 0;
110*b2b569f2SArmin Le Grand                     if( props[n].Value >>= nColor )
111*b2b569f2SArmin Le Grand                     {
112*b2b569f2SArmin Le Grand                         maColor.SetColor( nColor );
113cdf0e10cSrcweir                     }
114cdf0e10cSrcweir 
115*b2b569f2SArmin Le Grand                 }
116*b2b569f2SArmin Le Grand             }
117*b2b569f2SArmin Le Grand         }
118*b2b569f2SArmin Le Grand 	}
119*b2b569f2SArmin Le Grand     catch(Exception&)
120*b2b569f2SArmin Le Grand 	{
121*b2b569f2SArmin Le Grand         OSL_ASSERT(false);
122*b2b569f2SArmin Le Grand 	}
123*b2b569f2SArmin Le Grand 
124*b2b569f2SArmin Le Grand     return ret;
125*b2b569f2SArmin Le Grand }
126*b2b569f2SArmin Le Grand 
127*b2b569f2SArmin Le Grand // -----------------------------------------------------------------------
128*b2b569f2SArmin Le Grand // eof
129