xref: /trunk/main/dbaccess/source/ui/misc/ToolBoxHelper.cxx (revision b63233d868a9af170b0457a7aa0c5809011cc2c1)
196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir #ifndef DBAUI_TOOLBOXHELPER_HXX
27cdf0e10cSrcweir #include "ToolBoxHelper.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef _SV_TOOLBOX_HXX
30cdf0e10cSrcweir #include <vcl/toolbox.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_MISCOPT_HXX
36cdf0e10cSrcweir #include <svtools/miscopt.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
39cdf0e10cSrcweir #include "UITools.hxx"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef _SVTOOLS_IMGDEF_HXX
42cdf0e10cSrcweir #include <svtools/imgdef.hxx>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <vcl/event.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace dbaui
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     DBG_NAME(OToolBoxHelper)
49cdf0e10cSrcweir     OToolBoxHelper::OToolBoxHelper()
50cdf0e10cSrcweir         : m_bIsHiContrast(sal_False)
51cdf0e10cSrcweir         ,m_nSymbolsSize(-1 )
52cdf0e10cSrcweir         ,m_pToolBox(NULL)
53cdf0e10cSrcweir     {
54cdf0e10cSrcweir         DBG_CTOR(OToolBoxHelper,NULL);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         OSL_ENSURE(m_nSymbolsSize != SvtMiscOptions().GetCurrentSymbolsSize(),"SymbolsSize should not be identical");
57cdf0e10cSrcweir         SvtMiscOptions().AddListenerLink( LINK( this, OToolBoxHelper, ConfigOptionsChanged ) );
58cdf0e10cSrcweir         Application::AddEventListener( LINK( this, OToolBoxHelper, SettingsChanged ) );
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir     // -----------------------------------------------------------------------------
61cdf0e10cSrcweir     OToolBoxHelper::~OToolBoxHelper()
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         SvtMiscOptions().RemoveListenerLink( LINK( this, OToolBoxHelper, ConfigOptionsChanged ) );
64cdf0e10cSrcweir         Application::RemoveEventListener( LINK( this, OToolBoxHelper, SettingsChanged ) );
65cdf0e10cSrcweir         DBG_DTOR(OToolBoxHelper,NULL);
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     // -----------------------------------------------------------------------------
69cdf0e10cSrcweir     void OToolBoxHelper::checkImageList()
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         if ( m_pToolBox )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             sal_Int16 nCurSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize();
74cdf0e10cSrcweir             if ( nCurSymbolsSize != m_nSymbolsSize ||
75cdf0e10cSrcweir                 m_bIsHiContrast != m_pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode() )
76cdf0e10cSrcweir             {
77cdf0e10cSrcweir                 m_nSymbolsSize  = nCurSymbolsSize;
78cdf0e10cSrcweir                 m_bIsHiContrast = m_pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir                 m_pToolBox->SetImageList( getImageList(m_nSymbolsSize,m_bIsHiContrast) );
82cdf0e10cSrcweir                 Size aTbOldSize = m_pToolBox->GetSizePixel();
83cdf0e10cSrcweir                 adjustToolBoxSize(m_pToolBox);
84cdf0e10cSrcweir                 Size aTbNewSize = m_pToolBox->GetSizePixel();
85cdf0e10cSrcweir                 resizeControls(Size(aTbNewSize.Width() - aTbOldSize.Width(),
86cdf0e10cSrcweir                                     aTbNewSize.Height() - aTbOldSize.Height())
87cdf0e10cSrcweir                                 );
88cdf0e10cSrcweir             }
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir     // -----------------------------------------------------------------------------
92cdf0e10cSrcweir     IMPL_LINK(OToolBoxHelper, ConfigOptionsChanged, SvtMiscOptions*, /*_pOptions*/)
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         if ( m_pToolBox )
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             SvtMiscOptions aOptions;
97cdf0e10cSrcweir             // check if imagelist changed
98cdf0e10cSrcweir             checkImageList();
99cdf0e10cSrcweir             if ( aOptions.GetToolboxStyle() != m_pToolBox->GetOutStyle() )
100cdf0e10cSrcweir                 m_pToolBox->SetOutStyle(aOptions.GetToolboxStyle());
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         return 0L;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir     // -----------------------------------------------------------------------------
106cdf0e10cSrcweir     IMPL_LINK(OToolBoxHelper, SettingsChanged, VclWindowEvent*, _pEvt)
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         if ( m_pToolBox && _pEvt && _pEvt->GetId() == VCLEVENT_APPLICATION_DATACHANGED )
109cdf0e10cSrcweir         {
110cdf0e10cSrcweir             DataChangedEvent* pData = reinterpret_cast<DataChangedEvent*>(_pEvt->GetData());
111cdf0e10cSrcweir             if ( pData && ((( pData->GetType() == DATACHANGED_SETTINGS  )   ||
112cdf0e10cSrcweir             ( pData->GetType() == DATACHANGED_DISPLAY   ))  &&
113cdf0e10cSrcweir             ( pData->GetFlags() & SETTINGS_STYLE        )))
114cdf0e10cSrcweir                 // check if imagelist changed
115cdf0e10cSrcweir                 checkImageList();
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         return 0L;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     // -----------------------------------------------------------------------------
121cdf0e10cSrcweir     void OToolBoxHelper::setToolBox(ToolBox* _pTB)
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         sal_Bool bFirstTime = (m_pToolBox == NULL);
124cdf0e10cSrcweir         m_pToolBox = _pTB;
125cdf0e10cSrcweir         if ( m_pToolBox )
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir             //  m_bIsHiContrast = m_pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();
128cdf0e10cSrcweir             ConfigOptionsChanged(NULL);
129cdf0e10cSrcweir             if ( bFirstTime )
130cdf0e10cSrcweir                 adjustToolBoxSize(m_pToolBox);
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir // -----------------------------------------------------------------------------
134cdf0e10cSrcweir } // namespace
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
136cdf0e10cSrcweir 
137