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