<commit_before>/*************************************************************************
 *
 *  $RCSfile: tlog.hxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: sz $ $Date: 2001-04-12 10:55:26 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _SOLTOOLS_TESTSHL_TLOG_HXX__
#define _SOLTOOLS_TESTSHL_TLOG_HXX__

#ifndef _OSL_FILE_HXX_
#include    <osl/file.hxx>
#endif

#ifndef _RTL_TRES_HXX_
#include <rtl/tres.hxx>
#endif

#ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_
#include "tutil.hxx"
#endif

#include <iostream>

using namespace std;

// <namespace_tstutl>
namespace tstutl {

// <class_tLog>
class tLog {

    // <private_members>
    ::osl::File*    m_logfile;              // fileobject
    ::rtl::OUString m_logname;              // name of log
    // </private_members>

    // <private_methods>
    void initialize( const ::rtl::OString& name );
    // </private_methods>

public:

    // <public_ctors>
    tLog() : m_logfile( 0 ) {
    }

    tLog( const sal_Char* name ) {
        if( name ) {
            initialize( name );
        }
        else  {
            m_logfile = 0;
        }

    }
    // </public_ctors>

    // <dtor>
    virtual ~tLog() {
        if ( m_logfile ) {
            m_logfile->close();
            delete( m_logfile );
        }
    } // </dtor>

    // <public_methods>
    inline ::rtl::OUString& getName() { return m_logname; }
    inline ::osl::File* getFile() { return m_logfile; }

    // open logfile for overwrite (default) or append
    ::osl::FileBase::RC open( sal_Bool append = sal_False );
    ::osl::FileBase::RC close();

    ::osl::FileBase::RC writeRes( ::rtl::tRes& oRes, sal_Bool v = sal_False ,
                                                  sal_Bool xml = sal_False );

    // write methods without (default) or with echo on display
    ::osl::FileBase::RC write( const sal_Char* buf, sal_Bool v = sal_False );
    // </public_methods>

}; // </class_tLog>

} // </namespace_tstutl>

#endif
<commit_msg>*** empty log message ***<commit_after>/*************************************************************************
 *
 *  $RCSfile: tlog.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: ganaya $ $Date: 2001-05-04 04:29:27 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _SOLTOOLS_TESTSHL_TLOG_HXX__
#define _SOLTOOLS_TESTSHL_TLOG_HXX__

#ifndef _OSL_FILE_HXX_
#include    <osl/file.hxx>
#endif

#ifndef _RTL_TRES_HXX_
#include <rtl/tres.hxx>
#endif

#ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_
#include "tutil.hxx"
#endif

#include <iostream>

using namespace std;

// <namespace_tstutl>
namespace tstutl {

// <class_tLog>
class tLog {

    // <private_members>
    ::osl::File*    m_logfile;              // fileobject
    ::rtl::OUString m_logname;              // name of log
    // </private_members>

    // <private_methods>
    void initialize( const ::rtl::OString& name );
    // </private_methods>

public:

    // <public_ctors>
    tLog() : m_logfile( 0 ) {
    }

    tLog( const sal_Char* name ) {
        if( name ) {
            initialize( name );
        }
        else  {
            m_logfile = 0;
        }

    }
    // </public_ctors>

    // <dtor>
    virtual ~tLog() {
        if ( m_logfile ) {
            m_logfile->close();
            delete( m_logfile );
        }
    } // </dtor>

    // <public_methods>
    inline ::rtl::OUString& getName() { return m_logname; }
    inline ::osl::File* getFile() { return m_logfile; }

    // open logfile for overwrite (default) or append
    ::osl::FileBase::RC open( sal_Bool append = sal_False );
    ::osl::FileBase::RC close();

    ::osl::FileBase::RC writeRes( ::rtl::TestResult& oRes, sal_Bool v = sal_False ,
                                                  sal_Bool xml = sal_False );

    // write methods without (default) or with echo on display
    ::osl::FileBase::RC write( const sal_Char* buf, sal_Bool v = sal_False );
    // </public_methods>

}; // </class_tLog>

} // </namespace_tstutl>

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: InsertFunctions.cxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_reportdesign.hxx"
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>

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

#include <toolkit/helper/vclunohelper.hxx>
#include <sot/exchange.hxx>
#include <svtools/globalnameitem.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/docfile.hxx>
#include <svtools/stritem.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdview.hxx>
#include <svx/pfiledlg.hxx>
#include <tools/urlobj.hxx>
#include <vcl/msgbox.hxx>
#include <svtools/urihelper.hxx>
#include <svtools/moduleoptions.hxx>
#include <svtools/insdlg.hxx>
#include <svtools/soerr.hxx>
#include <svx/svxdlg.hxx>
#include <sot/clsids.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdundo.hxx>
#include <svx/svdmodel.hxx>

#include <cppuhelper/component_context.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/property.hxx>
#include <comphelper/types.hxx>
#include <comphelper/embeddedobjectcontainer.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/chart/ChartDataRowSource.hpp>
#include <com/sun/star/chart2/data/XDataReceiver.hpp>

using namespace ::com::sun::star;

#include "InsertFunctions.hxx"
#include "RptObject.hxx"

namespace rptui
{
//------------------------------------------------------------------------
void InitializeChart( const uno::Reference< frame::XModel>& _xModel,
                      const uno::Reference < embed::XEmbeddedObject >& xObj)
{
    //ScDocShell* pDocShell = pViewData->GetDocShell();
    //ScDocument* pScDoc = pDocShell->GetDocument();

    //rtl::OUString aRangeString( rRangeParam );
    //if ( !aRangeString.getLength() )
    //{
    //    SCCOL nCol1 = 0;
    //    SCROW nRow1 = 0;
    //    SCTAB nTab1 = 0;
    //    SCCOL nCol2 = 0;
    //    SCROW nRow2 = 0;
    //    SCTAB nTab2 = 0;

    //    ScMarkData& rMark = pViewData->GetMarkData();
    //    if ( !rMark.IsMarked() )
    //        pViewData->GetView()->MarkDataArea( TRUE );

    //    if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) )
    //    {
    //        PutInOrder( nCol1, nCol2 );
    //        PutInOrder( nRow1, nRow2 );
    //        if ( nCol2>nCol1 || nRow2>nRow1 )
    //        {
    //            ScDocument* pDoc = pViewData->GetDocument();
    //            pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );

    //            String aStr;
    //            ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
    //            aRange.Format( aStr, SCR_ABS_3D, pScDoc );
    //            aRangeString = aStr;
    //        }
    //    }
    //}

    //if ( rRangeParam.getLength() )
    {
        // connect to Calc data (if no range string, leave chart alone, with its own data)

        uno::Reference< chart2::data::XDataReceiver > xReceiver;
        uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
        if( xCompSupp.is())
            xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
        OSL_ASSERT( xReceiver.is());
        if( xReceiver.is() )
        {
            // lock the model to suppress any internal updates
            uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
            if( xChartModel.is() )
                xChartModel->lockControllers();

            uno::Reference< lang::XMultiServiceFactory> xFac(_xModel,uno::UNO_QUERY_THROW);
            uno::Reference< chart2::data::XDatabaseDataProvider > xDataProvider( xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider"))),uno::UNO_QUERY);
            xReceiver->attachDataProvider( xDataProvider.get() );

            uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( _xModel, uno::UNO_QUERY );
            xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );

            uno::Sequence< beans::PropertyValue > aArgs( 4 );
            aArgs[0] = beans::PropertyValue(
                ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
                uno::makeAny( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("all")) ), beans::PropertyState_DIRECT_VALUE );
            aArgs[1] = beans::PropertyValue(
                ::rtl::OUString::createFromAscii("HasCategories"), -1,
                uno::makeAny( sal_True ), beans::PropertyState_DIRECT_VALUE );
            aArgs[2] = beans::PropertyValue(
                ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
                uno::makeAny( sal_False ), beans::PropertyState_DIRECT_VALUE );
            aArgs[3] = beans::PropertyValue(
                ::rtl::OUString::createFromAscii("DataRowSource"), -1,
                uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
            xReceiver->setArguments( aArgs );

            if( xChartModel.is() )
                xChartModel->unlockControllers();
        }
    }
}
// -----------------------------------------------------------------------------
} // namespace rptui
// -----------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS rptchart02 (1.2.4); FILE MERGED 2008/04/30 13:03:35 oj 1.2.4.3: #i88843# impl clone method 2008/04/16 06:30:23 oj 1.2.4.2: RESYNC: (1.2-1.3); FILE MERGED 2008/03/12 09:45:18 oj 1.2.4.1: impl chart handling<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: InsertFunctions.cxx,v $
 * $Revision: 1.4 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_reportdesign.hxx"
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
//------------------------------------------------------------------------

#include <toolkit/helper/vclunohelper.hxx>
#include <sot/exchange.hxx>
#include <svtools/globalnameitem.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/docfile.hxx>
#include <svtools/stritem.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdview.hxx>
#include <svx/pfiledlg.hxx>
#include <tools/urlobj.hxx>
#include <vcl/msgbox.hxx>
#include <svtools/urihelper.hxx>
#include <svtools/moduleoptions.hxx>
#include <svtools/insdlg.hxx>
#include <svtools/soerr.hxx>
#include <svx/svxdlg.hxx>
#include <sot/clsids.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdundo.hxx>
#include <svx/svdmodel.hxx>

#include <cppuhelper/component_context.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/property.hxx>
#include <comphelper/types.hxx>
#include <comphelper/embeddedobjectcontainer.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/chart/ChartDataRowSource.hpp>
#include <com/sun/star/chart2/data/XDataReceiver.hpp>

using namespace ::com::sun::star;

#include "InsertFunctions.hxx"
#include "RptObject.hxx"

namespace rptui
{
//------------------------------------------------------------------------
// -----------------------------------------------------------------------------
} // namespace rptui
// -----------------------------------------------------------------------------

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: stgelem.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: mba $ $Date: 2001-02-05 18:11:55 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

// This file reflects the structure of MS file elements.
// It is very sensitive to alignment!

#ifndef _STGELEM_HXX
#define _STGELEM_HXX

#ifndef _TOOLS_SOLAR_H
#include <tools/solar.h>
#endif

class StgIo;
class SvStream;
class String;

SvStream& operator>>( SvStream&, ClsId& );
SvStream& operator<<( SvStream&, const ClsId& );

class StgHeader
{
    BYTE    cSignature[ 8 ];            // 00 signature (see below)
    ClsId   aClsId;                     // 08 Class ID
    INT32   nVersion;                   // 18 version number
    UINT16  nByteOrder;                 // 1C Unicode byte order indicator
    INT16   nPageSize;                  // 1E 1 << nPageSize = block size
    INT16   nDataPageSize;              // 20 1 << this size == data block size
    BYTE    bDirty;                     // 22 internal dirty flag
    BYTE    cReserved[ 9 ];             // 23
    INT32   nFATSize;                   // 2C total number of FAT pages
    INT32   nTOCstrm;                   // 30 starting page for the TOC stream
    INT32   nReserved;                  // 34
    INT32   nThreshold;                 // 38 minimum file size for big data
    INT32   nDataFAT;                   // 3C page # of 1st data FAT block
    INT32   nDataFATSize;               // 40 # of data fat blocks
    INT32   nMasterChain;               // 44 chain to the next master block
    INT32   nMaster;                    // 48 # of additional master blocks
    INT32   nMasterFAT[ 109 ];          // 4C first 109 master FAT pages
public:
    StgHeader();
    void  Init();                       // initialize the header
    BOOL  Load( StgIo& );
    BOOL  Load( SvStream& );
    BOOL  Store( StgIo& );
    BOOL  Check();                      // check the signature and version
    short GetByteOrder() const          { return nByteOrder;    }
    INT32 GetTOCStart() const           { return nTOCstrm;      }
    void  SetTOCStart( INT32 n );
    INT32 GetDataFATStart() const       { return nDataFAT;      }
    void  SetDataFATStart( INT32 n );
    INT32 GetDataFATSize() const        { return nDataFATSize;  }
    void  SetDataFATSize( INT32 n );
    INT32 GetThreshold() const          { return nThreshold;    }
    short GetPageSize() const           { return nPageSize;     }
    short GetDataPageSize() const       { return nDataPageSize; }
    INT32 GetFATSize() const            { return nFATSize;      }
    void  SetFATSize( INT32 n );
    INT32 GetFATChain() const           { return nMasterChain;  }
    void  SetFATChain( INT32 n );
    INT32 GetMasters() const            { return nMaster;       }
    void  SetMasters( INT32 n );
    short GetFAT1Size() const           { return 109;           }
    const ClsId& GetClassId() const     { return aClsId;        }
    void  SetClassId( const ClsId& );
    INT32 GetFATPage( short ) const;
    void  SetFATPage( short, INT32 );
};

enum StgEntryType {                     // dir entry types:
    STG_EMPTY     = 0,
    STG_STORAGE   = 1,
    STG_STREAM    = 2,
    STG_LOCKBYTES = 3,
    STG_PROPERTY  = 4,
    STG_ROOT      = 5
};

enum StgEntryRef {                      // reference blocks:
    STG_LEFT      = 0,                  // left
    STG_RIGHT     = 1,                  // right
    STG_CHILD     = 2,                  // child
    STG_DATA      = 3                   // data start
};

enum StgEntryTime {                     // time codes:
    STG_MODIFIED  = 0,                  // last modification
    STG_ACCESSED  = 1                   // last access
};

class StgStream;

#define STGENTRY_SIZE 128

class StgEntry {                        // directory enty
    UINT16  nName[ 32 ];                // 00 name as WCHAR
    INT16   nNameLen;                   // 40 size of name in bytes including 00H
    BYTE    cType;                      // 42 entry type
    BYTE    cFlags;                     // 43 0 or 1 (tree balance?)
    INT32   nLeft;                      // 44 left node entry
    INT32   nRight;                     // 48 right node entry
    INT32   nChild;                     // 4C 1st child entry if storage
    ClsId   aClsId;                     // 50 class ID (optional)
    INT32   nFlags;                     // 60 state flags(?)
    INT32   nMtime[ 2 ];                // 64 modification time
    INT32   nAtime[ 2 ];                // 6C creation and access time
    INT32   nPage1;                     // 74 starting block (either direct or translated)
    INT32   nSize;                      // 78 file size
    INT32   nUnknown;                   // 7C unknown
    String  aName;                      // Name as Compare String (ascii, upper)
public:
    BOOL    Init();                     // initialize the data
    BOOL    SetName( const String& );   // store a name (ASCII, up to 32 chars)
    void    GetName( String& rName ) const;
                                        // fill in the name
    short   Compare( const StgEntry& ) const;   // compare two entries
    BOOL    Load( const void* );
    void    Store( void* );
    StgEntryType GetType() const        { return (StgEntryType) cType;  }
    INT32   GetStartPage() const        { return nPage1; }
    void    SetType( StgEntryType t )   { cType = (BYTE) t;             }
    BYTE    GetFlags() const            { return cFlags;                }
    void    SetFlags( BYTE c )          { cFlags = c;                   }
    INT32   GetSize() const             { return nSize;                 }
    void    SetSize( INT32 n )          { nSize = n;                    }
    const   ClsId& GetClassId() const   { return aClsId;                }
    void    SetClassId( const ClsId& );
    INT32   GetLeaf( StgEntryRef ) const;
    void    SetLeaf( StgEntryRef, INT32 );
    const   INT32* GetTime( StgEntryTime ) const;
    void    SetTime( StgEntryTime, INT32* );
};

#define STG_FREE    -1L                 // page is free
#define STG_EOF     -2L                 // page is last page in chain
#define STG_FAT     -3L                 // page is FAT page
#define STG_MASTER  -4L                 // page is master FAT page

#endif
<commit_msg>#65293# moved clsid<commit_after>/*************************************************************************
 *
 *  $RCSfile: stgelem.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2001-02-13 13:45:44 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

// This file reflects the structure of MS file elements.
// It is very sensitive to alignment!

#ifndef _STGELEM_HXX
#define _STGELEM_HXX

#ifndef _TOOLS_SOLAR_H
#include <tools/solar.h>
#endif

#include <stg.hxx>

class StgIo;
class SvStream;
class String;

SvStream& operator>>( SvStream&, ClsId& );
SvStream& operator<<( SvStream&, const ClsId& );

class StgHeader
{
    BYTE    cSignature[ 8 ];            // 00 signature (see below)
    ClsId   aClsId;                     // 08 Class ID
    INT32   nVersion;                   // 18 version number
    UINT16  nByteOrder;                 // 1C Unicode byte order indicator
    INT16   nPageSize;                  // 1E 1 << nPageSize = block size
    INT16   nDataPageSize;              // 20 1 << this size == data block size
    BYTE    bDirty;                     // 22 internal dirty flag
    BYTE    cReserved[ 9 ];             // 23
    INT32   nFATSize;                   // 2C total number of FAT pages
    INT32   nTOCstrm;                   // 30 starting page for the TOC stream
    INT32   nReserved;                  // 34
    INT32   nThreshold;                 // 38 minimum file size for big data
    INT32   nDataFAT;                   // 3C page # of 1st data FAT block
    INT32   nDataFATSize;               // 40 # of data fat blocks
    INT32   nMasterChain;               // 44 chain to the next master block
    INT32   nMaster;                    // 48 # of additional master blocks
    INT32   nMasterFAT[ 109 ];          // 4C first 109 master FAT pages
public:
    StgHeader();
    void  Init();                       // initialize the header
    BOOL  Load( StgIo& );
    BOOL  Load( SvStream& );
    BOOL  Store( StgIo& );
    BOOL  Check();                      // check the signature and version
    short GetByteOrder() const          { return nByteOrder;    }
    INT32 GetTOCStart() const           { return nTOCstrm;      }
    void  SetTOCStart( INT32 n );
    INT32 GetDataFATStart() const       { return nDataFAT;      }
    void  SetDataFATStart( INT32 n );
    INT32 GetDataFATSize() const        { return nDataFATSize;  }
    void  SetDataFATSize( INT32 n );
    INT32 GetThreshold() const          { return nThreshold;    }
    short GetPageSize() const           { return nPageSize;     }
    short GetDataPageSize() const       { return nDataPageSize; }
    INT32 GetFATSize() const            { return nFATSize;      }
    void  SetFATSize( INT32 n );
    INT32 GetFATChain() const           { return nMasterChain;  }
    void  SetFATChain( INT32 n );
    INT32 GetMasters() const            { return nMaster;       }
    void  SetMasters( INT32 n );
    short GetFAT1Size() const           { return 109;           }
    const ClsId& GetClassId() const     { return aClsId;        }
    void  SetClassId( const ClsId& );
    INT32 GetFATPage( short ) const;
    void  SetFATPage( short, INT32 );
};

enum StgEntryType {                     // dir entry types:
    STG_EMPTY     = 0,
    STG_STORAGE   = 1,
    STG_STREAM    = 2,
    STG_LOCKBYTES = 3,
    STG_PROPERTY  = 4,
    STG_ROOT      = 5
};

enum StgEntryRef {                      // reference blocks:
    STG_LEFT      = 0,                  // left
    STG_RIGHT     = 1,                  // right
    STG_CHILD     = 2,                  // child
    STG_DATA      = 3                   // data start
};

enum StgEntryTime {                     // time codes:
    STG_MODIFIED  = 0,                  // last modification
    STG_ACCESSED  = 1                   // last access
};

class StgStream;

#define STGENTRY_SIZE 128

class StgEntry {                        // directory enty
    UINT16  nName[ 32 ];                // 00 name as WCHAR
    INT16   nNameLen;                   // 40 size of name in bytes including 00H
    BYTE    cType;                      // 42 entry type
    BYTE    cFlags;                     // 43 0 or 1 (tree balance?)
    INT32   nLeft;                      // 44 left node entry
    INT32   nRight;                     // 48 right node entry
    INT32   nChild;                     // 4C 1st child entry if storage
    ClsId   aClsId;                     // 50 class ID (optional)
    INT32   nFlags;                     // 60 state flags(?)
    INT32   nMtime[ 2 ];                // 64 modification time
    INT32   nAtime[ 2 ];                // 6C creation and access time
    INT32   nPage1;                     // 74 starting block (either direct or translated)
    INT32   nSize;                      // 78 file size
    INT32   nUnknown;                   // 7C unknown
    String  aName;                      // Name as Compare String (ascii, upper)
public:
    BOOL    Init();                     // initialize the data
    BOOL    SetName( const String& );   // store a name (ASCII, up to 32 chars)
    void    GetName( String& rName ) const;
                                        // fill in the name
    short   Compare( const StgEntry& ) const;   // compare two entries
    BOOL    Load( const void* );
    void    Store( void* );
    StgEntryType GetType() const        { return (StgEntryType) cType;  }
    INT32   GetStartPage() const        { return nPage1; }
    void    SetType( StgEntryType t )   { cType = (BYTE) t;             }
    BYTE    GetFlags() const            { return cFlags;                }
    void    SetFlags( BYTE c )          { cFlags = c;                   }
    INT32   GetSize() const             { return nSize;                 }
    void    SetSize( INT32 n )          { nSize = n;                    }
    const   ClsId& GetClassId() const   { return aClsId;                }
    void    SetClassId( const ClsId& );
    INT32   GetLeaf( StgEntryRef ) const;
    void    SetLeaf( StgEntryRef, INT32 );
    const   INT32* GetTime( StgEntryTime ) const;
    void    SetTime( StgEntryTime, INT32* );
};

#define STG_FREE    -1L                 // page is free
#define STG_EOF     -2L                 // page is last page in chain
#define STG_FAT     -3L                 // page is FAT page
#define STG_MASTER  -4L                 // page is master FAT page

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: NeonTypes.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: obo $ $Date: 2005-01-27 12:13:58 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _NEONTYPES_HXX_
#define _NEONTYPES_HXX_

#ifndef NE_SESSION_H
#include <neon/ne_session.h> // for ne_session
#endif
#ifndef NE_UTILS_H
#include <neon/ne_utils.h> // for ne_status
#endif
#ifndef NE_BASIC_H
#include <neon/ne_basic.h> // for ne_server_capabilities
#endif
#ifndef NE_PROPS_H
#include <neon/ne_props.h> // for ne_propname, ne_prop_result_set
#endif

typedef ne_session                  HttpSession;
typedef ne_status                   HttpStatus;
typedef ne_server_capabilities      HttpServerCapabilities;

typedef ne_propname                 NeonPropName;
typedef ne_prop_result_set          NeonPropFindResultSet;

#endif // _NEONTYPES_HXX_
<commit_msg>INTEGRATION: CWS ooo19126 (1.9.34); FILE MERGED 2005/09/05 18:45:37 rt 1.9.34.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: NeonTypes.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 16:13:33 $
 *
 *  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
 *
 ************************************************************************/

#ifndef _NEONTYPES_HXX_
#define _NEONTYPES_HXX_

#ifndef NE_SESSION_H
#include <neon/ne_session.h> // for ne_session
#endif
#ifndef NE_UTILS_H
#include <neon/ne_utils.h> // for ne_status
#endif
#ifndef NE_BASIC_H
#include <neon/ne_basic.h> // for ne_server_capabilities
#endif
#ifndef NE_PROPS_H
#include <neon/ne_props.h> // for ne_propname, ne_prop_result_set
#endif

typedef ne_session                  HttpSession;
typedef ne_status                   HttpStatus;
typedef ne_server_capabilities      HttpServerCapabilities;

typedef ne_propname                 NeonPropName;
typedef ne_prop_result_set          NeonPropFindResultSet;

#endif // _NEONTYPES_HXX_
<|endoftext|>


<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/cursor/cursor_loader_x11.h"

#include <X11/Xlib.h>
#include <X11/cursorfont.h>

#include "base/logging.h"
#include "grit/ui_resources.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"

namespace {

// Returns X font cursor shape from an Aura cursor.
int CursorShapeFromNative(gfx::NativeCursor native_cursor) {
  switch (native_cursor.native_type()) {
    case ui::kCursorMiddlePanning:
      return XC_fleur;
    case ui::kCursorEastPanning:
      return XC_sb_right_arrow;
    case ui::kCursorNorthPanning:
      return XC_sb_up_arrow;
    case ui::kCursorNorthEastPanning:
      return XC_top_right_corner;
    case ui::kCursorNorthWestPanning:
      return XC_top_left_corner;
    case ui::kCursorSouthPanning:
      return XC_sb_down_arrow;
    case ui::kCursorSouthEastPanning:
      return XC_bottom_right_corner;
    case ui::kCursorSouthWestPanning:
      return XC_bottom_left_corner;
    case ui::kCursorWestPanning:
      return XC_sb_left_arrow;
    case ui::kCursorNone:
    case ui::kCursorGrab:
    case ui::kCursorGrabbing:
      // TODO(jamescook): Need cursors for these.  crbug.com/111650
      return XC_left_ptr;

#if defined(OS_CHROMEOS)
    case ui::kCursorNull:
    case ui::kCursorPointer:
    case ui::kCursorNoDrop:
    case ui::kCursorNotAllowed:
    case ui::kCursorCopy:
    case ui::kCursorMove:
    case ui::kCursorEastResize:
    case ui::kCursorNorthResize:
    case ui::kCursorSouthResize:
    case ui::kCursorWestResize:
    case ui::kCursorNorthEastResize:
    case ui::kCursorNorthWestResize:
    case ui::kCursorSouthWestResize:
    case ui::kCursorSouthEastResize:
    case ui::kCursorIBeam:
    case ui::kCursorAlias:
    case ui::kCursorCell:
    case ui::kCursorContextMenu:
    case ui::kCursorCross:
    case ui::kCursorHelp:
    case ui::kCursorWait:
    case ui::kCursorNorthSouthResize:
    case ui::kCursorEastWestResize:
    case ui::kCursorNorthEastSouthWestResize:
    case ui::kCursorNorthWestSouthEastResize:
    case ui::kCursorProgress:
    case ui::kCursorColumnResize:
    case ui::kCursorRowResize:
    case ui::kCursorVerticalText:
    case ui::kCursorZoomIn:
    case ui::kCursorZoomOut:
      // In some environments, the image assets are not set (e.g. in
      // content-browsertests, content-shell etc.).
      return XC_left_ptr;
#else  // defined(OS_CHROMEOS)
    case ui::kCursorNull:
      return XC_left_ptr;
    case ui::kCursorPointer:
      return XC_left_ptr;
    case ui::kCursorMove:
      return XC_fleur;
    case ui::kCursorCross:
      return XC_crosshair;
    case ui::kCursorHand:
      return XC_hand2;
    case ui::kCursorIBeam:
      return XC_xterm;
    case ui::kCursorWait:
      return XC_watch;
    case ui::kCursorHelp:
      return XC_question_arrow;
    case ui::kCursorEastResize:
      return XC_right_side;
    case ui::kCursorNorthResize:
      return XC_top_side;
    case ui::kCursorNorthEastResize:
      return XC_top_right_corner;
    case ui::kCursorNorthWestResize:
      return XC_top_left_corner;
    case ui::kCursorSouthResize:
      return XC_bottom_side;
    case ui::kCursorSouthEastResize:
      return XC_bottom_right_corner;
    case ui::kCursorSouthWestResize:
      return XC_bottom_left_corner;
    case ui::kCursorWestResize:
      return XC_left_side;
    case ui::kCursorNorthSouthResize:
      return XC_sb_v_double_arrow;
    case ui::kCursorEastWestResize:
      return XC_sb_h_double_arrow;
    case ui::kCursorNorthEastSouthWestResize:
    case ui::kCursorNorthWestSouthEastResize:
      // There isn't really a useful cursor available for these.
      return XC_left_ptr;
    case ui::kCursorColumnResize:
      return XC_sb_h_double_arrow;
    case ui::kCursorRowResize:
      return XC_sb_v_double_arrow;
#endif  // defined(OS_CHROMEOS)
    case ui::kCursorCustom:
      NOTREACHED();
      return XC_left_ptr;
  }
  NOTREACHED() << "Case not handled for " << native_cursor.native_type();
  return XC_left_ptr;
}

}  // namespace

namespace ui {

CursorLoader* CursorLoader::Create() {
  return new CursorLoaderX11;
}

CursorLoaderX11::CursorLoaderX11()
    : invisible_cursor_(CreateInvisibleCursor(), GetXDisplay()) {
}

CursorLoaderX11::~CursorLoaderX11() {
  UnloadAll();
  // Clears XCursorCache.
  GetXCursor(kCursorClearXCursorCache);
}

void CursorLoaderX11::LoadImageCursor(int id,
                                      int resource_id,
                                      const gfx::Point& hot) {
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
      GetScaleFactorFromScale(device_scale_factor()));
  XcursorImage* x_image =
      SkBitmapToXcursorImage(&image_rep.sk_bitmap(), hot);
  cursors_[id] = CreateReffedCustomXCursor(x_image);
  // |image_rep| is owned by the resource bundle. So we do not need to free it.
}

void CursorLoaderX11::LoadAnimatedCursor(int id,
                                         int resource_id,
                                         const gfx::Point& hot,
                                         int frame_delay_ms) {
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
      GetScaleFactorFromScale(device_scale_factor()));
  const SkBitmap bitmap = image_rep.sk_bitmap();
  DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config);
  int frame_width = bitmap.height();
  int frame_height = frame_width;
  int total_width = bitmap.width();
  DCHECK_EQ(total_width % frame_width, 0);
  int frame_count = total_width / frame_width;
  DCHECK_GT(frame_count, 0);
  XcursorImages* x_images = XcursorImagesCreate(frame_count);
  x_images->nimage = frame_count;
  bitmap.lockPixels();
  unsigned int* pixels = bitmap.getAddr32(0, 0);
  // Create each frame.
  for (int frame = 0; frame < frame_count; ++frame) {
    XcursorImage* x_image = XcursorImageCreate(frame_width, frame_height);
    for (int row = 0; row < frame_height; ++row) {
      // Copy |row|'th row of |frame|'th frame.
      memcpy(x_image->pixels + row * frame_width,
             pixels + frame * frame_width + row * total_width,
             frame_width * 4);
    }
    x_image->xhot = hot.x();
    x_image->yhot = hot.y();
    x_image->delay = frame_delay_ms;
    x_images->images[frame] = x_image;
  }
  bitmap.unlockPixels();

  animated_cursors_[id] = std::make_pair(
      XcursorImagesLoadCursor(GetXDisplay(), x_images), x_images);
  // |bitmap| is owned by the resource bundle. So we do not need to free it.
}

