LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - optcolor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 596 0.2 %
Date: 2012-12-27 Functions: 2 95 2.1 %
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 "optcolor.hrc"
      36             : #include <svx/dlgutil.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::svtools;
      40             : 
      41             : namespace
      42             : {
      43             : 
      44             : // list of default groups
      45             : enum Group
      46             : {
      47             :     Group_Unknown = -1,
      48             : 
      49             :     Group_General,
      50             :     Group_Writer,
      51             :     Group_Html,
      52             :     Group_Calc,
      53             :     Group_Draw,
      54             :     Group_Basic,
      55             :     Group_Sql,
      56             : 
      57             :     nGroupCount
      58             : };
      59             : 
      60             : // group data
      61             : struct
      62             : {
      63             :     // resource id for the title text
      64             :     int nTextResId;
      65             : }
      66             : const vGroupInfo[] =
      67             : {
      68             :     // the groups are in the same order as in enum Group above
      69             :     { FT_GENERAL },
      70             :     { FT_WRITER },
      71             :     { FT_HTML },
      72             :     { FT_CALC },
      73             :     { FT_DRAW },
      74             :     { FT_BASIC },
      75             :     { FT_SQL_COMMAND }, // FIXME
      76             : };
      77             : 
      78             : // color config entry data (see ColorConfigWindow_Impl::Entry below)
      79             : struct
      80             : {
      81             :     // group
      82             :     Group eGroup;
      83             : 
      84             :     // help id for ...
      85             :     //     color listbox
      86             :     char const* sColorListHid;
      87             :     //     checkbox
      88             :     char const* sCheckBoxHid;
      89             : 
      90             :     // resource id for ...
      91             :     //     checkbox (or simple text)
      92             :     int nTextResId;
      93             :     //     color listbox
      94             :     int nColorListResId;
      95             :     //     preview box
      96             :     int nPreviewResId;
      97             : 
      98             :     // has checkbox?
      99             :     bool bCheckBox;
     100             : }
     101             : const vEntryInfo[] =
     102             : {
     103             :     // These macros simplify the list of constants.
     104             :     // There is a unique name that is the same in the ids of the same entry
     105             :     // (except one).
     106             :     // Entries with and without checkboxes need different macros:
     107             :     #define IDS(Name) \
     108             :         HID_COLORPAGE_##Name##_LB, HID_COLORPAGE_##Name##_CB, \
     109             :         FT_##Name, LB_##Name, WN_##Name, false
     110             :     #define IDS_CB(Name) \
     111             :         HID_COLORPAGE_##Name##_LB, HID_COLORPAGE_##Name##_CB, \
     112             :         CB_##Name, LB_##Name, WN_##Name, true
     113             : 
     114             :     // resolve different names
     115             :     #define CB_DOCBOUNDARIES CB_DOCBOUND
     116             :     #define LB_DOCBOUNDARIES LB_DOCBOUND
     117             :     #define WN_DOCBOUNDARIES WN_DOCBOUND
     118             :     #define FT_CALCPAGEBREAKAUTOMATIC FT_CALCPAGEBREAKAUTO
     119             :     #define LB_CALCPAGEBREAKAUTOMATIC LB_CALCPAGEBREAKAUTO
     120             :     #define WN_CALCPAGEBREAKAUTOMATIC WN_CALCPAGEBREAKAUTO
     121             : 
     122             :     // The list of these entries (enum ColorConfigEntry) are in colorcfg.hxx.
     123             : 
     124             :     { Group_General, IDS(DOCCOLOR) },
     125             :     { Group_General, IDS_CB(DOCBOUNDARIES) },
     126             :     { Group_General, IDS(APPBACKGROUND) },
     127             :     { Group_General, IDS_CB(OBJECTBOUNDARIES) },
     128             :     { Group_General, IDS_CB(TABLEBOUNDARIES) },
     129             :     { Group_General, IDS(FONTCOLOR) },
     130             :     { Group_General, IDS_CB(LINKS) },
     131             :     { Group_General, IDS_CB(LINKSVISITED) },
     132             :     { Group_General, IDS(SPELL) },
     133             :     { Group_General, IDS(SMARTTAGS) },
     134             :     { Group_General, IDS_CB(SHADOWCOLOR) },
     135             :     { Group_Writer,  IDS(WRITERTEXTGRID) },
     136             :     { Group_Writer,  IDS_CB(WRITERFIELDSHADINGS) },
     137             :     { Group_Writer,  IDS_CB(WRITERIDXSHADINGS) },
     138             :     { Group_Writer,  IDS(WRITERDIRECTCURSOR) },
     139             :     { Group_Writer,  IDS(WRITERSCRIPTINDICATOR) },
     140             :     { Group_Writer,  IDS_CB(WRITERSECTIONBOUNDARIES) },
     141             :     { Group_Writer,  IDS(WRITERHEADERFOOTERMARK) },
     142             :     { Group_Writer,  IDS(WRITERPAGEBREAKS) },
     143             :     { Group_Html,    IDS(HTMLSGML) },
     144             :     { Group_Html,    IDS(HTMLCOMMENT) },
     145             :     { Group_Html,    IDS(HTMLKEYWORD) },
     146             :     { Group_Html,    IDS(HTMLUNKNOWN) },
     147             :     { Group_Calc,    IDS(CALCGRID) },
     148             :     { Group_Calc,    IDS(CALCPAGEBREAK) },
     149             :     { Group_Calc,    IDS(CALCPAGEBREAKMANUAL) },
     150             :     { Group_Calc,    IDS(CALCPAGEBREAKAUTOMATIC) },
     151             :     { Group_Calc,    IDS(CALCDETECTIVE) },
     152             :     { Group_Calc,    IDS(CALCDETECTIVEERROR) },
     153             :     { Group_Calc,    IDS(CALCREFERENCE) },
     154             :     { Group_Calc,    IDS(CALCNOTESBACKGROUND) },
     155             :     { Group_Draw,    IDS(DRAWGRID) },
     156             :     { Group_Basic,   IDS(BASICIDENTIFIER) },
     157             :     { Group_Basic,   IDS(BASICCOMMENT) },
     158             :     { Group_Basic,   IDS(BASICNUMBER) },
     159             :     { Group_Basic,   IDS(BASICSTRING) },
     160             :     { Group_Basic,   IDS(BASICOPERATOR) },
     161             :     { Group_Basic,   IDS(BASICKEYWORD) },
     162             :     { Group_Basic,   IDS(BASICERROR) },
     163             :     { Group_Sql,     IDS(SQLIDENTIFIER) },
     164             :     { Group_Sql,     IDS(SQLNUMBER) },
     165             :     { Group_Sql,     IDS(SQLSTRING) },
     166             :     { Group_Sql,     IDS(SQLOPERATOR) },
     167             :     { Group_Sql,     IDS(SQLKEYWORD) },
     168             :     { Group_Sql,     IDS(SQLPARAMETER) },
     169             :     { Group_Sql,     IDS(SQLCOMMENT) },
     170             : 
     171             :     #undef IDS_CB
     172             :     #undef IDS
     173             : };
     174             : 
     175             : } // namespace
     176             : 
     177             : 
     178             : //
     179             : // SvxExtFixedText_Impl
     180             : //
     181             : 
     182           0 : class SvxExtFixedText_Impl : public FixedText
     183             : {
     184             : private:
     185             :     long m_nGroupHeight;
     186             : 
     187             : protected:
     188             :     virtual void DataChanged (DataChangedEvent const& rDCEvt);
     189             : 
     190             : public:
     191           0 :     SvxExtFixedText_Impl (Window* pParent, ResId const& rResId) :
     192           0 :         FixedText(pParent, rResId), m_nGroupHeight(0)
     193           0 :     { }
     194             : 
     195           0 :     long GetGroupHeight () const { return m_nGroupHeight; }
     196           0 :     void SetGroupHeight (long nHeight) { m_nGroupHeight = nHeight; }
     197             : };
     198             : 
     199           0 : void SvxExtFixedText_Impl::DataChanged (DataChangedEvent const& rDCEvt)
     200             : {
     201           0 :     FixedText::DataChanged(rDCEvt);
     202           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     203           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     204             :     {
     205           0 :         Font aFont = GetFont();
     206           0 :         aFont.SetWeight(WEIGHT_BOLD);
     207           0 :         SetFont(aFont);
     208           0 :         SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
     209             :     }
     210           0 : }
     211             : 
     212             : 
     213             : //
     214             : // ColorConfigWindow_Impl
     215             : //
     216             : 
     217             : class ColorConfigWindow_Impl : public Window
     218             : {
     219             : public:
     220             :     ColorConfigWindow_Impl (Window* pParent, ResId const& rResId);
     221             :     ~ColorConfigWindow_Impl ();
     222             : 
     223             : public:
     224             :     void SetLinks (Link const&, Link const&, Link const&);
     225           0 :     unsigned GetEntryHeight () const { return vEntries[0]->GetHeight(); }
     226             :     void Update (EditableColorConfig const*, EditableExtendedColorConfig const*);
     227             :     void ScrollHdl (long& nScrollPos, ScrollBar const&);
     228             :     void ClickHdl (EditableColorConfig*, CheckBox*);
     229             :     void ColorHdl (EditableColorConfig*, EditableExtendedColorConfig*, ColorListBox*);
     230             :     void SetHeaderBar (HeaderBar&, ScrollBar const&, ResMgr&);
     231             :     void SetScrollBar (ScrollBar&);
     232             : 
     233             : 
     234             : private:
     235             :     // Chapter -- horizontal group separator stripe with text
     236           0 :     class Chapter
     237             :     {
     238             :         // parent window
     239             :         ColorConfigWindow_Impl& rParent;
     240             :         // gray (?) stripe
     241             :         Window aBackground;
     242             :         // text
     243             :         SvxExtFixedText_Impl aText;
     244             : 
     245             :     public:
     246             :         Chapter (ColorConfigWindow_Impl& rParent, Group, ResMgr&);
     247             :         Chapter (ColorConfigWindow_Impl& rParent, ResMgr&, unsigned nYPos, rtl::OUString const& sDisplayName);
     248             :     public:
     249             :         void Show (Wallpaper const& rBackWall);
     250             :         void Hide ();
     251             :         void MoveVertically (long nOffset);
     252           0 :         void SetBackground (Wallpaper const& W) { aBackground.SetBackground(W); }
     253           0 :         long GetHeight () const { return aText.GetGroupHeight(); }
     254           0 :         void SetHeight (long nHeight) { aText.SetGroupHeight(nHeight); }
     255           0 :         long GetLeft () const { return aText.GetPosPixel().X(); }
     256           0 :         long GetTop () const { return aText.GetPosPixel().Y(); }
     257             :     };
     258             : 
     259             :     // Entry -- a color config entry:
     260             :     // text (checkbox) + color list box + preview box
     261           0 :     class Entry
     262             :     {
     263             :     public:
     264             :         Entry (Window& rParent, unsigned iEntry, ResMgr&);
     265             :         Entry (Window& rParent, ResMgr&, unsigned nYPos, ExtendedColorConfigValue const& aColorEntry);
     266             :     public:
     267             :         void MoveVertically (long nOffset);
     268             :         bool MoveAndShow (long nOffset, long nMaxVisible, bool bShow);
     269             :         void Show ();
     270             :         void Hide ();
     271             :         void SetAppearance (unsigned iEntry, Wallpaper const& aTextWall, ColorListBox const& aSampleList);
     272           0 :         void SetTextColor (Color C) { pText->SetTextColor(C); }
     273             :     public:
     274             :         void SetLinks (Link const&, Link const&, Link const&);
     275             :         void SetHeader (ColorConfigWindow_Impl const& rParent, HeaderBar&, ResMgr&) const;
     276             :         void Update (ColorConfigEntry, ColorConfigValue const&);
     277             :         void Update (ExtendedColorConfigValue const&);
     278             :         void ColorChanged (ColorConfigEntry, ColorConfigValue&);
     279             :         void ColorChanged (ExtendedColorConfigValue&);
     280             :     public:
     281           0 :         long GetTop () const { return aPreview.GetPosPixel().Y(); }
     282           0 :         long GetBottom () const { return GetTop() + aPreview.GetSizePixel().Height(); }
     283           0 :         unsigned GetHeight () const { return aColorList.GetSizePixel().Height(); }
     284             :     public:
     285           0 :         bool Is (CheckBox* pBox) const { return pText.get() == pBox; }
     286           0 :         bool Is (ColorListBox* pBox) const { return &aColorList == pBox; }
     287             : 
     288             :     private:
     289             :         // checkbox (CheckBox) or simple text (FixedText)
     290             :         boost::shared_ptr<Control> pText;
     291             :         // color list box
     292             :         ColorListBox aColorList;
     293             :         // color preview box
     294             :         Window aPreview;
     295             :         // default color
     296             :         Color aDefaultColor;
     297             : 
     298             :     private:
     299             :         void SetColor (Color);
     300             :     };
     301             : 
     302             :     // vChapters -- groups (group headers)
     303             :     std::vector<boost::shared_ptr<Chapter> > vChapters;
     304             :     // vEntries -- color options
     305             :     std::vector<boost::shared_ptr<Entry> > vEntries;
     306             : 
     307             :     // module options
     308             :     SvtModuleOptions aModuleOptions;
     309             : 
     310             : 
     311             : private:
     312             :     // initialization
     313             :     void CreateEntries (ResMgr&);
     314             :     void SetAppearance ();
     315             : 
     316             : private:
     317             :     long GetDeltaAbove (Group) const;
     318             : 
     319             :     virtual void Command (CommandEvent const& rCEvt);
     320             :     virtual void DataChanged (DataChangedEvent const& rDCEvt);
     321             : 
     322             :     unsigned GetPosBehindLastChapter () const;
     323             : 
     324             :     bool IsGroupVisible (Group) const;
     325             : };
     326             : 
     327             : namespace
     328             : {
     329             : 
     330             : // entry -> group
     331           0 : Group GetGroup (unsigned nEntry)
     332             : {
     333           0 :     if (nEntry >= ColorConfigEntryCount)
     334           0 :         return nGroupCount; // feature of an extension
     335           0 :     return vEntryInfo[nEntry].eGroup;
     336             : }
     337             : 
     338             : // moves a window vertically
     339           0 : void MoveVertically (Window& rWin, long nOffset)
     340             : {
     341           0 :     if (nOffset)
     342             :     {
     343           0 :         Point aPos = rWin.GetPosPixel();
     344           0 :         aPos.Y() += nOffset;
     345           0 :         rWin.SetPosPixel(aPos);
     346             :     }
     347           0 : }
     348             : 
     349             : // moves a window vertically and optionally shows it
     350           0 : bool MoveAndShow (Window& rWin, long nOffset, long nMaxVisible, bool bShow)
     351             : {
     352             :     // moves
     353           0 :     Point aPos = rWin.GetPosPixel();
     354           0 :     aPos.Y() += nOffset;
     355           0 :     rWin.SetPosPixel(aPos);
     356             :     // shows only if it is really visible
     357           0 :     if (bShow)
     358           0 :         bShow = aPos.Y() <= nMaxVisible && aPos.Y() + rWin.GetSizePixel().Height() >= 0;
     359           0 :     rWin.Show(bShow);
     360           0 :     return bShow;
     361             : }
     362             : 
     363             : } // namespace
     364             : 
     365             : 
     366             : 
     367             : //
     368             : // ColorConfigWindow_Impl::Chapter
     369             : //
     370             : 
     371             : // ctor for default groups
     372             : // rParent: parent window (ColorConfigWindow_Impl)
     373             : // eGroup: which group is this?
     374             : // rResMgr: resource manager
     375           0 : ColorConfigWindow_Impl::Chapter::Chapter (
     376             :     ColorConfigWindow_Impl& Parent, Group eGroup, ResMgr& rResMgr
     377             : ) :
     378             :     rParent(Parent),
     379             :     aBackground(&rParent),
     380           0 :     aText(&rParent, ResId(vGroupInfo[eGroup].nTextResId, rResMgr))
     381           0 : { }
     382             : 
     383             : // ctor for extended groups
     384           0 : ColorConfigWindow_Impl::Chapter::Chapter (
     385             :     ColorConfigWindow_Impl& Parent, ResMgr& rResMgr,
     386             :     unsigned nYPos, rtl::OUString const& sDisplayName
     387             : ) :
     388             :     rParent(Parent),
     389             :     aBackground(&rParent),
     390           0 :     aText(&rParent, ResId(FT_SQL_COMMAND, rResMgr))
     391             : {
     392           0 :     Point const aTextPos = rParent.LogicToPixel(Point(FT_XPOS, nYPos), MAP_APPFONT);
     393           0 :     Size const aTextSize = rParent.LogicToPixel(Size(FT_WIDTH, SEP_HEIGHT), MAP_APPFONT);
     394           0 :     aText.SetPosSizePixel(aTextPos, aTextSize);
     395           0 :     aText.SetText(sDisplayName);
     396           0 : }
     397             : 
     398             : 
     399           0 : void ColorConfigWindow_Impl::Chapter::Show (Wallpaper const& rBackWall)
     400             : {
     401             :     { // background
     402             :         Point const aBgPos(
     403           0 :             rParent.LogicToPixel(Point(0, 0), MAP_APPFONT).X(),
     404           0 :             aText.GetPosPixel().Y()
     405           0 :         );
     406             :         Size const aBgSize(
     407           0 :             rParent.GetSizePixel().Width(),
     408           0 :             rParent.LogicToPixel(Size(0, SEP_HEIGHT), MAP_APPFONT).Height()
     409           0 :         );
     410           0 :         aBackground.SetPosSizePixel(aBgPos, aBgSize);
     411           0 :         aBackground.SetBackground(rBackWall);
     412           0 :         aBackground.Show();
     413             :     }
     414             : 
     415             :     { // text
     416           0 :         Font aFont = aText.GetFont();
     417           0 :         aFont.SetWeight(WEIGHT_BOLD);
     418           0 :         aText.SetFont(aFont);
     419           0 :         aText.SetBackground(rBackWall);
     420           0 :         aText.Show();
     421           0 :         aText.SetZOrder(0, WINDOW_ZORDER_FIRST);
     422             :     }
     423           0 : }
     424             : 
     425           0 : void ColorConfigWindow_Impl::Chapter::Hide ()
     426             : {
     427           0 :     aBackground.Hide();
     428           0 :     aText.Hide();
     429           0 : }
     430             : 
     431             : // moves the chapter title vertically by nOffset pixels
     432           0 : void ColorConfigWindow_Impl::Chapter::MoveVertically (long nOffset)
     433             : {
     434           0 :     ::MoveVertically(aBackground, nOffset);
     435           0 :     ::MoveVertically(aText, nOffset);
     436           0 : }
     437             : 
     438             : 
     439             : //
     440             : // ColorConfigWindow_Impl::Entry
     441             : //
     442             : 
     443             : // ctor for default entries
     444             : // pParent: parent window (ColorConfigWindow_Impl)
     445             : // iEntry: which entry is this? (in the vEntryInfo[] array above)
     446             : // rResMgr: resource manager
     447           0 : ColorConfigWindow_Impl::Entry::Entry (
     448             :     Window& rParent, unsigned iEntry, ResMgr& rResMgr
     449             : ) :
     450             :     aColorList(&rParent, ResId(vEntryInfo[iEntry].nColorListResId, rResMgr)),
     451             :     aPreview(&rParent, ResId(vEntryInfo[iEntry].nPreviewResId, rResMgr)),
     452           0 :     aDefaultColor(ColorConfig::GetDefaultColor(static_cast<ColorConfigEntry>(iEntry)))
     453             : {
     454             :     // has checkbox?
     455           0 :     if (vEntryInfo[iEntry].bCheckBox)
     456             :     {
     457             :         pText = boost::shared_ptr<CheckBox>( new CheckBox (
     458             :             &rParent, ResId(vEntryInfo[iEntry].nTextResId, rResMgr)
     459           0 :         ) );
     460             :     }
     461             :     else
     462             :     {
     463             :         pText = boost::shared_ptr<FixedText>( new FixedText (
     464             :             &rParent, ResId(vEntryInfo[iEntry].nTextResId, rResMgr)
     465           0 :         ) );
     466             :     }
     467           0 : }
     468             : 
     469             : // ctor for extended entries
     470           0 : ColorConfigWindow_Impl::Entry::Entry (
     471             :     Window& rParent, ResMgr& rResMgr,
     472             :     unsigned nYPos, ExtendedColorConfigValue const& aColorEntry
     473             : ) :
     474           0 :     pText(boost::shared_ptr<FixedText>(new FixedText (&rParent, ResId(FT_BASICERROR, rResMgr)))),
     475             :     aColorList(&rParent, ResId(LB_BASICERROR, rResMgr)),
     476             :     aPreview(&rParent, ResId(WN_BASICERROR, rResMgr)),
     477           0 :     aDefaultColor(aColorEntry.getDefaultColor())
     478             : {
     479             :     { // text (no checkbox)
     480           0 :         FixedText* const pFixedText = static_cast<FixedText*>(pText.get());
     481           0 :         Point const aTextPos = rParent.LogicToPixel(Point(FT_XPOS, nYPos), MAP_APPFONT);
     482           0 :         Size const aTextSize = rParent.LogicToPixel(Size(FT_WIDTH, FT_HEIGHT), MAP_APPFONT);
     483           0 :         pFixedText->SetPosSizePixel(aTextPos, aTextSize);
     484           0 :         pFixedText->SetText(aColorEntry.getDisplayName());
     485             :     }
     486             :     { // color listbox
     487           0 :         Point const aListPos = rParent.LogicToPixel(Point(LB_XPOS, nYPos), MAP_APPFONT);
     488           0 :         Size const aListSize = rParent.LogicToPixel(Size(LB_WIDTH, LB_HEIGHT), MAP_APPFONT);
     489           0 :         aColorList.SetPosSizePixel(aListPos, aListSize);
     490             :     }
     491             :     { // preview box
     492           0 :         Point const aPreviewPos = rParent.LogicToPixel(Point(WN_XPOS, nYPos), MAP_APPFONT);
     493           0 :         Size const aPreviewSize = rParent.LogicToPixel(Size(WN_WIDTH, WN_HEIGHT), MAP_APPFONT);
     494           0 :         aPreview.SetPosSizePixel(aPreviewPos, aPreviewSize);
     495             :     }
     496           0 : }
     497             : 
     498             : // moves entry vertically by nOffset pixels
     499           0 : void ColorConfigWindow_Impl::Entry::MoveVertically (long nOffset)
     500             : {
     501             :     // moving all components
     502           0 :     ::MoveVertically(*pText, nOffset);
     503           0 :     ::MoveVertically(aColorList, nOffset);
     504           0 :     ::MoveVertically(aPreview, nOffset);
     505           0 : }
     506             : 
     507             : // moves and shows
     508           0 : bool ColorConfigWindow_Impl::Entry::MoveAndShow (long nOffset, long nMaxVisible, bool bShow)
     509             : {
     510             :     // if any of the items on the current line is visible, the
     511             :     // whole line should be visible
     512           0 :     bool bRes = false;
     513           0 :     bRes = ::MoveAndShow(*pText,     nOffset, nMaxVisible, bShow) || bRes;
     514           0 :     bRes = ::MoveAndShow(aColorList, nOffset, nMaxVisible, bShow) || bRes;
     515           0 :     bRes = ::MoveAndShow(aPreview,   nOffset, nMaxVisible, bShow) || bRes;
     516           0 :     return bRes;
     517             : }
     518             : 
     519           0 : void ColorConfigWindow_Impl::Entry::Show ()
     520             : {
     521           0 :     pText->Show();
     522           0 :     aColorList.Show();
     523           0 :     aPreview.Show();
     524           0 : }
     525             : 
     526           0 : void ColorConfigWindow_Impl::Entry::Hide ()
     527             : {
     528           0 :     pText->Hide();
     529           0 :     aColorList.Hide();
     530           0 :     aPreview.Hide();
     531           0 : }
     532             : 
     533             : // SetAppearance()
     534             : // iEntry: which entry is this?
     535             : // aTextWall: background of the text (transparent)
     536             : // aSampleList: sample color listbox (to copy from)
     537           0 : void ColorConfigWindow_Impl::Entry::SetAppearance (
     538             :     unsigned iEntry, Wallpaper const& aTextWall,
     539             :     ColorListBox const& aSampleList
     540             : ) {
     541             :     // text (and optionally checkbox)
     542           0 :     pText->SetBackground(aTextWall);
     543           0 :     if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
     544           0 :         pCheckBox->SetHelpId(vEntryInfo[iEntry].sCheckBoxHid);
     545             :     // preview
     546           0 :     aPreview.SetBorderStyle(WINDOW_BORDER_MONO);
     547             :     // color list
     548           0 :     aColorList.CopyEntries(aSampleList);
     549           0 :     aColorList.InsertAutomaticEntryColor(aDefaultColor);
     550           0 :     if (iEntry < ColorConfigEntryCount)
     551           0 :         aColorList.SetHelpId(vEntryInfo[iEntry].sColorListHid);
     552           0 : }
     553             : 
     554             : // SetLinks()
     555           0 : void ColorConfigWindow_Impl::Entry::SetLinks (
     556             :     Link const& aCheckLink, Link const& aColorLink, Link const& aGetFocusLink
     557             : ) {
     558           0 :     aColorList.SetSelectHdl(aColorLink);
     559           0 :     aColorList.SetGetFocusHdl(aGetFocusLink);
     560           0 :     if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
     561             :     {
     562           0 :         pCheckBox->SetClickHdl(aCheckLink);
     563           0 :         pCheckBox->SetGetFocusHdl(aGetFocusLink);
     564             :     }
     565           0 : }
     566             : 
     567             : // fills the header bar
     568           0 : void ColorConfigWindow_Impl::Entry::SetHeader (
     569             :     ColorConfigWindow_Impl const& rParent,
     570             :     HeaderBar& rHeader, ResMgr& rResMgr
     571             : ) const {
     572             :     // title strings
     573             :     String const sTitle[] =
     574             :     {
     575             :         ResId(ST_ON, rResMgr),
     576             :         ResId(ST_UIELEM, rResMgr),
     577             :         ResId(ST_COLSET, rResMgr),
     578             :         ResId(ST_PREVIEW, rResMgr),
     579           0 :     };
     580             :     // horizontal positions
     581           0 :     unsigned const nX0 = 0;
     582           0 :     unsigned const nX1 = rParent.vChapters.front()->GetLeft();
     583           0 :     unsigned const nX2 = aColorList.GetPosPixel().X();
     584           0 :     unsigned const nX3 = aPreview.GetPosPixel().X();
     585           0 :     unsigned const nX4 = rHeader.GetSizePixel().Width();
     586             :     // filling
     587           0 :     WinBits const nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS;
     588           0 :     rHeader.InsertItem(1, sTitle[0], nX1 - nX0, nHeadBits | HIB_CENTER);
     589           0 :     rHeader.InsertItem(2, sTitle[1], nX2 - nX1, nHeadBits | HIB_LEFT);
     590           0 :     rHeader.InsertItem(3, sTitle[2], nX3 - nX2, nHeadBits | HIB_LEFT);
     591           0 :     rHeader.InsertItem(4, sTitle[3], nX4 - nX3, nHeadBits | HIB_LEFT);
     592           0 : }
     593             : 
     594             : // updates a default color config entry
     595           0 : void ColorConfigWindow_Impl::Entry::Update (
     596             :     ColorConfigEntry aColorEntry, ColorConfigValue const& rValue
     597             : ) {
     598           0 :     Color aColor;
     599           0 :     if ((unsigned)rValue.nColor == COL_AUTO)
     600             :     {
     601           0 :         aColor = ColorConfig::GetDefaultColor(aColorEntry);
     602           0 :         aColorList.SelectEntryPos(0);
     603             :     }
     604             :     else
     605             :     {
     606           0 :         aColor = Color(rValue.nColor);
     607           0 :         aColorList.SelectEntry(aColor);
     608             :     }
     609           0 :     aPreview.SetBackground(Wallpaper(aColor));
     610           0 :     if (CheckBox* pCheckBox = dynamic_cast<CheckBox*>(pText.get()))
     611           0 :         pCheckBox->Check(rValue.bIsVisible);
     612           0 : }
     613             : 
     614             : // updates an extended color config entry
     615           0 : void ColorConfigWindow_Impl::Entry::Update (
     616             :     ExtendedColorConfigValue const& rValue
     617             : ) {
     618           0 :     Color aColor(rValue.getColor());
     619           0 :     if (rValue.getColor() == rValue.getDefaultColor())
     620           0 :         aColorList.SelectEntryPos(0);
     621             :     else
     622           0 :         aColorList.SelectEntry(aColor);
     623           0 :     SetColor(aColor);
     624           0 : }
     625             : 
     626             : // color of a default entry has changed
     627           0 : void ColorConfigWindow_Impl::Entry::ColorChanged (
     628             :     ColorConfigEntry aColorEntry,
     629             :     ColorConfigValue& rValue
     630             : ) {
     631           0 :     Color aColor;
     632           0 :     if (aColorList.IsAutomaticSelected())
     633             :     {
     634           0 :         aColor = ColorConfig::GetDefaultColor(aColorEntry);
     635           0 :         rValue.nColor = COL_AUTO;
     636             :     }
     637             :     else
     638             :     {
     639           0 :         aColor = aColorList.GetSelectEntryColor();
     640           0 :         rValue.nColor = aColor.GetColor();
     641             :     }
     642           0 :     SetColor(aColor);
     643           0 : }
     644             : 
     645             : // color of an extended entry has changed
     646           0 : void ColorConfigWindow_Impl::Entry::ColorChanged (
     647             :     ExtendedColorConfigValue& rValue
     648             : ) {
     649           0 :     Color aColor = aColorList.GetSelectEntryColor();
     650           0 :     rValue.setColor(aColor.GetColor());
     651             :     // automatic?
     652           0 :     if (aColorList.GetSelectEntryPos() == 0)
     653             :     {
     654           0 :         rValue.setColor(rValue.getDefaultColor());
     655           0 :         aColor.SetColor(rValue.getColor());
     656             :     }
     657           0 :     SetColor(aColor);
     658           0 : }
     659             : 
     660           0 : void ColorConfigWindow_Impl::Entry::SetColor (Color aColor)
     661             : {
     662           0 :     aPreview.SetBackground(Wallpaper(aColor));
     663           0 :     aPreview.Invalidate();
     664           0 : }
     665             : 
     666             : 
     667             : //
     668             : // ColorConfigWindow_Impl
     669             : //
     670             : 
     671           0 : ColorConfigWindow_Impl::ColorConfigWindow_Impl (Window* pParent, ResId const& rResId) :
     672           0 :     Window(pParent, rResId)
     673             : {
     674           0 :     CreateEntries(*rResId.GetResMgr());
     675           0 :     Resource::FreeResource();
     676           0 :     SetAppearance();
     677           0 : }
     678             : 
     679           0 : void ColorConfigWindow_Impl::CreateEntries (ResMgr& rResMgr)
     680             : {
     681             :     // creating group headers
     682           0 :     vChapters.reserve(nGroupCount);
     683           0 :     for (unsigned i = 0; i != nGroupCount; ++i)
     684             :     {
     685             :         vChapters.push_back(boost::shared_ptr<Chapter> (
     686           0 :             new Chapter( *this, static_cast<Group>(i), rResMgr ) ) );
     687             :     }
     688             : 
     689             :     // creating entries
     690           0 :     vEntries.reserve(ColorConfigEntryCount);
     691           0 :     for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
     692           0 :         vEntries.push_back( boost::shared_ptr<Entry>(new Entry (*this, i, rResMgr) ) );
     693             : 
     694             :     // calculate heights of groups which can be hidden
     695             :     {
     696           0 :         unsigned nNextY = GetPosBehindLastChapter(); // next Y coordinate
     697           0 :         for (int i = nGroupCount - 1; i >= 0; --i)
     698             :         {
     699           0 :             unsigned nY = vChapters[i]->GetTop();
     700           0 :             vChapters[i]->SetHeight(nNextY - nY);
     701           0 :             nNextY = nY;
     702             :         }
     703             :     }
     704             : 
     705             :     // extended entries
     706           0 :     ExtendedColorConfig aExtConfig;
     707           0 :     if (unsigned const nExtGroupCount = aExtConfig.GetComponentCount())
     708             :     {
     709           0 :         unsigned nLineNum = ( GetPosBehindLastChapter() /
     710           0 :             LogicToPixel(Size(0, LINE_HEIGHT), MAP_APPFONT).Height() ) + 1;
     711           0 :         for (unsigned j = 0; j != nExtGroupCount; ++j)
     712             :         {
     713           0 :             rtl::OUString const sComponentName = aExtConfig.GetComponentName(j);
     714             :             vChapters.push_back(boost::shared_ptr<Chapter>(new Chapter (
     715             :                 *this, rResMgr, nLineNum * LINE_HEIGHT,
     716             :                 aExtConfig.GetComponentDisplayName(sComponentName)
     717           0 :             )));
     718           0 :             ++nLineNum;
     719           0 :             unsigned nColorCount = aExtConfig.GetComponentColorCount(sComponentName);
     720           0 :             for (unsigned i = 0; i != nColorCount; ++i)
     721             :             {
     722             :                 ExtendedColorConfigValue const aColorEntry =
     723           0 :                     aExtConfig.GetComponentColorConfigValue(sComponentName, i);
     724             :                 vEntries.push_back(boost::shared_ptr<Entry>( new Entry (
     725             :                     *this, rResMgr, nLineNum * LINE_HEIGHT, aColorEntry
     726           0 :                 )));
     727           0 :                 ++nLineNum;
     728           0 :             }
     729           0 :         }
     730           0 :     }
     731           0 : }
     732             : 
     733           0 : void ColorConfigWindow_Impl::SetAppearance ()
     734             : {
     735           0 :     Color TempColor(COL_TRANSPARENT);
     736           0 :     Wallpaper const aTransparentWall(TempColor);
     737           0 :     StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
     738           0 :     Color const aBackColor = rStyleSettings.GetHighContrastMode() ?
     739           0 :         rStyleSettings.GetShadowColor() : Color(COL_LIGHTGRAY);
     740           0 :     Wallpaper const aBackWall(aBackColor);
     741           0 :     for (unsigned i = 0; i != vChapters.size(); ++i)
     742             :     {
     743           0 :         if (IsGroupVisible(static_cast<Group>(i)))
     744           0 :             vChapters[i]->Show(aBackWall);
     745             :         else
     746           0 :             vChapters[i]->Hide();
     747             :     }
     748           0 :     SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
     749           0 :     SetHelpId(HID_OPTIONS_COLORCONFIG_COLORLIST_WIN);
     750             : 
     751             :     // #104195# when the window color is the same as the text color it has to be changed
     752           0 :     Color aWinCol = rStyleSettings.GetWindowColor();
     753           0 :     Color aRCheckCol = rStyleSettings.GetRadioCheckTextColor();
     754           0 :     if (aWinCol == aRCheckCol)
     755             :     {
     756           0 :         aRCheckCol.Invert();
     757             :         // if inversion didn't work (gray) then it's set to black
     758           0 :         if (aRCheckCol == aWinCol)
     759           0 :             aRCheckCol = Color(COL_BLACK);
     760             :         // setting new text color for each entry
     761           0 :         for (unsigned i = 0; i != vEntries.size(); ++i)
     762           0 :             vEntries[i]->SetTextColor(aRCheckCol);
     763             :     }
     764             : 
     765             :     OSL_ENSURE( vEntries.size() >= sizeof vEntryInfo / sizeof vEntryInfo[0], "wrong number of helpIDs for color listboxes" );
     766             : 
     767             :     // creating a sample color listbox with the color entries
     768           0 :     ColorListBox aSampleColorList(this);
     769             :     {
     770           0 :         XColorListRef const xColorTable = XColorList::CreateStdColorList();
     771           0 :         for (sal_Int32 i = 0; i != xColorTable->Count(); ++i)
     772             :         {
     773           0 :             XColorEntry& rEntry = *xColorTable->GetColor(i);
     774           0 :             aSampleColorList.InsertEntry(rEntry.GetColor(), rEntry.GetName());
     775           0 :         }
     776             :     }
     777             : 
     778             :     // positioning and appearance
     779           0 :     Group eGroup = Group_Unknown;
     780           0 :     for (unsigned i = 0; i != vEntries.size(); ++i)
     781             :     {
     782           0 :         Group const eNewGroup = GetGroup(i);
     783           0 :         bool const bShow = IsGroupVisible(eNewGroup);
     784           0 :         long const nDelta = bShow ? -GetDeltaAbove(eNewGroup) : 0;
     785             : 
     786             :         // new group?
     787           0 :         if (eNewGroup > eGroup)
     788             :         {
     789           0 :             eGroup = eNewGroup;
     790           0 :             if (bShow)
     791           0 :                 vChapters[eGroup]->MoveVertically(nDelta);
     792             :         }
     793             :         // positioning
     794           0 :         if (bShow)
     795           0 :             vEntries[i]->MoveVertically(nDelta);
     796             :         else
     797           0 :             vEntries[i]->Hide();
     798             :         // appearance
     799           0 :         vEntries[i]->SetAppearance(i, aTransparentWall, aSampleColorList);
     800           0 :     }
     801           0 : }
     802             : 
     803             : 
     804           0 : ColorConfigWindow_Impl::~ColorConfigWindow_Impl ()
     805           0 : { }
     806             : 
     807           0 : void ColorConfigWindow_Impl::SetHeaderBar (
     808             :     HeaderBar& rHeaderBar, ScrollBar const& rVScroll, ResMgr& rResMgr
     809             : ) {
     810             :     rHeaderBar.SetPosSizePixel(
     811             :         Point(0, 0),
     812           0 :         Size(GetParent()->GetOutputSizePixel().Width(), rVScroll.GetPosPixel().Y())
     813           0 :     );
     814           0 :     vEntries.front()->SetHeader(*this, rHeaderBar, rResMgr);
     815           0 :     rHeaderBar.Show();
     816           0 : }
     817             : 
     818           0 : void ColorConfigWindow_Impl::SetScrollBar (ScrollBar& rVScroll)
     819             : {
     820           0 :     rVScroll.EnableDrag();
     821           0 :     rVScroll.Show();
     822           0 :     rVScroll.SetRangeMin(0);
     823             :     unsigned const nScrollOffset =
     824           0 :         vEntries[1]->GetTop() - vEntries[0]->GetTop();
     825           0 :     unsigned const nVisibleEntries = GetSizePixel().Height() / nScrollOffset;
     826             : 
     827           0 :     rVScroll.SetRangeMax(vEntries.size() + vChapters.size());
     828             :     { // dynamic: calculate the hidden lines
     829           0 :         unsigned nInvisibleLines = 0;
     830           0 :         Group eGroup = Group_Unknown;
     831           0 :         for (unsigned i = 0; i != vEntries.size(); ++i)
     832             :         {
     833           0 :             Group const eNewGroup = GetGroup(i);
     834           0 :             bool const bVisible = IsGroupVisible(eNewGroup);
     835           0 :             if (!bVisible)
     836           0 :                 nInvisibleLines++;
     837           0 :             if (eNewGroup > eGroup)
     838             :             {
     839           0 :                 eGroup = eNewGroup;
     840           0 :                 if (!bVisible)
     841           0 :                     nInvisibleLines++;
     842             :             }
     843             :         }
     844           0 :         rVScroll.SetRangeMax(rVScroll.GetRangeMax() - nInvisibleLines);
     845             :     }
     846             : 
     847           0 :     rVScroll.SetPageSize(nVisibleEntries - 1);
     848           0 :     rVScroll.SetVisibleSize(nVisibleEntries);
     849           0 : }
     850             : 
     851             : // SetLinks()
     852           0 : void ColorConfigWindow_Impl::SetLinks (
     853             :     Link const& aCheckLink, Link const& aColorLink, Link const& aGetFocusLink
     854             : ) {
     855           0 :     for (unsigned i = 0; i != vEntries.size(); ++i)
     856           0 :         vEntries[i]->SetLinks(aCheckLink, aColorLink, aGetFocusLink);
     857           0 : }
     858             : 
     859             : // Update()
     860           0 : void ColorConfigWindow_Impl::Update (
     861             :     EditableColorConfig const* pConfig,
     862             :     EditableExtendedColorConfig const* pExtConfig
     863             : ) {
     864             :     // updating default entries
     865           0 :     for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
     866             :     {
     867           0 :         ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
     868           0 :         vEntries[i]->Update(
     869           0 :             aColorEntry, pConfig->GetColorValue(aColorEntry)
     870           0 :         );
     871             :     }
     872             : 
     873             :     // updating extended entries
     874           0 :     unsigned i = ColorConfigEntryCount;
     875           0 :     unsigned const nExtCount = pExtConfig->GetComponentCount();
     876           0 :     for (unsigned j = 0; j != nExtCount; ++j)
     877             :     {
     878           0 :         rtl::OUString sComponentName = pExtConfig->GetComponentName(j);
     879           0 :         unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
     880           0 :         for (unsigned k = 0; i != vEntries.size() && k != nColorCount; ++i, ++k)
     881           0 :             vEntries[i]->Update(
     882             :                 pExtConfig->GetComponentColorConfigValue(sComponentName, k)
     883           0 :             );
     884           0 :     }
     885           0 : }
     886             : 
     887             : // ScrollHdl()
     888           0 : void ColorConfigWindow_Impl::ScrollHdl (long& nScrollPos, ScrollBar const& rVScroll)
     889             : {
     890           0 :     SetUpdateMode(true);
     891             :     long const nOffset =
     892           0 :         (vEntries[1]->GetTop() - vEntries[0]->GetTop()) *
     893           0 :         (nScrollPos - rVScroll.GetThumbPos());
     894           0 :     nScrollPos = rVScroll.GetThumbPos();
     895           0 :     long const nWindowHeight = GetSizePixel().Height();
     896           0 :     int nFirstVisible = -1, nLastVisible = -1;
     897           0 :     for (unsigned i = 0; i != vEntries.size(); ++i)
     898             :     {
     899             :         //controls outside of the view need to be hidden to speed up accessibility tools
     900           0 :         bool const bShowCtrl = IsGroupVisible(GetGroup(i));
     901           0 :         if (vEntries[i]->MoveAndShow(nOffset, nWindowHeight, bShowCtrl))
     902             :         {
     903           0 :             if (nFirstVisible == -1)
     904           0 :                 nFirstVisible = i;
     905             :             else
     906           0 :                 nLastVisible = i;
     907             :         }
     908             :     }
     909             : 
     910             :     // show the one prior to the first visible and the first after the last visble control
     911             :     // to enable KEY_TAB travelling
     912           0 :     if(nFirstVisible > 0)
     913             :     {
     914           0 :         --nFirstVisible;
     915           0 :         if (IsGroupVisible(GetGroup(nFirstVisible)))
     916           0 :             vEntries[nFirstVisible]->Show();
     917             :     }
     918           0 :     if (nLastVisible != -1 && (unsigned)nLastVisible < vEntries.size() - 1)
     919             :     {
     920           0 :         ++nLastVisible;
     921           0 :         if (IsGroupVisible(GetGroup(nLastVisible)))
     922           0 :             vEntries[nLastVisible]->Show();
     923             :     }
     924             : 
     925           0 :     for (unsigned i = 0; i != vChapters.size(); ++i)
     926           0 :         vChapters[i]->MoveVertically(nOffset);
     927           0 :     SetUpdateMode(true);
     928           0 : }
     929             : 
     930             : // ClickHdl()
     931           0 : void ColorConfigWindow_Impl::ClickHdl (EditableColorConfig* pConfig, CheckBox* pBox)
     932             : {
     933           0 :     for (unsigned i = 0; i != ColorConfigEntryCount; ++i)
     934             :     {
     935           0 :         if (vEntries[i]->Is(pBox))
     936             :         {
     937           0 :             ColorConfigEntry const aEntry = static_cast<ColorConfigEntry>(i);
     938           0 :             ColorConfigValue aValue = pConfig->GetColorValue(aEntry);
     939           0 :             aValue.bIsVisible = pBox->IsChecked();
     940           0 :             pConfig->SetColorValue(aEntry, aValue);
     941             :             break;
     942             :         }
     943             :     }
     944           0 : }
     945             : 
     946             : // ColorHdl()
     947           0 : void ColorConfigWindow_Impl::ColorHdl (
     948             :     EditableColorConfig* pConfig, EditableExtendedColorConfig* pExtConfig,
     949             :     ColorListBox* pBox
     950             : ) {
     951           0 :     unsigned i = 0;
     952             : 
     953             :     // default entries
     954           0 :     for ( ; i != ColorConfigEntryCount; ++i)
     955             :     {
     956           0 :         if (pBox && vEntries[i]->Is(pBox))
     957             :         {
     958           0 :             ColorConfigEntry const aColorEntry = static_cast<ColorConfigEntry>(i);
     959           0 :             ColorConfigValue aValue = pConfig->GetColorValue(aColorEntry);
     960           0 :             vEntries[i]->ColorChanged(aColorEntry, aValue);
     961           0 :             pConfig->SetColorValue(aColorEntry, aValue);
     962             :             break;
     963             :         }
     964             :     }
     965             : 
     966             :     // extended entries
     967           0 :     unsigned const nExtCount = pExtConfig->GetComponentCount();
     968           0 :     for (unsigned j = 0; j != nExtCount; ++j)
     969             :     {
     970           0 :         rtl::OUString sComponentName = pExtConfig->GetComponentName(j);
     971           0 :         unsigned const nColorCount = pExtConfig->GetComponentColorCount(sComponentName);
     972           0 :         unsigned const nCount = vEntries.size();
     973           0 :         for (unsigned k = 0; i != nCount && k != nColorCount; ++i, ++k)
     974             :         {
     975           0 :             if (pBox && vEntries[i]->Is(pBox))
     976             :             {
     977             :                 ExtendedColorConfigValue aValue =
     978           0 :                     pExtConfig->GetComponentColorConfigValue(sComponentName, k);
     979           0 :                 vEntries[i]->ColorChanged(aValue);
     980           0 :                 pExtConfig->SetColorValue(sComponentName, aValue);
     981           0 :                 break;
     982             :             }
     983             :         }
     984           0 :     }
     985           0 : }
     986             : 
     987             : 
     988             : // IsGroupVisible()
     989           0 : bool ColorConfigWindow_Impl::IsGroupVisible (Group eGroup) const
     990             : {
     991           0 :     switch (eGroup)
     992             :     {
     993             :         case Group_Writer:
     994             :         case Group_Html:
     995           0 :             return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SWRITER);
     996             : 
     997             :         case Group_Calc:
     998           0 :             return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SCALC);
     999             : 
    1000             :         case Group_Draw:
    1001             :             return
    1002           0 :                 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDRAW) ||
    1003           0 :                 aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SIMPRESS);
    1004             : 
    1005             :         case Group_Sql:
    1006           0 :             return aModuleOptions.IsModuleInstalled(SvtModuleOptions::E_SDATABASE);
    1007             : 
    1008             :         default:
    1009           0 :             return true;
    1010             :     }
    1011             : }
    1012             : 
    1013             : // calculate position behind last chapter
    1014           0 : unsigned ColorConfigWindow_Impl::GetPosBehindLastChapter () const
    1015             : {
    1016           0 :     int nLastY = vEntries.back()->GetBottom();
    1017           0 :     nLastY += LogicToPixel( Size(0, 3), MAP_APPFONT ).Height();
    1018           0 :     return nLastY;
    1019             : }
    1020             : 
    1021             : // calculates the overall height of the invisible groups above eGroup
    1022           0 : long ColorConfigWindow_Impl::GetDeltaAbove (Group eGroup) const
    1023             : {
    1024           0 :     long nDelta = 0;
    1025           0 :     for (int i = 0; i != eGroup; ++i)
    1026           0 :         if (!IsGroupVisible(static_cast<Group>(i)))
    1027           0 :             nDelta += vChapters[i]->GetHeight();
    1028           0 :     return nDelta;
    1029             : }
    1030             : 
    1031           0 : void ColorConfigWindow_Impl::DataChanged (DataChangedEvent const& rDCEvt)
    1032             : {
    1033           0 :     Window::DataChanged( rDCEvt );
    1034           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    1035           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    1036             :     {
    1037           0 :         StyleSettings const& rStyleSettings = GetSettings().GetStyleSettings();
    1038           0 :         bool const bHighContrast = rStyleSettings.GetHighContrastMode();
    1039           0 :         Wallpaper const aBackWall(Color(bHighContrast ? COL_TRANSPARENT : COL_LIGHTGRAY));
    1040           0 :         for (unsigned i = 0; i != vChapters.size(); ++i)
    1041           0 :             vChapters[i]->SetBackground(aBackWall);
    1042           0 :         SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
    1043             :     }
    1044           0 : }
    1045             : 
    1046             : 
    1047           0 : void ColorConfigWindow_Impl::Command( const CommandEvent& rCEvt )
    1048             : {
    1049           0 :     GetParent()->Command(rCEvt);
    1050           0 : }
    1051             : 
    1052             : //
    1053             : // ColorConfigCtrl_Impl
    1054             : //
    1055             : 
    1056             : class ColorConfigCtrl_Impl : public Control
    1057             : {
    1058             :     HeaderBar               aHeaderHB;
    1059             :     ScrollBar               aVScroll;
    1060             : 
    1061             :     ColorConfigWindow_Impl  aScrollWindow;
    1062             : 
    1063             :     EditableColorConfig*            pColorConfig;
    1064             :     EditableExtendedColorConfig*    pExtColorConfig;
    1065             : 
    1066             :     long nScrollPos;
    1067             : 
    1068             :     DECL_LINK(ScrollHdl, ScrollBar*);
    1069             :     DECL_LINK(ClickHdl, CheckBox*);
    1070             :     DECL_LINK(ColorHdl, ColorListBox*);
    1071             :     DECL_LINK(ControlFocusHdl, Control*);
    1072             : 
    1073             :     virtual long PreNotify (NotifyEvent& rNEvt);
    1074             :     virtual void Command (CommandEvent const& rCEvt);
    1075             :     virtual void DataChanged (DataChangedEvent const& rDCEvt);
    1076             : public:
    1077             :     ColorConfigCtrl_Impl (Window* pParent, ResId const& rResId);
    1078             :     ~ColorConfigCtrl_Impl ();
    1079             : 
    1080           0 :     void SetConfig (EditableColorConfig& rConfig) { pColorConfig = &rConfig; }
    1081           0 :     void SetExtendedConfig (EditableExtendedColorConfig& rConfig) { pExtColorConfig = &rConfig; }
    1082             :     void Update ();
    1083           0 :     long GetScrollPosition () { return aVScroll.GetThumbPos(); }
    1084           0 :     void SetScrollPosition (long nSet)
    1085             :     {
    1086           0 :         aVScroll.SetThumbPos(nSet);
    1087           0 :         ScrollHdl(&aVScroll);
    1088           0 :     }
    1089             : };
    1090             : 
    1091           0 : ColorConfigCtrl_Impl::ColorConfigCtrl_Impl (
    1092             :     Window* pParent, ResId const& rResId
    1093             : ) :
    1094             :     Control(pParent, rResId),
    1095             : 
    1096             :     aHeaderHB(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
    1097           0 :     aVScroll(this,      ResId(VB_VSCROLL, *rResId.GetResMgr())),
    1098           0 :     aScrollWindow(this, ResId(WN_SCROLL,  *rResId.GetResMgr())),
    1099             : 
    1100             :     pColorConfig(0),
    1101             :     pExtColorConfig(0),
    1102           0 :     nScrollPos(0)
    1103             : {
    1104           0 :     aScrollWindow.SetHeaderBar(aHeaderHB, aVScroll, *rResId.GetResMgr());
    1105           0 :     aScrollWindow.SetScrollBar(aVScroll);
    1106             : 
    1107           0 :     Resource::FreeResource();
    1108             : 
    1109           0 :     Link aScrollLink = LINK(this, ColorConfigCtrl_Impl, ScrollHdl);
    1110           0 :     aVScroll.SetScrollHdl(aScrollLink);
    1111           0 :     aVScroll.SetEndScrollHdl(aScrollLink);
    1112             : 
    1113           0 :     Link aCheckLink = LINK(this, ColorConfigCtrl_Impl, ClickHdl);
    1114           0 :     Link aColorLink = LINK(this, ColorConfigCtrl_Impl, ColorHdl);
    1115           0 :     Link aGetFocusLink = LINK(this, ColorConfigCtrl_Impl, ControlFocusHdl);
    1116           0 :     aScrollWindow.SetLinks(aCheckLink, aColorLink, aGetFocusLink);
    1117           0 : }
    1118             : 
    1119           0 : ColorConfigCtrl_Impl::~ColorConfigCtrl_Impl()
    1120             : {
    1121           0 : }
    1122             : 
    1123           0 : void ColorConfigCtrl_Impl::Update ()
    1124             : {
    1125             :     DBG_ASSERT(pColorConfig, "Configuration not set");
    1126           0 :     aScrollWindow.Update(pColorConfig, pExtColorConfig);
    1127           0 : }
    1128             : 
    1129           0 : IMPL_LINK(ColorConfigCtrl_Impl, ScrollHdl, ScrollBar*, pScrollBar)
    1130             : {
    1131           0 :     aScrollWindow.ScrollHdl(nScrollPos, *pScrollBar);
    1132           0 :     return 0;
    1133             : }
    1134             : 
    1135           0 : long ColorConfigCtrl_Impl::PreNotify( NotifyEvent& rNEvt )
    1136             : {
    1137           0 :     if(rNEvt.GetType() == EVENT_COMMAND)
    1138             :     {
    1139           0 :         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
    1140           0 :         sal_uInt16 nCmd = pCEvt->GetCommand();
    1141           0 :         if( COMMAND_WHEEL == nCmd )
    1142             :         {
    1143           0 :             Command(*pCEvt);
    1144           0 :             return 1;
    1145             :         }
    1146             :     }
    1147           0 :     return Control::PreNotify(rNEvt);
    1148             : }
    1149             : 
    1150           0 : void ColorConfigCtrl_Impl::Command( const CommandEvent& rCEvt )
    1151             : {
    1152           0 :     switch ( rCEvt.GetCommand() )
    1153             :     {
    1154             : 
    1155             :         case COMMAND_WHEEL:
    1156             :         case COMMAND_STARTAUTOSCROLL:
    1157             :         case COMMAND_AUTOSCROLL:
    1158             :         {
    1159           0 :             const CommandWheelData* pWheelData = rCEvt.GetWheelData();
    1160           0 :             if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
    1161             :             {
    1162           0 :                 HandleScrollCommand( rCEvt, 0, &aVScroll );
    1163             :             }
    1164             :         }
    1165           0 :         break;
    1166             :         default:
    1167           0 :             Control::Command(rCEvt);
    1168             :     }
    1169           0 : }
    1170             : 
    1171           0 : void ColorConfigCtrl_Impl::DataChanged( const DataChangedEvent& rDCEvt )
    1172             : {
    1173           0 :     Window::DataChanged( rDCEvt );
    1174           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    1175           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    1176             :     {
    1177           0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
    1178           0 :         SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
    1179             :     }
    1180           0 : }
    1181             : 
    1182           0 : IMPL_LINK(ColorConfigCtrl_Impl, ClickHdl, CheckBox*, pBox)
    1183             : {
    1184             :     DBG_ASSERT(pColorConfig, "Configuration not set");
    1185           0 :     aScrollWindow.ClickHdl(pColorConfig, pBox);
    1186           0 :     return 0;
    1187             : }
    1188             : 
    1189             : // a color list has changed
    1190           0 : IMPL_LINK(ColorConfigCtrl_Impl, ColorHdl, ColorListBox*, pBox)
    1191             : {
    1192             :     DBG_ASSERT(pColorConfig, "Configuration not set" );
    1193           0 :     if (pBox)
    1194           0 :         aScrollWindow.ColorHdl(pColorConfig, pExtColorConfig, pBox);
    1195           0 :     return 0;
    1196             : }
    1197           0 : IMPL_LINK(ColorConfigCtrl_Impl, ControlFocusHdl, Control*, pCtrl)
    1198             : {
    1199             :     // determine whether a control is completely visible
    1200             :     // and make it visible
    1201           0 :     long aCtrlPosY = pCtrl->GetPosPixel().Y();
    1202           0 :     unsigned const nWinHeight = aScrollWindow.GetSizePixel().Height();
    1203           0 :     unsigned const nEntryHeight = aScrollWindow.GetEntryHeight();
    1204           0 :     if (0 != (GETFOCUS_TAB & pCtrl->GetGetFocusFlags()) &&
    1205             :         (aCtrlPosY < 0 || nWinHeight < aCtrlPosY + nEntryHeight)
    1206             :     ) {
    1207           0 :         long nThumbPos = aVScroll.GetThumbPos();
    1208           0 :         if (nWinHeight < aCtrlPosY + nEntryHeight)
    1209             :         {
    1210             :             //scroll down
    1211           0 :             nThumbPos += 2;
    1212             :         }
    1213             :         else
    1214             :         {
    1215             :             //scroll up
    1216           0 :             nThumbPos -= 2;
    1217           0 :             if(nThumbPos < 0)
    1218           0 :                 nThumbPos = 0;
    1219             :         }
    1220           0 :         aVScroll.SetThumbPos(nThumbPos);
    1221           0 :         ScrollHdl(&aVScroll);
    1222             :     }
    1223           0 :     return 0;
    1224             : };
    1225             : 
    1226             : 
    1227             : //
    1228             : // SvxColorOptionsTabPage
    1229             : //
    1230             : 
    1231           0 : SvxColorOptionsTabPage::SvxColorOptionsTabPage(
    1232             :     Window* pParent, const SfxItemSet& rCoreSet) :
    1233           0 :     SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_COLORCONFIG ), rCoreSet ),
    1234           0 :        aColorSchemeFL(  this, CUI_RES( FL_COLORSCHEME ) ),
    1235           0 :        aColorSchemeFT(  this, CUI_RES( FT_COLORSCHEME ) ),
    1236           0 :        aColorSchemeLB(  this, CUI_RES( LB_COLORSCHEME ) ),
    1237           0 :        aSaveSchemePB(   this, CUI_RES( PB_SAVESCHEME) ),
    1238           0 :        aDeleteSchemePB( this, CUI_RES( PB_DELETESCHEME ) ),
    1239           0 :        aCustomColorsFL( this, CUI_RES( FL_CUSTOMCOLORS ) ),
    1240             :        bFillItemSetCalled(sal_False),
    1241             :        pColorConfig(0),
    1242             :        pExtColorConfig(0),
    1243           0 :        pColorConfigCT(  new ColorConfigCtrl_Impl(this, CUI_RES( CT_COLORCONFIG ) ))
    1244             : {
    1245           0 :     FreeResource();
    1246           0 :     aColorSchemeLB.SetSelectHdl(LINK(this, SvxColorOptionsTabPage, SchemeChangedHdl_Impl));
    1247           0 :     Link aLk = LINK(this, SvxColorOptionsTabPage, SaveDeleteHdl_Impl );
    1248           0 :     aSaveSchemePB.SetClickHdl(aLk);
    1249           0 :     aDeleteSchemePB.SetClickHdl(aLk);
    1250           0 : }
    1251             : 
    1252           0 : SvxColorOptionsTabPage::~SvxColorOptionsTabPage()
    1253             : {
    1254             :     //when the dialog is cancelled but the color scheme ListBox has been changed these
    1255             :     //changes need to be undone
    1256           0 :     if(!bFillItemSetCalled && aColorSchemeLB.GetSavedValue() != aColorSchemeLB.GetSelectEntryPos())
    1257             :     {
    1258           0 :         rtl::OUString sOldScheme =  aColorSchemeLB.GetEntry(aColorSchemeLB.GetSavedValue());
    1259           0 :         if(!sOldScheme.isEmpty())
    1260             :         {
    1261           0 :             pColorConfig->SetCurrentSchemeName(sOldScheme);
    1262           0 :             pExtColorConfig->SetCurrentSchemeName(sOldScheme);
    1263           0 :         }
    1264             :     }
    1265           0 :     delete pColorConfigCT;
    1266           0 :     pColorConfig->ClearModified();
    1267           0 :     pColorConfig->EnableBroadcast();
    1268           0 :     delete pColorConfig;
    1269           0 :     pExtColorConfig->ClearModified();
    1270           0 :     pExtColorConfig->EnableBroadcast();
    1271           0 :     delete pExtColorConfig;
    1272           0 : }
    1273             : 
    1274           0 : SfxTabPage* SvxColorOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
    1275             : {
    1276           0 :     return ( new SvxColorOptionsTabPage( pParent, rAttrSet ) );
    1277             : }
    1278             : 
    1279           0 : sal_Bool SvxColorOptionsTabPage::FillItemSet( SfxItemSet&  )
    1280             : {
    1281           0 :     bFillItemSetCalled = sal_True;
    1282           0 :     if(aColorSchemeLB.GetSavedValue() != aColorSchemeLB.GetSelectEntryPos())
    1283             :     {
    1284           0 :         pColorConfig->SetModified();
    1285           0 :         pExtColorConfig->SetModified();
    1286             :     }
    1287           0 :     if(pColorConfig->IsModified())
    1288           0 :         pColorConfig->Commit();
    1289           0 :     if(pExtColorConfig->IsModified())
    1290           0 :         pExtColorConfig->Commit();
    1291           0 :     return sal_True;
    1292             : }
    1293             : 
    1294           0 : void SvxColorOptionsTabPage::Reset( const SfxItemSet& )
    1295             : {
    1296           0 :     if(pColorConfig)
    1297             :     {
    1298           0 :         pColorConfig->ClearModified();
    1299           0 :         pColorConfig->DisableBroadcast();
    1300           0 :         delete pColorConfig;
    1301             :     }
    1302           0 :     pColorConfig = new EditableColorConfig;
    1303           0 :     pColorConfigCT->SetConfig(*pColorConfig);
    1304             : 
    1305           0 :     if(pExtColorConfig)
    1306             :     {
    1307           0 :         pExtColorConfig->ClearModified();
    1308           0 :         pExtColorConfig->DisableBroadcast();
    1309           0 :         delete pExtColorConfig;
    1310             :     }
    1311           0 :     pExtColorConfig = new EditableExtendedColorConfig;
    1312           0 :     pColorConfigCT->SetExtendedConfig(*pExtColorConfig);
    1313             : 
    1314           0 :     String sUser = GetUserData();
    1315             :     //has to be called always to speed up accessibility tools
    1316           0 :     pColorConfigCT->SetScrollPosition(sUser.ToInt32());
    1317           0 :     aColorSchemeLB.Clear();
    1318           0 :     uno::Sequence< ::rtl::OUString >  aSchemes = pColorConfig->GetSchemeNames();
    1319           0 :     const rtl::OUString* pSchemes = aSchemes.getConstArray();
    1320           0 :     for(sal_Int32 i = 0; i < aSchemes.getLength(); i++)
    1321           0 :         aColorSchemeLB.InsertEntry(pSchemes[i]);
    1322           0 :     aColorSchemeLB.SelectEntry(pColorConfig->GetCurrentSchemeName());
    1323           0 :     aColorSchemeLB.SaveValue();
    1324           0 :     aDeleteSchemePB.Enable( aSchemes.getLength() > 1 );
    1325           0 :     UpdateColorConfig();
    1326           0 : }
    1327             : 
    1328           0 : int SvxColorOptionsTabPage::DeactivatePage( SfxItemSet* pSet_ )
    1329             : {
    1330           0 :     if ( pSet_ )
    1331           0 :         FillItemSet( *pSet_ );
    1332           0 :     return( LEAVE_PAGE );
    1333             : }
    1334             : 
    1335           0 : void SvxColorOptionsTabPage::UpdateColorConfig()
    1336             : {
    1337             :     //update the color config control
    1338           0 :     pColorConfigCT->Update();
    1339           0 : }
    1340             : 
    1341           0 : IMPL_LINK(SvxColorOptionsTabPage, SchemeChangedHdl_Impl, ListBox*, pBox)
    1342             : {
    1343           0 :     pColorConfig->LoadScheme(pBox->GetSelectEntry());
    1344           0 :     pExtColorConfig->LoadScheme(pBox->GetSelectEntry());
    1345           0 :     UpdateColorConfig();
    1346           0 :     return 0;
    1347             : }
    1348             : 
    1349           0 : IMPL_LINK(SvxColorOptionsTabPage, SaveDeleteHdl_Impl, PushButton*, pButton )
    1350             : {
    1351           0 :     if(&aSaveSchemePB == pButton)
    1352             :     {
    1353           0 :         String sName;
    1354             : 
    1355           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1356             :         DBG_ASSERT(pFact, "Dialogdiet fail!");
    1357             :         AbstractSvxNameDialog* aNameDlg = pFact->CreateSvxNameDialog( pButton,
    1358           0 :                             sName, String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE2)) );
    1359             :         DBG_ASSERT(aNameDlg, "Dialogdiet fail!");
    1360           0 :         aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
    1361           0 :         aNameDlg->SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_SAVE1)));
    1362           0 :         aNameDlg->SetHelpId(HID_OPTIONS_COLORCONFIG_SAVE_SCHEME);
    1363           0 :         aNameDlg->SetEditHelpId(HID_OPTIONS_COLORCONFIG_NAME_SCHEME);
    1364           0 :         aNameDlg->SetCheckNameHdl( LINK(this, SvxColorOptionsTabPage, CheckNameHdl_Impl));
    1365           0 :         if(RET_OK == aNameDlg->Execute())
    1366             :         {
    1367           0 :             aNameDlg->GetName(sName);
    1368           0 :             pColorConfig->AddScheme(sName);
    1369           0 :             pExtColorConfig->AddScheme(sName);
    1370           0 :             aColorSchemeLB.InsertEntry(sName);
    1371           0 :             aColorSchemeLB.SelectEntry(sName);
    1372           0 :             aColorSchemeLB.GetSelectHdl().Call(&aColorSchemeLB);
    1373             :         }
    1374           0 :         delete aNameDlg;
    1375             :     }
    1376             :     else
    1377             :     {
    1378             :         DBG_ASSERT(aColorSchemeLB.GetEntryCount() > 1, "don't delete the last scheme");
    1379           0 :         QueryBox aQuery(pButton, CUI_RES(RID_SVXQB_DELETE_COLOR_CONFIG));
    1380           0 :         aQuery.SetText(String(CUI_RES(RID_SVXSTR_COLOR_CONFIG_DELETE)));
    1381           0 :         if(RET_YES == aQuery.Execute())
    1382             :         {
    1383           0 :             rtl::OUString sDeleteScheme(aColorSchemeLB.GetSelectEntry());
    1384           0 :             aColorSchemeLB.RemoveEntry(aColorSchemeLB.GetSelectEntryPos());
    1385           0 :             aColorSchemeLB.SelectEntryPos(0);
    1386           0 :             aColorSchemeLB.GetSelectHdl().Call(&aColorSchemeLB);
    1387             :             //first select the new scheme and then delete the old one
    1388           0 :             pColorConfig->DeleteScheme(sDeleteScheme);
    1389           0 :             pExtColorConfig->DeleteScheme(sDeleteScheme);
    1390           0 :         }
    1391             :     }
    1392           0 :     aDeleteSchemePB.Enable( aColorSchemeLB.GetEntryCount() > 1 );
    1393           0 :     return 0;
    1394             : }
    1395             : 
    1396           0 : IMPL_LINK(SvxColorOptionsTabPage, CheckNameHdl_Impl, AbstractSvxNameDialog*, pDialog )
    1397             : {
    1398           0 :     String sName;
    1399           0 :     pDialog->GetName(sName);
    1400           0 :     return sName.Len() && LISTBOX_ENTRY_NOTFOUND == aColorSchemeLB.GetEntryPos( sName );
    1401             : }
    1402             : 
    1403           0 : void SvxColorOptionsTabPage::FillUserData()
    1404             : {
    1405           0 :     SetUserData(String::CreateFromInt32(pColorConfigCT->GetScrollPosition()));
    1406           3 : }
    1407             : 
    1408             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10