summaryrefslogtreecommitdiff
path: root/rsc/source/res/rscrange.cxx
blob: db7957d076449c3d8d6db93e231f6b5bb63eb2c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <rscrange.hxx>

RscLongRange::RscLongRange( Atom nId, RESOURCE_TYPE nTypeId )
    : RscTop( nId, nTypeId )
    , nMin(0), nMax(0)
{
}

void RscLongRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum )
{
    if( nMinimum > nMaximum )
    {
        nMin = nMaximum;
        nMax = nMinimum;
    }
    else
    {
        nMax = nMaximum;
        nMin = nMinimum;
    }
}

bool RscLongRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
{
    if( pDef )
        return 0 == memcmp( &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue,
                            &reinterpret_cast<RscLongRangeInst*>(pDef)->nValue,
                            sizeof( sal_Int32 ) );

    return false;
}

ERRTYPE RscLongRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
{
    if( nMax < nValue || nMin > nValue )
        return ERR_RSCRANGE_OUTDEFSET;

    void * pData = &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue;
    memcpy( pData, &nValue, sizeof( sal_Int32 ) );
    reinterpret_cast<RscLongRangeInst *>(rInst.pData)->bDflt = false;
    return ERR_OK;
}

ERRTYPE RscLongRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN )
{
    memmove( pN, &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue,
             sizeof( sal_Int32 ) );
    return ERR_OK;
}

RSCINST RscLongRange::Create( RSCINST * pInst, const RSCINST & rDflt,
                              bool bOwnClass )
{
    RSCINST aInst;

    if( !pInst )
    {
        aInst.pClass = this;
        aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( sizeof( RscLongRangeInst ) ));
    }
    else
        aInst = *pInst;

    if( !bOwnClass && rDflt.IsInst() )
        bOwnClass = rDflt.pClass->InHierarchy( this );

    if( bOwnClass )
        memmove( aInst.pData, rDflt.pData, sizeof( RscLongRangeInst ) );
    else
    {
        sal_Int32   lDflt;
        if( 0 >= nMin && 0 <= nMax )
            lDflt = 0;
        else
            lDflt = nMin;

        void * pData = &reinterpret_cast<RscLongRangeInst*>(aInst.pData)->nValue;
        memcpy( pData, &lDflt, sizeof( sal_Int32 ) );
        reinterpret_cast<RscLongRangeInst *>(aInst.pData)->bDflt = true;
    }

    return aInst;
}

void RscLongRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
                             RscTypCont *, sal_uInt32, const char * )
{
    sal_Int32 lVal;
    GetNumber( rInst, &lVal );
    fprintf( fOutput, "%d", static_cast<int>(lVal) );
}

ERRTYPE RscLongRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
                               RscTypCont *, sal_uInt32 )
{
    sal_Int32 lVal;

    GetNumber( rInst, &lVal );
    aMem.Put( lVal );

    return ERR_OK;
}

RscLongEnumRange::RscLongEnumRange( Atom nId, RESOURCE_TYPE nTypeId )
    : RscLongRange( nId, nTypeId )
{
}

ERRTYPE RscLongEnumRange::SetConst( const RSCINST & rInst, Atom /*nConst*/,
                                    sal_Int32 nValue )
{
    return SetNumber( rInst, nValue );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */