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