xref: /trunk/main/cui/source/tabpages/tpcolor.cxx (revision aa64976b)
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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <tools/urlobj.hxx>
30 #include <unotools/pathoptions.hxx>
31 #include <sfx2/app.hxx>
32 #include <sfx2/module.hxx>
33 #include <svtools/colrdlg.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <sfx2/filedlghelper.hxx>
36 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
37 
38 #define _SVX_TPCOLOR_CXX
39 
40 #include <cuires.hrc>
41 #include "helpid.hrc"
42 #include "svx/xattr.hxx"
43 #include <svx/xpool.hxx>
44 #include <svx/xtable.hxx>
45 #include "svx/drawitem.hxx"
46 #include "cuitabarea.hxx"
47 #include "tabarea.hrc"
48 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
49 //#include "dlgname.hrc"
50 #include <svx/svxdlg.hxx> //CHINA001
51 #include <dialmgr.hxx>
52 #include <cuitabline.hxx>
53 #include <svx/dialmgr.hxx>
54 #include <svx/dialogs.hrc>
55 
56 #define DLGWIN GetParentDialog( this )
57 
58 /*************************************************************************
59 |*
60 |*	Dialog zum Aendern und Definieren der Farben
61 |*
62 \************************************************************************/
63 
GetParentDialog(Window * pWindow)64 static Window* GetParentDialog( Window* pWindow )
65 {
66 	while( pWindow )
67 	{
68 		if( pWindow->IsDialog() )
69 			break;
70 
71 		pWindow = pWindow->GetParent();
72 	}
73 
74 	return pWindow;
75 }
76 
SvxColorTabPage(Window * pParent,const SfxItemSet & rInAttrs)77 SvxColorTabPage::SvxColorTabPage
78 (
79 	Window* pParent,
80 	const SfxItemSet& rInAttrs
81 ) :
82 
83 	SfxTabPage			( pParent, CUI_RES( RID_SVXPAGE_COLOR ), rInAttrs ),
84 
85     aFlProp             ( this, CUI_RES( FL_PROP ) ),
86     aFtName             ( this, CUI_RES( FT_NAME ) ),
87 	aEdtName			( this, CUI_RES( EDT_NAME ) ),
88 	aFtColor			( this, CUI_RES( FT_COLOR ) ),
89 	aLbColor			( this, CUI_RES( LB_COLOR ) ),
90 
91     aTableNameFT        ( this, CUI_RES( FT_TABLE_NAME ) ),
92     aValSetColorTable   ( this, CUI_RES( CTL_COLORTABLE ) ),
93 
94     aCtlPreviewOld      ( this, CUI_RES( CTL_PREVIEW_OLD ) ),
95     aCtlPreviewNew      ( this, CUI_RES( CTL_PREVIEW_NEW ) ),
96 
97     aLbColorModel       ( this, CUI_RES( LB_COLORMODEL ) ),
98 	aFtColorModel1		( this, CUI_RES( FT_1 ) ),
99 	aMtrFldColorModel1	( this, CUI_RES( MTR_FLD_1 ) ),
100 	aFtColorModel2		( this, CUI_RES( FT_2 ) ),
101 	aMtrFldColorModel2	( this, CUI_RES( MTR_FLD_2 ) ),
102 	aFtColorModel3		( this, CUI_RES( FT_3 ) ),
103 	aMtrFldColorModel3	( this, CUI_RES( MTR_FLD_3 ) ),
104 	aFtColorModel4		( this, CUI_RES( FT_4 ) ),
105 	aMtrFldColorModel4	( this, CUI_RES( MTR_FLD_4 ) ),
106 	aBtnAdd 			( this, CUI_RES( BTN_ADD ) ),
107 	aBtnModify			( this, CUI_RES( BTN_MODIFY ) ),
108 	aBtnWorkOn			( this, CUI_RES( BTN_WORK_ON ) ),
109 	aBtnDelete			( this, CUI_RES( BTN_DELETE ) ),
110 	aBtnLoad			( this, CUI_RES( BTN_LOAD ) ),
111 	aBtnSave			( this, CUI_RES( BTN_SAVE ) ),
112 
113     rOutAttrs           ( rInAttrs ),
114     maColorTab(),
115 
116     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
117     aXFStyleItem        ( XFILL_SOLID ),
118     aXFillColorItem     ( String(), Color( COL_BLACK ) ),
119     aXFillAttr          ( pXPool ),
120     rXFSet              ( aXFillAttr.GetItemSet() ),
121 
122     eCM                 ( CM_RGB )
123 
124 {
125 	aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
126 	aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
127 
128 	FreeResource();
129 
130 	// diese Page braucht ExchangeSupport
131 	SetExchangeSupport();
132 
133 	// Setzen des Output-Devices
134 	rXFSet.Put( aXFStyleItem );
135 	rXFSet.Put( aXFillColorItem );
136 	aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
137 	aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
138 
139 	// Handler ueberladen
140 	aLbColor.SetSelectHdl(
141 		LINK( this, SvxColorTabPage, SelectColorLBHdl_Impl ) );
142 	aValSetColorTable.SetSelectHdl(
143 		LINK( this, SvxColorTabPage, SelectValSetHdl_Impl ) );
144 	aLbColorModel.SetSelectHdl(
145 		LINK( this, SvxColorTabPage, SelectColorModelHdl_Impl ) );
146 
147 	Link aLink = LINK( this, SvxColorTabPage, ModifiedHdl_Impl );
148 	aMtrFldColorModel1.SetModifyHdl( aLink );
149 	aMtrFldColorModel2.SetModifyHdl( aLink );
150 	aMtrFldColorModel3.SetModifyHdl( aLink );
151 	aMtrFldColorModel4.SetModifyHdl( aLink );
152 
153 	aBtnAdd.SetClickHdl( LINK( this, SvxColorTabPage, ClickAddHdl_Impl ) );
154 	aBtnModify.SetClickHdl(
155 		LINK( this, SvxColorTabPage, ClickModifyHdl_Impl ) );
156 	aBtnWorkOn.SetClickHdl(
157 		LINK( this, SvxColorTabPage, ClickWorkOnHdl_Impl ) );
158 	aBtnDelete.SetClickHdl(
159 		LINK( this, SvxColorTabPage, ClickDeleteHdl_Impl ) );
160 	aBtnLoad.SetClickHdl( LINK( this, SvxColorTabPage, ClickLoadHdl_Impl ) );
161 	aBtnSave.SetClickHdl( LINK( this, SvxColorTabPage, ClickSaveHdl_Impl ) );
162 
163 	// ValueSet
164 	aValSetColorTable.SetStyle( aValSetColorTable.GetStyle() | WB_ITEMBORDER );
165 	aValSetColorTable.Show();
166 
167 	aLbColorModel.SetAccessibleName( String( CUI_RES(STR_CUI_COLORMODEL) ) );
168 	aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
169 	aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
170 	aBtnWorkOn.SetAccessibleRelationMemberOf( &aFlProp );
171 	aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
172 }
173 
174 // -----------------------------------------------------------------------
175 
ImpColorCountChanged()176 void SvxColorTabPage::ImpColorCountChanged()
177 {
178     if(maColorTab.get())
179     {
180         aValSetColorTable.SetColCount(aValSetColorTable.getColumnCount());
181 
182         // here we have enough space to the left, so layout with fixed column size
183         // and fixed height, adapt width. Apply the adapted width by moving the left
184         // edge of the control to the left, keeping the right edge aligned
185         // with the original position
186         const Point aCurrentPos(aValSetColorTable.GetPosPixel());
187         const Size aCurrentSize(aValSetColorTable.GetOutputSizePixel());
188         const long nColorCount(maColorTab->Count());
189         const Size aNewSize(aValSetColorTable.layoutToGivenHeight(aCurrentSize.Height(), nColorCount));
190         const Point aNewPos((aCurrentPos.X() + aCurrentSize.Width()) - aNewSize.Width(), aCurrentPos.Y());
191 
192         aValSetColorTable.SetOutputSizePixel(aNewSize);
193         aValSetColorTable.SetPosSizePixel(aNewPos, aNewSize);
194     }
195 }
196 
197 // -----------------------------------------------------------------------
198 
Construct()199 void SvxColorTabPage::Construct()
200 {
201     if(maColorTab.get())
202     {
203         aLbColor.Fill(maColorTab);
204         aValSetColorTable.addEntriesForXColorList(maColorTab);
205         ImpColorCountChanged();
206     }
207 }
208 
209 // -----------------------------------------------------------------------
210 
ActivatePage(const SfxItemSet &)211 void SvxColorTabPage::ActivatePage( const SfxItemSet& )
212 {
213 	if( *pDlgType == 0 ) // Flaechen-Dialog
214 	{
215 		*pbAreaTP = sal_False;
216 
217 		if( maColorTab.get() )
218 		{
219 			if( *pPageType == PT_COLOR && *pPos != LISTBOX_ENTRY_NOTFOUND )
220 			{
221 				aLbColor.SelectEntryPos( *pPos );
222 				aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
223 				aEdtName.SetText( aLbColor.GetSelectEntry() );
224 
225 				ChangeColorHdl_Impl( this );
226 			}
227 			else if( *pPageType == PT_COLOR && *pPos == LISTBOX_ENTRY_NOTFOUND )
228 			{
229 				const SfxPoolItem* pPoolItem = NULL;
230 				if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
231 				{
232 					aLbColorModel.SelectEntryPos( CM_RGB );
233 
234                     aAktuellColor.SetColor ( ( ( const XFillColorItem* ) pPoolItem )->GetColorValue().GetColor() );
235 
236 					aEdtName.SetText( ( ( const XFillColorItem* ) pPoolItem )->GetName() );
237 
238 					aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
239 					aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
240 					aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
241 
242 					// ItemSet fuellen und an XOut weiterleiten
243 					rXFSet.Put( XFillColorItem( String(), aAktuellColor ) );
244 					aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
245 					aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
246 
247 					aCtlPreviewNew.Invalidate();
248 					aCtlPreviewOld.Invalidate();
249 				}
250 			}
251 
252 			// Ermitteln (evtl. abschneiden) des Namens und in
253 			// der GroupBox darstellen
254 			String			aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
255 			INetURLObject	aURL( maColorTab->GetPath() );
256 
257 			aURL.Append( maColorTab->GetName() );
258 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
259 
260 			if ( aURL.getBase().getLength() > 18 )
261 			{
262 				aString += String(aURL.getBase()).Copy( 0, 15 );
263 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
264 			}
265 			else
266 				aString += String(aURL.getBase());
267 
268             aTableNameFT.SetText( aString );
269 
270 			// Damit evtl. geaenderte Farbe verworfen wird
271 			SelectColorLBHdl_Impl( this );
272 
273 			*pPageType = PT_COLOR;
274 			*pPos = LISTBOX_ENTRY_NOTFOUND;
275 		}
276 	}
277 	else
278 	{
279 		// Buttons werden gehided, weil Paletten z.Z. nur
280 		// ueber den AreaDlg funktionieren!!!
281 		// ActivatePage() muss von anderen Dialogen explizit
282 		// gerufen werden, da ActivatePage() nicht gerufen wird,
283 		// wenn Seite als Erste im Dialog angezeigt wird
284 		aBtnLoad.Hide();
285 		aBtnSave.Hide();
286 	}
287 }
288 
289 // -----------------------------------------------------------------------
290 
DeactivatePage(SfxItemSet * _pSet)291 int SvxColorTabPage::DeactivatePage( SfxItemSet* _pSet )
292 {
293 	if ( CheckChanges_Impl() == -1L )
294 		return( KEEP_PAGE );
295 
296     if( _pSet )
297         FillItemSet( *_pSet );
298 
299 	return( LEAVE_PAGE );
300 }
301 
302 // -----------------------------------------------------------------------
303 
CheckChanges_Impl()304 long SvxColorTabPage::CheckChanges_Impl()
305 {
306 	// wird hier benutzt, um Aenderungen NICHT zu verlieren
307 
308 	Color aTmpColor (aAktuellColor);
309 	if (eCM != CM_RGB)
310 		ConvertColorValues (aTmpColor, CM_RGB);
311 
312 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
313 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
314 	{
315         Color aColor = maColorTab->GetColor( nPos )->GetColor();
316 		String aString = aLbColor.GetSelectEntry();
317 
318 		// aNewColor, da COL_USER != COL_irgendwas, auch wenn RGB-Werte gleich
319 		// Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
320 
321 		if( ColorToPercent_Impl( aTmpColor.GetRed() ) != ColorToPercent_Impl( aColor.GetRed() ) ||
322 			ColorToPercent_Impl( aTmpColor.GetGreen() ) != ColorToPercent_Impl( aColor.GetGreen() ) ||
323 			ColorToPercent_Impl( aTmpColor.GetBlue() ) != ColorToPercent_Impl( aColor.GetBlue() ) ||
324 			aString != aEdtName.GetText() )
325 		{
326 			ResMgr& rMgr = CUI_MGR();
327             Image aWarningBoxImage = WarningBox::GetStandardImage();
328 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
329 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
330 			AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
331 														SVX_RESSTR( RID_SVXSTR_COLOR ),
332 														String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR, rMgr ) ),
333 														&aWarningBoxImage );
334 			DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
335 			aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
336 									String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
337 			aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
338 									String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
339 
340 			short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
341 
342 			switch( nRet )
343 			{
344 				case RET_BTN_1: // Aendern
345 				{
346 					ClickModifyHdl_Impl( this );
347                     aColor = maColorTab->GetColor( nPos )->GetColor();
348 				}
349 				break;
350 
351 				case RET_BTN_2: // Hinzufuegen
352 				{
353 					ClickAddHdl_Impl( this );
354 					nPos = aLbColor.GetSelectEntryPos();
355                     aColor = maColorTab->GetColor( nPos )->GetColor();
356 				}
357 				break;
358 
359 				case RET_CANCEL:
360 					// return( -1L ); <-- wuerde die Seite nicht verlassen
361 				break;
362 				// return( sal_True ); // Abbruch
363 			}
364 			delete aMessDlg; //add by CHINA001
365 		}
366 	}
367 	if( *pDlgType == 0 ) // Flaechen-Dialog
368 	{
369 		nPos = aLbColor.GetSelectEntryPos();
370 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
371 		{
372 			*pPos = nPos;
373 		}
374 	}
375 	return( 0L );
376 }
377 
378 // -----------------------------------------------------------------------
379 
FillItemSet(SfxItemSet & rSet)380 sal_Bool SvxColorTabPage::FillItemSet( SfxItemSet& rSet )
381 {
382 	if( ( *pDlgType != 0 ) ||
383 		( *pPageType == PT_COLOR && *pbAreaTP == sal_False ) )
384 	{
385 		String aString;
386 		Color  aColor;
387 
388 		// CheckChanges_Impl(); <-- doppelte Abfrage ?
389 
390 		sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
391 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
392 		{
393             aColor  = maColorTab->GetColor( nPos )->GetColor();
394 			aString = aLbColor.GetSelectEntry();
395 		}
396 		else
397 		{
398 			aColor.SetColor (aAktuellColor.GetColor());
399 			if (eCM != CM_RGB)
400 				ConvertColorValues (aColor, CM_RGB);
401 		}
402         rSet.Put( XFillColorItem( aString, aColor ) );
403         rSet.Put( XFillStyleItem( XFILL_SOLID ) );
404 	}
405 
406 	return( sal_True );
407 }
408 
409 // -----------------------------------------------------------------------
410 
Reset(const SfxItemSet & rSet)411 void SvxColorTabPage::Reset( const SfxItemSet& rSet )
412 {
413     sal_uInt16 nState = rSet.GetItemState( XATTR_FILLCOLOR );
414 
415 	if ( nState >= SFX_ITEM_DEFAULT )
416 	{
417         XFillColorItem aColorItem( (const XFillColorItem&)rSet.Get( XATTR_FILLCOLOR ) );
418 		aLbColor.SelectEntry( aColorItem.GetColorValue() );
419 		aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
420 		aEdtName.SetText( aLbColor.GetSelectEntry() );
421 	}
422 
423 	// Farbmodell setzen
424 	String aStr = GetUserData();
425 	aLbColorModel.SelectEntryPos( (sal_uInt16) aStr.ToInt32() );
426 
427 	ChangeColorHdl_Impl( this );
428 	SelectColorModelHdl_Impl( this );
429 
430 	aCtlPreviewOld.Invalidate();
431 
432 	// Status der Buttons ermitteln
433 	if( maColorTab->Count() )
434 	{
435 		aBtnModify.Enable();
436 		aBtnWorkOn.Enable();
437 		aBtnDelete.Enable();
438 		aBtnSave.Enable();
439 	}
440 	else
441 	{
442 		aBtnModify.Disable();
443 		aBtnWorkOn.Disable();
444 		aBtnDelete.Disable();
445 		aBtnSave.Disable();
446 	}
447 }
448 
449 // -----------------------------------------------------------------------
450 
Create(Window * pWindow,const SfxItemSet & rOutAttrs)451 SfxTabPage* SvxColorTabPage::Create( Window* pWindow,
452 				const SfxItemSet& rOutAttrs )
453 {
454 	return( new SvxColorTabPage( pWindow, rOutAttrs ) );
455 }
456 
457 //------------------------------------------------------------------------
458 
459 //
460 // Wird aufgerufen, wenn Inhalt der MtrFileds f�r Farbwerte ver�ndert wird
461 //
IMPL_LINK(SvxColorTabPage,ModifiedHdl_Impl,void *,EMPTYARG)462 IMPL_LINK( SvxColorTabPage, ModifiedHdl_Impl, void *, EMPTYARG )
463 {
464 	// lese aktuelle MtrFields aus, wenn cmyk, dann k-Wert als Trans.-Farbe
465 	aAktuellColor.SetColor ( Color( (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel4.GetValue() ),
466 									(sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel1.GetValue() ),
467 									(sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel2.GetValue() ),
468 									(sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel3.GetValue() ) ).GetColor() );
469 
470 	Color aTmpColor(aAktuellColor);
471 	if (eCM != CM_RGB)
472 		ConvertColorValues (aTmpColor, CM_RGB);
473 
474 	rXFSet.Put( XFillColorItem( String(), aTmpColor ) );
475 	aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
476 
477 	aCtlPreviewNew.Invalidate();
478 
479 	return( 0L );
480 }
481 
482 //------------------------------------------------------------------------
483 
484 //
485 // Button 'Hinzuf�gen'
486 //
IMPL_LINK(SvxColorTabPage,ClickAddHdl_Impl,void *,EMPTYARG)487 IMPL_LINK( SvxColorTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
488 {
489 	Window *pWindow = this;
490 	bool bEnabled;
491 	while( pWindow )
492 	{
493 		bEnabled = pWindow->IsEnabled();
494 		pWindow = pWindow->GetParent();
495 	}
496 
497 	ResMgr& rMgr = CUI_MGR();
498 	String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
499 	String aName( aEdtName.GetText() );
500 	XColorEntry* pEntry;
501 	long nCount = maColorTab->Count();
502 	sal_Bool bDifferent = sal_True;
503 
504 	// Pruefen, ob Name schon vorhanden ist
505 	for ( long i = 0; i < nCount && bDifferent; i++ )
506         if ( aName == maColorTab->GetColor( i )->GetName() )
507 			bDifferent = sal_False;
508 
509 	// Wenn ja, wird wiederholt ein neuer Name angefordert
510 	if ( !bDifferent )
511 	{
512 		WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ),
513 			String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
514 		aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
515 		aWarningBox.Execute();
516 
517 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
518 		DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
519 		AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
520 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
521 		sal_Bool bLoop = sal_True;
522 
523 		while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
524 		{
525 			pDlg->GetName( aName );
526 			bDifferent = sal_True;
527 
528 			for( long i = 0; i < nCount && bDifferent; i++ )
529 			{
530                 if( aName == maColorTab->GetColor( i )->GetName() )
531 					bDifferent = sal_False;
532 			}
533 
534 			if( bDifferent )
535 				bLoop = sal_False;
536 			else
537 				aWarningBox.Execute();
538 		}
539 		delete( pDlg );
540 	}
541 
542 	// Wenn nicht vorhanden, wird Eintrag aufgenommen
543 	if( bDifferent )
544 	{
545 		if (eCM != CM_RGB)
546 			ConvertColorValues (aAktuellColor, CM_RGB);
547 		pEntry = new XColorEntry( aAktuellColor, aName );
548 
549 		maColorTab->Insert( pEntry, maColorTab->Count() );
550 
551 		aLbColor.Append( *pEntry );
552 		aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1, pEntry->GetColor(), pEntry->GetName() );
553         ImpColorCountChanged();
554 
555 		aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
556 
557 		// Flag fuer modifiziert setzen
558 		*pnColorTableState |= CT_MODIFIED;
559 
560 		SelectColorLBHdl_Impl( this );
561 	}
562 	// Status der Buttons ermitteln
563 	if( maColorTab->Count() )
564 	{
565 		aBtnModify.Enable();
566 		aBtnWorkOn.Enable();
567 		aBtnDelete.Enable();
568 		aBtnSave.Enable();
569 	}
570 	return( 0L );
571 }
572 
573 //------------------------------------------------------------------------
574 
575 //
576 // Button '�ndern'
577 //
IMPL_LINK(SvxColorTabPage,ClickModifyHdl_Impl,void *,EMPTYARG)578 IMPL_LINK( SvxColorTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
579 {
580 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
581 
582 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
583 	{
584 		ResMgr& rMgr = CUI_MGR();
585 		String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
586 		String aName( aEdtName.GetText() );
587 		long nCount = maColorTab->Count();
588 		sal_Bool bDifferent = sal_True;
589 
590 		// Pruefen, ob Name schon vorhanden ist
591 		for ( long i = 0; i < nCount && bDifferent; i++ )
592             if ( aName == maColorTab->GetColor( i )->GetName() && nPos != i )
593 				bDifferent = sal_False;
594 
595 		// Wenn ja, wird wiederholt ein neuer Name angefordert
596 		if ( !bDifferent )
597 		{
598 			WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ),
599 				String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
600 			aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
601 			aWarningBox.Execute();
602 
603 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
604 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
605 			AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
606 			DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
607 			sal_Bool bLoop = sal_True;
608 
609 			while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
610 			{
611 				pDlg->GetName( aName );
612 				bDifferent = sal_True;
613 
614 				for ( long i = 0; i < nCount && bDifferent; i++ )
615                     if( aName == maColorTab->GetColor( i )->GetName() && nPos != i )
616 						bDifferent = sal_False;
617 
618 				if( bDifferent )
619 					bLoop = sal_False;
620 				else
621 					aWarningBox.Execute();
622 			}
623 			delete( pDlg );
624 		}
625 
626 		// Wenn nicht vorhanden, wird Eintrag aufgenommen
627 		if( bDifferent )
628 		{
629 			Color aTmpColor (aAktuellColor);
630 
631             if (eCM != CM_RGB)
632 				ConvertColorValues (aTmpColor, CM_RGB);
633 
634             // #123497# Need to replace the existing entry with a new one (old returned needs to be deleted)
635             XColorEntry* pEntry = new XColorEntry(aTmpColor, aName);
636             delete maColorTab->Replace(pEntry, nPos);
637 
638             aLbColor.Modify( *pEntry, nPos );
639 			aLbColor.SelectEntryPos( nPos );
640 
641             aValSetColorTable.SetItemColor( nPos + 1, pEntry->GetColor() );
642 			aValSetColorTable.SetItemText( nPos + 1, pEntry->GetName() );
643 			aEdtName.SetText( aName );
644 
645 			aCtlPreviewOld.Invalidate();
646 
647 			// Flag fuer modifiziert setzen
648 			*pnColorTableState |= CT_MODIFIED;
649 		}
650 	}
651 	return( 0L );
652 }
653 
654 //------------------------------------------------------------------------
655 
656 //
657 // Button 'Bearbeiten'
658 //
IMPL_LINK(SvxColorTabPage,ClickWorkOnHdl_Impl,void *,EMPTYARG)659 IMPL_LINK( SvxColorTabPage, ClickWorkOnHdl_Impl, void *, EMPTYARG )
660 {
661 	SvColorDialog* pColorDlg = new SvColorDialog( DLGWIN );
662 
663 	Color aTmpColor (aAktuellColor);
664 	if (eCM != CM_RGB)
665 		ConvertColorValues (aTmpColor, CM_RGB);
666 
667 	pColorDlg->SetColor (aTmpColor);
668     pColorDlg->SetMode( svtools::ColorPickerMode_MODIFY );
669 
670 	if( pColorDlg->Execute() == RET_OK )
671 	{
672 		sal_uInt16 nK = 0;
673 		Color aPreviewColor = pColorDlg->GetColor();
674 		aAktuellColor = aPreviewColor;
675 		if (eCM != CM_RGB)
676 			ConvertColorValues (aAktuellColor, eCM);
677 
678 		aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
679 		aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
680 		aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
681 		aMtrFldColorModel4.SetValue( ColorToPercent_Impl( nK ) );
682 
683 		// ItemSet fuellen und an XOut weiterleiten
684 		rXFSet.Put( XFillColorItem( String(), aPreviewColor ) );
685 		//aCtlPreviewOld.SetAttributes( aXFillAttr );
686 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
687 
688 		aCtlPreviewNew.Invalidate();
689 	}
690 	delete( pColorDlg );
691 
692 	return( 0L );
693 }
694 
695 //------------------------------------------------------------------------
696 
697 //
698 // Button 'Loeschen'
699 //
IMPL_LINK(SvxColorTabPage,ClickDeleteHdl_Impl,void *,EMPTYARG)700 IMPL_LINK( SvxColorTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
701 {
702 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
703 
704 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
705 	{
706 		QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
707 			String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) );
708 
709 		if( aQueryBox.Execute() == RET_YES )
710 		{
711 			// Jetzt wird richtig geloescht
712 			sal_uLong nCount = maColorTab->Count() - 1;
713 			XColorEntry* pEntry;
714 
715 			pEntry = maColorTab->Remove( nPos );
716 			DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (1) !" );
717 			delete pEntry;
718 
719 			for( sal_uLong i = nPos; i < nCount; i++ )
720 			{
721 				pEntry = maColorTab->Remove( i + 1 );
722 				DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (2) !" );
723 				maColorTab->Insert( pEntry, i );
724 			}
725 
726 			// Listbox und ValueSet aktualisieren
727 			aLbColor.RemoveEntry( nPos );
728 			aValSetColorTable.Clear();
729             aValSetColorTable.addEntriesForXColorList(maColorTab);
730             ImpColorCountChanged();
731 			//FillValueSet_Impl( aValSetColorTable );
732 
733 			// Positionieren
734 			aLbColor.SelectEntryPos( nPos );
735 			SelectColorLBHdl_Impl( this );
736 
737 			aCtlPreviewOld.Invalidate();
738 
739 			// Flag fuer modifiziert setzen
740 			*pnColorTableState |= CT_MODIFIED;
741 		}
742 	}
743 	// Status der Buttons ermitteln
744 	if( !maColorTab->Count() )
745 	{
746 		aBtnModify.Disable();
747 		aBtnWorkOn.Disable();
748 		aBtnDelete.Disable();
749 		aBtnSave.Disable();
750 	}
751 	return( 0L );
752 }
753 
754 // -----------------------------------------------------------------------
755 
756 //
757 // Button 'Farbtabelle laden'
758 //
IMPL_LINK(SvxColorTabPage,ClickLoadHdl_Impl,void *,EMPTYARG)759 IMPL_LINK( SvxColorTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
760 {
761 	ResMgr& rMgr = CUI_MGR();
762 	sal_uInt16 nReturn = RET_YES;
763 
764 	if( *pnColorTableState & CT_MODIFIED )
765 	{
766 		nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
767 					String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
768 
769 		if ( nReturn == RET_YES )
770 			maColorTab->Save();
771 	}
772 
773 	if ( nReturn != RET_CANCEL )
774 	{
775     	::sfx2::FileDialogHelper aDlg(
776             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
777             0 );
778 		String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
779 		aDlg.AddFilter( aStrFilterType, aStrFilterType );
780 		INetURLObject aFile( SvtPathOptions().GetPalettePath() );
781 		aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
782 
783     	if ( aDlg.Execute() == ERRCODE_NONE )
784 		{
785 			INetURLObject aURL( aDlg.GetPath() );
786 			INetURLObject aPathURL( aURL );
787 
788 			aPathURL.removeSegment();
789 			aPathURL.removeFinalSlash();
790 
791 			// Tabelle speichern
792 			XColorListSharedPtr aColTab(XPropertyListFactory::CreateSharedXColorList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
793 			aColTab->SetName( aURL.getName() ); // XXX
794 			if( aColTab->Load() )
795 			{
796 				if( aColTab.get() )
797 				{
798 					// Pruefen, ob Tabelle geloescht werden darf:
799 					XColorListSharedPtr aTempTable;
800 					SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( DLGWIN );
801 					SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( DLGWIN );
802 
803 					if( pArea )
804 					{
805 						aTempTable = pArea->GetColorTable();
806 					}
807 					else if( pLine )
808 					{
809 						aTempTable = pLine->GetColorTable();
810 					}
811 
812 					maColorTab = aColTab;
813 
814 					if( pArea )
815 					{
816 						pArea->SetNewColorTable( maColorTab );
817 					}
818 					else if( pLine )
819 					{
820 						pLine->SetNewColorTable( maColorTab );
821 					}
822 
823 					aLbColor.Clear();
824 					aValSetColorTable.Clear();
825 					Construct();
826 					Reset( rOutAttrs );
827 
828 					maColorTab->SetName( aURL.getName() );
829 
830 					// Ermitteln (evtl. abschneiden) des Namens und in
831 					// der GroupBox darstellen
832 					String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
833 					aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
834 
835 					if ( aURL.getBase().getLength() > 18 )
836 					{
837 						aString += String(aURL.getBase()).Copy( 0, 15 );
838 						aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
839 					}
840 					else
841 						aString += String(aURL.getBase());
842 
843                     aTableNameFT.SetText( aString );
844 
845 					// Flag fuer gewechselt setzen
846 					*pnColorTableState |= CT_CHANGED;
847 					// Flag fuer modifiziert entfernen
848 					*pnColorTableState &= ~CT_MODIFIED;
849 
850 					if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
851 						aLbColor.SelectEntryPos( 0 );
852 					else
853 						aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() );
854 
855 					ChangeColorHdl_Impl( this );
856 					SelectColorLBHdl_Impl( this );
857 				}
858 			}
859 			else
860 			{
861 				//aIStream.Close();
862 				ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
863 					String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) );
864                 aErrorBox.Execute();
865 			}
866 		}
867 	}
868 
869 	// Status der Buttons ermitteln
870 	if ( maColorTab->Count() )
871 	{
872 		aBtnModify.Enable();
873 		aBtnWorkOn.Enable();
874 		aBtnDelete.Enable();
875 		aBtnSave.Enable();
876 	}
877 	else
878 	{
879 		aBtnModify.Disable();
880 		aBtnWorkOn.Disable();
881 		aBtnDelete.Disable();
882 		aBtnSave.Disable();
883 	}
884 	return( 0L );
885 }
886 
887 // -----------------------------------------------------------------------
888 
889 //
890 // Button 'Farbtabelle speichern'
891 //
IMPL_LINK(SvxColorTabPage,ClickSaveHdl_Impl,void *,EMPTYARG)892 IMPL_LINK( SvxColorTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
893 {
894    	::sfx2::FileDialogHelper aDlg(
895         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
896 	String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
897 	aDlg.AddFilter( aStrFilterType, aStrFilterType );
898 
899 	INetURLObject aFile( SvtPathOptions().GetPalettePath() );
900 	DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
901 
902 	if( maColorTab->GetName().Len() )
903 	{
904 		aFile.Append( maColorTab->GetName() );
905 
906 		if( !aFile.getExtension().getLength() )
907 			aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) );
908 	}
909 
910 	aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
911 	if ( aDlg.Execute() == ERRCODE_NONE )
912 	{
913 		INetURLObject aURL( aDlg.GetPath() );
914 		INetURLObject aPathURL( aURL );
915 
916 		aPathURL.removeSegment();
917 		aPathURL.removeFinalSlash();
918 
919 		maColorTab->SetName( aURL.getName() );
920 		maColorTab->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
921 
922 		if( maColorTab->Save() )
923 		{
924 			// Ermitteln (evtl. abschneiden) des Namens und in
925 			// der GroupBox darstellen
926 			String aString( CUI_RES( RID_SVXSTR_TABLE ) );
927 			aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
928 
929 			if ( aURL.getBase().getLength() > 18 )
930 			{
931 				aString += String(aURL.getBase()).Copy( 0, 15 );
932 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
933 			}
934 			else
935 				aString += String(aURL.getBase());
936             aTableNameFT.SetText( aString );
937 
938 			// Flag fuer gespeichert setzen
939 			*pnColorTableState |= CT_SAVED;
940 			// Flag fuer modifiziert entfernen
941 			*pnColorTableState &= ~CT_MODIFIED;
942 		}
943 		else
944 		{
945 			ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
946 				String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) );
947             aErrorBox.Execute();
948 		}
949 	}
950 	return( 0L );
951 }
952 
953 //------------------------------------------------------------------------
954 
IMPL_LINK(SvxColorTabPage,SelectColorLBHdl_Impl,void *,EMPTYARG)955 IMPL_LINK( SvxColorTabPage, SelectColorLBHdl_Impl, void *, EMPTYARG )
956 {
957 	sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
958 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
959 	{
960 		aValSetColorTable.SelectItem( nPos + 1 );
961 		aEdtName.SetText( aLbColor.GetSelectEntry() );
962 
963 		rXFSet.Put( XFillColorItem( String(),
964 									aLbColor.GetSelectEntryColor() ) );
965 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
966 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
967 
968 		aCtlPreviewOld.Invalidate();
969 		aCtlPreviewNew.Invalidate();
970 
971 		ChangeColorHdl_Impl( this );
972 	}
973 	return( 0L );
974 }
975 
976 //------------------------------------------------------------------------
977 
IMPL_LINK(SvxColorTabPage,SelectValSetHdl_Impl,void *,EMPTYARG)978 IMPL_LINK( SvxColorTabPage, SelectValSetHdl_Impl, void *, EMPTYARG )
979 {
980 	sal_uInt16 nPos = aValSetColorTable.GetSelectItemId();
981 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
982 	{
983 		aLbColor.SelectEntryPos( nPos - 1 );
984 		aEdtName.SetText( aLbColor.GetSelectEntry() );
985 
986 		rXFSet.Put( XFillColorItem( String(),
987 									aLbColor.GetSelectEntryColor() ) );
988 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
989 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
990 
991 		aCtlPreviewOld.Invalidate();
992 		aCtlPreviewNew.Invalidate();
993 
994 		ChangeColorHdl_Impl( this );
995 	}
996 	return( 0L );
997 }
998 
999 //------------------------------------------------------------------------
1000 
1001 //
1002 // Farbwerte je nach �bergebenes Farbmodell umrechnen
1003 //
ConvertColorValues(Color & rColor,ColorModel eModell)1004 void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell)
1005 {
1006 	switch (eModell)
1007 	{
1008 		case CM_RGB:
1009 		{
1010 			CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() );
1011 			rColor.SetTransparency ((sal_uInt8) 0);
1012 		}
1013 		break;
1014 
1015 		case CM_CMYK:
1016 		{
1017 			sal_uInt16 nK;
1018 			RgbToCmyk_Impl (rColor, nK );
1019 			rColor.SetTransparency ((sal_uInt8) nK);
1020 		}
1021 		break;
1022 	}
1023 }
1024 
1025 //
1026 // Auswahl Listbox 'Farbmodell' (RGB/CMY)
1027 //
IMPL_LINK(SvxColorTabPage,SelectColorModelHdl_Impl,void *,EMPTYARG)1028 IMPL_LINK( SvxColorTabPage, SelectColorModelHdl_Impl, void *, EMPTYARG )
1029 {
1030 	int nPos = aLbColorModel.GetSelectEntryPos();
1031 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
1032 	{
1033 		if (eCM != (ColorModel) nPos)
1034 		{
1035 			// wenn Farbmodell geaendert wurde, dann Werte umrechnen
1036 			ConvertColorValues (aAktuellColor, (ColorModel) nPos);
1037 		}
1038 
1039 		eCM = (ColorModel) nPos;
1040 
1041 		switch( eCM )
1042 		{
1043 			case CM_RGB:
1044 			{
1045 				String aStr( aLbColorModel.GetSelectEntry() );
1046 				String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1047 				xub_StrLen nIdx = 1;
1048 				aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1049 				aFtColorModel1.SetText( aColorStr );
1050 				aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1051 				aFtColorModel2.SetText( aColorStr );
1052 				aColorStr.SetChar( nIdx, aStr.GetChar( 2 ) );
1053 				aFtColorModel3.SetText( aColorStr );
1054 
1055 				aFtColorModel4.Hide();
1056 				aMtrFldColorModel4.Hide();
1057 				aMtrFldColorModel4.SetValue( 0L );
1058 
1059 				aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 );
1060 				aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 );
1061 				aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 );
1062 
1063 				// Da der alte HelpText noch am Control steht wuerde
1064 				// ein Umsetzen der HelpID alleine nichts bewirken
1065 				aMtrFldColorModel1.SetHelpText( String() );
1066 				aMtrFldColorModel2.SetHelpText( String() );
1067 				aMtrFldColorModel3.SetHelpText( String() );
1068 
1069 				// RGB-Werte im Bereich 0..255 verarbeiten (nicht in %),
1070 				// dazu MetricField's entsprechend einstellen
1071 				aMtrFldColorModel1.SetUnit(FUNIT_NONE);
1072                 aMtrFldColorModel1.SetMin(0);
1073                 aMtrFldColorModel1.SetMax(255);
1074 				aMtrFldColorModel1.SetLast(255);
1075 
1076 				aMtrFldColorModel2.SetUnit(FUNIT_NONE);
1077                 aMtrFldColorModel2.SetMin(0);
1078                 aMtrFldColorModel2.SetMax(255);
1079 				aMtrFldColorModel2.SetLast(255);
1080 
1081 				aMtrFldColorModel3.SetUnit(FUNIT_NONE);
1082                 aMtrFldColorModel3.SetMin(0);
1083                 aMtrFldColorModel3.SetMax(255);
1084 				aMtrFldColorModel3.SetLast(255);
1085 			}
1086 			break;
1087 
1088 			case CM_CMYK:
1089 			{
1090 				String aStr( aLbColorModel.GetSelectEntry() );
1091 				String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1092 				xub_StrLen nIdx = 1;
1093 				aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1094 				aFtColorModel1.SetText( aColorStr );
1095 				aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1096 				aFtColorModel2.SetText( aColorStr );
1097 				aColorStr.SetChar( nIdx,aStr.GetChar( 2 ) );
1098 				aFtColorModel3.SetText( aColorStr );
1099 				aColorStr.SetChar( nIdx,aStr.GetChar( 3 ) );
1100 				aFtColorModel4.SetText( aColorStr );
1101 
1102 				aFtColorModel4.Show();
1103 				aMtrFldColorModel4.Show();
1104 
1105 				aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 );
1106 				aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 );
1107 				aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 );
1108 
1109 				// s.o.
1110 				aMtrFldColorModel1.SetHelpText( String() );
1111 				aMtrFldColorModel2.SetHelpText( String() );
1112 				aMtrFldColorModel3.SetHelpText( String() );
1113 
1114 				// CMYK-Werte im Bereich 0..100% verarbeiten,
1115 				// dazu MetricField's entsprechend einstellen
1116 				String aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) );
1117 
1118 				aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM);
1119 				aMtrFldColorModel1.SetCustomUnitText( aStrUnit );
1120                 aMtrFldColorModel1.SetMin(0);
1121                 aMtrFldColorModel1.SetMax(100);
1122 				aMtrFldColorModel1.SetLast(100);
1123 
1124 				aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM);
1125 				aMtrFldColorModel2.SetCustomUnitText( aStrUnit );
1126                 aMtrFldColorModel2.SetMin(0);
1127                 aMtrFldColorModel2.SetMax(100);
1128 				aMtrFldColorModel2.SetLast(100);
1129 
1130 				aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM);
1131 				aMtrFldColorModel3.SetCustomUnitText( aStrUnit );
1132                 aMtrFldColorModel3.SetMin(0);
1133                 aMtrFldColorModel3.SetMax(100);
1134 				aMtrFldColorModel3.SetLast(100);
1135 			}
1136 			break;
1137 		}
1138 
1139 		aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1140 		aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1141 		aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1142 		aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1143 	}
1144 
1145 	aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) );
1146 	aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) );
1147 	aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) );
1148 	aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) );
1149 
1150 	return( 0L );
1151 }
1152 
1153 //------------------------------------------------------------------------
1154 
ChangeColorHdl_Impl(void *)1155 long SvxColorTabPage::ChangeColorHdl_Impl( void* )
1156 {
1157 	int nPos = aLbColor.GetSelectEntryPos();
1158 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
1159 	{
1160         XColorEntry* pEntry = maColorTab->GetColor( nPos );
1161 
1162 		aAktuellColor.SetColor ( pEntry->GetColor().GetColor() );
1163 		if (eCM != CM_RGB)
1164 			ConvertColorValues (aAktuellColor, eCM);
1165 
1166 		aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1167 		aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1168 		aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1169 		aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1170 
1171 		// ItemSet fuellen und an XOut weiterleiten
1172 		rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) );
1173 		aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
1174 		aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
1175 
1176 		aCtlPreviewNew.Invalidate();
1177 	}
1178 	return( 0L );
1179 }
1180 
1181 //------------------------------------------------------------------------
1182 
1183 //void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs )
1184 //{
1185 //	long nCount = maColorTab->Count();
1186 //	XColorEntry* pColorEntry;
1187 //
1188 //	for( long i = 0; i < nCount; i++ )
1189 //	{
1190 //        pColorEntry = maColorTab->GetColor( i );
1191 //		rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
1192 //	}
1193 //}
1194 
1195 //------------------------------------------------------------------------
1196 
1197 // Ein RGB-Wert wird in einen CMYK-Wert konvertiert, wobei die Color-
1198 // Klasse vergewaltigt wird, da R in C, G in M und B in Y umgewandelt
1199 // wird. Der Wert K wird in einer Extra-Variablen gehalten.
1200 // Bei weiteren Farbmodellen sollte man hierfuer eigene Klassen entwickeln,
1201 // die dann auch entsprechende Casts enthalten.
1202 
RgbToCmyk_Impl(Color & rColor,sal_uInt16 & rK)1203 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
1204 {
1205 	sal_uInt16 nColor1, nColor2, nColor3;
1206 	sal_uInt16 nProzent; // nur temporaer !!!
1207 
1208 	nColor1 = 255 - rColor.GetRed();
1209 	nProzent = ColorToPercent_Impl( nColor1 );
1210 
1211 	nColor2 = 255 - rColor.GetGreen();
1212 	nProzent = ColorToPercent_Impl( nColor2 );
1213 
1214 	nColor3 = 255 - rColor.GetBlue();
1215 	nProzent = ColorToPercent_Impl( nColor3 );
1216 
1217 	rK = Min( Min( nColor1, nColor2 ), nColor3 );
1218 
1219 	rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
1220 	rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
1221 	rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
1222 }
1223 
1224 //------------------------------------------------------------------------
1225 
1226 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.)
1227 
CmykToRgb_Impl(Color & rColor,const sal_uInt16 nK)1228 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
1229 {
1230 	long lTemp;
1231 
1232 	lTemp = 255 - ( rColor.GetRed() + nK );
1233 
1234 	if( lTemp < 0L )
1235 		lTemp = 0L;
1236 	rColor.SetRed( (sal_uInt8)lTemp );
1237 
1238 	lTemp = 255 - ( rColor.GetGreen() + nK );
1239 
1240 	if( lTemp < 0L )
1241 		lTemp = 0L;
1242 	rColor.SetGreen( (sal_uInt8)lTemp );
1243 
1244 	lTemp = 255 - ( rColor.GetBlue() + nK );
1245 
1246 	if( lTemp < 0L )
1247 		lTemp = 0L;
1248 	rColor.SetBlue( (sal_uInt8)lTemp );
1249 }
1250 
1251 //------------------------------------------------------------------------
1252 
ColorToPercent_Impl(sal_uInt16 nColor)1253 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
1254 {
1255 	sal_uInt16 nWert = 0;
1256 
1257 	switch (eCM)
1258 	{
1259 		case CM_RGB :
1260 			nWert = nColor;
1261 			break;
1262 
1263 		case CM_CMYK:
1264 			nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 );
1265 			break;
1266 	}
1267 
1268 	return ( nWert );
1269 }
1270 
1271 //------------------------------------------------------------------------
1272 
PercentToColor_Impl(sal_uInt16 nPercent)1273 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
1274 {
1275 	sal_uInt16 nWert = 0;
1276 
1277 	switch (eCM)
1278 	{
1279 		case CM_RGB :
1280 			nWert = nPercent;
1281 			break;
1282 
1283 		case CM_CMYK:
1284 			nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 );
1285 			break;
1286 	}
1287 
1288 	return ( nWert );
1289 }
1290 
1291 //------------------------------------------------------------------------
1292 
FillUserData()1293 void SvxColorTabPage::FillUserData()
1294 {
1295 	// Das Farbmodell wird in der Ini-Datei festgehalten
1296 	SetUserData( UniString::CreateFromInt32( eCM ) );
1297 }
1298 
1299 
1300