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>
22 #include <dialmgr.hxx>
23 #include <sfx2/app.hxx>
24 #include <sfx2/module.hxx>
25 #include <swpossizetabpage.hxx>
26 #include <vcl/settings.hxx>
28 #include <svx/dialogs.hrc>
29 #include <svx/svddef.hxx>
30 #include <svx/sxcaitm.hxx>
31 #include <svx/sxcecitm.hxx>
32 #include <svx/sxcgitm.hxx>
33 #include <svx/sxcllitm.hxx>
34 #include <svx/sxctitm.hxx>
36 #include "svx/dlgutil.hxx"
38 #include "transfrm.hxx"
40 // define ----------------------------------------------------------------
44 #define AZ_VON_LINKS 2
45 #define AZ_HORIZONTAL 3
52 #define BMP_CAPTTYPE_1 1
53 #define BMP_CAPTTYPE_2 2
54 #define BMP_CAPTTYPE_3 3
56 // static ----------------------------------------------------------------
58 const sal_uInt16
SvxCaptionTabPage::pCaptionRanges
[] =
61 SDRATTR_CAPTIONFIXEDANGLE
,
64 SDRATTR_CAPTIONESCDIR
,
65 SDRATTR_CAPTIONESCISREL
,
66 SDRATTR_CAPTIONESCREL
,
67 SDRATTR_CAPTIONESCABS
,
68 SDRATTR_CAPTIONLINELEN
,
69 SDRATTR_CAPTIONFITLINELEN
,
73 SvxCaptionTabPage::SvxCaptionTabPage(vcl::Window
* pParent
, const SfxItemSet
& rInAttrs
)
74 : SfxTabPage(pParent
, "CalloutPage", "cui/ui/calloutpage.ui", &rInAttrs
)
88 get(m_pCT_CAPTTYPE
, "valueset");
90 Size
aSize(m_pCT_CAPTTYPE
->LogicToPixel(Size(187, 38), MAP_APPFONT
));
91 m_pCT_CAPTTYPE
->set_width_request(aSize
.Width());
92 m_pCT_CAPTTYPE
->set_height_request(aSize
.Height());
94 get(m_pMF_ABSTAND
, "spacing");
95 get(m_pLB_ANSATZ
, "extension");
96 get(m_pFT_UM
, "byft");
97 get(m_pMF_ANSATZ
, "by");
98 get(m_pFT_ANSATZ_REL
, "positionft");
99 get(m_pLB_ANSATZ_REL
, "position");
101 assert(m_pLB_ANSATZ_REL
->GetEntryCount() == 6);
102 for (int i
= 0; i
< 3; ++i
)
103 m_aStrHorzList
.push_back(m_pLB_ANSATZ_REL
->GetEntry(i
));
104 for (int i
= 3; i
< 6; ++i
)
105 m_aStrVertList
.push_back(m_pLB_ANSATZ_REL
->GetEntry(i
));
106 m_pLB_ANSATZ_REL
->Clear();
108 ListBox
*pLineTypes
= get
<ListBox
>("linetypes");
109 assert(pLineTypes
->GetEntryCount() == 3);
110 for (int i
= 0; i
< 3; ++i
)
111 m_aLineTypes
.push_back(pLineTypes
->GetEntry(i
));
113 get(m_pFT_LAENGE
, "lengthft");
114 get(m_pMF_LAENGE
, "length");
115 get(m_pCB_LAENGE
, "optimal");
117 for(sal_uInt16 nBitmap
= 0; nBitmap
< CAPTYPE_BITMAPS_COUNT
; ++nBitmap
)
119 FixedImage
*pImage
= get
<FixedImage
>(OString("legtyp") + OString::number(nBitmap
+1));
120 m_aBmpCapTypes
[nBitmap
] = pImage
->GetImage();
123 //------------install ValueSet--------------------------
124 m_pCT_CAPTTYPE
->SetStyle( m_pCT_CAPTTYPE
->GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
| WB_NAMEFIELD
);
125 m_pCT_CAPTTYPE
->SetColCount(5);//XXX
126 m_pCT_CAPTTYPE
->SetLineCount(1);
127 m_pCT_CAPTTYPE
->SetSelectHdl(LINK( this, SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
));
130 m_pCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_1
, aImage
, m_aLineTypes
[0]);
131 m_pCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_2
, aImage
, m_aLineTypes
[1]);
132 m_pCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_3
, aImage
, m_aLineTypes
[2]);
136 m_pLB_ANSATZ
->SetSelectHdl(LINK(this,SvxCaptionTabPage
,AnsatzSelectHdl_Impl
));
137 m_pLB_ANSATZ_REL
->SetSelectHdl(LINK(this,SvxCaptionTabPage
,AnsatzRelSelectHdl_Impl
));
138 m_pCB_LAENGE
->SetClickHdl(LINK(this,SvxCaptionTabPage
,LineOptHdl_Impl
));
141 SvxCaptionTabPage::~SvxCaptionTabPage()
146 void SvxCaptionTabPage::dispose()
148 m_pCT_CAPTTYPE
.clear();
149 m_pMF_ABSTAND
.clear();
150 m_pLB_ANSATZ
.clear();
152 m_pMF_ANSATZ
.clear();
153 m_pFT_ANSATZ_REL
.clear();
154 m_pLB_ANSATZ_REL
.clear();
155 m_pFT_LAENGE
.clear();
156 m_pMF_LAENGE
.clear();
157 m_pCB_LAENGE
.clear();
158 SfxTabPage::dispose();
161 void SvxCaptionTabPage::Construct()
163 // set rectangle and working area
164 DBG_ASSERT( pView
, "Keine gueltige View Uebergeben!" );
169 bool SvxCaptionTabPage::FillItemSet( SfxItemSet
* _rOutAttrs
)
171 SfxItemPool
* pPool
= _rOutAttrs
->GetPool();
172 DBG_ASSERT( pPool
, "Wo ist der Pool" );
176 nCaptionType
= m_pCT_CAPTTYPE
->GetSelectItemId()-1;
178 _rOutAttrs
->Put( SdrCaptionTypeItem( (SdrCaptionType
) nCaptionType
) );
180 if( m_pMF_ABSTAND
->IsValueModified() )
182 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONGAP
) );
183 _rOutAttrs
->Put( SdrCaptionGapItem( GetCoreValue(*m_pMF_ABSTAND
, eUnit
) ) );
186 // special treatment!!! XXX
187 if( nCaptionType
==SDRCAPT_TYPE1
)
191 case SDRCAPT_ESCHORIZONTAL
: nEscDir
=SDRCAPT_ESCVERTICAL
;break;
192 case SDRCAPT_ESCVERTICAL
: nEscDir
=SDRCAPT_ESCHORIZONTAL
;break;
196 _rOutAttrs
->Put( SdrCaptionEscDirItem( (SdrCaptionEscDir
)nEscDir
) );
198 bEscRel
= m_pLB_ANSATZ_REL
->IsVisible();
199 _rOutAttrs
->Put( SdrCaptionEscIsRelItem( bEscRel
) );
205 switch( m_pLB_ANSATZ_REL
->GetSelectEntryPos() )
207 case AT_OBEN
: nVal
=0;break;
208 case AT_MITTE
: nVal
=5000;break;
209 case AT_UNTEN
: nVal
=10000;break;
211 _rOutAttrs
->Put( SdrCaptionEscRelItem( nVal
) );
215 if( m_pMF_ANSATZ
->IsValueModified() )
217 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONESCABS
) );
218 _rOutAttrs
->Put( SdrCaptionEscAbsItem( GetCoreValue(*m_pMF_ANSATZ
, eUnit
) ) );
222 bFitLineLen
= m_pCB_LAENGE
->IsChecked();
223 _rOutAttrs
->Put( SdrCaptionFitLineLenItem( bFitLineLen
) );
227 if( m_pMF_LAENGE
->IsValueModified() )
229 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONLINELEN
) );
230 _rOutAttrs
->Put( SdrCaptionLineLenItem( GetCoreValue(*m_pMF_LAENGE
, eUnit
) ) );
234 //NYI-------------the angles have to be added here!!! XXX----------------------
241 void SvxCaptionTabPage::Reset( const SfxItemSet
* )
244 //------------set metric-----------------------------
246 FieldUnit eFUnit
= GetModuleFieldUnit( rOutAttrs
);
255 default: ;//prevent warning
257 SetFieldUnit( *m_pMF_ABSTAND
, eFUnit
);
258 SetFieldUnit( *m_pMF_ANSATZ
, eFUnit
);
259 SetFieldUnit( *m_pMF_LAENGE
, eFUnit
);
261 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
262 DBG_ASSERT( pPool
, "Wo ist der Pool" );
267 nWhich
= GetWhich( SDRATTR_CAPTIONESCABS
);
268 eUnit
= pPool
->GetMetric( nWhich
);
269 nEscAbs
= static_cast<const SdrCaptionEscAbsItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
270 SetMetricValue( *m_pMF_ANSATZ
, nEscAbs
, eUnit
);
271 nEscAbs
= static_cast<long>(m_pMF_ANSATZ
->GetValue());
273 nWhich
= GetWhich( SDRATTR_CAPTIONESCREL
);
274 nEscRel
= (long)static_cast<const SdrCaptionEscRelItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
276 //------- line length ----------
277 nWhich
= GetWhich( SDRATTR_CAPTIONLINELEN
);
278 eUnit
= pPool
->GetMetric( nWhich
);
279 nLineLen
= static_cast<const SdrCaptionLineLenItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
280 SetMetricValue( *m_pMF_LAENGE
, nLineLen
, eUnit
);
281 nLineLen
= static_cast<long>(m_pMF_LAENGE
->GetValue());
283 //------- distance to box ----------
284 nWhich
= GetWhich( SDRATTR_CAPTIONGAP
);
285 eUnit
= pPool
->GetMetric( nWhich
);
286 nGap
= static_cast<const SdrCaptionGapItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
287 SetMetricValue( *m_pMF_ABSTAND
, nGap
, eUnit
);
288 nGap
= static_cast<long>(m_pMF_ABSTAND
->GetValue());
290 nCaptionType
= (short)static_cast<const SdrCaptionTypeItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONTYPE
) ) ).GetValue();
291 bFitLineLen
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN
) ) ).GetValue();
292 nEscDir
= (short)static_cast<const SdrCaptionEscDirItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCDIR
) ) ).GetValue();
293 bEscRel
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCISREL
) ) ).GetValue();
295 // special treatment!!! XXX
296 if( nCaptionType
==SDRCAPT_TYPE1
)
300 case SDRCAPT_ESCHORIZONTAL
: nEscDir
=SDRCAPT_ESCVERTICAL
;break;
301 case SDRCAPT_ESCVERTICAL
: nEscDir
=SDRCAPT_ESCHORIZONTAL
;break;
305 nAnsatzRelPos
=AT_MITTE
;
306 nAnsatzTypePos
=AZ_OPTIMAL
;
308 m_pMF_ABSTAND
->SetValue( nGap
);
310 if( nEscDir
== SDRCAPT_ESCHORIZONTAL
)
315 nAnsatzRelPos
= AT_OBEN
;
317 nAnsatzRelPos
= AT_UNTEN
;
318 nAnsatzTypePos
= AZ_HORIZONTAL
;
322 nAnsatzTypePos
= AZ_VON_OBEN
;
323 m_pMF_ANSATZ
->SetValue( nEscAbs
);
326 else if( nEscDir
== SDRCAPT_ESCVERTICAL
)
331 nAnsatzRelPos
= AT_OBEN
;
333 nAnsatzRelPos
= AT_UNTEN
;
334 nAnsatzTypePos
= AZ_VERTIKAL
;
338 nAnsatzTypePos
= AZ_VON_LINKS
;
339 m_pMF_ANSATZ
->SetValue( nEscAbs
);
342 else if( nEscDir
== SDRCAPT_ESCBESTFIT
)
344 nAnsatzTypePos
= AZ_OPTIMAL
;
347 m_pCB_LAENGE
->Check( bFitLineLen
);
348 m_pMF_LAENGE
->SetValue( nLineLen
);
350 m_pLB_ANSATZ
->SelectEntryPos( nAnsatzTypePos
);
352 SetupAnsatz_Impl( nAnsatzTypePos
);
353 m_pCT_CAPTTYPE
->SelectItem( nCaptionType
+1 ); // Enum starts at 0!
354 SetupType_Impl( nCaptionType
+1 );
359 VclPtr
<SfxTabPage
> SvxCaptionTabPage::Create( vcl::Window
* pWindow
,
360 const SfxItemSet
* rOutAttrs
)
362 return VclPtr
<SvxCaptionTabPage
>::Create( pWindow
, *rOutAttrs
);
367 void SvxCaptionTabPage::SetupAnsatz_Impl( sal_uInt16 nType
)
372 m_pMF_ANSATZ
->Show();
374 m_pFT_ANSATZ_REL
->Hide();
375 m_pLB_ANSATZ_REL
->Hide();
376 nEscDir
= SDRCAPT_ESCBESTFIT
;
380 m_pMF_ANSATZ
->Show();
382 m_pFT_ANSATZ_REL
->Hide();
383 m_pLB_ANSATZ_REL
->Hide();
384 nEscDir
= SDRCAPT_ESCHORIZONTAL
;
388 m_pMF_ANSATZ
->Show();
390 m_pFT_ANSATZ_REL
->Hide();
391 m_pLB_ANSATZ_REL
->Hide();
392 nEscDir
= SDRCAPT_ESCVERTICAL
;
396 m_pLB_ANSATZ_REL
->Clear();
397 for (size_t i
= 0 ; i
< m_aStrHorzList
.size(); ++i
)
398 m_pLB_ANSATZ_REL
->InsertEntry(m_aStrHorzList
[i
]);
399 m_pLB_ANSATZ_REL
->SelectEntryPos(nAnsatzRelPos
);
401 m_pMF_ANSATZ
->Hide();
403 m_pFT_ANSATZ_REL
->Show();
404 m_pLB_ANSATZ_REL
->Show();
405 nEscDir
= SDRCAPT_ESCHORIZONTAL
;
409 m_pLB_ANSATZ_REL
->Clear();
410 for (size_t i
= 0 ; i
< m_aStrVertList
.size(); ++i
)
411 m_pLB_ANSATZ_REL
->InsertEntry(m_aStrVertList
[i
]);
412 m_pLB_ANSATZ_REL
->SelectEntryPos(nAnsatzRelPos
);
414 m_pMF_ANSATZ
->Hide();
416 m_pFT_ANSATZ_REL
->Show();
417 m_pLB_ANSATZ_REL
->Show();
418 nEscDir
= SDRCAPT_ESCVERTICAL
;
425 IMPL_LINK( SvxCaptionTabPage
, AnsatzSelectHdl_Impl
, ListBox
*, pListBox
)
427 if (pListBox
== m_pLB_ANSATZ
)
429 SetupAnsatz_Impl( m_pLB_ANSATZ
->GetSelectEntryPos() );
434 IMPL_LINK( SvxCaptionTabPage
, AnsatzRelSelectHdl_Impl
, ListBox
*, pListBox
)
436 if (pListBox
== m_pLB_ANSATZ_REL
)
438 nAnsatzRelPos
= m_pLB_ANSATZ_REL
->GetSelectEntryPos();
443 IMPL_LINK( SvxCaptionTabPage
, LineOptHdl_Impl
, Button
*, pButton
)
445 if (pButton
== m_pCB_LAENGE
)
447 if( m_pCB_LAENGE
->IsChecked() || ! m_pCB_LAENGE
->IsEnabled() )
449 m_pFT_LAENGE
->Disable();
450 m_pMF_LAENGE
->Disable();
454 m_pFT_LAENGE
->Enable();
455 m_pMF_LAENGE
->Enable();
463 IMPL_LINK_NOARG(SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
)
465 SetupType_Impl( m_pCT_CAPTTYPE
->GetSelectItemId() );
469 void SvxCaptionTabPage::SetupType_Impl( sal_uInt16 nType
)
474 m_pFT_LAENGE
->Disable();
475 m_pCB_LAENGE
->Disable();
476 LineOptHdl_Impl( m_pCB_LAENGE
);
480 m_pFT_LAENGE
->Disable();
481 m_pCB_LAENGE
->Disable();
482 LineOptHdl_Impl( m_pCB_LAENGE
);
486 m_pFT_LAENGE
->Enable();
487 m_pCB_LAENGE
->Enable();
488 LineOptHdl_Impl( m_pCB_LAENGE
);
492 m_pFT_LAENGE
->Enable();
493 m_pCB_LAENGE
->Enable();
494 LineOptHdl_Impl( m_pCB_LAENGE
);
501 void SvxCaptionTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
503 SfxTabPage::DataChanged( rDCEvt
);
505 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) && (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
511 void SvxCaptionTabPage::FillValueSet()
513 m_pCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_1
, m_aBmpCapTypes
[0] );
514 m_pCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_2
, m_aBmpCapTypes
[1] );
515 m_pCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_3
, m_aBmpCapTypes
[2] );
521 SvxCaptionTabDialog::SvxCaptionTabDialog(vcl::Window
* pParent
, const SdrView
* pSdrView
,
522 sal_uInt16 nAnchorTypes
)
523 : SfxTabDialog( pParent
, "CalloutDialog", "cui/ui/calloutdialog.ui")
525 , nAnchorCtrls(nAnchorTypes
)
526 , m_nSwPosSizePageId(0)
527 , m_nPositionSizePageId(0)
528 , m_nCaptionPageId(0)
530 assert(pView
); //Keine gueltige View Uebergeben!
532 //different positioning page in Writer
533 if (nAnchorCtrls
& 0x00ff)
535 m_nSwPosSizePageId
= AddTabPage("RID_SVXPAGE_SWPOSSIZE", SvxSwPosSizeTabPage::Create
,
536 SvxSwPosSizeTabPage::GetRanges
);
537 RemoveTabPage("RID_SVXPAGE_POSITION_SIZE");
541 m_nPositionSizePageId
= AddTabPage("RID_SVXPAGE_POSITION_SIZE", SvxPositionSizeTabPage::Create
,
542 SvxPositionSizeTabPage::GetRanges
);
543 RemoveTabPage("RID_SVXPAGE_SWPOSSIZE");
545 m_nCaptionPageId
= AddTabPage("RID_SVXPAGE_CAPTION", SvxCaptionTabPage::Create
,
546 SvxCaptionTabPage::GetRanges
);
549 void SvxCaptionTabDialog::PageCreated( sal_uInt16 nId
, SfxTabPage
&rPage
)
551 if (nId
== m_nPositionSizePageId
)
553 static_cast<SvxPositionSizeTabPage
&>( rPage
).SetView( pView
);
554 static_cast<SvxPositionSizeTabPage
&>( rPage
).Construct();
555 if( nAnchorCtrls
& SVX_OBJ_NORESIZE
)
556 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableResize();
558 if( nAnchorCtrls
& SVX_OBJ_NOPROTECT
)
559 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableProtect();
561 else if (nId
== m_nSwPosSizePageId
)
563 SvxSwPosSizeTabPage
& rSwPage
= static_cast<SvxSwPosSizeTabPage
&>(rPage
);
564 rSwPage
.EnableAnchorTypes(nAnchorCtrls
);
565 rSwPage
.SetValidateFramePosLink( aValidateLink
);
567 else if (nId
== m_nCaptionPageId
)
569 static_cast<SvxCaptionTabPage
&>( rPage
).SetView( pView
);
570 static_cast<SvxCaptionTabPage
&>( rPage
).Construct();
574 void SvxCaptionTabDialog::SetValidateFramePosLink( const Link
<>& rLink
)
576 aValidateLink
= rLink
;
580 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */