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 "ParaBulletsControl.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 <svx/nbdtmg.hxx>
35 #include <svx/nbdtmgfact.hxx>
36 
37 namespace svx { namespace sidebar {
38 
ParaBulletsControl(Window * pParent,svx::sidebar::ParaPropertyPanel & rPanel)39 ParaBulletsControl::ParaBulletsControl(
40     Window* pParent,
41     svx::sidebar::ParaPropertyPanel& rPanel )
42     : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_PARAPAGE_BULLETS) )
43     , maBulletsVS( this,SVX_RES(VS_VALUES) )
44     , maMoreButton( this,SVX_RES(CB_BULLET_MORE) )
45     , mrParaPropertyPanel( rPanel )
46     , mpBindings( mrParaPropertyPanel.GetBindings() )
47 {
48     FreeResource();
49 
50     maBulletsVS.SetColCount(3);
51     maBulletsVS.SetLineCount(3);
52     maBulletsVS.SetStyle( maBulletsVS.GetStyle() | WB_ITEMBORDER |WB_NO_DIRECTSELECT);
53     maBulletsVS.SetExtraSpacing(BULLET_IMAGE_SPACING);
54     maBulletsVS.SetItemWidth(BULLET_IMAGE_WIDTH);
55     maBulletsVS.SetItemHeight(BULLET_IMAGE_HEIGHT);
56     maBulletsVS.InsertItem( DEFAULT_NONE );
57     for( sal_uInt16 nVSIdx = 1; nVSIdx <= DEFAULT_BULLET_TYPES; ++nVSIdx )
58     {
59         maBulletsVS.InsertItem( nVSIdx );
60     }
61 
62     maBulletsVS.SetItemText( DEFAULT_NONE, SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE ));
63     NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
64     if ( pBullets )
65     {
66         for( sal_uInt16 nIndex = 0; nIndex < DEFAULT_BULLET_TYPES; ++nIndex )
67         {
68             maBulletsVS.SetItemText( nIndex + 1, pBullets->GetDescription(nIndex) );
69         }
70     }
71 
72     maBulletsVS.Show();
73     maBulletsVS.SetSelectHdl(LINK(this, ParaBulletsControl, BulletSelectHdl_Impl));
74 
75     maBulletsVS.SetColor( GetSettings().GetStyleSettings().GetHighContrastMode()
76                           ? GetSettings().GetStyleSettings().GetMenuColor()
77                           : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
78     maBulletsVS.SetBackground( GetSettings().GetStyleSettings().GetHighContrastMode()
79                                ? GetSettings().GetStyleSettings().GetMenuColor()
80                                : sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ) );
81 
82     maMoreButton.SetClickHdl(LINK(this, ParaBulletsControl, MoreButtonClickHdl_Impl));
83 
84 }
85 
86 
~ParaBulletsControl()87 ParaBulletsControl::~ParaBulletsControl()
88 {
89 }
90 
91 
UpdateValueSet()92 void ParaBulletsControl::UpdateValueSet()
93 {
94     maBulletsVS.StateChanged(STATE_CHANGE_STYLE);
95     maBulletsVS.StateChanged(STATE_CHANGE_INITSHOW);
96 
97     const sal_uInt16 nTypeIndex = mrParaPropertyPanel.GetBulletTypeIndex();
98     if ( nTypeIndex != (sal_uInt16)0xFFFF )
99         maBulletsVS.SelectItem( nTypeIndex );
100     else
101     {
102         maBulletsVS.SelectItem(0);
103     }
104     maMoreButton.GrabFocus();
105 }
106 
107 
IMPL_LINK(ParaBulletsControl,BulletSelectHdl_Impl,ValueSet *,EMPTYARG)108 IMPL_LINK(ParaBulletsControl, BulletSelectHdl_Impl, ValueSet*, EMPTYARG)
109 {
110     const sal_uInt16 nIdx = maBulletsVS.GetSelectItemId();
111     SfxUInt16Item aItem( FN_SVX_SET_BULLET, nIdx );
112     if (mpBindings)
113         mpBindings->GetDispatcher()->Execute( FN_SVX_SET_BULLET, SFX_CALLMODE_RECORD, &aItem, 0L );
114 
115     mrParaPropertyPanel.EndBulletsPopupMode();
116 
117     return 0;
118 }
119 
120 
IMPL_LINK(ParaBulletsControl,MoreButtonClickHdl_Impl,void *,EMPTYARG)121 IMPL_LINK(ParaBulletsControl, MoreButtonClickHdl_Impl, void*, EMPTYARG)
122 {
123     if (mpBindings)
124         mpBindings->GetDispatcher()->Execute( SID_OUTLINE_BULLET, SFX_CALLMODE_ASYNCHRON );
125 
126     mrParaPropertyPanel.EndBulletsPopupMode();
127 
128     return 0;
129 }
130 
131 }} // end of namespace sidebar
132 
133 
134