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