colrdlg.cxx (5900e8ec) colrdlg.cxx (b2b569f2)
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

--- 12 unchanged lines hidden (view full) ---

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
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

--- 12 unchanged lines hidden (view full) ---

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 <svtools/svtdata.hxx>
30#include "colrdlg.hrc"
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>
31#include <svtools/colrdlg.hxx>
32
35#include <svtools/colrdlg.hxx>
36
37using rtl::OUString;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::ui::dialogs;
42
33// ---------------
34// - ColorDialog -
35// ---------------
36
43// ---------------
44// - ColorDialog -
45// ---------------
46
37SvColorDialog::SvColorDialog( Window* pWindow ) :
38 ModalDialog ( pWindow, SvtResId( DLG_COLOR ) ),
39 maColMixCtrl ( this, SvtResId( VAL_SET_COLOR ), 8, 8 ),
40 maBtn1 ( this, SvtResId( BTN_1 ) ),
41 maBtn2 ( this, SvtResId( BTN_2 ) ),
42 //maBtn3 ( this, SvtResId( BTN_3 ) ),
43 //maBtn4 ( this, SvtResId( BTN_4 ) ),
44 //maFtRGB ( this, SvtResId( FT_RGB ) ),
45 maCtlColor ( this, SvtResId( CTL_COLOR ) ),
46
47 maFtCyan ( this, SvtResId( FT_CYAN ) ),
48 maNumCyan ( this, SvtResId( NUM_CYAN ) ),
49 maFtMagenta ( this, SvtResId( FT_MAGENTA ) ),
50 maNumMagenta ( this, SvtResId( NUM_MAGENTA ) ),
51 maFtYellow ( this, SvtResId( FT_YELLOW ) ),
52 maNumYellow ( this, SvtResId( NUM_YELLOW ) ),
53 maFtKey ( this, SvtResId( FT_KEY ) ),
54 maNumKey ( this, SvtResId( NUM_KEY ) ),
55
56 maFtRed ( this, SvtResId( FT_RED ) ),
57 maNumRed ( this, SvtResId( NUM_RED ) ),
58 maFtGreen ( this, SvtResId( FT_GREEN ) ),
59 maNumGreen ( this, SvtResId( NUM_GREEN ) ),
60 maFtBlue ( this, SvtResId( FT_BLUE ) ),
61 maNumBlue ( this, SvtResId( NUM_BLUE ) ),
62
63 maFtHue ( this, SvtResId( FT_HUE ) ),
64 maNumHue ( this, SvtResId( NUM_HUE ) ),
65 maFtSaturation ( this, SvtResId( FT_SATURATION ) ),
66 maNumSaturation ( this, SvtResId( NUM_SATURATION ) ),
67 maFtLuminance ( this, SvtResId( FT_LUMINANCE ) ),
68 maNumLuminance ( this, SvtResId( NUM_LUMINANCE ) ),
69
70 maCtlPreview ( this, SvtResId( CTL_PREVIEW ) ),
71 maCtlPreviewOld ( this, SvtResId( CTL_PREVIEW_OLD ) ),
72
73 maBtnOK ( this, SvtResId( BTN_OK ) ),
74 maBtnCancel ( this, SvtResId( BTN_CANCEL ) ),
75 maBtnHelp ( this, SvtResId( BTN_HELP ) )
47SvColorDialog::SvColorDialog( Window* pWindow )
48: mpParent( pWindow )
49, meMode( svtools::ColorPickerMode_SELECT )
76{
50{
77 FreeResource();
78
79 maColMixCtrl.SetDoubleClickHdl( LINK( this, SvColorDialog, ClickMixCtrlHdl ) );
80 maColMixCtrl.SetSelectHdl( LINK( this, SvColorDialog, SelectMixCtrlHdl ) );
81
82 Link aLink( LINK( this, SvColorDialog, ColorModifyHdl ) );
83 maCtlColor.SetModifyHdl( aLink );
84
85 maNumRed.SetModifyHdl( aLink );
86 maNumGreen.SetModifyHdl( aLink );
87 maNumBlue.SetModifyHdl( aLink );
88
89 maNumCyan.SetModifyHdl( aLink );
90 maNumMagenta.SetModifyHdl( aLink );
91 maNumYellow.SetModifyHdl( aLink );
92 maNumKey.SetModifyHdl( aLink );
93
94 maNumHue.SetModifyHdl( aLink );
95 maNumSaturation.SetModifyHdl( aLink );
96 maNumLuminance.SetModifyHdl( aLink );
97
98 aLink = ( LINK( this, SvColorDialog, ClickBtnHdl ) );
99 maBtn1.SetClickHdl( aLink );
100 maBtn2.SetClickHdl( aLink );
101 //maBtn3.SetClickHdl( aLink );
102 //maBtn4.SetClickHdl( aLink );
103
104 maColMixCtrl.SetExtraSpacing( 0 );
105}
106
51}
52
107
108// -----------------------------------------------------------------------
53// -----------------------------------------------------------------------
109SvColorDialog::~SvColorDialog()
110{
111}
112
54
113// -----------------------------------------------------------------------
114void SvColorDialog::Initialize()
115{
116 maNumRed.SetValue( maColor.GetRed() );
117 maNumGreen.SetValue( maColor.GetGreen() );
118 maNumBlue.SetValue( maColor.GetBlue() );
119
120 ColorCMYK aColorCMYK( maColor );
121
122 long aCyan = (long) ( (double)aColorCMYK.GetCyan() * 100.0 / 255.0 + 0.5 );
123 long aMagenta = (long) ( (double)aColorCMYK.GetMagenta() * 100.0 / 255.0 + 0.5 );
124 long aYellow = (long) ( (double)aColorCMYK.GetYellow() * 100.0 / 255.0 + 0.5 );
125 long aKey = (long) ( (double)aColorCMYK.GetKey() * 100.0 / 255.0 + 0.5 );
126 maNumCyan.SetValue( aCyan );
127 maNumMagenta.SetValue( aMagenta );
128 maNumYellow.SetValue( aYellow );
129 maNumKey.SetValue( aKey );
130
131 ColorHSB aColorHSB( maColor );
132 maNumHue.SetValue( aColorHSB.GetHue() );
133 maNumSaturation.SetValue( aColorHSB.GetSat() );
134 maNumLuminance.SetValue( aColorHSB.GetBri() );
135
136 maCtlColor.SetColor( aColorHSB );
137
138 maColMixCtrl.SelectItem( 1 );
139
140 maCtlPreview.SetColor( maColor );
141 maCtlPreviewOld.SetColor( maColor );
142}
143
144// -----------------------------------------------------------------------
145void SvColorDialog::SetColor( const Color& rColor )
146{
147 maColor = rColor;
148}
149
150// -----------------------------------------------------------------------
55void SvColorDialog::SetColor( const Color& rColor )
56{
57 maColor = rColor;
58}
59
60// -----------------------------------------------------------------------
61
151const Color& SvColorDialog::GetColor() const
152{
62const Color& SvColorDialog::GetColor() const
63{
153 return( maColor );
64 return maColor;
154}
155
156// -----------------------------------------------------------------------
65}
66
67// -----------------------------------------------------------------------
157IMPL_LINK( SvColorDialog, ColorModifyHdl, void *, p )
68
69void SvColorDialog::SetMode( sal_Int16 eMode )
158{
70{
159 sal_uInt16 n = 0x00; // 1 == RGB, 2 == CMYK, 4 == HSB
71 meMode = eMode;
72}
160
73
161 if( p == &maCtlColor )
162 {
163 maColor = maCtlColor.GetColor();
164 maNumRed.SetValue( maColor.GetRed() );
165 maNumGreen.SetValue( maColor.GetGreen() );
166 maNumBlue.SetValue( maColor.GetBlue() );
74// -----------------------------------------------------------------------
167
75
168 n = 7;
169 }
170 else if( p == &maNumRed )
76short SvColorDialog::Execute()
77{
78 short ret = 0;
79 try
171 {
80 {
172 maColor.SetRed( (sal_uInt8)maNumRed.GetValue() );
173 maCtlColor.SetColor( maColor );
174 n = 6;
175 }
176 else if( p == &maNumGreen )
177 {
178 maColor.SetGreen( (sal_uInt8)maNumGreen.GetValue() );
179 maCtlColor.SetColor( maColor );
180 n = 6;
181 }
182 else if( p == &maNumBlue )
183 {
184 maColor.SetBlue( (sal_uInt8)maNumBlue.GetValue() );
185 maCtlColor.SetColor( maColor );
186 n = 6;
187 }
188 else if( p == &maNumHue ||
189 p == &maNumSaturation ||
190 p == &maNumLuminance )
191 {
81 const OUString sColor( RTL_CONSTASCII_USTRINGPARAM( "Color" ) );
82 Reference< XMultiServiceFactory > xSMGR( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
192
83
193 ColorHSB aColorHSB( (sal_uInt16) maNumHue.GetValue(),
194 (sal_uInt16) maNumSaturation.GetValue(),
195 (sal_uInt16) maNumLuminance.GetValue() );
196 maCtlColor.SetColor( aColorHSB );
197 maColor = maCtlColor.GetColor();
198 n = 3;
199 }
200 else if( p == &maNumCyan ||
201 p == &maNumMagenta ||
202 p == &maNumYellow ||
203 p == &maNumKey )
204 {
205 long aCyan = (long) ( (double)maNumCyan.GetValue() * 255.0 / 100.0 + 0.5 );
206 long aMagenta = (long) ( (double)maNumMagenta.GetValue() * 255.0 / 100.0 + 0.5 );
207 long aYellow = (long) ( (double)maNumYellow.GetValue() * 255.0 / 100.0 + 0.5 );
208 long aKey = (long) ( (double)maNumKey.GetValue() * 255.0 / 100.0 + 0.5 );
84 Reference< com::sun::star::awt::XWindow > xParent( VCLUnoHelper::GetInterface( mpParent ) );
209
85
210 ColorCMYK aColorCMYK( (sal_uInt16) aCyan,
211 (sal_uInt16) aMagenta,
212 (sal_uInt16) aYellow,
213 (sal_uInt16) aKey );
214 maColor = aColorCMYK.GetRGB();
215 maCtlColor.SetColor( maColor );
216 n = 5;
217 }
86 Sequence< Any > args(1);
87 args[0] = Any( xParent );
218
88
219 if( n & 1 ) // RGB setzen
220 {
221 maNumRed.SetValue( maColor.GetRed() );
222 maNumGreen.SetValue( maColor.GetGreen() );
223 maNumBlue.SetValue( maColor.GetBlue() );
224 }
225 if( n & 2 ) // CMYK setzen
226 {
227 ColorCMYK aColorCMYK( maColor );
228 long aCyan = (long) ( (double)aColorCMYK.GetCyan() * 100.0 / 255.0 + 0.5 );
229 long aMagenta = (long) ( (double)aColorCMYK.GetMagenta() * 100.0 / 255.0 + 0.5 );
230 long aYellow = (long) ( (double)aColorCMYK.GetYellow() * 100.0 / 255.0 + 0.5 );
231 long aKey = (long) ( (double)aColorCMYK.GetKey() * 100.0 / 255.0 + 0.5 );
232 maNumCyan.SetValue( aCyan );
233 maNumMagenta.SetValue( aMagenta );
234 maNumYellow.SetValue( aYellow );
235 maNumKey.SetValue( aKey );
236 }
237 if( n & 4 ) // HSB setzen
238 {
239 ColorHSB aColorHSB( maColor );
240 maNumHue.SetValue( aColorHSB.GetHue() );
241 maNumSaturation.SetValue( aColorHSB.GetSat() );
242 maNumLuminance.SetValue( aColorHSB.GetBri() );
243 }
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 );
244
91
245 maCtlPreview.SetColor( maColor );
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;
246
97
247 return 0;
248}
98 xPropertyAccess->setPropertyValues( props );
249
99
250// -----------------------------------------------------------------------
251IMPL_LINK( SvColorDialog, ClickBtnHdl, void *, p )
252{
253 /*
254 Color aColor = maCtlColor.GetColor();
255 if( p == &maBtn1 )
256 maColMixCtrl.SetColor( CMC_TOPLEFT, aColor );
257 if( p == &maBtn2 )
258 maColMixCtrl.SetColor( CMC_TOPRIGHT, aColor );
259 if( p == &maBtn3 )
260 maColMixCtrl.SetColor( CMC_BOTTOMLEFT, aColor );
261 if( p == &maBtn4 )
262 maColMixCtrl.SetColor( CMC_BOTTOMRIGHT, aColor );
263 */
100 ret = xDialog->execute();
264
101
265 if( p == &maBtn1 )
266 {
267 CMCPosition ePos = maColMixCtrl.GetCMCPosition();
268 if( ePos != CMC_OTHER )
269 maColMixCtrl.SetColor( ePos, maColor );
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 }
270 }
118 }
271 else if( p == &maBtn2 )
119 catch(Exception&)
272 {
120 {
273 sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
274 maColor = maColMixCtrl.GetItemColor( nPos );
275 maCtlColor.SetColor( maColor );
276 ColorModifyHdl( &maCtlColor );
121 OSL_ASSERT(false);
277 }
278
122 }
123
279 return 0;
124 return ret;
280}
281
282// -----------------------------------------------------------------------
125}
126
127// -----------------------------------------------------------------------
283IMPL_LINK( SvColorDialog, ClickMixCtrlHdl, void *, EMPTYARG )
284{
285 sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
286 CMCPosition ePos = maColMixCtrl.GetCMCPosition();
287
288 if( ePos != CMC_OTHER )
289 maColMixCtrl.SetColor( ePos, maColor );
290 else
291 {
292 maColor = maColMixCtrl.GetItemColor( nPos );
293 maCtlColor.SetColor( maColor );
294 ColorModifyHdl( &maCtlColor );
295 }
296
297 return 0;
298}
299
300// -----------------------------------------------------------------------
301IMPL_LINK( SvColorDialog, SelectMixCtrlHdl, void *, EMPTYARG )
302{
303 //sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
304 //maFtRGB.SetText( maColMixCtrl.GetItemText( nPos ) );
305
306 CMCPosition ePos = maColMixCtrl.GetCMCPosition();
307 if( ePos == CMC_OTHER )
308 maBtn1.Enable( sal_False );
309 else
310 maBtn1.Enable();
311
312 return 0;
313}
314
315// -----------------------------------------------------------------------
316short SvColorDialog::Execute()
317{
318 Initialize();
319
320 short nRet = ModalDialog::Execute();
321
322 return( nRet );
323}
324
128// eof