void CursorLoaderX11::UnloadAll() {
  for (ImageCursorMap::const_iterator it = cursors_.begin();
       it != cursors_.end(); ++it)
    UnrefCustomXCursor(it->second);

  // Free animated cursors and images.
  for (AnimatedCursorMap::iterator it = animated_cursors_.begin();
       it != animated_cursors_.end(); ++it) {
    XcursorImagesDestroy(it->second.second);  // also frees individual frames.
    XFreeCursor(GetXDisplay(), it->second.first);
  }
}

void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) {
  DCHECK(cursor);

  ::Cursor xcursor;
  if (IsImageCursor(*cursor))
    xcursor = ImageCursorFromNative(*cursor);
  else if (*cursor == kCursorNone)
    xcursor =  invisible_cursor_.get();
  else if (*cursor == kCursorCustom)
    xcursor = cursor->platform();
  else if (device_scale_factor() == 1.0f)
    xcursor = GetXCursor(CursorShapeFromNative(*cursor));
  else
    xcursor = ImageCursorFromNative(kCursorPointer);

  cursor->SetPlatformCursor(xcursor);
}

bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) {
  int type = native_cursor.native_type();
  return cursors_.count(type) || animated_cursors_.count(type);
}

::Cursor CursorLoaderX11::ImageCursorFromNative(
    gfx::NativeCursor native_cursor) {
  int type = native_cursor.native_type();
  if (animated_cursors_.count(type))
    return animated_cursors_[type].first;

  ImageCursorMap::iterator find = cursors_.find(type);
  if (find != cursors_.end())
    return cursors_[type];
  return GetXCursor(CursorShapeFromNative(native_cursor));
}

}  // namespace ui
<commit_msg>Fixing crash with Chrome upon cursor access<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/cursor/cursor_loader_x11.h"

#include <X11/Xlib.h>
#include <X11/cursorfont.h>

#include "base/logging.h"
#include "grit/ui_resources.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"

namespace {

// Returns X font cursor shape from an Aura cursor.
int CursorShapeFromNative(gfx::NativeCursor native_cursor) {
  switch (native_cursor.native_type()) {
    case ui::kCursorMiddlePanning:
      return XC_fleur;
    case ui::kCursorEastPanning:
      return XC_sb_right_arrow;
    case ui::kCursorNorthPanning:
      return XC_sb_up_arrow;
    case ui::kCursorNorthEastPanning:
      return XC_top_right_corner;
    case ui::kCursorNorthWestPanning:
      return XC_top_left_corner;
    case ui::kCursorSouthPanning:
      return XC_sb_down_arrow;
    case ui::kCursorSouthEastPanning:
      return XC_bottom_right_corner;
    case ui::kCursorSouthWestPanning:
      return XC_bottom_left_corner;
    case ui::kCursorWestPanning:
      return XC_sb_left_arrow;
    case ui::kCursorNone:
    case ui::kCursorGrab:
    case ui::kCursorGrabbing:
      // TODO(jamescook): Need cursors for these.  crbug.com/111650
      return XC_left_ptr;

#if defined(OS_CHROMEOS)
    case ui::kCursorNull:
    case ui::kCursorPointer:
    case ui::kCursorNoDrop:
    case ui::kCursorNotAllowed:
    case ui::kCursorCopy:
    case ui::kCursorMove:
    case ui::kCursorEastResize:
    case ui::kCursorNorthResize:
    case ui::kCursorSouthResize:
    case ui::kCursorWestResize:
    case ui::kCursorNorthEastResize:
    case ui::kCursorNorthWestResize:
    case ui::kCursorSouthWestResize:
    case ui::kCursorSouthEastResize:
    case ui::kCursorIBeam:
    case ui::kCursorAlias:
    case ui::kCursorCell:
    case ui::kCursorContextMenu:
    case ui::kCursorCross:
    case ui::kCursorHelp:
    case ui::kCursorWait:
    case ui::kCursorNorthSouthResize:
    case ui::kCursorEastWestResize:
    case ui::kCursorNorthEastSouthWestResize:
    case ui::kCursorNorthWestSouthEastResize:
    case ui::kCursorProgress:
    case ui::kCursorColumnResize:
    case ui::kCursorRowResize:
    case ui::kCursorVerticalText:
    case ui::kCursorZoomIn:
    case ui::kCursorZoomOut:
    case ui::kCursorHand:
      // In some environments, the image assets are not set (e.g. in
      // content-browsertests, content-shell etc.).
      return XC_left_ptr;
#else  // defined(OS_CHROMEOS)
    case ui::kCursorNull:
      return XC_left_ptr;
    case ui::kCursorPointer:
      return XC_left_ptr;
    case ui::kCursorMove:
      return XC_fleur;
    case ui::kCursorCross:
      return XC_crosshair;
    case ui::kCursorHand:
      return XC_hand2;
    case ui::kCursorIBeam:
      return XC_xterm;
    case ui::kCursorWait:
      return XC_watch;
    case ui::kCursorHelp:
      return XC_question_arrow;
    case ui::kCursorEastResize:
      return XC_right_side;
    case ui::kCursorNorthResize:
      return XC_top_side;
    case ui::kCursorNorthEastResize:
      return XC_top_right_corner;
    case ui::kCursorNorthWestResize:
      return XC_top_left_corner;
    case ui::kCursorSouthResize:
      return XC_bottom_side;
    case ui::kCursorSouthEastResize:
      return XC_bottom_right_corner;
    case ui::kCursorSouthWestResize:
      return XC_bottom_left_corner;
    case ui::kCursorWestResize:
      return XC_left_side;
    case ui::kCursorNorthSouthResize:
      return XC_sb_v_double_arrow;
    case ui::kCursorEastWestResize:
      return XC_sb_h_double_arrow;
    case ui::kCursorNorthEastSouthWestResize:
    case ui::kCursorNorthWestSouthEastResize:
      // There isn't really a useful cursor available for these.
      return XC_left_ptr;
    case ui::kCursorColumnResize:
      return XC_sb_h_double_arrow;
    case ui::kCursorRowResize:
      return XC_sb_v_double_arrow;
#endif  // defined(OS_CHROMEOS)
    case ui::kCursorCustom:
      NOTREACHED();
      return XC_left_ptr;
  }
  NOTREACHED() << "Case not handled for " << native_cursor.native_type();
  return XC_left_ptr;
}

}  // namespace

