fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableRow.cxx
blob3f7d2e103c3f86e254fd7b22ac3771c624e5f1d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TableRow.hxx"
21 #include <tools/debug.hxx>
22 #include "FieldDescriptions.hxx"
23 #include <algorithm>
24 #include <comphelper/types.hxx>
26 using namespace dbaui;
27 using namespace ::com::sun::star::sdbc;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::beans;
31 // class OTableRow
32 OTableRow::OTableRow()
33 :m_pActFieldDescr( NULL )
34 ,m_nPos( -1 )
35 ,m_bReadOnly( false )
36 ,m_bOwnsDescriptions(false)
40 OTableRow::OTableRow(const Reference< XPropertySet >& xAffectedCol)
41 :m_pActFieldDescr( NULL )
42 ,m_nPos( -1 )
43 ,m_bReadOnly( false )
44 ,m_bOwnsDescriptions(true)
46 m_pActFieldDescr = new OFieldDescription(xAffectedCol);
49 OTableRow::OTableRow( const OTableRow& rRow, long nPosition )
50 :m_pActFieldDescr(NULL)
51 ,m_nPos( nPosition )
52 ,m_bReadOnly(rRow.IsReadOnly())
53 ,m_bOwnsDescriptions(false)
56 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
57 if(pSrcField)
59 m_pActFieldDescr = new OFieldDescription(*pSrcField);
60 m_bOwnsDescriptions = true;
64 OTableRow::~OTableRow()
66 if(m_bOwnsDescriptions)
67 delete m_pActFieldDescr;
70 void OTableRow::SetPrimaryKey( bool bSet )
72 if(m_pActFieldDescr)
73 m_pActFieldDescr->SetPrimaryKey(bSet);
76 bool OTableRow::IsPrimaryKey() const
78 return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey();
81 void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, bool _bForce )
83 if ( _pType.get() )
85 if( !m_pActFieldDescr )
87 m_pActFieldDescr = new OFieldDescription();
88 m_bOwnsDescriptions = true;
90 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,true);
92 else
94 delete m_pActFieldDescr;
95 m_pActFieldDescr = NULL;
99 namespace dbaui
101 SvStream& WriteOTableRow( SvStream& _rStr, const OTableRow& _rRow )
103 _rStr.WriteInt32( _rRow.m_nPos );
104 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
105 if(pFieldDesc)
107 _rStr.WriteInt32( 1 );
108 _rStr.WriteUniOrByteString(pFieldDesc->GetName(), _rStr.GetStreamCharSet());
109 _rStr.WriteUniOrByteString(pFieldDesc->GetDescription(), _rStr.GetStreamCharSet());
110 _rStr.WriteUniOrByteString(pFieldDesc->GetHelpText(), _rStr.GetStreamCharSet());
111 double nValue = 0.0;
112 Any aValue = pFieldDesc->GetControlDefault();
113 if ( aValue >>= nValue )
115 _rStr.WriteInt32( 1 );
116 _rStr.WriteDouble( nValue );
118 else
120 _rStr.WriteInt32( 2 );
121 _rStr.WriteUniOrByteString(::comphelper::getString(aValue), _rStr.GetStreamCharSet());
124 _rStr.WriteInt32( pFieldDesc->GetType() );
126 _rStr.WriteInt32( pFieldDesc->GetPrecision() );
127 _rStr.WriteInt32( pFieldDesc->GetScale() );
128 _rStr.WriteInt32( pFieldDesc->GetIsNullable() );
129 _rStr.WriteInt32( pFieldDesc->GetFormatKey() );
130 _rStr.WriteInt32( pFieldDesc->GetHorJustify() );
131 _rStr.WriteInt32( pFieldDesc->IsAutoIncrement() ? 1 : 0 );
132 _rStr.WriteInt32( pFieldDesc->IsPrimaryKey() ? 1 : 0 );
133 _rStr.WriteInt32( pFieldDesc->IsCurrency() ? 1 : 0 );
135 else
136 _rStr.WriteInt32( 0 );
137 return _rStr;
139 SvStream& ReadOTableRow( SvStream& _rStr, OTableRow& _rRow )
141 _rStr.ReadInt32( _rRow.m_nPos );
142 sal_Int32 nValue = 0;
143 _rStr.ReadInt32( nValue );
144 if ( nValue )
146 OFieldDescription* pFieldDesc = new OFieldDescription();
147 _rRow.m_pActFieldDescr = pFieldDesc;
148 OUString sValue = _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
149 pFieldDesc->SetName(sValue);
151 sValue = _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
152 pFieldDesc->SetDescription(sValue);
153 sValue = _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
154 pFieldDesc->SetHelpText(sValue);
156 _rStr.ReadInt32( nValue );
157 Any aControlDefault;
158 switch ( nValue )
160 case 1:
162 double nControlDefault;
163 _rStr.ReadDouble( nControlDefault );
164 aControlDefault <<= nControlDefault;
165 break;
167 case 2:
168 sValue = _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
169 aControlDefault <<= OUString(sValue);
170 break;
173 pFieldDesc->SetControlDefault(aControlDefault);
175 _rStr.ReadInt32( nValue );
176 pFieldDesc->SetTypeValue(nValue);
178 _rStr.ReadInt32( nValue );
179 pFieldDesc->SetPrecision(nValue);
180 _rStr.ReadInt32( nValue );
181 pFieldDesc->SetScale(nValue);
182 _rStr.ReadInt32( nValue );
183 pFieldDesc->SetIsNullable(nValue);
184 _rStr.ReadInt32( nValue );
185 pFieldDesc->SetFormatKey(nValue);
186 _rStr.ReadInt32( nValue );
187 pFieldDesc->SetHorJustify((SvxCellHorJustify)nValue);
189 _rStr.ReadInt32( nValue );
190 pFieldDesc->SetAutoIncrement(nValue != 0);
191 _rStr.ReadInt32( nValue );
192 pFieldDesc->SetPrimaryKey(nValue != 0);
193 _rStr.ReadInt32( nValue );
194 pFieldDesc->SetCurrency(nValue != 0);
196 return _rStr;
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */