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

Generated by: LCOV version 1.10