namespace ui {

CursorLoader* CursorLoader::Create() {
  return new CursorLoaderX11;
}

CursorLoaderX11::CursorLoaderX11()
    : invisible_cursor_(CreateInvisibleCursor(), GetXDisplay()) {
}

CursorLoaderX11::~CursorLoaderX11() {
  UnloadAll();
  // Clears XCursorCache.
  GetXCursor(kCursorClearXCursorCache);
}

void CursorLoaderX11::LoadImageCursor(int id,
                                      int resource_id,
                                      const gfx::Point& hot) {
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
      GetScaleFactorFromScale(device_scale_factor()));
  XcursorImage* x_image =
      SkBitmapToXcursorImage(&image_rep.sk_bitmap(), hot);
  cursors_[id] = CreateReffedCustomXCursor(x_image);
  // |image_rep| is owned by the resource bundle. So we do not need to free it.
}

void CursorLoaderX11::LoadAnimatedCursor(int id,
                                         int resource_id,
                                         const gfx::Point& hot,
                                         int frame_delay_ms) {
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
      GetScaleFactorFromScale(device_scale_factor()));
  const SkBitmap bitmap = image_rep.sk_bitmap();
  DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config);
  int frame_width = bitmap.height();
  int frame_height = frame_width;
  int total_width = bitmap.width();
  DCHECK_EQ(total_width % frame_width, 0);
  int frame_count = total_width / frame_width;
  DCHECK_GT(frame_count, 0);
  XcursorImages* x_images = XcursorImagesCreate(frame_count);
  x_images->nimage = frame_count;
  bitmap.lockPixels();
  unsigned int* pixels = bitmap.getAddr32(0, 0);
  // Create each frame.
  for (int frame = 0; frame < frame_count; ++frame) {
    XcursorImage* x_image = XcursorImageCreate(frame_width, frame_height);
    for (int row = 0; row < frame_height; ++row) {
      // Copy |row|'th row of |frame|'th frame.
      memcpy(x_image->pixels + row * frame_width,
             pixels + frame * frame_width + row * total_width,
             frame_width * 4);
    }
    x_image->xhot = hot.x();
    x_image->yhot = hot.y();
    x_image->delay = frame_delay_ms;
    x_images->images[frame] = x_image;
  }
  bitmap.unlockPixels();

  animated_cursors_[id] = std::make_pair(
      XcursorImagesLoadCursor(GetXDisplay(), x_images), x_images);
  // |bitmap| is owned by the resource bundle. So we do not need to free it.
}

void CursorLoaderX11::UnloadAll() {
  for (ImageCursorMap::const_iterator it = cursors_.begin();
       it != cursors_.end(); ++it)
    UnrefCustomXCursor(it->second);

  // Free animated cursors and images.
  for (AnimatedCursorMap::iterator it = animated_cursors_.begin();
       it != animated_cursors_.end(); ++it) {
    XcursorImagesDestroy(it->second.second);  // also frees individual frames.
    XFreeCursor(GetXDisplay(), it->second.first);
  }
}

void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) {
  DCHECK(cursor);

  ::Cursor xcursor;
  if (IsImageCursor(*cursor))
    xcursor = ImageCursorFromNative(*cursor);
  else if (*cursor == kCursorNone)
    xcursor =  invisible_cursor_.get();
  else if (*cursor == kCursorCustom)
    xcursor = cursor->platform();
  else if (device_scale_factor() == 1.0f)
    xcursor = GetXCursor(CursorShapeFromNative(*cursor));
  else
    xcursor = ImageCursorFromNative(kCursorPointer);

  cursor->SetPlatformCursor(xcursor);
}

bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) {
  int type = native_cursor.native_type();
  return cursors_.count(type) || animated_cursors_.count(type);
}

::Cursor CursorLoaderX11::ImageCursorFromNative(
    gfx::NativeCursor native_cursor) {
  int type = native_cursor.native_type();
  if (animated_cursors_.count(type))
    return animated_cursors_[type].first;

  ImageCursorMap::iterator find = cursors_.find(type);
  if (find != cursors_.end())
    return cursors_[type];
  return GetXCursor(CursorShapeFromNative(native_cursor));
}

}  // namespace ui
<|endoftext|>


<commit_before>/*************************************************************************/
/*  file_access_memory.cpp                                               */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#include "file_access_memory.h"

#include "os/dir_access.h"
#include "os/copymem.h"
#include "globals.h"
#include "map.h"

static Map<String, Vector<uint8_t> >* files = NULL;

void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {

	if (!files) {
		files = memnew((Map<String, Vector<uint8_t> >));
	};

	String name;
	if (Globals::get_singleton())
		name = Globals::get_singleton()->globalize_path(p_name);
	else
		name = p_name;
	name = DirAccess::normalize_path(name);

	(*files)[name] = p_data;
};

void FileAccessMemory::cleanup() {

	if (!files)
		return;

	memdelete(files);
};

FileAccess* FileAccessMemory::create() {

	return memnew(FileAccessMemory);
};

bool FileAccessMemory::file_exists(const String& p_name) {

	String name = fix_path(p_name);
	name = DirAccess::normalize_path(name);

	return files && (files->find(name) != NULL);
};

Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {

	ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);

	String name = fix_path(p_path);
	name = DirAccess::normalize_path(name);

	Map<String, Vector<uint8_t> >::Element* E = files->find(name);
	ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND);

	data = &(E->get()[0]);
	length = E->get().size();
	pos = 0;

	return OK;
};

void FileAccessMemory::close() {

	data = NULL;
};

bool FileAccessMemory::is_open() const {

	return data != NULL;
};

void FileAccessMemory::seek(size_t p_position) {

	ERR_FAIL_COND(!data);
	pos = p_position;
};

void FileAccessMemory::seek_end(int64_t p_position) {

	ERR_FAIL_COND(!data);
	pos = length + p_position;
};

size_t FileAccessMemory::get_pos() const {

	ERR_FAIL_COND_V(!data, 0);
	return pos;
};

size_t FileAccessMemory::get_len() const {

	ERR_FAIL_COND_V(!data, 0);
	return length;
};

bool FileAccessMemory::eof_reached() const {

	return pos >= length;
};

uint8_t FileAccessMemory::get_8() const {

	uint8_t ret = 0;
	if (pos < length) {
		ret = data[pos];
	};
	++pos;

	return ret;
};

int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const {

	ERR_FAIL_COND_V(!data, -1);

	int left = length - pos;
	int read = MIN(p_length, left);

	if (read < p_length) {
		WARN_PRINT("Reading less data than requested");
	};

	copymem(p_dst, &data[pos], read);
	pos += p_length;

	return read;
};

Error FileAccessMemory::get_error() const {

	return pos >= length ? ERR_FILE_EOF : OK;
};

void FileAccessMemory::store_8(uint8_t p_byte) {

	ERR_FAIL_COND(!data);
	ERR_FAIL_COND(pos >= length);
	data[pos++] = p_byte;
};

void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) {

	int left = length - pos;
	int write = MIN(p_length, left);
	if (write < p_length) {
		WARN_PRINT("Writing less data than requested");
	};

	copymem(&data[pos], p_src, write);
	pos += p_length;
};

