masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / tabpages / tpcolor.cxx
blob2a34f5beb702d21639d89420594bd5ab01ca4142
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <tools/urlobj.hxx>
34 #include <unotools/pathoptions.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/module.hxx>
37 #include <svtools/colrdlg.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/filedlghelper.hxx>
40 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
42 #define _SVX_TPCOLOR_CXX
44 #include <cuires.hrc>
45 #include "helpid.hrc"
46 #include "svx/xattr.hxx"
47 #include <svx/xpool.hxx>
48 #include <svx/xtable.hxx>
49 #include "svx/drawitem.hxx"
50 #include "cuitabarea.hxx"
51 #include "tabarea.hrc"
52 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
53 //#include "dlgname.hrc"
54 #include <svx/svxdlg.hxx> //CHINA001
55 #include <dialmgr.hxx>
56 #include <cuitabline.hxx>
57 #include <svx/dialmgr.hxx>
58 #include <svx/dialogs.hrc>
60 #define DLGWIN GetParentDialog( this )
62 /*************************************************************************
64 |* Dialog zum Aendern und Definieren der Farben
66 \************************************************************************/
68 static Window* GetParentDialog( Window* pWindow )
70 while( pWindow )
72 if( pWindow->IsDialog() )
73 break;
75 pWindow = pWindow->GetParent();
78 return pWindow;
81 SvxColorTabPage::SvxColorTabPage
83 Window* pParent,
84 const SfxItemSet& rInAttrs
85 ) :
87 SfxTabPage ( pParent, CUI_RES( RID_SVXPAGE_COLOR ), rInAttrs ),
89 aFlProp ( this, CUI_RES( FL_PROP ) ),
90 aFtName ( this, CUI_RES( FT_NAME ) ),
91 aEdtName ( this, CUI_RES( EDT_NAME ) ),
92 aFtColor ( this, CUI_RES( FT_COLOR ) ),
93 aLbColor ( this, CUI_RES( LB_COLOR ) ),
95 aTableNameFT ( this, CUI_RES( FT_TABLE_NAME ) ),
96 aValSetColorTable ( this, CUI_RES( CTL_COLORTABLE ) ),
98 aCtlPreviewOld ( this, CUI_RES( CTL_PREVIEW_OLD ) ),
99 aCtlPreviewNew ( this, CUI_RES( CTL_PREVIEW_NEW ) ),
101 aLbColorModel ( this, CUI_RES( LB_COLORMODEL ) ),
102 aFtColorModel1 ( this, CUI_RES( FT_1 ) ),
103 aMtrFldColorModel1 ( this, CUI_RES( MTR_FLD_1 ) ),
104 aFtColorModel2 ( this, CUI_RES( FT_2 ) ),
105 aMtrFldColorModel2 ( this, CUI_RES( MTR_FLD_2 ) ),
106 aFtColorModel3 ( this, CUI_RES( FT_3 ) ),
107 aMtrFldColorModel3 ( this, CUI_RES( MTR_FLD_3 ) ),
108 aFtColorModel4 ( this, CUI_RES( FT_4 ) ),
109 aMtrFldColorModel4 ( this, CUI_RES( MTR_FLD_4 ) ),
110 aBtnAdd ( this, CUI_RES( BTN_ADD ) ),
111 aBtnModify ( this, CUI_RES( BTN_MODIFY ) ),
112 aBtnWorkOn ( this, CUI_RES( BTN_WORK_ON ) ),
113 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ),
114 aBtnLoad ( this, CUI_RES( BTN_LOAD ) ),
115 aBtnSave ( this, CUI_RES( BTN_SAVE ) ),
117 rOutAttrs ( rInAttrs ),
118 pColorTab( NULL ),
120 bDeleteColorTable ( sal_True ),
122 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
123 aXFStyleItem ( XFILL_SOLID ),
124 aXFillColorItem ( String(), Color( COL_BLACK ) ),
125 aXFillAttr ( pXPool ),
126 rXFSet ( aXFillAttr.GetItemSet() ),
128 eCM ( CM_RGB )
131 aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
132 aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
134 FreeResource();
136 // diese Page braucht ExchangeSupport
137 SetExchangeSupport();
139 // Setzen des Output-Devices
140 rXFSet.Put( aXFStyleItem );
141 rXFSet.Put( aXFillColorItem );
142 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
143 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
145 // Handler ueberladen
146 aLbColor.SetSelectHdl(
147 LINK( this, SvxColorTabPage, SelectColorLBHdl_Impl ) );
148 aValSetColorTable.SetSelectHdl(
149 LINK( this, SvxColorTabPage, SelectValSetHdl_Impl ) );
150 aLbColorModel.SetSelectHdl(
151 LINK( this, SvxColorTabPage, SelectColorModelHdl_Impl ) );
153 Link aLink = LINK( this, SvxColorTabPage, ModifiedHdl_Impl );
154 aMtrFldColorModel1.SetModifyHdl( aLink );
155 aMtrFldColorModel2.SetModifyHdl( aLink );
156 aMtrFldColorModel3.SetModifyHdl( aLink );
157 aMtrFldColorModel4.SetModifyHdl( aLink );
159 aBtnAdd.SetClickHdl( LINK( this, SvxColorTabPage, ClickAddHdl_Impl ) );
160 aBtnModify.SetClickHdl(
161 LINK( this, SvxColorTabPage, ClickModifyHdl_Impl ) );
162 aBtnWorkOn.SetClickHdl(
163 LINK( this, SvxColorTabPage, ClickWorkOnHdl_Impl ) );
164 aBtnDelete.SetClickHdl(
165 LINK( this, SvxColorTabPage, ClickDeleteHdl_Impl ) );
166 aBtnLoad.SetClickHdl( LINK( this, SvxColorTabPage, ClickLoadHdl_Impl ) );
167 aBtnSave.SetClickHdl( LINK( this, SvxColorTabPage, ClickSaveHdl_Impl ) );
169 // ValueSet
170 aValSetColorTable.SetStyle( aValSetColorTable.GetStyle() | WB_VSCROLL | WB_ITEMBORDER );
171 aValSetColorTable.SetColCount( 8 );
172 aValSetColorTable.SetLineCount( 10 );
173 aValSetColorTable.SetExtraSpacing( 0 );
174 aValSetColorTable.Show();
176 aLbColorModel.SetAccessibleName( String( CUI_RES(STR_CUI_COLORMODEL) ) );
177 aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
178 aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
179 aBtnWorkOn.SetAccessibleRelationMemberOf( &aFlProp );
180 aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
183 // -----------------------------------------------------------------------
185 void SvxColorTabPage::Construct()
187 aLbColor.Fill( pColorTab );
188 FillValueSet_Impl( aValSetColorTable );
191 // -----------------------------------------------------------------------
193 void SvxColorTabPage::ActivatePage( const SfxItemSet& )
195 if( *pDlgType == 0 ) // Flaechen-Dialog
197 *pbAreaTP = sal_False;
199 if( pColorTab )
201 if( *pPageType == PT_COLOR && *pPos != LISTBOX_ENTRY_NOTFOUND )
203 aLbColor.SelectEntryPos( *pPos );
204 aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
205 aEdtName.SetText( aLbColor.GetSelectEntry() );
207 ChangeColorHdl_Impl( this );
209 else if( *pPageType == PT_COLOR && *pPos == LISTBOX_ENTRY_NOTFOUND )
211 const SfxPoolItem* pPoolItem = NULL;
212 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
214 aLbColorModel.SelectEntryPos( CM_RGB );
216 aAktuellColor.SetColor ( ( ( const XFillColorItem* ) pPoolItem )->GetColorValue().GetColor() );
218 aEdtName.SetText( ( ( const XFillColorItem* ) pPoolItem )->GetName() );
220 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
221 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
222 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
224 // ItemSet fuellen und an XOut weiterleiten
225 rXFSet.Put( XFillColorItem( String(), aAktuellColor ) );
226 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
227 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
229 aCtlPreviewNew.Invalidate();
230 aCtlPreviewOld.Invalidate();
234 // Ermitteln (evtl. abschneiden) des Namens und in
235 // der GroupBox darstellen
236 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
237 INetURLObject aURL( pColorTab->GetPath() );
239 aURL.Append( pColorTab->GetName() );
240 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
242 if ( aURL.getBase().getLength() > 18 )
244 aString += String(aURL.getBase()).Copy( 0, 15 );
245 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
247 else
248 aString += String(aURL.getBase());
250 aTableNameFT.SetText( aString );
252 // Damit evtl. geaenderte Farbe verworfen wird
253 SelectColorLBHdl_Impl( this );
255 *pPageType = PT_COLOR;
256 *pPos = LISTBOX_ENTRY_NOTFOUND;
259 else
261 // Buttons werden gehided, weil Paletten z.Z. nur
262 // ueber den AreaDlg funktionieren!!!
263 // ActivatePage() muss von anderen Dialogen explizit
264 // gerufen werden, da ActivatePage() nicht gerufen wird,
265 // wenn Seite als Erste im Dialog angezeigt wird
266 aBtnLoad.Hide();
267 aBtnSave.Hide();
271 // -----------------------------------------------------------------------
273 int SvxColorTabPage::DeactivatePage( SfxItemSet* _pSet )
275 if ( CheckChanges_Impl() == -1L )
276 return( KEEP_PAGE );
278 if( _pSet )
279 FillItemSet( *_pSet );
281 return( LEAVE_PAGE );
284 // -----------------------------------------------------------------------
286 long SvxColorTabPage::CheckChanges_Impl()
288 // wird hier benutzt, um Aenderungen NICHT zu verlieren
290 Color aTmpColor (aAktuellColor);
291 if (eCM != CM_RGB)
292 ConvertColorValues (aTmpColor, CM_RGB);
294 sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
295 if( nPos != LISTBOX_ENTRY_NOTFOUND )
297 Color aColor = pColorTab->GetColor( nPos )->GetColor();
298 String aString = aLbColor.GetSelectEntry();
300 // aNewColor, da COL_USER != COL_irgendwas, auch wenn RGB-Werte gleich
301 // Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
303 if( ColorToPercent_Impl( aTmpColor.GetRed() ) != ColorToPercent_Impl( aColor.GetRed() ) ||
304 ColorToPercent_Impl( aTmpColor.GetGreen() ) != ColorToPercent_Impl( aColor.GetGreen() ) ||
305 ColorToPercent_Impl( aTmpColor.GetBlue() ) != ColorToPercent_Impl( aColor.GetBlue() ) ||
306 aString != aEdtName.GetText() )
308 ResMgr& rMgr = CUI_MGR();
309 Image aWarningBoxImage = WarningBox::GetStandardImage();
310 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
311 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
312 AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
313 SVX_RESSTR( RID_SVXSTR_COLOR ),
314 String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR, rMgr ) ),
315 &aWarningBoxImage );
316 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
317 aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
318 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
319 aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
320 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
322 short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
324 switch( nRet )
326 case RET_BTN_1: // Aendern
328 ClickModifyHdl_Impl( this );
329 aColor = pColorTab->GetColor( nPos )->GetColor();
331 break;
333 case RET_BTN_2: // Hinzufuegen
335 ClickAddHdl_Impl( this );
336 nPos = aLbColor.GetSelectEntryPos();
337 aColor = pColorTab->GetColor( nPos )->GetColor();
339 break;
341 case RET_CANCEL:
342 // return( -1L ); <-- wuerde die Seite nicht verlassen
343 break;
344 // return( sal_True ); // Abbruch
346 delete aMessDlg; //add by CHINA001
349 if( *pDlgType == 0 ) // Flaechen-Dialog
351 nPos = aLbColor.GetSelectEntryPos();
352 if( nPos != LISTBOX_ENTRY_NOTFOUND )
354 *pPos = nPos;
357 return( 0L );
360 // -----------------------------------------------------------------------
362 sal_Bool SvxColorTabPage::FillItemSet( SfxItemSet& rSet )
364 if( ( *pDlgType != 0 ) ||
365 ( *pPageType == PT_COLOR && *pbAreaTP == sal_False ) )
367 String aString;
368 Color aColor;
370 // CheckChanges_Impl(); <-- doppelte Abfrage ?
372 sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
373 if( nPos != LISTBOX_ENTRY_NOTFOUND )
375 aColor = pColorTab->GetColor( nPos )->GetColor();
376 aString = aLbColor.GetSelectEntry();
378 else
380 aColor.SetColor (aAktuellColor.GetColor());
381 if (eCM != CM_RGB)
382 ConvertColorValues (aColor, CM_RGB);
384 rSet.Put( XFillColorItem( aString, aColor ) );
385 rSet.Put( XFillStyleItem( XFILL_SOLID ) );
388 return( sal_True );
391 // -----------------------------------------------------------------------
393 void SvxColorTabPage::Reset( const SfxItemSet& rSet )
395 sal_uInt16 nState = rSet.GetItemState( XATTR_FILLCOLOR );
397 if ( nState >= SFX_ITEM_DEFAULT )
399 XFillColorItem aColorItem( (const XFillColorItem&)rSet.Get( XATTR_FILLCOLOR ) );
400 aLbColor.SelectEntry( aColorItem.GetColorValue() );
401 aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
402 aEdtName.SetText( aLbColor.GetSelectEntry() );
405 // Farbmodell setzen
406 String aStr = GetUserData();
407 aLbColorModel.SelectEntryPos( (sal_uInt16) aStr.ToInt32() );
409 ChangeColorHdl_Impl( this );
410 SelectColorModelHdl_Impl( this );
412 aCtlPreviewOld.Invalidate();
414 // Status der Buttons ermitteln
415 if( pColorTab->Count() )
417 aBtnModify.Enable();
418 aBtnWorkOn.Enable();
419 aBtnDelete.Enable();
420 aBtnSave.Enable();
422 else
424 aBtnModify.Disable();
425 aBtnWorkOn.Disable();
426 aBtnDelete.Disable();
427 aBtnSave.Disable();
431 // -----------------------------------------------------------------------
433 SfxTabPage* SvxColorTabPage::Create( Window* pWindow,
434 const SfxItemSet& rOutAttrs )
436 return( new SvxColorTabPage( pWindow, rOutAttrs ) );
439 //------------------------------------------------------------------------
442 // Wird aufgerufen, wenn Inhalt der MtrFileds f�r Farbwerte ver�ndert wird
444 IMPL_LINK( SvxColorTabPage, ModifiedHdl_Impl, void *, EMPTYARG )
446 // lese aktuelle MtrFields aus, wenn cmyk, dann k-Wert als Trans.-Farbe
447 aAktuellColor.SetColor ( Color( (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel4.GetValue() ),
448 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel1.GetValue() ),
449 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel2.GetValue() ),
450 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel3.GetValue() ) ).GetColor() );
452 Color aTmpColor(aAktuellColor);
453 if (eCM != CM_RGB)
454 ConvertColorValues (aTmpColor, CM_RGB);
456 rXFSet.Put( XFillColorItem( String(), aTmpColor ) );
457 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
459 aCtlPreviewNew.Invalidate();
461 return( 0L );
464 //------------------------------------------------------------------------
467 // Button 'Hinzuf�gen'
469 IMPL_LINK( SvxColorTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
471 Window *pWindow = this;
472 bool bEnabled;
473 while( pWindow )
475 bEnabled = pWindow->IsEnabled();
476 pWindow = pWindow->GetParent();
479 ResMgr& rMgr = CUI_MGR();
480 String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
481 String aName( aEdtName.GetText() );
482 XColorEntry* pEntry;
483 long nCount = pColorTab->Count();
484 sal_Bool bDifferent = sal_True;
486 // Pruefen, ob Name schon vorhanden ist
487 for ( long i = 0; i < nCount && bDifferent; i++ )
488 if ( aName == pColorTab->GetColor( i )->GetName() )
489 bDifferent = sal_False;
491 // Wenn ja, wird wiederholt ein neuer Name angefordert
492 if ( !bDifferent )
494 WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ),
495 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
496 aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
497 aWarningBox.Execute();
499 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
500 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
501 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
502 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
503 sal_Bool bLoop = sal_True;
505 while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
507 pDlg->GetName( aName );
508 bDifferent = sal_True;
510 for( long i = 0; i < nCount && bDifferent; i++ )
512 if( aName == pColorTab->GetColor( i )->GetName() )
513 bDifferent = sal_False;
516 if( bDifferent )
517 bLoop = sal_False;
518 else
519 aWarningBox.Execute();
521 delete( pDlg );
524 // Wenn nicht vorhanden, wird Eintrag aufgenommen
525 if( bDifferent )
527 if (eCM != CM_RGB)
528 ConvertColorValues (aAktuellColor, CM_RGB);
529 pEntry = new XColorEntry( aAktuellColor, aName );
531 pColorTab->Insert( pColorTab->Count(), pEntry );
533 aLbColor.Append( pEntry );
534 aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1,
535 pEntry->GetColor(), pEntry->GetName() );
537 aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
539 // Flag fuer modifiziert setzen
540 *pnColorTableState |= CT_MODIFIED;
542 SelectColorLBHdl_Impl( this );
544 // Status der Buttons ermitteln
545 if( pColorTab->Count() )
547 aBtnModify.Enable();
548 aBtnWorkOn.Enable();
549 aBtnDelete.Enable();
550 aBtnSave.Enable();
552 return( 0L );
555 //------------------------------------------------------------------------
558 // Button '�ndern'
560 IMPL_LINK( SvxColorTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
562 sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
564 if( nPos != LISTBOX_ENTRY_NOTFOUND )
566 ResMgr& rMgr = CUI_MGR();
567 String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
568 String aName( aEdtName.GetText() );
569 long nCount = pColorTab->Count();
570 sal_Bool bDifferent = sal_True;
572 // Pruefen, ob Name schon vorhanden ist
573 for ( long i = 0; i < nCount && bDifferent; i++ )
574 if ( aName == pColorTab->GetColor( i )->GetName() && nPos != i )
575 bDifferent = sal_False;
577 // Wenn ja, wird wiederholt ein neuer Name angefordert
578 if ( !bDifferent )
580 WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ),
581 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
582 aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
583 aWarningBox.Execute();
585 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
586 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
587 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
588 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
589 sal_Bool bLoop = sal_True;
591 while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
593 pDlg->GetName( aName );
594 bDifferent = sal_True;
596 for ( long i = 0; i < nCount && bDifferent; i++ )
597 if( aName == pColorTab->GetColor( i )->GetName() && nPos != i )
598 bDifferent = sal_False;
600 if( bDifferent )
601 bLoop = sal_False;
602 else
603 aWarningBox.Execute();
605 delete( pDlg );
608 // Wenn nicht vorhanden, wird Eintrag aufgenommen
609 if( bDifferent )
611 XColorEntry* pEntry = pColorTab->GetColor( nPos );
613 Color aTmpColor (aAktuellColor);
614 if (eCM != CM_RGB)
615 ConvertColorValues (aTmpColor, CM_RGB);
617 pEntry->SetColor( aTmpColor );
618 pEntry->SetName( aName );
620 aLbColor.Modify( pEntry, nPos );
621 aLbColor.SelectEntryPos( nPos );
622 /////
623 aValSetColorTable.SetItemColor( nPos + 1, pEntry->GetColor() );
624 aValSetColorTable.SetItemText( nPos + 1, pEntry->GetName() );
625 aEdtName.SetText( aName );
627 aCtlPreviewOld.Invalidate();
629 // Flag fuer modifiziert setzen
630 *pnColorTableState |= CT_MODIFIED;
633 return( 0L );
636 //------------------------------------------------------------------------
639 // Button 'Bearbeiten'
641 IMPL_LINK( SvxColorTabPage, ClickWorkOnHdl_Impl, void *, EMPTYARG )
643 SvColorDialog* pColorDlg = new SvColorDialog( DLGWIN );
645 Color aTmpColor (aAktuellColor);
646 if (eCM != CM_RGB)
647 ConvertColorValues (aTmpColor, CM_RGB);
649 pColorDlg->SetColor (aTmpColor);
651 if( pColorDlg->Execute() == RET_OK )
653 sal_uInt16 nK = 0;
654 Color aPreviewColor = pColorDlg->GetColor();
655 aAktuellColor = aPreviewColor;
656 if (eCM != CM_RGB)
657 ConvertColorValues (aAktuellColor, eCM);
659 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
660 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
661 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
662 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( nK ) );
664 // ItemSet fuellen und an XOut weiterleiten
665 rXFSet.Put( XFillColorItem( String(), aPreviewColor ) );
666 //aCtlPreviewOld.SetAttributes( aXFillAttr );
667 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
669 aCtlPreviewNew.Invalidate();
671 delete( pColorDlg );
673 return( 0L );
676 //------------------------------------------------------------------------
679 // Button 'Loeschen'
681 IMPL_LINK( SvxColorTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
683 sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
685 if( nPos != LISTBOX_ENTRY_NOTFOUND )
687 QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
688 String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) );
690 if( aQueryBox.Execute() == RET_YES )
692 // Jetzt wird richtig geloescht
693 sal_uLong nCount = pColorTab->Count() - 1;
694 XColorEntry* pEntry;
696 pEntry = pColorTab->Remove( nPos );
697 DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (1) !" );
698 delete pEntry;
700 for( sal_uLong i = nPos; i < nCount; i++ )
702 pEntry = pColorTab->Remove( i + 1 );
703 DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (2) !" );
704 pColorTab->Insert( i, pEntry );
707 // Listbox und ValueSet aktualisieren
708 aLbColor.RemoveEntry( nPos );
709 aValSetColorTable.Clear();
710 FillValueSet_Impl( aValSetColorTable );
712 // Positionieren
713 aLbColor.SelectEntryPos( nPos );
714 SelectColorLBHdl_Impl( this );
716 aCtlPreviewOld.Invalidate();
718 // Flag fuer modifiziert setzen
719 *pnColorTableState |= CT_MODIFIED;
722 // Status der Buttons ermitteln
723 if( !pColorTab->Count() )
725 aBtnModify.Disable();
726 aBtnWorkOn.Disable();
727 aBtnDelete.Disable();
728 aBtnSave.Disable();
730 return( 0L );
733 // -----------------------------------------------------------------------
736 // Button 'Farbtabelle laden'
738 IMPL_LINK( SvxColorTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
740 ResMgr& rMgr = CUI_MGR();
741 sal_uInt16 nReturn = RET_YES;
743 if( *pnColorTableState & CT_MODIFIED )
745 nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
746 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
748 if ( nReturn == RET_YES )
749 pColorTab->Save();
752 if ( nReturn != RET_CANCEL )
754 ::sfx2::FileDialogHelper aDlg(
755 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
756 0 );
757 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
758 aDlg.AddFilter( aStrFilterType, aStrFilterType );
759 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
760 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
762 if ( aDlg.Execute() == ERRCODE_NONE )
764 INetURLObject aURL( aDlg.GetPath() );
765 INetURLObject aPathURL( aURL );
767 aPathURL.removeSegment();
768 aPathURL.removeFinalSlash();
770 // Tabelle speichern
771 XColorTable* pColTab = new XColorTable( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
772 pColTab->SetName( aURL.getName() ); // XXX
773 if( pColTab->Load() )
775 if( pColTab )
777 // Pruefen, ob Tabelle geloescht werden darf:
778 const XColorTable *pTempTable = 0;
779 SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( DLGWIN );
780 SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( DLGWIN );
781 if( pArea )
783 pTempTable = pArea->GetColorTable();
785 else if( pLine )
787 pTempTable = pLine->GetColorTable();
790 if( pColorTab != pTempTable )
792 if( bDeleteColorTable )
793 delete pColorTab;
794 else
795 bDeleteColorTable = sal_True;
798 pColorTab = pColTab;
799 if( pArea )
801 pArea->SetNewColorTable( pColorTab );
803 else if( pLine )
805 pLine->SetNewColorTable( pColorTab );
808 aLbColor.Clear();
809 aValSetColorTable.Clear();
810 Construct();
811 Reset( rOutAttrs );
813 pColorTab->SetName( aURL.getName() );
815 // Ermitteln (evtl. abschneiden) des Namens und in
816 // der GroupBox darstellen
817 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
818 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
820 if ( aURL.getBase().getLength() > 18 )
822 aString += String(aURL.getBase()).Copy( 0, 15 );
823 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
825 else
826 aString += String(aURL.getBase());
828 aTableNameFT.SetText( aString );
830 // Flag fuer gewechselt setzen
831 *pnColorTableState |= CT_CHANGED;
832 // Flag fuer modifiziert entfernen
833 *pnColorTableState &= ~CT_MODIFIED;
835 if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
836 aLbColor.SelectEntryPos( 0 );
837 else
838 aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() );
840 ChangeColorHdl_Impl( this );
841 SelectColorLBHdl_Impl( this );
844 else
846 //aIStream.Close();
847 ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
848 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) );
849 aErrorBox.Execute();
854 // Status der Buttons ermitteln
855 if ( pColorTab->Count() )
857 aBtnModify.Enable();
858 aBtnWorkOn.Enable();
859 aBtnDelete.Enable();
860 aBtnSave.Enable();
862 else
864 aBtnModify.Disable();
865 aBtnWorkOn.Disable();
866 aBtnDelete.Disable();
867 aBtnSave.Disable();
869 return( 0L );
872 // -----------------------------------------------------------------------
875 // Button 'Farbtabelle speichern'
877 IMPL_LINK( SvxColorTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
879 ::sfx2::FileDialogHelper aDlg(
880 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
881 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
882 aDlg.AddFilter( aStrFilterType, aStrFilterType );
884 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
885 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
887 if( pColorTab->GetName().Len() )
889 aFile.Append( pColorTab->GetName() );
891 if( !aFile.getExtension().getLength() )
892 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) );
895 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
896 if ( aDlg.Execute() == ERRCODE_NONE )
898 INetURLObject aURL( aDlg.GetPath() );
899 INetURLObject aPathURL( aURL );
901 aPathURL.removeSegment();
902 aPathURL.removeFinalSlash();
904 pColorTab->SetName( aURL.getName() );
905 pColorTab->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
907 if( pColorTab->Save() )
909 // Ermitteln (evtl. abschneiden) des Namens und in
910 // der GroupBox darstellen
911 String aString( CUI_RES( RID_SVXSTR_TABLE ) );
912 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
914 if ( aURL.getBase().getLength() > 18 )
916 aString += String(aURL.getBase()).Copy( 0, 15 );
917 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
919 else
920 aString += String(aURL.getBase());
921 aTableNameFT.SetText( aString );
923 // Flag fuer gespeichert setzen
924 *pnColorTableState |= CT_SAVED;
925 // Flag fuer modifiziert entfernen
926 *pnColorTableState &= ~CT_MODIFIED;
928 else
930 ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
931 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) );
932 aErrorBox.Execute();
935 return( 0L );
938 //------------------------------------------------------------------------
940 IMPL_LINK( SvxColorTabPage, SelectColorLBHdl_Impl, void *, EMPTYARG )
942 sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
943 if( nPos != LISTBOX_ENTRY_NOTFOUND )
945 aValSetColorTable.SelectItem( nPos + 1 );
946 aEdtName.SetText( aLbColor.GetSelectEntry() );
948 rXFSet.Put( XFillColorItem( String(),
949 aLbColor.GetSelectEntryColor() ) );
950 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
951 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
953 aCtlPreviewOld.Invalidate();
954 aCtlPreviewNew.Invalidate();
956 ChangeColorHdl_Impl( this );
958 return( 0L );
961 //------------------------------------------------------------------------
963 IMPL_LINK( SvxColorTabPage, SelectValSetHdl_Impl, void *, EMPTYARG )
965 sal_uInt16 nPos = aValSetColorTable.GetSelectItemId();
966 if( nPos != LISTBOX_ENTRY_NOTFOUND )
968 aLbColor.SelectEntryPos( nPos - 1 );
969 aEdtName.SetText( aLbColor.GetSelectEntry() );
971 rXFSet.Put( XFillColorItem( String(),
972 aLbColor.GetSelectEntryColor() ) );
973 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
974 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
976 aCtlPreviewOld.Invalidate();
977 aCtlPreviewNew.Invalidate();
979 ChangeColorHdl_Impl( this );
981 return( 0L );
984 //------------------------------------------------------------------------
987 // Farbwerte je nach �bergebenes Farbmodell umrechnen
989 void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell)
991 switch (eModell)
993 case CM_RGB:
995 CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() );
996 rColor.SetTransparency ((sal_uInt8) 0);
998 break;
1000 case CM_CMYK:
1002 sal_uInt16 nK;
1003 RgbToCmyk_Impl (rColor, nK );
1004 rColor.SetTransparency ((sal_uInt8) nK);
1006 break;
1011 // Auswahl Listbox 'Farbmodell' (RGB/CMY)
1013 IMPL_LINK( SvxColorTabPage, SelectColorModelHdl_Impl, void *, EMPTYARG )
1015 int nPos = aLbColorModel.GetSelectEntryPos();
1016 if( nPos != LISTBOX_ENTRY_NOTFOUND )
1018 if (eCM != (ColorModel) nPos)
1020 // wenn Farbmodell geaendert wurde, dann Werte umrechnen
1021 ConvertColorValues (aAktuellColor, (ColorModel) nPos);
1024 eCM = (ColorModel) nPos;
1026 switch( eCM )
1028 case CM_RGB:
1030 String aStr( aLbColorModel.GetSelectEntry() );
1031 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1032 xub_StrLen nIdx = 1;
1033 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1034 aFtColorModel1.SetText( aColorStr );
1035 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1036 aFtColorModel2.SetText( aColorStr );
1037 aColorStr.SetChar( nIdx, aStr.GetChar( 2 ) );
1038 aFtColorModel3.SetText( aColorStr );
1040 aFtColorModel4.Hide();
1041 aMtrFldColorModel4.Hide();
1042 aMtrFldColorModel4.SetValue( 0L );
1044 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 );
1045 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 );
1046 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 );
1048 // Da der alte HelpText noch am Control steht wuerde
1049 // ein Umsetzen der HelpID alleine nichts bewirken
1050 aMtrFldColorModel1.SetHelpText( String() );
1051 aMtrFldColorModel2.SetHelpText( String() );
1052 aMtrFldColorModel3.SetHelpText( String() );
1054 // RGB-Werte im Bereich 0..255 verarbeiten (nicht in %),
1055 // dazu MetricField's entsprechend einstellen
1056 aMtrFldColorModel1.SetUnit(FUNIT_NONE);
1057 aMtrFldColorModel1.SetMin(0);
1058 aMtrFldColorModel1.SetMax(255);
1059 aMtrFldColorModel1.SetLast(255);
1061 aMtrFldColorModel2.SetUnit(FUNIT_NONE);
1062 aMtrFldColorModel2.SetMin(0);
1063 aMtrFldColorModel2.SetMax(255);
1064 aMtrFldColorModel2.SetLast(255);
1066 aMtrFldColorModel3.SetUnit(FUNIT_NONE);
1067 aMtrFldColorModel3.SetMin(0);
1068 aMtrFldColorModel3.SetMax(255);
1069 aMtrFldColorModel3.SetLast(255);
1071 break;
1073 case CM_CMYK:
1075 String aStr( aLbColorModel.GetSelectEntry() );
1076 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1077 xub_StrLen nIdx = 1;
1078 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1079 aFtColorModel1.SetText( aColorStr );
1080 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1081 aFtColorModel2.SetText( aColorStr );
1082 aColorStr.SetChar( nIdx,aStr.GetChar( 2 ) );
1083 aFtColorModel3.SetText( aColorStr );
1084 aColorStr.SetChar( nIdx,aStr.GetChar( 3 ) );
1085 aFtColorModel4.SetText( aColorStr );
1087 aFtColorModel4.Show();
1088 aMtrFldColorModel4.Show();
1090 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 );
1091 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 );
1092 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 );
1094 // s.o.
1095 aMtrFldColorModel1.SetHelpText( String() );
1096 aMtrFldColorModel2.SetHelpText( String() );
1097 aMtrFldColorModel3.SetHelpText( String() );
1099 // CMYK-Werte im Bereich 0..100% verarbeiten,
1100 // dazu MetricField's entsprechend einstellen
1101 String aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) );
1103 aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM);
1104 aMtrFldColorModel1.SetCustomUnitText( aStrUnit );
1105 aMtrFldColorModel1.SetMin(0);
1106 aMtrFldColorModel1.SetMax(100);
1107 aMtrFldColorModel1.SetLast(100);
1109 aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM);
1110 aMtrFldColorModel2.SetCustomUnitText( aStrUnit );
1111 aMtrFldColorModel2.SetMin(0);
1112 aMtrFldColorModel2.SetMax(100);
1113 aMtrFldColorModel2.SetLast(100);
1115 aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM);
1116 aMtrFldColorModel3.SetCustomUnitText( aStrUnit );
1117 aMtrFldColorModel3.SetMin(0);
1118 aMtrFldColorModel3.SetMax(100);
1119 aMtrFldColorModel3.SetLast(100);
1121 break;
1124 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1125 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1126 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1127 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1130 aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) );
1131 aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) );
1132 aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) );
1133 aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) );
1135 return( 0L );
1138 //------------------------------------------------------------------------
1140 long SvxColorTabPage::ChangeColorHdl_Impl( void* )
1142 int nPos = aLbColor.GetSelectEntryPos();
1143 if( nPos != LISTBOX_ENTRY_NOTFOUND )
1145 XColorEntry* pEntry = pColorTab->GetColor( nPos );
1147 aAktuellColor.SetColor ( pEntry->GetColor().GetColor() );
1148 if (eCM != CM_RGB)
1149 ConvertColorValues (aAktuellColor, eCM);
1151 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1152 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1153 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1154 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1156 // ItemSet fuellen und an XOut weiterleiten
1157 rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) );
1158 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
1159 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
1161 aCtlPreviewNew.Invalidate();
1163 return( 0L );
1166 //------------------------------------------------------------------------
1168 void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs )
1170 long nCount = pColorTab->Count();
1171 XColorEntry* pColorEntry;
1173 for( long i = 0; i < nCount; i++ )
1175 pColorEntry = pColorTab->GetColor( i );
1176 rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
1180 //------------------------------------------------------------------------
1182 // Ein RGB-Wert wird in einen CMYK-Wert konvertiert, wobei die Color-
1183 // Klasse vergewaltigt wird, da R in C, G in M und B in Y umgewandelt
1184 // wird. Der Wert K wird in einer Extra-Variablen gehalten.
1185 // Bei weiteren Farbmodellen sollte man hierfuer eigene Klassen entwickeln,
1186 // die dann auch entsprechende Casts enthalten.
1188 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
1190 sal_uInt16 nColor1, nColor2, nColor3;
1191 sal_uInt16 nProzent; // nur temporaer !!!
1193 nColor1 = 255 - rColor.GetRed();
1194 nProzent = ColorToPercent_Impl( nColor1 );
1196 nColor2 = 255 - rColor.GetGreen();
1197 nProzent = ColorToPercent_Impl( nColor2 );
1199 nColor3 = 255 - rColor.GetBlue();
1200 nProzent = ColorToPercent_Impl( nColor3 );
1202 rK = Min( Min( nColor1, nColor2 ), nColor3 );
1204 rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
1205 rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
1206 rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
1209 //------------------------------------------------------------------------
1211 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.)
1213 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
1215 long lTemp;
1217 lTemp = 255 - ( rColor.GetRed() + nK );
1219 if( lTemp < 0L )
1220 lTemp = 0L;
1221 rColor.SetRed( (sal_uInt8)lTemp );
1223 lTemp = 255 - ( rColor.GetGreen() + nK );
1225 if( lTemp < 0L )
1226 lTemp = 0L;
1227 rColor.SetGreen( (sal_uInt8)lTemp );
1229 lTemp = 255 - ( rColor.GetBlue() + nK );
1231 if( lTemp < 0L )
1232 lTemp = 0L;
1233 rColor.SetBlue( (sal_uInt8)lTemp );
1236 //------------------------------------------------------------------------
1238 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
1240 sal_uInt16 nWert = 0;
1242 switch (eCM)
1244 case CM_RGB :
1245 nWert = nColor;
1246 break;
1248 case CM_CMYK:
1249 nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 );
1250 break;
1253 return ( nWert );
1256 //------------------------------------------------------------------------
1258 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
1260 sal_uInt16 nWert = 0;
1262 switch (eCM)
1264 case CM_RGB :
1265 nWert = nPercent;
1266 break;
1268 case CM_CMYK:
1269 nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 );
1270 break;
1273 return ( nWert );
1276 //------------------------------------------------------------------------
1278 void SvxColorTabPage::FillUserData()
1280 // Das Farbmodell wird in der Ini-Datei festgehalten
1281 SetUserData( UniString::CreateFromInt32( eCM ) );