merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / dialogs / colrdlg.cxx
blob1f8df364efda28585055b3ca6886b48c55bd49dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colrdlg.cxx,v $
10 * $Revision: 1.7 $
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"
33 #ifndef GCC
34 #endif
36 #include <svtools/svtdata.hxx>
37 #include "colrdlg.hrc"
38 #include <svtools/colrdlg.hxx>
40 // ---------------
41 // - ColorDialog -
42 // ---------------
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 ) )
84 FreeResource();
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 )
154 maColor = rColor;
157 // -----------------------------------------------------------------------
158 const Color& SvColorDialog::GetColor() const
160 return( maColor );
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() );
175 n = 7;
177 else if( p == &maNumRed )
179 maColor.SetRed( (UINT8)maNumRed.GetValue() );
180 maCtlColor.SetColor( maColor );
181 n = 6;
183 else if( p == &maNumGreen )
185 maColor.SetGreen( (UINT8)maNumGreen.GetValue() );
186 maCtlColor.SetColor( maColor );
187 n = 6;
189 else if( p == &maNumBlue )
191 maColor.SetBlue( (UINT8)maNumBlue.GetValue() );
192 maCtlColor.SetColor( maColor );
193 n = 6;
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();
205 n = 3;
207 else if( p == &maNumCyan ||
208 p == &maNumMagenta ||
209 p == &maNumYellow ||
210 p == &maNumKey )
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,
218 (UINT16) aMagenta,
219 (UINT16) aYellow,
220 (UINT16) aKey );
221 maColor = aColorCMYK.GetRGB();
222 maCtlColor.SetColor( maColor );
223 n = 5;
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 );
254 return 0;
257 // -----------------------------------------------------------------------
258 IMPL_LINK( SvColorDialog, ClickBtnHdl, void *, p )
261 Color aColor = maCtlColor.GetColor();
262 if( p == &maBtn1 )
263 maColMixCtrl.SetColor( CMC_TOPLEFT, aColor );
264 if( p == &maBtn2 )
265 maColMixCtrl.SetColor( CMC_TOPRIGHT, aColor );
266 if( p == &maBtn3 )
267 maColMixCtrl.SetColor( CMC_BOTTOMLEFT, aColor );
268 if( p == &maBtn4 )
269 maColMixCtrl.SetColor( CMC_BOTTOMRIGHT, aColor );
272 if( p == &maBtn1 )
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 );
286 return 0;
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 );
297 else
299 maColor = maColMixCtrl.GetItemColor( nPos );
300 maCtlColor.SetColor( maColor );
301 ColorModifyHdl( &maCtlColor );
304 return 0;
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 );
316 else
317 maBtn1.Enable();
319 return 0;
322 // -----------------------------------------------------------------------
323 short SvColorDialog::Execute()
325 Initialize();
327 short nRet = ModalDialog::Execute();
329 return( nRet );