Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <bitset>
23 :
24 : #include <svtools/colorcfg.hxx>
25 : #include <svtools/extcolorcfg.hxx>
26 : #include <svtools/headbar.hxx>
27 : #include <svtools/ctrlbox.hxx>
28 : #include <vcl/scrbar.hxx>
29 : #include <svx/xtable.hxx>
30 : #include <unotools/moduleoptions.hxx>
31 : #include <unotools/pathoptions.hxx>
32 : #include <vcl/msgbox.hxx>
33 : #include <vcl/settings.hxx>
34 : #include <boost/shared_ptr.hpp>
35 : #include <svx/svxdlg.hxx>
36 : #include <helpid.hrc>
37 : #include <dialmgr.hxx>
38 : #include "optcolor.hxx"
39 : #include <cuires.hrc>
40 : #include <svx/dlgutil.hxx>
41 :
42 : using namespace ::com::sun::star;
43 : using namespace ::svtools;
44 :
45 : namespace
46 : {
47 :
48 : // list of default groups
49 : enum Group
50 : {
51 : Group_Unknown = -1,
52 :
53 : Group_General,
54 : Group_Writer,
55 : Group_Html,
56 : Group_Calc,
57 : Group_Draw,
58 : Group_Basic,
59 : Group_Sql,
60 :
61 : nGroupCount
62 : };
63 :
64 : // group data
65 : struct
66 : {
67 : // group
68 : Group eGroup;
69 : // .ui group name
70 : const char *pGroup;
71 : }
72 : const vGroupInfo[] =
73 : {
74 : // the groups are in the same order as in enum Group above
75 : { Group_General, "general" },
76 : { Group_Writer, "writer" },
77 : { Group_Html, "html" },
78 : { Group_Calc, "calc" },
79 : { Group_Draw, "draw" },
80 : { Group_Basic, "basic" },
81 : { Group_Sql, "sql" }
82 : };
83 :
84 : // color config entry data (see ColorConfigWindow_Impl::Entry below)
85 : struct
86 : {
87 : // group
88 : Group eGroup;
89 : //checkbox (or simple text)
90 : const char *pText;
91 : //color listbox
92 : const char *pColor;
93 : //preview box
94 : const char *pPreview;
95 : // has checkbox?
96 : bool bCheckBox;
97 : }
98 : const vEntryInfo[] =
99 : {
100 : #define IDS(Name) \
101 : SAL_STRINGIFY(Name), SAL_STRINGIFY(Name##_lb), SAL_STRINGIFY(Name##_wn), false
102 :
103 : #define IDS_CB(Name) \
104 : SAL_STRINGIFY(Name), SAL_STRINGIFY(Name##_lb), SAL_STRINGIFY(Name##_wn), true
105 :
106 : // The list of these entries (enum ColorConfigEntry) are in colorcfg.hxx.
107 :
108 : { Group_General, IDS(doccolor) },
109 : { Group_General, IDS_CB(docboundaries) },
110 : { Group_General, IDS(appback) },
111 : { Group_General, IDS_CB(objboundaries) },
112 : { Group_General, IDS_CB(tblboundaries) },
113 : { Group_General, IDS(font) },
114 : { Group_General, IDS_CB(unvisitedlinks) },
115 : { Group_General, IDS_CB(visitedlinks) },
116 : { Group_General, IDS(autospellcheck) },
117 : { Group_General, IDS(smarttags) },
118 : { Group_General, IDS_CB(shadows) },
119 :
120 : { Group_Writer, IDS(writergrid) },
121 : { Group_Writer, IDS_CB(field) },
122 : { Group_Writer, IDS_CB(index) },
123 : { Group_Writer, IDS(direct) },
124 : { Group_Writer, IDS(script) },
125 : { Group_Writer, IDS_CB(section) },
126 : { Group_Writer, IDS(hdft) },
127 : { Group_Writer, IDS(pagebreak) },
128 :
129 : { Group_Html, IDS(sgml) },
130 : { Group_Html, IDS(htmlcomment) },
131 : { Group_Html, IDS(htmlkeyword) },
132 : { Group_Html, IDS(unknown) },
133 :
134 : { Group_Calc, IDS(calcgrid) },
135 : { Group_Calc, IDS(brk) },
136 : { Group_Calc, IDS(brkmanual) },
137 : { Group_Calc, IDS(brkauto) },
138 : { Group_Calc, IDS(det) },
139 : { Group_Calc, IDS(deterror) },
140 : { Group_Calc, IDS(ref) },
141 : { Group_Calc, IDS(notes) },
142 :
143 : { Group_Draw, IDS(drawgrid) },
144 :
145 : { Group_Basic, IDS(basicid) },
146 : { Group_Basic, IDS(basiccomment) },
147 : { Group_Basic, IDS(basicnumber) },
148 : { Group_Basic, IDS(basicstring) },
149 : { Group_Basic, IDS(basicop) },
150 : { Group_Basic, IDS(basickeyword) },
151 : { Group_Basic, IDS(error) },
152 :
153 : { Group_Sql, IDS(sqlid) },
154 : { Group_Sql, IDS(sqlnumber) },
155 : { Group_Sql, IDS(sqlstring) },
156 : { Group_Sql, IDS(sqlop) },
157 : { Group_Sql, IDS(sqlkeyword) },
158 : { Group_Sql, IDS(sqlparam) },
159 : { Group_Sql, IDS(sqlcomment) }
160 :
161 : #undef IDS
162 : };
163 :
164 : } // namespace
165 :
166 :
167 : // ColorConfigWindow_Impl
168 :
169 :
170 : class ColorConfigWindow_Impl
171 : : public VclContainer
172 : , public VclBuilderContainer
173 : {
174 : public:
175 : ColorConfigWindow_Impl(Window* pParent);
176 : virtual ~ColorConfigWindow_Impl();
177 :
178 : public:
179 : void SetLinks (Link const&, Link const&, Link const&);
180 0 : unsigned GetEntryHeight () const { return vEntries[0]->GetHeight(); }
181 : void Update (EditableColorConfig const*, EditableExtendedColorConfig const*);
182 : void ScrollHdl(const ScrollBar&);
183 : void ClickHdl (EditableColorConfig*, CheckBox*);
184 : void ColorHdl (EditableColorConfig*, EditableExtendedColorConfig*, ColorListBox*);
185 : void Init(ScrollBar *pVScroll, HeaderBar *m_pHeaderHB);
186 : void AdjustScrollBar();
187 : void AdjustHeaderBar();
188 :
189 : private:
190 : // Chapter -- horizontal group separator stripe with text
191 : class Chapter
192 : {
193 : // text
194 : bool m_bOwnsWidget;
195 : FixedText *m_pText;
196 : public:
197 : Chapter(FixedText *pText, bool bShow);
198 : Chapter(Window *pGrid, unsigned nYPos, const OUString& sDisplayName);
199 : ~Chapter();
200 : public:
201 0 : void SetBackground(const Wallpaper& W) { m_pText->SetBackground(W); }
202 : long GetHeight() const { return m_pText->GetSizePixel().Height(); }
203 : long GetLeft() const { return m_pText->GetPosPixel().X(); }
204 : void Show(const Wallpaper& rBackWall);
205 : void Hide();
206 : };
207 :
208 : // Entry -- a color config entry:
209 : // text (checkbox) + color list box + preview box
210 : class Entry
211 : {
212 : public:
213 : Entry(ColorConfigWindow_Impl& rParent, unsigned iEntry, long nCheckBoxLabelOffset, bool bShow);
214 : Entry(Window* pGrid, unsigned nYPos, const ExtendedColorConfigValue& aColorEntry,
215 : long nCheckBoxLabelOffset);
216 : ~Entry();
217 : public:
218 : void Show ();
219 : void Hide ();
220 : void SetAppearance(Wallpaper const& aTextWall, ColorListBox const& aSampleList);
221 0 : void SetTextColor (Color C) { m_pText->SetTextColor(C); }
222 : public:
223 : void SetLinks (Link const&, Link const&, Link const&);
224 : void Update (ColorConfigEntry, ColorConfigValue const&);
225 : void Update (ExtendedColorConfigValue const&);
226 : void ColorChanged (ColorConfigEntry, ColorConfigValue&);
227 : void ColorChanged (ExtendedColorConfigValue&);
228 : public:
229 0 : long GetTop () const { return m_pPreview->GetPosPixel().Y(); }
230 : long GetBottom () const { return GetTop() + m_pPreview->GetSizePixel().Height(); }
231 0 : unsigned GetHeight () const { return m_pColorList->GetSizePixel().Height(); }
232 : public:
233 0 : bool Is (CheckBox* pBox) const { return m_pText == pBox; }
234 0 : bool Is (ColorListBox* pBox) const { return m_pColorList == pBox; }
235 :
236 : private:
237 : bool m_bOwnsWidgets;
238 : // checkbox (CheckBox) or simple text (FixedText)
239 : Control* m_pText;
240 : // color list box
241 : ColorListBox* m_pColorList;
242 : // color preview box
243 : Window* m_pPreview;
244 : // default color
245 : Color m_aDefaultColor;
246 : private:
247 : void SetColor (Color);
248 : };
249 :
250 : // vChapters -- groups (group headers)
251 : std::vector<boost::shared_ptr<Chapter> > vChapters;
252 : // vEntries -- color options
253 : std::vector<boost::shared_ptr<Entry> > vEntries;
254 :
255 : // module options
256 : SvtModuleOptions aModuleOptions;
257 :
258 :
259 : private:
260 : VclGrid *m_pGrid;
261 : ScrollBar *m_pVScroll;
262 : HeaderBar *m_pHeaderHB;
263 :
264 : // initialization
265 : void CreateEntries();
266 : void SetAppearance();
267 :
268 : private:
269 : virtual void Command (CommandEvent const& rCEvt) SAL_OVERRIDE;
270 : virtual void DataChanged (DataChangedEvent const& rDCEvt) SAL_OVERRIDE;
271 :
272 : virtual Size calculateRequisition() const SAL_OVERRIDE;
273 : virtual void setAllocation(const Size &rAllocation) SAL_OVERRIDE;
274 :
275 : bool IsGroupVisible (Group) const;
276 : };
277 :
278 :
279 : // ColorConfigWindow_Impl::Chapter
280 :
281 :
282 : // ctor for default groups
283 : // rParent: parent window (ColorConfigWindow_Impl)
284 : // eGroup: which group is this?
285 : // rResMgr: resource manager
286 0 : ColorConfigWindow_Impl::Chapter::Chapter(FixedText* pText, bool bShow)
287 : : m_bOwnsWidget(false)
288 0 : , m_pText(pText)
289 : {
290 0 : if (!bShow)
291 0 : Hide();
292 0 : }
293 :
294 : // ctor for extended groups
295 0 : ColorConfigWindow_Impl::Chapter::Chapter(Window *pGrid,
296 : unsigned nYPos, const OUString& rDisplayName)
297 0 : : m_bOwnsWidget(true)
298 : {
299 0 : m_pText = new FixedText(pGrid, WB_LEFT|WB_VCENTER|WB_3DLOOK);
300 0 : m_pText->set_font_attribute("weight", "bold");
301 0 : m_pText->set_grid_width(3);
302 0 : m_pText->set_grid_left_attach(0);
303 0 : m_pText->set_grid_top_attach(nYPos);
304 0 : m_pText->SetText(rDisplayName);
305 0 : }
306 :
307 0 : ColorConfigWindow_Impl::Chapter::~Chapter()
308 : {
309 0 : if (m_bOwnsWidget)
310 0 : delete m_pText;
311 0 : }
312 :
313 0 : void ColorConfigWindow_Impl::Chapter::Show(Wallpaper const& rBackWall)
314 : {
315 : // background
316 0 : m_pText->SetBackground(rBackWall);
317 0 : m_pText->Show();
318 0 : }
319 :
320 0 : void ColorConfigWindow_Impl::Chapter::Hide ()
321 : {
322 0 : m_pText->Hide();
323 0 : }
324 :
325 :
326 : // ColorConfigWindow_Impl::Entry
327 :
328 :
329 0 : ColorConfigWindow_Impl::Entry::Entry(ColorConfigWindow_Impl& rParent, unsigned iEntry,
330 : long nCheckBoxLabelOffset, bool bShow)
331 : : m_bOwnsWidgets(false)
332 0 : , m_aDefaultColor(ColorConfig::GetDefaultColor(static_cast<ColorConfigEntry>(iEntry)))
333 : {
334 0 : rParent.get(m_pText, vEntryInfo[iEntry].pText);
335 0 : if (!vEntryInfo[iEntry].bCheckBox)
336 : {
337 0 : m_pText->set_margin_left(m_pText->get_margin_left() +
338 0 : nCheckBoxLabelOffset);
339 : }
340 0 : rParent.get(m_pColorList, vEntryInfo[iEntry].pColor);
341 0 : rParent.get(m_pPreview, vEntryInfo[iEntry].pPreview);
342 :
343 0 : if (!bShow)
344 0 : Hide();
345 0 : }
346 :
347 : // ctor for extended entries
348 0 : ColorConfigWindow_Impl::Entry::Entry( Window *pGrid, unsigned nYPos,
349 : ExtendedColorConfigValue const& rColorEntry, long nCheckBoxLabelOffset)
350 : : m_bOwnsWidgets(true)
351 0 : , m_aDefaultColor(rColorEntry.getDefaultColor())
352 : {
353 0 : m_pText = new FixedText(pGrid, WB_LEFT|WB_VCENTER|WB_3DLOOK);
354 0 : m_pText->set_grid_left_attach(0);
355 0 : m_pText->set_grid_top_attach(nYPos);
356 0 : m_pText->set_margin_left(6 + nCheckBoxLabelOffset);
357 0 : m_pText->SetText(rColorEntry.getDisplayName());
358 :
359 0 : WinBits nWinBits = WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_TABSTOP|WB_DROPDOWN;
360 0 : m_pColorList = new ColorListBox(pGrid, nWinBits);
361 0 : m_pColorList->EnableAutoSize(true);
362 0 : m_pColorList->set_grid_left_attach(1);
363 0 : m_pColorList->set_grid_top_attach(nYPos);
364 :
365 0 : m_pPreview = new Window(pGrid, WB_BORDER);
366 0 : m_pPreview->set_grid_left_attach(2);
367 0 : m_pPreview->set_grid_top_attach(nYPos);
368 0 : m_pPreview->set_margin_right(6);
369 :
370 0 : Show();
371 0 : }
372 :
373 0 : ColorConfigWindow_Impl::Entry::~Entry()
374 : {
375 0 : if (m_bOwnsWidgets)
376 : {
377 0 : delete m_pText;
378 0 : delete m_pColorList;
379 0 : delete m_pPreview;
380 : }
381 0 : }
382 :
383 0 : void ColorConfigWindow_Impl::Entry::Show()
384 : {
385 0 : m_pText->Show();
386 0 : m_pColorList->Show();
387 0 : m_pPreview->Show();
388 0 : }
389 :
390 0 : void ColorConfigWindow_Impl::Entry::Hide()
391 : {
392 0 : m_pText->Hide();
393 0 : m_pColorList->Hide();
394 0 : m_pPreview->Hide();
395 0 : }
396 :
397 : // SetAppearance()
398 : // iEntry: which entry is this?
399 : // aTextWall: background of the text (transparent)
400 : // aSampleList: sample color listbox (to copy from)
401 0 : void ColorConfigWindow_Impl::Entry::SetAppearance(
402 : Wallpaper const& aTextWall,
403 : ColorListBox const& aSampleList)
404 : {
405 : // text (and optionally checkbox)
406 0 : m_pText->SetBackground(aTextWall);
407 : // preview
408 0 : m_pPreview->SetBorderStyle(WINDOW_BORDER_MONO);
409 : // color list
410 0 : m_pColorList->CopyEntries(aSampleList);
411 0 : m_pColorList->InsertAutomaticEntryColor(m_aDefaultColor);
412 0 : }
413 :
414 : // SetLinks()
415 0 : void ColorConfigWindow_Impl::Entry::SetLinks(
416 : Link const& aCheckLink, Link const& aColorLink,
417 : Link const& aGetFocusLink)
418 : {
419 0 : m_pColorList->SetSelectHdl(aColorLink);
420 0 : m_pColorList->SetGetFocusHdl(aGetFocusLink);
421 0 : if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(m_pText))
422 : {
423 0 : pCheckBox->SetClickHdl(aCheckLink);
424 0 : pCheckBox->SetGetFocusHdl(aGetFocusLink);
425 : }
426 0 : }
427 :
428 : // updates a default color config entry
429 0 : void ColorConfigWindow_Impl::Entry::Update (
430 : ColorConfigEntry aColorEntry, ColorConfigValue const& rValue
431 : ) {
432 0 : Color aColor;
433 0 : if ((unsigned)rValue.nColor == COL_AUTO)
434 : {
435 0 : aColor = ColorConfig::GetDefaultColor(aColorEntry);
436 0 : m_pColorList->SelectEntryPos(0);
437 : }
438 : else
439 : {
440 0 : aColor = Color(rValue.nColor);
441 0 : m_pColorList->SelectEntry(aColor);
442 : }
443 0 : m_pPreview->SetBackground(Wallpaper(aColor));
444 0 : if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(m_pText))
445 0 : pCheckBox->Check(rValue.bIsVisible);
446 0 : }
447 :
448 : // updates an extended color config entry
449 0 : void ColorConfigWindow_Impl::Entry::Update (
450 : ExtendedColorConfigValue const& rValue
451 : ) {
452 0 : Color aColor(rValue.getColor());
453 0 : if (rValue.getColor() == rValue.getDefaultColor())
454 0 : m_pColorList->SelectEntryPos(0);
455 : else
456 0 : m_pColorList->SelectEntry(aColor);
457 0 : SetColor(aColor);
458 0 : }
459 :
460 : // color of a default entry has changed
461 0 : void ColorConfigWindow_Impl::Entry::ColorChanged (
462 : ColorConfigEntry aColorEntry,
463 : ColorConfigValue& rValue
464 : ) {
465 0 : Color aColor;
466 0 : if (m_pColorList->IsAutomaticSelected())
467 : {
468 0 : aColor = ColorConfig::GetDefaultColor(aColorEntry);
469 0 : rValue.nColor = COL_AUTO;
470 : }
471 : else
472 : {
473 0 : aColor = m_pColorList->GetSelectEntryColor();
474 0 : rValue.nColor = aColor.GetColor();
475 : }
476 0 : SetColor(aColor);
477 0 : }
478 :
479 : // color of an extended entry has changed
480 0 : void ColorConfigWindow_Impl::Entry::ColorChanged (
481 : ExtendedColorConfigValue& rValue
482 : ) {
483 0 : Color aColor = m_pColorList->GetSelectEntryColor();
484 0 : rValue.setColor(aColor.GetColor());
485 : // automatic?
486 0 : if (m_pColorList->GetSelectEntryPos() == 0)
487 : {
488 0 : rValue.setColor(rValue.getDefaultColor());
489 0 : aColor.SetColor(rValue.getColor());
490 : }
491 0 : SetColor(aColor);
492 0 : }
493 :
494 0 : void ColorConfigWindow_Impl::Entry::SetColor (Color aColor)
495 : {
496 0 : m_pPreview->SetBackground(Wallpaper(aColor));
497 0 : m_pPreview->Invalidate();
498 0 : }
499 :
500 :
501 :
502 : // ColorConfigWindow_Impl
503 :
504 :
505 0 : ColorConfigWindow_Impl::ColorConfigWindow_Impl(Window* pParent)
506 0 : : VclContainer(pParent)
507 : {
508 0 : m_pUIBuilder = new VclBuilder(this, getUIRootDir(), "cui/ui/colorconfigwin.ui");
509 0 : get(m_pGrid, "ColorConfigWindow");
510 0 : CreateEntries();
511 0 : SetAppearance();
512 0 : }
513 :
514 0 : Size ColorConfigWindow_Impl::calculateRequisition() const
515 : {
516 0 : return getLayoutRequisition(*m_pGrid);
517 : }
518 :
519 0 : void ColorConfigWindow_Impl::setAllocation(const Size &rAllocation)
520 : {
521 0 : Point aChildPos(0, 0);
522 0 : Size aChildSize(getLayoutRequisition(*m_pGrid));
523 0 : aChildSize.Width() = rAllocation.Width();
524 0 : setLayoutPosSize(*m_pGrid, aChildPos, aChildSize);
525 0 : AdjustScrollBar();
526 0 : AdjustHeaderBar();
527 0 : ScrollHdl(*m_pVScroll);
528 0 : }
529 :
530 0 : void ColorConfigWindow_Impl::CreateEntries()
531 : {
532 0 : std::bitset<nGroupCount> aModulesInstalled;
533 : // creating group headers
534 0 : vChapters.reserve(nGroupCount);
535 0 : for (unsigned i = 0; i != nGroupCount; ++i)
536 : {
537 0 : aModulesInstalled[i] = IsGroupVisible(vGroupInfo[i].eGroup);
538 : vChapters.push_back(boost::shared_ptr<Chapter>(
539 0 : new Chapter(get<FixedText>(vGroupInfo[i].pGroup), aModulesInstalled[i])));
540 : }
541 :
542 : //Here we want to get the amount to add to the position
543 : //of a FixedText to get it to align its contents
544 : //with that of a CheckBox
545 : //We should have something like a Control::getTextOrigin
546 : //Ideally we could use something like GetCharacterBounds,
547 : //but I think that only works on truly visible controls
548 0 : long nCheckBoxLabelOffset = 0;
549 : {
550 0 : OUString sSampleText("X");
551 0 : CheckBox aCheckBox(this);
552 0 : FixedText aFixedText(this);
553 0 : aCheckBox.SetText(sSampleText);
554 0 : aFixedText.SetText(sSampleText);
555 0 : Size aCheckSize(aCheckBox.CalcMinimumSize(0x7fffffff));
556 0 : Size aFixedSize(aFixedText.CalcMinimumSize(0x7fffffff));
557 0 : nCheckBoxLabelOffset = aCheckSize.Width() - aFixedSize.Width();
558 : }
559 :
560 : // creating entries
561 0 : vEntries.reserve(ColorConfigEntryCount);
562 0 : for (unsigned i = 0; i < SAL_N_ELEMENTS(vEntryInfo); ++i)
563 : {
564 : vEntries.push_back(boost::shared_ptr<Entry>(new Entry(*this, i, nCheckBoxLabelOffset,
565 0 : aModulesInstalled[vEntryInfo[i].eGroup])));
566 : }
567 :
568 : // extended entries
569 0 : ExtendedColorConfig aExtConfig;
570 0 : if (unsigned const nExtGroupCount = aExtConfig.GetComponentCount())
571 : {
572 0 : size_t nLineNum = vChapters.size() + vEntries.size() + 1;
573 0 : for (unsigned j = 0; j != nExtGroupCount; ++j)
574 : {
575 0 : OUString const sComponentName = aExtConfig.GetComponentName(j);
576 : vChapters.push_back(boost::shared_ptr<Chapter>(new Chapter(
577 : m_pGrid, nLineNum,
578 : aExtConfig.GetComponentDisplayName(sComponentName)
579 0 : )));
580 0 : ++nLineNum;
581 0 : unsigned nColorCount = aExtConfig.GetComponentColorCount(sComponentName);
582 0 : for (unsigned i = 0; i != nColorCount; ++i)
583 : {
584 : ExtendedColorConfigValue const aColorEntry =
585 0 : aExtConfig.GetComponentColorConfigValue(sComponentName, i);
586 : vEntries.push_back(boost::shared_ptr<Entry>( new Entry (
587 : m_pGrid, nLineNum, aColorEntry, nCheckBoxLabelOffset
588 0 : )));
589 0 : ++nLineNum;
590 0 : }
591 0 : }
592 0 : }
593 0 : }
594 :
595 0 : void ColorConfigWindow_Impl::SetAppearance ()
596 : {
597 0 : Color TempColor(COL_TRANSPARENT);
598 0 : Wallpaper const aTransparentWall(TempColor);
599 0 : StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
600 0 : Color const aBackColor = rStyleSettings.GetHighContrastMode() ?
601 0 : rStyleSettings.GetShadowColor() : Color(COL_LIGHTGRAY);
602 0 : Wallpaper const aBackWall(aBackColor);
603 0 : for (size_t i = 0; i != vChapters.size(); ++i)
604 0 : vChapters[i]->Show(aBackWall);
605 0 : Wallpaper aBack(rStyleSettings.GetFieldColor());
606 0 : SetBackground(aBack);
607 0 : m_pGrid->SetBackground(aBack);
608 :
609 : // #104195# when the window color is the same as the text color it has to be changed
610 0 : Color aWinCol = rStyleSettings.GetWindowColor();
611 0 : Color aRCheckCol = rStyleSettings.GetRadioCheckTextColor();
612 0 : if (aWinCol == aRCheckCol)
613 : {
614 0 : aRCheckCol.Invert();
615 : // if inversion didn't work (gray) then it's set to black
616 0 : if (aRCheckCol == aWinCol)
617 0 : aRCheckCol = Color(COL_BLACK);
618 : // setting new text color for each entry
619 0 : for (size_t i = 0; i != vEntries.size(); ++i)
620 0 : vEntries[i]->SetTextColor(aRCheckCol);
621 : }
622 :
623 : OSL_ENSURE( vEntries.size() >= sizeof vEntryInfo / sizeof vEntryInfo[0], "wrong number of helpIDs for color listboxes" );
624 :
625 : // creating a sample color listbox with the color entries
626 0 : ColorListBox aSampleColorList(this);
627 : {
628 0 : XColorListRef const xColorTable = XColorList::CreateStdColorList();
629 0 : for (sal_Int32 i = 0; i != xColorTable->Count(); ++i)
630 : {
631 0 : XColorEntry& rEntry = *xColorTable->GetColor(i);
632 0 : aSampleColorList.InsertEntry(rEntry.GetColor(), rEntry.GetName());
633 0 : }
634 : }
635 :
636 : // appearance
637 0 : for (size_t i = 0; i != vEntries.size(); ++i)
638 : {
639 : // appearance
640 0 : vEntries[i]->SetAppearance(aTransparentWall, aSampleColorList);
641 0 : }
642 0 : }
643 :
644 0 : ColorConfigWindow_Impl::~ColorConfigWindow_Impl ()
645 0 : { }
646 :
647 0 : void ColorConfigWindow_Impl::AdjustHeaderBar()
648 : {
649 : // horizontal positions
650 0 : unsigned const nX0 = 0;
651 0 : unsigned const nX1 = get<Window>("doccolor")->GetPosPixel().X();
652 0 : unsigned const nX2 = get<Window>("doccolor_lb")->GetPosPixel().X();
653 0 : unsigned const nX3 = get<Window>("doccolor_wn")->GetPosPixel().X();
654 0 : unsigned const nX4 = m_pHeaderHB->GetSizePixel().Width();
655 0 : m_pHeaderHB->SetItemSize(1, nX1 - nX0);
656 0 : m_pHeaderHB->SetItemSize(2, nX2 - nX1);
657 0 : m_pHeaderHB->SetItemSize(3, nX3 - nX2);
658 0 : m_pHeaderHB->SetItemSize(4, nX4 - nX3);
659 0 : }
660 :
661 0 : void ColorConfigWindow_Impl::AdjustScrollBar()
662 : {
663 : unsigned const nScrollOffset =
664 0 : vEntries[1]->GetTop() - vEntries[0]->GetTop();
665 0 : unsigned const nVisibleEntries = GetSizePixel().Height() / nScrollOffset;
666 0 : m_pVScroll->SetPageSize(nVisibleEntries - 1);
667 0 : m_pVScroll->SetVisibleSize(nVisibleEntries);
668 0 : }
669 :
670 0 : void ColorConfigWindow_Impl::Init(ScrollBar *pVScroll, HeaderBar *pHeaderHB)
671 : {
672 0 : m_pHeaderHB = pHeaderHB;
673 0 : m_pVScroll = pVScroll;
674 0 : m_pVScroll->EnableDrag();
675 0 : m_pVScroll->SetRangeMin(0);
676 0 : m_pVScroll->SetRangeMax(vEntries.size() + vChapters.size());
677 0 : }
678 :
679 : // SetLinks()
680 0 : void ColorConfigWindow_Impl::SetLinks (
681 : Link const& aCheckLink, Link const& aColorLink, Link const& aGetFocusLink
682 : ) {
683 0 : for (unsigned i = 0; i != vEntries.size(); ++i)
684 0 : vEntries[i]->SetLinks(aCheckLink, aColorLink, aGetFocusLink);
685 0 : }
686 :
687 : // Update()
688 0 : void ColorConfigWindow_Impl::Update (
689 : EditableColorConfig const* pConfig,
690 : EditableExtendedColorConfig const* pExtConfig)
691 : {
692 : // updating default entries
693 0 : for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
694 : {
695 0 : ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
696 0 : vEntries[i]->Update(
697 0 : aColorEntry, pConfig->GetColorValue(aColorEntry)
698 0 : );
699 : }
700 :
701 : // updating extended entries
702 0 : unsigned i = ColorConfigEntryCount;
703 0 : unsigned const nExtCount = pExtConfig->GetComponentCount();
704 0 : for (unsigned j = 0; j != nExtCount; ++j)
705 : {
706 0 : OUString sComponentName = pExtConfig->GetComponentName(j);
707 0 : unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
708 0 : for (unsigned k = 0; i != vEntries.size() && k != nColorCount; ++i, ++k)
709 0 : vEntries[i]->Update(
710 : pExtConfig->GetComponentColorConfigValue(sComponentName, k)
711 0 : );
712 0 : }
713 0 : }
714 :
715 : // ScrollHdl()
716 0 : void ColorConfigWindow_Impl::ScrollHdl(const ScrollBar& rVScroll)
717 : {
718 0 : SetUpdateMode(true);
719 0 : const long nRowHeight = (vEntries[1]->GetTop() - vEntries[0]->GetTop());
720 0 : Point aPos(0, 0 - rVScroll.GetThumbPos() * nRowHeight);
721 0 : m_pGrid->SetPosPixel(aPos);
722 0 : SetUpdateMode(true);
723 0 : }
724 :
725 : // ClickHdl()
726 0 : void ColorConfigWindow_Impl::ClickHdl (EditableColorConfig* pConfig, CheckBox* pBox)
727 : {
728 0 : for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
729 : {
730 0 : if (vEntries[i]->Is(pBox))
731 : {
732 0 : ColorConfigEntry const aEntry = static_cast<ColorConfigEntry>(i);
733 0 : ColorConfigValue aValue = pConfig->GetColorValue(aEntry);
734 0 : aValue.bIsVisible = pBox->IsChecked();
735 0 : pConfig->SetColorValue(aEntry, aValue);
736 0 : break;
737 : }
738 : }
739 0 : }
740 :
741 : // ColorHdl()
742 0 : void ColorConfigWindow_Impl::ColorHdl (
743 : EditableColorConfig* pConfig, EditableExtendedColorConfig* pExtConfig,
744 : ColorListBox* pBox
745 : ) {
746 0 : unsigned i = 0;
747 :
748 : // default entries
749 0 : for ( ; i != ColorConfigEntryCount; ++i)
750 : {
751 0 : if (pBox && vEntries[i]->Is(pBox))
752 : {
753 0 : ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
754 0 : ColorConfigValue aValue = pConfig->GetColorValue(aColorEntry);
755 0 : vEntries[i]->ColorChanged(aColorEntry, aValue);
756 0 : pConfig->SetColorValue(aColorEntry, aValue);
757 0 : break;
758 : }
759 : }
760 :
761 : // extended entries
762 0 : unsigned const nExtCount = pExtConfig->GetComponentCount();
763 0 : i = ColorConfigEntryCount;
764 0 : for (unsigned j = 0; j != nExtCount; ++j)
765 : {
766 0 : OUString sComponentName = pExtConfig->GetComponentName(j);
767 0 : unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
768 0 : unsigned const nCount = vEntries.size();
769 0 : for (unsigned k = 0; i != nCount && k != nColorCount; ++i, ++k)
770 : {
771 0 : if (pBox && vEntries[i]->Is(pBox))
772 : {
773 : ExtendedColorConfigValue aValue =
774 0 : pExtConfig->GetComponentColorConfigValue(sComponentName, k);
775 0 : vEntries[i]->ColorChanged(aValue);
776 0 : pExtConfig->SetColorValue(sComponentName, aValue);
777 0 : break;
778 : }
779 : }
780 0 : }
781 0 : }
782 :
783 :
784 : // IsGroupVisible()
785 0 : bool ColorConfigWindow_Impl::IsGroupVisible (Group eGroup) const
786 : {
787 0 : switch (eGroup)
788 : {
789 : case Group_Writer:
790 : case Group_Html:
791 0 : return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SWRITER);
792 : case Group_Calc:
793 0 : return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SCALC);
794 : case Group_Draw:
795 : return
796 0 : aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDRAW) ||
797 0 : aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SIMPRESS);
798 : case Group_Sql:
799 0 : return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDATABASE);
800 : default:
801 0 : return true;
802 : }
803 : }
804 :
805 0 : void ColorConfigWindow_Impl::DataChanged (DataChangedEvent const& rDCEvt)
806 : {
807 0 : Window::DataChanged( rDCEvt );
808 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
809 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
810 : {
811 0 : StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
812 0 : bool const bHighContrast = rStyleSettings.GetHighContrastMode();
813 0 : Wallpaper const aBackWall(Color(bHighContrast ? COL_TRANSPARENT : COL_LIGHTGRAY));
814 0 : for (unsigned i = 0; i != vChapters.size(); ++i)
815 0 : vChapters[i]->SetBackground(aBackWall);
816 0 : SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
817 : }
818 0 : }
819 :
820 :
821 0 : void ColorConfigWindow_Impl::Command( const CommandEvent& rCEvt )
822 : {
823 0 : GetParent()->Command(rCEvt);
824 0 : }
825 :
826 : class ColorConfigCtrl_Impl : public VclVBox
827 : {
828 : HeaderBar* m_pHeaderHB;
829 : VclHBox* m_pBody;
830 : ColorConfigWindow_Impl* m_pScrollWindow;
831 : ScrollBar* m_pVScroll;
832 :
833 : EditableColorConfig* pColorConfig;
834 : EditableExtendedColorConfig* pExtColorConfig;
835 :
836 : DECL_LINK(ScrollHdl, ScrollBar*);
837 : DECL_LINK(ClickHdl, CheckBox*);
838 : DECL_LINK(ColorHdl, ColorListBox*);
839 : DECL_LINK(ControlFocusHdl, Control*);
840 :
841 : virtual bool PreNotify (NotifyEvent& rNEvt) SAL_OVERRIDE;
842 : virtual void Command (CommandEvent const& rCEvt) SAL_OVERRIDE;
843 : virtual void DataChanged (DataChangedEvent const& rDCEvt) SAL_OVERRIDE;
844 : public:
845 : ColorConfigCtrl_Impl(Window* pParent);
846 : virtual ~ColorConfigCtrl_Impl();
847 :
848 : void InitHeaderBar(const OUString &rOn, const OUString &rUIElems,
849 : const OUString &rColorSetting, const OUString &rPreview);
850 0 : void SetConfig (EditableColorConfig& rConfig) { pColorConfig = &rConfig; }
851 0 : void SetExtendedConfig (EditableExtendedColorConfig& rConfig) { pExtColorConfig = &rConfig; }
852 : void Update ();
853 0 : long GetScrollPosition ()
854 : {
855 0 : return m_pVScroll->GetThumbPos();
856 : }
857 0 : void SetScrollPosition (long nSet)
858 : {
859 0 : m_pVScroll->SetThumbPos(nSet);
860 0 : ScrollHdl(m_pVScroll);
861 0 : }
862 : };
863 :
864 0 : ColorConfigCtrl_Impl::ColorConfigCtrl_Impl(Window* pParent)
865 : : VclVBox(pParent)
866 : , pColorConfig(0)
867 0 : , pExtColorConfig(0)
868 : {
869 0 : m_pHeaderHB = new HeaderBar(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER);
870 :
871 0 : m_pBody = new VclHBox(this);
872 0 : m_pScrollWindow = new ColorConfigWindow_Impl(m_pBody);
873 0 : m_pVScroll = new ScrollBar(m_pBody, WB_VERT);
874 0 : m_pScrollWindow->Init(m_pVScroll, m_pHeaderHB);
875 :
876 0 : m_pBody->set_hexpand(true);
877 0 : m_pBody->set_vexpand(true);
878 0 : m_pBody->set_expand(true);
879 0 : m_pBody->set_fill(true);
880 :
881 0 : m_pScrollWindow->set_hexpand(true);
882 0 : m_pScrollWindow->set_vexpand(true);
883 0 : m_pScrollWindow->set_expand(true);
884 0 : m_pScrollWindow->set_fill(true);
885 :
886 0 : Link aScrollLink = LINK(this, ColorConfigCtrl_Impl, ScrollHdl);
887 0 : m_pVScroll->SetScrollHdl(aScrollLink);
888 0 : m_pVScroll->SetEndScrollHdl(aScrollLink);
889 :
890 0 : Link aCheckLink = LINK(this, ColorConfigCtrl_Impl, ClickHdl);
891 0 : Link aColorLink = LINK(this, ColorConfigCtrl_Impl, ColorHdl);
892 0 : Link aGetFocusLink = LINK(this, ColorConfigCtrl_Impl, ControlFocusHdl);
893 0 : m_pScrollWindow->SetLinks(aCheckLink, aColorLink, aGetFocusLink);
894 :
895 0 : m_pHeaderHB->Show();
896 0 : m_pVScroll->Show();
897 0 : m_pBody->Show();
898 0 : m_pScrollWindow->Show();
899 0 : }
900 :
901 0 : void ColorConfigCtrl_Impl::InitHeaderBar(const OUString &rOn, const OUString &rUIElems,
902 : const OUString &rColorSetting, const OUString &rPreview)
903 : {
904 : // filling
905 0 : const WinBits nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS;
906 0 : m_pHeaderHB->InsertItem(1, rOn, 0, nHeadBits | HIB_CENTER);
907 0 : m_pHeaderHB->InsertItem(2, rUIElems, 0, nHeadBits | HIB_LEFT);
908 0 : m_pHeaderHB->InsertItem(3, rColorSetting, 0, nHeadBits | HIB_LEFT);
909 0 : m_pHeaderHB->InsertItem(4, rPreview, 0, nHeadBits | HIB_LEFT);
910 0 : m_pHeaderHB->set_height_request(GetTextHeight() + 6);
911 0 : }
912 :
913 0 : ColorConfigCtrl_Impl::~ColorConfigCtrl_Impl()
914 : {
915 0 : delete m_pVScroll;
916 0 : delete m_pScrollWindow;
917 0 : delete m_pBody;
918 0 : delete m_pHeaderHB;
919 0 : }
920 :
921 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeColorConfigCtrl(Window *pParent, VclBuilder::stringmap &)
922 : {
923 0 : return new ColorConfigCtrl_Impl(pParent);
924 : }
925 :
926 0 : void ColorConfigCtrl_Impl::Update ()
927 : {
928 : DBG_ASSERT(pColorConfig, "Configuration not set");
929 0 : m_pScrollWindow->Update(pColorConfig, pExtColorConfig);
930 0 : }
931 :
932 0 : IMPL_LINK(ColorConfigCtrl_Impl, ScrollHdl, ScrollBar*, pScrollBar)
933 : {
934 0 : m_pScrollWindow->ScrollHdl(*pScrollBar);
935 0 : return 0;
936 : }
937 :
938 0 : bool ColorConfigCtrl_Impl::PreNotify( NotifyEvent& rNEvt )
939 : {
940 0 : if(rNEvt.GetType() == EVENT_COMMAND)
941 : {
942 0 : const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
943 0 : sal_uInt16 nCmd = pCEvt->GetCommand();
944 0 : if( COMMAND_WHEEL == nCmd )
945 : {
946 0 : Command(*pCEvt);
947 0 : return true;
948 : }
949 : }
950 0 : return VclVBox::PreNotify(rNEvt);
951 : }
952 :
953 0 : void ColorConfigCtrl_Impl::Command( const CommandEvent& rCEvt )
954 : {
955 0 : switch ( rCEvt.GetCommand() )
956 : {
957 :
958 : case COMMAND_WHEEL:
959 : case COMMAND_STARTAUTOSCROLL:
960 : case COMMAND_AUTOSCROLL:
961 : {
962 0 : const CommandWheelData* pWheelData = rCEvt.GetWheelData();
963 0 : if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
964 : {
965 0 : HandleScrollCommand(rCEvt, 0, m_pVScroll);
966 : }
967 : }
968 0 : break;
969 : default:
970 0 : VclVBox::Command(rCEvt);
971 : }
972 0 : }
973 :
974 0 : void ColorConfigCtrl_Impl::DataChanged( const DataChangedEvent& rDCEvt )
975 : {
976 0 : Window::DataChanged( rDCEvt );
977 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
978 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
979 : {
980 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
981 0 : SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
982 : }
983 0 : }
984 :
985 0 : IMPL_LINK(ColorConfigCtrl_Impl, ClickHdl, CheckBox*, pBox)
986 : {
987 : DBG_ASSERT(pColorConfig, "Configuration not set");
988 0 : m_pScrollWindow->ClickHdl(pColorConfig, pBox);
989 0 : return 0;
990 : }
991 :
992 : // a color list has changed
993 0 : IMPL_LINK(ColorConfigCtrl_Impl, ColorHdl, ColorListBox*, pBox)
994 : {
995 : DBG_ASSERT(pColorConfig, "Configuration not set" );
996 0 : if (pBox)
997 0 : m_pScrollWindow->ColorHdl(pColorConfig, pExtColorConfig, pBox);
998 0 : return 0;
999 : }
1000 0 : IMPL_LINK(ColorConfigCtrl_Impl, ControlFocusHdl, Control*, pCtrl)
1001 : {
1002 : // determine whether a control is completely visible
1003 : // and make it visible
1004 0 : long aCtrlPosY = pCtrl->GetPosPixel().Y();
1005 0 : unsigned const nWinHeight = m_pScrollWindow->GetSizePixel().Height();
1006 0 : unsigned const nEntryHeight = m_pScrollWindow->GetEntryHeight();
1007 0 : if (0 != (GETFOCUS_TAB & pCtrl->GetGetFocusFlags()) &&
1008 0 : (aCtrlPosY < 0 || nWinHeight < aCtrlPosY + nEntryHeight)
1009 : ) {
1010 0 : long nThumbPos = m_pVScroll->GetThumbPos();
1011 0 : if (nWinHeight < aCtrlPosY + nEntryHeight)
1012 : {
1013 : //scroll down
1014 0 : nThumbPos += 2;
1015 : }
1016 : else
1017 : {
1018 : //scroll up
1019 0 : nThumbPos -= 2;
1020 0 : if(nThumbPos < 0)
1021 0 : nThumbPos = 0;
1022 : }
1023 0 : m_pVScroll->SetThumbPos(nThumbPos);
1024 0 : ScrollHdl(m_pVScroll);
1025 : }
1026 0 : return 0;
1027 : };
1028 :
1029 :
1030 :
1031 : // SvxColorOptionsTabPage
1032 :
1033 :
1034 0 : SvxColorOptionsTabPage::SvxColorOptionsTabPage(
1035 : Window* pParent, const SfxItemSet& rCoreSet)
1036 : : SfxTabPage(pParent, "OptAppearancePage", "cui/ui/optappearancepage.ui", rCoreSet)
1037 : , bFillItemSetCalled(false)
1038 : , pColorConfig(0)
1039 0 : , pExtColorConfig(0)
1040 : {
1041 0 : get(m_pColorSchemeLB, "colorschemelb");
1042 0 : m_pColorSchemeLB->SetStyle(m_pColorSchemeLB->GetStyle() | WB_SORT);
1043 0 : get(m_pSaveSchemePB, "save");
1044 0 : get(m_pDeleteSchemePB, "delete");
1045 0 : get(m_pColorConfigCT, "colorconfig");
1046 :
1047 : m_pColorConfigCT->InitHeaderBar(
1048 0 : get<Window>("on")->GetText(),
1049 0 : get<Window>("uielements")->GetText(),
1050 0 : get<Window>("colorsetting")->GetText(),
1051 0 : get<Window>("preview")->GetText());
1052 :
1053 0 : m_pColorSchemeLB->SetSelectHdl(LINK(this, SvxColorOptionsTabPage, SchemeChangedHdl_Impl));
1054 0 : Link aLk = LINK(this, SvxColorOptionsTabPage, SaveDeleteHdl_Impl );
1055 0 : m_pSaveSchemePB->SetClickHdl(aLk);
1056 0 : m_pDeleteSchemePB->SetClickHdl(aLk);
1057 0 : }
1058 :
1059 0 : SvxColorOptionsTabPage::~SvxColorOptionsTabPage()
1060 : {
1061 : //when the dialog is cancelled but the color scheme ListBox has been changed these
1062 : //changes need to be undone
1063 0 : if(!bFillItemSetCalled && m_pColorSchemeLB->GetSavedValue() != m_pColorSchemeLB->GetSelectEntryPos())
1064 : {
1065 0 : OUString sOldScheme = m_pColorSchemeLB->GetEntry(m_pColorSchemeLB->GetSavedValue());
1066 0 : if(!sOldScheme.isEmpty())
1067 : {
1068 0 : pColorConfig->SetCurrentSchemeName(sOldScheme);
1069 0 : pExtColorConfig->SetCurrentSchemeName(sOldScheme);
1070 0 : }
1071 : }
1072 0 : pColorConfig->ClearModified();
1073 0 : pColorConfig->EnableBroadcast();
1074 0 : delete pColorConfig;
1075 0 : pExtColorConfig->ClearModified();
1076 0 : pExtColorConfig->EnableBroadcast();
1077 0 : delete pExtColorConfig;
1078 0 : }
1079 :
1080 0 : SfxTabPage* SvxColorOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1081 : {
1082 0 : return ( new SvxColorOptionsTabPage( pParent, rAttrSet ) );
1083 : }
1084 :
1085 0 : bool SvxColorOptionsTabPage::FillItemSet( SfxItemSet& )
1086 : {
1087 0 : bFillItemSetCalled = sal_True;
1088 0 : if(m_pColorSchemeLB->GetSavedValue() != m_pColorSchemeLB->GetSelectEntryPos())
1089 : {
1090 0 : pColorConfig->SetModified();
1091 0 : pExtColorConfig->SetModified();
1092 : }
1093 0 : if(pColorConfig->IsModified())
1094 0 : pColorConfig->Commit();
1095 0 : if(pExtColorConfig->IsModified())
1096 0 : pExtColorConfig->Commit();
1097 0 : return true;
1098 : }
1099 :
1100 0 : void SvxColorOptionsTabPage::Reset( const SfxItemSet& )
1101 : {
1102 0 : if(pColorConfig)
1103 : {
1104 0 : pColorConfig->ClearModified();
1105 0 : pColorConfig->DisableBroadcast();
1106 0 : delete pColorConfig;
1107 : }
1108 0 : pColorConfig = new EditableColorConfig;
1109 0 : m_pColorConfigCT->SetConfig(*pColorConfig);
1110 :
1111 0 : if(pExtColorConfig)
1112 : {
1113 0 : pExtColorConfig->ClearModified();
1114 0 : pExtColorConfig->DisableBroadcast();
1115 0 : delete pExtColorConfig;
1116 : }
1117 0 : pExtColorConfig = new EditableExtendedColorConfig;
1118 0 : m_pColorConfigCT->SetExtendedConfig(*pExtColorConfig);
1119 :
1120 0 : OUString sUser = GetUserData();
1121 : //has to be called always to speed up accessibility tools
1122 0 : m_pColorConfigCT->SetScrollPosition(sUser.toInt32());
1123 0 : m_pColorSchemeLB->Clear();
1124 0 : uno::Sequence< OUString > aSchemes = pColorConfig->GetSchemeNames();
1125 0 : const OUString* pSchemes = aSchemes.getConstArray();
1126 0 : for(sal_Int32 i = 0; i < aSchemes.getLength(); i++)
1127 0 : m_pColorSchemeLB->InsertEntry(pSchemes[i]);
1128 0 : m_pColorSchemeLB->SelectEntry(pColorConfig->GetCurrentSchemeName());
1129 0 : m_pColorSchemeLB->SaveValue();
1130 0 : m_pDeleteSchemePB->Enable( aSchemes.getLength() > 1 );
1131 0 : UpdateColorConfig();
1132 0 : }
1133 :
1134 0 : int SvxColorOptionsTabPage::DeactivatePage( SfxItemSet* pSet_ )
1135 : {
1136 0 : if ( pSet_ )
1137 0 : FillItemSet( *pSet_ );
1138 0 : return( LEAVE_PAGE );
1139 : }
1140 :
1141 0 : void SvxColorOptionsTabPage::UpdateColorConfig()
1142 : {
1143 : //update the color config control
1144 0 : m_pColorConfigCT->Update();
1145 0 : }
1146 :
1147 0 : IMPL_LINK(SvxColorOptionsTabPage, SchemeChangedHdl_Impl, ListBox*, pBox)
1148 : {
1149 0 : pColorConfig->LoadScheme(pBox->GetSelectEntry());
1150 0 : pExtColorConfig->LoadScheme(pBox->GetSelectEntry());
1151 0 : UpdateColorConfig();
1152 0 : return 0;
1153 : }
1154 :
1155 0 : IMPL_LINK(SvxColorOptionsTabPage, SaveDeleteHdl_Impl, PushButton*, pButton )
1156 : {
1157 0 : if (m_pSaveSchemePB == pButton)
1158 : {
1159 0 : OUString sName;
1160 :
1161 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1162 : DBG_ASSERT(pFact, "Dialogdiet fail!");
1163 : AbstractSvxNameDialog* aNameDlg = pFact->CreateSvxNameDialog( pButton,
1164 0 : sName, CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE2) );
1165 : DBG_ASSERT(aNameDlg, "Dialogdiet fail!");
1166 0 : aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
1167 0 : aNameDlg->SetText(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE1));
1168 0 : aNameDlg->SetHelpId(HID_OPTIONS_COLORCONFIG_SAVE_SCHEME);
1169 0 : aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
1170 0 : if(RET_OK == aNameDlg->Execute())
1171 : {
1172 0 : aNameDlg->GetName(sName);
1173 0 : pColorConfig->AddScheme(sName);
1174 0 : pExtColorConfig->AddScheme(sName);
1175 0 : m_pColorSchemeLB->InsertEntry(sName);
1176 0 : m_pColorSchemeLB->SelectEntry(sName);
1177 0 : m_pColorSchemeLB->GetSelectHdl().Call(m_pColorSchemeLB);
1178 : }
1179 0 : delete aNameDlg;
1180 : }
1181 : else
1182 : {
1183 : DBG_ASSERT(m_pColorSchemeLB->GetEntryCount() > 1, "don't delete the last scheme");
1184 0 : QueryBox aQuery(pButton, CUI_RES(RID_SVXQB_DELETE_COLOR_CONFIG));
1185 0 : aQuery.SetText(CUI_RES(RID_SVXSTR_COLOR_CONFIG_DELETE));
1186 0 : if(RET_YES == aQuery.Execute())
1187 : {
1188 0 : OUString sDeleteScheme(m_pColorSchemeLB->GetSelectEntry());
1189 0 : m_pColorSchemeLB->RemoveEntry(m_pColorSchemeLB->GetSelectEntryPos());
1190 0 : m_pColorSchemeLB->SelectEntryPos(0);
1191 0 : m_pColorSchemeLB->GetSelectHdl().Call(m_pColorSchemeLB);
1192 : //first select the new scheme and then delete the old one
1193 0 : pColorConfig->DeleteScheme(sDeleteScheme);
1194 0 : pExtColorConfig->DeleteScheme(sDeleteScheme);
1195 0 : }
1196 : }
1197 0 : m_pDeleteSchemePB->Enable( m_pColorSchemeLB->GetEntryCount() > 1 );
1198 0 : return 0;
1199 : }
1200 :
1201 0 : IMPL_LINK(SvxColorOptionsTabPage, CheckNameHdl_Impl, AbstractSvxNameDialog*, pDialog )
1202 : {
1203 0 : OUString sName;
1204 0 : pDialog->GetName(sName);
1205 0 : return long(!sName.isEmpty() && LISTBOX_ENTRY_NOTFOUND == m_pColorSchemeLB->GetEntryPos( sName ));
1206 : }
1207 :
1208 0 : void SvxColorOptionsTabPage::FillUserData()
1209 : {
1210 0 : SetUserData(OUString::number(m_pColorConfigCT->GetScrollPosition()));
1211 0 : }
1212 :
1213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|