FileAccessMemory::FileAccessMemory() {

	data = NULL;
}
<commit_msg>removed unnecessary semicolons<commit_after>/*************************************************************************/
/*  file_access_memory.cpp                                               */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#include "file_access_memory.h"

#include "os/dir_access.h"
#include "os/copymem.h"
#include "globals.h"
#include "map.h"

static Map<String, Vector<uint8_t> >* files = NULL;

void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {

	if (!files) {
		files = memnew((Map<String, Vector<uint8_t> >));
	}

	String name;
	if (Globals::get_singleton())
		name = Globals::get_singleton()->globalize_path(p_name);
	else
		name = p_name;
	name = DirAccess::normalize_path(name);

	(*files)[name] = p_data;
}

void FileAccessMemory::cleanup() {

	if (!files)
		return;

	memdelete(files);
}

FileAccess* FileAccessMemory::create() {

	return memnew(FileAccessMemory);
}

bool FileAccessMemory::file_exists(const String& p_name) {

	String name = fix_path(p_name);
	name = DirAccess::normalize_path(name);

	return files && (files->find(name) != NULL);
}

Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {

	ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);

	String name = fix_path(p_path);
	name = DirAccess::normalize_path(name);

	Map<String, Vector<uint8_t> >::Element* E = files->find(name);
	ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND);

	data = &(E->get()[0]);
	length = E->get().size();
	pos = 0;

	return OK;
}

void FileAccessMemory::close() {

	data = NULL;
}

bool FileAccessMemory::is_open() const {

	return data != NULL;
}

void FileAccessMemory::seek(size_t p_position) {

	ERR_FAIL_COND(!data);
	pos = p_position;
}

void FileAccessMemory::seek_end(int64_t p_position) {

	ERR_FAIL_COND(!data);
	pos = length + p_position;
}

size_t FileAccessMemory::get_pos() const {

	ERR_FAIL_COND_V(!data, 0);
	return pos;
}

size_t FileAccessMemory::get_len() const {

	ERR_FAIL_COND_V(!data, 0);
	return length;
}

bool FileAccessMemory::eof_reached() const {

	return pos >= length;
}

uint8_t FileAccessMemory::get_8() const {

	uint8_t ret = 0;
	if (pos < length) {
		ret = data[pos];
	}
	++pos;

	return ret;
}

int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const {

	ERR_FAIL_COND_V(!data, -1);

	int left = length - pos;
	int read = MIN(p_length, left);

	if (read < p_length) {
		WARN_PRINT("Reading less data than requested");
	};

	copymem(p_dst, &data[pos], read);
	pos += p_length;

	return read;
}

Error FileAccessMemory::get_error() const {

	return pos >= length ? ERR_FILE_EOF : OK;
}

void FileAccessMemory::store_8(uint8_t p_byte) {

	ERR_FAIL_COND(!data);
	ERR_FAIL_COND(pos >= length);
	data[pos++] = p_byte;
}

void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) {

	int left = length - pos;
	int write = MIN(p_length, left);
	if (write < p_length) {
		WARN_PRINT("Writing less data than requested");
	}

	copymem(&data[pos], p_src, write);
	pos += p_length;
}

FileAccessMemory::FileAccessMemory() {

	data = NULL;
}
<|endoftext|>


<commit_before>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtp_format_vp8.h"

#include <cassert>  // assert
#include <string.h> // memcpy

namespace webrtc {

// Define how the VP8PacketizerModes are implemented.
// Modes are: kStrict, kAggregate, kSloppy.
const RtpFormatVp8::AggregationMode RtpFormatVp8::aggr_modes_[kNumModes] =
    { kAggrNone, kAggrPartitions, kAggrFragments };
const bool RtpFormatVp8::balance_modes_[kNumModes] =
    { true, true, false };
const bool RtpFormatVp8::separate_first_modes_[kNumModes] =
    { true, false, false };

RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
                           WebRtc_UWord32 payload_size,
                           const RTPVideoHeaderVP8& hdr_info,
                           const RTPFragmentationHeader& fragmentation,
                           VP8PacketizerMode mode)
    : payload_data_(payload_data),
      payload_size_(static_cast<int>(payload_size)),
      payload_bytes_sent_(0),
      part_ix_(0),
      beginning_(true),
      first_fragment_(true),
      vp8_header_bytes_(1),
      aggr_mode_(aggr_modes_[mode]),
      balance_(balance_modes_[mode]),
      separate_first_(separate_first_modes_[mode]),
      hdr_info_(hdr_info)
{
    part_info_ = fragmentation;
}

RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
                           WebRtc_UWord32 payload_size,
                           const RTPVideoHeaderVP8& hdr_info)
    : payload_data_(payload_data),
      payload_size_(static_cast<int>(payload_size)),
      part_info_(),
      payload_bytes_sent_(0),
      part_ix_(0),
      beginning_(true),
      first_fragment_(true),
      vp8_header_bytes_(1),
      aggr_mode_(aggr_modes_[kSloppy]),
      balance_(balance_modes_[kSloppy]),
      separate_first_(separate_first_modes_[kSloppy]),
      hdr_info_(hdr_info)
{
    part_info_.VerifyAndAllocateFragmentationHeader(1);
    part_info_.fragmentationLength[0] = payload_size;
    part_info_.fragmentationOffset[0] = 0;
}

int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes,
                               bool split_payload) const
{
    if (max_payload_len == 0 || remaining_bytes == 0)
    {
        return 0;
    }
    if (!split_payload)
    {
        return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
    }

    if (balance_)
    {
        // Balance payload sizes to produce (almost) equal size
        // fragments.
        // Number of fragments for remaining_bytes:
        int num_frags = remaining_bytes / max_payload_len + 1;
        // Number of bytes in this fragment:
        return static_cast<int>(static_cast<double>(remaining_bytes)
            / num_frags + 0.5);
    }
    else
    {
        return max_payload_len >= remaining_bytes ? remaining_bytes
            : max_payload_len;
    }
}

int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
                             int* bytes_to_send, bool* last_packet)
{
    const int num_partitions = part_info_.fragmentationVectorSize;
    int send_bytes = 0; // How much data to send in this packet.
    bool split_payload = true; // Splitting of partitions is initially allowed.
    int remaining_in_partition = part_info_.fragmentationOffset[part_ix_] -
        payload_bytes_sent_ + part_info_.fragmentationLength[part_ix_] +
        FirstHeaderExtraLength(); // Add header extra length to payload length.
    int rem_payload_len = max_payload_len - vp8_header_bytes_;
    const int first_partition_in_packet = part_ix_;

    while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
        split_payload))
    {
        send_bytes += next_size;
        rem_payload_len -= next_size;
        remaining_in_partition -= next_size;

        if (remaining_in_partition == 0 && !(beginning_ && separate_first_))
        {
            // Advance to next partition?
            // Check that there are more partitions; verify that we are either
            // allowed to aggregate fragments, or that we are allowed to
            // aggregate intact partitions and that we started this packet
            // with an intact partition (indicated by first_fragment_ == true).
            if (part_ix_ + 1 < num_partitions &&
                ((aggr_mode_ == kAggrFragments) ||
                 (aggr_mode_ == kAggrPartitions && first_fragment_)))
            {
                remaining_in_partition
                    = part_info_.fragmentationLength[++part_ix_];
                // Disallow splitting unless kAggrFragments. In kAggrPartitions,
                // we can only aggregate intact partitions.
                split_payload = (aggr_mode_ == kAggrFragments);
            }
        }
        else if (balance_ && remaining_in_partition > 0)
        {
            break;
        }
    }
    if (remaining_in_partition == 0)
    {
        ++part_ix_; // Advance to next partition.
    }

    send_bytes -= FirstHeaderExtraLength(); // Remove the extra length again.
    assert(send_bytes > 0);
    const bool end_of_fragment = (remaining_in_partition == 0);
    // Write the payload header and the payload to buffer.
    *bytes_to_send = WriteHeaderAndPayload(send_bytes, end_of_fragment, buffer,
        max_payload_len);
    if (*bytes_to_send < 0)
    {
        return -1;
    }

    *last_packet = (payload_bytes_sent_ >= payload_size_);
    assert(!*last_packet || (payload_bytes_sent_ == payload_size_));
    return first_partition_in_packet;
}

