Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / sidebar / paragraph / ParaNumberingControl.cxx
blob6a597591838215a29f04941e0b74589ee3c30882
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "ParaNumberingControl.hxx"
20 #include "ParaPropertyPanel.hrc"
21 #include <sfx2/sidebar/ResourceDefinitions.hrc>
22 #include <svx/dialogs.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <unotools/viewoptions.hxx>
25 #include <editeng/kernitem.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/sidebar/Theme.hxx>
29 #include <svtools/unitconv.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
32 #include <com/sun/star/text/XNumberingFormatter.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <comphelper/processfactory.hxx>
35 #include <svx/nbdtmg.hxx>
36 #include <svx/nbdtmgfact.hxx>
37 #include <editeng/unolingu.hxx>
38 #include <vcl/settings.hxx>
40 using namespace com::sun::star;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::text;
46 namespace svx { namespace sidebar {
48 Reference<XDefaultNumberingProvider> lcl_GetNumberingProvider()
50 return DefaultNumberingProvider::create( comphelper::getProcessComponentContext() );
53 ParaNumberingControl::ParaNumberingControl(
54 Window* pParent,
55 svx::sidebar::ParaPropertyPanel& rPanel )
56 : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_PARAPAGE_NUMBERING) )
57 , maNumberVS( this,SVX_RES(VS_NUMBERING) )
58 , maMoreButton( this,SVX_RES(CB_NUMBERING_MORE) )
59 , mrParaPropertyPanel( rPanel )
60 , mpBindings( mrParaPropertyPanel.GetBindings() )
62 FreeResource();
64 maNumberVS.SetStyle( maNumberVS.GetStyle() | WB_NO_DIRECTSELECT );
65 maNumberVS.SetExtraSpacing( NUM_IMAGE_SPACING );
66 maNumberVS.SetItemWidth(NUM_IMAGE_WIDTH);
67 maNumberVS.SetItemHeight(NUM_IMAGE_HEIGHT);
69 Reference<XDefaultNumberingProvider> xDefNum = lcl_GetNumberingProvider();
70 if(xDefNum.is())
72 Sequence< Sequence< PropertyValue > > aNumberings;
73 Locale aLocale = GetSettings().GetLanguageTag().getLocale();
74 try
76 aNumberings = xDefNum->getDefaultContinuousNumberingLevels( aLocale );
78 catch(Exception&)
81 Reference<XNumberingFormatter> xFormat(xDefNum, UNO_QUERY);
82 maNumberVS.SetNumberingSettings(aNumberings, xFormat, aLocale);
85 maNumberVS.Show();
86 maNumberVS.SetSelectHdl( LINK(this, ParaNumberingControl, NumSelectHdl_Impl) );
88 maNumberVS.SetColor( GetSettings().GetStyleSettings().GetHighContrastMode()
89 ? GetSettings().GetStyleSettings().GetMenuColor()
90 : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
91 maNumberVS.SetBackground( GetSettings().GetStyleSettings().GetHighContrastMode()
92 ? GetSettings().GetStyleSettings().GetMenuColor()
93 : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
95 maMoreButton.SetClickHdl(LINK(this, ParaNumberingControl, MoreButtonClickHdl_Impl));
99 ParaNumberingControl::~ParaNumberingControl()
104 IMPL_LINK(ParaNumberingControl, NumSelectHdl_Impl, ValueSet*, EMPTYARG)
106 const sal_uInt16 nIdx = maNumberVS.GetSelectItemId();
107 SfxUInt16Item aItem( FN_SVX_SET_NUMBER, nIdx );
108 if (mpBindings)
109 mpBindings->GetDispatcher()->Execute( FN_SVX_SET_NUMBER, SFX_CALLMODE_RECORD, &aItem, 0L );
111 mrParaPropertyPanel.EndNumberingPopupMode();
113 return 0;
117 IMPL_LINK(ParaNumberingControl, MoreButtonClickHdl_Impl, void*, EMPTYARG)
119 if (mpBindings)
120 mpBindings->GetDispatcher()->Execute( SID_OUTLINE_BULLET, SFX_CALLMODE_ASYNCHRON );
122 mrParaPropertyPanel.EndNumberingPopupMode();
124 return 0;
128 void ParaNumberingControl::UpdateValueSet()
130 maNumberVS.StateChanged(STATE_CHANGE_STYLE);
131 maNumberVS.StateChanged(STATE_CHANGE_INITSHOW);
133 const sal_uInt16 nTypeIndex = mrParaPropertyPanel.GetNumTypeIndex();
134 if ( nTypeIndex != (sal_uInt16)0xFFFF )
135 maNumberVS.SelectItem( nTypeIndex );
136 else
138 maNumberVS.SelectItem(0);
140 maMoreButton.GrabFocus();
143 }} // end of namespace sidebar
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */