<commit_before>#include "khmapp.h"
#include <assert.h>

namespace nim {

    void DisplayElement::MarkForExtentUpdate(void)
    {
        MarkChildrenForExtentUpdate();
        for (DisplayElement * p = this; p; p = TQPARENT(p)) {
            p->recalc_extents = true;
        }
    }

    void DisplayElement::MarkChildrenForExtentUpdate(void)
    {
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->visible) {
                c->recalc_extents = true;
                c->MarkChildrenForExtentUpdate();
            }
    }

    void DisplayElement::InsertChildAfter(DisplayElement * e, DisplayElement * previous)
    {
        TQINSERT(this, previous, e);
        e->recalc_extents = true;
        e->visible = visible;
        e->SetOwner(owner);
        MarkForExtentUpdate();
    }

    void DisplayElement::InsertChildBefore(DisplayElement * e, DisplayElement * next)
    {
        TQINSERTP(this, next, e);
        e->recalc_extents = true;
        e->visible = visible;
        e->SetOwner(owner);
        MarkForExtentUpdate();
    }

    void DisplayElement::DeleteChild(DisplayElement * e)
    {
        NotifyDeleteChild(e);
        e->DeleteAllChildren();
        TQDELCHILD(this, e);
        delete e;
        MarkForExtentUpdate();
    }

    void DisplayElement::DeleteAllChildren()
    {
        NotifyDeleteAllChildren();
        for (DisplayElement * e = TQFIRSTCHILD(this); e; e = TQFIRSTCHILD(this)) {
            e->DeleteAllChildren();
            TQDELCHILD(this, e);
            delete e;
        }
        MarkForExtentUpdate();
    }

    void DisplayElement::MoveChildAfter(DisplayElement * e, DisplayElement * previous)
    {
        TQDELCHILD(this, e);
        TQINSERT(this, previous, e);
        e->recalc_extents = true;
        MarkForExtentUpdate();
    }

    void DisplayElement::MoveChildBefore(DisplayElement * e, DisplayElement * next)
    {
        TQDELCHILD(this, e);
        TQINSERTP(this, next, e);
        e->recalc_extents = true;
        MarkForExtentUpdate();
    }

    void DisplayElement::SetOwner(DisplayContainer * _owner)
    {
        owner = _owner;
        for (DisplayElement * e = TQFIRSTCHILD(this); e; e = TQNEXTSIBLING(e)) {
            e->SetOwner(_owner);
        }
    }

    void DisplayElement::NotifyDeleteChild(DisplayElement * e)
    {
        if (owner && owner != dynamic_cast<DisplayContainer *>(this)) {
            owner->NotifyDeleteChild(e);
        }
    }

    void DisplayElement::NotifyDeleteAllChildren()
    {
        if (owner && owner != dynamic_cast<DisplayContainer *>(this)) {
            owner->NotifyDeleteAllChildren();
        }
    }

    void DisplayElement::UpdateLayout(Graphics & g, const Rect & layout)
    {
        Rect t_layout;

        layout.GetBounds(&t_layout);
        UpdateLayoutPre(g, t_layout);

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->visible && c->recalc_extents)
                c->UpdateLayout(g, t_layout);
        }

        UpdateLayoutPost(g, t_layout);
        recalc_extents = false;
    }

    void DisplayElement::UpdateLayoutPre(Graphics& g, Rect& layout)
    {
    }

    void DisplayElement::UpdateLayoutPost(Graphics& g, const Rect& layout)
    {
        extents.Width = 0;
        extents.Height = 0;
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->origin.X + c->extents.Width > extents.Width)
                extents.Width = c->origin.X + c->extents.Width;
            if (c->origin.Y + c->extents.Height > extents.Height)
                extents.Height = c->origin.Y + c->extents.Height;
        }
    }

    void DisplayElement::Invalidate(const Rect & r)
    {
        Point pto;
        if (owner == NULL) return;
        r.GetLocation(&pto);
        pto = owner->MapFromDescendant(this, pto);
        owner->Invalidate(Rect(pto, Size(r.Width, r.Height)));
    }

    Point DisplayElement::MapToParent(const Point& pt)
    {
        return pt + origin;
    }

    Point DisplayElement::MapToScreen(const Point & pt)
    {
        return owner->MapToScreen(owner->MapFromDescendant(this, pt));
    }

    Point DisplayElement::MapToDescendant(const DisplayElement * e, const Point& pt)
    {
        Point cpt(pt);
        for (const DisplayElement * p = e; p && p != this; p = TQPARENT(p)) {
            cpt = cpt - p->origin;
        }
        return cpt;
    }

    Point DisplayElement::MapFromDescendant(const DisplayElement * c, const Point& pt)
    {
        Point ppt(pt);
        for (const DisplayElement * p = c; p && p != this; p = TQPARENT(p)) {
            ppt = ppt + p->origin;
        }
        return ppt;
    }

    DisplayElement * DisplayElement::ChildFromPoint(const Point& pt)
    {
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->visible && Rect(c->origin, c->extents).Contains(pt))
                return c;
        }
        return NULL;
    }

    DisplayElement * DisplayElement::DescendantFromPoint(const Point& pt)
    {
        Point cpt(pt);

        DisplayElement * d = ChildFromPoint(pt);
        while (d) {
            cpt = cpt - d->origin;
            DisplayElement * nd = d->ChildFromPoint(cpt);
            if (nd == NULL)
                break;
            d = nd;
        }

        return d;
    }

    void DisplayElement::OnPaint(Graphics& g, const Rect& bounds, const Rect& clip)
    {
        PaintSelf(g, bounds, clip);

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->visible) {
                Rect cr(c->origin, c->extents);
                cr.Offset(bounds.X, bounds.Y);

                if (clip.IntersectsWith(cr))
                    c->OnPaint(g, cr, clip);
            }
    }

    void DisplayElement::Expand(bool expand)
    {
        if (expanded == expand)
            return;

        expanded = expand;

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->is_outline) {
                c->visible = expand;
            }

        MarkForExtentUpdate();
        Invalidate();
    }

    void DisplayElement::Show(bool show)
    {
        if (visible == show)
            return;

        visible = show;
        MarkForExtentUpdate();
        Invalidate();
    }

    bool DisplayElement::IsVisible()
    {
        for (DisplayElement * p = this; p; p = TQPARENT(p)) {
            if (!p->visible)
                return false;
        }
        return true;
    }

    void DisplayElement::Select(bool _select)
    {
        if (selected == _select)
            return;

        selected = _select;
        Invalidate();
    }

    void DisplayElement::Focus(bool _focus)
    {
        if (focus == _focus)
            return;
        focus = _focus;
        Invalidate();
    }

}
<commit_msg>Add a _parent parameter when passing around a notification of child deletion.<commit_after>#include "khmapp.h"
#include <assert.h>

namespace nim {

    void DisplayElement::MarkForExtentUpdate(void)
    {
        MarkChildrenForExtentUpdate();
        for (DisplayElement * p = this; p; p = TQPARENT(p)) {
            p->recalc_extents = true;
        }
    }

    void DisplayElement::MarkChildrenForExtentUpdate(void)
    {
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->visible) {
                c->recalc_extents = true;
                c->MarkChildrenForExtentUpdate();
            }
    }

    void DisplayElement::InsertChildAfter(DisplayElement * e, DisplayElement * previous)
    {
        TQINSERT(this, previous, e);
        e->recalc_extents = true;
        e->visible = visible;
        e->SetOwner(owner);
        MarkForExtentUpdate();
    }

    void DisplayElement::InsertChildBefore(DisplayElement * e, DisplayElement * next)
    {
        TQINSERTP(this, next, e);
        e->recalc_extents = true;
        e->visible = visible;
        e->SetOwner(owner);
        MarkForExtentUpdate();
    }

    void DisplayElement::DeleteChild(DisplayElement * e)
    {
        NotifyDeleteChild(this, e);
        e->DeleteAllChildren();
        TQDELCHILD(this, e);
        delete e;
        MarkForExtentUpdate();
    }

    void DisplayElement::DeleteAllChildren()
    {
        NotifyDeleteAllChildren(this);
        for (DisplayElement * e = TQFIRSTCHILD(this); e; e = TQFIRSTCHILD(this)) {
            e->DeleteAllChildren();
            TQDELCHILD(this, e);
            delete e;
        }
        MarkForExtentUpdate();
    }

    void DisplayElement::MoveChildAfter(DisplayElement * e, DisplayElement * previous)
    {
        TQDELCHILD(this, e);
        TQINSERT(this, previous, e);
        e->recalc_extents = true;
        MarkForExtentUpdate();
    }

    void DisplayElement::MoveChildBefore(DisplayElement * e, DisplayElement * next)
    {
        TQDELCHILD(this, e);
        TQINSERTP(this, next, e);
        e->recalc_extents = true;
        MarkForExtentUpdate();
    }

    void DisplayElement::SetOwner(DisplayContainer * _owner)
    {
        owner = _owner;
        for (DisplayElement * e = TQFIRSTCHILD(this); e; e = TQNEXTSIBLING(e)) {
            e->SetOwner(_owner);
        }
    }

    void DisplayElement::NotifyDeleteChild(DisplayElement * _parent, DisplayElement * e)
    {
        if (owner != this) {
            owner->NotifyDeleteChild(_parent, e);
        }
    }

    void DisplayElement::NotifyDeleteAllChildren(DisplayElement * _parent)
    {
        if (owner != this) {
            owner->NotifyDeleteAllChildren(_parent);
        }
    }

    void DisplayElement::UpdateLayout(Graphics & g, const Rect & layout)
    {
        Rect t_layout;

        layout.GetBounds(&t_layout);
        UpdateLayoutPre(g, t_layout);

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->visible && c->recalc_extents)
                c->UpdateLayout(g, t_layout);
        }

        UpdateLayoutPost(g, t_layout);
        recalc_extents = false;
    }

    void DisplayElement::UpdateLayoutPre(Graphics& g, Rect& layout)
    {
    }

    void DisplayElement::UpdateLayoutPost(Graphics& g, const Rect& layout)
    {
        extents.Width = 0;
        extents.Height = 0;
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->origin.X + c->extents.Width > extents.Width)
                extents.Width = c->origin.X + c->extents.Width;
            if (c->origin.Y + c->extents.Height > extents.Height)
                extents.Height = c->origin.Y + c->extents.Height;
        }
    }

    void DisplayElement::Invalidate(const Rect & r)
    {
        Point pto;
        if (owner == NULL) return;
        r.GetLocation(&pto);
        pto = owner->MapFromDescendant(this, pto);
        owner->Invalidate(Rect(pto, Size(r.Width, r.Height)));
    }

    Point DisplayElement::MapToParent(const Point& pt)
    {
        return pt + origin;
    }

    Point DisplayElement::MapToScreen(const Point & pt)
    {
        return owner->MapToScreen(owner->MapFromDescendant(this, pt));
    }

    Point DisplayElement::MapToDescendant(const DisplayElement * e, const Point& pt)
    {
        Point cpt(pt);
        for (const DisplayElement * p = e; p && p != this; p = TQPARENT(p)) {
            cpt = cpt - p->origin;
        }
        return cpt;
    }

    Point DisplayElement::MapFromDescendant(const DisplayElement * c, const Point& pt)
    {
        Point ppt(pt);
        for (const DisplayElement * p = c; p && p != this; p = TQPARENT(p)) {
            ppt = ppt + p->origin;
        }
        return ppt;
    }

    DisplayElement * DisplayElement::ChildFromPoint(const Point& pt)
    {
        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c)) {
            if (c->visible && Rect(c->origin, c->extents).Contains(pt))
                return c;
        }
        return NULL;
    }

    DisplayElement * DisplayElement::DescendantFromPoint(const Point& pt)
    {
        Point cpt(pt);

        DisplayElement * d = ChildFromPoint(pt);
        while (d) {
            cpt = cpt - d->origin;
            DisplayElement * nd = d->ChildFromPoint(cpt);
            if (nd == NULL)
                break;
            d = nd;
        }

        return d;
    }

    void DisplayElement::OnPaint(Graphics& g, const Rect& bounds, const Rect& clip)
    {
        PaintSelf(g, bounds, clip);

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->visible) {
                Rect cr(c->origin, c->extents);
                cr.Offset(bounds.X, bounds.Y);

                if (clip.IntersectsWith(cr))
                    c->OnPaint(g, cr, clip);
            }
    }

    void DisplayElement::Expand(bool expand)
    {
        if (expanded == expand)
            return;

        expanded = expand;

        for (DisplayElement * c = TQFIRSTCHILD(this); c; c = TQNEXTSIBLING(c))
            if (c->is_outline) {
                c->visible = expand;
            }

        MarkForExtentUpdate();
        Invalidate();
    }

    void DisplayElement::Show(bool show)
    {
        if (visible == show)
            return;

        visible = show;
        MarkForExtentUpdate();
        Invalidate();
    }

    bool DisplayElement::IsVisible()
    {
        for (DisplayElement * p = this; p; p = TQPARENT(p)) {
            if (!p->visible)
                return false;
        }
        return true;
    }

    void DisplayElement::Select(bool _select)
    {
        if (selected == _select)
            return;

        selected = _select;
        Invalidate();
    }

    void DisplayElement::Focus(bool _focus)
    {
        if (focus == _focus)
            return;
        focus = _focus;
        Invalidate();
    }

}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xmltabi.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 11:01:22 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"

#ifndef _COM_SUN_STAR_STYLE_TABALIGN_HPP_
#include <com/sun/star/style/TabAlign.hpp>
#endif

#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif

#ifndef _XMLOFF_XMLTKMAP_HXX
#include "xmltkmap.hxx"
#endif
#ifndef _XMLOFF_NMSPMAP_HXX
#include "nmspmap.hxx"
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include "xmlnmspe.hxx"
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include "xmlimp.hxx"
#endif

#ifndef _COM_SUN_STAR_STYLE_TABSTOP_HPP_
#include <com/sun/star/style/TabStop.hpp>
#endif

#ifndef _XMLOFF_XMLTOKEN_HXX
#include "xmltoken.hxx"
#endif
#ifndef _XMLOFF_I18NMAP_HXX
#include "i18nmap.hxx"
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include "xmluconv.hxx"
#endif

#include "xmltabi.hxx"

#define _SVSTDARR_USHORTS
#include <svtools/svstdarr.hxx>

using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::xmloff::token;

// ---

enum SvXMLTokenMapAttrs
{
    XML_TOK_TABSTOP_POSITION,
    XML_TOK_TABSTOP_TYPE,
    XML_TOK_TABSTOP_CHAR,
    XML_TOK_TABSTOP_LEADER_STYLE,
    XML_TOK_TABSTOP_LEADER_TEXT,
    XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
};

static __FAR_DATA SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
{
    { XML_NAMESPACE_STYLE, XML_POSITION,     XML_TOK_TABSTOP_POSITION },
    { XML_NAMESPACE_STYLE, XML_TYPE,         XML_TOK_TABSTOP_TYPE },
    { XML_NAMESPACE_STYLE, XML_CHAR,         XML_TOK_TABSTOP_CHAR },
    { XML_NAMESPACE_STYLE, XML_LEADER_TEXT,  XML_TOK_TABSTOP_LEADER_TEXT },
    { XML_NAMESPACE_STYLE, XML_LEADER_STYLE,  XML_TOK_TABSTOP_LEADER_STYLE },
    XML_TOKEN_MAP_END
};

// ---

class SvxXMLTabStopContext_Impl : public SvXMLImportContext
{
private:
     style::TabStop aTabStop;

public:
    TYPEINFO();

    SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
                               const OUString& rLName,
                               const uno::Reference< xml::sax::XAttributeList > & xAttrList );

    virtual ~SvxXMLTabStopContext_Impl();

    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & xAttrList );

    const style::TabStop& getTabStop() const { return aTabStop; }
};

TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );

SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
                               SvXMLImport& rImport, sal_uInt16 nPrfx,
                               const OUString& rLName,
                               const uno::Reference< xml::sax::XAttributeList > & xAttrList )
: SvXMLImportContext( rImport, nPrfx, rLName )
{
    aTabStop.Position = 0;
    aTabStop.Alignment = style::TabAlign_LEFT;
    aTabStop.DecimalChar = sal_Unicode( ',' );
    aTabStop.FillChar = sal_Unicode( ' ' );
    sal_Unicode cTextFillChar = 0;

    SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );

    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for( sal_Int16 i=0; i < nAttrCount; i++ )
    {
        const OUString& rAttrName = xAttrList->getNameByIndex( i );
        OUString aLocalName;
        sal_uInt16 nPrefix =
            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                            &aLocalName );
        const OUString& rValue = xAttrList->getValueByIndex( i );

        sal_Int32 nVal;
        switch( aTokenMap.Get( nPrefix, aLocalName ) )
        {
        case XML_TOK_TABSTOP_POSITION:
            if( GetImport().GetMM100UnitConverter().convertMeasure( nVal,
                                                                    rValue ) )
                aTabStop.Position = nVal;
            break;
        case XML_TOK_TABSTOP_TYPE:
            if( IsXMLToken( rValue, XML_LEFT ) )
            {
                aTabStop.Alignment = style::TabAlign_LEFT;
            }
            else if( IsXMLToken( rValue, XML_RIGHT ) )
            {
                aTabStop.Alignment = style::TabAlign_RIGHT;
            }
            else if( IsXMLToken( rValue, XML_CENTER ) )
            {
                aTabStop.Alignment = style::TabAlign_CENTER;
            }
            else if( IsXMLToken( rValue, XML_CHAR ) )
            {
                aTabStop.Alignment = style::TabAlign_DECIMAL;
            }
            else if( IsXMLToken( rValue, XML_DEFAULT ) )
            {
                aTabStop.Alignment = style::TabAlign_DEFAULT;
            }
            break;
        case XML_TOK_TABSTOP_CHAR:
            if( 0 != rValue.getLength() )
                aTabStop.DecimalChar = rValue[0];
            break;
        case XML_TOK_TABSTOP_LEADER_STYLE:
            if( IsXMLToken( rValue, XML_NONE ) )
                aTabStop.FillChar = ' ';
            else if( IsXMLToken( rValue, XML_DOTTED ) )
                aTabStop.FillChar = '.';
            else
                aTabStop.FillChar = '_';
            break;
        case XML_TOK_TABSTOP_LEADER_TEXT:
            if( 0 != rValue.getLength() )
                cTextFillChar = rValue[0];
            break;
        }
    }

    if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
        aTabStop.FillChar = cTextFillChar;
}

SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
{
}

SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
                                   sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & )
{
    return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
}

typedef SvxXMLTabStopContext_Impl *SvxXMLTabStopContext_Impl_ImplPtr;
SV_DECL_PTRARR( SvxXMLTabStopArray_Impl, SvxXMLTabStopContext_Impl_ImplPtr, 20, 5 )

// ---

TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );

SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
                                SvXMLImport& rImport, sal_uInt16 nPrfx,
                                const OUString& rLName,
                                const XMLPropertyState& rProp,
                                 ::std::vector< XMLPropertyState > &rProps )
: XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
  mpTabStops( NULL )
{
}

SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
{
    if( mpTabStops )
    {
        sal_uInt16 nCount = mpTabStops->Count();
        while( nCount )
        {
            nCount--;
            SvxXMLTabStopContext_Impl *pTabStop = (*mpTabStops)[nCount];
            mpTabStops->Remove( nCount, 1 );
            pTabStop->ReleaseRef();
        }
    }

    delete mpTabStops;
}

SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
                                   sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
    SvXMLImportContext *pContext = 0;

    if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
    {
        // create new tabstop import context
        SvxXMLTabStopContext_Impl *pTabStopContext =
            new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
                                           xAttrList );

        // add new tabstop to array of tabstops
        if( !mpTabStops )
            mpTabStops = new SvxXMLTabStopArray_Impl;

        mpTabStops->Insert( pTabStopContext, mpTabStops->Count() );
        pTabStopContext->AddRef();

        pContext = pTabStopContext;
    }
    else
    {
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
    }

    return pContext;
}

void SvxXMLTabStopImportContext::EndElement( )
{
    sal_uInt16 nCount = mpTabStops ? mpTabStops->Count() : 0;
    uno::Sequence< style::TabStop> aSeq( nCount );

    if( mpTabStops )
    {
        sal_uInt16 nNewCount = 0;

        style::TabStop* pTabStops = aSeq.getArray();
        for( sal_uInt16 i=0; i < nCount; i++ )
        {
            SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
            const style::TabStop& rTabStop = pTabStopContext->getTabStop();
            sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
            if( !bDflt || 0==i )
            {
                *pTabStops++ = pTabStopContext->getTabStop();
                nNewCount++;
            }
            if( bDflt && 0==i )
                break;
        }

        if( nCount != nNewCount )
            aSeq.realloc( nNewCount );
    }
    aProp.maValue <<= aSeq;

    SetInsert( sal_True );
    XMLElementPropertyContext::EndElement();

}

<commit_msg>INTEGRATION: CWS vgbugs07 (1.14.124); FILE MERGED 2007/06/04 13:23:33 vg 1.14.124.1: #i76605# Remove -I .../inc/module hack introduced by hedaburemove01<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xmltabi.cxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 15:49:46 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"

#ifndef _COM_SUN_STAR_STYLE_TABALIGN_HPP_
#include <com/sun/star/style/TabAlign.hpp>
#endif

#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif

#ifndef _XMLOFF_XMLTKMAP_HXX
#include <xmloff/xmltkmap.hxx>
#endif
#ifndef _XMLOFF_NMSPMAP_HXX
#include <xmloff/nmspmap.hxx>
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include "xmlnmspe.hxx"
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include <xmloff/xmlimp.hxx>
#endif

#ifndef _COM_SUN_STAR_STYLE_TABSTOP_HPP_
#include <com/sun/star/style/TabStop.hpp>
#endif

#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif
#ifndef _XMLOFF_I18NMAP_HXX
#include "i18nmap.hxx"
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include <xmloff/xmluconv.hxx>
#endif

#include "xmltabi.hxx"

#define _SVSTDARR_USHORTS
#include <svtools/svstdarr.hxx>

using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::xmloff::token;

// ---

enum SvXMLTokenMapAttrs
{
    XML_TOK_TABSTOP_POSITION,
    XML_TOK_TABSTOP_TYPE,
    XML_TOK_TABSTOP_CHAR,
    XML_TOK_TABSTOP_LEADER_STYLE,
    XML_TOK_TABSTOP_LEADER_TEXT,
    XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
};

static __FAR_DATA SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
{
    { XML_NAMESPACE_STYLE, XML_POSITION,     XML_TOK_TABSTOP_POSITION },
    { XML_NAMESPACE_STYLE, XML_TYPE,         XML_TOK_TABSTOP_TYPE },
    { XML_NAMESPACE_STYLE, XML_CHAR,         XML_TOK_TABSTOP_CHAR },
    { XML_NAMESPACE_STYLE, XML_LEADER_TEXT,  XML_TOK_TABSTOP_LEADER_TEXT },
    { XML_NAMESPACE_STYLE, XML_LEADER_STYLE,  XML_TOK_TABSTOP_LEADER_STYLE },
    XML_TOKEN_MAP_END
};

// ---

class SvxXMLTabStopContext_Impl : public SvXMLImportContext
{
private:
     style::TabStop aTabStop;

public:
    TYPEINFO();

    SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
                               const OUString& rLName,
                               const uno::Reference< xml::sax::XAttributeList > & xAttrList );

    virtual ~SvxXMLTabStopContext_Impl();

    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & xAttrList );

    const style::TabStop& getTabStop() const { return aTabStop; }
};

TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );

SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
                               SvXMLImport& rImport, sal_uInt16 nPrfx,
                               const OUString& rLName,
                               const uno::Reference< xml::sax::XAttributeList > & xAttrList )
: SvXMLImportContext( rImport, nPrfx, rLName )
{
    aTabStop.Position = 0;
    aTabStop.Alignment = style::TabAlign_LEFT;
    aTabStop.DecimalChar = sal_Unicode( ',' );
    aTabStop.FillChar = sal_Unicode( ' ' );
    sal_Unicode cTextFillChar = 0;

    SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );

    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for( sal_Int16 i=0; i < nAttrCount; i++ )
    {
        const OUString& rAttrName = xAttrList->getNameByIndex( i );
        OUString aLocalName;
        sal_uInt16 nPrefix =
            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                            &aLocalName );
        const OUString& rValue = xAttrList->getValueByIndex( i );

        sal_Int32 nVal;
        switch( aTokenMap.Get( nPrefix, aLocalName ) )
        {
        case XML_TOK_TABSTOP_POSITION:
            if( GetImport().GetMM100UnitConverter().convertMeasure( nVal,
                                                                    rValue ) )
                aTabStop.Position = nVal;
            break;
        case XML_TOK_TABSTOP_TYPE:
            if( IsXMLToken( rValue, XML_LEFT ) )
            {
                aTabStop.Alignment = style::TabAlign_LEFT;
            }
            else if( IsXMLToken( rValue, XML_RIGHT ) )
            {
                aTabStop.Alignment = style::TabAlign_RIGHT;
            }
            else if( IsXMLToken( rValue, XML_CENTER ) )
            {
                aTabStop.Alignment = style::TabAlign_CENTER;
            }
            else if( IsXMLToken( rValue, XML_CHAR ) )
            {
                aTabStop.Alignment = style::TabAlign_DECIMAL;
            }
            else if( IsXMLToken( rValue, XML_DEFAULT ) )
            {
                aTabStop.Alignment = style::TabAlign_DEFAULT;
            }
            break;
        case XML_TOK_TABSTOP_CHAR:
            if( 0 != rValue.getLength() )
                aTabStop.DecimalChar = rValue[0];
            break;
        case XML_TOK_TABSTOP_LEADER_STYLE:
            if( IsXMLToken( rValue, XML_NONE ) )
                aTabStop.FillChar = ' ';
            else if( IsXMLToken( rValue, XML_DOTTED ) )
                aTabStop.FillChar = '.';
            else
                aTabStop.FillChar = '_';
            break;
        case XML_TOK_TABSTOP_LEADER_TEXT:
            if( 0 != rValue.getLength() )
                cTextFillChar = rValue[0];
            break;
        }
    }

    if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
        aTabStop.FillChar = cTextFillChar;
}

SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
{
}

SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
                                   sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & )
{
    return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
}

typedef SvxXMLTabStopContext_Impl *SvxXMLTabStopContext_Impl_ImplPtr;
SV_DECL_PTRARR( SvxXMLTabStopArray_Impl, SvxXMLTabStopContext_Impl_ImplPtr, 20, 5 )

// ---

TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );

SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
                                SvXMLImport& rImport, sal_uInt16 nPrfx,
                                const OUString& rLName,
                                const XMLPropertyState& rProp,
                                 ::std::vector< XMLPropertyState > &rProps )
: XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
  mpTabStops( NULL )
{
}

SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
{
    if( mpTabStops )
    {
        sal_uInt16 nCount = mpTabStops->Count();
        while( nCount )
        {
            nCount--;
            SvxXMLTabStopContext_Impl *pTabStop = (*mpTabStops)[nCount];
            mpTabStops->Remove( nCount, 1 );
            pTabStop->ReleaseRef();
        }
    }

    delete mpTabStops;
}

SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
                                   sal_uInt16 nPrefix,
                                   const OUString& rLocalName,
                                   const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
    SvXMLImportContext *pContext = 0;

    if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
    {
        // create new tabstop import context
        SvxXMLTabStopContext_Impl *pTabStopContext =
            new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
                                           xAttrList );

        // add new tabstop to array of tabstops
        if( !mpTabStops )
            mpTabStops = new SvxXMLTabStopArray_Impl;

        mpTabStops->Insert( pTabStopContext, mpTabStops->Count() );
        pTabStopContext->AddRef();

        pContext = pTabStopContext;
    }
    else
    {
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
    }

    return pContext;
}

void SvxXMLTabStopImportContext::EndElement( )
{
    sal_uInt16 nCount = mpTabStops ? mpTabStops->Count() : 0;
    uno::Sequence< style::TabStop> aSeq( nCount );

    if( mpTabStops )
    {
        sal_uInt16 nNewCount = 0;

        style::TabStop* pTabStops = aSeq.getArray();
        for( sal_uInt16 i=0; i < nCount; i++ )
        {
            SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
            const style::TabStop& rTabStop = pTabStopContext->getTabStop();
            sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
            if( !bDflt || 0==i )
            {
                *pTabStops++ = pTabStopContext->getTabStop();
                nNewCount++;
            }
            if( bDflt && 0==i )
                break;
        }

        if( nCount != nNewCount )
            aSeq.realloc( nNewCount );
    }
    aProp.maValue <<= aSeq;

    SetInsert( sal_True );
    XMLElementPropertyContext::EndElement();

}

<|endoftext|>


<commit_before>/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkShader.h"

/*
 *  Want to ensure that our bitmap sampler (in bitmap shader) keeps plenty of
 *  precision when scaling very large images (where the dx might get very small.
 */

#define W   257
#define H   161

class GiantBitmapGM : public skiagm::GM {
    SkBitmap* fBM;
    SkShader::TileMode fMode;
    bool fDoFilter;
    bool fDoRotate;

    const SkBitmap& getBitmap() {
        if (NULL == fBM) {
            fBM = new SkBitmap;
            fBM->allocN32Pixels(W, H);
            fBM->eraseColor(SK_ColorWHITE);

            const SkColor colors[] = {
                SK_ColorBLUE, SK_ColorRED, SK_ColorBLACK, SK_ColorGREEN
            };

            SkCanvas canvas(*fBM);
            SkPaint paint;
            paint.setAntiAlias(true);
            paint.setStrokeWidth(SkIntToScalar(20));

#if 0
            for (int y = -H*2; y < H; y += 50) {
                SkScalar yy = SkIntToScalar(y);
                paint.setColor(colors[y/50 & 0x3]);
                canvas.drawLine(0, yy, SkIntToScalar(W), yy + SkIntToScalar(W),
                                paint);
            }
#else
            for (int x = -W; x < W; x += 60) {
                paint.setColor(colors[x/60 & 0x3]);

                SkScalar xx = SkIntToScalar(x);
                canvas.drawLine(xx, 0, xx, SkIntToScalar(H),
                                paint);
            }
#endif
        }
        return *fBM;
    }

public:
    GiantBitmapGM(SkShader::TileMode mode, bool doFilter, bool doRotate) : fBM(NULL) {
        fMode = mode;
        fDoFilter = doFilter;
        fDoRotate = doRotate;
    }

    virtual ~GiantBitmapGM() {
        SkDELETE(fBM);
    }

protected:
    virtual uint32_t onGetFlags() const SK_OVERRIDE {
        if (fDoFilter && fDoRotate && fMode != SkShader::kClamp_TileMode) {
            return kSkipTiled_Flag;
        }
        return 0;
    }

    virtual SkString onShortName() {
        SkString str("giantbitmap_");
        switch (fMode) {
            case SkShader::kClamp_TileMode:
                str.append("clamp");
                break;
            case SkShader::kRepeat_TileMode:
                str.append("repeat");
                break;
            case SkShader::kMirror_TileMode:
                str.append("mirror");
                break;
            default:
                break;
        }
        str.append(fDoFilter ? "_bilerp" : "_point");
        str.append(fDoRotate ? "_rotate" : "_scale");
        return str;
    }

    virtual SkISize onISize() { return SkISize::Make(640, 480); }

    virtual void onDraw(SkCanvas* canvas) {
        SkPaint paint;

        SkMatrix m;
        if (fDoRotate) {
//            m.setRotate(SkIntToScalar(30), 0, 0);
            m.setSkew(SK_Scalar1, 0, 0, 0);
//            m.postScale(2*SK_Scalar1/3, 2*SK_Scalar1/3);
        } else {
            SkScalar scale = 11*SK_Scalar1/12;
            m.setScale(scale, scale);
        }
        SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);

        paint.setShader(s)->unref();
        paint.setFilterLevel(fDoFilter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);

        canvas->translate(SkIntToScalar(50), SkIntToScalar(50));

//        SkRect r = SkRect::MakeXYWH(-50, -50, 32, 16);
//        canvas->drawRect(r, paint); return;
        canvas->drawPaint(paint);
    }

private:
    typedef GM INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

static skiagm::GM* G000(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, false); }
static skiagm::GM* G100(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, false); }
static skiagm::GM* G200(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, false); }
static skiagm::GM* G010(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, false); }
static skiagm::GM* G110(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, false); }
static skiagm::GM* G210(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, false); }

static skiagm::GM* G001(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, true); }
static skiagm::GM* G101(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, true); }
static skiagm::GM* G201(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, true); }
static skiagm::GM* G011(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, true); }
static skiagm::GM* G111(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, true); }
static skiagm::GM* G211(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, true); }

static skiagm::GMRegistry reg000(G000);
static skiagm::GMRegistry reg100(G100);
static skiagm::GMRegistry reg200(G200);
static skiagm::GMRegistry reg010(G010);
static skiagm::GMRegistry reg110(G110);
static skiagm::GMRegistry reg210(G210);

static skiagm::GMRegistry reg001(G001);
static skiagm::GMRegistry reg101(G101);
static skiagm::GMRegistry reg201(G201);
static skiagm::GMRegistry reg011(G011);
static skiagm::GMRegistry reg111(G111);
static skiagm::GMRegistry reg211(G211);
<commit_msg>On Android, skip tiling for all giantbitmap variants.<commit_after>/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkShader.h"

/*
 *  Want to ensure that our bitmap sampler (in bitmap shader) keeps plenty of
 *  precision when scaling very large images (where the dx might get very small.
 */

#define W   257
#define H   161

class GiantBitmapGM : public skiagm::GM {
    SkBitmap* fBM;
    SkShader::TileMode fMode;
    bool fDoFilter;
    bool fDoRotate;

    const SkBitmap& getBitmap() {
        if (NULL == fBM) {
            fBM = new SkBitmap;
            fBM->allocN32Pixels(W, H);
            fBM->eraseColor(SK_ColorWHITE);

            const SkColor colors[] = {
                SK_ColorBLUE, SK_ColorRED, SK_ColorBLACK, SK_ColorGREEN
            };

            SkCanvas canvas(*fBM);
            SkPaint paint;
            paint.setAntiAlias(true);
            paint.setStrokeWidth(SkIntToScalar(20));

#if 0
            for (int y = -H*2; y < H; y += 50) {
                SkScalar yy = SkIntToScalar(y);
                paint.setColor(colors[y/50 & 0x3]);
                canvas.drawLine(0, yy, SkIntToScalar(W), yy + SkIntToScalar(W),
                                paint);
            }
#else
            for (int x = -W; x < W; x += 60) {
                paint.setColor(colors[x/60 & 0x3]);

                SkScalar xx = SkIntToScalar(x);
                canvas.drawLine(xx, 0, xx, SkIntToScalar(H),
                                paint);
            }
#endif
        }
        return *fBM;
    }

public:
    GiantBitmapGM(SkShader::TileMode mode, bool doFilter, bool doRotate) : fBM(NULL) {
        fMode = mode;
        fDoFilter = doFilter;
        fDoRotate = doRotate;
    }

    virtual ~GiantBitmapGM() {
        SkDELETE(fBM);
    }

protected:
    virtual uint32_t onGetFlags() const SK_OVERRIDE {
#ifdef SK_BUILD_FOR_ANDROID
        return kSkipTiled_Flag;
#else
        if (fDoFilter && fDoRotate && fMode != SkShader::kClamp_TileMode) {
            return kSkipTiled_Flag;
        }
        return 0;
#endif
    }

    virtual SkString onShortName() {
        SkString str("giantbitmap_");
        switch (fMode) {
            case SkShader::kClamp_TileMode:
                str.append("clamp");
                break;
            case SkShader::kRepeat_TileMode:
                str.append("repeat");
                break;
            case SkShader::kMirror_TileMode:
                str.append("mirror");
                break;
            default:
                break;
        }
        str.append(fDoFilter ? "_bilerp" : "_point");
        str.append(fDoRotate ? "_rotate" : "_scale");
        return str;
    }

    virtual SkISize onISize() { return SkISize::Make(640, 480); }

    virtual void onDraw(SkCanvas* canvas) {
        SkPaint paint;

        SkMatrix m;
        if (fDoRotate) {
//            m.setRotate(SkIntToScalar(30), 0, 0);
            m.setSkew(SK_Scalar1, 0, 0, 0);
//            m.postScale(2*SK_Scalar1/3, 2*SK_Scalar1/3);
        } else {
            SkScalar scale = 11*SK_Scalar1/12;
            m.setScale(scale, scale);
        }
        SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);

        paint.setShader(s)->unref();
        paint.setFilterLevel(fDoFilter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);

        canvas->translate(SkIntToScalar(50), SkIntToScalar(50));

//        SkRect r = SkRect::MakeXYWH(-50, -50, 32, 16);
//        canvas->drawRect(r, paint); return;
        canvas->drawPaint(paint);
    }

private:
    typedef GM INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

static skiagm::GM* G000(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, false); }
static skiagm::GM* G100(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, false); }
static skiagm::GM* G200(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, false); }
static skiagm::GM* G010(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, false); }
static skiagm::GM* G110(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, false); }
static skiagm::GM* G210(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, false); }

static skiagm::GM* G001(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, true); }
static skiagm::GM* G101(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, true); }
static skiagm::GM* G201(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, true); }
static skiagm::GM* G011(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, true); }
static skiagm::GM* G111(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, true); }
static skiagm::GM* G211(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, true); }

static skiagm::GMRegistry reg000(G000);
static skiagm::GMRegistry reg100(G100);
static skiagm::GMRegistry reg200(G200);
static skiagm::GMRegistry reg010(G010);
static skiagm::GMRegistry reg110(G110);
static skiagm::GMRegistry reg210(G210);

static skiagm::GMRegistry reg001(G001);
static skiagm::GMRegistry reg101(G101);
static skiagm::GMRegistry reg201(G201);
static skiagm::GMRegistry reg011(G011);
static skiagm::GMRegistry reg111(G111);
static skiagm::GMRegistry reg211(G211);
<|endoftext|>


<commit_before>#include "loss.h"
#include "task.h"
#include "model.h"
#include "io/io.h"
#include "trainer.h"
#include "checkpoint.h"
#include "text/table.h"
#include "accumulator.h"
#include "text/cmdline.h"
#include <iomanip>
#include <iostream>

using namespace nano;

static bool load_json(const string_t& path, const char* name, string_t& json, string_t& id)
{
        if (!load_string(path, json) || json.empty())
        {
                return false;
        }

        json_reader_t(json).object(name, id);
        return !id.empty();
}

int main(int argc, const char *argv[])
{
        // parse the command line
        cmdline_t cmdline("train a model");
        cmdline.add("", "task",         join(get_tasks().ids()) + " (.json)");
        cmdline.add("", "fold",         "fold index to use for training", "0");
        cmdline.add("", "model",        "model configuration (.json)");
        cmdline.add("", "trainer",      join(get_trainers().ids()) + " (.json)");
        cmdline.add("", "loss",         join(get_losses().ids()) + " (.json)");
        cmdline.add("", "basepath",     "basepath where to save results (e.g. model, logs, history)");
        cmdline.add("", "threads",      "number of threads to use", physical_cpus());
        cmdline.add("", "trials",       "number of trials", 10);

        cmdline.process(argc, argv);

        // check arguments and options
        const auto cmd_task = cmdline.get<string_t>("task");
        const auto cmd_fold = cmdline.get<size_t>("fold");
        const auto cmd_model = cmdline.get<string_t>("model");
        const auto cmd_trainer = cmdline.get<string_t>("trainer");
        const auto cmd_loss = cmdline.get<string_t>("loss");
        const auto cmd_basepath = cmdline.get<string_t>("basepath");
        const auto cmd_threads = cmdline.get<size_t>("threads");
        const auto cmd_trials = cmdline.get<size_t>("trials");

        checkpoint_t checkpoint;
        string_t params, id;

        // load task
        checkpoint.step(strcat("load task configuration from <", cmd_task, ">"));
        checkpoint.critical(load_json(cmd_task, "task", params, id));

        rtask_t task;
        checkpoint.step(strcat("search task <", id, ">"));
        checkpoint.critical((task = get_tasks().get(id)) != nullptr);

        task->config(params);
        checkpoint.step(strcat("load task <", id, ">"));
        checkpoint.measure(task->load());

        describe(*task, id);

        // load loss
        checkpoint.step(strcat("load loss configuration from <", cmd_loss, ">"));
        checkpoint.critical(load_json(cmd_loss, "loss", params, id));

        rloss_t loss;
        checkpoint.step(strcat("search loss <", id, ">"));
        checkpoint.critical((loss = get_losses().get(id)) != nullptr);

        // load trainer
        checkpoint.step(strcat("load trainer configuration from <", cmd_trainer, ">"));
        checkpoint.critical(load_json(cmd_trainer, "trainer", params, id));

        rtrainer_t trainer;
        checkpoint.step(strcat("search trainer <", id, ">"));
        checkpoint.critical((trainer = get_trainers().get(id)) != nullptr);

        trainer->config(params);

        // load model
        checkpoint.step(strcat("load model configuration from <", cmd_model, ">"));
        checkpoint.critical(load_string(cmd_model, params));

        model_t model;
        checkpoint.step("configure model");
        checkpoint.measure(model.config(params) && model.resize(task->idims(), task->odims()));

        model.describe();
        if (model != *task)
        {
                log_error() << "model not compatible with the task!";
                return EXIT_FAILURE;
        }

        // setup accumulator
        accumulator_t acc(model, *loss);
        acc.threads(cmd_threads);

        // tune the trainer (once!)
        acc.random();
        trainer->tune(*task, cmd_fold, acc);

        table_t table;
        table.header()
                << "trial" << "epoch"
                << "train_loss" << "train_error"
                << "valid_loss" << "valid_error"
                << "test_loss" << "test_error"
                << "xnorm" << "gnorm"
                << "seconds" << "speed";
        table.delim();

        // train & save the model using multiple trials
        for (size_t trial = 0; trial < cmd_trials; ++ trial)
        {
                acc.random();
                trainer_result_t result;
                checkpoint.step("train model");
                checkpoint.measure((result = trainer->train(*task, cmd_fold, acc)) == true);

                model.params(result.optimum_params());

                const auto& state = result.optimum_state();
                table.append()
                        << (trial + 1) << state.m_epoch
                        << state.m_train.m_value << state.m_train.m_error
                        << state.m_valid.m_value << state.m_valid.m_error
                        << state.m_test.m_value << state.m_test.m_error
                        << state.m_xnorm << state.m_gnorm
                        << idiv(state.m_milis.count(), 1000)
                        << result.convergence_speed();

                checkpoint.step("save model");
                checkpoint.critical(
                        model.save(strcat(cmd_basepath, "_trial", trial + 1, ".model")) &&
                        result.save(strcat(cmd_basepath, "_trial", trial + 1, ".csv")));
        }

        checkpoint.step("save stats");
        checkpoint.critical(table.save(strcat(cmd_basepath, ".csv")));

        std::cout << std::fixed << std::setprecision(3) << table;

        // OK
        log_info() << done;
        return EXIT_SUCCESS;
}
<commit_msg>fix setting up the accumulator for training<commit_after>#include "loss.h"
#include "task.h"
#include "model.h"
#include "io/io.h"
#include "trainer.h"
#include "checkpoint.h"
#include "text/table.h"
#include "accumulator.h"
#include "text/cmdline.h"
#include <iomanip>
#include <iostream>

using namespace nano;

static bool load_json(const string_t& path, const char* name, string_t& json, string_t& id)
{
        if (!load_string(path, json) || json.empty())
        {
                return false;
        }

        json_reader_t(json).object(name, id);
        return !id.empty();
}

