View | Details | Raw Unified | Return to issue 40827
Collapse All | Expand All

(-)a/sw/source/ui/dbui/dbmgr.cxx (-56 / +61 lines)
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-3269 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
            do
3236
            {
3257
            {
3237
                aMonitorDlg.SetCurrentPosition( nDocNo );
3258
                nStartRow = pMergeData->xResultSet->getRow();
3238
                aMonitorDlg.Invalidate();
3259
                if (!IsMergeSilent())
3239
                aMonitorDlg.Update();
3260
                {
3240
                // the print monitor needs some time to act
3261
                    aMonitorDlg.SetCurrentPosition( nDocNo );
3241
                for( USHORT i = 0; i < 25; i++)
3262
                    aMonitorDlg.Update();
3242
                    Application::Reschedule();
3263
                }
3243
            }
3244
3264
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
3265
                // create a layout
3268
                rWorkShell.CalcLayout();
3266
                rWorkShell.CalcLayout();
3269
                SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
3267
                SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
Lines 3342-3362 sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig, Link Here
3342
                rMMConfig.AddMergedDocument( aMergeInfo );
3340
                rMMConfig.AddMergedDocument( aMergeInfo );
3343
                ++nRet;
3341
                ++nRet;
3344
3342
3345
                // the print monitor needs some time to act
3343
                // Undo everything on current workshell allows to loop for a
3346
                for( USHORT i = 0; i < 25; i++)
3344
                // merge action within the same document. It saves _loads_
3347
                    Application::Reschedule();
3345
                // of times : 7 times faster than the previous way.
3348
3346
                // see i40827 for more information
3349
                //restore the ole DBMgr
3347
                const SwNodes *pUndoNds = pWorkDoc->GetUndoNds();
3350
                pWorkDoc->SetNewDBMgr( pWorkDBMgr );
3348
                if (pUndoNds)
3351
                //now the temporary document should be closed
3349
                {
3352
                SfxObjectShellRef xDocSh(pWorkView->GetDocShell());
3350
                    for( USHORT j = 0; j < pUndoNds->Count(); j++)
3353
                xDocSh->DoClose();
3351
                        rWorkShell.Undo();
3354
            }
3352
                }
3355
            nEndRow = pImpl->pMergeData->xResultSet->getRow();
3353
                nEndRow = pMergeData->xResultSet->getRow();
3356
            ++nDocNo;
3354
                ++nDocNo;
3357
        } while( !bCancel &&
3355
            } while( !bCancel &&
3358
                (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
3356
                (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
3359
3357
3358
            //restore the ole DBMgr
3359
            pWorkDoc->SetNewDBMgr( pWorkDBMgr );
3360
3361
            //now the temporary document should be closed
3362
            SfxObjectShellRef xDocSh(pWorkView->GetDocShell());
3363
            xDocSh->DoClose();
3364
        }
3360
        //deselect all, go out of the frame and go to the beginning of the document
3365
        //deselect all, go out of the frame and go to the beginning of the document
3361
        Point aPt(LONG_MIN, LONG_MIN);
3366
        Point aPt(LONG_MIN, LONG_MIN);
3362
        pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME);
3367
        pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME);

Return to issue 40827