1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
37 #define _SDR_NOTRANSFORM
38 #define _SDR_NOOBJECTS
40 #define _SDR_NOVIEWMARKER
41 #define _SDR_NODRAGMETHODS
43 #define _SDR_NOXOUTDEV
44 #include <vcl/wrkwin.hxx>
45 #include <tools/shl.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <tools/urlobj.hxx>
48 #include <unotools/ucbstreamhelper.hxx>
49 #include <unotools/pathoptions.hxx>
50 #include <sfx2/app.hxx>
51 #include <sfx2/filedlghelper.hxx>
52 #include <unotools/localfilehelper.hxx>
53 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
54 #include <svx/dialmgr.hxx>
55 #include <vcl/bmpacc.hxx>
56 #include <svx/dialogs.hrc>
58 #define _SVX_TPBITMAP_CXX
62 #include "svx/xattr.hxx"
63 #include <svx/xpool.hxx>
64 #include <svx/xtable.hxx>
65 #include "svx/xoutbmp.hxx"
66 #include "svx/drawitem.hxx"
67 #include "cuitabarea.hxx"
68 #include "tabarea.hrc"
69 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
70 //#include "dlgname.hrc"
71 #include <svx/svxdlg.hxx> //CHINA001
72 #include <dialmgr.hxx>
73 #include "sfx2/opengrf.hxx"
74 #include "paragrph.hrc"
76 #define DLGWIN this->GetParent()->GetParent()
78 /*************************************************************************
80 |* Dialog zum Aendern und Definieren der Bitmaps
82 \************************************************************************/
84 SvxBitmapTabPage::SvxBitmapTabPage
87 const SfxItemSet
& rInAttrs
90 SvxTabPage ( pParent
, CUI_RES( RID_SVXPAGE_BITMAP
), rInAttrs
),
92 aCtlPixel ( this, CUI_RES( CTL_PIXEL
) ),
93 aFtPixelEdit ( this, CUI_RES( FT_PIXEL_EDIT
) ),
94 aFtColor ( this, CUI_RES( FT_COLOR
) ),
95 aLbColor ( this, CUI_RES( LB_COLOR
) ),
96 aFtBackgroundColor ( this, CUI_RES( FT_BACKGROUND_COLOR
) ),
97 aLbBackgroundColor ( this, CUI_RES( LB_BACKGROUND_COLOR
) ),
98 // This fix text is used only to provide the name for the following
99 // bitmap list box. The fixed text is not displayed.
100 aLbBitmapsHidden ( this, CUI_RES( FT_BITMAPS_HIDDEN
) ),
101 aLbBitmaps ( this, CUI_RES( LB_BITMAPS
) ),
102 aFlProp ( this, CUI_RES( FL_PROP
) ),
103 aCtlPreview ( this, CUI_RES( CTL_PREVIEW
) ),
104 aBtnAdd ( this, CUI_RES( BTN_ADD
) ),
105 aBtnModify ( this, CUI_RES( BTN_MODIFY
) ),
106 aBtnImport ( this, CUI_RES( BTN_IMPORT
) ),
107 aBtnDelete ( this, CUI_RES( BTN_DELETE
) ),
108 aBtnLoad ( this, CUI_RES( BTN_LOAD
) ),
109 aBtnSave ( this, CUI_RES( BTN_SAVE
) ),
111 aBitmapCtl ( this, aCtlPreview
.GetSizePixel() ),
112 rOutAttrs ( rInAttrs
),
117 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
118 aXFStyleItem ( XFILL_BITMAP
),
119 aXBitmapItem ( String(), XOBitmap() ),
120 aXFillAttr ( pXPool
),
121 rXFSet ( aXFillAttr
.GetItemSet() )
123 aBtnLoad
.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H
) ), BMP_COLOR_HIGHCONTRAST
);
124 aBtnSave
.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H
) ), BMP_COLOR_HIGHCONTRAST
);
127 // diese Page braucht ExchangeSupport
128 SetExchangeSupport();
130 // Setzen des Output-Devices
131 rXFSet
.Put( aXFStyleItem
);
132 rXFSet
.Put( aXBitmapItem
);
133 //aCtlPreview.SetAttributes( aXFillAttr );
135 aBtnAdd
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickAddHdl_Impl
) );
136 aBtnImport
.SetClickHdl(
137 LINK( this, SvxBitmapTabPage
, ClickImportHdl_Impl
) );
138 aBtnModify
.SetClickHdl(
139 LINK( this, SvxBitmapTabPage
, ClickModifyHdl_Impl
) );
140 aBtnDelete
.SetClickHdl(
141 LINK( this, SvxBitmapTabPage
, ClickDeleteHdl_Impl
) );
142 aBtnLoad
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickLoadHdl_Impl
) );
143 aBtnSave
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickSaveHdl_Impl
) );
145 aLbBitmaps
.SetSelectHdl(
146 LINK( this, SvxBitmapTabPage
, ChangeBitmapHdl_Impl
) );
147 aLbColor
.SetSelectHdl(
148 LINK( this, SvxBitmapTabPage
, ChangePixelColorHdl_Impl
) );
149 aLbBackgroundColor
.SetSelectHdl(
150 LINK( this, SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
) );
152 String accName
= String(SVX_RES(STR_EXAMPLE
));
153 aCtlPreview
.SetAccessibleName(accName
);
154 aCtlPixel
.SetAccessibleRelationMemberOf( &aFlProp
);
155 aCtlPixel
.SetAccessibleRelationLabeledBy( &aFtPixelEdit
);
156 aLbBitmaps
.SetAccessibleRelationLabeledBy(&aLbBitmaps
);
157 aBtnAdd
.SetAccessibleRelationMemberOf( &aFlProp
);
158 aBtnModify
.SetAccessibleRelationMemberOf( &aFlProp
);
159 aBtnImport
.SetAccessibleRelationMemberOf( &aFlProp
);
160 aBtnDelete
.SetAccessibleRelationMemberOf( &aFlProp
);
164 // -----------------------------------------------------------------------
166 void SvxBitmapTabPage::Construct()
169 aLbColor
.Fill( pColorTab
);
170 aLbBackgroundColor
.CopyEntries( aLbColor
);
173 aLbBitmaps
.Fill( pBitmapList
);
176 // -----------------------------------------------------------------------
178 void SvxBitmapTabPage::ActivatePage( const SfxItemSet
& )
183 if( *pDlgType
== 0 ) // Flaechen-Dialog
185 *pbAreaTP
= sal_False
;
190 if( *pnColorTableState
& CT_CHANGED
||
191 *pnColorTableState
& CT_MODIFIED
)
193 if( *pnColorTableState
& CT_CHANGED
)
194 pColorTab
= ( (SvxAreaTabDialog
*) DLGWIN
)->GetNewColorTable();
197 nPos
= aLbColor
.GetSelectEntryPos();
199 aLbColor
.Fill( pColorTab
);
200 nCount
= aLbColor
.GetEntryCount();
202 ; // Dieser Fall sollte nicht auftreten
203 else if( nCount
<= nPos
)
204 aLbColor
.SelectEntryPos( 0 );
206 aLbColor
.SelectEntryPos( nPos
);
209 nPos
= aLbBackgroundColor
.GetSelectEntryPos();
210 aLbBackgroundColor
.Clear();
211 aLbBackgroundColor
.CopyEntries( aLbColor
);
212 nCount
= aLbBackgroundColor
.GetEntryCount();
214 ; // Dieser Fall sollte nicht auftreten
215 else if( nCount
<= nPos
)
216 aLbBackgroundColor
.SelectEntryPos( 0 );
218 aLbBackgroundColor
.SelectEntryPos( nPos
);
220 ChangePixelColorHdl_Impl( this );
221 ChangeBackgrndColorHdl_Impl( this );
224 // Ermitteln (evtl. abschneiden) des Namens und in
225 // der GroupBox darstellen
226 String
aString( CUI_RES( RID_SVXSTR_TABLE
) ); aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
227 INetURLObject
aURL( pBitmapList
->GetPath() );
229 aURL
.Append( pBitmapList
->GetName() );
230 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
232 if( aURL
.getBase().getLength() > 18 )
234 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
235 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
238 aString
+= String(aURL
.getBase());
240 if( *pPageType
== PT_BITMAP
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
242 aLbBitmaps
.SelectEntryPos( *pPos
);
244 // Farben koennten geloescht worden sein
245 ChangeBitmapHdl_Impl( this );
247 *pPageType
= PT_BITMAP
;
248 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
253 // -----------------------------------------------------------------------
255 int SvxBitmapTabPage::DeactivatePage( SfxItemSet
* _pSet
)
257 if ( CheckChanges_Impl() == -1L )
261 FillItemSet( *_pSet
);
266 // -----------------------------------------------------------------------
268 sal_Bool
SvxBitmapTabPage::FillItemSet( SfxItemSet
& _rOutAttrs
)
270 if( *pDlgType
== 0 && *pbAreaTP
== sal_False
) // Flaechen-Dialog
272 if( *pPageType
== PT_BITMAP
)
274 // CheckChanges_Impl(); <-- doppelte Abfrage ?
278 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
279 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
281 aXOBitmap
= pBitmapList
->GetBitmap( nPos
)->GetXBitmap();
282 aString
= aLbBitmaps
.GetSelectEntry();
287 aXOBitmap
= aBitmapCtl
.GetXBitmap();
289 // #85339# if it's an array, force conversion to bitmap before using it.
290 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
291 aXOBitmap
.GetBitmap();
294 _rOutAttrs
.Put( XFillStyleItem( XFILL_BITMAP
) );
295 _rOutAttrs
.Put( XFillBitmapItem( aString
, aXOBitmap
) );
301 // -----------------------------------------------------------------------
303 void SvxBitmapTabPage::Reset( const SfxItemSet
& )
305 // aLbBitmaps.SelectEntryPos( 0 );
307 aBitmapCtl
.SetLines( aCtlPixel
.GetLineCount() );
308 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
309 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
310 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
312 // Bitmap holen und darstellen
313 XFillBitmapItem
aBmpItem( (const String
&) String(), aBitmapCtl
.GetXBitmap() );
314 rXFSet
.Put( aBmpItem
);
315 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
316 aCtlPreview
.Invalidate();
318 ChangeBitmapHdl_Impl( this );
320 // Status der Buttons ermitteln
321 if( pBitmapList
->Count() )
330 aBtnModify
.Disable();
331 aBtnDelete
.Disable();
336 // -----------------------------------------------------------------------
338 SfxTabPage
* SvxBitmapTabPage::Create( Window
* pWindow
,
339 const SfxItemSet
& rSet
)
341 return new SvxBitmapTabPage( pWindow
, rSet
);
344 //------------------------------------------------------------------------
346 IMPL_LINK( SvxBitmapTabPage
, ChangeBitmapHdl_Impl
, void *, EMPTYARG
)
348 XOBitmap
* pXOBitmap
= NULL
;
349 int nPos
= aLbBitmaps
.GetSelectEntryPos();
351 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
352 pXOBitmap
= new XOBitmap( ( (XBitmapEntry
*) pBitmapList
->GetBitmap( nPos
) )->GetXBitmap() );
355 const SfxPoolItem
* pPoolItem
= NULL
;
356 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLSTYLE
), sal_True
, &pPoolItem
) )
358 XFillStyle eXFS
= (XFillStyle
) ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue();
359 if( ( XFILL_BITMAP
== eXFS
) &&
360 ( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLBITMAP
), sal_True
, &pPoolItem
) ) )
362 pXOBitmap
= new XOBitmap( ( ( const XFillBitmapItem
* ) pPoolItem
)->GetBitmapValue() );
367 aLbBitmaps
.SelectEntryPos( 0 );
368 nPos
= aLbBitmaps
.GetSelectEntryPos();
369 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
370 pXOBitmap
= new XOBitmap( ( (XBitmapEntry
*) pBitmapList
->GetBitmap( nPos
) )->GetXBitmap() );
375 //WorkWindow aTmpWW( DLGWIN );
376 //VirtualDevice aVD( aTmpWW );
377 //sal_uInt16 nLines = aCtlPixel.GetLineCount();
378 //Color aPixelColor, aBackColor;
379 //sal_Bool bPixelColor = sal_False;
380 //sal_uInt16 nWidth = pBitmap->GetSizePixel().Width();
381 //sal_uInt16 nHeight = pBitmap->GetSizePixel().Height();
383 // #85339# try to convert bitmapped item to array item.
384 if(pXOBitmap
->GetBitmapType() == XBITMAP_IMPORT
)
386 Bitmap
aBitmap(pXOBitmap
->GetBitmap());
387 Size
aSizePixel(aBitmap
.GetSizePixel());
389 if(8 == aSizePixel
.Width() && 8 == aSizePixel
.Height())
391 sal_uInt16
* pPixelArray
= new sal_uInt16
[64];
392 sal_uInt32
nCol1(0xffffffff); // background
393 sal_uInt32
nCol2(0xffffffff); // pixel
394 BitmapReadAccess
* pAccess
= aBitmap
.AcquireReadAccess();
395 sal_Bool
bValid(sal_True
);
399 for(sal_uInt32
a(0); bValid
&& a
< 64; a
++)
401 const BitmapColor aBmCol
= pAccess
->GetColor(a
>>3, a
%8);
402 Color
aRgbCol(aBmCol
.GetRed(), aBmCol
.GetGreen(), aBmCol
.GetBlue());
403 sal_uInt32 nColVal
= aRgbCol
.GetRGBColor();
408 if(0xffffffff == nCol1
)
410 // nCol1 is used first time
419 if(0xffffffff == nCol2
)
421 // nCol2 used first time
427 // Third color detected
433 // color is pixel color
440 // color is background color
445 // release ReadAccess
446 aBitmap
.ReleaseAccess(pAccess
);
450 // no access -> no success
459 // no pixel color found? Use opposite od background color.
460 if(0xffffffff == nCol2
)
463 0xff - aCol1
.GetRed(),
464 0xff - aCol1
.GetGreen(),
465 0xff - aCol1
.GetBlue());
468 // transformation did work, create a new Item
470 pXOBitmap
= new XOBitmap(pPixelArray
, aCol2
, aCol1
);
474 delete[] pPixelArray
;
478 aLbColor
.SetNoSelection();
479 aLbBackgroundColor
.SetNoSelection();
481 if( pXOBitmap
->GetBitmapType() == XBITMAP_IMPORT
)
484 aCtlPixel
.SetPaintable( sal_False
);
486 aFtPixelEdit
.Disable();
489 aFtBackgroundColor
.Disable();
490 aLbBackgroundColor
.Disable();
491 aBtnModify
.Disable();
494 else if( pXOBitmap
->GetBitmapType() == XBITMAP_8X8
)
496 aCtlPixel
.SetPaintable( sal_True
);
498 aFtPixelEdit
.Enable();
501 aFtBackgroundColor
.Enable();
502 aLbBackgroundColor
.Enable();
506 // Setzen des PixelControls
507 aCtlPixel
.SetXBitmap( *pXOBitmap
);
509 Color aPixelColor
= pXOBitmap
->GetPixelColor();
510 Color aBackColor
= pXOBitmap
->GetBackgroundColor();
512 aBitmapCtl
.SetPixelColor( aPixelColor
);
513 aBitmapCtl
.SetBackgroundColor( aBackColor
);
515 // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
516 // temporaer hinzugenommen
517 if( 0 == aLbBitmaps
.GetSelectEntryPos() )
519 aLbColor
.SelectEntry( Color( COL_BLACK
) );
520 ChangePixelColorHdl_Impl( this );
523 aLbColor
.SelectEntry( aPixelColor
);
524 if( aLbColor
.GetSelectEntryCount() == 0 )
526 aLbColor
.InsertEntry( aPixelColor
, String() );
527 aLbColor
.SelectEntry( aPixelColor
);
529 aLbBackgroundColor
.SelectEntry( aBackColor
);
530 if( aLbBackgroundColor
.GetSelectEntryCount() == 0 )
532 aLbBackgroundColor
.InsertEntry( aBackColor
, String() );
533 aLbBackgroundColor
.SelectEntry( aBackColor
);
536 aCtlPixel
.Invalidate();
539 XFillBitmapItem
aXBmpItem( (const String
&) String(), *pXOBitmap
);
540 rXFSet
.Put( aXBmpItem
);
542 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
543 aCtlPreview
.Invalidate();
545 bBmpChanged
= sal_False
;
551 // -----------------------------------------------------------------------
553 long SvxBitmapTabPage::CheckChanges_Impl()
555 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
556 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
558 String aString
= aLbBitmaps
.GetSelectEntry();
562 ResMgr
& rMgr
= CUI_MGR();
563 Image aWarningBoxImage
= WarningBox::GetStandardImage();
564 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
565 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
566 AbstractSvxMessDialog
* aMessDlg
= pFact
->CreateSvxMessDialog( DLGWIN
, RID_SVXDLG_MESSBOX
,
567 String( SVX_RES( RID_SVXSTR_BITMAP
) ),
568 String( CUI_RES( RID_SVXSTR_ASK_CHANGE_BITMAP
) ),
570 DBG_ASSERT(aMessDlg
, "Dialogdiet fail!");//CHINA001
571 aMessDlg
->SetButtonText( MESS_BTN_1
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
572 String( ResId( RID_SVXSTR_CHANGE
, rMgr
) ) );
573 aMessDlg
->SetButtonText( MESS_BTN_2
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
574 String( ResId( RID_SVXSTR_ADD
, rMgr
) ) );
576 short nRet
= aMessDlg
->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
580 case RET_BTN_1
: // Aendern
582 ClickModifyHdl_Impl( this );
586 case RET_BTN_2
: // Hinzufuegen
588 ClickAddHdl_Impl( this );
589 nPos
= aLbBitmaps
.GetSelectEntryPos();
596 // return( sal_True ); // Abbruch
598 delete aMessDlg
; //add by CHINA001
601 nPos
= aLbBitmaps
.GetSelectEntryPos();
602 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
607 //------------------------------------------------------------------------
609 IMPL_LINK( SvxBitmapTabPage
, ClickAddHdl_Impl
, void *, EMPTYARG
)
611 ResMgr
& rMgr
= CUI_MGR();
612 String
aNewName( SVX_RES( RID_SVXSTR_BITMAP
) );
613 String
aDesc( CUI_RES( RID_SVXSTR_DESC_NEW_BITMAP
) );
616 long nCount
= pBitmapList
->Count();
618 sal_Bool bDifferent
= sal_False
;
623 aName
+= sal_Unicode(' ');
624 aName
+= UniString::CreateFromInt32( j
++ );
625 bDifferent
= sal_True
;
627 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
628 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
629 bDifferent
= sal_False
;
632 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
633 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
634 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
635 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
636 WarningBox
* pWarnBox
= NULL
;
637 sal_uInt16 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
639 while( pDlg
->Execute() == RET_OK
)
641 pDlg
->GetName( aName
);
643 bDifferent
= sal_True
;
645 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
646 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
647 bDifferent
= sal_False
;
656 pWarnBox
= new WarningBox( DLGWIN
,
657 WinBits( WB_OK_CANCEL
),
658 String( ResId( nError
, rMgr
) ) );
659 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
662 if( pWarnBox
->Execute() != RET_OK
)
665 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
671 XBitmapEntry
* pEntry
= 0;
672 if( aCtlPixel
.IsEnabled() )
674 XOBitmap aXOBitmap
= aBitmapCtl
.GetXBitmap();
676 // #85339# if it's an array, force conversion to bitmap before using it.
677 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
678 aXOBitmap
.GetBitmap();
680 pEntry
= new XBitmapEntry( aXOBitmap
, aName
);
682 else // Es muss sich um eine nicht vorhandene importierte Bitmap handeln
684 const SfxPoolItem
* pPoolItem
= NULL
;
685 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( XATTR_FILLBITMAP
, sal_True
, &pPoolItem
) )
687 XOBitmap
aXOBitmap( ( ( const XFillBitmapItem
* ) pPoolItem
)->GetBitmapValue() );
688 pEntry
= new XBitmapEntry( aXOBitmap
, aName
);
692 DBG_ASSERT( pEntry
, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
696 pBitmapList
->Insert( pEntry
);
698 aLbBitmaps
.Append( pEntry
);
699 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
702 // hack: #31355# W.P.
703 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
704 if( sal_True
) { // ??? overlapped with pDlg
707 //aLbBitmaps.Invalidate();
711 // Flag fuer modifiziert setzen
712 *pnBitmapListState
|= CT_MODIFIED
;
714 ChangeBitmapHdl_Impl( this );
718 // Status der Buttons ermitteln
719 if( pBitmapList
->Count() )
729 /******************************************************************************/
730 /******************************************************************************/
733 //------------------------------------------------------------------------
736 #pragma optimize ( "", off )
739 IMPL_LINK( SvxBitmapTabPage
, ClickImportHdl_Impl
, void *, EMPTYARG
)
741 ResMgr
& rMgr
= CUI_MGR();
742 SvxOpenGraphicDialog
aDlg( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Import" ) ) );
743 aDlg
.EnableLink(sal_False
);
745 if( !aDlg
.Execute() )
751 nError
= aDlg
.GetGraphic( aGraphic
);
756 String
aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP
, rMgr
) );
757 WarningBox
* pWarnBox
= NULL
;
759 // convert file URL to UI name
761 INetURLObject
aURL( aDlg
.GetPath() );
762 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
763 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
764 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, String(aURL
.GetName()).GetToken( 0, '.' ), aDesc
);
765 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
766 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
768 while( pDlg
->Execute() == RET_OK
)
770 pDlg
->GetName( aName
);
772 sal_Bool bDifferent
= sal_True
;
773 long nCount
= pBitmapList
->Count();
775 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
776 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
777 bDifferent
= sal_False
;
786 pWarnBox
= new WarningBox( DLGWIN
,
787 WinBits( WB_OK_CANCEL
),
788 String( ResId( nError
, rMgr
) ) );
789 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
793 if( pWarnBox
->Execute() != RET_OK
)
796 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
802 Bitmap
aBmp( aGraphic
.GetBitmap() );
803 XBitmapEntry
* pEntry
=
804 new XBitmapEntry( XOBitmap( aBmp
), aName
);
805 pBitmapList
->Insert( pEntry
);
807 aLbBitmaps
.Append( pEntry
);
808 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
811 // hack: #31355# W.P.
812 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
813 if( sal_True
) { // ??? overlapped with pDlg
816 //aLbBitmaps.Invalidate();
820 // Flag fuer modifiziert setzen
821 *pnBitmapListState
|= CT_MODIFIED
;
823 ChangeBitmapHdl_Impl( this );
827 // Graphik konnte nicht geladen werden
830 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
837 #pragma optimize ( "", on )
840 //------------------------------------------------------------------------
842 IMPL_LINK( SvxBitmapTabPage
, ClickModifyHdl_Impl
, void *, EMPTYARG
)
844 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
846 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
848 ResMgr
& rMgr
= CUI_MGR();
849 String
aNewName( SVX_RES( RID_SVXSTR_BITMAP
) );
850 String
aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP
, rMgr
) );
851 String
aName( pBitmapList
->GetBitmap( nPos
)->GetName() );
852 String aOldName
= aName
;
854 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
855 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
856 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
857 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
859 long nCount
= pBitmapList
->Count();
860 sal_Bool bDifferent
= sal_False
;
861 sal_Bool bLoop
= sal_True
;
863 while( bLoop
&& pDlg
->Execute() == RET_OK
)
865 pDlg
->GetName( aName
);
866 bDifferent
= sal_True
;
868 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
870 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() &&
872 bDifferent
= sal_False
;
878 XBitmapEntry
* pEntry
= pBitmapList
->GetBitmap( nPos
);
880 pEntry
->SetName( aName
);
882 XOBitmap aXOBitmap
= aBitmapCtl
.GetXBitmap();
884 // #85339# if it's an array, force conversion to bitmap before using it.
885 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
886 aXOBitmap
.GetBitmap();
888 pEntry
->SetXBitmap( aXOBitmap
);
890 aLbBitmaps
.Modify( pEntry
, nPos
);
891 aLbBitmaps
.SelectEntryPos( nPos
);
893 // Flag fuer modifiziert setzen
894 *pnBitmapListState
|= CT_MODIFIED
;
896 bBmpChanged
= sal_False
;
900 WarningBox
aBox( DLGWIN
, WinBits( WB_OK
), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
901 aBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
910 //------------------------------------------------------------------------
912 IMPL_LINK( SvxBitmapTabPage
, ClickDeleteHdl_Impl
, void *, EMPTYARG
)
914 sal_uInt16 nPos
= aLbBitmaps
.GetSelectEntryPos();
916 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
918 QueryBox
aQueryBox( DLGWIN
, WinBits( WB_YES_NO
| WB_DEF_NO
),
919 String( CUI_RES( RID_SVXSTR_ASK_DEL_BITMAP
) ) );
921 if( aQueryBox
.Execute() == RET_YES
)
923 delete pBitmapList
->Remove( nPos
);
924 aLbBitmaps
.RemoveEntry( nPos
);
925 aLbBitmaps
.SelectEntryPos( 0 );
927 aCtlPreview
.Invalidate();
928 aCtlPixel
.Invalidate();
930 ChangeBitmapHdl_Impl( this );
932 // Flag fuer modifiziert setzen
933 *pnBitmapListState
|= CT_MODIFIED
;
936 // Status der Buttons ermitteln
937 if( !pBitmapList
->Count() )
939 aBtnModify
.Disable();
940 aBtnDelete
.Disable();
946 // -----------------------------------------------------------------------
948 IMPL_LINK( SvxBitmapTabPage
, ClickLoadHdl_Impl
, void *, EMPTYARG
)
950 sal_uInt16 nReturn
= RET_YES
;
951 ResMgr
& rMgr
= CUI_MGR();
953 if ( *pnBitmapListState
& CT_MODIFIED
)
955 nReturn
= WarningBox( DLGWIN
, WinBits( WB_YES_NO_CANCEL
),
956 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
958 if ( nReturn
== RET_YES
)
962 if ( nReturn
!= RET_CANCEL
)
964 ::sfx2::FileDialogHelper
aDlg(
965 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
967 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
968 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
969 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
970 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
972 if ( aDlg
.Execute() == ERRCODE_NONE
)
975 INetURLObject
aURL( aDlg
.GetPath() );
976 INetURLObject
aPathURL( aURL
);
978 aPathURL
.removeSegment();
979 aPathURL
.removeFinalSlash();
982 XBitmapList
* pBmpList
= new XBitmapList( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
983 pBmpList
->SetName( aURL
.getName() );
984 if( pBmpList
->Load() )
988 // Pruefen, ob Tabelle geloescht werden darf:
989 if( pBitmapList
!= ( (SvxAreaTabDialog
*) DLGWIN
)->GetBitmapList() )
992 pBitmapList
= pBmpList
;
993 ( (SvxAreaTabDialog
*) DLGWIN
)->SetNewBitmapList( pBitmapList
);
996 aLbBitmaps
.Fill( pBitmapList
);
999 pBitmapList
->SetName( aURL
.getName() );
1001 // Ermitteln (evtl. abschneiden) des Namens und in
1002 // der GroupBox darstellen
1003 String
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
1004 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
1006 if ( aURL
.getBase().getLength() > 18 )
1008 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
1009 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1012 aString
+= String(aURL
.getBase());
1014 // Flag fuer gewechselt setzen
1015 *pnBitmapListState
|= CT_CHANGED
;
1016 // Flag fuer modifiziert entfernen
1017 *pnBitmapListState
&= ~CT_MODIFIED
;
1024 ErrorBox( DLGWIN
, WinBits( WB_OK
),
1025 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
1030 // Status der Buttons ermitteln
1031 if( pBitmapList
->Count() )
1033 aBtnModify
.Enable();
1034 aBtnDelete
.Enable();
1039 aBtnModify
.Disable();
1040 aBtnDelete
.Disable();
1046 // -----------------------------------------------------------------------
1048 IMPL_LINK( SvxBitmapTabPage
, ClickSaveHdl_Impl
, void *, EMPTYARG
)
1050 ::sfx2::FileDialogHelper
aDlg(
1051 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
1052 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
1053 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
1055 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
1056 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
1058 if( pBitmapList
->GetName().Len() )
1060 aFile
.Append( pBitmapList
->GetName() );
1062 if( !aFile
.getExtension().getLength() )
1063 aFile
.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sob" ) ) );
1066 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
1067 if ( aDlg
.Execute() == ERRCODE_NONE
)
1069 INetURLObject
aURL( aDlg
.GetPath() );
1070 INetURLObject
aPathURL( aURL
);
1072 aPathURL
.removeSegment();
1073 aPathURL
.removeFinalSlash();
1075 pBitmapList
->SetName( aURL
.getName() );
1076 pBitmapList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
1078 if( pBitmapList
->Save() )
1080 // Ermitteln (evtl. abschneiden) des Namens und in
1081 // der GroupBox darstellen
1082 String
aString( CUI_RES( RID_SVXSTR_TABLE
) );
1083 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
1085 if ( aURL
.getBase().getLength() > 18 )
1087 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
1088 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1091 aString
+= String(aURL
.getBase());
1093 // Flag fuer gespeichert setzen
1094 *pnBitmapListState
|= CT_SAVED
;
1095 // Flag fuer modifiziert entfernen
1096 *pnBitmapListState
&= ~CT_MODIFIED
;
1100 ErrorBox( DLGWIN
, WinBits( WB_OK
),
1101 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) ).Execute();
1108 //------------------------------------------------------------------------
1110 IMPL_LINK( SvxBitmapTabPage
, ChangePixelColorHdl_Impl
, void *, EMPTYARG
)
1112 aCtlPixel
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
1113 aCtlPixel
.Invalidate();
1115 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
1117 // Bitmap holen und darstellen
1118 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1119 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1120 aCtlPreview
.Invalidate();
1122 bBmpChanged
= sal_True
;
1127 //------------------------------------------------------------------------
1129 IMPL_LINK( SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
, void *, EMPTYARG
)
1131 aCtlPixel
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
1132 aCtlPixel
.Invalidate();
1134 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
1136 // Bitmap holen und darstellen
1137 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1138 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1139 aCtlPreview
.Invalidate();
1141 bBmpChanged
= sal_True
;
1146 //------------------------------------------------------------------------
1148 void SvxBitmapTabPage::PointChanged( Window
* pWindow
, RECT_POINT
)
1150 if( pWindow
== &aCtlPixel
)
1152 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
1154 // Bitmap holen und darstellen
1155 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1156 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1157 aCtlPreview
.Invalidate();
1159 bBmpChanged
= sal_True
;
1166 Window
* SvxBitmapTabPage::GetParentLabeledBy( const Window
* pLabeled
) const
1168 if (pLabeled
== &aLbBitmaps
)
1169 return const_cast<FixedText
*>(&aLbBitmapsHidden
);
1171 return SvxTabPage::GetParentLabeledBy (pLabeled
);