xref: /aoo4110/main/cui/source/tabpages/align.cxx (revision b1cdbd2c)
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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include "align.hxx"
30 
31 #include <editeng/svxenum.hxx>
32 #include <svx/dialogs.hrc>
33 #include <cuires.hrc>
34 #include "align.hrc"
35 #include <svx/rotmodit.hxx>
36 
37 #include <svx/algitem.hxx>
38 #include <editeng/frmdiritem.hxx>
39 #include <dialmgr.hxx>
40 #include <svx/dlgutil.hxx>
41 #include <tools/shl.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/module.hxx>
44 #include <sfx2/itemconnect.hxx>
45 #include <svl/cjkoptions.hxx>
46 #include <svl/languageoptions.hxx>
47 #include <svtools/localresaccess.hxx>
48 #include <svx/flagsdef.hxx>	//CHINA001
49 #include <svl/intitem.hxx> //CHINA001
50 #include <sfx2/request.hxx> //CHINA001
51 
52 namespace svx {
53 
54 // item connections ===========================================================
55 
56 // horizontal alignment -------------------------------------------------------
57 
58 typedef sfx::ValueItemWrapper< SvxHorJustifyItem, SvxCellHorJustify, sal_uInt16 > HorJustItemWrapper;
59 typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnection;
60 
61 static const HorJustConnection::MapEntryType s_pHorJustMap[] =
62 {
63     { ALIGNDLG_HORALIGN_STD,    SVX_HOR_JUSTIFY_STANDARD    },
64     { ALIGNDLG_HORALIGN_LEFT,   SVX_HOR_JUSTIFY_LEFT        },
65     { ALIGNDLG_HORALIGN_CENTER, SVX_HOR_JUSTIFY_CENTER      },
66     { ALIGNDLG_HORALIGN_RIGHT,  SVX_HOR_JUSTIFY_RIGHT       },
67     { ALIGNDLG_HORALIGN_BLOCK,  SVX_HOR_JUSTIFY_BLOCK       },
68     { ALIGNDLG_HORALIGN_FILL,   SVX_HOR_JUSTIFY_REPEAT      },
69     { LISTBOX_ENTRY_NOTFOUND,   SVX_HOR_JUSTIFY_STANDARD    }
70 };
71 
72 // vertical alignment ---------------------------------------------------------
73 
74 typedef sfx::ValueItemWrapper< SvxVerJustifyItem, SvxCellVerJustify, sal_uInt16 > VerJustItemWrapper;
75 typedef sfx::ListBoxConnection< VerJustItemWrapper > VerJustConnection;
76 
77 static const VerJustConnection::MapEntryType s_pVerJustMap[] =
78 {
79     { ALIGNDLG_VERALIGN_STD,    SVX_VER_JUSTIFY_STANDARD    },
80     { ALIGNDLG_VERALIGN_TOP,    SVX_VER_JUSTIFY_TOP         },
81     { ALIGNDLG_VERALIGN_MID,    SVX_VER_JUSTIFY_CENTER      },
82     { ALIGNDLG_VERALIGN_BOTTOM, SVX_VER_JUSTIFY_BOTTOM      },
83     { LISTBOX_ENTRY_NOTFOUND,   SVX_VER_JUSTIFY_STANDARD    }
84 };
85 
86 // cell rotate mode -----------------------------------------------------------
87 
88 typedef sfx::ValueItemWrapper< SvxRotateModeItem, SvxRotateMode, sal_uInt16 > RotateModeItemWrapper;
89 typedef sfx::ValueSetConnection< RotateModeItemWrapper > RotateModeConnection;
90 
91 static const RotateModeConnection::MapEntryType s_pRotateModeMap[] =
92 {
93     { IID_BOTTOMLOCK,           SVX_ROTATE_MODE_BOTTOM      },
94     { IID_TOPLOCK,              SVX_ROTATE_MODE_TOP         },
95     { IID_CELLLOCK,             SVX_ROTATE_MODE_STANDARD    },
96     { VALUESET_ITEM_NOTFOUND,   SVX_ROTATE_MODE_STANDARD    }
97 };
98 
99 // ============================================================================
100 
101 static sal_uInt16 s_pRanges[] =
102 {
103     SID_ATTR_ALIGN_HOR_JUSTIFY,SID_ATTR_ALIGN_VER_JUSTIFY,
104     SID_ATTR_ALIGN_STACKED,SID_ATTR_ALIGN_LINEBREAK,
105     SID_ATTR_ALIGN_INDENT,SID_ATTR_ALIGN_INDENT,
106     SID_ATTR_ALIGN_DEGREES,SID_ATTR_ALIGN_DEGREES,
107     SID_ATTR_ALIGN_LOCKPOS,SID_ATTR_ALIGN_LOCKPOS,
108     SID_ATTR_ALIGN_HYPHENATION,SID_ATTR_ALIGN_HYPHENATION,
109     SID_ATTR_ALIGN_ASIANVERTICAL,SID_ATTR_ALIGN_ASIANVERTICAL,
110     SID_ATTR_FRAMEDIRECTION,SID_ATTR_FRAMEDIRECTION,
111     SID_ATTR_ALIGN_SHRINKTOFIT,SID_ATTR_ALIGN_SHRINKTOFIT,
112     0
113 };
114 
115 // ============================================================================
116 
AlignmentTabPage(Window * pParent,const SfxItemSet & rCoreAttrs)117 AlignmentTabPage::AlignmentTabPage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
118 
119 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_ALIGNMENT ), rCoreAttrs ),
120 
121     maFlAlignment   ( this, CUI_RES( FL_ALIGNMENT ) ),
122     maFtHorAlign    ( this, CUI_RES( FT_HORALIGN ) ),
123     maLbHorAlign    ( this, CUI_RES( LB_HORALIGN ) ),
124     maFtIndent      ( this, CUI_RES( FT_INDENT ) ),
125     maEdIndent      ( this, CUI_RES( ED_INDENT ) ),
126     maFtVerAlign    ( this, CUI_RES( FT_VERALIGN ) ),
127     maLbVerAlign    ( this, CUI_RES( LB_VERALIGN ) ),
128 
129     maFlOrient      ( this, CUI_RES( FL_ORIENTATION ) ),
130     maCtrlDial      ( this, CUI_RES( CTR_DIAL ) ),
131     maFtRotate      ( this, CUI_RES( FT_DEGREES ) ),
132     maNfRotate      ( this, CUI_RES( NF_DEGREES ) ),
133     maFtRefEdge     ( this, CUI_RES( FT_BORDER_LOCK ) ),
134     maVsRefEdge     ( this, CUI_RES( CTR_BORDER_LOCK ) ),
135     maCbStacked     ( this, CUI_RES( BTN_TXTSTACKED ) ),
136     maCbAsianMode   ( this, CUI_RES( BTN_ASIAN_VERTICAL ) ),
137     maOrientHlp     ( maCtrlDial, maNfRotate, maCbStacked ),
138 
139     maFlProperties  ( this, CUI_RES( FL_WRAP ) ),
140     maBtnWrap       ( this, CUI_RES( BTN_WRAP ) ),
141     maBtnHyphen     ( this, CUI_RES( BTN_HYPH ) ),
142     maBtnShrink     ( this, CUI_RES( BTN_SHRINK ) ),
143     maFtFrameDir    ( this, CUI_RES( FT_TEXTFLOW ) ),
144     maLbFrameDir    ( this, CUI_RES( LB_FRAMEDIR ) )
145 {
146     InitVsRefEgde();
147 
148     // windows to be disabled, if stacked text is turned ON
149     maOrientHlp.AddDependentWindow( maFtRotate,     STATE_CHECK );
150     maOrientHlp.AddDependentWindow( maFtRefEdge,    STATE_CHECK );
151     maOrientHlp.AddDependentWindow( maVsRefEdge,    STATE_CHECK );
152     // windows to be disabled, if stacked text is turned OFF
153     maOrientHlp.AddDependentWindow( maCbAsianMode,  STATE_NOCHECK );
154 
155     Link aLink = LINK( this, AlignmentTabPage, UpdateEnableHdl );
156 
157     maLbHorAlign.SetSelectHdl( aLink );
158     maBtnWrap.SetClickHdl( aLink );
159 
160     // Asian vertical mode
161     maCbAsianMode.Show( SvtCJKOptions().IsVerticalTextEnabled() );
162 
163     // CTL frame direction
164     maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_LTR ), FRMDIR_HORI_LEFT_TOP );
165     maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_RTL ), FRMDIR_HORI_RIGHT_TOP );
166     maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_SUPER ), FRMDIR_ENVIRONMENT );
167     if( !SvtLanguageOptions().IsCTLFontEnabled() )
168     {
169         maFtFrameDir.Hide();
170         maLbFrameDir.Hide();
171     }
172 
173 	// diese Page braucht ExchangeSupport
174 	SetExchangeSupport();
175 
176 	FreeResource();
177 
178     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maFtHorAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
179     AddItemConnection( new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
180     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_INDENT, maFtIndent, sfx::ITEMCONN_HIDE_UNKNOWN ) );
181     AddItemConnection( new sfx::UInt16MetricConnection( SID_ATTR_ALIGN_INDENT, maEdIndent, FUNIT_TWIP, sfx::ITEMCONN_HIDE_UNKNOWN ) );
182     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maFtVerAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
183     AddItemConnection( new VerJustConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maLbVerAlign, s_pVerJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
184     AddItemConnection( new DialControlConnection( SID_ATTR_ALIGN_DEGREES, maCtrlDial, sfx::ITEMCONN_HIDE_UNKNOWN ) );
185     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_DEGREES, maFtRotate, sfx::ITEMCONN_HIDE_UNKNOWN ) );
186     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_LOCKPOS, maFtRefEdge, sfx::ITEMCONN_HIDE_UNKNOWN ) );
187     AddItemConnection( new RotateModeConnection( SID_ATTR_ALIGN_LOCKPOS, maVsRefEdge, s_pRotateModeMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
188     AddItemConnection( new OrientStackedConnection( SID_ATTR_ALIGN_STACKED, maOrientHlp ) );
189     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_STACKED, maCbStacked, sfx::ITEMCONN_HIDE_UNKNOWN ) );
190     AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_ASIANVERTICAL, maCbAsianMode, sfx::ITEMCONN_HIDE_UNKNOWN ) );
191     AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_LINEBREAK, maBtnWrap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
192     AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_HYPHENATION, maBtnHyphen, sfx::ITEMCONN_HIDE_UNKNOWN ) );
193     AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_SHRINKTOFIT, maBtnShrink, sfx::ITEMCONN_HIDE_UNKNOWN ) );
194     AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_FRAMEDIRECTION, maFtFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
195     AddItemConnection( new FrameDirListBoxConnection( SID_ATTR_FRAMEDIRECTION, maLbFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
196 
197 	maLbHorAlign.SetAccessibleRelationMemberOf( &maFlAlignment );
198 	maEdIndent.SetAccessibleRelationMemberOf( &maFlAlignment );
199 	maLbVerAlign.SetAccessibleRelationMemberOf( &maFlAlignment );
200 }
201 
~AlignmentTabPage()202 AlignmentTabPage::~AlignmentTabPage()
203 {
204 }
205 
Create(Window * pParent,const SfxItemSet & rAttrSet)206 SfxTabPage* AlignmentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
207 {
208     return new AlignmentTabPage( pParent, rAttrSet );
209 }
210 
GetRanges()211 sal_uInt16* AlignmentTabPage::GetRanges()
212 {
213     return s_pRanges;
214 }
215 
Reset(const SfxItemSet & rCoreAttrs)216 void AlignmentTabPage::Reset( const SfxItemSet& rCoreAttrs )
217 {
218     SfxTabPage::Reset( rCoreAttrs );
219     UpdateEnableControls();
220 }
221 
DeactivatePage(SfxItemSet * _pSet)222 int AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
223 {
224     if( _pSet )
225         FillItemSet( *_pSet );
226 	return LEAVE_PAGE;
227 }
228 
DataChanged(const DataChangedEvent & rDCEvt)229 void AlignmentTabPage::DataChanged( const DataChangedEvent& rDCEvt )
230 {
231     SfxTabPage::DataChanged( rDCEvt );
232     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
233     {
234         svt::OLocalResourceAccess aLocalResAcc( CUI_RES( RID_SVXPAGE_ALIGNMENT ), RSC_TABPAGE );
235         InitVsRefEgde();
236     }
237 }
238 
InitVsRefEgde()239 void AlignmentTabPage::InitVsRefEgde()
240 {
241     // remember selection - is deleted in call to ValueSet::Clear()
242     sal_uInt16 nSel = maVsRefEdge.GetSelectItemId();
243 
244     ResId aResId( GetSettings().GetStyleSettings().GetHighContrastMode() ? IL_LOCK_BMPS_HC : IL_LOCK_BMPS, CUI_MGR() );
245     ImageList aImageList( aResId );
246     Size aItemSize( aImageList.GetImage( IID_BOTTOMLOCK ).GetSizePixel() );
247 
248     maVsRefEdge.Clear();
249     maVsRefEdge.SetStyle( maVsRefEdge.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
250 
251     maVsRefEdge.SetColCount( 3 );
252     maVsRefEdge.InsertItem( IID_BOTTOMLOCK, aImageList.GetImage( IID_BOTTOMLOCK ),  String( CUI_RES( STR_BOTTOMLOCK ) ) );
253     maVsRefEdge.InsertItem( IID_TOPLOCK,    aImageList.GetImage( IID_TOPLOCK ),     String( CUI_RES( STR_TOPLOCK ) ) );
254     maVsRefEdge.InsertItem( IID_CELLLOCK,   aImageList.GetImage( IID_CELLLOCK ),    String( CUI_RES( STR_CELLLOCK ) ) );
255 
256     maVsRefEdge.SetSizePixel( maVsRefEdge.CalcWindowSizePixel( aItemSize ) );
257 
258     maVsRefEdge.SelectItem( nSel );
259 }
260 
UpdateEnableControls()261 void AlignmentTabPage::UpdateEnableControls()
262 {
263     sal_uInt16 nHorAlign = maLbHorAlign.GetSelectEntryPos();
264     bool bHorLeft  = (nHorAlign == ALIGNDLG_HORALIGN_LEFT);
265     bool bHorBlock = (nHorAlign == ALIGNDLG_HORALIGN_BLOCK);
266     bool bHorFill  = (nHorAlign == ALIGNDLG_HORALIGN_FILL);
267 
268     // indent edit field only for left alignment
269     maFtIndent.Enable( bHorLeft );
270     maEdIndent.Enable( bHorLeft );
271 
272     // rotation/stacked disabled for fill alignment
273     maOrientHlp.Enable( !bHorFill );
274 
275     // hyphenation only for automatic line breaks or for block alignment
276     maBtnHyphen.Enable( maBtnWrap.IsChecked() || bHorBlock );
277 
278     // shrink only without automatic line break, and not for block and fill
279     maBtnShrink.Enable( (maBtnWrap.GetState() == STATE_NOCHECK) && !bHorBlock && !bHorFill );
280 
281     // visibility of fixed lines
282     maFlAlignment.Show( maLbHorAlign.IsVisible() || maEdIndent.IsVisible() || maLbVerAlign.IsVisible() );
283     maFlOrient.Show( maCtrlDial.IsVisible() || maVsRefEdge.IsVisible() || maCbStacked.IsVisible() || maCbAsianMode.IsVisible() );
284     maFlProperties.Show( maBtnWrap.IsVisible() || maBtnHyphen.IsVisible() || maBtnShrink.IsVisible() || maLbFrameDir.IsVisible() );
285 }
286 
IMPL_LINK(AlignmentTabPage,UpdateEnableHdl,void *,EMPTYARG)287 IMPL_LINK( AlignmentTabPage, UpdateEnableHdl, void*, EMPTYARG )
288 {
289     UpdateEnableControls();
290     return 0;
291 }
292 
293 // ============================================================================
294 
295 } // namespace svx
296 
297