Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Christian Lippka <cl@lippka.com>
17 : : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Major Contributor(s):
21 : : *
22 : : *
23 : : * For minor contributions see the git repository.
24 : : *
25 : : * Alternatively, the contents of this file may be used under the terms of
26 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
27 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
28 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
29 : : * instead of those above.
30 : : */
31 : :
32 : : #include <com/sun/star/uno/XComponentContext.hpp>
33 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
34 : : #include <com/sun/star/beans/XPropertyAccess.hpp>
35 : : #include <com/sun/star/lang/XInitialization.hpp>
36 : : #include <com/sun/star/lang/XServiceInfo.hpp>
37 : : #include <com/sun/star/datatransfer/XTransferable.hpp>
38 : : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
39 : : #include <com/sun/star/awt/XWindow.hpp>
40 : :
41 : : #include <cppuhelper/compbase4.hxx>
42 : :
43 : : #include <comphelper/broadcasthelper.hxx>
44 : :
45 : : #include <vcl/dialog.hxx>
46 : : #include <vcl/button.hxx>
47 : : #include <vcl/fixed.hxx>
48 : : #include <vcl/edit.hxx>
49 : : #include <vcl/field.hxx>
50 : : #include <vcl/bmpacc.hxx>
51 : : #include <vcl/decoview.hxx>
52 : : #include <vcl/svapp.hxx>
53 : :
54 : : #include <toolkit/helper/vclunohelper.hxx>
55 : :
56 : : #include <sot/exchange.hxx>
57 : : #include <sot/formats.hxx>
58 : :
59 : : #include <sax/tools/converter.hxx>
60 : :
61 : : #include <basegfx/color/bcolortools.hxx>
62 : :
63 : : #include "dialmgr.hxx"
64 : : #include "colorpicker.hrc"
65 : :
66 : : #include <cmath>
67 : :
68 : : using rtl::OUString;
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::lang;
71 : : using namespace ::com::sun::star::ui::dialogs;
72 : : using namespace ::com::sun::star::beans;
73 : : using namespace ::basegfx;
74 : :
75 : : namespace cui
76 : : {
77 : :
78 : : const sal_uInt16 COLORMODE_RGB = 0x10;
79 : : const sal_uInt16 COLORMODE_HSV = 0x20;
80 : : const sal_uInt16 COLORMODE_CMYK = 0x40;
81 : :
82 : : const sal_uInt16 COLORCOMP_RED = 0x10;
83 : : const sal_uInt16 COLORCOMP_GREEN = 0x11;
84 : : const sal_uInt16 COLORCOMP_BLUE = 0x12;
85 : :
86 : : const sal_uInt16 COLORCOMP_HUE = 0x20;
87 : : const sal_uInt16 COLORCOMP_SAT = 0x21;
88 : : const sal_uInt16 COLORCOMP_BRI = 0x22;
89 : :
90 : : const sal_uInt16 COLORCOMP_CYAN = 0x40;
91 : : const sal_uInt16 COLORCOMP_YELLOW = 0x41;
92 : : const sal_uInt16 COLORCOMP_MAGENTA = 0x42;
93 : : const sal_uInt16 COLORCOMP_KEY = 0x43;
94 : :
95 : : // color space conversion helpers
96 : :
97 : 0 : static void RGBtoHSV( double dR, double dG, double dB, double& dH, double& dS, double& dV )
98 : : {
99 [ # # ]: 0 : BColor result = tools::rgb2hsv( BColor( dR, dG, dB ) );
100 : :
101 : 0 : dH = result.getX();
102 : 0 : dS = result.getY();
103 : 0 : dV = result.getZ();
104 : 0 : }
105 : :
106 : 0 : static void HSVtoRGB(double dH, double dS, double dV, double& dR, double& dG, double& dB )
107 : : {
108 [ # # ]: 0 : BColor result = tools::hsv2rgb( BColor( dH, dS, dV ) );
109 : :
110 : 0 : dR = result.getRed();
111 : 0 : dG = result.getGreen();
112 : 0 : dB = result.getBlue();
113 : 0 : }
114 : :
115 : : // -----------------------------------------------------------------------
116 : :
117 : : // CMYK values from 0 to 1
118 : 0 : static void CMYKtoRGB( double fCyan, double fMagenta, double fYellow, double fKey, double& dR, double& dG, double& dB )
119 : : {
120 : 0 : fCyan = (fCyan * ( 1.0 - fKey )) + fKey;
121 : 0 : fMagenta = (fMagenta * ( 1.0 - fKey )) + fKey;
122 : 0 : fYellow = (fYellow * ( 1.0 - fKey )) + fKey;
123 : :
124 [ # # ][ # # ]: 0 : dR = std::max( std::min( ( 1.0 - fCyan ), 1.0), 0.0 );
125 [ # # ][ # # ]: 0 : dG = std::max( std::min( ( 1.0 - fMagenta ), 1.0), 0.0 );
126 [ # # ][ # # ]: 0 : dB = std::max( std::min( ( 1.0 - fYellow ), 1.0), 0.0 );
127 : 0 : }
128 : :
129 : : // -----------------------------------------------------------------------
130 : :
131 : : // CMY results from 0 to 1
132 : 0 : static void RGBtoCMYK( double dR, double dG, double dB, double& fCyan, double& fMagenta, double& fYellow, double& fKey )
133 : : {
134 : 0 : fCyan = 1 - dR;
135 : 0 : fMagenta = 1 - dG;
136 : 0 : fYellow = 1 - dB;
137 : :
138 : : //CMYK and CMY values from 0 to 1
139 : 0 : fKey = 1.0;
140 [ # # ]: 0 : if( fCyan < fKey ) fKey = fCyan;
141 [ # # ]: 0 : if( fMagenta < fKey ) fKey = fMagenta;
142 [ # # ]: 0 : if( fYellow < fKey ) fKey = fYellow;
143 : :
144 [ # # ]: 0 : if( fKey >= 1.0 )
145 : : {
146 : : //Black
147 : 0 : fCyan = 0.0;
148 : 0 : fMagenta = 0.0;
149 : 0 : fYellow = 0.0;
150 : : }
151 : : else
152 : : {
153 : 0 : fCyan = ( fCyan - fKey ) / ( 1.0 - fKey );
154 : 0 : fMagenta = ( fMagenta - fKey ) / ( 1.0 - fKey );
155 : 0 : fYellow = ( fYellow - fKey ) / ( 1.0 - fKey );
156 : : }
157 : 0 : }
158 : :
159 : : // ====================================================================
160 : :
161 [ # # ]: 0 : class HexColorControl : public Edit
162 : : {
163 : : public:
164 : : HexColorControl( Window* pParent, const ResId& rResId );
165 : :
166 : : virtual long PreNotify( NotifyEvent& rNEvt );
167 : : virtual void Paste();
168 : :
169 : : void SetColor( sal_Int32 nColor );
170 : : sal_Int32 GetColor();
171 : :
172 : : private:
173 : : bool ImplProcessKeyInput( const KeyEvent& rKEv );
174 : : };
175 : :
176 : 0 : HexColorControl::HexColorControl( Window* pParent, const ResId& rResId )
177 : 0 : : Edit( pParent, rResId )
178 : : {
179 [ # # ]: 0 : SetMaxTextLen( 6 );
180 : 0 : }
181 : :
182 : : // -----------------------------------------------------------------------
183 : :
184 : 0 : void HexColorControl::SetColor( sal_Int32 nColor )
185 : : {
186 : 0 : ::rtl::OUStringBuffer aBuffer;
187 [ # # ]: 0 : sax::Converter::convertColor( aBuffer, nColor );
188 [ # # ][ # # ]: 0 : SetText( aBuffer.makeStringAndClear().copy(1) );
[ # # ][ # # ]
189 : 0 : }
190 : :
191 : : // -----------------------------------------------------------------------
192 : :
193 : 0 : sal_Int32 HexColorControl::GetColor()
194 : : {
195 : 0 : sal_Int32 nColor = -1;
196 : :
197 [ # # ]: 0 : OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "#" ) );
198 [ # # ][ # # ]: 0 : aStr += GetText();
[ # # ]
199 : 0 : sal_Int32 nLen = aStr.getLength();
200 [ # # ]: 0 : if( nLen < 7 )
201 : : {
202 : : static const sal_Char* pNullStr = "000000";
203 : 0 : aStr += OUString::createFromAscii( &pNullStr[nLen-1] );
204 : : }
205 : :
206 [ # # ]: 0 : sax::Converter::convertColor( nColor, aStr );
207 : :
208 [ # # ]: 0 : if( nColor == -1 )
209 [ # # ]: 0 : SetControlBackground( Color( COL_RED ) );
210 : : else
211 [ # # ]: 0 : SetControlBackground();
212 : :
213 : 0 : return nColor;
214 : : }
215 : :
216 : : // -----------------------------------------------------------------------
217 : :
218 : 0 : long HexColorControl::PreNotify( NotifyEvent& rNEvt )
219 : : {
220 [ # # ][ # # ]: 0 : if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
[ # # ]
221 : : {
222 [ # # ]: 0 : if ( ImplProcessKeyInput( *rNEvt.GetKeyEvent() ) )
223 : 0 : return 1;
224 : : }
225 : :
226 : 0 : return Edit::PreNotify( rNEvt );
227 : : }
228 : :
229 : : // -----------------------------------------------------------------------
230 : :
231 : 0 : void HexColorControl::Paste()
232 : : {
233 [ # # ]: 0 : ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipboard(GetClipboard());
234 [ # # ]: 0 : if ( aClipboard.is() )
235 : : {
236 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xDataObj;
237 : :
238 [ # # ]: 0 : const sal_uInt32 nRef = Application::ReleaseSolarMutex();
239 : :
240 : : try
241 : : {
242 [ # # ][ # # ]: 0 : xDataObj = aClipboard->getContents();
[ # # ][ # # ]
243 : : }
244 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
245 : : {
246 : : }
247 : :
248 [ # # ]: 0 : Application::AcquireSolarMutex( nRef );
249 : :
250 [ # # ]: 0 : if ( xDataObj.is() )
251 : : {
252 : 0 : ::com::sun::star::datatransfer::DataFlavor aFlavor;
253 [ # # ]: 0 : SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
254 : : try
255 : : {
256 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Any aData = xDataObj->getTransferData( aFlavor );
257 : 0 : ::rtl::OUString aText;
258 : 0 : aData >>= aText;
259 : :
260 [ # # ][ # # ]: 0 : if( !aText.isEmpty() && aText.matchAsciiL( "#", 1, 0 ) )
[ # # ]
261 : 0 : aText = aText.copy(1);
262 : :
263 [ # # ]: 0 : if( aText.getLength() > 6 )
264 : 0 : aText = aText.copy( 0, 6 );
265 : :
266 [ # # ][ # # ]: 0 : SetText( aText );
[ # # ][ # # ]
267 : : }
268 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
269 : : {
270 : 0 : }
271 : 0 : }
272 : 0 : }
273 : 0 : }
274 : :
275 : : // -----------------------------------------------------------------------
276 : :
277 : 0 : bool HexColorControl::ImplProcessKeyInput( const KeyEvent& rKEv )
278 : : {
279 : 0 : const KeyCode& rKeyCode = rKEv.GetKeyCode();
280 : :
281 [ # # ][ # # ]: 0 : if( rKeyCode.GetGroup() == KEYGROUP_ALPHA && !rKeyCode.IsMod1() && !rKeyCode.IsMod2() )
[ # # ][ # # ]
282 : : {
283 [ # # ][ # # ]: 0 : if( (rKeyCode.GetCode() < KEY_A) || (rKeyCode.GetCode() > KEY_F) )
[ # # ]
284 : 0 : return true;
285 : : }
286 [ # # ]: 0 : else if( rKeyCode.GetGroup() == KEYGROUP_NUM )
287 : : {
288 [ # # ]: 0 : if( rKeyCode.IsShift() )
289 : 0 : return true;
290 : : }
291 : 0 : return false;
292 : : }
293 : :
294 : : // ====================================================================
295 : :
296 [ # # ]: 0 : class ColorPreviewControl : public Control
297 : : {
298 : : public:
299 : : ColorPreviewControl( Window* pParent, const ResId& rResId );
300 : :
301 : : virtual void Paint( const Rectangle& rRect );
302 : :
303 : : void SetColor( const Color& rColor );
304 : : private:
305 : : Color maColor;
306 : : };
307 : :
308 : : // -----------------------------------------------------------------------
309 : :
310 : 0 : ColorPreviewControl::ColorPreviewControl( Window* pParent, const ResId& rResId )
311 : 0 : : Control( pParent, rResId )
312 : : {
313 [ # # ]: 0 : SetFillColor( maColor );
314 [ # # ]: 0 : SetLineColor( maColor );
315 : 0 : }
316 : :
317 : : // -----------------------------------------------------------------------
318 : :
319 : 0 : void ColorPreviewControl::SetColor( const Color& rCol )
320 : : {
321 [ # # ]: 0 : if( rCol != maColor )
322 : : {
323 : 0 : maColor = rCol;
324 : 0 : SetFillColor( maColor );
325 : 0 : SetLineColor( maColor );
326 : 0 : Invalidate();
327 : : }
328 : 0 : }
329 : :
330 : : // -----------------------------------------------------------------------
331 : :
332 : 0 : void ColorPreviewControl::Paint( const Rectangle& rRect )
333 : : {
334 : 0 : DrawRect( rRect );
335 : 0 : }
336 : :
337 : : // ====================================================================
338 : :
339 : : enum ColorMode { HUE, SATURATION, BRIGHTNESS, RED, GREEN, BLUE };
340 : : const ColorMode DefaultMode = HUE;
341 : :
342 : : class ColorFieldControl : public Control
343 : : {
344 : : public:
345 : : ColorFieldControl( Window* pParent, const ResId& rResId );
346 : : ~ColorFieldControl();
347 : :
348 : : virtual void MouseMove( const MouseEvent& rMEvt );
349 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
350 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
351 : : virtual void KeyInput( const KeyEvent& rKEvt );
352 : : virtual void Paint( const Rectangle& rRect );
353 : : virtual void Resize();
354 : :
355 : : void UpdateBitmap();
356 : : void ShowPosition( const Point& rPos, bool bUpdate );
357 : : void UpdatePosition();
358 : : void Modify();
359 : :
360 : : void SetValues( Color aColor, ColorMode eMode, double x, double y );
361 : : double GetX();
362 : : double GetY();
363 : :
364 : : void KeyMove( int dx, int dy );
365 : :
366 : 0 : void SetModifyHdl( Link& rLink ) { maModifyHdl = rLink; }
367 : :
368 : : private:
369 : : Link maModifyHdl;
370 : : ColorMode meMode;
371 : : Color maColor;
372 : : double mdX;
373 : : double mdY;
374 : : Point maPosition;
375 : : Bitmap* mpBitmap;
376 : : std::vector< sal_uInt8 > maRGB_Horiz;
377 : : std::vector< sal_uInt16 > maGrad_Horiz;
378 : : std::vector< sal_uInt16 > maPercent_Horiz;
379 : : std::vector< sal_uInt8 > maRGB_Vert;
380 : : std::vector< sal_uInt16 > maPercent_Vert;
381 : : bool mbInit;
382 : : };
383 : :
384 : : // -----------------------------------------------------------------------
385 : :
386 : 0 : ColorFieldControl::ColorFieldControl( Window* pParent, const ResId& rResId )
387 : : : Control( pParent, rResId )
388 : : , meMode( DefaultMode )
389 : : , mdX( -1.0 )
390 : : , mdY( -1.0 )
391 : : , mpBitmap( 0 )
392 [ # # ][ # # ]: 0 : , mbInit( false )
[ # # ][ # # ]
[ # # ][ # # ]
393 : : {
394 [ # # ]: 0 : SetControlBackground();
395 : 0 : }
396 : :
397 : : // -----------------------------------------------------------------------
398 : :
399 : 0 : ColorFieldControl::~ColorFieldControl()
400 : : {
401 [ # # ][ # # ]: 0 : delete mpBitmap;
402 [ # # ]: 0 : }
403 : :
404 : : // -----------------------------------------------------------------------
405 : :
406 : 0 : void ColorFieldControl::UpdateBitmap()
407 : : {
408 : 0 : const Size aSize( GetOutputSizePixel() );
409 : :
410 [ # # ][ # # ]: 0 : if( mpBitmap && mpBitmap->GetSizePixel() != aSize )
[ # # ]
[ # # # # ]
[ # # ]
411 [ # # ][ # # ]: 0 : delete mpBitmap, mpBitmap = NULL;
412 : :
413 : 0 : const sal_Int32 nWidth = aSize.Width();
414 : 0 : const sal_Int32 nHeight = aSize.Height();
415 : :
416 [ # # ]: 0 : if( !mpBitmap )
417 : : {
418 [ # # ][ # # ]: 0 : mpBitmap = new Bitmap( aSize, 24 );
419 : :
420 [ # # ]: 0 : maRGB_Horiz.resize( nWidth );
421 [ # # ]: 0 : maGrad_Horiz.resize( nWidth );
422 [ # # ]: 0 : maPercent_Horiz.resize( nWidth );
423 : :
424 [ # # ]: 0 : sal_uInt8* pRGB = &(*maRGB_Horiz.begin());
425 [ # # ]: 0 : sal_uInt16* pGrad = &(*maGrad_Horiz.begin());
426 [ # # ]: 0 : sal_uInt16* pPercent = &(*maPercent_Horiz.begin());
427 : :
428 [ # # ]: 0 : for( sal_Int32 x = 0; x < nWidth; x++ )
429 : : {
430 : 0 : *pRGB++ = static_cast< sal_uInt8 >( (x * 256) / nWidth );
431 : 0 : *pGrad++ = static_cast< sal_uInt16 >( (x * 359) / nWidth );
432 : 0 : *pPercent++ = static_cast< sal_uInt16 >( (x * 100) / nWidth );
433 : : }
434 : :
435 [ # # ]: 0 : maRGB_Vert.resize( nHeight );
436 [ # # ]: 0 : maPercent_Vert.resize( nHeight );
437 : :
438 [ # # ]: 0 : pRGB = &(*maRGB_Vert.begin());
439 [ # # ]: 0 : pPercent = &(*maPercent_Vert.begin());
440 : :
441 : 0 : sal_Int32 y = nHeight;
442 [ # # ]: 0 : while( y-- )
443 : : {
444 : 0 : *pRGB++ = static_cast< sal_uInt8 >( (y * 256) / nHeight );
445 : 0 : *pPercent++ = static_cast< sal_uInt16 >( (y * 100) / nHeight );
446 : : }
447 : : }
448 : :
449 [ # # ]: 0 : sal_uInt8* pRGB_Horiz = &(*maRGB_Horiz.begin());
450 [ # # ]: 0 : sal_uInt16* pGrad_Horiz = &(*maGrad_Horiz.begin());
451 [ # # ]: 0 : sal_uInt16* pPercent_Horiz = &(*maPercent_Horiz.begin());
452 [ # # ]: 0 : sal_uInt8* pRGB_Vert = &(*maRGB_Vert.begin());
453 [ # # ]: 0 : sal_uInt16* pPercent_Vert = &(*maPercent_Vert.begin());
454 : :
455 [ # # ]: 0 : BitmapWriteAccess* pWriteAccess = mpBitmap->AcquireWriteAccess();
456 [ # # ]: 0 : if( pWriteAccess )
457 : : {
458 : 0 : BitmapColor aBitmapColor( maColor );
459 : :
460 : : sal_uInt16 nHue, nSat, nBri;
461 [ # # ]: 0 : maColor.RGBtoHSB( nHue, nSat, nBri );
462 : :
463 : : // this has been unlooped for performance reason, please do not merge back!
464 : :
465 : 0 : sal_uInt16 y = nHeight,x;
466 : :
467 [ # # # # : 0 : switch( meMode )
# # # ]
468 : : {
469 : : case HUE:
470 [ # # ]: 0 : while( y-- )
471 : : {
472 : 0 : nBri = pPercent_Vert[y];
473 : 0 : x = nWidth;
474 [ # # ]: 0 : while( x-- )
475 : : {
476 : 0 : nSat = pPercent_Horiz[x];
477 [ # # ][ # # ]: 0 : pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
478 : : }
479 : : }
480 : 0 : break;
481 : : case SATURATION:
482 [ # # ]: 0 : while( y-- )
483 : : {
484 : 0 : nBri = pPercent_Vert[y];
485 : 0 : x = nWidth;
486 [ # # ]: 0 : while( x-- )
487 : : {
488 : 0 : nHue = pGrad_Horiz[x];
489 [ # # ][ # # ]: 0 : pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
490 : : }
491 : : }
492 : 0 : break;
493 : : case BRIGHTNESS:
494 [ # # ]: 0 : while( y-- )
495 : : {
496 : 0 : nSat = pPercent_Vert[y];
497 : 0 : x = nWidth;
498 [ # # ]: 0 : while( x-- )
499 : : {
500 : 0 : nHue = pGrad_Horiz[x];
501 [ # # ][ # # ]: 0 : pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
502 : : }
503 : : }
504 : 0 : break;
505 : : case RED:
506 [ # # ]: 0 : while( y-- )
507 : : {
508 : 0 : aBitmapColor.SetGreen( pRGB_Vert[y] );
509 : 0 : x = nWidth;
510 [ # # ]: 0 : while( x-- )
511 : : {
512 : 0 : aBitmapColor.SetBlue( pRGB_Horiz[x] );
513 [ # # ]: 0 : pWriteAccess->SetPixel( y, x, aBitmapColor );
514 : : }
515 : : }
516 : 0 : break;
517 : : case GREEN:
518 [ # # ]: 0 : while( y-- )
519 : : {
520 : 0 : aBitmapColor.SetRed( pRGB_Vert[y] );
521 : 0 : x = nWidth;
522 [ # # ]: 0 : while( x-- )
523 : : {
524 : 0 : aBitmapColor.SetBlue( pRGB_Horiz[x] );
525 [ # # ]: 0 : pWriteAccess->SetPixel( y, x, aBitmapColor );
526 : : }
527 : : }
528 : 0 : break;
529 : : case BLUE:
530 [ # # ]: 0 : while( y-- )
531 : : {
532 : 0 : aBitmapColor.SetGreen( pRGB_Vert[y] );
533 : 0 : x = nWidth;
534 [ # # ]: 0 : while( x-- )
535 : : {
536 : 0 : aBitmapColor.SetRed( pRGB_Horiz[x] );
537 [ # # ]: 0 : pWriteAccess->SetPixel( y, x, aBitmapColor );
538 : : }
539 : : }
540 : 0 : break;
541 : : }
542 : :
543 [ # # ]: 0 : mpBitmap->ReleaseAccess( pWriteAccess );
544 : : }
545 : 0 : }
546 : :
547 : : // -----------------------------------------------------------------------
548 : :
549 : 0 : void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate )
550 : : {
551 [ # # ]: 0 : if( !mpBitmap )
552 : : {
553 [ # # ]: 0 : UpdateBitmap();
554 [ # # ]: 0 : Invalidate();
555 : : }
556 : :
557 [ # # ]: 0 : const Size aSize( mpBitmap->GetSizePixel() );
558 : :
559 : 0 : long nX = rPos.X();
560 : 0 : long nY = rPos.Y();
561 [ # # ]: 0 : if( nX < 0L )
562 : 0 : nX = 0L;
563 [ # # ]: 0 : else if( nX >= aSize.Width() )
564 : 0 : nX = aSize.Width() - 1L;
565 : :
566 [ # # ]: 0 : if( nY < 0L )
567 : 0 : nY= 0L;
568 [ # # ]: 0 : else if( nY >= aSize.Height() )
569 : 0 : nY = aSize.Height() - 1L;
570 : :
571 : 0 : Point aPos = maPosition;
572 : 0 : maPosition.X() = nX - 5;
573 : 0 : maPosition.Y() = nY - 5;
574 [ # # ][ # # ]: 0 : Invalidate( Rectangle( aPos, Size( 11, 11) ) );
575 [ # # ][ # # ]: 0 : Invalidate( Rectangle( maPosition, Size( 11, 11) ) );
576 : :
577 [ # # ]: 0 : if( bUpdate )
578 : : {
579 : 0 : mdX = (double)nX / (double)(aSize.Width()-1);
580 : 0 : mdY = (double)(aSize.Height()-1-nY) / (double)(aSize.Height()-1);
581 : :
582 [ # # ]: 0 : BitmapReadAccess* pReadAccess = mpBitmap->AcquireReadAccess();
583 [ # # ]: 0 : if( pReadAccess != NULL )
584 : : {
585 : : // mpBitmap always has a bit count of 24 => use of GetPixel(...) is safe
586 [ # # ][ # # ]: 0 : maColor = pReadAccess->GetPixel( nY, nX );
587 [ # # ]: 0 : mpBitmap->ReleaseAccess( pReadAccess );
588 : 0 : pReadAccess = NULL;
589 : : }
590 : : }
591 : 0 : }
592 : : // -----------------------------------------------------------------------
593 : :
594 : 0 : void ColorFieldControl::MouseMove( const MouseEvent& rMEvt )
595 : : {
596 [ # # ]: 0 : if( rMEvt.IsLeft() )
597 : : {
598 : 0 : ShowPosition( rMEvt.GetPosPixel(), true );
599 : 0 : Modify();
600 : : }
601 : 0 : }
602 : :
603 : : // -----------------------------------------------------------------------
604 : 0 : void ColorFieldControl::MouseButtonDown( const MouseEvent& rMEvt )
605 : : {
606 [ # # ][ # # ]: 0 : if( rMEvt.IsLeft() && !rMEvt.IsShift() )
[ # # ]
607 : : {
608 : 0 : CaptureMouse();
609 : 0 : ShowPosition( rMEvt.GetPosPixel(), true );
610 : 0 : Modify();
611 : : }
612 : 0 : }
613 : :
614 : : // -----------------------------------------------------------------------
615 : 0 : void ColorFieldControl::MouseButtonUp( const MouseEvent& )
616 : : {
617 [ # # ]: 0 : if( IsMouseCaptured() )
618 : 0 : ReleaseMouse();
619 : 0 : }
620 : :
621 : : // -----------------------------------------------------------------------
622 : :
623 : 0 : void ColorFieldControl::KeyMove( int dx, int dy )
624 : : {
625 : 0 : Size aSize( GetOutputSizePixel() );
626 : 0 : Point aPos(static_cast<long>(mdX * aSize.Width()), static_cast<long>((1.0 - mdY) * aSize.Height()));
627 : 0 : aPos.X() += dx;
628 : 0 : aPos.Y() += dy;
629 [ # # ]: 0 : if( aPos.X() < 0 )
630 : 0 : aPos.X() += aSize.Width();
631 [ # # ]: 0 : else if( aPos.X() >= aSize.Width() )
632 : 0 : aPos.X() -= aSize.Width();
633 : :
634 [ # # ]: 0 : if( aPos.Y() < 0 )
635 : 0 : aPos.Y() += aSize.Height();
636 [ # # ]: 0 : else if( aPos.Y() >= aSize.Height() )
637 : 0 : aPos.Y() -= aSize.Height();
638 : :
639 [ # # ]: 0 : ShowPosition( aPos, true );
640 [ # # ]: 0 : Modify();
641 : 0 : }
642 : :
643 : : // -----------------------------------------------------------------------
644 : :
645 : 0 : void ColorFieldControl::KeyInput( const KeyEvent& rKEvt )
646 : : {
647 : 0 : bool bShift = rKEvt.GetKeyCode().IsShift();
648 : 0 : bool bCtrl = rKEvt.GetKeyCode().IsMod1();
649 : 0 : bool bAlt = rKEvt.GetKeyCode().IsMod2();
650 : :
651 [ # # ][ # # ]: 0 : if ( !bAlt && !bShift )
652 : : {
653 [ # # # # : 0 : switch( rKEvt.GetKeyCode().GetCode() )
# ]
654 : : {
655 [ # # ]: 0 : case KEY_DOWN: KeyMove( 0, bCtrl ? 5 : 1 ); return;
656 [ # # ]: 0 : case KEY_UP: KeyMove( 0, bCtrl ? -5 : -1 ); return;
657 [ # # ]: 0 : case KEY_LEFT: KeyMove( bCtrl ? -5 : -1, 0 ); return;
658 [ # # ]: 0 : case KEY_RIGHT: KeyMove( bCtrl ? 5 : 1, 0 ); return;
659 : : }
660 : : }
661 : 0 : Control::KeyInput( rKEvt );
662 : : }
663 : :
664 : : // -----------------------------------------------------------------------
665 : :
666 : 0 : void ColorFieldControl::Paint( const Rectangle& rRect )
667 : : {
668 [ # # ]: 0 : if( !mpBitmap )
669 [ # # ]: 0 : UpdateBitmap();
670 : :
671 [ # # ]: 0 : Bitmap aOutputBitmap( *mpBitmap );
672 : :
673 [ # # ][ # # ]: 0 : if( GetBitCount() <= 8 )
674 [ # # ]: 0 : aOutputBitmap.Dither();
675 : :
676 [ # # ][ # # ]: 0 : DrawBitmap( rRect.TopLeft(), rRect.GetSize(), rRect.TopLeft(), rRect.GetSize(), aOutputBitmap );
[ # # ]
677 : :
678 : : // draw circle around current color
679 [ # # ][ # # ]: 0 : if( maColor.IsDark() )
680 [ # # ]: 0 : SetLineColor( COL_WHITE );
681 : : else
682 [ # # ]: 0 : SetLineColor( COL_BLACK );
683 : :
684 [ # # ]: 0 : SetFillColor();
685 : :
686 [ # # ][ # # ]: 0 : DrawEllipse( Rectangle( maPosition, Size( 11, 11) ) );
[ # # ]
687 : 0 : }
688 : :
689 : : // -----------------------------------------------------------------------
690 : :
691 : 0 : void ColorFieldControl::Resize()
692 : : {
693 : 0 : UpdateBitmap();
694 : 0 : Control::Resize();
695 : 0 : }
696 : :
697 : : // -----------------------------------------------------------------------
698 : :
699 : 0 : void ColorFieldControl::Modify()
700 : : {
701 : 0 : maModifyHdl.Call( this );
702 : 0 : }
703 : :
704 : : // -----------------------------------------------------------------------
705 : :
706 : 0 : void ColorFieldControl::SetValues( Color aColor, ColorMode eMode, double x, double y )
707 : : {
708 [ # # ][ # # ]: 0 : bool bUpdateBitmap = (maColor!= aColor) || (meMode != eMode);
709 [ # # ][ # # ]: 0 : if( bUpdateBitmap || (mdX != x) || (mdY != y) )
[ # # ]
710 : : {
711 : 0 : maColor = aColor;
712 : 0 : meMode = eMode;
713 : 0 : mdX = x;
714 : 0 : mdY = y;
715 : :
716 [ # # ]: 0 : if( bUpdateBitmap )
717 : 0 : UpdateBitmap();
718 : 0 : UpdatePosition();
719 [ # # ]: 0 : if( bUpdateBitmap )
720 : 0 : Invalidate();
721 : : }
722 : 0 : }
723 : :
724 : : // -----------------------------------------------------------------------
725 : :
726 : 0 : double ColorFieldControl::GetX()
727 : : {
728 : 0 : return mdX;
729 : : }
730 : :
731 : : // -----------------------------------------------------------------------
732 : :
733 : 0 : double ColorFieldControl::GetY()
734 : : {
735 : 0 : return mdY;
736 : : }
737 : :
738 : : // -----------------------------------------------------------------------
739 : :
740 : 0 : void ColorFieldControl::UpdatePosition()
741 : : {
742 : 0 : Size aSize( GetOutputSizePixel() );
743 [ # # ]: 0 : ShowPosition( Point(static_cast<long>(mdX * aSize.Width()), static_cast<long>((1.0 - mdY) * aSize.Height())), false );
744 : 0 : }
745 : :
746 : : // ====================================================================
747 : :
748 : : class ColorSliderControl : public Control
749 : : {
750 : : public:
751 : : ColorSliderControl( Window* pParent, const ResId& rResId );
752 : : ~ColorSliderControl();
753 : :
754 : : virtual void MouseMove( const MouseEvent& rMEvt );
755 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
756 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
757 : : virtual void KeyInput( const KeyEvent& rKEvt );
758 : : virtual void Paint( const Rectangle& rRect );
759 : : virtual void Resize();
760 : :
761 : : void UpdateBitmap();
762 : : void ChangePosition( long nY );
763 : : void Modify();
764 : :
765 : : void SetValue( const Color& rColor, ColorMode eMode, double dValue );
766 : 0 : double GetValue() const { return mdValue; }
767 : :
768 : : void KeyMove( int dy );
769 : :
770 : 0 : void SetModifyHdl( Link& rLink ) { maModifyHdl = rLink; }
771 : :
772 : 0 : sal_Int16 GetLevel() const { return mnLevel; }
773 : :
774 : : private:
775 : : Link maModifyHdl;
776 : : Color maColor;
777 : : ColorMode meMode;
778 : : Bitmap* mpBitmap;
779 : : sal_Int16 mnLevel;
780 : : double mdValue;
781 : : };
782 : :
783 : : // -----------------------------------------------------------------------
784 : :
785 : 0 : ColorSliderControl::ColorSliderControl( Window* pParent, const ResId& rResId )
786 : : : Control( pParent, rResId )
787 : : , meMode( DefaultMode )
788 : : , mpBitmap( 0 )
789 : : , mnLevel( 0 )
790 [ # # ]: 0 : , mdValue( -1.0 )
791 : : {
792 [ # # ]: 0 : SetControlBackground();
793 : 0 : }
794 : :
795 : : // -----------------------------------------------------------------------
796 : :
797 : 0 : ColorSliderControl::~ColorSliderControl()
798 : : {
799 [ # # ][ # # ]: 0 : delete mpBitmap;
800 [ # # ]: 0 : }
801 : :
802 : : // -----------------------------------------------------------------------
803 : :
804 : 0 : void ColorSliderControl::UpdateBitmap()
805 : : {
806 : 0 : Size aSize( 1, GetOutputSizePixel().Height() );
807 : :
808 [ # # ][ # # ]: 0 : if( mpBitmap && mpBitmap->GetSizePixel() != aSize )
[ # # ]
[ # # # # ]
[ # # ]
809 [ # # ][ # # ]: 0 : delete mpBitmap, mpBitmap = NULL;
810 : :
811 [ # # ]: 0 : if( !mpBitmap )
812 [ # # ][ # # ]: 0 : mpBitmap = new Bitmap( aSize, 24 );
813 : :
814 [ # # ]: 0 : BitmapWriteAccess* pWriteAccess = mpBitmap->AcquireWriteAccess();
815 : :
816 [ # # ]: 0 : if( pWriteAccess )
817 : : {
818 : 0 : const long nY = aSize.Height()-1;
819 : :
820 : 0 : BitmapColor aBitmapColor( maColor );
821 : :
822 : : sal_uInt16 nHue, nSat, nBri;
823 [ # # ]: 0 : maColor.RGBtoHSB( nHue, nSat, nBri );
824 : :
825 : : // this has been unlooped for performance reason, please do not merge back!
826 : :
827 [ # # # # : 0 : switch( meMode )
# # # ]
828 : : {
829 : : case HUE:
830 : 0 : nSat = 100;
831 : 0 : nBri = 100;
832 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
833 : : {
834 : 0 : nHue = static_cast< sal_uInt16 >( (359 * y) / nY );
835 [ # # ]: 0 : aBitmapColor = BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) );
836 [ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
837 : : }
838 : 0 : break;
839 : :
840 : : case SATURATION:
841 [ # # ]: 0 : nBri = std::max( (sal_uInt16)32, nBri );
842 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
843 : : {
844 : 0 : nSat = static_cast< sal_uInt16 >( (100 * y) / nY );
845 [ # # ][ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
846 : : }
847 : 0 : break;
848 : :
849 : : case BRIGHTNESS:
850 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
851 : : {
852 : 0 : nBri = static_cast< sal_uInt16 >( (100 * y) / nY );
853 [ # # ][ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
854 : : }
855 : 0 : break;
856 : :
857 : : case RED:
858 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
859 : : {
860 : 0 : aBitmapColor.SetRed( sal_uInt8( ((long)255 * y) / nY ) );
861 [ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
862 : : }
863 : 0 : break;
864 : :
865 : : case GREEN:
866 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
867 : : {
868 : 0 : aBitmapColor.SetGreen( sal_uInt8( ((long)255 * y) / nY ) );
869 [ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
870 : : }
871 : 0 : break;
872 : :
873 : : case BLUE:
874 [ # # ]: 0 : for( long y = 0; y <= nY; y++ )
875 : : {
876 : 0 : aBitmapColor.SetBlue( sal_uInt8( ((long)255 * y) / nY ) );
877 [ # # ]: 0 : pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
878 : : }
879 : 0 : break;
880 : : }
881 : :
882 [ # # ]: 0 : mpBitmap->ReleaseAccess( pWriteAccess );
883 : : }
884 : 0 : }
885 : :
886 : : // -----------------------------------------------------------------------
887 : :
888 : 0 : void ColorSliderControl::ChangePosition( long nY )
889 : : {
890 : 0 : const long nHeight = GetOutputSizePixel().Height() - 1;
891 : :
892 [ # # ]: 0 : if( nY < 0L )
893 : 0 : nY = 0;
894 [ # # ]: 0 : else if( nY > nHeight )
895 : 0 : nY = nHeight;
896 : :
897 : 0 : mnLevel = nY;
898 : 0 : mdValue = ((double)(nHeight - nY)) / (double)nHeight;
899 : 0 : }
900 : :
901 : : // -----------------------------------------------------------------------
902 : :
903 : 0 : void ColorSliderControl::MouseMove( const MouseEvent& rMEvt )
904 : : {
905 [ # # ]: 0 : if( rMEvt.IsLeft() )
906 : : {
907 : 0 : ChangePosition( rMEvt.GetPosPixel().Y() );
908 : 0 : Modify();
909 : : }
910 : 0 : }
911 : :
912 : : // -----------------------------------------------------------------------
913 : 0 : void ColorSliderControl::MouseButtonDown( const MouseEvent& rMEvt )
914 : : {
915 [ # # ][ # # ]: 0 : if( rMEvt.IsLeft() && !rMEvt.IsShift() )
[ # # ]
916 : : {
917 : 0 : CaptureMouse();
918 : 0 : ChangePosition( rMEvt.GetPosPixel().Y() );
919 : 0 : Modify();
920 : : }
921 : 0 : }
922 : :
923 : : // -----------------------------------------------------------------------
924 : 0 : void ColorSliderControl::MouseButtonUp( const MouseEvent& )
925 : : {
926 [ # # ]: 0 : if( IsMouseCaptured() )
927 : 0 : ReleaseMouse();
928 : 0 : }
929 : :
930 : : // -----------------------------------------------------------------------
931 : :
932 : 0 : void ColorSliderControl::KeyMove( int dy )
933 : : {
934 : 0 : ChangePosition( mnLevel + dy );
935 : 0 : Modify();
936 : 0 : }
937 : :
938 : : // -----------------------------------------------------------------------
939 : :
940 : 0 : void ColorSliderControl::KeyInput( const KeyEvent& rKEvt )
941 : : {
942 [ # # ][ # # ]: 0 : if ( !rKEvt.GetKeyCode().IsMod2() && !rKEvt.GetKeyCode().IsShift() )
[ # # ]
943 : : {
944 [ # # # ]: 0 : switch( rKEvt.GetKeyCode().GetCode() )
945 : : {
946 [ # # ]: 0 : case KEY_DOWN: KeyMove( rKEvt.GetKeyCode().IsMod1() ? 5 : 1 ); return;
947 [ # # ]: 0 : case KEY_UP: KeyMove( rKEvt.GetKeyCode().IsMod1() ? -5 : -1 ); return;
948 : : }
949 : : }
950 : :
951 : 0 : Control::KeyInput( rKEvt );
952 : : }
953 : : // -----------------------------------------------------------------------
954 : :
955 : 0 : void ColorSliderControl::Paint( const Rectangle& /*rRect*/ )
956 : : {
957 [ # # ]: 0 : if( !mpBitmap )
958 [ # # ]: 0 : UpdateBitmap();
959 : :
960 : 0 : const Size aSize( GetOutputSizePixel() );
961 : :
962 [ # # ]: 0 : Bitmap aOutputBitmap( *mpBitmap );
963 : :
964 [ # # ][ # # ]: 0 : if( GetBitCount() <= 8 )
965 [ # # ]: 0 : aOutputBitmap.Dither();
966 : :
967 : 0 : Point aPos;
968 : 0 : int x = aSize.Width();
969 [ # # ]: 0 : while( x-- )
970 : : {
971 [ # # ]: 0 : DrawBitmap( aPos, aOutputBitmap );
972 : 0 : aPos.X() += 1;
973 [ # # ]: 0 : }
974 : 0 : }
975 : :
976 : : // -----------------------------------------------------------------------
977 : :
978 : 0 : void ColorSliderControl::Resize()
979 : : {
980 : 0 : UpdateBitmap();
981 : 0 : Control::Resize();
982 : 0 : }
983 : :
984 : : // -----------------------------------------------------------------------
985 : :
986 : 0 : void ColorSliderControl::Modify()
987 : : {
988 : 0 : maModifyHdl.Call( this );
989 : 0 : }
990 : :
991 : : // -----------------------------------------------------------------------
992 : :
993 : 0 : void ColorSliderControl::SetValue( const Color& rColor, ColorMode eMode, double dValue )
994 : : {
995 [ # # ][ # # ]: 0 : bool bUpdateBitmap = (rColor != maColor) || (eMode != meMode);
996 [ # # ][ # # ]: 0 : if( bUpdateBitmap || (mdValue != dValue))
997 : : {
998 : 0 : maColor = rColor;
999 : 0 : mdValue = dValue;
1000 : 0 : mnLevel = static_cast<sal_Int16>((1.0-dValue) * GetOutputSizePixel().Height());
1001 : 0 : meMode = eMode;
1002 [ # # ]: 0 : if( bUpdateBitmap )
1003 : 0 : UpdateBitmap();
1004 : 0 : Invalidate();
1005 : : }
1006 : 0 : }
1007 : :
1008 : : // ====================================================================
1009 : :
1010 : : const sal_uInt16 UPDATE_RGB = 0x01;
1011 : : const sal_uInt16 UPDATE_CMYK = 0x02;
1012 : : const sal_uInt16 UPDATE_HSB = 0x04;
1013 : : const sal_uInt16 UPDATE_COLORCHOOSER = 0x08;
1014 : : const sal_uInt16 UPDATE_COLORSLIDER = 0x10;
1015 : : const sal_uInt16 UPDATE_HEX = 0x20;
1016 : : const sal_uInt16 UPDATE_ALL = 0xff;
1017 : :
1018 [ # # ][ # # ]: 0 : class ColorPickerDialog : public ModalDialog
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1019 : : {
1020 : : public:
1021 : : ColorPickerDialog( Window* pParent, sal_Int32 nColor, sal_Int16 nMode );
1022 : :
1023 : : void update_color( sal_uInt16 n = UPDATE_ALL );
1024 : :
1025 : : DECL_LINK( ColorModifyHdl, void * );
1026 : : DECL_LINK( ModeModifyHdl, void * );
1027 : :
1028 : : sal_Int32 GetColor() const;
1029 : :
1030 : : void setColorComponent( sal_uInt16 nComp, double dValue );
1031 : :
1032 : : private:
1033 : : Color maPreviousColor;
1034 : : sal_Int16 mnDialogMode;
1035 : : ColorMode meMode;
1036 : :
1037 : : double mdRed, mdGreen, mdBlue;
1038 : : double mdHue, mdSat, mdBri;
1039 : : double mdCyan, mdMagenta, mdYellow, mdKey;
1040 : :
1041 : : private:
1042 : : ColorFieldControl maColorField;
1043 : : ColorSliderControl maColorSlider;
1044 : : ColorPreviewControl maColorPreview;
1045 : : ColorPreviewControl maColorPrevious;
1046 : :
1047 : : FixedImage maFISliderLeft;
1048 : : FixedImage maFISliderRight;
1049 : : Image maSliderImage;
1050 : :
1051 : : #if 0
1052 : : ImageButton maBtnPicker;
1053 : : #endif
1054 : :
1055 : : FixedLine maFLRGB;
1056 : :
1057 : : RadioButton maRBRed;
1058 : : RadioButton maRBGreen;
1059 : : RadioButton maRBBlue;
1060 : : RadioButton maRBHue;
1061 : : RadioButton maRBSaturation;
1062 : : RadioButton maRBBrightness;
1063 : :
1064 : : FixedText maFTRed;
1065 : : MetricField maMFRed;
1066 : : FixedText maFTGreen;
1067 : : MetricField maMFGreen;
1068 : : FixedText maFTBlue;
1069 : : MetricField maMFBlue;
1070 : : FixedText maFTHex;
1071 : : HexColorControl maEDHex;
1072 : :
1073 : : FixedLine maFLHSB;
1074 : : FixedText maFTHue;
1075 : : MetricField maMFHue;
1076 : : FixedText maFTSaturation;
1077 : : MetricField maMFSaturation;
1078 : : FixedText maFTBrightness;
1079 : : MetricField maMFBrightness;
1080 : :
1081 : : FixedLine maFLCMYK;
1082 : : FixedText maFTCyan;
1083 : : MetricField maMFCyan;
1084 : : FixedText maFTMagenta;
1085 : : MetricField maMFMagenta;
1086 : : FixedText maFTYellow;
1087 : : MetricField maMFYellow;
1088 : : FixedText maFTKey;
1089 : : MetricField maMFKey;
1090 : :
1091 : : FixedLine maFLBottmLine;
1092 : : HelpButton maBTNHelp;
1093 : : OKButton maBTNOk;
1094 : : CancelButton maBTNCancel;
1095 : : };
1096 : :
1097 : : // --------------------------------------------------------------------
1098 : :
1099 : 0 : ColorPickerDialog::ColorPickerDialog( Window* pParent, sal_Int32 nColor, sal_Int16 nMode )
1100 : 0 : : ModalDialog( pParent, CUI_RES( RID_CUI_DIALOG_COLORPICKER ) )
1101 : : , maPreviousColor( nColor )
1102 : : , mnDialogMode( nMode )
1103 : : , meMode( DefaultMode )
1104 [ # # ]: 0 : , maColorField( this, CUI_RES( CT_COLORFIELD ) )
1105 [ # # ]: 0 : , maColorSlider( this, CUI_RES( CT_COLORSLIDER ) )
1106 [ # # ]: 0 : , maColorPreview( this, CUI_RES( CT_PREVIEW ) )
1107 [ # # ]: 0 : , maColorPrevious( this, CUI_RES( CT_PREVIOUS ) )
1108 [ # # ]: 0 : , maFISliderLeft( this, CUI_RES( CT_LEFT_SLIDER ) )
1109 [ # # ]: 0 : , maFISliderRight( this, CUI_RES( CT_RIGHT_SLIDER ) )
1110 [ # # ]: 0 : , maSliderImage( CUI_RES( CT_SLIDERIMG ) )
1111 : : #if 0
1112 : : , maBtnPicker( this, CUI_RES( PB_PICKER ) )
1113 : : #endif
1114 [ # # ]: 0 : , maFLRGB( this, CUI_RES( FL_RGB ) )
1115 [ # # ]: 0 : , maRBRed( this, CUI_RES( CT_RED ) )
1116 [ # # ]: 0 : , maRBGreen( this, CUI_RES( CT_GREEN ) )
1117 [ # # ]: 0 : , maRBBlue( this, CUI_RES( CT_BLUE ) )
1118 [ # # ]: 0 : , maRBHue( this, CUI_RES( CT_HUE ) )
1119 [ # # ]: 0 : , maRBSaturation( this, CUI_RES( CT_SATURATION ) )
1120 [ # # ]: 0 : , maRBBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
1121 [ # # ]: 0 : , maFTRed( this, CUI_RES( CT_RED ) )
1122 [ # # ]: 0 : , maMFRed( this, CUI_RES( CT_RED ) )
1123 [ # # ]: 0 : , maFTGreen( this, CUI_RES( CT_GREEN ) )
1124 [ # # ]: 0 : , maMFGreen( this, CUI_RES( CT_GREEN ) )
1125 [ # # ]: 0 : , maFTBlue( this, CUI_RES( CT_BLUE ) )
1126 [ # # ]: 0 : , maMFBlue( this, CUI_RES( CT_BLUE ) )
1127 [ # # ]: 0 : , maFTHex( this, CUI_RES( CT_HEX ) )
1128 [ # # ]: 0 : , maEDHex( this, CUI_RES( CT_HEX ) )
1129 [ # # ]: 0 : , maFLHSB( this, CUI_RES( FL_HSB ) )
1130 [ # # ]: 0 : , maFTHue( this, CUI_RES( CT_HUE ) )
1131 [ # # ]: 0 : , maMFHue( this, CUI_RES( CT_HUE ) )
1132 [ # # ]: 0 : , maFTSaturation( this, CUI_RES( CT_SATURATION ) )
1133 [ # # ]: 0 : , maMFSaturation( this, CUI_RES( CT_SATURATION ) )
1134 [ # # ]: 0 : , maFTBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
1135 [ # # ]: 0 : , maMFBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
1136 [ # # ]: 0 : , maFLCMYK( this, CUI_RES( FL_CMYK ) )
1137 [ # # ]: 0 : , maFTCyan( this, CUI_RES( CT_CYAN ) )
1138 [ # # ]: 0 : , maMFCyan( this, CUI_RES( CT_CYAN ) )
1139 [ # # ]: 0 : , maFTMagenta( this, CUI_RES( CT_MAGENTA ) )
1140 [ # # ]: 0 : , maMFMagenta( this, CUI_RES( CT_MAGENTA ) )
1141 [ # # ]: 0 : , maFTYellow( this, CUI_RES( CT_YELLOW ) )
1142 [ # # ]: 0 : , maMFYellow( this, CUI_RES( CT_YELLOW ) )
1143 [ # # ]: 0 : , maFTKey( this, CUI_RES( CT_KEY ) )
1144 [ # # ]: 0 : , maMFKey( this, CUI_RES( CT_KEY ) )
1145 : :
1146 [ # # ]: 0 : , maFLBottmLine( this, CUI_RES( FT_BOTTOMLINE ) )
1147 [ # # ]: 0 : , maBTNHelp( this, CUI_RES( BTN_HELP ) )
1148 [ # # ]: 0 : , maBTNOk( this, CUI_RES( BTN_OK ) )
1149 [ # # ][ # # ]: 0 : , maBTNCancel( this, CUI_RES( BTN_CANCEL ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1150 : : {
1151 [ # # ]: 0 : FreeResource();
1152 : :
1153 [ # # ]: 0 : Link aLink( LINK( this, ColorPickerDialog, ColorModifyHdl ) );
1154 : 0 : maColorField.SetModifyHdl( aLink );
1155 : 0 : maColorSlider.SetModifyHdl( aLink );
1156 : :
1157 : 0 : maMFRed.SetModifyHdl( aLink );
1158 : 0 : maMFGreen.SetModifyHdl( aLink );
1159 : 0 : maMFBlue.SetModifyHdl( aLink );
1160 : :
1161 : 0 : maMFCyan.SetModifyHdl( aLink );
1162 : 0 : maMFMagenta.SetModifyHdl( aLink );
1163 : 0 : maMFYellow.SetModifyHdl( aLink );
1164 : 0 : maMFKey.SetModifyHdl( aLink );
1165 : :
1166 : 0 : maMFHue.SetModifyHdl( aLink );
1167 : 0 : maMFSaturation.SetModifyHdl( aLink );
1168 : 0 : maMFBrightness.SetModifyHdl( aLink );
1169 : :
1170 : 0 : maEDHex.SetModifyHdl( aLink );
1171 : :
1172 [ # # ]: 0 : aLink = LINK( this, ColorPickerDialog, ModeModifyHdl );
1173 : 0 : maRBRed.SetToggleHdl( aLink );
1174 : 0 : maRBGreen.SetToggleHdl( aLink );
1175 : 0 : maRBBlue.SetToggleHdl( aLink );
1176 : 0 : maRBHue.SetToggleHdl( aLink );
1177 : 0 : maRBSaturation.SetToggleHdl( aLink );
1178 : 0 : maRBBrightness.SetToggleHdl( aLink );
1179 : :
1180 [ # # ]: 0 : Image aSliderImage( maSliderImage );
1181 : :
1182 [ # # ]: 0 : maFISliderLeft.SetImage( aSliderImage );
1183 : :
1184 [ # # ]: 0 : BitmapEx aTmpBmp( maSliderImage.GetBitmapEx() );
1185 [ # # ]: 0 : aTmpBmp.Mirror( BMP_MIRROR_HORZ );
1186 [ # # ][ # # ]: 0 : maFISliderRight.SetImage( Image( aTmpBmp ) );
[ # # ]
1187 : :
1188 [ # # ]: 0 : Size aSize( maSliderImage.GetSizePixel() );
1189 [ # # ]: 0 : maFISliderLeft.SetSizePixel( aSize );
1190 [ # # ]: 0 : maFISliderRight.SetSizePixel( aSize );
1191 : :
1192 [ # # ]: 0 : Point aPos( maColorSlider.GetPosPixel() );
1193 : :
1194 : 0 : aPos.X() -= aSize.Width();
1195 : 0 : aPos.Y() -= aSize.Height() / 2;
1196 [ # # ]: 0 : maFISliderLeft.SetPosPixel( aPos );
1197 : :
1198 [ # # ]: 0 : aPos.X() += aSize.Width() + maColorSlider.GetSizePixel().Width();
1199 [ # # ]: 0 : maFISliderRight.SetPosPixel( aPos );
1200 : :
1201 : 0 : Color aColor( nColor );
1202 : :
1203 : : // modify
1204 [ # # ]: 0 : if( mnDialogMode == 2 )
1205 : : {
1206 [ # # ][ # # ]: 0 : maColorPreview.SetSizePixel( maColorPrevious.GetSizePixel() );
1207 [ # # ]: 0 : maColorPrevious.SetColor( aColor );
1208 [ # # ]: 0 : maColorPrevious.Show( true );
1209 : : }
1210 : :
1211 : 0 : mdRed = ((double)aColor.GetRed()) / 255.0;
1212 : 0 : mdGreen = ((double)aColor.GetGreen()) / 255.0;
1213 : 0 : mdBlue = ((double)aColor.GetBlue()) / 255.0;
1214 : :
1215 [ # # ]: 0 : RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
1216 : 0 : RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
1217 : :
1218 [ # # ][ # # ]: 0 : update_color();
[ # # ]
1219 : 0 : }
1220 : :
1221 : : // --------------------------------------------------------------------
1222 : :
1223 : 0 : static int toInt( double dValue, double dRange )
1224 : : {
1225 : 0 : return static_cast< int >( std::floor((dValue * dRange) + 0.5 ) );
1226 : : }
1227 : :
1228 : 0 : sal_Int32 ColorPickerDialog::GetColor() const
1229 : : {
1230 : 0 : return Color( toInt(mdRed,255.0), toInt(mdGreen,255.0), toInt(mdBlue,255.0) ).GetColor();
1231 : : }
1232 : :
1233 : 0 : void ColorPickerDialog::update_color( sal_uInt16 n )
1234 : : {
1235 : 0 : sal_uInt8 nRed = toInt(mdRed,255.0);
1236 : 0 : sal_uInt8 nGreen = toInt(mdGreen,255.0);
1237 : 0 : sal_uInt8 nBlue = toInt(mdBlue,255.0);
1238 : :
1239 : 0 : Color aColor( nRed, nGreen, nBlue );
1240 : :
1241 [ # # ]: 0 : if( n & UPDATE_RGB ) // update RGB
1242 : : {
1243 [ # # ]: 0 : maMFRed.SetValue( nRed );
1244 [ # # ]: 0 : maMFGreen.SetValue( nGreen );
1245 [ # # ]: 0 : maMFBlue.SetValue( nBlue );
1246 : : }
1247 : :
1248 [ # # ]: 0 : if( n & UPDATE_CMYK ) // update CMYK
1249 : : {
1250 [ # # ]: 0 : maMFCyan.SetValue( toInt( mdCyan, 100.0 ) );
1251 [ # # ]: 0 : maMFMagenta.SetValue( toInt( mdMagenta, 100.0 ) );
1252 [ # # ]: 0 : maMFYellow.SetValue( toInt( mdYellow, 100.0 ) );
1253 [ # # ]: 0 : maMFKey.SetValue( toInt( mdKey, 100.0 ) );
1254 : : }
1255 : :
1256 [ # # ]: 0 : if( n & UPDATE_HSB ) // update HSB
1257 : : {
1258 [ # # ]: 0 : maMFHue.SetValue( toInt( mdHue, 1.0 ) );
1259 [ # # ]: 0 : maMFSaturation.SetValue( toInt( mdSat, 100.0 ) );
1260 [ # # ]: 0 : maMFBrightness.SetValue( toInt( mdBri, 100.0 ) );
1261 : : }
1262 : :
1263 [ # # ]: 0 : if( n & UPDATE_COLORCHOOSER ) // update Color Chooser 1
1264 : : {
1265 [ # # # # : 0 : switch( meMode )
# # # ]
1266 : : {
1267 [ # # ]: 0 : case HUE: maColorField.SetValues( aColor, meMode, mdSat, mdBri ); break;
1268 [ # # ]: 0 : case SATURATION: maColorField.SetValues( aColor, meMode, mdHue / 360.0, mdBri ); break;
1269 [ # # ]: 0 : case BRIGHTNESS: maColorField.SetValues( aColor, meMode, mdHue / 360.0, mdSat ); break;
1270 [ # # ]: 0 : case RED: maColorField.SetValues( aColor, meMode, mdBlue, mdGreen ); break;
1271 [ # # ]: 0 : case GREEN: maColorField.SetValues( aColor, meMode, mdBlue, mdRed ); break;
1272 [ # # ]: 0 : case BLUE: maColorField.SetValues( aColor, meMode, mdRed, mdGreen ); break;
1273 : : }
1274 : : }
1275 : :
1276 [ # # ]: 0 : if( n & UPDATE_COLORSLIDER ) // update Color Chooser 2
1277 : : {
1278 [ # # # # : 0 : switch( meMode )
# # # ]
1279 : : {
1280 [ # # ]: 0 : case HUE: maColorSlider.SetValue( aColor, meMode, mdHue / 360.0 ); break;
1281 [ # # ]: 0 : case SATURATION: maColorSlider.SetValue( aColor, meMode, mdSat ); break;
1282 [ # # ]: 0 : case BRIGHTNESS: maColorSlider.SetValue( aColor, meMode, mdBri ); break;
1283 [ # # ]: 0 : case RED: maColorSlider.SetValue( aColor, meMode, mdRed ); break;
1284 [ # # ]: 0 : case GREEN: maColorSlider.SetValue( aColor, meMode, mdGreen ); break;
1285 [ # # ]: 0 : case BLUE: maColorSlider.SetValue( aColor, meMode, mdBlue ); break;
1286 : : }
1287 : : }
1288 : :
1289 [ # # ]: 0 : if( n & UPDATE_HEX ) // update hex
1290 : : {
1291 [ # # ]: 0 : maEDHex.SetColor( aColor.GetColor() );
1292 : : }
1293 : :
1294 : : {
1295 [ # # ]: 0 : Point aPos( 0, maColorSlider.GetLevel() + maColorSlider.GetPosPixel().Y() - 1 );
1296 : :
1297 [ # # ]: 0 : aPos.X() = maFISliderLeft.GetPosPixel().X();
1298 [ # # ][ # # ]: 0 : if( aPos != maFISliderLeft.GetPosPixel() )
1299 : : {
1300 [ # # ]: 0 : maFISliderLeft.SetPosPixel( aPos );
1301 : :
1302 [ # # ]: 0 : aPos.X() = maFISliderRight.GetPosPixel().X();
1303 [ # # ]: 0 : maFISliderRight.SetPosPixel( aPos );
1304 : : }
1305 : : }
1306 : :
1307 [ # # ]: 0 : maColorPreview.SetColor( aColor );
1308 : 0 : }
1309 : :
1310 : : // --------------------------------------------------------------------
1311 : :
1312 : 0 : IMPL_LINK( ColorPickerDialog, ColorModifyHdl, void *, p )
1313 : : {
1314 : 0 : sal_uInt16 n = 0;
1315 : :
1316 [ # # ]: 0 : if( p == &maColorField )
1317 : : {
1318 : 0 : double x = maColorField.GetX();
1319 : 0 : double y = maColorField.GetY();
1320 : :
1321 [ # # # # : 0 : switch( meMode )
# # # ]
1322 : : {
1323 : 0 : case HUE: mdSat = x; setColorComponent( COLORCOMP_BRI, y ); break;
1324 : 0 : case SATURATION: mdHue = x * 360.0; setColorComponent( COLORCOMP_BRI, y ); break;
1325 : 0 : case BRIGHTNESS: mdHue = x * 360.0; setColorComponent( COLORCOMP_SAT, y ); break;
1326 : 0 : case RED: mdBlue = x; setColorComponent( COLORCOMP_GREEN, y ); break;
1327 : 0 : case GREEN: mdBlue = x; setColorComponent( COLORCOMP_RED, y ); break;
1328 : 0 : case BLUE: mdRed = x; setColorComponent( COLORCOMP_GREEN, y ); break;
1329 : : }
1330 : :
1331 : 0 : n = UPDATE_ALL&~(UPDATE_COLORCHOOSER);
1332 : : }
1333 [ # # ]: 0 : else if( p == &maColorSlider )
1334 : : {
1335 : 0 : double dValue = maColorSlider.GetValue();
1336 [ # # # # : 0 : switch( meMode )
# # # ]
1337 : : {
1338 : 0 : case HUE: setColorComponent( COLORCOMP_HUE, dValue * 360.0 ); break;
1339 : 0 : case SATURATION: setColorComponent( COLORCOMP_SAT, dValue ); break;
1340 : 0 : case BRIGHTNESS: setColorComponent( COLORCOMP_BRI, dValue ); break;
1341 : 0 : case RED: setColorComponent( COLORCOMP_RED, dValue ); break;
1342 : 0 : case GREEN: setColorComponent( COLORCOMP_GREEN, dValue ); break;
1343 : 0 : case BLUE: setColorComponent( COLORCOMP_BLUE, dValue ); break;
1344 : : }
1345 : :
1346 : 0 : n = UPDATE_ALL&~(UPDATE_COLORSLIDER);
1347 : : }
1348 [ # # ]: 0 : else if( p == &maMFRed )
1349 : : {
1350 : 0 : setColorComponent( COLORCOMP_RED, ((double)maMFRed.GetValue()) / 255.0 );
1351 : 0 : n = UPDATE_ALL&~(UPDATE_RGB);
1352 : : }
1353 [ # # ]: 0 : else if( p == &maMFGreen )
1354 : : {
1355 : 0 : setColorComponent( COLORCOMP_GREEN, ((double)maMFGreen.GetValue()) / 255.0 );
1356 : 0 : n = UPDATE_ALL&~(UPDATE_RGB);
1357 : : }
1358 [ # # ]: 0 : else if( p == &maMFBlue )
1359 : : {
1360 : 0 : setColorComponent( COLORCOMP_BLUE, ((double)maMFBlue.GetValue()) / 255.0 );
1361 : 0 : n = UPDATE_ALL&~(UPDATE_RGB);
1362 : : }
1363 [ # # ]: 0 : else if( p == &maMFHue )
1364 : : {
1365 : 0 : setColorComponent( COLORCOMP_HUE, (double)maMFHue.GetValue() );
1366 : 0 : n = UPDATE_ALL&~(UPDATE_HSB);
1367 : : }
1368 [ # # ]: 0 : else if( p == &maMFSaturation )
1369 : : {
1370 : 0 : setColorComponent( COLORCOMP_SAT, ((double)maMFSaturation.GetValue()) / 100.0 );
1371 : 0 : n = UPDATE_ALL&~(UPDATE_HSB);
1372 : : }
1373 [ # # ]: 0 : else if( p == &maMFBrightness )
1374 : : {
1375 : 0 : setColorComponent( COLORCOMP_BRI, ((double)maMFBrightness.GetValue()) / 100.0 );
1376 : 0 : n = UPDATE_ALL&~(UPDATE_HSB);
1377 : : }
1378 [ # # ]: 0 : else if( p == &maMFCyan )
1379 : : {
1380 : 0 : setColorComponent( COLORCOMP_CYAN, ((double)maMFCyan.GetValue()) / 100.0 );
1381 : 0 : n = UPDATE_ALL&~(UPDATE_CMYK);
1382 : : }
1383 [ # # ]: 0 : else if( p == &maMFMagenta )
1384 : : {
1385 : 0 : setColorComponent( COLORCOMP_MAGENTA, ((double)maMFMagenta.GetValue()) / 100.0 );
1386 : 0 : n = UPDATE_ALL&~(UPDATE_CMYK);
1387 : : }
1388 [ # # ]: 0 : else if( p == &maMFYellow )
1389 : : {
1390 : 0 : setColorComponent( COLORCOMP_YELLOW, ((double)maMFYellow.GetValue()) / 100.0 );
1391 : 0 : n = UPDATE_ALL&~(UPDATE_CMYK);
1392 : : }
1393 [ # # ]: 0 : else if( p == &maMFKey )
1394 : : {
1395 : 0 : setColorComponent( COLORCOMP_KEY, ((double)maMFKey.GetValue()) / 100.0 );
1396 : 0 : n = UPDATE_ALL&~(UPDATE_CMYK);
1397 : : }
1398 [ # # ]: 0 : else if( p == &maEDHex )
1399 : : {
1400 : 0 : sal_Int32 nColor = maEDHex.GetColor();
1401 : :
1402 [ # # ]: 0 : if( nColor != -1 )
1403 : : {
1404 : 0 : Color aColor( nColor );
1405 : :
1406 [ # # ]: 0 : if( aColor != GetColor() )
1407 : : {
1408 : 0 : mdRed = ((double)aColor.GetRed()) / 255.0;
1409 : 0 : mdGreen = ((double)aColor.GetRed()) / 255.0;
1410 : 0 : mdBlue = ((double)aColor.GetRed()) / 255.0;
1411 : :
1412 [ # # ]: 0 : RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
1413 : 0 : RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
1414 : 0 : n = UPDATE_ALL&~(UPDATE_HEX);
1415 : : }
1416 : : }
1417 : : }
1418 : :
1419 [ # # ]: 0 : if( n )
1420 : 0 : update_color( n );
1421 : :
1422 : 0 : return 0;
1423 : : }
1424 : :
1425 : : // --------------------------------------------------------------------
1426 : :
1427 : 0 : IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl)
1428 : : {
1429 : 0 : ColorMode eMode = HUE;
1430 : :
1431 [ # # ]: 0 : if( maRBRed.IsChecked() )
1432 : : {
1433 : 0 : eMode = RED;
1434 : : }
1435 [ # # ]: 0 : else if( maRBGreen.IsChecked() )
1436 : : {
1437 : 0 : eMode = GREEN;
1438 : : }
1439 [ # # ]: 0 : else if( maRBBlue.IsChecked() )
1440 : : {
1441 : 0 : eMode = BLUE;
1442 : : }
1443 [ # # ]: 0 : else if( maRBSaturation.IsChecked() )
1444 : : {
1445 : 0 : eMode = SATURATION;
1446 : : }
1447 [ # # ]: 0 : else if( maRBBrightness.IsChecked() )
1448 : : {
1449 : 0 : eMode = BRIGHTNESS;
1450 : : }
1451 : :
1452 [ # # ]: 0 : if( meMode != eMode )
1453 : : {
1454 : 0 : meMode = eMode;
1455 : 0 : update_color( UPDATE_COLORCHOOSER | UPDATE_COLORSLIDER );
1456 : : }
1457 : :
1458 : 0 : return 0;
1459 : : }
1460 : :
1461 : : // --------------------------------------------------------------------
1462 : :
1463 : 0 : void ColorPickerDialog::setColorComponent( sal_uInt16 nComp, double dValue )
1464 : : {
1465 [ # # # # : 0 : switch( nComp )
# # # # #
# # ]
1466 : : {
1467 : 0 : case COLORCOMP_RED: mdRed = dValue; break;
1468 : 0 : case COLORCOMP_GREEN: mdGreen = dValue; break;
1469 : 0 : case COLORCOMP_BLUE: mdBlue = dValue; break;
1470 : 0 : case COLORCOMP_HUE: mdHue = dValue; break;
1471 : 0 : case COLORCOMP_SAT: mdSat = dValue; break;
1472 : 0 : case COLORCOMP_BRI: mdBri = dValue; break;
1473 : 0 : case COLORCOMP_CYAN: mdCyan = dValue; break;
1474 : 0 : case COLORCOMP_YELLOW: mdYellow = dValue; break;
1475 : 0 : case COLORCOMP_MAGENTA: mdMagenta = dValue; break;
1476 : 0 : case COLORCOMP_KEY: mdKey = dValue; break;
1477 : : }
1478 : :
1479 [ # # ]: 0 : if( nComp & COLORMODE_RGB )
1480 : : {
1481 : 0 : RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
1482 : 0 : RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
1483 : : }
1484 [ # # ]: 0 : else if( nComp & COLORMODE_HSV )
1485 : : {
1486 : 0 : HSVtoRGB( mdHue, mdSat, mdBri, mdRed, mdGreen, mdBlue );
1487 : 0 : RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
1488 : : }
1489 : : else
1490 : : {
1491 : 0 : CMYKtoRGB( mdCyan, mdMagenta, mdYellow, mdKey, mdRed, mdGreen, mdBlue );
1492 : 0 : RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
1493 : : }
1494 : 0 : }
1495 : :
1496 : : // --------------------------------------------------------------------
1497 : :
1498 : : typedef ::cppu::WeakComponentImplHelper4< XServiceInfo, XExecutableDialog, XInitialization, XPropertyAccess > ColorPickerBase;
1499 : :
1500 [ # # ][ # # ]: 0 : class ColorPicker : protected ::comphelper::OBaseMutex, // Struct for right initalization of mutex member! Must be first of baseclasses.
1501 : : public ColorPickerBase
1502 : : {
1503 : : public:
1504 : : ColorPicker( Reference< XComponentContext > const & xContext );
1505 : :
1506 : : // XInitialization
1507 : : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
1508 : :
1509 : : // XInitialization
1510 : : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException);
1511 : : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
1512 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
1513 : :
1514 : : // XPropertyAccess
1515 : : virtual Sequence< PropertyValue > SAL_CALL getPropertyValues( ) throw (RuntimeException);
1516 : : virtual void SAL_CALL setPropertyValues( const Sequence< PropertyValue >& aProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
1517 : :
1518 : : // XExecutableDialog
1519 : : virtual void SAL_CALL setTitle( const OUString& aTitle ) throw (RuntimeException);
1520 : : virtual sal_Int16 SAL_CALL execute( ) throw (RuntimeException);
1521 : :
1522 : : private:
1523 : : Reference< XComponentContext > mxContext;
1524 : : OUString msTitle;
1525 : : const OUString msColorKey;
1526 : : const OUString msModeKey;
1527 : : sal_Int32 mnColor;
1528 : : sal_Int16 mnMode;
1529 : : Reference< ::com::sun::star::awt::XWindow > mxParent;
1530 : : };
1531 : :
1532 : : // --------------------------------------------------------------------
1533 : :
1534 : 0 : OUString SAL_CALL ColorPicker_getImplementationName()
1535 : : {
1536 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.cui.ColorPicker" ) );
1537 : : }
1538 : :
1539 : : // --------------------------------------------------------------------
1540 : :
1541 : 0 : Reference< XInterface > SAL_CALL ColorPicker_createInstance( Reference< XComponentContext > const & xContext ) SAL_THROW( (Exception) )
1542 : : {
1543 [ # # ]: 0 : return static_cast<XWeak*>( new ColorPicker( xContext ) );
1544 : : }
1545 : :
1546 : : // --------------------------------------------------------------------
1547 : :
1548 : 0 : Sequence< OUString > SAL_CALL ColorPicker_getSupportedServiceNames() throw( RuntimeException )
1549 : : {
1550 : 0 : Sequence< OUString > seq(1);
1551 [ # # ][ # # ]: 0 : seq[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.ColorPicker" ) );
1552 : 0 : return seq;
1553 : : }
1554 : :
1555 : : // --------------------------------------------------------------------
1556 : :
1557 : 0 : ColorPicker::ColorPicker( Reference< XComponentContext > const & xContext )
1558 : : : ColorPickerBase( m_aMutex )
1559 : : , mxContext( xContext )
1560 : : , msColorKey( RTL_CONSTASCII_USTRINGPARAM( "Color" ) )
1561 : : , msModeKey( RTL_CONSTASCII_USTRINGPARAM( "Mode" ) )
1562 : : , mnColor( 0 )
1563 [ # # ][ # # ]: 0 : , mnMode( 0 )
1564 : : {
1565 : 0 : }
1566 : :
1567 : : // --------------------------------------------------------------------
1568 : :
1569 : : // XInitialization
1570 : 0 : void SAL_CALL ColorPicker::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
1571 : : {
1572 [ # # ]: 0 : if( aArguments.getLength() == 1 )
1573 : : {
1574 : 0 : aArguments[0] >>= mxParent;
1575 : : }
1576 : 0 : }
1577 : :
1578 : : // --------------------------------------------------------------------
1579 : :
1580 : : // XInitialization
1581 : 0 : OUString SAL_CALL ColorPicker::getImplementationName( ) throw (RuntimeException)
1582 : : {
1583 : 0 : return ColorPicker_getImplementationName();
1584 : : }
1585 : :
1586 : : // --------------------------------------------------------------------
1587 : :
1588 : 0 : sal_Bool SAL_CALL ColorPicker::supportsService( const OUString& sServiceName ) throw (RuntimeException)
1589 : : {
1590 : 0 : return sServiceName == "com.sun.star.ui.dialogs.ColorPicker";
1591 : : }
1592 : :
1593 : : // --------------------------------------------------------------------
1594 : :
1595 : 0 : Sequence< OUString > SAL_CALL ColorPicker::getSupportedServiceNames( ) throw (RuntimeException)
1596 : : {
1597 : 0 : return ColorPicker_getSupportedServiceNames();
1598 : : }
1599 : :
1600 : : // --------------------------------------------------------------------
1601 : :
1602 : : // XPropertyAccess
1603 : 0 : Sequence< PropertyValue > SAL_CALL ColorPicker::getPropertyValues( ) throw (RuntimeException)
1604 : : {
1605 : 0 : Sequence< PropertyValue > props(1);
1606 [ # # ]: 0 : props[0].Name = msColorKey;
1607 [ # # ][ # # ]: 0 : props[0].Value <<= mnColor;
1608 : 0 : return props;
1609 : : }
1610 : :
1611 : : // --------------------------------------------------------------------
1612 : :
1613 : 0 : void SAL_CALL ColorPicker::setPropertyValues( const Sequence< PropertyValue >& aProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1614 : : {
1615 [ # # ]: 0 : for( sal_Int32 n = 0; n < aProps.getLength(); n++ )
1616 : : {
1617 [ # # ]: 0 : if( aProps[n].Name.equals( msColorKey ) )
1618 : : {
1619 : 0 : aProps[n].Value >>= mnColor;
1620 : : }
1621 [ # # ]: 0 : else if( aProps[n].Name.equals( msModeKey ) )
1622 : : {
1623 : 0 : aProps[n].Value >>= mnMode;
1624 : : }
1625 : : }
1626 : 0 : }
1627 : :
1628 : : // --------------------------------------------------------------------
1629 : :
1630 : : // XExecutableDialog
1631 : 0 : void SAL_CALL ColorPicker::setTitle( const OUString& sTitle ) throw (RuntimeException)
1632 : : {
1633 : 0 : msTitle = sTitle;
1634 : 0 : }
1635 : :
1636 : : // --------------------------------------------------------------------
1637 : :
1638 : 0 : sal_Int16 SAL_CALL ColorPicker::execute( ) throw (RuntimeException)
1639 : : {
1640 [ # # ][ # # ]: 0 : ColorPickerDialog aDlg( VCLUnoHelper::GetWindow( mxParent ), mnColor, mnMode );
1641 [ # # ]: 0 : sal_Int16 ret = aDlg.Execute();
1642 [ # # ]: 0 : if( ret )
1643 : 0 : mnColor = aDlg.GetColor();
1644 : :
1645 [ # # ]: 0 : return ret;
1646 : : }
1647 : :
1648 : : // --------------------------------------------------------------------
1649 : :
1650 : : }
1651 : :
1652 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|