int main(int argc, const char *argv[])
{
        // parse the command line
        cmdline_t cmdline("train a model");
        cmdline.add("", "task",         join(get_tasks().ids()) + " (.json)");
        cmdline.add("", "fold",         "fold index to use for training", "0");
        cmdline.add("", "model",        "model configuration (.json)");
        cmdline.add("", "trainer",      join(get_trainers().ids()) + " (.json)");
        cmdline.add("", "loss",         join(get_losses().ids()) + " (.json)");
        cmdline.add("", "basepath",     "basepath where to save results (e.g. model, logs, history)");
        cmdline.add("", "threads",      "number of threads to use", physical_cpus());
        cmdline.add("", "trials",       "number of trials", 10);

        cmdline.process(argc, argv);

        // check arguments and options
        const auto cmd_task = cmdline.get<string_t>("task");
        const auto cmd_fold = cmdline.get<size_t>("fold");
        const auto cmd_model = cmdline.get<string_t>("model");
        const auto cmd_trainer = cmdline.get<string_t>("trainer");
        const auto cmd_loss = cmdline.get<string_t>("loss");
        const auto cmd_basepath = cmdline.get<string_t>("basepath");
        const auto cmd_threads = cmdline.get<size_t>("threads");
        const auto cmd_trials = cmdline.get<size_t>("trials");

        checkpoint_t checkpoint;
        string_t params, id;

        // load task
        checkpoint.step(strcat("load task configuration from <", cmd_task, ">"));
        checkpoint.critical(load_json(cmd_task, "task", params, id));

        rtask_t task;
        checkpoint.step(strcat("search task <", id, ">"));
        checkpoint.critical((task = get_tasks().get(id)) != nullptr);

        task->config(params);
        checkpoint.step(strcat("load task <", id, ">"));
        checkpoint.measure(task->load());

        describe(*task, id);

        // load loss
        checkpoint.step(strcat("load loss configuration from <", cmd_loss, ">"));
        checkpoint.critical(load_json(cmd_loss, "loss", params, id));

        rloss_t loss;
        checkpoint.step(strcat("search loss <", id, ">"));
        checkpoint.critical((loss = get_losses().get(id)) != nullptr);

        // load trainer
        checkpoint.step(strcat("load trainer configuration from <", cmd_trainer, ">"));
        checkpoint.critical(load_json(cmd_trainer, "trainer", params, id));

        rtrainer_t trainer;
        checkpoint.step(strcat("search trainer <", id, ">"));
        checkpoint.critical((trainer = get_trainers().get(id)) != nullptr);

        trainer->config(params);

        // load model
        checkpoint.step(strcat("load model configuration from <", cmd_model, ">"));
        checkpoint.critical(load_string(cmd_model, params));

        model_t model;
        checkpoint.step("configure model");
        checkpoint.measure(model.config(params) && model.resize(task->idims(), task->odims()));

        model.describe();
        if (model != *task)
        {
                log_error() << "model not compatible with the task!";
                return EXIT_FAILURE;
        }

        // setup accumulator
        accumulator_t acc(model, *loss);
        acc.mode(accumulator_t::type::vgrad);
        acc.threads(cmd_threads);

        // tune the trainer (once!)
        acc.random();
        trainer->tune(*task, cmd_fold, acc);

        table_t table;
        table.header()
                << "trial" << "epoch"
                << "train_loss" << "train_error"
                << "valid_loss" << "valid_error"
                << "test_loss" << "test_error"
                << "xnorm" << "gnorm"
                << "seconds" << "speed";
        table.delim();

        // train & save the model using multiple trials
        for (size_t trial = 0; trial < cmd_trials; ++ trial)
        {
                acc.random();
                trainer_result_t result;
                checkpoint.step("train model");
                checkpoint.measure((result = trainer->train(*task, cmd_fold, acc)) == true);

                model.params(result.optimum_params());

                const auto& state = result.optimum_state();
                table.append()
                        << (trial + 1) << state.m_epoch
                        << state.m_train.m_value << state.m_train.m_error
                        << state.m_valid.m_value << state.m_valid.m_error
                        << state.m_test.m_value << state.m_test.m_error
                        << state.m_xnorm << state.m_gnorm
                        << idiv(state.m_milis.count(), 1000)
                        << result.convergence_speed();

                checkpoint.step("save model");
                checkpoint.critical(
                        model.save(strcat(cmd_basepath, "_trial", trial + 1, ".model")) &&
                        result.save(strcat(cmd_basepath, "_trial", trial + 1, ".csv")));
        }

        checkpoint.step("save stats");
        checkpoint.critical(table.save(strcat(cmd_basepath, ".csv")));

        std::cout << std::fixed << std::setprecision(3) << table;

        // OK
        log_info() << done;
        return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>#include "base/flags.hpp"

namespace principia {
namespace base {

void Flags::Clear() {
  flags_.clear();
}

void Flags::Set(std::string_view const name, std::string_view const value) {
  flags_.emplace(std::string(name), std::string(value));
}

bool Flags::IsPresent(std::string_view const name) {
  return flags_.find(std::string(name)) != flags_.end();
}

bool Flags::IsPresent(std::string_view const name,
                      std::string_view const value) {
  auto const pair = flags_.equal_range(std::string(name));
  std::set<std::string> values;
  for (auto it = pair.first; it != pair.second; ++it) {
    if (it->second == value) {
      return true;
    }
  }
  return false;
}

std::set<std::string> Flags::Values(std::string_view const name) {
  auto const pair = flags_.equal_range(std::string(name));
  std::set<std::string> values;
  for (auto it = pair.first; it != pair.second; ++it) {
    values.insert(it->second);
  }
  return values;
}

std::multimap<std::string, std::string> Flags::flags_;

}  // namespace base
}  // namespace principia
<commit_msg>Lint.<commit_after>#include "base/flags.hpp"

#include <map>
#include <set>
#include <string>

namespace principia {
namespace base {

void Flags::Clear() {
  flags_.clear();
}

void Flags::Set(std::string_view const name, std::string_view const value) {
  flags_.emplace(std::string(name), std::string(value));
}

bool Flags::IsPresent(std::string_view const name) {
  return flags_.find(std::string(name)) != flags_.end();
}

bool Flags::IsPresent(std::string_view const name,
                      std::string_view const value) {
  auto const pair = flags_.equal_range(std::string(name));
  std::set<std::string> values;
  for (auto it = pair.first; it != pair.second; ++it) {
    if (it->second == value) {
      return true;
    }
  }
  return false;
}

std::set<std::string> Flags::Values(std::string_view const name) {
  auto const pair = flags_.equal_range(std::string(name));
  std::set<std::string> values;
  for (auto it = pair.first; it != pair.second; ++it) {
    values.insert(it->second);
  }
  return values;
}

std::multimap<std::string, std::string> Flags::flags_;

}  // namespace base
}  // namespace principia
<|endoftext|>


<commit_before>/*
 * InputPaths.cpp
 *
 *  Created on: 23 Oct 2015
 *      Author: hieu
 */
#include <iostream>
#include "InputPaths.h"
#include "Phrase.h"
#include "System.h"
#include "moses/Range.h"

using namespace std;

InputPaths::~InputPaths() {
	// TODO Auto-generated destructor stub
}

void InputPaths::Init(const PhraseImpl &input, const System &system)
{
  size_t numPt = system.mappings.size();
  size_t size = input.GetSize();
  for (size_t phaseSize = 1; phaseSize <= min(size, system.maxPhraseLength) ; ++phaseSize) {
  //for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
	for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
	  size_t endPos = startPos + phaseSize -1;

	  SubPhrase subPhrase = input.GetSubPhrase(startPos, endPos);
	  Moses::Range range(startPos, endPos);

	  InputPath path(subPhrase, range, numPt);
	  m_inputPaths.push_back(path);
	}
  }

}

void InputPaths::DeleteUnusedPaths()
{
	size_t ind = 0;
	while (ind < m_inputPaths.size()) {
		const InputPath &path = m_inputPaths[ind];
		if (path.IsUsed()) {
			m_inputPaths.erase(m_inputPaths.begin() + ind);
		}
		else {
			++ind;
		}
	}
}

<commit_msg>prefix path<commit_after>/*
 * InputPaths.cpp
 *
 *  Created on: 23 Oct 2015
 *      Author: hieu
 */
#include <iostream>
#include "InputPaths.h"
#include "Phrase.h"
#include "System.h"
#include "moses/Range.h"

using namespace std;

InputPaths::~InputPaths() {
	// TODO Auto-generated destructor stub
}

void InputPaths::Init(const PhraseImpl &input, const System &system)
{
  size_t numPt = system.mappings.size();
  size_t size = input.GetSize();
  size_t maxLength = min(size, system.maxPhraseLength);

  for (size_t phaseSize = 1; phaseSize <= maxLength; ++phaseSize) {
	for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
	  size_t endPos = startPos + phaseSize -1;

	  SubPhrase subPhrase = input.GetSubPhrase(startPos, endPos);
	  Moses::Range range(startPos, endPos);

	  InputPath path(subPhrase, range, numPt);
	  m_inputPaths.push_back(path);
	}
  }

}

void InputPaths::DeleteUnusedPaths()
{
	size_t ind = 0;
	while (ind < m_inputPaths.size()) {
		const InputPath &path = m_inputPaths[ind];
		if (path.IsUsed()) {
			m_inputPaths.erase(m_inputPaths.begin() + ind);
		}
		else {
			++ind;
		}
	}
}

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * 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.
 *
 ************************************************************************/

#include <unx/svunx.h>
#include <unx/desktops.hxx>
#include <tools/prex.h>
#include <X11/Xatom.h>
#include <tools/postx.h>

#include "rtl/process.h"
#include "rtl/ustrbuf.hxx"
#include "osl/module.h"
#include "osl/thread.h"
#include "vcl/svapp.hxx"

#include "vclpluginapi.h"

#include <unistd.h>
#include <string.h>

using ::rtl::OUString;
using ::rtl::OString;

static bool is_gnome_desktop( Display* pDisplay )
{
    bool ret = false;

    // warning: these checks are coincidental, GNOME does not
    // explicitly advertise itself

    if ( NULL != getenv( "GNOME_DESKTOP_SESSION_ID" ) )
        ret = true;

    if( ! ret )
    {
        Atom nAtom1 = XInternAtom( pDisplay, "GNOME_SM_PROXY", True );
        Atom nAtom2 = XInternAtom( pDisplay, "NAUTILUS_DESKTOP_WINDOW_ID", True );
        if( nAtom1 || nAtom2 )
        {
            int nProperties = 0;
            Atom* pProperties = XListProperties( pDisplay, DefaultRootWindow( pDisplay ), &nProperties );
            if( pProperties && nProperties )
            {
                for( int i = 0; i < nProperties; i++ )
                    if( pProperties[ i ] == nAtom1 ||
                        pProperties[ i ] == nAtom2 )
                {
                    ret = true;
                }
                XFree( pProperties );
            }
        }
    }

    if( ! ret )
    {
        Atom nUTFAtom       = XInternAtom( pDisplay, "UTF8_STRING", True );
        Atom nNetWMNameAtom = XInternAtom( pDisplay, "_NET_WM_NAME", True );
        if( nUTFAtom && nNetWMNameAtom )
        {
            // another, more expensive check: search for a gnome-panel
            XLIB_Window aRoot, aParent, *pChildren = NULL;
            unsigned int nChildren = 0;
            XQueryTree( pDisplay, DefaultRootWindow( pDisplay ),
                        &aRoot, &aParent, &pChildren, &nChildren );
            if( pChildren && nChildren )
            {
                for( unsigned int i = 0; i < nChildren && ! ret; i++ )
                {
                    Atom nType = None;
                    int nFormat = 0;
                    unsigned long nItems = 0, nBytes = 0;
                    unsigned char* pProp = NULL;
                    XGetWindowProperty( pDisplay,
                                        pChildren[i],
                                        nNetWMNameAtom,
                                        0, 8,
                                        False,
                                        nUTFAtom,
                                        &nType,
                                        &nFormat,
                                        &nItems,
                                        &nBytes,
                                        &pProp );
                    if( pProp && nType == nUTFAtom )
                    {
                        OString aWMName( (sal_Char*)pProp );
                        if( aWMName.equalsIgnoreAsciiCase( "gnome-panel" ) )
                            ret = true;
                    }
                    if( pProp )
                        XFree( pProp );
                }
                XFree( pChildren );
            }
        }
    }

    return ret;
}

