LCOV - code coverage report
Current view: top level - cui/source/options - optcolor.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 535 0.0 %
Date: 2014-04-14 Functions: 0 80 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10