update dev300-m58
[ooovba.git] / svx / source / cui / align.cxx
blob77538a9a6677573db8d2d55064d02c92b7e53f2e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: align.cxx,v $
10 * $Revision: 1.26.272.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
40 #include <svx/svxenum.hxx>
42 #include <svx/dialogs.hrc>
43 #include "align.hrc"
44 #include "rotmodit.hxx"
46 #include <svx/algitem.hxx>
47 #include <svx/frmdiritem.hxx>
48 #include "align.hxx"
49 #include <svx/dialmgr.hxx>
50 #include "dlgutil.hxx"
51 #include <tools/shl.hxx>
52 #include <sfx2/app.hxx>
53 #include <sfx2/module.hxx>
54 #include <sfx2/itemconnect.hxx>
55 #include <svtools/cjkoptions.hxx>
56 #include <svtools/languageoptions.hxx>
57 #include <svtools/localresaccess.hxx>
58 #include <svx/svxids.hrc> //CHINA001
59 #include "flagsdef.hxx" //CHINA001
60 #include <svtools/intitem.hxx> //CHINA001
61 #include <sfx2/request.hxx> //CHINA001
63 namespace svx {
65 // item connections ===========================================================
67 // horizontal alignment -------------------------------------------------------
69 typedef sfx::ValueItemWrapper< SvxHorJustifyItem, SvxCellHorJustify, USHORT > HorJustItemWrapper;
70 typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnection;
72 static const HorJustConnection::MapEntryType s_pHorJustMap[] =
74 { ALIGNDLG_HORALIGN_STD, SVX_HOR_JUSTIFY_STANDARD },
75 { ALIGNDLG_HORALIGN_LEFT, SVX_HOR_JUSTIFY_LEFT },
76 { ALIGNDLG_HORALIGN_CENTER, SVX_HOR_JUSTIFY_CENTER },
77 { ALIGNDLG_HORALIGN_RIGHT, SVX_HOR_JUSTIFY_RIGHT },
78 { ALIGNDLG_HORALIGN_BLOCK, SVX_HOR_JUSTIFY_BLOCK },
79 { ALIGNDLG_HORALIGN_FILL, SVX_HOR_JUSTIFY_REPEAT },
80 { LISTBOX_ENTRY_NOTFOUND, SVX_HOR_JUSTIFY_STANDARD }
83 // vertical alignment ---------------------------------------------------------
85 typedef sfx::ValueItemWrapper< SvxVerJustifyItem, SvxCellVerJustify, USHORT > VerJustItemWrapper;
86 typedef sfx::ListBoxConnection< VerJustItemWrapper > VerJustConnection;
88 static const VerJustConnection::MapEntryType s_pVerJustMap[] =
90 { ALIGNDLG_VERALIGN_STD, SVX_VER_JUSTIFY_STANDARD },
91 { ALIGNDLG_VERALIGN_TOP, SVX_VER_JUSTIFY_TOP },
92 { ALIGNDLG_VERALIGN_MID, SVX_VER_JUSTIFY_CENTER },
93 { ALIGNDLG_VERALIGN_BOTTOM, SVX_VER_JUSTIFY_BOTTOM },
94 { LISTBOX_ENTRY_NOTFOUND, SVX_VER_JUSTIFY_STANDARD }
97 // cell rotate mode -----------------------------------------------------------
99 typedef sfx::ValueItemWrapper< SvxRotateModeItem, SvxRotateMode, USHORT > RotateModeItemWrapper;
100 typedef sfx::ValueSetConnection< RotateModeItemWrapper > RotateModeConnection;
102 static const RotateModeConnection::MapEntryType s_pRotateModeMap[] =
104 { IID_BOTTOMLOCK, SVX_ROTATE_MODE_BOTTOM },
105 { IID_TOPLOCK, SVX_ROTATE_MODE_TOP },
106 { IID_CELLLOCK, SVX_ROTATE_MODE_STANDARD },
107 { VALUESET_ITEM_NOTFOUND, SVX_ROTATE_MODE_STANDARD }
110 // ============================================================================
112 static USHORT s_pRanges[] =
114 SID_ATTR_ALIGN_HOR_JUSTIFY,SID_ATTR_ALIGN_VER_JUSTIFY,
115 SID_ATTR_ALIGN_STACKED,SID_ATTR_ALIGN_LINEBREAK,
116 SID_ATTR_ALIGN_INDENT,SID_ATTR_ALIGN_INDENT,
117 SID_ATTR_ALIGN_DEGREES,SID_ATTR_ALIGN_DEGREES,
118 SID_ATTR_ALIGN_LOCKPOS,SID_ATTR_ALIGN_LOCKPOS,
119 SID_ATTR_ALIGN_HYPHENATION,SID_ATTR_ALIGN_HYPHENATION,
120 SID_ATTR_ALIGN_ASIANVERTICAL,SID_ATTR_ALIGN_ASIANVERTICAL,
121 SID_ATTR_FRAMEDIRECTION,SID_ATTR_FRAMEDIRECTION,
122 SID_ATTR_ALIGN_SHRINKTOFIT,SID_ATTR_ALIGN_SHRINKTOFIT,
126 // ============================================================================
128 AlignmentTabPage::AlignmentTabPage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
130 SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_ALIGNMENT ), rCoreAttrs ),
132 maFlAlignment ( this, SVX_RES( FL_ALIGNMENT ) ),
133 maFtHorAlign ( this, SVX_RES( FT_HORALIGN ) ),
134 maLbHorAlign ( this, SVX_RES( LB_HORALIGN ) ),
135 maFtIndent ( this, SVX_RES( FT_INDENT ) ),
136 maEdIndent ( this, SVX_RES( ED_INDENT ) ),
137 maFtVerAlign ( this, SVX_RES( FT_VERALIGN ) ),
138 maLbVerAlign ( this, SVX_RES( LB_VERALIGN ) ),
140 maFlOrient ( this, SVX_RES( FL_ORIENTATION ) ),
141 maCtrlDial ( this, SVX_RES( CTR_DIAL ) ),
142 maFtRotate ( this, SVX_RES( FT_DEGREES ) ),
143 maNfRotate ( this, SVX_RES( NF_DEGREES ) ),
144 maFtRefEdge ( this, SVX_RES( FT_BORDER_LOCK ) ),
145 maVsRefEdge ( this, SVX_RES( CTR_BORDER_LOCK ) ),
146 maCbStacked ( this, SVX_RES( BTN_TXTSTACKED ) ),
147 maCbAsianMode ( this, SVX_RES( BTN_ASIAN_VERTICAL ) ),
148 maOrientHlp ( maCtrlDial, maNfRotate, maCbStacked ),
150 maFlProperties ( this, SVX_RES( FL_WRAP ) ),
151 maBtnWrap ( this, SVX_RES( BTN_WRAP ) ),
152 maBtnHyphen ( this, SVX_RES( BTN_HYPH ) ),
153 maBtnShrink ( this, SVX_RES( BTN_SHRINK ) ),
154 maFtFrameDir ( this, SVX_RES( FT_TEXTFLOW ) ),
155 maLbFrameDir ( this, SVX_RES( LB_FRAMEDIR ) )
157 InitVsRefEgde();
159 // windows to be disabled, if stacked text is turned ON
160 maOrientHlp.AddDependentWindow( maFtRotate, STATE_CHECK );
161 maOrientHlp.AddDependentWindow( maFtRefEdge, STATE_CHECK );
162 maOrientHlp.AddDependentWindow( maVsRefEdge, STATE_CHECK );
163 // windows to be disabled, if stacked text is turned OFF
164 maOrientHlp.AddDependentWindow( maCbAsianMode, STATE_NOCHECK );
166 Link aLink = LINK( this, AlignmentTabPage, UpdateEnableHdl );
168 maLbHorAlign.SetSelectHdl( aLink );
169 maBtnWrap.SetClickHdl( aLink );
171 // Asian vertical mode
172 maCbAsianMode.Show( SvtCJKOptions().IsVerticalTextEnabled() );
174 // CTL frame direction
175 maLbFrameDir.InsertEntryValue( SVX_RESSTR( RID_SVXSTR_FRAMEDIR_LTR ), FRMDIR_HORI_LEFT_TOP );
176 maLbFrameDir.InsertEntryValue( SVX_RESSTR( RID_SVXSTR_FRAMEDIR_RTL ), FRMDIR_HORI_RIGHT_TOP );
177 maLbFrameDir.InsertEntryValue( SVX_RESSTR( RID_SVXSTR_FRAMEDIR_SUPER ), FRMDIR_ENVIRONMENT );
178 if( !SvtLanguageOptions().IsCTLFontEnabled() )
180 maFtFrameDir.Hide();
181 maLbFrameDir.Hide();
184 // diese Page braucht ExchangeSupport
185 SetExchangeSupport();
187 FreeResource();
189 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maFtHorAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
190 AddItemConnection( new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
191 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_INDENT, maFtIndent, sfx::ITEMCONN_HIDE_UNKNOWN ) );
192 AddItemConnection( new sfx::UInt16MetricConnection( SID_ATTR_ALIGN_INDENT, maEdIndent, FUNIT_TWIP, sfx::ITEMCONN_HIDE_UNKNOWN ) );
193 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maFtVerAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
194 AddItemConnection( new VerJustConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maLbVerAlign, s_pVerJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
195 AddItemConnection( new DialControlConnection( SID_ATTR_ALIGN_DEGREES, maCtrlDial, sfx::ITEMCONN_HIDE_UNKNOWN ) );
196 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_DEGREES, maFtRotate, sfx::ITEMCONN_HIDE_UNKNOWN ) );
197 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_LOCKPOS, maFtRefEdge, sfx::ITEMCONN_HIDE_UNKNOWN ) );
198 AddItemConnection( new RotateModeConnection( SID_ATTR_ALIGN_LOCKPOS, maVsRefEdge, s_pRotateModeMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
199 AddItemConnection( new OrientStackedConnection( SID_ATTR_ALIGN_STACKED, maOrientHlp ) );
200 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_STACKED, maCbStacked, sfx::ITEMCONN_HIDE_UNKNOWN ) );
201 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_ASIANVERTICAL, maCbAsianMode, sfx::ITEMCONN_HIDE_UNKNOWN ) );
202 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_LINEBREAK, maBtnWrap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
203 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_HYPHENATION, maBtnHyphen, sfx::ITEMCONN_HIDE_UNKNOWN ) );
204 AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_SHRINKTOFIT, maBtnShrink, sfx::ITEMCONN_HIDE_UNKNOWN ) );
205 AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_FRAMEDIRECTION, maFtFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
206 AddItemConnection( new FrameDirListBoxConnection( SID_ATTR_FRAMEDIRECTION, maLbFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
209 AlignmentTabPage::~AlignmentTabPage()
213 SfxTabPage* AlignmentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
215 return new AlignmentTabPage( pParent, rAttrSet );
218 USHORT* AlignmentTabPage::GetRanges()
220 return s_pRanges;
223 void AlignmentTabPage::Reset( const SfxItemSet& rCoreAttrs )
225 SfxTabPage::Reset( rCoreAttrs );
226 UpdateEnableControls();
229 int AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
231 if( _pSet )
232 FillItemSet( *_pSet );
233 return LEAVE_PAGE;
236 void AlignmentTabPage::DataChanged( const DataChangedEvent& rDCEvt )
238 SfxTabPage::DataChanged( rDCEvt );
239 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
241 svt::OLocalResourceAccess aLocalResAcc( SVX_RES( RID_SVXPAGE_ALIGNMENT ), RSC_TABPAGE );
242 InitVsRefEgde();
246 void AlignmentTabPage::InitVsRefEgde()
248 // remember selection - is deleted in call to ValueSet::Clear()
249 USHORT nSel = maVsRefEdge.GetSelectItemId();
251 ResId aResId( GetBackground().GetColor().IsDark() ? IL_LOCK_BMPS_HC : IL_LOCK_BMPS, DIALOG_MGR() );
252 ImageList aImageList( aResId );
253 Size aItemSize( aImageList.GetImage( IID_BOTTOMLOCK ).GetSizePixel() );
255 maVsRefEdge.Clear();
256 maVsRefEdge.SetStyle( maVsRefEdge.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
258 maVsRefEdge.SetColCount( 3 );
259 maVsRefEdge.InsertItem( IID_BOTTOMLOCK, aImageList.GetImage( IID_BOTTOMLOCK ), String( SVX_RES( STR_BOTTOMLOCK ) ) );
260 maVsRefEdge.InsertItem( IID_TOPLOCK, aImageList.GetImage( IID_TOPLOCK ), String( SVX_RES( STR_TOPLOCK ) ) );
261 maVsRefEdge.InsertItem( IID_CELLLOCK, aImageList.GetImage( IID_CELLLOCK ), String( SVX_RES( STR_CELLLOCK ) ) );
263 maVsRefEdge.SetSizePixel( maVsRefEdge.CalcWindowSizePixel( aItemSize ) );
265 maVsRefEdge.SelectItem( nSel );
268 void AlignmentTabPage::UpdateEnableControls()
270 USHORT nHorAlign = maLbHorAlign.GetSelectEntryPos();
271 bool bHorLeft = (nHorAlign == ALIGNDLG_HORALIGN_LEFT);
272 bool bHorBlock = (nHorAlign == ALIGNDLG_HORALIGN_BLOCK);
273 bool bHorFill = (nHorAlign == ALIGNDLG_HORALIGN_FILL);
275 // indent edit field only for left alignment
276 maFtIndent.Enable( bHorLeft );
277 maEdIndent.Enable( bHorLeft );
279 // rotation/stacked disabled for fill alignment
280 maOrientHlp.Enable( !bHorFill );
282 // hyphenation only for automatic line breaks or for block alignment
283 maBtnHyphen.Enable( maBtnWrap.IsChecked() || bHorBlock );
285 // shrink only without automatic line break, and not for block and fill
286 maBtnShrink.Enable( (maBtnWrap.GetState() == STATE_NOCHECK) && !bHorBlock && !bHorFill );
288 // visibility of fixed lines
289 maFlAlignment.Show( maLbHorAlign.IsVisible() || maEdIndent.IsVisible() || maLbVerAlign.IsVisible() );
290 maFlOrient.Show( maCtrlDial.IsVisible() || maVsRefEdge.IsVisible() || maCbStacked.IsVisible() || maCbAsianMode.IsVisible() );
291 maFlProperties.Show( maBtnWrap.IsVisible() || maBtnHyphen.IsVisible() || maBtnShrink.IsVisible() || maLbFrameDir.IsVisible() );
294 IMPL_LINK( AlignmentTabPage, UpdateEnableHdl, void*, EMPTYARG )
296 UpdateEnableControls();
297 return 0;
300 // ============================================================================
302 } // namespace svx