1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_svx.hxx"
23 #include "ParaNumberingControl.hxx"
24 #include "ParaPropertyPanel.hrc"
25 #include <sfx2/sidebar/ResourceDefinitions.hrc>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <unotools/viewoptions.hxx>
29 #include <editeng/kernitem.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/sidebar/Theme.hxx>
33 #include <svtools/unitconv.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
36 #include <com/sun/star/text/XNumberingFormatter.hpp>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <comphelper/processfactory.hxx>
39 #include <svx/nbdtmg.hxx>
40 #include <svx/nbdtmgfact.hxx>
41 #include <editeng/unolingu.hxx>
42 using namespace com::sun::star;
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::beans;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::text;
47 
48 namespace svx { namespace sidebar {
49 
lcl_GetNumberingProvider()50 Reference<XDefaultNumberingProvider> lcl_GetNumberingProvider()
51 {
52     Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
53     Reference < XInterface > xI = xMSF->createInstance(
54         ::rtl::OUString::createFromAscii( "com.sun.star.text.DefaultNumberingProvider" ) );
55     Reference<XDefaultNumberingProvider> xRet(xI, UNO_QUERY);
56 
57     return xRet;
58 }
59 
ParaNumberingControl(Window * pParent,svx::sidebar::ParaPropertyPanel & rPanel)60 ParaNumberingControl::ParaNumberingControl(
61     Window* pParent,
62     svx::sidebar::ParaPropertyPanel& rPanel )
63     : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_PARAPAGE_NUMBERING) )
64     , maNumberVS( this,SVX_RES(VS_NUMBERING) )
65     , maMoreButton( this,SVX_RES(CB_NUMBERING_MORE) )
66     , mrParaPropertyPanel( rPanel )
67     , mpBindings( mrParaPropertyPanel.GetBindings() )
68 {
69     FreeResource();
70 
71     maNumberVS.SetStyle( maNumberVS.GetStyle() | WB_NO_DIRECTSELECT );
72     maNumberVS.SetExtraSpacing( NUM_IMAGE_SPACING );
73     maNumberVS.SetItemWidth(NUM_IMAGE_WIDTH);
74     maNumberVS.SetItemHeight(NUM_IMAGE_HEIGHT);
75 
76     Reference<XDefaultNumberingProvider> xDefNum = lcl_GetNumberingProvider();
77     if(xDefNum.is())
78     {
79         Sequence< Sequence< PropertyValue > > aNumberings;
80         LanguageType eLang = GetSettings().GetLanguage();
81         Locale aLocale = SvxCreateLocale(eLang);
82         try
83         {
84             aNumberings = xDefNum->getDefaultContinuousNumberingLevels( aLocale );
85         }
86         catch(Exception&)
87         {
88         }
89         Reference<XNumberingFormatter> xFormat(xDefNum, UNO_QUERY);
90         maNumberVS.SetNumberingSettings(aNumberings, xFormat, aLocale);
91     }
92 
93     maNumberVS.Show();
94     maNumberVS.SetSelectHdl( LINK(this, ParaNumberingControl, NumSelectHdl_Impl) );
95 
96     maNumberVS.SetColor( GetSettings().GetStyleSettings().GetHighContrastMode()
97                          ? GetSettings().GetStyleSettings().GetMenuColor()
98                          : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
99     maNumberVS.SetBackground( GetSettings().GetStyleSettings().GetHighContrastMode()
100                               ? GetSettings().GetStyleSettings().GetMenuColor()
101                               : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
102 
103     maMoreButton.SetClickHdl(LINK(this, ParaNumberingControl, MoreButtonClickHdl_Impl));
104 }
105 
106 
~ParaNumberingControl()107 ParaNumberingControl::~ParaNumberingControl()
108 {
109 }
110 
111 
IMPL_LINK(ParaNumberingControl,NumSelectHdl_Impl,ValueSet *,EMPTYARG)112 IMPL_LINK(ParaNumberingControl, NumSelectHdl_Impl, ValueSet*, EMPTYARG)
113 {
114     const sal_uInt16 nIdx = maNumberVS.GetSelectItemId();
115     SfxUInt16Item aItem( FN_SVX_SET_NUMBER, nIdx );
116     if (mpBindings)
117         mpBindings->GetDispatcher()->Execute( FN_SVX_SET_NUMBER, SFX_CALLMODE_RECORD, &aItem, 0L );
118 
119     mrParaPropertyPanel.EndNumberingPopupMode();
120 
121     return 0;
122 }
123 
124 
IMPL_LINK(ParaNumberingControl,MoreButtonClickHdl_Impl,void *,EMPTYARG)125 IMPL_LINK(ParaNumberingControl, MoreButtonClickHdl_Impl, void*, EMPTYARG)
126 {
127     if (mpBindings)
128         mpBindings->GetDispatcher()->Execute( SID_OUTLINE_BULLET, SFX_CALLMODE_ASYNCHRON );
129 
130     mrParaPropertyPanel.EndNumberingPopupMode();
131 
132     return 0;
133 }
134 
135 
UpdateValueSet()136 void ParaNumberingControl::UpdateValueSet()
137 {
138     maNumberVS.StateChanged(STATE_CHANGE_STYLE);
139     maNumberVS.StateChanged(STATE_CHANGE_INITSHOW);
140 
141     const sal_uInt16 nTypeIndex = mrParaPropertyPanel.GetNumTypeIndex();
142     if ( nTypeIndex != (sal_uInt16)0xFFFF )
143         maNumberVS.SelectItem( nTypeIndex );
144     else
145     {
146         maNumberVS.SelectItem(0);
147     }
148     maMoreButton.GrabFocus();
149 }
150 
151 }} // end of namespace sidebar
152 
153 
154 
155