<commit_before>/*************************************************************************
 *
 *  $RCSfile: htmlexp2.cxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: vg $ $Date: 2005-02-21 13:36:25 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PCH
#include "filt_pch.hxx"
#endif

#pragma hdrstop

//------------------------------------------------------------------------

#ifdef MAC
#define _SYSDEP_HXX
#endif

#include <svx/svditer.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
#include <svx/xoutbmp.hxx>
#ifndef _SVDXCGV_HXX
#include <svx/svdxcgv.hxx>
#endif
#include <sot/exchange.hxx>
#include <svtools/htmlkywd.hxx>
#include <svtools/htmlout.hxx>
#include <svtools/transfer.hxx>
#include <svtools/embedtransfer.hxx>
#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#include <tools/urlobj.hxx>

#if defined(WIN) || defined(WNT)
#ifndef _SVWIN_H
#include <tools/svwin.h>
#endif
#endif

#include "htmlexp.hxx"
#include "global.hxx"
#include "document.hxx"
#include "drwlayer.hxx"
#include "ftools.hxx"

using namespace com::sun::star;

//------------------------------------------------------------------------

void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
        SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
{
    if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
    {
        SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
        if ( pDrawPage )
        {
            bTabHasGraphics = TRUE;
            FillGraphList( pDrawPage, nTab,
                nStartCol, nStartRow, nEndCol, nEndRow );
            for ( ScHTMLGraphEntry* pE = aGraphList.First(); pE;
                    pE = aGraphList.Next() )
            {
                if ( !pE->bInCell )
                {   // nicht alle in Zellen: einige neben Tabelle
                    bTabAlignedLeft = TRUE;
                    break;
                }
            }
        }
    }
}

void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
        SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
{
    ULONG   nObjCount = pPage->GetObjCount();
    if ( nObjCount )
    {
        Rectangle aRect;
        if ( !bAll )
            aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
        SdrObjListIter aIter( *pPage, IM_FLAT );
        SdrObject* pObject = aIter.Next();
        while ( pObject )
        {
            Rectangle aObjRect = pObject->GetCurrentBoundRect();
            if ( bAll || aRect.IsInside( aObjRect ) )
            {
                Size aSpace;
                ScRange aR = pDoc->GetRange( nTab, aObjRect );
                // Rectangle in mm/100
                Size aSize( MMToPixel( aObjRect.GetSize() ) );
                // If the image is somewhere in a merged range we must
                // move the anchor to the upper left (THE span cell).
                pDoc->ExtendOverlapped( aR );
                SCCOL nCol1 = aR.aStart.Col();
                SCROW nRow1 = aR.aStart.Row();
                SCCOL nCol2 = aR.aEnd.Col();
                SCROW nRow2 = aR.aEnd.Row();
                // All cells empty under object?
                BOOL bInCell = (pDoc->GetEmptyLinesInBlock(
                    nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
                    == (nRow2 - nRow1));    // rows-1 !
                if ( bInCell )
                {   // Spacing in spanning cell
                    Rectangle aCellRect = pDoc->GetMMRect(
                        nCol1, nRow1, nCol2, nRow2, nTab );
                    aSpace = MMToPixel( Size(
                        aCellRect.GetWidth() - aObjRect.GetWidth(),
                        aCellRect.GetHeight() - aObjRect.GetHeight() ));
                    aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
                    aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
                    aSpace.Width() /= 2;
                    aSpace.Height() /= 2;
                }
                ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
                    aR, aSize, bInCell, aSpace );
                aGraphList.Insert( pE, LIST_APPEND );
            }
            pObject = aIter.Next();
        }
    }
}

void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
{
    SdrObject* pObject = pE->pObject;
    ByteString aOpt;
    (((aOpt += ' ') += sHTML_O_width) += '=') +=
        ByteString::CreateFromInt32( pE->aSize.Width() );
    (((aOpt += ' ') += sHTML_O_height) += '=') +=
        ByteString::CreateFromInt32( pE->aSize.Height() );
    if ( pE->bInCell )
    {
        (((aOpt += ' ') += sHTML_O_hspace) += '=') +=
            ByteString::CreateFromInt32( pE->aSpace.Width() );
        (((aOpt += ' ') += sHTML_O_vspace) += '=') +=
            ByteString::CreateFromInt32( pE->aSpace.Height() );
    }
    switch ( pObject->GetObjIdentifier() )
    {
        case OBJ_GRAF:
        {
            const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
            const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
            USHORT nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
                    ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
            BOOL bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
            BOOL bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
            ULONG nXOutFlags = 0;
            if ( bHMirr )
                nXOutFlags |= XOUTBMP_MIRROR_HORZ;
            if ( bVMirr )
                nXOutFlags |= XOUTBMP_MIRROR_VERT;
            String aLinkName;
            if ( pSGO->IsLinkedGraphic() )
                aLinkName = pSGO->GetFileName();
            WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
            pE->bWritten = TRUE;
        }
        break;
        case OBJ_OLE2:
        {
            uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
            DBG_ASSERT( xObj.is(), "WriteGraphEntry: no OLE ObjRef" );
            if ( xObj.is() )
            {
                TransferableDataHelper aOleData( new SvEmbedTransferHelper( xObj ) );
                GDIMetaFile aMtf;
                if( aOleData.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
                {
                    Graphic aGraph( aMtf );
                    String aLinkName;
                    WriteImage( aLinkName, aGraph, aOpt );
                    pE->bWritten = TRUE;
                }
            }
        }
        break;
        default:
        {
            Graphic aGraph( SdrExchangeView::GetObjGraphic(
                pDoc->GetDrawLayer(), pObject ) );
            String aLinkName;
            WriteImage( aLinkName, aGraph, aOpt );
            pE->bWritten = TRUE;
        }
    }
}

void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
            const ByteString& rImgOptions, ULONG nXOutFlags )
{
    // embeddete Grafik -> via WriteGraphic schreiben
    if( !rLinkName.Len() )
    {
        if( aStreamPath.Len() > 0 )
        {
            // Grafik als (JPG-)File speichern
            String aGrfNm( aStreamPath );
            nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
            USHORT nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
                CREATE_STRING( "JPG" ), nXOutFlags );
            if( !nErr )     // sonst fehlerhaft, da ist nichts auszugeben
            {
                rLinkName = URIHelper::SmartRel2Abs(
                        INetURLObject(aBaseURL),
                        aGrfNm,
                        URIHelper::GetMaybeFileHdl());
                if ( HasCId() )
                    MakeCIdURL( rLinkName );
            }
        }
    }
    else
    {
        if( bCopyLocalFileToINet || HasCId() )
        {
            CopyLocalFileToINet( rLinkName, aStreamPath );
            if ( HasCId() )
                MakeCIdURL( rLinkName );
        }
        else
            rLinkName = URIHelper::SmartRel2Abs(
                    INetURLObject(aBaseURL),
                    rLinkName,
                    URIHelper::GetMaybeFileHdl());
    }
    if( rLinkName.Len() )
    {   // <IMG SRC="..."[ rImgOptions]>
        rStrm << '<' << sHTML_image << ' ' << sHTML_O_src << "=\"";
        HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
                    aBaseURL,
                    rLinkName ), eDestEnc ) << '\"';
        if ( rImgOptions.Len() )
            rStrm << rImgOptions.GetBuffer();
        rStrm << '>' << sNewLine << GetIndentStr();
    }
}

<commit_msg>INTEGRATION: CWS ooo19126 (1.11.146); FILE MERGED 2005/09/05 15:02:34 rt 1.11.146.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: htmlexp2.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:12:38 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifdef PCH
#include "filt_pch.hxx"
#endif

#pragma hdrstop

//------------------------------------------------------------------------

#ifdef MAC
#define _SYSDEP_HXX
#endif

#include <svx/svditer.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
#include <svx/xoutbmp.hxx>
#ifndef _SVDXCGV_HXX
#include <svx/svdxcgv.hxx>
#endif
#include <sot/exchange.hxx>
#include <svtools/htmlkywd.hxx>
#include <svtools/htmlout.hxx>
#include <svtools/transfer.hxx>
#include <svtools/embedtransfer.hxx>
#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#include <tools/urlobj.hxx>

#if defined(WIN) || defined(WNT)
#ifndef _SVWIN_H
#include <tools/svwin.h>
#endif
#endif

#include "htmlexp.hxx"
#include "global.hxx"
#include "document.hxx"
#include "drwlayer.hxx"
#include "ftools.hxx"

using namespace com::sun::star;

//------------------------------------------------------------------------

void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
        SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
{
    if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
    {
        SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
        if ( pDrawPage )
        {
            bTabHasGraphics = TRUE;
            FillGraphList( pDrawPage, nTab,
                nStartCol, nStartRow, nEndCol, nEndRow );
            for ( ScHTMLGraphEntry* pE = aGraphList.First(); pE;
                    pE = aGraphList.Next() )
            {
                if ( !pE->bInCell )
                {   // nicht alle in Zellen: einige neben Tabelle
                    bTabAlignedLeft = TRUE;
                    break;
                }
            }
        }
    }
}

void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
        SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
{
    ULONG   nObjCount = pPage->GetObjCount();
    if ( nObjCount )
    {
        Rectangle aRect;
        if ( !bAll )
            aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
        SdrObjListIter aIter( *pPage, IM_FLAT );
        SdrObject* pObject = aIter.Next();
        while ( pObject )
        {
            Rectangle aObjRect = pObject->GetCurrentBoundRect();
            if ( bAll || aRect.IsInside( aObjRect ) )
            {
                Size aSpace;
                ScRange aR = pDoc->GetRange( nTab, aObjRect );
                // Rectangle in mm/100
                Size aSize( MMToPixel( aObjRect.GetSize() ) );
                // If the image is somewhere in a merged range we must
                // move the anchor to the upper left (THE span cell).
                pDoc->ExtendOverlapped( aR );
                SCCOL nCol1 = aR.aStart.Col();
                SCROW nRow1 = aR.aStart.Row();
                SCCOL nCol2 = aR.aEnd.Col();
                SCROW nRow2 = aR.aEnd.Row();
                // All cells empty under object?
                BOOL bInCell = (pDoc->GetEmptyLinesInBlock(
                    nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
                    == (nRow2 - nRow1));    // rows-1 !
                if ( bInCell )
                {   // Spacing in spanning cell
                    Rectangle aCellRect = pDoc->GetMMRect(
                        nCol1, nRow1, nCol2, nRow2, nTab );
                    aSpace = MMToPixel( Size(
                        aCellRect.GetWidth() - aObjRect.GetWidth(),
                        aCellRect.GetHeight() - aObjRect.GetHeight() ));
                    aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
                    aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
                    aSpace.Width() /= 2;
                    aSpace.Height() /= 2;
                }
                ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
                    aR, aSize, bInCell, aSpace );
                aGraphList.Insert( pE, LIST_APPEND );
            }
            pObject = aIter.Next();
        }
    }
}

void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
{
    SdrObject* pObject = pE->pObject;
    ByteString aOpt;
    (((aOpt += ' ') += sHTML_O_width) += '=') +=
        ByteString::CreateFromInt32( pE->aSize.Width() );
    (((aOpt += ' ') += sHTML_O_height) += '=') +=
        ByteString::CreateFromInt32( pE->aSize.Height() );
    if ( pE->bInCell )
    {
        (((aOpt += ' ') += sHTML_O_hspace) += '=') +=
            ByteString::CreateFromInt32( pE->aSpace.Width() );
        (((aOpt += ' ') += sHTML_O_vspace) += '=') +=
            ByteString::CreateFromInt32( pE->aSpace.Height() );
    }
    switch ( pObject->GetObjIdentifier() )
    {
        case OBJ_GRAF:
        {
            const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
            const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
            USHORT nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
                    ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
            BOOL bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
            BOOL bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
            ULONG nXOutFlags = 0;
            if ( bHMirr )
                nXOutFlags |= XOUTBMP_MIRROR_HORZ;
            if ( bVMirr )
                nXOutFlags |= XOUTBMP_MIRROR_VERT;
            String aLinkName;
            if ( pSGO->IsLinkedGraphic() )
                aLinkName = pSGO->GetFileName();
            WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
            pE->bWritten = TRUE;
        }
        break;
        case OBJ_OLE2:
        {
            uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
            DBG_ASSERT( xObj.is(), "WriteGraphEntry: no OLE ObjRef" );
            if ( xObj.is() )
            {
                TransferableDataHelper aOleData( new SvEmbedTransferHelper( xObj ) );
                GDIMetaFile aMtf;
                if( aOleData.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
                {
                    Graphic aGraph( aMtf );
                    String aLinkName;
                    WriteImage( aLinkName, aGraph, aOpt );
                    pE->bWritten = TRUE;
                }
            }
        }
        break;
        default:
        {
            Graphic aGraph( SdrExchangeView::GetObjGraphic(
                pDoc->GetDrawLayer(), pObject ) );
            String aLinkName;
            WriteImage( aLinkName, aGraph, aOpt );
            pE->bWritten = TRUE;
        }
    }
}

void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
            const ByteString& rImgOptions, ULONG nXOutFlags )
{
    // embeddete Grafik -> via WriteGraphic schreiben
    if( !rLinkName.Len() )
    {
        if( aStreamPath.Len() > 0 )
        {
            // Grafik als (JPG-)File speichern
            String aGrfNm( aStreamPath );
            nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
            USHORT nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
                CREATE_STRING( "JPG" ), nXOutFlags );
            if( !nErr )     // sonst fehlerhaft, da ist nichts auszugeben
            {
                rLinkName = URIHelper::SmartRel2Abs(
                        INetURLObject(aBaseURL),
                        aGrfNm,
                        URIHelper::GetMaybeFileHdl());
                if ( HasCId() )
                    MakeCIdURL( rLinkName );
            }
        }
    }
    else
    {
        if( bCopyLocalFileToINet || HasCId() )
        {
            CopyLocalFileToINet( rLinkName, aStreamPath );
            if ( HasCId() )
                MakeCIdURL( rLinkName );
        }
        else
            rLinkName = URIHelper::SmartRel2Abs(
                    INetURLObject(aBaseURL),
                    rLinkName,
                    URIHelper::GetMaybeFileHdl());
    }
    if( rLinkName.Len() )
    {   // <IMG SRC="..."[ rImgOptions]>
        rStrm << '<' << sHTML_image << ' ' << sHTML_O_src << "=\"";
        HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
                    aBaseURL,
                    rLinkName ), eDestEnc ) << '\"';
        if ( rImgOptions.Len() )
            rStrm << rImgOptions.GetBuffer();
        rStrm << '>' << sNewLine << GetIndentStr();
    }
}

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#undef SC_DLLIMPLEMENTATION

#include "datafdlg.hxx"
#include "scresid.hxx"
#include "viewdata.hxx"
#include "docsh.hxx"
#include "refundo.hxx"
#include "undodat.hxx"

#include <rtl/ustrbuf.hxx>

#define HDL(hdl)            LINK( this, ScDataFormDlg, hdl )

ScDataFormDlg::ScDataFormDlg(vcl::Window* pParent, ScTabViewShell* pTabViewShellOri)
    : ModalDialog(pParent, "DataFormDialog", "modules/scalc/ui/dataform.ui")
    , pTabViewShell(pTabViewShellOri)
    , aColLength(0)
    , nCurrentRow(0)
    , nStartCol(0)
    , nEndCol(0)
    , nStartRow(0)
    , nEndRow(0)
    , nTab(0)
    , bNoSelection(false)
{
    get(m_pBtnNew, "new");
    get(m_pBtnDelete, "delete");
    get(m_pBtnRestore, "restore");
    get(m_pBtnPrev, "prev");
    get(m_pBtnNext, "next");
    get(m_pBtnClose, "close");
    get(m_pFixedText, "label");
    sNewRecord = m_pFixedText->GetText();
    get(m_pSlider, "scrollbar");
    get(m_pGrid, "grid");

    //read header form current document, and add new controls
    OSL_ENSURE( pTabViewShell, "pTabViewShell is NULL! :-/" );
    ScViewData& rViewData = pTabViewShell->GetViewData();

    pDoc = rViewData.GetDocument();
    if (pDoc)
    {
        ScRange aRange;
        rViewData.GetSimpleArea( aRange );
        ScAddress aStart = aRange.aStart;
        ScAddress aEnd = aRange.aEnd;

        nStartCol = aStart.Col();
        nEndCol = aEnd.Col();
        nStartRow   = aStart.Row();
        nEndRow = aEnd.Row();

        nTab = rViewData.GetTabNo();
        //if there is no selection
        if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
            bNoSelection = true;

        if (bNoSelection)
        {
            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                nEndCol++;
                OUString aColName = pDoc->GetString(nEndCol, nStartRow, nTab);
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if (aColName.isEmpty() && nColWidth)
                {
                    nEndCol--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                if (nStartCol <= 0)
                    break;
                nStartCol--;

                OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if (aColName.isEmpty() && nColWidth)
                {
                    nStartCol++;
                    break;
                }
            }

            //skip leading hide column
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
                if (nColWidth)
                    break;
                nStartCol++;
            }

            if (nEndCol < nStartCol)
                nEndCol = nStartCol;

            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                nEndRow++;
                OUString aColName = pDoc->GetString(nStartCol, nEndRow, nTab);
                if (aColName.isEmpty())
                {
                    nEndRow--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                if (nStartRow <= 0)
                    break;
                nStartRow--;

                OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
                if (aColName.isEmpty())
                {
                    nStartRow++;
                    break;
                }
            }

            if (nEndRow < nStartRow)
                nEndRow = nStartRow;
        }

        nCurrentRow = nStartRow + 1;

        aColLength = nEndCol - nStartCol + 1;

        //new the controls
        maFixedTexts.reserve(aColLength);
        maEdits.reserve(aColLength);

        sal_Int32 nGridRow = 0;
        for(sal_uInt16 nIndex = 0; nIndex < aColLength; ++nIndex)
        {
            OUString aFieldName = pDoc->GetString(nIndex + nStartCol, nStartRow, nTab);
            int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
            if (nColWidth)
            {
                maFixedTexts.push_back( new FixedText(m_pGrid) );
                maEdits.push_back( new Edit(m_pGrid, WB_BORDER) );

                maFixedTexts[nIndex].set_grid_left_attach(0);
                maEdits[nIndex].set_grid_left_attach(1);
                maFixedTexts[nIndex].set_grid_top_attach(nGridRow);
                maEdits[nIndex].set_grid_top_attach(nGridRow);

                maEdits[nIndex].SetWidthInChars(32);
                maEdits[nIndex].set_hexpand(true);

                ++nGridRow;

                maFixedTexts[nIndex].SetText(aFieldName);
                maFixedTexts[nIndex].Show();
                maEdits[nIndex].Show();
            }
            else
            {
                maFixedTexts.push_back( NULL );
                maEdits.push_back( NULL );
            }
            if (!maEdits.is_null(nIndex))
                maEdits[nIndex].SetModifyHdl( HDL(Impl_DataModifyHdl) );
        }
    }

    FillCtrls(nCurrentRow);

    m_pSlider->SetPageSize( 10 );
    m_pSlider->SetVisibleSize( 1 );
    m_pSlider->SetLineSize( 1 );
    m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
    m_pSlider->Show();

    m_pBtnNew->SetClickHdl(HDL(Impl_NewHdl));
    m_pBtnPrev->SetClickHdl(HDL(Impl_PrevHdl));
    m_pBtnNext->SetClickHdl(HDL(Impl_NextHdl));

    m_pBtnRestore->SetClickHdl(HDL(Impl_RestoreHdl));
    m_pBtnDelete->SetClickHdl(HDL(Impl_DeleteHdl));
    m_pBtnClose->SetClickHdl(HDL(Impl_CloseHdl));

    m_pSlider->SetEndScrollHdl(HDL(Impl_ScrollHdl));

    SetButtonState();
}

ScDataFormDlg::~ScDataFormDlg()
{

}

void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
{
    OUString  aFieldName;
    for (sal_uInt16 i = 0; i < aColLength; ++i)
    {
        if (!maEdits.is_null(i))
        {
            if (nCurrentRow<=nEndRow)
            {
                aFieldName = pDoc->GetString(i + nStartCol, nCurrentRow, nTab);
                maEdits[i].SetText(aFieldName);
            }
            else
                maEdits[i].SetText(OUString());
        }
    }

    if (nCurrentRow <= nEndRow)
    {
        OUStringBuffer aBuf;
        aBuf.append(static_cast<sal_Int32>(nCurrentRow - nStartRow));
        aBuf.appendAscii(" / ");
        aBuf.append(static_cast<sal_Int32>(nEndRow - nStartRow));
        m_pFixedText->SetText(aBuf.makeStringAndClear());
    }
    else
        m_pFixedText->SetText(sNewRecord);

    m_pSlider->SetThumbPos(nCurrentRow-nStartRow-1);
}

IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
{
    if ( pEdit->IsModified() )
        m_pBtnRestore->Enable( true );
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl)
{
    ScViewData& rViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = rViewData.GetDocShell();
    if ( pDoc )
    {
        bool bHasData = false;
        boost::ptr_vector<Edit>::iterator itr = maEdits.begin(), itrEnd = maEdits.end();
        for(; itr != itrEnd; ++itr)
            if (!boost::is_null(itr))
                if ( !(*itr).GetText().isEmpty() )
                {
                    bHasData = true;
                    break;
                }

        if ( bHasData )
        {
            pTabViewShell->DataFormPutData( nCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , maEdits , aColLength );
            nCurrentRow++;
            if (nCurrentRow >= nEndRow + 2)
            {
                    nEndRow ++ ;
                    m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
            }
            SetButtonState();
            FillCtrls(nCurrentRow);
            pDocSh->SetDocumentModified();
            pDocSh->PostPaintGridAll();
            }
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_PrevHdl)
{
    if (pDoc)
    {
        if ( nCurrentRow > nStartRow +1 )
            nCurrentRow--;

        SetButtonState();
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_NextHdl)
{
    if (pDoc)
    {
        if ( nCurrentRow <= nEndRow)
            nCurrentRow++;

        SetButtonState();
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_RestoreHdl)
{
    if (pDoc)
    {
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_DeleteHdl)
{
    ScViewData& rViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = rViewData.GetDocShell();
    if (pDoc)
    {
        ScRange aRange(nStartCol, nCurrentRow, nTab, nEndCol, nCurrentRow, nTab);
        pDoc->DeleteRow(aRange);
        nEndRow--;

        SetButtonState();
        pDocSh->GetUndoManager()->Clear();

        FillCtrls(nCurrentRow);
        pDocSh->SetDocumentModified();
        pDocSh->PostPaintGridAll();
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_CloseHdl)
{
    EndDialog( );
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_ScrollHdl)
{
    long nOffset = m_pSlider->GetThumbPos();
    nCurrentRow = nStartRow + nOffset + 1;
    SetButtonState();
    FillCtrls(nCurrentRow);
    return 0;
}

void ScDataFormDlg::SetButtonState()
{
    if (nCurrentRow > nEndRow)
    {
        m_pBtnDelete->Enable( false );
        m_pBtnNext->Enable( false );
    }
    else
    {
        m_pBtnDelete->Enable( true );
        m_pBtnNext->Enable( true );
    }

    if (nCurrentRow == nStartRow + 1)
        m_pBtnPrev->Enable( false );
    else
        m_pBtnPrev->Enable( true );

    m_pBtnRestore->Enable( false );
    if ( maEdits.size()>=1 && !maEdits.is_null(0) )
        maEdits[0].GrabFocus();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>coverity#1242430 Dereference after null check<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#undef SC_DLLIMPLEMENTATION

#include "datafdlg.hxx"
#include "scresid.hxx"
#include "viewdata.hxx"
#include "docsh.hxx"
#include "refundo.hxx"
#include "undodat.hxx"

#include <rtl/ustrbuf.hxx>

#define HDL(hdl)            LINK( this, ScDataFormDlg, hdl )

ScDataFormDlg::ScDataFormDlg(vcl::Window* pParent, ScTabViewShell* pTabViewShellOri)
    : ModalDialog(pParent, "DataFormDialog", "modules/scalc/ui/dataform.ui")
    , pTabViewShell(pTabViewShellOri)
    , aColLength(0)
    , nCurrentRow(0)
    , nStartCol(0)
    , nEndCol(0)
    , nStartRow(0)
    , nEndRow(0)
    , nTab(0)
    , bNoSelection(false)
{
    get(m_pBtnNew, "new");
    get(m_pBtnDelete, "delete");
    get(m_pBtnRestore, "restore");
    get(m_pBtnPrev, "prev");
    get(m_pBtnNext, "next");
    get(m_pBtnClose, "close");
    get(m_pFixedText, "label");
    sNewRecord = m_pFixedText->GetText();
    get(m_pSlider, "scrollbar");
    get(m_pGrid, "grid");

    //read header form current document, and add new controls
    OSL_ENSURE( pTabViewShell, "pTabViewShell is NULL! :-/" );
    ScViewData& rViewData = pTabViewShell->GetViewData();

    pDoc = rViewData.GetDocument();
    if (pDoc)
    {
        ScRange aRange;
        rViewData.GetSimpleArea( aRange );
        ScAddress aStart = aRange.aStart;
        ScAddress aEnd = aRange.aEnd;

        nStartCol = aStart.Col();
        nEndCol = aEnd.Col();
        nStartRow   = aStart.Row();
        nEndRow = aEnd.Row();

        nTab = rViewData.GetTabNo();
        //if there is no selection
        if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
            bNoSelection = true;

        if (bNoSelection)
        {
            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                nEndCol++;
                OUString aColName = pDoc->GetString(nEndCol, nStartRow, nTab);
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if (aColName.isEmpty() && nColWidth)
                {
                    nEndCol--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                if (nStartCol <= 0)
                    break;
                nStartCol--;

                OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if (aColName.isEmpty() && nColWidth)
                {
                    nStartCol++;
                    break;
                }
            }

            //skip leading hide column
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
                if (nColWidth)
                    break;
                nStartCol++;
            }

            if (nEndCol < nStartCol)
                nEndCol = nStartCol;

            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                nEndRow++;
                OUString aColName = pDoc->GetString(nStartCol, nEndRow, nTab);
                if (aColName.isEmpty())
                {
                    nEndRow--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                if (nStartRow <= 0)
                    break;
                nStartRow--;

                OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
                if (aColName.isEmpty())
                {
                    nStartRow++;
                    break;
                }
            }

            if (nEndRow < nStartRow)
                nEndRow = nStartRow;
        }

        nCurrentRow = nStartRow + 1;

        aColLength = nEndCol - nStartCol + 1;

        //new the controls
        maFixedTexts.reserve(aColLength);
        maEdits.reserve(aColLength);

        sal_Int32 nGridRow = 0;
        for(sal_uInt16 nIndex = 0; nIndex < aColLength; ++nIndex)
        {
            OUString aFieldName = pDoc->GetString(nIndex + nStartCol, nStartRow, nTab);
            int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
            if (nColWidth)
            {
                maFixedTexts.push_back( new FixedText(m_pGrid) );
                maEdits.push_back( new Edit(m_pGrid, WB_BORDER) );

                maFixedTexts[nIndex].set_grid_left_attach(0);
                maEdits[nIndex].set_grid_left_attach(1);
                maFixedTexts[nIndex].set_grid_top_attach(nGridRow);
                maEdits[nIndex].set_grid_top_attach(nGridRow);

                maEdits[nIndex].SetWidthInChars(32);
                maEdits[nIndex].set_hexpand(true);

                ++nGridRow;

                maFixedTexts[nIndex].SetText(aFieldName);
                maFixedTexts[nIndex].Show();
                maEdits[nIndex].Show();
            }
            else
            {
                maFixedTexts.push_back( NULL );
                maEdits.push_back( NULL );
            }
            if (!maEdits.is_null(nIndex))
                maEdits[nIndex].SetModifyHdl( HDL(Impl_DataModifyHdl) );
        }
    }

    FillCtrls(nCurrentRow);

    m_pSlider->SetPageSize( 10 );
    m_pSlider->SetVisibleSize( 1 );
    m_pSlider->SetLineSize( 1 );
    m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
    m_pSlider->Show();

    m_pBtnNew->SetClickHdl(HDL(Impl_NewHdl));
    m_pBtnPrev->SetClickHdl(HDL(Impl_PrevHdl));
    m_pBtnNext->SetClickHdl(HDL(Impl_NextHdl));

    m_pBtnRestore->SetClickHdl(HDL(Impl_RestoreHdl));
    m_pBtnDelete->SetClickHdl(HDL(Impl_DeleteHdl));
    m_pBtnClose->SetClickHdl(HDL(Impl_CloseHdl));

    m_pSlider->SetEndScrollHdl(HDL(Impl_ScrollHdl));

    SetButtonState();
}

ScDataFormDlg::~ScDataFormDlg()
{

}

void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
{
    for (sal_uInt16 i = 0; i < aColLength; ++i)
    {
        if (!maEdits.is_null(i))
        {
            if (nCurrentRow<=nEndRow && pDoc)
            {
                OUString  aFieldName(pDoc->GetString(i + nStartCol, nCurrentRow, nTab));
                maEdits[i].SetText(aFieldName);
            }
            else
                maEdits[i].SetText(OUString());
        }
    }

    if (nCurrentRow <= nEndRow)
    {
        OUStringBuffer aBuf;
        aBuf.append(static_cast<sal_Int32>(nCurrentRow - nStartRow));
        aBuf.appendAscii(" / ");
        aBuf.append(static_cast<sal_Int32>(nEndRow - nStartRow));
        m_pFixedText->SetText(aBuf.makeStringAndClear());
    }
    else
        m_pFixedText->SetText(sNewRecord);

    m_pSlider->SetThumbPos(nCurrentRow-nStartRow-1);
}

IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
{
    if ( pEdit->IsModified() )
        m_pBtnRestore->Enable( true );
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl)
{
    ScViewData& rViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = rViewData.GetDocShell();
    if ( pDoc )
    {
        bool bHasData = false;
        boost::ptr_vector<Edit>::iterator itr = maEdits.begin(), itrEnd = maEdits.end();
        for(; itr != itrEnd; ++itr)
            if (!boost::is_null(itr))
                if ( !(*itr).GetText().isEmpty() )
                {
                    bHasData = true;
                    break;
                }

        if ( bHasData )
        {
            pTabViewShell->DataFormPutData( nCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , maEdits , aColLength );
            nCurrentRow++;
            if (nCurrentRow >= nEndRow + 2)
            {
                    nEndRow ++ ;
                    m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
            }
            SetButtonState();
            FillCtrls(nCurrentRow);
            pDocSh->SetDocumentModified();
            pDocSh->PostPaintGridAll();
            }
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_PrevHdl)
{
    if (pDoc)
    {
        if ( nCurrentRow > nStartRow +1 )
            nCurrentRow--;

        SetButtonState();
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_NextHdl)
{
    if (pDoc)
    {
        if ( nCurrentRow <= nEndRow)
            nCurrentRow++;

        SetButtonState();
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_RestoreHdl)
{
    if (pDoc)
    {
        FillCtrls(nCurrentRow);
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_DeleteHdl)
{
    ScViewData& rViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = rViewData.GetDocShell();
    if (pDoc)
    {
        ScRange aRange(nStartCol, nCurrentRow, nTab, nEndCol, nCurrentRow, nTab);
        pDoc->DeleteRow(aRange);
        nEndRow--;

        SetButtonState();
        pDocSh->GetUndoManager()->Clear();

        FillCtrls(nCurrentRow);
        pDocSh->SetDocumentModified();
        pDocSh->PostPaintGridAll();
    }
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_CloseHdl)
{
    EndDialog( );
    return 0;
}

IMPL_LINK_NOARG(ScDataFormDlg, Impl_ScrollHdl)
{
    long nOffset = m_pSlider->GetThumbPos();
    nCurrentRow = nStartRow + nOffset + 1;
    SetButtonState();
    FillCtrls(nCurrentRow);
    return 0;
}

void ScDataFormDlg::SetButtonState()
{
    if (nCurrentRow > nEndRow)
    {
        m_pBtnDelete->Enable( false );
        m_pBtnNext->Enable( false );
    }
    else
    {
        m_pBtnDelete->Enable( true );
        m_pBtnNext->Enable( true );
    }

    if (nCurrentRow == nStartRow + 1)
        m_pBtnPrev->Enable( false );
    else
        m_pBtnPrev->Enable( true );

    m_pBtnRestore->Enable( false );
    if ( maEdits.size()>=1 && !maEdits.is_null(0) )
        maEdits[0].GrabFocus();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: inscodlg.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: nn $ $Date: 2002-07-15 14:33:42 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

//------------------------------------------------------------------

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

BOOL   ScInsertContentsDlg::bPreviousAllCheck = TRUE;
USHORT ScInsertContentsDlg::nPreviousChecks   = (IDF_DATETIME | IDF_STRING  |
                                                 IDF_NOTE     | IDF_FORMULA |
                                                 IDF_ATTRIB   | IDF_OBJECTS);
USHORT ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
USHORT ScInsertContentsDlg::nPreviousChecks2 = 0;
USHORT ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

//-----------------------------------------------------------------------

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          USHORT        nCheckDefaults,
                                          const String* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    bOtherDoc       ( FALSE ),
    bFillMode       ( FALSE ),
    bChangeTrack    ( FALSE ),
    bMoveDownDisabled( FALSE ),
    bMoveRightDisabled( FALSE )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = FALSE;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(TRUE); break;
        case PASTE_ADD:    aRbAdd.Check(TRUE); break;
        case PASTE_SUB:    aRbSub.Check(TRUE); break;
        case PASTE_MUL:    aRbMul.Check(TRUE); break;
        case PASTE_DIV:    aRbDiv.Check(TRUE); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(TRUE); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(TRUE); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(TRUE); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

//------------------------------------------------------------------------

USHORT ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

//------------------------------------------------------------------------

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

//------------------------------------------------------------------------

void ScInsertContentsDlg::DisableChecks( BOOL bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(TRUE);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( BOOL bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetFillMode( BOOL bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetChangeTrack( BOOL bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    BOOL bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    BOOL bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(TRUE);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(TRUE);
    }
}

//------------------------------------------------------------------------

IMPL_LINK( ScInsertContentsDlg, InsAllHdl, void*, EMPTY_ARG )
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK( ScInsertContentsDlg, LinkBtnHdl, void*, EMPTY_ARG )
{
    TestModes();

    return 0;
}

__EXPORT ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

USHORT  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

<commit_msg>INTEGRATION: CWS tune03 (1.3.492); FILE MERGED 2004/07/08 16:45:13 mhu 1.3.492.1: #i29979# Added SC_DLLPUBLIC/PRIVATE (see scdllapi.h) to exported symbols/classes.<commit_after>/*************************************************************************
 *
 *  $RCSfile: inscodlg.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2004-08-23 09:36:57 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#undef SC_DLLIMPLEMENTATION

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

//------------------------------------------------------------------

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

BOOL   ScInsertContentsDlg::bPreviousAllCheck = TRUE;
USHORT ScInsertContentsDlg::nPreviousChecks   = (IDF_DATETIME | IDF_STRING  |
                                                 IDF_NOTE     | IDF_FORMULA |
                                                 IDF_ATTRIB   | IDF_OBJECTS);
USHORT ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
USHORT ScInsertContentsDlg::nPreviousChecks2 = 0;
USHORT ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

//-----------------------------------------------------------------------

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          USHORT        nCheckDefaults,
                                          const String* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    bOtherDoc       ( FALSE ),
    bFillMode       ( FALSE ),
    bChangeTrack    ( FALSE ),
    bMoveDownDisabled( FALSE ),
    bMoveRightDisabled( FALSE )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = FALSE;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(TRUE); break;
        case PASTE_ADD:    aRbAdd.Check(TRUE); break;
        case PASTE_SUB:    aRbSub.Check(TRUE); break;
        case PASTE_MUL:    aRbMul.Check(TRUE); break;
        case PASTE_DIV:    aRbDiv.Check(TRUE); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(TRUE); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(TRUE); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(TRUE); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

//------------------------------------------------------------------------

USHORT ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

//------------------------------------------------------------------------

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

//------------------------------------------------------------------------

void ScInsertContentsDlg::DisableChecks( BOOL bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(TRUE);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( BOOL bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetFillMode( BOOL bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetChangeTrack( BOOL bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    BOOL bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    BOOL bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(TRUE);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(TRUE);
    }
}

//------------------------------------------------------------------------

IMPL_LINK( ScInsertContentsDlg, InsAllHdl, void*, EMPTY_ARG )
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK( ScInsertContentsDlg, LinkBtnHdl, void*, EMPTY_ARG )
{
    TestModes();

    return 0;
}

__EXPORT ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

USHORT  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#undef SC_DLLIMPLEMENTATION

//------------------------------------------------------------------

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

sal_Bool   ScInsertContentsDlg::bPreviousAllCheck = sal_True;
sal_uInt16 ScInsertContentsDlg::nPreviousChecks   = (IDF_DATETIME | IDF_STRING  |
                                                 IDF_NOTE     | IDF_FORMULA |
                                                 IDF_ATTRIB   | IDF_OBJECTS);
sal_uInt16 ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
sal_uInt16 ScInsertContentsDlg::nPreviousChecks2 = 0;
sal_uInt16 ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

//-----------------------------------------------------------------------

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          sal_uInt16        nCheckDefaults,
                                          const OUString* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    bOtherDoc       ( false ),
    bFillMode       ( false ),
    bChangeTrack    ( false ),
    bMoveDownDisabled( false ),
    bMoveRightDisabled( false )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = false;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(sal_True); break;
        case PASTE_ADD:    aRbAdd.Check(sal_True); break;
        case PASTE_SUB:    aRbSub.Check(sal_True); break;
        case PASTE_MUL:    aRbMul.Check(sal_True); break;
        case PASTE_DIV:    aRbDiv.Check(sal_True); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(sal_True); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(sal_True); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(sal_True); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

//------------------------------------------------------------------------

sal_uInt16 ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

//------------------------------------------------------------------------

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

//------------------------------------------------------------------------

void ScInsertContentsDlg::DisableChecks( sal_Bool bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(sal_True);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( sal_Bool bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetFillMode( sal_Bool bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetChangeTrack( sal_Bool bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    sal_Bool bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    sal_Bool bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(sal_True);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(sal_True);
    }
}

//------------------------------------------------------------------------

IMPL_LINK_NOARG(ScInsertContentsDlg, InsAllHdl)
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK_NOARG(ScInsertContentsDlg, LinkBtnHdl)
{
    TestModes();

    return 0;
}

ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

sal_uInt16  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>Resolves: #i123626# change default for paste special dialog of Calc...<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#undef SC_DLLIMPLEMENTATION

//------------------------------------------------------------------

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

sal_Bool   ScInsertContentsDlg::bPreviousAllCheck = sal_False;
sal_uInt16 ScInsertContentsDlg::nPreviousChecks   = (IDF_VALUE | IDF_DATETIME | IDF_STRING);
sal_uInt16 ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
sal_uInt16 ScInsertContentsDlg::nPreviousChecks2 = 0;
sal_uInt16 ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

//-----------------------------------------------------------------------

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          sal_uInt16        nCheckDefaults,
                                          const OUString* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    bOtherDoc       ( false ),
    bFillMode       ( false ),
    bChangeTrack    ( false ),
    bMoveDownDisabled( false ),
    bMoveRightDisabled( false )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = false;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(sal_True); break;
        case PASTE_ADD:    aRbAdd.Check(sal_True); break;
        case PASTE_SUB:    aRbSub.Check(sal_True); break;
        case PASTE_MUL:    aRbMul.Check(sal_True); break;
        case PASTE_DIV:    aRbDiv.Check(sal_True); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(sal_True); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(sal_True); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(sal_True); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

//------------------------------------------------------------------------

sal_uInt16 ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

//------------------------------------------------------------------------

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

//------------------------------------------------------------------------

void ScInsertContentsDlg::DisableChecks( sal_Bool bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(sal_True);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( sal_Bool bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetFillMode( sal_Bool bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetChangeTrack( sal_Bool bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(sal_True);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    sal_Bool bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    sal_Bool bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(sal_True);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(sal_True);
    }
}

//------------------------------------------------------------------------

IMPL_LINK_NOARG(ScInsertContentsDlg, InsAllHdl)
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK_NOARG(ScInsertContentsDlg, LinkBtnHdl)
{
    TestModes();

    return 0;
}

ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

sal_uInt16  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>