1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpcolor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <tools/urlobj.hxx>
41 #include <svtools/pathoptions.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/module.hxx>
44 #include <svtools/colrdlg.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <sfx2/filedlghelper.hxx>
47 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
49 #define _SVX_TPCOLOR_CXX
52 #include <svx/dialogs.hrc>
56 #include <svx/xpool.hxx>
57 #include <svx/xtable.hxx>
58 #include "drawitem.hxx"
59 #include "cuitabarea.hxx"
60 #include "tabarea.hrc"
61 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
62 #include "dlgname.hrc"
63 #include <svx/svxdlg.hxx> //CHINA001
64 #include <svx/dialmgr.hxx>
65 #include <cuitabline.hxx>
67 #define DLGWIN GetParentDialog( this )
69 /*************************************************************************
71 |* Dialog zum Aendern und Definieren der Farben
73 \************************************************************************/
75 static Window
* GetParentDialog( Window
* pWindow
)
79 if( pWindow
->IsDialog() )
82 pWindow
= pWindow
->GetParent();
88 SvxColorTabPage::SvxColorTabPage
91 const SfxItemSet
& rInAttrs
94 SfxTabPage ( pParent
, SVX_RES( RID_SVXPAGE_COLOR
), rInAttrs
),
96 aFlProp ( this, SVX_RES( FL_PROP
) ),
97 aFtName ( this, SVX_RES( FT_NAME
) ),
98 aEdtName ( this, SVX_RES( EDT_NAME
) ),
99 aFtColor ( this, SVX_RES( FT_COLOR
) ),
100 aLbColor ( this, SVX_RES( LB_COLOR
) ),
102 aTableNameFT ( this, SVX_RES( FT_TABLE_NAME
) ),
103 aValSetColorTable ( this, SVX_RES( CTL_COLORTABLE
) ),
105 aCtlPreviewOld ( this, SVX_RES( CTL_PREVIEW_OLD
) ),
106 aCtlPreviewNew ( this, SVX_RES( CTL_PREVIEW_NEW
) ),
108 aLbColorModel ( this, SVX_RES( LB_COLORMODEL
) ),
109 aFtColorModel1 ( this, SVX_RES( FT_1
) ),
110 aMtrFldColorModel1 ( this, SVX_RES( MTR_FLD_1
) ),
111 aFtColorModel2 ( this, SVX_RES( FT_2
) ),
112 aMtrFldColorModel2 ( this, SVX_RES( MTR_FLD_2
) ),
113 aFtColorModel3 ( this, SVX_RES( FT_3
) ),
114 aMtrFldColorModel3 ( this, SVX_RES( MTR_FLD_3
) ),
115 aFtColorModel4 ( this, SVX_RES( FT_4
) ),
116 aMtrFldColorModel4 ( this, SVX_RES( MTR_FLD_4
) ),
117 aBtnAdd ( this, SVX_RES( BTN_ADD
) ),
118 aBtnModify ( this, SVX_RES( BTN_MODIFY
) ),
119 aBtnWorkOn ( this, SVX_RES( BTN_WORK_ON
) ),
120 aBtnDelete ( this, SVX_RES( BTN_DELETE
) ),
121 aBtnLoad ( this, SVX_RES( BTN_LOAD
) ),
122 aBtnSave ( this, SVX_RES( BTN_SAVE
) ),
124 rOutAttrs ( rInAttrs
),
127 bDeleteColorTable ( TRUE
),
129 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
130 aXFStyleItem ( XFILL_SOLID
),
131 aXFillColorItem ( String(), Color( COL_BLACK
) ),
132 aXFillAttr ( pXPool
),
133 rXFSet ( aXFillAttr
.GetItemSet() ),
138 aBtnLoad
.SetModeImage( Image( SVX_RES( RID_SVXIMG_LOAD_H
) ), BMP_COLOR_HIGHCONTRAST
);
139 aBtnSave
.SetModeImage( Image( SVX_RES( RID_SVXIMG_SAVE_H
) ), BMP_COLOR_HIGHCONTRAST
);
143 // diese Page braucht ExchangeSupport
144 SetExchangeSupport();
146 // Setzen des Output-Devices
147 rXFSet
.Put( aXFStyleItem
);
148 rXFSet
.Put( aXFillColorItem
);
149 aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
150 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
152 // Handler ueberladen
153 aLbColor
.SetSelectHdl(
154 LINK( this, SvxColorTabPage
, SelectColorLBHdl_Impl
) );
155 aValSetColorTable
.SetSelectHdl(
156 LINK( this, SvxColorTabPage
, SelectValSetHdl_Impl
) );
157 aLbColorModel
.SetSelectHdl(
158 LINK( this, SvxColorTabPage
, SelectColorModelHdl_Impl
) );
160 Link aLink
= LINK( this, SvxColorTabPage
, ModifiedHdl_Impl
);
161 aMtrFldColorModel1
.SetModifyHdl( aLink
);
162 aMtrFldColorModel2
.SetModifyHdl( aLink
);
163 aMtrFldColorModel3
.SetModifyHdl( aLink
);
164 aMtrFldColorModel4
.SetModifyHdl( aLink
);
166 aBtnAdd
.SetClickHdl( LINK( this, SvxColorTabPage
, ClickAddHdl_Impl
) );
167 aBtnModify
.SetClickHdl(
168 LINK( this, SvxColorTabPage
, ClickModifyHdl_Impl
) );
169 aBtnWorkOn
.SetClickHdl(
170 LINK( this, SvxColorTabPage
, ClickWorkOnHdl_Impl
) );
171 aBtnDelete
.SetClickHdl(
172 LINK( this, SvxColorTabPage
, ClickDeleteHdl_Impl
) );
173 aBtnLoad
.SetClickHdl( LINK( this, SvxColorTabPage
, ClickLoadHdl_Impl
) );
174 aBtnSave
.SetClickHdl( LINK( this, SvxColorTabPage
, ClickSaveHdl_Impl
) );
177 aValSetColorTable
.SetStyle( aValSetColorTable
.GetStyle() | WB_VSCROLL
| WB_ITEMBORDER
);
178 aValSetColorTable
.SetColCount( 8 );
179 aValSetColorTable
.SetLineCount( 10 );
180 aValSetColorTable
.SetExtraSpacing( 0 );
181 aValSetColorTable
.Show();
185 // -----------------------------------------------------------------------
187 void SvxColorTabPage::Construct()
189 aLbColor
.Fill( pColorTab
);
190 FillValueSet_Impl( aValSetColorTable
);
193 // -----------------------------------------------------------------------
195 void SvxColorTabPage::ActivatePage( const SfxItemSet
& )
197 if( *pDlgType
== 0 ) // Flaechen-Dialog
203 if( *pPageType
== PT_COLOR
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
205 aLbColor
.SelectEntryPos( *pPos
);
206 aValSetColorTable
.SelectItem( aLbColor
.GetSelectEntryPos() + 1 );
207 aEdtName
.SetText( aLbColor
.GetSelectEntry() );
209 ChangeColorHdl_Impl( this );
211 else if( *pPageType
== PT_COLOR
&& *pPos
== LISTBOX_ENTRY_NOTFOUND
)
213 const SfxPoolItem
* pPoolItem
= NULL
;
214 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLCOLOR
), TRUE
, &pPoolItem
) )
216 aLbColorModel
.SelectEntryPos( CM_RGB
);
218 aAktuellColor
.SetColor ( ( ( const XFillColorItem
* ) pPoolItem
)->GetColorValue().GetColor() );
220 aEdtName
.SetText( ( ( const XFillColorItem
* ) pPoolItem
)->GetName() );
222 aMtrFldColorModel1
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetRed() ) );
223 aMtrFldColorModel2
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetGreen() ) );
224 aMtrFldColorModel3
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetBlue() ) );
226 // ItemSet fuellen und an XOut weiterleiten
227 rXFSet
.Put( XFillColorItem( String(), aAktuellColor
) );
228 aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
229 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
231 aCtlPreviewNew
.Invalidate();
232 aCtlPreviewOld
.Invalidate();
236 // Ermitteln (evtl. abschneiden) des Namens und in
237 // der GroupBox darstellen
238 String
aString( SVX_RES( RID_SVXSTR_TABLE
) ); aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
239 INetURLObject
aURL( pColorTab
->GetPath() );
241 aURL
.Append( pColorTab
->GetName() );
242 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
244 if ( aURL
.getBase().getLength() > 18 )
246 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
247 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
250 aString
+= String(aURL
.getBase());
252 aTableNameFT
.SetText( aString
);
254 // Damit evtl. geaenderte Farbe verworfen wird
255 SelectColorLBHdl_Impl( this );
257 *pPageType
= PT_COLOR
;
258 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
263 // Buttons werden gehided, weil Paletten z.Z. nur
264 // ueber den AreaDlg funktionieren!!!
265 // ActivatePage() muss von anderen Dialogen explizit
266 // gerufen werden, da ActivatePage() nicht gerufen wird,
267 // wenn Seite als Erste im Dialog angezeigt wird
273 // -----------------------------------------------------------------------
275 int SvxColorTabPage::DeactivatePage( SfxItemSet
* _pSet
)
277 if ( CheckChanges_Impl() == -1L )
281 FillItemSet( *_pSet
);
283 return( LEAVE_PAGE
);
286 // -----------------------------------------------------------------------
288 long SvxColorTabPage::CheckChanges_Impl()
290 // wird hier benutzt, um Aenderungen NICHT zu verlieren
292 Color
aTmpColor (aAktuellColor
);
294 ConvertColorValues (aTmpColor
, CM_RGB
);
296 USHORT nPos
= aLbColor
.GetSelectEntryPos();
297 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
299 Color aColor
= pColorTab
->GetColor( nPos
)->GetColor();
300 String aString
= aLbColor
.GetSelectEntry();
302 // aNewColor, da COL_USER != COL_irgendwas, auch wenn RGB-Werte gleich
303 // Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
305 if( ColorToPercent_Impl( aTmpColor
.GetRed() ) != ColorToPercent_Impl( aColor
.GetRed() ) ||
306 ColorToPercent_Impl( aTmpColor
.GetGreen() ) != ColorToPercent_Impl( aColor
.GetGreen() ) ||
307 ColorToPercent_Impl( aTmpColor
.GetBlue() ) != ColorToPercent_Impl( aColor
.GetBlue() ) ||
308 aString
!= aEdtName
.GetText() )
310 ResMgr
& rMgr
= DIALOG_MGR();
311 Image aWarningBoxImage
= WarningBox::GetStandardImage();
312 //CHINA001 SvxMessDialog aMessDlg( DLGWIN,
313 //CHINA001 String( SVX_RES( RID_SVXSTR_COLOR, pMgr ) ),
314 //CHINA001 String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR, pMgr ) ),
315 //CHINA001 &aWarningBoxImage );
316 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
317 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
318 AbstractSvxMessDialog
* aMessDlg
= pFact
->CreateSvxMessDialog( DLGWIN
, RID_SVXDLG_MESSBOX
,
319 String( ResId( RID_SVXSTR_COLOR
, rMgr
) ),
320 String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR
, rMgr
) ),
322 DBG_ASSERT(aMessDlg
, "Dialogdiet fail!");//CHINA001
323 aMessDlg
->SetButtonText( MESS_BTN_1
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
324 String( ResId( RID_SVXSTR_CHANGE
, rMgr
) ) );
325 aMessDlg
->SetButtonText( MESS_BTN_2
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
326 String( ResId( RID_SVXSTR_ADD
, rMgr
) ) );
328 short nRet
= aMessDlg
->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
332 case RET_BTN_1
: // Aendern
334 ClickModifyHdl_Impl( this );
335 aColor
= pColorTab
->GetColor( nPos
)->GetColor();
339 case RET_BTN_2
: // Hinzufuegen
341 ClickAddHdl_Impl( this );
342 nPos
= aLbColor
.GetSelectEntryPos();
343 aColor
= pColorTab
->GetColor( nPos
)->GetColor();
348 // return( -1L ); <-- wuerde die Seite nicht verlassen
350 // return( TRUE ); // Abbruch
352 delete aMessDlg
; //add by CHINA001
355 if( *pDlgType
== 0 ) // Flaechen-Dialog
357 nPos
= aLbColor
.GetSelectEntryPos();
358 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
366 // -----------------------------------------------------------------------
368 BOOL
SvxColorTabPage::FillItemSet( SfxItemSet
& rSet
)
370 if( ( *pDlgType
!= 0 ) ||
371 ( *pPageType
== PT_COLOR
&& *pbAreaTP
== FALSE
) )
376 // CheckChanges_Impl(); <-- doppelte Abfrage ?
378 USHORT nPos
= aLbColor
.GetSelectEntryPos();
379 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
381 aColor
= pColorTab
->GetColor( nPos
)->GetColor();
382 aString
= aLbColor
.GetSelectEntry();
386 aColor
.SetColor (aAktuellColor
.GetColor());
388 ConvertColorValues (aColor
, CM_RGB
);
390 rSet
.Put( XFillColorItem( aString
, aColor
) );
391 rSet
.Put( XFillStyleItem( XFILL_SOLID
) );
397 // -----------------------------------------------------------------------
399 void SvxColorTabPage::Reset( const SfxItemSet
& rSet
)
401 USHORT nState
= rSet
.GetItemState( XATTR_FILLCOLOR
);
403 if ( nState
>= SFX_ITEM_DEFAULT
)
405 XFillColorItem
aColorItem( (const XFillColorItem
&)rSet
.Get( XATTR_FILLCOLOR
) );
406 aLbColor
.SelectEntry( aColorItem
.GetColorValue() );
407 aValSetColorTable
.SelectItem( aLbColor
.GetSelectEntryPos() + 1 );
408 aEdtName
.SetText( aLbColor
.GetSelectEntry() );
412 String aStr
= GetUserData();
413 aLbColorModel
.SelectEntryPos( (USHORT
) aStr
.ToInt32() );
415 ChangeColorHdl_Impl( this );
416 SelectColorModelHdl_Impl( this );
418 aCtlPreviewOld
.Invalidate();
420 // Status der Buttons ermitteln
421 if( pColorTab
->Count() )
430 aBtnModify
.Disable();
431 aBtnWorkOn
.Disable();
432 aBtnDelete
.Disable();
437 // -----------------------------------------------------------------------
439 SfxTabPage
* SvxColorTabPage::Create( Window
* pWindow
,
440 const SfxItemSet
& rOutAttrs
)
442 return( new SvxColorTabPage( pWindow
, rOutAttrs
) );
445 //------------------------------------------------------------------------
448 // Wird aufgerufen, wenn Inhalt der MtrFileds f�r Farbwerte ver�ndert wird
450 IMPL_LINK( SvxColorTabPage
, ModifiedHdl_Impl
, void *, EMPTYARG
)
452 // lese aktuelle MtrFields aus, wenn cmyk, dann k-Wert als Trans.-Farbe
453 aAktuellColor
.SetColor ( Color( (UINT8
)PercentToColor_Impl( (USHORT
) aMtrFldColorModel4
.GetValue() ),
454 (UINT8
)PercentToColor_Impl( (USHORT
) aMtrFldColorModel1
.GetValue() ),
455 (UINT8
)PercentToColor_Impl( (USHORT
) aMtrFldColorModel2
.GetValue() ),
456 (UINT8
)PercentToColor_Impl( (USHORT
) aMtrFldColorModel3
.GetValue() ) ).GetColor() );
458 Color
aTmpColor(aAktuellColor
);
460 ConvertColorValues (aTmpColor
, CM_RGB
);
462 rXFSet
.Put( XFillColorItem( String(), aTmpColor
) );
463 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
465 aCtlPreviewNew
.Invalidate();
470 //------------------------------------------------------------------------
473 // Button 'Hinzuf�gen'
475 IMPL_LINK( SvxColorTabPage
, ClickAddHdl_Impl
, void *, EMPTYARG
)
477 Window
*pWindow
= this;
481 bEnabled
= pWindow
->IsEnabled();
482 pWindow
= pWindow
->GetParent();
485 ResMgr
& rMgr
= DIALOG_MGR();
486 String
aDesc( ResId( RID_SVXSTR_DESC_COLOR
, rMgr
) );
487 String
aName( aEdtName
.GetText() );
489 long nCount
= pColorTab
->Count();
490 BOOL bDifferent
= TRUE
;
492 // Pruefen, ob Name schon vorhanden ist
493 for ( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
494 if ( aName
== pColorTab
->GetColor( i
)->GetName() )
497 // Wenn ja, wird wiederholt ein neuer Name angefordert
500 WarningBox
aWarningBox( DLGWIN
, WinBits( WB_OK
),
501 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
502 aWarningBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
503 aWarningBox
.Execute();
505 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
506 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
507 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
508 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
, RID_SVXDLG_NAME
);
509 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
512 while ( !bDifferent
&& bLoop
&& pDlg
->Execute() == RET_OK
)
514 pDlg
->GetName( aName
);
517 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
519 if( aName
== pColorTab
->GetColor( i
)->GetName() )
526 aWarningBox
.Execute();
531 // Wenn nicht vorhanden, wird Eintrag aufgenommen
535 ConvertColorValues (aAktuellColor
, CM_RGB
);
536 pEntry
= new XColorEntry( aAktuellColor
, aName
);
538 pColorTab
->Insert( pColorTab
->Count(), pEntry
);
540 aLbColor
.Append( pEntry
);
541 aValSetColorTable
.InsertItem( aValSetColorTable
.GetItemCount() + 1,
542 pEntry
->GetColor(), pEntry
->GetName() );
544 aLbColor
.SelectEntryPos( aLbColor
.GetEntryCount() - 1 );
546 // Flag fuer modifiziert setzen
547 *pnColorTableState
|= CT_MODIFIED
;
549 SelectColorLBHdl_Impl( this );
551 // Status der Buttons ermitteln
552 if( pColorTab
->Count() )
562 //------------------------------------------------------------------------
567 IMPL_LINK( SvxColorTabPage
, ClickModifyHdl_Impl
, void *, EMPTYARG
)
569 USHORT nPos
= aLbColor
.GetSelectEntryPos();
571 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
573 ResMgr
& rMgr
= DIALOG_MGR();
574 String
aDesc( ResId( RID_SVXSTR_DESC_COLOR
, rMgr
) );
575 String
aName( aEdtName
.GetText() );
576 long nCount
= pColorTab
->Count();
577 BOOL bDifferent
= TRUE
;
579 // Pruefen, ob Name schon vorhanden ist
580 for ( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
581 if ( aName
== pColorTab
->GetColor( i
)->GetName() && nPos
!= i
)
584 // Wenn ja, wird wiederholt ein neuer Name angefordert
587 WarningBox
aWarningBox( DLGWIN
, WinBits( WB_OK
),
588 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
589 aWarningBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
590 aWarningBox
.Execute();
592 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
593 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
594 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
595 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
, RID_SVXDLG_NAME
);
596 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
599 while ( !bDifferent
&& bLoop
&& pDlg
->Execute() == RET_OK
)
601 pDlg
->GetName( aName
);
604 for ( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
605 if( aName
== pColorTab
->GetColor( i
)->GetName() && nPos
!= i
)
611 aWarningBox
.Execute();
616 // Wenn nicht vorhanden, wird Eintrag aufgenommen
619 XColorEntry
* pEntry
= pColorTab
->GetColor( nPos
);
621 Color
aTmpColor (aAktuellColor
);
623 ConvertColorValues (aTmpColor
, CM_RGB
);
625 pEntry
->SetColor( aTmpColor
);
626 pEntry
->SetName( aName
);
628 aLbColor
.Modify( pEntry
, nPos
);
629 aLbColor
.SelectEntryPos( nPos
);
631 aValSetColorTable
.SetItemColor( nPos
+ 1, pEntry
->GetColor() );
632 aValSetColorTable
.SetItemText( nPos
+ 1, pEntry
->GetName() );
633 aEdtName
.SetText( aName
);
635 aCtlPreviewOld
.Invalidate();
637 // Flag fuer modifiziert setzen
638 *pnColorTableState
|= CT_MODIFIED
;
644 //------------------------------------------------------------------------
647 // Button 'Bearbeiten'
649 IMPL_LINK( SvxColorTabPage
, ClickWorkOnHdl_Impl
, void *, EMPTYARG
)
651 SvColorDialog
* pColorDlg
= new SvColorDialog( DLGWIN
);
653 Color
aTmpColor (aAktuellColor
);
655 ConvertColorValues (aTmpColor
, CM_RGB
);
657 pColorDlg
->SetColor (aTmpColor
);
659 if( pColorDlg
->Execute() == RET_OK
)
662 Color aPreviewColor
= pColorDlg
->GetColor();
663 aAktuellColor
= aPreviewColor
;
665 ConvertColorValues (aAktuellColor
, eCM
);
667 aMtrFldColorModel1
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetRed() ) );
668 aMtrFldColorModel2
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetGreen() ) );
669 aMtrFldColorModel3
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetBlue() ) );
670 aMtrFldColorModel4
.SetValue( ColorToPercent_Impl( nK
) );
672 // ItemSet fuellen und an XOut weiterleiten
673 rXFSet
.Put( XFillColorItem( String(), aPreviewColor
) );
674 //aCtlPreviewOld.SetAttributes( aXFillAttr );
675 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
677 aCtlPreviewNew
.Invalidate();
684 //------------------------------------------------------------------------
689 IMPL_LINK( SvxColorTabPage
, ClickDeleteHdl_Impl
, void *, EMPTYARG
)
691 USHORT nPos
= aLbColor
.GetSelectEntryPos();
693 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
695 QueryBox
aQueryBox( DLGWIN
, WinBits( WB_YES_NO
| WB_DEF_NO
),
696 String( SVX_RES( RID_SVXSTR_ASK_DEL_COLOR
) ) );
698 if( aQueryBox
.Execute() == RET_YES
)
700 // Jetzt wird richtig geloescht
701 ULONG nCount
= pColorTab
->Count() - 1;
704 pEntry
= pColorTab
->Remove( nPos
);
705 DBG_ASSERT( pEntry
, "ColorEntry nicht vorhanden (1) !" );
708 for( ULONG i
= nPos
; i
< nCount
; i
++ )
710 pEntry
= pColorTab
->Remove( i
+ 1 );
711 DBG_ASSERT( pEntry
, "ColorEntry nicht vorhanden (2) !" );
712 pColorTab
->Insert( i
, pEntry
);
715 // Listbox und ValueSet aktualisieren
716 aLbColor
.RemoveEntry( nPos
);
717 aValSetColorTable
.Clear();
718 FillValueSet_Impl( aValSetColorTable
);
721 aLbColor
.SelectEntryPos( nPos
);
722 SelectColorLBHdl_Impl( this );
724 aCtlPreviewOld
.Invalidate();
726 // Flag fuer modifiziert setzen
727 *pnColorTableState
|= CT_MODIFIED
;
730 // Status der Buttons ermitteln
731 if( !pColorTab
->Count() )
733 aBtnModify
.Disable();
734 aBtnWorkOn
.Disable();
735 aBtnDelete
.Disable();
741 // -----------------------------------------------------------------------
744 // Button 'Farbtabelle laden'
746 IMPL_LINK( SvxColorTabPage
, ClickLoadHdl_Impl
, void *, EMPTYARG
)
748 ResMgr
& rMgr
= DIALOG_MGR();
749 USHORT nReturn
= RET_YES
;
751 if( *pnColorTableState
& CT_MODIFIED
)
753 nReturn
= WarningBox( DLGWIN
, WinBits( WB_YES_NO_CANCEL
),
754 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
756 if ( nReturn
== RET_YES
)
760 if ( nReturn
!= RET_CANCEL
)
762 ::sfx2::FileDialogHelper
aDlg(
763 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
765 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
766 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
767 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
768 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
770 if ( aDlg
.Execute() == ERRCODE_NONE
)
772 INetURLObject
aURL( aDlg
.GetPath() );
773 INetURLObject
aPathURL( aURL
);
775 aPathURL
.removeSegment();
776 aPathURL
.removeFinalSlash();
779 XColorTable
* pColTab
= new XColorTable( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
780 pColTab
->SetName( aURL
.getName() ); // XXX
781 if( pColTab
->Load() )
785 // Pruefen, ob Tabelle geloescht werden darf:
786 const XColorTable
*pTempTable
= 0;
787 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( DLGWIN
);
788 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( DLGWIN
);
791 pTempTable
= pArea
->GetColorTable();
795 pTempTable
= pLine
->GetColorTable();
798 if( pColorTab
!= pTempTable
)
800 if( bDeleteColorTable
)
803 bDeleteColorTable
= TRUE
;
809 pArea
->SetNewColorTable( pColorTab
);
813 pLine
->SetNewColorTable( pColorTab
);
817 aValSetColorTable
.Clear();
821 pColorTab
->SetName( aURL
.getName() );
823 // Ermitteln (evtl. abschneiden) des Namens und in
824 // der GroupBox darstellen
825 String
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
826 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
828 if ( aURL
.getBase().getLength() > 18 )
830 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
831 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
834 aString
+= String(aURL
.getBase());
836 aTableNameFT
.SetText( aString
);
838 // Flag fuer gewechselt setzen
839 *pnColorTableState
|= CT_CHANGED
;
840 // Flag fuer modifiziert entfernen
841 *pnColorTableState
&= ~CT_MODIFIED
;
843 if( aLbColor
.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND
)
844 aLbColor
.SelectEntryPos( 0 );
846 aLbColor
.SelectEntryPos( aLbColor
.GetSelectEntryPos() );
848 ChangeColorHdl_Impl( this );
849 SelectColorLBHdl_Impl( this );
855 ErrorBox
aErrorBox( DLGWIN
, WinBits( WB_OK
),
856 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) );
862 // Status der Buttons ermitteln
863 if ( pColorTab
->Count() )
872 aBtnModify
.Disable();
873 aBtnWorkOn
.Disable();
874 aBtnDelete
.Disable();
880 // -----------------------------------------------------------------------
883 // Button 'Farbtabelle speichern'
885 IMPL_LINK( SvxColorTabPage
, ClickSaveHdl_Impl
, void *, EMPTYARG
)
887 ::sfx2::FileDialogHelper
aDlg(
888 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
889 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) );
890 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
892 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
893 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
895 if( pColorTab
->GetName().Len() )
897 aFile
.Append( pColorTab
->GetName() );
899 if( !aFile
.getExtension().getLength() )
900 aFile
.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) );
903 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
904 if ( aDlg
.Execute() == ERRCODE_NONE
)
906 INetURLObject
aURL( aDlg
.GetPath() );
907 INetURLObject
aPathURL( aURL
);
909 aPathURL
.removeSegment();
910 aPathURL
.removeFinalSlash();
912 pColorTab
->SetName( aURL
.getName() );
913 pColorTab
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
915 if( pColorTab
->Save() )
917 // Ermitteln (evtl. abschneiden) des Namens und in
918 // der GroupBox darstellen
919 String
aString( SVX_RES( RID_SVXSTR_TABLE
) );
920 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
922 if ( aURL
.getBase().getLength() > 18 )
924 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
925 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
928 aString
+= String(aURL
.getBase());
929 aTableNameFT
.SetText( aString
);
931 // Flag fuer gespeichert setzen
932 *pnColorTableState
|= CT_SAVED
;
933 // Flag fuer modifiziert entfernen
934 *pnColorTableState
&= ~CT_MODIFIED
;
938 ErrorBox
aErrorBox( DLGWIN
, WinBits( WB_OK
),
939 String( SVX_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) );
946 //------------------------------------------------------------------------
948 IMPL_LINK( SvxColorTabPage
, SelectColorLBHdl_Impl
, void *, EMPTYARG
)
950 USHORT nPos
= aLbColor
.GetSelectEntryPos();
951 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
953 aValSetColorTable
.SelectItem( nPos
+ 1 );
954 aEdtName
.SetText( aLbColor
.GetSelectEntry() );
956 rXFSet
.Put( XFillColorItem( String(),
957 aLbColor
.GetSelectEntryColor() ) );
958 aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
959 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
961 aCtlPreviewOld
.Invalidate();
962 aCtlPreviewNew
.Invalidate();
964 ChangeColorHdl_Impl( this );
969 //------------------------------------------------------------------------
971 IMPL_LINK( SvxColorTabPage
, SelectValSetHdl_Impl
, void *, EMPTYARG
)
973 USHORT nPos
= aValSetColorTable
.GetSelectItemId();
974 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
976 aLbColor
.SelectEntryPos( nPos
- 1 );
977 aEdtName
.SetText( aLbColor
.GetSelectEntry() );
979 rXFSet
.Put( XFillColorItem( String(),
980 aLbColor
.GetSelectEntryColor() ) );
981 aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
982 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
984 aCtlPreviewOld
.Invalidate();
985 aCtlPreviewNew
.Invalidate();
987 ChangeColorHdl_Impl( this );
992 //------------------------------------------------------------------------
995 // Farbwerte je nach �bergebenes Farbmodell umrechnen
997 void SvxColorTabPage::ConvertColorValues (Color
& rColor
, ColorModel eModell
)
1003 CmykToRgb_Impl (rColor
, (USHORT
)rColor
.GetTransparency() );
1004 rColor
.SetTransparency ((UINT8
) 0);
1011 RgbToCmyk_Impl (rColor
, nK
);
1012 rColor
.SetTransparency ((UINT8
) nK
);
1019 // Auswahl Listbox 'Farbmodell' (RGB/CMY)
1021 IMPL_LINK( SvxColorTabPage
, SelectColorModelHdl_Impl
, void *, EMPTYARG
)
1023 int nPos
= aLbColorModel
.GetSelectEntryPos();
1024 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
1026 if (eCM
!= (ColorModel
) nPos
)
1028 // wenn Farbmodell geaendert wurde, dann Werte umrechnen
1029 ConvertColorValues (aAktuellColor
, (ColorModel
) nPos
);
1032 eCM
= (ColorModel
) nPos
;
1038 String
aStr( aLbColorModel
.GetSelectEntry() );
1039 String
aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1040 xub_StrLen nIdx
= 1;
1041 aColorStr
.SetChar( nIdx
, aStr
.GetChar( 0 ) );
1042 aFtColorModel1
.SetText( aColorStr
);
1043 aColorStr
.SetChar( nIdx
, aStr
.GetChar( 1 ) );
1044 aFtColorModel2
.SetText( aColorStr
);
1045 aColorStr
.SetChar( nIdx
, aStr
.GetChar( 2 ) );
1046 aFtColorModel3
.SetText( aColorStr
);
1048 aFtColorModel4
.Hide();
1049 aMtrFldColorModel4
.Hide();
1050 aMtrFldColorModel4
.SetValue( 0L );
1052 aMtrFldColorModel1
.SetHelpId( HID_TPCOLOR_RGB_1
);
1053 aMtrFldColorModel2
.SetHelpId( HID_TPCOLOR_RGB_2
);
1054 aMtrFldColorModel3
.SetHelpId( HID_TPCOLOR_RGB_3
);
1056 // Da der alte HelpText noch am Control steht wuerde
1057 // ein Umsetzen der HelpID alleine nichts bewirken
1058 aMtrFldColorModel1
.SetHelpText( String() );
1059 aMtrFldColorModel2
.SetHelpText( String() );
1060 aMtrFldColorModel3
.SetHelpText( String() );
1062 // RGB-Werte im Bereich 0..255 verarbeiten (nicht in %),
1063 // dazu MetricField's entsprechend einstellen
1064 aMtrFldColorModel1
.SetUnit(FUNIT_NONE
);
1065 aMtrFldColorModel1
.SetMin(0);
1066 aMtrFldColorModel1
.SetMax(255);
1067 aMtrFldColorModel1
.SetLast(255);
1069 aMtrFldColorModel2
.SetUnit(FUNIT_NONE
);
1070 aMtrFldColorModel2
.SetMin(0);
1071 aMtrFldColorModel2
.SetMax(255);
1072 aMtrFldColorModel2
.SetLast(255);
1074 aMtrFldColorModel3
.SetUnit(FUNIT_NONE
);
1075 aMtrFldColorModel3
.SetMin(0);
1076 aMtrFldColorModel3
.SetMax(255);
1077 aMtrFldColorModel3
.SetLast(255);
1083 String
aStr( aLbColorModel
.GetSelectEntry() );
1084 String
aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) );
1085 xub_StrLen nIdx
= 1;
1086 aColorStr
.SetChar( nIdx
, aStr
.GetChar( 0 ) );
1087 aFtColorModel1
.SetText( aColorStr
);
1088 aColorStr
.SetChar( nIdx
, aStr
.GetChar( 1 ) );
1089 aFtColorModel2
.SetText( aColorStr
);
1090 aColorStr
.SetChar( nIdx
,aStr
.GetChar( 2 ) );
1091 aFtColorModel3
.SetText( aColorStr
);
1092 aColorStr
.SetChar( nIdx
,aStr
.GetChar( 3 ) );
1093 aFtColorModel4
.SetText( aColorStr
);
1095 aFtColorModel4
.Show();
1096 aMtrFldColorModel4
.Show();
1098 aMtrFldColorModel1
.SetHelpId( HID_TPCOLOR_CMYK_1
);
1099 aMtrFldColorModel2
.SetHelpId( HID_TPCOLOR_CMYK_2
);
1100 aMtrFldColorModel3
.SetHelpId( HID_TPCOLOR_CMYK_3
);
1103 aMtrFldColorModel1
.SetHelpText( String() );
1104 aMtrFldColorModel2
.SetHelpText( String() );
1105 aMtrFldColorModel3
.SetHelpText( String() );
1107 // CMYK-Werte im Bereich 0..100% verarbeiten,
1108 // dazu MetricField's entsprechend einstellen
1109 String
aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) );
1111 aMtrFldColorModel1
.SetUnit(FUNIT_CUSTOM
);
1112 aMtrFldColorModel1
.SetCustomUnitText( aStrUnit
);
1113 aMtrFldColorModel1
.SetMin(0);
1114 aMtrFldColorModel1
.SetMax(100);
1115 aMtrFldColorModel1
.SetLast(100);
1117 aMtrFldColorModel2
.SetUnit(FUNIT_CUSTOM
);
1118 aMtrFldColorModel2
.SetCustomUnitText( aStrUnit
);
1119 aMtrFldColorModel2
.SetMin(0);
1120 aMtrFldColorModel2
.SetMax(100);
1121 aMtrFldColorModel2
.SetLast(100);
1123 aMtrFldColorModel3
.SetUnit(FUNIT_CUSTOM
);
1124 aMtrFldColorModel3
.SetCustomUnitText( aStrUnit
);
1125 aMtrFldColorModel3
.SetMin(0);
1126 aMtrFldColorModel3
.SetMax(100);
1127 aMtrFldColorModel3
.SetLast(100);
1132 aMtrFldColorModel1
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetRed() ) );
1133 aMtrFldColorModel2
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetGreen() ) );
1134 aMtrFldColorModel3
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetBlue() ) );
1135 aMtrFldColorModel4
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetTransparency() ) );
1140 //------------------------------------------------------------------------
1142 long SvxColorTabPage::ChangeColorHdl_Impl( void* )
1144 int nPos
= aLbColor
.GetSelectEntryPos();
1145 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
1147 XColorEntry
* pEntry
= pColorTab
->GetColor( nPos
);
1149 aAktuellColor
.SetColor ( pEntry
->GetColor().GetColor() );
1151 ConvertColorValues (aAktuellColor
, eCM
);
1153 aMtrFldColorModel1
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetRed() ) );
1154 aMtrFldColorModel2
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetGreen() ) );
1155 aMtrFldColorModel3
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetBlue() ) );
1156 aMtrFldColorModel4
.SetValue( ColorToPercent_Impl( aAktuellColor
.GetTransparency() ) );
1158 // ItemSet fuellen und an XOut weiterleiten
1159 rXFSet
.Put( XFillColorItem( String(), pEntry
->GetColor() ) );
1160 aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
1161 aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
1163 aCtlPreviewNew
.Invalidate();
1168 //------------------------------------------------------------------------
1170 void SvxColorTabPage::FillValueSet_Impl( ValueSet
& rVs
)
1172 long nCount
= pColorTab
->Count();
1173 XColorEntry
* pColorEntry
;
1175 for( long i
= 0; i
< nCount
; i
++ )
1177 pColorEntry
= pColorTab
->GetColor( i
);
1178 rVs
.InsertItem( (USHORT
) i
+ 1, pColorEntry
->GetColor(), pColorEntry
->GetName() );
1182 //------------------------------------------------------------------------
1184 // Ein RGB-Wert wird in einen CMYK-Wert konvertiert, wobei die Color-
1185 // Klasse vergewaltigt wird, da R in C, G in M und B in Y umgewandelt
1186 // wird. Der Wert K wird in einer Extra-Variablen gehalten.
1187 // Bei weiteren Farbmodellen sollte man hierfuer eigene Klassen entwickeln,
1188 // die dann auch entsprechende Casts enthalten.
1190 void SvxColorTabPage::RgbToCmyk_Impl( Color
& rColor
, USHORT
& rK
)
1192 USHORT nColor1
, nColor2
, nColor3
;
1193 USHORT nProzent
; // nur temporaer !!!
1195 nColor1
= 255 - rColor
.GetRed();
1196 nProzent
= ColorToPercent_Impl( nColor1
);
1198 nColor2
= 255 - rColor
.GetGreen();
1199 nProzent
= ColorToPercent_Impl( nColor2
);
1201 nColor3
= 255 - rColor
.GetBlue();
1202 nProzent
= ColorToPercent_Impl( nColor3
);
1204 rK
= Min( Min( nColor1
, nColor2
), nColor3
);
1206 rColor
.SetRed( sal::static_int_cast
< UINT8
>( nColor1
- rK
) );
1207 rColor
.SetGreen( sal::static_int_cast
< UINT8
>( nColor2
- rK
) );
1208 rColor
.SetBlue( sal::static_int_cast
< UINT8
>( nColor3
- rK
) );
1211 //------------------------------------------------------------------------
1213 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.)
1215 void SvxColorTabPage::CmykToRgb_Impl( Color
& rColor
, const USHORT nK
)
1219 lTemp
= 255 - ( rColor
.GetRed() + nK
);
1223 rColor
.SetRed( (BYTE
)lTemp
);
1225 lTemp
= 255 - ( rColor
.GetGreen() + nK
);
1229 rColor
.SetGreen( (BYTE
)lTemp
);
1231 lTemp
= 255 - ( rColor
.GetBlue() + nK
);
1235 rColor
.SetBlue( (BYTE
)lTemp
);
1238 //------------------------------------------------------------------------
1240 USHORT
SvxColorTabPage::ColorToPercent_Impl( USHORT nColor
)
1251 nWert
= (USHORT
) ( (double) nColor
* 100.0 / 255.0 + 0.5 );
1258 //------------------------------------------------------------------------
1260 USHORT
SvxColorTabPage::PercentToColor_Impl( USHORT nPercent
)
1271 nWert
= (USHORT
) ( (double) nPercent
* 255.0 / 100.0 + 0.5 );
1278 //------------------------------------------------------------------------
1280 void SvxColorTabPage::FillUserData()
1282 // Das Farbmodell wird in der Ini-Datei festgehalten
1283 SetUserData( UniString::CreateFromInt32( eCM
) );