static bool bWasXError = false;

static inline bool WasXError()
{
    bool bRet = bWasXError;
    bWasXError = false;
    return bRet;
}

extern "C"
{
    static int autodect_error_handler( Display*, XErrorEvent* )
    {
        bWasXError = true;
        return 0;
    }

    typedef int(* XErrorHandler)(Display*,XErrorEvent*);
}

static int TDEVersion( Display* pDisplay )
{
    int nRet = 0;

    Atom nFullSession = XInternAtom( pDisplay, "TDE_FULL_SESSION", True );
    Atom nTDEVersion  = XInternAtom( pDisplay, "TDE_SESSION_VERSION", True );

    if( nFullSession )
    {
        if( !nTDEVersion )
            return 14;

        Atom                aRealType   = None;
        int                 nFormat     = 8;
        unsigned long       nItems      = 0;
        unsigned long       nBytesLeft  = 0;
        unsigned char*  pProperty   = NULL;
        XGetWindowProperty( pDisplay,
                            DefaultRootWindow( pDisplay ),
                            nTDEVersion,
                            0, 1,
                            False,
                            AnyPropertyType,
                            &aRealType,
                            &nFormat,
                            &nItems,
                            &nBytesLeft,
                            &pProperty );
        if( !WasXError() && nItems != 0 && pProperty )
        {
            nRet = *reinterpret_cast< sal_Int32* >( pProperty );
        }
        if( pProperty )
        {
            XFree( pProperty );
            pProperty = NULL;
        }
    }
    return nRet;
}

static int KDEVersion( Display* pDisplay )
{
    int nRet = 0;

    Atom nFullSession = XInternAtom( pDisplay, "KDE_FULL_SESSION", True );
    Atom nKDEVersion  = XInternAtom( pDisplay, "KDE_SESSION_VERSION", True );

    if( nFullSession )
    {
        if( !nKDEVersion )
            return 3;

        Atom                aRealType   = None;
        int                 nFormat     = 8;
        unsigned long       nItems      = 0;
        unsigned long       nBytesLeft  = 0;
        unsigned char*  pProperty   = NULL;
        XGetWindowProperty( pDisplay,
                            DefaultRootWindow( pDisplay ),
                            nKDEVersion,
                            0, 1,
                            False,
                            AnyPropertyType,
                            &aRealType,
                            &nFormat,
                            &nItems,
                            &nBytesLeft,
                            &pProperty );
        if( !WasXError() && nItems != 0 && pProperty )
        {
            nRet = *reinterpret_cast< sal_Int32* >( pProperty );
        }
        if( pProperty )
        {
            XFree( pProperty );
            pProperty = NULL;
        }
    }
    return nRet;
}

static bool is_tde_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "TDE_FULL_SESSION" ) )
    {
        return true; // TDE
    }

    if ( TDEVersion( pDisplay ) >= 14 )
        return true;

    return false;
}

static bool is_kde_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "KDE_FULL_SESSION" ) )
    {
        const char *pVer = getenv( "KDE_SESSION_VERSION" );
        if ( !pVer || pVer[0] == '0' )
        {
            return true; // does not exist => KDE3
        }

        rtl::OUString aVer( RTL_CONSTASCII_USTRINGPARAM( "3" ) );
        if ( aVer.equalsIgnoreAsciiCaseAscii( pVer ) )
        {
            return true;
        }
    }

    if ( KDEVersion( pDisplay ) == 3 )
        return true;

    return false;
}

static bool is_kde4_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "KDE_FULL_SESSION" ) )
    {
        rtl::OUString aVer( RTL_CONSTASCII_USTRINGPARAM( "4" ) );

        const char *pVer = getenv( "KDE_SESSION_VERSION" );
        if ( pVer && aVer.equalsIgnoreAsciiCaseAscii( pVer ) )
            return true;
    }

    if ( KDEVersion( pDisplay ) == 4 )
        return true;

    return false;
}

extern "C"
{

DESKTOP_DETECTOR_PUBLIC DesktopType get_desktop_environment()
{
    static const char *pOverride = getenv( "OOO_FORCE_DESKTOP" );

    if ( pOverride && *pOverride )
    {
        OString aOver( pOverride );

        if ( aOver.equalsIgnoreAsciiCase( "tde" ) )
            return DESKTOP_TDE;
        if ( aOver.equalsIgnoreAsciiCase( "kde4" ) )
            return DESKTOP_KDE4;
        if ( aOver.equalsIgnoreAsciiCase( "gnome" ) )
            return DESKTOP_GNOME;
        if ( aOver.equalsIgnoreAsciiCase( "kde" ) )
            return DESKTOP_KDE;
        if ( aOver.equalsIgnoreAsciiCase( "none" ) )
            return DESKTOP_UNKNOWN;
    }

    // get display to connect to
    const char* pDisplayStr = getenv( "DISPLAY" );

    const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );

    if ((pUsePlugin && (strcmp(pUsePlugin, "svp") == 0))
        || Application::IsHeadlessModeRequested())
        pDisplayStr = NULL;
    else
    {
        int nParams = rtl_getAppCommandArgCount();
        OUString aParam;
        OString aBParm;
        for( int i = 0; i < nParams; i++ )
        {
            rtl_getAppCommandArg( i, &aParam.pData );
            if( i < nParams-1 && (aParam == "-display" || aParam == "--display" ) )
            {
                osl_getCommandArg( i+1, &aParam.pData );
                aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() );
                pDisplayStr = aBParm.getStr();
                break;
            }
        }
    }

    // no server at all
    if( ! pDisplayStr || !*pDisplayStr )
        return DESKTOP_NONE;

    /* #i92121# workaround deadlocks in the X11 implementation
    */
    static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
    /* #i90094#
       from now on we know that an X connection will be
       established, so protect X against itself
    */
    if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
        XInitThreads();

    Display* pDisplay = XOpenDisplay( pDisplayStr );
    if( pDisplay == NULL )
        return DESKTOP_NONE;

    DesktopType ret;

    XErrorHandler pOldHdl = XSetErrorHandler( autodect_error_handler );

    if ( is_tde_desktop( pDisplay ) )
        ret = DESKTOP_TDE;
    else if ( is_kde4_desktop( pDisplay ) )
        ret = DESKTOP_KDE4;
    else if ( is_gnome_desktop( pDisplay ) )
        ret = DESKTOP_GNOME;
    else if ( is_kde_desktop( pDisplay ) )
        ret = DESKTOP_KDE;
    else
        ret = DESKTOP_UNKNOWN;

    // set the default handler again
    XSetErrorHandler( pOldHdl );

    XCloseDisplay( pDisplay );

    return ret;
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>Related: fdo#30763 fill in default user realname under GNOME3<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * 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.
 *
 ************************************************************************/

#include <unx/svunx.h>
#include <unx/desktops.hxx>
#include <tools/prex.h>
#include <X11/Xatom.h>
#include <tools/postx.h>

#include "rtl/process.h"
#include "rtl/ustrbuf.hxx"
#include "osl/module.h"
#include "osl/thread.h"
#include "vcl/svapp.hxx"

#include "vclpluginapi.h"

#include <unistd.h>
#include <string.h>

using ::rtl::OUString;
using ::rtl::OString;

static bool is_gnome_desktop( Display* pDisplay )
{
    bool ret = false;

    // warning: these checks are coincidental, GNOME does not
    // explicitly advertise itself

    if ( NULL != getenv( "GNOME_DESKTOP_SESSION_ID" ) )
        ret = true;

    if( ! ret )
    {
        Atom nAtom1 = XInternAtom( pDisplay, "GNOME_SM_PROXY", True );
        Atom nAtom2 = XInternAtom( pDisplay, "NAUTILUS_DESKTOP_WINDOW_ID", True );
        if( nAtom1 || nAtom2 )
        {
            int nProperties = 0;
            Atom* pProperties = XListProperties( pDisplay, DefaultRootWindow( pDisplay ), &nProperties );
            if( pProperties && nProperties )
            {
                for( int i = 0; i < nProperties; i++ )
                    if( pProperties[ i ] == nAtom1 ||
                        pProperties[ i ] == nAtom2 )
                {
                    ret = true;
                }
                XFree( pProperties );
            }
        }
    }

    if( ! ret )
    {
        Atom nUTFAtom       = XInternAtom( pDisplay, "UTF8_STRING", True );
        Atom nNetWMNameAtom = XInternAtom( pDisplay, "_NET_WM_NAME", True );
        if( nUTFAtom && nNetWMNameAtom )
        {
            // another, more expensive check: search for a gnome-panel
            XLIB_Window aRoot, aParent, *pChildren = NULL;
            unsigned int nChildren = 0;
            XQueryTree( pDisplay, DefaultRootWindow( pDisplay ),
                        &aRoot, &aParent, &pChildren, &nChildren );
            if( pChildren && nChildren )
            {
                for( unsigned int i = 0; i < nChildren && ! ret; i++ )
                {
                    Atom nType = None;
                    int nFormat = 0;
                    unsigned long nItems = 0, nBytes = 0;
                    unsigned char* pProp = NULL;
                    XGetWindowProperty( pDisplay,
                                        pChildren[i],
                                        nNetWMNameAtom,
                                        0, 8,
                                        False,
                                        nUTFAtom,
                                        &nType,
                                        &nFormat,
                                        &nItems,
                                        &nBytes,
                                        &pProp );
                    if( pProp && nType == nUTFAtom )
                    {
                        OString aWMName( (sal_Char*)pProp );
                        if (
                            (aWMName.equalsIgnoreAsciiCase("gnome-shell")) ||
                            (aWMName.equalsIgnoreAsciiCase("gnome-panel"))
                           )
                        {
                            ret = true;
                        }
                    }
                    if( pProp )
                        XFree( pProp );
                }
                XFree( pChildren );
            }
        }
    }

    return ret;
}

static bool bWasXError = false;

static inline bool WasXError()
{
    bool bRet = bWasXError;
    bWasXError = false;
    return bRet;
}

extern "C"
{
    static int autodect_error_handler( Display*, XErrorEvent* )
    {
        bWasXError = true;
        return 0;
    }

    typedef int(* XErrorHandler)(Display*,XErrorEvent*);
}

static int TDEVersion( Display* pDisplay )
{
    int nRet = 0;

    Atom nFullSession = XInternAtom( pDisplay, "TDE_FULL_SESSION", True );
    Atom nTDEVersion  = XInternAtom( pDisplay, "TDE_SESSION_VERSION", True );

    if( nFullSession )
    {
        if( !nTDEVersion )
            return 14;

        Atom                aRealType   = None;
        int                 nFormat     = 8;
        unsigned long       nItems      = 0;
        unsigned long       nBytesLeft  = 0;
        unsigned char*  pProperty   = NULL;
        XGetWindowProperty( pDisplay,
                            DefaultRootWindow( pDisplay ),
                            nTDEVersion,
                            0, 1,
                            False,
                            AnyPropertyType,
                            &aRealType,
                            &nFormat,
                            &nItems,
                            &nBytesLeft,
                            &pProperty );
        if( !WasXError() && nItems != 0 && pProperty )
        {
            nRet = *reinterpret_cast< sal_Int32* >( pProperty );
        }
        if( pProperty )
        {
            XFree( pProperty );
            pProperty = NULL;
        }
    }
    return nRet;
}

