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