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: tpbitmap.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 ---------------------------------------------------------------
44 #define _SDR_NOTRANSFORM
45 #define _SDR_NOOBJECTS
47 #define _SDR_NOVIEWMARKER
48 #define _SDR_NODRAGMETHODS
50 #define _SDR_NOXOUTDEV
51 #include <vcl/wrkwin.hxx>
52 #include <tools/shl.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <tools/urlobj.hxx>
55 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
56 #include <unotools/ucbstreamhelper.hxx>
58 #include <svtools/pathoptions.hxx>
59 #include <sfx2/app.hxx>
60 #include <sfx2/filedlghelper.hxx>
61 #include <unotools/localfilehelper.hxx>
62 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
63 #include <vcl/bmpacc.hxx>
65 #define _SVX_TPBITMAP_CXX
69 #include <svx/dialogs.hrc>
73 #include <svx/xpool.hxx>
74 #include <svx/xtable.hxx>
75 #include "xoutbmp.hxx"
76 #include "drawitem.hxx"
77 #include "cuitabarea.hxx"
78 #include "tabarea.hrc"
79 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
80 #include "dlgname.hrc"
81 #include <svx/svxdlg.hxx> //CHINA001
82 #include <svx/dialmgr.hxx>
83 #include "opengrf.hxx"
85 #define DLGWIN this->GetParent()->GetParent()
87 /*************************************************************************
89 |* Dialog zum Aendern und Definieren der Bitmaps
91 \************************************************************************/
93 SvxBitmapTabPage::SvxBitmapTabPage
96 const SfxItemSet
& rInAttrs
99 SvxTabPage ( pParent
, SVX_RES( RID_SVXPAGE_BITMAP
), rInAttrs
),
101 aCtlPixel ( this, SVX_RES( CTL_PIXEL
) ),
102 aFtPixelEdit ( this, SVX_RES( FT_PIXEL_EDIT
) ),
103 aFtColor ( this, SVX_RES( FT_COLOR
) ),
104 aLbColor ( this, SVX_RES( LB_COLOR
) ),
105 aFtBackgroundColor ( this, SVX_RES( FT_BACKGROUND_COLOR
) ),
106 aLbBackgroundColor ( this, SVX_RES( LB_BACKGROUND_COLOR
) ),
107 // This fix text is used only to provide the name for the following
108 // bitmap list box. The fixed text is not displayed.
109 aLbBitmapsHidden ( this, SVX_RES( FT_BITMAPS_HIDDEN
) ),
110 aLbBitmaps ( this, SVX_RES( LB_BITMAPS
) ),
111 aFlProp ( this, SVX_RES( FL_PROP
) ),
112 aCtlPreview ( this, SVX_RES( CTL_PREVIEW
) ),
113 aBtnAdd ( this, SVX_RES( BTN_ADD
) ),
114 aBtnModify ( this, SVX_RES( BTN_MODIFY
) ),
115 aBtnImport ( this, SVX_RES( BTN_IMPORT
) ),
116 aBtnDelete ( this, SVX_RES( BTN_DELETE
) ),
117 aBtnLoad ( this, SVX_RES( BTN_LOAD
) ),
118 aBtnSave ( this, SVX_RES( BTN_SAVE
) ),
120 aBitmapCtl ( this, aCtlPreview
.GetSizePixel() ),
121 rOutAttrs ( rInAttrs
),
126 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
127 aXFStyleItem ( XFILL_BITMAP
),
128 aXBitmapItem ( String(), XOBitmap() ),
129 aXFillAttr ( pXPool
),
130 rXFSet ( aXFillAttr
.GetItemSet() )
132 aBtnLoad
.SetModeImage( Image( SVX_RES( RID_SVXIMG_LOAD_H
) ), BMP_COLOR_HIGHCONTRAST
);
133 aBtnSave
.SetModeImage( Image( SVX_RES( RID_SVXIMG_SAVE_H
) ), BMP_COLOR_HIGHCONTRAST
);
136 // diese Page braucht ExchangeSupport
137 SetExchangeSupport();
139 // Setzen des Output-Devices
140 rXFSet
.Put( aXFStyleItem
);
141 rXFSet
.Put( aXBitmapItem
);
142 //aCtlPreview.SetAttributes( aXFillAttr );
144 aBtnAdd
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickAddHdl_Impl
) );
145 aBtnImport
.SetClickHdl(
146 LINK( this, SvxBitmapTabPage
, ClickImportHdl_Impl
) );
147 aBtnModify
.SetClickHdl(
148 LINK( this, SvxBitmapTabPage
, ClickModifyHdl_Impl
) );
149 aBtnDelete
.SetClickHdl(
150 LINK( this, SvxBitmapTabPage
, ClickDeleteHdl_Impl
) );
151 aBtnLoad
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickLoadHdl_Impl
) );
152 aBtnSave
.SetClickHdl( LINK( this, SvxBitmapTabPage
, ClickSaveHdl_Impl
) );
154 aLbBitmaps
.SetSelectHdl(
155 LINK( this, SvxBitmapTabPage
, ChangeBitmapHdl_Impl
) );
156 aLbColor
.SetSelectHdl(
157 LINK( this, SvxBitmapTabPage
, ChangePixelColorHdl_Impl
) );
158 aLbBackgroundColor
.SetSelectHdl(
159 LINK( this, SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
) );
163 // -----------------------------------------------------------------------
165 void SvxBitmapTabPage::Construct()
168 aLbColor
.Fill( pColorTab
);
169 aLbBackgroundColor
.CopyEntries( aLbColor
);
172 aLbBitmaps
.Fill( pBitmapList
);
175 // -----------------------------------------------------------------------
177 void SvxBitmapTabPage::ActivatePage( const SfxItemSet
& )
182 if( *pDlgType
== 0 ) // Flaechen-Dialog
189 if( *pnColorTableState
& CT_CHANGED
||
190 *pnColorTableState
& CT_MODIFIED
)
192 if( *pnColorTableState
& CT_CHANGED
)
193 pColorTab
= ( (SvxAreaTabDialog
*) DLGWIN
)->GetNewColorTable();
196 nPos
= aLbColor
.GetSelectEntryPos();
198 aLbColor
.Fill( pColorTab
);
199 nCount
= aLbColor
.GetEntryCount();
201 ; // Dieser Fall sollte nicht auftreten
202 else if( nCount
<= nPos
)
203 aLbColor
.SelectEntryPos( 0 );
205 aLbColor
.SelectEntryPos( nPos
);
208 nPos
= aLbBackgroundColor
.GetSelectEntryPos();
209 aLbBackgroundColor
.Clear();
210 aLbBackgroundColor
.CopyEntries( aLbColor
);
211 nCount
= aLbBackgroundColor
.GetEntryCount();
213 ; // Dieser Fall sollte nicht auftreten
214 else if( nCount
<= nPos
)
215 aLbBackgroundColor
.SelectEntryPos( 0 );
217 aLbBackgroundColor
.SelectEntryPos( nPos
);
219 ChangePixelColorHdl_Impl( this );
220 ChangeBackgrndColorHdl_Impl( this );
223 // Ermitteln (evtl. abschneiden) des Namens und in
224 // der GroupBox darstellen
225 String
aString( SVX_RES( RID_SVXSTR_TABLE
) ); aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
226 INetURLObject
aURL( pBitmapList
->GetPath() );
228 aURL
.Append( pBitmapList
->GetName() );
229 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
231 if( aURL
.getBase().getLength() > 18 )
233 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
234 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
237 aString
+= String(aURL
.getBase());
239 if( *pPageType
== PT_BITMAP
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
241 aLbBitmaps
.SelectEntryPos( *pPos
);
243 // Farben koennten geloescht worden sein
244 ChangeBitmapHdl_Impl( this );
246 *pPageType
= PT_BITMAP
;
247 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
252 // -----------------------------------------------------------------------
254 int SvxBitmapTabPage::DeactivatePage( SfxItemSet
* _pSet
)
256 if ( CheckChanges_Impl() == -1L )
260 FillItemSet( *_pSet
);
265 // -----------------------------------------------------------------------
267 BOOL
SvxBitmapTabPage::FillItemSet( SfxItemSet
& _rOutAttrs
)
269 if( *pDlgType
== 0 && *pbAreaTP
== FALSE
) // Flaechen-Dialog
271 if( *pPageType
== PT_BITMAP
)
273 // CheckChanges_Impl(); <-- doppelte Abfrage ?
277 USHORT nPos
= aLbBitmaps
.GetSelectEntryPos();
278 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
280 aXOBitmap
= pBitmapList
->GetBitmap( nPos
)->GetXBitmap();
281 aString
= aLbBitmaps
.GetSelectEntry();
286 aXOBitmap
= aBitmapCtl
.GetXBitmap();
288 // #85339# if it's an array, force conversion to bitmap before using it.
289 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
290 aXOBitmap
.GetBitmap();
293 _rOutAttrs
.Put( XFillStyleItem( XFILL_BITMAP
) );
294 _rOutAttrs
.Put( XFillBitmapItem( aString
, aXOBitmap
) );
300 // -----------------------------------------------------------------------
302 void SvxBitmapTabPage::Reset( const SfxItemSet
& )
304 // aLbBitmaps.SelectEntryPos( 0 );
306 aBitmapCtl
.SetLines( aCtlPixel
.GetLineCount() );
307 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
308 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
309 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
311 // Bitmap holen und darstellen
312 XFillBitmapItem
aBmpItem( (const String
&) String(), aBitmapCtl
.GetXBitmap() );
313 rXFSet
.Put( aBmpItem
);
314 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
315 aCtlPreview
.Invalidate();
317 ChangeBitmapHdl_Impl( this );
319 // Status der Buttons ermitteln
320 if( pBitmapList
->Count() )
329 aBtnModify
.Disable();
330 aBtnDelete
.Disable();
335 // -----------------------------------------------------------------------
337 SfxTabPage
* SvxBitmapTabPage::Create( Window
* pWindow
,
338 const SfxItemSet
& rSet
)
340 return new SvxBitmapTabPage( pWindow
, rSet
);
343 //------------------------------------------------------------------------
345 IMPL_LINK( SvxBitmapTabPage
, ChangeBitmapHdl_Impl
, void *, EMPTYARG
)
347 XOBitmap
* pXOBitmap
= NULL
;
348 int nPos
= aLbBitmaps
.GetSelectEntryPos();
350 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
351 pXOBitmap
= new XOBitmap( ( (XBitmapEntry
*) pBitmapList
->GetBitmap( nPos
) )->GetXBitmap() );
354 const SfxPoolItem
* pPoolItem
= NULL
;
355 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLSTYLE
), TRUE
, &pPoolItem
) )
357 XFillStyle eXFS
= (XFillStyle
) ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue();
358 if( ( XFILL_BITMAP
== eXFS
) &&
359 ( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLBITMAP
), TRUE
, &pPoolItem
) ) )
361 pXOBitmap
= new XOBitmap( ( ( const XFillBitmapItem
* ) pPoolItem
)->GetBitmapValue() );
366 aLbBitmaps
.SelectEntryPos( 0 );
367 nPos
= aLbBitmaps
.GetSelectEntryPos();
368 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
369 pXOBitmap
= new XOBitmap( ( (XBitmapEntry
*) pBitmapList
->GetBitmap( nPos
) )->GetXBitmap() );
374 //WorkWindow aTmpWW( DLGWIN );
375 //VirtualDevice aVD( aTmpWW );
376 //USHORT nLines = aCtlPixel.GetLineCount();
377 //Color aPixelColor, aBackColor;
378 //BOOL bPixelColor = FALSE;
379 //USHORT nWidth = pBitmap->GetSizePixel().Width();
380 //USHORT nHeight = pBitmap->GetSizePixel().Height();
382 // #85339# try to convert bitmapped item to array item.
383 if(pXOBitmap
->GetBitmapType() == XBITMAP_IMPORT
)
385 Bitmap
aBitmap(pXOBitmap
->GetBitmap());
386 Size
aSizePixel(aBitmap
.GetSizePixel());
388 if(8 == aSizePixel
.Width() && 8 == aSizePixel
.Height())
390 sal_uInt16
* pPixelArray
= new sal_uInt16
[64];
391 sal_uInt32
nCol1(0xffffffff); // background
392 sal_uInt32
nCol2(0xffffffff); // pixel
393 BitmapReadAccess
* pAccess
= aBitmap
.AcquireReadAccess();
394 sal_Bool
bValid(TRUE
);
398 for(sal_uInt32
a(0); bValid
&& a
< 64; a
++)
400 const BitmapColor aBmCol
= pAccess
->GetColor(a
>>3, a
%8);
401 Color
aRgbCol(aBmCol
.GetRed(), aBmCol
.GetGreen(), aBmCol
.GetBlue());
402 sal_uInt32 nColVal
= aRgbCol
.GetRGBColor();
407 if(0xffffffff == nCol1
)
409 // nCol1 is used first time
418 if(0xffffffff == nCol2
)
420 // nCol2 used first time
426 // Third color detected
432 // color is pixel color
439 // color is background color
444 // release ReadAccess
445 aBitmap
.ReleaseAccess(pAccess
);
449 // no access -> no success
458 // no pixel color found? Use opposite od background color.
459 if(0xffffffff == nCol2
)
462 0xff - aCol1
.GetRed(),
463 0xff - aCol1
.GetGreen(),
464 0xff - aCol1
.GetBlue());
467 // transformation did work, create a new Item
469 pXOBitmap
= new XOBitmap(pPixelArray
, aCol2
, aCol1
);
473 delete[] pPixelArray
;
477 aLbColor
.SetNoSelection();
478 aLbBackgroundColor
.SetNoSelection();
480 if( pXOBitmap
->GetBitmapType() == XBITMAP_IMPORT
)
483 aCtlPixel
.SetPaintable( FALSE
);
485 aFtPixelEdit
.Disable();
488 aFtBackgroundColor
.Disable();
489 aLbBackgroundColor
.Disable();
490 aBtnModify
.Disable();
493 else if( pXOBitmap
->GetBitmapType() == XBITMAP_8X8
)
495 aCtlPixel
.SetPaintable( TRUE
);
497 aFtPixelEdit
.Enable();
500 aFtBackgroundColor
.Enable();
501 aLbBackgroundColor
.Enable();
505 // Setzen des PixelControls
506 aCtlPixel
.SetXBitmap( *pXOBitmap
);
508 Color aPixelColor
= pXOBitmap
->GetPixelColor();
509 Color aBackColor
= pXOBitmap
->GetBackgroundColor();
511 aBitmapCtl
.SetPixelColor( aPixelColor
);
512 aBitmapCtl
.SetBackgroundColor( aBackColor
);
514 // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
515 // temporaer hinzugenommen
516 if( 0 == aLbBitmaps
.GetSelectEntryPos() )
518 aLbColor
.SelectEntry( Color( COL_BLACK
) );
519 ChangePixelColorHdl_Impl( this );
522 aLbColor
.SelectEntry( aPixelColor
);
523 if( aLbColor
.GetSelectEntryCount() == 0 )
525 aLbColor
.InsertEntry( aPixelColor
, String() );
526 aLbColor
.SelectEntry( aPixelColor
);
528 aLbBackgroundColor
.SelectEntry( aBackColor
);
529 if( aLbBackgroundColor
.GetSelectEntryCount() == 0 )
531 aLbBackgroundColor
.InsertEntry( aBackColor
, String() );
532 aLbBackgroundColor
.SelectEntry( aBackColor
);
535 aCtlPixel
.Invalidate();
538 XFillBitmapItem
aXBmpItem( (const String
&) String(), *pXOBitmap
);
539 rXFSet
.Put( aXBmpItem
);
541 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
542 aCtlPreview
.Invalidate();
550 // -----------------------------------------------------------------------
552 long SvxBitmapTabPage::CheckChanges_Impl()
554 USHORT nPos
= aLbBitmaps
.GetSelectEntryPos();
555 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
557 String aString
= aLbBitmaps
.GetSelectEntry();
561 ResMgr
& rMgr
= DIALOG_MGR();
562 Image aWarningBoxImage
= WarningBox::GetStandardImage();
563 //CHINA001 SvxMessDialog aMessDlg( DLGWIN,
564 //CHINA001 String( SVX_RES( RID_SVXSTR_BITMAP, rMgr ) ),
565 //CHINA001 String( SVX_RES( RID_SVXSTR_ASK_CHANGE_BITMAP, rMgr ) ),
566 //CHINA001 &aWarningBoxImage );
567 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
568 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
569 AbstractSvxMessDialog
* aMessDlg
= pFact
->CreateSvxMessDialog( DLGWIN
, RID_SVXDLG_MESSBOX
,
570 String( ResId( RID_SVXSTR_BITMAP
, rMgr
) ),
571 String( ResId( RID_SVXSTR_ASK_CHANGE_BITMAP
, rMgr
) ),
573 DBG_ASSERT(aMessDlg
, "Dialogdiet fail!");//CHINA001
574 aMessDlg
->SetButtonText( MESS_BTN_1
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
575 String( ResId( RID_SVXSTR_CHANGE
, rMgr
) ) );
576 aMessDlg
->SetButtonText( MESS_BTN_2
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
577 String( ResId( RID_SVXSTR_ADD
, rMgr
) ) );
579 short nRet
= aMessDlg
->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
583 case RET_BTN_1
: // Aendern
585 ClickModifyHdl_Impl( this );
589 case RET_BTN_2
: // Hinzufuegen
591 ClickAddHdl_Impl( this );
592 nPos
= aLbBitmaps
.GetSelectEntryPos();
599 // return( TRUE ); // Abbruch
601 delete aMessDlg
; //add by CHINA001
604 nPos
= aLbBitmaps
.GetSelectEntryPos();
605 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
610 //------------------------------------------------------------------------
612 IMPL_LINK( SvxBitmapTabPage
, ClickAddHdl_Impl
, void *, EMPTYARG
)
614 ResMgr
& rMgr
= DIALOG_MGR();
615 String
aNewName( ResId( RID_SVXSTR_BITMAP
, rMgr
) );
616 String
aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP
, rMgr
) );
619 long nCount
= pBitmapList
->Count();
621 BOOL bDifferent
= FALSE
;
626 aName
+= sal_Unicode(' ');
627 aName
+= UniString::CreateFromInt32( j
++ );
630 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
631 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
635 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
636 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
637 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
638 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
, RID_SVXDLG_NAME
);
639 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
640 WarningBox
* pWarnBox
= NULL
;
641 USHORT nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
643 while( pDlg
->Execute() == RET_OK
)
645 pDlg
->GetName( aName
);
649 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
650 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
660 pWarnBox
= new WarningBox( DLGWIN
,
661 WinBits( WB_OK_CANCEL
),
662 String( ResId( nError
, rMgr
) ) );
663 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
666 if( pWarnBox
->Execute() != RET_OK
)
669 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
675 XBitmapEntry
* pEntry
= 0;
676 if( aCtlPixel
.IsEnabled() )
678 XOBitmap aXOBitmap
= aBitmapCtl
.GetXBitmap();
680 // #85339# if it's an array, force conversion to bitmap before using it.
681 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
682 aXOBitmap
.GetBitmap();
684 pEntry
= new XBitmapEntry( aXOBitmap
, aName
);
686 else // Es muss sich um eine nicht vorhandene importierte Bitmap handeln
688 const SfxPoolItem
* pPoolItem
= NULL
;
689 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( XATTR_FILLBITMAP
, TRUE
, &pPoolItem
) )
691 XOBitmap
aXOBitmap( ( ( const XFillBitmapItem
* ) pPoolItem
)->GetBitmapValue() );
692 pEntry
= new XBitmapEntry( aXOBitmap
, aName
);
696 DBG_ASSERT( pEntry
, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
700 pBitmapList
->Insert( pEntry
);
702 aLbBitmaps
.Append( pEntry
);
703 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
706 // hack: #31355# W.P.
707 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
708 if( TRUE
) { // ??? overlapped with pDlg
711 //aLbBitmaps.Invalidate();
715 // Flag fuer modifiziert setzen
716 *pnBitmapListState
|= CT_MODIFIED
;
718 ChangeBitmapHdl_Impl( this );
722 // Status der Buttons ermitteln
723 if( pBitmapList
->Count() )
733 /******************************************************************************/
734 /******************************************************************************/
737 //------------------------------------------------------------------------
740 #pragma optimize ( "", off )
743 IMPL_LINK( SvxBitmapTabPage
, ClickImportHdl_Impl
, void *, EMPTYARG
)
745 ResMgr
& rMgr
= DIALOG_MGR();
746 SvxOpenGraphicDialog
aDlg( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Import" ) ) );
747 aDlg
.EnableLink(sal_False
);
749 if( !aDlg
.Execute() )
755 nError
= aDlg
.GetGraphic( aGraphic
);
760 String
aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP
, rMgr
) );
761 WarningBox
* pWarnBox
= NULL
;
763 // convert file URL to UI name
765 INetURLObject
aURL( aDlg
.GetPath() );
766 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aURL.GetName().GetToken( 0, '.' ), aDesc );
767 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
768 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
769 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, String(aURL
.GetName()).GetToken( 0, '.' ), aDesc
, RID_SVXDLG_NAME
);
770 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
771 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
773 while( pDlg
->Execute() == RET_OK
)
775 pDlg
->GetName( aName
);
777 BOOL bDifferent
= TRUE
;
778 long nCount
= pBitmapList
->Count();
780 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
781 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() )
791 pWarnBox
= new WarningBox( DLGWIN
,
792 WinBits( WB_OK_CANCEL
),
793 String( ResId( nError
, rMgr
) ) );
794 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
798 if( pWarnBox
->Execute() != RET_OK
)
801 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
807 Bitmap
aBmp( aGraphic
.GetBitmap() );
808 XBitmapEntry
* pEntry
=
809 new XBitmapEntry( XOBitmap( aBmp
), aName
);
810 pBitmapList
->Insert( pEntry
);
812 aLbBitmaps
.Append( pEntry
);
813 aLbBitmaps
.SelectEntryPos( aLbBitmaps
.GetEntryCount() - 1 );
816 // hack: #31355# W.P.
817 Rectangle
aRect( aLbBitmaps
.GetPosPixel(), aLbBitmaps
.GetSizePixel() );
818 if( TRUE
) { // ??? overlapped with pDlg
821 //aLbBitmaps.Invalidate();
825 // Flag fuer modifiziert setzen
826 *pnBitmapListState
|= CT_MODIFIED
;
828 ChangeBitmapHdl_Impl( this );
832 // Graphik konnte nicht geladen werden
835 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
842 #pragma optimize ( "", on )
845 //------------------------------------------------------------------------
847 IMPL_LINK( SvxBitmapTabPage
, ClickModifyHdl_Impl
, void *, EMPTYARG
)
849 USHORT nPos
= aLbBitmaps
.GetSelectEntryPos();
851 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
853 ResMgr
& rMgr
= DIALOG_MGR();
854 String
aNewName( ResId( RID_SVXSTR_BITMAP
, rMgr
) );
855 String
aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP
, rMgr
) );
856 String
aName( pBitmapList
->GetBitmap( nPos
)->GetName() );
857 String aOldName
= aName
;
859 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
860 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
861 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
862 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
, RID_SVXDLG_NAME
);
863 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
865 long nCount
= pBitmapList
->Count();
866 BOOL bDifferent
= FALSE
;
869 while( bLoop
&& pDlg
->Execute() == RET_OK
)
871 pDlg
->GetName( aName
);
874 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
876 if( aName
== pBitmapList
->GetBitmap( i
)->GetName() &&
884 XBitmapEntry
* pEntry
= pBitmapList
->GetBitmap( nPos
);
886 pEntry
->SetName( aName
);
888 XOBitmap aXOBitmap
= aBitmapCtl
.GetXBitmap();
890 // #85339# if it's an array, force conversion to bitmap before using it.
891 if(aXOBitmap
.GetBitmapType() == XBITMAP_8X8
)
892 aXOBitmap
.GetBitmap();
894 pEntry
->SetXBitmap( aXOBitmap
);
896 aLbBitmaps
.Modify( pEntry
, nPos
);
897 aLbBitmaps
.SelectEntryPos( nPos
);
899 // Flag fuer modifiziert setzen
900 *pnBitmapListState
|= CT_MODIFIED
;
906 WarningBox
aBox( DLGWIN
, WinBits( WB_OK
), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
907 aBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
916 //------------------------------------------------------------------------
918 IMPL_LINK( SvxBitmapTabPage
, ClickDeleteHdl_Impl
, void *, EMPTYARG
)
920 USHORT nPos
= aLbBitmaps
.GetSelectEntryPos();
922 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
924 QueryBox
aQueryBox( DLGWIN
, WinBits( WB_YES_NO
| WB_DEF_NO
),
925 //! SVX_RES( RID_SVXSTR_DEL_BITMAP ),
926 String( SVX_RES( RID_SVXSTR_ASK_DEL_BITMAP
) ) );
928 if( aQueryBox
.Execute() == RET_YES
)
930 delete pBitmapList
->Remove( nPos
);
931 aLbBitmaps
.RemoveEntry( nPos
);
932 aLbBitmaps
.SelectEntryPos( 0 );
934 aCtlPreview
.Invalidate();
935 aCtlPixel
.Invalidate();
937 ChangeBitmapHdl_Impl( this );
939 // Flag fuer modifiziert setzen
940 *pnBitmapListState
|= CT_MODIFIED
;
943 // Status der Buttons ermitteln
944 if( !pBitmapList
->Count() )
946 aBtnModify
.Disable();
947 aBtnDelete
.Disable();
953 // -----------------------------------------------------------------------
955 IMPL_LINK( SvxBitmapTabPage
, ClickLoadHdl_Impl
, void *, EMPTYARG
)
957 USHORT nReturn
= RET_YES
;
958 ResMgr
& rMgr
= DIALOG_MGR();
960 if ( *pnBitmapListState
& CT_MODIFIED
)
962 nReturn
= WarningBox( DLGWIN
, WinBits( WB_YES_NO_CANCEL
),
963 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
965 if ( nReturn
== RET_YES
)
969 if ( nReturn
!= RET_CANCEL
)
971 ::sfx2::FileDialogHelper
aDlg(
972 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
974 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
975 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
976 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
977 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
979 if ( aDlg
.Execute() == ERRCODE_NONE
)
982 INetURLObject
aURL( aDlg
.GetPath() );
983 INetURLObject
aPathURL( aURL
);
985 aPathURL
.removeSegment();
986 aPathURL
.removeFinalSlash();
989 XBitmapList
* pBmpList
= new XBitmapList( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
990 pBmpList
->SetName( aURL
.getName() );
991 if( pBmpList
->Load() )
995 // Pruefen, ob Tabelle geloescht werden darf:
996 if( pBitmapList
!= ( (SvxAreaTabDialog
*) DLGWIN
)->GetBitmapList() )
999 pBitmapList
= pBmpList
;
1000 ( (SvxAreaTabDialog
*) DLGWIN
)->SetNewBitmapList( pBitmapList
);
1003 aLbBitmaps
.Fill( pBitmapList
);
1006 pBitmapList
->SetName( aURL
.getName() );
1008 // Ermitteln (evtl. abschneiden) des Namens und in
1009 // der GroupBox darstellen
1010 String
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
1011 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
1013 if ( aURL
.getBase().getLength() > 18 )
1015 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
1016 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1019 aString
+= String(aURL
.getBase());
1021 // Flag fuer gewechselt setzen
1022 *pnBitmapListState
|= CT_CHANGED
;
1023 // Flag fuer modifiziert entfernen
1024 *pnBitmapListState
&= ~CT_MODIFIED
;
1031 ErrorBox( DLGWIN
, WinBits( WB_OK
),
1032 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
1037 // Status der Buttons ermitteln
1038 if( pBitmapList
->Count() )
1040 aBtnModify
.Enable();
1041 aBtnDelete
.Enable();
1046 aBtnModify
.Disable();
1047 aBtnDelete
.Disable();
1053 // -----------------------------------------------------------------------
1055 IMPL_LINK( SvxBitmapTabPage
, ClickSaveHdl_Impl
, void *, EMPTYARG
)
1057 ::sfx2::FileDialogHelper
aDlg(
1058 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
1059 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
1060 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
1062 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
1063 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
1065 if( pBitmapList
->GetName().Len() )
1067 aFile
.Append( pBitmapList
->GetName() );
1069 if( !aFile
.getExtension().getLength() )
1070 aFile
.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sob" ) ) );
1073 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
1074 if ( aDlg
.Execute() == ERRCODE_NONE
)
1076 INetURLObject
aURL( aDlg
.GetPath() );
1077 INetURLObject
aPathURL( aURL
);
1079 aPathURL
.removeSegment();
1080 aPathURL
.removeFinalSlash();
1082 pBitmapList
->SetName( aURL
.getName() );
1083 pBitmapList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
1085 if( pBitmapList
->Save() )
1087 // Ermitteln (evtl. abschneiden) des Namens und in
1088 // der GroupBox darstellen
1089 String
aString( SVX_RES( RID_SVXSTR_TABLE
) );
1090 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
1092 if ( aURL
.getBase().getLength() > 18 )
1094 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
1095 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1098 aString
+= String(aURL
.getBase());
1100 // Flag fuer gespeichert setzen
1101 *pnBitmapListState
|= CT_SAVED
;
1102 // Flag fuer modifiziert entfernen
1103 *pnBitmapListState
&= ~CT_MODIFIED
;
1107 ErrorBox( DLGWIN
, WinBits( WB_OK
),
1108 String( SVX_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) ).Execute();
1115 //------------------------------------------------------------------------
1117 IMPL_LINK( SvxBitmapTabPage
, ChangePixelColorHdl_Impl
, void *, EMPTYARG
)
1119 aCtlPixel
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
1120 aCtlPixel
.Invalidate();
1122 aBitmapCtl
.SetPixelColor( aLbColor
.GetSelectEntryColor() );
1124 // Bitmap holen und darstellen
1125 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1126 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1127 aCtlPreview
.Invalidate();
1134 //------------------------------------------------------------------------
1136 IMPL_LINK( SvxBitmapTabPage
, ChangeBackgrndColorHdl_Impl
, void *, EMPTYARG
)
1138 aCtlPixel
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
1139 aCtlPixel
.Invalidate();
1141 aBitmapCtl
.SetBackgroundColor( aLbBackgroundColor
.GetSelectEntryColor() );
1143 // Bitmap holen und darstellen
1144 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1145 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1146 aCtlPreview
.Invalidate();
1153 //------------------------------------------------------------------------
1155 void SvxBitmapTabPage::PointChanged( Window
* pWindow
, RECT_POINT
)
1157 if( pWindow
== &aCtlPixel
)
1159 aBitmapCtl
.SetBmpArray( aCtlPixel
.GetBitmapPixelPtr() );
1161 // Bitmap holen und darstellen
1162 rXFSet
.Put( XFillBitmapItem( String(), aBitmapCtl
.GetXBitmap() ) );
1163 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
1164 aCtlPreview
.Invalidate();
1173 Window
* SvxBitmapTabPage::GetParentLabeledBy( const Window
* pLabeled
) const
1175 if (pLabeled
== &aLbBitmaps
)
1176 return const_cast<FixedText
*>(&aLbBitmapsHidden
);
1178 return SvxTabPage::GetParentLabeledBy (pLabeled
);