int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
                                        bool end_of_fragment,
                                        WebRtc_UWord8* buffer,
                                        int buffer_length)
{
    // Write the VP8 payload header.
    //  0                   1                   2
    //  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // | RSV |I|N|FI |B|   PictureID (1 or 2 octets)   |
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    if (payload_bytes < 0)
    {
        return -1;
    }
    if (payload_bytes_sent_ + payload_bytes > payload_size_)
    {
        return -1;
    }

    buffer[0] = 0;
    if (hdr_info_.nonReference) buffer[0] |= (0x01 << 3); // N
    buffer[0] |= (GetFIFlag(end_of_fragment) << 1); // FI
    if (beginning_) buffer[0] |= 0x01; // B

    int pic_id_len = WritePictureID(&buffer[vp8_header_bytes_],
        buffer_length - vp8_header_bytes_);
    if (pic_id_len < 0) return pic_id_len; // error
    if (pic_id_len > 0) buffer[0] |= (0x01 << 4); // I

    if (vp8_header_bytes_ + pic_id_len + payload_bytes > buffer_length)
    {
        return -1;
    }
    memcpy(&buffer[vp8_header_bytes_ + pic_id_len],
        &payload_data_[payload_bytes_sent_], payload_bytes);

    beginning_ = false; // next packet cannot be first packet in frame
    // next packet starts new fragment if this ended one
    first_fragment_ = end_of_fragment;
    payload_bytes_sent_ += payload_bytes;

    // Return total length of written data.
    return payload_bytes + vp8_header_bytes_ + pic_id_len;
}

int RtpFormatVp8::WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const
{
    const WebRtc_UWord16 pic_id =
        static_cast<WebRtc_UWord16> (hdr_info_.pictureId);
    int picture_id_len = PictureIdLength();
    if (picture_id_len > buffer_length) return -1; // error
    if (picture_id_len == 2)
    {
        buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F);
        buffer[1] = pic_id & 0xFF;
    }
    else if (picture_id_len == 1)
    {
        buffer[0] = pic_id & 0x7F;
    }
    return picture_id_len;
}

int RtpFormatVp8::FirstHeaderExtraLength() const
{
    if (!beginning_)
    {
        return 0;
    }
    int length = 0;

    length += PictureIdLength();

    return length;
}

int RtpFormatVp8::PictureIdLength() const
{
    if (!beginning_ || hdr_info_.pictureId == kNoPictureId)
    {
        return 0;
    }
    if (hdr_info_.pictureId <= 0x7F)
    {
        return 1;
    }
    else
    {
        return 2;
    }
}

int RtpFormatVp8::GetFIFlag(bool end_of_fragment) const
{
    if (first_fragment_ && end_of_fragment) {
        return 0x0;
    }
    else if (first_fragment_ && !end_of_fragment) {
        return 0x1;
    }
    else if (!first_fragment_ && !end_of_fragment) {
        return 0x2;
    }
    else if (!first_fragment_ && end_of_fragment) {
        return 0x3;
    }
}

} // namespace webrtc
<commit_msg>Add return value Review URL: http://webrtc-codereview.appspot.com/98004<commit_after>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtp_format_vp8.h"

#include <cassert>  // assert
#include <string.h> // memcpy

namespace webrtc {

// Define how the VP8PacketizerModes are implemented.
// Modes are: kStrict, kAggregate, kSloppy.
const RtpFormatVp8::AggregationMode RtpFormatVp8::aggr_modes_[kNumModes] =
    { kAggrNone, kAggrPartitions, kAggrFragments };
const bool RtpFormatVp8::balance_modes_[kNumModes] =
    { true, true, false };
const bool RtpFormatVp8::separate_first_modes_[kNumModes] =
    { true, false, false };

RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
                           WebRtc_UWord32 payload_size,
                           const RTPVideoHeaderVP8& hdr_info,
                           const RTPFragmentationHeader& fragmentation,
                           VP8PacketizerMode mode)
    : payload_data_(payload_data),
      payload_size_(static_cast<int>(payload_size)),
      payload_bytes_sent_(0),
      part_ix_(0),
      beginning_(true),
      first_fragment_(true),
      vp8_header_bytes_(1),
      aggr_mode_(aggr_modes_[mode]),
      balance_(balance_modes_[mode]),
      separate_first_(separate_first_modes_[mode]),
      hdr_info_(hdr_info)
{
    part_info_ = fragmentation;
}

RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
                           WebRtc_UWord32 payload_size,
                           const RTPVideoHeaderVP8& hdr_info)
    : payload_data_(payload_data),
      payload_size_(static_cast<int>(payload_size)),
      part_info_(),
      payload_bytes_sent_(0),
      part_ix_(0),
      beginning_(true),
      first_fragment_(true),
      vp8_header_bytes_(1),
      aggr_mode_(aggr_modes_[kSloppy]),
      balance_(balance_modes_[kSloppy]),
      separate_first_(separate_first_modes_[kSloppy]),
      hdr_info_(hdr_info)
{
    part_info_.VerifyAndAllocateFragmentationHeader(1);
    part_info_.fragmentationLength[0] = payload_size;
    part_info_.fragmentationOffset[0] = 0;
}

int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes,
                               bool split_payload) const
{
    if (max_payload_len == 0 || remaining_bytes == 0)
    {
        return 0;
    }
    if (!split_payload)
    {
        return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
    }

    if (balance_)
    {
        // Balance payload sizes to produce (almost) equal size
        // fragments.
        // Number of fragments for remaining_bytes:
        int num_frags = remaining_bytes / max_payload_len + 1;
        // Number of bytes in this fragment:
        return static_cast<int>(static_cast<double>(remaining_bytes)
            / num_frags + 0.5);
    }
    else
    {
        return max_payload_len >= remaining_bytes ? remaining_bytes
            : max_payload_len;
    }
}

int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
                             int* bytes_to_send, bool* last_packet)
{
    const int num_partitions = part_info_.fragmentationVectorSize;
    int send_bytes = 0; // How much data to send in this packet.
    bool split_payload = true; // Splitting of partitions is initially allowed.
    int remaining_in_partition = part_info_.fragmentationOffset[part_ix_] -
        payload_bytes_sent_ + part_info_.fragmentationLength[part_ix_] +
        FirstHeaderExtraLength(); // Add header extra length to payload length.
    int rem_payload_len = max_payload_len - vp8_header_bytes_;
    const int first_partition_in_packet = part_ix_;

    while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
        split_payload))
    {
        send_bytes += next_size;
        rem_payload_len -= next_size;
        remaining_in_partition -= next_size;

        if (remaining_in_partition == 0 && !(beginning_ && separate_first_))
        {
            // Advance to next partition?
            // Check that there are more partitions; verify that we are either
            // allowed to aggregate fragments, or that we are allowed to
            // aggregate intact partitions and that we started this packet
            // with an intact partition (indicated by first_fragment_ == true).
            if (part_ix_ + 1 < num_partitions &&
                ((aggr_mode_ == kAggrFragments) ||
                 (aggr_mode_ == kAggrPartitions && first_fragment_)))
            {
                remaining_in_partition
                    = part_info_.fragmentationLength[++part_ix_];
                // Disallow splitting unless kAggrFragments. In kAggrPartitions,
                // we can only aggregate intact partitions.
                split_payload = (aggr_mode_ == kAggrFragments);
            }
        }
        else if (balance_ && remaining_in_partition > 0)
        {
            break;
        }
    }
    if (remaining_in_partition == 0)
    {
        ++part_ix_; // Advance to next partition.
    }

    send_bytes -= FirstHeaderExtraLength(); // Remove the extra length again.
    assert(send_bytes > 0);
    const bool end_of_fragment = (remaining_in_partition == 0);
    // Write the payload header and the payload to buffer.
    *bytes_to_send = WriteHeaderAndPayload(send_bytes, end_of_fragment, buffer,
        max_payload_len);
    if (*bytes_to_send < 0)
    {
        return -1;
    }

    *last_packet = (payload_bytes_sent_ >= payload_size_);
    assert(!*last_packet || (payload_bytes_sent_ == payload_size_));
    return first_partition_in_packet;
}

int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
                                        bool end_of_fragment,
                                        WebRtc_UWord8* buffer,
                                        int buffer_length)
{
    // Write the VP8 payload header.
    //  0                   1                   2
    //  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    // | RSV |I|N|FI |B|   PictureID (1 or 2 octets)   |
    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    if (payload_bytes < 0)
    {
        return -1;
    }
    if (payload_bytes_sent_ + payload_bytes > payload_size_)
    {
        return -1;
    }

    buffer[0] = 0;
    if (hdr_info_.nonReference) buffer[0] |= (0x01 << 3); // N
    buffer[0] |= (GetFIFlag(end_of_fragment) << 1); // FI
    if (beginning_) buffer[0] |= 0x01; // B

    int pic_id_len = WritePictureID(&buffer[vp8_header_bytes_],
        buffer_length - vp8_header_bytes_);
    if (pic_id_len < 0) return pic_id_len; // error
    if (pic_id_len > 0) buffer[0] |= (0x01 << 4); // I

    if (vp8_header_bytes_ + pic_id_len + payload_bytes > buffer_length)
    {
        return -1;
    }
    memcpy(&buffer[vp8_header_bytes_ + pic_id_len],
        &payload_data_[payload_bytes_sent_], payload_bytes);

    beginning_ = false; // next packet cannot be first packet in frame
    // next packet starts new fragment if this ended one
    first_fragment_ = end_of_fragment;
    payload_bytes_sent_ += payload_bytes;

    // Return total length of written data.
    return payload_bytes + vp8_header_bytes_ + pic_id_len;
}

