1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <LimitBox.hxx>
11 #include <strings.hrc>
12 #include <core_resource.hxx>
13 
14 #define ALL_STRING DBA_RES(STR_QUERY_LIMIT_ALL)
15 #define ALL_INT -1
16 
17 namespace global{
18 
19 /// Default values
20 sal_Int64 const aDefLimitAry[] =
21 {
22     5,
23     10,
24     20,
25     50
26 };
27 
28 }
29 
30 namespace dbaui
31 {
32 
33 
LimitBox(vcl::Window * pParent)34 LimitBox::LimitBox( vcl::Window* pParent )
35     : NumericBox( pParent, WB_DROPDOWN | WB_VSCROLL )
36 {
37     SetShowTrailingZeros( false );
38     SetDecimalDigits( 0 );
39     SetMin( -1 );
40     SetMax( SAL_MAX_INT64 );
41     LoadDefaultLimits();
42 
43     Size aSize(
44         GetSizePixel().Width(),
45         CalcWindowSizePixel(GetEntryCount() + 1) );
46     SetSizePixel(aSize);
47 }
48 
CreateFieldText(sal_Int64 nValue) const49 OUString LimitBox::CreateFieldText( sal_Int64 nValue ) const
50 {
51     if( nValue == ALL_INT )
52         return ALL_STRING;
53     else
54         return NumericBox::CreateFieldText( nValue );
55 }
56 
Reformat()57 void LimitBox::Reformat()
58 {
59 
60     if( GetText() == ALL_STRING )
61     {
62         SetValue( ALL_INT );
63     }
64     ///Reformat only when text is not All
65     else
66     {
67         ///Not allow user to type in -1
68         if( GetText() == "-1" )
69         {
70             Undo();
71         }
72         else
73             NumericBox::Reformat();
74     }
75 }
76 
ReformatAll()77 void LimitBox::ReformatAll()
78 {
79     ///First entry is All, which do not need numeric reformat
80     if ( GetEntryCount() > 0 )
81     {
82         RemoveEntryAt( 0 );
83         NumericBox::ReformatAll();
84         InsertValue( ALL_INT, 0);
85     }
86     else
87     {
88         NumericBox::ReformatAll();
89     }
90 }
91 
GetOptimalSize() const92 Size LimitBox::GetOptimalSize() const
93 {
94     return CalcBlockSize(10,1);
95 }
96 
97 ///Initialize entries
LoadDefaultLimits()98 void LimitBox::LoadDefaultLimits()
99 {
100     InsertValue( ALL_INT );
101 
102     for(long nIndex : global::aDefLimitAry)
103     {
104         InsertValue( nIndex );
105     }
106 }
107 
108 } ///dbaui namespace
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
111