static int KDEVersion( Display* pDisplay )
{
    int nRet = 0;

    Atom nFullSession = XInternAtom( pDisplay, "KDE_FULL_SESSION", True );
    Atom nKDEVersion  = XInternAtom( pDisplay, "KDE_SESSION_VERSION", True );

    if( nFullSession )
    {
        if( !nKDEVersion )
            return 3;

        Atom                aRealType   = None;
        int                 nFormat     = 8;
        unsigned long       nItems      = 0;
        unsigned long       nBytesLeft  = 0;
        unsigned char*  pProperty   = NULL;
        XGetWindowProperty( pDisplay,
                            DefaultRootWindow( pDisplay ),
                            nKDEVersion,
                            0, 1,
                            False,
                            AnyPropertyType,
                            &aRealType,
                            &nFormat,
                            &nItems,
                            &nBytesLeft,
                            &pProperty );
        if( !WasXError() && nItems != 0 && pProperty )
        {
            nRet = *reinterpret_cast< sal_Int32* >( pProperty );
        }
        if( pProperty )
        {
            XFree( pProperty );
            pProperty = NULL;
        }
    }
    return nRet;
}

static bool is_tde_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "TDE_FULL_SESSION" ) )
    {
        return true; // TDE
    }

    if ( TDEVersion( pDisplay ) >= 14 )
        return true;

    return false;
}

static bool is_kde_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "KDE_FULL_SESSION" ) )
    {
        const char *pVer = getenv( "KDE_SESSION_VERSION" );
        if ( !pVer || pVer[0] == '0' )
        {
            return true; // does not exist => KDE3
        }

        rtl::OUString aVer( RTL_CONSTASCII_USTRINGPARAM( "3" ) );
        if ( aVer.equalsIgnoreAsciiCaseAscii( pVer ) )
        {
            return true;
        }
    }

    if ( KDEVersion( pDisplay ) == 3 )
        return true;

    return false;
}

static bool is_kde4_desktop( Display* pDisplay )
{
    if ( NULL != getenv( "KDE_FULL_SESSION" ) )
    {
        rtl::OUString aVer( RTL_CONSTASCII_USTRINGPARAM( "4" ) );

        const char *pVer = getenv( "KDE_SESSION_VERSION" );
        if ( pVer && aVer.equalsIgnoreAsciiCaseAscii( pVer ) )
            return true;
    }

    if ( KDEVersion( pDisplay ) == 4 )
        return true;

    return false;
}

extern "C"
{

DESKTOP_DETECTOR_PUBLIC DesktopType get_desktop_environment()
{
    static const char *pOverride = getenv( "OOO_FORCE_DESKTOP" );

    if ( pOverride && *pOverride )
    {
        OString aOver( pOverride );

        if ( aOver.equalsIgnoreAsciiCase( "tde" ) )
            return DESKTOP_TDE;
        if ( aOver.equalsIgnoreAsciiCase( "kde4" ) )
            return DESKTOP_KDE4;
        if ( aOver.equalsIgnoreAsciiCase( "gnome" ) )
            return DESKTOP_GNOME;
        if ( aOver.equalsIgnoreAsciiCase( "kde" ) )
            return DESKTOP_KDE;
        if ( aOver.equalsIgnoreAsciiCase( "none" ) )
            return DESKTOP_UNKNOWN;
    }

    // get display to connect to
    const char* pDisplayStr = getenv( "DISPLAY" );

    const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );

    if ((pUsePlugin && (strcmp(pUsePlugin, "svp") == 0))
        || Application::IsHeadlessModeRequested())
        pDisplayStr = NULL;
    else
    {
        int nParams = rtl_getAppCommandArgCount();
        OUString aParam;
        OString aBParm;
        for( int i = 0; i < nParams; i++ )
        {
            rtl_getAppCommandArg( i, &aParam.pData );
            if( i < nParams-1 && (aParam == "-display" || aParam == "--display" ) )
            {
                osl_getCommandArg( i+1, &aParam.pData );
                aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() );
                pDisplayStr = aBParm.getStr();
                break;
            }
        }
    }

    // no server at all
    if( ! pDisplayStr || !*pDisplayStr )
        return DESKTOP_NONE;

    /* #i92121# workaround deadlocks in the X11 implementation
    */
    static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
    /* #i90094#
       from now on we know that an X connection will be
       established, so protect X against itself
    */
    if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
        XInitThreads();

    Display* pDisplay = XOpenDisplay( pDisplayStr );
    if( pDisplay == NULL )
        return DESKTOP_NONE;

    DesktopType ret;

    XErrorHandler pOldHdl = XSetErrorHandler( autodect_error_handler );

    if ( is_tde_desktop( pDisplay ) )
        ret = DESKTOP_TDE;
    else if ( is_kde4_desktop( pDisplay ) )
        ret = DESKTOP_KDE4;
    else if ( is_gnome_desktop( pDisplay ) )
        ret = DESKTOP_GNOME;
    else if ( is_kde_desktop( pDisplay ) )
        ret = DESKTOP_KDE;
    else
        ret = DESKTOP_UNKNOWN;

    // set the default handler again
    XSetErrorHandler( pOldHdl );

    XCloseDisplay( pDisplay );

    return ret;
}

}

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


<commit_before>/*
 * ModuleClassRegistry.cpp
 * Copyright (C) 2008 - 2015 by MegaMol Consortium
 * All rights reserved. Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "factories/ModuleClassRegistry.h"

#include "mmcore/factories/ModuleDescriptionManager.h"
#include "mmcore/factories/LoaderADModuleAutoDescription.h"
#include "mmcore/factories/ModuleAutoDescription.h"
#include "mmcore/factories/ModuleDescription.h"

#include "mmcore/cluster/ClusterController.h"
#include "mmcore/cluster/ClusterViewMaster.h"
#include "mmcore/cluster/PowerwallView.h"
#include "mmcore/cluster/mpi/MpiProvider.h"
#include "mmcore/cluster/mpi/View.h"
#include "mmcore/cluster/simple/Client.h"
#include "mmcore/cluster/simple/Heartbeat.h"
#include "mmcore/cluster/simple/Server.h"
#include "mmcore/cluster/simple/View.h"
#include "mmcore/misc/SiffCSplineFitter.h"
#include "mmcore/misc/WatermarkRenderer.h"
#include "mmcore/misc/TestSpheresDataSource.h"
#include "mmcore/moldyn/AddParticleColours.h"
#include "mmcore/moldyn/ArrowRenderer.h"
#include "mmcore/moldyn/DataGridder.h"
#include "mmcore/moldyn/GrimRenderer.h"
#include "mmcore/moldyn/MipDepthSphereRenderer.h"
#include "mmcore/moldyn/MMPGDDataSource.h"
#include "mmcore/moldyn/MMPGDWriter.h"
#include "mmcore/moldyn/MMPLDDataSource.h"
#include "mmcore/moldyn/MMPLDWriter.h"
#include "mmcore/moldyn/OracleSphereRenderer.h"
#include "mmcore/moldyn/SimpleGeoSphereRenderer.h"
#include "mmcore/moldyn/SimpleSphereRenderer.h"
#include "mmcore/moldyn/ClusteredSphereRenderer.h"
#include "mmcore/moldyn/SphereOutlineRenderer.h"
#include "mmcore/moldyn/DirPartColModulate.h"
#include "mmcore/moldyn/DirPartFilter.h"
#include "mmcore/moldyn/ParticleListFilter.h"
//#include "mmcore/special/ColStereoDisplay.h"
#include "mmcore/special/StubModule.h"
#include "mmcore/view/ClipPlane.h"
#include "mmcore/view/LinearTransferFunction.h"
#include "mmcore/view/TransferFunctionRenderer.h"
#include "mmcore/view/MuxRenderer3D.h"
#include "mmcore/view/special/AnaglyphStereoView.h"
#include "mmcore/view/special/ChronoGraph.h"
#include "mmcore/view/special/DemoRenderer2D.h"
#include "mmcore/view/special/QuadBufferStereoView.h"
#include "mmcore/view/special/ScreenShooter.h"
#include "mmcore/view/SwitchRenderer3D.h"
#include "mmcore/view/TileView.h"
#include "mmcore/view/View2D.h"
#include "mmcore/view/View3D.h"
#include "mmcore/view/RendererRegistration.h"
#ifdef MEGAMOLCORE_WITH_DIRECT3D11
#include "mmcore/view/ViewDirect3D.h"
#include "mmcore/moldyn/D3D11SimpleSphereRenderer.h"
#endif /* MEGAMOLCORE_WITH_DIRECT3D11 */
#include "mmcore/view/BlinnPhongRendererDeferred.h"
#include "mmcore/view/SplitView.h"
#include "mmcore/view/SharedCameraParameters.h"
#include "mmcore/view/LinkedView3D.h"
#include "mmcore/job/DataWriterJob.h"
#include "mmcore/job/JobThread.h"
#include "mmcore/moldyn/VolumeDataCall.h"
#include "mmcore/moldyn/AddClusterColours.h"
#include "mmcore/moldyn/DynDensityGradientEstimator.h"
#include "job/PluginsStateFileGeneratorJob.h"
#include "mmcore/utility/LuaHostSettingsModule.h"

using namespace megamol::core;

/*
 * factories::register_module_classes
 */
void factories::register_module_classes(factories::ModuleDescriptionManager& instance) {

    //////////////////////////////////////////////////////////////////////
    // Register all rendering graph module descriptions here
    //////////////////////////////////////////////////////////////////////

    instance.RegisterAutoDescription<cluster::ClusterController>();
    instance.RegisterAutoDescription<cluster::ClusterViewMaster>();
    instance.RegisterAutoDescription<cluster::PowerwallView>();
    instance.RegisterAutoDescription<cluster::simple::Client>();
    instance.RegisterAutoDescription<cluster::simple::Heartbeat>();
    instance.RegisterAutoDescription<cluster::simple::Server>();
    instance.RegisterAutoDescription<cluster::simple::View>();
    instance.RegisterAutoDescription<cluster::mpi::MpiProvider>();
    instance.RegisterAutoDescription<cluster::mpi::View>();
    instance.RegisterAutoDescription<misc::SiffCSplineFitter>();
    instance.RegisterAutoDescription<misc::WatermarkRenderer>();
    instance.RegisterAutoDescription<misc::TestSpheresDataSource>();
    instance.RegisterAutoDescription<moldyn::AddParticleColours>();
    instance.RegisterAutoDescription<moldyn::ArrowRenderer>();
    instance.RegisterAutoDescription<moldyn::DataGridder>();
    instance.RegisterAutoDescription<moldyn::GrimRenderer>();
    instance.RegisterAutoDescription<moldyn::MipDepthSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::MMPGDDataSource>();
    instance.RegisterAutoDescription<moldyn::MMPGDWriter>();
    instance.RegisterAutoDescription<moldyn::MMPLDDataSource>();
    instance.RegisterAutoDescription<moldyn::MMPLDWriter>();
    instance.RegisterAutoDescription<moldyn::SimpleGeoSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::SimpleSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::ClusteredSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::SphereOutlineRenderer>();
    instance.RegisterAutoDescription<moldyn::OracleSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::DirPartColModulate>();
    instance.RegisterAutoDescription<moldyn::ParticleListFilter>();
    instance.RegisterAutoDescription<moldyn::DirPartFilter>();
    //instance.RegisterAutoDescription<special::ColStereoDisplay>();
    instance.RegisterAutoDescription<special::StubModule>();
    instance.RegisterAutoDescription<view::ClipPlane>();
    instance.RegisterAutoDescription<view::LinearTransferFunction>();
    instance.RegisterAutoDescription<view::TransferFunctionRenderer>();
    instance.RegisterAutoDescription<view::MuxRenderer3D<2> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<3> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<4> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<5> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<10> >();
    instance.RegisterAutoDescription<view::special::AnaglyphStereoView>();
    instance.RegisterAutoDescription<view::special::ChronoGraph>();
    instance.RegisterAutoDescription<view::special::DemoRenderer2D>();
    instance.RegisterAutoDescription<view::special::QuadBufferStereoView>();
    instance.RegisterAutoDescription<view::special::ScreenShooter>();
    instance.RegisterAutoDescription<view::SwitchRenderer3D>();
    instance.RegisterAutoDescription<view::TileView>();
    instance.RegisterAutoDescription<view::View2D>();
    instance.RegisterAutoDescription<view::View3D>();
    instance.RegisterAutoDescription<view::BlinnPhongRendererDeferred>();
    instance.RegisterAutoDescription<view::SplitView>();
    instance.RegisterAutoDescription<view::SharedCameraParameters>();
    instance.RegisterAutoDescription<view::LinkedView3D>();
    instance.RegisterAutoDescription<view::RendererRegistration>();
    instance.RegisterAutoDescription<job::DataWriterJob>();
    instance.RegisterAutoDescription<job::JobThread>();
    instance.RegisterAutoDescription<moldyn::AddClusterColours>();
    instance.RegisterAutoDescription<moldyn::DynDensityGradientEstimator>();
#ifdef MEGAMOLCORE_WITH_DIRECT3D11
    instance.RegisterAutoDescription<view::ViewDirect3D>();
    instance.RegisterAutoDescription<moldyn::D3D11SimpleSphereRenderer>();
#endif /* MEGAMOLCORE_WITH_DIRECT3D11 */
    instance.RegisterAutoDescription<job::PluginsStateFileGeneratorJob>();
    instance.RegisterAutoDescription<core::utility::LuaHostSettingsModule>();
}
<commit_msg>made the new view visible to the configurator<commit_after>/*
 * ModuleClassRegistry.cpp
 * Copyright (C) 2008 - 2015 by MegaMol Consortium
 * All rights reserved. Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "factories/ModuleClassRegistry.h"

#include "mmcore/factories/ModuleDescriptionManager.h"
#include "mmcore/factories/LoaderADModuleAutoDescription.h"
#include "mmcore/factories/ModuleAutoDescription.h"
#include "mmcore/factories/ModuleDescription.h"

#include "mmcore/cluster/ClusterController.h"
#include "mmcore/cluster/ClusterViewMaster.h"
#include "mmcore/cluster/PowerwallView.h"
#include "mmcore/cluster/mpi/MpiProvider.h"
#include "mmcore/cluster/mpi/View.h"
#include "mmcore/cluster/simple/Client.h"
#include "mmcore/cluster/simple/Heartbeat.h"
#include "mmcore/cluster/simple/Server.h"
#include "mmcore/cluster/simple/View.h"
#include "mmcore/misc/SiffCSplineFitter.h"
#include "mmcore/misc/WatermarkRenderer.h"
#include "mmcore/misc/TestSpheresDataSource.h"
#include "mmcore/moldyn/AddParticleColours.h"
#include "mmcore/moldyn/ArrowRenderer.h"
#include "mmcore/moldyn/DataGridder.h"
#include "mmcore/moldyn/GrimRenderer.h"
#include "mmcore/moldyn/MipDepthSphereRenderer.h"
#include "mmcore/moldyn/MMPGDDataSource.h"
#include "mmcore/moldyn/MMPGDWriter.h"
#include "mmcore/moldyn/MMPLDDataSource.h"
#include "mmcore/moldyn/MMPLDWriter.h"
#include "mmcore/moldyn/OracleSphereRenderer.h"
#include "mmcore/moldyn/SimpleGeoSphereRenderer.h"
#include "mmcore/moldyn/SimpleSphereRenderer.h"
#include "mmcore/moldyn/ClusteredSphereRenderer.h"
#include "mmcore/moldyn/SphereOutlineRenderer.h"
#include "mmcore/moldyn/DirPartColModulate.h"
#include "mmcore/moldyn/DirPartFilter.h"
#include "mmcore/moldyn/ParticleListFilter.h"
//#include "mmcore/special/ColStereoDisplay.h"
#include "mmcore/special/StubModule.h"
#include "mmcore/view/ClipPlane.h"
#include "mmcore/view/LinearTransferFunction.h"
#include "mmcore/view/TransferFunctionRenderer.h"
#include "mmcore/view/MuxRenderer3D.h"
#include "mmcore/view/special/AnaglyphStereoView.h"
#include "mmcore/view/special/ChronoGraph.h"
#include "mmcore/view/special/DemoRenderer2D.h"
#include "mmcore/view/special/QuadBufferStereoView.h"
#include "mmcore/view/special/ScreenShooter.h"
#include "mmcore/view/SwitchRenderer3D.h"
#include "mmcore/view/TileView.h"
#include "mmcore/view/View2D.h"
#include "mmcore/view/View3D.h"
#include "mmcore/view/View3D2000GT.h"
#include "mmcore/view/RendererRegistration.h"
#ifdef MEGAMOLCORE_WITH_DIRECT3D11
#include "mmcore/view/ViewDirect3D.h"
#include "mmcore/moldyn/D3D11SimpleSphereRenderer.h"
#endif /* MEGAMOLCORE_WITH_DIRECT3D11 */
#include "mmcore/view/BlinnPhongRendererDeferred.h"
#include "mmcore/view/SplitView.h"
#include "mmcore/view/SharedCameraParameters.h"
#include "mmcore/view/LinkedView3D.h"
#include "mmcore/job/DataWriterJob.h"
#include "mmcore/job/JobThread.h"
#include "mmcore/moldyn/VolumeDataCall.h"
#include "mmcore/moldyn/AddClusterColours.h"
#include "mmcore/moldyn/DynDensityGradientEstimator.h"
#include "job/PluginsStateFileGeneratorJob.h"
#include "mmcore/utility/LuaHostSettingsModule.h"

using namespace megamol::core;

/*
 * factories::register_module_classes
 */
void factories::register_module_classes(factories::ModuleDescriptionManager& instance) {

    //////////////////////////////////////////////////////////////////////
    // Register all rendering graph module descriptions here
    //////////////////////////////////////////////////////////////////////

    instance.RegisterAutoDescription<cluster::ClusterController>();
    instance.RegisterAutoDescription<cluster::ClusterViewMaster>();
    instance.RegisterAutoDescription<cluster::PowerwallView>();
    instance.RegisterAutoDescription<cluster::simple::Client>();
    instance.RegisterAutoDescription<cluster::simple::Heartbeat>();
    instance.RegisterAutoDescription<cluster::simple::Server>();
    instance.RegisterAutoDescription<cluster::simple::View>();
    instance.RegisterAutoDescription<cluster::mpi::MpiProvider>();
    instance.RegisterAutoDescription<cluster::mpi::View>();
    instance.RegisterAutoDescription<misc::SiffCSplineFitter>();
    instance.RegisterAutoDescription<misc::WatermarkRenderer>();
    instance.RegisterAutoDescription<misc::TestSpheresDataSource>();
    instance.RegisterAutoDescription<moldyn::AddParticleColours>();
    instance.RegisterAutoDescription<moldyn::ArrowRenderer>();
    instance.RegisterAutoDescription<moldyn::DataGridder>();
    instance.RegisterAutoDescription<moldyn::GrimRenderer>();
    instance.RegisterAutoDescription<moldyn::MipDepthSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::MMPGDDataSource>();
    instance.RegisterAutoDescription<moldyn::MMPGDWriter>();
    instance.RegisterAutoDescription<moldyn::MMPLDDataSource>();
    instance.RegisterAutoDescription<moldyn::MMPLDWriter>();
    instance.RegisterAutoDescription<moldyn::SimpleGeoSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::SimpleSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::ClusteredSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::SphereOutlineRenderer>();
    instance.RegisterAutoDescription<moldyn::OracleSphereRenderer>();
    instance.RegisterAutoDescription<moldyn::DirPartColModulate>();
    instance.RegisterAutoDescription<moldyn::ParticleListFilter>();
    instance.RegisterAutoDescription<moldyn::DirPartFilter>();
    //instance.RegisterAutoDescription<special::ColStereoDisplay>();
    instance.RegisterAutoDescription<special::StubModule>();
    instance.RegisterAutoDescription<view::ClipPlane>();
    instance.RegisterAutoDescription<view::LinearTransferFunction>();
    instance.RegisterAutoDescription<view::TransferFunctionRenderer>();
    instance.RegisterAutoDescription<view::MuxRenderer3D<2> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<3> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<4> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<5> >();
    instance.RegisterAutoDescription<view::MuxRenderer3D<10> >();
    instance.RegisterAutoDescription<view::special::AnaglyphStereoView>();
    instance.RegisterAutoDescription<view::special::ChronoGraph>();
    instance.RegisterAutoDescription<view::special::DemoRenderer2D>();
    instance.RegisterAutoDescription<view::special::QuadBufferStereoView>();
    instance.RegisterAutoDescription<view::special::ScreenShooter>();
    instance.RegisterAutoDescription<view::SwitchRenderer3D>();
    instance.RegisterAutoDescription<view::TileView>();
    instance.RegisterAutoDescription<view::View2D>();
    instance.RegisterAutoDescription<view::View3D>();
	instance.RegisterAutoDescription<view::View3D2000GT>();
    instance.RegisterAutoDescription<view::BlinnPhongRendererDeferred>();
    instance.RegisterAutoDescription<view::SplitView>();
    instance.RegisterAutoDescription<view::SharedCameraParameters>();
    instance.RegisterAutoDescription<view::LinkedView3D>();
    instance.RegisterAutoDescription<view::RendererRegistration>();
    instance.RegisterAutoDescription<job::DataWriterJob>();
    instance.RegisterAutoDescription<job::JobThread>();
    instance.RegisterAutoDescription<moldyn::AddClusterColours>();
    instance.RegisterAutoDescription<moldyn::DynDensityGradientEstimator>();
#ifdef MEGAMOLCORE_WITH_DIRECT3D11
    instance.RegisterAutoDescription<view::ViewDirect3D>();
    instance.RegisterAutoDescription<moldyn::D3D11SimpleSphereRenderer>();
#endif /* MEGAMOLCORE_WITH_DIRECT3D11 */
    instance.RegisterAutoDescription<job::PluginsStateFileGeneratorJob>();
    instance.RegisterAutoDescription<core::utility::LuaHostSettingsModule>();
}
<|endoftext|>