int RtpFormatVp8::WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const
{
    const WebRtc_UWord16 pic_id =
        static_cast<WebRtc_UWord16> (hdr_info_.pictureId);
    int picture_id_len = PictureIdLength();
    if (picture_id_len > buffer_length) return -1; // error
    if (picture_id_len == 2)
    {
        buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F);
        buffer[1] = pic_id & 0xFF;
    }
    else if (picture_id_len == 1)
    {
        buffer[0] = pic_id & 0x7F;
    }
    return picture_id_len;
}

int RtpFormatVp8::FirstHeaderExtraLength() const
{
    if (!beginning_)
    {
        return 0;
    }
    int length = 0;

    length += PictureIdLength();

    return length;
}

int RtpFormatVp8::PictureIdLength() const
{
    if (!beginning_ || hdr_info_.pictureId == kNoPictureId)
    {
        return 0;
    }
    if (hdr_info_.pictureId <= 0x7F)
    {
        return 1;
    }
    else
    {
        return 2;
    }
}

int RtpFormatVp8::GetFIFlag(bool end_of_fragment) const
{
    if (first_fragment_ && end_of_fragment) {
        return 0x0;
    }
    if (first_fragment_ && !end_of_fragment) {
        return 0x1;
    }
    if (!first_fragment_ && !end_of_fragment) {
        return 0x2;
    }
    // if (!first_fragment_ && end_of_fragment)
    return 0x3;
}

} // namespace webrtc
<|endoftext|>


<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/color_utils.h"
#include "ui/gfx/sys_color_change_listener.h"

#if defined(OS_WIN)
#include <windows.h>
#endif

#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#if defined(OS_WIN)
#include "ui/base/win/singleton_hwnd.h"
#endif

namespace gfx {

namespace {

bool g_is_inverted_color_scheme = false;
bool g_is_inverted_color_scheme_initialized = false;

void UpdateInvertedColorScheme() {
#if defined(OS_WIN)
  int foreground = color_utils::GetLuminanceForColor(
      color_utils::GetSysSkColor(COLOR_WINDOWTEXT));
  int background = color_utils::GetLuminanceForColor(
      color_utils::GetSysSkColor(COLOR_WINDOW));
  HIGHCONTRAST high_contrast = {0};
  high_contrast.cbSize = sizeof(HIGHCONTRAST);
  g_is_inverted_color_scheme =
      SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
      ((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0);
  g_is_inverted_color_scheme_initialized = true;
#endif
}

}  // namespace

bool IsInvertedColorScheme() {
  if (!g_is_inverted_color_scheme_initialized)
    UpdateInvertedColorScheme();
  return g_is_inverted_color_scheme;
}

#if defined(OS_WIN)
class SysColorChangeObserver : public ui::SingletonHwnd::Observer {
 public:
  static SysColorChangeObserver* GetInstance();

  void AddListener(SysColorChangeListener* listener);
  void RemoveListener(SysColorChangeListener* listener);

 private:
  friend struct DefaultSingletonTraits<SysColorChangeObserver>;

  SysColorChangeObserver();
  virtual ~SysColorChangeObserver();

  virtual void OnWndProc(HWND hwnd,
                         UINT message,
                         WPARAM wparam,
                         LPARAM lparam) OVERRIDE;

  ObserverList<SysColorChangeListener> listeners_;
};

// static
SysColorChangeObserver* SysColorChangeObserver::GetInstance() {
  return Singleton<SysColorChangeObserver>::get();
}

SysColorChangeObserver::SysColorChangeObserver() {
  ui::SingletonHwnd::GetInstance()->AddObserver(this);
}

SysColorChangeObserver::~SysColorChangeObserver() {
  ui::SingletonHwnd::GetInstance()->RemoveObserver(this);
}

void SysColorChangeObserver::AddListener(SysColorChangeListener* listener) {
  listeners_.AddObserver(listener);
}

void SysColorChangeObserver::RemoveListener(SysColorChangeListener* listener) {
  listeners_.RemoveObserver(listener);
}

void SysColorChangeObserver::OnWndProc(HWND hwnd,
                                       UINT message,
                                       WPARAM wparam,
                                       LPARAM lparam) {
  if (message == WM_SYSCOLORCHANGE ||
      (message == WM_SETTINGCHANGE && wparam == SPI_SETHIGHCONTRAST)) {
    UpdateInvertedColorScheme();
    FOR_EACH_OBSERVER(SysColorChangeListener, listeners_, OnSysColorChange());
  }
}
#endif

ScopedSysColorChangeListener::ScopedSysColorChangeListener(
    SysColorChangeListener* listener)
    : listener_(listener) {
#if defined(OS_WIN)
  SysColorChangeObserver::GetInstance()->AddListener(listener_);
#endif
}

ScopedSysColorChangeListener::~ScopedSysColorChangeListener() {
#if defined(OS_WIN)
  SysColorChangeObserver::GetInstance()->RemoveListener(listener_);
#endif
}

}  // namespace gfx
<commit_msg>Disable inverting web content when high-contrast mode is on.<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/color_utils.h"
#include "ui/gfx/sys_color_change_listener.h"

#if defined(OS_WIN)
#include <windows.h>
#endif

#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#if defined(OS_WIN)
#include "ui/base/win/singleton_hwnd.h"
#endif

namespace gfx {

namespace {

bool g_is_inverted_color_scheme = false;
bool g_is_inverted_color_scheme_initialized = false;

void UpdateInvertedColorScheme() {
#if defined(OS_WIN)
  int foreground = color_utils::GetLuminanceForColor(
      color_utils::GetSysSkColor(COLOR_WINDOWTEXT));
  int background = color_utils::GetLuminanceForColor(
      color_utils::GetSysSkColor(COLOR_WINDOW));
  HIGHCONTRAST high_contrast = {0};
  high_contrast.cbSize = sizeof(HIGHCONTRAST);

  // TODO(dmazzoni): this is temporarily disabled until the color inverting
  // can be made optional or the need is addressed some other way.
  // http://crbug.com/112944
  //g_is_inverted_color_scheme =
  //    SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
  //    ((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0);
  g_is_inverted_color_scheme_initialized = true;
#endif
}

}  // namespace

bool IsInvertedColorScheme() {
  if (!g_is_inverted_color_scheme_initialized)
    UpdateInvertedColorScheme();
  return g_is_inverted_color_scheme;
}

#if defined(OS_WIN)
class SysColorChangeObserver : public ui::SingletonHwnd::Observer {
 public:
  static SysColorChangeObserver* GetInstance();

  void AddListener(SysColorChangeListener* listener);
  void RemoveListener(SysColorChangeListener* listener);

 private:
  friend struct DefaultSingletonTraits<SysColorChangeObserver>;

  SysColorChangeObserver();
  virtual ~SysColorChangeObserver();

  virtual void OnWndProc(HWND hwnd,
                         UINT message,
                         WPARAM wparam,
                         LPARAM lparam) OVERRIDE;

  ObserverList<SysColorChangeListener> listeners_;
};

// static
SysColorChangeObserver* SysColorChangeObserver::GetInstance() {
  return Singleton<SysColorChangeObserver>::get();
}

SysColorChangeObserver::SysColorChangeObserver() {
  ui::SingletonHwnd::GetInstance()->AddObserver(this);
}

SysColorChangeObserver::~SysColorChangeObserver() {
  ui::SingletonHwnd::GetInstance()->RemoveObserver(this);
}

void SysColorChangeObserver::AddListener(SysColorChangeListener* listener) {
  listeners_.AddObserver(listener);
}

void SysColorChangeObserver::RemoveListener(SysColorChangeListener* listener) {
  listeners_.RemoveObserver(listener);
}

void SysColorChangeObserver::OnWndProc(HWND hwnd,
                                       UINT message,
                                       WPARAM wparam,
                                       LPARAM lparam) {
  if (message == WM_SYSCOLORCHANGE ||
      (message == WM_SETTINGCHANGE && wparam == SPI_SETHIGHCONTRAST)) {
    UpdateInvertedColorScheme();
    FOR_EACH_OBSERVER(SysColorChangeListener, listeners_, OnSysColorChange());
  }
}
#endif

ScopedSysColorChangeListener::ScopedSysColorChangeListener(
    SysColorChangeListener* listener)
    : listener_(listener) {
#if defined(OS_WIN)
  SysColorChangeObserver::GetInstance()->AddListener(listener_);
#endif
}

ScopedSysColorChangeListener::~ScopedSysColorChangeListener() {
#if defined(OS_WIN)
  SysColorChangeObserver::GetInstance()->RemoveListener(listener_);
#endif
}

}  // namespace gfx
<|endoftext|>