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

#ifndef _LINK_HXX //autogen
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX //autogen wg. Size
#include <tools/gen.hxx>
#endif
#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _CALBCK_HXX
#include <calbck.hxx>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx>       // Fuer die inline-ASSERTs
#endif
#ifndef _SWERROR_H
#include <error.h>          // Fuer die inline-ASSERTs
#endif
#ifndef _SVX_NUMITEM_HXX
#include <svx/numitem.hxx>
#endif

#include <SwBitArray.hxx> // #i27615#

class Font;
class SvxBrushItem;
class SvxNumRule;
class SwCharFmt;
class SwDoc;
class SwFmtVertOrient;
class SwNodeNum;
class SwTxtNode;

extern char __FAR_DATA sOutlineStr[];   // SWG-Filter

BYTE GetRealLevel( const BYTE nLvl );

BOOL IsNum( BYTE nLvl );

BOOL IsShowNum( BYTE nLvl );

void SetNoNum( BYTE * nLvl, BOOL nVal = TRUE );

const sal_Unicode cBulletChar   = 0x2022;   // Charakter fuer Aufzaehlungen

class SwNumFmt : public SvxNumberFormat, public SwClient
{
    SwFmtVertOrient* pVertOrient;

    void UpdateNumNodes( SwDoc* pDoc );
    virtual void NotifyGraphicArrived();
public:
    SwNumFmt();
    SwNumFmt( const SwNumFmt& );
    SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);

    virtual ~SwNumFmt();

    SwNumFmt& operator=( const SwNumFmt& );
    BOOL operator==( const SwNumFmt& ) const;
    BOOL operator!=( const SwNumFmt& r ) const { return !(*this == r); }

    const Graphic* GetGraphic() const;

    SwCharFmt* GetCharFmt() const { return (SwCharFmt*)pRegisteredIn; }
    void SetCharFmt( SwCharFmt* );
    virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );

    virtual void            SetCharFmtName(const String& rSet);
    virtual const String&   GetCharFmtName()const;

    virtual void    SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const SvxFrameVertOrient* pOrient = 0);

    virtual void                SetVertOrient(SvxFrameVertOrient eSet);
    virtual SvxFrameVertOrient  GetVertOrient() const;
    const SwFmtVertOrient*      GetGraphicOrientation() const;
};

enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
class SwNumRule
{
    friend void _FinitCore();

    static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
    static USHORT aDefNumIndents[ MAXLEVEL ];
    static USHORT nRefCount;
    static Font* pDefBulletFont;
    static char* pDefOutlineName;

    SwNumFmt* aFmts[ MAXLEVEL ];

    /**
       marked levels
     */
    SwBitArray aMarkedLevels;

    String sName;
    SwNumRuleType eRuleType;
    USHORT nPoolFmtId;      // Id-fuer "automatich" erzeugte NumRules
    USHORT nPoolHelpId;     // HelpId fuer diese Pool-Vorlage
    BYTE nPoolHlpFileId;    // FilePos ans Doc auf die Vorlagen-Hilfen
    BOOL bAutoRuleFlag : 1;
    BOOL bInvalidRuleFlag : 1;
    BOOL bContinusNum : 1;  // Fortlaufende Numerierung - ohne Ebenen
    BOOL bAbsSpaces : 1;    // die Ebenen repraesentieren absol. Einzuege

    static void _MakeDefBulletFont();

public:
    SwNumRule( const String& rNm, SwNumRuleType = NUM_RULE,
                BOOL bAutoFlg = TRUE );

    SwNumRule( const SwNumRule& );
    ~SwNumRule();

    SwNumRule& operator=( const SwNumRule& );
    BOOL operator==( const SwNumRule& ) const;
    BOOL operator!=( const SwNumRule& r ) const { return !(*this == r); }

    const SwNumFmt* GetNumFmt( USHORT i ) const;
    const SwNumFmt& Get( USHORT i ) const;

    void Set( USHORT i, const SwNumFmt* );
    void Set( USHORT i, const SwNumFmt& );
    String MakeNumString( const SwNodeNum&, BOOL bInclStrings = TRUE,
                            BOOL bOnlyArabic = FALSE ) const;

    sal_Unicode GetBulletChar( const SwNodeNum& ) const;
    const Font* GetBulletFont( const SwNodeNum& ) const;
    static const Font& GetDefBulletFont();

    static char* GetOutlineRuleName() { return pDefOutlineName; }

    static USHORT GetNumIndent( BYTE nLvl );
    static USHORT GetBullIndent( BYTE nLvl );

    SwNumRuleType GetRuleType() const           { return eRuleType; }
    void SetRuleType( SwNumRuleType eNew )      { eRuleType = eNew;
                                                  bInvalidRuleFlag = TRUE; }

    // eine Art Copy-Constructor, damit die Num-Formate auch an den
    // richtigen CharFormaten eines Dokumentes haengen !!
    // (Kopiert die NumFormate und returnt sich selbst)
    SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );

    // testet ob die CharFormate aus dem angegeben Doc sind und kopiert
    // die gegebenfalls
    void CheckCharFmts( SwDoc* pDoc );

    // test ob der Einzug von dieser Numerierung kommt.
    BOOL IsRuleLSpace( SwTxtNode& rNd ) const;

    const String& GetName() const       { return sName; }
    void SetName( const String& rNm )   { sName = rNm; }

    BOOL IsAutoRule() const             { return bAutoRuleFlag; }
    void SetAutoRule( BOOL bFlag )      { bAutoRuleFlag = bFlag; }

    BOOL IsInvalidRule() const          { return bInvalidRuleFlag; }
    void SetInvalidRule( BOOL bFlag )   { bInvalidRuleFlag = bFlag; }

    BOOL IsContinusNum() const          { return bContinusNum; }
    void SetContinusNum( BOOL bFlag )   { bContinusNum = bFlag; }

    BOOL IsAbsSpaces() const            { return bAbsSpaces; }
    void SetAbsSpaces( BOOL bFlag )     { bAbsSpaces = bFlag; }

    // #115901#
    BOOL IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }

    // erfragen und setzen der Poolvorlagen-Id's
    USHORT GetPoolFmtId() const         { return nPoolFmtId; }
    void SetPoolFmtId( USHORT nId )     { nPoolFmtId = nId; }

    // erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
    USHORT GetPoolHelpId() const        { return nPoolHelpId; }
    void SetPoolHelpId( USHORT nId )    { nPoolHelpId = nId; }
    BYTE GetPoolHlpFileId() const       { return nPoolHlpFileId; }
    void SetPoolHlpFileId( BYTE nId )   { nPoolHlpFileId = nId; }

    /**
        #109308# Sets adjustment in all formats of the numbering rule.

        @param eNum adjustment to be set
    */
    void SetNumAdjust(SvxAdjust eNum);

    void        SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
    SvxNumRule  MakeSvxNumRule() const;

    // -> #i27615#
    /**
       Returns if a level is marked.

       @param nLvl     level to check

       @retval TRUE    level is marked
       @retval FALSE   level is not marked
    */
    BOOL IsLevelMarked(BYTE nLvl) const { return aMarkedLevels.Get(nLvl); }

    /**
       Mark/unmark a level.

       @param nLvl     level to mark/unmark
       @param bVal     - TRUE    mark
                       - FALSE   unmark

       @return bit array in which the altered levels are marked.
    */
    SwBitArray SetLevelMarked(BYTE nLvl, BOOL bVal);

    /**
       Unmarks all levels.
    */
    void ResetMarkedLevels() { aMarkedLevels.Reset(); }
    // <- #i27615#
    // #i23726#, #i23725#
    void        Indent(short aAmount, int nLevel = -1,
                       int nReferenceLevel = -1, BOOL bRelative = TRUE,
                       BOOL bFirstLine = TRUE, BOOL bCheckGtZero = TRUE);
};

class SwNodeNum
{
    USHORT nLevelVal[ MAXLEVEL ];       // Nummern aller Levels
    USHORT nSetValue;                   // vorgegeben Nummer
    BYTE nMyLevel;                      // akt. Level
    BOOL bStartNum;                     // Numerierung neu starten
    BOOL bContNum;                      // #111955#
                                        // TRUE -> in continuous numbering

public:
    SwNodeNum( BYTE nLevel = NO_NUMBERING, USHORT nSetVal = USHRT_MAX );
    SwNodeNum& operator=( const SwNodeNum& rCpy );

    BOOL operator==( const SwNodeNum& ) const;

    BYTE GetLevel() const                   { return nMyLevel; }
    void SetLevel( BYTE nVal )              { nMyLevel = nVal; }

    BOOL IsStart() const                    { return bStartNum; }
    void SetStart( BOOL bFlag = TRUE )      { bStartNum = bFlag; }

    // -> #111955#
    BOOL IsContinuousNum() const { return bContNum; }
    void SetContinuousNum( BOOL bFlag = TRUE ) { bContNum = bFlag; }
    // <- #111955#

    BOOL HasSetValue() const { return USHRT_MAX != nSetValue; }
    USHORT GetSetValue() const              { return nSetValue; }
    void SetSetValue( USHORT nVal )         { nSetValue = nVal; }

    const USHORT* GetLevelVal() const       { return nLevelVal; }
          USHORT* GetLevelVal()             { return nLevelVal; }

    BYTE GetRealLevel() const { return ::GetRealLevel(nMyLevel); }
    BOOL IsNum() const { return ::IsNum(nMyLevel); }
    BOOL IsShowNum() const { return ::IsShowNum(nMyLevel); }

    void SetNoNum(BOOL nVal = TRUE)
    {
        nMyLevel = nVal ? nMyLevel | NO_NUMLEVEL : nMyLevel & ~NO_NUMLEVEL;
    }

};

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

#ifndef _LINK_HXX //autogen
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX //autogen wg. Size
#include <tools/gen.hxx>
#endif
#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _CALBCK_HXX
#include <calbck.hxx>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx>       // Fuer die inline-ASSERTs
#endif
#ifndef _SWERROR_H
#include <error.h>          // Fuer die inline-ASSERTs
#endif
#ifndef _SVX_NUMITEM_HXX
#include <svx/numitem.hxx>
#endif

#include <SwBitArray.hxx> // #i27615#

class Font;
class SvxBrushItem;
class SvxNumRule;
class SwCharFmt;
class SwDoc;
class SwFmtVertOrient;
class SwNodeNum;
class SwTxtNode;

extern char __FAR_DATA sOutlineStr[];   // SWG-Filter

BYTE GetRealLevel( const BYTE nLvl );

BOOL IsNum( BYTE nLvl );

BOOL IsShowNum( BYTE nLvl );

void SetNoNum( BYTE * nLvl, BOOL nVal = TRUE );

const sal_Unicode cBulletChar   = 0x2022;   // Charakter fuer Aufzaehlungen

class SwNumFmt : public SvxNumberFormat, public SwClient
{
    SwFmtVertOrient* pVertOrient;

    void UpdateNumNodes( SwDoc* pDoc );
    virtual void NotifyGraphicArrived();
public:
    SwNumFmt();
    SwNumFmt( const SwNumFmt& );
    SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);

    virtual ~SwNumFmt();

    SwNumFmt& operator=( const SwNumFmt& );
    BOOL operator==( const SwNumFmt& ) const;
    BOOL operator!=( const SwNumFmt& r ) const { return !(*this == r); }

    const Graphic* GetGraphic() const;

    SwCharFmt* GetCharFmt() const { return (SwCharFmt*)pRegisteredIn; }
    void SetCharFmt( SwCharFmt* );
    virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );

    virtual void            SetCharFmtName(const String& rSet);
    virtual const String&   GetCharFmtName()const;

    virtual void    SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const SvxFrameVertOrient* pOrient = 0);

    virtual void                SetVertOrient(SvxFrameVertOrient eSet);
    virtual SvxFrameVertOrient  GetVertOrient() const;
    const SwFmtVertOrient*      GetGraphicOrientation() const;

    BOOL IsEnumeration() const; // #i22362#
    BOOL IsItemize() const; // #i29560#
};

enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
class SwNumRule
{
    friend void _FinitCore();

    static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
    static USHORT aDefNumIndents[ MAXLEVEL ];
    static USHORT nRefCount;
    static Font* pDefBulletFont;
    static char* pDefOutlineName;

    SwNumFmt* aFmts[ MAXLEVEL ];

    /**
       marked levels
     */
    SwBitArray aMarkedLevels;

    String sName;
    SwNumRuleType eRuleType;
    USHORT nPoolFmtId;      // Id-fuer "automatich" erzeugte NumRules
    USHORT nPoolHelpId;     // HelpId fuer diese Pool-Vorlage
    BYTE nPoolHlpFileId;    // FilePos ans Doc auf die Vorlagen-Hilfen
    BOOL bAutoRuleFlag : 1;
    BOOL bInvalidRuleFlag : 1;
    BOOL bContinusNum : 1;  // Fortlaufende Numerierung - ohne Ebenen
    BOOL bAbsSpaces : 1;    // die Ebenen repraesentieren absol. Einzuege

    static void _MakeDefBulletFont();

public:
    SwNumRule( const String& rNm, SwNumRuleType = NUM_RULE,
                BOOL bAutoFlg = TRUE );

    SwNumRule( const SwNumRule& );
    ~SwNumRule();

    SwNumRule& operator=( const SwNumRule& );
    BOOL operator==( const SwNumRule& ) const;
    BOOL operator!=( const SwNumRule& r ) const { return !(*this == r); }

    const SwNumFmt* GetNumFmt( USHORT i ) const;
    const SwNumFmt& Get( USHORT i ) const;

    void Set( USHORT i, const SwNumFmt* );
    void Set( USHORT i, const SwNumFmt& );
    String MakeNumString( const SwNodeNum&, BOOL bInclStrings = TRUE,
                            BOOL bOnlyArabic = FALSE ) const;

    sal_Unicode GetBulletChar( const SwNodeNum& ) const;
    const Font* GetBulletFont( const SwNodeNum& ) const;
    static const Font& GetDefBulletFont();

    static char* GetOutlineRuleName() { return pDefOutlineName; }

    static USHORT GetNumIndent( BYTE nLvl );
    static USHORT GetBullIndent( BYTE nLvl );

    SwNumRuleType GetRuleType() const           { return eRuleType; }
    void SetRuleType( SwNumRuleType eNew )      { eRuleType = eNew;
                                                  bInvalidRuleFlag = TRUE; }

    // eine Art Copy-Constructor, damit die Num-Formate auch an den
    // richtigen CharFormaten eines Dokumentes haengen !!
    // (Kopiert die NumFormate und returnt sich selbst)
    SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );

    // testet ob die CharFormate aus dem angegeben Doc sind und kopiert
    // die gegebenfalls
    void CheckCharFmts( SwDoc* pDoc );

    // test ob der Einzug von dieser Numerierung kommt.
    BOOL IsRuleLSpace( SwTxtNode& rNd ) const;

    const String& GetName() const       { return sName; }
    void SetName( const String& rNm )   { sName = rNm; }

    BOOL IsAutoRule() const             { return bAutoRuleFlag; }
    void SetAutoRule( BOOL bFlag )      { bAutoRuleFlag = bFlag; }

    BOOL IsInvalidRule() const          { return bInvalidRuleFlag; }
    void SetInvalidRule( BOOL bFlag )   { bInvalidRuleFlag = bFlag; }

    BOOL IsContinusNum() const          { return bContinusNum; }
    void SetContinusNum( BOOL bFlag )   { bContinusNum = bFlag; }

    BOOL IsAbsSpaces() const            { return bAbsSpaces; }
    void SetAbsSpaces( BOOL bFlag )     { bAbsSpaces = bFlag; }

    // #115901#
    BOOL IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }

    // erfragen und setzen der Poolvorlagen-Id's
    USHORT GetPoolFmtId() const         { return nPoolFmtId; }
    void SetPoolFmtId( USHORT nId )     { nPoolFmtId = nId; }

    // erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
    USHORT GetPoolHelpId() const        { return nPoolHelpId; }
    void SetPoolHelpId( USHORT nId )    { nPoolHelpId = nId; }
    BYTE GetPoolHlpFileId() const       { return nPoolHlpFileId; }
    void SetPoolHlpFileId( BYTE nId )   { nPoolHlpFileId = nId; }

    /**
        #109308# Sets adjustment in all formats of the numbering rule.

        @param eNum adjustment to be set
    */
    void SetNumAdjust(SvxAdjust eNum);

    void        SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
    SvxNumRule  MakeSvxNumRule() const;

    // -> #i27615#
    /**
       Returns if a level is marked.

       @param nLvl     level to check

       @retval TRUE    level is marked
       @retval FALSE   level is not marked
    */
    BOOL IsLevelMarked(BYTE nLvl) const { return aMarkedLevels.Get(nLvl); }

    /**
       Mark/unmark a level.

       @param nLvl     level to mark/unmark
       @param bVal     - TRUE    mark
                       - FALSE   unmark

       @return bit array in which the altered levels are marked.
    */
    SwBitArray SetLevelMarked(BYTE nLvl, BOOL bVal);

    /**
       Unmarks all levels.
    */
    void ResetMarkedLevels() { aMarkedLevels.Reset(); }
    // <- #i27615#
    // #i23726#, #i23725#
    void        Indent(short aAmount, int nLevel = -1,
                       int nReferenceLevel = -1, BOOL bRelative = TRUE,
                       BOOL bFirstLine = TRUE, BOOL bCheckGtZero = TRUE);
};

class SwNodeNum
{
    USHORT nLevelVal[ MAXLEVEL ];       // Nummern aller Levels
    USHORT nSetValue;                   // vorgegeben Nummer
    BYTE nMyLevel;                      // akt. Level
    BOOL bStartNum;                     // Numerierung neu starten
    BOOL bContNum;                      // #111955#
                                        // TRUE -> in continuous numbering

public:
    SwNodeNum( BYTE nLevel = NO_NUMBERING, USHORT nSetVal = USHRT_MAX );
    SwNodeNum& operator=( const SwNodeNum& rCpy );

    BOOL operator==( const SwNodeNum& ) const;

    BYTE GetLevel() const                   { return nMyLevel; }
    void SetLevel( BYTE nVal )              { nMyLevel = nVal; }

    BOOL IsStart() const                    { return bStartNum; }
    void SetStart( BOOL bFlag = TRUE )      { bStartNum = bFlag; }

    // -> #111955#
    BOOL IsContinuousNum() const { return bContNum; }
    void SetContinuousNum( BOOL bFlag = TRUE ) { bContNum = bFlag; }
    // <- #111955#

    BOOL HasSetValue() const { return USHRT_MAX != nSetValue; }
    USHORT GetSetValue() const              { return nSetValue; }
    void SetSetValue( USHORT nVal )         { nSetValue = nVal; }

    const USHORT* GetLevelVal() const       { return nLevelVal; }
          USHORT* GetLevelVal()             { return nLevelVal; }

    BYTE GetRealLevel() const { return ::GetRealLevel(nMyLevel); }
    BOOL IsNum() const { return ::IsNum(nMyLevel); }
    BOOL IsShowNum() const { return ::IsShowNum(nMyLevel); }

    void SetNoNum(BOOL nVal = TRUE)
    {
        nMyLevel = nVal ? nMyLevel | NO_NUMLEVEL : nMyLevel & ~NO_NUMLEVEL;
    }

};

#endif  // _NUMRULE_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tblafmt.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: hr $ $Date: 2006-08-14 15:35:08 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _TBLAFMT_HXX
#define _TBLAFMT_HXX
/*************************************************************************
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

JP 20.07.95:

    Die akt. Struktur der Autoformatierung darf nicht mehr veraendert werden.
    Diese wird durch unterschiedlichen Code vom StartWriter und vom StarCalc
    eingelesen/geschrieben.
    Sollte sich doch mal eine Aenderung nicht vermeiden lassen, dann auf
    jedenfall in beiden Applikationen aendern.

    The structure of table auto formatting should not changed. It is used
    by different code of Writer and Calc. If a change is necessary, the
    source code of both applications must be changed!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**************************************************************************/

#ifndef _SVARRAY_HXX //autogen
#include <svtools/svarray.hxx>
#endif

#ifndef _HINTIDS_HXX
#include "hintids.hxx"          //_immmer_ vor den solar-items!
#endif

#define ITEMID_HORJUSTIFY   0
#define ITEMID_VERJUSTIFY   0
#define ITEMID_ORIENTATION  0
#define ITEMID_MARGIN       0
#ifndef ITEMID_LINE
#define ITEMID_LINE         0
#endif

