xref: /aoo42x/main/svtools/source/dialogs/colrdlg.cxx (revision 5900e8ec)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #ifndef GCC
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svtools/svtdata.hxx>
30cdf0e10cSrcweir #include "colrdlg.hrc"
31cdf0e10cSrcweir #include <svtools/colrdlg.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // ---------------
34cdf0e10cSrcweir // - ColorDialog -
35cdf0e10cSrcweir // ---------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir SvColorDialog::SvColorDialog( Window* pWindow ) :
38cdf0e10cSrcweir 		ModalDialog		( pWindow, SvtResId( DLG_COLOR ) ),
39cdf0e10cSrcweir 		maColMixCtrl	( this, SvtResId( VAL_SET_COLOR ), 8, 8 ),
40cdf0e10cSrcweir 		maBtn1			( this, SvtResId( BTN_1 ) ),
41cdf0e10cSrcweir 		maBtn2			( this, SvtResId( BTN_2 ) ),
42cdf0e10cSrcweir 		//maBtn3			( this, SvtResId( BTN_3 ) ),
43cdf0e10cSrcweir 		//maBtn4			( this, SvtResId( BTN_4 ) ),
44cdf0e10cSrcweir 		//maFtRGB			( this, SvtResId( FT_RGB ) ),
45cdf0e10cSrcweir 		maCtlColor		( this, SvtResId( CTL_COLOR ) ),
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 		maFtCyan		( this, SvtResId( FT_CYAN ) ),
48cdf0e10cSrcweir 		maNumCyan       ( this, SvtResId( NUM_CYAN ) ),
49cdf0e10cSrcweir 		maFtMagenta     ( this, SvtResId( FT_MAGENTA ) ),
50cdf0e10cSrcweir 		maNumMagenta    ( this, SvtResId( NUM_MAGENTA ) ),
51cdf0e10cSrcweir 		maFtYellow      ( this, SvtResId( FT_YELLOW ) ),
52cdf0e10cSrcweir 		maNumYellow     ( this, SvtResId( NUM_YELLOW ) ),
53cdf0e10cSrcweir 		maFtKey         ( this, SvtResId( FT_KEY ) ),
54cdf0e10cSrcweir 		maNumKey        ( this, SvtResId( NUM_KEY ) ),
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 		maFtRed	 		( this, SvtResId( FT_RED ) ),
57cdf0e10cSrcweir 		maNumRed		( this, SvtResId( NUM_RED ) ),
58cdf0e10cSrcweir 		maFtGreen		( this, SvtResId( FT_GREEN ) ),
59cdf0e10cSrcweir 		maNumGreen   	( this, SvtResId( NUM_GREEN ) ),
60cdf0e10cSrcweir 		maFtBlue		( this, SvtResId( FT_BLUE ) ),
61cdf0e10cSrcweir 		maNumBlue		( this, SvtResId( NUM_BLUE ) ),
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 		maFtHue			( this, SvtResId( FT_HUE ) ),
64cdf0e10cSrcweir 		maNumHue	   	( this, SvtResId( NUM_HUE ) ),
65cdf0e10cSrcweir 		maFtSaturation	( this, SvtResId( FT_SATURATION ) ),
66cdf0e10cSrcweir 		maNumSaturation	( this, SvtResId( NUM_SATURATION ) ),
67cdf0e10cSrcweir 		maFtLuminance	( this, SvtResId( FT_LUMINANCE ) ),
68cdf0e10cSrcweir 		maNumLuminance	( this, SvtResId( NUM_LUMINANCE ) ),
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 		maCtlPreview	( this, SvtResId( CTL_PREVIEW ) ),
71cdf0e10cSrcweir 		maCtlPreviewOld ( this, SvtResId( CTL_PREVIEW_OLD ) ),
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		maBtnOK			( this, SvtResId( BTN_OK ) ),
74cdf0e10cSrcweir 		maBtnCancel		( this, SvtResId( BTN_CANCEL ) ),
75cdf0e10cSrcweir 		maBtnHelp		( this, SvtResId( BTN_HELP ) )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	FreeResource();
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	maColMixCtrl.SetDoubleClickHdl( LINK( this, SvColorDialog, ClickMixCtrlHdl ) );
80cdf0e10cSrcweir 	maColMixCtrl.SetSelectHdl( LINK( this, SvColorDialog, SelectMixCtrlHdl ) );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	Link aLink( LINK( this, SvColorDialog, ColorModifyHdl ) );
83cdf0e10cSrcweir 	maCtlColor.SetModifyHdl( aLink );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	maNumRed.SetModifyHdl( aLink );
86cdf0e10cSrcweir 	maNumGreen.SetModifyHdl( aLink );
87cdf0e10cSrcweir 	maNumBlue.SetModifyHdl( aLink );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	maNumCyan.SetModifyHdl( aLink );
90cdf0e10cSrcweir 	maNumMagenta.SetModifyHdl( aLink );
91cdf0e10cSrcweir 	maNumYellow.SetModifyHdl( aLink );
92cdf0e10cSrcweir 	maNumKey.SetModifyHdl( aLink );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	maNumHue.SetModifyHdl( aLink );
95cdf0e10cSrcweir 	maNumSaturation.SetModifyHdl( aLink );
96cdf0e10cSrcweir 	maNumLuminance.SetModifyHdl( aLink );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	aLink = ( LINK( this, SvColorDialog, ClickBtnHdl ) );
99cdf0e10cSrcweir 	maBtn1.SetClickHdl( aLink );
100cdf0e10cSrcweir 	maBtn2.SetClickHdl( aLink );
101cdf0e10cSrcweir 	//maBtn3.SetClickHdl( aLink );
102cdf0e10cSrcweir 	//maBtn4.SetClickHdl( aLink );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	maColMixCtrl.SetExtraSpacing( 0 );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // -----------------------------------------------------------------------
109cdf0e10cSrcweir SvColorDialog::~SvColorDialog()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // -----------------------------------------------------------------------
114cdf0e10cSrcweir void SvColorDialog::Initialize()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	maNumRed.SetValue( maColor.GetRed() );
117cdf0e10cSrcweir 	maNumGreen.SetValue( maColor.GetGreen() );
118cdf0e10cSrcweir 	maNumBlue.SetValue( maColor.GetBlue() );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	ColorCMYK aColorCMYK( maColor );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	long aCyan    = (long) ( (double)aColorCMYK.GetCyan() * 100.0 / 255.0 + 0.5 );
123cdf0e10cSrcweir 	long aMagenta = (long) ( (double)aColorCMYK.GetMagenta() * 100.0 / 255.0 + 0.5 );
124cdf0e10cSrcweir 	long aYellow  = (long) ( (double)aColorCMYK.GetYellow() * 100.0 / 255.0 + 0.5 );
125cdf0e10cSrcweir 	long aKey     = (long) ( (double)aColorCMYK.GetKey() * 100.0 / 255.0 + 0.5 );
126cdf0e10cSrcweir 	maNumCyan.SetValue( aCyan );
127cdf0e10cSrcweir 	maNumMagenta.SetValue( aMagenta );
128cdf0e10cSrcweir 	maNumYellow.SetValue( aYellow );
129cdf0e10cSrcweir 	maNumKey.SetValue( aKey );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	ColorHSB aColorHSB( maColor );
132cdf0e10cSrcweir 	maNumHue.SetValue( aColorHSB.GetHue() );
133cdf0e10cSrcweir 	maNumSaturation.SetValue( aColorHSB.GetSat() );
134cdf0e10cSrcweir 	maNumLuminance.SetValue( aColorHSB.GetBri() );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	maCtlColor.SetColor( aColorHSB );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	maColMixCtrl.SelectItem( 1 );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	maCtlPreview.SetColor( maColor );
141cdf0e10cSrcweir 	maCtlPreviewOld.SetColor( maColor );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // -----------------------------------------------------------------------
145cdf0e10cSrcweir void SvColorDialog::SetColor( const Color& rColor )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	maColor = rColor;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir // -----------------------------------------------------------------------
151cdf0e10cSrcweir const Color& SvColorDialog::GetColor() const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	return( maColor );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // -----------------------------------------------------------------------
157cdf0e10cSrcweir IMPL_LINK( SvColorDialog, ColorModifyHdl, void *, p )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	sal_uInt16 n = 0x00; // 1 == RGB, 2 == CMYK, 4 == HSB
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	if( p == &maCtlColor )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		maColor = maCtlColor.GetColor();
164cdf0e10cSrcweir 		maNumRed.SetValue( maColor.GetRed() );
165cdf0e10cSrcweir 		maNumGreen.SetValue( maColor.GetGreen() );
166cdf0e10cSrcweir 		maNumBlue.SetValue( maColor.GetBlue() );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		n = 7;
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 	else if( p == &maNumRed )
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 		maColor.SetRed( (sal_uInt8)maNumRed.GetValue() );
173cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
174cdf0e10cSrcweir 		n = 6;
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 	else if( p == &maNumGreen )
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		maColor.SetGreen( (sal_uInt8)maNumGreen.GetValue() );
179cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
180cdf0e10cSrcweir 		n = 6;
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 	else if( p == &maNumBlue )
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		maColor.SetBlue( (sal_uInt8)maNumBlue.GetValue() );
185cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
186cdf0e10cSrcweir 		n = 6;
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 	else if( p == &maNumHue ||
189cdf0e10cSrcweir 			 p == &maNumSaturation ||
190cdf0e10cSrcweir 			 p == &maNumLuminance )
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		ColorHSB aColorHSB( (sal_uInt16) maNumHue.GetValue(),
194cdf0e10cSrcweir 							(sal_uInt16) maNumSaturation.GetValue(),
195cdf0e10cSrcweir 							(sal_uInt16) maNumLuminance.GetValue() );
196cdf0e10cSrcweir 		maCtlColor.SetColor( aColorHSB );
197cdf0e10cSrcweir 		maColor = maCtlColor.GetColor();
198cdf0e10cSrcweir 		n = 3;
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 	else if( p == &maNumCyan ||
201cdf0e10cSrcweir 			 p == &maNumMagenta ||
202cdf0e10cSrcweir 			 p == &maNumYellow ||
203cdf0e10cSrcweir 			 p == &maNumKey )
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		long aCyan    = (long) ( (double)maNumCyan.GetValue() * 255.0 / 100.0 + 0.5 );
206cdf0e10cSrcweir 		long aMagenta = (long) ( (double)maNumMagenta.GetValue() * 255.0 / 100.0 + 0.5 );
207cdf0e10cSrcweir 		long aYellow  = (long) ( (double)maNumYellow.GetValue() * 255.0 / 100.0 + 0.5 );
208cdf0e10cSrcweir 		long aKey     = (long) ( (double)maNumKey.GetValue() * 255.0 / 100.0 + 0.5 );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 		ColorCMYK aColorCMYK( (sal_uInt16) aCyan,
211cdf0e10cSrcweir 							  (sal_uInt16) aMagenta,
212cdf0e10cSrcweir 							  (sal_uInt16) aYellow,
213cdf0e10cSrcweir 							  (sal_uInt16) aKey );
214cdf0e10cSrcweir 		maColor = aColorCMYK.GetRGB();
215cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
216cdf0e10cSrcweir 		n = 5;
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	if( n & 1 ) // RGB setzen
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		maNumRed.SetValue( maColor.GetRed() );
222cdf0e10cSrcweir 		maNumGreen.SetValue( maColor.GetGreen() );
223cdf0e10cSrcweir 		maNumBlue.SetValue( maColor.GetBlue() );
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 	if( n & 2 ) // CMYK setzen
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		ColorCMYK aColorCMYK( maColor );
228cdf0e10cSrcweir 		long aCyan    = (long) ( (double)aColorCMYK.GetCyan() * 100.0 / 255.0 + 0.5 );
229cdf0e10cSrcweir 		long aMagenta = (long) ( (double)aColorCMYK.GetMagenta() * 100.0 / 255.0 + 0.5 );
230cdf0e10cSrcweir 		long aYellow  = (long) ( (double)aColorCMYK.GetYellow() * 100.0 / 255.0 + 0.5 );
231cdf0e10cSrcweir 		long aKey     = (long) ( (double)aColorCMYK.GetKey() * 100.0 / 255.0 + 0.5 );
232cdf0e10cSrcweir 		maNumCyan.SetValue( aCyan );
233cdf0e10cSrcweir 		maNumMagenta.SetValue( aMagenta );
234cdf0e10cSrcweir 		maNumYellow.SetValue( aYellow );
235cdf0e10cSrcweir 		maNumKey.SetValue( aKey );
236cdf0e10cSrcweir 	}
237cdf0e10cSrcweir 	if( n & 4 ) // HSB setzen
238cdf0e10cSrcweir 	{
239cdf0e10cSrcweir 		ColorHSB aColorHSB( maColor );
240cdf0e10cSrcweir 		maNumHue.SetValue( aColorHSB.GetHue() );
241cdf0e10cSrcweir 		maNumSaturation.SetValue( aColorHSB.GetSat() );
242cdf0e10cSrcweir 		maNumLuminance.SetValue( aColorHSB.GetBri() );
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	maCtlPreview.SetColor( maColor );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	return 0;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // -----------------------------------------------------------------------
251cdf0e10cSrcweir IMPL_LINK( SvColorDialog, ClickBtnHdl, void *, p )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir 	/*
254cdf0e10cSrcweir 	Color aColor = maCtlColor.GetColor();
255cdf0e10cSrcweir 	if( p == &maBtn1 )
256cdf0e10cSrcweir 		maColMixCtrl.SetColor( CMC_TOPLEFT, aColor );
257cdf0e10cSrcweir 	if( p == &maBtn2 )
258cdf0e10cSrcweir 		maColMixCtrl.SetColor( CMC_TOPRIGHT, aColor );
259cdf0e10cSrcweir 	if( p == &maBtn3 )
260cdf0e10cSrcweir 		maColMixCtrl.SetColor( CMC_BOTTOMLEFT, aColor );
261cdf0e10cSrcweir 	if( p == &maBtn4 )
262cdf0e10cSrcweir 		maColMixCtrl.SetColor( CMC_BOTTOMRIGHT, aColor );
263cdf0e10cSrcweir 	*/
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	if( p == &maBtn1 )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		CMCPosition ePos = maColMixCtrl.GetCMCPosition();
268cdf0e10cSrcweir 		if( ePos != CMC_OTHER )
269cdf0e10cSrcweir 			maColMixCtrl.SetColor( ePos, maColor );
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir 	else if( p == &maBtn2 )
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir 		sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
274cdf0e10cSrcweir 		maColor = maColMixCtrl.GetItemColor( nPos );
275cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
276cdf0e10cSrcweir 		ColorModifyHdl( &maCtlColor );
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	return 0;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir // -----------------------------------------------------------------------
283cdf0e10cSrcweir IMPL_LINK( SvColorDialog, ClickMixCtrlHdl, void *, EMPTYARG )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
286cdf0e10cSrcweir 	CMCPosition ePos = maColMixCtrl.GetCMCPosition();
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	if( ePos != CMC_OTHER )
289cdf0e10cSrcweir 		maColMixCtrl.SetColor( ePos, maColor );
290cdf0e10cSrcweir 	else
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 		maColor = maColMixCtrl.GetItemColor( nPos );
293cdf0e10cSrcweir 		maCtlColor.SetColor( maColor );
294cdf0e10cSrcweir 		ColorModifyHdl( &maCtlColor );
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	return 0;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir // -----------------------------------------------------------------------
301cdf0e10cSrcweir IMPL_LINK( SvColorDialog, SelectMixCtrlHdl, void *, EMPTYARG )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	//sal_uInt16 nPos = maColMixCtrl.GetSelectItemId();
304cdf0e10cSrcweir 	//maFtRGB.SetText( maColMixCtrl.GetItemText( nPos ) );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	CMCPosition ePos = maColMixCtrl.GetCMCPosition();
307cdf0e10cSrcweir 	if( ePos == CMC_OTHER )
308cdf0e10cSrcweir 		maBtn1.Enable( sal_False );
309cdf0e10cSrcweir 	else
310cdf0e10cSrcweir 		maBtn1.Enable();
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	return 0;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // -----------------------------------------------------------------------
316cdf0e10cSrcweir short SvColorDialog::Execute()
317cdf0e10cSrcweir {
318cdf0e10cSrcweir 	Initialize();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 	short nRet = ModalDialog::Execute();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	return( nRet );
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325