update credits
[LibreOffice.git] / cui / source / tabpages / align.cxx
blob9aa47e8566dc0d0e7e5375f62818cc4b2fee59b0
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 .
20 #include "align.hxx"
22 #include <editeng/svxenum.hxx>
23 #include <svx/dialogs.hrc>
24 #include <cuires.hrc>
25 #include "align.hrc"
26 #include <svx/rotmodit.hxx>
28 #include <svx/algitem.hxx>
29 #include <editeng/frmdiritem.hxx>
30 #include <editeng/justifyitem.hxx>
31 #include <dialmgr.hxx>
32 #include <svx/dlgutil.hxx>
33 #include <tools/shl.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/module.hxx>
36 #include <sfx2/itemconnect.hxx>
37 #include <svl/cjkoptions.hxx>
38 #include <svl/languageoptions.hxx>
39 #include <svtools/localresaccess.hxx>
40 #include <svx/flagsdef.hxx>
41 #include <svl/intitem.hxx>
42 #include <sfx2/request.hxx>
44 namespace svx {
46 // item connections ===========================================================
48 // horizontal alignment -------------------------------------------------------
50 typedef sfx::ValueItemWrapper< SvxHorJustifyItem, SvxCellHorJustify, sal_uInt16 > HorJustItemWrapper;
51 typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnection;
53 static const HorJustConnection::MapEntryType s_pHorJustMap[] =
55 { ALIGNDLG_HORALIGN_STD, SVX_HOR_JUSTIFY_STANDARD },
56 { ALIGNDLG_HORALIGN_LEFT, SVX_HOR_JUSTIFY_LEFT },
57 { ALIGNDLG_HORALIGN_CENTER, SVX_HOR_JUSTIFY_CENTER },
58 { ALIGNDLG_HORALIGN_RIGHT, SVX_HOR_JUSTIFY_RIGHT },
59 { ALIGNDLG_HORALIGN_BLOCK, SVX_HOR_JUSTIFY_BLOCK },
60 { ALIGNDLG_HORALIGN_FILL, SVX_HOR_JUSTIFY_REPEAT },
61 { ALIGNDLG_HORALIGN_DISTRIBUTED, SVX_HOR_JUSTIFY_BLOCK },
62 { LISTBOX_ENTRY_NOTFOUND, SVX_HOR_JUSTIFY_STANDARD }
65 // vertical alignment ---------------------------------------------------------
67 typedef sfx::ValueItemWrapper< SvxVerJustifyItem, SvxCellVerJustify, sal_uInt16 > VerJustItemWrapper;
68 typedef sfx::ListBoxConnection< VerJustItemWrapper > VerJustConnection;
70 static const VerJustConnection::MapEntryType s_pVerJustMap[] =
72 { ALIGNDLG_VERALIGN_STD, SVX_VER_JUSTIFY_STANDARD },
73 { ALIGNDLG_VERALIGN_TOP, SVX_VER_JUSTIFY_TOP },
74 { ALIGNDLG_VERALIGN_MID, SVX_VER_JUSTIFY_CENTER },
75 { ALIGNDLG_VERALIGN_BOTTOM, SVX_VER_JUSTIFY_BOTTOM },
76 { ALIGNDLG_VERALIGN_BLOCK, SVX_VER_JUSTIFY_BLOCK },
77 { ALIGNDLG_VERALIGN_DISTRIBUTED, SVX_VER_JUSTIFY_BLOCK },
78 { LISTBOX_ENTRY_NOTFOUND, SVX_VER_JUSTIFY_STANDARD }
81 // cell rotate mode -----------------------------------------------------------
83 typedef sfx::ValueItemWrapper< SvxRotateModeItem, SvxRotateMode, sal_uInt16 > RotateModeItemWrapper;
84 typedef sfx::ValueSetConnection< RotateModeItemWrapper > RotateModeConnection;
86 static const RotateModeConnection::MapEntryType s_pRotateModeMap[] =
88 { IID_BOTTOMLOCK, SVX_ROTATE_MODE_BOTTOM },
89 { IID_TOPLOCK, SVX_ROTATE_MODE_TOP },
90 { IID_CELLLOCK, SVX_ROTATE_MODE_STANDARD },
91 { VALUESET_ITEM_NOTFOUND, SVX_ROTATE_MODE_STANDARD }
94 // ============================================================================
96 static sal_uInt16 s_pRanges[] =
98 SID_ATTR_ALIGN_HOR_JUSTIFY,SID_ATTR_ALIGN_VER_JUSTIFY,
99 SID_ATTR_ALIGN_STACKED,SID_ATTR_ALIGN_LINEBREAK,
100 SID_ATTR_ALIGN_INDENT,SID_ATTR_ALIGN_INDENT,
101 SID_ATTR_ALIGN_DEGREES,SID_ATTR_ALIGN_DEGREES,
102 SID_ATTR_ALIGN_LOCKPOS,SID_ATTR_ALIGN_LOCKPOS,
103 SID_ATTR_ALIGN_HYPHENATION,SID_ATTR_ALIGN_HYPHENATION,
104 SID_ATTR_ALIGN_ASIANVERTICAL,SID_ATTR_ALIGN_ASIANVERTICAL,
105 SID_ATTR_FRAMEDIRECTION,SID_ATTR_FRAMEDIRECTION,
106 SID_ATTR_ALIGN_SHRINKTOFIT,SID_ATTR_ALIGN_SHRINKTOFIT,
110 // ============================================================================
112 namespace {
114 template<typename _JustContainerType, typename _JustEnumType>
115 void lcl_MaybeResetAlignToDistro(
116 ListBox& rLB, sal_uInt16 nListPos, const SfxItemSet& rCoreAttrs, sal_uInt16 nWhichAlign, sal_uInt16 nWhichJM, _JustEnumType eBlock)
118 const SfxPoolItem* pItem;
119 if (rCoreAttrs.GetItemState(nWhichAlign, sal_True, &pItem) != SFX_ITEM_SET)
120 // alignment not set.
121 return;
123 const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
124 _JustContainerType eVal = static_cast<_JustContainerType>(p->GetEnumValue());
125 if (eVal != eBlock)
126 // alignment is not 'justify'. No need to go further.
127 return;
129 if (rCoreAttrs.GetItemState(nWhichJM, sal_True, &pItem) != SFX_ITEM_SET)
130 // justification method is not set.
131 return;
133 p = static_cast<const SfxEnumItem*>(pItem);
134 SvxCellJustifyMethod eMethod = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
135 if (eMethod == SVX_JUSTIFY_METHOD_DISTRIBUTE)
136 // Select the 'distribute' entry in the specified list box.
137 rLB.SelectEntryPos(nListPos);
140 void lcl_SetJustifyMethodToItemSet(SfxItemSet& rSet, sal_uInt16 nWhichJM, const ListBox& rLB, sal_uInt16 nListPos)
142 SvxCellJustifyMethod eJM = SVX_JUSTIFY_METHOD_AUTO;
143 if (rLB.GetSelectEntryPos() == nListPos)
144 eJM = SVX_JUSTIFY_METHOD_DISTRIBUTE;
146 SvxJustifyMethodItem aItem(eJM, nWhichJM);
147 rSet.Put(aItem);
150 }//namespace
152 // ============================================================================
154 AlignmentTabPage::AlignmentTabPage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
156 SfxTabPage( pParent, "CellAlignPage","cui/ui/cellalignment.ui", rCoreAttrs )
159 // text alignment
160 get(m_pLbHorAlign,"comboboxHorzAlign");
161 get(m_pFtIndent,"labelIndent");
162 get(m_pEdIndent,"spinIndentFrom");
163 get(m_pLbVerAlign,"comboboxVertAlign");
165 //text rotation
166 get(m_pNfRotate,"spinDegrees");
167 get(m_pCtrlDial,"dialcontrol");
168 get(m_pFtRotate,"labelDegrees");
169 get(m_pFtRefEdge,"labelRefEdge");
170 get(m_pVsRefEdge,"references");
171 get(m_pBoxDirection,"boxDirection");
173 //Asian mode
174 get(m_pCbStacked,"checkVertStack");
175 get(m_pCbAsianMode,"checkAsianMode");
177 m_pOrientHlp = new OrientationHelper(*m_pCtrlDial, *m_pNfRotate, *m_pCbStacked);
179 // Properties
180 get(m_pBtnWrap,"checkWrapTextAuto");
181 get(m_pBtnHyphen,"checkHyphActive");
182 get(m_pBtnShrink,"checkShrinkFitCellSize");
183 get(m_pLbFrameDir,"comboTextDirBox");
185 //ValueSet hover strings
186 get(m_pFtBotLock,"labelSTR_BOTTOMLOCK");
187 get(m_pFtTopLock,"labelSTR_TOPLOCK");
188 get(m_pFtCelLock,"labelSTR_CELLLOCK");
189 get(m_pFtABCD,"labelABCD");
191 m_pCtrlDial->SetText(m_pFtABCD->GetText());
193 InitVsRefEgde();
195 // windows to be disabled, if stacked text is turned ON
196 m_pOrientHlp->AddDependentWindow( *m_pFtRotate, STATE_CHECK );
197 m_pOrientHlp->AddDependentWindow( *m_pFtRefEdge, STATE_CHECK );
198 m_pOrientHlp->AddDependentWindow( *m_pVsRefEdge, STATE_CHECK );
199 // windows to be disabled, if stacked text is turned OFF
200 m_pOrientHlp->AddDependentWindow( *m_pCbAsianMode, STATE_NOCHECK );
202 Link aLink = LINK( this, AlignmentTabPage, UpdateEnableHdl );
204 m_pLbHorAlign->SetSelectHdl( aLink );
205 m_pBtnWrap->SetClickHdl( aLink );
207 // Asian vertical mode
208 m_pCbAsianMode->Show( SvtCJKOptions().IsVerticalTextEnabled() );
211 if( !SvtLanguageOptions().IsCTLFontEnabled() )
213 m_pBoxDirection->Hide();
215 else
217 // CTL frame direction
218 m_pLbFrameDir->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_LTR ), FRMDIR_HORI_LEFT_TOP );
219 m_pLbFrameDir->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_RTL ), FRMDIR_HORI_RIGHT_TOP );
220 m_pLbFrameDir->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_SUPER ), FRMDIR_ENVIRONMENT );
221 m_pBoxDirection->Show();
224 // This page needs ExchangeSupport.
225 SetExchangeSupport();
227 AddItemConnection( new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, *m_pLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
228 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_INDENT, *m_pFtIndent, sfx::ITEMCONN_HIDE_UNKNOWN ) );
229 AddItemConnection( new sfx::UInt16MetricConnection( SID_ATTR_ALIGN_INDENT, *m_pEdIndent, FUNIT_TWIP, sfx::ITEMCONN_HIDE_UNKNOWN ) );
230 AddItemConnection( new VerJustConnection( SID_ATTR_ALIGN_VER_JUSTIFY, *m_pLbVerAlign, s_pVerJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
231 AddItemConnection( new DialControlConnection( SID_ATTR_ALIGN_DEGREES, *m_pCtrlDial, sfx::ITEMCONN_HIDE_UNKNOWN ) );
232 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_DEGREES, *m_pFtRotate, sfx::ITEMCONN_HIDE_UNKNOWN ) );
233 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_LOCKPOS, *m_pFtRefEdge, sfx::ITEMCONN_HIDE_UNKNOWN ) );
234 AddItemConnection( new RotateModeConnection( SID_ATTR_ALIGN_LOCKPOS, *m_pVsRefEdge, s_pRotateModeMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
235 AddItemConnection( new OrientStackedConnection( SID_ATTR_ALIGN_STACKED, *m_pOrientHlp ) );
236 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_STACKED, *m_pCbStacked, sfx::ITEMCONN_HIDE_UNKNOWN ) );
237 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_ASIANVERTICAL, *m_pCbAsianMode, sfx::ITEMCONN_HIDE_UNKNOWN ) );
238 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_LINEBREAK, *m_pBtnWrap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
239 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_HYPHENATION, *m_pBtnHyphen, sfx::ITEMCONN_HIDE_UNKNOWN ) );
240 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_SHRINKTOFIT, *m_pBtnShrink, sfx::ITEMCONN_HIDE_UNKNOWN ) );
241 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_FRAMEDIRECTION, *m_pBoxDirection, sfx::ITEMCONN_HIDE_UNKNOWN ) );
242 AddItemConnection( new FrameDirListBoxConnection( SID_ATTR_FRAMEDIRECTION, *m_pLbFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
246 AlignmentTabPage::~AlignmentTabPage()
248 delete m_pOrientHlp;
251 SfxTabPage* AlignmentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
253 return new AlignmentTabPage( pParent, rAttrSet );
256 sal_uInt16* AlignmentTabPage::GetRanges()
258 return s_pRanges;
261 sal_Bool AlignmentTabPage::FillItemSet( SfxItemSet& rSet )
263 bool bChanged = SfxTabPage::FillItemSet(rSet);
265 // Special treatment for distributed alignment; we need to set the justify
266 // method to 'distribute' to distinguish from the normal justification.
268 sal_uInt16 nWhichHorJM = GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD);
269 lcl_SetJustifyMethodToItemSet(rSet, nWhichHorJM, *m_pLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED);
270 if (!bChanged)
271 bChanged = HasAlignmentChanged(rSet, nWhichHorJM);
273 sal_uInt16 nWhichVerJM = GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD);
274 lcl_SetJustifyMethodToItemSet(rSet, nWhichVerJM, *m_pLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED);
275 if (!bChanged)
276 bChanged = HasAlignmentChanged(rSet, nWhichVerJM);
278 return bChanged;
281 void AlignmentTabPage::Reset( const SfxItemSet& rCoreAttrs )
283 SfxTabPage::Reset( rCoreAttrs );
285 // Special treatment for distributed alignment; we need to set the justify
286 // method to 'distribute' to distinguish from the normal justification.
288 lcl_MaybeResetAlignToDistro<SvxCellHorJustify, SvxCellHorJustify>(
289 *m_pLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED, rCoreAttrs,
290 GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY), GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD),
291 SVX_HOR_JUSTIFY_BLOCK);
293 lcl_MaybeResetAlignToDistro<SvxCellVerJustify, SvxCellVerJustify>(
294 *m_pLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED, rCoreAttrs,
295 GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY), GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD),
296 SVX_VER_JUSTIFY_BLOCK);
298 UpdateEnableControls();
301 int AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
303 if( _pSet )
304 FillItemSet( *_pSet );
305 return LEAVE_PAGE;
308 void AlignmentTabPage::DataChanged( const DataChangedEvent& rDCEvt )
310 SfxTabPage::DataChanged( rDCEvt );
311 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
313 svt::OLocalResourceAccess aLocalResAcc( CUI_RES( RID_SVXPAGE_ALIGNMENT ), RSC_TABPAGE );
314 InitVsRefEgde();
318 void AlignmentTabPage::InitVsRefEgde()
320 // remember selection - is deleted in call to ValueSet::Clear()
321 sal_uInt16 nSel = m_pVsRefEdge->GetSelectItemId();
323 ResId aResId( IL_LOCK_BMPS, CUI_MGR() );
324 ImageList aImageList( aResId );
325 Size aItemSize( aImageList.GetImage( IID_BOTTOMLOCK ).GetSizePixel() );
327 m_pVsRefEdge->Clear();
328 m_pVsRefEdge->SetStyle( m_pVsRefEdge->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
330 m_pVsRefEdge->SetColCount( 3 );
331 m_pVsRefEdge->InsertItem( IID_BOTTOMLOCK, aImageList.GetImage( IID_BOTTOMLOCK ), m_pFtBotLock->GetText() );
332 m_pVsRefEdge->InsertItem( IID_TOPLOCK, aImageList.GetImage( IID_TOPLOCK ), m_pFtTopLock->GetText() );
333 m_pVsRefEdge->InsertItem( IID_CELLLOCK, aImageList.GetImage( IID_CELLLOCK ), m_pFtCelLock->GetText() );
335 m_pVsRefEdge->SetSizePixel( m_pVsRefEdge->CalcWindowSizePixel( aItemSize ) );
337 m_pVsRefEdge->SelectItem( nSel );
340 void AlignmentTabPage::UpdateEnableControls()
342 sal_uInt16 nHorAlign = m_pLbHorAlign->GetSelectEntryPos();
343 bool bHorLeft = (nHorAlign == ALIGNDLG_HORALIGN_LEFT);
344 bool bHorBlock = (nHorAlign == ALIGNDLG_HORALIGN_BLOCK);
345 bool bHorFill = (nHorAlign == ALIGNDLG_HORALIGN_FILL);
346 bool bHorDist = (nHorAlign == ALIGNDLG_HORALIGN_DISTRIBUTED);
348 // indent edit field only for left alignment
349 m_pFtIndent->Enable( bHorLeft );
350 m_pEdIndent->Enable( bHorLeft );
352 // rotation/stacked disabled for fill alignment
353 m_pOrientHlp->Enable( !bHorFill );
355 // hyphenation only for automatic line breaks or for block alignment
356 m_pBtnHyphen->Enable( m_pBtnWrap->IsChecked() || bHorBlock );
358 // shrink only without automatic line break, and not for block, fill or distribute.
359 m_pBtnShrink->Enable( (m_pBtnWrap->GetState() == STATE_NOCHECK) && !bHorBlock && !bHorFill && !bHorDist );
363 bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, sal_uInt16 nWhich ) const
365 const SfxItemSet& rOld = GetItemSet();
366 const SfxPoolItem* pItem;
367 SvxCellJustifyMethod eMethodOld = SVX_JUSTIFY_METHOD_AUTO;
368 SvxCellJustifyMethod eMethodNew = SVX_JUSTIFY_METHOD_AUTO;
369 if (rOld.GetItemState(nWhich, sal_True, &pItem) == SFX_ITEM_SET)
371 const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
372 eMethodOld = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
375 if (rNew.GetItemState(nWhich, sal_True, &pItem) == SFX_ITEM_SET)
377 const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
378 eMethodNew = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
381 return eMethodOld != eMethodNew;
384 IMPL_LINK_NOARG(AlignmentTabPage, UpdateEnableHdl)
386 UpdateEnableControls();
387 return 0;
390 // ============================================================================
392 } // namespace svx
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */