1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colrdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 #include <svtools/svtdata.hxx>
37 #include "colrdlg.hrc"
38 #include <svtools/colrdlg.hxx>
44 SvColorDialog::SvColorDialog( Window
* pWindow
) :
45 ModalDialog ( pWindow
, SvtResId( DLG_COLOR
) ),
46 maColMixCtrl ( this, SvtResId( VAL_SET_COLOR
), 8, 8 ),
47 maBtn1 ( this, SvtResId( BTN_1
) ),
48 maBtn2 ( this, SvtResId( BTN_2
) ),
49 //maBtn3 ( this, SvtResId( BTN_3 ) ),
50 //maBtn4 ( this, SvtResId( BTN_4 ) ),
51 //maFtRGB ( this, SvtResId( FT_RGB ) ),
52 maCtlColor ( this, SvtResId( CTL_COLOR
) ),
54 maFtCyan ( this, SvtResId( FT_CYAN
) ),
55 maNumCyan ( this, SvtResId( NUM_CYAN
) ),
56 maFtMagenta ( this, SvtResId( FT_MAGENTA
) ),
57 maNumMagenta ( this, SvtResId( NUM_MAGENTA
) ),
58 maFtYellow ( this, SvtResId( FT_YELLOW
) ),
59 maNumYellow ( this, SvtResId( NUM_YELLOW
) ),
60 maFtKey ( this, SvtResId( FT_KEY
) ),
61 maNumKey ( this, SvtResId( NUM_KEY
) ),
63 maFtRed ( this, SvtResId( FT_RED
) ),
64 maNumRed ( this, SvtResId( NUM_RED
) ),
65 maFtGreen ( this, SvtResId( FT_GREEN
) ),
66 maNumGreen ( this, SvtResId( NUM_GREEN
) ),
67 maFtBlue ( this, SvtResId( FT_BLUE
) ),
68 maNumBlue ( this, SvtResId( NUM_BLUE
) ),
70 maFtHue ( this, SvtResId( FT_HUE
) ),
71 maNumHue ( this, SvtResId( NUM_HUE
) ),
72 maFtSaturation ( this, SvtResId( FT_SATURATION
) ),
73 maNumSaturation ( this, SvtResId( NUM_SATURATION
) ),
74 maFtLuminance ( this, SvtResId( FT_LUMINANCE
) ),
75 maNumLuminance ( this, SvtResId( NUM_LUMINANCE
) ),
77 maCtlPreview ( this, SvtResId( CTL_PREVIEW
) ),
78 maCtlPreviewOld ( this, SvtResId( CTL_PREVIEW_OLD
) ),
80 maBtnOK ( this, SvtResId( BTN_OK
) ),
81 maBtnCancel ( this, SvtResId( BTN_CANCEL
) ),
82 maBtnHelp ( this, SvtResId( BTN_HELP
) )
86 maColMixCtrl
.SetDoubleClickHdl( LINK( this, SvColorDialog
, ClickMixCtrlHdl
) );
87 maColMixCtrl
.SetSelectHdl( LINK( this, SvColorDialog
, SelectMixCtrlHdl
) );
89 Link
aLink( LINK( this, SvColorDialog
, ColorModifyHdl
) );
90 maCtlColor
.SetModifyHdl( aLink
);
92 maNumRed
.SetModifyHdl( aLink
);
93 maNumGreen
.SetModifyHdl( aLink
);
94 maNumBlue
.SetModifyHdl( aLink
);
96 maNumCyan
.SetModifyHdl( aLink
);
97 maNumMagenta
.SetModifyHdl( aLink
);
98 maNumYellow
.SetModifyHdl( aLink
);
99 maNumKey
.SetModifyHdl( aLink
);
101 maNumHue
.SetModifyHdl( aLink
);
102 maNumSaturation
.SetModifyHdl( aLink
);
103 maNumLuminance
.SetModifyHdl( aLink
);
105 aLink
= ( LINK( this, SvColorDialog
, ClickBtnHdl
) );
106 maBtn1
.SetClickHdl( aLink
);
107 maBtn2
.SetClickHdl( aLink
);
108 //maBtn3.SetClickHdl( aLink );
109 //maBtn4.SetClickHdl( aLink );
111 maColMixCtrl
.SetExtraSpacing( 0 );
115 // -----------------------------------------------------------------------
116 SvColorDialog::~SvColorDialog()
120 // -----------------------------------------------------------------------
121 void SvColorDialog::Initialize()
123 maNumRed
.SetValue( maColor
.GetRed() );
124 maNumGreen
.SetValue( maColor
.GetGreen() );
125 maNumBlue
.SetValue( maColor
.GetBlue() );
127 ColorCMYK
aColorCMYK( maColor
);
129 long aCyan
= (long) ( (double)aColorCMYK
.GetCyan() * 100.0 / 255.0 + 0.5 );
130 long aMagenta
= (long) ( (double)aColorCMYK
.GetMagenta() * 100.0 / 255.0 + 0.5 );
131 long aYellow
= (long) ( (double)aColorCMYK
.GetYellow() * 100.0 / 255.0 + 0.5 );
132 long aKey
= (long) ( (double)aColorCMYK
.GetKey() * 100.0 / 255.0 + 0.5 );
133 maNumCyan
.SetValue( aCyan
);
134 maNumMagenta
.SetValue( aMagenta
);
135 maNumYellow
.SetValue( aYellow
);
136 maNumKey
.SetValue( aKey
);
138 ColorHSB
aColorHSB( maColor
);
139 maNumHue
.SetValue( aColorHSB
.GetHue() );
140 maNumSaturation
.SetValue( aColorHSB
.GetSat() );
141 maNumLuminance
.SetValue( aColorHSB
.GetBri() );
143 maCtlColor
.SetColor( aColorHSB
);
145 maColMixCtrl
.SelectItem( 1 );
147 maCtlPreview
.SetColor( maColor
);
148 maCtlPreviewOld
.SetColor( maColor
);
151 // -----------------------------------------------------------------------
152 void SvColorDialog::SetColor( const Color
& rColor
)
157 // -----------------------------------------------------------------------
158 const Color
& SvColorDialog::GetColor() const
163 // -----------------------------------------------------------------------
164 IMPL_LINK( SvColorDialog
, ColorModifyHdl
, void *, p
)
166 UINT16 n
= 0x00; // 1 == RGB, 2 == CMYK, 4 == HSB
168 if( p
== &maCtlColor
)
170 maColor
= maCtlColor
.GetColor();
171 maNumRed
.SetValue( maColor
.GetRed() );
172 maNumGreen
.SetValue( maColor
.GetGreen() );
173 maNumBlue
.SetValue( maColor
.GetBlue() );
177 else if( p
== &maNumRed
)
179 maColor
.SetRed( (UINT8
)maNumRed
.GetValue() );
180 maCtlColor
.SetColor( maColor
);
183 else if( p
== &maNumGreen
)
185 maColor
.SetGreen( (UINT8
)maNumGreen
.GetValue() );
186 maCtlColor
.SetColor( maColor
);
189 else if( p
== &maNumBlue
)
191 maColor
.SetBlue( (UINT8
)maNumBlue
.GetValue() );
192 maCtlColor
.SetColor( maColor
);
195 else if( p
== &maNumHue
||
196 p
== &maNumSaturation
||
197 p
== &maNumLuminance
)
200 ColorHSB
aColorHSB( (UINT16
) maNumHue
.GetValue(),
201 (UINT16
) maNumSaturation
.GetValue(),
202 (UINT16
) maNumLuminance
.GetValue() );
203 maCtlColor
.SetColor( aColorHSB
);
204 maColor
= maCtlColor
.GetColor();
207 else if( p
== &maNumCyan
||
208 p
== &maNumMagenta
||
212 long aCyan
= (long) ( (double)maNumCyan
.GetValue() * 255.0 / 100.0 + 0.5 );
213 long aMagenta
= (long) ( (double)maNumMagenta
.GetValue() * 255.0 / 100.0 + 0.5 );
214 long aYellow
= (long) ( (double)maNumYellow
.GetValue() * 255.0 / 100.0 + 0.5 );
215 long aKey
= (long) ( (double)maNumKey
.GetValue() * 255.0 / 100.0 + 0.5 );
217 ColorCMYK
aColorCMYK( (UINT16
) aCyan
,
221 maColor
= aColorCMYK
.GetRGB();
222 maCtlColor
.SetColor( maColor
);
226 if( n
& 1 ) // RGB setzen
228 maNumRed
.SetValue( maColor
.GetRed() );
229 maNumGreen
.SetValue( maColor
.GetGreen() );
230 maNumBlue
.SetValue( maColor
.GetBlue() );
232 if( n
& 2 ) // CMYK setzen
234 ColorCMYK
aColorCMYK( maColor
);
235 long aCyan
= (long) ( (double)aColorCMYK
.GetCyan() * 100.0 / 255.0 + 0.5 );
236 long aMagenta
= (long) ( (double)aColorCMYK
.GetMagenta() * 100.0 / 255.0 + 0.5 );
237 long aYellow
= (long) ( (double)aColorCMYK
.GetYellow() * 100.0 / 255.0 + 0.5 );
238 long aKey
= (long) ( (double)aColorCMYK
.GetKey() * 100.0 / 255.0 + 0.5 );
239 maNumCyan
.SetValue( aCyan
);
240 maNumMagenta
.SetValue( aMagenta
);
241 maNumYellow
.SetValue( aYellow
);
242 maNumKey
.SetValue( aKey
);
244 if( n
& 4 ) // HSB setzen
246 ColorHSB
aColorHSB( maColor
);
247 maNumHue
.SetValue( aColorHSB
.GetHue() );
248 maNumSaturation
.SetValue( aColorHSB
.GetSat() );
249 maNumLuminance
.SetValue( aColorHSB
.GetBri() );
252 maCtlPreview
.SetColor( maColor
);
257 // -----------------------------------------------------------------------
258 IMPL_LINK( SvColorDialog
, ClickBtnHdl
, void *, p
)
261 Color aColor = maCtlColor.GetColor();
263 maColMixCtrl.SetColor( CMC_TOPLEFT, aColor );
265 maColMixCtrl.SetColor( CMC_TOPRIGHT, aColor );
267 maColMixCtrl.SetColor( CMC_BOTTOMLEFT, aColor );
269 maColMixCtrl.SetColor( CMC_BOTTOMRIGHT, aColor );
274 CMCPosition ePos
= maColMixCtrl
.GetCMCPosition();
275 if( ePos
!= CMC_OTHER
)
276 maColMixCtrl
.SetColor( ePos
, maColor
);
278 else if( p
== &maBtn2
)
280 USHORT nPos
= maColMixCtrl
.GetSelectItemId();
281 maColor
= maColMixCtrl
.GetItemColor( nPos
);
282 maCtlColor
.SetColor( maColor
);
283 ColorModifyHdl( &maCtlColor
);
289 // -----------------------------------------------------------------------
290 IMPL_LINK( SvColorDialog
, ClickMixCtrlHdl
, void *, EMPTYARG
)
292 USHORT nPos
= maColMixCtrl
.GetSelectItemId();
293 CMCPosition ePos
= maColMixCtrl
.GetCMCPosition();
295 if( ePos
!= CMC_OTHER
)
296 maColMixCtrl
.SetColor( ePos
, maColor
);
299 maColor
= maColMixCtrl
.GetItemColor( nPos
);
300 maCtlColor
.SetColor( maColor
);
301 ColorModifyHdl( &maCtlColor
);
307 // -----------------------------------------------------------------------
308 IMPL_LINK( SvColorDialog
, SelectMixCtrlHdl
, void *, EMPTYARG
)
310 //USHORT nPos = maColMixCtrl.GetSelectItemId();
311 //maFtRGB.SetText( maColMixCtrl.GetItemText( nPos ) );
313 CMCPosition ePos
= maColMixCtrl
.GetCMCPosition();
314 if( ePos
== CMC_OTHER
)
315 maBtn1
.Enable( FALSE
);
322 // -----------------------------------------------------------------------
323 short SvColorDialog::Execute()
327 short nRet
= ModalDialog::Execute();