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 : #include <sfx2/sidebar/Theme.hxx>
20 : #include "Paint.hxx"
21 : #include "SidebarResource.hxx"
22 : #include <sfx2/sidebar/Tools.hxx>
23 : #include <sfx2/app.hxx>
24 :
25 : #include <tools/svborder.hxx>
26 : #include <tools/rc.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <vcl/settings.hxx>
29 :
30 : using namespace css;
31 : using namespace cssu;
32 :
33 :
34 : namespace sfx2 { namespace sidebar {
35 :
36 :
37 2448 : Theme& Theme::GetCurrentTheme()
38 : {
39 2448 : return SFX_APP()->GetSidebarTheme();
40 : }
41 :
42 5 : Theme::Theme()
43 : : ThemeInterfaceBase(m_aMutex),
44 : maImages(),
45 : maColors(),
46 : maPaints(),
47 : maIntegers(),
48 : maBooleans(),
49 5 : mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
50 : mbIsHighContrastModeSetManually(false),
51 : maPropertyNameToIdMap(),
52 : maPropertyIdToNameMap(),
53 : maRawValues(),
54 : maChangeListeners(),
55 10 : maVetoableListeners()
56 :
57 : {
58 5 : SetupPropertyMaps();
59 5 : }
60 :
61 :
62 :
63 :
64 10 : Theme::~Theme (void)
65 : {
66 10 : }
67 :
68 :
69 :
70 :
71 124 : Image Theme::GetImage (const ThemeItem eItem)
72 : {
73 124 : const PropertyType eType (GetPropertyType(eItem));
74 : OSL_ASSERT(eType==PT_Image);
75 124 : const sal_Int32 nIndex (GetIndex(eItem, eType));
76 124 : const Theme& rTheme (GetCurrentTheme());
77 124 : return rTheme.maImages[nIndex];
78 : }
79 :
80 :
81 :
82 :
83 84 : Color Theme::GetColor (const ThemeItem eItem)
84 : {
85 84 : const PropertyType eType (GetPropertyType(eItem));
86 : OSL_ASSERT(eType==PT_Color || eType==PT_Paint);
87 84 : const sal_Int32 nIndex (GetIndex(eItem, eType));
88 84 : const Theme& rTheme (GetCurrentTheme());
89 84 : if (eType == PT_Color)
90 73 : return rTheme.maColors[nIndex];
91 11 : else if (eType == PT_Paint)
92 11 : return rTheme.maPaints[nIndex].GetColor();
93 : else
94 0 : return COL_WHITE;
95 : }
96 :
97 :
98 :
99 :
100 382 : const Paint& Theme::GetPaint (const ThemeItem eItem)
101 : {
102 382 : const PropertyType eType (GetPropertyType(eItem));
103 : OSL_ASSERT(eType==PT_Paint);
104 382 : const sal_Int32 nIndex (GetIndex(eItem, eType));
105 382 : const Theme& rTheme (GetCurrentTheme());
106 382 : return rTheme.maPaints[nIndex];
107 : }
108 :
109 :
110 :
111 :
112 22 : const Wallpaper Theme::GetWallpaper (const ThemeItem eItem)
113 : {
114 22 : return GetPaint(eItem).GetWallpaper();
115 : }
116 :
117 :
118 :
119 :
120 1679 : sal_Int32 Theme::GetInteger (const ThemeItem eItem)
121 : {
122 1679 : const PropertyType eType (GetPropertyType(eItem));
123 : OSL_ASSERT(eType==PT_Integer);
124 1679 : const sal_Int32 nIndex (GetIndex(eItem, eType));
125 1679 : const Theme& rTheme (GetCurrentTheme());
126 1679 : return rTheme.maIntegers[nIndex];
127 : }
128 :
129 :
130 :
131 :
132 26 : bool Theme::GetBoolean (const ThemeItem eItem)
133 : {
134 26 : const PropertyType eType (GetPropertyType(eItem));
135 : OSL_ASSERT(eType==PT_Boolean);
136 26 : const sal_Int32 nIndex (GetIndex(eItem, eType));
137 26 : const Theme& rTheme (GetCurrentTheme());
138 26 : return rTheme.maBooleans[nIndex];
139 : }
140 :
141 :
142 :
143 :
144 88 : bool Theme::IsHighContrastMode (void)
145 : {
146 88 : const Theme& rTheme (GetCurrentTheme());
147 88 : return rTheme.mbIsHighContrastMode;
148 : }
149 :
150 :
151 :
152 :
153 5 : void Theme::HandleDataChange (void)
154 : {
155 5 : Theme& rTheme (GetCurrentTheme());
156 :
157 5 : if ( ! rTheme.mbIsHighContrastModeSetManually)
158 : {
159 : // Do not modify mbIsHighContrastMode when it was manually set.
160 5 : GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
161 5 : rTheme.maRawValues[Bool_IsHighContrastModeActive] = Any(GetCurrentTheme().mbIsHighContrastMode);
162 : }
163 :
164 5 : GetCurrentTheme().UpdateTheme();
165 5 : }
166 :
167 :
168 :
169 :
170 5 : void Theme::InitializeTheme (void)
171 : {
172 : setPropertyValue(
173 5 : maPropertyIdToNameMap[Bool_UseSymphonyIcons],
174 10 : Any(false));
175 : setPropertyValue(
176 5 : maPropertyIdToNameMap[Bool_UseSystemColors],
177 10 : Any(false));
178 5 : }
179 :
180 :
181 :
182 :
183 5 : void Theme::UpdateTheme (void)
184 : {
185 5 : SidebarResource aLocalResource;
186 :
187 : try
188 : {
189 5 : const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings());
190 5 : const bool bUseSystemColors (GetBoolean(Bool_UseSystemColors));
191 :
192 : #define Alternatives(n,hc,sys) (mbIsHighContrastMode ? hc : (bUseSystemColors ? sys : n))
193 :
194 5 : Color aBaseBackgroundColor (rStyle.GetDialogColor());
195 : // UX says this should be a little brighter, but that looks off when compared to the other windows.
196 : //aBaseBackgroundColor.IncreaseLuminance(7);
197 5 : Color aBorderColor (aBaseBackgroundColor);
198 5 : aBorderColor.DecreaseLuminance(15);
199 5 : Color aSecondColor (aBaseBackgroundColor);
200 5 : aSecondColor.DecreaseLuminance(15);
201 :
202 : setPropertyValue(
203 5 : maPropertyIdToNameMap[Paint_DeckBackground],
204 10 : Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
205 :
206 : setPropertyValue(
207 5 : maPropertyIdToNameMap[Paint_DeckTitleBarBackground],
208 10 : Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
209 : setPropertyValue(
210 5 : maPropertyIdToNameMap[Int_DeckLeftPadding],
211 10 : Any(sal_Int32(2)));
212 : setPropertyValue(
213 5 : maPropertyIdToNameMap[Int_DeckTopPadding],
214 10 : Any(sal_Int32(2)));
215 : setPropertyValue(
216 5 : maPropertyIdToNameMap[Int_DeckRightPadding],
217 10 : Any(sal_Int32(2)));
218 : setPropertyValue(
219 5 : maPropertyIdToNameMap[Int_DeckBottomPadding],
220 10 : Any(sal_Int32(2)));
221 : setPropertyValue(
222 5 : maPropertyIdToNameMap[Int_DeckBorderSize],
223 10 : Any(sal_Int32(1)));
224 : setPropertyValue(
225 5 : maPropertyIdToNameMap[Int_DeckSeparatorHeight],
226 10 : Any(sal_Int32(1)));
227 : setPropertyValue(
228 5 : maPropertyIdToNameMap[Int_ButtonCornerRadius],
229 10 : Any(sal_Int32(3)));
230 : setPropertyValue(
231 5 : maPropertyIdToNameMap[Color_DeckTitleFont],
232 10 : Any(sal_Int32(rStyle.GetFontColor().GetRGBColor())));
233 : setPropertyValue(
234 5 : maPropertyIdToNameMap[Int_DeckTitleBarHeight],
235 : Any(sal_Int32(Alternatives(
236 : 26,
237 : 26,
238 10 : rStyle.GetFloatTitleHeight()))));
239 : setPropertyValue(
240 5 : maPropertyIdToNameMap[Paint_PanelBackground],
241 10 : Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
242 :
243 : setPropertyValue(
244 5 : maPropertyIdToNameMap[Paint_PanelTitleBarBackground],
245 : Any(Tools::VclToAwtGradient(Gradient(
246 : GradientStyle_LINEAR,
247 : aSecondColor.GetRGBColor(),
248 : aBaseBackgroundColor.GetRGBColor()
249 10 : ))));
250 : setPropertyValue(
251 5 : maPropertyIdToNameMap[Color_PanelTitleFont],
252 10 : Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626)));
253 : setPropertyValue(
254 5 : maPropertyIdToNameMap[Int_PanelTitleBarHeight],
255 : Any(sal_Int32(Alternatives(
256 : 26,
257 : 26,
258 10 : rStyle.GetTitleHeight()))));
259 : setPropertyValue(
260 5 : maPropertyIdToNameMap[Paint_TabBarBackground],
261 10 : Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
262 : setPropertyValue(
263 5 : maPropertyIdToNameMap[Int_TabBarLeftPadding],
264 10 : Any(sal_Int32(2)));
265 : setPropertyValue(
266 5 : maPropertyIdToNameMap[Int_TabBarTopPadding],
267 10 : Any(sal_Int32(2)));
268 : setPropertyValue(
269 5 : maPropertyIdToNameMap[Int_TabBarRightPadding],
270 10 : Any(sal_Int32(2)));
271 : setPropertyValue(
272 5 : maPropertyIdToNameMap[Int_TabBarBottomPadding],
273 10 : Any(sal_Int32(2)));
274 :
275 : setPropertyValue(
276 5 : maPropertyIdToNameMap[Int_TabMenuPadding],
277 10 : Any(sal_Int32(6)));
278 : setPropertyValue(
279 5 : maPropertyIdToNameMap[Color_TabMenuSeparator],
280 10 : Any(sal_Int32(aBorderColor.GetRGBColor())));
281 : setPropertyValue(
282 5 : maPropertyIdToNameMap[Int_TabMenuSeparatorPadding],
283 10 : Any(sal_Int32(7)));
284 :
285 : setPropertyValue(
286 5 : maPropertyIdToNameMap[Int_TabItemWidth],
287 10 : Any(sal_Int32(32)));
288 : setPropertyValue(
289 5 : maPropertyIdToNameMap[Int_TabItemHeight],
290 10 : Any(sal_Int32(32)));
291 : setPropertyValue(
292 5 : maPropertyIdToNameMap[Color_TabItemBorder],
293 10 : Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
294 : // mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf)));
295 :
296 : setPropertyValue(
297 5 : maPropertyIdToNameMap[Paint_DropDownBackground],
298 10 : Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
299 : setPropertyValue(
300 5 : maPropertyIdToNameMap[Color_DropDownBorder],
301 10 : Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
302 :
303 : setPropertyValue(
304 5 : maPropertyIdToNameMap[Color_Highlight],
305 10 : Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
306 : setPropertyValue(
307 5 : maPropertyIdToNameMap[Color_HighlightText],
308 10 : Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
309 :
310 : setPropertyValue(
311 5 : maPropertyIdToNameMap[Paint_TabItemBackgroundNormal],
312 10 : Any());
313 : setPropertyValue(
314 5 : maPropertyIdToNameMap[Paint_TabItemBackgroundHighlight],
315 10 : Any(sal_Int32(rStyle.GetActiveTabColor().GetRGBColor())));
316 : // mbIsHighContrastMode ? 0x000000 : 0x00ffffff)));
317 :
318 : setPropertyValue(
319 5 : maPropertyIdToNameMap[Paint_HorizontalBorder],
320 10 : Any(sal_Int32(aBorderColor.GetRGBColor())));
321 : // mbIsHighContrastMode ? 0x00ff00 : 0xe4e4e4)));
322 : setPropertyValue(
323 5 : maPropertyIdToNameMap[Paint_VerticalBorder],
324 10 : Any(sal_Int32(aBorderColor.GetRGBColor())));
325 : setPropertyValue(
326 5 : maPropertyIdToNameMap[Image_Grip],
327 10 : Any(OUString("private:graphicrepository/sfx2/res/grip.png")));
328 : setPropertyValue(
329 5 : maPropertyIdToNameMap[Image_Expand],
330 10 : Any(OUString("private:graphicrepository/res/plus.png")));
331 : setPropertyValue(
332 5 : maPropertyIdToNameMap[Image_Collapse],
333 10 : Any(OUString("private:graphicrepository/res/minus.png")));
334 : setPropertyValue(
335 5 : maPropertyIdToNameMap[Image_TabBarMenu],
336 10 : Any(OUString("private:graphicrepository/sfx2/res/symphony/open_more.png")));
337 : setPropertyValue(
338 5 : maPropertyIdToNameMap[Image_PanelMenu],
339 10 : Any(OUString("private:graphicrepository/sfx2/res/symphony/morebutton.png")));
340 : setPropertyValue(
341 5 : maPropertyIdToNameMap[Image_Closer],
342 10 : Any(OUString("private:graphicrepository/sfx2/res/closedoc.png")));
343 : setPropertyValue(
344 5 : maPropertyIdToNameMap[Image_CloseIndicator],
345 10 : Any(OUString("private:graphicrepository/cmd/lc_decrementlevel.png")));
346 : setPropertyValue(
347 5 : maPropertyIdToNameMap[Image_ToolBoxItemSeparator],
348 : Any(
349 10 : OUString("private:graphicrepository/sfx2/res/separator.png")));
350 :
351 : // ToolBox
352 :
353 : /*
354 : // Separator style
355 : setPropertyValue(
356 : maPropertyIdToNameMap[Paint_ToolBoxBackground],
357 : Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
358 : setPropertyValue(
359 : maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
360 : Any());
361 : setPropertyValue(
362 : maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
363 : Any());
364 : setPropertyValue(
365 : maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
366 : Any());
367 : setPropertyValue(
368 : maPropertyIdToNameMap[Rect_ToolBoxPadding],
369 : Any(awt::Rectangle(2,2,2,2)));
370 : setPropertyValue(
371 : maPropertyIdToNameMap[Rect_ToolBoxBorder],
372 : Any(awt::Rectangle(0,0,0,0)));
373 : setPropertyValue(
374 : maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
375 : Any(true));
376 :
377 : */
378 :
379 : // Gradient style
380 5 : Color aGradientStop2 (aBaseBackgroundColor);
381 5 : aGradientStop2.IncreaseLuminance(17);
382 5 : Color aToolBoxBorderColor (aBaseBackgroundColor);
383 5 : aToolBoxBorderColor.DecreaseLuminance(12);
384 : setPropertyValue(
385 5 : maPropertyIdToNameMap[Paint_ToolBoxBackground],
386 : Any(Tools::VclToAwtGradient(Gradient(
387 : GradientStyle_LINEAR,
388 : aBaseBackgroundColor.GetRGBColor(),
389 : aGradientStop2.GetRGBColor()
390 10 : ))));
391 : setPropertyValue(
392 5 : maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
393 : mbIsHighContrastMode
394 : ? Any(util::Color(sal_uInt32(0x00ff00)))
395 10 : : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
396 : setPropertyValue(
397 5 : maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
398 : mbIsHighContrastMode
399 : ? Any(util::Color(sal_uInt32(0x00ff00)))
400 10 : : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
401 : setPropertyValue(
402 5 : maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
403 : mbIsHighContrastMode
404 : ? Any(util::Color(sal_uInt32(0x00ff00)))
405 10 : : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
406 : setPropertyValue(
407 5 : maPropertyIdToNameMap[Rect_ToolBoxPadding],
408 10 : Any(awt::Rectangle(2,2,2,2)));
409 : setPropertyValue(
410 5 : maPropertyIdToNameMap[Rect_ToolBoxBorder],
411 10 : Any(awt::Rectangle(1,1,1,1)));
412 : setPropertyValue(
413 5 : maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
414 10 : Any(false));
415 : }
416 0 : catch(beans::UnknownPropertyException& rException)
417 : {
418 : OSL_TRACE("unknown property: %s",
419 : OUStringToOString(
420 : rException.Message,
421 : RTL_TEXTENCODING_ASCII_US).getStr());
422 : OSL_ASSERT(false);
423 5 : }
424 5 : }
425 :
426 :
427 :
428 :
429 5 : void SAL_CALL Theme::disposing (void)
430 : {
431 5 : ChangeListeners aListeners;
432 5 : maChangeListeners.swap(aListeners);
433 :
434 10 : const lang::EventObject aEvent (static_cast<XWeak*>(this));
435 :
436 5 : for (ChangeListeners::const_iterator
437 5 : iContainer(maChangeListeners.begin()),
438 5 : iContainerEnd(maChangeListeners.end());
439 : iContainerEnd!=iContainerEnd;
440 : ++iContainerEnd)
441 : {
442 0 : for (ChangeListenerContainer::const_iterator
443 0 : iListener(iContainer->second.begin()),
444 0 : iEnd(iContainer->second.end());
445 : iListener!=iEnd;
446 : ++iListener)
447 : {
448 : try
449 : {
450 0 : (*iListener)->disposing(aEvent);
451 : }
452 0 : catch(const Exception&)
453 : {
454 : }
455 : }
456 5 : }
457 5 : }
458 :
459 :
460 :
461 :
462 45 : Reference<beans::XPropertySet> Theme::GetPropertySet (void)
463 : {
464 45 : return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
465 : }
466 :
467 :
468 :
469 :
470 0 : Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo (void)
471 : throw(cssu::RuntimeException, std::exception)
472 : {
473 0 : return Reference<beans::XPropertySetInfo>(this);
474 : }
475 :
476 :
477 :
478 :
479 255 : void SAL_CALL Theme::setPropertyValue (
480 : const ::rtl::OUString& rsPropertyName,
481 : const cssu::Any& rValue)
482 : throw(cssu::RuntimeException, std::exception)
483 : {
484 255 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
485 255 : if (iId == maPropertyNameToIdMap.end())
486 0 : throw beans::UnknownPropertyException(rsPropertyName, NULL);
487 :
488 255 : const PropertyType eType (GetPropertyType(iId->second));
489 255 : if (eType == PT_Invalid)
490 0 : throw beans::UnknownPropertyException(rsPropertyName, NULL);
491 :
492 255 : const ThemeItem eItem (iId->second);
493 :
494 255 : if (rValue == maRawValues[eItem])
495 : {
496 : // Value is not different from the one in the property
497 : // set => nothing to do.
498 10 : return;
499 : }
500 :
501 250 : const Any aOldValue (maRawValues[eItem]);
502 :
503 : const beans::PropertyChangeEvent aEvent(
504 : static_cast<XWeak*>(this),
505 : rsPropertyName,
506 : sal_False,
507 : eItem,
508 : aOldValue,
509 500 : rValue);
510 :
511 250 : if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent))
512 0 : return;
513 250 : if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
514 0 : return;
515 :
516 250 : maRawValues[eItem] = rValue;
517 250 : ProcessNewValue(rValue, eItem, eType);
518 :
519 250 : BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent);
520 500 : BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
521 : }
522 :
523 :
524 :
525 :
526 0 : Any SAL_CALL Theme::getPropertyValue (
527 : const ::rtl::OUString& rsPropertyName)
528 : throw(css::beans::UnknownPropertyException,
529 : css::lang::WrappedTargetException,
530 : cssu::RuntimeException, std::exception)
531 : {
532 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
533 0 : if (iId == maPropertyNameToIdMap.end())
534 0 : throw beans::UnknownPropertyException();
535 :
536 0 : const PropertyType eType (GetPropertyType(iId->second));
537 0 : if (eType == PT_Invalid)
538 0 : throw beans::UnknownPropertyException();
539 :
540 0 : const ThemeItem eItem (iId->second);
541 :
542 0 : return maRawValues[eItem];
543 : }
544 :
545 :
546 :
547 :
548 17 : void SAL_CALL Theme::addPropertyChangeListener(
549 : const ::rtl::OUString& rsPropertyName,
550 : const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
551 : throw(css::beans::UnknownPropertyException,
552 : css::lang::WrappedTargetException,
553 : cssu::RuntimeException, std::exception)
554 : {
555 17 : ThemeItem eItem (__AnyItem);
556 17 : if (rsPropertyName.getLength() > 0)
557 : {
558 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
559 0 : if (iId == maPropertyNameToIdMap.end())
560 0 : throw beans::UnknownPropertyException();
561 :
562 0 : const PropertyType eType (GetPropertyType(iId->second));
563 0 : if (eType == PT_Invalid)
564 0 : throw beans::UnknownPropertyException();
565 :
566 0 : eItem = iId->second;
567 : }
568 17 : ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
569 17 : if (pListeners != NULL)
570 17 : pListeners->push_back(rxListener);
571 17 : }
572 :
573 :
574 :
575 :
576 17 : void SAL_CALL Theme::removePropertyChangeListener(
577 : const ::rtl::OUString& rsPropertyName,
578 : const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
579 : throw(css::beans::UnknownPropertyException,
580 : css::lang::WrappedTargetException,
581 : cssu::RuntimeException, std::exception)
582 : {
583 17 : ThemeItem eItem (__AnyItem);
584 17 : if (rsPropertyName.getLength() > 0)
585 : {
586 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
587 0 : if (iId == maPropertyNameToIdMap.end())
588 0 : throw beans::UnknownPropertyException();
589 :
590 0 : const PropertyType eType (GetPropertyType(iId->second));
591 0 : if (eType == PT_Invalid)
592 0 : throw beans::UnknownPropertyException();
593 :
594 0 : eItem = iId->second;
595 : }
596 17 : ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
597 17 : if (pContainer != NULL)
598 : {
599 17 : ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
600 17 : if (iListener != pContainer->end())
601 : {
602 17 : pContainer->erase(iListener);
603 :
604 : // Remove the listener container when empty.
605 17 : if (pContainer->empty())
606 17 : maChangeListeners.erase(eItem);
607 : }
608 : }
609 17 : }
610 :
611 :
612 :
613 :
614 0 : void SAL_CALL Theme::addVetoableChangeListener(
615 : const ::rtl::OUString& rsPropertyName,
616 : const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
617 : throw(css::beans::UnknownPropertyException,
618 : css::lang::WrappedTargetException,
619 : cssu::RuntimeException, std::exception)
620 : {
621 0 : ThemeItem eItem (__AnyItem);
622 0 : if (rsPropertyName.getLength() > 0)
623 : {
624 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
625 0 : if (iId == maPropertyNameToIdMap.end())
626 0 : throw beans::UnknownPropertyException();
627 :
628 0 : const PropertyType eType (GetPropertyType(iId->second));
629 0 : if (eType == PT_Invalid)
630 0 : throw beans::UnknownPropertyException();
631 :
632 0 : eItem = iId->second;
633 : }
634 0 : VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
635 0 : if (pListeners != NULL)
636 0 : pListeners->push_back(rxListener);
637 0 : }
638 :
639 :
640 :
641 :
642 0 : void SAL_CALL Theme::removeVetoableChangeListener(
643 : const ::rtl::OUString& rsPropertyName,
644 : const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
645 : throw(css::beans::UnknownPropertyException,
646 : css::lang::WrappedTargetException,
647 : cssu::RuntimeException, std::exception)
648 : {
649 0 : ThemeItem eItem (__AnyItem);
650 0 : if (rsPropertyName.getLength() > 0)
651 : {
652 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
653 0 : if (iId == maPropertyNameToIdMap.end())
654 0 : throw beans::UnknownPropertyException();
655 :
656 0 : const PropertyType eType (GetPropertyType(iId->second));
657 0 : if (eType == PT_Invalid)
658 0 : throw beans::UnknownPropertyException();
659 :
660 0 : eItem = iId->second;
661 : }
662 0 : VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
663 0 : if (pContainer != NULL)
664 : {
665 0 : VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
666 0 : if (iListener != pContainer->end())
667 : {
668 0 : pContainer->erase(iListener);
669 : // Remove container when empty.
670 0 : if (pContainer->empty())
671 0 : maVetoableListeners.erase(eItem);
672 : }
673 : }
674 0 : }
675 :
676 :
677 :
678 :
679 0 : cssu::Sequence<css::beans::Property> SAL_CALL Theme::getProperties (void)
680 : throw(cssu::RuntimeException, std::exception)
681 : {
682 0 : ::std::vector<beans::Property> aProperties;
683 :
684 0 : for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem)
685 : {
686 0 : const ThemeItem eItem (static_cast<ThemeItem>(nItem));
687 0 : const PropertyType eType (GetPropertyType(eItem));
688 0 : if (eType == PT_Invalid)
689 0 : continue;
690 :
691 : const beans::Property aProperty(
692 0 : maPropertyIdToNameMap[eItem],
693 : eItem,
694 : GetCppuType(eType),
695 0 : 0);
696 0 : aProperties.push_back(aProperty);
697 0 : }
698 :
699 : return cssu::Sequence<css::beans::Property>(
700 0 : &aProperties.front(),
701 0 : aProperties.size());
702 : }
703 :
704 :
705 :
706 :
707 0 : beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName)
708 : throw(css::beans::UnknownPropertyException,
709 : cssu::RuntimeException, std::exception)
710 : {
711 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
712 0 : if (iId == maPropertyNameToIdMap.end())
713 0 : throw beans::UnknownPropertyException();
714 :
715 0 : const PropertyType eType (GetPropertyType(iId->second));
716 0 : if (eType == PT_Invalid)
717 0 : throw beans::UnknownPropertyException();
718 :
719 0 : const ThemeItem eItem (iId->second);
720 :
721 : return beans::Property(
722 : rsPropertyName,
723 : eItem,
724 : GetCppuType(eType),
725 0 : 0);
726 : }
727 :
728 :
729 :
730 :
731 0 : sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName)
732 : throw(cssu::RuntimeException, std::exception)
733 : {
734 0 : PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
735 0 : if (iId == maPropertyNameToIdMap.end())
736 0 : return sal_False;
737 :
738 0 : const PropertyType eType (GetPropertyType(iId->second));
739 0 : if (eType == PT_Invalid)
740 0 : return sal_False;
741 :
742 0 : return sal_True;
743 : }
744 :
745 :
746 :
747 :
748 5 : void Theme::SetupPropertyMaps (void)
749 : {
750 5 : maPropertyIdToNameMap.resize(__Post_Rect);
751 5 : maImages.resize(__Image_Color - __Pre_Image - 1);
752 5 : maColors.resize(__Color_Paint - __Image_Color - 1);
753 5 : maPaints.resize(__Paint_Int - __Color_Paint - 1);
754 5 : maIntegers.resize(__Int_Bool - __Paint_Int - 1);
755 5 : maBooleans.resize(__Bool_Rect - __Int_Bool - 1);
756 5 : maRectangles.resize(__Post_Rect - __Bool_Rect - 1);
757 :
758 : #define AddEntry(e) maPropertyNameToIdMap[OUString(#e)]=e; maPropertyIdToNameMap[e]=OUString(#e)
759 :
760 5 : AddEntry(Image_Grip);
761 5 : AddEntry(Image_Expand);
762 5 : AddEntry(Image_Collapse);
763 5 : AddEntry(Image_TabBarMenu);
764 5 : AddEntry(Image_PanelMenu);
765 5 : AddEntry(Image_ToolBoxItemSeparator);
766 5 : AddEntry(Image_Closer);
767 5 : AddEntry(Image_CloseIndicator);
768 :
769 5 : AddEntry(Color_DeckTitleFont);
770 5 : AddEntry(Color_PanelTitleFont);
771 5 : AddEntry(Color_TabMenuSeparator);
772 5 : AddEntry(Color_TabItemBorder);
773 5 : AddEntry(Color_DropDownBorder);
774 5 : AddEntry(Color_Highlight);
775 5 : AddEntry(Color_HighlightText);
776 :
777 5 : AddEntry(Paint_DeckBackground);
778 5 : AddEntry(Paint_DeckTitleBarBackground);
779 5 : AddEntry(Paint_PanelBackground);
780 5 : AddEntry(Paint_PanelTitleBarBackground);
781 5 : AddEntry(Paint_TabBarBackground);
782 5 : AddEntry(Paint_TabItemBackgroundNormal);
783 5 : AddEntry(Paint_TabItemBackgroundHighlight);
784 5 : AddEntry(Paint_HorizontalBorder);
785 5 : AddEntry(Paint_VerticalBorder);
786 5 : AddEntry(Paint_ToolBoxBackground);
787 5 : AddEntry(Paint_ToolBoxBorderTopLeft);
788 5 : AddEntry(Paint_ToolBoxBorderCenterCorners);
789 5 : AddEntry(Paint_ToolBoxBorderBottomRight);
790 5 : AddEntry(Paint_DropDownBackground);
791 :
792 5 : AddEntry(Int_DeckTitleBarHeight);
793 5 : AddEntry(Int_DeckBorderSize);
794 5 : AddEntry(Int_DeckSeparatorHeight);
795 5 : AddEntry(Int_PanelTitleBarHeight);
796 5 : AddEntry(Int_TabMenuPadding);
797 5 : AddEntry(Int_TabMenuSeparatorPadding);
798 5 : AddEntry(Int_TabItemWidth);
799 5 : AddEntry(Int_TabItemHeight);
800 5 : AddEntry(Int_DeckLeftPadding);
801 5 : AddEntry(Int_DeckTopPadding);
802 5 : AddEntry(Int_DeckRightPadding);
803 5 : AddEntry(Int_DeckBottomPadding);
804 5 : AddEntry(Int_TabBarLeftPadding);
805 5 : AddEntry(Int_TabBarTopPadding);
806 5 : AddEntry(Int_TabBarRightPadding);
807 5 : AddEntry(Int_TabBarBottomPadding);
808 5 : AddEntry(Int_ButtonCornerRadius);
809 :
810 5 : AddEntry(Bool_UseSymphonyIcons);
811 5 : AddEntry(Bool_UseSystemColors);
812 5 : AddEntry(Bool_UseToolBoxItemSeparator);
813 5 : AddEntry(Bool_IsHighContrastModeActive);
814 :
815 5 : AddEntry(Rect_ToolBoxPadding);
816 5 : AddEntry(Rect_ToolBoxBorder);
817 :
818 : #undef AddEntry
819 :
820 5 : maRawValues.resize(maPropertyIdToNameMap.size());
821 5 : }
822 :
823 :
824 :
825 :
826 2550 : Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
827 : {
828 2550 : switch(eItem)
829 : {
830 : case Image_Grip:
831 : case Image_Expand:
832 : case Image_Collapse:
833 : case Image_TabBarMenu:
834 : case Image_PanelMenu:
835 : case Image_ToolBoxItemSeparator:
836 : case Image_Closer:
837 : case Image_CloseIndicator:
838 164 : return PT_Image;
839 :
840 : case Color_DeckTitleFont:
841 : case Color_PanelTitleFont:
842 : case Color_TabMenuSeparator:
843 : case Color_TabItemBorder:
844 : case Color_DropDownBorder:
845 : case Color_Highlight:
846 : case Color_HighlightText:
847 108 : return PT_Color;
848 :
849 : case Paint_DeckBackground:
850 : case Paint_DeckTitleBarBackground:
851 : case Paint_PanelBackground:
852 : case Paint_PanelTitleBarBackground:
853 : case Paint_TabBarBackground:
854 : case Paint_TabItemBackgroundNormal:
855 : case Paint_TabItemBackgroundHighlight:
856 : case Paint_HorizontalBorder:
857 : case Paint_VerticalBorder:
858 : case Paint_ToolBoxBackground:
859 : case Paint_ToolBoxBorderTopLeft:
860 : case Paint_ToolBoxBorderCenterCorners:
861 : case Paint_ToolBoxBorderBottomRight:
862 : case Paint_DropDownBackground:
863 463 : return PT_Paint;
864 :
865 : case Int_DeckTitleBarHeight:
866 : case Int_DeckBorderSize:
867 : case Int_DeckSeparatorHeight:
868 : case Int_PanelTitleBarHeight:
869 : case Int_TabMenuPadding:
870 : case Int_TabMenuSeparatorPadding:
871 : case Int_TabItemWidth:
872 : case Int_TabItemHeight:
873 : case Int_DeckLeftPadding:
874 : case Int_DeckTopPadding:
875 : case Int_DeckRightPadding:
876 : case Int_DeckBottomPadding:
877 : case Int_TabBarLeftPadding:
878 : case Int_TabBarTopPadding:
879 : case Int_TabBarRightPadding:
880 : case Int_TabBarBottomPadding:
881 : case Int_ButtonCornerRadius:
882 1764 : return PT_Integer;
883 :
884 : case Bool_UseSymphonyIcons:
885 : case Bool_UseSystemColors:
886 : case Bool_UseToolBoxItemSeparator:
887 : case Bool_IsHighContrastModeActive:
888 41 : return PT_Boolean;
889 :
890 : case Rect_ToolBoxBorder:
891 : case Rect_ToolBoxPadding:
892 10 : return PT_Rectangle;
893 :
894 : default:
895 0 : return PT_Invalid;
896 : }
897 : }
898 :
899 :
900 :
901 :
902 0 : cssu::Type Theme::GetCppuType (const PropertyType eType)
903 : {
904 0 : switch(eType)
905 : {
906 : case PT_Image:
907 0 : return getCppuType((rtl::OUString*)NULL);
908 :
909 : case PT_Color:
910 0 : return getCppuType((sal_uInt32*)NULL);
911 :
912 : case PT_Paint:
913 0 : return getCppuVoidType();
914 :
915 : case PT_Integer:
916 0 : return getCppuType((sal_Int32*)NULL);
917 :
918 : case PT_Boolean:
919 0 : return getCppuType((sal_Bool*)NULL);
920 :
921 : case PT_Rectangle:
922 0 : return getCppuType((awt::Rectangle*)NULL);
923 :
924 : case PT_Invalid:
925 : default:
926 0 : return getCppuVoidType();
927 : }
928 : }
929 :
930 :
931 :
932 :
933 2545 : sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
934 : {
935 2545 : switch(eType)
936 : {
937 : case PT_Image:
938 164 : return eItem - __Pre_Image-1;
939 : case PT_Color:
940 108 : return eItem - __Image_Color-1;
941 : case PT_Paint:
942 458 : return eItem - __Color_Paint-1;
943 : case PT_Integer:
944 1764 : return eItem - __Paint_Int-1;
945 : case PT_Boolean:
946 41 : return eItem - __Int_Bool-1;
947 : case PT_Rectangle:
948 10 : return eItem - __Bool_Rect-1;
949 :
950 : default:
951 : OSL_ASSERT(false);
952 0 : return 0;
953 : }
954 : }
955 :
956 :
957 :
958 :
959 500 : Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
960 : const ThemeItem eItem,
961 : const bool bCreate)
962 : {
963 500 : VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
964 500 : if (iContainer != maVetoableListeners.end())
965 0 : return &iContainer->second;
966 500 : else if (bCreate)
967 : {
968 0 : maVetoableListeners[eItem] = VetoableListenerContainer();
969 0 : return &maVetoableListeners[eItem];
970 : }
971 : else
972 500 : return NULL;
973 : }
974 :
975 :
976 :
977 :
978 534 : Theme::ChangeListenerContainer* Theme::GetChangeListeners (
979 : const ThemeItem eItem,
980 : const bool bCreate)
981 : {
982 534 : ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
983 534 : if (iContainer != maChangeListeners.end())
984 17 : return &iContainer->second;
985 517 : else if (bCreate)
986 : {
987 17 : maChangeListeners[eItem] = ChangeListenerContainer();
988 17 : return &maChangeListeners[eItem];
989 : }
990 : else
991 500 : return NULL;
992 : }
993 :
994 :
995 :
996 :
997 500 : bool Theme::DoVetoableListenersVeto (
998 : const VetoableListenerContainer* pListeners,
999 : const beans::PropertyChangeEvent& rEvent) const
1000 : {
1001 500 : if (pListeners == NULL)
1002 500 : return false;
1003 :
1004 0 : VetoableListenerContainer aListeners (*pListeners);
1005 : try
1006 : {
1007 0 : for (VetoableListenerContainer::const_iterator
1008 0 : iListener(aListeners.begin()),
1009 0 : iEnd(aListeners.end());
1010 : iListener!=iEnd;
1011 : ++iListener)
1012 : {
1013 0 : (*iListener)->vetoableChange(rEvent);
1014 : }
1015 : }
1016 0 : catch(const beans::PropertyVetoException&)
1017 : {
1018 0 : return true;
1019 : }
1020 0 : catch(const Exception&)
1021 : {
1022 : // Ignore any other errors (such as disposed listeners).
1023 : }
1024 0 : return false;
1025 : }
1026 :
1027 :
1028 :
1029 :
1030 500 : void Theme::BroadcastPropertyChange (
1031 : const ChangeListenerContainer* pListeners,
1032 : const beans::PropertyChangeEvent& rEvent) const
1033 : {
1034 500 : if (pListeners == NULL)
1035 1000 : return;
1036 :
1037 0 : const ChangeListenerContainer aListeners (*pListeners);
1038 : try
1039 : {
1040 0 : for (ChangeListenerContainer::const_iterator
1041 0 : iListener(aListeners.begin()),
1042 0 : iEnd(aListeners.end());
1043 : iListener!=iEnd;
1044 : ++iListener)
1045 : {
1046 0 : (*iListener)->propertyChange(rEvent);
1047 : }
1048 : }
1049 0 : catch(const Exception&)
1050 : {
1051 : // Ignore any errors (such as disposed listeners).
1052 0 : }
1053 : }
1054 :
1055 :
1056 :
1057 :
1058 250 : void Theme::ProcessNewValue (
1059 : const Any& rValue,
1060 : const ThemeItem eItem,
1061 : const PropertyType eType)
1062 : {
1063 250 : const sal_Int32 nIndex (GetIndex (eItem, eType));
1064 250 : switch (eType)
1065 : {
1066 : case PT_Image:
1067 : {
1068 40 : ::rtl::OUString sURL;
1069 40 : if (rValue >>= sURL)
1070 : {
1071 40 : maImages[nIndex] = Tools::GetImage(sURL, NULL);
1072 : }
1073 40 : break;
1074 : }
1075 : case PT_Color:
1076 : {
1077 35 : sal_Int32 nColorValue (0);
1078 35 : if (rValue >>= nColorValue)
1079 : {
1080 35 : maColors[nIndex] = Color(nColorValue);
1081 : }
1082 35 : break;
1083 : }
1084 : case PT_Paint:
1085 : {
1086 65 : maPaints[nIndex] = Paint::Create(rValue);
1087 65 : break;
1088 : }
1089 : case PT_Integer:
1090 : {
1091 85 : sal_Int32 nValue (0);
1092 85 : if (rValue >>= nValue)
1093 : {
1094 85 : maIntegers[nIndex] = nValue;
1095 : }
1096 85 : break;
1097 : }
1098 : case PT_Boolean:
1099 : {
1100 15 : bool nValue (false);
1101 15 : if (rValue >>= nValue)
1102 : {
1103 15 : maBooleans[nIndex] = nValue;
1104 15 : if (eItem == Bool_IsHighContrastModeActive)
1105 : {
1106 0 : mbIsHighContrastModeSetManually = true;
1107 0 : mbIsHighContrastMode = maBooleans[nIndex];
1108 0 : HandleDataChange();
1109 : }
1110 15 : else if (eItem == Bool_UseSystemColors)
1111 : {
1112 5 : HandleDataChange();
1113 : }
1114 : }
1115 15 : break;
1116 : }
1117 : case PT_Rectangle:
1118 : {
1119 10 : awt::Rectangle aBox;
1120 10 : if (rValue >>= aBox)
1121 : {
1122 10 : maRectangles[nIndex] = Rectangle(
1123 : aBox.X,
1124 : aBox.Y,
1125 : aBox.Width,
1126 10 : aBox.Height);
1127 : }
1128 10 : break;
1129 : }
1130 : case PT_Invalid:
1131 : OSL_ASSERT(eType != PT_Invalid);
1132 0 : throw RuntimeException();
1133 : }
1134 250 : }
1135 :
1136 : } } // end of namespace sfx2::sidebar
1137 :
1138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|