xref: /trunk/main/svtools/source/dialogs/colrdlg.cxx (revision 5900e8ec)
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 <svtools/svtdata.hxx>
30 #include "colrdlg.hrc"
31 #include <svtools/colrdlg.hxx>
32 
33 // ---------------
34 // - ColorDialog -
35 // ---------------
36 
37 SvColorDialog::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 ) )
76 {
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 
107 
108 // -----------------------------------------------------------------------
109 SvColorDialog::~SvColorDialog()
110 {
111 }
112 
113 // -----------------------------------------------------------------------
114 void 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 // -----------------------------------------------------------------------
145 void SvColorDialog::SetColor( const Color& rColor )
146 {
147 	maColor = rColor;
148 }
149 
150 // -----------------------------------------------------------------------
151 const Color& SvColorDialog::GetColor() const
152 {
153 	return( maColor );
154 }
155 
156 // -----------------------------------------------------------------------
157 IMPL_LINK( SvColorDialog, ColorModifyHdl, void *, p )
158 {
159 	sal_uInt16 n = 0x00; // 1 == RGB, 2 == CMYK, 4 == HSB
160 
161 	if( p == &maCtlColor )
162 	{
163 		maColor = maCtlColor.GetColor();
164 		maNumRed.SetValue( maColor.GetRed() );
165 		maNumGreen.SetValue( maColor.GetGreen() );
166 		maNumBlue.SetValue( maColor.GetBlue() );
167 
168 		n = 7;
169 	}
170 	else if( p == &maNumRed )
171 	{
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 	{
192 
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 );
209 
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 	}
218 
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 	}
244 
245 	maCtlPreview.SetColor( maColor );
246 
247 	return 0;
248 }
249 
250 // -----------------------------------------------------------------------
251 IMPL_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 	*/
264 
265 	if( p == &maBtn1 )
266 	{
267 		CMCPosition ePos = maColMixCtrl.GetCMCPosition();
268 		if( ePos != CMC_OTHER )
269 			maColMixCtrl.SetColor( ePos, maColor );
270 	}
271 	else if( p == &maBtn2 )
272 	{
273 		sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
274 		maColor = maColMixCtrl.GetItemColor( nPos );
275 		maCtlColor.SetColor( maColor );
276 		ColorModifyHdl( &maCtlColor );
277 	}
278 
279 	return 0;
280 }
281 
282 // -----------------------------------------------------------------------
283 IMPL_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 // -----------------------------------------------------------------------
301 IMPL_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 // -----------------------------------------------------------------------
316 short SvColorDialog::Execute()
317 {
318 	Initialize();
319 
320 	short nRet = ModalDialog::Execute();
321 
322 	return( nRet );
323 }
324 
325