1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <sfx2/sidebar/ResourceDefinitions.hrc>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <sfx2/sidebar/ControlFactory.hxx>
25 #include <sfx2/sidebar/Layouter.hxx>
26 #include "PosSizePropertyPanel.hxx"
27 #include "PosSizePropertyPanel.hrc"
28 #include <svx/sidebar/SidebarDialControl.hxx>
29 #include <svx/dialogs.hrc>
30 #include <svx/dialmgr.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <sfx2/imagemgr.hxx>
36 #include <svx/dlgutil.hxx>
37 #include <unotools/viewoptions.hxx>
38 #include <vcl/virdev.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/field.hxx>
41 #include <vcl/fixed.hxx>
42 #include <vcl/toolbox.hxx>
43 #include <svx/svdview.hxx>
44 #include <svl/aeitem.hxx>
45 
46 using namespace css;
47 using namespace cssu;
48 using ::sfx2::sidebar::Layouter;
49 using ::sfx2::sidebar::Theme;
50 
51 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
52 #define USERITEM_NAME rtl::OUString::createFromAscii("FitItem")
53 #define NO_SELECT       (65535)
54 
55 
56 
57 namespace svx { namespace sidebar {
58 
59 
60 
PosSizePropertyPanel(Window * pParent,const cssu::Reference<css::frame::XFrame> & rxFrame,SfxBindings * pBindings,const cssu::Reference<css::ui::XSidebar> & rxSidebar)61 PosSizePropertyPanel::PosSizePropertyPanel(
62     Window* pParent,
63     const cssu::Reference<css::frame::XFrame>& rxFrame,
64     SfxBindings* pBindings,
65     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
66 :   Control(
67         pParent,
68         SVX_RES(RID_SIDEBAR_POSSIZE_PANEL)),
69     mpFtPosX(new FixedText(this, SVX_RES(FT_SBSHAPE_HORIZONTAL))),
70     mpMtrPosX(new MetricField(this, SVX_RES(MF_SBSHAPE_HORIZONTAL))),
71     mpFtPosY(new FixedText(this, SVX_RES(FT_SBSHAPE_VERTICAL))),
72     mpMtrPosY(new MetricField(this, SVX_RES(MF_SBSHAPE_VERTICAL))),
73     mpFtWidth(new FixedText(this, SVX_RES(FT_WIDTH))),
74     mpMtrWidth(new MetricField(this, SVX_RES(MTR_FLD_WIDTH))),
75     mpFtHeight(new FixedText(this, SVX_RES(FT_HEIGHT))),
76     mpMtrHeight(new MetricField(this, SVX_RES(MTR_FLD_HEIGHT))),
77     mpCbxScale(new CheckBox(this, SVX_RES(CBX_SCALE))),
78     mpFtAngle(new FixedText(this, SVX_RES(FT_ANGLE))),
79     mpMtrAngle(new MetricBox(this, SVX_RES(MTR_FLD_ANGLE))),
80     mpDial(new SidebarDialControl(this, SVX_RES(DIAL_CONTROL))),
81     mpFtFlip(new FixedText(this, SVX_RES(FT_FLIP))),
82     mpFlipTbxBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
83     mpFlipTbx(sfx2::sidebar::ControlFactory::CreateToolBox(mpFlipTbxBackground.get(), SVX_RES(TBX_FLIP))),
84     maRect(),
85     mpView(0),
86     mlOldWidth(1),
87     mlOldHeight(1),
88     meRP(RP_LT),
89     maAnchorPos(),
90     mlRotX(0),
91     mlRotY(0),
92     maUIScale(),
93     mePoolUnit(),
94     meDlgUnit(),
95     maTransfPosXControl(SID_ATTR_TRANSFORM_POS_X, *pBindings, *this),
96     maTransfPosYControl(SID_ATTR_TRANSFORM_POS_Y, *pBindings, *this),
97     maTransfWidthControl(SID_ATTR_TRANSFORM_WIDTH, *pBindings, *this),
98     maTransfHeightControl(SID_ATTR_TRANSFORM_HEIGHT, *pBindings, *this),
99     maSvxAngleControl( SID_ATTR_TRANSFORM_ANGLE, *pBindings, *this),
100     maRotXControl(SID_ATTR_TRANSFORM_ROT_X, *pBindings, *this),
101     maRotYControl(SID_ATTR_TRANSFORM_ROT_Y, *pBindings, *this),
102     maProPosControl(SID_ATTR_TRANSFORM_PROTECT_POS, *pBindings, *this),
103     maProSizeControl(SID_ATTR_TRANSFORM_PROTECT_SIZE, *pBindings, *this),
104     maAutoWidthControl(SID_ATTR_TRANSFORM_AUTOWIDTH, *pBindings, *this),
105     maAutoHeightControl(SID_ATTR_TRANSFORM_AUTOHEIGHT, *pBindings, *this),
106     m_aMetricCtl(SID_ATTR_METRIC, *pBindings, *this),
107     mxFrame(rxFrame),
108     maContext(),
109     mpBindings(pBindings),
110     maFtWidthOrigPos(mpFtWidth->GetPosPixel()),
111     maMtrWidthOrigPos(mpMtrWidth->GetPosPixel()),
112     maFtHeightOrigPos(mpFtHeight->GetPosPixel()),
113     maMtrHeightOrigPos(mpMtrHeight->GetPosPixel()),
114     maCbxScaleOrigPos(mpCbxScale->GetPosPixel()),
115     maFtAngleOrigPos(mpFtAngle->GetPosPixel()),
116     maMtrAnglOrigPos(mpMtrAngle->GetPosPixel()),
117     maFlipTbxOrigPos(mpFlipTbx->GetPosPixel()),
118     maDialOrigPos(mpDial->GetPosPixel()),
119     maFtFlipOrigPos(mpFtFlip->GetPosPixel()),
120     mbMtrPosXMirror(false),
121     mbSizeProtected(false),
122     mbPositionProtected(false),
123     mbAutoWidth(false),
124     mbAutoHeight(false),
125     mbAdjustEnabled(false),
126     mbIsFlip(false),
127     mxSidebar(rxSidebar),
128     maLayouter(*this)
129 {
130     Initialize();
131     FreeResource();
132 
133     mpBindings->Update( SID_ATTR_TRANSFORM_WIDTH );
134     mpBindings->Update( SID_ATTR_TRANSFORM_HEIGHT );
135     mpBindings->Update( SID_ATTR_TRANSFORM_PROTECT_SIZE );
136     mpBindings->Update( SID_ATTR_METRIC );
137 
138     // Setup the grid layouter.
139     const sal_Int32 nMappedMboxWidth (Layouter::MapWidth(*this, MBOX_WIDTH));
140 
141     maLayouter.GetCell(0,0).SetControl(*mpFtPosX);
142     maLayouter.GetCell(1,0).SetControl(*mpMtrPosX);
143 
144     maLayouter.GetCell(0,2).SetControl(*mpFtPosY);
145     maLayouter.GetCell(1,2).SetControl(*mpMtrPosY);
146 
147     maLayouter.GetCell(2,0).SetControl(*mpFtWidth);
148     maLayouter.GetCell(3,0).SetControl(*mpMtrWidth);
149 
150     maLayouter.GetCell(2,2).SetControl(*mpFtHeight);
151     maLayouter.GetCell(3,2).SetControl(*mpMtrHeight);
152 
153     maLayouter.GetCell(4,0).SetControl(*mpCbxScale).SetGridWidth(3);
154     maLayouter.GetCell(5,0).SetControl(*mpFtAngle).SetGridWidth(3);
155 
156 
157     maLayouter.GetColumn(0)
158         .SetWeight(1)
159         .SetLeftPadding(Layouter::MapWidth(*this,SECTIONPAGE_MARGIN_HORIZONTAL))
160         .SetMinimumWidth(nMappedMboxWidth);
161     maLayouter.GetColumn(1)
162         .SetWeight(0)
163         .SetMinimumWidth(Layouter::MapWidth(*this, CONTROL_SPACING_HORIZONTAL));
164     maLayouter.GetColumn(2)
165         .SetWeight(1)
166         .SetRightPadding(Layouter::MapWidth(*this,SECTIONPAGE_MARGIN_HORIZONTAL))
167         .SetMinimumWidth(nMappedMboxWidth);
168 
169     // Make controls that display text handle short widths more
170     // graceful.
171     Layouter::PrepareForLayouting(*mpFtPosX);
172     Layouter::PrepareForLayouting(*mpFtPosY);
173     Layouter::PrepareForLayouting(*mpFtWidth);
174     Layouter::PrepareForLayouting(*mpFtHeight);
175     Layouter::PrepareForLayouting(*mpCbxScale);
176     Layouter::PrepareForLayouting(*mpFtAngle);
177 
178 }
179 
180 
181 
~PosSizePropertyPanel()182 PosSizePropertyPanel::~PosSizePropertyPanel()
183 {
184     // Destroy the background windows of the toolboxes.
185     mpFlipTbx.reset();
186     mpFlipTbxBackground.reset();
187 }
188 
189 
190 
ShowMenu(void)191 void PosSizePropertyPanel::ShowMenu (void)
192 {
193     if (mpBindings != NULL)
194     {
195         SfxDispatcher* pDispatcher = mpBindings->GetDispatcher();
196         if (pDispatcher != NULL)
197             pDispatcher->Execute(SID_ATTR_TRANSFORM, SFX_CALLMODE_ASYNCHRON);
198     }
199 }
200 
201 
202 
203 namespace
204 {
hasText(const SdrView & rSdrView)205     bool hasText(const SdrView& rSdrView)
206     {
207         const SdrMarkList& rMarkList = rSdrView.GetMarkedObjectList();
208 
209         if(1 == rMarkList.GetMarkCount())
210         {
211             const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
212             const SdrObjKind eKind((SdrObjKind)pObj->GetObjIdentifier());
213 
214             if((pObj->GetObjInventor() == SdrInventor) && (OBJ_TEXT == eKind || OBJ_TITLETEXT == eKind || OBJ_OUTLINETEXT == eKind))
215             {
216                 const SdrTextObj* pSdrTextObj = dynamic_cast< const SdrTextObj* >(pObj);
217 
218                 if(pSdrTextObj && pSdrTextObj->HasText())
219                 {
220                     return true;
221                 }
222             }
223         }
224 
225         return false;
226     }
227 } // end of anonymous namespace
228 
229 
230 
231 
Resize(void)232 void PosSizePropertyPanel::Resize (void)
233 {
234     maLayouter.Layout();
235 }
236 
237 
238 
239 
Initialize()240 void PosSizePropertyPanel::Initialize()
241 {
242     mpFtPosX->SetBackground(Wallpaper());
243     mpFtPosY->SetBackground(Wallpaper());
244     mpFtWidth->SetBackground(Wallpaper());
245     mpFtHeight->SetBackground(Wallpaper());
246     mpFtAngle->SetBackground(Wallpaper());
247     mpFtFlip->SetBackground(Wallpaper());
248 
249         //Position : Horizontal / Vertical
250     mpMtrPosX->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangePosXHdl ) );
251     mpMtrPosY->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangePosYHdl ) );
252     mpMtrPosX->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Horizontal")));	//wj acc
253     mpMtrPosY->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Vertical")));		//wj acc
254 
255     //Size : Width / Height
256     mpMtrWidth->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangeWidthHdl ) );
257     mpMtrHeight->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangeHeightHdl ) );
258     mpMtrWidth->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width")));	//wj acc
259     mpMtrHeight->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height")));	//wj acc
260 
261     //Size : Keep ratio
262     mpCbxScale->SetClickHdl( LINK( this, PosSizePropertyPanel, ClickAutoHdl ) );
263 
264     //rotation:
265     mpMtrAngle->SetModifyHdl(LINK( this, PosSizePropertyPanel, AngleModifiedHdl));
266     mpMtrAngle->EnableAutocomplete( false );
267     mpMtrAngle->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Rotation")));	//wj acc
268 
269     //rotation control
270     mpDial->SetModifyHdl(LINK( this, PosSizePropertyPanel, RotationHdl));
271 
272     //flip:
273     mpFlipTbx->SetSelectHdl( LINK( this, PosSizePropertyPanel, FlipHdl) );
274     mpFlipTbx->SetItemImage(
275         FLIP_HORIZONTAL,
276         GetImage(mxFrame, A2S(".uno:FlipHorizontal"), sal_False, Theme::IsHighContrastMode()));
277     mpFlipTbx->SetItemImage(
278         FLIP_VERTICAL,
279         GetImage(mxFrame, A2S(".uno:FlipVertical"), sal_False, Theme::IsHighContrastMode()));
280     mpFlipTbx->SetQuickHelpText(FLIP_HORIZONTAL,String(SVX_RES(STR_QH_HORI_FLIP))); //Add
281     mpFlipTbx->SetQuickHelpText(FLIP_VERTICAL,String(SVX_RES(STR_QH_VERT_FLIP))); //Add
282 
283     mpMtrPosX->SetAccessibleRelationLabeledBy(mpFtPosX.get());
284     mpMtrPosY->SetAccessibleRelationLabeledBy(mpFtPosY.get());
285     mpMtrWidth->SetAccessibleRelationLabeledBy(mpFtWidth.get());
286     mpMtrHeight->SetAccessibleRelationLabeledBy(mpFtHeight.get());
287     mpMtrAngle->SetAccessibleRelationLabeledBy(mpFtAngle.get());
288 #ifdef HAS_IA2
289     mpMtrAngle->SetMpSubEditAccLableBy(mpFtAngle.get());
290 #endif
291     mpFlipTbx->SetAccessibleRelationLabeledBy(mpFtFlip.get());
292 
293     mpMtrAngle->InsertValue(0, FUNIT_CUSTOM);
294     mpMtrAngle->InsertValue(4500, FUNIT_CUSTOM);
295     mpMtrAngle->InsertValue(9000, FUNIT_CUSTOM);
296     mpMtrAngle->InsertValue(13500, FUNIT_CUSTOM);
297     mpMtrAngle->InsertValue(18000, FUNIT_CUSTOM);
298     mpMtrAngle->InsertValue(22500, FUNIT_CUSTOM);
299     mpMtrAngle->InsertValue(27000, FUNIT_CUSTOM);
300     mpMtrAngle->InsertValue(31500, FUNIT_CUSTOM);
301     mpMtrAngle->AdaptDropDownLineCountToMaximum();
302 
303     SfxViewShell* pCurSh = SfxViewShell::Current();
304     if ( pCurSh )
305         mpView = pCurSh->GetDrawView();
306     else
307         mpView = NULL;
308 
309     if ( mpView != NULL )
310     {
311         maUIScale = mpView->GetModel()->GetUIScale();
312         mbAdjustEnabled = hasText(*mpView);
313     }
314 
315     mePoolUnit = maTransfWidthControl.GetCoreMetric();
316     meDlgUnit = GetModuleFieldUnit();
317     SetFieldUnit( *mpMtrPosX, meDlgUnit, true );
318     SetFieldUnit( *mpMtrPosY, meDlgUnit, true );
319     SetFieldUnit( *mpMtrWidth, meDlgUnit, true );
320     SetFieldUnit( *mpMtrHeight, meDlgUnit, true );
321 }
322 
323 
324 
SetupIcons(void)325 void PosSizePropertyPanel::SetupIcons(void)
326 {
327     if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
328     {
329         // todo
330     }
331     else
332     {
333         // todo
334     }
335 }
336 
337 
338 
Create(Window * pParent,const cssu::Reference<css::frame::XFrame> & rxFrame,SfxBindings * pBindings,const cssu::Reference<css::ui::XSidebar> & rxSidebar)339 PosSizePropertyPanel* PosSizePropertyPanel::Create (
340     Window* pParent,
341     const cssu::Reference<css::frame::XFrame>& rxFrame,
342     SfxBindings* pBindings,
343     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
344 {
345     if (pParent == NULL)
346         throw lang::IllegalArgumentException(A2S("no parent Window given to PosSizePropertyPanel::Create"), NULL, 0);
347     if ( ! rxFrame.is())
348         throw lang::IllegalArgumentException(A2S("no XFrame given to PosSizePropertyPanel::Create"), NULL, 1);
349     if (pBindings == NULL)
350         throw lang::IllegalArgumentException(A2S("no SfxBindings given to PosSizePropertyPanel::Create"), NULL, 2);
351 
352     return new PosSizePropertyPanel(
353         pParent,
354         rxFrame,
355         pBindings,
356         rxSidebar);
357 }
358 
359 
360 
DataChanged(const DataChangedEvent & rEvent)361 void PosSizePropertyPanel::DataChanged(
362     const DataChangedEvent& rEvent)
363 {
364     (void)rEvent;
365 
366     SetupIcons();
367 }
368 
369 
370 
AdaptWidthHeightScalePosition(bool bOriginal)371 void PosSizePropertyPanel::AdaptWidthHeightScalePosition(bool bOriginal)
372 {
373     if(bOriginal)
374     {
375         mpFtWidth->SetPosPixel(maFtWidthOrigPos);
376         mpMtrWidth->SetPosPixel(maMtrWidthOrigPos);
377         mpFtHeight->SetPosPixel(maFtHeightOrigPos);
378         mpMtrHeight->SetPosPixel(maMtrHeightOrigPos);
379         mpCbxScale->SetPosPixel(maCbxScaleOrigPos);
380     }
381     else
382     {
383         mpFtWidth->SetPosPixel(Point(LogicToPixel(Point(FT_POSITION_X_X,FT_POSITION_X_Y), MAP_APPFONT)));
384         mpMtrWidth->SetPosPixel(Point(LogicToPixel(Point(MF_POSITION_X_X,MF_POSITION_X_Y), MAP_APPFONT)));
385         mpFtHeight->SetPosPixel(Point(LogicToPixel(Point(FT_POSITION_Y_X,FT_POSITION_Y_Y), MAP_APPFONT)));
386         mpMtrHeight->SetPosPixel(Point(LogicToPixel(Point(MF_POSITION_Y_X,MF_POSITION_Y_Y), MAP_APPFONT)));
387         mpCbxScale->SetPosPixel(Point(LogicToPixel(Point(FT_WIDTH_X,FT_WIDTH_Y), MAP_APPFONT)));
388     }
389 }
390 
AdaptAngleFlipDialPosition(bool bOriginal)391 void PosSizePropertyPanel::AdaptAngleFlipDialPosition(bool bOriginal)
392 {
393     if(bOriginal)
394     {
395         mpFtAngle->SetPosPixel(maFtAngleOrigPos);
396         mpMtrAngle->SetPosPixel(maMtrAnglOrigPos);
397         mpFlipTbx->SetPosPixel(maFlipTbxOrigPos);
398         mpDial->SetPosPixel(maDialOrigPos);
399         mpFtFlip->SetPosPixel(maFtFlipOrigPos);
400     }
401     else
402     {
403         mpFtAngle->SetPosPixel(Point(LogicToPixel(Point(FT_ANGLE_X,FT_ANGLE_Y), MAP_APPFONT)));
404         mpMtrAngle->SetPosPixel(Point(LogicToPixel(Point(MF_ANGLE_X2,MF_ANGLE_Y2), MAP_APPFONT)));
405         mpFlipTbx->SetPosPixel(Point(LogicToPixel(Point(FLIP_HORI_X2,FLIP_HORI_Y2), MAP_APPFONT)));
406         mpDial->SetPosPixel(Point(LogicToPixel(Point(ROTATE_CONTROL_X2,ROTATE_CONTROL_Y2), MAP_APPFONT)));
407         mpFtFlip->SetPosPixel(Point(LogicToPixel(Point(FT_FLIP_X2,FT_FLIP_Y2), MAP_APPFONT)));
408     }
409 }
410 
HandleContextChange(const::sfx2::sidebar::EnumContext aContext)411 void PosSizePropertyPanel::HandleContextChange(
412     const ::sfx2::sidebar::EnumContext aContext)
413 {
414     if(maContext == aContext)
415     {
416         // Nothing to do.
417         return;
418     }
419 
420     maContext = aContext;
421 
422     sal_Int32 nLayoutMode (0);
423     switch (maContext.GetCombinedContext_DI())
424     {
425         case CombinedEnumContext(Application_WriterVariants, Context_Draw):
426             nLayoutMode = 0;
427             break;
428 
429         case CombinedEnumContext(Application_WriterVariants, Context_Graphic):
430         case CombinedEnumContext(Application_WriterVariants, Context_Media):
431         case CombinedEnumContext(Application_WriterVariants, Context_Frame):
432         case CombinedEnumContext(Application_WriterVariants, Context_OLE):
433         case CombinedEnumContext(Application_WriterVariants, Context_Form):
434             nLayoutMode = 1;
435             break;
436 
437         case CombinedEnumContext(Application_Calc, Context_Draw):
438         case CombinedEnumContext(Application_Calc, Context_Graphic):
439         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
440         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
441         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
442             nLayoutMode = 2;
443             break;
444 
445         case CombinedEnumContext(Application_Calc, Context_Chart):
446         case CombinedEnumContext(Application_Calc, Context_Form):
447         case CombinedEnumContext(Application_Calc, Context_Media):
448         case CombinedEnumContext(Application_Calc, Context_OLE):
449         case CombinedEnumContext(Application_Calc, Context_MultiObject):
450         case CombinedEnumContext(Application_DrawImpress, Context_Media):
451         case CombinedEnumContext(Application_DrawImpress, Context_Form):
452         case CombinedEnumContext(Application_DrawImpress, Context_OLE):
453         case CombinedEnumContext(Application_DrawImpress, Context_3DObject):
454         case CombinedEnumContext(Application_DrawImpress, Context_MultiObject):
455             nLayoutMode = 3;
456             break;
457     }
458 
459     switch (nLayoutMode)
460     {
461         case 0:
462         {
463             mpMtrWidth->SetMin( 2 );
464             mpMtrHeight->SetMin( 2 );
465             mpFtPosX->Hide();
466             mpMtrPosX->Hide();
467             mpFtPosY->Hide();
468             mpMtrPosY->Hide();
469 
470             //rotation
471             mpFtAngle->Show();
472             mpMtrAngle->Show();
473             mpDial->Show();
474 
475             //flip
476             mpFtFlip->Show();
477             mpFlipTbx->Show();
478             Size aTbxSize = mpFlipTbx->CalcWindowSizePixel();
479             mpFlipTbx->SetOutputSizePixel( aTbxSize );
480             mbIsFlip = true;
481 
482             AdaptWidthHeightScalePosition(false);
483             AdaptAngleFlipDialPosition(false);
484 
485             mpFtAngle->SetPosPixel(Point(LogicToPixel(Point(FT_ANGLE_X,FT_ANGLE_Y), MAP_APPFONT)));
486             mpMtrAngle->SetPosPixel(Point(LogicToPixel(Point(MF_ANGLE_X2,MF_ANGLE_Y2), MAP_APPFONT)));
487             mpFlipTbx->SetPosPixel(Point(LogicToPixel(Point(FLIP_HORI_X2,FLIP_HORI_Y2), MAP_APPFONT)));
488             mpDial->SetPosPixel(Point(LogicToPixel(Point(ROTATE_CONTROL_X2,ROTATE_CONTROL_Y2), MAP_APPFONT)));
489             mpFtFlip->SetPosPixel(Point(LogicToPixel(Point(FT_FLIP_X2,FT_FLIP_Y2), MAP_APPFONT)));
490 
491             Size aSize(GetOutputSizePixel().Width(),PS_SECTIONPAGE_HEIGHT2);
492             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
493             SetSizePixel(aSize);
494             if (mxSidebar.is())
495                 mxSidebar->requestLayout();
496         }
497         break;
498 
499         case 1:
500         {
501             mpMtrWidth->SetMin( 2 );
502             mpMtrHeight->SetMin( 2 );
503             mpFtPosX->Hide();
504             mpMtrPosX->Hide();
505             mpFtPosY->Hide();
506             mpMtrPosY->Hide();
507 
508             //rotation
509             mpFtAngle->Hide();
510             mpMtrAngle->Hide();
511             mpDial->Hide();
512 
513             //flip
514             mpFlipTbx->Hide();
515             mpFtFlip->Hide();
516             mbIsFlip = false;
517 
518             AdaptWidthHeightScalePosition(false);
519             AdaptAngleFlipDialPosition(true);
520 
521             Size aSize(GetOutputSizePixel().Width(),PS_SECTIONPAGE_HEIGHT3);
522             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
523             SetSizePixel(aSize);
524             if (mxSidebar.is())
525                 mxSidebar->requestLayout();
526         }
527         break;
528 
529         case 2:
530         {
531             mpMtrWidth->SetMin( 1 );
532             mpMtrHeight->SetMin( 1 );
533             mpFtPosX->Show();
534             mpMtrPosX->Show();
535             mpFtPosY->Show();
536             mpMtrPosY->Show();
537 
538             //rotation
539             mpFtAngle->Show();
540             mpMtrAngle->Show();
541             mpDial->Show();
542 
543             //flip
544             mpFlipTbx->Show();
545             mpFtFlip->Show();
546             Size aTbxSize = mpFlipTbx->CalcWindowSizePixel();
547             mpFlipTbx->SetOutputSizePixel( aTbxSize );
548             mbIsFlip = true;
549 
550             AdaptWidthHeightScalePosition(true);
551             AdaptAngleFlipDialPosition(true);
552 
553             Size aSize(GetOutputSizePixel().Width(),PS_SECTIONPAGE_HEIGHT);
554             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
555             SetSizePixel(aSize);
556             if (mxSidebar.is())
557                 mxSidebar->requestLayout();
558         }
559         break;
560 
561         case 3:
562         {
563             mpMtrWidth->SetMin( 1 );
564             mpMtrHeight->SetMin( 1 );
565             mpFtPosX->Show();
566             mpMtrPosX->Show();
567             mpFtPosY->Show();
568             mpMtrPosY->Show();
569 
570             //rotation
571             mpFtAngle->Hide();
572             mpMtrAngle->Hide();
573             mpDial->Hide();
574 
575             //flip
576             mpFlipTbx->Hide();
577             mpFtFlip->Hide();
578             mbIsFlip = false;
579 
580             AdaptWidthHeightScalePosition(true);
581             AdaptAngleFlipDialPosition(true);
582 
583             Size aSize(GetOutputSizePixel().Width(),PS_SECTIONPAGE_HEIGHT4);
584             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
585             SetSizePixel(aSize);
586             if (mxSidebar.is())
587                 mxSidebar->requestLayout();
588         }
589         break;
590     }
591 
592     //Added for windows classic theme
593     mpFlipTbx->SetBackground(Wallpaper());
594     mpFlipTbx->SetPaintTransparent(true);
595 }
596 
597 
598 
599 IMPL_LINK( PosSizePropertyPanel, ChangeWidthHdl, void*, /*pBox*/ )
600 {
601     if( mpCbxScale->IsChecked() &&
602         mpCbxScale->IsEnabled() )
603     {
604         long nHeight = (long) ( ((double) mlOldHeight * (double) mpMtrWidth->GetValue()) / (double) mlOldWidth );
605         if( nHeight <= mpMtrHeight->GetMax( FUNIT_NONE ) )
606         {
607             mpMtrHeight->SetUserValue( nHeight, FUNIT_NONE );
608         }
609         else
610         {
611             nHeight = (long)mpMtrHeight->GetMax( FUNIT_NONE );
612             mpMtrHeight->SetUserValue( nHeight );
613             const long nWidth = (long) ( ((double) mlOldWidth * (double) nHeight) / (double) mlOldHeight );
614             mpMtrWidth->SetUserValue( nWidth, FUNIT_NONE );
615         }
616     }
617     executeSize();
618     return 0;
619 }
620 
621 
622 
IMPL_LINK(PosSizePropertyPanel,ChangeHeightHdl,void *,EMPTYARG)623 IMPL_LINK( PosSizePropertyPanel, ChangeHeightHdl, void *, EMPTYARG )
624 {
625     if( mpCbxScale->IsChecked() &&
626         mpCbxScale->IsEnabled() )
627     {
628         long nWidth = (long) ( ((double)mlOldWidth * (double)mpMtrHeight->GetValue()) / (double)mlOldHeight );
629         if( nWidth <= mpMtrWidth->GetMax( FUNIT_NONE ) )
630         {
631             mpMtrWidth->SetUserValue( nWidth, FUNIT_NONE );
632         }
633         else
634         {
635             nWidth = (long)mpMtrWidth->GetMax( FUNIT_NONE );
636             mpMtrWidth->SetUserValue( nWidth );
637             const long nHeight = (long) ( ((double)mlOldHeight * (double)nWidth) / (double)mlOldWidth );
638             mpMtrHeight->SetUserValue( nHeight, FUNIT_NONE );
639         }
640     }
641     executeSize();
642     return 0;
643 }
644 
645 
646 
IMPL_LINK(PosSizePropertyPanel,ChangePosXHdl,void *,EMPTYARG)647 IMPL_LINK( PosSizePropertyPanel, ChangePosXHdl, void *, EMPTYARG )
648 {
649     executePosX();
650     return 0;
651 }
652 
653 
654 
IMPL_LINK(PosSizePropertyPanel,ChangePosYHdl,void *,EMPTYARG)655 IMPL_LINK( PosSizePropertyPanel, ChangePosYHdl, void *, EMPTYARG )
656 {
657     executePosY();
658     return 0;
659 }
660 
661 
662 
IMPL_LINK(PosSizePropertyPanel,ClickAutoHdl,void *,EMPTYARG)663 IMPL_LINK( PosSizePropertyPanel, ClickAutoHdl, void *, EMPTYARG )
664 {
665     if ( mpCbxScale->IsChecked() )
666     {
667         mlOldWidth  = Max( GetCoreValue( *mpMtrWidth,  mePoolUnit ), 1L );
668         mlOldHeight = Max( GetCoreValue( *mpMtrHeight, mePoolUnit ), 1L );
669     }
670 
671     // mpCbxScale must synchronized with that on Position and Size tabpage on Shape Properties dialog
672     SvtViewOptions	aPageOpt( E_TABPAGE, String::CreateFromInt32( RID_SVXPAGE_POSITION_SIZE ) );
673     aPageOpt.SetUserItem( USERITEM_NAME, ::com::sun::star::uno::makeAny( ::rtl::OUString( String::CreateFromInt32( mpCbxScale->IsChecked() ) ) ) );
674 
675     return 0;
676 }
677 
678 
679 
IMPL_LINK(PosSizePropertyPanel,AngleModifiedHdl,void *,EMPTYARG)680 IMPL_LINK( PosSizePropertyPanel, AngleModifiedHdl, void *, EMPTYARG )
681 {
682     String sTmp = mpMtrAngle->GetText();
683     bool    bNegative = 0;
684     sal_Unicode nChar = sTmp.GetChar( 0 );
685 
686     if( nChar == '-' )
687     {
688         bNegative = 1;
689         nChar = sTmp.GetChar( 1 );
690     }
691 
692     if( (nChar < '0') || (nChar > '9') )
693         return 0;
694     double dTmp = sTmp.ToDouble();
695     if(bNegative)
696     {
697         while(dTmp<0)
698             dTmp += 360;
699     }
700     sal_Int64 nTmp = dTmp*100;
701 
702     // #123993# Need to take UIScale into account when executing rotations
703     const double fUIScale(mpView && mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
704     SfxInt32Item aAngleItem( SID_ATTR_TRANSFORM_ANGLE,(sal_uInt32) nTmp);
705     SfxInt32Item aRotXItem( SID_ATTR_TRANSFORM_ROT_X, basegfx::fround(mlRotX * fUIScale));
706     SfxInt32Item aRotYItem( SID_ATTR_TRANSFORM_ROT_Y, basegfx::fround(mlRotY * fUIScale));
707 
708     GetBindings()->GetDispatcher()->Execute(
709         SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aAngleItem, &aRotXItem, &aRotYItem, 0L );
710 
711     return 0;
712 }
713 
714 
715 
IMPL_LINK(PosSizePropertyPanel,RotationHdl,void *,EMPTYARG)716 IMPL_LINK( PosSizePropertyPanel, RotationHdl, void *, EMPTYARG )
717 {
718     sal_Int32 nTmp = mpDial->GetRotation();
719 
720     // #123993# Need to take UIScale into account when executing rotations
721     const double fUIScale(mpView && mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
722     SfxInt32Item aAngleItem( SID_ATTR_TRANSFORM_ANGLE,(sal_uInt32) nTmp);
723     SfxInt32Item aRotXItem( SID_ATTR_TRANSFORM_ROT_X, basegfx::fround(mlRotX * fUIScale));
724     SfxInt32Item aRotYItem( SID_ATTR_TRANSFORM_ROT_Y, basegfx::fround(mlRotY * fUIScale));
725 
726     GetBindings()->GetDispatcher()->Execute(
727         SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aAngleItem, &aRotXItem, &aRotYItem, 0L );
728 
729     return 0;
730 }
731 
732 
733 
IMPL_LINK(PosSizePropertyPanel,FlipHdl,ToolBox *,pBox)734 IMPL_LINK( PosSizePropertyPanel, FlipHdl, ToolBox*, pBox )
735 {
736     switch (pBox->GetCurItemId())
737     {
738         case FLIP_HORIZONTAL:
739         {
740             SfxVoidItem aHoriItem (SID_FLIP_HORIZONTAL);
741             GetBindings()->GetDispatcher()->Execute(
742                 SID_FLIP_HORIZONTAL, SFX_CALLMODE_RECORD, &aHoriItem, 0L );
743         }
744         break;
745         case FLIP_VERTICAL:
746         {
747             SfxVoidItem aVertItem (SID_FLIP_VERTICAL );
748             GetBindings()->GetDispatcher()->Execute(
749                 SID_FLIP_VERTICAL, SFX_CALLMODE_RECORD, &aVertItem, 0L );
750         }
751         break;
752     }
753     return 0;
754 }
755 
756 
757 
NotifyItemUpdate(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState,const bool)758 void PosSizePropertyPanel::NotifyItemUpdate(
759     sal_uInt16 nSID,
760     SfxItemState eState,
761     const SfxPoolItem* pState,
762     const bool /* bIsEnabled */)
763 {
764     mpFtAngle->Enable();
765     mpMtrAngle->Enable();
766     mpDial->Enable();
767     mpFtFlip->Enable();
768     mpFlipTbx->Enable();
769 
770     const SfxUInt32Item*	pWidthItem;
771     const SfxUInt32Item*	pHeightItem;
772 
773     SfxViewShell* pCurSh = SfxViewShell::Current();
774     if ( pCurSh )
775         mpView = pCurSh->GetDrawView();
776     else
777         mpView = NULL;
778 
779     if ( mpView == NULL )
780         return;
781 
782     mbAdjustEnabled = hasText(*mpView);
783 
784     // Pool unit and dialog unit may have changed, make sure that we
785     // have the current values.
786     mePoolUnit = maTransfWidthControl.GetCoreMetric();
787     meDlgUnit = GetModuleFieldUnit();
788 
789     switch (nSID)
790     {
791         case SID_ATTR_TRANSFORM_WIDTH:
792             if ( SFX_ITEM_AVAILABLE == eState )
793             {
794                 pWidthItem = dynamic_cast< const SfxUInt32Item* >(pState);
795 
796                 if(pWidthItem)
797                 {
798                     long mlOldWidth1 = pWidthItem->GetValue();
799 
800                     mlOldWidth1 = Fraction( mlOldWidth1 ) / maUIScale;
801                     SetFieldUnit( *mpMtrWidth, meDlgUnit, true );
802                     SetMetricValue( *mpMtrWidth, mlOldWidth1, mePoolUnit );
803                     mlOldWidth = mlOldWidth1;
804                     break;
805                 }
806             }
807 
808             mpMtrWidth->SetText( String());
809             break;
810 
811         case SID_ATTR_TRANSFORM_HEIGHT:
812             if ( SFX_ITEM_AVAILABLE == eState )
813             {
814                 pHeightItem = dynamic_cast< const SfxUInt32Item* >(pState);
815 
816                 if(pHeightItem)
817                 {
818                     long mlOldHeight1 = pHeightItem->GetValue();
819 
820                     mlOldHeight1 = Fraction( mlOldHeight1 ) / maUIScale;
821                     SetFieldUnit( *mpMtrHeight, meDlgUnit, true );
822                     SetMetricValue( *mpMtrHeight, mlOldHeight1, mePoolUnit );
823                     mlOldHeight = mlOldHeight1;
824                     break;
825                 }
826             }
827 
828             mpMtrHeight->SetText( String());
829             break;
830 
831         case SID_ATTR_TRANSFORM_POS_X:
832             if(SFX_ITEM_AVAILABLE == eState)
833             {
834                 const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
835 
836                 if(pItem)
837                 {
838                     long nTmp = pItem->GetValue();
839                     nTmp = Fraction( nTmp ) / maUIScale;
840                     SetFieldUnit( *mpMtrPosX, meDlgUnit, true );
841                     SetMetricValue( *mpMtrPosX, nTmp, mePoolUnit );
842                     break;
843                 }
844             }
845 
846             mpMtrPosX->SetText( String());
847             break;
848 
849         case SID_ATTR_TRANSFORM_POS_Y:
850             if(SFX_ITEM_AVAILABLE == eState)
851             {
852                 const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
853 
854                 if(pItem)
855                 {
856                     long nTmp = pItem->GetValue();
857                     nTmp = Fraction( nTmp ) / maUIScale;
858                     SetFieldUnit( *mpMtrPosY, meDlgUnit, true );
859                     SetMetricValue( *mpMtrPosY, nTmp, mePoolUnit );
860                     break;
861                 }
862             }
863 
864             mpMtrPosY->SetText( String());
865             break;
866 
867         case SID_ATTR_TRANSFORM_ROT_X:
868             if (SFX_ITEM_AVAILABLE == eState)
869             {
870                 const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
871 
872                 if(pItem)
873                 {
874                     mlRotX = pItem->GetValue();
875                     mlRotX = Fraction( mlRotX ) / maUIScale;
876                 }
877             }
878             break;
879 
880         case SID_ATTR_TRANSFORM_ROT_Y:
881             if (SFX_ITEM_AVAILABLE == eState)
882             {
883                 const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
884 
885                 if(pItem)
886                 {
887                     mlRotY = pItem->GetValue();
888                     mlRotY = Fraction( mlRotY ) / maUIScale;
889                 }
890             }
891             break;
892 
893         case SID_ATTR_TRANSFORM_PROTECT_POS:
894             if(SFX_ITEM_AVAILABLE == eState)
895             {
896                 const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
897 
898                 if(pItem)
899                 {
900                     // record the state of position protect
901                     mbPositionProtected = pItem->GetValue();
902                     break;
903                 }
904             }
905 
906             mbPositionProtected = false;
907             break;
908 
909         case SID_ATTR_TRANSFORM_PROTECT_SIZE:
910             if(SFX_ITEM_AVAILABLE == eState)
911             {
912                 const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
913 
914                 if(pItem)
915                 {
916                     // record the state of size protect
917                     mbSizeProtected = pItem->GetValue();
918                     break;
919                 }
920             }
921 
922             mbSizeProtected = false;
923             break;
924 
925         case SID_ATTR_TRANSFORM_AUTOWIDTH:
926             if(SFX_ITEM_AVAILABLE == eState)
927             {
928                 const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
929 
930                 if(pItem)
931                 {
932                     mbAutoWidth = pItem->GetValue();
933                 }
934             }
935             break;
936 
937         case SID_ATTR_TRANSFORM_AUTOHEIGHT:
938             if(SFX_ITEM_AVAILABLE == eState)
939             {
940                 const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
941 
942                 if(pItem)
943                 {
944                     mbAutoHeight = pItem->GetValue();
945                 }
946             }
947             break;
948 
949         case SID_ATTR_TRANSFORM_ANGLE:
950             if (eState >= SFX_ITEM_AVAILABLE)
951             {
952                 const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
953 
954                 if(pItem)
955                 {
956                     long nTmp = pItem->GetValue();
957 
958                     mpMtrAngle->SetValue( nTmp );
959                     mpDial->SetRotation( nTmp );
960 
961                     switch(nTmp)
962                     {
963                         case 0:
964                             mpMtrAngle->SelectEntryPos(0);
965                             break;
966                         case 4500:
967                             mpMtrAngle->SelectEntryPos(1);
968                             break;
969                         case 9000:
970                             mpMtrAngle->SelectEntryPos(2);
971                             break;
972                         case 13500:
973                             mpMtrAngle->SelectEntryPos(3);
974                             break;
975                         case 18000:
976                             mpMtrAngle->SelectEntryPos(4);
977                             break;
978                         case 22500:
979                             mpMtrAngle->SelectEntryPos(5);
980                             break;
981                         case 27000:
982                             mpMtrAngle->SelectEntryPos(6);
983                             break;
984                         case 315000:
985                             mpMtrAngle->SelectEntryPos(7);
986                             break;
987                     }
988 
989                     break;
990                 }
991             }
992 
993             mpMtrAngle->SetText( String() );
994             mpDial->SetRotation( 0 );
995             break;
996 
997         case SID_ATTR_METRIC:
998             MetricState( eState, pState );
999             UpdateUIScale();
1000             break;
1001 
1002         default:
1003             break;
1004     }
1005 
1006     const sal_Int32 nCombinedContext(maContext.GetCombinedContext_DI());
1007     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
1008 
1009     switch (rMarkList.GetMarkCount())
1010     {
1011         case 0:
1012             break;
1013 
1014         case 1:
1015         {
1016             const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
1017             const SdrObjKind eKind((SdrObjKind)pObj->GetObjIdentifier());
1018 
1019             if(((nCombinedContext == CombinedEnumContext(Application_DrawImpress, Context_Draw)
1020                || nCombinedContext == CombinedEnumContext(Application_DrawImpress, Context_TextObject)
1021                  ) && OBJ_EDGE == eKind)
1022                || OBJ_CAPTION == eKind)
1023             {
1024                 mpFtAngle->Disable();
1025                 mpMtrAngle->Disable();
1026                 mpDial->Disable();
1027                 mpFlipTbx->Disable();
1028                 mpFtFlip->Disable();
1029             }
1030             break;
1031         }
1032 
1033         default:
1034         {
1035             sal_uInt16 nMarkObj = 0;
1036             bool isNoEdge = true;
1037 
1038             while(isNoEdge && rMarkList.GetMark(nMarkObj))
1039             {
1040                 const SdrObject* pObj = rMarkList.GetMark(nMarkObj)->GetMarkedSdrObj();
1041                 const SdrObjKind eKind((SdrObjKind)pObj->GetObjIdentifier());
1042 
1043                 if(((nCombinedContext == CombinedEnumContext(Application_DrawImpress, Context_Draw)
1044                   || nCombinedContext == CombinedEnumContext(Application_DrawImpress, Context_TextObject)
1045                      ) && OBJ_EDGE == eKind)
1046                   || OBJ_CAPTION == eKind)
1047                 {
1048                     isNoEdge = false;
1049                     break;
1050                 }
1051                 nMarkObj++;
1052             }
1053 
1054             if(!isNoEdge)
1055             {
1056                 mpFtAngle->Disable();
1057                 mpMtrAngle->Disable();
1058                 mpDial->Disable();
1059                 mpFlipTbx->Disable();
1060                 mpFtFlip->Disable();
1061             }
1062             break;
1063         }
1064     }
1065 
1066     if(nCombinedContext == CombinedEnumContext(Application_DrawImpress, Context_TextObject))
1067     {
1068         mpFlipTbx->Disable();
1069         mpFtFlip->Disable();
1070     }
1071 
1072     DisableControls();
1073 
1074     // mpCbxScale must synchronized with that on Position and Size tabpage on Shape Properties dialog
1075     SvtViewOptions	aPageOpt( E_TABPAGE, String::CreateFromInt32( RID_SVXPAGE_POSITION_SIZE ) );
1076     String	sUserData;
1077     ::com::sun::star::uno::Any	aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
1078     ::rtl::OUString	aTemp;
1079     if ( aUserItem >>= aTemp )
1080         sUserData = String( aTemp );
1081     mpCbxScale->Check( (bool)sUserData.ToInt32() );
1082 }
1083 
1084 
1085 
1086 
GetBindings()1087 SfxBindings* PosSizePropertyPanel::GetBindings()
1088 {
1089     return mpBindings;
1090 }
1091 
1092 
1093 
executeSize()1094 void PosSizePropertyPanel::executeSize()
1095 {
1096     if ( mpMtrWidth->IsValueModified() || mpMtrHeight->IsValueModified())
1097     {
1098         Fraction aUIScale = mpView->GetModel()->GetUIScale();
1099 
1100         // get Width
1101         double nWidth = (double)mpMtrWidth->GetValue( meDlgUnit );
1102         nWidth = MetricField::ConvertDoubleValue( nWidth, mpMtrWidth->GetBaseValue(), mpMtrWidth->GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
1103         long lWidth = (long)(nWidth * (double)aUIScale);
1104         lWidth = OutputDevice::LogicToLogic( lWidth, MAP_100TH_MM, (MapUnit)mePoolUnit );
1105         lWidth = (long)mpMtrWidth->Denormalize( lWidth );
1106 
1107         // get Height
1108         double nHeight = (double)mpMtrHeight->GetValue( meDlgUnit );
1109         nHeight = MetricField::ConvertDoubleValue( nHeight, mpMtrHeight->GetBaseValue(), mpMtrHeight->GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
1110         long lHeight = (long)(nHeight * (double)aUIScale);
1111         lHeight = OutputDevice::LogicToLogic( lHeight, MAP_100TH_MM, (MapUnit)mePoolUnit );
1112         lHeight = (long)mpMtrWidth->Denormalize( lHeight );
1113 
1114         // put Width & Height to itemset
1115         SfxUInt32Item aWidthItem( SID_ATTR_TRANSFORM_WIDTH, (sal_uInt32) lWidth);
1116         SfxUInt32Item aHeightItem( SID_ATTR_TRANSFORM_HEIGHT, (sal_uInt32) lHeight);
1117         SfxAllEnumItem aPointItem (SID_ATTR_TRANSFORM_SIZE_POINT, (sal_uInt16)meRP);
1118         const sal_Int32 nCombinedContext(maContext.GetCombinedContext_DI());
1119 
1120         if( nCombinedContext == CombinedEnumContext(Application_WriterVariants, Context_Graphic)
1121             || nCombinedContext == CombinedEnumContext(Application_WriterVariants, Context_OLE)
1122             )
1123         {
1124             GetBindings()->GetDispatcher()->Execute(SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aWidthItem, &aHeightItem, &aPointItem, 0L );
1125         }
1126         else
1127         {
1128             if ( (mpMtrWidth->IsValueModified()) && (mpMtrHeight->IsValueModified()))
1129                 GetBindings()->GetDispatcher()->Execute(SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aWidthItem, &aHeightItem, &aPointItem, 0L );
1130             else if( mpMtrWidth->IsValueModified())
1131                 GetBindings()->GetDispatcher()->Execute(SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aWidthItem, &aPointItem, 0L );
1132             else if ( mpMtrHeight->IsValueModified())
1133                 GetBindings()->GetDispatcher()->Execute(SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aHeightItem, &aPointItem, 0L );
1134         }
1135     }
1136 }
1137 
1138 
1139 
executePosX()1140 void PosSizePropertyPanel::executePosX()
1141 {
1142     if ( mpMtrPosX->IsValueModified())
1143     {
1144         long lX = GetCoreValue( *mpMtrPosX, mePoolUnit );
1145         if( mbMtrPosXMirror )
1146             lX = -lX;
1147         long lY = GetCoreValue( *mpMtrPosY, mePoolUnit );
1148 
1149         Size aPageSize;
1150         Rectangle aRect;
1151         maRect = mpView->GetAllMarkedRect();
1152         aRect = mpView->GetAllMarkedRect();
1153 
1154         Fraction aUIScale = mpView->GetModel()->GetUIScale();
1155         lX += maAnchorPos.X();
1156         lX = Fraction( lX ) * aUIScale;
1157         lY += maAnchorPos.Y();
1158         lY = Fraction( lY ) * aUIScale;
1159 
1160         SfxInt32Item aPosXItem( SID_ATTR_TRANSFORM_POS_X,(sal_uInt32) lX);
1161         SfxInt32Item aPosYItem( SID_ATTR_TRANSFORM_POS_Y,(sal_uInt32) lY);
1162 
1163         GetBindings()->GetDispatcher()->Execute(
1164             SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aPosXItem, 0L );
1165     }
1166 }
1167 
1168 
1169 
executePosY()1170 void PosSizePropertyPanel::executePosY()
1171 {
1172     if ( mpMtrPosY->IsValueModified() )
1173     {
1174         long lX = GetCoreValue( *mpMtrPosX, mePoolUnit );
1175         long lY = GetCoreValue( *mpMtrPosY, mePoolUnit );
1176 
1177         Size aPageSize;
1178         Rectangle aRect;
1179         maRect = mpView->GetAllMarkedRect();
1180         aRect = mpView->GetAllMarkedRect();
1181 
1182         Fraction aUIScale = mpView->GetModel()->GetUIScale();
1183         lX += maAnchorPos.X();
1184         lX = Fraction( lX ) * aUIScale;
1185         lY += maAnchorPos.Y();
1186         lY = Fraction( lY ) * aUIScale;
1187 
1188         SfxInt32Item aPosXItem( SID_ATTR_TRANSFORM_POS_X,(sal_uInt32) lX);
1189         SfxInt32Item aPosYItem( SID_ATTR_TRANSFORM_POS_Y,(sal_uInt32) lY);
1190 
1191         GetBindings()->GetDispatcher()->Execute(
1192             SID_ATTR_TRANSFORM, SFX_CALLMODE_RECORD, &aPosYItem, 0L );
1193     }
1194 }
1195 
1196 
1197 
MetricState(SfxItemState eState,const SfxPoolItem * pState)1198 void PosSizePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState )
1199 {
1200     bool bPosXBlank = false;
1201     bool bPosYBlank = false;
1202     bool bWidthBlank = false;
1203     bool bHeightBlank = false;
1204     String sNull = String::CreateFromAscii("");
1205     meDlgUnit = GetCurrentUnit(eState,pState);
1206 
1207     if( mpMtrPosX->GetText() == sNull )
1208         bPosXBlank = true;
1209     SetFieldUnit( *mpMtrPosX, meDlgUnit, true );
1210     if(bPosXBlank)
1211         mpMtrPosX->SetText(String());
1212 
1213     if( mpMtrPosY->GetText() == sNull )
1214         bPosYBlank = true;
1215     SetFieldUnit( *mpMtrPosY, meDlgUnit, true );
1216     if(bPosYBlank)
1217         mpMtrPosY->SetText(String());
1218 
1219     if( mpMtrWidth->GetText() == sNull )
1220         bWidthBlank = true;
1221     SetFieldUnit( *mpMtrWidth, meDlgUnit, true );
1222     if(bWidthBlank)
1223         mpMtrWidth->SetText(String());
1224 
1225     if( mpMtrHeight->GetText() == sNull )
1226         bHeightBlank = true;
1227     SetFieldUnit( *mpMtrHeight, meDlgUnit, true );
1228     if(bHeightBlank)
1229         mpMtrHeight->SetText(String());
1230 }
1231 
1232 
1233 
GetCurrentUnit(SfxItemState eState,const SfxPoolItem * pState)1234 FieldUnit PosSizePropertyPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState )
1235 {
1236     FieldUnit eUnit = FUNIT_NONE;
1237 
1238     if ( pState && eState >= SFX_ITEM_DEFAULT )
1239     {
1240         eUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue();
1241     }
1242     else
1243     {
1244         SfxViewFrame* pFrame = SfxViewFrame::Current();
1245         SfxObjectShell* pSh = NULL;
1246         if ( pFrame )
1247             pSh = pFrame->GetObjectShell();
1248         if ( pSh )
1249         {
1250             SfxModule* pModule = pSh->GetModule();
1251             if ( pModule )
1252             {
1253                 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
1254                 if ( pItem )
1255                     eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
1256             }
1257             else
1258             {
1259                 DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
1260             }
1261         }
1262     }
1263 
1264     return eUnit;
1265 }
1266 
1267 
1268 
DisableControls()1269 void PosSizePropertyPanel::DisableControls()
1270 {
1271     if( mbPositionProtected )
1272     {
1273         // the position is protected("Position protect" option in modal dialog is checked),
1274         // disable all the Position controls in sidebar
1275         mpFtPosX->Disable();
1276         mpMtrPosX->Disable();
1277         mpFtPosY->Disable();
1278         mpMtrPosY->Disable();
1279         mpFtAngle->Disable();
1280         mpMtrAngle->Disable();
1281         mpDial->Disable();
1282         mpFtFlip->Disable();
1283         mpFlipTbx->Disable();
1284 
1285         mpFtWidth->Disable();
1286         mpMtrWidth->Disable();
1287         mpFtHeight->Disable();
1288         mpMtrHeight->Disable();
1289         mpCbxScale->Disable();
1290     }
1291     else
1292     {
1293         mpFtPosX->Enable();
1294         mpMtrPosX->Enable();
1295         mpFtPosY->Enable();
1296         mpMtrPosY->Enable();
1297 
1298         //mpFtAngle->Enable();
1299         //mpMtrAngle->Enable();
1300         //mpDial->Enable();
1301         //mpFtFlip->Enable();
1302         //mpFlipTbx->Enable();
1303 
1304         if( mbSizeProtected )
1305         {
1306             mpFtWidth->Disable();
1307             mpMtrWidth->Disable();
1308             mpFtHeight->Disable();
1309             mpMtrHeight->Disable();
1310             mpCbxScale->Disable();
1311         }
1312         else
1313         {
1314             if(	mbAdjustEnabled )
1315             {
1316                 if( mbAutoWidth )
1317                 {
1318                     mpFtWidth->Disable();
1319                     mpMtrWidth->Disable();
1320                     mpCbxScale->Disable();
1321                 }
1322                 else
1323                 {
1324                     mpFtWidth->Enable();
1325                     mpMtrWidth->Enable();
1326                 }
1327                 if( mbAutoHeight )
1328                 {
1329                     mpFtHeight->Disable();
1330                     mpMtrHeight->Disable();
1331                     mpCbxScale->Disable();
1332                 }
1333                 else
1334                 {
1335                     mpFtHeight->Enable();
1336                     mpMtrHeight->Enable();
1337                 }
1338                 if( !mbAutoWidth && !mbAutoHeight )
1339                     mpCbxScale->Enable();
1340             }
1341             else
1342             {
1343                 mpFtWidth->Enable();
1344                 mpMtrWidth->Enable();
1345                 mpFtHeight->Enable();
1346                 mpMtrHeight->Enable();
1347                 mpCbxScale->Enable();
1348             }
1349         }
1350     }
1351 }
1352 
1353 
1354 
1355 
UpdateUIScale(void)1356 void PosSizePropertyPanel::UpdateUIScale (void)
1357 {
1358     const Fraction aUIScale (mpView->GetModel()->GetUIScale());
1359     if (maUIScale != aUIScale)
1360     {
1361         // UI scale has changed.
1362 
1363         // Remember the new UI scale.
1364         maUIScale = aUIScale;
1365 
1366         // The content of the position and size boxes is only updated when item changes are notified.
1367         // Request such notifications without changing the actual item values.
1368         GetBindings()->Invalidate(SID_ATTR_TRANSFORM_POS_X, sal_True, sal_False);
1369         GetBindings()->Invalidate(SID_ATTR_TRANSFORM_POS_Y, sal_True, sal_False);
1370         GetBindings()->Invalidate(SID_ATTR_TRANSFORM_WIDTH, sal_True, sal_False);
1371         GetBindings()->Invalidate(SID_ATTR_TRANSFORM_HEIGHT, sal_True, sal_False);
1372     }
1373 }
1374 
1375 
1376 } } // end of namespace svx::sidebar
1377 
1378 // eof
1379