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