1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// include ---------------------------------------------------------------
#include "align.hxx"
#include <editeng/svxenum.hxx>
#include <svx/dialogs.hrc>
#include <cuires.hrc>
#include "align.hrc"
#include <svx/rotmodit.hxx>
#include <svx/algitem.hxx>
#include <editeng/frmdiritem.hxx>
#include <editeng/justifyitem.hxx>
#include <dialmgr.hxx>
#include <svx/dlgutil.hxx>
#include <tools/shl.hxx>
#include <sfx2/app.hxx>
#include <sfx2/module.hxx>
#include <sfx2/itemconnect.hxx>
#include <svl/cjkoptions.hxx>
#include <svl/languageoptions.hxx>
#include <svtools/localresaccess.hxx>
#include <svx/flagsdef.hxx>
#include <svl/intitem.hxx>
#include <sfx2/request.hxx>
namespace svx {
// item connections ===========================================================
// horizontal alignment -------------------------------------------------------
typedef sfx::ValueItemWrapper< SvxHorJustifyItem, SvxCellHorJustify, USHORT > HorJustItemWrapper;
typedef sfx::ListBoxConnection< HorJustItemWrapper > HorJustConnection;
static const HorJustConnection::MapEntryType s_pHorJustMap[] =
{
{ ALIGNDLG_HORALIGN_STD, SVX_HOR_JUSTIFY_STANDARD },
{ ALIGNDLG_HORALIGN_LEFT, SVX_HOR_JUSTIFY_LEFT },
{ ALIGNDLG_HORALIGN_CENTER, SVX_HOR_JUSTIFY_CENTER },
{ ALIGNDLG_HORALIGN_RIGHT, SVX_HOR_JUSTIFY_RIGHT },
{ ALIGNDLG_HORALIGN_BLOCK, SVX_HOR_JUSTIFY_BLOCK },
{ ALIGNDLG_HORALIGN_FILL, SVX_HOR_JUSTIFY_REPEAT },
{ ALIGNDLG_HORALIGN_DISTRIBUTED, SVX_HOR_JUSTIFY_BLOCK },
{ LISTBOX_ENTRY_NOTFOUND, SVX_HOR_JUSTIFY_STANDARD }
};
// vertical alignment ---------------------------------------------------------
typedef sfx::ValueItemWrapper< SvxVerJustifyItem, SvxCellVerJustify, USHORT > VerJustItemWrapper;
typedef sfx::ListBoxConnection< VerJustItemWrapper > VerJustConnection;
static const VerJustConnection::MapEntryType s_pVerJustMap[] =
{
{ ALIGNDLG_VERALIGN_STD, SVX_VER_JUSTIFY_STANDARD },
{ ALIGNDLG_VERALIGN_TOP, SVX_VER_JUSTIFY_TOP },
{ ALIGNDLG_VERALIGN_MID, SVX_VER_JUSTIFY_CENTER },
{ ALIGNDLG_VERALIGN_BOTTOM, SVX_VER_JUSTIFY_BOTTOM },
{ ALIGNDLG_VERALIGN_BLOCK, SVX_VER_JUSTIFY_BLOCK },
{ ALIGNDLG_VERALIGN_DISTRIBUTED, SVX_VER_JUSTIFY_BLOCK },
{ LISTBOX_ENTRY_NOTFOUND, SVX_VER_JUSTIFY_STANDARD }
};
// cell rotate mode -----------------------------------------------------------
typedef sfx::ValueItemWrapper< SvxRotateModeItem, SvxRotateMode, USHORT > RotateModeItemWrapper;
typedef sfx::ValueSetConnection< RotateModeItemWrapper > RotateModeConnection;
static const RotateModeConnection::MapEntryType s_pRotateModeMap[] =
{
{ IID_BOTTOMLOCK, SVX_ROTATE_MODE_BOTTOM },
{ IID_TOPLOCK, SVX_ROTATE_MODE_TOP },
{ IID_CELLLOCK, SVX_ROTATE_MODE_STANDARD },
{ VALUESET_ITEM_NOTFOUND, SVX_ROTATE_MODE_STANDARD }
};
// ============================================================================
static USHORT s_pRanges[] =
{
SID_ATTR_ALIGN_HOR_JUSTIFY,SID_ATTR_ALIGN_VER_JUSTIFY,
SID_ATTR_ALIGN_STACKED,SID_ATTR_ALIGN_LINEBREAK,
SID_ATTR_ALIGN_INDENT,SID_ATTR_ALIGN_INDENT,
SID_ATTR_ALIGN_DEGREES,SID_ATTR_ALIGN_DEGREES,
SID_ATTR_ALIGN_LOCKPOS,SID_ATTR_ALIGN_LOCKPOS,
SID_ATTR_ALIGN_HYPHENATION,SID_ATTR_ALIGN_HYPHENATION,
SID_ATTR_ALIGN_ASIANVERTICAL,SID_ATTR_ALIGN_ASIANVERTICAL,
SID_ATTR_FRAMEDIRECTION,SID_ATTR_FRAMEDIRECTION,
SID_ATTR_ALIGN_SHRINKTOFIT,SID_ATTR_ALIGN_SHRINKTOFIT,
0
};
// ============================================================================
namespace {
template<typename _JustContainerType, typename _JustEnumType>
void lcl_MaybeResetAlignToDistro(
ListBox& rLB, USHORT nListPos, const SfxItemSet& rCoreAttrs, USHORT nWhichAlign, USHORT nWhichJM, _JustEnumType eBlock)
{
const SfxPoolItem* pItem;
if (rCoreAttrs.GetItemState(nWhichAlign, TRUE, &pItem) != SFX_ITEM_SET)
// alignment not set.
return;
const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
_JustContainerType eVal = static_cast<_JustContainerType>(p->GetEnumValue());
if (eVal != eBlock)
// alignment is not 'justify'. No need to go further.
return;
if (rCoreAttrs.GetItemState(nWhichJM, TRUE, &pItem) != SFX_ITEM_SET)
// justification method is not set.
return;
p = static_cast<const SfxEnumItem*>(pItem);
SvxCellJustifyMethod eMethod = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
if (eMethod == SVX_JUSTIFY_METHOD_DISTRIBUTE)
// Select the 'distribute' entry in the specified list box.
rLB.SelectEntryPos(nListPos);
}
void lcl_SetJustifyMethodToItemSet(SfxItemSet& rSet, USHORT nWhichJM, const ListBox& rLB, USHORT nListPos)
{
SvxCellJustifyMethod eJM = SVX_JUSTIFY_METHOD_AUTO;
if (rLB.GetSelectEntryPos() == nListPos)
eJM = SVX_JUSTIFY_METHOD_DISTRIBUTE;
SvxJustifyMethodItem aItem(eJM, nWhichJM);
rSet.Put(aItem);
}
}
// ============================================================================
AlignmentTabPage::AlignmentTabPage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_ALIGNMENT ), rCoreAttrs ),
maFlAlignment ( this, CUI_RES( FL_ALIGNMENT ) ),
maFtHorAlign ( this, CUI_RES( FT_HORALIGN ) ),
maLbHorAlign ( this, CUI_RES( LB_HORALIGN ) ),
maFtIndent ( this, CUI_RES( FT_INDENT ) ),
maEdIndent ( this, CUI_RES( ED_INDENT ) ),
maFtVerAlign ( this, CUI_RES( FT_VERALIGN ) ),
maLbVerAlign ( this, CUI_RES( LB_VERALIGN ) ),
maFlOrient ( this, CUI_RES( FL_ORIENTATION ) ),
maCtrlDial ( this, CUI_RES( CTR_DIAL ) ),
maFtRotate ( this, CUI_RES( FT_DEGREES ) ),
maNfRotate ( this, CUI_RES( NF_DEGREES ) ),
maFtRefEdge ( this, CUI_RES( FT_BORDER_LOCK ) ),
maVsRefEdge ( this, CUI_RES( CTR_BORDER_LOCK ) ),
maCbStacked ( this, CUI_RES( BTN_TXTSTACKED ) ),
maCbAsianMode ( this, CUI_RES( BTN_ASIAN_VERTICAL ) ),
maOrientHlp ( maCtrlDial, maNfRotate, maCbStacked ),
maFlProperties ( this, CUI_RES( FL_WRAP ) ),
maBtnWrap ( this, CUI_RES( BTN_WRAP ) ),
maBtnHyphen ( this, CUI_RES( BTN_HYPH ) ),
maBtnShrink ( this, CUI_RES( BTN_SHRINK ) ),
maFtFrameDir ( this, CUI_RES( FT_TEXTFLOW ) ),
maLbFrameDir ( this, CUI_RES( LB_FRAMEDIR ) )
{
InitVsRefEgde();
// windows to be disabled, if stacked text is turned ON
maOrientHlp.AddDependentWindow( maFtRotate, STATE_CHECK );
maOrientHlp.AddDependentWindow( maFtRefEdge, STATE_CHECK );
maOrientHlp.AddDependentWindow( maVsRefEdge, STATE_CHECK );
// windows to be disabled, if stacked text is turned OFF
maOrientHlp.AddDependentWindow( maCbAsianMode, STATE_NOCHECK );
Link aLink = LINK( this, AlignmentTabPage, UpdateEnableHdl );
maLbHorAlign.SetSelectHdl( aLink );
maBtnWrap.SetClickHdl( aLink );
// Asian vertical mode
maCbAsianMode.Show( SvtCJKOptions().IsVerticalTextEnabled() );
// CTL frame direction
maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_LTR ), FRMDIR_HORI_LEFT_TOP );
maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_RTL ), FRMDIR_HORI_RIGHT_TOP );
maLbFrameDir.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_FRAMEDIR_SUPER ), FRMDIR_ENVIRONMENT );
if( !SvtLanguageOptions().IsCTLFontEnabled() )
{
maFtFrameDir.Hide();
maLbFrameDir.Hide();
}
// This page needs ExchangeSupport.
SetExchangeSupport();
FreeResource();
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maFtHorAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new HorJustConnection( SID_ATTR_ALIGN_HOR_JUSTIFY, maLbHorAlign, s_pHorJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_INDENT, maFtIndent, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::UInt16MetricConnection( SID_ATTR_ALIGN_INDENT, maEdIndent, FUNIT_TWIP, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maFtVerAlign, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new VerJustConnection( SID_ATTR_ALIGN_VER_JUSTIFY, maLbVerAlign, s_pVerJustMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new DialControlConnection( SID_ATTR_ALIGN_DEGREES, maCtrlDial, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_DEGREES, maFtRotate, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_LOCKPOS, maFtRefEdge, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new RotateModeConnection( SID_ATTR_ALIGN_LOCKPOS, maVsRefEdge, s_pRotateModeMap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new OrientStackedConnection( SID_ATTR_ALIGN_STACKED, maOrientHlp ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_ALIGN_STACKED, maCbStacked, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_ASIANVERTICAL, maCbAsianMode, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_LINEBREAK, maBtnWrap, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_HYPHENATION, maBtnHyphen, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::CheckBoxConnection( SID_ATTR_ALIGN_SHRINKTOFIT, maBtnShrink, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new sfx::DummyItemConnection( SID_ATTR_FRAMEDIRECTION, maFtFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
AddItemConnection( new FrameDirListBoxConnection( SID_ATTR_FRAMEDIRECTION, maLbFrameDir, sfx::ITEMCONN_HIDE_UNKNOWN ) );
}
AlignmentTabPage::~AlignmentTabPage()
{
}
SfxTabPage* AlignmentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
{
return new AlignmentTabPage( pParent, rAttrSet );
}
USHORT* AlignmentTabPage::GetRanges()
{
return s_pRanges;
}
BOOL AlignmentTabPage::FillItemSet( SfxItemSet& rSet )
{
bool bChanged = SfxTabPage::FillItemSet(rSet);
// Special treatment for distributed alignment; we need to set the justify
// method to 'distribute' to distinguish from the normal justification.
USHORT nWhichHorJM = GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD);
lcl_SetJustifyMethodToItemSet(rSet, nWhichHorJM, maLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED);
if (!bChanged)
bChanged = HasAlignmentChanged(rSet, nWhichHorJM);
USHORT nWhichVerJM = GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD);
lcl_SetJustifyMethodToItemSet(rSet, nWhichVerJM, maLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED);
if (!bChanged)
bChanged = HasAlignmentChanged(rSet, nWhichVerJM);
return bChanged;
}
void AlignmentTabPage::Reset( const SfxItemSet& rCoreAttrs )
{
SfxTabPage::Reset( rCoreAttrs );
// Special treatment for distributed alignment; we need to set the justify
// method to 'distribute' to distinguish from the normal justification.
lcl_MaybeResetAlignToDistro<SvxCellHorJustify, SvxCellHorJustify>(
maLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED, rCoreAttrs,
GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY), GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD),
SVX_HOR_JUSTIFY_BLOCK);
lcl_MaybeResetAlignToDistro<SvxCellVerJustify, SvxCellVerJustify>(
maLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED, rCoreAttrs,
GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY), GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD),
SVX_VER_JUSTIFY_BLOCK);
UpdateEnableControls();
}
int AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
{
if( _pSet )
FillItemSet( *_pSet );
return LEAVE_PAGE;
}
void AlignmentTabPage::DataChanged( const DataChangedEvent& rDCEvt )
{
SfxTabPage::DataChanged( rDCEvt );
if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
svt::OLocalResourceAccess aLocalResAcc( CUI_RES( RID_SVXPAGE_ALIGNMENT ), RSC_TABPAGE );
InitVsRefEgde();
}
}
void AlignmentTabPage::InitVsRefEgde()
{
// remember selection - is deleted in call to ValueSet::Clear()
USHORT nSel = maVsRefEdge.GetSelectItemId();
ResId aResId( IL_LOCK_BMPS, CUI_MGR() );
ImageList aImageList( aResId );
Size aItemSize( aImageList.GetImage( IID_BOTTOMLOCK ).GetSizePixel() );
maVsRefEdge.Clear();
maVsRefEdge.SetStyle( maVsRefEdge.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
maVsRefEdge.SetColCount( 3 );
maVsRefEdge.InsertItem( IID_BOTTOMLOCK, aImageList.GetImage( IID_BOTTOMLOCK ), String( CUI_RES( STR_BOTTOMLOCK ) ) );
maVsRefEdge.InsertItem( IID_TOPLOCK, aImageList.GetImage( IID_TOPLOCK ), String( CUI_RES( STR_TOPLOCK ) ) );
maVsRefEdge.InsertItem( IID_CELLLOCK, aImageList.GetImage( IID_CELLLOCK ), String( CUI_RES( STR_CELLLOCK ) ) );
maVsRefEdge.SetSizePixel( maVsRefEdge.CalcWindowSizePixel( aItemSize ) );
maVsRefEdge.SelectItem( nSel );
}
void AlignmentTabPage::UpdateEnableControls()
{
USHORT nHorAlign = maLbHorAlign.GetSelectEntryPos();
bool bHorLeft = (nHorAlign == ALIGNDLG_HORALIGN_LEFT);
bool bHorBlock = (nHorAlign == ALIGNDLG_HORALIGN_BLOCK);
bool bHorFill = (nHorAlign == ALIGNDLG_HORALIGN_FILL);
bool bHorDist = (nHorAlign == ALIGNDLG_HORALIGN_DISTRIBUTED);
// indent edit field only for left alignment
maFtIndent.Enable( bHorLeft );
maEdIndent.Enable( bHorLeft );
// rotation/stacked disabled for fill alignment
maOrientHlp.Enable( !bHorFill );
// hyphenation only for automatic line breaks or for block alignment
maBtnHyphen.Enable( maBtnWrap.IsChecked() || bHorBlock );
// shrink only without automatic line break, and not for block, fill or distribute.
maBtnShrink.Enable( (maBtnWrap.GetState() == STATE_NOCHECK) && !bHorBlock && !bHorFill && !bHorDist );
// visibility of fixed lines
maFlAlignment.Show( maLbHorAlign.IsVisible() || maEdIndent.IsVisible() || maLbVerAlign.IsVisible() );
maFlOrient.Show( maCtrlDial.IsVisible() || maVsRefEdge.IsVisible() || maCbStacked.IsVisible() || maCbAsianMode.IsVisible() );
maFlProperties.Show( maBtnWrap.IsVisible() || maBtnHyphen.IsVisible() || maBtnShrink.IsVisible() || maLbFrameDir.IsVisible() );
}
bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, USHORT nWhich ) const
{
const SfxItemSet& rOld = GetItemSet();
const SfxPoolItem* pItem;
SvxCellJustifyMethod eMethodOld = SVX_JUSTIFY_METHOD_AUTO;
SvxCellJustifyMethod eMethodNew = SVX_JUSTIFY_METHOD_AUTO;
if (rOld.GetItemState(nWhich, TRUE, &pItem) == SFX_ITEM_SET)
{
const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
eMethodOld = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
}
if (rNew.GetItemState(nWhich, TRUE, &pItem) == SFX_ITEM_SET)
{
const SfxEnumItem* p = static_cast<const SfxEnumItem*>(pItem);
eMethodNew = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
}
return eMethodOld != eMethodNew;
}
IMPL_LINK( AlignmentTabPage, UpdateEnableHdl, void*, EMPTYARG )
{
UpdateEnableControls();
return 0;
}
// ============================================================================
} // namespace svx
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|