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