xref: /trunk/main/cui/source/tabpages/tpbitmap.cxx (revision 61dff127b6698e0bae836c8aedd6ec62111483d1)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 // include ---------------------------------------------------------------
32 
33 //svdraw.hxx
34 #define _SVDRAW_HXX
35 #define _SDR_NOITEMS
36 #define _SDR_NOTOUCH
37 #define _SDR_NOTRANSFORM
38 #define _SDR_NOOBJECTS
39 #define _SDR_NOVIEWS
40 #define _SDR_NOVIEWMARKER
41 #define _SDR_NODRAGMETHODS
42 #define _SDR_NOUNDO
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>
57 
58 #define _SVX_TPBITMAP_CXX
59 
60 #include <cuires.hrc>
61 #include "helpid.hrc"
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"
75 
76 #define DLGWIN this->GetParent()->GetParent()
77 
78 /*************************************************************************
79 |*
80 |*  Dialog zum Aendern und Definieren der Bitmaps
81 |*
82 \************************************************************************/
83 
84 SvxBitmapTabPage::SvxBitmapTabPage
85 (
86     Window* pParent,
87     const SfxItemSet& rInAttrs
88 ) :
89 
90     SvxTabPage          ( pParent, CUI_RES( RID_SVXPAGE_BITMAP ), rInAttrs ),
91 
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 ) ),
110 
111     aBitmapCtl          ( this, aCtlPreview.GetSizePixel() ),
112     rOutAttrs           ( rInAttrs ),
113 
114     pColorTab( NULL ),
115     pBitmapList( NULL ),
116 
117     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
118     aXFStyleItem        ( XFILL_BITMAP ),
119     aXBitmapItem        ( String(), XOBitmap() ),
120     aXFillAttr          ( pXPool ),
121     rXFSet              ( aXFillAttr.GetItemSet() )
122 {
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 );
125     FreeResource();
126 
127     // diese Page braucht ExchangeSupport
128     SetExchangeSupport();
129 
130     // Setzen des Output-Devices
131     rXFSet.Put( aXFStyleItem );
132     rXFSet.Put( aXBitmapItem );
133     //aCtlPreview.SetAttributes( aXFillAttr );
134 
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 ) );
144 
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 ) );
151 
152     String accName = String(CUI_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 );
161 
162 }
163 
164 // -----------------------------------------------------------------------
165 
166 void SvxBitmapTabPage::Construct()
167 {
168     // Farbtabellen
169     aLbColor.Fill( pColorTab );
170     aLbBackgroundColor.CopyEntries( aLbColor );
171 
172     // Bitmaptabelle
173     aLbBitmaps.Fill( pBitmapList );
174 }
175 
176 // -----------------------------------------------------------------------
177 
178 void SvxBitmapTabPage::ActivatePage( const SfxItemSet&  )
179 {
180     sal_uInt16 nPos;
181     sal_uInt16 nCount;
182 
183     if( *pDlgType == 0 ) // Flaechen-Dialog
184     {
185         *pbAreaTP = sal_False;
186 
187         if( pColorTab )
188         {
189             // ColorTable
190             if( *pnColorTableState & CT_CHANGED ||
191                 *pnColorTableState & CT_MODIFIED )
192             {
193                 if( *pnColorTableState & CT_CHANGED )
194                     pColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable();
195 
196                 // LbColor
197                 nPos = aLbColor.GetSelectEntryPos();
198                 aLbColor.Clear();
199                 aLbColor.Fill( pColorTab );
200                 nCount = aLbColor.GetEntryCount();
201                 if( nCount == 0 )
202                     ; // Dieser Fall sollte nicht auftreten
203                 else if( nCount <= nPos )
204                     aLbColor.SelectEntryPos( 0 );
205                 else
206                     aLbColor.SelectEntryPos( nPos );
207 
208                 // LbColorBackground
209                 nPos = aLbBackgroundColor.GetSelectEntryPos();
210                 aLbBackgroundColor.Clear();
211                 aLbBackgroundColor.CopyEntries( aLbColor );
212                 nCount = aLbBackgroundColor.GetEntryCount();
213                 if( nCount == 0 )
214                     ; // Dieser Fall sollte nicht auftreten
215                 else if( nCount <= nPos )
216                     aLbBackgroundColor.SelectEntryPos( 0 );
217                 else
218                     aLbBackgroundColor.SelectEntryPos( nPos );
219 
220                 ChangePixelColorHdl_Impl( this );
221                 ChangeBackgrndColorHdl_Impl( this );
222             }
223 
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() );
228 
229             aURL.Append( pBitmapList->GetName() );
230             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
231 
232             if( aURL.getBase().getLength() > 18 )
233             {
234                 aString += String(aURL.getBase()).Copy( 0, 15 );
235                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
236             }
237             else
238                 aString += String(aURL.getBase());
239 
240             if( *pPageType == PT_BITMAP && *pPos != LISTBOX_ENTRY_NOTFOUND )
241             {
242                 aLbBitmaps.SelectEntryPos( *pPos );
243             }
244             // Farben koennten geloescht worden sein
245             ChangeBitmapHdl_Impl( this );
246 
247             *pPageType = PT_BITMAP;
248             *pPos = LISTBOX_ENTRY_NOTFOUND;
249         }
250     }
251 }
252 
253 // -----------------------------------------------------------------------
254 
255 int SvxBitmapTabPage::DeactivatePage( SfxItemSet* _pSet)
256 {
257     if ( CheckChanges_Impl() == -1L )
258         return KEEP_PAGE;
259 
260     if( _pSet )
261         FillItemSet( *_pSet );
262 
263     return LEAVE_PAGE;
264 }
265 
266 // -----------------------------------------------------------------------
267 
268 sal_Bool SvxBitmapTabPage::FillItemSet( SfxItemSet& _rOutAttrs )
269 {
270     if( *pDlgType == 0 && *pbAreaTP == sal_False ) // Flaechen-Dialog
271     {
272         if( *pPageType == PT_BITMAP )
273         {
274             // CheckChanges_Impl(); <-- doppelte Abfrage ?
275 
276             XOBitmap aXOBitmap;
277             String aString;
278             sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
279             if( nPos != LISTBOX_ENTRY_NOTFOUND )
280             {
281                 aXOBitmap = pBitmapList->GetBitmap( nPos )->GetXBitmap();
282                 aString = aLbBitmaps.GetSelectEntry();
283 
284             }
285             else
286             {
287                 aXOBitmap = aBitmapCtl.GetXBitmap();
288 
289                 // #85339# if it's an array, force conversion to bitmap before using it.
290                 if(aXOBitmap.GetBitmapType() == XBITMAP_8X8)
291                     aXOBitmap.GetBitmap();
292 
293             }
294             _rOutAttrs.Put( XFillStyleItem( XFILL_BITMAP ) );
295             _rOutAttrs.Put( XFillBitmapItem( aString, aXOBitmap ) );
296         }
297     }
298     return sal_True;
299 }
300 
301 // -----------------------------------------------------------------------
302 
303 void SvxBitmapTabPage::Reset( const SfxItemSet&  )
304 {
305     // aLbBitmaps.SelectEntryPos( 0 );
306 
307     aBitmapCtl.SetLines( aCtlPixel.GetLineCount() );
308     aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
309     aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
310     aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
311 
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();
317 
318     ChangeBitmapHdl_Impl( this );
319 
320     // Status der Buttons ermitteln
321     if( pBitmapList->Count() )
322     {
323         aBtnAdd.Enable();
324         aBtnModify.Enable();
325         aBtnDelete.Enable();
326         aBtnSave.Enable();
327     }
328     else
329     {
330         aBtnModify.Disable();
331         aBtnDelete.Disable();
332         aBtnSave.Disable();
333     }
334 }
335 
336 // -----------------------------------------------------------------------
337 
338 SfxTabPage* SvxBitmapTabPage::Create( Window* pWindow,
339                 const SfxItemSet& rSet )
340 {
341     return new SvxBitmapTabPage( pWindow, rSet );
342 }
343 
344 //------------------------------------------------------------------------
345 
346 IMPL_LINK( SvxBitmapTabPage, ChangeBitmapHdl_Impl, void *, EMPTYARG )
347 {
348     XOBitmap* pXOBitmap = NULL;
349     int nPos = aLbBitmaps.GetSelectEntryPos();
350 
351     if( nPos != LISTBOX_ENTRY_NOTFOUND )
352         pXOBitmap = new XOBitmap( ( (XBitmapEntry*) pBitmapList->GetBitmap( nPos ) )->GetXBitmap() );
353     else
354     {
355         const SfxPoolItem* pPoolItem = NULL;
356         if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
357         {
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 ) ) )
361             {
362                 pXOBitmap = new XOBitmap( ( ( const XFillBitmapItem* ) pPoolItem )->GetBitmapValue() );
363             }
364         }
365         if( !pXOBitmap )
366         {
367             aLbBitmaps.SelectEntryPos( 0 );
368             nPos = aLbBitmaps.GetSelectEntryPos();
369             if( nPos != LISTBOX_ENTRY_NOTFOUND )
370                 pXOBitmap = new XOBitmap( ( (XBitmapEntry*) pBitmapList->GetBitmap( nPos ) )->GetXBitmap() );
371         }
372     }
373     if( pXOBitmap )
374     {
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();
382 
383         // #85339# try to convert bitmapped item to array item.
384         if(pXOBitmap->GetBitmapType() == XBITMAP_IMPORT)
385         {
386             Bitmap aBitmap(pXOBitmap->GetBitmap());
387             Size aSizePixel(aBitmap.GetSizePixel());
388 
389             if(8 == aSizePixel.Width() && 8 == aSizePixel.Height())
390             {
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);
396 
397                 if(pAccess)
398                 {
399                     for(sal_uInt32 a(0); bValid && a < 64; a++)
400                     {
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();
404 
405                         // test with nCol1
406                         if(nCol1 != nColVal)
407                         {
408                             if(0xffffffff == nCol1)
409                             {
410                                 // nCol1 is used first time
411                                 nCol1 = nColVal;
412                                 pPixelArray[a] = 0;
413                             }
414                             else
415                             {
416                                 // test with nCol2
417                                 if(nCol2 != nColVal)
418                                 {
419                                     if(0xffffffff == nCol2)
420                                     {
421                                         // nCol2 used first time
422                                         nCol2 = nColVal;
423                                         pPixelArray[a] = 1;
424                                     }
425                                     else
426                                     {
427                                         // Third color detected
428                                         bValid = sal_False;
429                                     }
430                                 }
431                                 else
432                                 {
433                                     // color is pixel color
434                                     pPixelArray[a] = 1;
435                                 }
436                             }
437                         }
438                         else
439                         {
440                             // color is background color
441                             pPixelArray[a] = 0;
442                         }
443                     }
444 
445                     // release ReadAccess
446                     aBitmap.ReleaseAccess(pAccess);
447                 }
448                 else
449                 {
450                     // no access -> no success
451                     bValid = sal_False;
452                 }
453 
454                 if(bValid)
455                 {
456                     Color aCol1(nCol1);
457                     Color aCol2(nCol2);
458 
459                     // no pixel color found? Use opposite od background color.
460                     if(0xffffffff == nCol2)
461                     {
462                         aCol2 = Color(
463                             0xff - aCol1.GetRed(),
464                             0xff - aCol1.GetGreen(),
465                             0xff - aCol1.GetBlue());
466                     }
467 
468                     // transformation did work, create a new Item
469                     delete pXOBitmap;
470                     pXOBitmap = new XOBitmap(pPixelArray, aCol2, aCol1);
471                 }
472 
473                 // cleanup
474                 delete[] pPixelArray;
475             }
476         }
477 
478         aLbColor.SetNoSelection();
479         aLbBackgroundColor.SetNoSelection();
480 
481         if( pXOBitmap->GetBitmapType() == XBITMAP_IMPORT )
482         {
483             aCtlPixel.Reset();
484             aCtlPixel.SetPaintable( sal_False );
485             aCtlPixel.Disable();
486             aFtPixelEdit.Disable();
487             aFtColor.Disable();
488             aLbColor.Disable();
489             aFtBackgroundColor.Disable();
490             aLbBackgroundColor.Disable();
491             aBtnModify.Disable();
492             aBtnAdd.Disable();
493         }
494         else if( pXOBitmap->GetBitmapType() == XBITMAP_8X8 )
495         {
496             aCtlPixel.SetPaintable( sal_True );
497             aCtlPixel.Enable();
498             aFtPixelEdit.Enable();
499             aFtColor.Enable();
500             aLbColor.Enable();
501             aFtBackgroundColor.Enable();
502             aLbBackgroundColor.Enable();
503             aBtnModify.Enable();
504             aBtnAdd.Enable();
505 
506             // Setzen des PixelControls
507             aCtlPixel.SetXBitmap( *pXOBitmap );
508 
509             Color aPixelColor = pXOBitmap->GetPixelColor();
510             Color aBackColor  = pXOBitmap->GetBackgroundColor();
511 
512             aBitmapCtl.SetPixelColor( aPixelColor );
513             aBitmapCtl.SetBackgroundColor( aBackColor );
514 
515             // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
516             // temporaer hinzugenommen
517             if( 0 == aLbBitmaps.GetSelectEntryPos() )
518             {
519                 aLbColor.SelectEntry( Color( COL_BLACK ) );
520                 ChangePixelColorHdl_Impl( this );
521             }
522             else
523                 aLbColor.SelectEntry( aPixelColor );
524             if( aLbColor.GetSelectEntryCount() == 0 )
525             {
526                 aLbColor.InsertEntry( aPixelColor, String() );
527                 aLbColor.SelectEntry( aPixelColor );
528             }
529             aLbBackgroundColor.SelectEntry( aBackColor );
530             if( aLbBackgroundColor.GetSelectEntryCount() == 0 )
531             {
532                 aLbBackgroundColor.InsertEntry( aBackColor, String() );
533                 aLbBackgroundColor.SelectEntry( aBackColor );
534             }
535         }
536         aCtlPixel.Invalidate();
537 
538         // Bitmap darstellen
539         XFillBitmapItem aXBmpItem( (const String &) String(), *pXOBitmap );
540         rXFSet.Put( aXBmpItem );
541 
542         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
543         aCtlPreview.Invalidate();
544 
545         bBmpChanged = sal_False;
546         delete pXOBitmap;
547     }
548     return 0L;
549 }
550 
551 // -----------------------------------------------------------------------
552 
553 long SvxBitmapTabPage::CheckChanges_Impl()
554 {
555     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
556     if( nPos != LISTBOX_ENTRY_NOTFOUND )
557     {
558         String aString = aLbBitmaps.GetSelectEntry();
559 
560         if( bBmpChanged )
561         {
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 ) ),
569                                                         &aWarningBoxImage  );
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 ) ) );
575 
576             short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
577 
578             switch( nRet )
579             {
580                 case RET_BTN_1: // Aendern
581                 {
582                     ClickModifyHdl_Impl( this );
583                 }
584                 break;
585 
586                 case RET_BTN_2: // Hinzufuegen
587                 {
588                     ClickAddHdl_Impl( this );
589                     nPos = aLbBitmaps.GetSelectEntryPos();
590                 }
591                 break;
592 
593                 case RET_CANCEL:
594                     // return( -1L );
595                 break;
596                 // return( sal_True ); // Abbruch
597             }
598             delete aMessDlg; //add by CHINA001
599         }
600     }
601     nPos = aLbBitmaps.GetSelectEntryPos();
602     if( nPos != LISTBOX_ENTRY_NOTFOUND )
603         *pPos = nPos;
604     return 0L;
605 }
606 
607 //------------------------------------------------------------------------
608 
609 IMPL_LINK( SvxBitmapTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
610 {
611     ResMgr& rMgr = CUI_MGR();
612     String aNewName( SVX_RES( RID_SVXSTR_BITMAP ) );
613     String aDesc( CUI_RES( RID_SVXSTR_DESC_NEW_BITMAP ) );
614     String aName;
615 
616     long nCount = pBitmapList->Count();
617     long j = 1;
618     sal_Bool bDifferent = sal_False;
619 
620     while( !bDifferent )
621     {
622         aName  = aNewName;
623         aName += sal_Unicode(' ');
624         aName += UniString::CreateFromInt32( j++ );
625         bDifferent = sal_True;
626 
627         for( long i = 0; i < nCount && bDifferent; i++ )
628             if( aName == pBitmapList->GetBitmap( i )->GetName() )
629                 bDifferent = sal_False;
630     }
631 
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;
638 
639     while( pDlg->Execute() == RET_OK )
640     {
641         pDlg->GetName( aName );
642 
643         bDifferent = sal_True;
644 
645         for( long i = 0; i < nCount && bDifferent; i++ )
646             if( aName == pBitmapList->GetBitmap( i )->GetName() )
647                 bDifferent = sal_False;
648 
649         if( bDifferent ) {
650             nError = 0;
651             break;
652         }
653 
654         if( !pWarnBox )
655         {
656             pWarnBox = new WarningBox( DLGWIN,
657                                        WinBits( WB_OK_CANCEL ),
658                                        String( ResId( nError, rMgr ) ) );
659             pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
660         }
661 
662         if( pWarnBox->Execute() != RET_OK )
663             break;
664     }
665     //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
666     delete pDlg;
667     delete pWarnBox;
668 
669     if( !nError )
670     {
671         XBitmapEntry* pEntry = 0;
672         if( aCtlPixel.IsEnabled() )
673         {
674             XOBitmap aXOBitmap = aBitmapCtl.GetXBitmap();
675 
676             // #85339# if it's an array, force conversion to bitmap before using it.
677             if(aXOBitmap.GetBitmapType() == XBITMAP_8X8)
678                 aXOBitmap.GetBitmap();
679 
680             pEntry = new XBitmapEntry( aXOBitmap, aName );
681         }
682         else // Es muss sich um eine nicht vorhandene importierte Bitmap handeln
683         {
684             const SfxPoolItem* pPoolItem = NULL;
685             if( SFX_ITEM_SET == rOutAttrs.GetItemState( XATTR_FILLBITMAP, sal_True, &pPoolItem ) )
686             {
687                 XOBitmap aXOBitmap( ( ( const XFillBitmapItem* ) pPoolItem )->GetBitmapValue() );
688                 pEntry = new XBitmapEntry( aXOBitmap, aName );
689             }
690         }
691 
692         DBG_ASSERT( pEntry, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
693 
694         if( pEntry )
695         {
696             pBitmapList->Insert( pEntry );
697 
698             aLbBitmaps.Append( pEntry );
699             aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
700 
701 #ifdef WNT
702             // hack: #31355# W.P.
703             Rectangle aRect( aLbBitmaps.GetPosPixel(), aLbBitmaps.GetSizePixel() );
704             if( sal_True ) {                // ??? overlapped with pDlg
705                                         // and srolling
706                 Invalidate( aRect );
707                 //aLbBitmaps.Invalidate();
708             }
709 #endif
710 
711             // Flag fuer modifiziert setzen
712             *pnBitmapListState |= CT_MODIFIED;
713 
714             ChangeBitmapHdl_Impl( this );
715         }
716     }
717 
718     // Status der Buttons ermitteln
719     if( pBitmapList->Count() )
720     {
721         aBtnModify.Enable();
722         aBtnDelete.Enable();
723         aBtnSave.Enable();
724     }
725     return 0L;
726 }
727 
728 
729 /******************************************************************************/
730 /******************************************************************************/
731 
732 
733 //------------------------------------------------------------------------
734 
735 #ifdef _MSC_VER
736 #pragma optimize ( "", off )
737 #endif
738 
739 IMPL_LINK( SvxBitmapTabPage, ClickImportHdl_Impl, void *, EMPTYARG )
740 {
741     ResMgr& rMgr = CUI_MGR();
742     SvxOpenGraphicDialog aDlg( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Import" ) ) );
743     aDlg.EnableLink(sal_False);
744 
745     if( !aDlg.Execute() )
746     {
747         Graphic         aGraphic;
748         int             nError = 1;
749 
750         EnterWait();
751         nError = aDlg.GetGraphic( aGraphic );
752         LeaveWait();
753 
754         if( !nError )
755         {
756             String aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP, rMgr) );
757             WarningBox*    pWarnBox = NULL;
758 
759             // convert file URL to UI name
760             String          aName;
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;
767 
768             while( pDlg->Execute() == RET_OK )
769             {
770                 pDlg->GetName( aName );
771 
772                 sal_Bool bDifferent = sal_True;
773                 long nCount     = pBitmapList->Count();
774 
775                 for( long i = 0; i < nCount && bDifferent; i++ )
776                     if( aName == pBitmapList->GetBitmap( i )->GetName() )
777                         bDifferent = sal_False;
778 
779                 if( bDifferent ) {
780                     nError = 0;
781                     break;
782                 }
783 
784                 if( !pWarnBox )
785                 {
786                     pWarnBox = new WarningBox( DLGWIN,
787                                                WinBits( WB_OK_CANCEL ),
788                                                String( ResId( nError, rMgr ) ) );
789                     pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
790                 }
791 
792 
793                 if( pWarnBox->Execute() != RET_OK )
794                     break;
795             }
796             //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
797             delete pDlg;
798             delete pWarnBox;
799 
800             if( !nError )
801             {
802                 Bitmap aBmp( aGraphic.GetBitmap() );
803                 XBitmapEntry* pEntry =
804                     new XBitmapEntry( XOBitmap( aBmp ), aName );
805                 pBitmapList->Insert( pEntry );
806 
807                 aLbBitmaps.Append( pEntry );
808                 aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
809 
810 #ifdef WNT
811                 // hack: #31355# W.P.
812                 Rectangle aRect( aLbBitmaps.GetPosPixel(), aLbBitmaps.GetSizePixel() );
813                 if( sal_True ) {                // ??? overlapped with pDlg
814                                             // and srolling
815                     Invalidate( aRect );
816                     //aLbBitmaps.Invalidate();
817                 }
818 #endif
819 
820                 // Flag fuer modifiziert setzen
821                 *pnBitmapListState |= CT_MODIFIED;
822 
823                 ChangeBitmapHdl_Impl( this );
824             }
825         }
826         else
827             // Graphik konnte nicht geladen werden
828             ErrorBox( DLGWIN,
829                       WinBits( WB_OK ),
830                       String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
831     }
832 
833     return 0L;
834 }
835 
836 #ifdef _MSC_VER
837 #pragma optimize ( "", on )
838 #endif
839 
840 //------------------------------------------------------------------------
841 
842 IMPL_LINK( SvxBitmapTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
843 {
844     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
845 
846     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
847     {
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;
853 
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
858 
859         long nCount = pBitmapList->Count();
860         sal_Bool bDifferent = sal_False;
861         sal_Bool bLoop = sal_True;
862 
863         while( bLoop && pDlg->Execute() == RET_OK )
864         {
865             pDlg->GetName( aName );
866             bDifferent = sal_True;
867 
868             for( long i = 0; i < nCount && bDifferent; i++ )
869             {
870                 if( aName == pBitmapList->GetBitmap( i )->GetName() &&
871                     aName != aOldName )
872                     bDifferent = sal_False;
873             }
874 
875             if( bDifferent )
876             {
877                 bLoop = sal_False;
878                 XBitmapEntry* pEntry = pBitmapList->GetBitmap( nPos );
879 
880                 pEntry->SetName( aName );
881 
882                 XOBitmap aXOBitmap = aBitmapCtl.GetXBitmap();
883 
884                 // #85339# if it's an array, force conversion to bitmap before using it.
885                 if(aXOBitmap.GetBitmapType() == XBITMAP_8X8)
886                     aXOBitmap.GetBitmap();
887 
888                 pEntry->SetXBitmap( aXOBitmap );
889 
890                 aLbBitmaps.Modify( pEntry, nPos );
891                 aLbBitmaps.SelectEntryPos( nPos );
892 
893                 // Flag fuer modifiziert setzen
894                 *pnBitmapListState |= CT_MODIFIED;
895 
896                 bBmpChanged = sal_False;
897             }
898             else
899             {
900                 WarningBox aBox( DLGWIN, WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
901                 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
902                 aBox.Execute();
903             }
904         }
905         delete pDlg;
906     }
907     return 0L;
908 }
909 
910 //------------------------------------------------------------------------
911 
912 IMPL_LINK( SvxBitmapTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
913 {
914     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
915 
916     if( nPos != LISTBOX_ENTRY_NOTFOUND )
917     {
918         QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
919             String( CUI_RES( RID_SVXSTR_ASK_DEL_BITMAP ) ) );
920 
921         if( aQueryBox.Execute() == RET_YES )
922         {
923             delete pBitmapList->Remove( nPos );
924             aLbBitmaps.RemoveEntry( nPos );
925             aLbBitmaps.SelectEntryPos( 0 );
926 
927             aCtlPreview.Invalidate();
928             aCtlPixel.Invalidate();
929 
930             ChangeBitmapHdl_Impl( this );
931 
932             // Flag fuer modifiziert setzen
933             *pnBitmapListState |= CT_MODIFIED;
934         }
935     }
936     // Status der Buttons ermitteln
937     if( !pBitmapList->Count() )
938     {
939         aBtnModify.Disable();
940         aBtnDelete.Disable();
941         aBtnSave.Disable();
942     }
943     return 0L;
944 }
945 
946 // -----------------------------------------------------------------------
947 
948 IMPL_LINK( SvxBitmapTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
949 {
950     sal_uInt16 nReturn = RET_YES;
951     ResMgr& rMgr = CUI_MGR();
952 
953     if ( *pnBitmapListState & CT_MODIFIED )
954     {
955         nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
956             String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
957 
958         if ( nReturn == RET_YES )
959             pBitmapList->Save();
960     }
961 
962     if ( nReturn != RET_CANCEL )
963     {
964         ::sfx2::FileDialogHelper aDlg(
965             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
966             0 );
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 ) );
971 
972         if ( aDlg.Execute() == ERRCODE_NONE )
973         {
974             EnterWait();
975             INetURLObject aURL( aDlg.GetPath() );
976             INetURLObject aPathURL( aURL );
977 
978             aPathURL.removeSegment();
979             aPathURL.removeFinalSlash();
980 
981             // Tabelle speichern
982             XBitmapList* pBmpList = new XBitmapList( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
983             pBmpList->SetName( aURL.getName() );
984             if( pBmpList->Load() )
985             {
986                 if( pBmpList )
987                 {
988                     // Pruefen, ob Tabelle geloescht werden darf:
989                     if( pBitmapList != ( (SvxAreaTabDialog*) DLGWIN )->GetBitmapList() )
990                         delete pBitmapList;
991 
992                     pBitmapList = pBmpList;
993                     ( (SvxAreaTabDialog*) DLGWIN )->SetNewBitmapList( pBitmapList );
994 
995                     aLbBitmaps.Clear();
996                     aLbBitmaps.Fill( pBitmapList );
997                     Reset( rOutAttrs );
998 
999                     pBitmapList->SetName( aURL.getName() );
1000 
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( ": " ) );
1005 
1006                     if ( aURL.getBase().getLength() > 18 )
1007                     {
1008                         aString += String(aURL.getBase()).Copy( 0, 15 );
1009                         aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1010                     }
1011                     else
1012                         aString += String(aURL.getBase());
1013 
1014                     // Flag fuer gewechselt setzen
1015                     *pnBitmapListState |= CT_CHANGED;
1016                     // Flag fuer modifiziert entfernen
1017                     *pnBitmapListState &= ~CT_MODIFIED;
1018                 }
1019                 LeaveWait();
1020             }
1021             else
1022             {
1023                 LeaveWait();
1024                 ErrorBox( DLGWIN, WinBits( WB_OK ),
1025                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
1026             }
1027         }
1028     }
1029 
1030     // Status der Buttons ermitteln
1031     if( pBitmapList->Count() )
1032     {
1033         aBtnModify.Enable();
1034         aBtnDelete.Enable();
1035         aBtnSave.Enable();
1036     }
1037     else
1038     {
1039         aBtnModify.Disable();
1040         aBtnDelete.Disable();
1041         aBtnSave.Disable();
1042     }
1043     return 0L;
1044 }
1045 
1046 // -----------------------------------------------------------------------
1047 
1048 IMPL_LINK( SvxBitmapTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
1049 {
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 );
1054 
1055     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
1056     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
1057 
1058     if( pBitmapList->GetName().Len() )
1059     {
1060         aFile.Append( pBitmapList->GetName() );
1061 
1062         if( !aFile.getExtension().getLength() )
1063             aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sob" ) ) );
1064     }
1065 
1066     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
1067     if ( aDlg.Execute() == ERRCODE_NONE )
1068     {
1069         INetURLObject   aURL( aDlg.GetPath() );
1070         INetURLObject   aPathURL( aURL );
1071 
1072         aPathURL.removeSegment();
1073         aPathURL.removeFinalSlash();
1074 
1075         pBitmapList->SetName( aURL.getName() );
1076         pBitmapList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
1077 
1078         if( pBitmapList->Save() )
1079         {
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( ": " ) );
1084 
1085             if ( aURL.getBase().getLength() > 18 )
1086             {
1087                 aString += String(aURL.getBase()).Copy( 0, 15 );
1088                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
1089             }
1090             else
1091                 aString += String(aURL.getBase());
1092 
1093             // Flag fuer gespeichert setzen
1094             *pnBitmapListState |= CT_SAVED;
1095             // Flag fuer modifiziert entfernen
1096             *pnBitmapListState &= ~CT_MODIFIED;
1097         }
1098         else
1099         {
1100             ErrorBox( DLGWIN, WinBits( WB_OK ),
1101                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
1102         }
1103     }
1104 
1105     return 0L;
1106 }
1107 
1108 //------------------------------------------------------------------------
1109 
1110 IMPL_LINK( SvxBitmapTabPage, ChangePixelColorHdl_Impl, void *, EMPTYARG )
1111 {
1112     aCtlPixel.SetPixelColor( aLbColor.GetSelectEntryColor() );
1113     aCtlPixel.Invalidate();
1114 
1115     aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
1116 
1117     // Bitmap holen und darstellen
1118     rXFSet.Put( XFillBitmapItem( String(), aBitmapCtl.GetXBitmap() ) );
1119     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1120     aCtlPreview.Invalidate();
1121 
1122     bBmpChanged = sal_True;
1123 
1124     return 0L;
1125 }
1126 
1127 //------------------------------------------------------------------------
1128 
1129 IMPL_LINK( SvxBitmapTabPage, ChangeBackgrndColorHdl_Impl, void *, EMPTYARG )
1130 {
1131     aCtlPixel.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
1132     aCtlPixel.Invalidate();
1133 
1134     aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
1135 
1136     // Bitmap holen und darstellen
1137     rXFSet.Put( XFillBitmapItem( String(), aBitmapCtl.GetXBitmap() ) );
1138     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1139     aCtlPreview.Invalidate();
1140 
1141     bBmpChanged = sal_True;
1142 
1143     return 0L;
1144 }
1145 
1146 //------------------------------------------------------------------------
1147 
1148 void SvxBitmapTabPage::PointChanged( Window* pWindow, RECT_POINT )
1149 {
1150     if( pWindow == &aCtlPixel )
1151     {
1152         aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
1153 
1154         // Bitmap holen und darstellen
1155         rXFSet.Put( XFillBitmapItem( String(), aBitmapCtl.GetXBitmap() ) );
1156         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1157         aCtlPreview.Invalidate();
1158 
1159         bBmpChanged = sal_True;
1160     }
1161 }
1162 
1163 
1164 
1165 
1166 Window* SvxBitmapTabPage::GetParentLabeledBy( const Window* pLabeled ) const
1167 {
1168     if (pLabeled == &aLbBitmaps)
1169         return const_cast<FixedText*>(&aLbBitmapsHidden);
1170     else
1171         return SvxTabPage::GetParentLabeledBy (pLabeled);
1172 }
1173