1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CONNECTIVITY_FORMATTEDCOLUMNVALUE_HXX
25 #define CONNECTIVITY_FORMATTEDCOLUMNVALUE_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/sdbc/XRowSet.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/sdb/XColumn.hpp>
31 #include <com/sun/star/sdb/XColumnUpdate.hpp>
32 #include <com/sun/star/util/XNumberFormatter.hpp>
33 /** === end UNO includes === **/
34 
35 #include <boost/noncopyable.hpp>
36 
37 #include <memory>
38 #include "connectivity/dbtoolsdllapi.hxx"
39 
40 namespace comphelper { class ComponentContext; }
41 
42 //........................................................................
43 namespace dbtools
44 {
45 //........................................................................
46 
47     struct FormattedColumnValue_Data;
48 	//====================================================================
49 	//= FormattedColumnValue
50 	//====================================================================
51     /** a class which helps retrieving and setting the value of a database column
52         as formatted string.
53     */
54     class OOO_DLLPUBLIC_DBTOOLS FormattedColumnValue : public ::boost::noncopyable
55 	{
56     public:
57         /** constructs an instance
58 
59             The format key for the string value exchange is taken from the given column object.
60             If it has a non-<NULL/> property value <code>FormatKey</code>, this key is taken.
61             Otherwise, a default format matching the column type is determined.
62 
63             The locale of this fallback format is the current system locale.
64 
65             The number formats supplier is determined from the given <code>RowSet</code>, by
66             examining its <code>ActiveConnection</code>.
67         */
68         FormattedColumnValue(
69             const ::comphelper::ComponentContext& _rContext,
70             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet,
71             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn
72         );
73 
74         /** constructs an instance
75 
76             The format key for the string value exchange is taken from the given column object.
77             If it has a non-<NULL/> property value <code>FormatKey</code>, this key is taken.
78             Otherwise, a default format matching the column type is determined.
79 
80             The locale of this fallback format is the current system locale.
81         */
82         FormattedColumnValue(
83             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& i_rNumberFormatter,
84             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& i_rColumn
85         );
86 
87         // note that all methods of this class need to be virtual, since it's
88         // used in a load-on-demand context in module SVX
89 
90         virtual ~FormattedColumnValue();
91 
92         virtual void clear();
93 
94         // access to the details of the formatting we determined
95         virtual sal_Int32   getFormatKey() const;
96         virtual sal_Int32   getFieldType() const;
97         virtual sal_Int16   getKeyType() const;
98         virtual bool        isNumericField() const;
99         virtual const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn >&
100                             getColumn() const;
101         virtual const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumnUpdate >&
102                             getColumnUpdate() const;
103 
104         virtual bool            setFormattedValue( const ::rtl::OUString& _rFormattedStringValue ) const;
105         virtual ::rtl::OUString getFormattedValue() const;
106 
107     private:
108         ::std::auto_ptr< FormattedColumnValue_Data >    m_pData;
109 	};
110 
111 //........................................................................
112 } // namespace dbtools
113 //........................................................................
114 
115 #endif // CONNECTIVITY_FORMATTEDCOLUMNVALUE_HXX
116