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