xref: /trunk/main/cui/source/tabpages/tpcolor.cxx (revision c945f2553a89a0730a645e382b4d7941bc6e551c)
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 //
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 //
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 //
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             const XColorEntry aEntry(aTmpColor, aName);
635 
636             aLbColor.Modify( aEntry, nPos );
637             aLbColor.SelectEntryPos( nPos );
638 
639             aValSetColorTable.SetItemColor( nPos + 1, aEntry.GetColor() );
640             aValSetColorTable.SetItemText( nPos + 1, aEntry.GetName() );
641             aEdtName.SetText( aName );
642 
643             aCtlPreviewOld.Invalidate();
644 
645             // Flag fuer modifiziert setzen
646             *pnColorTableState |= CT_MODIFIED;
647         }
648     }
649     return( 0L );
650 }
651 
652 //------------------------------------------------------------------------
653 
654 //
655 // Button 'Bearbeiten'
656 //
657 IMPL_LINK( SvxColorTabPage, ClickWorkOnHdl_Impl, void *, EMPTYARG )
658 {
659     SvColorDialog* pColorDlg = new SvColorDialog( DLGWIN );
660 
661     Color aTmpColor (aAktuellColor);
662     if (eCM != CM_RGB)
663         ConvertColorValues (aTmpColor, CM_RGB);
664 
665     pColorDlg->SetColor (aTmpColor);
666     pColorDlg->SetMode( svtools::ColorPickerMode_MODIFY );
667 
668     if( pColorDlg->Execute() == RET_OK )
669     {
670         sal_uInt16 nK = 0;
671         Color aPreviewColor = pColorDlg->GetColor();
672         aAktuellColor = aPreviewColor;
673         if (eCM != CM_RGB)
674             ConvertColorValues (aAktuellColor, eCM);
675 
676         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
677         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
678         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
679         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( nK ) );
680 
681         // ItemSet fuellen und an XOut weiterleiten
682         rXFSet.Put( XFillColorItem( String(), aPreviewColor ) );
683         //aCtlPreviewOld.SetAttributes( aXFillAttr );
684         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
685 
686         aCtlPreviewNew.Invalidate();
687     }
688     delete( pColorDlg );
689 
690     return( 0L );
691 }
692 
693 //------------------------------------------------------------------------
694 
695 //
696 // Button 'Loeschen'
697 //
698 IMPL_LINK( SvxColorTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
699 {
700     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
701 
702     if( nPos != LISTBOX_ENTRY_NOTFOUND )
703     {
704         QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
705             String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) );
706 
707         if( aQueryBox.Execute() == RET_YES )
708         {
709             // Jetzt wird richtig geloescht
710             sal_uLong nCount = maColorTab->Count() - 1;
711             XColorEntry* pEntry;
712 
713             pEntry = maColorTab->Remove( nPos );
714             DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (1) !" );
715             delete pEntry;
716 
717             for( sal_uLong i = nPos; i < nCount; i++ )
718             {
719                 pEntry = maColorTab->Remove( i + 1 );
720                 DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (2) !" );
721                 maColorTab->Insert( pEntry, i );
722             }
723 
724             // Listbox und ValueSet aktualisieren
725             aLbColor.RemoveEntry( nPos );
726             aValSetColorTable.Clear();
727             aValSetColorTable.addEntriesForXColorList(maColorTab);
728             ImpColorCountChanged();
729             //FillValueSet_Impl( aValSetColorTable );
730 
731             // Positionieren
732             aLbColor.SelectEntryPos( nPos );
733             SelectColorLBHdl_Impl( this );
734 
735             aCtlPreviewOld.Invalidate();
736 
737             // Flag fuer modifiziert setzen
738             *pnColorTableState |= CT_MODIFIED;
739         }
740     }
741     // Status der Buttons ermitteln
742     if( !maColorTab->Count() )
743     {
744         aBtnModify.Disable();
745         aBtnWorkOn.Disable();
746         aBtnDelete.Disable();
747         aBtnSave.Disable();
748     }
749     return( 0L );
750 }
751 
752 // -----------------------------------------------------------------------
753 
754 //
755 // Button 'Farbtabelle laden'
756 //
757 IMPL_LINK( SvxColorTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
758 {
759     ResMgr& rMgr = CUI_MGR();
760     sal_uInt16 nReturn = RET_YES;
761 
762     if( *pnColorTableState & CT_MODIFIED )
763     {
764         nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
765                     String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
766 
767         if ( nReturn == RET_YES )
768             maColorTab->Save();
769     }
770 
771     if ( nReturn != RET_CANCEL )
772     {
773         ::sfx2::FileDialogHelper aDlg(
774             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
775             0 );
776         String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
777         aDlg.AddFilter( aStrFilterType, aStrFilterType );
778         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
779         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
780 
781         if ( aDlg.Execute() == ERRCODE_NONE )
782         {
783             INetURLObject aURL( aDlg.GetPath() );
784             INetURLObject aPathURL( aURL );
785 
786             aPathURL.removeSegment();
787             aPathURL.removeFinalSlash();
788 
789             // Tabelle speichern
790             XColorListSharedPtr aColTab(XPropertyListFactory::CreateSharedXColorList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
791             aColTab->SetName( aURL.getName() ); // XXX
792             if( aColTab->Load() )
793             {
794                 if( aColTab.get() )
795                 {
796                     // Pruefen, ob Tabelle geloescht werden darf:
797                     XColorListSharedPtr aTempTable;
798                     SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( DLGWIN );
799                     SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( DLGWIN );
800 
801                     if( pArea )
802                     {
803                         aTempTable = pArea->GetColorTable();
804                     }
805                     else if( pLine )
806                     {
807                         aTempTable = pLine->GetColorTable();
808                     }
809 
810                     maColorTab = aColTab;
811 
812                     if( pArea )
813                     {
814                         pArea->SetNewColorTable( maColorTab );
815                     }
816                     else if( pLine )
817                     {
818                         pLine->SetNewColorTable( maColorTab );
819                     }
820 
821                     aLbColor.Clear();
822                     aValSetColorTable.Clear();
823                     Construct();
824                     Reset( rOutAttrs );
825 
826                     maColorTab->SetName( aURL.getName() );
827 
828                     // Ermitteln (evtl. abschneiden) des Namens und in
829                     // der GroupBox darstellen
830                     String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
831                     aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
832 
833                     if ( aURL.getBase().getLength() > 18 )
834                     {
835                         aString += String(aURL.getBase()).Copy( 0, 15 );
836                         aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
837                     }
838                     else
839                         aString += String(aURL.getBase());
840 
841                     aTableNameFT.SetText( aString );
842 
843                     // Flag fuer gewechselt setzen
844                     *pnColorTableState |= CT_CHANGED;
845                     // Flag fuer modifiziert entfernen
846                     *pnColorTableState &= ~CT_MODIFIED;
847 
848                     if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
849                         aLbColor.SelectEntryPos( 0 );
850                     else
851                         aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() );
852 
853                     ChangeColorHdl_Impl( this );
854                     SelectColorLBHdl_Impl( this );
855                 }
856             }
857             else
858             {
859                 //aIStream.Close();
860                 ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
861                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) );
862                 aErrorBox.Execute();
863             }
864         }
865     }
866 
867     // Status der Buttons ermitteln
868     if ( maColorTab->Count() )
869     {
870         aBtnModify.Enable();
871         aBtnWorkOn.Enable();
872         aBtnDelete.Enable();
873         aBtnSave.Enable();
874     }
875     else
876     {
877         aBtnModify.Disable();
878         aBtnWorkOn.Disable();
879         aBtnDelete.Disable();
880         aBtnSave.Disable();
881     }
882     return( 0L );
883 }
884 
885 // -----------------------------------------------------------------------
886 
887 //
888 // Button 'Farbtabelle speichern'
889 //
890 IMPL_LINK( SvxColorTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
891 {
892     ::sfx2::FileDialogHelper aDlg(
893         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
894     String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
895     aDlg.AddFilter( aStrFilterType, aStrFilterType );
896 
897     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
898     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
899 
900     if( maColorTab->GetName().Len() )
901     {
902         aFile.Append( maColorTab->GetName() );
903 
904         if( !aFile.getExtension().getLength() )
905             aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) );
906     }
907 
908     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
909     if ( aDlg.Execute() == ERRCODE_NONE )
910     {
911         INetURLObject aURL( aDlg.GetPath() );
912         INetURLObject aPathURL( aURL );
913 
914         aPathURL.removeSegment();
915         aPathURL.removeFinalSlash();
916 
917         maColorTab->SetName( aURL.getName() );
918         maColorTab->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
919 
920         if( maColorTab->Save() )
921         {
922             // Ermitteln (evtl. abschneiden) des Namens und in
923             // der GroupBox darstellen
924             String aString( CUI_RES( RID_SVXSTR_TABLE ) );
925             aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
926 
927             if ( aURL.getBase().getLength() > 18 )
928             {
929                 aString += String(aURL.getBase()).Copy( 0, 15 );
930                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
931             }
932             else
933                 aString += String(aURL.getBase());
934             aTableNameFT.SetText( aString );
935 
936             // Flag fuer gespeichert setzen
937             *pnColorTableState |= CT_SAVED;
938             // Flag fuer modifiziert entfernen
939             *pnColorTableState &= ~CT_MODIFIED;
940         }
941         else
942         {
943             ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ),
944                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) );
945             aErrorBox.Execute();
946         }
947     }
948     return( 0L );
949 }
950 
951 //------------------------------------------------------------------------
952 
953 IMPL_LINK( SvxColorTabPage, SelectColorLBHdl_Impl, void *, EMPTYARG )
954 {
955     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
956     if( nPos != LISTBOX_ENTRY_NOTFOUND )
957     {
958         aValSetColorTable.SelectItem( nPos + 1 );
959         aEdtName.SetText( aLbColor.GetSelectEntry() );
960 
961         rXFSet.Put( XFillColorItem( String(),
962                                     aLbColor.GetSelectEntryColor() ) );
963         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
964         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
965 
966         aCtlPreviewOld.Invalidate();
967         aCtlPreviewNew.Invalidate();
968 
969         ChangeColorHdl_Impl( this );
970     }
971     return( 0L );
972 }
973 
974 //------------------------------------------------------------------------
975 
976 IMPL_LINK( SvxColorTabPage, SelectValSetHdl_Impl, void *, EMPTYARG )
977 {
978     sal_uInt16 nPos = aValSetColorTable.GetSelectItemId();
979     if( nPos != LISTBOX_ENTRY_NOTFOUND )
980     {
981         aLbColor.SelectEntryPos( nPos - 1 );
982         aEdtName.SetText( aLbColor.GetSelectEntry() );
983 
984         rXFSet.Put( XFillColorItem( String(),
985                                     aLbColor.GetSelectEntryColor() ) );
986         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
987         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
988 
989         aCtlPreviewOld.Invalidate();
990         aCtlPreviewNew.Invalidate();
991 
992         ChangeColorHdl_Impl( this );
993     }
994     return( 0L );
995 }
996 
997 //------------------------------------------------------------------------
998 
999 //
1000 // Farbwerte je nach �bergebenes Farbmodell umrechnen
1001 //
1002 void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell)
1003 {
1004     switch (eModell)
1005     {
1006         case CM_RGB:
1007         {
1008             CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() );
1009             rColor.SetTransparency ((sal_uInt8) 0);
1010         }
1011         break;
1012 
1013         case CM_CMYK:
1014         {
1015             sal_uInt16 nK;
1016             RgbToCmyk_Impl (rColor, nK );
1017             rColor.SetTransparency ((sal_uInt8) nK);
1018         }
1019         break;
1020     }
1021 }
1022 
1023 //
1024 // Auswahl Listbox 'Farbmodell' (RGB/CMY)
1025 //
1026 IMPL_LINK( SvxColorTabPage, SelectColorModelHdl_Impl, void *, EMPTYARG )
1027 {
1028     int nPos = aLbColorModel.GetSelectEntryPos();
1029     if( nPos != LISTBOX_ENTRY_NOTFOUND )
1030     {
1031         if (eCM != (ColorModel) nPos)
1032         {
1033             // wenn Farbmodell geaendert wurde, dann Werte umrechnen
1034             ConvertColorValues (aAktuellColor, (ColorModel) nPos);
1035         }
1036 
1037         eCM = (ColorModel) nPos;
1038 
1039         switch( eCM )
1040         {
1041             case CM_RGB:
1042             {
1043                 String aStr( aLbColorModel.GetSelectEntry() );
1044                 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1045                 xub_StrLen nIdx = 1;
1046                 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1047                 aFtColorModel1.SetText( aColorStr );
1048                 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1049                 aFtColorModel2.SetText( aColorStr );
1050                 aColorStr.SetChar( nIdx, aStr.GetChar( 2 ) );
1051                 aFtColorModel3.SetText( aColorStr );
1052 
1053                 aFtColorModel4.Hide();
1054                 aMtrFldColorModel4.Hide();
1055                 aMtrFldColorModel4.SetValue( 0L );
1056 
1057                 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 );
1058                 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 );
1059                 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 );
1060 
1061                 // Da der alte HelpText noch am Control steht wuerde
1062                 // ein Umsetzen der HelpID alleine nichts bewirken
1063                 aMtrFldColorModel1.SetHelpText( String() );
1064                 aMtrFldColorModel2.SetHelpText( String() );
1065                 aMtrFldColorModel3.SetHelpText( String() );
1066 
1067                 // RGB-Werte im Bereich 0..255 verarbeiten (nicht in %),
1068                 // dazu MetricField's entsprechend einstellen
1069                 aMtrFldColorModel1.SetUnit(FUNIT_NONE);
1070                 aMtrFldColorModel1.SetMin(0);
1071                 aMtrFldColorModel1.SetMax(255);
1072                 aMtrFldColorModel1.SetLast(255);
1073 
1074                 aMtrFldColorModel2.SetUnit(FUNIT_NONE);
1075                 aMtrFldColorModel2.SetMin(0);
1076                 aMtrFldColorModel2.SetMax(255);
1077                 aMtrFldColorModel2.SetLast(255);
1078 
1079                 aMtrFldColorModel3.SetUnit(FUNIT_NONE);
1080                 aMtrFldColorModel3.SetMin(0);
1081                 aMtrFldColorModel3.SetMax(255);
1082                 aMtrFldColorModel3.SetLast(255);
1083             }
1084             break;
1085 
1086             case CM_CMYK:
1087             {
1088                 String aStr( aLbColorModel.GetSelectEntry() );
1089                 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1090                 xub_StrLen nIdx = 1;
1091                 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
1092                 aFtColorModel1.SetText( aColorStr );
1093                 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
1094                 aFtColorModel2.SetText( aColorStr );
1095                 aColorStr.SetChar( nIdx,aStr.GetChar( 2 ) );
1096                 aFtColorModel3.SetText( aColorStr );
1097                 aColorStr.SetChar( nIdx,aStr.GetChar( 3 ) );
1098                 aFtColorModel4.SetText( aColorStr );
1099 
1100                 aFtColorModel4.Show();
1101                 aMtrFldColorModel4.Show();
1102 
1103                 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 );
1104                 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 );
1105                 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 );
1106 
1107                 // s.o.
1108                 aMtrFldColorModel1.SetHelpText( String() );
1109                 aMtrFldColorModel2.SetHelpText( String() );
1110                 aMtrFldColorModel3.SetHelpText( String() );
1111 
1112                 // CMYK-Werte im Bereich 0..100% verarbeiten,
1113                 // dazu MetricField's entsprechend einstellen
1114                 String aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) );
1115 
1116                 aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM);
1117                 aMtrFldColorModel1.SetCustomUnitText( aStrUnit );
1118                 aMtrFldColorModel1.SetMin(0);
1119                 aMtrFldColorModel1.SetMax(100);
1120                 aMtrFldColorModel1.SetLast(100);
1121 
1122                 aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM);
1123                 aMtrFldColorModel2.SetCustomUnitText( aStrUnit );
1124                 aMtrFldColorModel2.SetMin(0);
1125                 aMtrFldColorModel2.SetMax(100);
1126                 aMtrFldColorModel2.SetLast(100);
1127 
1128                 aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM);
1129                 aMtrFldColorModel3.SetCustomUnitText( aStrUnit );
1130                 aMtrFldColorModel3.SetMin(0);
1131                 aMtrFldColorModel3.SetMax(100);
1132                 aMtrFldColorModel3.SetLast(100);
1133             }
1134             break;
1135         }
1136 
1137         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1138         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1139         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1140         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1141     }
1142 
1143     aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) );
1144     aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) );
1145     aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) );
1146     aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) );
1147 
1148     return( 0L );
1149 }
1150 
1151 //------------------------------------------------------------------------
1152 
1153 long SvxColorTabPage::ChangeColorHdl_Impl( void* )
1154 {
1155     int nPos = aLbColor.GetSelectEntryPos();
1156     if( nPos != LISTBOX_ENTRY_NOTFOUND )
1157     {
1158         XColorEntry* pEntry = maColorTab->GetColor( nPos );
1159 
1160         aAktuellColor.SetColor ( pEntry->GetColor().GetColor() );
1161         if (eCM != CM_RGB)
1162             ConvertColorValues (aAktuellColor, eCM);
1163 
1164         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
1165         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
1166         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
1167         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
1168 
1169         // ItemSet fuellen und an XOut weiterleiten
1170         rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) );
1171         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
1172         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
1173 
1174         aCtlPreviewNew.Invalidate();
1175     }
1176     return( 0L );
1177 }
1178 
1179 //------------------------------------------------------------------------
1180 
1181 //void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs )
1182 //{
1183 //  long nCount = maColorTab->Count();
1184 //  XColorEntry* pColorEntry;
1185 //
1186 //  for( long i = 0; i < nCount; i++ )
1187 //  {
1188 //        pColorEntry = maColorTab->GetColor( i );
1189 //      rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
1190 //  }
1191 //}
1192 
1193 //------------------------------------------------------------------------
1194 
1195 // Ein RGB-Wert wird in einen CMYK-Wert konvertiert, wobei die Color-
1196 // Klasse vergewaltigt wird, da R in C, G in M und B in Y umgewandelt
1197 // wird. Der Wert K wird in einer Extra-Variablen gehalten.
1198 // Bei weiteren Farbmodellen sollte man hierfuer eigene Klassen entwickeln,
1199 // die dann auch entsprechende Casts enthalten.
1200 
1201 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
1202 {
1203     sal_uInt16 nColor1, nColor2, nColor3;
1204     sal_uInt16 nProzent; // nur temporaer !!!
1205 
1206     nColor1 = 255 - rColor.GetRed();
1207     nProzent = ColorToPercent_Impl( nColor1 );
1208 
1209     nColor2 = 255 - rColor.GetGreen();
1210     nProzent = ColorToPercent_Impl( nColor2 );
1211 
1212     nColor3 = 255 - rColor.GetBlue();
1213     nProzent = ColorToPercent_Impl( nColor3 );
1214 
1215     rK = Min( Min( nColor1, nColor2 ), nColor3 );
1216 
1217     rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
1218     rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
1219     rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
1220 }
1221 
1222 //------------------------------------------------------------------------
1223 
1224 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.)
1225 
1226 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
1227 {
1228     long lTemp;
1229 
1230     lTemp = 255 - ( rColor.GetRed() + nK );
1231 
1232     if( lTemp < 0L )
1233         lTemp = 0L;
1234     rColor.SetRed( (sal_uInt8)lTemp );
1235 
1236     lTemp = 255 - ( rColor.GetGreen() + nK );
1237 
1238     if( lTemp < 0L )
1239         lTemp = 0L;
1240     rColor.SetGreen( (sal_uInt8)lTemp );
1241 
1242     lTemp = 255 - ( rColor.GetBlue() + nK );
1243 
1244     if( lTemp < 0L )
1245         lTemp = 0L;
1246     rColor.SetBlue( (sal_uInt8)lTemp );
1247 }
1248 
1249 //------------------------------------------------------------------------
1250 
1251 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
1252 {
1253     sal_uInt16 nWert = 0;
1254 
1255     switch (eCM)
1256     {
1257         case CM_RGB :
1258             nWert = nColor;
1259             break;
1260 
1261         case CM_CMYK:
1262             nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 );
1263             break;
1264     }
1265 
1266     return ( nWert );
1267 }
1268 
1269 //------------------------------------------------------------------------
1270 
1271 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
1272 {
1273     sal_uInt16 nWert = 0;
1274 
1275     switch (eCM)
1276     {
1277         case CM_RGB :
1278             nWert = nPercent;
1279             break;
1280 
1281         case CM_CMYK:
1282             nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 );
1283             break;
1284     }
1285 
1286     return ( nWert );
1287 }
1288 
1289 //------------------------------------------------------------------------
1290 
1291 void SvxColorTabPage::FillUserData()
1292 {
1293     // Das Farbmodell wird in der Ini-Datei festgehalten
1294     SetUserData( UniString::CreateFromInt32( eCM ) );
1295 }
1296 
1297 
1298