Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <unotools/pathoptions.hxx>
21 : #include <vcl/builder.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <tools/urlobj.hxx>
24 : #include <sfx2/objsh.hxx>
25 : #include <sfx2/docfile.hxx>
26 : #include <svl/cntwall.hxx>
27 : #include <sfx2/cntids.hrc>
28 : #include <svx/dialogs.hrc>
29 :
30 : #include <cuires.hrc>
31 : #include <svx/dialmgr.hxx>
32 : #include <editeng/memberids.hrc>
33 : #include <editeng/editrids.hrc>
34 : #include <editeng/eerdll.hxx>
35 :
36 : // table background
37 : #define TBL_DEST_CELL 0
38 : #define TBL_DEST_ROW 1
39 : #define TBL_DEST_TBL 2
40 :
41 : #include <editeng/brushitem.hxx>
42 : #include "backgrnd.hxx"
43 :
44 : #include <svx/xtable.hxx>
45 : #include <sfx2/opengrf.hxx>
46 : #include <svx/svxerr.hxx>
47 : #include <svx/drawitem.hxx>
48 : #include <dialmgr.hxx>
49 : #include <sfx2/htmlmode.hxx>
50 : #include <svtools/controldims.hrc>
51 : #include <svx/flagsdef.hxx>
52 : #include <svx/xfillit0.hxx>
53 : #include <svx/xflgrit.hxx>
54 : #include <svl/intitem.hxx>
55 : #include <sfx2/request.hxx>
56 : #include <svtools/grfmgr.hxx>
57 :
58 : using namespace ::com::sun::star;
59 : // static ----------------------------------------------------------------
60 :
61 : static sal_uInt16 pRanges[] =
62 : {
63 : SID_VIEW_FLD_PIC, SID_VIEW_FLD_PIC,
64 : SID_ATTR_BRUSH, SID_ATTR_BRUSH,
65 : SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
66 : 0
67 : };
68 :
69 : struct SvxBackgroundTable_Impl
70 : {
71 : SvxBrushItem* pCellBrush;
72 : SvxBrushItem* pRowBrush;
73 : SvxBrushItem* pTableBrush;
74 : sal_uInt16 nCellWhich;
75 : sal_uInt16 nRowWhich;
76 : sal_uInt16 nTableWhich;
77 : sal_uInt16 nActPos;
78 :
79 0 : SvxBackgroundTable_Impl() :
80 : pCellBrush(NULL), pRowBrush(NULL), pTableBrush(NULL),
81 0 : nCellWhich(0), nRowWhich(0), nTableWhich(0) {}
82 : };
83 :
84 : struct SvxBackgroundPara_Impl
85 : {
86 : SvxBrushItem* pParaBrush;
87 : SvxBrushItem* pCharBrush;
88 :
89 : sal_uInt16 nActPos;
90 :
91 0 : SvxBackgroundPara_Impl() :
92 0 : pParaBrush(NULL), pCharBrush(NULL) {}
93 : };
94 :
95 : struct SvxBackgroundPage_Impl
96 : {
97 : Timer* pLoadTimer;
98 : sal_Bool bIsImportDlgInExecute;
99 :
100 0 : SvxBackgroundPage_Impl() :
101 0 : pLoadTimer(NULL), bIsImportDlgInExecute(sal_False) {}
102 : };
103 :
104 0 : static inline sal_uInt8 lcl_PercentToTransparency(long nPercent)
105 : {
106 : //0xff must not be returned!
107 0 : return sal_uInt8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
108 : }
109 0 : static inline sal_uInt8 lcl_TransparencyToPercent(sal_uInt8 nTrans)
110 : {
111 0 : return (nTrans * 100 + 127) / 254;
112 : }
113 0 : static void lcl_SetTransparency(SvxBrushItem& rBrush, long nTransparency)
114 : {
115 0 : uno::Any aTransparency;
116 0 : aTransparency <<= (sal_Int8)nTransparency;
117 0 : rBrush.PutValue(aTransparency, MID_GRAPHIC_TRANSPARENCY);
118 0 : }
119 :
120 : /// Returns the fill style of the currently selected entry.
121 0 : static XFillStyle lcl_getFillStyle(ListBox* pLbSelect)
122 : {
123 0 : return (XFillStyle)(sal_uLong)pLbSelect->GetEntryData(pLbSelect->GetSelectEntryPos());
124 : }
125 :
126 : // Selects the entry matching the specified fill style.
127 0 : static void lcl_setFillStyle(ListBox* pLbSelect, XFillStyle eStyle)
128 : {
129 0 : for (int i = 0; i < pLbSelect->GetEntryCount(); ++i)
130 0 : if ((XFillStyle)(sal_uLong)pLbSelect->GetEntryData(i) == eStyle)
131 : {
132 0 : pLbSelect->SelectEntryPos(i);
133 0 : return;
134 : }
135 : }
136 : //-------------------------------------------------------------------------
137 :
138 0 : sal_uInt16 GetItemId_Impl( ValueSet& rValueSet, const Color& rCol )
139 : {
140 0 : sal_Bool bFound = sal_False;
141 0 : sal_uInt16 nCount = rValueSet.GetItemCount();
142 0 : sal_uInt16 n = 1;
143 :
144 0 : while ( !bFound && n <= nCount )
145 : {
146 0 : Color aValCol = rValueSet.GetItemColor(n);
147 :
148 0 : bFound = ( aValCol.GetRed() == rCol.GetRed()
149 0 : && aValCol.GetGreen() == rCol.GetGreen()
150 0 : && aValCol.GetBlue() == rCol.GetBlue() );
151 :
152 0 : if ( !bFound )
153 0 : n++;
154 : }
155 0 : return bFound ? n : 0;
156 : }
157 :
158 : // class BackgroundPreview -----------------------------------------------
159 :
160 : /* [Description]
161 :
162 : preview window for brush or bitmap
163 : */
164 :
165 : class BackgroundPreviewImpl : public Window
166 : {
167 : public:
168 : BackgroundPreviewImpl(Window* pParent);
169 : void setBmp(bool bBmp);
170 : ~BackgroundPreviewImpl();
171 :
172 : void NotifyChange( const Color& rColor );
173 : void NotifyChange( const Bitmap* pBitmap );
174 :
175 : protected:
176 : virtual void Paint( const Rectangle& rRect );
177 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
178 : virtual void Resize();
179 :
180 : private:
181 :
182 : void recalcDrawPos();
183 :
184 : bool bIsBmp;
185 : Bitmap* pBitmap;
186 : Point aDrawPos;
187 : Size aDrawSize;
188 : Rectangle aDrawRect;
189 : sal_uInt8 nTransparency;
190 : };
191 :
192 0 : BackgroundPreviewImpl::BackgroundPreviewImpl(Window* pParent)
193 : : Window(pParent, WB_BORDER)
194 : , bIsBmp(false)
195 : , pBitmap(NULL)
196 0 : , aDrawRect(Point(0,0), GetOutputSizePixel())
197 0 : , nTransparency(0)
198 : {
199 0 : SetBorderStyle(WINDOW_BORDER_MONO);
200 0 : Paint(aDrawRect);
201 0 : }
202 :
203 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeBackgroundPreview(Window *pParent, VclBuilder::stringmap &)
204 : {
205 0 : return new BackgroundPreviewImpl(pParent);
206 : }
207 :
208 0 : void BackgroundPreviewImpl::setBmp(bool bBmp)
209 : {
210 0 : bIsBmp = bBmp;
211 0 : Invalidate();
212 0 : }
213 :
214 : //-----------------------------------------------------------------------
215 :
216 0 : BackgroundPreviewImpl::~BackgroundPreviewImpl()
217 : {
218 0 : delete pBitmap;
219 0 : }
220 :
221 : //-----------------------------------------------------------------------
222 0 : void BackgroundPreviewImpl::NotifyChange( const Color& rColor )
223 : {
224 0 : if ( !bIsBmp )
225 : {
226 0 : const static Color aTranspCol( COL_TRANSPARENT );
227 :
228 0 : nTransparency = lcl_TransparencyToPercent( rColor.GetTransparency() );
229 :
230 0 : SetFillColor( rColor == aTranspCol ? GetSettings().GetStyleSettings().GetFieldColor() : (Color) rColor.GetRGBColor() );
231 0 : Paint( aDrawRect );
232 : }
233 0 : }
234 :
235 : //-----------------------------------------------------------------------
236 :
237 0 : void BackgroundPreviewImpl::NotifyChange( const Bitmap* pNewBitmap )
238 : {
239 0 : if ( bIsBmp && (pNewBitmap || pBitmap) )
240 : {
241 0 : if ( pNewBitmap && pBitmap )
242 0 : *pBitmap = *pNewBitmap;
243 0 : else if ( pNewBitmap && !pBitmap )
244 0 : pBitmap = new Bitmap( *pNewBitmap );
245 0 : else if ( !pNewBitmap )
246 0 : DELETEZ( pBitmap );
247 :
248 0 : recalcDrawPos();
249 :
250 0 : Invalidate( aDrawRect );
251 0 : Update();
252 : }
253 0 : }
254 :
255 0 : void BackgroundPreviewImpl::recalcDrawPos()
256 : {
257 0 : if ( pBitmap )
258 : {
259 0 : Size aSize = GetOutputSizePixel();
260 : // InnerSize == Size without one pixel border
261 0 : Size aInnerSize = aSize;
262 0 : aInnerSize.Width() -= 2;
263 0 : aInnerSize.Height() -= 2;
264 0 : aDrawSize = pBitmap->GetSizePixel();
265 :
266 : // bitmap bigger than preview window?
267 0 : if ( aDrawSize.Width() > aInnerSize.Width() )
268 : {
269 0 : aDrawSize.Height() = aDrawSize.Height() * aInnerSize.Width() / aDrawSize.Width();
270 0 : if ( aDrawSize.Height() > aInnerSize.Height() )
271 : {
272 0 : aDrawSize.Width() = aDrawSize.Height();
273 0 : aDrawSize.Height() = aInnerSize.Height();
274 : }
275 : else
276 0 : aDrawSize.Width() = aInnerSize.Width();
277 : }
278 0 : else if ( aDrawSize.Height() > aInnerSize.Height() )
279 : {
280 0 : aDrawSize.Width() = aDrawSize.Width() * aInnerSize.Height() / aDrawSize.Height();
281 0 : if ( aDrawSize.Width() > aInnerSize.Width() )
282 : {
283 0 : aDrawSize.Height() = aDrawSize.Width();
284 0 : aDrawSize.Width() = aInnerSize.Width();
285 : }
286 : else
287 0 : aDrawSize.Height() = aInnerSize.Height();
288 : }
289 :
290 0 : aDrawPos.X() = (aSize.Width() - aDrawSize.Width()) / 2;
291 0 : aDrawPos.Y() = (aSize.Height() - aDrawSize.Height()) / 2;
292 : }
293 0 : }
294 :
295 0 : void BackgroundPreviewImpl::Resize()
296 : {
297 0 : Window::Resize();
298 0 : aDrawRect = Rectangle(Point(0,0), GetOutputSizePixel());
299 0 : recalcDrawPos();
300 0 : }
301 :
302 : //-----------------------------------------------------------------------
303 :
304 0 : void BackgroundPreviewImpl::Paint( const Rectangle& )
305 : {
306 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
307 0 : SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
308 0 : SetLineColor();
309 0 : if(bIsBmp)
310 0 : SetFillColor( Color(COL_TRANSPARENT) );
311 0 : DrawRect( aDrawRect );
312 0 : if ( bIsBmp )
313 : {
314 0 : if ( pBitmap )
315 0 : DrawBitmap( aDrawPos, aDrawSize, *pBitmap );
316 : else
317 : {
318 0 : Size aSize = GetOutputSizePixel();
319 0 : DrawLine( Point(0,0), Point(aSize.Width(),aSize.Height()) );
320 0 : DrawLine( Point(0,aSize.Height()), Point(aSize.Width(),0) );
321 : }
322 : }
323 0 : }
324 :
325 0 : void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
326 : {
327 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
328 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
329 : {
330 0 : Invalidate();
331 : }
332 0 : Window::DataChanged( rDCEvt );
333 0 : }
334 :
335 : // class SvxBackgroundTabPage --------------------------------------------
336 :
337 : #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
338 :
339 0 : SvxBackgroundTabPage::SvxBackgroundTabPage(Window* pParent, const SfxItemSet& rCoreSet)
340 : : SvxTabPage(pParent, "BackgroundPage", "cui/ui/backgroundpage.ui", rCoreSet)
341 0 : , m_pXPool(rCoreSet.GetPool())
342 : , m_aXFillAttr(m_pXPool)
343 0 : , m_rXFillSet(m_aXFillAttr.GetItemSet())
344 : , nHtmlMode(0)
345 : , bAllowShowSelector(true)
346 : , bIsGraphicValid(false)
347 : , bLinkOnly(false)
348 : , bColTransparency(false)
349 : , bGraphTransparency(false)
350 0 : , pPageImpl(new SvxBackgroundPage_Impl)
351 : , pImportDlg(NULL)
352 : , pTableBck_Impl(NULL)
353 0 : , pParaBck_Impl(NULL)
354 : {
355 0 : get(m_pAsGrid, "asgrid");
356 0 : get(m_pSelectTxt, "asft");
357 0 : get(m_pLbSelect, "selectlb");
358 0 : get(m_pTblDesc, "forft");
359 0 : get(m_pTblLBox, "tablelb");
360 0 : get(m_pParaLBox, "paralb");
361 :
362 0 : get(m_pBackGroundColorFrame, "backgroundcolorframe");
363 0 : get(m_pBackgroundColorSet, "backgroundcolorset");
364 0 : get(m_pPreviewWin1, "preview1");
365 :
366 0 : get(m_pColTransFT, "transparencyft");
367 0 : get(m_pColTransMF, "transparencymf");
368 0 : get(m_pBtnPreview, "showpreview");
369 :
370 : // Initialize gradient controls
371 0 : get(m_pBackGroundGradientFrame, "backgroundgradientframe");
372 0 : get(m_pLbGradients, "gradientslb");
373 0 : Size aSize = LogicToPixel(Size(88, 110), MAP_APPFONT);
374 0 : m_pLbGradients->set_width_request(aSize.Width());
375 0 : m_pLbGradients->set_height_request(aSize.Height());
376 0 : get(m_pCtlPreview, "previewctl");
377 0 : aSize = LogicToPixel(Size(88, 42), MAP_APPFONT);
378 0 : m_pCtlPreview->set_width_request(aSize.Width());
379 0 : m_pCtlPreview->set_height_request(aSize.Height());
380 :
381 0 : get(m_pBitmapContainer, "graphicgrid");
382 0 : get(m_pFileFrame, "fileframe");
383 0 : get(m_pBtnBrowse, "browse");
384 0 : get(m_pBtnLink, "link");
385 0 : get(m_pFtUnlinked, "unlinkedft");
386 0 : get(m_pFtFile, "fileft");
387 :
388 0 : get(m_pTypeFrame, "typeframe");
389 0 : get(m_pBtnPosition, "positionrb");
390 0 : get(m_pBtnArea, "arearb");
391 0 : get(m_pBtnTile, "tilerb");
392 0 : get(m_pWndPosition, "windowpos");
393 :
394 0 : get(m_pGraphTransFrame, "graphtransframe");
395 0 : get(m_pGraphTransMF, "graphtransmf");
396 :
397 0 : get(m_pPreviewWin2, "preview2");
398 0 : m_pPreviewWin2->setBmp(true);
399 :
400 : // this page needs ExchangeSupport
401 0 : SetExchangeSupport();
402 :
403 : const SfxPoolItem* pItem;
404 : SfxObjectShell* pShell;
405 :
406 0 : if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_HTML_MODE, sal_False, &pItem )
407 0 : || ( 0 != ( pShell = SfxObjectShell::Current()) &&
408 0 : 0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
409 : {
410 0 : nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
411 : }
412 :
413 0 : FillColorValueSets_Impl();
414 :
415 0 : m_pBackgroundColorSet->SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
416 0 : m_pBackgroundColorSet->SetStyle(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
417 0 : m_pBackgroundColorSet->SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT));
418 0 : }
419 :
420 : //------------------------------------------------------------------------
421 :
422 0 : SvxBackgroundTabPage::~SvxBackgroundTabPage()
423 : {
424 0 : delete pPageImpl->pLoadTimer;
425 0 : delete pPageImpl;
426 0 : delete pImportDlg;
427 :
428 0 : if( pTableBck_Impl)
429 : {
430 0 : delete pTableBck_Impl->pCellBrush;
431 0 : delete pTableBck_Impl->pRowBrush;
432 0 : delete pTableBck_Impl->pTableBrush;
433 0 : delete pTableBck_Impl;
434 : }
435 :
436 0 : if(pParaBck_Impl)
437 : {
438 0 : delete pParaBck_Impl->pParaBrush;
439 0 : delete pParaBck_Impl->pCharBrush;
440 0 : delete pParaBck_Impl;
441 : }
442 0 : }
443 :
444 : //------------------------------------------------------------------------
445 :
446 0 : sal_uInt16* SvxBackgroundTabPage::GetRanges()
447 :
448 : /* [Description]
449 :
450 : returns the area of the which-values
451 : */
452 :
453 : {
454 0 : return pRanges;
455 : }
456 :
457 : //------------------------------------------------------------------------
458 :
459 0 : SfxTabPage* SvxBackgroundTabPage::Create( Window* pParent,
460 : const SfxItemSet& rAttrSet )
461 :
462 : /* [Description]
463 :
464 : create method for the TabDialog
465 : */
466 :
467 : {
468 0 : return ( new SvxBackgroundTabPage( pParent, rAttrSet ) );
469 : }
470 :
471 : //------------------------------------------------------------------------
472 :
473 0 : void SvxBackgroundTabPage::Reset( const SfxItemSet& rSet )
474 : {
475 : // os: Such a nonsense! One will always find such an item somewhere,
476 : // but it must be existing in the rSet!
477 : // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
478 : // if( pX && pX->ISA(SfxWallpaperItem))
479 0 : if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
480 : {
481 0 : ResetFromWallpaperItem( rSet );
482 0 : return;
483 : }
484 :
485 : // condition of the preview button is persistent due to UserData
486 0 : String aUserData = GetUserData();
487 0 : m_pBtnPreview->Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
488 :
489 : // don't be allowed to call ShowSelector() after reset anymore
490 0 : bAllowShowSelector = sal_False;
491 :
492 :
493 : // get and evaluate Input-BrushItem
494 0 : const SvxBrushItem* pBgdAttr = NULL;
495 0 : sal_uInt16 nSlot = SID_ATTR_BRUSH;
496 : const SfxPoolItem* pItem;
497 0 : sal_uInt16 nDestValue = USHRT_MAX;
498 :
499 0 : if ( SFX_ITEM_SET == rSet.GetItemState( SID_BACKGRND_DESTINATION,
500 0 : sal_False, &pItem ) )
501 : {
502 0 : nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
503 0 : m_pTblLBox->SelectEntryPos(nDestValue);
504 :
505 0 : switch ( nDestValue )
506 : {
507 : case TBL_DEST_CELL:
508 0 : nSlot = SID_ATTR_BRUSH;
509 0 : break;
510 : case TBL_DEST_ROW:
511 0 : nSlot = SID_ATTR_BRUSH_ROW;
512 0 : break;
513 : case TBL_DEST_TBL:
514 0 : nSlot = SID_ATTR_BRUSH_TABLE;
515 0 : break;
516 : }
517 : }
518 0 : else if( SFX_ITEM_SET == rSet.GetItemState(
519 0 : SID_PARA_BACKGRND_DESTINATION, sal_False, &pItem ) )
520 : {
521 0 : nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
522 : // character activated?
523 0 : sal_uInt16 nParaSel = m_pParaLBox->GetSelectEntryPos();
524 0 : if(1 == nParaSel)
525 : {
526 : // then it was a "standard"-call
527 0 : nDestValue = nParaSel;
528 : }
529 0 : m_pParaLBox->SelectEntryPos(nDestValue);
530 :
531 0 : switch ( nDestValue )
532 : {
533 : case PARA_DEST_PARA:
534 0 : nSlot = SID_ATTR_BRUSH;
535 0 : break;
536 : case PARA_DEST_CHAR:
537 0 : nSlot = SID_ATTR_BRUSH_CHAR;
538 0 : break;
539 : }
540 : }
541 : //#111173# the destination item is missing when the parent style has been changed
542 0 : if(USHRT_MAX == nDestValue && (m_pParaLBox->IsVisible()||m_pTblLBox->IsVisible()))
543 0 : nDestValue = 0;
544 0 : sal_uInt16 nWhich = GetWhich( nSlot );
545 :
546 0 : if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
547 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
548 :
549 0 : m_pBtnTile->Check();
550 :
551 0 : if ( pBgdAttr )
552 : {
553 0 : FillControls_Impl(*pBgdAttr, aUserData);
554 0 : aBgdColor = ( (SvxBrushItem*)pBgdAttr )->GetColor();
555 : }
556 : else
557 : {
558 0 : m_pSelectTxt->Hide();
559 0 : m_pLbSelect->Hide();
560 0 : lcl_setFillStyle(m_pLbSelect, XFILL_SOLID);
561 0 : ShowColorUI_Impl();
562 :
563 0 : const SfxPoolItem* pOld = GetOldItem( rSet, SID_ATTR_BRUSH );
564 :
565 0 : if ( pOld )
566 0 : aBgdColor = ( (SvxBrushItem*)pOld )->GetColor();
567 : }
568 :
569 0 : if ( nDestValue != USHRT_MAX )
570 : {
571 0 : if(m_pTblLBox->IsVisible())
572 : {
573 0 : sal_uInt16 nValue = m_pTblLBox->GetSelectEntryPos();
574 :
575 0 : if ( pTableBck_Impl )
576 : {
577 0 : DELETEZ( pTableBck_Impl->pCellBrush);
578 0 : DELETEZ( pTableBck_Impl->pRowBrush);
579 0 : DELETEZ( pTableBck_Impl->pTableBrush);
580 : }
581 : else
582 0 : pTableBck_Impl = new SvxBackgroundTable_Impl();
583 :
584 0 : pTableBck_Impl->nActPos = nValue;
585 :
586 0 : nWhich = GetWhich( SID_ATTR_BRUSH );
587 0 : if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
588 : {
589 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
590 0 : pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
591 : }
592 0 : pTableBck_Impl->nCellWhich = nWhich;
593 :
594 0 : if ( rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False ) >= SFX_ITEM_AVAILABLE )
595 : {
596 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_ROW ) );
597 0 : pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
598 : }
599 0 : pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
600 :
601 0 : if ( rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False ) >= SFX_ITEM_AVAILABLE )
602 : {
603 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_TABLE ) );
604 0 : pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
605 : }
606 0 : pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
607 :
608 0 : TblDestinationHdl_Impl(m_pTblLBox);
609 0 : m_pTblLBox->SaveValue();
610 : }
611 : else
612 : {
613 0 : sal_uInt16 nValue = m_pParaLBox->GetSelectEntryPos();
614 :
615 0 : if ( pParaBck_Impl )
616 : {
617 0 : delete pParaBck_Impl->pParaBrush;
618 0 : delete pParaBck_Impl->pCharBrush;
619 : }
620 : else
621 0 : pParaBck_Impl = new SvxBackgroundPara_Impl();
622 :
623 0 : pParaBck_Impl->nActPos = nValue;
624 :
625 0 : nWhich = GetWhich( SID_ATTR_BRUSH );
626 0 : if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
627 : {
628 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
629 0 : pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
630 : }
631 :
632 0 : nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
633 0 : rSet.GetItemState( nWhich, sal_True );
634 0 : rSet.GetItemState( nWhich, sal_False );
635 0 : if ( rSet.GetItemState( nWhich, sal_True ) > SFX_ITEM_AVAILABLE )
636 : {
637 0 : pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
638 0 : pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
639 : }
640 : else
641 0 : pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
642 :
643 0 : ParaDestinationHdl_Impl(m_pParaLBox);
644 0 : m_pParaLBox->SaveValue();
645 : }
646 0 : }
647 : }
648 :
649 0 : void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
650 : {
651 0 : ShowSelector();
652 :
653 : // condition of the preview button is persistent due to UserData
654 0 : String aUserData = GetUserData();
655 0 : m_pBtnPreview->Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
656 :
657 : // get and evaluate Input-BrushItem
658 0 : const SvxBrushItem* pBgdAttr = NULL;
659 0 : sal_uInt16 nSlot = SID_VIEW_FLD_PIC;
660 0 : sal_uInt16 nWhich = GetWhich( nSlot );
661 0 : SvxBrushItem* pTemp = 0;
662 0 : const CntWallpaperItem* pItem = 0;
663 :
664 0 : if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
665 : {
666 0 : pItem = (const CntWallpaperItem*)&rSet.Get( nWhich );
667 0 : pTemp = new SvxBrushItem( *pItem, nWhich );
668 0 : pBgdAttr = pTemp;
669 : }
670 :
671 0 : m_pBtnTile->Check();
672 :
673 0 : if ( pBgdAttr )
674 : {
675 0 : FillControls_Impl(*pBgdAttr, aUserData);
676 : // brush shall be kept when showing the graphic, too
677 0 : if( aBgdColor != pBgdAttr->GetColor() )
678 : {
679 0 : aBgdColor = pBgdAttr->GetColor();
680 0 : sal_uInt16 nCol = GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor);
681 0 : m_pBackgroundColorSet->SelectItem( nCol );
682 0 : m_pPreviewWin1->NotifyChange( aBgdColor );
683 : }
684 : }
685 : else
686 : {
687 0 : lcl_setFillStyle(m_pLbSelect, XFILL_SOLID);
688 0 : ShowColorUI_Impl();
689 :
690 0 : const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
691 0 : if ( pOld )
692 0 : aBgdColor = Color( ((CntWallpaperItem*)pOld)->GetColor() );
693 : }
694 :
695 : // We now have always a link to the background
696 0 : bLinkOnly = sal_True;
697 0 : m_pBtnLink->Check( sal_True );
698 0 : m_pBtnLink->Show( sal_False );
699 : // if( !pItem || !pItem->GetWallpaper(sal_False).IsBitmap() )
700 : // m_pBtnLink->Check();
701 :
702 0 : delete pTemp;
703 0 : }
704 :
705 :
706 :
707 : //------------------------------------------------------------------------
708 :
709 0 : void SvxBackgroundTabPage::FillUserData()
710 :
711 : /* [Description]
712 :
713 : When destroying a SfxTabPage this virtual method is called,
714 : so that the TabPage can save internal information.
715 :
716 : In this case the condition of the preview button is saved.
717 : */
718 :
719 : {
720 0 : SetUserData( m_pBtnPreview->IsChecked() ? OUString('1') : OUString('0') );
721 0 : }
722 :
723 : //------------------------------------------------------------------------
724 :
725 0 : sal_Bool SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
726 : {
727 0 : if ( pPageImpl->pLoadTimer && pPageImpl->pLoadTimer->IsActive() )
728 : {
729 0 : pPageImpl->pLoadTimer->Stop();
730 0 : LoadTimerHdl_Impl( pPageImpl->pLoadTimer );
731 : }
732 : // os: Such a nonsense! One will always find such an item somewhere,
733 : // but it must be existing in the rSet!
734 :
735 : // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
736 : // if( pX && pX->ISA(SfxWallpaperItem))
737 0 : if(SFX_ITEM_AVAILABLE <= rCoreSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
738 0 : return FillItemSetWithWallpaperItem( rCoreSet, SID_VIEW_FLD_PIC );
739 :
740 0 : sal_Bool bModified = sal_False;
741 0 : sal_uInt16 nSlot = SID_ATTR_BRUSH;
742 :
743 0 : if ( m_pTblLBox->IsVisible() )
744 : {
745 0 : switch( m_pTblLBox->GetSelectEntryPos() )
746 : {
747 : case TBL_DEST_CELL:
748 0 : nSlot = SID_ATTR_BRUSH;
749 0 : break;
750 : case TBL_DEST_ROW:
751 0 : nSlot = SID_ATTR_BRUSH_ROW;
752 0 : break;
753 : case TBL_DEST_TBL:
754 0 : nSlot = SID_ATTR_BRUSH_TABLE;
755 0 : break;
756 : }
757 : }
758 0 : else if (m_pParaLBox->GetData() == m_pParaLBox)
759 : {
760 0 : switch(m_pParaLBox->GetSelectEntryPos())
761 : {
762 : case PARA_DEST_PARA:
763 0 : nSlot = SID_ATTR_BRUSH;
764 0 : break;
765 : case PARA_DEST_CHAR:
766 0 : nSlot = SID_ATTR_BRUSH_CHAR;
767 0 : break;
768 : }
769 : }
770 0 : sal_uInt16 nWhich = GetWhich( nSlot );
771 :
772 0 : const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
773 0 : SfxItemState eOldItemState = rCoreSet.GetItemState(nSlot, sal_False);
774 0 : const SfxItemSet& rOldSet = GetItemSet();
775 :
776 0 : sal_Bool bGraphTransparencyChanged = bGraphTransparency && (m_pGraphTransMF->GetText() != m_pGraphTransMF->GetSavedValue());
777 0 : if ( pOld )
778 : {
779 0 : const SvxBrushItem& rOldItem = (const SvxBrushItem&)*pOld;
780 0 : SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
781 0 : const sal_Bool bIsBrush = ( XFILL_SOLID == lcl_getFillStyle(m_pLbSelect) );
782 0 : const bool bIsGradient = ( XFILL_GRADIENT == lcl_getFillStyle(m_pLbSelect) );
783 :
784 : // transparency has to be set if enabled, the color not already set to "No fill" and
785 0 : if( bColTransparency &&
786 0 : aBgdColor.GetTransparency() < 0xff)
787 : {
788 0 : aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF->GetValue())));
789 : }
790 0 : if ( ( (GPOS_NONE == eOldPos) && (bIsBrush || bIsGradient) )
791 0 : || ( (GPOS_NONE != eOldPos) && !(bIsBrush || bIsGradient) ) ) // Brush <-> Bitmap changed?
792 : {
793 : // background art hasn't been changed:
794 :
795 0 : if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
796 : {
797 0 : if (bIsBrush)
798 : {
799 : // Brush-treatment:
800 0 : if ( rOldItem.GetColor() != aBgdColor ||
801 0 : (SFX_ITEM_AVAILABLE >= eOldItemState && !m_pBackgroundColorSet->IsNoSelection()))
802 : {
803 0 : bModified = sal_True;
804 0 : rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
805 : }
806 0 : else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
807 0 : rCoreSet.ClearItem( nWhich );
808 : // Handle XFILL_GRADIENT -> XFILL_SOLID
809 0 : XFillStyleItem aFillStyleItem(XFILL_SOLID, GetWhich(SID_ATTR_FILL_STYLE));
810 0 : rCoreSet.Put(aFillStyleItem);
811 : }
812 : else
813 : {
814 0 : XFillStyleItem aFillStyleItem(((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue(), GetWhich(SID_ATTR_FILL_STYLE));
815 0 : rCoreSet.Put(aFillStyleItem);
816 :
817 0 : const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)m_rXFillSet.Get(XATTR_FILLGRADIENT);
818 0 : XFillGradientItem aFillGradientItem(rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue(), GetWhich(SID_ATTR_FILL_GRADIENT));
819 0 : rCoreSet.Put(aFillGradientItem);
820 : }
821 : }
822 : else
823 : {
824 : // Bitmap-treatment:
825 :
826 0 : SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
827 0 : const sal_Bool bIsLink = m_pBtnLink->IsChecked();
828 0 : const sal_Bool bWasLink = (NULL != rOldItem.GetGraphicLink() );
829 :
830 :
831 0 : if ( !bIsLink && !bIsGraphicValid )
832 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
833 :
834 0 : if ( bGraphTransparencyChanged ||
835 : eNewPos != eOldPos
836 0 : || bIsLink != bWasLink
837 0 : || ( bWasLink && *rOldItem.GetGraphicLink()
838 0 : != aBgdGraphicPath )
839 0 : || ( !bWasLink && rOldItem.GetGraphic()->GetBitmap()
840 0 : != aBgdGraphic.GetBitmap() )
841 : )
842 : {
843 0 : bModified = sal_True;
844 :
845 0 : SvxBrushItem aTmpBrush(nWhich);
846 0 : if ( bIsLink )
847 : {
848 0 : aTmpBrush = SvxBrushItem( aBgdGraphicPath,
849 : aBgdGraphicFilter,
850 : eNewPos,
851 0 : nWhich );
852 : }
853 : else
854 0 : aTmpBrush = SvxBrushItem( aBgdGraphic,
855 : eNewPos,
856 0 : nWhich );
857 0 : lcl_SetTransparency(aTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
858 :
859 0 : rCoreSet.Put(aTmpBrush);
860 : }
861 0 : else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
862 0 : rCoreSet.ClearItem( nWhich );
863 0 : }
864 : }
865 : else // Brush <-> Bitmap changed!
866 : {
867 0 : if (bIsBrush || bIsGradient)
868 : {
869 0 : rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
870 0 : if (bIsGradient)
871 : {
872 : // Handle XFILL_BITMAP -> XFILL_GRADIENT
873 0 : XFillStyleItem aFillStyleItem(((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue(), GetWhich(SID_ATTR_FILL_STYLE));
874 0 : rCoreSet.Put(aFillStyleItem);
875 :
876 0 : const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)m_rXFillSet.Get(XATTR_FILLGRADIENT);
877 0 : XFillGradientItem aFillGradientItem(rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue(), GetWhich(SID_ATTR_FILL_GRADIENT));
878 0 : rCoreSet.Put(aFillGradientItem);
879 0 : }
880 : }
881 : else
882 : {
883 0 : SvxBrushItem* pTmpBrush = 0;
884 0 : if ( m_pBtnLink->IsChecked() )
885 : {
886 : pTmpBrush = new SvxBrushItem( aBgdGraphicPath,
887 : aBgdGraphicFilter,
888 : GetGraphicPosition_Impl(),
889 0 : nWhich );
890 : }
891 : else
892 : {
893 0 : if ( !bIsGraphicValid )
894 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
895 :
896 0 : if ( bIsGraphicValid )
897 : pTmpBrush = new SvxBrushItem( aBgdGraphic,
898 : GetGraphicPosition_Impl(),
899 0 : nWhich );
900 : }
901 0 : if(pTmpBrush)
902 : {
903 0 : lcl_SetTransparency(*pTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
904 0 : rCoreSet.Put(*pTmpBrush);
905 0 : delete pTmpBrush;
906 : }
907 : }
908 0 : bModified = ( bIsBrush || bIsGradient || m_pBtnLink->IsChecked() || bIsGraphicValid );
909 : }
910 : }
911 0 : else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
912 : {
913 0 : rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
914 0 : bModified = sal_True;
915 : }
916 :
917 0 : if( m_pTblLBox->IsVisible() )
918 : {
919 : // the current condition has already been put
920 0 : if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
921 : {
922 : const SfxPoolItem* pOldCell =
923 0 : GetOldItem( rCoreSet, SID_ATTR_BRUSH );
924 :
925 0 : if ( *pTableBck_Impl->pCellBrush != *pOldCell )
926 : {
927 0 : rCoreSet.Put( *pTableBck_Impl->pCellBrush );
928 0 : bModified |= sal_True;
929 : }
930 : }
931 :
932 0 : if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
933 : {
934 : const SfxPoolItem* pOldRow =
935 0 : GetOldItem( rCoreSet, SID_ATTR_BRUSH_ROW );
936 :
937 0 : if ( *pTableBck_Impl->pRowBrush != *pOldRow )
938 : {
939 0 : rCoreSet.Put( *pTableBck_Impl->pRowBrush );
940 0 : bModified |= sal_True;
941 : }
942 : }
943 :
944 0 : if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
945 : {
946 : const SfxPoolItem* pOldTable =
947 0 : GetOldItem( rCoreSet, SID_ATTR_BRUSH_TABLE );
948 :
949 0 : if ( *pTableBck_Impl->pTableBrush != *pOldTable )
950 : {
951 0 : rCoreSet.Put( *pTableBck_Impl->pTableBrush );
952 0 : bModified |= sal_True;
953 : }
954 : }
955 :
956 0 : if( m_pTblLBox->GetSavedValue() != m_pTblLBox->GetSelectEntryPos() )
957 : {
958 : rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
959 0 : m_pTblLBox->GetSelectEntryPos() ) );
960 0 : bModified |= sal_True;
961 : }
962 : }
963 0 : else if (m_pParaLBox->GetData() == m_pParaLBox)
964 : {
965 : // the current condition has already been put
966 0 : if( nSlot != SID_ATTR_BRUSH && m_pParaLBox->IsVisible()) // not in search format dialog
967 : {
968 : const SfxPoolItem* pOldPara =
969 0 : GetOldItem( rCoreSet, SID_ATTR_BRUSH );
970 :
971 0 : if ( *pParaBck_Impl->pParaBrush != *pOldPara )
972 : {
973 0 : rCoreSet.Put( *pParaBck_Impl->pParaBrush );
974 0 : bModified |= sal_True;
975 : }
976 : }
977 :
978 0 : if( nSlot != SID_ATTR_BRUSH_CHAR )
979 : {
980 : const SfxPoolItem* pOldChar =
981 0 : GetOldItem( rCoreSet, SID_ATTR_BRUSH_CHAR );
982 : DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
983 0 : if ( pOldChar &&
984 : //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
985 0 : pParaBck_Impl &&
986 0 : (*pParaBck_Impl->pCharBrush != *pOldChar ||
987 0 : *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
988 : {
989 0 : rCoreSet.Put( *pParaBck_Impl->pCharBrush );
990 0 : bModified |= sal_True;
991 : }
992 : }
993 :
994 0 : if( m_pParaLBox->GetSavedValue() != m_pParaLBox->GetSelectEntryPos() )
995 : {
996 : rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
997 0 : m_pParaLBox->GetSelectEntryPos() ) );
998 0 : bModified |= sal_True;
999 : }
1000 : }
1001 0 : return bModified;
1002 : }
1003 :
1004 0 : sal_Bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, sal_uInt16 nSlot)
1005 : {
1006 0 : sal_uInt16 nWhich = GetWhich( nSlot );
1007 0 : const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
1008 0 : const SfxItemSet& rOldSet = GetItemSet();
1009 : DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
1010 :
1011 0 : SvxBrushItem rOldItem( (const CntWallpaperItem&)*pOld, nWhich );
1012 0 : SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
1013 0 : const sal_Bool bIsBrush = ( XFILL_SOLID == lcl_getFillStyle(m_pLbSelect) );
1014 0 : sal_Bool bModified = sal_False;
1015 :
1016 0 : if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
1017 0 : || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
1018 : {
1019 : // background art hasn't been changed
1020 :
1021 0 : if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
1022 : {
1023 : // Brush-treatment:
1024 0 : if ( rOldItem.GetColor() != aBgdColor )
1025 : {
1026 0 : bModified = sal_True;
1027 0 : CntWallpaperItem aItem( nWhich );
1028 0 : aItem.SetColor( aBgdColor );
1029 0 : rCoreSet.Put( aItem );
1030 : }
1031 0 : else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
1032 0 : rCoreSet.ClearItem( nWhich );
1033 : }
1034 : else
1035 : {
1036 : // Bitmap-treatment:
1037 0 : SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1038 :
1039 0 : int bBitmapChanged = ( ( eNewPos != eOldPos ) ||
1040 0 : ( *rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
1041 0 : int bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
1042 0 : if( bBitmapChanged || bBrushChanged )
1043 : {
1044 0 : bModified = sal_True;
1045 :
1046 0 : CntWallpaperItem aItem( nWhich );
1047 0 : WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
1048 0 : aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1049 0 : aItem.SetColor( aBgdColor );
1050 0 : aItem.SetBitmapURL( aBgdGraphicPath );
1051 0 : rCoreSet.Put( aItem );
1052 : }
1053 0 : else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
1054 0 : rCoreSet.ClearItem( nWhich );
1055 0 : }
1056 : }
1057 : else // Brush <-> Bitmap changed!
1058 : {
1059 0 : CntWallpaperItem aItem( nWhich );
1060 0 : if ( bIsBrush )
1061 : {
1062 0 : aItem.SetColor( aBgdColor );
1063 0 : rCoreSet.Put( aItem );
1064 : }
1065 : else
1066 : {
1067 : WallpaperStyle eWallStyle =
1068 0 : SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1069 0 : aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1070 0 : aItem.SetColor( aBgdColor );
1071 0 : aItem.SetBitmapURL( aBgdGraphicPath );
1072 0 : rCoreSet.Put( aItem );
1073 : }
1074 :
1075 0 : bModified = sal_True;
1076 : }
1077 0 : return bModified;
1078 : }
1079 :
1080 : //-----------------------------------------------------------------------
1081 :
1082 0 : int SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
1083 :
1084 : /* [Description]
1085 :
1086 : virtual method; is called on deactivation
1087 : */
1088 :
1089 : {
1090 0 : if ( pPageImpl->bIsImportDlgInExecute )
1091 0 : return KEEP_PAGE;
1092 :
1093 0 : if ( _pSet )
1094 0 : FillItemSet( *_pSet );
1095 :
1096 0 : return LEAVE_PAGE;
1097 : }
1098 :
1099 : //-----------------------------------------------------------------------
1100 :
1101 0 : void SvxBackgroundTabPage::PointChanged( Window* , RECT_POINT )
1102 : {
1103 : // has to be implemented so that position control can work
1104 0 : }
1105 :
1106 : //-----------------------------------------------------------------------
1107 :
1108 0 : void SvxBackgroundTabPage::ShowSelector()
1109 : {
1110 0 : if( bAllowShowSelector)
1111 : {
1112 0 : m_pAsGrid->Show();
1113 0 : m_pSelectTxt->Show();
1114 0 : m_pLbSelect->Show();
1115 0 : m_pLbSelect->SetSelectHdl( HDL(SelectHdl_Impl) );
1116 0 : m_pBtnLink->SetClickHdl( HDL(FileClickHdl_Impl) );
1117 0 : m_pBtnPreview->SetClickHdl( HDL(FileClickHdl_Impl) );
1118 0 : m_pBtnBrowse->SetClickHdl( HDL(BrowseHdl_Impl) );
1119 0 : m_pBtnArea->SetClickHdl( HDL(RadioClickHdl_Impl) );
1120 0 : m_pBtnTile->SetClickHdl( HDL(RadioClickHdl_Impl) );
1121 0 : m_pBtnPosition->SetClickHdl( HDL(RadioClickHdl_Impl) );
1122 0 : m_pLbGradients->SetSelectHdl(HDL(ModifyGradientHdl_Impl));
1123 :
1124 : // delayed loading via timer (because of UI-Update)
1125 0 : pPageImpl->pLoadTimer = new Timer;
1126 0 : pPageImpl->pLoadTimer->SetTimeout( 500 );
1127 : pPageImpl->pLoadTimer->SetTimeoutHdl(
1128 0 : LINK( this, SvxBackgroundTabPage, LoadTimerHdl_Impl ) );
1129 :
1130 0 : bAllowShowSelector = sal_False;
1131 :
1132 0 : if(nHtmlMode & HTMLMODE_ON)
1133 : {
1134 0 : m_pBtnArea->Enable(sal_False);
1135 : }
1136 : }
1137 0 : }
1138 :
1139 : //------------------------------------------------------------------------
1140 :
1141 :
1142 0 : void SvxBackgroundTabPage::RaiseLoadError_Impl()
1143 : {
1144 : SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
1145 : String(),
1146 : this,
1147 : RID_SVXERRCTX,
1148 0 : &CUI_MGR() );
1149 :
1150 : ErrorHandler::HandleError(
1151 : *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
1152 0 : aBgdGraphicPath ) );
1153 0 : }
1154 :
1155 : //------------------------------------------------------------------------
1156 :
1157 0 : sal_Bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1158 : {
1159 0 : sal_Bool bResult = ( aBgdGraphicPath.Len() > 0 ) &&
1160 : ( GRFILTER_OK == GraphicFilter::LoadGraphic( aBgdGraphicPath,
1161 : aBgdGraphicFilter,
1162 0 : aBgdGraphic ) );
1163 0 : return bResult;
1164 : }
1165 :
1166 : //------------------------------------------------------------------------
1167 :
1168 :
1169 0 : void SvxBackgroundTabPage::FillColorValueSets_Impl()
1170 : {
1171 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
1172 0 : const SfxPoolItem* pItem = NULL;
1173 0 : XColorListRef pColorTable = NULL;
1174 0 : if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1175 : {
1176 0 : pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
1177 : }
1178 :
1179 0 : if ( !pColorTable.is() )
1180 0 : pColorTable = XColorList::CreateStdColorList();
1181 :
1182 0 : if ( pColorTable.is() )
1183 : {
1184 0 : m_pBackgroundColorSet->Clear();
1185 0 : m_pBackgroundColorSet->addEntriesForXColorList(*pColorTable);
1186 : }
1187 :
1188 0 : const WinBits nBits(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
1189 0 : m_pBackgroundColorSet->SetStyle(nBits);
1190 0 : m_pBackgroundColorSet->SetColCount(m_pBackgroundColorSet->getColumnCount());
1191 0 : }
1192 :
1193 : //------------------------------------------------------------------------
1194 :
1195 :
1196 :
1197 : //------------------------------------------------------------------------
1198 :
1199 0 : void SvxBackgroundTabPage::ShowColorUI_Impl()
1200 :
1201 : /* [Description]
1202 :
1203 : Hide the controls for editing the bitmap
1204 : and show the controls for color settings instead.
1205 : */
1206 :
1207 : {
1208 0 : if (!m_pBackGroundColorFrame->IsVisible())
1209 : {
1210 0 : HideBitmapUI_Impl();
1211 0 : HideGradientUI_Impl();
1212 0 : m_pBackGroundColorFrame->Show();
1213 :
1214 0 : if(bColTransparency)
1215 : {
1216 0 : m_pColTransFT->Show();
1217 0 : m_pColTransMF->Show();
1218 : }
1219 : }
1220 0 : }
1221 :
1222 0 : void SvxBackgroundTabPage::HideColorUI_Impl()
1223 : {
1224 0 : m_pBackGroundColorFrame->Hide();
1225 0 : }
1226 :
1227 : //------------------------------------------------------------------------
1228 :
1229 0 : void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1230 :
1231 : /* [Description]
1232 :
1233 : Hide the controls for color settings
1234 : and show controls for editing the bitmap instead.
1235 : */
1236 :
1237 : {
1238 0 : if (m_pLbSelect->IsVisible() &&
1239 0 : (m_pBackGroundColorFrame->IsVisible() || !m_pFileFrame->IsVisible()))
1240 : {
1241 0 : HideColorUI_Impl();
1242 0 : HideGradientUI_Impl();
1243 :
1244 :
1245 0 : m_pBitmapContainer->Show();
1246 :
1247 0 : m_pFileFrame->Show();
1248 0 : m_pBtnLink->Show(!bLinkOnly && ! nHtmlMode & HTMLMODE_ON);
1249 :
1250 0 : m_pTypeFrame->Show();
1251 :
1252 0 : m_pPreviewWin2->Show();
1253 0 : m_pBtnPreview->Show();
1254 :
1255 0 : m_pGraphTransFrame->Show(bGraphTransparency);
1256 0 : m_pColTransFT->Show(sal_False);
1257 0 : m_pColTransMF->Show(sal_False);
1258 : }
1259 0 : }
1260 :
1261 0 : void SvxBackgroundTabPage::HideBitmapUI_Impl()
1262 : {
1263 0 : m_pBitmapContainer->Hide();
1264 0 : m_pFileFrame->Hide();
1265 0 : m_pTypeFrame->Hide();
1266 0 : m_pPreviewWin2->Hide();
1267 0 : m_pBtnPreview->Hide();
1268 0 : m_pGraphTransFrame->Hide();
1269 0 : }
1270 :
1271 0 : void SvxBackgroundTabPage::ShowGradientUI_Impl()
1272 : {
1273 0 : if (!m_pBackGroundGradientFrame->IsVisible())
1274 : {
1275 0 : HideColorUI_Impl();
1276 0 : HideBitmapUI_Impl();
1277 :
1278 0 : m_pBackGroundGradientFrame->Show();
1279 0 : if (!m_rXFillSet.HasItem(XATTR_FILLSTYLE) || ((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue() != XFILL_GRADIENT)
1280 : {
1281 : // Frame has no gradient? Then select the first one, just to be able to show something in the preview control.
1282 0 : m_pLbGradients->SelectEntryPos(0);
1283 0 : ModifyGradientHdl_Impl(this);
1284 : }
1285 : else
1286 : {
1287 : // It has one, try to select the matching entry in the gradient list box.
1288 0 : const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)m_rXFillSet.Get(XATTR_FILLGRADIENT);
1289 0 : m_pLbGradients->SelectEntryByList(m_pGradientList, rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue());
1290 : }
1291 : }
1292 0 : }
1293 :
1294 0 : void SvxBackgroundTabPage::HideGradientUI_Impl()
1295 : {
1296 0 : m_pBackGroundGradientFrame->Hide();
1297 0 : }
1298 :
1299 : //------------------------------------------------------------------------
1300 :
1301 0 : void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1302 : {
1303 0 : switch ( ePos )
1304 : {
1305 : case GPOS_AREA:
1306 : {
1307 0 : m_pBtnArea->Check();
1308 0 : m_pWndPosition->Disable();
1309 : }
1310 0 : break;
1311 :
1312 : case GPOS_TILED:
1313 : {
1314 0 : m_pBtnTile->Check();
1315 0 : m_pWndPosition->Disable();
1316 : }
1317 0 : break;
1318 :
1319 : default:
1320 : {
1321 0 : m_pBtnPosition->Check();
1322 0 : m_pWndPosition->Enable();
1323 0 : RECT_POINT eNewPos = RP_MM;
1324 :
1325 0 : switch ( ePos )
1326 : {
1327 0 : case GPOS_MM: break;
1328 0 : case GPOS_LT: eNewPos = RP_LT; break;
1329 0 : case GPOS_MT: eNewPos = RP_MT; break;
1330 0 : case GPOS_RT: eNewPos = RP_RT; break;
1331 0 : case GPOS_LM: eNewPos = RP_LM; break;
1332 0 : case GPOS_RM: eNewPos = RP_RM; break;
1333 0 : case GPOS_LB: eNewPos = RP_LB; break;
1334 0 : case GPOS_MB: eNewPos = RP_MB; break;
1335 0 : case GPOS_RB: eNewPos = RP_RB; break;
1336 : default: ;//prevent warning
1337 : }
1338 0 : m_pWndPosition->SetActualRP( eNewPos );
1339 : }
1340 0 : break;
1341 : }
1342 0 : m_pWndPosition->Invalidate();
1343 0 : }
1344 :
1345 : //------------------------------------------------------------------------
1346 :
1347 0 : SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1348 : {
1349 0 : if ( m_pBtnTile->IsChecked() )
1350 0 : return GPOS_TILED;
1351 0 : else if ( m_pBtnArea->IsChecked() )
1352 0 : return GPOS_AREA;
1353 : else
1354 : {
1355 0 : switch ( m_pWndPosition->GetActualRP() )
1356 : {
1357 0 : case RP_LT: return GPOS_LT;
1358 0 : case RP_MT: return GPOS_MT;
1359 0 : case RP_RT: return GPOS_RT;
1360 0 : case RP_LM: return GPOS_LM;
1361 0 : case RP_MM: return GPOS_MM;
1362 0 : case RP_RM: return GPOS_RM;
1363 0 : case RP_LB: return GPOS_LB;
1364 0 : case RP_MB: return GPOS_MB;
1365 0 : case RP_RB: return GPOS_RB;
1366 : }
1367 : }
1368 0 : return GPOS_MM;
1369 : }
1370 :
1371 : //-----------------------------------------------------------------------
1372 : // Handler
1373 : //-----------------------------------------------------------------------
1374 :
1375 0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, BackgroundColorHdl_Impl)
1376 : /*
1377 : Handler, called when color selection is changed
1378 : */
1379 : {
1380 0 : sal_uInt16 nItemId = m_pBackgroundColorSet->GetSelectItemId();
1381 0 : Color aColor = nItemId ? ( m_pBackgroundColorSet->GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1382 0 : aBgdColor = aColor;
1383 0 : m_pPreviewWin1->NotifyChange( aBgdColor );
1384 0 : sal_Bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1385 0 : m_pColTransFT->Enable(bEnableTransp);
1386 0 : m_pColTransMF->Enable(bEnableTransp);
1387 0 : return 0;
1388 : }
1389 :
1390 : //------------------------------------------------------------------------
1391 :
1392 0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, SelectHdl_Impl)
1393 : {
1394 0 : if ( XFILL_SOLID == lcl_getFillStyle(m_pLbSelect) )
1395 : {
1396 0 : ShowColorUI_Impl();
1397 0 : m_pParaLBox->Enable(); // drawing background can't be a bitmap
1398 : }
1399 0 : else if ( XFILL_BITMAP == lcl_getFillStyle(m_pLbSelect) )
1400 : {
1401 0 : ShowBitmapUI_Impl();
1402 0 : m_pParaLBox->Enable(sal_False); // drawing background can't be a bitmap
1403 : }
1404 : else
1405 : {
1406 0 : ShowGradientUI_Impl();
1407 : }
1408 0 : return 0;
1409 : }
1410 :
1411 : //------------------------------------------------------------------------
1412 :
1413 0 : IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1414 : {
1415 0 : if (m_pBtnLink == pBox)
1416 : {
1417 0 : if ( m_pBtnLink->IsChecked() )
1418 : {
1419 0 : m_pFtUnlinked->Hide();
1420 0 : INetURLObject aObj( aBgdGraphicPath );
1421 0 : String aFilePath;
1422 0 : if ( aObj.GetProtocol() == INET_PROT_FILE )
1423 0 : aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1424 : else
1425 0 : aFilePath = aBgdGraphicPath;
1426 0 : m_pFtFile->SetText( aFilePath );
1427 0 : m_pFtFile->Show();
1428 : }
1429 : else
1430 : {
1431 0 : m_pFtUnlinked->Show();
1432 0 : m_pFtFile->Hide();
1433 : }
1434 : }
1435 0 : else if (m_pBtnPreview == pBox)
1436 : {
1437 0 : if ( m_pBtnPreview->IsChecked() )
1438 : {
1439 0 : if ( !bIsGraphicValid )
1440 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
1441 :
1442 0 : if ( bIsGraphicValid )
1443 : {
1444 0 : Bitmap aBmp = aBgdGraphic.GetBitmap();
1445 0 : m_pPreviewWin2->NotifyChange( &aBmp );
1446 : }
1447 : else
1448 : {
1449 0 : if ( aBgdGraphicPath.Len() > 0 ) // only for linked bitmap
1450 0 : RaiseLoadError_Impl();
1451 0 : m_pPreviewWin2->NotifyChange( NULL );
1452 : }
1453 : }
1454 : else
1455 0 : m_pPreviewWin2->NotifyChange( NULL );
1456 : }
1457 0 : return 0;
1458 : }
1459 :
1460 : //------------------------------------------------------------------------
1461 :
1462 0 : IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1463 : {
1464 0 : if (pBtn == m_pBtnPosition)
1465 : {
1466 0 : if ( !m_pWndPosition->IsEnabled() )
1467 : {
1468 0 : m_pWndPosition->Enable();
1469 0 : m_pWndPosition->Invalidate();
1470 : }
1471 : }
1472 0 : else if ( m_pWndPosition->IsEnabled() )
1473 : {
1474 0 : m_pWndPosition->Disable();
1475 0 : m_pWndPosition->Invalidate();
1476 : }
1477 0 : return 0;
1478 : }
1479 :
1480 0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, ModifyGradientHdl_Impl)
1481 : {
1482 0 : sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
1483 :
1484 0 : if (nPos != LISTBOX_ENTRY_NOTFOUND)
1485 : {
1486 0 : XGradientEntry* pEntry = m_pGradientList->GetGradient(nPos);
1487 0 : m_rXFillSet.Put( XFillStyleItem( XFILL_GRADIENT ) );
1488 0 : m_rXFillSet.Put( XFillGradientItem( pEntry->GetName(), pEntry->GetGradient() ) );
1489 : }
1490 0 : m_pCtlPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
1491 0 : m_pCtlPreview->Invalidate();
1492 0 : return 0;
1493 : }
1494 :
1495 : //------------------------------------------------------------------------
1496 :
1497 0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, BrowseHdl_Impl)
1498 :
1499 : /* [Description]
1500 :
1501 : Handler, called by pressing the browse button.
1502 : Create graphic/insert dialog, set path and start.
1503 : */
1504 :
1505 : {
1506 0 : if ( pPageImpl->pLoadTimer->IsActive() )
1507 0 : return 0;
1508 0 : sal_Bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1509 :
1510 0 : OUString aStrBrowse(get<Window>("findgraphicsft")->GetText());
1511 0 : pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1512 0 : if ( bHtml || bLinkOnly )
1513 0 : pImportDlg->EnableLink(sal_False);
1514 0 : pImportDlg->SetPath( aBgdGraphicPath, m_pBtnLink->IsChecked() );
1515 :
1516 0 : pPageImpl->bIsImportDlgInExecute = sal_True;
1517 0 : short nErr = pImportDlg->Execute();
1518 0 : pPageImpl->bIsImportDlgInExecute = sal_False;
1519 :
1520 0 : if( !nErr )
1521 : {
1522 0 : if ( bHtml )
1523 0 : m_pBtnLink->Check();
1524 : // if link isn't checked and preview isn't, either,
1525 : // activate preview, so that the user sees which
1526 : // graphic he has chosen
1527 0 : if ( !m_pBtnLink->IsChecked() && !m_pBtnPreview->IsChecked() )
1528 0 : m_pBtnPreview->Check( sal_True );
1529 : // timer-delayed loading of the graphic
1530 0 : pPageImpl->pLoadTimer->Start();
1531 : }
1532 : else
1533 0 : DELETEZ( pImportDlg );
1534 0 : return 0;
1535 : }
1536 :
1537 : //-----------------------------------------------------------------------
1538 :
1539 0 : IMPL_LINK( SvxBackgroundTabPage, LoadTimerHdl_Impl, Timer* , pTimer )
1540 :
1541 : /* [Description]
1542 :
1543 : Delayed loading of the graphic.
1544 : Graphic is only loaded, if it's
1545 : different to the current graphic.
1546 : */
1547 :
1548 : {
1549 0 : if ( pTimer == pPageImpl->pLoadTimer )
1550 : {
1551 0 : pPageImpl->pLoadTimer->Stop();
1552 :
1553 0 : if ( pImportDlg )
1554 : {
1555 0 : INetURLObject aOld( aBgdGraphicPath );
1556 0 : INetURLObject aNew( pImportDlg->GetPath() );
1557 0 : if ( !aBgdGraphicPath.Len() || aNew != aOld )
1558 : {
1559 : // new file chosen
1560 0 : aBgdGraphicPath = pImportDlg->GetPath();
1561 0 : aBgdGraphicFilter = pImportDlg->GetCurrentFilter();
1562 0 : sal_Bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly ? sal_True : pImportDlg->IsAsLink();
1563 0 : m_pBtnLink->Check( bLink );
1564 0 : m_pBtnLink->Enable();
1565 :
1566 0 : if ( m_pBtnPreview->IsChecked() )
1567 : {
1568 0 : if( !pImportDlg->GetGraphic(aBgdGraphic) )
1569 : {
1570 0 : bIsGraphicValid = sal_True;
1571 : }
1572 : else
1573 : {
1574 0 : aBgdGraphicFilter.Erase();
1575 0 : aBgdGraphicPath.Erase();
1576 0 : bIsGraphicValid = sal_False;
1577 : }
1578 : }
1579 : else
1580 0 : bIsGraphicValid = sal_False; // load graphic not until preview click
1581 :
1582 0 : if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1583 : {
1584 0 : Bitmap aBmp = aBgdGraphic.GetBitmap();
1585 0 : m_pPreviewWin2->NotifyChange( &aBmp );
1586 : }
1587 : else
1588 0 : m_pPreviewWin2->NotifyChange( NULL );
1589 : }
1590 :
1591 0 : FileClickHdl_Impl(m_pBtnLink);
1592 0 : DELETEZ( pImportDlg );
1593 : }
1594 : }
1595 0 : return 0;
1596 : }
1597 :
1598 : //-----------------------------------------------------------------------
1599 :
1600 0 : void SvxBackgroundTabPage::ShowTblControl()
1601 : {
1602 0 : m_pTblLBox->SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1603 0 : m_pTblLBox->SelectEntryPos(0);
1604 0 : m_pTblDesc->Show();
1605 0 : m_pTblLBox->Show();
1606 0 : m_pAsGrid->Show();
1607 0 : }
1608 :
1609 : //-----------------------------------------------------------------------
1610 :
1611 0 : void SvxBackgroundTabPage::ShowParaControl(sal_Bool bCharOnly)
1612 : {
1613 0 : m_pParaLBox->SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1614 0 : m_pParaLBox->SelectEntryPos(0);
1615 0 : if (!bCharOnly)
1616 : {
1617 0 : m_pTblDesc->Show();
1618 0 : m_pParaLBox->Show();
1619 0 : m_pAsGrid->Show();
1620 : }
1621 0 : m_pParaLBox->SetData(m_pParaLBox); // here it can be recognized that this mode is turned on
1622 0 : }
1623 : //-----------------------------------------------------------------------
1624 :
1625 0 : IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1626 : {
1627 0 : sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1628 0 : if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1629 : {
1630 0 : SvxBrushItem* pActItem = NULL;
1631 0 : bool bDelete = false;
1632 0 : sal_uInt16 nWhich = 0;
1633 0 : switch(pTableBck_Impl->nActPos)
1634 : {
1635 : case TBL_DEST_CELL:
1636 0 : pActItem = pTableBck_Impl->pCellBrush;
1637 0 : nWhich = pTableBck_Impl->nCellWhich;
1638 0 : break;
1639 : case TBL_DEST_ROW:
1640 0 : pActItem = pTableBck_Impl->pRowBrush;
1641 0 : nWhich = pTableBck_Impl->nRowWhich;
1642 0 : break;
1643 : case TBL_DEST_TBL:
1644 0 : pActItem = pTableBck_Impl->pTableBrush;
1645 0 : nWhich = pTableBck_Impl->nTableWhich;
1646 0 : break;
1647 : default:
1648 0 : pActItem = NULL;
1649 0 : break;
1650 : }
1651 0 : pTableBck_Impl->nActPos = nSelPos;
1652 0 : if(!pActItem)
1653 : {
1654 0 : pActItem = new SvxBrushItem(nWhich);
1655 0 : bDelete = true;
1656 : }
1657 0 : if(XFILL_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1658 : {
1659 0 : *pActItem = SvxBrushItem( aBgdColor, nWhich );
1660 : }
1661 : else
1662 : {
1663 0 : SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1664 0 : const sal_Bool bIsLink = m_pBtnLink->IsChecked();
1665 :
1666 0 : if ( !bIsLink && !bIsGraphicValid )
1667 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
1668 :
1669 0 : if ( bIsLink )
1670 0 : *pActItem = SvxBrushItem( aBgdGraphicPath,
1671 : aBgdGraphicFilter,
1672 : eNewPos,
1673 0 : pActItem->Which() );
1674 : else
1675 0 : *pActItem = SvxBrushItem( aBgdGraphic,
1676 : eNewPos,
1677 0 : pActItem->Which() );
1678 : }
1679 0 : switch(nSelPos)
1680 : {
1681 : case TBL_DEST_CELL:
1682 0 : pActItem = pTableBck_Impl->pCellBrush;
1683 0 : m_pLbSelect->Enable();
1684 0 : nWhich = pTableBck_Impl->nCellWhich;
1685 0 : break;
1686 : case TBL_DEST_ROW:
1687 0 : if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_SOME_STYLES))
1688 0 : m_pLbSelect->Disable();
1689 0 : pActItem = pTableBck_Impl->pRowBrush;
1690 0 : nWhich = pTableBck_Impl->nRowWhich;
1691 0 : break;
1692 : case TBL_DEST_TBL:
1693 0 : pActItem = pTableBck_Impl->pTableBrush;
1694 0 : m_pLbSelect->Enable();
1695 0 : nWhich = pTableBck_Impl->nTableWhich;
1696 0 : break;
1697 : default:
1698 0 : if (bDelete)
1699 : {
1700 : // The item will be new'ed again below, but that will be the
1701 : // default item then, not an existing modified one.
1702 0 : delete pActItem;
1703 0 : bDelete = false;
1704 : }
1705 0 : pActItem = NULL;
1706 0 : break;
1707 : }
1708 0 : String aUserData = GetUserData();
1709 0 : if(!pActItem)
1710 : {
1711 0 : pActItem = new SvxBrushItem(nWhich);
1712 0 : bDelete = true;
1713 : }
1714 0 : FillControls_Impl(*pActItem, aUserData);
1715 0 : if (bDelete)
1716 0 : delete pActItem;
1717 : }
1718 0 : return 0;
1719 : }
1720 :
1721 : //-----------------------------------------------------------------------
1722 :
1723 0 : IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1724 : {
1725 0 : sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1726 0 : if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1727 : {
1728 0 : SvxBrushItem* pActItem = NULL;
1729 0 : switch(pParaBck_Impl->nActPos)
1730 : {
1731 : case PARA_DEST_PARA:
1732 0 : pActItem = pParaBck_Impl->pParaBrush;
1733 0 : break;
1734 : case PARA_DEST_CHAR:
1735 0 : pActItem = pParaBck_Impl->pCharBrush;
1736 0 : break;
1737 : default:
1738 : /* we assert here because the rest of the code expect pActItem to be non NULL */
1739 : assert(false);
1740 0 : return 0;
1741 : }
1742 0 : pParaBck_Impl->nActPos = nSelPos;
1743 0 : if(XFILL_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1744 : {
1745 0 : sal_uInt16 nWhich = pActItem->Which();
1746 0 : *pActItem = SvxBrushItem( aBgdColor, nWhich );
1747 : }
1748 : else
1749 : {
1750 0 : SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1751 0 : const sal_Bool bIsLink = m_pBtnLink->IsChecked();
1752 :
1753 0 : if ( !bIsLink && !bIsGraphicValid )
1754 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
1755 :
1756 0 : if ( bIsLink )
1757 0 : *pActItem = SvxBrushItem( aBgdGraphicPath,
1758 : aBgdGraphicFilter,
1759 : eNewPos,
1760 0 : pActItem->Which() );
1761 : else
1762 0 : *pActItem = SvxBrushItem( aBgdGraphic,
1763 : eNewPos,
1764 0 : pActItem->Which() );
1765 : }
1766 0 : switch(nSelPos)
1767 : {
1768 : case PARA_DEST_PARA:
1769 0 : pActItem = pParaBck_Impl->pParaBrush;
1770 0 : m_pLbSelect->Enable();
1771 0 : break;
1772 : case PARA_DEST_CHAR:
1773 : {
1774 0 : pActItem = pParaBck_Impl->pCharBrush;
1775 0 : m_pLbSelect->Enable(sal_False);
1776 : }
1777 0 : break;
1778 : }
1779 0 : String aUserData = GetUserData();
1780 0 : FillControls_Impl(*pActItem, aUserData);
1781 : }
1782 0 : return 0;
1783 : }
1784 :
1785 : //-----------------------------------------------------------------------
1786 :
1787 0 : void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1788 : const String& rUserData )
1789 : {
1790 0 : SvxGraphicPosition ePos = rBgdAttr.GetGraphicPos();
1791 0 : const Color& rColor = rBgdAttr.GetColor();
1792 0 : if(bColTransparency)
1793 : {
1794 0 : m_pColTransMF->SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1795 0 : m_pColTransMF->SaveValue();
1796 0 : sal_Bool bEnableTransp = rColor.GetTransparency() < 0xff;
1797 0 : m_pColTransFT->Enable(bEnableTransp);
1798 0 : m_pColTransMF->Enable(bEnableTransp);
1799 : //the default setting should be "no transparency"
1800 0 : if(!bEnableTransp)
1801 0 : m_pColTransMF->SetValue(0);
1802 : }
1803 :
1804 0 : if ( GPOS_NONE == ePos || !m_pLbSelect->IsVisible() )
1805 : {
1806 : // We don't have a graphic, do we have gradient fill style?
1807 0 : if (!m_rXFillSet.HasItem(XATTR_FILLSTYLE) || ((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue() != XFILL_GRADIENT)
1808 : {
1809 0 : lcl_setFillStyle(m_pLbSelect, XFILL_SOLID);
1810 0 : ShowColorUI_Impl();
1811 0 : Color aTrColor( COL_TRANSPARENT );
1812 0 : aBgdColor = rColor;
1813 :
1814 0 : sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
1815 0 : GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor) : 0;
1816 :
1817 0 : if( aTrColor != aBgdColor && nCol == 0)
1818 : {
1819 0 : m_pBackgroundColorSet->SetNoSelection();
1820 : }
1821 : else
1822 : {
1823 0 : m_pBackgroundColorSet->SelectItem( nCol );
1824 : }
1825 :
1826 0 : m_pPreviewWin1->NotifyChange( aBgdColor );
1827 : }
1828 : else
1829 : {
1830 : // Gradient fill style, then initialize preview with data from Writer.
1831 0 : lcl_setFillStyle(m_pLbSelect, XFILL_GRADIENT);
1832 0 : ShowGradientUI_Impl();
1833 0 : m_pCtlPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
1834 0 : m_pCtlPreview->Invalidate();
1835 : }
1836 0 : if ( m_pLbSelect->IsVisible() ) // initialize graphic part
1837 : {
1838 0 : aBgdGraphicFilter.Erase();
1839 0 : aBgdGraphicPath.Erase();
1840 :
1841 0 : if ( !rUserData.Len() )
1842 0 : m_pBtnPreview->Check( sal_False );
1843 0 : m_pBtnLink->Check( sal_False );
1844 0 : m_pBtnLink->Disable();
1845 0 : m_pPreviewWin2->NotifyChange( NULL );
1846 0 : SetGraphicPosition_Impl( GPOS_TILED ); // tiles as default
1847 : }
1848 : }
1849 : else
1850 : {
1851 0 : const String* pStrLink = rBgdAttr.GetGraphicLink();
1852 0 : const String* pStrFilter = rBgdAttr.GetGraphicFilter();
1853 :
1854 0 : lcl_setFillStyle(m_pLbSelect, XFILL_BITMAP);
1855 0 : ShowBitmapUI_Impl();
1856 :
1857 0 : if ( pStrLink )
1858 : {
1859 : #ifdef DBG_UTIL
1860 : INetURLObject aObj( *pStrLink );
1861 : DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1862 : #endif
1863 0 : aBgdGraphicPath = *pStrLink;
1864 0 : m_pBtnLink->Check( sal_True );
1865 0 : m_pBtnLink->Enable();
1866 : }
1867 : else
1868 : {
1869 0 : aBgdGraphicPath.Erase();
1870 0 : m_pBtnLink->Check( sal_False );
1871 0 : m_pBtnLink->Disable();
1872 : }
1873 :
1874 0 : if(bGraphTransparency)
1875 : {
1876 0 : const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
1877 0 : if(pObject)
1878 0 : m_pGraphTransMF->SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1879 : else
1880 0 : m_pGraphTransMF->SetValue(0);
1881 0 : m_pGraphTransMF->SaveValue();
1882 : }
1883 :
1884 0 : FileClickHdl_Impl(m_pBtnLink);
1885 :
1886 0 : if ( pStrFilter )
1887 0 : aBgdGraphicFilter = *pStrFilter;
1888 : else
1889 0 : aBgdGraphicFilter.Erase();
1890 :
1891 0 : if ( !pStrLink || m_pBtnPreview->IsChecked() )
1892 : {
1893 : // Graphic exists in the item and doesn't have
1894 : // to be loaded:
1895 :
1896 0 : const Graphic* pGraphic = rBgdAttr.GetGraphic();
1897 :
1898 0 : if ( !pGraphic && m_pBtnPreview->IsChecked() )
1899 0 : bIsGraphicValid = LoadLinkedGraphic_Impl();
1900 0 : else if ( pGraphic )
1901 : {
1902 0 : aBgdGraphic = *pGraphic;
1903 0 : bIsGraphicValid = sal_True;
1904 :
1905 0 : if ( !rUserData.Len() )
1906 0 : m_pBtnPreview->Check();
1907 : }
1908 : else
1909 : {
1910 0 : RaiseLoadError_Impl();
1911 0 : bIsGraphicValid = sal_False;
1912 :
1913 0 : if ( !rUserData.Len() )
1914 0 : m_pBtnPreview->Check( sal_False );
1915 : }
1916 : }
1917 :
1918 0 : if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1919 : {
1920 0 : Bitmap aBmp = aBgdGraphic.GetBitmap();
1921 0 : m_pPreviewWin2->NotifyChange( &aBmp );
1922 : }
1923 : else
1924 0 : m_pPreviewWin2->NotifyChange( NULL );
1925 :
1926 0 : SetGraphicPosition_Impl( ePos );
1927 : }
1928 0 : }
1929 :
1930 0 : void SvxBackgroundTabPage::EnableTransparency(sal_Bool bColor, sal_Bool bGraphic)
1931 : {
1932 0 : bColTransparency = bColor;
1933 0 : bGraphTransparency = bGraphic;
1934 0 : m_pColTransFT->Show(bColor);
1935 0 : m_pColTransMF->Show(bColor);
1936 0 : }
1937 :
1938 0 : void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet)
1939 : {
1940 0 : SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
1941 0 : SFX_ITEMSET_ARG (&aSet,pGradientListItem,SvxGradientListItem,SID_GRADIENT_LIST,sal_False);
1942 :
1943 0 : if (pFlagItem)
1944 : {
1945 0 : sal_uInt32 nFlags=pFlagItem->GetValue();
1946 0 : if ( ( nFlags & SVX_SHOW_TBLCTL ) == SVX_SHOW_TBLCTL )
1947 0 : ShowTblControl();
1948 0 : if ( ( nFlags & SVX_SHOW_PARACTL ) == SVX_SHOW_PARACTL )
1949 0 : ShowParaControl();
1950 0 : if ( ( nFlags & SVX_SHOW_SELECTOR ) == SVX_SHOW_SELECTOR )
1951 0 : ShowSelector();
1952 0 : if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
1953 0 : EnableTransparency(sal_True, sal_True);
1954 : }
1955 :
1956 0 : if (pGradientListItem)
1957 : {
1958 : // If we get a gradient list, also read fill and gradient style.
1959 0 : m_pGradientList = pGradientListItem->GetGradientList();
1960 0 : m_pLbGradients->Fill(m_pGradientList);
1961 0 : const XFillStyleItem& rFillStyleItem = (const XFillStyleItem&)aSet.Get(SID_ATTR_FILL_STYLE);
1962 0 : m_rXFillSet.Put(XFillStyleItem(rFillStyleItem.GetValue()));
1963 0 : const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)aSet.Get(SID_ATTR_FILL_GRADIENT);
1964 0 : m_rXFillSet.Put(XFillGradientItem(rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue()));
1965 : }
1966 : else
1967 : // Otherwise hide the gradient UI.
1968 0 : for (int i = 0; i < m_pLbSelect->GetEntryCount(); ++i)
1969 0 : if ((XFillStyle)(sal_uLong)m_pLbSelect->GetEntryData(i) == XFILL_GRADIENT)
1970 : {
1971 0 : m_pLbSelect->RemoveEntry(i);
1972 0 : break;
1973 : }
1974 0 : }
1975 :
1976 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|