1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: applab.cxx,v $
10 * $Revision: 1.34.46.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #if STLPORT_VERSION>=321
40 #include <hintids.hxx>
42 #ifndef _APP_HXX //autogen
43 #include <vcl/svapp.hxx>
45 #ifndef _WRKWIN_HXX //autogen
46 #include <vcl/wrkwin.hxx>
48 #ifndef _MSGBOX_HXX //autogen
49 #include <vcl/msgbox.hxx>
51 #include <sfx2/app.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <sfx2/printer.hxx>
54 #include <sfx2/request.hxx>
55 #include <sfx2/linkmgr.hxx>
56 #include <svx/pbinitem.hxx>
57 #include <svx/ulspitem.hxx>
58 #include <svx/lrspitem.hxx>
59 #include <svx/boxitem.hxx>
60 #include <svx/paperinf.hxx>
61 #include <svx/protitem.hxx>
62 #include <com/sun/star/frame/XStorable.hpp>
63 #include <com/sun/star/frame/XModel.hpp>
64 #include <fmthdft.hxx>
65 #include <fmtanchr.hxx>
66 #include <fmtfsize.hxx>
67 #include <fmtornt.hxx>
69 #include <gloshdl.hxx>
73 #include <swmodule.hxx>
94 #include <section.hxx>
95 #include <pagedesc.hxx>
96 #include <poolfmt.hxx>
102 #include <poolfmt.hrc>
104 #include "swabstdlg.hxx"
105 #include "envelp.hrc"
108 #include <IDocumentDeviceAccess.hxx>
110 using namespace ::com::sun::star
;
111 using ::rtl::OUString
;
113 // steht im appenv.cxx
114 extern String
InsertLabEnvText( SwWrtShell
& , SwFldMgr
& , const String
& );
116 const char __FAR_DATA MASTER_LABEL
[] = "MasterLabel";
118 // --------------------------------------------------------------------------
120 const SwFrmFmt
*lcl_InsertBCText( SwWrtShell
& rSh
, const SwLabItem
& rItem
,
122 sal_uInt16 nCol
, sal_uInt16 nRow
, sal_Bool bPage
)
124 SfxItemSet
aSet(rSh
.GetAttrPool(), RES_ANCHOR
, RES_ANCHOR
,
125 RES_VERT_ORIENT
, RES_VERT_ORIENT
, RES_HORI_ORIENT
, RES_HORI_ORIENT
, 0 );
126 sal_uInt16 nPhyPageNum
, nVirtPageNum
;
127 rSh
.GetPageNum( nPhyPageNum
, nVirtPageNum
);
129 aSet
.Put(SwFmtAnchor(bPage
? FLY_IN_CNTNT
: FLY_PAGE
, nPhyPageNum
));
132 aSet
.Put(SwFmtHoriOrient(rItem
.lLeft
+ nCol
* rItem
.lHDist
,
133 text::HoriOrientation::NONE
, text::RelOrientation::PAGE_FRAME
));
134 aSet
.Put(SwFmtVertOrient(rItem
.lUpper
+ nRow
* rItem
.lVDist
,
135 text::VertOrientation::NONE
, text::RelOrientation::PAGE_FRAME
));
137 const SwFrmFmt
*pFmt
= rSh
.NewFlyFrm(aSet
, sal_True
, &rFmt
); // Fly einfuegen
138 ASSERT( pFmt
, "Fly not inserted" );
140 rSh
.UnSelectFrm(); //Rahmen wurde automatisch selektiert
142 rSh
.SetTxtFmtColl( rSh
.GetTxtCollFromPool( RES_POOLCOLL_STANDARD
) );
145 if(!rItem
.bSynchron
|| !(nCol
|nRow
))
147 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
148 DBG_ASSERT(pFact
, "Dialogdiet fail!");
149 ::GlossarySetActGroup fnSetActGroup
= pFact
->SetGlossaryActGroupFunc( DLG_RENAME_GLOS
);
151 (*fnSetActGroup
)( rItem
.sGlossaryGroup
);
152 SwGlossaryHdl
* pGlosHdl
= rSh
.GetView().GetGlosHdl();
153 pGlosHdl
->SetCurGroup(rItem
.sGlossaryGroup
, sal_True
);
154 pGlosHdl
->InsertGlossary( rItem
.sGlossaryBlockName
);
160 const SwFrmFmt
*lcl_InsertLabText( SwWrtShell
& rSh
, const SwLabItem
& rItem
,
161 SwFrmFmt
&rFmt
, SwFldMgr
& rFldMgr
,
162 sal_uInt16 nCol
, sal_uInt16 nRow
, sal_Bool bLast
, sal_Bool bPage
)
164 SfxItemSet
aSet(rSh
.GetAttrPool(), RES_ANCHOR
, RES_ANCHOR
,
165 RES_VERT_ORIENT
, RES_VERT_ORIENT
, RES_HORI_ORIENT
, RES_HORI_ORIENT
, 0 );
166 sal_uInt16 nPhyPageNum
, nVirtPageNum
;
167 rSh
.GetPageNum( nPhyPageNum
, nVirtPageNum
);
169 aSet
.Put(SwFmtAnchor(bPage
? FLY_IN_CNTNT
: FLY_PAGE
, nPhyPageNum
));
172 aSet
.Put(SwFmtHoriOrient(rItem
.lLeft
+ nCol
* rItem
.lHDist
,
173 text::HoriOrientation::NONE
, text::RelOrientation::PAGE_FRAME
));
174 aSet
.Put(SwFmtVertOrient(rItem
.lUpper
+ nRow
* rItem
.lVDist
,
175 text::VertOrientation::NONE
, text::RelOrientation::PAGE_FRAME
));
177 const SwFrmFmt
*pFmt
= rSh
.NewFlyFrm(aSet
, sal_True
, &rFmt
); // Fly einfuegen
178 ASSERT( pFmt
, "Fly not inserted" );
180 rSh
.UnSelectFrm(); //Rahmen wurde automatisch selektiert
182 rSh
.SetTxtFmtColl( rSh
.GetTxtCollFromPool( RES_POOLCOLL_STANDARD
) );
184 // Ggf. "Naechster Datensatz"
186 if( (!rItem
.bSynchron
|| !(nCol
|nRow
)) && (sDBName
= InsertLabEnvText( rSh
, rFldMgr
, rItem
.aWriting
)).Len() && !bLast
)
188 sDBName
.SetToken( 3, DB_DELIM
, String::CreateFromAscii("True"));
189 SwInsertFld_Data
aData(TYP_DBNEXTSETFLD
, 0, sDBName
, aEmptyStr
, 0, &rSh
);
190 rFldMgr
.InsertFld( aData
);
196 // ----------------------------------------------------------------------------
199 void SwModule::InsertLab(SfxRequest
& rReq
, sal_Bool bLabel
)
201 static sal_uInt16 nLabelTitleNo
= 0;
202 static sal_uInt16 nBCTitleNo
= 0;
204 // DB-Manager anlegen
205 SwNewDBMgr
* pNewDBMgr
= new SwNewDBMgr
;
207 // SwLabItem aus Config lesen
208 SwLabCfgItem
aLabCfg(bLabel
);
211 SfxItemSet
aSet( GetPool(), FN_LABEL
, FN_LABEL
, 0 );
212 aSet
.Put( aLabCfg
.GetItem() );
214 SwAbstractDialogFactory
* pDialogFactory
= SwAbstractDialogFactory::Create();
215 DBG_ASSERT(pDialogFactory
, "SwAbstractDialogFactory fail!");
217 AbstarctSwLabDlg
* pDlg
= pDialogFactory
->CreateSwLabDlg( 0, aSet
, pNewDBMgr
, bLabel
, DLG_LAB
);
218 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
220 if ( RET_OK
== pDlg
->Execute() )
222 // Dialog auslesen, Item in Config speichern
223 const SwLabItem
& rItem
= (const SwLabItem
&) pDlg
->
224 GetOutputItemSet()->Get(FN_LABEL
);
225 aLabCfg
.GetItem() = rItem
;
228 // Neues Dokument erzeugen.
229 SfxObjectShellRef
xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD
));
230 xDocSh
->DoInitNew( 0 );
233 Printer
*pPrt
= pDlg
->GetPrt();
236 SwDocShell
*pDocSh
= (SwDocShell
*)(&*xDocSh
);
237 pDocSh
->getIDocumentDeviceAccess()->setJobsetup(pPrt
->GetJobSetup());
240 const SfxItemSet
*pArgs
= rReq
.GetArgs();
241 DBG_ASSERT( pArgs
, "no arguments in SfxRequest");
242 const SfxPoolItem
* pFrameItem
= 0;
244 pArgs
->GetItemState(SID_DOCFRAME
, FALSE
, &pFrameItem
);
246 SfxViewFrame
* pFrame
= 0;
249 SfxFrame
* pFr
= ((const SfxFrameItem
*)pFrameItem
)->GetFrame();
250 xDocSh
->PutItem(SfxBoolItem(SID_HIDDEN
, TRUE
));
251 pFr
->InsertDocument(xDocSh
);
252 pFrame
= pFr
->GetCurrentViewFrame();
256 pFrame
= SfxViewFrame::CreateViewFrame( *xDocSh
, 0, TRUE
);
258 SwView
*pNewView
= (SwView
*) pFrame
->GetViewShell();
259 pNewView
->AttrChangedNotify( &pNewView
->GetWrtShell() );//Damit SelectShell gerufen wird.
261 // Dokumenttitel setzen
265 aTmp
= String(SW_RES( STR_LAB_TITLE
));
266 aTmp
+= String::CreateFromInt32(++nLabelTitleNo
);
270 aTmp
= pDlg
->GetBusinessCardStr();
271 aTmp
+= String::CreateFromInt32( ++nBCTitleNo
);
273 xDocSh
->SetTitle( aTmp
);
275 pFrame
->GetFrame()->Appear();
278 SwWrtShell
*pSh
= pNewView
->GetWrtShellPtr();
279 ASSERT( pSh
, "missing WrtShell" );
281 { // block for locks the dispatcher!!
283 SwWait
aWait( (SwDocShell
&)*xDocSh
, sal_True
);
286 pSh
->SetLabelDoc(rItem
.bSynchron
);
287 pSh
->DoUndo( sal_False
);
288 pSh
->StartAllAction();
290 pSh
->SetNewDoc(); // Performanceprobleme vermeiden
292 SwPageDesc aDesc
= pSh
->GetPageDesc( 0 );
293 SwFrmFmt
& rFmt
= aDesc
.GetMaster();
296 SvxLRSpaceItem
aLRMargin( RES_LR_SPACE
);
297 SvxULSpaceItem
aULMargin( RES_UL_SPACE
);
298 aLRMargin
.SetLeft ((sal_uInt16
) rItem
.lLeft
);
299 aULMargin
.SetUpper((sal_uInt16
) rItem
.lUpper
);
300 aLRMargin
.SetRight(MINLAY
/2);
301 aULMargin
.SetLower(MINLAY
/2);
302 rFmt
.SetFmtAttr(aLRMargin
);
303 rFmt
.SetFmtAttr(aULMargin
);
305 // Kopf- und Fusszeilen
306 rFmt
.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False
)));
307 aDesc
.ChgHeaderShare(sal_False
);
308 rFmt
.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False
)));
309 aDesc
.ChgFooterShare(sal_False
);
312 aDesc
.SetUseOn(nsUseOnPage::PD_ALL
); // Seitennumerierung
314 // Einstellen der Seitengroesse
315 rFmt
.SetFmtAttr(SwFmtFrmSize(ATT_FIX_SIZE
,
316 rItem
.lLeft
+ rItem
.nCols
* rItem
.lHDist
+ MINLAY
,
317 rItem
.lUpper
+ rItem
.nRows
* rItem
.lVDist
+ MINLAY
));
321 aType
.SetNumberingType(SVX_NUM_NUMBER_NONE
);
322 aDesc
.SetNumType( aType
);
325 const SwPageDesc
&rFollow
= pSh
->GetPageDesc( pSh
->GetCurPageDesc() );
326 aDesc
.SetFollow( &rFollow
);
328 pPrt
= pSh
->getIDocumentDeviceAccess()->getPrinter( true );
329 SvxPaperBinItem
aItem( RES_PAPER_BIN
);
330 aItem
.SetValue((sal_Int8
)pPrt
->GetPaperBin());
331 rFmt
.SetFmtAttr(aItem
);
333 //determine orientation by calculating the width and height of the resulting page
334 const int nResultWidth
= rItem
.lHDist
* (rItem
.nCols
- 1) + rItem
.lWidth
+ rItem
.lLeft
;
335 const int nResultHeight
= rItem
.lVDist
* (rItem
.nRows
- 1) + rItem
.lHeight
+ rItem
.lUpper
;
336 aDesc
.SetLandscape(nResultWidth
> nResultHeight
);
338 pSh
->ChgPageDesc( 0, aDesc
);
341 SwFldMgr
* pFldMgr
= new SwFldMgr
;
342 pFldMgr
->SetEvalExpFlds(sal_False
);
344 //fix(24446): Damit der Text der Ettiketten nicht im unbedruckbaren
345 //Bereich landet stellen wir entsprechende Raender ein. Um das Handling
346 //so Optimal wie moeglich zu halten stellen wir zunaechst an der
347 //aktuellen Absatzvorlage keinen Rand als hartes Attribut ein (Damit die
348 //Formatierung wg. der Zeichengeb. Rahmen passt. Dann stellen wir die
349 //Standarabsatzvorlage anhand des unbedruckbaren Bereiches ein.
350 const long nMin
= pPrt
->GetPageOffset().X() - rItem
.lLeft
;
353 SvxLRSpaceItem
aLR( RES_LR_SPACE
);
355 SwFmt
*pStandard
= pSh
->GetTxtCollFromPool( RES_POOLCOLL_STANDARD
);
356 aLR
.SetLeft ( sal_uInt16(nMin
) );
357 aLR
.SetRight( sal_uInt16(nMin
) );
358 pStandard
->SetFmtAttr( aLR
);
361 // Rahmenvorlage vorbereiten
362 SwFrmFmt
* pFmt
= pSh
->GetFrmFmtFromPool( RES_POOLFRM_LABEL
);
363 SwFmtFrmSize
aFrmSize( ATT_FIX_SIZE
,
364 rItem
.lHDist
- (rItem
.lHDist
-rItem
.lWidth
),
365 rItem
.lVDist
- (rItem
.lVDist
-rItem
.lHeight
));
366 pFmt
->SetFmtAttr(aFrmSize
);
368 SvxLRSpaceItem
aFrmLRSpace( 0, (sal_uInt16
)(rItem
.lHDist
- rItem
.lWidth
),
371 pFmt
->SetFmtAttr(aFrmLRSpace
);
373 SvxULSpaceItem
aFrmULSpace( 0, (sal_uInt16
)(rItem
.lVDist
- rItem
.lHeight
),
375 pFmt
->SetFmtAttr(aFrmULSpace
);
377 const SwFrmFmt
*pFirstFlyFmt
= 0;
380 SwFmtVertOrient
aFrmVertOrient( pFmt
->GetVertOrient() );
381 aFrmVertOrient
.SetVertOrient( text::VertOrientation::TOP
);
382 pFmt
->SetFmtAttr(aFrmVertOrient
);
384 for ( sal_uInt16 i
= 0; i
< rItem
.nRows
; ++i
)
386 for ( sal_uInt16 j
= 0; j
< rItem
.nCols
; ++j
)
389 const SwFrmFmt
*pTmp
=
391 lcl_InsertLabText( *pSh
, rItem
, *pFmt
, *pFldMgr
, j
, i
,
392 i
== rItem
.nRows
- 1 && j
== rItem
.nCols
- 1,
394 lcl_InsertBCText(*pSh
, rItem
, *pFmt
, j
, i
, sal_True
);
401 // if there is no content in the fly then
402 // dont leave the fly!!!
405 sal_Bool bInFly
= 0 != pSh
->WizzardGetFly();
409 pSh
->EndDoc(sal_True
); // select all content
412 pSh
->SetMark(); // set only the mark
414 SwSection
aSect( CONTENT_SECTION
,
415 String::CreateFromAscii(MASTER_LABEL
));
416 pSh
->InsertSection(aSect
);
419 else if (rItem
.bSynchron
)
421 SwSection
aSect(FILE_LINK_SECTION
, pSh
->GetUniqueSectionName());
422 String
sLinkName(sfx2::cTokenSeperator
);
423 sLinkName
+= sfx2::cTokenSeperator
;
424 sLinkName
+= String::CreateFromAscii(MASTER_LABEL
);
425 aSect
.SetLinkFileName(sLinkName
);
427 pSh
->Insert(aDotStr
); // Dummytext zum Zuweisen der Section
429 pSh
->EndDoc(sal_True
); // Alles im Rahmen selektieren
430 pSh
->InsertSection(aSect
);
432 pSh
->Pop( sal_False
);
434 if ( i
+ 1 != rItem
.nRows
)
435 pSh
->SplitNode(); // Kleine Optimierung
440 pFirstFlyFmt
= bLabel
?
441 lcl_InsertLabText( *pSh
, rItem
, *pFmt
, *pFldMgr
,
442 static_cast< sal_uInt16
>(rItem
.nCol
- 1),
443 static_cast< sal_uInt16
>(rItem
.nRow
- 1), sal_True
, sal_False
) :
444 lcl_InsertBCText(*pSh
, rItem
, *pFmt
,
445 static_cast< sal_uInt16
>(rItem
.nCol
- 1),
446 static_cast< sal_uInt16
>(rItem
.nRow
- 1), sal_False
);
449 //fill the user fields
452 uno::Reference
< frame::XModel
> xModel
= pSh
->GetView().GetDocShell()->GetBaseModel();
453 DBG_ASSERT(pDialogFactory
, "SwAbstractDialogFactory fail!");
454 SwLabDlgMethod SwLabDlgUpdateFieldInformation
= pDialogFactory
->GetSwLabDlgStaticMethod ();
455 SwLabDlgUpdateFieldInformation(xModel
, rItem
);
458 pFldMgr
->SetEvalExpFlds(sal_True
);
459 pFldMgr
->EvalExpFlds(pSh
);
463 pSh
->GotoFly(pFirstFlyFmt
->GetName(), FLYCNTTYPE_ALL
, sal_False
);
466 pSh
->DoUndo( sal_True
);
469 if( rItem
.aWriting
.indexOf( '<' ) >= 0 )
471 // Datenbankbrowser mit zuletzt verwendeter Datenbank oeffnen
472 ShowDBObj( *pNewView
, pSh
->GetDBData() );
475 if( rItem
.bSynchron
)
477 SfxDispatcher
* pDisp
= pFrame
->GetDispatcher();
478 ASSERT(pDisp
, "Heute kein Dispatcher am Frame?");
479 pDisp
->Execute(FN_SYNC_LABELS
, SFX_CALLMODE_ASYNCHRON
);
481 rReq
.SetReturnValue(SfxVoidItem(bLabel
? FN_LABEL
: FN_BUSINESS_CARD
));