1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svtools/colorcfg.hxx>
21 #include <svtools/extcolorcfg.hxx>
22 #include <svtools/headbar.hxx>
23 #include <svtools/ctrlbox.hxx>
24 #include <vcl/scrbar.hxx>
25 #include <svx/xtable.hxx>
26 #include <unotools/moduleoptions.hxx>
27 #include <unotools/pathoptions.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <boost/shared_ptr.hpp>
30 #include <svx/svxdlg.hxx>
32 #include <dialmgr.hxx>
33 #include "optcolor.hxx"
35 #include <svx/dlgutil.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::svtools
;
43 // list of default groups
69 // the groups are in the same order as in enum Group above
70 { Group_General
, "general" },
71 { Group_Writer
, "writer" },
72 { Group_Html
, "html" },
73 { Group_Calc
, "calc" },
74 { Group_Draw
, "draw" },
75 { Group_Basic
, "basic" },
79 // color config entry data (see ColorConfigWindow_Impl::Entry below)
84 //checkbox (or simple text)
96 SAL_STRINGIFY(Name), SAL_STRINGIFY(Name##_lb), SAL_STRINGIFY(Name##_wn), false
98 #define IDS_CB(Name) \
99 SAL_STRINGIFY(Name), SAL_STRINGIFY(Name##_lb), SAL_STRINGIFY(Name##_wn), true
101 // The list of these entries (enum ColorConfigEntry) are in colorcfg.hxx.
103 { Group_General
, IDS(doccolor
) },
104 { Group_General
, IDS_CB(docboundaries
) },
105 { Group_General
, IDS(appback
) },
106 { Group_General
, IDS_CB(objboundaries
) },
107 { Group_General
, IDS_CB(tblboundaries
) },
108 { Group_General
, IDS(font
) },
109 { Group_General
, IDS_CB(unvisitedlinks
) },
110 { Group_General
, IDS_CB(visitedlinks
) },
111 { Group_General
, IDS(autospellcheck
) },
112 { Group_General
, IDS(smarttags
) },
113 { Group_General
, IDS_CB(shadows
) },
115 { Group_Writer
, IDS(writergrid
) },
116 { Group_Writer
, IDS_CB(field
) },
117 { Group_Writer
, IDS_CB(index
) },
118 { Group_Writer
, IDS(direct
) },
119 { Group_Writer
, IDS(script
) },
120 { Group_Writer
, IDS_CB(section
) },
121 { Group_Writer
, IDS(hdft
) },
122 { Group_Writer
, IDS(pagebreak
) },
124 { Group_Html
, IDS(sgml
) },
125 { Group_Html
, IDS(htmlcomment
) },
126 { Group_Html
, IDS(htmlkeyword
) },
127 { Group_Html
, IDS(unknown
) },
129 { Group_Calc
, IDS(calcgrid
) },
130 { Group_Calc
, IDS(brk
) },
131 { Group_Calc
, IDS(brkmanual
) },
132 { Group_Calc
, IDS(brkauto
) },
133 { Group_Calc
, IDS(det
) },
134 { Group_Calc
, IDS(deterror
) },
135 { Group_Calc
, IDS(ref
) },
136 { Group_Calc
, IDS(notes
) },
138 { Group_Draw
, IDS(drawgrid
) },
140 { Group_Basic
, IDS(basicid
) },
141 { Group_Basic
, IDS(basiccomment
) },
142 { Group_Basic
, IDS(basicnumber
) },
143 { Group_Basic
, IDS(basicstring
) },
144 { Group_Basic
, IDS(basicop
) },
145 { Group_Basic
, IDS(basickeyword
) },
146 { Group_Basic
, IDS(error
) },
148 { Group_Sql
, IDS(sqlid
) },
149 { Group_Sql
, IDS(sqlnumber
) },
150 { Group_Sql
, IDS(sqlstring
) },
151 { Group_Sql
, IDS(sqlop
) },
152 { Group_Sql
, IDS(sqlkeyword
) },
153 { Group_Sql
, IDS(sqlparam
) },
154 { Group_Sql
, IDS(sqlcomment
) }
162 // ColorConfigWindow_Impl
165 class ColorConfigWindow_Impl
166 : public VclContainer
167 , public VclBuilderContainer
170 ColorConfigWindow_Impl(Window
* pParent
);
171 ~ColorConfigWindow_Impl();
174 void SetLinks (Link
const&, Link
const&, Link
const&);
175 unsigned GetEntryHeight () const { return vEntries
[0]->GetHeight(); }
176 void Update (EditableColorConfig
const*, EditableExtendedColorConfig
const*);
177 void ScrollHdl(const ScrollBar
&);
178 void ClickHdl (EditableColorConfig
*, CheckBox
*);
179 void ColorHdl (EditableColorConfig
*, EditableExtendedColorConfig
*, ColorListBox
*);
180 void Init(ScrollBar
*pVScroll
, HeaderBar
*m_pHeaderHB
);
181 void AdjustScrollBar();
182 void AdjustHeaderBar();
185 // Chapter -- horizontal group separator stripe with text
192 Chapter(FixedText
*pText
, bool bShow
);
193 Chapter(Window
*pGrid
, unsigned nYPos
, const OUString
& sDisplayName
);
196 void SetBackground(const Wallpaper
& W
) { m_pText
->SetBackground(W
); }
197 long GetHeight() const { return m_pText
->GetSizePixel().Height(); }
198 long GetLeft() const { return m_pText
->GetPosPixel().X(); }
199 void Show(const Wallpaper
& rBackWall
);
203 // Entry -- a color config entry:
204 // text (checkbox) + color list box + preview box
208 Entry(ColorConfigWindow_Impl
& rParent
, unsigned iEntry
, long nCheckBoxLabelOffset
, bool bShow
);
209 Entry(Window
* pGrid
, unsigned nYPos
, const ExtendedColorConfigValue
& aColorEntry
,
210 long nCheckBoxLabelOffset
);
215 void SetAppearance(Wallpaper
const& aTextWall
, ColorListBox
const& aSampleList
);
216 void SetTextColor (Color C
) { m_pText
->SetTextColor(C
); }
218 void SetLinks (Link
const&, Link
const&, Link
const&);
219 void Update (ColorConfigEntry
, ColorConfigValue
const&);
220 void Update (ExtendedColorConfigValue
const&);
221 void ColorChanged (ColorConfigEntry
, ColorConfigValue
&);
222 void ColorChanged (ExtendedColorConfigValue
&);
224 long GetTop () const { return m_pPreview
->GetPosPixel().Y(); }
225 long GetBottom () const { return GetTop() + m_pPreview
->GetSizePixel().Height(); }
226 unsigned GetHeight () const { return m_pColorList
->GetSizePixel().Height(); }
228 bool Is (CheckBox
* pBox
) const { return m_pText
== pBox
; }
229 bool Is (ColorListBox
* pBox
) const { return m_pColorList
== pBox
; }
233 // checkbox (CheckBox) or simple text (FixedText)
236 ColorListBox
* m_pColorList
;
240 Color m_aDefaultColor
;
242 void SetColor (Color
);
245 // vChapters -- groups (group headers)
246 std::vector
<boost::shared_ptr
<Chapter
> > vChapters
;
247 // vEntries -- color options
248 std::vector
<boost::shared_ptr
<Entry
> > vEntries
;
251 SvtModuleOptions aModuleOptions
;
256 ScrollBar
*m_pVScroll
;
257 HeaderBar
*m_pHeaderHB
;
260 void CreateEntries();
261 void SetAppearance();
264 virtual void Command (CommandEvent
const& rCEvt
);
265 virtual void DataChanged (DataChangedEvent
const& rDCEvt
);
267 virtual Size
calculateRequisition() const;
268 virtual void setAllocation(const Size
&rAllocation
);
270 bool IsGroupVisible (Group
) const;
274 // ColorConfigWindow_Impl::Chapter
277 // ctor for default groups
278 // rParent: parent window (ColorConfigWindow_Impl)
279 // eGroup: which group is this?
280 // rResMgr: resource manager
281 ColorConfigWindow_Impl::Chapter::Chapter(FixedText
* pText
, bool bShow
)
282 : m_bOwnsWidget(false)
289 // ctor for extended groups
290 ColorConfigWindow_Impl::Chapter::Chapter(Window
*pGrid
,
291 unsigned nYPos
, const OUString
& rDisplayName
)
292 : m_bOwnsWidget(true)
294 m_pText
= new FixedText(pGrid
, WB_LEFT
|WB_VCENTER
|WB_3DLOOK
);
295 m_pText
->set_font_attribute("weight", "bold");
296 m_pText
->set_grid_width(3);
297 m_pText
->set_grid_left_attach(0);
298 m_pText
->set_grid_top_attach(nYPos
);
299 m_pText
->SetText(rDisplayName
);
302 ColorConfigWindow_Impl::Chapter::~Chapter()
308 void ColorConfigWindow_Impl::Chapter::Show(Wallpaper
const& rBackWall
)
311 m_pText
->SetBackground(rBackWall
);
315 void ColorConfigWindow_Impl::Chapter::Hide ()
321 // ColorConfigWindow_Impl::Entry
324 ColorConfigWindow_Impl::Entry::Entry(ColorConfigWindow_Impl
& rParent
, unsigned iEntry
,
325 long nCheckBoxLabelOffset
, bool bShow
)
326 : m_bOwnsWidgets(false)
327 , m_aDefaultColor(ColorConfig::GetDefaultColor(static_cast<ColorConfigEntry
>(iEntry
)))
329 rParent
.get(m_pText
, vEntryInfo
[iEntry
].pText
);
330 if (!vEntryInfo
[iEntry
].bCheckBox
)
332 m_pText
->set_margin_left(m_pText
->get_margin_left() +
333 nCheckBoxLabelOffset
);
335 rParent
.get(m_pColorList
, vEntryInfo
[iEntry
].pColor
);
336 rParent
.get(m_pPreview
, vEntryInfo
[iEntry
].pPreview
);
342 // ctor for extended entries
343 ColorConfigWindow_Impl::Entry::Entry( Window
*pGrid
, unsigned nYPos
,
344 ExtendedColorConfigValue
const& rColorEntry
, long nCheckBoxLabelOffset
)
345 : m_bOwnsWidgets(true)
346 , m_aDefaultColor(rColorEntry
.getDefaultColor())
348 m_pText
= new FixedText(pGrid
, WB_LEFT
|WB_VCENTER
|WB_3DLOOK
);
349 m_pText
->set_grid_left_attach(0);
350 m_pText
->set_grid_top_attach(nYPos
);
351 m_pText
->set_margin_left(6 + nCheckBoxLabelOffset
);
352 m_pText
->SetText(rColorEntry
.getDisplayName());
354 WinBits nWinBits
= WB_LEFT
|WB_VCENTER
|WB_3DLOOK
|WB_TABSTOP
|WB_DROPDOWN
;
355 m_pColorList
= new ColorListBox(pGrid
, nWinBits
);
356 m_pColorList
->EnableAutoSize(true);
357 m_pColorList
->set_grid_left_attach(1);
358 m_pColorList
->set_grid_top_attach(nYPos
);
360 m_pPreview
= new Window(pGrid
, WB_BORDER
);
361 m_pPreview
->set_grid_left_attach(2);
362 m_pPreview
->set_grid_top_attach(nYPos
);
363 m_pPreview
->set_margin_right(6);
368 ColorConfigWindow_Impl::Entry::~Entry()
378 void ColorConfigWindow_Impl::Entry::Show()
381 m_pColorList
->Show();
385 void ColorConfigWindow_Impl::Entry::Hide()
388 m_pColorList
->Hide();
393 // iEntry: which entry is this?
394 // aTextWall: background of the text (transparent)
395 // aSampleList: sample color listbox (to copy from)
396 void ColorConfigWindow_Impl::Entry::SetAppearance(
397 Wallpaper
const& aTextWall
,
398 ColorListBox
const& aSampleList
)
400 // text (and optionally checkbox)
401 m_pText
->SetBackground(aTextWall
);
403 m_pPreview
->SetBorderStyle(WINDOW_BORDER_MONO
);
405 m_pColorList
->CopyEntries(aSampleList
);
406 m_pColorList
->InsertAutomaticEntryColor(m_aDefaultColor
);
410 void ColorConfigWindow_Impl::Entry::SetLinks(
411 Link
const& aCheckLink
, Link
const& aColorLink
,
412 Link
const& aGetFocusLink
)
414 m_pColorList
->SetSelectHdl(aColorLink
);
415 m_pColorList
->SetGetFocusHdl(aGetFocusLink
);
416 if (CheckBox
* pCheckBox
= dynamic_cast<CheckBox
*>(m_pText
))
418 pCheckBox
->SetClickHdl(aCheckLink
);
419 pCheckBox
->SetGetFocusHdl(aGetFocusLink
);
423 // updates a default color config entry
424 void ColorConfigWindow_Impl::Entry::Update (
425 ColorConfigEntry aColorEntry
, ColorConfigValue
const& rValue
428 if ((unsigned)rValue
.nColor
== COL_AUTO
)
430 aColor
= ColorConfig::GetDefaultColor(aColorEntry
);
431 m_pColorList
->SelectEntryPos(0);
435 aColor
= Color(rValue
.nColor
);
436 m_pColorList
->SelectEntry(aColor
);
438 m_pPreview
->SetBackground(Wallpaper(aColor
));
439 if (CheckBox
* pCheckBox
= dynamic_cast<CheckBox
*>(m_pText
))
440 pCheckBox
->Check(rValue
.bIsVisible
);
443 // updates an extended color config entry
444 void ColorConfigWindow_Impl::Entry::Update (
445 ExtendedColorConfigValue
const& rValue
447 Color
aColor(rValue
.getColor());
448 if (rValue
.getColor() == rValue
.getDefaultColor())
449 m_pColorList
->SelectEntryPos(0);
451 m_pColorList
->SelectEntry(aColor
);
455 // color of a default entry has changed
456 void ColorConfigWindow_Impl::Entry::ColorChanged (
457 ColorConfigEntry aColorEntry
,
458 ColorConfigValue
& rValue
461 if (m_pColorList
->IsAutomaticSelected())
463 aColor
= ColorConfig::GetDefaultColor(aColorEntry
);
464 rValue
.nColor
= COL_AUTO
;
468 aColor
= m_pColorList
->GetSelectEntryColor();
469 rValue
.nColor
= aColor
.GetColor();
474 // color of an extended entry has changed
475 void ColorConfigWindow_Impl::Entry::ColorChanged (
476 ExtendedColorConfigValue
& rValue
478 Color aColor
= m_pColorList
->GetSelectEntryColor();
479 rValue
.setColor(aColor
.GetColor());
481 if (m_pColorList
->GetSelectEntryPos() == 0)
483 rValue
.setColor(rValue
.getDefaultColor());
484 aColor
.SetColor(rValue
.getColor());
489 void ColorConfigWindow_Impl::Entry::SetColor (Color aColor
)
491 m_pPreview
->SetBackground(Wallpaper(aColor
));
492 m_pPreview
->Invalidate();
497 // ColorConfigWindow_Impl
500 ColorConfigWindow_Impl::ColorConfigWindow_Impl(Window
* pParent
)
501 : VclContainer(pParent
)
503 m_pUIBuilder
= new VclBuilder(this, getUIRootDir(), "cui/ui/colorconfigwin.ui");
504 get(m_pGrid
, "ColorConfigWindow");
509 Size
ColorConfigWindow_Impl::calculateRequisition() const
511 return getLayoutRequisition(*m_pGrid
);
514 void ColorConfigWindow_Impl::setAllocation(const Size
&rAllocation
)
516 Point
aChildPos(0, 0);
517 Size
aChildSize(getLayoutRequisition(*m_pGrid
));
518 aChildSize
.Width() = rAllocation
.Width();
519 setLayoutPosSize(*m_pGrid
, aChildPos
, aChildSize
);
522 ScrollHdl(*m_pVScroll
);
525 void ColorConfigWindow_Impl::CreateEntries()
527 std::vector
<int> aModulesInstalled
;
528 // creating group headers
529 vChapters
.reserve(nGroupCount
);
530 aModulesInstalled
.reserve(nGroupCount
);
531 for (unsigned i
= 0; i
!= nGroupCount
; ++i
)
533 aModulesInstalled
.push_back(IsGroupVisible(vGroupInfo
[i
].eGroup
));
534 vChapters
.push_back(boost::shared_ptr
<Chapter
>(
535 new Chapter(get
<FixedText
>(vGroupInfo
[i
].pGroup
), aModulesInstalled
[i
])));
538 //Here we want to get the amount to add to the position
539 //of a FixedText to get it to align its contents
540 //with that of a CheckBox
541 //We should have something like a Control::getTextOrigin
542 //Ideally we could use something like GetCharacterBounds,
543 //but I think that only works on truly visible controls
544 long nCheckBoxLabelOffset
= 0;
546 OUString
sSampleText("X");
547 CheckBox
aCheckBox(this);
548 FixedText
aFixedText(this);
549 aCheckBox
.SetText(sSampleText
);
550 aFixedText
.SetText(sSampleText
);
551 Size
aCheckSize(aCheckBox
.CalcMinimumSize(0x7fffffff));
552 Size
aFixedSize(aFixedText
.CalcMinimumSize(0x7fffffff));
553 nCheckBoxLabelOffset
= aCheckSize
.Width() - aFixedSize
.Width();
557 vEntries
.reserve(ColorConfigEntryCount
);
558 for (unsigned i
= 0; i
< SAL_N_ELEMENTS(vEntryInfo
); ++i
)
560 vEntries
.push_back(boost::shared_ptr
<Entry
>(new Entry(*this, i
, nCheckBoxLabelOffset
,
561 aModulesInstalled
[vEntryInfo
[i
].eGroup
])));
565 ExtendedColorConfig aExtConfig
;
566 if (unsigned const nExtGroupCount
= aExtConfig
.GetComponentCount())
568 size_t nLineNum
= vChapters
.size() + vEntries
.size() + 1;
569 for (unsigned j
= 0; j
!= nExtGroupCount
; ++j
)
571 OUString
const sComponentName
= aExtConfig
.GetComponentName(j
);
572 vChapters
.push_back(boost::shared_ptr
<Chapter
>(new Chapter(
574 aExtConfig
.GetComponentDisplayName(sComponentName
)
577 unsigned nColorCount
= aExtConfig
.GetComponentColorCount(sComponentName
);
578 for (unsigned i
= 0; i
!= nColorCount
; ++i
)
580 ExtendedColorConfigValue
const aColorEntry
=
581 aExtConfig
.GetComponentColorConfigValue(sComponentName
, i
);
582 vEntries
.push_back(boost::shared_ptr
<Entry
>( new Entry (
583 m_pGrid
, nLineNum
, aColorEntry
, nCheckBoxLabelOffset
591 void ColorConfigWindow_Impl::SetAppearance ()
593 Color
TempColor(COL_TRANSPARENT
);
594 Wallpaper
const aTransparentWall(TempColor
);
595 StyleSettings
const& rStyleSettings
= GetSettings().GetStyleSettings();
596 Color
const aBackColor
= rStyleSettings
.GetHighContrastMode() ?
597 rStyleSettings
.GetShadowColor() : Color(COL_LIGHTGRAY
);
598 Wallpaper
const aBackWall(aBackColor
);
599 for (size_t i
= 0; i
!= vChapters
.size(); ++i
)
600 vChapters
[i
]->Show(aBackWall
);
601 SetBackground(Wallpaper(rStyleSettings
.GetFieldColor()));
603 // #104195# when the window color is the same as the text color it has to be changed
604 Color aWinCol
= rStyleSettings
.GetWindowColor();
605 Color aRCheckCol
= rStyleSettings
.GetRadioCheckTextColor();
606 if (aWinCol
== aRCheckCol
)
609 // if inversion didn't work (gray) then it's set to black
610 if (aRCheckCol
== aWinCol
)
611 aRCheckCol
= Color(COL_BLACK
);
612 // setting new text color for each entry
613 for (size_t i
= 0; i
!= vEntries
.size(); ++i
)
614 vEntries
[i
]->SetTextColor(aRCheckCol
);
617 OSL_ENSURE( vEntries
.size() >= sizeof vEntryInfo
/ sizeof vEntryInfo
[0], "wrong number of helpIDs for color listboxes" );
619 // creating a sample color listbox with the color entries
620 ColorListBox
aSampleColorList(this);
622 XColorListRef
const xColorTable
= XColorList::CreateStdColorList();
623 for (sal_Int32 i
= 0; i
!= xColorTable
->Count(); ++i
)
625 XColorEntry
& rEntry
= *xColorTable
->GetColor(i
);
626 aSampleColorList
.InsertEntry(rEntry
.GetColor(), rEntry
.GetName());
631 for (size_t i
= 0; i
!= vEntries
.size(); ++i
)
634 vEntries
[i
]->SetAppearance(aTransparentWall
, aSampleColorList
);
638 ColorConfigWindow_Impl::~ColorConfigWindow_Impl ()
641 void ColorConfigWindow_Impl::AdjustHeaderBar()
643 // horizontal positions
644 unsigned const nX0
= 0;
645 unsigned const nX1
= get
<Window
>("doccolor")->GetPosPixel().X();
646 unsigned const nX2
= get
<Window
>("doccolor_lb")->GetPosPixel().X();
647 unsigned const nX3
= get
<Window
>("doccolor_wn")->GetPosPixel().X();
648 unsigned const nX4
= m_pHeaderHB
->GetSizePixel().Width();
649 m_pHeaderHB
->SetItemSize(1, nX1
- nX0
);
650 m_pHeaderHB
->SetItemSize(2, nX2
- nX1
);
651 m_pHeaderHB
->SetItemSize(3, nX3
- nX2
);
652 m_pHeaderHB
->SetItemSize(4, nX4
- nX3
);
655 void ColorConfigWindow_Impl::AdjustScrollBar()
657 unsigned const nScrollOffset
=
658 vEntries
[1]->GetTop() - vEntries
[0]->GetTop();
659 unsigned const nVisibleEntries
= GetSizePixel().Height() / nScrollOffset
;
660 m_pVScroll
->SetPageSize(nVisibleEntries
- 1);
661 m_pVScroll
->SetVisibleSize(nVisibleEntries
);
664 void ColorConfigWindow_Impl::Init(ScrollBar
*pVScroll
, HeaderBar
*pHeaderHB
)
666 m_pHeaderHB
= pHeaderHB
;
667 m_pVScroll
= pVScroll
;
668 m_pVScroll
->EnableDrag();
669 m_pVScroll
->SetRangeMin(0);
670 m_pVScroll
->SetRangeMax(vEntries
.size() + vChapters
.size());
674 void ColorConfigWindow_Impl::SetLinks (
675 Link
const& aCheckLink
, Link
const& aColorLink
, Link
const& aGetFocusLink
677 for (unsigned i
= 0; i
!= vEntries
.size(); ++i
)
678 vEntries
[i
]->SetLinks(aCheckLink
, aColorLink
, aGetFocusLink
);
682 void ColorConfigWindow_Impl::Update (
683 EditableColorConfig
const* pConfig
,
684 EditableExtendedColorConfig
const* pExtConfig
)
686 // updating default entries
687 for (unsigned i
= 0; i
!= ColorConfigEntryCount
; ++i
)
689 ColorConfigEntry
const aColorEntry
= static_cast<ColorConfigEntry
>(i
);
691 aColorEntry
, pConfig
->GetColorValue(aColorEntry
)
695 // updating extended entries
696 unsigned i
= ColorConfigEntryCount
;
697 unsigned const nExtCount
= pExtConfig
->GetComponentCount();
698 for (unsigned j
= 0; j
!= nExtCount
; ++j
)
700 OUString sComponentName
= pExtConfig
->GetComponentName(j
);
701 unsigned const nColorCount
= pExtConfig
->GetComponentColorCount(sComponentName
);
702 for (unsigned k
= 0; i
!= vEntries
.size() && k
!= nColorCount
; ++i
, ++k
)
704 pExtConfig
->GetComponentColorConfigValue(sComponentName
, k
)
710 void ColorConfigWindow_Impl::ScrollHdl(const ScrollBar
& rVScroll
)
713 const long nRowHeight
= (vEntries
[1]->GetTop() - vEntries
[0]->GetTop());
714 Point
aPos(0, 0 - rVScroll
.GetThumbPos() * nRowHeight
);
715 m_pGrid
->SetPosPixel(aPos
);
720 void ColorConfigWindow_Impl::ClickHdl (EditableColorConfig
* pConfig
, CheckBox
* pBox
)
722 for (unsigned i
= 0; i
!= ColorConfigEntryCount
; ++i
)
724 if (vEntries
[i
]->Is(pBox
))
726 ColorConfigEntry
const aEntry
= static_cast<ColorConfigEntry
>(i
);
727 ColorConfigValue aValue
= pConfig
->GetColorValue(aEntry
);
728 aValue
.bIsVisible
= pBox
->IsChecked();
729 pConfig
->SetColorValue(aEntry
, aValue
);
736 void ColorConfigWindow_Impl::ColorHdl (
737 EditableColorConfig
* pConfig
, EditableExtendedColorConfig
* pExtConfig
,
743 for ( ; i
!= ColorConfigEntryCount
; ++i
)
745 if (pBox
&& vEntries
[i
]->Is(pBox
))
747 ColorConfigEntry
const aColorEntry
= static_cast<ColorConfigEntry
>(i
);
748 ColorConfigValue aValue
= pConfig
->GetColorValue(aColorEntry
);
749 vEntries
[i
]->ColorChanged(aColorEntry
, aValue
);
750 pConfig
->SetColorValue(aColorEntry
, aValue
);
756 unsigned const nExtCount
= pExtConfig
->GetComponentCount();
757 i
= ColorConfigEntryCount
;
758 for (unsigned j
= 0; j
!= nExtCount
; ++j
)
760 OUString sComponentName
= pExtConfig
->GetComponentName(j
);
761 unsigned const nColorCount
= pExtConfig
->GetComponentColorCount(sComponentName
);
762 unsigned const nCount
= vEntries
.size();
763 for (unsigned k
= 0; i
!= nCount
&& k
!= nColorCount
; ++i
, ++k
)
765 if (pBox
&& vEntries
[i
]->Is(pBox
))
767 ExtendedColorConfigValue aValue
=
768 pExtConfig
->GetComponentColorConfigValue(sComponentName
, k
);
769 vEntries
[i
]->ColorChanged(aValue
);
770 pExtConfig
->SetColorValue(sComponentName
, aValue
);
779 bool ColorConfigWindow_Impl::IsGroupVisible (Group eGroup
) const
785 return aModuleOptions
.IsModuleInstalled(SvtModuleOptions::E_SWRITER
);
787 return aModuleOptions
.IsModuleInstalled(SvtModuleOptions::E_SCALC
);
790 aModuleOptions
.IsModuleInstalled(SvtModuleOptions::E_SDRAW
) ||
791 aModuleOptions
.IsModuleInstalled(SvtModuleOptions::E_SIMPRESS
);
793 return aModuleOptions
.IsModuleInstalled(SvtModuleOptions::E_SDATABASE
);
799 void ColorConfigWindow_Impl::DataChanged (DataChangedEvent
const& rDCEvt
)
801 Window::DataChanged( rDCEvt
);
802 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
803 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
805 StyleSettings
const& rStyleSettings
= GetSettings().GetStyleSettings();
806 bool const bHighContrast
= rStyleSettings
.GetHighContrastMode();
807 Wallpaper
const aBackWall(Color(bHighContrast
? COL_TRANSPARENT
: COL_LIGHTGRAY
));
808 for (unsigned i
= 0; i
!= vChapters
.size(); ++i
)
809 vChapters
[i
]->SetBackground(aBackWall
);
810 SetBackground(Wallpaper(rStyleSettings
.GetWindowColor()));
815 void ColorConfigWindow_Impl::Command( const CommandEvent
& rCEvt
)
817 GetParent()->Command(rCEvt
);
820 class ColorConfigCtrl_Impl
: public VclVBox
822 HeaderBar
* m_pHeaderHB
;
824 ColorConfigWindow_Impl
* m_pScrollWindow
;
825 ScrollBar
* m_pVScroll
;
827 EditableColorConfig
* pColorConfig
;
828 EditableExtendedColorConfig
* pExtColorConfig
;
830 DECL_LINK(ScrollHdl
, ScrollBar
*);
831 DECL_LINK(ClickHdl
, CheckBox
*);
832 DECL_LINK(ColorHdl
, ColorListBox
*);
833 DECL_LINK(ControlFocusHdl
, Control
*);
835 virtual long PreNotify (NotifyEvent
& rNEvt
);
836 virtual void Command (CommandEvent
const& rCEvt
);
837 virtual void DataChanged (DataChangedEvent
const& rDCEvt
);
839 ColorConfigCtrl_Impl(Window
* pParent
);
840 ~ColorConfigCtrl_Impl();
842 void InitHeaderBar(const OUString
&rOn
, const OUString
&rUIElems
,
843 const OUString
&rColorSetting
, const OUString
&rPreview
);
844 void SetConfig (EditableColorConfig
& rConfig
) { pColorConfig
= &rConfig
; }
845 void SetExtendedConfig (EditableExtendedColorConfig
& rConfig
) { pExtColorConfig
= &rConfig
; }
847 long GetScrollPosition ()
849 return m_pVScroll
->GetThumbPos();
851 void SetScrollPosition (long nSet
)
853 m_pVScroll
->SetThumbPos(nSet
);
854 ScrollHdl(m_pVScroll
);
858 ColorConfigCtrl_Impl::ColorConfigCtrl_Impl(Window
* pParent
)
863 m_pHeaderHB
= new HeaderBar(this, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
865 m_pBody
= new VclHBox(this);
866 m_pScrollWindow
= new ColorConfigWindow_Impl(m_pBody
);
867 m_pVScroll
= new ScrollBar(m_pBody
, WB_VERT
);
868 m_pScrollWindow
->Init(m_pVScroll
, m_pHeaderHB
);
870 m_pBody
->set_hexpand(true);
871 m_pBody
->set_vexpand(true);
872 m_pBody
->set_expand(true);
873 m_pBody
->set_fill(true);
875 m_pScrollWindow
->set_hexpand(true);
876 m_pScrollWindow
->set_vexpand(true);
877 m_pScrollWindow
->set_expand(true);
878 m_pScrollWindow
->set_fill(true);
880 Link aScrollLink
= LINK(this, ColorConfigCtrl_Impl
, ScrollHdl
);
881 m_pVScroll
->SetScrollHdl(aScrollLink
);
882 m_pVScroll
->SetEndScrollHdl(aScrollLink
);
884 Link aCheckLink
= LINK(this, ColorConfigCtrl_Impl
, ClickHdl
);
885 Link aColorLink
= LINK(this, ColorConfigCtrl_Impl
, ColorHdl
);
886 Link aGetFocusLink
= LINK(this, ColorConfigCtrl_Impl
, ControlFocusHdl
);
887 m_pScrollWindow
->SetLinks(aCheckLink
, aColorLink
, aGetFocusLink
);
892 m_pScrollWindow
->Show();
895 void ColorConfigCtrl_Impl::InitHeaderBar(const OUString
&rOn
, const OUString
&rUIElems
,
896 const OUString
&rColorSetting
, const OUString
&rPreview
)
899 const WinBits nHeadBits
= HIB_VCENTER
| HIB_FIXED
| HIB_FIXEDPOS
;
900 m_pHeaderHB
->InsertItem(1, rOn
, 0, nHeadBits
| HIB_CENTER
);
901 m_pHeaderHB
->InsertItem(2, rUIElems
, 0, nHeadBits
| HIB_LEFT
);
902 m_pHeaderHB
->InsertItem(3, rColorSetting
, 0, nHeadBits
| HIB_LEFT
);
903 m_pHeaderHB
->InsertItem(4, rPreview
, 0, nHeadBits
| HIB_LEFT
);
904 m_pHeaderHB
->set_height_request(GetTextHeight() + 6);
907 ColorConfigCtrl_Impl::~ColorConfigCtrl_Impl()
910 delete m_pScrollWindow
;
915 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeColorConfigCtrl(Window
*pParent
, VclBuilder::stringmap
&)
917 return new ColorConfigCtrl_Impl(pParent
);
920 void ColorConfigCtrl_Impl::Update ()
922 DBG_ASSERT(pColorConfig
, "Configuration not set");
923 m_pScrollWindow
->Update(pColorConfig
, pExtColorConfig
);
926 IMPL_LINK(ColorConfigCtrl_Impl
, ScrollHdl
, ScrollBar
*, pScrollBar
)
928 m_pScrollWindow
->ScrollHdl(*pScrollBar
);
932 long ColorConfigCtrl_Impl::PreNotify( NotifyEvent
& rNEvt
)
934 if(rNEvt
.GetType() == EVENT_COMMAND
)
936 const CommandEvent
* pCEvt
= rNEvt
.GetCommandEvent();
937 sal_uInt16 nCmd
= pCEvt
->GetCommand();
938 if( COMMAND_WHEEL
== nCmd
)
944 return VclVBox::PreNotify(rNEvt
);
947 void ColorConfigCtrl_Impl::Command( const CommandEvent
& rCEvt
)
949 switch ( rCEvt
.GetCommand() )
953 case COMMAND_STARTAUTOSCROLL
:
954 case COMMAND_AUTOSCROLL
:
956 const CommandWheelData
* pWheelData
= rCEvt
.GetWheelData();
957 if(pWheelData
&& !pWheelData
->IsHorz() && COMMAND_WHEEL_ZOOM
!= pWheelData
->GetMode())
959 HandleScrollCommand(rCEvt
, 0, m_pVScroll
);
964 VclVBox::Command(rCEvt
);
968 void ColorConfigCtrl_Impl::DataChanged( const DataChangedEvent
& rDCEvt
)
970 Window::DataChanged( rDCEvt
);
971 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
972 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
974 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
975 SetBackground(Wallpaper(rStyleSettings
.GetFieldColor()));
979 IMPL_LINK(ColorConfigCtrl_Impl
, ClickHdl
, CheckBox
*, pBox
)
981 DBG_ASSERT(pColorConfig
, "Configuration not set");
982 m_pScrollWindow
->ClickHdl(pColorConfig
, pBox
);
986 // a color list has changed
987 IMPL_LINK(ColorConfigCtrl_Impl
, ColorHdl
, ColorListBox
*, pBox
)
989 DBG_ASSERT(pColorConfig
, "Configuration not set" );
991 m_pScrollWindow
->ColorHdl(pColorConfig
, pExtColorConfig
, pBox
);
994 IMPL_LINK(ColorConfigCtrl_Impl
, ControlFocusHdl
, Control
*, pCtrl
)
996 // determine whether a control is completely visible
997 // and make it visible
998 long aCtrlPosY
= pCtrl
->GetPosPixel().Y();
999 unsigned const nWinHeight
= m_pScrollWindow
->GetSizePixel().Height();
1000 unsigned const nEntryHeight
= m_pScrollWindow
->GetEntryHeight();
1001 if (0 != (GETFOCUS_TAB
& pCtrl
->GetGetFocusFlags()) &&
1002 (aCtrlPosY
< 0 || nWinHeight
< aCtrlPosY
+ nEntryHeight
)
1004 long nThumbPos
= m_pVScroll
->GetThumbPos();
1005 if (nWinHeight
< aCtrlPosY
+ nEntryHeight
)
1017 m_pVScroll
->SetThumbPos(nThumbPos
);
1018 ScrollHdl(m_pVScroll
);
1025 // SvxColorOptionsTabPage
1028 SvxColorOptionsTabPage::SvxColorOptionsTabPage(
1029 Window
* pParent
, const SfxItemSet
& rCoreSet
)
1030 : SfxTabPage(pParent
, "OptAppearancePage", "cui/ui/optappearancepage.ui", rCoreSet
)
1031 , bFillItemSetCalled(false)
1033 , pExtColorConfig(0)
1035 get(m_pColorSchemeLB
, "colorschemelb");
1036 m_pColorSchemeLB
->SetStyle(m_pColorSchemeLB
->GetStyle() | WB_SORT
);
1037 get(m_pSaveSchemePB
, "save");
1038 get(m_pDeleteSchemePB
, "delete");
1039 get(m_pColorConfigCT
, "colorconfig");
1041 m_pColorConfigCT
->InitHeaderBar(
1042 get
<Window
>("on")->GetText(),
1043 get
<Window
>("uielements")->GetText(),
1044 get
<Window
>("colorsetting")->GetText(),
1045 get
<Window
>("preview")->GetText());
1047 m_pColorSchemeLB
->SetSelectHdl(LINK(this, SvxColorOptionsTabPage
, SchemeChangedHdl_Impl
));
1048 Link aLk
= LINK(this, SvxColorOptionsTabPage
, SaveDeleteHdl_Impl
);
1049 m_pSaveSchemePB
->SetClickHdl(aLk
);
1050 m_pDeleteSchemePB
->SetClickHdl(aLk
);
1053 SvxColorOptionsTabPage::~SvxColorOptionsTabPage()
1055 //when the dialog is cancelled but the color scheme ListBox has been changed these
1056 //changes need to be undone
1057 if(!bFillItemSetCalled
&& m_pColorSchemeLB
->GetSavedValue() != m_pColorSchemeLB
->GetSelectEntryPos())
1059 OUString sOldScheme
= m_pColorSchemeLB
->GetEntry(m_pColorSchemeLB
->GetSavedValue());
1060 if(!sOldScheme
.isEmpty())
1062 pColorConfig
->SetCurrentSchemeName(sOldScheme
);
1063 pExtColorConfig
->SetCurrentSchemeName(sOldScheme
);
1066 pColorConfig
->ClearModified();
1067 pColorConfig
->EnableBroadcast();
1068 delete pColorConfig
;
1069 pExtColorConfig
->ClearModified();
1070 pExtColorConfig
->EnableBroadcast();
1071 delete pExtColorConfig
;
1074 SfxTabPage
* SvxColorOptionsTabPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
1076 return ( new SvxColorOptionsTabPage( pParent
, rAttrSet
) );
1079 sal_Bool
SvxColorOptionsTabPage::FillItemSet( SfxItemSet
& )
1081 bFillItemSetCalled
= sal_True
;
1082 if(m_pColorSchemeLB
->GetSavedValue() != m_pColorSchemeLB
->GetSelectEntryPos())
1084 pColorConfig
->SetModified();
1085 pExtColorConfig
->SetModified();
1087 if(pColorConfig
->IsModified())
1088 pColorConfig
->Commit();
1089 if(pExtColorConfig
->IsModified())
1090 pExtColorConfig
->Commit();
1094 void SvxColorOptionsTabPage::Reset( const SfxItemSet
& )
1098 pColorConfig
->ClearModified();
1099 pColorConfig
->DisableBroadcast();
1100 delete pColorConfig
;
1102 pColorConfig
= new EditableColorConfig
;
1103 m_pColorConfigCT
->SetConfig(*pColorConfig
);
1107 pExtColorConfig
->ClearModified();
1108 pExtColorConfig
->DisableBroadcast();
1109 delete pExtColorConfig
;
1111 pExtColorConfig
= new EditableExtendedColorConfig
;
1112 m_pColorConfigCT
->SetExtendedConfig(*pExtColorConfig
);
1114 String sUser
= GetUserData();
1115 //has to be called always to speed up accessibility tools
1116 m_pColorConfigCT
->SetScrollPosition(sUser
.ToInt32());
1117 m_pColorSchemeLB
->Clear();
1118 uno::Sequence
< OUString
> aSchemes
= pColorConfig
->GetSchemeNames();
1119 const OUString
* pSchemes
= aSchemes
.getConstArray();
1120 for(sal_Int32 i
= 0; i
< aSchemes
.getLength(); i
++)
1121 m_pColorSchemeLB
->InsertEntry(pSchemes
[i
]);
1122 m_pColorSchemeLB
->SelectEntry(pColorConfig
->GetCurrentSchemeName());
1123 m_pColorSchemeLB
->SaveValue();
1124 m_pDeleteSchemePB
->Enable( aSchemes
.getLength() > 1 );
1125 UpdateColorConfig();
1128 int SvxColorOptionsTabPage::DeactivatePage( SfxItemSet
* pSet_
)
1131 FillItemSet( *pSet_
);
1132 return( LEAVE_PAGE
);
1135 void SvxColorOptionsTabPage::UpdateColorConfig()
1137 //update the color config control
1138 m_pColorConfigCT
->Update();
1141 IMPL_LINK(SvxColorOptionsTabPage
, SchemeChangedHdl_Impl
, ListBox
*, pBox
)
1143 pColorConfig
->LoadScheme(pBox
->GetSelectEntry());
1144 pExtColorConfig
->LoadScheme(pBox
->GetSelectEntry());
1145 UpdateColorConfig();
1149 IMPL_LINK(SvxColorOptionsTabPage
, SaveDeleteHdl_Impl
, PushButton
*, pButton
)
1151 if (m_pSaveSchemePB
== pButton
)
1155 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
1156 DBG_ASSERT(pFact
, "Dialogdiet fail!");
1157 AbstractSvxNameDialog
* aNameDlg
= pFact
->CreateSvxNameDialog( pButton
,
1158 sName
, String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE2
)) );
1159 DBG_ASSERT(aNameDlg
, "Dialogdiet fail!");
1160 aNameDlg
->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage
, CheckNameHdl_Impl
));
1161 aNameDlg
->SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE1
)));
1162 aNameDlg
->SetHelpId(HID_OPTIONS_COLORCONFIG_SAVE_SCHEME
);
1163 aNameDlg
->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage
, CheckNameHdl_Impl
));
1164 if(RET_OK
== aNameDlg
->Execute())
1166 aNameDlg
->GetName(sName
);
1167 pColorConfig
->AddScheme(sName
);
1168 pExtColorConfig
->AddScheme(sName
);
1169 m_pColorSchemeLB
->InsertEntry(sName
);
1170 m_pColorSchemeLB
->SelectEntry(sName
);
1171 m_pColorSchemeLB
->GetSelectHdl().Call(m_pColorSchemeLB
);
1177 DBG_ASSERT(m_pColorSchemeLB
->GetEntryCount() > 1, "don't delete the last scheme");
1178 QueryBox
aQuery(pButton
, CUI_RES(RID_SVXQB_DELETE_COLOR_CONFIG
));
1179 aQuery
.SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_DELETE
)));
1180 if(RET_YES
== aQuery
.Execute())
1182 OUString
sDeleteScheme(m_pColorSchemeLB
->GetSelectEntry());
1183 m_pColorSchemeLB
->RemoveEntry(m_pColorSchemeLB
->GetSelectEntryPos());
1184 m_pColorSchemeLB
->SelectEntryPos(0);
1185 m_pColorSchemeLB
->GetSelectHdl().Call(m_pColorSchemeLB
);
1186 //first select the new scheme and then delete the old one
1187 pColorConfig
->DeleteScheme(sDeleteScheme
);
1188 pExtColorConfig
->DeleteScheme(sDeleteScheme
);
1191 m_pDeleteSchemePB
->Enable( m_pColorSchemeLB
->GetEntryCount() > 1 );
1195 IMPL_LINK(SvxColorOptionsTabPage
, CheckNameHdl_Impl
, AbstractSvxNameDialog
*, pDialog
)
1198 pDialog
->GetName(sName
);
1199 return sName
.Len() && LISTBOX_ENTRY_NOTFOUND
== m_pColorSchemeLB
->GetEntryPos( sName
);
1202 void SvxColorOptionsTabPage::FillUserData()
1204 SetUserData(OUString::number(m_pColorConfigCT
->GetScrollPosition()));
1207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */