1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/awt/XWindow.hpp>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/beans/XPropertyAccess.hpp>
24 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
25 #include <com/sun/star/cui/ColorPicker.hpp>
27 #include <comphelper/processfactory.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
31 #include <svtools/colrdlg.hxx>
32 #include <vcl/window.hxx>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::ui::dialogs
;
43 SvColorDialog::SvColorDialog( vcl::Window
* pWindow
)
45 , meMode( svtools::ColorPickerMode_SELECT
)
49 SvColorDialog::~SvColorDialog()
53 void SvColorDialog::SetColor( const Color
& rColor
)
63 void SvColorDialog::SetMode( sal_Int16 eMode
)
70 short SvColorDialog::Execute()
75 const OUString
sColor( "Color" );
76 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
78 Reference
< com::sun::star::awt::XWindow
> xParent( VCLUnoHelper::GetInterface( mpParent
) );
80 Reference
< XExecutableDialog
> xDialog
= com::sun::star::cui::ColorPicker::createWithParent(xContext
, xParent
);
81 Reference
< XPropertyAccess
> xPropertyAccess( xDialog
, UNO_QUERY_THROW
);
83 Sequence
< PropertyValue
> props( 2 );
84 props
[0].Name
= sColor
;
85 props
[0].Value
<<= (sal_Int32
) maColor
.GetColor();
86 props
[1].Name
= "Mode";
87 props
[1].Value
<<= (sal_Int16
) meMode
;
89 xPropertyAccess
->setPropertyValues( props
);
91 ret
= xDialog
->execute();
95 props
= xPropertyAccess
->getPropertyValues();
96 for( sal_Int32 n
= 0; n
< props
.getLength(); n
++ )
98 if( props
[n
].Name
.equals( sColor
) )
100 sal_Int32 nColor
= 0;
101 if( props
[n
].Value
>>= nColor
)
103 maColor
.SetColor( nColor
);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */