1766ce4d0SZheng Fan /**************************************************************
2766ce4d0SZheng Fan  *
3766ce4d0SZheng Fan  * Licensed to the Apache Software Foundation (ASF) under one
4766ce4d0SZheng Fan  * or more contributor license agreements.  See the NOTICE file
5766ce4d0SZheng Fan  * distributed with this work for additional information
6766ce4d0SZheng Fan  * regarding copyright ownership.  The ASF licenses this file
7766ce4d0SZheng Fan  * to you under the Apache License, Version 2.0 (the
8766ce4d0SZheng Fan  * "License"); you may not use this file except in compliance
9766ce4d0SZheng Fan  * with the License.  You may obtain a copy of the License at
10766ce4d0SZheng Fan  *
11766ce4d0SZheng Fan  *   http://www.apache.org/licenses/LICENSE-2.0
12766ce4d0SZheng Fan  *
13766ce4d0SZheng Fan  * Unless required by applicable law or agreed to in writing,
14766ce4d0SZheng Fan  * software distributed under the License is distributed on an
15766ce4d0SZheng Fan  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16766ce4d0SZheng Fan  * KIND, either express or implied.  See the License for the
17766ce4d0SZheng Fan  * specific language governing permissions and limitations
18766ce4d0SZheng Fan  * under the License.
19766ce4d0SZheng Fan  *
20766ce4d0SZheng Fan  *************************************************************/
21766ce4d0SZheng Fan 
22766ce4d0SZheng Fan #include "precompiled_svx.hxx"
23766ce4d0SZheng Fan #include "ParaNumberingControl.hxx"
24766ce4d0SZheng Fan #include "ParaPropertyPanel.hrc"
25*d29c2fc2SAndre Fischer #include <sfx2/sidebar/ResourceDefinitions.hrc>
26766ce4d0SZheng Fan #include <svx/dialogs.hrc>
27766ce4d0SZheng Fan #include <svx/dialmgr.hxx>
28766ce4d0SZheng Fan #include <unotools/viewoptions.hxx>
29766ce4d0SZheng Fan #include <editeng/kernitem.hxx>
30766ce4d0SZheng Fan #include <sfx2/bindings.hxx>
31766ce4d0SZheng Fan #include <sfx2/dispatch.hxx>
32766ce4d0SZheng Fan #include <sfx2/sidebar/Theme.hxx>
33766ce4d0SZheng Fan #include <svtools/unitconv.hxx>
34766ce4d0SZheng Fan #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35766ce4d0SZheng Fan #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
36766ce4d0SZheng Fan #include <com/sun/star/text/XNumberingFormatter.hpp>
37766ce4d0SZheng Fan #include <com/sun/star/beans/PropertyValue.hpp>
38766ce4d0SZheng Fan #include <comphelper/processfactory.hxx>
39766ce4d0SZheng Fan #include <svx/nbdtmg.hxx>
40766ce4d0SZheng Fan #include <svx/nbdtmgfact.hxx>
41766ce4d0SZheng Fan #include <editeng/unolingu.hxx>
42766ce4d0SZheng Fan using namespace com::sun::star;
43766ce4d0SZheng Fan using namespace com::sun::star::uno;
44766ce4d0SZheng Fan using namespace com::sun::star::beans;
45766ce4d0SZheng Fan using namespace com::sun::star::lang;
46766ce4d0SZheng Fan using namespace com::sun::star::text;
47766ce4d0SZheng Fan 
48766ce4d0SZheng Fan namespace svx { namespace sidebar {
49766ce4d0SZheng Fan 
lcl_GetNumberingProvider()50766ce4d0SZheng Fan Reference<XDefaultNumberingProvider> lcl_GetNumberingProvider()
51766ce4d0SZheng Fan {
527aed46aaSOliver-Rainer Wittmann     Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
537aed46aaSOliver-Rainer Wittmann     Reference < XInterface > xI = xMSF->createInstance(
547aed46aaSOliver-Rainer Wittmann         ::rtl::OUString::createFromAscii( "com.sun.star.text.DefaultNumberingProvider" ) );
557aed46aaSOliver-Rainer Wittmann     Reference<XDefaultNumberingProvider> xRet(xI, UNO_QUERY);
56766ce4d0SZheng Fan 
577aed46aaSOliver-Rainer Wittmann     return xRet;
58766ce4d0SZheng Fan }
59766ce4d0SZheng Fan 
ParaNumberingControl(Window * pParent,svx::sidebar::ParaPropertyPanel & rPanel)607aed46aaSOliver-Rainer Wittmann ParaNumberingControl::ParaNumberingControl(
617aed46aaSOliver-Rainer Wittmann     Window* pParent,
627aed46aaSOliver-Rainer Wittmann     svx::sidebar::ParaPropertyPanel& rPanel )
637aed46aaSOliver-Rainer Wittmann     : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_PARAPAGE_NUMBERING) )
647aed46aaSOliver-Rainer Wittmann     , maNumberVS( this,SVX_RES(VS_NUMBERING) )
657aed46aaSOliver-Rainer Wittmann     , maMoreButton( this,SVX_RES(CB_NUMBERING_MORE) )
667aed46aaSOliver-Rainer Wittmann     , mrParaPropertyPanel( rPanel )
677aed46aaSOliver-Rainer Wittmann     , mpBindings( mrParaPropertyPanel.GetBindings() )
68766ce4d0SZheng Fan {
697aed46aaSOliver-Rainer Wittmann     FreeResource();
707aed46aaSOliver-Rainer Wittmann 
717aed46aaSOliver-Rainer Wittmann     maNumberVS.SetStyle( maNumberVS.GetStyle() | WB_NO_DIRECTSELECT );
727aed46aaSOliver-Rainer Wittmann     maNumberVS.SetExtraSpacing( NUM_IMAGE_SPACING );
737aed46aaSOliver-Rainer Wittmann     maNumberVS.SetItemWidth(NUM_IMAGE_WIDTH);
747aed46aaSOliver-Rainer Wittmann     maNumberVS.SetItemHeight(NUM_IMAGE_HEIGHT);
757aed46aaSOliver-Rainer Wittmann 
767aed46aaSOliver-Rainer Wittmann     Reference<XDefaultNumberingProvider> xDefNum = lcl_GetNumberingProvider();
777aed46aaSOliver-Rainer Wittmann     if(xDefNum.is())
787aed46aaSOliver-Rainer Wittmann     {
797aed46aaSOliver-Rainer Wittmann         Sequence< Sequence< PropertyValue > > aNumberings;
80766ce4d0SZheng Fan         LanguageType eLang = GetSettings().GetLanguage();
817aed46aaSOliver-Rainer Wittmann         Locale aLocale = SvxCreateLocale(eLang);
827aed46aaSOliver-Rainer Wittmann         try
837aed46aaSOliver-Rainer Wittmann         {
847aed46aaSOliver-Rainer Wittmann             aNumberings = xDefNum->getDefaultContinuousNumberingLevels( aLocale );
857aed46aaSOliver-Rainer Wittmann         }
867aed46aaSOliver-Rainer Wittmann         catch(Exception&)
877aed46aaSOliver-Rainer Wittmann         {
887aed46aaSOliver-Rainer Wittmann         }
897aed46aaSOliver-Rainer Wittmann         Reference<XNumberingFormatter> xFormat(xDefNum, UNO_QUERY);
907aed46aaSOliver-Rainer Wittmann         maNumberVS.SetNumberingSettings(aNumberings, xFormat, aLocale);
917aed46aaSOliver-Rainer Wittmann     }
92766ce4d0SZheng Fan 
93766ce4d0SZheng Fan     maNumberVS.Show();
947aed46aaSOliver-Rainer Wittmann     maNumberVS.SetSelectHdl( LINK(this, ParaNumberingControl, NumSelectHdl_Impl) );
957aed46aaSOliver-Rainer Wittmann 
967aed46aaSOliver-Rainer Wittmann     maNumberVS.SetColor( GetSettings().GetStyleSettings().GetHighContrastMode()
977aed46aaSOliver-Rainer Wittmann                          ? GetSettings().GetStyleSettings().GetMenuColor()
987aed46aaSOliver-Rainer Wittmann                          : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
997aed46aaSOliver-Rainer Wittmann     maNumberVS.SetBackground( GetSettings().GetStyleSettings().GetHighContrastMode()
1007aed46aaSOliver-Rainer Wittmann                               ? GetSettings().GetStyleSettings().GetMenuColor()
1017aed46aaSOliver-Rainer Wittmann                               : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
102766ce4d0SZheng Fan 
1037aed46aaSOliver-Rainer Wittmann     maMoreButton.SetClickHdl(LINK(this, ParaNumberingControl, MoreButtonClickHdl_Impl));
104766ce4d0SZheng Fan }
105766ce4d0SZheng Fan 
1067aed46aaSOliver-Rainer Wittmann 
~ParaNumberingControl()107766ce4d0SZheng Fan ParaNumberingControl::~ParaNumberingControl()
1087aed46aaSOliver-Rainer Wittmann {
109766ce4d0SZheng Fan }
110766ce4d0SZheng Fan 
111766ce4d0SZheng Fan 
IMPL_LINK(ParaNumberingControl,NumSelectHdl_Impl,ValueSet *,EMPTYARG)112766ce4d0SZheng Fan IMPL_LINK(ParaNumberingControl, NumSelectHdl_Impl, ValueSet*, EMPTYARG)
113766ce4d0SZheng Fan {
1147aed46aaSOliver-Rainer Wittmann     const sal_uInt16 nIdx = maNumberVS.GetSelectItemId();
1157aed46aaSOliver-Rainer Wittmann     SfxUInt16Item aItem( FN_SVX_SET_NUMBER, nIdx );
1167aed46aaSOliver-Rainer Wittmann     if (mpBindings)
1177aed46aaSOliver-Rainer Wittmann         mpBindings->GetDispatcher()->Execute( FN_SVX_SET_NUMBER, SFX_CALLMODE_RECORD, &aItem, 0L );
1187aed46aaSOliver-Rainer Wittmann 
1197aed46aaSOliver-Rainer Wittmann     mrParaPropertyPanel.EndNumberingPopupMode();
1207aed46aaSOliver-Rainer Wittmann 
1217aed46aaSOliver-Rainer Wittmann     return 0;
122766ce4d0SZheng Fan }
123766ce4d0SZheng Fan 
1247aed46aaSOliver-Rainer Wittmann 
IMPL_LINK(ParaNumberingControl,MoreButtonClickHdl_Impl,void *,EMPTYARG)125766ce4d0SZheng Fan IMPL_LINK(ParaNumberingControl, MoreButtonClickHdl_Impl, void*, EMPTYARG)
126766ce4d0SZheng Fan {
1277aed46aaSOliver-Rainer Wittmann     if (mpBindings)
1287aed46aaSOliver-Rainer Wittmann         mpBindings->GetDispatcher()->Execute( SID_OUTLINE_BULLET, SFX_CALLMODE_ASYNCHRON );
129766ce4d0SZheng Fan 
1307aed46aaSOliver-Rainer Wittmann     mrParaPropertyPanel.EndNumberingPopupMode();
131766ce4d0SZheng Fan 
1327aed46aaSOliver-Rainer Wittmann     return 0;
133766ce4d0SZheng Fan }
134766ce4d0SZheng Fan 
135766ce4d0SZheng Fan 
UpdateValueSet()1367aed46aaSOliver-Rainer Wittmann void ParaNumberingControl::UpdateValueSet()
137766ce4d0SZheng Fan {
1387aed46aaSOliver-Rainer Wittmann     maNumberVS.StateChanged(STATE_CHANGE_STYLE);
1397aed46aaSOliver-Rainer Wittmann     maNumberVS.StateChanged(STATE_CHANGE_INITSHOW);
1407aed46aaSOliver-Rainer Wittmann 
1417aed46aaSOliver-Rainer Wittmann     const sal_uInt16 nTypeIndex = mrParaPropertyPanel.GetNumTypeIndex();
1427aed46aaSOliver-Rainer Wittmann     if ( nTypeIndex != (sal_uInt16)0xFFFF )
1437aed46aaSOliver-Rainer Wittmann         maNumberVS.SelectItem( nTypeIndex );
1447aed46aaSOliver-Rainer Wittmann     else
1457aed46aaSOliver-Rainer Wittmann     {
1467aed46aaSOliver-Rainer Wittmann         maNumberVS.SelectItem(0);
1477aed46aaSOliver-Rainer Wittmann     }
1487aed46aaSOliver-Rainer Wittmann     maMoreButton.GrabFocus();
149766ce4d0SZheng Fan }
150766ce4d0SZheng Fan 
151766ce4d0SZheng Fan }} // end of namespace sidebar
152766ce4d0SZheng Fan 
153766ce4d0SZheng Fan 
154766ce4d0SZheng Fan 
155