#ifndef _SVX_ALGITEM_HXX //autogen
#include <svx/algitem.hxx>
#endif
#ifndef _SVX_FONTITEM_HXX //autogen
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_FHGTITEM_HXX //autogen
#include <svx/fhgtitem.hxx>
#endif
#ifndef _SVX_WGHTITEM_HXX //autogen
#include <svx/wghtitem.hxx>
#endif
#ifndef _SVX_POSTITEM_HXX //autogen
#include <svx/postitem.hxx>
#endif
#ifndef _SVX_UDLNITEM_HXX //autogen
#include <svx/udlnitem.hxx>
#endif
#ifndef _SVX_CRSDITEM_HXX //autogen
#include <svx/crsditem.hxx>
#endif
#ifndef _SVX_CNTRTITEM_HXX //autogen
#include <svx/cntritem.hxx>
#endif
#ifndef _SVX_SHDDITEM_HXX //autogen
#include <svx/shdditem.hxx>
#endif
#ifndef _SVX_COLRITEM_HXX //autogen
#include <svx/colritem.hxx>
#endif
#ifndef _SVX_BOXITEM_HXX //autogen
#include <svx/boxitem.hxx>
#endif
#ifndef _SVX_BRSHITEM_HXX //autogen
#include <svx/brshitem.hxx>
#endif
#ifndef _SVX_ADJITEM_HXX //autogen
#include <svx/adjitem.hxx>
#endif
#ifndef _SVX_ROTMODIT_HXX //autogen
#include <svx/rotmodit.hxx>
#endif
#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif
#ifndef _SVX_BOLNITEM_HXX
#include <svx/bolnitem.hxx>
#endif

#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif

struct SwAfVersions;

class SvNumberFormatter;

class SwBoxAutoFmt
{
    // common attributes of Calc and Writer
    // --- from 641 on: CJK and CTL font settings
    SvxFontItem         aFont;
    SvxFontHeightItem   aHeight;
    SvxWeightItem       aWeight;
    SvxPostureItem      aPosture;

    SvxFontItem         aCJKFont;
    SvxFontHeightItem   aCJKHeight;
    SvxWeightItem       aCJKWeight;
    SvxPostureItem      aCJKPosture;

    SvxFontItem         aCTLFont;
    SvxFontHeightItem   aCTLHeight;
    SvxWeightItem       aCTLWeight;
    SvxPostureItem      aCTLPosture;

    SvxUnderlineItem    aUnderline;
    SvxCrossedOutItem   aCrossedOut;
    SvxContourItem      aContour;
    SvxShadowedItem     aShadowed;
    SvxColorItem        aColor;
    SvxBoxItem          aBox;
    SvxLineItem         aTLBR;
    SvxLineItem         aBLTR;
    SvxBrushItem        aBackground;

    // Writer specific
    SvxAdjustItem       aAdjust;

    // Calc specific
    SvxHorJustifyItem   aHorJustify;
    SvxVerJustifyItem   aVerJustify;
    SfxBoolItem         aStacked;
    SvxMarginItem       aMargin;
    SfxBoolItem         aLinebreak;
    SfxInt32Item        aRotateAngle;
    SvxRotateModeItem   aRotateMode;

    // number format
    String              sNumFmtString;
    LanguageType        eSysLanguage, eNumFmtLanguage;

public:
    SwBoxAutoFmt();
    SwBoxAutoFmt( const SwBoxAutoFmt& rNew );
    ~SwBoxAutoFmt();

    int operator==( const SwBoxAutoFmt& rCmp ) const;
    SwBoxAutoFmt& operator=( const SwBoxAutoFmt& rNew );

    // die Get-Methoden
    const SvxFontItem       &GetFont() const        { return aFont; }
    const SvxFontHeightItem &GetHeight() const      { return aHeight; }
    const SvxWeightItem     &GetWeight() const      { return aWeight; }
    const SvxPostureItem    &GetPosture() const     { return aPosture; }
    const SvxFontItem       &GetCJKFont() const     { return aCJKFont; }
    const SvxFontHeightItem &GetCJKHeight() const   { return aCJKHeight; }
    const SvxWeightItem     &GetCJKWeight() const   { return aCJKWeight; }
    const SvxPostureItem    &GetCJKPosture() const  { return aCJKPosture; }
    const SvxFontItem       &GetCTLFont() const     { return aCTLFont; }
    const SvxFontHeightItem &GetCTLHeight() const   { return aCTLHeight; }
    const SvxWeightItem     &GetCTLWeight() const   { return aCTLWeight; }
    const SvxPostureItem    &GetCTLPosture() const  { return aCTLPosture; }
    const SvxUnderlineItem  &GetUnderline() const   { return aUnderline; }
    const SvxCrossedOutItem &GetCrossedOut() const  { return aCrossedOut; }
    const SvxContourItem    &GetContour() const     { return aContour; }
    const SvxShadowedItem   &GetShadowed() const    { return aShadowed; }
    const SvxColorItem      &GetColor() const       { return aColor; }
    const SvxAdjustItem     &GetAdjust() const      { return aAdjust; }
    const SvxBoxItem        &GetBox() const         { return aBox; }
    const SvxLineItem       &GetTLBR() const        { return aTLBR; }
    const SvxLineItem       &GetBLTR() const        { return aBLTR; }
    const SvxBrushItem      &GetBackground() const  { return aBackground; }
    void GetValueFormat( String& rFmt, LanguageType& rLng, LanguageType& rSys ) const
        { rFmt = sNumFmtString; rLng = eNumFmtLanguage; rSys = eSysLanguage; }

    // die SetMethoden
    void SetFont( const SvxFontItem& rNew )             { aFont = rNew; }
    void SetHeight( const SvxFontHeightItem& rNew )     { aHeight = rNew; }
    void SetWeight( const SvxWeightItem& rNew )         { aWeight = rNew; }
    void SetPosture( const SvxPostureItem& rNew )       { aPosture = rNew; }
    void SetCJKFont( const SvxFontItem& rNew )          { aCJKFont = rNew; }
    void SetCJKHeight( const SvxFontHeightItem& rNew )  { aCJKHeight = rNew; }
    void SetCJKWeight( const SvxWeightItem& rNew )      { aCJKWeight = rNew; }
    void SetCJKPosture( const SvxPostureItem& rNew )    { aCJKPosture = rNew; }
    void SetCTLFont( const SvxFontItem& rNew )          { aCTLFont = rNew; }
    void SetCTLHeight( const SvxFontHeightItem& rNew )  { aCTLHeight = rNew; }
    void SetCTLWeight( const SvxWeightItem& rNew )      { aCTLWeight = rNew; }
    void SetCTLPosture( const SvxPostureItem& rNew )    { aCTLPosture = rNew; }
    void SetUnderline( const SvxUnderlineItem& rNew )   { aUnderline = rNew; }
    void SetCrossedOut( const SvxCrossedOutItem& rNew ) { aCrossedOut = rNew; }
    void SetContour( const SvxContourItem& rNew )       { aContour = rNew; }
    void SetShadowed( const SvxShadowedItem& rNew )     { aShadowed = rNew; }
    void SetColor( const SvxColorItem& rNew )           { aColor = rNew; }
    void SetAdjust( const SvxAdjustItem& rNew )
        {
            aAdjust.SetAdjust( rNew.GetAdjust() );
            aAdjust.SetOneWord( rNew.GetOneWord() );
            aAdjust.SetLastBlock( rNew.GetLastBlock() );
        }
    void SetBox( const SvxBoxItem& rNew )               { aBox = rNew; }
    void SetBackground( const SvxBrushItem& rNew )      { aBackground = rNew; }
    void SetValueFormat( const String& rFmt, LanguageType eLng, LanguageType eSys )
        { sNumFmtString = rFmt; eNumFmtLanguage = eLng; eSysLanguage = eSys; }

    BOOL Load( SvStream& rStream, const SwAfVersions& rVersions, USHORT nVer );
    BOOL Save( SvStream& rStream ) const;
    BOOL SaveVerionNo( SvStream& rStream ) const;

#ifdef READ_OLDVERS
    // lade alte Version
    BOOL LoadOld( SvStream& rStream, USHORT aLoadVer[] );
#endif
};

class SW_DLLPUBLIC SwTableAutoFmt
{
    friend void _FinitCore();       // zum Zerstoeren des dflt. Pointers
    static SwBoxAutoFmt* pDfltBoxAutoFmt;

    String aName;
    USHORT nStrResId;

    // common flags of Calc and Writer
    BOOL bInclFont : 1;
    BOOL bInclJustify : 1;
    BOOL bInclFrame : 1;
    BOOL bInclBackground : 1;
    BOOL bInclValueFormat : 1;

    // Calc specific flags
    BOOL bInclWidthHeight : 1;

    SwBoxAutoFmt* aBoxAutoFmt[ 16 ];

public:
    SwTableAutoFmt( const String& rName );
    SwTableAutoFmt( const SwTableAutoFmt& rNew );
    ~SwTableAutoFmt();

    SwTableAutoFmt& operator=( const SwTableAutoFmt& rNew );

    void SetBoxFmt( const SwBoxAutoFmt& rNew, BYTE nPos );
    const SwBoxAutoFmt& GetBoxFmt( BYTE nPos ) const;

    void SetName( const String& rNew ) { aName = rNew; nStrResId = USHRT_MAX; }
    const String& GetName() const { return aName; }

    enum UpdateFlags { UPDATE_CHAR = 1, UPDATE_BOX = 2, UPDATE_ALL = 3 };
    SwBoxAutoFmt& UpdateFromSet( BYTE nPos, const SfxItemSet& rSet,
                                UpdateFlags eFlags, SvNumberFormatter* );
    void UpdateToSet( BYTE nPos, SfxItemSet& rSet, UpdateFlags eFlags,
                        SvNumberFormatter* ) const ;

    BOOL IsFont() const         { return bInclFont; }
    BOOL IsJustify() const      { return bInclJustify; }
    BOOL IsFrame() const        { return bInclFrame; }
    BOOL IsBackground() const   { return bInclBackground; }
    BOOL IsValueFormat() const  { return bInclValueFormat; }

    void SetFont( const BOOL bNew )         { bInclFont = bNew; }
    void SetJustify( const  BOOL bNew )     { bInclJustify = bNew; }
    void SetFrame( const BOOL bNew )        { bInclFrame = bNew; }
    void SetBackground( const BOOL bNew )   { bInclBackground = bNew; }
    void SetValueFormat( const BOOL bNew )  { bInclValueFormat = bNew; }
    void SetWidthHeight( const BOOL bNew )  { bInclWidthHeight = bNew; }

