fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / sidebar / AlignmentPropertyPanel.cxx
blobd572ffd61a75e68352ec2f7e7d3f5c76a0750a65
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 "AlignmentPropertyPanel.hxx"
21 #include <editeng/justifyitem.hxx>
22 #include "sc.hrc"
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>
31 using namespace css;
32 using namespace css::uno;
34 // namespace open
36 namespace sc { namespace sidebar {
38 AlignmentPropertyPanel::AlignmentPropertyPanel(
39 vcl::Window* pParent,
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),
49 mxFrame(rxFrame),
50 maContext(),
51 mpBindings(pBindings)
53 get(mpFTLeftIndent, "leftindentlabel");
54 get(mpMFLeftIndent, "leftindent");
55 get(mpCBXWrapText, "wraptext");
56 get(mpCBXMergeCell, "mergecells");
57 get(mpFtRotate, "orientationlabel");
58 get(mpMtrAngle, "orientationdegrees");
60 Initialize();
62 mpFTLeftIndent->SetBackground(Wallpaper());
63 mpFtRotate->SetBackground(Wallpaper());
66 AlignmentPropertyPanel::~AlignmentPropertyPanel()
68 disposeOnce();
71 void AlignmentPropertyPanel::dispose()
73 mpFTLeftIndent.clear();
74 mpMFLeftIndent.clear();
75 mpCBXWrapText.clear();
76 mpCBXMergeCell.clear();
77 mpFtRotate.clear();
78 mpMtrAngle.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 );
103 //rotation control
105 //rotation
106 mpMtrAngle->SetAccessibleName(OUString( "Text Orientation")); //wj acc
107 mpMtrAngle->SetModifyHdl(LINK( this, AlignmentPropertyPanel, AngleModifiedHdl));
108 mpMtrAngle->EnableAutocomplete( false );
110 //Vertical stacked
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();
129 if (sTmp.isEmpty())
130 return 0;
131 sal_Unicode nChar = sTmp[0];
132 if( nChar == '-' )
134 if (sTmp.getLength() < 2)
135 return 0;
136 nChar = sTmp[1];
139 if( (nChar < '0') || (nChar > '9') )
140 return 0;
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)
153 return 0;
155 FormatDegrees(fTmp);
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 );
162 return 0;
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);
171 return 0L;
174 IMPL_LINK_NOARG(AlignmentPropertyPanel, CBOXMergnCellClkHdl)
176 bool bState = mpCBXMergeCell->IsChecked();
178 //Modified
179 //SfxBoolItem aItem( FID_MERGE_TOGGLE , bState);
180 //GetBindings()->GetDispatcher()->Execute(FID_MERGE_TOGGLE, SfxCallMode::RECORD, &aItem, false, 0L);
181 if(bState)
182 GetBindings()->GetDispatcher()->Execute(FID_MERGE_ON, SfxCallMode::RECORD);
183 else
184 GetBindings()->GetDispatcher()->Execute(FID_MERGE_OFF, SfxCallMode::RECORD);
185 GetBindings()->Invalidate(FID_MERGE_TOGGLE,true,false);
186 //modified end
188 return 0;
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);
196 return 0;
199 VclPtr<vcl::Window> AlignmentPropertyPanel::Create (
200 vcl::Window* pParent,
201 const css::uno::Reference<css::frame::XFrame>& rxFrame,
202 SfxBindings* pBindings)
204 if (pParent == NULL)
205 throw lang::IllegalArgumentException("no parent Window given to AlignmentPropertyPanel::Create", NULL, 0);
206 if ( ! rxFrame.is())
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)
218 (void)rEvent;
221 void AlignmentPropertyPanel::HandleContextChange(
222 const ::sfx2::sidebar::EnumContext& rContext)
224 if (maContext == rContext)
226 // Nothing to do.
227 return;
230 maContext = rContext;
233 void AlignmentPropertyPanel::NotifyItemUpdate(
234 sal_uInt16 nSID,
235 SfxItemState eState,
236 const SfxPoolItem* pState,
237 const bool bIsEnabled)
239 (void)bIsEnabled;
241 switch(nSID)
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();
257 else
259 mpFtRotate->Enable(!mbMultiDisable);
260 mpMtrAngle->Enable(!mbMultiDisable);
263 mpFTLeftIndent->Enable( meHorAlignState == SVX_HOR_JUSTIFY_LEFT );
264 mpMFLeftIndent->Enable( meHorAlignState == SVX_HOR_JUSTIFY_LEFT );
266 break;
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) );
274 else
276 mpMFLeftIndent->SetValue(0);
277 mpMFLeftIndent->SetText(OUString());
279 break;
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());
287 else
289 mpCBXMergeCell->Check(false);
290 mpCBXMergeCell->Disable();
292 break;
294 case SID_ATTR_ALIGN_LINEBREAK:
295 if(eState == SfxItemState::DISABLED)
297 mpCBXWrapText->EnableTriState(false);
298 mpCBXWrapText->Check(false);
299 mpCBXWrapText->Disable();
301 else
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);
316 break;
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
322 switch(nTmp)
324 case 0:
325 mpMtrAngle->SelectEntryPos(0);
326 break;
327 case 4500:
328 mpMtrAngle->SelectEntryPos(1);
329 break;
330 case 9000:
331 mpMtrAngle->SelectEntryPos(2);
332 break;
333 case 13500:
334 mpMtrAngle->SelectEntryPos(3);
335 break;
336 case 18000:
337 mpMtrAngle->SelectEntryPos(4);
338 break;
339 case 22500:
340 mpMtrAngle->SelectEntryPos(5);
341 break;
342 case 27000:
343 mpMtrAngle->SelectEntryPos(6);
344 break;
345 case 31500:
346 mpMtrAngle->SelectEntryPos(7);
349 else
351 mpMtrAngle->SetText( OUString() );
353 break;
357 void AlignmentPropertyPanel::FormatDegrees(double& dTmp)
359 while(dTmp<0)
360 dTmp += 360;
361 while (dTmp > 359) //modify
362 dTmp = 359;
365 // namespace close
367 }} // end of namespace ::sc::sidebar
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */