Lines 3147-3173
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3147 |
pImpl->pMergeData = new SwDSParam( |
3147 |
pImpl->pMergeData = new SwDSParam( |
3148 |
rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection()); |
3148 |
rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection()); |
3149 |
|
3149 |
|
|
|
3150 |
SwDSParam* pMergeData = pImpl->pMergeData; |
3150 |
try{ |
3151 |
try{ |
3151 |
//set to start position |
3152 |
//set to start position |
3152 |
if(pImpl->pMergeData->aSelection.getLength()) |
3153 |
if(pMergeData->aSelection.getLength()) |
3153 |
{ |
3154 |
{ |
3154 |
sal_Int32 nPos = 0; |
3155 |
sal_Int32 nPos = 0; |
3155 |
pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos; |
3156 |
pMergeData->aSelection.getConstArray()[ pMergeData->nSelectionIndex++ ] >>= nPos; |
3156 |
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos ); |
3157 |
pMergeData->bEndOfDB = !pMergeData->xResultSet->absolute( nPos ); |
3157 |
pImpl->pMergeData->CheckEndOfDB(); |
3158 |
pMergeData->CheckEndOfDB(); |
3158 |
if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength()) |
3159 |
if(pMergeData->nSelectionIndex >= pMergeData->aSelection.getLength()) |
3159 |
pImpl->pMergeData->bEndOfDB = TRUE; |
3160 |
pMergeData->bEndOfDB = TRUE; |
3160 |
} |
3161 |
} |
3161 |
else |
3162 |
else |
3162 |
{ |
3163 |
{ |
3163 |
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first(); |
3164 |
pMergeData->bEndOfDB = !pMergeData->xResultSet->first(); |
3164 |
pImpl->pMergeData->CheckEndOfDB(); |
3165 |
pMergeData->CheckEndOfDB(); |
3165 |
} |
3166 |
} |
3166 |
} |
3167 |
} |
3167 |
catch(Exception&) |
3168 |
catch(Exception&) |
3168 |
{ |
3169 |
{ |
3169 |
pImpl->pMergeData->bEndOfDB = TRUE; |
3170 |
pMergeData->bEndOfDB = TRUE; |
3170 |
pImpl->pMergeData->CheckEndOfDB(); |
3171 |
pMergeData->CheckEndOfDB(); |
3171 |
DBG_ERROR("exception in MergeNew()"); |
3172 |
DBG_ERROR("exception in MergeNew()"); |
3172 |
} |
3173 |
} |
3173 |
|
3174 |
|
Lines 3246-3301
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3246 |
long nStartRow, nEndRow; |
3247 |
long nStartRow, nEndRow; |
3247 |
ULONG nDocNo = 1; |
3248 |
ULONG nDocNo = 1; |
3248 |
sal_Int32 nDocCount = 0; |
3249 |
sal_Int32 nDocCount = 0; |
3249 |
if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) ) |
3250 |
if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pMergeData->xResultSet ) ) |
3250 |
aMonitorDlg.SetTotalCount( nDocCount ); |
3251 |
aMonitorDlg.SetTotalCount( nDocCount ); |
3251 |
|
3252 |
|
3252 |
do |
3253 |
// create a new docshell from the temporary document |
|
|
3254 |
SfxBoolItem aHidden( SID_HIDDEN, TRUE ); |
3255 |
SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii(URL_PREFIX_PRIV_SOFFICE )); |
3256 |
SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") ); |
3257 |
SfxStringItem aURL( SID_FILE_NAME, sSourceDocURL ); |
3258 |
const SfxPoolItem* pReturnValue = |
3259 |
rSourceView.GetViewFrame()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, |
3260 |
&aURL, &aFilterName, &aHidden, &aReferer, &aTarget, 0L); |
3261 |
|
3262 |
if(pReturnValue) |
3253 |
{ |
3263 |
{ |
3254 |
nStartRow = pImpl->pMergeData->xResultSet->getRow(); |
3264 |
SfxViewFrameItem* pVItem = (SfxViewFrameItem*)pReturnValue; |
3255 |
if (!IsMergeSilent()) |
3265 |
SwView* pWorkView = (SwView*) pVItem->GetFrame()->GetViewShell(); |
|
|
3266 |
SwWrtShell& rWorkShell = pWorkView->GetWrtShell(); |
3267 |
pWorkView->AttrChangedNotify( &rWorkShell );//Damit SelectShell gerufen wird. |
3268 |
|
3269 |
// prepare workind document |
3270 |
SwDoc* pWorkDoc = rWorkShell.GetDoc(); |
3271 |
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr(); |
3272 |
pWorkDoc->SetNewDBMgr( this ); |
3273 |
pWorkDoc->EmbedAllLinks(); |
3274 |
if(UNDO_UI_DELETE_INVISIBLECNTNT == rWorkShell.GetUndoIds()) |
3275 |
rWorkShell.Undo(); |
3276 |
do |
3256 |
{ |
3277 |
{ |
3257 |
aMonitorDlg.SetCurrentPosition( nDocNo ); |
3278 |
nStartRow = pMergeData->xResultSet->getRow(); |
3258 |
aMonitorDlg.Invalidate(); |
3279 |
if (!IsMergeSilent()) |
3259 |
aMonitorDlg.Update(); |
3280 |
{ |
3260 |
// the print monitor needs some time to act |
3281 |
aMonitorDlg.SetCurrentPosition( nDocNo ); |
3261 |
for( USHORT i = 0; i < 25; i++) |
3282 |
aMonitorDlg.Update(); |
3262 |
Application::Reschedule(); |
3283 |
} |
3263 |
} |
|
|
3264 |
|
3284 |
|
3265 |
// create a new docshell from the temporary document |
|
|
3266 |
SfxBoolItem aHidden( SID_HIDDEN, TRUE ); |
3267 |
SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii(URL_PREFIX_PRIV_SOFFICE )); |
3268 |
SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") ); |
3269 |
SfxStringItem aURL( SID_FILE_NAME, sSourceDocURL ); |
3270 |
const SfxPoolItem* pReturnValue = |
3271 |
rSourceView.GetViewFrame()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, |
3272 |
&aURL, &aFilterName, &aHidden, &aReferer, &aTarget, 0L); |
3273 |
if(pReturnValue) |
3274 |
{ |
3275 |
SfxViewFrameItem* pVItem = (SfxViewFrameItem*)pReturnValue; |
3276 |
SwView* pWorkView = (SwView*) pVItem->GetFrame()->GetViewShell(); |
3277 |
SwWrtShell& rWorkShell = pWorkView->GetWrtShell(); |
3278 |
pWorkView->AttrChangedNotify( &rWorkShell );//Damit SelectShell gerufen wird. |
3279 |
|
3280 |
// merge the data |
3281 |
SwDoc* pWorkDoc = rWorkShell.GetDoc(); |
3282 |
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr(); |
3283 |
pWorkDoc->SetNewDBMgr( this ); |
3284 |
pWorkDoc->EmbedAllLinks(); |
3285 |
if(UNDO_UI_DELETE_INVISIBLECNTNT == rWorkShell.GetUndoIds()) |
3286 |
rWorkShell.Undo(); |
3287 |
// create a layout |
3285 |
// create a layout |
3288 |
rWorkShell.CalcLayout(); |
3286 |
rWorkShell.CalcLayout(); |
3289 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3287 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3290 |
rWorkShell.ViewShell::UpdateFlds(); |
3288 |
rWorkShell.ViewShell::UpdateFlds(); |
3291 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3289 |
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, rWorkShell.GetView().GetViewFrame()->GetObjectShell())); |
3292 |
|
3290 |
// Ensure numbering is correct on target document |
3293 |
// strip invisible content and convert fields to text |
|
|
3294 |
rWorkShell.RemoveInvisibleContent(); |
3291 |
rWorkShell.RemoveInvisibleContent(); |
3295 |
rWorkShell.ConvertFieldsToText(); |
|
|
3296 |
rWorkShell.SetNumberingRestart(); |
3292 |
rWorkShell.SetNumberingRestart(); |
3297 |
|
3293 |
|
3298 |
|
|
|
3299 |
// insert the document into the target document |
3294 |
// insert the document into the target document |
3300 |
rWorkShell.SttEndDoc(FALSE); |
3295 |
rWorkShell.SttEndDoc(FALSE); |
3301 |
rWorkShell.SttEndDoc(TRUE); |
3296 |
rWorkShell.SttEndDoc(TRUE); |
Lines 3346-3351
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3346 |
} |
3341 |
} |
3347 |
} |
3342 |
} |
3348 |
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True ); |
3343 |
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True ); |
|
|
3344 |
pTargetShell->ConvertFieldsToText(); |
3349 |
//convert fields in page styles (header/footer - has to be done after the first document has been pasted |
3345 |
//convert fields in page styles (header/footer - has to be done after the first document has been pasted |
3350 |
if(1 == nDocNo) |
3346 |
if(1 == nDocNo) |
3351 |
{ |
3347 |
{ |
Lines 3362-3382
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
Link Here
|
3362 |
rMMConfig.AddMergedDocument( aMergeInfo ); |
3358 |
rMMConfig.AddMergedDocument( aMergeInfo ); |
3363 |
++nRet; |
3359 |
++nRet; |
3364 |
|
3360 |
|
3365 |
// the print monitor needs some time to act |
3361 |
// Undo everything on current workshell allows to loop for a |
3366 |
for( USHORT i = 0; i < 25; i++) |
3362 |
// merge action within the same document. It saves _loads_ |
3367 |
Application::Reschedule(); |
3363 |
// of times : 7 times faster than the previous way. |
3368 |
|
3364 |
// see i40827 for more information |
3369 |
//restore the ole DBMgr |
3365 |
const SwNodes *pUndoNds = pWorkDoc->GetUndoNds(); |
3370 |
pWorkDoc->SetNewDBMgr( pWorkDBMgr ); |
3366 |
if (pUndoNds) |
3371 |
//now the temporary document should be closed |
3367 |
{ |
3372 |
SfxObjectShellRef xDocSh(pWorkView->GetDocShell()); |
3368 |
for( USHORT j = 0; j < pUndoNds->Count(); j++) |
3373 |
xDocSh->DoClose(); |
3369 |
rWorkShell.Undo(); |
3374 |
} |
3370 |
} |
3375 |
nEndRow = pImpl->pMergeData->xResultSet->getRow(); |
3371 |
nEndRow = pMergeData->xResultSet->getRow(); |
3376 |
++nDocNo; |
3372 |
++nDocNo; |
3377 |
} while( !bCancel && |
3373 |
} while( !bCancel && |
3378 |
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); |
3374 |
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); |
3379 |
|
3375 |
|
|
|
3376 |
//restore the ole DBMgr |
3377 |
pWorkDoc->SetNewDBMgr( pWorkDBMgr ); |
3378 |
|
3379 |
//now the temporary document should be closed |
3380 |
SfxObjectShellRef xDocSh(pWorkView->GetDocShell()); |
3381 |
xDocSh->DoClose(); |
3382 |
} |
3380 |
//deselect all, go out of the frame and go to the beginning of the document |
3383 |
//deselect all, go out of the frame and go to the beginning of the document |
3381 |
Point aPt(LONG_MIN, LONG_MIN); |
3384 |
Point aPt(LONG_MIN, LONG_MIN); |
3382 |
pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME); |
3385 |
pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME); |
Lines 3428-3431
void SwConnectionDisposedListener_Impl::disposing( const EventObject& rSource )
Link Here
|
3428 |
} |
3431 |
} |
3429 |
} |
3432 |
} |
3430 |
} |
3433 |
} |
3431 |
|
|
|