    BOOL Load( SvStream& rStream, const SwAfVersions& );
    BOOL Save( SvStream& rStream ) const;

#ifdef READ_OLDVERS
    // lade alte Version
    BOOL LoadOld( SvStream& rStream, USHORT aLoadVer[] );
#endif
};

typedef SwTableAutoFmt* SwTableAutoFmtPtr ;
SV_DECL_PTRARR_DEL( _SwTableAutoFmtTbl, SwTableAutoFmtPtr, 1, 5 )

class SW_DLLPUBLIC SwTableAutoFmtTbl : public _SwTableAutoFmtTbl
{
    SW_DLLPRIVATE BOOL Load( SvStream& rStream );
    SW_DLLPRIVATE BOOL Save( SvStream& rStream ) const;

public:
    SwTableAutoFmtTbl();

    BOOL Load();
    BOOL Save() const;
};

#endif
<commit_msg>INTEGRATION: CWS pchfix04 (1.7.120); FILE MERGED 2007/02/05 08:27:16 os 1.7.120.1: #i73604# usage of ITEMID_* removed<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tblafmt.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: kz $ $Date: 2007-05-10 15:53:53 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _TBLAFMT_HXX
#define _TBLAFMT_HXX
/*************************************************************************
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

JP 20.07.95:

    Die akt. Struktur der Autoformatierung darf nicht mehr veraendert werden.
    Diese wird durch unterschiedlichen Code vom StartWriter und vom StarCalc
    eingelesen/geschrieben.
    Sollte sich doch mal eine Aenderung nicht vermeiden lassen, dann auf
    jedenfall in beiden Applikationen aendern.

    The structure of table auto formatting should not changed. It is used
    by different code of Writer and Calc. If a change is necessary, the
    source code of both applications must be changed!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**************************************************************************/

#ifndef _SVARRAY_HXX //autogen
#include <svtools/svarray.hxx>
#endif

#ifndef _HINTIDS_HXX
#include "hintids.hxx"          //_immmer_ vor den solar-items!
#endif

#ifndef _SVX_ALGITEM_HXX //autogen
#include <svx/algitem.hxx>
#endif
#ifndef _SVX_FONTITEM_HXX //autogen
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_FHGTITEM_HXX //autogen
#include <svx/fhgtitem.hxx>
#endif
#ifndef _SVX_WGHTITEM_HXX //autogen
#include <svx/wghtitem.hxx>
#endif
#ifndef _SVX_POSTITEM_HXX //autogen
#include <svx/postitem.hxx>
#endif
#ifndef _SVX_UDLNITEM_HXX //autogen
#include <svx/udlnitem.hxx>
#endif
#ifndef _SVX_CRSDITEM_HXX //autogen
#include <svx/crsditem.hxx>
#endif
#ifndef _SVX_CNTRTITEM_HXX //autogen
#include <svx/cntritem.hxx>
#endif
#ifndef _SVX_SHDDITEM_HXX //autogen
#include <svx/shdditem.hxx>
#endif
#ifndef _SVX_COLRITEM_HXX //autogen
#include <svx/colritem.hxx>
#endif
#ifndef _SVX_BOXITEM_HXX //autogen
#include <svx/boxitem.hxx>
#endif
#ifndef _SVX_BRSHITEM_HXX //autogen
#include <svx/brshitem.hxx>
#endif
#ifndef _SVX_ADJITEM_HXX //autogen
#include <svx/adjitem.hxx>
#endif
#ifndef _SVX_ROTMODIT_HXX //autogen
#include <svx/rotmodit.hxx>
#endif
#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif
#ifndef _SVX_BOLNITEM_HXX
#include <svx/bolnitem.hxx>
#endif

#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif

struct SwAfVersions;

class SvNumberFormatter;

class SwBoxAutoFmt
{
    // common attributes of Calc and Writer
    // --- from 641 on: CJK and CTL font settings
    SvxFontItem         aFont;
    SvxFontHeightItem   aHeight;
    SvxWeightItem       aWeight;
    SvxPostureItem      aPosture;

    SvxFontItem         aCJKFont;
    SvxFontHeightItem   aCJKHeight;
    SvxWeightItem       aCJKWeight;
    SvxPostureItem      aCJKPosture;

    SvxFontItem         aCTLFont;
    SvxFontHeightItem   aCTLHeight;
    SvxWeightItem       aCTLWeight;
    SvxPostureItem      aCTLPosture;

    SvxUnderlineItem    aUnderline;
    SvxCrossedOutItem   aCrossedOut;
    SvxContourItem      aContour;
    SvxShadowedItem     aShadowed;
    SvxColorItem        aColor;
    SvxBoxItem          aBox;
    SvxLineItem         aTLBR;
    SvxLineItem         aBLTR;
    SvxBrushItem        aBackground;

    // Writer specific
    SvxAdjustItem       aAdjust;

    // Calc specific
    SvxHorJustifyItem   aHorJustify;
    SvxVerJustifyItem   aVerJustify;
    SfxBoolItem         aStacked;
    SvxMarginItem       aMargin;
    SfxBoolItem         aLinebreak;
    SfxInt32Item        aRotateAngle;
    SvxRotateModeItem   aRotateMode;

    // number format
    String              sNumFmtString;
    LanguageType        eSysLanguage, eNumFmtLanguage;

public:
    SwBoxAutoFmt();
    SwBoxAutoFmt( const SwBoxAutoFmt& rNew );
    ~SwBoxAutoFmt();

    int operator==( const SwBoxAutoFmt& rCmp ) const;
    SwBoxAutoFmt& operator=( const SwBoxAutoFmt& rNew );

    // die Get-Methoden
    const SvxFontItem       &GetFont() const        { return aFont; }
    const SvxFontHeightItem &GetHeight() const      { return aHeight; }
    const SvxWeightItem     &GetWeight() const      { return aWeight; }
    const SvxPostureItem    &GetPosture() const     { return aPosture; }
    const SvxFontItem       &GetCJKFont() const     { return aCJKFont; }
    const SvxFontHeightItem &GetCJKHeight() const   { return aCJKHeight; }
    const SvxWeightItem     &GetCJKWeight() const   { return aCJKWeight; }
    const SvxPostureItem    &GetCJKPosture() const  { return aCJKPosture; }
    const SvxFontItem       &GetCTLFont() const     { return aCTLFont; }
    const SvxFontHeightItem &GetCTLHeight() const   { return aCTLHeight; }
    const SvxWeightItem     &GetCTLWeight() const   { return aCTLWeight; }
    const SvxPostureItem    &GetCTLPosture() const  { return aCTLPosture; }
    const SvxUnderlineItem  &GetUnderline() const   { return aUnderline; }
    const SvxCrossedOutItem &GetCrossedOut() const  { return aCrossedOut; }
    const SvxContourItem    &GetContour() const     { return aContour; }
    const SvxShadowedItem   &GetShadowed() const    { return aShadowed; }
    const SvxColorItem      &GetColor() const       { return aColor; }
    const SvxAdjustItem     &GetAdjust() const      { return aAdjust; }
    const SvxBoxItem        &GetBox() const         { return aBox; }
    const SvxLineItem       &GetTLBR() const        { return aTLBR; }
    const SvxLineItem       &GetBLTR() const        { return aBLTR; }
    const SvxBrushItem      &GetBackground() const  { return aBackground; }
    void GetValueFormat( String& rFmt, LanguageType& rLng, LanguageType& rSys ) const
        { rFmt = sNumFmtString; rLng = eNumFmtLanguage; rSys = eSysLanguage; }

    // die SetMethoden
    void SetFont( const SvxFontItem& rNew )             { aFont = rNew; }
    void SetHeight( const SvxFontHeightItem& rNew )     { aHeight = rNew; }
    void SetWeight( const SvxWeightItem& rNew )         { aWeight = rNew; }
    void SetPosture( const SvxPostureItem& rNew )       { aPosture = rNew; }
    void SetCJKFont( const SvxFontItem& rNew )          { aCJKFont = rNew; }
    void SetCJKHeight( const SvxFontHeightItem& rNew )  { aCJKHeight = rNew; }
    void SetCJKWeight( const SvxWeightItem& rNew )      { aCJKWeight = rNew; }
    void SetCJKPosture( const SvxPostureItem& rNew )    { aCJKPosture = rNew; }
    void SetCTLFont( const SvxFontItem& rNew )          { aCTLFont = rNew; }
    void SetCTLHeight( const SvxFontHeightItem& rNew )  { aCTLHeight = rNew; }
    void SetCTLWeight( const SvxWeightItem& rNew )      { aCTLWeight = rNew; }
    void SetCTLPosture( const SvxPostureItem& rNew )    { aCTLPosture = rNew; }
    void SetUnderline( const SvxUnderlineItem& rNew )   { aUnderline = rNew; }
    void SetCrossedOut( const SvxCrossedOutItem& rNew ) { aCrossedOut = rNew; }
    void SetContour( const SvxContourItem& rNew )       { aContour = rNew; }
    void SetShadowed( const SvxShadowedItem& rNew )     { aShadowed = rNew; }
    void SetColor( const SvxColorItem& rNew )           { aColor = rNew; }
    void SetAdjust( const SvxAdjustItem& rNew )
        {
            aAdjust.SetAdjust( rNew.GetAdjust() );
            aAdjust.SetOneWord( rNew.GetOneWord() );
            aAdjust.SetLastBlock( rNew.GetLastBlock() );
        }
    void SetBox( const SvxBoxItem& rNew )               { aBox = rNew; }
    void SetBackground( const SvxBrushItem& rNew )      { aBackground = rNew; }
    void SetValueFormat( const String& rFmt, LanguageType eLng, LanguageType eSys )
        { sNumFmtString = rFmt; eNumFmtLanguage = eLng; eSysLanguage = eSys; }

    BOOL Load( SvStream& rStream, const SwAfVersions& rVersions, USHORT nVer );
    BOOL Save( SvStream& rStream ) const;
    BOOL SaveVerionNo( SvStream& rStream ) const;

#ifdef READ_OLDVERS
    // lade alte Version
    BOOL LoadOld( SvStream& rStream, USHORT aLoadVer[] );
#endif
};

class SW_DLLPUBLIC SwTableAutoFmt
{
    friend void _FinitCore();       // zum Zerstoeren des dflt. Pointers
    static SwBoxAutoFmt* pDfltBoxAutoFmt;

    String aName;
    USHORT nStrResId;

    // common flags of Calc and Writer
    BOOL bInclFont : 1;
    BOOL bInclJustify : 1;
    BOOL bInclFrame : 1;
    BOOL bInclBackground : 1;
    BOOL bInclValueFormat : 1;

    // Calc specific flags
    BOOL bInclWidthHeight : 1;

    SwBoxAutoFmt* aBoxAutoFmt[ 16 ];

public:
    SwTableAutoFmt( const String& rName );
    SwTableAutoFmt( const SwTableAutoFmt& rNew );
    ~SwTableAutoFmt();

    SwTableAutoFmt& operator=( const SwTableAutoFmt& rNew );

    void SetBoxFmt( const SwBoxAutoFmt& rNew, BYTE nPos );
    const SwBoxAutoFmt& GetBoxFmt( BYTE nPos ) const;

    void SetName( const String& rNew ) { aName = rNew; nStrResId = USHRT_MAX; }
    const String& GetName() const { return aName; }

    enum UpdateFlags { UPDATE_CHAR = 1, UPDATE_BOX = 2, UPDATE_ALL = 3 };
    SwBoxAutoFmt& UpdateFromSet( BYTE nPos, const SfxItemSet& rSet,
                                UpdateFlags eFlags, SvNumberFormatter* );
    void UpdateToSet( BYTE nPos, SfxItemSet& rSet, UpdateFlags eFlags,
                        SvNumberFormatter* ) const ;

    BOOL IsFont() const         { return bInclFont; }
    BOOL IsJustify() const      { return bInclJustify; }
    BOOL IsFrame() const        { return bInclFrame; }
    BOOL IsBackground() const   { return bInclBackground; }
    BOOL IsValueFormat() const  { return bInclValueFormat; }

    void SetFont( const BOOL bNew )         { bInclFont = bNew; }
    void SetJustify( const  BOOL bNew )     { bInclJustify = bNew; }
    void SetFrame( const BOOL bNew )        { bInclFrame = bNew; }
    void SetBackground( const BOOL bNew )   { bInclBackground = bNew; }
    void SetValueFormat( const BOOL bNew )  { bInclValueFormat = bNew; }
    void SetWidthHeight( const BOOL bNew )  { bInclWidthHeight = bNew; }

    BOOL Load( SvStream& rStream, const SwAfVersions& );
    BOOL Save( SvStream& rStream ) const;

#ifdef READ_OLDVERS
    // lade alte Version
    BOOL LoadOld( SvStream& rStream, USHORT aLoadVer[] );
#endif
};

typedef SwTableAutoFmt* SwTableAutoFmtPtr ;
SV_DECL_PTRARR_DEL( _SwTableAutoFmtTbl, SwTableAutoFmtPtr, 1, 5 )

class SW_DLLPUBLIC SwTableAutoFmtTbl : public _SwTableAutoFmtTbl
{
    SW_DLLPRIVATE BOOL Load( SvStream& rStream );
    SW_DLLPRIVATE BOOL Save( SvStream& rStream ) const;

public:
    SwTableAutoFmtTbl();

    BOOL Load();
    BOOL Save() const;
};

#endif
<|endoftext|>


<commit_before>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "aboutdialog.h"
#include "ui_aboutdialog.h"

#include <QProcess>
#include <QLabel>
#include <QPushButton>
#include <QFormLayout>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>

namespace {

struct meta_entry
{
    QString name;
    QLabel* value;
};

class MetaWidget : public QWidget
{
public:

    MetaWidget(QWidget*parent=nullptr)
        : QWidget(parent)
    {
        setLayout(new QFormLayout());

        // Add default string, so that user always knows what is going on
        dynamic_cast<QFormLayout*>(layout())->addRow("No GstMeta available.", new QLabel());
    };

    ~MetaWidget()
    {}

    void update(GstStructure& struc)
    {
        // GstMeta will always have more than 1 entry
        // this is a reliable identifier for us receiving the
        // first update and having to remove the default string
        if (dynamic_cast<QFormLayout*>(layout())->rowCount() == 1)
        {
            dynamic_cast<QFormLayout*>(layout())->removeRow(0);
        }

        auto meta_cb = [] (GQuark field_id,
                           const GValue* value,
                           gpointer user_data) -> gboolean
        {

            auto fill_label = [] (QLabel* label, const GValue* gvalue)
            {
                if (G_VALUE_TYPE(gvalue) == G_TYPE_BOOLEAN)
                {
                    gboolean val = g_value_get_boolean(gvalue);
                    if (val)
                    {
                        label->setText("true");
                    }
                    else
                    {
                        label->setText("false");
                    }
                }
                else if (G_VALUE_TYPE(gvalue) == G_TYPE_DOUBLE)
                {
                    double val = g_value_get_double(gvalue);
                    label->setText(QString::number(val));

                }
                else if (G_VALUE_TYPE(gvalue) == G_TYPE_UINT64)
                {
                    guint64 val = g_value_get_uint64(gvalue);
                    label->setText(QString::number(val));
                }
                else
                {
                    qWarning("value type not implemented for TcamMeta\n");
                }
            };

            MetaWidget* self  = (MetaWidget*)user_data;

            QString name = g_quark_to_string(field_id);

            auto iter = std::find_if(self->m_entries.begin(), self->m_entries.end(),
                                     [&name] (const meta_entry& entry)
                                     {
                                         if (entry.name == name)
                                         {
                                             return true;
                                         }
                                         return false;
                                     });

            if (iter == self->m_entries.end())
            {
                meta_entry e = {name, new QLabel()};
                e.value->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
                self->m_entries.push_back(e);

                dynamic_cast<QFormLayout*>(self->layout())->addRow(name, e.value);
                fill_label(e.value, value);
            }
            else
            {
                fill_label(iter->value, value);
            }

            return TRUE;
        };

        gst_structure_foreach(&struc, meta_cb, this);

    }

private:

    std::vector<meta_entry> m_entries;
};

} // namespace

AboutDialog::AboutDialog(const QString& pipeline_str, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AboutDialog),
    m_pipeline_str(pipeline_str)
{
    ui->setupUi(this);

    ui->tab_versions->layout()->setAlignment(Qt::AlignTop);

    fill_stream();
    fill_versions();
    fill_state();
}

AboutDialog::~AboutDialog()
{
    delete ui;
}

void AboutDialog::fill_stream()
{
    auto layout = dynamic_cast<QFormLayout*>(ui->tab_stream->layout());

    auto tmp = m_pipeline_str;

    tmp.replace("!", "
!");

    auto pipe_label = new QLabel(tmp);
    pipe_label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);

    layout->addRow("Pipeline: ", pipe_label);

    if (!p_label_device_caps)
    {
        p_label_device_caps = new QLabel();
        p_label_device_caps->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
    }

    layout->addRow("Device caps: ", p_label_device_caps);

    p_meta = new MetaWidget();

    layout->addRow("GstMeta:", p_meta);

}

void AboutDialog::fill_versions()
{
    QProcess process_tis_version;
    process_tis_version.start("tcam-ctrl", {"--version"});
    process_tis_version.waitForFinished(-1); // will wait forever until finished

    QString stdout_tis = process_tis_version.readAllStandardOutput();
    QString stderr = process_tis_version.readAllStandardError();

    QProcess process_tis_packages;
    process_tis_packages.start("tcam-ctrl", {"--packages"});
    process_tis_packages.waitForFinished(-1); // will wait forever until finished

    QString stdout_packages = process_tis_packages.readAllStandardOutput();

    // we work with a rich text label
    // this means a 'normal' string
    // does not suffice. Instead use html tags.
    stdout_tis.replace("\n", "
");
    stdout_packages.replace("\n", "
");
    stdout_packages.replace("\t", " ");

    QString s = "
Tiscamera:
"
        + stdout_tis
        + "
Packages:
"
        + stdout_packages;

    ui->label_versions->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
    ui->label_versions->setText(s);
}

void AboutDialog::fill_state()
{
    auto apply_button = ui->buttonBox_2->button(QDialogButtonBox::Apply);
    auto reset_button = ui->buttonBox_2->button(QDialogButtonBox::Reset);
    auto save_button = ui->buttonBox_2->button(QDialogButtonBox::Save);
    auto open_button = ui->buttonBox_2->button(QDialogButtonBox::Open);

    connect(apply_button, &QPushButton::clicked, this, &AboutDialog::write_state);
    connect(reset_button, &QPushButton::clicked, this, &AboutDialog::update_state);
    connect(save_button, &QPushButton::clicked, this, &AboutDialog::save_state);
    connect(open_button, &QPushButton::clicked, this, &AboutDialog::open_state);
}

void AboutDialog::set_device_caps(const QString& dev_caps)
{
    p_label_device_caps->setText(dev_caps);
}

void AboutDialog::set_tcambin(GstElement* bin)
{
    p_tcambin = bin;

    update_state();
}

void AboutDialog::update_meta(GstStructure* meta)
{
    MetaWidget* m = (MetaWidget*)p_meta;

    m->update(*meta);

    // has to free here
    gst_structure_free(meta);
}

void AboutDialog::update_state()
{
    if (!p_tcambin)
    {
        ui->state_field->setPlainText("");
        ui->state_field->setEnabled(false);
        return;
    }

    GValue state = G_VALUE_INIT;
    g_object_get_property(G_OBJECT(p_tcambin), "tcam-properties-json", &state);

    ui->state_field->setPlainText(g_value_get_string(&state));

    ui->state_field->setEnabled(true);
}

void AboutDialog::write_state()
{
    auto str = ui->state_field->toPlainText();

    g_object_set(p_tcambin, "tcam-properties-json", str.toStdString().c_str(), nullptr);

}

void AboutDialog::open_state()
{
    auto filename = QFileDialog::getOpenFileName(this,
                                                 "Open JSON State",
                                                 QString(),
                                                 ("*.json"));

    if (filename.isEmpty())
    {
        return;
    }

    QFile f(filename);

    f.open(QIODevice::ReadOnly);
    ui->state_field->setPlainText(f.readAll().toStdString().c_str());

    f.close();
}

void AboutDialog::save_state()
{
    auto filename = QFileDialog::getSaveFileName(this,
                                                 "Save JSON State",
                                                 QString(),
                                                 ("*.json"));

    if (filename.isEmpty())
    {
        return;
    }

    QFile f(filename);

    f.open(QIODevice::WriteOnly);
    f.write(ui->state_field->toPlainText().toUtf8());

    f.close();
}
<commit_msg>tcam-capture: Fix state retrieval on tegras<commit_after>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "aboutdialog.h"
#include "ui_aboutdialog.h"

#include <QProcess>
#include <QLabel>
#include <QPushButton>
#include <QFormLayout>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>

namespace {

struct meta_entry
{
    QString name;
    QLabel* value;
};

class MetaWidget : public QWidget
{
public:

    MetaWidget(QWidget*parent=nullptr)
        : QWidget(parent)
    {
        setLayout(new QFormLayout());

        // Add default string, so that user always knows what is going on
        dynamic_cast<QFormLayout*>(layout())->addRow("No GstMeta available.", new QLabel());
    };

    ~MetaWidget()
    {}

    void update(GstStructure& struc)
    {
        // GstMeta will always have more than 1 entry
        // this is a reliable identifier for us receiving the
        // first update and having to remove the default string
        if (dynamic_cast<QFormLayout*>(layout())->rowCount() == 1)
        {
            dynamic_cast<QFormLayout*>(layout())->removeRow(0);
        }

        auto meta_cb = [] (GQuark field_id,
                           const GValue* value,
                           gpointer user_data) -> gboolean
        {

            auto fill_label = [] (QLabel* label, const GValue* gvalue)
            {
                if (G_VALUE_TYPE(gvalue) == G_TYPE_BOOLEAN)
                {
                    gboolean val = g_value_get_boolean(gvalue);
                    if (val)
                    {
                        label->setText("true");
                    }
                    else
                    {
                        label->setText("false");
                    }
                }
                else if (G_VALUE_TYPE(gvalue) == G_TYPE_DOUBLE)
                {
                    double val = g_value_get_double(gvalue);
                    label->setText(QString::number(val));

                }
                else if (G_VALUE_TYPE(gvalue) == G_TYPE_UINT64)
                {
                    guint64 val = g_value_get_uint64(gvalue);
                    label->setText(QString::number(val));
                }
                else
                {
                    qWarning("value type not implemented for TcamMeta\n");
                }
            };

            MetaWidget* self  = (MetaWidget*)user_data;

            QString name = g_quark_to_string(field_id);

            auto iter = std::find_if(self->m_entries.begin(), self->m_entries.end(),
                                     [&name] (const meta_entry& entry)
                                     {
                                         if (entry.name == name)
                                         {
                                             return true;
                                         }
                                         return false;
                                     });

            if (iter == self->m_entries.end())
            {
                meta_entry e = {name, new QLabel()};
                e.value->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
                self->m_entries.push_back(e);

                dynamic_cast<QFormLayout*>(self->layout())->addRow(name, e.value);
                fill_label(e.value, value);
            }
            else
            {
                fill_label(iter->value, value);
            }

            return TRUE;
        };

        gst_structure_foreach(&struc, meta_cb, this);

    }

private:

    std::vector<meta_entry> m_entries;
};

} // namespace

AboutDialog::AboutDialog(const QString& pipeline_str, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AboutDialog),
    m_pipeline_str(pipeline_str)
{
    ui->setupUi(this);

    ui->tab_versions->layout()->setAlignment(Qt::AlignTop);

    fill_stream();
    fill_versions();
    fill_state();
}

AboutDialog::~AboutDialog()
{
    delete ui;
}

void AboutDialog::fill_stream()
{
    auto layout = dynamic_cast<QFormLayout*>(ui->tab_stream->layout());

    auto tmp = m_pipeline_str;

    tmp.replace("!", "
!");

    auto pipe_label = new QLabel(tmp);
    pipe_label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);

    layout->addRow("Pipeline: ", pipe_label);

    if (!p_label_device_caps)
    {
        p_label_device_caps = new QLabel();
        p_label_device_caps->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
    }

    layout->addRow("Device caps: ", p_label_device_caps);

    p_meta = new MetaWidget();

    layout->addRow("GstMeta:", p_meta);

}

void AboutDialog::fill_versions()
{
    QProcess process_tis_version;
    process_tis_version.start("tcam-ctrl", {"--version"});
    process_tis_version.waitForFinished(-1); // will wait forever until finished

    QString stdout_tis = process_tis_version.readAllStandardOutput();
    QString stderr = process_tis_version.readAllStandardError();

    QProcess process_tis_packages;
    process_tis_packages.start("tcam-ctrl", {"--packages"});
    process_tis_packages.waitForFinished(-1); // will wait forever until finished

    QString stdout_packages = process_tis_packages.readAllStandardOutput();

    // we work with a rich text label
    // this means a 'normal' string
    // does not suffice. Instead use html tags.
    stdout_tis.replace("\n", "
");
    stdout_packages.replace("\n", "
");
    stdout_packages.replace("\t", " ");

    QString s = "
Tiscamera:
"
        + stdout_tis
        + "
Packages:
"
        + stdout_packages;

    ui->label_versions->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
    ui->label_versions->setText(s);
}

void AboutDialog::fill_state()
{
    auto apply_button = ui->buttonBox_2->button(QDialogButtonBox::Apply);
    auto reset_button = ui->buttonBox_2->button(QDialogButtonBox::Reset);
    auto save_button = ui->buttonBox_2->button(QDialogButtonBox::Save);
    auto open_button = ui->buttonBox_2->button(QDialogButtonBox::Open);

    connect(apply_button, &QPushButton::clicked, this, &AboutDialog::write_state);
    connect(reset_button, &QPushButton::clicked, this, &AboutDialog::update_state);
    connect(save_button, &QPushButton::clicked, this, &AboutDialog::save_state);
    connect(open_button, &QPushButton::clicked, this, &AboutDialog::open_state);
}

void AboutDialog::set_device_caps(const QString& dev_caps)
{
    p_label_device_caps->setText(dev_caps);
}

void AboutDialog::set_tcambin(GstElement* bin)
{
    p_tcambin = bin;

    update_state();
}

void AboutDialog::update_meta(GstStructure* meta)
{
    MetaWidget* m = (MetaWidget*)p_meta;

    m->update(*meta);

    // has to free here
    gst_structure_free(meta);
}

void AboutDialog::update_state()
{
    if (!p_tcambin)
    {
        ui->state_field->setPlainText("");
        ui->state_field->setEnabled(false);
        return;
    }

    GValue state = G_VALUE_INIT;
    g_value_init(&state, G_TYPE_STRING);
    g_object_get_property(G_OBJECT(p_tcambin), "tcam-properties-json", &state);

    ui->state_field->setPlainText(g_value_get_string(&state));

    g_value_unset(&state);

    ui->state_field->setEnabled(true);
}

void AboutDialog::write_state()
{
    auto str = ui->state_field->toPlainText();

    g_object_set(p_tcambin, "tcam-properties-json", str.toStdString().c_str(), nullptr);

}

void AboutDialog::open_state()
{
    auto filename = QFileDialog::getOpenFileName(this,
                                                 "Open JSON State",
                                                 QString(),
                                                 ("*.json"));

    if (filename.isEmpty())
    {
        return;
    }

    QFile f(filename);

    f.open(QIODevice::ReadOnly);
    ui->state_field->setPlainText(f.readAll().toStdString().c_str());

    f.close();
}

void AboutDialog::save_state()
{
    auto filename = QFileDialog::getSaveFileName(this,
                                                 "Save JSON State",
                                                 QString(),
                                                 ("*.json"));

    if (filename.isEmpty())
    {
        return;
    }

    QFile f(filename);

    f.open(QIODevice::WriteOnly);
    f.write(ui->state_field->toPlainText().toUtf8());

    f.close();
}
<|endoftext|>


<commit_before>

#include <iostream>

#include "storage/Devices/BlkDeviceImpl.h"
#include "storage/Devices/BtrfsImpl.h"
#include "storage/Devicegraph.h"
#include "storage/Action.h"
#include "storage/Utils/StorageDefines.h"
#include "storage/Utils/HumanString.h"
#include "storage/Utils/SystemCmd.h"
#include "storage/FreeInfo.h"

namespace storage
{

    using namespace std;

    const char* DeviceTraits<Btrfs>::classname = "Btrfs";

    Btrfs::Impl::Impl(const xmlNode* node)
	: Filesystem::Impl(node)
    {
    }

    ResizeInfo
    Btrfs::Impl::detect_resize_info() const
    {
	ResizeInfo resize_info = Filesystem::Impl::detect_resize_info();

	resize_info.combine(ResizeInfo(true, 256 * MiB, 16 * EiB));

	return resize_info;
    }

    void
    Btrfs::Impl::do_create() const
    {
	const BlkDevice* blk_device = get_blk_device();

	blk_device->get_impl().wait_for_device();

	string cmd_line = MKFSBTRFSBIN " -f " + quote(blk_device->get_name());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("create btrfs failed"));
    }

    void
    Btrfs::Impl::do_set_label() const
    {
	const BlkDevice* blk_device = get_blk_device();

	// TODO handle mounted

        string cmd_line = BTRFSBIN " filesystem label " + quote(blk_device->get_name()) + " " +
	    quote(get_label());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("set-label btrfs failed"));
    }

}
<commit_msg>- use long option<commit_after>

#include <iostream>

#include "storage/Devices/BlkDeviceImpl.h"
#include "storage/Devices/BtrfsImpl.h"
#include "storage/Devicegraph.h"
#include "storage/Action.h"
#include "storage/Utils/StorageDefines.h"
#include "storage/Utils/HumanString.h"
#include "storage/Utils/SystemCmd.h"
#include "storage/FreeInfo.h"

namespace storage
{

    using namespace std;

    const char* DeviceTraits<Btrfs>::classname = "Btrfs";

    Btrfs::Impl::Impl(const xmlNode* node)
	: Filesystem::Impl(node)
    {
    }

    ResizeInfo
    Btrfs::Impl::detect_resize_info() const
    {
	ResizeInfo resize_info = Filesystem::Impl::detect_resize_info();

	resize_info.combine(ResizeInfo(true, 256 * MiB, 16 * EiB));

	return resize_info;
    }

    void
    Btrfs::Impl::do_create() const
    {
	const BlkDevice* blk_device = get_blk_device();

	blk_device->get_impl().wait_for_device();

	string cmd_line = MKFSBTRFSBIN " --force " + quote(blk_device->get_name());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("create btrfs failed"));
    }

    void
    Btrfs::Impl::do_set_label() const
    {
	const BlkDevice* blk_device = get_blk_device();

	// TODO handle mounted

        string cmd_line = BTRFSBIN " filesystem label " + quote(blk_device->get_name()) + " " +
	    quote(get_label());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("set-label btrfs failed"));
    }

}
<|endoftext|>


<commit_before>/* Aurora Renderer
 * Copyright (c) 2013 Michal Siejak
 * Licensed under MIT open-source license, see COPYING.txt file for details.
 */

#include <stdafx.h>
#include <core/scene.h>

#include <vector>

#include <maya/MMatrix.h>
#include <maya/MPointArray.h>
#include <maya/MIntArray.h>
#include <maya/MItDag.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnMesh.h>
#include <maya/MItMeshPolygon.h>

using namespace Aurora;

Scene::Scene()
{
	m_geometry.initialize();
}

Scene::~Scene()
{
	m_geometry.free();
}

MStatus Scene::updateMeshes(MDagPathArray& meshPaths, MStatus& status)
{
	unsigned int primitiveCount  = 0;
	std::vector<MObject> objects;

	for(unsigned int i=0; i<meshPaths.length(); i++) {
		MDagPath& dagPath = meshPaths[i];
		MItMeshPolygon polyIterator(dagPath.node());

		unsigned int currentPrimitiveCount = 0;
		bool isValidObject = true;
		for(; !polyIterator.isDone(); polyIterator.next()) {
			int numTriangles;
			if(!polyIterator.hasValidTriangulation()) {
				isValidObject = false;
				break;
			}

			polyIterator.numTriangles(numTriangles);
			currentPrimitiveCount += numTriangles;
		}

		if(isValidObject) {
			primitiveCount += currentPrimitiveCount;
			objects.push_back(dagPath.node());
		}
	}

	Geometry buffer;
	buffer.initialize();
	if(!m_geometry.resize(primitiveCount, Geometry::AllocDefault)) {
		return status = MS::kInsufficientMemory;
	}
	if(!buffer.resize(primitiveCount, Geometry::AllocStaging)) {
		m_geometry.free();
		return status = MS::kInsufficientMemory;
	}

	unsigned int vertexOffset = 0;
	unsigned int normalOffset = 0;
	for(auto obj=objects.begin(); obj!=objects.end(); obj++) {
		MItMeshPolygon polyIterator(*obj);

		for(; !polyIterator.isDone(); polyIterator.next()) {
			int numTriangles;
			polyIterator.numTriangles(numTriangles);

			for(int i=0; i<numTriangles; i++) {
				MPointArray positions;
				MIntArray   indices;
				polyIterator.getTriangle(i, positions, indices, MSpace::kWorld);

				// Store vertices (in format optimised for fast traversal)
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].x;
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].y;
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].z;

				// Store normals
				for(int k=0; k<3; k++) {
					MVector normal;
					polyIterator.getNormal(indices[k], normal, MSpace::kWorld);
					buffer.normals[normalOffset++] = (float)normal.x;
					buffer.normals[normalOffset++] = (float)normal.y;
					buffer.normals[normalOffset++] = (float)normal.z;
				}
			}
		}
	}

	buffer.padToEven(primitiveCount);
	buffer.copyToDevice(m_geometry);
	buffer.free();
	return status = MS::kSuccess;
}

MStatus Scene::update(const int updateMask)
{
	MStatus status;

	MItDag   dagIterator(MItDag::kDepthFirst);
	MDagPath dagPath;

	MDagPathArray dagMeshes;

	for(; !dagIterator.isDone(); dagIterator.next()) {
		if(!dagIterator.getPath(dagPath))
			continue;

		// Transform extended to shape
		if(dagPath.hasFn(MFn::kMesh) && dagPath.hasFn(MFn::kTransform))
			continue;

		// Shape node
		if((updateMask & Scene::NodeGeometry) && dagPath.hasFn(MFn::kMesh))
			dagMeshes.append(dagPath);
	}

	if(dagMeshes.length() > 0) {
		if(!updateMeshes(dagMeshes, status))
			return status;
	}

	return MS::kSuccess;
}<commit_msg>Fixed a bug in normal retrieval code.<commit_after>/* Aurora Renderer
 * Copyright (c) 2013 Michal Siejak
 * Licensed under MIT open-source license, see COPYING.txt file for details.
 */

#include <stdafx.h>
#include <core/scene.h>

#include <vector>

#include <maya/MMatrix.h>
#include <maya/MPointArray.h>
#include <maya/MIntArray.h>
#include <maya/MItDag.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnMesh.h>
#include <maya/MItMeshPolygon.h>

using namespace Aurora;

Scene::Scene()
{
	m_geometry.initialize();
}

Scene::~Scene()
{
	m_geometry.free();
}

MStatus Scene::updateMeshes(MDagPathArray& meshPaths, MStatus& status)
{
	unsigned int primitiveCount  = 0;
	std::vector<MObject> objects;

	for(unsigned int i=0; i<meshPaths.length(); i++) {
		MDagPath& dagPath = meshPaths[i];
		MItMeshPolygon polyIterator(dagPath.node());

		unsigned int currentPrimitiveCount = 0;
		bool isValidObject = true;
		for(; !polyIterator.isDone(); polyIterator.next()) {
			int numTriangles;
			if(!polyIterator.hasValidTriangulation()) {
				isValidObject = false;
				break;
			}

			polyIterator.numTriangles(numTriangles);
			currentPrimitiveCount += numTriangles;
		}

		if(isValidObject) {
			primitiveCount += currentPrimitiveCount;
			objects.push_back(dagPath.node());
		}
	}

	Geometry buffer;
	buffer.initialize();
	if(!m_geometry.resize(primitiveCount, Geometry::AllocDefault)) {
		return status = MS::kInsufficientMemory;
	}
	if(!buffer.resize(primitiveCount, Geometry::AllocStaging)) {
		m_geometry.free();
		return status = MS::kInsufficientMemory;
	}

	unsigned int vertexOffset = 0;
	unsigned int normalOffset = 0;
	for(auto obj=objects.begin(); obj!=objects.end(); obj++) {
		MFnMesh dagMesh(*obj);
		MItMeshPolygon polyIterator(*obj);

		for(; !polyIterator.isDone(); polyIterator.next()) {
			int numTriangles;
			polyIterator.numTriangles(numTriangles);

			for(int i=0; i<numTriangles; i++) {
				MPointArray positions;
				MIntArray   indices;
				polyIterator.getTriangle(i, positions, indices, MSpace::kWorld);

				// Store vertices (in format optimised for fast traversal)
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].x;
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].y;
				for(int k=0; k<3; k++)
					buffer.vertices[vertexOffset++] = (float)positions[k].z;

				// Store normals
				for(int k=0; k<3; k++) {
					MVector normal;

					dagMesh.getFaceVertexNormal(polyIterator.index(), indices[k], normal, MSpace::kWorld);
					buffer.normals[normalOffset++] = (float)normal.x;
					buffer.normals[normalOffset++] = (float)normal.y;
					buffer.normals[normalOffset++] = (float)normal.z;
				}
			}
		}
	}

	buffer.padToEven(primitiveCount);
	buffer.copyToDevice(m_geometry);
	buffer.free();
	return status = MS::kSuccess;
}

MStatus Scene::update(const int updateMask)
{
	MStatus status;

	MItDag   dagIterator(MItDag::kDepthFirst);
	MDagPath dagPath;

	MDagPathArray dagMeshes;

	for(; !dagIterator.isDone(); dagIterator.next()) {
		if(!dagIterator.getPath(dagPath))
			continue;

		// Transform extended to shape
		if(dagPath.hasFn(MFn::kMesh) && dagPath.hasFn(MFn::kTransform))
			continue;

		// Shape node
		if((updateMask & Scene::NodeGeometry) && dagPath.hasFn(MFn::kMesh))
			dagMeshes.append(dagPath);
	}

	if(dagMeshes.length() > 0) {
		if(!updateMeshes(dagMeshes, status))
			return status;
	}

	return MS::kSuccess;
}<|endoftext|>


<commit_before>//
// Created by Miguel Rentes on 11/03/17.
//

#include "strings.h"

int main(void) {
    unsigned int n, q;
    cin >> n >> q;

    string temp;
    vector<string> hrml;
    vector<string> quer;
    cin.ignore();

    for(int i = 0; i < n; i++) {
        getline(cin, temp);
        hrml.push_back(temp);
    }

    for(int i = 0; i < q; i++) {
        getline(cin, temp);
        quer.push_back(temp);
    }

    map<string, string> m;
    vector<string> tag;

    for(int i = 0; i < n; i++) {
        temp=hrml[i];
        temp.erase(remove(temp.begin(), temp.end(), '\"'), temp.end());
        temp.erase(remove(temp.begin(), temp.end(), '>'), temp.end());

        if(temp.substr(0,2) == "</") {
            tag.pop_back();
        }
        else {
            stringstream ss;
            ss.str("");
            ss << temp;
            string t1, p1, v1;
            char ch;
            ss >> ch >> t1 >> p1 >> ch >> v1;
            string temp1 = "";
            if(tag.size() > 0) {
                temp1 =* tag.rbegin();
                temp1 = temp1 + "." + t1;
            }
            else
                temp1 = t1;
            tag.push_back(temp1);
            m[*tag.rbegin() + "~" + p1] = v1;
            while(ss) {
                ss >> p1 >> ch >> v1;
                m[*tag.rbegin() + "~" + p1] = v1;
            }
        }
    }

    for(int i = 0; i < q; i++) {
        if (m.find(quer[i]) == m.end())
            cout << "Not Found!" << endl;
        else
            cout << m[quer[i]] << endl;
    }
    return EXIT_SUCCESS;
}
<commit_msg>Refactors solution for the Attribute Parser challenge.<commit_after>//
// Created by Miguel Rentes on 11/03/17.
//

#include "strings.h"

int main(void) {
    unsigned int n, q;
    cin >> n >> q;

    string temp;
    vector<string> hrml;
    vector<string> queries;
    cin.ignore();

    for(int i = 0; i < n; i++) {
        getline(cin, temp);
        hrml.push_back(temp);
    }

    for(int i = 0; i < q; i++) {
        getline(cin, temp);
        queries.push_back(temp);
    }

    map<string, string> m;
    vector<string> tag;

    for(int i = 0; i < n; i++) {
        temp = hrml[i];
        temp.erase(remove(temp.begin(), temp.end(), '\"'), temp.end());
        temp.erase(remove(temp.begin(), temp.end(), '>'), temp.end());

        if(temp.substr(0, 2) == "</") {
            tag.pop_back();
        }
        else {
            stringstream ss;
            ss.str("");
            ss << temp;
            string t1, p1, v1;
            char ch;
            ss >> ch >> t1 >> p1 >> ch >> v1;
            string temp1 = "";
            if(tag.size() > 0) {
                temp1 =* tag.rbegin();
                temp1 = temp1 + "." + t1;
            }
            else
                temp1 = t1;
            tag.push_back(temp1);
            m[*tag.rbegin() + "~" + p1] = v1;
            while(ss) {
                ss >> p1 >> ch >> v1;
                m[*tag.rbegin() + "~" + p1] = v1;
            }
        }
    }

    for(int i = 0; i < q; i++) {
        if (m.find(queries[i]) == m.end())
            cout << "Not Found!" << endl;
        else
            cout << m[queries[i]] << endl;
    }

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before><commit_msg>Updated help texts.<commit_after><|endoftext|>


<commit_before>/*
 * ftphere
 * Start a ftp server monitor the current directory.
 * It could be used to transport files conveniently.
 */

#define FTPSERVER_HPP

#include <boost/asio.hpp>
#include <iostream>
#include <exception>
#include <unistd.h>

#ifndef LOGGER_HPP
#define LOGGER_HPP
#include "logger.hpp"
#endif

#ifndef CMD_HPP
#define CMD_HPP
#include "cmd.hpp"
#endif

#ifndef UTIL_HPP
#define UTIL_HPP
#include "util.hpp"
#endif

namespace ftp {

using namespace boost::asio;
using boost::asio::ip::tcp;
using std::string;
using std::exception;
using boost::system::error_code;

class FTPServer {
    public:
        FTPServer():
            port_(21),
            local_ep_(tcp::v4(), port_),
            ios_(),
            acceptor_(ios_),
            logger_("./ftpserver.log"),
            getcwd(cwd_, 1024) {

        }

        ~FTPServer() {

        }

        void Run() {
            error_code ec;
            tcp::socket remote_socket(ios_);

            /* init the acceptor */
            try {
                acceptor_.open(tcp::v4());
                acceptor_.bind(local_ep_);
                acceptor_.listen();
            } catch (exception& e) {
                Error(e.what());
                exit(1);
            }

            while (true) {
                try {
                    acceptor_.accept(remote_socket, ec);
                    HandleClient(remote_socket);
                } catch (exception& e) {
                    Error(e.what());
                }
            }
        }

    private:
        void HandleClient(tcp::socket& socket) {
            LogClientAction(socket, "sign in");

            error_code ec;
            streambuf buff;
            std::istream is(&buff);
            string line;
            int endable = 0;

            while (!endable) {
                read_until(socket, buff, '\n', ec);
                std::getline(is, line);

                auto cmd_args = Split(line, ' ');
                endable = Dispatch(socket, cmd_args);
            }
            socket.close();
        }

        int Dispatch(tcp::socket& socket, std::vector<std::string>& cmd_args) {
            CMD cmd_code = ResolveCMD(cmd_args[0]);
            switch (cmd_code) {
                /* normal cmd */
                case CWD:

                case HELP:
                case LIST:
                case MODE:
                case NLST:
                case NOOP:
                case PORT:
                case PASV:
                case PASS:
                case USER:
                case PWD:
                case RETR:
                case STRU:
                case TYPE:

                /* unsupported cmd */
                case DELE:
                case MKD:
                case PORT:
                case RMD:
                case STOR:

                /* illegal cmd */
                default:
            }
        }

        void LogClientAction(tcp::socket& socket, const char* msg) {
            ip::address address = socket.remote_endpoint().address();
            string info = address.to_string() + ": " + msg;
            logger_.Log(info, Logger::INFO);
        }

        void Error(const char* msg) {
            logger_.Log(msg, Logger::ERROR);
        }

        void Error(const string& msg) {
            logger_.Log(msg, Logger::ERROR);
        }

        const char* log_path_ = "./ftphere.log";
        unsigned short port_;
        char cwd_[1024];
        tcp::endpoint local_ep_;
        io_service ios_;
        tcp::acceptor acceptor_;
        Logger logger_;
};
}
<commit_msg>implement part of commands<commit_after>/*
 * ftphere
 * Start a ftp server monitor the current directory.
 * It could be used to transport files conveniently.
 */

#define FTPSERVER_HPP

#include <boost/asio.hpp>
#include <iostream>
#include <exception>
#include <unistd.h>
#include <string>

#ifndef LOGGER_HPP
#define LOGGER_HPP
#include "logger.hpp"
#endif

#ifndef CMD_HPP
#define CMD_HPP
#include "cmd.hpp"
#endif

#ifndef UTIL_HPP
#define UTIL_HPP
#include "util.hpp"
#endif

namespace ftp {

using namespace boost::asio;
using boost::asio::ip::tcp;
using std::string;
using std::exception;
using boost::system::error_code;

class FTPServer {
    public:
        FTPServer():
            port_(21),
            data_port_(20),
            local_ep_(tcp::v4(), port_),
            ios_(),
            acceptor_(ios_),
            logger_("./ftpserver.log") {
            getcwd(cwd_, 1024);
        }

        ~FTPServer() {

        }

        void Run() {
            error_code ec;
            tcp::socket remote_socket(ios_);
            tcp::endpoint data_ep(tcp::v4(), data_port_);
            tcp::socket data_socket(ios_, data_ep);

            /* init the acceptor */
            try {
                acceptor_.open(tcp::v4());
                acceptor_.bind(local_ep_);
                acceptor_.listen();
            } catch (exception& e) {
                Error(e.what());
                exit(1);
            }

            while (true) {
                try {
                    acceptor_.accept(remote_socket, ec);
                    HandleClient(remote_socket, data_socket);
                } catch (exception& e) {
                    Error(e.what());
                    remote_socket.close();
                }
            }
        }

    private:
        void HandleClient(tcp::socket& ctl_socket, tcp::socket& data_socket) {
            LogClientAction(ctl_socket, "sign in");

            error_code ec;
            streambuf buff;
            std::istream is(&buff);
            string line;
            int endable = 0;

            while (!endable) {
                read_until(socket, buff, '\n', ec);
                std::getline(is, line);

                auto cmd_args = Split(line, ' ');
                endable = Dispatch(ctl_socket, data_socket, cmd_args);
            }
        }

        int Dispatch(tcp::socket& ctl_socket, tcp::socket& data_socket, std::vector<std::string>& cmd_args) {
            CMD cmd_code = ResolveCMD(cmd_args[0]);
            string res;
            switch (cmd_code) {
                /* normal cmd */
                case CWD: {
                    // todo
                    strcat(cwd_, cmd_args[1].data());
                    res = "250 Directory successfully changed.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                          }
                case HELP: {
                    res = "214 The following commands are recognized.";
                    res += "ABOR ABOR CWD HELP LIST MKD\r\n";
                    res += "MODE NLST NOOP PASS PASV PORT PWD QUIT RETR\r\n";
                    res += "SITE SIZE SMNT STAT STOR STRU SYST TYPE USER\r\n";
                    res += "214 Help okay\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case LIST: {
                    // todo
                           }
                case MODE:
                    // todo
                case NLST:
                    // todo
                case NOOP: {
                    res = "200 NOOP okay.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case PASV: {
                    res = "227 Entering passive mode(";
                    int remote_port = rand() % 65536;
                    string address = ctl_socket.remote_endpoint().address().to_string();
                    std::replace(address.begin(), address.end(), '.', ',');
                    res += address + "," +
                        std::to_string(remote_port / 256) + "," +
                        std::to_string(remote_port % 256) + ").\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case PASS: {
                    res = "230 User logged in successfully.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case USER: {
                    res = "331 Please specify the password.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case PWD: {
                    res = "257 ";
                    res += cwd_;
                    res += "\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                          }
                case RETR: {
                    res = "150 Opening BINARY mode data connection for file.\r\n";
                    ctl_socket.write_some(buffer(res));
                    /* todo */
                    char buff[1024];
                    FILE* file = fopen(cmd_args[1].data(), "r");
                    size_t len;

                    while ((len = fread(buff, 1024, 1, file))) {
                        write(data_socket, buffer(buff, len));
                    }
                    fclose(file);
                    res = "226 Transfer complete.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case STRU:
                    // todo
                case SYST:
                    ctl_socket.write_some(buffer("215 UNIX Type.\r\n"));
                    break;
                case TYPE: {
                    if (cmd_args[1] == "I") {
                        res = "200 Switching to binary mode.\r\n";
                    } else {
                        res = "504 Command not implemented for the parameter.\r\n";
                    }
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case PORT: {
                    auto args = Split(cmd_args[1], ',');
                    string address;
                    for (int i = 0; i < 4; i++)
                        address += args[i] + ".";
                    address.pop_back();
                    int port = stoi(args[4]) * 256 + stoi(args[5]);
                    tcp::endpoint ep(ip::address::from_string(address), port);
                    data_socket.connect(ep);

                    res = "200 PORT command successful.\r\n";
                    ctl_socket.write_some(buffer(res));
                    break;
                           }
                case QUIT: {
                    res = "221 Goodbye.\r\n";
                    ctl_socket.write_some(buffer(res));
                    return 1;
                           }

                /* unsupported cmd */
                case DELE:
                case MKD:
                case RMD:
                case STOR: {
                    ctl_socket.write_some(buffer("502 Command not implemented.\r\n"));
                    break;
                           }
                /* illegal cmd */
                default:
                    ctl_socket.write_some(buffer("500 Syntax error, command unrecognized.\r\n"));
            }
            return 0;
        }

        void OpenDataConnection(int port) {
            tcp::endpoint data_ep(ip::tcp::v4(), port);

        }

        void LogClientAction(tcp::socket& socket, const char* msg) {
            ip::address address = socket.remote_endpoint().address();
            string info = address.to_string() + ": " + msg;
            logger_.Log(info, Logger::INFO);
        }

        void Error(const char* msg) {
            logger_.Log(msg, Logger::ERROR);
        }

        void Error(const string& msg) {
            logger_.Log(msg, Logger::ERROR);
        }

        const char* log_path_ = "./ftphere.log";
        unsigned short port_;
        unsigned short data_port_;
        char cwd_[1024];
        tcp::endpoint local_ep_;
        io_service ios_;
        tcp::acceptor acceptor_;
        Logger logger_;
};
}
<|endoftext|>