# Cppcheck report - LibreOffice: dbaccess/source/ui/querydesign/LimitBox.cxx

      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

    /* -*- 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/.
     */

    #include <vcl/builder.hxx>
    #include "LimitBox.hxx"
    #include "dbu_qry.hrc"
    #include "moduledbu.hxx"

    #define ALL_STRING ModuleRes(STR_QUERY_LIMIT_ALL).toString()
    #define ALL_INT -1

    namespace global{

    /// Default values
    sal_Int64 aDefLimitAry[] =
    {
        5,
        10,
        20,
        50
    };

    }

    namespace dbaui
    {

    LimitBox::LimitBox( vcl::Window* pParent, WinBits nStyle )
        : NumericBox( pParent, nStyle )
    {
        SetShowTrailingZeros( false );
        SetDecimalDigits( 0 );
        SetMin( -1 );
        SetMax( SAL_MAX_INT64 );
        LoadDefaultLimits();

        Size aSize(
            GetSizePixel().Width(),
            CalcWindowSizePixel(GetEntryCount() + 1) );
        SetSizePixel(aSize);
    }

    LimitBox::~LimitBox()
    {
    }

    OUString LimitBox::CreateFieldText( sal_Int64 nValue ) const
    {
        if( nValue == ALL_INT )
            return ALL_STRING;
        else
            return NumericBox::CreateFieldText( nValue );
    }

    void LimitBox::Reformat()
    {

        if( GetText() == ALL_STRING )
        {
            SetValue( ALL_INT );
        }
        ///Reformat only when text is not All
        else
        {
            ///Not allow user to type in -1
            if( GetText() == "-1" )
            {
                Undo();
            }
            else
                NumericBox::Reformat();
        }
    }

    void LimitBox::ReformatAll()
    {
        ///First entry is All, which do not need numeric reformat
        if ( GetEntryCount() > 0 )
        {
            RemoveEntryAt( 0 );
            NumericBox::ReformatAll();
            InsertValue( ALL_INT, 0);
        }
        else
        {
            NumericBox::ReformatAll();
        }
    }

    Size LimitBox::GetOptimalSize() const
    {
        return CalcBlockSize(10,1);
    }

    ///Initialize entries
    void LimitBox::LoadDefaultLimits()
    {
        InsertValue( ALL_INT );

        const unsigned nSize =
            sizeof(global::aDefLimitAry)/sizeof(global::aDefLimitAry[0]);
        for( unsigned nIndex = 0; nIndex< nSize; ++nIndex)
        {
            InsertValue( global::aDefLimitAry[nIndex] );
        }
    }

    extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeLimitBox( vcl::Window *pParent, VclBuilder::stringmap & )<--- The function 'makeLimitBox' is never used.
    {
        LimitBox* pBox = new LimitBox( pParent, WB_DROPDOWN | WB_VSCROLL );
        return pBox;
    }

    } ///dbaui namespace

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