Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / cui / source / options / optcolor.cxx
blobcc217e40b0d12eadabb67d1cabb0978f9d394812
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 "optcolor.hrc"
36 #include <svx/dlgutil.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::svtools;
41 namespace
44 // list of default groups
45 enum Group
47 Group_Unknown = -1,
49 Group_General,
50 Group_Writer,
51 Group_Html,
52 Group_Calc,
53 Group_Draw,
54 Group_Basic,
55 Group_Sql,
57 nGroupCount
60 // group data
61 struct
63 // resource id for the title text
64 int nTextResId;
66 const vGroupInfo[] =
68 // the groups are in the same order as in enum Group above
69 { FT_GENERAL },
70 { FT_WRITER },
71 { FT_HTML },
72 { FT_CALC },
73 { FT_DRAW },
74 { FT_BASIC },
75 { FT_SQL_COMMAND }, // FIXME
78 // color config entry data (see ColorConfigWindow_Impl::Entry below)
79 struct
81 // group
82 Group eGroup;
84 // help id for ...
85 // color listbox
86 char const* sColorListHid;
87 // checkbox
88 char const* sCheckBoxHid;
90 // resource id for ...
91 // checkbox (or simple text)
92 int nTextResId;
93 // color listbox
94 int nColorListResId;
95 // preview box
96 int nPreviewResId;
98 // has checkbox?
99 bool bCheckBox;
101 const vEntryInfo[] =
103 // These macros simplify the list of constants.
104 // There is a unique name that is the same in the ids of the same entry
105 // (except one).
106 // Entries with and without checkboxes need different macros:
107 #define IDS(Name) \
108 HID_COLORPAGE_##Name##_LB, HID_COLORPAGE_##Name##_CB, \
109 FT_##Name, LB_##Name, WN_##Name, false
110 #define IDS_CB(Name) \
111 HID_COLORPAGE_##Name##_LB, HID_COLORPAGE_##Name##_CB, \
112 CB_##Name, LB_##Name, WN_##Name, true
114 // resolve different names
115 #define CB_DOCBOUNDARIES CB_DOCBOUND
116 #define LB_DOCBOUNDARIES LB_DOCBOUND
117 #define WN_DOCBOUNDARIES WN_DOCBOUND
118 #define FT_CALCPAGEBREAKAUTOMATIC FT_CALCPAGEBREAKAUTO
119 #define LB_CALCPAGEBREAKAUTOMATIC LB_CALCPAGEBREAKAUTO
120 #define WN_CALCPAGEBREAKAUTOMATIC WN_CALCPAGEBREAKAUTO
122 // The list of these entries (enum ColorConfigEntry) are in colorcfg.hxx.
124 { Group_General, IDS(DOCCOLOR) },
125 { Group_General, IDS_CB(DOCBOUNDARIES) },
126 { Group_General, IDS(APPBACKGROUND) },
127 { Group_General, IDS_CB(OBJECTBOUNDARIES) },
128 { Group_General, IDS_CB(TABLEBOUNDARIES) },
129 { Group_General, IDS(FONTCOLOR) },
130 { Group_General, IDS_CB(LINKS) },
131 { Group_General, IDS_CB(LINKSVISITED) },
132 { Group_General, IDS(SPELL) },
133 { Group_General, IDS(SMARTTAGS) },
134 { Group_General, IDS_CB(SHADOWCOLOR) },
135 { Group_Writer, IDS(WRITERTEXTGRID) },
136 { Group_Writer, IDS_CB(WRITERFIELDSHADINGS) },
137 { Group_Writer, IDS_CB(WRITERIDXSHADINGS) },
138 { Group_Writer, IDS(WRITERDIRECTCURSOR) },
139 { Group_Writer, IDS(WRITERSCRIPTINDICATOR) },
140 { Group_Writer, IDS_CB(WRITERSECTIONBOUNDARIES) },
141 { Group_Writer, IDS(WRITERHEADERFOOTERMARK) },
142 { Group_Writer, IDS(WRITERPAGEBREAKS) },
143 { Group_Html, IDS(HTMLSGML) },
144 { Group_Html, IDS(HTMLCOMMENT) },
145 { Group_Html, IDS(HTMLKEYWORD) },
146 { Group_Html, IDS(HTMLUNKNOWN) },
147 { Group_Calc, IDS(CALCGRID) },
148 { Group_Calc, IDS(CALCPAGEBREAK) },
149 { Group_Calc, IDS(CALCPAGEBREAKMANUAL) },
150 { Group_Calc, IDS(CALCPAGEBREAKAUTOMATIC) },
151 { Group_Calc, IDS(CALCDETECTIVE) },
152 { Group_Calc, IDS(CALCDETECTIVEERROR) },
153 { Group_Calc, IDS(CALCREFERENCE) },
154 { Group_Calc, IDS(CALCNOTESBACKGROUND) },
155 { Group_Draw, IDS(DRAWGRID) },
156 { Group_Basic, IDS(BASICIDENTIFIER) },
157 { Group_Basic, IDS(BASICCOMMENT) },
158 { Group_Basic, IDS(BASICNUMBER) },
159 { Group_Basic, IDS(BASICSTRING) },
160 { Group_Basic, IDS(BASICOPERATOR) },
161 { Group_Basic, IDS(BASICKEYWORD) },
162 { Group_Basic, IDS(BASICERROR) },
163 { Group_Sql, IDS(SQLIDENTIFIER) },
164 { Group_Sql, IDS(SQLNUMBER) },
165 { Group_Sql, IDS(SQLSTRING) },
166 { Group_Sql, IDS(SQLOPERATOR) },
167 { Group_Sql, IDS(SQLKEYWORD) },
168 { Group_Sql, IDS(SQLPARAMETER) },
169 { Group_Sql, IDS(SQLCOMMENT) },
171 #undef IDS_CB
172 #undef IDS
175 } // namespace
179 // SvxExtFixedText_Impl
182 class SvxExtFixedText_Impl : public FixedText
184 private:
185 long m_nGroupHeight;
187 protected:
188 virtual void DataChanged (DataChangedEvent const& rDCEvt);
190 public:
191 SvxExtFixedText_Impl (Window* pParent, ResId const& rResId) :
192 FixedText(pParent, rResId), m_nGroupHeight(0)
195 long GetGroupHeight () const { return m_nGroupHeight; }
196 void SetGroupHeight (long nHeight) { m_nGroupHeight = nHeight; }
199 void SvxExtFixedText_Impl::DataChanged (DataChangedEvent const& rDCEvt)
201 FixedText::DataChanged(rDCEvt);
202 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
203 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
205 Font aFont = GetFont();
206 aFont.SetWeight(WEIGHT_BOLD);
207 SetFont(aFont);
208 SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
214 // ColorConfigWindow_Impl
217 class ColorConfigWindow_Impl : public Window
219 public:
220 ColorConfigWindow_Impl (Window* pParent, ResId const& rResId);
221 ~ColorConfigWindow_Impl ();
223 public:
224 void SetLinks (Link const&, Link const&, Link const&);
225 unsigned GetEntryHeight () const { return vEntries[0]->GetHeight(); }
226 void Update (EditableColorConfig const*, EditableExtendedColorConfig const*);
227 void ScrollHdl (long& nScrollPos, ScrollBar const&);
228 void ClickHdl (EditableColorConfig*, CheckBox*);
229 void ColorHdl (EditableColorConfig*, EditableExtendedColorConfig*, ColorListBox*);
230 void SetHeaderBar (HeaderBar&, ScrollBar const&, ResMgr&);
231 void SetScrollBar (ScrollBar&);
234 private:
235 // Chapter -- horizontal group separator stripe with text
236 class Chapter
238 // parent window
239 ColorConfigWindow_Impl& rParent;
240 // gray (?) stripe
241 Window aBackground;
242 // text
243 SvxExtFixedText_Impl aText;
245 public:
246 Chapter (ColorConfigWindow_Impl& rParent, Group, ResMgr&);
247 Chapter (ColorConfigWindow_Impl& rParent, ResMgr&, unsigned nYPos, rtl::OUString const& sDisplayName);
248 public:
249 void Show (Wallpaper const& rBackWall);
250 void Hide ();
251 void MoveVertically (long nOffset);
252 void SetBackground (Wallpaper const& W) { aBackground.SetBackground(W); }
253 long GetHeight () const { return aText.GetGroupHeight(); }
254 void SetHeight (long nHeight) { aText.SetGroupHeight(nHeight); }
255 long GetLeft () const { return aText.GetPosPixel().X(); }
256 long GetTop () const { return aText.GetPosPixel().Y(); }
259 // Entry -- a color config entry:
260 // text (checkbox) + color list box + preview box
261 class Entry
263 public:
264 Entry (Window& rParent, unsigned iEntry, ResMgr&);
265 Entry (Window& rParent, ResMgr&, unsigned nYPos, ExtendedColorConfigValue const& aColorEntry);
266 public:
267 void MoveVertically (long nOffset);
268 bool MoveAndShow (long nOffset, long nMaxVisible, bool bShow);
269 void Show ();
270 void Hide ();
271 void SetAppearance (unsigned iEntry, Wallpaper const& aTextWall, ColorListBox const& aSampleList);
272 void SetTextColor (Color C) { pText->SetTextColor(C); }
273 public:
274 void SetLinks (Link const&, Link const&, Link const&);
275 void SetHeader (ColorConfigWindow_Impl const& rParent, HeaderBar&, ResMgr&) const;
276 void Update (ColorConfigEntry, ColorConfigValue const&);
277 void Update (ExtendedColorConfigValue const&);
278 void ColorChanged (ColorConfigEntry, ColorConfigValue&);
279 void ColorChanged (ExtendedColorConfigValue&);
280 public:
281 long GetTop () const { return aPreview.GetPosPixel().Y(); }
282 long GetBottom () const { return GetTop() + aPreview.GetSizePixel().Height(); }
283 unsigned GetHeight () const { return aColorList.GetSizePixel().Height(); }
284 public:
285 bool Is (CheckBox* pBox) const { return pText.get() == pBox; }
286 bool Is (ColorListBox* pBox) const { return &aColorList == pBox; }
288 private:
289 // checkbox (CheckBox) or simple text (FixedText)
290 boost::shared_ptr<Control> pText;
291 // color list box
292 ColorListBox aColorList;
293 // color preview box
294 Window aPreview;
295 // default color
296 Color aDefaultColor;
298 private:
299 void SetColor (Color);
302 // vChapters -- groups (group headers)
303 std::vector<boost::shared_ptr<Chapter> > vChapters;
304 // vEntries -- color options
305 std::vector<boost::shared_ptr<Entry> > vEntries;
307 // module options
308 SvtModuleOptions aModuleOptions;
311 private:
312 // initialization
313 void CreateEntries (ResMgr&);
314 void SetAppearance ();
316 private:
317 long GetDeltaAbove (Group) const;
319 virtual void Command (CommandEvent const& rCEvt);
320 virtual void DataChanged (DataChangedEvent const& rDCEvt);
322 unsigned GetPosBehindLastChapter () const;
324 bool IsGroupVisible (Group) const;
327 namespace
330 // entry -> group
331 Group GetGroup (unsigned nEntry)
333 if (nEntry >= ColorConfigEntryCount)
334 return nGroupCount; // feature of an extension
335 return vEntryInfo[nEntry].eGroup;
338 // moves a window vertically
339 void MoveVertically (Window& rWin, long nOffset)
341 if (nOffset)
343 Point aPos = rWin.GetPosPixel();
344 aPos.Y() += nOffset;
345 rWin.SetPosPixel(aPos);
349 // moves a window vertically and optionally shows it
350 bool MoveAndShow (Window& rWin, long nOffset, long nMaxVisible, bool bShow)
352 // moves
353 Point aPos = rWin.GetPosPixel();
354 aPos.Y() += nOffset;
355 rWin.SetPosPixel(aPos);
356 // shows only if it is really visible
357 if (bShow)
358 bShow = aPos.Y() <= nMaxVisible && aPos.Y() + rWin.GetSizePixel().Height() >= 0;
359 rWin.Show(bShow);
360 return bShow;
363 } // namespace
368 // ColorConfigWindow_Impl::Chapter
371 // ctor for default groups
372 // rParent: parent window (ColorConfigWindow_Impl)
373 // eGroup: which group is this?
374 // rResMgr: resource manager
375 ColorConfigWindow_Impl::Chapter::Chapter (
376 ColorConfigWindow_Impl& Parent, Group eGroup, ResMgr& rResMgr
378 rParent(Parent),
379 aBackground(&rParent),
380 aText(&rParent, ResId(vGroupInfo[eGroup].nTextResId, rResMgr))
383 // ctor for extended groups
384 ColorConfigWindow_Impl::Chapter::Chapter (
385 ColorConfigWindow_Impl& Parent, ResMgr& rResMgr,
386 unsigned nYPos, rtl::OUString const& sDisplayName
388 rParent(Parent),
389 aBackground(&rParent),
390 aText(&rParent, ResId(FT_SQL_COMMAND, rResMgr))
392 Point const aTextPos = rParent.LogicToPixel(Point(FT_XPOS, nYPos), MAP_APPFONT);
393 Size const aTextSize = rParent.LogicToPixel(Size(FT_WIDTH, SEP_HEIGHT), MAP_APPFONT);
394 aText.SetPosSizePixel(aTextPos, aTextSize);
395 aText.SetText(sDisplayName);
399 void ColorConfigWindow_Impl::Chapter::Show (Wallpaper const& rBackWall)
401 { // background
402 Point const aBgPos(
403 rParent.LogicToPixel(Point(0, 0), MAP_APPFONT).X(),
404 aText.GetPosPixel().Y()
406 Size const aBgSize(
407 rParent.GetSizePixel().Width(),
408 rParent.LogicToPixel(Size(0, SEP_HEIGHT), MAP_APPFONT).Height()
410 aBackground.SetPosSizePixel(aBgPos, aBgSize);
411 aBackground.SetBackground(rBackWall);
412 aBackground.Show();
415 { // text
416 Font aFont = aText.GetFont();
417 aFont.SetWeight(WEIGHT_BOLD);
418 aText.SetFont(aFont);
419 aText.SetBackground(rBackWall);
420 aText.Show();
421 aText.SetZOrder(0, WINDOW_ZORDER_FIRST);
425 void ColorConfigWindow_Impl::Chapter::Hide ()
427 aBackground.Hide();
428 aText.Hide();
431 // moves the chapter title vertically by nOffset pixels
432 void ColorConfigWindow_Impl::Chapter::MoveVertically (long nOffset)
434 ::MoveVertically(aBackground, nOffset);
435 ::MoveVertically(aText, nOffset);
440 // ColorConfigWindow_Impl::Entry
443 // ctor for default entries
444 // pParent: parent window (ColorConfigWindow_Impl)
445 // iEntry: which entry is this? (in the vEntryInfo[] array above)
446 // rResMgr: resource manager
447 ColorConfigWindow_Impl::Entry::Entry (
448 Window& rParent, unsigned iEntry, ResMgr& rResMgr
450 aColorList(&rParent, ResId(vEntryInfo[iEntry].nColorListResId, rResMgr)),
451 aPreview(&rParent, ResId(vEntryInfo[iEntry].nPreviewResId, rResMgr)),
452 aDefaultColor(ColorConfig::GetDefaultColor(static_cast<ColorConfigEntry>(iEntry)))
454 // has checkbox?
455 if (vEntryInfo[iEntry].bCheckBox)
457 pText = boost::shared_ptr<CheckBox>( new CheckBox (
458 &rParent, ResId(vEntryInfo[iEntry].nTextResId, rResMgr)
459 ) );
461 else
463 pText = boost::shared_ptr<FixedText>( new FixedText (
464 &rParent, ResId(vEntryInfo[iEntry].nTextResId, rResMgr)
465 ) );
469 // ctor for extended entries
470 ColorConfigWindow_Impl::Entry::Entry (
471 Window& rParent, ResMgr& rResMgr,
472 unsigned nYPos, ExtendedColorConfigValue const& aColorEntry
474 pText(boost::shared_ptr<FixedText>(new FixedText (&rParent, ResId(FT_BASICERROR, rResMgr)))),
475 aColorList(&rParent, ResId(LB_BASICERROR, rResMgr)),
476 aPreview(&rParent, ResId(WN_BASICERROR, rResMgr)),
477 aDefaultColor(aColorEntry.getDefaultColor())
479 { // text (no checkbox)
480 FixedText* const pFixedText = static_cast<FixedText*>(pText.get());
481 Point const aTextPos = rParent.LogicToPixel(Point(FT_XPOS, nYPos), MAP_APPFONT);
482 Size const aTextSize = rParent.LogicToPixel(Size(FT_WIDTH, FT_HEIGHT), MAP_APPFONT);
483 pFixedText->SetPosSizePixel(aTextPos, aTextSize);
484 pFixedText->SetText(aColorEntry.getDisplayName());
486 { // color listbox
487 Point const aListPos = rParent.LogicToPixel(Point(LB_XPOS, nYPos), MAP_APPFONT);
488 Size const aListSize = rParent.LogicToPixel(Size(LB_WIDTH, LB_HEIGHT), MAP_APPFONT);
489 aColorList.SetPosSizePixel(aListPos, aListSize);
491 { // preview box
492 Point const aPreviewPos = rParent.LogicToPixel(Point(WN_XPOS, nYPos), MAP_APPFONT);
493 Size const aPreviewSize = rParent.LogicToPixel(Size(WN_WIDTH, WN_HEIGHT), MAP_APPFONT);
494 aPreview.SetPosSizePixel(aPreviewPos, aPreviewSize);
498 // moves entry vertically by nOffset pixels
499 void ColorConfigWindow_Impl::Entry::MoveVertically (long nOffset)
501 // moving all components
502 ::MoveVertically(*pText, nOffset);
503 ::MoveVertically(aColorList, nOffset);
504 ::MoveVertically(aPreview, nOffset);
507 // moves and shows
508 bool ColorConfigWindow_Impl::Entry::MoveAndShow (long nOffset, long nMaxVisible, bool bShow)
510 // if any of the items on the current line is visible, the
511 // whole line should be visible
512 bool bRes = false;
513 bRes = ::MoveAndShow(*pText, nOffset, nMaxVisible, bShow) || bRes;
514 bRes = ::MoveAndShow(aColorList, nOffset, nMaxVisible, bShow) || bRes;
515 bRes = ::MoveAndShow(aPreview, nOffset, nMaxVisible, bShow) || bRes;
516 return bRes;
519 void ColorConfigWindow_Impl::Entry::Show ()
521 pText->Show();
522 aColorList.Show();
523 aPreview.Show();
526 void ColorConfigWindow_Impl::Entry::Hide ()
528 pText->Hide();
529 aColorList.Hide();
530 aPreview.Hide();
533 // SetAppearance()
534 // iEntry: which entry is this?
535 // aTextWall: background of the text (transparent)
536 // aSampleList: sample color listbox (to copy from)
537 void ColorConfigWindow_Impl::Entry::SetAppearance (
538 unsigned iEntry, Wallpaper const& aTextWall,
539 ColorListBox const& aSampleList
541 // text (and optionally checkbox)
542 pText->SetBackground(aTextWall);
543 if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
544 pCheckBox->SetHelpId(vEntryInfo[iEntry].sCheckBoxHid);
545 // preview
546 aPreview.SetBorderStyle(WINDOW_BORDER_MONO);
547 // color list
548 aColorList.CopyEntries(aSampleList);
549 aColorList.InsertAutomaticEntryColor(aDefaultColor);
550 if (iEntry < ColorConfigEntryCount)
551 aColorList.SetHelpId(vEntryInfo[iEntry].sColorListHid);
554 // SetLinks()
555 void ColorConfigWindow_Impl::Entry::SetLinks (
556 Link const& aCheckLink, Link const& aColorLink, Link const& aGetFocusLink
558 aColorList.SetSelectHdl(aColorLink);
559 aColorList.SetGetFocusHdl(aGetFocusLink);
560 if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
562 pCheckBox->SetClickHdl(aCheckLink);
563 pCheckBox->SetGetFocusHdl(aGetFocusLink);
567 // fills the header bar
568 void ColorConfigWindow_Impl::Entry::SetHeader (
569 ColorConfigWindow_Impl const& rParent,
570 HeaderBar& rHeader, ResMgr& rResMgr
571 ) const {
572 // title strings
573 String const sTitle[] =
575 ResId(ST_ON, rResMgr),
576 ResId(ST_UIELEM, rResMgr),
577 ResId(ST_COLSET, rResMgr),
578 ResId(ST_PREVIEW, rResMgr),
580 // horizontal positions
581 unsigned const nX0 = 0;
582 unsigned const nX1 = rParent.vChapters.front()->GetLeft();
583 unsigned const nX2 = aColorList.GetPosPixel().X();
584 unsigned const nX3 = aPreview.GetPosPixel().X();
585 unsigned const nX4 = rHeader.GetSizePixel().Width();
586 // filling
587 WinBits const nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS;
588 rHeader.InsertItem(1, sTitle[0], nX1 - nX0, nHeadBits | HIB_CENTER);
589 rHeader.InsertItem(2, sTitle[1], nX2 - nX1, nHeadBits | HIB_LEFT);
590 rHeader.InsertItem(3, sTitle[2], nX3 - nX2, nHeadBits | HIB_LEFT);
591 rHeader.InsertItem(4, sTitle[3], nX4 - nX3, nHeadBits | HIB_LEFT);
594 // updates a default color config entry
595 void ColorConfigWindow_Impl::Entry::Update (
596 ColorConfigEntry aColorEntry, ColorConfigValue const& rValue
598 Color aColor;
599 if ((unsigned)rValue.nColor == COL_AUTO)
601 aColor = ColorConfig::GetDefaultColor(aColorEntry);
602 aColorList.SelectEntryPos(0);
604 else
606 aColor = Color(rValue.nColor);
607 aColorList.SelectEntry(aColor);
609 aPreview.SetBackground(Wallpaper(aColor));
610 if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
611 pCheckBox->Check(rValue.bIsVisible);
614 // updates an extended color config entry
615 void ColorConfigWindow_Impl::Entry::Update (
616 ExtendedColorConfigValue const& rValue
618 Color aColor(rValue.getColor());
619 if (rValue.getColor() == rValue.getDefaultColor())
620 aColorList.SelectEntryPos(0);
621 else
622 aColorList.SelectEntry(aColor);
623 SetColor(aColor);
626 // color of a default entry has changed
627 void ColorConfigWindow_Impl::Entry::ColorChanged (
628 ColorConfigEntry aColorEntry,
629 ColorConfigValue& rValue
631 Color aColor;
632 if (aColorList.IsAutomaticSelected())
634 aColor = ColorConfig::GetDefaultColor(aColorEntry);
635 rValue.nColor = COL_AUTO;
637 else
639 aColor = aColorList.GetSelectEntryColor();
640 rValue.nColor = aColor.GetColor();
642 SetColor(aColor);
645 // color of an extended entry has changed
646 void ColorConfigWindow_Impl::Entry::ColorChanged (
647 ExtendedColorConfigValue& rValue
649 Color aColor = aColorList.GetSelectEntryColor();
650 rValue.setColor(aColor.GetColor());
651 // automatic?
652 if (aColorList.GetSelectEntryPos() == 0)
654 rValue.setColor(rValue.getDefaultColor());
655 aColor.SetColor(rValue.getColor());
657 SetColor(aColor);
660 void ColorConfigWindow_Impl::Entry::SetColor (Color aColor)
662 aPreview.SetBackground(Wallpaper(aColor));
663 aPreview.Invalidate();
668 // ColorConfigWindow_Impl
671 ColorConfigWindow_Impl::ColorConfigWindow_Impl (Window* pParent, ResId const& rResId) :
672 Window(pParent, rResId)
674 CreateEntries(*rResId.GetResMgr());
675 Resource::FreeResource();
676 SetAppearance();
679 void ColorConfigWindow_Impl::CreateEntries (ResMgr& rResMgr)
681 // creating group headers
682 vChapters.reserve(nGroupCount);
683 for (unsigned i = 0; i != nGroupCount; ++i)
685 vChapters.push_back(boost::shared_ptr<Chapter> (
686 new Chapter( *this, static_cast<Group>(i), rResMgr ) ) );
689 // creating entries
690 vEntries.reserve(ColorConfigEntryCount);
691 for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
692 vEntries.push_back( boost::shared_ptr<Entry>(new Entry (*this, i, rResMgr) ) );
694 // calculate heights of groups which can be hidden
696 unsigned nNextY = GetPosBehindLastChapter(); // next Y coordinate
697 for (int i = nGroupCount - 1; i >= 0; --i)
699 unsigned nY = vChapters[i]->GetTop();
700 vChapters[i]->SetHeight(nNextY - nY);
701 nNextY = nY;
705 // extended entries
706 ExtendedColorConfig aExtConfig;
707 if (unsigned const nExtGroupCount = aExtConfig.GetComponentCount())
709 unsigned nLineNum = ( GetPosBehindLastChapter() /
710 LogicToPixel(Size(0, LINE_HEIGHT), MAP_APPFONT).Height() ) + 1;
711 for (unsigned j = 0; j != nExtGroupCount; ++j)
713 rtl::OUString const sComponentName = aExtConfig.GetComponentName(j);
714 vChapters.push_back(boost::shared_ptr<Chapter>(new Chapter (
715 *this, rResMgr, nLineNum * LINE_HEIGHT,
716 aExtConfig.GetComponentDisplayName(sComponentName)
717 )));
718 ++nLineNum;
719 unsigned nColorCount = aExtConfig.GetComponentColorCount(sComponentName);
720 for (unsigned i = 0; i != nColorCount; ++i)
722 ExtendedColorConfigValue const aColorEntry =
723 aExtConfig.GetComponentColorConfigValue(sComponentName, i);
724 vEntries.push_back(boost::shared_ptr<Entry>( new Entry (
725 *this, rResMgr, nLineNum * LINE_HEIGHT, aColorEntry
726 )));
727 ++nLineNum;
733 void ColorConfigWindow_Impl::SetAppearance ()
735 Color TempColor(COL_TRANSPARENT);
736 Wallpaper const aTransparentWall(TempColor);
737 StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
738 Color const aBackColor = rStyleSettings.GetHighContrastMode() ?
739 rStyleSettings.GetShadowColor() : Color(COL_LIGHTGRAY);
740 Wallpaper const aBackWall(aBackColor);
741 for (unsigned i = 0; i != vChapters.size(); ++i)
743 if (IsGroupVisible(static_cast<Group>(i)))
744 vChapters[i]->Show(aBackWall);
745 else
746 vChapters[i]->Hide();
748 SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
749 SetHelpId(HID_OPTIONS_COLORCONFIG_COLORLIST_WIN);
751 // #104195# when the window color is the same as the text color it has to be changed
752 Color aWinCol = rStyleSettings.GetWindowColor();
753 Color aRCheckCol = rStyleSettings.GetRadioCheckTextColor();
754 if (aWinCol == aRCheckCol)
756 aRCheckCol.Invert();
757 // if inversion didn't work (gray) then it's set to black
758 if (aRCheckCol == aWinCol)
759 aRCheckCol = Color(COL_BLACK);
760 // setting new text color for each entry
761 for (unsigned i = 0; i != vEntries.size(); ++i)
762 vEntries[i]->SetTextColor(aRCheckCol);
765 OSL_ENSURE( vEntries.size() >= sizeof vEntryInfo / sizeof vEntryInfo[0], "wrong number of helpIDs for color listboxes" );
767 // creating a sample color listbox with the color entries
768 ColorListBox aSampleColorList(this);
770 XColorListRef const xColorTable = XColorList::CreateStdColorList();
771 for (sal_Int32 i = 0; i != xColorTable->Count(); ++i)
773 XColorEntry& rEntry = *xColorTable->GetColor(i);
774 aSampleColorList.InsertEntry(rEntry.GetColor(), rEntry.GetName());
778 // positioning and appearance
779 Group eGroup = Group_Unknown;
780 for (unsigned i = 0; i != vEntries.size(); ++i)
782 Group const eNewGroup = GetGroup(i);
783 bool const bShow = IsGroupVisible(eNewGroup);
784 long const nDelta = bShow ? -GetDeltaAbove(eNewGroup) : 0;
786 // new group?
787 if (eNewGroup > eGroup)
789 eGroup = eNewGroup;
790 if (bShow)
791 vChapters[eGroup]->MoveVertically(nDelta);
793 // positioning
794 if (bShow)
795 vEntries[i]->MoveVertically(nDelta);
796 else
797 vEntries[i]->Hide();
798 // appearance
799 vEntries[i]->SetAppearance(i, aTransparentWall, aSampleColorList);
804 ColorConfigWindow_Impl::~ColorConfigWindow_Impl ()
807 void ColorConfigWindow_Impl::SetHeaderBar (
808 HeaderBar& rHeaderBar, ScrollBar const& rVScroll, ResMgr& rResMgr
810 rHeaderBar.SetPosSizePixel(
811 Point(0, 0),
812 Size(GetParent()->GetOutputSizePixel().Width(), rVScroll.GetPosPixel().Y())
814 vEntries.front()->SetHeader(*this, rHeaderBar, rResMgr);
815 rHeaderBar.Show();
818 void ColorConfigWindow_Impl::SetScrollBar (ScrollBar& rVScroll)
820 rVScroll.EnableDrag();
821 rVScroll.Show();
822 rVScroll.SetRangeMin(0);
823 unsigned const nScrollOffset =
824 vEntries[1]->GetTop() - vEntries[0]->GetTop();
825 unsigned const nVisibleEntries = GetSizePixel().Height() / nScrollOffset;
827 rVScroll.SetRangeMax(vEntries.size() + vChapters.size());
828 { // dynamic: calculate the hidden lines
829 unsigned nInvisibleLines = 0;
830 Group eGroup = Group_Unknown;
831 for (unsigned i = 0; i != vEntries.size(); ++i)
833 Group const eNewGroup = GetGroup(i);
834 bool const bVisible = IsGroupVisible(eNewGroup);
835 if (!bVisible)
836 nInvisibleLines++;
837 if (eNewGroup > eGroup)
839 eGroup = eNewGroup;
840 if (!bVisible)
841 nInvisibleLines++;
844 rVScroll.SetRangeMax(rVScroll.GetRangeMax() - nInvisibleLines);
847 rVScroll.SetPageSize(nVisibleEntries - 1);
848 rVScroll.SetVisibleSize(nVisibleEntries);
851 // SetLinks()
852 void ColorConfigWindow_Impl::SetLinks (
853 Link const& aCheckLink, Link const& aColorLink, Link const& aGetFocusLink
855 for (unsigned i = 0; i != vEntries.size(); ++i)
856 vEntries[i]->SetLinks(aCheckLink, aColorLink, aGetFocusLink);
859 // Update()
860 void ColorConfigWindow_Impl::Update (
861 EditableColorConfig const* pConfig,
862 EditableExtendedColorConfig const* pExtConfig
864 // updating default entries
865 for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
867 ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
868 vEntries[i]->Update(
869 aColorEntry, pConfig->GetColorValue(aColorEntry)
873 // updating extended entries
874 unsigned i = ColorConfigEntryCount;
875 unsigned const nExtCount = pExtConfig->GetComponentCount();
876 for (unsigned j = 0; j != nExtCount; ++j)
878 rtl::OUString sComponentName = pExtConfig->GetComponentName(j);
879 unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
880 for (unsigned k = 0; i != vEntries.size() && k != nColorCount; ++i, ++k)
881 vEntries[i]->Update(
882 pExtConfig->GetComponentColorConfigValue(sComponentName, k)
887 // ScrollHdl()
888 void ColorConfigWindow_Impl::ScrollHdl (long& nScrollPos, ScrollBar const& rVScroll)
890 SetUpdateMode(true);
891 long const nOffset =
892 (vEntries[1]->GetTop() - vEntries[0]->GetTop()) *
893 (nScrollPos - rVScroll.GetThumbPos());
894 nScrollPos = rVScroll.GetThumbPos();
895 long const nWindowHeight = GetSizePixel().Height();
896 int nFirstVisible = -1, nLastVisible = -1;
897 for (unsigned i = 0; i != vEntries.size(); ++i)
899 //controls outside of the view need to be hidden to speed up accessibility tools
900 bool const bShowCtrl = IsGroupVisible(GetGroup(i));
901 if (vEntries[i]->MoveAndShow(nOffset, nWindowHeight, bShowCtrl))
903 if (nFirstVisible == -1)
904 nFirstVisible = i;
905 else
906 nLastVisible = i;
910 // show the one prior to the first visible and the first after the last visble control
911 // to enable KEY_TAB travelling
912 if(nFirstVisible > 0)
914 --nFirstVisible;
915 if (IsGroupVisible(GetGroup(nFirstVisible)))
916 vEntries[nFirstVisible]->Show();
918 if (nLastVisible != -1 && (unsigned)nLastVisible < vEntries.size() - 1)
920 ++nLastVisible;
921 if (IsGroupVisible(GetGroup(nLastVisible)))
922 vEntries[nLastVisible]->Show();
925 for (unsigned i = 0; i != vChapters.size(); ++i)
926 vChapters[i]->MoveVertically(nOffset);
927 SetUpdateMode(true);
930 // ClickHdl()
931 void ColorConfigWindow_Impl::ClickHdl (EditableColorConfig* pConfig, CheckBox* pBox)
933 for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
935 if (vEntries[i]->Is(pBox))
937 ColorConfigEntry const aEntry = static_cast<ColorConfigEntry>(i);
938 ColorConfigValue aValue = pConfig->GetColorValue(aEntry);
939 aValue.bIsVisible = pBox->IsChecked();
940 pConfig->SetColorValue(aEntry, aValue);
941 break;
946 // ColorHdl()
947 void ColorConfigWindow_Impl::ColorHdl (
948 EditableColorConfig* pConfig, EditableExtendedColorConfig* pExtConfig,
949 ColorListBox* pBox
951 unsigned i = 0;
953 // default entries
954 for ( ; i != ColorConfigEntryCount; ++i)
956 if (pBox && vEntries[i]->Is(pBox))
958 ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
959 ColorConfigValue aValue = pConfig->GetColorValue(aColorEntry);
960 vEntries[i]->ColorChanged(aColorEntry, aValue);
961 pConfig->SetColorValue(aColorEntry, aValue);
962 break;
966 // extended entries
967 unsigned const nExtCount = pExtConfig->GetComponentCount();
968 for (unsigned j = 0; j != nExtCount; ++j)
970 rtl::OUString sComponentName = pExtConfig->GetComponentName(j);
971 unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
972 unsigned const nCount = vEntries.size();
973 for (unsigned k = 0; i != nCount && k != nColorCount; ++i, ++k)
975 if (pBox && vEntries[i]->Is(pBox))
977 ExtendedColorConfigValue aValue =
978 pExtConfig->GetComponentColorConfigValue(sComponentName, k);
979 vEntries[i]->ColorChanged(aValue);
980 pExtConfig->SetColorValue(sComponentName, aValue);
981 break;
988 // IsGroupVisible()
989 bool ColorConfigWindow_Impl::IsGroupVisible (Group eGroup) const
991 switch (eGroup)
993 case Group_Writer:
994 case Group_Html:
995 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SWRITER);
997 case Group_Calc:
998 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SCALC);
1000 case Group_Draw:
1001 return
1002 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDRAW) ||
1003 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SIMPRESS);
1005 case Group_Sql:
1006 return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDATABASE);
1008 default:
1009 return true;
1013 // calculate position behind last chapter
1014 unsigned ColorConfigWindow_Impl::GetPosBehindLastChapter () const
1016 int nLastY = vEntries.back()->GetBottom();
1017 nLastY += LogicToPixel( Size(0, 3), MAP_APPFONT ).Height();
1018 return nLastY;
1021 // calculates the overall height of the invisible groups above eGroup
1022 long ColorConfigWindow_Impl::GetDeltaAbove (Group eGroup) const
1024 long nDelta = 0;
1025 for (int i = 0; i != eGroup; ++i)
1026 if (!IsGroupVisible(static_cast<Group>(i)))
1027 nDelta += vChapters[i]->GetHeight();
1028 return nDelta;
1031 void ColorConfigWindow_Impl::DataChanged (DataChangedEvent const& rDCEvt)
1033 Window::DataChanged( rDCEvt );
1034 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1035 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1037 StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
1038 bool const bHighContrast = rStyleSettings.GetHighContrastMode();
1039 Wallpaper const aBackWall(Color(bHighContrast ? COL_TRANSPARENT : COL_LIGHTGRAY));
1040 for (unsigned i = 0; i != vChapters.size(); ++i)
1041 vChapters[i]->SetBackground(aBackWall);
1042 SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
1047 void ColorConfigWindow_Impl::Command( const CommandEvent& rCEvt )
1049 GetParent()->Command(rCEvt);
1053 // ColorConfigCtrl_Impl
1056 class ColorConfigCtrl_Impl : public Control
1058 HeaderBar aHeaderHB;
1059 ScrollBar aVScroll;
1061 ColorConfigWindow_Impl aScrollWindow;
1063 EditableColorConfig* pColorConfig;
1064 EditableExtendedColorConfig* pExtColorConfig;
1066 long nScrollPos;
1068 DECL_LINK(ScrollHdl, ScrollBar*);
1069 DECL_LINK(ClickHdl, CheckBox*);
1070 DECL_LINK(ColorHdl, ColorListBox*);
1071 DECL_LINK(ControlFocusHdl, Control*);
1073 virtual long PreNotify (NotifyEvent& rNEvt);
1074 virtual void Command (CommandEvent const& rCEvt);
1075 virtual void DataChanged (DataChangedEvent const& rDCEvt);
1076 public:
1077 ColorConfigCtrl_Impl (Window* pParent, ResId const& rResId);
1078 ~ColorConfigCtrl_Impl ();
1080 void SetConfig (EditableColorConfig& rConfig) { pColorConfig = &rConfig; }
1081 void SetExtendedConfig (EditableExtendedColorConfig& rConfig) { pExtColorConfig = &rConfig; }
1082 void Update ();
1083 long GetScrollPosition () { return aVScroll.GetThumbPos(); }
1084 void SetScrollPosition (long nSet)
1086 aVScroll.SetThumbPos(nSet);
1087 ScrollHdl(&aVScroll);
1091 ColorConfigCtrl_Impl::ColorConfigCtrl_Impl (
1092 Window* pParent, ResId const& rResId
1094 Control(pParent, rResId),
1096 aHeaderHB(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
1097 aVScroll(this, ResId(VB_VSCROLL, *rResId.GetResMgr())),
1098 aScrollWindow(this, ResId(WN_SCROLL, *rResId.GetResMgr())),
1100 pColorConfig(0),
1101 pExtColorConfig(0),
1102 nScrollPos(0)
1104 aScrollWindow.SetHeaderBar(aHeaderHB, aVScroll, *rResId.GetResMgr());
1105 aScrollWindow.SetScrollBar(aVScroll);
1107 Resource::FreeResource();
1109 Link aScrollLink = LINK(this, ColorConfigCtrl_Impl, ScrollHdl);
1110 aVScroll.SetScrollHdl(aScrollLink);
1111 aVScroll.SetEndScrollHdl(aScrollLink);
1113 Link aCheckLink = LINK(this, ColorConfigCtrl_Impl, ClickHdl);
1114 Link aColorLink = LINK(this, ColorConfigCtrl_Impl, ColorHdl);
1115 Link aGetFocusLink = LINK(this, ColorConfigCtrl_Impl, ControlFocusHdl);
1116 aScrollWindow.SetLinks(aCheckLink, aColorLink, aGetFocusLink);
1119 ColorConfigCtrl_Impl::~ColorConfigCtrl_Impl()
1123 void ColorConfigCtrl_Impl::Update ()
1125 DBG_ASSERT(pColorConfig, "Configuration not set");
1126 aScrollWindow.Update(pColorConfig, pExtColorConfig);
1129 IMPL_LINK(ColorConfigCtrl_Impl, ScrollHdl, ScrollBar*, pScrollBar)
1131 aScrollWindow.ScrollHdl(nScrollPos, *pScrollBar);
1132 return 0;
1135 long ColorConfigCtrl_Impl::PreNotify( NotifyEvent& rNEvt )
1137 if(rNEvt.GetType() == EVENT_COMMAND)
1139 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
1140 sal_uInt16 nCmd = pCEvt->GetCommand();
1141 if( COMMAND_WHEEL == nCmd )
1143 Command(*pCEvt);
1144 return 1;
1147 return Control::PreNotify(rNEvt);
1150 void ColorConfigCtrl_Impl::Command( const CommandEvent& rCEvt )
1152 switch ( rCEvt.GetCommand() )
1155 case COMMAND_WHEEL:
1156 case COMMAND_STARTAUTOSCROLL:
1157 case COMMAND_AUTOSCROLL:
1159 const CommandWheelData* pWheelData = rCEvt.GetWheelData();
1160 if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
1162 HandleScrollCommand( rCEvt, 0, &aVScroll );
1165 break;
1166 default:
1167 Control::Command(rCEvt);
1171 void ColorConfigCtrl_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1173 Window::DataChanged( rDCEvt );
1174 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1175 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1177 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1178 SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
1182 IMPL_LINK(ColorConfigCtrl_Impl, ClickHdl, CheckBox*, pBox)
1184 DBG_ASSERT(pColorConfig, "Configuration not set");
1185 aScrollWindow.ClickHdl(pColorConfig, pBox);
1186 return 0;
1189 // a color list has changed
1190 IMPL_LINK(ColorConfigCtrl_Impl, ColorHdl, ColorListBox*, pBox)
1192 DBG_ASSERT(pColorConfig, "Configuration not set" );
1193 if (pBox)
1194 aScrollWindow.ColorHdl(pColorConfig, pExtColorConfig, pBox);
1195 return 0;
1197 IMPL_LINK(ColorConfigCtrl_Impl, ControlFocusHdl, Control*, pCtrl)
1199 // determine whether a control is completely visible
1200 // and make it visible
1201 long aCtrlPosY = pCtrl->GetPosPixel().Y();
1202 unsigned const nWinHeight = aScrollWindow.GetSizePixel().Height();
1203 unsigned const nEntryHeight = aScrollWindow.GetEntryHeight();
1204 if (0 != (GETFOCUS_TAB & pCtrl->GetGetFocusFlags()) &&
1205 (aCtrlPosY < 0 || nWinHeight < aCtrlPosY + nEntryHeight)
1207 long nThumbPos = aVScroll.GetThumbPos();
1208 if (nWinHeight < aCtrlPosY + nEntryHeight)
1210 //scroll down
1211 nThumbPos += 2;
1213 else
1215 //scroll up
1216 nThumbPos -= 2;
1217 if(nThumbPos < 0)
1218 nThumbPos = 0;
1220 aVScroll.SetThumbPos(nThumbPos);
1221 ScrollHdl(&aVScroll);
1223 return 0;
1228 // SvxColorOptionsTabPage
1231 SvxColorOptionsTabPage::SvxColorOptionsTabPage(
1232 Window* pParent, const SfxItemSet& rCoreSet) :
1233 SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_COLORCONFIG ), rCoreSet ),
1234 aColorSchemeFL( this, CUI_RES( FL_COLORSCHEME ) ),
1235 aColorSchemeFT( this, CUI_RES( FT_COLORSCHEME ) ),
1236 aColorSchemeLB( this, CUI_RES( LB_COLORSCHEME ) ),
1237 aSaveSchemePB( this, CUI_RES( PB_SAVESCHEME) ),
1238 aDeleteSchemePB( this, CUI_RES( PB_DELETESCHEME ) ),
1239 aCustomColorsFL( this, CUI_RES( FL_CUSTOMCOLORS ) ),
1240 bFillItemSetCalled(sal_False),
1241 pColorConfig(0),
1242 pExtColorConfig(0),
1243 pColorConfigCT( new ColorConfigCtrl_Impl(this, CUI_RES( CT_COLORCONFIG ) ))
1245 FreeResource();
1246 aColorSchemeLB.SetSelectHdl(LINK(this, SvxColorOptionsTabPage, SchemeChangedHdl_Impl));
1247 Link aLk = LINK(this, SvxColorOptionsTabPage, SaveDeleteHdl_Impl );
1248 aSaveSchemePB.SetClickHdl(aLk);
1249 aDeleteSchemePB.SetClickHdl(aLk);
1252 SvxColorOptionsTabPage::~SvxColorOptionsTabPage()
1254 //when the dialog is cancelled but the color scheme ListBox has been changed these
1255 //changes need to be undone
1256 if(!bFillItemSetCalled && aColorSchemeLB.GetSavedValue() != aColorSchemeLB.GetSelectEntryPos())
1258 rtl::OUString sOldScheme = aColorSchemeLB.GetEntry(aColorSchemeLB.GetSavedValue());
1259 if(!sOldScheme.isEmpty())
1261 pColorConfig->SetCurrentSchemeName(sOldScheme);
1262 pExtColorConfig->SetCurrentSchemeName(sOldScheme);
1265 delete pColorConfigCT;
1266 pColorConfig->ClearModified();
1267 pColorConfig->EnableBroadcast();
1268 delete pColorConfig;
1269 pExtColorConfig->ClearModified();
1270 pExtColorConfig->EnableBroadcast();
1271 delete pExtColorConfig;
1274 SfxTabPage* SvxColorOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1276 return ( new SvxColorOptionsTabPage( pParent, rAttrSet ) );
1279 sal_Bool SvxColorOptionsTabPage::FillItemSet( SfxItemSet& )
1281 bFillItemSetCalled = sal_True;
1282 if(aColorSchemeLB.GetSavedValue() != aColorSchemeLB.GetSelectEntryPos())
1284 pColorConfig->SetModified();
1285 pExtColorConfig->SetModified();
1287 if(pColorConfig->IsModified())
1288 pColorConfig->Commit();
1289 if(pExtColorConfig->IsModified())
1290 pExtColorConfig->Commit();
1291 return sal_True;
1294 void SvxColorOptionsTabPage::Reset( const SfxItemSet& )
1296 if(pColorConfig)
1298 pColorConfig->ClearModified();
1299 pColorConfig->DisableBroadcast();
1300 delete pColorConfig;
1302 pColorConfig = new EditableColorConfig;
1303 pColorConfigCT->SetConfig(*pColorConfig);
1305 if(pExtColorConfig)
1307 pExtColorConfig->ClearModified();
1308 pExtColorConfig->DisableBroadcast();
1309 delete pExtColorConfig;
1311 pExtColorConfig = new EditableExtendedColorConfig;
1312 pColorConfigCT->SetExtendedConfig(*pExtColorConfig);
1314 String sUser = GetUserData();
1315 //has to be called always to speed up accessibility tools
1316 pColorConfigCT->SetScrollPosition(sUser.ToInt32());
1317 aColorSchemeLB.Clear();
1318 uno::Sequence< ::rtl::OUString > aSchemes = pColorConfig->GetSchemeNames();
1319 const rtl::OUString* pSchemes = aSchemes.getConstArray();
1320 for(sal_Int32 i = 0; i < aSchemes.getLength(); i++)
1321 aColorSchemeLB.InsertEntry(pSchemes[i]);
1322 aColorSchemeLB.SelectEntry(pColorConfig->GetCurrentSchemeName());
1323 aColorSchemeLB.SaveValue();
1324 aDeleteSchemePB.Enable( aSchemes.getLength() > 1 );
1325 UpdateColorConfig();
1328 int SvxColorOptionsTabPage::DeactivatePage( SfxItemSet* pSet_ )
1330 if ( pSet_ )
1331 FillItemSet( *pSet_ );
1332 return( LEAVE_PAGE );
1335 void SvxColorOptionsTabPage::UpdateColorConfig()
1337 //update the color config control
1338 pColorConfigCT->Update();
1341 IMPL_LINK(SvxColorOptionsTabPage, SchemeChangedHdl_Impl, ListBox*, pBox)
1343 pColorConfig->LoadScheme(pBox->GetSelectEntry());
1344 pExtColorConfig->LoadScheme(pBox->GetSelectEntry());
1345 UpdateColorConfig();
1346 return 0;
1349 IMPL_LINK(SvxColorOptionsTabPage, SaveDeleteHdl_Impl, PushButton*, pButton )
1351 if(&aSaveSchemePB == pButton)
1353 String sName;
1355 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1356 DBG_ASSERT(pFact, "Dialogdiet fail!");
1357 AbstractSvxNameDialog* aNameDlg = pFact->CreateSvxNameDialog( pButton,
1358 sName, String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE2)) );
1359 DBG_ASSERT(aNameDlg, "Dialogdiet fail!");
1360 aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
1361 aNameDlg->SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE1)));
1362 aNameDlg->SetHelpId(HID_OPTIONS_COLORCONFIG_SAVE_SCHEME);
1363 aNameDlg->SetEditHelpId(HID_OPTIONS_COLORCONFIG_NAME_SCHEME);
1364 aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
1365 if(RET_OK == aNameDlg->Execute())
1367 aNameDlg->GetName(sName);
1368 pColorConfig->AddScheme(sName);
1369 pExtColorConfig->AddScheme(sName);
1370 aColorSchemeLB.InsertEntry(sName);
1371 aColorSchemeLB.SelectEntry(sName);
1372 aColorSchemeLB.GetSelectHdl().Call(&aColorSchemeLB);
1374 delete aNameDlg;
1376 else
1378 DBG_ASSERT(aColorSchemeLB.GetEntryCount() > 1, "don't delete the last scheme");
1379 QueryBox aQuery(pButton, CUI_RES(RID_SVXQB_DELETE_COLOR_CONFIG));
1380 aQuery.SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_DELETE)));
1381 if(RET_YES == aQuery.Execute())
1383 rtl::OUString sDeleteScheme(aColorSchemeLB.GetSelectEntry());
1384 aColorSchemeLB.RemoveEntry(aColorSchemeLB.GetSelectEntryPos());
1385 aColorSchemeLB.SelectEntryPos(0);
1386 aColorSchemeLB.GetSelectHdl().Call(&aColorSchemeLB);
1387 //first select the new scheme and then delete the old one
1388 pColorConfig->DeleteScheme(sDeleteScheme);
1389 pExtColorConfig->DeleteScheme(sDeleteScheme);
1392 aDeleteSchemePB.Enable( aColorSchemeLB.GetEntryCount() > 1 );
1393 return 0;
1396 IMPL_LINK(SvxColorOptionsTabPage, CheckNameHdl_Impl, AbstractSvxNameDialog*, pDialog )
1398 String sName;
1399 pDialog->GetName(sName);
1400 return sName.Len() && LISTBOX_ENTRY_NOTFOUND == aColorSchemeLB.GetEntryPos( sName );
1403 void SvxColorOptionsTabPage::FillUserData()
1405 SetUserData(String::CreateFromInt32(pColorConfigCT->GetScrollPosition()));
1408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */