bump product version to 4.1.6.2
[LibreOffice.git] / cui / source / options / optcolor.cxx
blobedaae1cf3dcc43cfb7aa142dceacc85a50bcd6e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
31 #include <helpid.hrc>
32 #include <dialmgr.hxx>
33 #include "optcolor.hxx"
34 #include <cuires.hrc>
35 #include <svx/dlgutil.hxx>
37 using namespace ::com::sun::star;
38 using namespace ::svtools;
40 namespace
43 // list of default groups
44 enum Group
46 Group_Unknown = -1,
48 Group_General,
49 Group_Writer,
50 Group_Html,
51 Group_Calc,
52 Group_Draw,
53 Group_Basic,
54 Group_Sql,
56 nGroupCount
59 // group data
60 struct
62 // group
63 Group eGroup;
64 // .ui group name
65 const char *pGroup;
67 const vGroupInfo[] =
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" },
76 { Group_Sql, "sql" }
79 // color config entry data (see ColorConfigWindow_Impl::Entry below)
80 struct
82 // group
83 Group eGroup;
84 //checkbox (or simple text)
85 const char *pText;
86 //color listbox
87 const char *pColor;
88 //preview box
89 const char *pPreview;
90 // has checkbox?
91 bool bCheckBox;
93 const vEntryInfo[] =
95 #define IDS(Name) \
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) }
156 #undef IDS
159 } // namespace
162 // ColorConfigWindow_Impl
165 class ColorConfigWindow_Impl
166 : public VclContainer
167 , public VclBuilderContainer
169 public:
170 ColorConfigWindow_Impl(Window* pParent);
171 ~ColorConfigWindow_Impl();
173 public:
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();
184 private:
185 // Chapter -- horizontal group separator stripe with text
186 class Chapter
188 // text
189 bool m_bOwnsWidget;
190 FixedText *m_pText;
191 public:
192 Chapter(FixedText *pText, bool bShow);
193 Chapter(Window *pGrid, unsigned nYPos, const OUString& sDisplayName);
194 ~Chapter();
195 public:
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);
200 void Hide();
203 // Entry -- a color config entry:
204 // text (checkbox) + color list box + preview box
205 class Entry
207 public:
208 Entry(ColorConfigWindow_Impl& rParent, unsigned iEntry, long nCheckBoxLabelOffset, bool bShow);
209 Entry(Window* pGrid, unsigned nYPos, const ExtendedColorConfigValue& aColorEntry,
210 long nCheckBoxLabelOffset);
211 ~Entry();
212 public:
213 void Show ();
214 void Hide ();
215 void SetAppearance(Wallpaper const& aTextWall, ColorListBox const& aSampleList);
216 void SetTextColor (Color C) { m_pText->SetTextColor(C); }
217 public:
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&);
223 public:
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(); }
227 public:
228 bool Is (CheckBox* pBox) const { return m_pText == pBox; }
229 bool Is (ColorListBox* pBox) const { return m_pColorList == pBox; }
231 private:
232 bool m_bOwnsWidgets;
233 // checkbox (CheckBox) or simple text (FixedText)
234 Control* m_pText;
235 // color list box
236 ColorListBox* m_pColorList;
237 // color preview box
238 Window* m_pPreview;
239 // default color
240 Color m_aDefaultColor;
241 private:
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;
250 // module options
251 SvtModuleOptions aModuleOptions;
254 private:
255 VclGrid *m_pGrid;
256 ScrollBar *m_pVScroll;
257 HeaderBar *m_pHeaderHB;
259 // initialization
260 void CreateEntries();
261 void SetAppearance();
263 private:
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)
283 , m_pText(pText)
285 if (!bShow)
286 Hide();
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()
304 if (m_bOwnsWidget)
305 delete m_pText;
308 void ColorConfigWindow_Impl::Chapter::Show(Wallpaper const& rBackWall)
310 // background
311 m_pText->SetBackground(rBackWall);
312 m_pText->Show();
315 void ColorConfigWindow_Impl::Chapter::Hide ()
317 m_pText->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);
338 if (!bShow)
339 Hide();
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);
365 Show();
368 ColorConfigWindow_Impl::Entry::~Entry()
370 if (m_bOwnsWidgets)
372 delete m_pText;
373 delete m_pColorList;
374 delete m_pPreview;
378 void ColorConfigWindow_Impl::Entry::Show()
380 m_pText->Show();
381 m_pColorList->Show();
382 m_pPreview->Show();
385 void ColorConfigWindow_Impl::Entry::Hide()
387 m_pText->Hide();
388 m_pColorList->Hide();
389 m_pPreview->Hide();
392 // SetAppearance()
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);
402 // preview
403 m_pPreview->SetBorderStyle(WINDOW_BORDER_MONO);
404 // color list
405 m_pColorList->CopyEntries(aSampleList);
406 m_pColorList->InsertAutomaticEntryColor(m_aDefaultColor);
409 // SetLinks()
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
427 Color aColor;
428 if ((unsigned)rValue.nColor == COL_AUTO)
430 aColor = ColorConfig::GetDefaultColor(aColorEntry);
431 m_pColorList->SelectEntryPos(0);
433 else
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);
450 else
451 m_pColorList->SelectEntry(aColor);
452 SetColor(aColor);
455 // color of a default entry has changed
456 void ColorConfigWindow_Impl::Entry::ColorChanged (
457 ColorConfigEntry aColorEntry,
458 ColorConfigValue& rValue
460 Color aColor;
461 if (m_pColorList->IsAutomaticSelected())
463 aColor = ColorConfig::GetDefaultColor(aColorEntry);
464 rValue.nColor = COL_AUTO;
466 else
468 aColor = m_pColorList->GetSelectEntryColor();
469 rValue.nColor = aColor.GetColor();
471 SetColor(aColor);
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());
480 // automatic?
481 if (m_pColorList->GetSelectEntryPos() == 0)
483 rValue.setColor(rValue.getDefaultColor());
484 aColor.SetColor(rValue.getColor());
486 SetColor(aColor);
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");
505 CreateEntries();
506 SetAppearance();
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);
520 AdjustScrollBar();
521 AdjustHeaderBar();
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();
556 // creating entries
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])));
564 // extended entries
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(
573 m_pGrid, nLineNum,
574 aExtConfig.GetComponentDisplayName(sComponentName)
575 )));
576 ++nLineNum;
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
584 )));
585 ++nLineNum;
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)
608 aRCheckCol.Invert();
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());
630 // appearance
631 for (size_t i = 0; i != vEntries.size(); ++i)
633 // appearance
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());
673 // SetLinks()
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);
681 // Update()
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);
690 vEntries[i]->Update(
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)
703 vEntries[i]->Update(
704 pExtConfig->GetComponentColorConfigValue(sComponentName, k)
709 // ScrollHdl()
710 void ColorConfigWindow_Impl::ScrollHdl(const ScrollBar& rVScroll)
712 SetUpdateMode(true);
713 const long nRowHeight = (vEntries[1]->GetTop() - vEntries[0]->GetTop());
714 Point aPos(0, 0 - rVScroll.GetThumbPos() * nRowHeight);
715 m_pGrid->SetPosPixel(aPos);
716 SetUpdateMode(true);
719 // ClickHdl()
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);
730 break;
735 // ColorHdl()
736 void ColorConfigWindow_Impl::ColorHdl (
737 EditableColorConfig* pConfig, EditableExtendedColorConfig* pExtConfig,
738 ColorListBox* pBox
740 unsigned i = 0;
742 // default entries
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);
751 break;
755 // extended entries
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);
771 break;
778 // IsGroupVisible()
779 bool ColorConfigWindow_Impl::IsGroupVisible (Group eGroup) const
781 switch (eGroup)
783 case Group_Writer:
784 case Group_Html:
785 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SWRITER);
786 case Group_Calc:
787 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SCALC);
788 case Group_Draw:
789 return
790 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDRAW) ||
791 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SIMPRESS);
792 case Group_Sql:
793 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDATABASE);
794 default:
795 return true;
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;
823 VclHBox* m_pBody;
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);
838 public:
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; }
846 void Update ();
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)
859 : VclVBox(pParent)
860 , pColorConfig(0)
861 , pExtColorConfig(0)
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);
889 m_pHeaderHB->Show();
890 m_pVScroll->Show();
891 m_pBody->Show();
892 m_pScrollWindow->Show();
895 void ColorConfigCtrl_Impl::InitHeaderBar(const OUString &rOn, const OUString &rUIElems,
896 const OUString &rColorSetting, const OUString &rPreview)
898 // filling
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()
909 delete m_pVScroll;
910 delete m_pScrollWindow;
911 delete m_pBody;
912 delete m_pHeaderHB;
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);
929 return 0;
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 )
940 Command(*pCEvt);
941 return 1;
944 return VclVBox::PreNotify(rNEvt);
947 void ColorConfigCtrl_Impl::Command( const CommandEvent& rCEvt )
949 switch ( rCEvt.GetCommand() )
952 case COMMAND_WHEEL:
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);
962 break;
963 default:
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);
983 return 0;
986 // a color list has changed
987 IMPL_LINK(ColorConfigCtrl_Impl, ColorHdl, ColorListBox*, pBox)
989 DBG_ASSERT(pColorConfig, "Configuration not set" );
990 if (pBox)
991 m_pScrollWindow->ColorHdl(pColorConfig, pExtColorConfig, pBox);
992 return 0;
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)
1007 //scroll down
1008 nThumbPos += 2;
1010 else
1012 //scroll up
1013 nThumbPos -= 2;
1014 if(nThumbPos < 0)
1015 nThumbPos = 0;
1017 m_pVScroll->SetThumbPos(nThumbPos);
1018 ScrollHdl(m_pVScroll);
1020 return 0;
1025 // SvxColorOptionsTabPage
1028 SvxColorOptionsTabPage::SvxColorOptionsTabPage(
1029 Window* pParent, const SfxItemSet& rCoreSet)
1030 : SfxTabPage(pParent, "OptAppearancePage", "cui/ui/optappearancepage.ui", rCoreSet)
1031 , bFillItemSetCalled(false)
1032 , pColorConfig(0)
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();
1091 return sal_True;
1094 void SvxColorOptionsTabPage::Reset( const SfxItemSet& )
1096 if(pColorConfig)
1098 pColorConfig->ClearModified();
1099 pColorConfig->DisableBroadcast();
1100 delete pColorConfig;
1102 pColorConfig = new EditableColorConfig;
1103 m_pColorConfigCT->SetConfig(*pColorConfig);
1105 if(pExtColorConfig)
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_ )
1130 if ( 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();
1146 return 0;
1149 IMPL_LINK(SvxColorOptionsTabPage, SaveDeleteHdl_Impl, PushButton*, pButton )
1151 if (m_pSaveSchemePB == pButton)
1153 String sName;
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);
1173 delete aNameDlg;
1175 else
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 );
1192 return 0;
1195 IMPL_LINK(SvxColorOptionsTabPage, CheckNameHdl_Impl, AbstractSvxNameDialog*, pDialog )
1197 String sName;
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: */