1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <tools/shl.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/module.hxx>
24 #include <swpossizetabpage.hxx>
25 #include <svx/dialogs.hrc>
27 #include <svx/svdattrx.hxx>
29 #include <dialmgr.hxx>
30 #include "svx/dlgutil.hxx"
31 #include "transfrm.hxx"
36 // define ----------------------------------------------------------------
40 #define AZ_VON_LINKS 2
41 #define AZ_HORIZONTAL 3
54 // static ----------------------------------------------------------------
56 static sal_uInt16 pCaptionRanges
[] =
59 SDRATTR_CAPTIONFIXEDANGLE
,
62 SDRATTR_CAPTIONESCDIR
,
63 SDRATTR_CAPTIONESCISREL
,
64 SDRATTR_CAPTIONESCREL
,
65 SDRATTR_CAPTIONESCABS
,
66 SDRATTR_CAPTIONLINELEN
,
67 SDRATTR_CAPTIONFITLINELEN
,
71 // -----------------------------------------------------------------------
73 SvxCaptionTabPage::SvxCaptionTabPage(Window
* pParent
, const SfxItemSet
& rInAttrs
)
74 : SfxTabPage( pParent
, CUI_RES( RID_SVXPAGE_CAPTION
), rInAttrs
),
76 aCT_CAPTTYPE( this, CUI_RES( CT_CAPTTYPE
) ),
77 aFT_ABSTAND( this, CUI_RES( FT_ABSTAND
) ),
78 aMF_ABSTAND( this, CUI_RES( MF_ABSTAND
) ),
79 aFT_WINKEL( this, CUI_RES( FT_WINKEL
) ),
80 aLB_WINKEL( this, CUI_RES( LB_WINKEL
) ),
81 aFT_ANSATZ( this, CUI_RES( FT_ANSATZ
) ),
82 aLB_ANSATZ( this, CUI_RES( LB_ANSATZ
) ),
83 aFT_UM( this, CUI_RES( FT_UM
) ),
84 aMF_ANSATZ( this, CUI_RES( MF_ANSATZ
) ),
85 aFT_ANSATZ_REL( this, CUI_RES( FT_ANSATZ_REL
) ),
86 aLB_ANSATZ_REL( this, CUI_RES( LB_ANSATZ_REL
) ),
87 aFT_LAENGE( this, CUI_RES( FT_LAENGE
) ),
88 aMF_LAENGE( this, CUI_RES( MF_LAENGE
) ),
89 aCB_LAENGE( this, CUI_RES( CB_LAENGE
) ),
91 aStrHorzList( CUI_RES(STR_HORZ_LIST
) ),
92 aStrVertList( CUI_RES(STR_VERT_LIST
) ),
94 rOutAttrs ( rInAttrs
)
96 //------------NYI-------------------------------------------
100 //------------correct positions-------------------------
101 aFT_ANSATZ_REL
.SetPosPixel( aFT_UM
.GetPosPixel() );
102 aLB_ANSATZ_REL
.SetPosPixel(
104 aFT_ANSATZ_REL
.GetPosPixel().X()+aFT_ANSATZ_REL
.GetSizePixel().Width()+6,
105 aLB_ANSATZ
.GetPosPixel().Y() )
108 aMF_ANSATZ
.SetPosPixel(
110 aFT_UM
.GetPosPixel().X()+aFT_UM
.GetSizePixel().Width()+6,
111 aLB_ANSATZ
.GetPosPixel().Y() )
115 for( nBitmap
= 0; nBitmap
< CAPTYPE_BITMAPS_COUNT
; nBitmap
++ )
116 mpBmpCapTypes
[nBitmap
] = new Image(Bitmap(CUI_RES(BMP_CAPTTYPE_1
+ nBitmap
)), COL_LIGHTMAGENTA
);
118 //------------install ValueSet--------------------------
119 aCT_CAPTTYPE
.SetStyle( aCT_CAPTTYPE
.GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
| WB_NAMEFIELD
);
120 aCT_CAPTTYPE
.SetColCount(5);//XXX
121 aCT_CAPTTYPE
.SetLineCount(1);
122 aCT_CAPTTYPE
.SetSelectHdl(LINK( this, SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
));
125 aCT_CAPTTYPE
.InsertItem(BMP_CAPTTYPE_1
, aImage
, String(CUI_RES(STR_CAPTTYPE_1
)));
126 aCT_CAPTTYPE
.InsertItem(BMP_CAPTTYPE_2
, aImage
, String(CUI_RES(STR_CAPTTYPE_2
)));
127 aCT_CAPTTYPE
.InsertItem(BMP_CAPTTYPE_3
, aImage
, String(CUI_RES(STR_CAPTTYPE_3
)));
131 aLB_ANSATZ
.SetSelectHdl(LINK(this,SvxCaptionTabPage
,AnsatzSelectHdl_Impl
));
132 aLB_ANSATZ_REL
.SetSelectHdl(LINK(this,SvxCaptionTabPage
,AnsatzRelSelectHdl_Impl
));
133 aCB_LAENGE
.SetClickHdl(LINK(this,SvxCaptionTabPage
,LineOptHdl_Impl
));
138 // -----------------------------------------------------------------------
140 SvxCaptionTabPage::~SvxCaptionTabPage()
143 for( nBitmap
= 0; nBitmap
< CAPTYPE_BITMAPS_COUNT
; nBitmap
++ )
144 delete mpBmpCapTypes
[nBitmap
];
147 // -----------------------------------------------------------------------
149 void SvxCaptionTabPage::Construct()
151 // set rectangle and working area
152 DBG_ASSERT( pView
, "Keine gueltige View Uebergeben!" );
155 // -----------------------------------------------------------------------
157 sal_Bool
SvxCaptionTabPage::FillItemSet( SfxItemSet
& _rOutAttrs
)
159 SfxItemPool
* pPool
= _rOutAttrs
.GetPool();
160 DBG_ASSERT( pPool
, "Wo ist der Pool" );
164 nCaptionType
= aCT_CAPTTYPE
.GetSelectItemId()-1;
166 _rOutAttrs
.Put( SdrCaptionTypeItem( (SdrCaptionType
) nCaptionType
) );
168 if( aMF_ABSTAND
.IsValueModified() )
170 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONGAP
) );
171 _rOutAttrs
.Put( SdrCaptionGapItem( GetCoreValue(aMF_ABSTAND
, eUnit
) ) );
174 // special treatment!!! XXX
175 if( nCaptionType
==SDRCAPT_TYPE1
)
179 case SDRCAPT_ESCHORIZONTAL
: nEscDir
=SDRCAPT_ESCVERTICAL
;break;
180 case SDRCAPT_ESCVERTICAL
: nEscDir
=SDRCAPT_ESCHORIZONTAL
;break;
184 _rOutAttrs
.Put( SdrCaptionEscDirItem( (SdrCaptionEscDir
)nEscDir
) );
186 bEscRel
= aLB_ANSATZ_REL
.IsVisible();
187 _rOutAttrs
.Put( SdrCaptionEscIsRelItem( bEscRel
) );
193 switch( aLB_ANSATZ_REL
.GetSelectEntryPos() )
195 case AT_OBEN
: nVal
=0;break;
196 case AT_MITTE
: nVal
=5000;break;
197 case AT_UNTEN
: nVal
=10000;break;
199 _rOutAttrs
.Put( SdrCaptionEscRelItem( nVal
) );
203 if( aMF_ANSATZ
.IsValueModified() )
205 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONESCABS
) );
206 _rOutAttrs
.Put( SdrCaptionEscAbsItem( GetCoreValue(aMF_ANSATZ
, eUnit
) ) );
210 bFitLineLen
= aCB_LAENGE
.IsChecked();
211 _rOutAttrs
.Put( SdrCaptionFitLineLenItem( bFitLineLen
) );
215 if( aMF_LAENGE
.IsValueModified() )
217 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONLINELEN
) );
218 _rOutAttrs
.Put( SdrCaptionLineLenItem( GetCoreValue(aMF_LAENGE
, eUnit
) ) );
222 //NYI-------------the angles have to be added here!!! XXX----------------------
227 // -----------------------------------------------------------------------
229 void SvxCaptionTabPage::Reset( const SfxItemSet
& )
232 //------------set metric-----------------------------
234 FieldUnit eFUnit
= GetModuleFieldUnit( rOutAttrs
);
243 default: ;//prevent warning
245 SetFieldUnit( aMF_ABSTAND
, eFUnit
);
246 SetFieldUnit( aMF_ANSATZ
, eFUnit
);
247 SetFieldUnit( aMF_LAENGE
, eFUnit
);
249 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
250 DBG_ASSERT( pPool
, "Wo ist der Pool" );
255 //------- angle ----------
256 nWhich
= GetWhich( SDRATTR_CAPTIONANGLE
);
257 nFixedAngle
= ( ( const SdrCaptionAngleItem
& ) rOutAttrs
.Get( nWhich
) ).GetValue();
259 nWhich
= GetWhich( SDRATTR_CAPTIONESCABS
);
260 eUnit
= pPool
->GetMetric( nWhich
);
261 nEscAbs
= ( ( const SdrCaptionEscAbsItem
& ) rOutAttrs
.Get( nWhich
) ).GetValue();
262 SetMetricValue( aMF_ANSATZ
, nEscAbs
, eUnit
);
263 nEscAbs
= static_cast<long>(aMF_ANSATZ
.GetValue());
265 nWhich
= GetWhich( SDRATTR_CAPTIONESCREL
);
266 nEscRel
= (long)( ( const SdrCaptionEscRelItem
& ) rOutAttrs
.Get( nWhich
) ).GetValue();
268 //------- line length ----------
269 nWhich
= GetWhich( SDRATTR_CAPTIONLINELEN
);
270 eUnit
= pPool
->GetMetric( nWhich
);
271 nLineLen
= ( ( const SdrCaptionLineLenItem
& ) rOutAttrs
.Get( nWhich
) ).GetValue();
272 SetMetricValue( aMF_LAENGE
, nLineLen
, eUnit
);
273 nLineLen
= static_cast<long>(aMF_LAENGE
.GetValue());
275 //------- distance to box ----------
276 nWhich
= GetWhich( SDRATTR_CAPTIONGAP
);
277 eUnit
= pPool
->GetMetric( nWhich
);
278 nGap
= ( ( const SdrCaptionGapItem
& ) rOutAttrs
.Get( nWhich
) ).GetValue();
279 SetMetricValue( aMF_ABSTAND
, nGap
, eUnit
);
280 nGap
= static_cast<long>(aMF_ABSTAND
.GetValue());
282 nCaptionType
= (short)( ( const SdrCaptionTypeItem
& ) rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONTYPE
) ) ).GetValue();
283 bFixedAngle
= ( ( const SfxBoolItem
& ) rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONFIXEDANGLE
) ) ).GetValue();
284 bFitLineLen
= ( ( const SfxBoolItem
& ) rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN
) ) ).GetValue();
285 nEscDir
= (short)( ( const SdrCaptionEscDirItem
& ) rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCDIR
) ) ).GetValue();
286 bEscRel
= ( ( const SfxBoolItem
& ) rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCISREL
) ) ).GetValue();
288 // special treatment!!! XXX
289 if( nCaptionType
==SDRCAPT_TYPE1
)
293 case SDRCAPT_ESCHORIZONTAL
: nEscDir
=SDRCAPT_ESCVERTICAL
;break;
294 case SDRCAPT_ESCVERTICAL
: nEscDir
=SDRCAPT_ESCHORIZONTAL
;break;
298 nAnsatzRelPos
=AT_MITTE
;
299 nAnsatzTypePos
=AZ_OPTIMAL
;
300 nWinkelTypePos
=WK_OPTIMAL
;
302 aMF_ABSTAND
.SetValue( nGap
);
304 if( nEscDir
== SDRCAPT_ESCHORIZONTAL
)
309 nAnsatzRelPos
= AT_OBEN
;
311 nAnsatzRelPos
= AT_UNTEN
;
312 nAnsatzTypePos
= AZ_HORIZONTAL
;
316 nAnsatzTypePos
= AZ_VON_OBEN
;
317 aMF_ANSATZ
.SetValue( nEscAbs
);
320 else if( nEscDir
== SDRCAPT_ESCVERTICAL
)
325 nAnsatzRelPos
= AT_OBEN
;
327 nAnsatzRelPos
= AT_UNTEN
;
328 nAnsatzTypePos
= AZ_VERTIKAL
;
332 nAnsatzTypePos
= AZ_VON_LINKS
;
333 aMF_ANSATZ
.SetValue( nEscAbs
);
336 else if( nEscDir
== SDRCAPT_ESCBESTFIT
)
338 nAnsatzTypePos
= AZ_OPTIMAL
;
343 if( nFixedAngle
<= 3000 )
344 nWinkelTypePos
=WK_30
;
345 else if( nFixedAngle
<= 4500 )
346 nWinkelTypePos
=WK_45
;
347 else if( nFixedAngle
<= 6000 )
348 nWinkelTypePos
=WK_60
;
350 nWinkelTypePos
=WK_90
;
353 aCB_LAENGE
.Check( bFitLineLen
);
354 aMF_LAENGE
.SetValue( nLineLen
);
356 aLB_ANSATZ
.SelectEntryPos( nAnsatzTypePos
);
357 aLB_WINKEL
.SelectEntryPos( nWinkelTypePos
);
359 SetupAnsatz_Impl( nAnsatzTypePos
);
360 aCT_CAPTTYPE
.SelectItem( nCaptionType
+1 ); // Enum starts at 0!
361 SetupType_Impl( nCaptionType
+1 );
364 // -----------------------------------------------------------------------
366 SfxTabPage
* SvxCaptionTabPage::Create( Window
* pWindow
,
367 const SfxItemSet
& rOutAttrs
)
369 return( new SvxCaptionTabPage( pWindow
, rOutAttrs
) );
372 //------------------------------------------------------------------------
374 sal_uInt16
* SvxCaptionTabPage::GetRanges()
376 return( pCaptionRanges
);
379 //------------------------------------------------------------------------
381 void SvxCaptionTabPage::SetupAnsatz_Impl( sal_uInt16 nType
)
383 xub_StrLen nCnt
=0, nIdx
=0;
388 // aMF_ANSATZ.Hide(); //XXX in case of OPTIMAL also absolute values are taken
392 aFT_ANSATZ_REL
.Hide();
393 aLB_ANSATZ_REL
.Hide();
394 nEscDir
= SDRCAPT_ESCBESTFIT
;
400 aFT_ANSATZ_REL
.Hide();
401 aLB_ANSATZ_REL
.Hide();
402 nEscDir
= SDRCAPT_ESCHORIZONTAL
;
408 aFT_ANSATZ_REL
.Hide();
409 aLB_ANSATZ_REL
.Hide();
410 nEscDir
= SDRCAPT_ESCVERTICAL
;
414 aLB_ANSATZ_REL
.Clear();
415 nCnt
= comphelper::string::getTokenCount(aStrHorzList
, ';');
416 for( nIdx
=0 ; nIdx
<nCnt
; nIdx
++ )
417 aLB_ANSATZ_REL
.InsertEntry( aStrHorzList
.GetToken(nIdx
) );
418 aLB_ANSATZ_REL
.SelectEntryPos( nAnsatzRelPos
);
422 aFT_ANSATZ_REL
.Show();
423 aLB_ANSATZ_REL
.Show();
424 nEscDir
= SDRCAPT_ESCHORIZONTAL
;
428 aLB_ANSATZ_REL
.Clear();
429 nCnt
= comphelper::string::getTokenCount(aStrVertList
, ';');
430 for( nIdx
=0 ; nIdx
<nCnt
; nIdx
++ )
431 aLB_ANSATZ_REL
.InsertEntry( aStrVertList
.GetToken(nIdx
) );
432 aLB_ANSATZ_REL
.SelectEntryPos( nAnsatzRelPos
);
436 aFT_ANSATZ_REL
.Show();
437 aLB_ANSATZ_REL
.Show();
438 nEscDir
= SDRCAPT_ESCVERTICAL
;
443 //------------------------------------------------------------------------
445 IMPL_LINK_INLINE_START( SvxCaptionTabPage
, AnsatzSelectHdl_Impl
, ListBox
*, pListBox
)
447 if( pListBox
== &aLB_ANSATZ
)
449 SetupAnsatz_Impl( aLB_ANSATZ
.GetSelectEntryPos() );
453 IMPL_LINK_INLINE_END( SvxCaptionTabPage
, AnsatzSelectHdl_Impl
, ListBox
*, pListBox
)
455 //------------------------------------------------------------------------
457 IMPL_LINK_INLINE_START( SvxCaptionTabPage
, AnsatzRelSelectHdl_Impl
, ListBox
*, pListBox
)
459 if( pListBox
== &aLB_ANSATZ_REL
)
461 nAnsatzRelPos
= aLB_ANSATZ_REL
.GetSelectEntryPos();
465 IMPL_LINK_INLINE_END( SvxCaptionTabPage
, AnsatzRelSelectHdl_Impl
, ListBox
*, pListBox
)
467 //------------------------------------------------------------------------
469 IMPL_LINK( SvxCaptionTabPage
, LineOptHdl_Impl
, Button
*, pButton
)
471 if( pButton
== &aCB_LAENGE
)
473 if( aCB_LAENGE
.IsChecked() || ! aCB_LAENGE
.IsEnabled() )
475 aFT_LAENGE
.Disable();
476 aMF_LAENGE
.Disable();
487 //------------------------------------------------------------------------
489 IMPL_LINK_NOARG_INLINE_START(SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
)
491 SetupType_Impl( aCT_CAPTTYPE
.GetSelectItemId() );
494 IMPL_LINK_NOARG_INLINE_END(SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
)
496 //------------------------------------------------------------------------
498 void SvxCaptionTabPage::SetupType_Impl( sal_uInt16 nType
)
503 aFT_WINKEL
.Disable();
504 aLB_WINKEL
.Disable();
505 aFT_LAENGE
.Disable();
506 aCB_LAENGE
.Disable();
507 LineOptHdl_Impl( &aCB_LAENGE
);
513 aFT_LAENGE
.Disable();
514 aCB_LAENGE
.Disable();
515 LineOptHdl_Impl( &aCB_LAENGE
);
523 LineOptHdl_Impl( &aCB_LAENGE
);
531 LineOptHdl_Impl( &aCB_LAENGE
);
536 // -----------------------------------------------------------------------
538 void SvxCaptionTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
540 SfxTabPage::DataChanged( rDCEvt
);
542 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
546 // -----------------------------------------------------------------------
548 void SvxCaptionTabPage::FillValueSet()
550 Image
** ppBitmaps
= mpBmpCapTypes
;
551 aCT_CAPTTYPE
.SetItemImage(BMP_CAPTTYPE_1
, *(ppBitmaps
[0]) );
552 aCT_CAPTTYPE
.SetItemImage(BMP_CAPTTYPE_2
, *(ppBitmaps
[1]) );
553 aCT_CAPTTYPE
.SetItemImage(BMP_CAPTTYPE_3
, *(ppBitmaps
[2]) );
556 //========================================================================
559 SvxCaptionTabDialog::SvxCaptionTabDialog(Window
* pParent
, const SdrView
* pSdrView
, sal_uInt16 nAnchorTypes
)
560 : SfxTabDialog( pParent
, CUI_RES( RID_SVXDLG_CAPTION
) ),
562 nAnchorCtrls(nAnchorTypes
)
566 DBG_ASSERT( pView
, "Keine gueltige View Uebergeben!" );
568 //different positioning page in Writer
569 if(nAnchorCtrls
& 0x00ff )
571 AddTabPage( RID_SVXPAGE_SWPOSSIZE
, SvxSwPosSizeTabPage::Create
,
572 SvxSwPosSizeTabPage::GetRanges
);
573 RemoveTabPage( RID_SVXPAGE_POSITION_SIZE
);
577 AddTabPage( RID_SVXPAGE_POSITION_SIZE
, SvxPositionSizeTabPage::Create
,
578 SvxPositionSizeTabPage::GetRanges
);
579 RemoveTabPage( RID_SVXPAGE_SWPOSSIZE
);
581 AddTabPage( RID_SVXPAGE_CAPTION
, SvxCaptionTabPage::Create
,
582 SvxCaptionTabPage::GetRanges
);
585 // -----------------------------------------------------------------------
587 SvxCaptionTabDialog::~SvxCaptionTabDialog()
591 // -----------------------------------------------------------------------
593 void SvxCaptionTabDialog::PageCreated( sal_uInt16 nId
, SfxTabPage
&rPage
)
597 case RID_SVXPAGE_POSITION_SIZE
:
598 ( (SvxPositionSizeTabPage
&) rPage
).SetView( pView
);
599 ( (SvxPositionSizeTabPage
&) rPage
).Construct();
600 if( nAnchorCtrls
& SVX_OBJ_NORESIZE
)
601 ( (SvxPositionSizeTabPage
&) rPage
).DisableResize();
603 if( nAnchorCtrls
& SVX_OBJ_NOPROTECT
)
604 ( (SvxPositionSizeTabPage
&) rPage
).DisableProtect();
606 case RID_SVXPAGE_SWPOSSIZE
:
608 SvxSwPosSizeTabPage
& rSwPage
= static_cast<SvxSwPosSizeTabPage
&>(rPage
);
609 rSwPage
.EnableAnchorTypes(nAnchorCtrls
);
610 rSwPage
.SetValidateFramePosLink( aValidateLink
);
614 case RID_SVXPAGE_CAPTION
:
615 ( (SvxCaptionTabPage
&) rPage
).SetView( pView
);
616 ( (SvxCaptionTabPage
&) rPage
).Construct();
621 void SvxCaptionTabDialog::SetValidateFramePosLink( const Link
& rLink
)
623 aValidateLink
= rLink
;
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */