Lines 3127-3153
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3127 |
pImpl->pMergeData = new SwDSParam( |
3127 |
pImpl->pMergeData = new SwDSParam( |
3128 |
rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection()); |
3128 |
rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection()); |
3129 |
|
3129 |
|
|
|
3130 |
SwDSParam* pMergeData = pImpl->pMergeData; |
3130 |
try{ |
3131 |
try{ |
3131 |
//set to start position |
3132 |
//set to start position |
3132 |
if(pImpl->pMergeData->aSelection.getLength()) |
3133 |
if(pMergeData->aSelection.getLength()) |
3133 |
{ |
3134 |
{ |
3134 |
sal_Int32 nPos = 0; |
3135 |
sal_Int32 nPos = 0; |
3135 |
pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos; |
3136 |
pMergeData->aSelection.getConstArray()[ pMergeData->nSelectionIndex++ ] >>= nPos; |
3136 |
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos ); |
3137 |
pMergeData->bEndOfDB = !pMergeData->xResultSet->absolute( nPos ); |
3137 |
pImpl->pMergeData->CheckEndOfDB(); |
3138 |
pMergeData->CheckEndOfDB(); |
3138 |
if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength()) |
3139 |
if(pMergeData->nSelectionIndex >= pMergeData->aSelection.getLength()) |
3139 |
pImpl->pMergeData->bEndOfDB = TRUE; |
3140 |
pMergeData->bEndOfDB = TRUE; |
3140 |
} |
3141 |
} |
3141 |
else |
3142 |
else |
3142 |
{ |
3143 |
{ |
3143 |
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first(); |
3144 |
pMergeData->bEndOfDB = !pMergeData->xResultSet->first(); |
3144 |
pImpl->pMergeData->CheckEndOfDB(); |
3145 |
pMergeData->CheckEndOfDB(); |
3145 |
} |
3146 |
} |
3146 |
} |
3147 |
} |
3147 |
catch(Exception&) |
3148 |
catch(Exception&) |
3148 |
{ |
3149 |
{ |
3149 |
pImpl->pMergeData->bEndOfDB = TRUE; |
3150 |
pMergeData->bEndOfDB = TRUE; |
3150 |
pImpl->pMergeData->CheckEndOfDB(); |
3151 |
pMergeData->CheckEndOfDB(); |
3151 |
DBG_ERROR("exception in MergeNew()") |
3152 |
DBG_ERROR("exception in MergeNew()") |
3152 |
} |
3153 |
} |
3153 |
|
3154 |
|
Lines 3226-3281
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3226 |
long nStartRow, nEndRow; |
3227 |
long nStartRow, nEndRow; |
3227 |
ULONG nDocNo = 1; |
3228 |
ULONG nDocNo = 1; |
3228 |
sal_Int32 nDocCount = 0; |
3229 |
sal_Int32 nDocCount = 0; |
3229 |
if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) ) |
3230 |
if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pMergeData->xResultSet ) ) |
3230 |
aMonitorDlg.SetTotalCount( nDocCount ); |
3231 |
aMonitorDlg.SetTotalCount( nDocCount ); |
3231 |
|
3232 |
|
3232 |
do |
3233 |
// create a new docshell from the temporary document |
|
|
3234 |
SfxBoolItem aHidden( SID_HIDDEN, TRUE ); |
3235 |
SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii(URL_PREFIX_PRIV_SOFFICE )); |
3236 |
SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") ); |
3237 |
SfxStringItem aURL( SID_FILE_NAME, sSourceDocURL ); |
3238 |
const SfxPoolItem* pReturnValue = |
3239 |
rSourceView.GetViewFrame()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, |
3240 |
&aURL, &aFilterName, &aHidden, &aReferer, &aTarget, 0L); |
3241 |
|
3242 |
if(pReturnValue) |
3233 |
{ |
3243 |
{ |
3234 |
nStartRow = pImpl->pMergeData->xResultSet->getRow(); |
3244 |
SfxViewFrameItem* pVItem = (SfxViewFrameItem*)pReturnValue; |
3235 |
if (!IsMergeSilent()) |
3245 |
SwView* pWorkView = (SwView*) pVItem->GetFrame()->GetViewShell(); |
|
|
3246 |
SwWrtShell& rWorkShell = pWorkView->GetWrtShell(); |
3247 |
pWorkView->AttrChangedNotify( &rWorkShell );//Damit SelectShell gerufen wird. |
3248 |
|
3249 |
// prepare workind document |
3250 |
SwDoc* pWorkDoc = rWorkShell.GetDoc(); |
3251 |
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr(); |
3252 |
pWorkDoc->SetNewDBMgr( this ); |
3253 |
pWorkDoc->EmbedAllLinks(); |
3254 |
if(UNDO_UI_DELETE_INVISIBLECNTNT == rWorkShell.GetUndoIds()) |
3255 |
rWorkShell.Undo(); |
3256 |
rWorkShell.RemoveInvisibleContent(); |
3257 |
rWorkShell.SetNumberingRestart(); |
3258 |
do |
3236 |
{ |
3259 |
{ |
3237 |
aMonitorDlg.SetCurrentPosition( nDocNo ); |
3260 |
nStartRow = pMergeData->xResultSet->getRow(); |
3238 |
aMonitorDlg.Invalidate(); |
3261 |
if (!IsMergeSilent()) |
3239 |
aMonitorDlg.Update(); |
3262 |
{ |
3240 |
// the print monitor needs some time to act |
3263 |
aMonitorDlg.SetCurrentPosition( nDocNo ); |
3241 |
for( USHORT i = 0; i < 25; i++) |
3264 |
aMonitorDlg.Update(); |
3242 |
Application::Reschedule(); |
3265 |
} |
3243 |
} |
|
|
3244 |
|
3266 |
|
3245 |
// create a new docshell from the temporary document |
|
|
3246 |
SfxBoolItem aHidden( SID_HIDDEN, TRUE ); |
3247 |
SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii(URL_PREFIX_PRIV_SOFFICE )); |
3248 |
SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") ); |
3249 |
SfxStringItem aURL( SID_FILE_NAME, sSourceDocURL ); |
3250 |
const SfxPoolItem* pReturnValue = |
3251 |
rSourceView.GetViewFrame()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, |
3252 |
&aURL, &aFilterName, &aHidden, &aReferer, &aTarget, 0L); |
3253 |
if(pReturnValue) |
3254 |
{ |
3255 |
SfxViewFrameItem* pVItem = (SfxViewFrameItem*)pReturnValue; |
3256 |
SwView* pWorkView = (SwView*) pVItem->GetFrame()->GetViewShell(); |
3257 |
SwWrtShell& rWorkShell = pWorkView->GetWrtShell(); |
3258 |
pWorkView->AttrChangedNotify( &rWorkShell );//Damit SelectShell gerufen wird. |
3259 |
|
3260 |
// merge the data |
3261 |
SwDoc* pWorkDoc = rWorkShell.GetDoc(); |
3262 |
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr(); |
3263 |
pWorkDoc->SetNewDBMgr( this ); |
3264 |
pWorkDoc->EmbedAllLinks(); |
3265 |
if(UNDO_UI_DELETE_INVISIBLECNTNT == rWorkShell.GetUndoIds()) |
3266 |
rWorkShell.Undo(); |
3267 |
// create a layout |
3267 |
// create a layout |
3268 |
rWorkShell.CalcLayout(); |
3268 |
rWorkShell.CalcLayout(); |
3269 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3269 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3270 |
rWorkShell.ViewShell::UpdateFlds(); |
3270 |
rWorkShell.ViewShell::UpdateFlds(); |
3271 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3271 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3272 |
|
3272 |
|
3273 |
// strip invisible content and convert fields to text |
|
|
3274 |
rWorkShell.RemoveInvisibleContent(); |
3275 |
rWorkShell.ConvertFieldsToText(); |
3276 |
rWorkShell.SetNumberingRestart(); |
3277 |
|
3278 |
|
3279 |
// insert the document into the target document |
3273 |
// insert the document into the target document |
3280 |
rWorkShell.SttEndDoc(FALSE); |
3274 |
rWorkShell.SttEndDoc(FALSE); |
3281 |
rWorkShell.SttEndDoc(TRUE); |
3275 |
rWorkShell.SttEndDoc(TRUE); |
Lines 3326-3331
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3326 |
} |
3320 |
} |
3327 |
} |
3321 |
} |
3328 |
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True ); |
3322 |
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True ); |
|
|
3323 |
pTargetShell->ConvertFieldsToText(); |
3329 |
//convert fields in page styles (header/footer - has to be done after the first document has been pasted |
3324 |
//convert fields in page styles (header/footer - has to be done after the first document has been pasted |
3330 |
if(1 == nDocNo) |
3325 |
if(1 == nDocNo) |
3331 |
{ |
3326 |
{ |
Lines 3342-3362
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3342 |
rMMConfig.AddMergedDocument( aMergeInfo ); |
3337 |
rMMConfig.AddMergedDocument( aMergeInfo ); |
3343 |
++nRet; |
3338 |
++nRet; |
3344 |
|
3339 |
|
3345 |
// the print monitor needs some time to act |
3340 |
// Undo everything on current workshell allows to loop for a |
3346 |
for( USHORT i = 0; i < 25; i++) |
3341 |
// merge action within the same document. It saves _loads_ |
3347 |
Application::Reschedule(); |
3342 |
// of times : 7 times faster than the previous way. |
3348 |
|
3343 |
// see i40827 for more information |
3349 |
//restore the ole DBMgr |
3344 |
const SwNodes *pUndoNds = pWorkDoc->GetUndoNds(); |
3350 |
pWorkDoc->SetNewDBMgr( pWorkDBMgr ); |
3345 |
if (pUndoNds) |
3351 |
//now the temporary document should be closed |
3346 |
{ |
3352 |
SfxObjectShellRef xDocSh(pWorkView->GetDocShell()); |
3347 |
for( USHORT j = 0; j < pUndoNds->Count(); j++) |
3353 |
xDocSh->DoClose(); |
3348 |
rWorkShell.Undo(); |
3354 |
} |
3349 |
} |
3355 |
nEndRow = pImpl->pMergeData->xResultSet->getRow(); |
3350 |
nEndRow = pMergeData->xResultSet->getRow(); |
3356 |
++nDocNo; |
3351 |
++nDocNo; |
3357 |
} while( !bCancel && |
3352 |
} while( !bCancel && |
3358 |
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); |
3353 |
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); |
3359 |
|
3354 |
|
|
|
3355 |
//restore the ole DBMgr |
3356 |
pWorkDoc->SetNewDBMgr( pWorkDBMgr ); |
3357 |
|
3358 |
//now the temporary document should be closed |
3359 |
SfxObjectShellRef xDocSh(pWorkView->GetDocShell()); |
3360 |
xDocSh->DoClose(); |
3361 |
} |
3360 |
//deselect all, go out of the frame and go to the beginning of the document |
3362 |
//deselect all, go out of the frame and go to the beginning of the document |
3361 |
Point aPt(LONG_MIN, LONG_MIN); |
3363 |
Point aPt(LONG_MIN, LONG_MIN); |
3362 |
pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME); |
3364 |
pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME); |