xref: /aoo42x/main/svtools/source/dialogs/colrdlg.cxx (revision 72368752)
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
105900e8ecSAndrew Rist  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist  *
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.
195900e8ecSAndrew Rist  *
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*72368752SAriel Constenla-Haile #include <com/sun/star/awt/XWindow.hpp>
30*72368752SAriel Constenla-Haile #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31*72368752SAriel Constenla-Haile #include <com/sun/star/beans/XPropertyAccess.hpp>
32*72368752SAriel Constenla-Haile #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33*72368752SAriel Constenla-Haile #include <comphelper/processfactory.hxx>
34*72368752SAriel Constenla-Haile #include <toolkit/helper/vclunohelper.hxx>
35*72368752SAriel Constenla-Haile #include <svtools/colrdlg.hxx>
36*72368752SAriel Constenla-Haile 
37*72368752SAriel Constenla-Haile using rtl::OUString;
38*72368752SAriel Constenla-Haile using namespace ::com::sun::star::uno;
39*72368752SAriel Constenla-Haile using namespace ::com::sun::star::lang;
40*72368752SAriel Constenla-Haile using namespace ::com::sun::star::beans;
41*72368752SAriel Constenla-Haile using namespace ::com::sun::star::ui::dialogs;
42*72368752SAriel Constenla-Haile 
43*72368752SAriel Constenla-Haile // ---------------
44*72368752SAriel Constenla-Haile // - ColorDialog -
45*72368752SAriel Constenla-Haile // ---------------
46*72368752SAriel Constenla-Haile 
SvColorDialog(Window * pWindow)47*72368752SAriel Constenla-Haile SvColorDialog::SvColorDialog( Window* pWindow )
48*72368752SAriel Constenla-Haile : mpParent( pWindow )
49*72368752SAriel Constenla-Haile , 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 // -----------------------------------------------------------------------
61b2b569f2SArmin Le Grand 
GetColor() const62cdf0e10cSrcweir const Color& SvColorDialog::GetColor() const
63cdf0e10cSrcweir {
64b2b569f2SArmin Le Grand 	return maColor;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------------
68*72368752SAriel Constenla-Haile 
SetMode(sal_Int16 eMode)69*72368752SAriel Constenla-Haile void SvColorDialog::SetMode( sal_Int16 eMode )
70*72368752SAriel Constenla-Haile {
71*72368752SAriel Constenla-Haile     meMode = eMode;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // -----------------------------------------------------------------------
75*72368752SAriel Constenla-Haile 
Execute()76*72368752SAriel Constenla-Haile short SvColorDialog::Execute()
77*72368752SAriel Constenla-Haile {
78*72368752SAriel Constenla-Haile     short ret = 0;
79*72368752SAriel Constenla-Haile     try
80cdf0e10cSrcweir 	{
81*72368752SAriel Constenla-Haile         const OUString sColor( RTL_CONSTASCII_USTRINGPARAM( "Color" ) );
82*72368752SAriel Constenla-Haile         Reference< XMultiServiceFactory > xSMGR( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
83*72368752SAriel Constenla-Haile 
84*72368752SAriel Constenla-Haile         Reference< com::sun::star::awt::XWindow > xParent( VCLUnoHelper::GetInterface( mpParent ) );
85*72368752SAriel Constenla-Haile 
86*72368752SAriel Constenla-Haile         Sequence< Any > args(1);
87*72368752SAriel Constenla-Haile         args[0] = Any( xParent );
88*72368752SAriel Constenla-Haile 
89*72368752SAriel Constenla-Haile         Reference< XExecutableDialog > xDialog( xSMGR->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.cui.ColorPicker"), args), UNO_QUERY_THROW );
90*72368752SAriel Constenla-Haile         Reference< XPropertyAccess > xPropertyAccess( xDialog, UNO_QUERY_THROW );
91*72368752SAriel Constenla-Haile 
92*72368752SAriel Constenla-Haile         Sequence< PropertyValue > props( 2 );
93*72368752SAriel Constenla-Haile         props[0].Name = sColor;
94*72368752SAriel Constenla-Haile         props[0].Value <<= (sal_Int32) maColor.GetColor();
95*72368752SAriel Constenla-Haile         props[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Mode" ) );
96*72368752SAriel Constenla-Haile         props[1].Value <<= (sal_Int16) meMode;
97*72368752SAriel Constenla-Haile 
98*72368752SAriel Constenla-Haile         xPropertyAccess->setPropertyValues( props );
99*72368752SAriel Constenla-Haile 
100*72368752SAriel Constenla-Haile         ret = xDialog->execute();
101*72368752SAriel Constenla-Haile 
102*72368752SAriel Constenla-Haile         if( ret )
103*72368752SAriel Constenla-Haile         {
104*72368752SAriel Constenla-Haile             props = xPropertyAccess->getPropertyValues();
105*72368752SAriel Constenla-Haile             for( sal_Int32 n = 0; n < props.getLength(); n++ )
106*72368752SAriel Constenla-Haile             {
107*72368752SAriel Constenla-Haile                 if( props[n].Name.equals( sColor ) )
108*72368752SAriel Constenla-Haile                 {
109*72368752SAriel Constenla-Haile                     sal_Int32 nColor = 0;
110*72368752SAriel Constenla-Haile                     if( props[n].Value >>= nColor )
111*72368752SAriel Constenla-Haile                     {
112*72368752SAriel Constenla-Haile                         maColor.SetColor( nColor );
113*72368752SAriel Constenla-Haile                     }
114*72368752SAriel Constenla-Haile 
115*72368752SAriel Constenla-Haile                 }
116*72368752SAriel Constenla-Haile             }
117*72368752SAriel Constenla-Haile         }
118cdf0e10cSrcweir 	}
119*72368752SAriel Constenla-Haile     catch(Exception&)
120cdf0e10cSrcweir 	{
121*72368752SAriel Constenla-Haile         OSL_ASSERT(false);
122cdf0e10cSrcweir 	}
123*72368752SAriel Constenla-Haile 
124*72368752SAriel Constenla-Haile     return ret;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir // -----------------------------------------------------------------------
128b2b569f2SArmin Le Grand // eof
129