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