xref: /trunk/main/cui/source/tabpages/tpbitmap.cxx (revision 1f69a0e2)
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 
SvxBitmapTabPage(Window * pParent,const SfxItemSet & rInAttrs)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     maColorTab(),
111     maBitmapList(),
112 
113     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
114     aXFStyleItem        ( XFILL_BITMAP ),
115     aXBitmapItem        ( String(), Graphic() ),
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 
Construct()162 void SvxBitmapTabPage::Construct()
163 {
164 	// Farbtabellen
165 	aLbColor.Fill( maColorTab );
166 	aLbBackgroundColor.CopyEntries( aLbColor );
167 
168 	// Bitmaptabelle
169 	aLbBitmaps.Fill( maBitmapList );
170 }
171 
172 // -----------------------------------------------------------------------
173 
ActivatePage(const SfxItemSet &)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( maColorTab.get() )
184 		{
185 			// ColorTable
186 			if( *pnColorTableState & CT_CHANGED ||
187 				*pnColorTableState & CT_MODIFIED )
188 			{
189 				if( *pnColorTableState & CT_CHANGED )
190 					maColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable();
191 
192 				// LbColor
193 				nPos = aLbColor.GetSelectEntryPos();
194 				aLbColor.Clear();
195 				aLbColor.Fill( maColorTab );
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( maBitmapList->GetPath() );
224 
225 			aURL.Append( maBitmapList->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 
DeactivatePage(SfxItemSet * _pSet)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 
FillItemSet(SfxItemSet & _rOutAttrs)264 sal_Bool SvxBitmapTabPage::FillItemSet( SfxItemSet& _rOutAttrs )
265 {
266 	if( *pDlgType == 0 && *pbAreaTP == sal_False ) // Flaechen-Dialog
267 	{
268 		if(PT_BITMAP == *pPageType)
269 		{
270 			const sal_uInt16 nPos(aLbBitmaps.GetSelectEntryPos());
271 
272             _rOutAttrs.Put(XFillStyleItem(XFILL_BITMAP));
273 
274             if(LISTBOX_ENTRY_NOTFOUND != nPos)
275 			{
276                 const XBitmapEntry* pXBitmapEntry = maBitmapList->GetBitmap(nPos);
277 				const String aString(aLbBitmaps.GetSelectEntry());
278 
279                 _rOutAttrs.Put(XFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject()));
280 			}
281 			else
282 			{
283 				const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
284 
285                 _rOutAttrs.Put(XFillBitmapItem(String(), Graphic(aBitmapEx)));
286 			}
287 		}
288 	}
289 
290     return sal_True;
291 }
292 
293 // -----------------------------------------------------------------------
294 
Reset(const SfxItemSet &)295 void SvxBitmapTabPage::Reset( const SfxItemSet&  )
296 {
297 	// aLbBitmaps.SelectEntryPos( 0 );
298 
299 	aBitmapCtl.SetLines( aCtlPixel.GetLineCount() );
300 	aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
301 	aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
302 	aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
303 
304 	// Bitmap holen und darstellen
305 	const XFillBitmapItem aBmpItem(String(), Graphic(aBitmapCtl.GetBitmapEx()));
306 	rXFSet.Put( aBmpItem );
307 	aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
308 	aCtlPreview.Invalidate();
309 
310 	ChangeBitmapHdl_Impl( this );
311 
312 	// Status der Buttons ermitteln
313 	if( maBitmapList.get() && maBitmapList->Count() )
314 	{
315 		aBtnAdd.Enable();
316 		aBtnModify.Enable();
317 		aBtnDelete.Enable();
318 		aBtnSave.Enable();
319 	}
320 	else
321 	{
322 		aBtnModify.Disable();
323 		aBtnDelete.Disable();
324 		aBtnSave.Disable();
325 	}
326 }
327 
328 // -----------------------------------------------------------------------
329 
Create(Window * pWindow,const SfxItemSet & rSet)330 SfxTabPage* SvxBitmapTabPage::Create( Window* pWindow,
331                 const SfxItemSet& rSet )
332 {
333     return new SvxBitmapTabPage( pWindow, rSet );
334 }
335 
336 //------------------------------------------------------------------------
337 
IMPL_LINK(SvxBitmapTabPage,ChangeBitmapHdl_Impl,void *,EMPTYARG)338 IMPL_LINK( SvxBitmapTabPage, ChangeBitmapHdl_Impl, void *, EMPTYARG )
339 {
340     GraphicObject* pGraphicObject = 0;
341 	int nPos(aLbBitmaps.GetSelectEntryPos());
342 
343 	if(LISTBOX_ENTRY_NOTFOUND != nPos)
344     {
345         pGraphicObject = new GraphicObject(maBitmapList->GetBitmap(nPos)->GetGraphicObject());
346     }
347 	else
348 	{
349 		const SfxPoolItem* pPoolItem = 0;
350 
351         if(SFX_ITEM_SET == rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
352 		{
353 			const XFillStyle eXFS((XFillStyle)((const XFillStyleItem*)pPoolItem)->GetValue());
354 
355             if((XFILL_BITMAP == eXFS) && (SFX_ITEM_SET == rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
356 			{
357                 pGraphicObject = new GraphicObject(((const XFillBitmapItem*)pPoolItem)->GetGraphicObject());
358 			}
359 		}
360 
361         if(!pGraphicObject)
362 		{
363 			aLbBitmaps.SelectEntryPos(0);
364 			nPos = aLbBitmaps.GetSelectEntryPos();
365 
366             if(LISTBOX_ENTRY_NOTFOUND != nPos)
367             {
368                 pGraphicObject = new GraphicObject(maBitmapList->GetBitmap(nPos)->GetGraphicObject());
369             }
370 		}
371 	}
372 
373     if(pGraphicObject)
374 	{
375         BitmapColor aBack;
376         BitmapColor aFront;
377         bool bIs8x8(isHistorical8x8(pGraphicObject->GetGraphic().GetBitmap(), aBack, aFront));
378 
379         aLbColor.SetNoSelection();
380 		aLbBackgroundColor.SetNoSelection();
381 
382 		if(bIs8x8)
383 		{
384 			aCtlPixel.SetPaintable( sal_True );
385 			aCtlPixel.Enable();
386             aFtPixelEdit.Enable();
387 			aFtColor.Enable();
388 			aLbColor.Enable();
389 			aFtBackgroundColor.Enable();
390 			aLbBackgroundColor.Enable();
391 			aBtnModify.Enable();
392 			aBtnAdd.Enable();
393 
394 			// Setzen des PixelControls
395 			aCtlPixel.SetXBitmap(pGraphicObject->GetGraphic().GetBitmapEx());
396 
397 			Color aPixelColor = aFront;
398 			Color aBackColor = aBack;
399 
400             // #123564# This causes the wrong color to be selected
401             // as foreground color when the 1st bitmap in the bitmap
402             // list is selected. I see no reason why this is done,
403             // thus I will take it out
404             //
405             //if( 0 == aLbBitmaps.GetSelectEntryPos() )
406             //{
407             //	aLbColor.SelectEntry( Color( COL_BLACK ) );
408             //	ChangePixelColorHdl_Impl( this );
409             //}
410             //else
411 
412             aLbColor.SelectEntry( aPixelColor );
413 
414             if( aLbColor.GetSelectEntryCount() == 0 )
415             {
416                 aLbColor.InsertEntry( aPixelColor, String() );
417                 aLbColor.SelectEntry( aPixelColor );
418             }
419 
420             aLbBackgroundColor.SelectEntry( aBackColor );
421 
422             if( aLbBackgroundColor.GetSelectEntryCount() == 0 )
423             {
424                 aLbBackgroundColor.InsertEntry( aBackColor, String() );
425                 aLbBackgroundColor.SelectEntry( aBackColor );
426             }
427 
428             // update aBitmapCtl, rXFSet and aCtlPreview
429             aBitmapCtl.SetPixelColor( aPixelColor );
430             aBitmapCtl.SetBackgroundColor( aBackColor );
431             rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
432             aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
433             aCtlPreview.Invalidate();
434         }
435         else
436 		{
437 			aCtlPixel.Reset();
438 			aCtlPixel.SetPaintable( sal_False );
439 			aCtlPixel.Disable();
440             aFtPixelEdit.Disable();
441 			aFtColor.Disable();
442 			aLbColor.Disable();
443 			aFtBackgroundColor.Disable();
444 			aLbBackgroundColor.Disable();
445 			aBtnModify.Disable();
446 			aBtnAdd.Disable();
447 		}
448 
449         aCtlPixel.Invalidate();
450 
451 		// Bitmap darstellen
452 		const XFillBitmapItem aXBmpItem(String(), *pGraphicObject);
453 		rXFSet.Put( aXBmpItem );
454 
455 		aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
456 		aCtlPreview.Invalidate();
457 
458 		bBmpChanged = sal_False;
459 		delete pGraphicObject;
460 	}
461 
462     return 0;
463 }
464 
465 // -----------------------------------------------------------------------
466 
CheckChanges_Impl()467 long SvxBitmapTabPage::CheckChanges_Impl()
468 {
469 	sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
470 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
471 	{
472 		String aString = aLbBitmaps.GetSelectEntry();
473 
474 		if( bBmpChanged )
475 		{
476 			ResMgr& rMgr = CUI_MGR();
477             Image aWarningBoxImage = WarningBox::GetStandardImage();
478 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
479 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
480 			AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
481 														String( SVX_RES( RID_SVXSTR_BITMAP ) ),
482 														String( CUI_RES( RID_SVXSTR_ASK_CHANGE_BITMAP ) ),
483 														&aWarningBoxImage  );
484 			DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
485 			aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
486 									String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
487 			aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
488 									String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
489 
490 			short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
491 
492 			switch( nRet )
493 			{
494 				case RET_BTN_1: // Aendern
495 				{
496 					ClickModifyHdl_Impl( this );
497 				}
498 				break;
499 
500 				case RET_BTN_2: // Hinzufuegen
501 				{
502 					ClickAddHdl_Impl( this );
503 					nPos = aLbBitmaps.GetSelectEntryPos();
504 				}
505 				break;
506 
507 				case RET_CANCEL:
508 					// return( -1L );
509 				break;
510 				// return( sal_True ); // Abbruch
511 			}
512 			delete aMessDlg; //add by CHINA001
513 		}
514 	}
515 	nPos = aLbBitmaps.GetSelectEntryPos();
516 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
517 		*pPos = nPos;
518 	return 0L;
519 }
520 
521 //------------------------------------------------------------------------
522 
IMPL_LINK(SvxBitmapTabPage,ClickAddHdl_Impl,void *,EMPTYARG)523 IMPL_LINK( SvxBitmapTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
524 {
525 	ResMgr& rMgr = CUI_MGR();
526 	String aNewName( SVX_RES( RID_SVXSTR_BITMAP ) );
527 	String aDesc( CUI_RES( RID_SVXSTR_DESC_NEW_BITMAP ) );
528 	String aName;
529 
530 	long nCount = maBitmapList.get() ? maBitmapList->Count() : 0;
531 	long j = 1;
532 	sal_Bool bDifferent = sal_False;
533 
534 	while( !bDifferent )
535 	{
536 		aName  = aNewName;
537 		aName += sal_Unicode(' ');
538 		aName += UniString::CreateFromInt32( j++ );
539 		bDifferent = sal_True;
540 
541 		for( long i = 0; i < nCount && bDifferent; i++ )
542             if( aName == maBitmapList->GetBitmap( i )->GetName() )
543 				bDifferent = sal_False;
544 	}
545 
546 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
547 	DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
548 	AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
549 	DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
550 	WarningBox*    pWarnBox = NULL;
551 	sal_uInt16         nError   = RID_SVXSTR_WARN_NAME_DUPLICATE;
552 
553 	while( pDlg->Execute() == RET_OK )
554 	{
555 		pDlg->GetName( aName );
556 
557 		bDifferent = sal_True;
558 
559 		for( long i = 0; i < nCount && bDifferent; i++ )
560             if( aName == maBitmapList->GetBitmap( i )->GetName() )
561 				bDifferent = sal_False;
562 
563 		if( bDifferent ) {
564 			nError = 0;
565 			break;
566 		}
567 
568 		if( !pWarnBox )
569 		{
570 			pWarnBox = new WarningBox( DLGWIN,
571 									   WinBits( WB_OK_CANCEL ),
572 									   String( ResId( nError, rMgr ) ) );
573 			pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
574 		}
575 
576 		if( pWarnBox->Execute() != RET_OK )
577 			break;
578 	}
579 
580     delete pDlg;
581 	delete pWarnBox;
582 
583 	if( !nError )
584 	{
585 		XBitmapEntry* pEntry = 0;
586 		if( aCtlPixel.IsEnabled() )
587 		{
588 			const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
589 
590 			pEntry = new XBitmapEntry(Graphic(aBitmapEx), aName);
591 		}
592 		else // Es muss sich um eine nicht vorhandene importierte Bitmap handeln
593 		{
594 			const SfxPoolItem* pPoolItem = 0;
595 
596             if(SFX_ITEM_SET == rOutAttrs.GetItemState(XATTR_FILLBITMAP, true, &pPoolItem))
597 			{
598                 pEntry = new XBitmapEntry(dynamic_cast< const XFillBitmapItem* >(pPoolItem)->GetGraphicObject(), aName);
599 			}
600 		}
601 
602 		DBG_ASSERT( pEntry, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
603 
604 		if( pEntry )
605 		{
606 			maBitmapList->Insert( pEntry );
607             const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
608 			aLbBitmaps.Append(rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry );
609 			aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
610 
611 			// Flag fuer modifiziert setzen
612 			*pnBitmapListState |= CT_MODIFIED;
613 
614 			ChangeBitmapHdl_Impl( this );
615 		}
616 	}
617 
618 	// Status der Buttons ermitteln
619 	if( maBitmapList.get() && maBitmapList->Count() )
620 	{
621 		aBtnModify.Enable();
622 		aBtnDelete.Enable();
623 		aBtnSave.Enable();
624 	}
625 	return 0L;
626 }
627 
628 
629 /******************************************************************************/
630 /******************************************************************************/
631 
632 
633 //------------------------------------------------------------------------
634 
635 #ifdef _MSC_VER
636 #pragma optimize ( "", off )
637 #endif
638 
IMPL_LINK(SvxBitmapTabPage,ClickImportHdl_Impl,void *,EMPTYARG)639 IMPL_LINK( SvxBitmapTabPage, ClickImportHdl_Impl, void *, EMPTYARG )
640 {
641 	ResMgr& rMgr = CUI_MGR();
642 	SvxOpenGraphicDialog aDlg( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Import" ) ) );
643 	aDlg.EnableLink(sal_False);
644 
645 	if( !aDlg.Execute() )
646 	{
647 		Graphic 		aGraphic;
648 		int 			nError = 1;
649 
650 		EnterWait();
651 		nError = aDlg.GetGraphic( aGraphic );
652 		LeaveWait();
653 
654 		if( !nError )
655 		{
656 			String aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP, rMgr) );
657 			WarningBox*    pWarnBox = NULL;
658 
659 			// convert file URL to UI name
660 			String 			aName;
661 			INetURLObject	aURL( aDlg.GetPath() );
662 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
663 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
664 			AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, String(aURL.GetName()).GetToken( 0, '.' ), aDesc );
665 			DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
666 			nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
667 
668 			while( pDlg->Execute() == RET_OK )
669 			{
670 				pDlg->GetName( aName );
671 
672 				sal_Bool bDifferent = sal_True;
673 				long nCount     = maBitmapList->Count();
674 
675 				for( long i = 0; i < nCount && bDifferent; i++ )
676                     if( aName == maBitmapList->GetBitmap( i )->GetName() )
677 						bDifferent = sal_False;
678 
679 				if( bDifferent ) {
680 					nError = 0;
681 					break;
682 				}
683 
684 				if( !pWarnBox )
685 				{
686 					pWarnBox = new WarningBox( DLGWIN,
687 											   WinBits( WB_OK_CANCEL ),
688 											   String( ResId( nError, rMgr ) ) );
689 					pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
690 				}
691 
692 
693 				if( pWarnBox->Execute() != RET_OK )
694 					break;
695 			}
696 
697             delete pDlg;
698 			delete pWarnBox;
699 
700 			if( !nError )
701 			{
702 				XBitmapEntry* pEntry = new XBitmapEntry( aGraphic, aName );
703 				maBitmapList->Insert( pEntry );
704 
705                 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
706                 aLbBitmaps.Append(rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry );
707 				aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
708 
709 				// Flag fuer modifiziert setzen
710 				*pnBitmapListState |= CT_MODIFIED;
711 
712 				ChangeBitmapHdl_Impl( this );
713 			}
714 		}
715 		else
716 			// Graphik konnte nicht geladen werden
717 			ErrorBox( DLGWIN,
718 					  WinBits( WB_OK ),
719 					  String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
720 	}
721 
722 	return 0L;
723 }
724 
725 #ifdef _MSC_VER
726 #pragma optimize ( "", on )
727 #endif
728 
729 //------------------------------------------------------------------------
730 
IMPL_LINK(SvxBitmapTabPage,ClickModifyHdl_Impl,void *,EMPTYARG)731 IMPL_LINK( SvxBitmapTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
732 {
733 	sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
734 
735 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
736 	{
737 		ResMgr& rMgr = CUI_MGR();
738 		String aNewName( SVX_RES( RID_SVXSTR_BITMAP ) );
739 		String aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP, rMgr ) );
740         String aName( maBitmapList->GetBitmap( nPos )->GetName() );
741 		String aOldName = aName;
742 
743 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
744 		DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
745 		AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
746 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
747 
748 		long nCount = maBitmapList.get() ? maBitmapList->Count() : 0;
749 		sal_Bool bDifferent = sal_False;
750 		sal_Bool bLoop = sal_True;
751         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
752 
753 		while( bLoop && pDlg->Execute() == RET_OK )
754 		{
755 			pDlg->GetName( aName );
756 			bDifferent = sal_True;
757 
758 			for( long i = 0; i < nCount && bDifferent; i++ )
759 			{
760                 if( aName == maBitmapList->GetBitmap( i )->GetName() &&
761 					aName != aOldName )
762 					bDifferent = sal_False;
763 			}
764 
765 			if( bDifferent )
766 			{
767 				bLoop = sal_False;
768 
769 				const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
770 
771                 // #123497# Need to replace the existing entry with a new one (old returned needs to be deleted)
772                 XBitmapEntry* pEntry = new XBitmapEntry(Graphic(aBitmapEx), aName);
773                 delete maBitmapList->Replace(pEntry, nPos);
774 
775 				aLbBitmaps.Modify( rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry, nPos );
776 				aLbBitmaps.SelectEntryPos( nPos );
777 
778 				// Flag fuer modifiziert setzen
779 				*pnBitmapListState |= CT_MODIFIED;
780 
781 				bBmpChanged = sal_False;
782 			}
783 			else
784 			{
785 				WarningBox aBox( DLGWIN, WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
786 				aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
787 				aBox.Execute();
788 			}
789 		}
790 		delete pDlg;
791 	}
792 	return 0L;
793 }
794 
795 //------------------------------------------------------------------------
796 
IMPL_LINK(SvxBitmapTabPage,ClickDeleteHdl_Impl,void *,EMPTYARG)797 IMPL_LINK( SvxBitmapTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
798 {
799 	sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
800 
801 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
802 	{
803 		QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
804 			String( CUI_RES( RID_SVXSTR_ASK_DEL_BITMAP ) ) );
805 
806 		if( aQueryBox.Execute() == RET_YES )
807 		{
808 			delete maBitmapList->Remove( nPos );
809 			aLbBitmaps.RemoveEntry( nPos );
810 			aLbBitmaps.SelectEntryPos( 0 );
811 
812 			aCtlPreview.Invalidate();
813 			aCtlPixel.Invalidate();
814 
815 			ChangeBitmapHdl_Impl( this );
816 
817 			// Flag fuer modifiziert setzen
818 			*pnBitmapListState |= CT_MODIFIED;
819 		}
820 	}
821 	// Status der Buttons ermitteln
822 	if( !maBitmapList.get() || !maBitmapList->Count() )
823 	{
824 		aBtnModify.Disable();
825 		aBtnDelete.Disable();
826 		aBtnSave.Disable();
827 	}
828 	return 0L;
829 }
830 
831 // -----------------------------------------------------------------------
832 
IMPL_LINK(SvxBitmapTabPage,ClickLoadHdl_Impl,void *,EMPTYARG)833 IMPL_LINK( SvxBitmapTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
834 {
835 	sal_uInt16 nReturn = RET_YES;
836 	ResMgr& rMgr = CUI_MGR();
837 
838 	if ( *pnBitmapListState & CT_MODIFIED )
839 	{
840 		nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
841 			String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
842 
843 		if ( nReturn == RET_YES )
844 			maBitmapList->Save();
845 	}
846 
847 	if ( nReturn != RET_CANCEL )
848 	{
849     	::sfx2::FileDialogHelper aDlg(
850             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
851             0 );
852 		String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
853 		aDlg.AddFilter( aStrFilterType, aStrFilterType );
854 		INetURLObject aFile( SvtPathOptions().GetPalettePath() );
855 		aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
856 
857     	if ( aDlg.Execute() == ERRCODE_NONE )
858 		{
859 			EnterWait();
860 			INetURLObject aURL( aDlg.GetPath() );
861 			INetURLObject aPathURL( aURL );
862 
863 			aPathURL.removeSegment();
864 			aPathURL.removeFinalSlash();
865 
866 			// Tabelle speichern
867 			XBitmapListSharedPtr aBmpList(XPropertyListFactory::CreateSharedXBitmapList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
868 			aBmpList->SetName( aURL.getName() );
869 			if( aBmpList->Load() )
870 			{
871 				if( aBmpList.get() )
872 				{
873 					maBitmapList = aBmpList;
874 					( (SvxAreaTabDialog*) DLGWIN )->SetNewBitmapList( maBitmapList );
875 
876 					aLbBitmaps.Clear();
877 					aLbBitmaps.Fill( maBitmapList );
878 					Reset( rOutAttrs );
879 
880 					maBitmapList->SetName( aURL.getName() );
881 
882 					// Ermitteln (evtl. abschneiden) des Namens und in
883 					// der GroupBox darstellen
884 					String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
885 					aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
886 
887 					if ( aURL.getBase().getLength() > 18 )
888 					{
889 						aString += String(aURL.getBase()).Copy( 0, 15 );
890 						aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
891 					}
892 					else
893 						aString += String(aURL.getBase());
894 
895 					// Flag fuer gewechselt setzen
896 					*pnBitmapListState |= CT_CHANGED;
897 					// Flag fuer modifiziert entfernen
898 					*pnBitmapListState &= ~CT_MODIFIED;
899 				}
900 				LeaveWait();
901 			}
902 			else
903 			{
904 				LeaveWait();
905 				ErrorBox( DLGWIN, WinBits( WB_OK ),
906 					String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
907 			}
908 		}
909 	}
910 
911 	// Status der Buttons ermitteln
912 	if( maBitmapList.get() && maBitmapList->Count() )
913 	{
914 		aBtnModify.Enable();
915 		aBtnDelete.Enable();
916 		aBtnSave.Enable();
917 	}
918 	else
919 	{
920 		aBtnModify.Disable();
921 		aBtnDelete.Disable();
922 		aBtnSave.Disable();
923 	}
924 	return 0L;
925 }
926 
927 // -----------------------------------------------------------------------
928 
IMPL_LINK(SvxBitmapTabPage,ClickSaveHdl_Impl,void *,EMPTYARG)929 IMPL_LINK( SvxBitmapTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
930 {
931    	::sfx2::FileDialogHelper aDlg(
932         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
933 	String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sob" ) );
934 	aDlg.AddFilter( aStrFilterType, aStrFilterType );
935 
936 	INetURLObject aFile( SvtPathOptions().GetPalettePath() );
937 	DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
938 
939 	if( maBitmapList->GetName().Len() )
940 	{
941 		aFile.Append( maBitmapList->GetName() );
942 
943 		if( !aFile.getExtension().getLength() )
944 			aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sob" ) ) );
945 	}
946 
947 	aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
948 	if ( aDlg.Execute() == ERRCODE_NONE )
949 	{
950 		INetURLObject	aURL( aDlg.GetPath() );
951 		INetURLObject	aPathURL( aURL );
952 
953 		aPathURL.removeSegment();
954 		aPathURL.removeFinalSlash();
955 
956 		maBitmapList->SetName( aURL.getName() );
957 		maBitmapList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
958 
959 		if( maBitmapList->Save() )
960 		{
961 			// Ermitteln (evtl. abschneiden) des Namens und in
962 			// der GroupBox darstellen
963 			String aString( CUI_RES( RID_SVXSTR_TABLE ) );
964 			aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
965 
966 			if ( aURL.getBase().getLength() > 18 )
967 			{
968 				aString += String(aURL.getBase()).Copy( 0, 15 );
969 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
970 			}
971 			else
972 				aString += String(aURL.getBase());
973 
974 			// Flag fuer gespeichert setzen
975 			*pnBitmapListState |= CT_SAVED;
976 			// Flag fuer modifiziert entfernen
977 			*pnBitmapListState &= ~CT_MODIFIED;
978 		}
979 		else
980 		{
981 			ErrorBox( DLGWIN, WinBits( WB_OK ),
982 				String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
983 		}
984 	}
985 
986 	return 0L;
987 }
988 
989 //------------------------------------------------------------------------
990 
IMPL_LINK(SvxBitmapTabPage,ChangePixelColorHdl_Impl,void *,EMPTYARG)991 IMPL_LINK( SvxBitmapTabPage, ChangePixelColorHdl_Impl, void *, EMPTYARG )
992 {
993 	aCtlPixel.SetPixelColor( aLbColor.GetSelectEntryColor() );
994 	aCtlPixel.Invalidate();
995 
996 	aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
997 
998 	// Bitmap holen und darstellen
999 	rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
1000 	aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1001 	aCtlPreview.Invalidate();
1002 
1003 	bBmpChanged = sal_True;
1004 
1005 	return 0L;
1006 }
1007 
1008 //------------------------------------------------------------------------
1009 
IMPL_LINK(SvxBitmapTabPage,ChangeBackgrndColorHdl_Impl,void *,EMPTYARG)1010 IMPL_LINK( SvxBitmapTabPage, ChangeBackgrndColorHdl_Impl, void *, EMPTYARG )
1011 {
1012 	aCtlPixel.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
1013 	aCtlPixel.Invalidate();
1014 
1015 	aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
1016 
1017 	// Bitmap holen und darstellen
1018 	rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
1019 	aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1020 	aCtlPreview.Invalidate();
1021 
1022 	bBmpChanged = sal_True;
1023 
1024 	return 0L;
1025 }
1026 
1027 //------------------------------------------------------------------------
1028 
PointChanged(Window * pWindow,RECT_POINT)1029 void SvxBitmapTabPage::PointChanged( Window* pWindow, RECT_POINT )
1030 {
1031 	if( pWindow == &aCtlPixel )
1032 	{
1033         aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
1034 
1035 		// Bitmap holen und darstellen
1036 		rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
1037 		aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
1038 		aCtlPreview.Invalidate();
1039 
1040 		bBmpChanged = sal_True;
1041 	}
1042 }
1043 
1044 
1045 
1046 
GetParentLabeledBy(const Window * pLabeled) const1047 Window*	SvxBitmapTabPage::GetParentLabeledBy( const Window* pLabeled ) const
1048 {
1049     if (pLabeled == &aLbBitmaps)
1050         return const_cast<FixedText*>(&aLbBitmapsHidden);
1051     else
1052         return SvxTabPage::GetParentLabeledBy (pLabeled);
1053 }
1054