xref: /AOO41X/main/cui/source/tabpages/tpcolor.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
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"
41 
42 #define _SVX_TPCOLOR_CXX
43 
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>
59 
60 #define DLGWIN GetParentDialog( this )
61 
62 /*************************************************************************
63 |*
64 |*	Dialog zum Aendern und Definieren der Farben
65 |*
66 \************************************************************************/
67 
68 static Window* GetParentDialog( Window* pWindow )
69 {
70 	while( pWindow )
71 	{
72 		if( pWindow->IsDialog() )
73 			break;
74 
75 		pWindow = pWindow->GetParent();
76 	}
77 
78 	return pWindow;
79 }
80 
81 SvxColorTabPage::SvxColorTabPage
82 (
83 	Window* pParent,
84 	const SfxItemSet& rInAttrs
85 ) :
86 
87 	SfxTabPage			( pParent, CUI_RES( RID_SVXPAGE_COLOR ), rInAttrs ),
88 
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 ) ),
94 
95     aTableNameFT        ( this, CUI_RES( FT_TABLE_NAME ) ),
96     aValSetColorTable   ( this, CUI_RES( CTL_COLORTABLE ) ),
97 
98     aCtlPreviewOld      ( this, CUI_RES( CTL_PREVIEW_OLD ) ),
99     aCtlPreviewNew      ( this, CUI_RES( CTL_PREVIEW_NEW ) ),
100 
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 ) ),
116 
117     rOutAttrs           ( rInAttrs ),
118     pColorTab( NULL ),
119 
120     bDeleteColorTable   ( sal_True ),
121 
122     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
123     aXFStyleItem        ( XFILL_SOLID ),
124     aXFillColorItem     ( String(), Color( COL_BLACK ) ),
125     aXFillAttr          ( pXPool ),
126     rXFSet              ( aXFillAttr.GetItemSet() ),
127 
128     eCM                 ( CM_RGB )
129 
130 {
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 );
133 
134 	FreeResource();
135 
136 	// diese Page braucht ExchangeSupport
137 	SetExchangeSupport();
138 
139 	// Setzen des Output-Devices
140 	rXFSet.Put( aXFStyleItem );
141 	rXFSet.Put( aXFillColorItem );
142 	aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
143 	aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
144 
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 ) );
152 
153 	Link aLink = LINK( this, SvxColorTabPage, ModifiedHdl_Impl );
154 	aMtrFldColorModel1.SetModifyHdl( aLink );
155 	aMtrFldColorModel2.SetModifyHdl( aLink );
156 	aMtrFldColorModel3.SetModifyHdl( aLink );
157 	aMtrFldColorModel4.SetModifyHdl( aLink );
158 
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 ) );
168 
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();
175 
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 );
181 }
182 
183 // -----------------------------------------------------------------------
184 
185 void SvxColorTabPage::Construct()
186 {
187 	aLbColor.Fill( pColorTab );
188 	FillValueSet_Impl( aValSetColorTable );
189 }
190 
191 // -----------------------------------------------------------------------
192 
193 void SvxColorTabPage::ActivatePage( const SfxItemSet& )
194 {
195 	if( *pDlgType == 0 ) // Flaechen-Dialog
196 	{
197 		*pbAreaTP = sal_False;
198 
199 		if( pColorTab )
200 		{
201 			if( *pPageType == PT_COLOR && *pPos != LISTBOX_ENTRY_NOTFOUND )
202 			{
203 				aLbColor.SelectEntryPos( *pPos );
204 				aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
205 				aEdtName.SetText( aLbColor.GetSelectEntry() );
206 
207 				ChangeColorHdl_Impl( this );
208 			}
209 			else if( *pPageType == PT_COLOR && *pPos == LISTBOX_ENTRY_NOTFOUND )
210 			{
211 				const SfxPoolItem* pPoolItem = NULL;
212 				if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
213 				{
214 					aLbColorModel.SelectEntryPos( CM_RGB );
215 
216                     aAktuellColor.SetColor ( ( ( const XFillColorItem* ) pPoolItem )->GetColorValue().GetColor() );
217 
218 					aEdtName.SetText( ( ( const XFillColorItem* ) pPoolItem )->GetName() );
219 
220 					aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
221 					aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
222 					aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
223 
224 					// ItemSet fuellen und an XOut weiterleiten
225 					rXFSet.Put( XFillColorItem( String(), aAktuellColor ) );
226 					aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
227 					aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
228 
229 					aCtlPreviewNew.Invalidate();
230 					aCtlPreviewOld.Invalidate();
231 				}
232 			}
233 
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() );
238 
239 			aURL.Append( pColorTab->GetName() );
240 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
241 
242 			if ( aURL.getBase().getLength() > 18 )
243 			{
244 				aString += String(aURL.getBase()).Copy( 0, 15 );
245 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
246 			}
247 			else
248 				aString += String(aURL.getBase());
249 
250             aTableNameFT.SetText( aString );
251 
252 			// Damit evtl. geaenderte Farbe verworfen wird
253 			SelectColorLBHdl_Impl( this );
254 
255 			*pPageType = PT_COLOR;
256 			*pPos = LISTBOX_ENTRY_NOTFOUND;
257 		}
258 	}
259 	else
260 	{
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();
268 	}
269 }
270 
271 // -----------------------------------------------------------------------
272 
273 int SvxColorTabPage::DeactivatePage( SfxItemSet* _pSet )
274 {
275 	if ( CheckChanges_Impl() == -1L )
276 		return( KEEP_PAGE );
277 
278     if( _pSet )
279         FillItemSet( *_pSet );
280 
281 	return( LEAVE_PAGE );
282 }
283 
284 // -----------------------------------------------------------------------
285 
286 long SvxColorTabPage::CheckChanges_Impl()
287 {
288 	// wird hier benutzt, um Aenderungen NICHT zu verlieren
289 
290 	Color aTmpColor (aAktuellColor);
291 	if (eCM != CM_RGB)
292 		ConvertColorValues (aTmpColor, CM_RGB);
293 
294 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
295 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
296 	{
297         Color aColor = pColorTab->GetColor( nPos )->GetColor();
298 		String aString = aLbColor.GetSelectEntry();
299 
300 		// aNewColor, da COL_USER != COL_irgendwas, auch wenn RGB-Werte gleich
301 		// Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
302 
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() )
307 		{
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 ) ) );
321 
322 			short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
323 
324 			switch( nRet )
325 			{
326 				case RET_BTN_1: // Aendern
327 				{
328 					ClickModifyHdl_Impl( this );
329                     aColor = pColorTab->GetColor( nPos )->GetColor();
330 				}
331 				break;
332 
333 				case RET_BTN_2: // Hinzufuegen
334 				{
335 					ClickAddHdl_Impl( this );
336 					nPos = aLbColor.GetSelectEntryPos();
337                     aColor = pColorTab->GetColor( nPos )->GetColor();
338 				}
339 				break;
340 
341 				case RET_CANCEL:
342 					// return( -1L ); <-- wuerde die Seite nicht verlassen
343 				break;
344 				// return( sal_True ); // Abbruch
345 			}
346 			delete aMessDlg; //add by CHINA001
347 		}
348 	}
349 	if( *pDlgType == 0 ) // Flaechen-Dialog
350 	{
351 		nPos = aLbColor.GetSelectEntryPos();
352 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
353 		{
354 			*pPos = nPos;
355 		}
356 	}
357 	return( 0L );
358 }
359 
360 // -----------------------------------------------------------------------
361 
362 sal_Bool SvxColorTabPage::FillItemSet( SfxItemSet& rSet )
363 {
364 	if( ( *pDlgType != 0 ) ||
365 		( *pPageType == PT_COLOR && *pbAreaTP == sal_False ) )
366 	{
367 		String aString;
368 		Color  aColor;
369 
370 		// CheckChanges_Impl(); <-- doppelte Abfrage ?
371 
372 		sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
373 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
374 		{
375             aColor  = pColorTab->GetColor( nPos )->GetColor();
376 			aString = aLbColor.GetSelectEntry();
377 		}
378 		else
379 		{
380 			aColor.SetColor (aAktuellColor.GetColor());
381 			if (eCM != CM_RGB)
382 				ConvertColorValues (aColor, CM_RGB);
383 		}
384         rSet.Put( XFillColorItem( aString, aColor ) );
385         rSet.Put( XFillStyleItem( XFILL_SOLID ) );
386 	}
387 
388 	return( sal_True );
389 }
390 
391 // -----------------------------------------------------------------------
392 
393 void SvxColorTabPage::Reset( const SfxItemSet& rSet )
394 {
395     sal_uInt16 nState = rSet.GetItemState( XATTR_FILLCOLOR );
396 
397 	if ( nState >= SFX_ITEM_DEFAULT )
398 	{
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() );
403 	}
404 
405 	// Farbmodell setzen
406 	String aStr = GetUserData();
407 	aLbColorModel.SelectEntryPos( (sal_uInt16) aStr.ToInt32() );
408 
409 	ChangeColorHdl_Impl( this );
410 	SelectColorModelHdl_Impl( this );
411 
412 	aCtlPreviewOld.Invalidate();
413 
414 	// Status der Buttons ermitteln
415 	if( pColorTab->Count() )
416 	{
417 		aBtnModify.Enable();
418 		aBtnWorkOn.Enable();
419 		aBtnDelete.Enable();
420 		aBtnSave.Enable();
421 	}
422 	else
423 	{
424 		aBtnModify.Disable();
425 		aBtnWorkOn.Disable();
426 		aBtnDelete.Disable();
427 		aBtnSave.Disable();
428 	}
429 }
430 
431 // -----------------------------------------------------------------------
432 
433 SfxTabPage* SvxColorTabPage::Create( Window* pWindow,
434 				const SfxItemSet& rOutAttrs )
435 {
436 	return( new SvxColorTabPage( pWindow, rOutAttrs ) );
437 }
438 
439 //------------------------------------------------------------------------
440 
441 //
442 // Wird aufgerufen, wenn Inhalt der MtrFileds f�r Farbwerte ver�ndert wird
443 //
444 IMPL_LINK( SvxColorTabPage, ModifiedHdl_Impl, void *, EMPTYARG )
445 {
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() );
451 
452 	Color aTmpColor(aAktuellColor);
453 	if (eCM != CM_RGB)
454 		ConvertColorValues (aTmpColor, CM_RGB);
455 
456 	rXFSet.Put( XFillColorItem( String(), aTmpColor ) );
457 	aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
458 
459 	aCtlPreviewNew.Invalidate();
460 
461 	return( 0L );
462 }
463 
464 //------------------------------------------------------------------------
465 
466 //
467 // Button 'Hinzuf�gen'
468 //
469 IMPL_LINK( SvxColorTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
470 {
471 	Window *pWindow = this;
472 	bool bEnabled;
473 	while( pWindow )
474 	{
475 		bEnabled = pWindow->IsEnabled();
476 		pWindow = pWindow->GetParent();
477 	}
478 
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;
485 
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;
490 
491 	// Wenn ja, wird wiederholt ein neuer Name angefordert
492 	if ( !bDifferent )
493 	{
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();
498 
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;
504 
505 		while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
506 		{
507 			pDlg->GetName( aName );
508 			bDifferent = sal_True;
509 
510 			for( long i = 0; i < nCount && bDifferent; i++ )
511 			{
512                 if( aName == pColorTab->GetColor( i )->GetName() )
513 					bDifferent = sal_False;
514 			}
515 
516 			if( bDifferent )
517 				bLoop = sal_False;
518 			else
519 				aWarningBox.Execute();
520 		}
521 		delete( pDlg );
522 	}
523 
524 	// Wenn nicht vorhanden, wird Eintrag aufgenommen
525 	if( bDifferent )
526 	{
527 		if (eCM != CM_RGB)
528 			ConvertColorValues (aAktuellColor, CM_RGB);
529 		pEntry = new XColorEntry( aAktuellColor, aName );
530 
531 		pColorTab->Insert( pColorTab->Count(), pEntry );
532 
533 		aLbColor.Append( pEntry );
534 		aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1,
535 				pEntry->GetColor(), pEntry->GetName() );
536 
537 		aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
538 
539 		// Flag fuer modifiziert setzen
540 		*pnColorTableState |= CT_MODIFIED;
541 
542 		SelectColorLBHdl_Impl( this );
543 	}
544 	// Status der Buttons ermitteln
545 	if( pColorTab->Count() )
546 	{
547 		aBtnModify.Enable();
548 		aBtnWorkOn.Enable();
549 		aBtnDelete.Enable();
550 		aBtnSave.Enable();
551 	}
552 	return( 0L );
553 }
554 
555 //------------------------------------------------------------------------
556 
557 //
558 // Button '�ndern'
559 //
560 IMPL_LINK( SvxColorTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
561 {
562 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
563 
564 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
565 	{
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;
571 
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;
576 
577 		// Wenn ja, wird wiederholt ein neuer Name angefordert
578 		if ( !bDifferent )
579 		{
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();
584 
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;
590 
591 			while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
592 			{
593 				pDlg->GetName( aName );
594 				bDifferent = sal_True;
595 
596 				for ( long i = 0; i < nCount && bDifferent; i++ )
597                     if( aName == pColorTab->GetColor( i )->GetName() && nPos != i )
598 						bDifferent = sal_False;
599 
600 				if( bDifferent )
601 					bLoop = sal_False;
602 				else
603 					aWarningBox.Execute();
604 			}
605 			delete( pDlg );
606 		}
607 
608 		// Wenn nicht vorhanden, wird Eintrag aufgenommen
609 		if( bDifferent )
610 		{
611             XColorEntry* pEntry = pColorTab->GetColor( nPos );
612 
613 			Color aTmpColor (aAktuellColor);
614 			if (eCM != CM_RGB)
615 				ConvertColorValues (aTmpColor, CM_RGB);
616 
617 			pEntry->SetColor( aTmpColor );
618 			pEntry->SetName( aName );
619 
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 );
626 
627 			aCtlPreviewOld.Invalidate();
628 
629 			// Flag fuer modifiziert setzen
630 			*pnColorTableState |= CT_MODIFIED;
631 		}
632 	}
633 	return( 0L );
634 }
635 
636 //------------------------------------------------------------------------
637 
638 //
639 // Button 'Bearbeiten'
640 //
641 IMPL_LINK( SvxColorTabPage, ClickWorkOnHdl_Impl, void *, EMPTYARG )
642 {
643 	SvColorDialog* pColorDlg = new SvColorDialog( DLGWIN );
644 
645 	Color aTmpColor (aAktuellColor);
646 	if (eCM != CM_RGB)
647 		ConvertColorValues (aTmpColor, CM_RGB);
648 
649 	pColorDlg->SetColor (aTmpColor);
650 
651 	if( pColorDlg->Execute() == RET_OK )
652 	{
653 		sal_uInt16 nK = 0;
654 		Color aPreviewColor = pColorDlg->GetColor();
655 		aAktuellColor = aPreviewColor;
656 		if (eCM != CM_RGB)
657 			ConvertColorValues (aAktuellColor, eCM);
658 
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 ) );
663 
664 		// ItemSet fuellen und an XOut weiterleiten
665 		rXFSet.Put( XFillColorItem( String(), aPreviewColor ) );
666 		//aCtlPreviewOld.SetAttributes( aXFillAttr );
667 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
668 
669 		aCtlPreviewNew.Invalidate();
670 	}
671 	delete( pColorDlg );
672 
673 	return( 0L );
674 }
675 
676 //------------------------------------------------------------------------
677 
678 //
679 // Button 'Loeschen'
680 //
681 IMPL_LINK( SvxColorTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
682 {
683 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
684 
685 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
686 	{
687 		QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
688 			String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) );
689 
690 		if( aQueryBox.Execute() == RET_YES )
691 		{
692 			// Jetzt wird richtig geloescht
693 			sal_uLong nCount = pColorTab->Count() - 1;
694 			XColorEntry* pEntry;
695 
696 			pEntry = pColorTab->Remove( nPos );
697 			DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (1) !" );
698 			delete pEntry;
699 
700 			for( sal_uLong i = nPos; i < nCount; i++ )
701 			{
702 				pEntry = pColorTab->Remove( i + 1 );
703 				DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (2) !" );
704 				pColorTab->Insert( i, pEntry );
705 			}
706 
707 			// Listbox und ValueSet aktualisieren
708 			aLbColor.RemoveEntry( nPos );
709 			aValSetColorTable.Clear();
710 			FillValueSet_Impl( aValSetColorTable );
711 
712 			// Positionieren
713 			aLbColor.SelectEntryPos( nPos );
714 			SelectColorLBHdl_Impl( this );
715 
716 			aCtlPreviewOld.Invalidate();
717 
718 			// Flag fuer modifiziert setzen
719 			*pnColorTableState |= CT_MODIFIED;
720 		}
721 	}
722 	// Status der Buttons ermitteln
723 	if( !pColorTab->Count() )
724 	{
725 		aBtnModify.Disable();
726 		aBtnWorkOn.Disable();
727 		aBtnDelete.Disable();
728 		aBtnSave.Disable();
729 	}
730 	return( 0L );
731 }
732 
733 // -----------------------------------------------------------------------
734 
735 //
736 // Button 'Farbtabelle laden'
737 //
738 IMPL_LINK( SvxColorTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
739 {
740 	ResMgr& rMgr = CUI_MGR();
741 	sal_uInt16 nReturn = RET_YES;
742 
743 	if( *pnColorTableState & CT_MODIFIED )
744 	{
745 		nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
746 					String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
747 
748 		if ( nReturn == RET_YES )
749 			pColorTab->Save();
750 	}
751 
752 	if ( nReturn != RET_CANCEL )
753 	{
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 ) );
761 
762     	if ( aDlg.Execute() == ERRCODE_NONE )
763 		{
764 			INetURLObject aURL( aDlg.GetPath() );
765 			INetURLObject aPathURL( aURL );
766 
767 			aPathURL.removeSegment();
768 			aPathURL.removeFinalSlash();
769 
770 			// Tabelle speichern
771 			XColorTable* pColTab = new XColorTable( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
772 			pColTab->SetName( aURL.getName() ); // XXX
773 			if( pColTab->Load() )
774 			{
775 				if( pColTab )
776 				{
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 )
782 					{
783 						pTempTable = pArea->GetColorTable();
784 					}
785 					else if( pLine )
786 					{
787 							pTempTable = pLine->GetColorTable();
788 					}
789 
790 					if( pColorTab != pTempTable )
791 					{
792 						if( bDeleteColorTable )
793 							delete pColorTab;
794 						else
795 							bDeleteColorTable = sal_True;
796 					}
797 
798 					pColorTab = pColTab;
799 					if( pArea )
800 					{
801 						pArea->SetNewColorTable( pColorTab );
802 					}
803 					else if( pLine )
804 					{
805 						pLine->SetNewColorTable( pColorTab );
806 					}
807 
808 					aLbColor.Clear();
809 					aValSetColorTable.Clear();
810 					Construct();
811 					Reset( rOutAttrs );
812 
813 					pColorTab->SetName( aURL.getName() );
814 
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( ": " ) );
819 
820 					if ( aURL.getBase().getLength() > 18 )
821 					{
822 						aString += String(aURL.getBase()).Copy( 0, 15 );
823 						aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
824 					}
825 					else
826 						aString += String(aURL.getBase());
827 
828                     aTableNameFT.SetText( aString );
829 
830 					// Flag fuer gewechselt setzen
831 					*pnColorTableState |= CT_CHANGED;
832 					// Flag fuer modifiziert entfernen
833 					*pnColorTableState &= ~CT_MODIFIED;
834 
835 					if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
836 						aLbColor.SelectEntryPos( 0 );
837 					else
838 						aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() );
839 
840 					ChangeColorHdl_Impl( this );
841 					SelectColorLBHdl_Impl( this );
842 				}
843 			}
844 			else
845 			{
846 				//aIStream.Close();
847 				ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
848 					String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) );
849                 aErrorBox.Execute();
850 			}
851 		}
852 	}
853 
854 	// Status der Buttons ermitteln
855 	if ( pColorTab->Count() )
856 	{
857 		aBtnModify.Enable();
858 		aBtnWorkOn.Enable();
859 		aBtnDelete.Enable();
860 		aBtnSave.Enable();
861 	}
862 	else
863 	{
864 		aBtnModify.Disable();
865 		aBtnWorkOn.Disable();
866 		aBtnDelete.Disable();
867 		aBtnSave.Disable();
868 	}
869 	return( 0L );
870 }
871 
872 // -----------------------------------------------------------------------
873 
874 //
875 // Button 'Farbtabelle speichern'
876 //
877 IMPL_LINK( SvxColorTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
878 {
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 );
883 
884 	INetURLObject aFile( SvtPathOptions().GetPalettePath() );
885 	DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
886 
887 	if( pColorTab->GetName().Len() )
888 	{
889 		aFile.Append( pColorTab->GetName() );
890 
891 		if( !aFile.getExtension().getLength() )
892 			aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) );
893 	}
894 
895 	aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
896 	if ( aDlg.Execute() == ERRCODE_NONE )
897 	{
898 		INetURLObject aURL( aDlg.GetPath() );
899 		INetURLObject aPathURL( aURL );
900 
901 		aPathURL.removeSegment();
902 		aPathURL.removeFinalSlash();
903 
904 		pColorTab->SetName( aURL.getName() );
905 		pColorTab->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
906 
907 		if( pColorTab->Save() )
908 		{
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( ": " ) );
913 
914 			if ( aURL.getBase().getLength() > 18 )
915 			{
916 				aString += String(aURL.getBase()).Copy( 0, 15 );
917 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
918 			}
919 			else
920 				aString += String(aURL.getBase());
921             aTableNameFT.SetText( aString );
922 
923 			// Flag fuer gespeichert setzen
924 			*pnColorTableState |= CT_SAVED;
925 			// Flag fuer modifiziert entfernen
926 			*pnColorTableState &= ~CT_MODIFIED;
927 		}
928 		else
929 		{
930 			ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
931 				String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) );
932             aErrorBox.Execute();
933 		}
934 	}
935 	return( 0L );
936 }
937 
938 //------------------------------------------------------------------------
939 
940 IMPL_LINK( SvxColorTabPage, SelectColorLBHdl_Impl, void *, EMPTYARG )
941 {
942 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
943 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
944 	{
945 		aValSetColorTable.SelectItem( nPos + 1 );
946 		aEdtName.SetText( aLbColor.GetSelectEntry() );
947 
948 		rXFSet.Put( XFillColorItem( String(),
949 									aLbColor.GetSelectEntryColor() ) );
950 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
951 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
952 
953 		aCtlPreviewOld.Invalidate();
954 		aCtlPreviewNew.Invalidate();
955 
956 		ChangeColorHdl_Impl( this );
957 	}
958 	return( 0L );
959 }
960 
961 //------------------------------------------------------------------------
962 
963 IMPL_LINK( SvxColorTabPage, SelectValSetHdl_Impl, void *, EMPTYARG )
964 {
965 	sal_uInt16 nPos = aValSetColorTable.GetSelectItemId();
966 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
967 	{
968 		aLbColor.SelectEntryPos( nPos - 1 );
969 		aEdtName.SetText( aLbColor.GetSelectEntry() );
970 
971 		rXFSet.Put( XFillColorItem( String(),
972 									aLbColor.GetSelectEntryColor() ) );
973 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
974 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
975 
976 		aCtlPreviewOld.Invalidate();
977 		aCtlPreviewNew.Invalidate();
978 
979 		ChangeColorHdl_Impl( this );
980 	}
981 	return( 0L );
982 }
983 
984 //------------------------------------------------------------------------
985 
986 //
987 // Farbwerte je nach �bergebenes Farbmodell umrechnen
988 //
989 void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell)
990 {
991 	switch (eModell)
992 	{
993 		case CM_RGB:
994 		{
995 			CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() );
996 			rColor.SetTransparency ((sal_uInt8) 0);
997 		}
998 		break;
999 
1000 		case CM_CMYK:
1001 		{
1002 			sal_uInt16 nK;
1003 			RgbToCmyk_Impl (rColor, nK );
1004 			rColor.SetTransparency ((sal_uInt8) nK);
1005 		}
1006 		break;
1007 	}
1008 }
1009 
1010 //
1011 // Auswahl Listbox 'Farbmodell' (RGB/CMY)
1012 //
1013 IMPL_LINK( SvxColorTabPage, SelectColorModelHdl_Impl, void *, EMPTYARG )
1014 {
1015 	int nPos = aLbColorModel.GetSelectEntryPos();
1016 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
1017 	{
1018 		if (eCM != (ColorModel) nPos)
1019 		{
1020 			// wenn Farbmodell geaendert wurde, dann Werte umrechnen
1021 			ConvertColorValues (aAktuellColor, (ColorModel) nPos);
1022 		}
1023 
1024 		eCM = (ColorModel) nPos;
1025 
1026 		switch( eCM )
1027 		{
1028 			case CM_RGB:
1029 			{
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 );
1039 
1040 				aFtColorModel4.Hide();
1041 				aMtrFldColorModel4.Hide();
1042 				aMtrFldColorModel4.SetValue( 0L );
1043 
1044 				aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 );
1045 				aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 );
1046 				aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 );
1047 
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() );
1053 
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);
1060 
1061 				aMtrFldColorModel2.SetUnit(FUNIT_NONE);
1062                 aMtrFldColorModel2.SetMin(0);
1063                 aMtrFldColorModel2.SetMax(255);
1064 				aMtrFldColorModel2.SetLast(255);
1065 
1066 				aMtrFldColorModel3.SetUnit(FUNIT_NONE);
1067                 aMtrFldColorModel3.SetMin(0);
1068                 aMtrFldColorModel3.SetMax(255);
1069 				aMtrFldColorModel3.SetLast(255);
1070 			}
1071 			break;
1072 
1073 			case CM_CMYK:
1074 			{
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 );
1086 
1087 				aFtColorModel4.Show();
1088 				aMtrFldColorModel4.Show();
1089 
1090 				aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 );
1091 				aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 );
1092 				aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 );
1093 
1094 				// s.o.
1095 				aMtrFldColorModel1.SetHelpText( String() );
1096 				aMtrFldColorModel2.SetHelpText( String() );
1097 				aMtrFldColorModel3.SetHelpText( String() );
1098 
1099 				// CMYK-Werte im Bereich 0..100% verarbeiten,
1100 				// dazu MetricField's entsprechend einstellen
1101 				String aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) );
1102 
1103 				aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM);
1104 				aMtrFldColorModel1.SetCustomUnitText( aStrUnit );
1105                 aMtrFldColorModel1.SetMin(0);
1106                 aMtrFldColorModel1.SetMax(100);
1107 				aMtrFldColorModel1.SetLast(100);
1108 
1109 				aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM);
1110 				aMtrFldColorModel2.SetCustomUnitText( aStrUnit );
1111                 aMtrFldColorModel2.SetMin(0);
1112                 aMtrFldColorModel2.SetMax(100);
1113 				aMtrFldColorModel2.SetLast(100);
1114 
1115 				aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM);
1116 				aMtrFldColorModel3.SetCustomUnitText( aStrUnit );
1117                 aMtrFldColorModel3.SetMin(0);
1118                 aMtrFldColorModel3.SetMax(100);
1119 				aMtrFldColorModel3.SetLast(100);
1120 			}
1121 			break;
1122 		}
1123 
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() ) );
1128 	}
1129 
1130 	aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) );
1131 	aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) );
1132 	aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) );
1133 	aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) );
1134 
1135 	return( 0L );
1136 }
1137 
1138 //------------------------------------------------------------------------
1139 
1140 long SvxColorTabPage::ChangeColorHdl_Impl( void* )
1141 {
1142 	int nPos = aLbColor.GetSelectEntryPos();
1143 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
1144 	{
1145         XColorEntry* pEntry = pColorTab->GetColor( nPos );
1146 
1147 		aAktuellColor.SetColor ( pEntry->GetColor().GetColor() );
1148 		if (eCM != CM_RGB)
1149 			ConvertColorValues (aAktuellColor, eCM);
1150 
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() ) );
1155 
1156 		// ItemSet fuellen und an XOut weiterleiten
1157 		rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) );
1158 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
1159 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
1160 
1161 		aCtlPreviewNew.Invalidate();
1162 	}
1163 	return( 0L );
1164 }
1165 
1166 //------------------------------------------------------------------------
1167 
1168 void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs )
1169 {
1170 	long nCount = pColorTab->Count();
1171 	XColorEntry* pColorEntry;
1172 
1173 	for( long i = 0; i < nCount; i++ )
1174 	{
1175         pColorEntry = pColorTab->GetColor( i );
1176 		rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
1177 	}
1178 }
1179 
1180 //------------------------------------------------------------------------
1181 
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.
1187 
1188 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
1189 {
1190 	sal_uInt16 nColor1, nColor2, nColor3;
1191 	sal_uInt16 nProzent; // nur temporaer !!!
1192 
1193 	nColor1 = 255 - rColor.GetRed();
1194 	nProzent = ColorToPercent_Impl( nColor1 );
1195 
1196 	nColor2 = 255 - rColor.GetGreen();
1197 	nProzent = ColorToPercent_Impl( nColor2 );
1198 
1199 	nColor3 = 255 - rColor.GetBlue();
1200 	nProzent = ColorToPercent_Impl( nColor3 );
1201 
1202 	rK = Min( Min( nColor1, nColor2 ), nColor3 );
1203 
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 ) );
1207 }
1208 
1209 //------------------------------------------------------------------------
1210 
1211 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.)
1212 
1213 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
1214 {
1215 	long lTemp;
1216 
1217 	lTemp = 255 - ( rColor.GetRed() + nK );
1218 
1219 	if( lTemp < 0L )
1220 		lTemp = 0L;
1221 	rColor.SetRed( (sal_uInt8)lTemp );
1222 
1223 	lTemp = 255 - ( rColor.GetGreen() + nK );
1224 
1225 	if( lTemp < 0L )
1226 		lTemp = 0L;
1227 	rColor.SetGreen( (sal_uInt8)lTemp );
1228 
1229 	lTemp = 255 - ( rColor.GetBlue() + nK );
1230 
1231 	if( lTemp < 0L )
1232 		lTemp = 0L;
1233 	rColor.SetBlue( (sal_uInt8)lTemp );
1234 }
1235 
1236 //------------------------------------------------------------------------
1237 
1238 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
1239 {
1240 	sal_uInt16 nWert = 0;
1241 
1242 	switch (eCM)
1243 	{
1244 		case CM_RGB :
1245 			nWert = nColor;
1246 			break;
1247 
1248 		case CM_CMYK:
1249 			nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 );
1250 			break;
1251 	}
1252 
1253 	return ( nWert );
1254 }
1255 
1256 //------------------------------------------------------------------------
1257 
1258 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
1259 {
1260 	sal_uInt16 nWert = 0;
1261 
1262 	switch (eCM)
1263 	{
1264 		case CM_RGB :
1265 			nWert = nPercent;
1266 			break;
1267 
1268 		case CM_CMYK:
1269 			nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 );
1270 			break;
1271 	}
1272 
1273 	return ( nWert );
1274 }
1275 
1276 //------------------------------------------------------------------------
1277 
1278 void SvxColorTabPage::FillUserData()
1279 {
1280 	// Das Farbmodell wird in der Ini-Datei festgehalten
1281 	SetUserData( UniString::CreateFromInt32( eCM ) );
1282 }
1283 
1284 
1285