update dev300-m58
[ooovba.git] / dbaccess / source / ui / tabledesign / TableRow.cxx
blobc17ce82834e953326c8c8800e819e1ffaf64f760
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableRow.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLEROW_HXX
34 #include "TableRow.hxx"
35 #endif
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
39 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
40 #include "FieldDescriptions.hxx"
41 #endif
42 #include <algorithm>
43 #include <comphelper/types.hxx>
45 using namespace dbaui;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
50 //========================================================================
51 // class OTableRow
52 //========================================================================
53 DBG_NAME(OTableRow)
54 //------------------------------------------------------------------------------
55 OTableRow::OTableRow()
56 :m_pActFieldDescr( NULL )
57 ,m_nPos( -1 )
58 ,m_bReadOnly( false )
59 ,m_bOwnsDescriptions(false)
61 DBG_CTOR(OTableRow,NULL);
63 //------------------------------------------------------------------------------
64 OTableRow::OTableRow(const Reference< XPropertySet >& xAffectedCol)
65 :m_pActFieldDescr( NULL )
66 ,m_nPos( -1 )
67 ,m_bReadOnly( false )
68 ,m_bOwnsDescriptions(true)
70 DBG_CTOR(OTableRow,NULL);
71 m_pActFieldDescr = new OFieldDescription(xAffectedCol);
73 //------------------------------------------------------------------------------
74 OTableRow::OTableRow( const OTableRow& rRow, long nPosition )
75 :m_pActFieldDescr(NULL)
76 ,m_nPos( nPosition )
77 ,m_bReadOnly(rRow.IsReadOnly())
78 ,m_bOwnsDescriptions(false)
80 DBG_CTOR(OTableRow,NULL);
82 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
83 if(pSrcField)
85 m_pActFieldDescr = new OFieldDescription(*pSrcField);
86 m_bOwnsDescriptions = true;
90 //------------------------------------------------------------------------------
91 OTableRow::~OTableRow()
93 DBG_DTOR(OTableRow,NULL);
94 if(m_bOwnsDescriptions)
95 delete m_pActFieldDescr;
98 //------------------------------------------------------------------------------
99 void OTableRow::SetPrimaryKey( sal_Bool bSet )
101 DBG_CHKTHIS(OTableRow,NULL);
102 if(m_pActFieldDescr)
103 m_pActFieldDescr->SetPrimaryKey(bSet);
105 // -----------------------------------------------------------------------------
106 sal_Bool OTableRow::IsPrimaryKey() const
108 DBG_CHKTHIS(OTableRow,NULL);
109 return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey();
111 // -----------------------------------------------------------------------------
112 void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, sal_Bool _bForce )
114 DBG_CHKTHIS(OTableRow,NULL);
115 if ( _pType.get() )
117 if( !m_pActFieldDescr )
119 m_pActFieldDescr = new OFieldDescription();
120 m_bOwnsDescriptions = true;
122 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,sal_True);
124 else
126 delete m_pActFieldDescr;
127 m_pActFieldDescr = NULL;
130 // -----------------------------------------------------------------------------
131 namespace dbaui
133 // -----------------------------------------------------------------------------
134 SvStream& operator<<( SvStream& _rStr, const OTableRow& _rRow )
136 _rStr << _rRow.m_nPos;
137 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
138 if(pFieldDesc)
140 _rStr << (sal_Int32)1;
141 _rStr.WriteByteString(pFieldDesc->GetName());
142 _rStr.WriteByteString(pFieldDesc->GetDescription());
143 double nValue = 0.0;
144 Any aValue = pFieldDesc->GetControlDefault();
145 if ( aValue >>= nValue )
147 _rStr << sal_Int32(1);
148 _rStr << nValue;
150 else
152 _rStr << sal_Int32(2);
153 _rStr.WriteByteString(::comphelper::getString(aValue));
156 _rStr << pFieldDesc->GetType();
158 _rStr << pFieldDesc->GetPrecision();
159 _rStr << pFieldDesc->GetScale();
160 _rStr << pFieldDesc->GetIsNullable();
161 _rStr << pFieldDesc->GetFormatKey();
162 _rStr << (sal_Int32)pFieldDesc->GetHorJustify();
163 _rStr << sal_Int32(pFieldDesc->IsAutoIncrement() ? 1 : 0);
164 _rStr << sal_Int32(pFieldDesc->IsPrimaryKey() ? 1 : 0);
165 _rStr << sal_Int32(pFieldDesc->IsCurrency() ? 1 : 0);
166 } // if(pFieldDesc)
167 else
168 _rStr << (sal_Int32)0;
169 return _rStr;
171 // -----------------------------------------------------------------------------
172 SvStream& operator>>( SvStream& _rStr, OTableRow& _rRow )
174 _rStr >> _rRow.m_nPos;
175 sal_Int32 nValue = 0;
176 _rStr >> nValue;
177 if ( nValue )
179 OFieldDescription* pFieldDesc = new OFieldDescription();
180 _rRow.m_pActFieldDescr = pFieldDesc;
181 String sValue;
182 _rStr.ReadByteString(sValue);
183 pFieldDesc->SetName(sValue);
185 _rStr.ReadByteString(sValue);
186 pFieldDesc->SetDescription(sValue);
188 _rStr >> nValue;
189 Any aControlDefault;
190 switch ( nValue )
192 case 1:
194 double nControlDefault;
195 _rStr >> nControlDefault;
196 aControlDefault <<= nControlDefault;
197 break;
199 case 2:
200 _rStr.ReadByteString(sValue);
201 aControlDefault <<= ::rtl::OUString(sValue);
202 break;
205 pFieldDesc->SetControlDefault(aControlDefault);
208 _rStr >> nValue;
209 pFieldDesc->SetTypeValue(nValue);
211 _rStr >> nValue;
212 pFieldDesc->SetPrecision(nValue);
213 _rStr >> nValue;
214 pFieldDesc->SetScale(nValue);
215 _rStr >> nValue;
216 pFieldDesc->SetIsNullable(nValue);
217 _rStr >> nValue;
218 pFieldDesc->SetFormatKey(nValue);
219 _rStr >> nValue;
220 pFieldDesc->SetHorJustify((SvxCellHorJustify)nValue);
222 _rStr >> nValue;
223 pFieldDesc->SetAutoIncrement(nValue != 0);
224 _rStr >> nValue;
225 pFieldDesc->SetPrimaryKey(nValue != 0);
226 _rStr >> nValue;
227 pFieldDesc->SetCurrency(nValue != 0);
229 return _rStr;
231 // -----------------------------------------------------------------------------