1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "AlignmentPropertyPanel.hxx"
21 #include <editeng/justifyitem.hxx>
23 #include "scresid.hxx"
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svx/algitem.hxx>
27 #include <svx/dlgutil.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <svx/sidebar/SidebarDialControl.hxx>
32 using namespace css::uno
;
36 namespace sc
{ namespace sidebar
{
38 AlignmentPropertyPanel::AlignmentPropertyPanel(
40 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
41 SfxBindings
* pBindings
)
42 : PanelLayout(pParent
, "AlignmentPropertyPanel", "modules/scalc/ui/sidebaralignment.ui", rxFrame
),
43 maAlignHorControl(SID_H_ALIGNCELL
, *pBindings
, *this),
44 maLeftIndentControl(SID_ATTR_ALIGN_INDENT
, *pBindings
, *this),
45 maMergeCellControl(FID_MERGE_TOGGLE
, *pBindings
, *this),
46 maWrapTextControl(SID_ATTR_ALIGN_LINEBREAK
, *pBindings
, *this),
47 maAngleControl(SID_ATTR_ALIGN_DEGREES
, *pBindings
, *this),
48 mbMultiDisable(false),
53 get(mpFTLeftIndent
, "leftindentlabel");
54 get(mpMFLeftIndent
, "leftindent");
55 get(mpCBXWrapText
, "wraptext");
56 get(mpCBXMergeCell
, "mergecells");
57 get(mpFtRotate
, "orientationlabel");
58 get(mpMtrAngle
, "orientationdegrees");
62 mpFTLeftIndent
->SetBackground(Wallpaper());
63 mpFtRotate
->SetBackground(Wallpaper());
66 AlignmentPropertyPanel::~AlignmentPropertyPanel()
71 void AlignmentPropertyPanel::dispose()
73 mpFTLeftIndent
.clear();
74 mpMFLeftIndent
.clear();
75 mpCBXWrapText
.clear();
76 mpCBXMergeCell
.clear();
80 maAlignHorControl
.dispose();
81 maLeftIndentControl
.dispose();
82 maMergeCellControl
.dispose();
83 maWrapTextControl
.dispose();
84 maAngleControl
.dispose();
86 PanelLayout::dispose();
89 void AlignmentPropertyPanel::Initialize()
91 mpFTLeftIndent
->Disable();
92 mpMFLeftIndent
->Disable();
93 mpMFLeftIndent
->SetAccessibleName(OUString( "Left Indent")); //wj acc
94 Link
<> aLink
= LINK(this, AlignmentPropertyPanel
, MFLeftIndentMdyHdl
);
95 mpMFLeftIndent
->SetModifyHdl ( aLink
);
97 aLink
= LINK(this, AlignmentPropertyPanel
, CBOXMergnCellClkHdl
);
98 mpCBXMergeCell
->SetClickHdl ( aLink
);
100 aLink
= LINK(this, AlignmentPropertyPanel
, CBOXWrapTextClkHdl
);
101 mpCBXWrapText
->SetClickHdl ( aLink
);
106 mpMtrAngle
->SetAccessibleName(OUString( "Text Orientation")); //wj acc
107 mpMtrAngle
->SetModifyHdl(LINK( this, AlignmentPropertyPanel
, AngleModifiedHdl
));
108 mpMtrAngle
->EnableAutocomplete( false );
112 mpMtrAngle
->InsertValue(0, FUNIT_CUSTOM
);
113 mpMtrAngle
->InsertValue(45, FUNIT_CUSTOM
);
114 mpMtrAngle
->InsertValue(90, FUNIT_CUSTOM
);
115 mpMtrAngle
->InsertValue(135, FUNIT_CUSTOM
);
116 mpMtrAngle
->InsertValue(180, FUNIT_CUSTOM
);
117 mpMtrAngle
->InsertValue(225, FUNIT_CUSTOM
);
118 mpMtrAngle
->InsertValue(270, FUNIT_CUSTOM
);
119 mpMtrAngle
->InsertValue(315, FUNIT_CUSTOM
);
120 mpMtrAngle
->SetDropDownLineCount(mpMtrAngle
->GetEntryCount());
122 mpMFLeftIndent
->SetAccessibleRelationLabeledBy(mpFTLeftIndent
);
123 mpMtrAngle
->SetAccessibleRelationLabeledBy(mpFtRotate
);
126 IMPL_LINK_NOARG( AlignmentPropertyPanel
, AngleModifiedHdl
)
128 OUString sTmp
= mpMtrAngle
->GetText();
131 sal_Unicode nChar
= sTmp
[0];
134 if (sTmp
.getLength() < 2)
139 if( (nChar
< '0') || (nChar
> '9') )
142 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
143 const sal_Unicode cSep
= rLocaleWrapper
.getNumDecimalSep()[0];
145 // Do not check that the entire string was parsed up to its end, there may
146 // be a degree symbol following the number. Note that this also means that
147 // the number recognized just stops at any non-matching character.
148 /* TODO: we could check for the degree symbol stop if there are no other
149 * cases with different symbol characters in any language? */
150 rtl_math_ConversionStatus eStatus
;
151 double fTmp
= rtl::math::stringToDouble( sTmp
, cSep
, 0, &eStatus
);
152 if (eStatus
!= rtl_math_ConversionStatus_Ok
)
157 sal_Int64 nTmp
= (sal_Int64
)fTmp
*100;
158 SfxInt32Item
aAngleItem( SID_ATTR_ALIGN_DEGREES
,(sal_uInt32
) nTmp
);
160 GetBindings()->GetDispatcher()->Execute(
161 SID_ATTR_ALIGN_DEGREES
, SfxCallMode::RECORD
, &aAngleItem
, 0L );
164 IMPL_LINK_NOARG(AlignmentPropertyPanel
, MFLeftIndentMdyHdl
)
166 mpCBXWrapText
->EnableTriState(false);
167 sal_uInt16 nVal
= (sal_uInt16
)mpMFLeftIndent
->GetValue();
168 SfxUInt16Item
aItem( SID_ATTR_ALIGN_INDENT
, (sal_uInt16
)CalcToUnit( nVal
, SFX_MAPUNIT_TWIP
) );
170 GetBindings()->GetDispatcher()->Execute(SID_ATTR_ALIGN_INDENT
, SfxCallMode::RECORD
, &aItem
, 0L);
174 IMPL_LINK_NOARG(AlignmentPropertyPanel
, CBOXMergnCellClkHdl
)
176 bool bState
= mpCBXMergeCell
->IsChecked();
179 //SfxBoolItem aItem( FID_MERGE_TOGGLE , bState);
180 //GetBindings()->GetDispatcher()->Execute(FID_MERGE_TOGGLE, SfxCallMode::RECORD, &aItem, false, 0L);
182 GetBindings()->GetDispatcher()->Execute(FID_MERGE_ON
, SfxCallMode::RECORD
);
184 GetBindings()->GetDispatcher()->Execute(FID_MERGE_OFF
, SfxCallMode::RECORD
);
185 GetBindings()->Invalidate(FID_MERGE_TOGGLE
,true,false);
191 IMPL_LINK_NOARG(AlignmentPropertyPanel
, CBOXWrapTextClkHdl
)
193 bool bState
= mpCBXWrapText
->IsChecked();
194 SfxBoolItem
aItem( SID_ATTR_ALIGN_LINEBREAK
, bState
);
195 GetBindings()->GetDispatcher()->Execute(SID_ATTR_ALIGN_LINEBREAK
, SfxCallMode::RECORD
, &aItem
, 0L);
199 VclPtr
<vcl::Window
> AlignmentPropertyPanel::Create (
200 vcl::Window
* pParent
,
201 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
202 SfxBindings
* pBindings
)
205 throw lang::IllegalArgumentException("no parent Window given to AlignmentPropertyPanel::Create", NULL
, 0);
207 throw lang::IllegalArgumentException("no XFrame given to AlignmentPropertyPanel::Create", NULL
, 1);
208 if (pBindings
== NULL
)
209 throw lang::IllegalArgumentException("no SfxBindings given to AlignmentPropertyPanel::Create", NULL
, 2);
211 return VclPtr
<AlignmentPropertyPanel
>::Create(
212 pParent
, rxFrame
, pBindings
);
215 void AlignmentPropertyPanel::DataChanged(
216 const DataChangedEvent
& rEvent
)
221 void AlignmentPropertyPanel::HandleContextChange(
222 const ::sfx2::sidebar::EnumContext
& rContext
)
224 if (maContext
== rContext
)
230 maContext
= rContext
;
233 void AlignmentPropertyPanel::NotifyItemUpdate(
236 const SfxPoolItem
* pState
,
237 const bool bIsEnabled
)
243 case SID_H_ALIGNCELL
:
245 SvxCellHorJustify meHorAlignState
= SVX_HOR_JUSTIFY_STANDARD
;
246 if(eState
>= SfxItemState::DEFAULT
&& pState
&& pState
->ISA(SvxHorJustifyItem
) )
248 const SvxHorJustifyItem
* pItem
= static_cast<const SvxHorJustifyItem
*>(pState
);
249 meHorAlignState
= (SvxCellHorJustify
)pItem
->GetValue();
252 if( meHorAlignState
== SVX_HOR_JUSTIFY_REPEAT
)
254 mpFtRotate
->Disable();
255 mpMtrAngle
->Disable();
259 mpFtRotate
->Enable(!mbMultiDisable
);
260 mpMtrAngle
->Enable(!mbMultiDisable
);
263 mpFTLeftIndent
->Enable( meHorAlignState
== SVX_HOR_JUSTIFY_LEFT
);
264 mpMFLeftIndent
->Enable( meHorAlignState
== SVX_HOR_JUSTIFY_LEFT
);
267 case SID_ATTR_ALIGN_INDENT
:
268 if(eState
>= SfxItemState::DEFAULT
&& pState
&& pState
->ISA(SfxUInt16Item
) )
270 const SfxUInt16Item
* pItem
= static_cast<const SfxUInt16Item
*>(pState
);
271 sal_uInt16 nVal
= pItem
->GetValue();
272 mpMFLeftIndent
->SetValue( CalcToPoint(nVal
, SFX_MAPUNIT_TWIP
, 1) );
276 mpMFLeftIndent
->SetValue(0);
277 mpMFLeftIndent
->SetText(OUString());
280 case FID_MERGE_TOGGLE
:
281 if(eState
>= SfxItemState::DEFAULT
&& pState
&& pState
->ISA(SfxBoolItem
) )
283 mpCBXMergeCell
->Enable();
284 const SfxBoolItem
* pItem
= static_cast<const SfxBoolItem
*>(pState
);
285 mpCBXMergeCell
->Check(pItem
->GetValue());
289 mpCBXMergeCell
->Check(false);
290 mpCBXMergeCell
->Disable();
294 case SID_ATTR_ALIGN_LINEBREAK
:
295 if(eState
== SfxItemState::DISABLED
)
297 mpCBXWrapText
->EnableTriState(false);
298 mpCBXWrapText
->Check(false);
299 mpCBXWrapText
->Disable();
303 mpCBXWrapText
->Enable();
304 if(eState
>= SfxItemState::DEFAULT
&& pState
&& pState
->ISA(SfxBoolItem
) )
306 mpCBXWrapText
->EnableTriState(false);
307 const SfxBoolItem
* pItem
= static_cast<const SfxBoolItem
*>(pState
);
308 mpCBXWrapText
->Check(pItem
->GetValue());
310 else if(eState
== SfxItemState::DONTCARE
)
312 mpCBXWrapText
->EnableTriState(true);
313 mpCBXWrapText
->SetState(TRISTATE_INDET
);
317 case SID_ATTR_ALIGN_DEGREES
:
318 if (eState
>= SfxItemState::DEFAULT
)
320 long nTmp
= static_cast<const SfxInt32Item
*>(pState
)->GetValue();
321 mpMtrAngle
->SetValue( nTmp
/ 100); //wj
325 mpMtrAngle
->SelectEntryPos(0);
328 mpMtrAngle
->SelectEntryPos(1);
331 mpMtrAngle
->SelectEntryPos(2);
334 mpMtrAngle
->SelectEntryPos(3);
337 mpMtrAngle
->SelectEntryPos(4);
340 mpMtrAngle
->SelectEntryPos(5);
343 mpMtrAngle
->SelectEntryPos(6);
346 mpMtrAngle
->SelectEntryPos(7);
351 mpMtrAngle
->SetText( OUString() );
357 void AlignmentPropertyPanel::FormatDegrees(double& dTmp
)
361 while (dTmp
> 359) //modify
367 }} // end of namespace ::sc::sidebar
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */