1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/wrkwin.hxx>
21 #include <tools/shl.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <tools/urlobj.hxx>
24 #include <unotools/ucbstreamhelper.hxx>
25 #include <unotools/pathoptions.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <unotools/localfilehelper.hxx>
29 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
30 #include <svx/dialmgr.hxx>
31 #include <vcl/bmpacc.hxx>
32 #include <svx/dialogs.hrc>
36 #include "svx/xattr.hxx"
37 #include <svx/xpool.hxx>
38 #include <svx/xtable.hxx>
39 #include "svx/xoutbmp.hxx"
40 #include "svx/drawitem.hxx"
41 #include "cuitabarea.hxx"
42 #include "tabarea.hrc"
43 #include "defdlgname.hxx"
44 #include "dlgname.hxx"
45 #include <svx/svxdlg.hxx>
46 #include <dialmgr.hxx>
47 #include "sfx2/opengrf.hxx"
48 #include "paragrph.hrc"
50 SvxBitmapTabPage::SvxBitmapTabPage
53 const SfxItemSet
& rInAttrs
56 SvxTabPage ( pParent
, CUI_RES( RID_SVXPAGE_BITMAP
), rInAttrs
),
58 aCtlPixel ( this, CUI_RES( CTL_PIXEL
) ),
59 aFtPixelEdit ( this, CUI_RES( FT_PIXEL_EDIT
) ),
60 aFtColor ( this, CUI_RES( FT_COLOR
) ),
61 aLbColor ( this, CUI_RES( LB_COLOR
) ),
62 aFtBackgroundColor ( this, CUI_RES( FT_BACKGROUND_COLOR
) ),
63 aLbBackgroundColor ( this, CUI_RES( LB_BACKGROUND_COLOR
) ),
64 // This fix text is used only to provide the name for the following
65 // bitmap list box. The fixed text is not displayed.
66 aLbBitmapsHidden ( this, CUI_RES( FT_BITMAPS_HIDDEN
) ),
67 aLbBitmaps ( this, CUI_RES( LB_BITMAPS
) ),
68 aFlProp ( this, CUI_RES( FL_PROP
) ),
69 aCtlPreview ( this, CUI_RES( CTL_PREVIEW
) ),
70 aBtnAdd ( this, CUI_RES( BTN_ADD
) ),
71 aBtnModify ( this, CUI_RES( BTN_MODIFY
) ),
72 aBtnImport ( this, CUI_RES( BTN_IMPORT
) ),
73 aBtnDelete ( this, CUI_RES( BTN_DELETE
) ),
74 aBtnLoad ( this, CUI_RES( BTN_LOAD
) ),
75 aBtnSave ( this, CUI_RES( BTN_SAVE
) ),
77 aBitmapCtl ( this, aCtlPreview
.GetSizePixel() ),
78 rOutAttrs ( rInAttrs
),
80 pnBitmapListState ( 0 ),
81 pnColorListState ( 0 ),
86 bBmpChanged ( false ),
88 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
89 aXFStyleItem ( XFILL_BITMAP
),
90 aXBitmapItem ( String(), Graphic() ),
91 aXFillAttr ( pXPool
),
92 rXFSet ( aXFillAttr
.GetItemSet() )
96 // this page needs ExchangeSupport
99 // setting the output device
100 rXFSet
.Put( aXFStyleItem
);
101 rXFSet
.Put( aXBitmapItem
);
103 aBtnAdd
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickAddHdl_Impl
) );
104 aBtnImport
.SetClickHdl(
105 LINK( this, SvxBitmapTabPage
, ClickImportHdl_Impl
) );
106 aBtnModify
.SetClickHdl(
107 LINK( this, SvxBitmapTabPage
, ClickModifyHdl_Impl
) );
108 aBtnDelete
.SetClickHdl(
109 LINK( this, SvxBitmapTabPage
, ClickDeleteHdl_Impl
) );
110 aBtnLoad
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickLoadHdl_Impl
) );
111 aBtnSave
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickSaveHdl_Impl
) );
113 aLbBitmaps
.SetSelectHdl(
114 LINK( this, SvxBitmapTabPage
, ChangeBitmapHdl_Impl
) );
115 aLbColor
.SetSelectHdl(
116 LINK( this, SvxBitmapTabPage
, ChangePixelColorHdl_Impl
) );
117 aLbBackgroundColor
.SetSelectHdl(
118 LINK( this, SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
) );
120 String accName
= String(CUI_RES(STR_EXAMPLE
));
121 aCtlPreview
.SetAccessibleName(accName
);
122 aCtlPixel
.SetAccessibleRelationMemberOf( &aFlProp
);
123 aCtlPixel
.SetAccessibleRelationLabeledBy( &aFtPixelEdit
);
124 aLbBitmaps
.SetAccessibleRelationLabeledBy(&aLbBitmaps
);
125 aBtnAdd
.SetAccessibleRelationMemberOf( &aFlProp
);
126 aBtnModify
.SetAccessibleRelationMemberOf( &aFlProp
);
127 aBtnImport
.SetAccessibleRelationMemberOf( &aFlProp
);
128 aBtnDelete
.SetAccessibleRelationMemberOf( &aFlProp
);
132 // -----------------------------------------------------------------------
134 void SvxBitmapTabPage::Construct()
136 aLbColor
.Fill( pColorList
);
137 aLbBackgroundColor
.CopyEntries( aLbColor
);
139 aLbBitmaps
.Fill( pBitmapList
);
142 // -----------------------------------------------------------------------
144 void SvxBitmapTabPage::ActivatePage( const SfxItemSet
& )
149 if( *pDlgType
== 0 ) // area dialog
151 *pbAreaTP
= sal_False
;
153 if( pColorList
.is() )
156 if( *pnColorListState
& CT_CHANGED
||
157 *pnColorListState
& CT_MODIFIED
)
159 if( *pnColorListState
& CT_CHANGED
)
160 pColorList
= ( (SvxAreaTabDialog
*) GetParentDialog() )->GetNewColorList();
163 nPos
= aLbColor
.GetSelectEntryPos();
165 aLbColor
.Fill( pColorList
);
166 nCount
= aLbColor
.GetEntryCount();
168 ; // this case should not occur
169 else if( nCount
<= nPos
)
170 aLbColor
.SelectEntryPos( 0 );
172 aLbColor
.SelectEntryPos( nPos
);
175 nPos
= aLbBackgroundColor
.GetSelectEntryPos();
176 aLbBackgroundColor
.Clear();
177 aLbBackgroundColor
.CopyEntries( aLbColor
);
178 nCount
= aLbBackgroundColor
.GetEntryCount();
180 ; // this case should not occur
181 else if( nCount
<= nPos
)
182 aLbBackgroundColor
.SelectEntryPos( 0 );
184 aLbBackgroundColor
.SelectEntryPos( nPos
);
186 ChangePixelColorHdl_Impl( this );
187 ChangeBackgrndColorHdl_Impl( this );
190 // determining (possibly cutting) the name and
191 // displaying it in the GroupBox
192 OUString
aString( CUI_RES( RID_SVXSTR_TABLE
) );
194 INetURLObject
aURL( pBitmapList
->GetPath() );
196 aURL
.Append( pBitmapList
->GetName() );
197 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
199 if( aURL
.getBase().getLength() > 18 )
201 aString
+= aURL
.getBase().copy( 0, 15 );
205 aString
+= aURL
.getBase();
207 if( *pPageType
== PT_BITMAP
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
209 aLbBitmaps
.SelectEntryPos( *pPos
);
211 // colors could have been deleted
212 ChangeBitmapHdl_Impl( this );
214 *pPageType
= PT_BITMAP
;
215 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
220 // -----------------------------------------------------------------------
222 int SvxBitmapTabPage::DeactivatePage( SfxItemSet
* _pSet
)
224 if ( CheckChanges_Impl() == -1L )
228 FillItemSet( *_pSet
);
233 // -----------------------------------------------------------------------
235 sal_Bool
SvxBitmapTabPage::FillItemSet( SfxItemSet
& _rOutAttrs
)
237 if( *pDlgType
== 0 && *pbAreaTP
== sal_False
) // area dialog
239 if(PT_BITMAP
== *pPageType
)
241 _rOutAttrs
.Put(XFillStyleItem(XFILL_BITMAP
));
242 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
243 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
245 const XBitmapEntry
* pXBitmapEntry
= pBitmapList
->GetBitmap(nPos
);
246 const String
aString(aLbBitmaps
.GetSelectEntry());
248 _rOutAttrs
.Put(XFillBitmapItem(aString
, pXBitmapEntry
->GetGraphicObject()));
252 const BitmapEx
aBitmapEx(aBitmapCtl
.GetBitmapEx());
254 _rOutAttrs
.Put(XFillBitmapItem(String(), Graphic(aBitmapEx
)));
262 // -----------------------------------------------------------------------
264 void SvxBitmapTabPage::Reset( const SfxItemSet
& )
266 // aLbBitmaps.SelectEntryPos( 0 );
268 aBitmapCtl
.SetLines( aCtlPixel
.GetLineCount() );
269 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
270 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
271 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
273 // get bitmap and display it
274 const XFillBitmapItem
aBmpItem(OUString(), Graphic(aBitmapCtl
.GetBitmapEx()));
275 rXFSet
.Put( aBmpItem
);
276 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
277 aCtlPreview
.Invalidate();
279 ChangeBitmapHdl_Impl( this );
281 // determine button state
282 if( pBitmapList
->Count() )
291 aBtnModify
.Disable();
292 aBtnDelete
.Disable();
297 // -----------------------------------------------------------------------
299 SfxTabPage
* SvxBitmapTabPage::Create( Window
* pWindow
,
300 const SfxItemSet
& rSet
)
302 return new SvxBitmapTabPage( pWindow
, rSet
);
305 //------------------------------------------------------------------------
307 IMPL_LINK_NOARG(SvxBitmapTabPage
, ChangeBitmapHdl_Impl
)
309 GraphicObject
* pGraphicObject
= 0;
310 int nPos(aLbBitmaps
.GetSelectEntryPos());
312 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
314 pGraphicObject
= new GraphicObject(pBitmapList
->GetBitmap(nPos
)->GetGraphicObject());
318 const SfxPoolItem
* pPoolItem
= 0;
320 if(SFX_ITEM_SET
== rOutAttrs
.GetItemState(GetWhich(XATTR_FILLSTYLE
), true, &pPoolItem
))
322 const XFillStyle
eXFS((XFillStyle
)((const XFillStyleItem
*)pPoolItem
)->GetValue());
324 if((XFILL_BITMAP
== eXFS
) && (SFX_ITEM_SET
== rOutAttrs
.GetItemState(GetWhich(XATTR_FILLBITMAP
), true, &pPoolItem
)))
326 pGraphicObject
= new GraphicObject(((const XFillBitmapItem
*)pPoolItem
)->GetGraphicObject());
332 aLbBitmaps
.SelectEntryPos(0);
333 nPos
= aLbBitmaps
.GetSelectEntryPos();
335 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
337 pGraphicObject
= new GraphicObject(pBitmapList
->GetBitmap(nPos
)->GetGraphicObject());
346 bool bIs8x8(isHistorical8x8(pGraphicObject
->GetGraphic().GetBitmap(), aBack
, aFront
));
348 aLbColor
.SetNoSelection();
349 aLbBackgroundColor
.SetNoSelection();
353 aCtlPixel
.SetPaintable( sal_True
);
355 aFtPixelEdit
.Enable();
358 aFtBackgroundColor
.Enable();
359 aLbBackgroundColor
.Enable();
363 // setting the pixel control
364 aCtlPixel
.SetXBitmap(pGraphicObject
->GetGraphic().GetBitmapEx());
366 Color aPixelColor
= aFront
;
367 Color aBackColor
= aBack
;
369 aBitmapCtl
.SetPixelColor( aPixelColor
);
370 aBitmapCtl
.SetBackgroundColor( aBackColor
);
372 // if the entry is not in the listbox,
373 // the color is added temporarily
374 if( 0 == aLbBitmaps
.GetSelectEntryPos() )
376 aLbColor
.SelectEntry( Color( COL_BLACK
) );
377 ChangePixelColorHdl_Impl( this );
380 aLbColor
.SelectEntry( aPixelColor
);
381 if( aLbColor
.GetSelectEntryCount() == 0 )
383 aLbColor
.InsertEntry( aPixelColor
, String() );
384 aLbColor
.SelectEntry( aPixelColor
);
386 aLbBackgroundColor
.SelectEntry( aBackColor
);
387 if( aLbBackgroundColor
.GetSelectEntryCount() == 0 )
389 aLbBackgroundColor
.InsertEntry( aBackColor
, String() );
390 aLbBackgroundColor
.SelectEntry( aBackColor
);
396 aCtlPixel
.SetPaintable( sal_False
);
398 aFtPixelEdit
.Disable();
401 aFtBackgroundColor
.Disable();
402 aLbBackgroundColor
.Disable();
403 aBtnModify
.Disable();
407 aCtlPixel
.Invalidate();
410 const XFillBitmapItem
aXBmpItem(String(), *pGraphicObject
);
411 rXFSet
.Put( aXBmpItem
);
413 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
414 aCtlPreview
.Invalidate();
416 bBmpChanged
= sal_False
;
417 delete pGraphicObject
;
423 // -----------------------------------------------------------------------
425 long SvxBitmapTabPage::CheckChanges_Impl()
427 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
428 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
432 ResMgr
& rMgr
= CUI_MGR();
433 Image aWarningBoxImage
= WarningBox::GetStandardImage();
434 SvxMessDialog
* aMessDlg
= new SvxMessDialog(GetParentDialog(),
435 String( SVX_RES( RID_SVXSTR_BITMAP
) ),
436 String( CUI_RES( RID_SVXSTR_ASK_CHANGE_BITMAP
) ),
438 DBG_ASSERT(aMessDlg
, "Dialogdiet fail!");
439 aMessDlg
->SetButtonText( MESS_BTN_1
,
440 String( ResId( RID_SVXSTR_CHANGE
, rMgr
) ) );
441 aMessDlg
->SetButtonText( MESS_BTN_2
,
442 String( ResId( RID_SVXSTR_ADD
, rMgr
) ) );
444 short nRet
= aMessDlg
->Execute();
450 ClickModifyHdl_Impl( this );
456 ClickAddHdl_Impl( this );
457 nPos
= aLbBitmaps
.GetSelectEntryPos();
467 nPos
= aLbBitmaps
.GetSelectEntryPos();
468 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
473 //------------------------------------------------------------------------
475 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickAddHdl_Impl
)
477 ResMgr
& rMgr
= CUI_MGR();
478 String
aNewName( SVX_RES( RID_SVXSTR_BITMAP
) );
479 String
aDesc( CUI_RES( RID_SVXSTR_DESC_NEW_BITMAP
) );
482 long nCount
= pBitmapList
->Count();
484 sal_Bool bDifferent
= sal_False
;
489 aName
+= sal_Unicode(' ');
490 aName
+= OUString::valueOf( j
++ );
491 bDifferent
= sal_True
;
493 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
494 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
495 bDifferent
= sal_False
;
498 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
499 DBG_ASSERT(pFact
, "Dialogdiet fail!");
500 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( GetParentDialog(), aName
, aDesc
);
501 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
502 WarningBox
* pWarnBox
= NULL
;
503 sal_uInt16 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
505 while( pDlg
->Execute() == RET_OK
)
507 pDlg
->GetName( aName
);
509 bDifferent
= sal_True
;
511 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
512 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
513 bDifferent
= sal_False
;
522 pWarnBox
= new WarningBox( GetParentDialog(),
523 WinBits( WB_OK_CANCEL
),
524 String( ResId( nError
, rMgr
) ) );
525 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
528 if( pWarnBox
->Execute() != RET_OK
)
536 XBitmapEntry
* pEntry
= 0;
537 if( aCtlPixel
.IsEnabled() )
539 const BitmapEx
aBitmapEx(aBitmapCtl
.GetBitmapEx());
541 pEntry
= new XBitmapEntry(Graphic(aBitmapEx
), aName
);
543 else // it must be a not existing imported bitmap
545 const SfxPoolItem
* pPoolItem
= 0;
547 if(SFX_ITEM_SET
== rOutAttrs
.GetItemState(XATTR_FILLBITMAP
, true, &pPoolItem
))
549 pEntry
= new XBitmapEntry(dynamic_cast< const XFillBitmapItem
* >(pPoolItem
)->GetGraphicObject(), aName
);
553 DBG_ASSERT( pEntry
, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
557 pBitmapList
->Insert( pEntry
);
558 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
559 aLbBitmaps
.Append(rStyleSettings
.GetListBoxPreviewDefaultPixelSize(), *pEntry
);
560 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
563 // hack: #31355# W.P.
564 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
565 if( sal_True
) { // ??? overlapped with pDlg
568 //aLbBitmaps.Invalidate();
572 *pnBitmapListState
|= CT_MODIFIED
;
574 ChangeBitmapHdl_Impl( this );
578 // determine button state
579 if( pBitmapList
->Count() )
589 /******************************************************************************/
590 /******************************************************************************/
593 //------------------------------------------------------------------------
595 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickImportHdl_Impl
)
597 ResMgr
& rMgr
= CUI_MGR();
598 SvxOpenGraphicDialog
aDlg( OUString("Import") );
599 aDlg
.EnableLink(sal_False
);
601 if( !aDlg
.Execute() )
607 nError
= aDlg
.GetGraphic( aGraphic
);
612 String
aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP
, rMgr
) );
613 WarningBox
* pWarnBox
= NULL
;
615 // convert file URL to UI name
617 INetURLObject
aURL( aDlg
.GetPath() );
618 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
619 DBG_ASSERT(pFact
, "Dialogdiet fail!");
620 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( GetParentDialog(), String(aURL
.GetName()).GetToken( 0, '.' ), aDesc
);
621 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
622 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
624 while( pDlg
->Execute() == RET_OK
)
626 pDlg
->GetName( aName
);
628 sal_Bool bDifferent
= sal_True
;
629 long nCount
= pBitmapList
->Count();
631 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
632 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
633 bDifferent
= sal_False
;
642 pWarnBox
= new WarningBox( GetParentDialog(),
643 WinBits( WB_OK_CANCEL
),
644 String( ResId( nError
, rMgr
) ) );
645 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
649 if( pWarnBox
->Execute() != RET_OK
)
657 XBitmapEntry
* pEntry
= new XBitmapEntry( aGraphic
, aName
);
658 pBitmapList
->Insert( pEntry
);
660 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
661 aLbBitmaps
.Append(rStyleSettings
.GetListBoxPreviewDefaultPixelSize(), *pEntry
);
662 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
665 // hack: #31355# W.P.
666 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
667 if( sal_True
) { // ??? overlapped with pDlg
673 *pnBitmapListState
|= CT_MODIFIED
;
675 ChangeBitmapHdl_Impl( this );
679 // graphic couldn't be loaded
680 ErrorBox( GetParentDialog(),
682 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
688 //------------------------------------------------------------------------
690 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickModifyHdl_Impl
)
692 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
694 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
696 ResMgr
& rMgr
= CUI_MGR();
697 String
aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP
, rMgr
) );
698 String
aName( pBitmapList
->GetBitmap( nPos
)->GetName() );
699 String aOldName
= aName
;
701 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
702 DBG_ASSERT(pFact
, "Dialogdiet fail!");
703 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( GetParentDialog(), aName
, aDesc
);
704 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
706 long nCount
= pBitmapList
->Count();
707 sal_Bool bDifferent
= sal_False
;
708 sal_Bool bLoop
= sal_True
;
709 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
711 while( bLoop
&& pDlg
->Execute() == RET_OK
)
713 pDlg
->GetName( aName
);
714 bDifferent
= sal_True
;
716 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
718 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() &&
720 bDifferent
= sal_False
;
726 XBitmapEntry
* pEntry
= pBitmapList
->GetBitmap( nPos
);
728 pEntry
->SetName( aName
);
730 const BitmapEx
aBitmapEx(aBitmapCtl
.GetBitmapEx());
732 pEntry
->SetGraphicObject(Graphic(aBitmapEx
));
734 aLbBitmaps
.Modify( rStyleSettings
.GetListBoxPreviewDefaultPixelSize(), *pEntry
, nPos
);
735 aLbBitmaps
.SelectEntryPos( nPos
);
737 *pnBitmapListState
|= CT_MODIFIED
;
739 bBmpChanged
= sal_False
;
743 WarningBox
aBox( GetParentDialog(), WinBits( WB_OK
), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
744 aBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
753 //------------------------------------------------------------------------
755 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickDeleteHdl_Impl
)
757 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
759 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
761 QueryBox
aQueryBox( GetParentDialog(), WinBits( WB_YES_NO
| WB_DEF_NO
),
762 String( CUI_RES( RID_SVXSTR_ASK_DEL_BITMAP
) ) );
764 if( aQueryBox
.Execute() == RET_YES
)
766 delete pBitmapList
->Remove( nPos
);
767 aLbBitmaps
.RemoveEntry( nPos
);
768 aLbBitmaps
.SelectEntryPos( 0 );
770 aCtlPreview
.Invalidate();
771 aCtlPixel
.Invalidate();
773 ChangeBitmapHdl_Impl( this );
775 *pnBitmapListState
|= CT_MODIFIED
;
778 // determine button state
779 if( !pBitmapList
->Count() )
781 aBtnModify
.Disable();
782 aBtnDelete
.Disable();
788 // -----------------------------------------------------------------------
790 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickLoadHdl_Impl
)
792 sal_uInt16 nReturn
= RET_YES
;
793 ResMgr
& rMgr
= CUI_MGR();
795 if ( *pnBitmapListState
& CT_MODIFIED
)
797 nReturn
= WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL
),
798 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
800 if ( nReturn
== RET_YES
)
804 if ( nReturn
!= RET_CANCEL
)
806 ::sfx2::FileDialogHelper
aDlg(
807 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
809 String
aStrFilterType( "*.sob" );
810 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
811 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
812 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
814 if ( aDlg
.Execute() == ERRCODE_NONE
)
817 INetURLObject
aURL( aDlg
.GetPath() );
818 INetURLObject
aPathURL( aURL
);
820 aPathURL
.removeSegment();
821 aPathURL
.removeFinalSlash();
824 XBitmapListRef pBmpList
= XPropertyList::CreatePropertyList(
825 XBITMAP_LIST
, aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
)->AsBitmapList();
826 pBmpList
->SetName( aURL
.getName() );
827 if( pBmpList
->Load() )
829 pBitmapList
= pBmpList
;
830 ( (SvxAreaTabDialog
*) GetParentDialog() )->SetNewBitmapList( pBitmapList
);
833 aLbBitmaps
.Fill( pBitmapList
);
836 pBitmapList
->SetName( aURL
.getName() );
838 // determining (possibly cutting) the name
839 // displaying it in the GroupBox
840 OUString
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
843 if ( aURL
.getBase().getLength() > 18 )
845 aString
+= aURL
.getBase().copy( 0, 15 );
849 aString
+= aURL
.getBase();
851 *pnBitmapListState
|= CT_CHANGED
;
852 *pnBitmapListState
&= ~CT_MODIFIED
;
858 ErrorBox( GetParentDialog(), WinBits( WB_OK
),
859 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
864 // determine button state
865 if( pBitmapList
->Count() )
873 aBtnModify
.Disable();
874 aBtnDelete
.Disable();
880 // -----------------------------------------------------------------------
882 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickSaveHdl_Impl
)
884 ::sfx2::FileDialogHelper
aDlg(
885 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
886 String
aStrFilterType( "*.sob" );
887 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
889 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
890 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
892 if( pBitmapList
->GetName().Len() )
894 aFile
.Append( pBitmapList
->GetName() );
896 if( aFile
.getExtension().isEmpty() )
897 aFile
.SetExtension( OUString("sob") );
900 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
901 if ( aDlg
.Execute() == ERRCODE_NONE
)
903 INetURLObject
aURL( aDlg
.GetPath() );
904 INetURLObject
aPathURL( aURL
);
906 aPathURL
.removeSegment();
907 aPathURL
.removeFinalSlash();
909 pBitmapList
->SetName( aURL
.getName() );
910 pBitmapList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
912 if( pBitmapList
->Save() )
914 // determining (possibly cutting) the name
915 // displaying it in the GroupBox
916 OUString
aString( CUI_RES( RID_SVXSTR_TABLE
) );
919 if ( aURL
.getBase().getLength() > 18 )
921 aString
+= aURL
.getBase().copy( 0, 15 );
925 aString
+= aURL
.getBase();
927 *pnBitmapListState
|= CT_SAVED
;
928 *pnBitmapListState
&= ~CT_MODIFIED
;
932 ErrorBox( GetParentDialog(), WinBits( WB_OK
),
933 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) ).Execute();
940 //------------------------------------------------------------------------
942 IMPL_LINK_NOARG(SvxBitmapTabPage
, ChangePixelColorHdl_Impl
)
944 aCtlPixel
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
945 aCtlPixel
.Invalidate();
947 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
949 // get bitmap and display it
950 rXFSet
.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl
.GetBitmapEx())));
951 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
952 aCtlPreview
.Invalidate();
954 bBmpChanged
= sal_True
;
959 //------------------------------------------------------------------------
961 IMPL_LINK_NOARG(SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
)
963 aCtlPixel
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
964 aCtlPixel
.Invalidate();
966 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
968 // get bitmap and display it
969 rXFSet
.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl
.GetBitmapEx())));
970 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
971 aCtlPreview
.Invalidate();
973 bBmpChanged
= sal_True
;
978 //------------------------------------------------------------------------
980 void SvxBitmapTabPage::PointChanged( Window
* pWindow
, RECT_POINT
)
982 if( pWindow
== &aCtlPixel
)
984 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
986 // get bitmap and display it
987 rXFSet
.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl
.GetBitmapEx())));
988 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
989 aCtlPreview
.Invalidate();
991 bBmpChanged
= sal_True
;
998 Window
* SvxBitmapTabPage::GetParentLabeledBy( const Window
* pLabeled
) const
1000 if (pLabeled
== &aLbBitmaps
)
1001 return const_cast<FixedText
*>(&aLbBitmapsHidden
);
1003 return SvxTabPage::GetParentLabeledBy (pLabeled
);
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */