Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #undef SC_DLLIMPLEMENTATION
21 :
22 : #include "mtrindlg.hxx"
23 : #include "scresid.hxx"
24 : #include "miscdlgs.hrc"
25 :
26 0 : ScMetricInputDlg::ScMetricInputDlg( vcl::Window* pParent,
27 : const OString& sDialogName,
28 : long nCurrent,
29 : long nDefault,
30 : FieldUnit eFUnit,
31 : sal_uInt16 nDecimals,
32 : long nMaximum,
33 : long nMinimum,
34 : long nFirst,
35 : long nLast )
36 :
37 : : ModalDialog(pParent, OStringToOUString(sDialogName, RTL_TEXTENCODING_UTF8),
38 0 : OStringToOUString("modules/scalc/ui/" +
39 0 : sDialogName.toAsciiLowerCase() + ".ui", RTL_TEXTENCODING_UTF8))
40 : {
41 0 : get(m_pEdValue, "value");
42 0 : get(m_pBtnDefVal, "default");
43 :
44 0 : m_pBtnDefVal->SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
45 0 : m_pEdValue->SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) );
46 :
47 0 : m_pEdValue->SetUnit ( eFUnit );
48 0 : m_pEdValue->SetDecimalDigits ( nDecimals );
49 0 : m_pEdValue->SetMax ( m_pEdValue->Normalize( nMaximum ), FUNIT_TWIP );
50 0 : m_pEdValue->SetMin ( m_pEdValue->Normalize( nMinimum ), FUNIT_TWIP );
51 0 : m_pEdValue->SetLast ( m_pEdValue->Normalize( nLast ), FUNIT_TWIP );
52 0 : m_pEdValue->SetFirst ( m_pEdValue->Normalize( nFirst ), FUNIT_TWIP );
53 0 : m_pEdValue->SetSpinSize ( m_pEdValue->Normalize( 1 ) / 10 );
54 0 : m_pEdValue->SetValue ( m_pEdValue->Normalize( nDefault ), FUNIT_TWIP );
55 0 : nDefaultValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
56 0 : m_pEdValue->SetValue ( m_pEdValue->Normalize( nCurrent ), FUNIT_TWIP );
57 0 : nCurrentValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
58 0 : m_pBtnDefVal->Check( nCurrentValue == nDefaultValue );
59 0 : }
60 :
61 0 : ScMetricInputDlg::~ScMetricInputDlg()
62 : {
63 0 : disposeOnce();
64 0 : }
65 :
66 0 : void ScMetricInputDlg::dispose()
67 : {
68 0 : m_pEdValue.clear();
69 0 : m_pBtnDefVal.clear();
70 0 : ModalDialog::dispose();
71 0 : }
72 :
73 0 : long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const
74 : {
75 : /*
76 : with decimal digits
77 :
78 : double nVal = m_pEdValue->GetValue( eUnit );
79 : sal_uInt16 nDecs = m_pEdValue->GetDecimalDigits();
80 : double nFactor = 0.0;
81 :
82 : // static long ImpPower10( sal_uInt16 nDecs )
83 : {
84 : nFactor = 1.0;
85 :
86 : for ( sal_uInt16 i=0; i < nDecs; i++ )
87 : nFactor *= 10.0;
88 : }
89 :
90 : return nVal / nFactor;
91 : */
92 : // first cut off the decimal digits - not that great...
93 :
94 0 : return sal::static_int_cast<long>( m_pEdValue->Denormalize( m_pEdValue->GetValue( eUnit ) ) );
95 : }
96 :
97 : // Handler:
98 :
99 0 : IMPL_LINK_NOARG(ScMetricInputDlg, SetDefValHdl)
100 : {
101 0 : if ( m_pBtnDefVal->IsChecked() )
102 : {
103 0 : nCurrentValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
104 0 : m_pEdValue->SetValue( nDefaultValue );
105 : }
106 : else
107 0 : m_pEdValue->SetValue( nCurrentValue );
108 0 : return 0;
109 : }
110 :
111 0 : IMPL_LINK_NOARG(ScMetricInputDlg, ModifyHdl)
112 : {
113 0 : m_pBtnDefVal->Check( nDefaultValue == m_pEdValue->GetValue() );
114 0 : return 0;
115 0 : }
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|