update credits
[LibreOffice.git] / cui / source / tabpages / tpbitmap.cxx
blobc052931a708d14323dd88762a5cee0640062cc32
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
34 #include <cuires.hrc>
35 #include "helpid.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
52 Window* pParent,
53 const SfxItemSet& rInAttrs
54 ) :
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 ),
82 pPageType ( 0 ),
83 pDlgType ( 0 ),
84 pbAreaTP ( 0 ),
86 bBmpChanged ( false ),
88 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
89 aXFStyleItem ( XFILL_BITMAP ),
90 aXBitmapItem ( String(), Graphic() ),
91 aXFillAttr ( pXPool ),
92 rXFSet ( aXFillAttr.GetItemSet() )
94 FreeResource();
96 // this page needs ExchangeSupport
97 SetExchangeSupport();
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& )
146 sal_uInt16 nPos;
147 sal_uInt16 nCount;
149 if( *pDlgType == 0 ) // area dialog
151 *pbAreaTP = sal_False;
153 if( pColorList.is() )
155 // ColorList
156 if( *pnColorListState & CT_CHANGED ||
157 *pnColorListState & CT_MODIFIED )
159 if( *pnColorListState & CT_CHANGED )
160 pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
162 // LbColor
163 nPos = aLbColor.GetSelectEntryPos();
164 aLbColor.Clear();
165 aLbColor.Fill( pColorList );
166 nCount = aLbColor.GetEntryCount();
167 if( nCount == 0 )
168 ; // this case should not occur
169 else if( nCount <= nPos )
170 aLbColor.SelectEntryPos( 0 );
171 else
172 aLbColor.SelectEntryPos( nPos );
174 // LbColorBackground
175 nPos = aLbBackgroundColor.GetSelectEntryPos();
176 aLbBackgroundColor.Clear();
177 aLbBackgroundColor.CopyEntries( aLbColor );
178 nCount = aLbBackgroundColor.GetEntryCount();
179 if( nCount == 0 )
180 ; // this case should not occur
181 else if( nCount <= nPos )
182 aLbBackgroundColor.SelectEntryPos( 0 );
183 else
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 ) );
193 aString += ": ";
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 );
202 aString += "...";
204 else
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 )
225 return KEEP_PAGE;
227 if( _pSet )
228 FillItemSet( *_pSet );
230 return LEAVE_PAGE;
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()));
250 else
252 const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
254 _rOutAttrs.Put(XFillBitmapItem(String(), Graphic(aBitmapEx)));
259 return sal_True;
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() )
284 aBtnAdd.Enable();
285 aBtnModify.Enable();
286 aBtnDelete.Enable();
287 aBtnSave.Enable();
289 else
291 aBtnModify.Disable();
292 aBtnDelete.Disable();
293 aBtnSave.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());
316 else
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());
330 if(!pGraphicObject)
332 aLbBitmaps.SelectEntryPos(0);
333 nPos = aLbBitmaps.GetSelectEntryPos();
335 if(LISTBOX_ENTRY_NOTFOUND != nPos)
337 pGraphicObject = new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject());
342 if(pGraphicObject)
344 BitmapColor aBack;
345 BitmapColor aFront;
346 bool bIs8x8(isHistorical8x8(pGraphicObject->GetGraphic().GetBitmap(), aBack, aFront));
348 aLbColor.SetNoSelection();
349 aLbBackgroundColor.SetNoSelection();
351 if(bIs8x8)
353 aCtlPixel.SetPaintable( sal_True );
354 aCtlPixel.Enable();
355 aFtPixelEdit.Enable();
356 aFtColor.Enable();
357 aLbColor.Enable();
358 aFtBackgroundColor.Enable();
359 aLbBackgroundColor.Enable();
360 aBtnModify.Enable();
361 aBtnAdd.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 );
379 else
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 );
393 else
395 aCtlPixel.Reset();
396 aCtlPixel.SetPaintable( sal_False );
397 aCtlPixel.Disable();
398 aFtPixelEdit.Disable();
399 aFtColor.Disable();
400 aLbColor.Disable();
401 aFtBackgroundColor.Disable();
402 aLbBackgroundColor.Disable();
403 aBtnModify.Disable();
404 aBtnAdd.Disable();
407 aCtlPixel.Invalidate();
409 // display bitmap
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;
420 return 0;
423 // -----------------------------------------------------------------------
425 long SvxBitmapTabPage::CheckChanges_Impl()
427 sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
428 if( nPos != LISTBOX_ENTRY_NOTFOUND )
430 if( bBmpChanged )
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 ) ),
437 &aWarningBoxImage );
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();
446 switch( nRet )
448 case RET_BTN_1:
450 ClickModifyHdl_Impl( this );
452 break;
454 case RET_BTN_2:
456 ClickAddHdl_Impl( this );
457 nPos = aLbBitmaps.GetSelectEntryPos();
459 break;
461 case RET_CANCEL:
462 break;
464 delete aMessDlg;
467 nPos = aLbBitmaps.GetSelectEntryPos();
468 if( nPos != LISTBOX_ENTRY_NOTFOUND )
469 *pPos = nPos;
470 return 0L;
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 ) );
480 String aName;
482 long nCount = pBitmapList->Count();
483 long j = 1;
484 sal_Bool bDifferent = sal_False;
486 while( !bDifferent )
488 aName = aNewName;
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;
515 if( bDifferent ) {
516 nError = 0;
517 break;
520 if( !pWarnBox )
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 )
529 break;
531 delete pDlg;
532 delete pWarnBox;
534 if( !nError )
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 ?" );
555 if( pEntry )
557 pBitmapList->Insert( pEntry );
558 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
559 aLbBitmaps.Append(rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry );
560 aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
562 #ifdef WNT
563 // hack: #31355# W.P.
564 Rectangle aRect( aLbBitmaps.GetPosPixel(), aLbBitmaps.GetSizePixel() );
565 if( sal_True ) { // ??? overlapped with pDlg
566 // and srolling
567 Invalidate( aRect );
568 //aLbBitmaps.Invalidate();
570 #endif
572 *pnBitmapListState |= CT_MODIFIED;
574 ChangeBitmapHdl_Impl( this );
578 // determine button state
579 if( pBitmapList->Count() )
581 aBtnModify.Enable();
582 aBtnDelete.Enable();
583 aBtnSave.Enable();
585 return 0L;
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() )
603 Graphic aGraphic;
604 int nError = 1;
606 EnterWait();
607 nError = aDlg.GetGraphic( aGraphic );
608 LeaveWait();
610 if( !nError )
612 String aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP, rMgr) );
613 WarningBox* pWarnBox = NULL;
615 // convert file URL to UI name
616 String aName;
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;
635 if( bDifferent ) {
636 nError = 0;
637 break;
640 if( !pWarnBox )
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 )
650 break;
652 delete pDlg;
653 delete pWarnBox;
655 if( !nError )
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 );
664 #ifdef WNT
665 // hack: #31355# W.P.
666 Rectangle aRect( aLbBitmaps.GetPosPixel(), aLbBitmaps.GetSizePixel() );
667 if( sal_True ) { // ??? overlapped with pDlg
668 // and srolling
669 Invalidate( aRect );
671 #endif
673 *pnBitmapListState |= CT_MODIFIED;
675 ChangeBitmapHdl_Impl( this );
678 else
679 // graphic couldn't be loaded
680 ErrorBox( GetParentDialog(),
681 WinBits( WB_OK ),
682 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
685 return 0L;
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() &&
719 aName != aOldName )
720 bDifferent = sal_False;
723 if( bDifferent )
725 bLoop = 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;
741 else
743 WarningBox aBox( GetParentDialog(), WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
744 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
745 aBox.Execute();
748 delete pDlg;
750 return 0L;
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();
783 aBtnSave.Disable();
785 return 0L;
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 )
801 pBitmapList->Save();
804 if ( nReturn != RET_CANCEL )
806 ::sfx2::FileDialogHelper aDlg(
807 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
808 0 );
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 )
816 EnterWait();
817 INetURLObject aURL( aDlg.GetPath() );
818 INetURLObject aPathURL( aURL );
820 aPathURL.removeSegment();
821 aPathURL.removeFinalSlash();
823 // save table
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 );
832 aLbBitmaps.Clear();
833 aLbBitmaps.Fill( pBitmapList );
834 Reset( rOutAttrs );
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 ) );
841 aString += ": ";
843 if ( aURL.getBase().getLength() > 18 )
845 aString += aURL.getBase().copy( 0, 15 );
846 aString += "...";
848 else
849 aString += aURL.getBase();
851 *pnBitmapListState |= CT_CHANGED;
852 *pnBitmapListState &= ~CT_MODIFIED;
853 LeaveWait();
855 else
857 LeaveWait();
858 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
859 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
864 // determine button state
865 if( pBitmapList->Count() )
867 aBtnModify.Enable();
868 aBtnDelete.Enable();
869 aBtnSave.Enable();
871 else
873 aBtnModify.Disable();
874 aBtnDelete.Disable();
875 aBtnSave.Disable();
877 return 0L;
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 ) );
917 aString += ": ";
919 if ( aURL.getBase().getLength() > 18 )
921 aString += aURL.getBase().copy( 0, 15 );
922 aString += "...";
924 else
925 aString += aURL.getBase();
927 *pnBitmapListState |= CT_SAVED;
928 *pnBitmapListState &= ~CT_MODIFIED;
930 else
932 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
933 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
937 return 0L;
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;
956 return 0L;
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;
975 return 0L;
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);
1002 else
1003 return SvxTabPage::GetParentLabeledBy (pLabeled);
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */