android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableRow.cxx
blob8f13193e1c41e296ccdf0a11fd7de6d6d8ccde64
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/stream.hxx>
22 #include <FieldDescriptions.hxx>
23 #include <comphelper/types.hxx>
25 using namespace dbaui;
26 using namespace ::com::sun::star::sdbc;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::beans;
30 OTableRow::OTableRow()
31 :m_pActFieldDescr( nullptr )
32 ,m_nPos( -1 )
33 ,m_bReadOnly( false )
34 ,m_bOwnsDescriptions(false)
38 OTableRow::OTableRow( const OTableRow& rRow, tools::Long nPosition )
39 :m_pActFieldDescr(nullptr)
40 ,m_nPos( nPosition )
41 ,m_bReadOnly(rRow.IsReadOnly())
42 ,m_bOwnsDescriptions(false)
45 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
46 if(pSrcField)
48 m_pActFieldDescr = new OFieldDescription(*pSrcField);
49 m_bOwnsDescriptions = true;
53 OTableRow::~OTableRow()
55 if(m_bOwnsDescriptions)
56 delete m_pActFieldDescr;
59 void OTableRow::SetPrimaryKey( bool bSet )
61 if(m_pActFieldDescr)
62 m_pActFieldDescr->SetPrimaryKey(bSet);
65 bool OTableRow::IsPrimaryKey() const
67 return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey();
70 void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, bool _bForce )
72 if ( _pType )
74 if( !m_pActFieldDescr )
76 m_pActFieldDescr = new OFieldDescription();
77 m_bOwnsDescriptions = true;
79 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,true);
81 else
83 delete m_pActFieldDescr;
84 m_pActFieldDescr = nullptr;
88 namespace dbaui
90 SvStream& WriteOTableRow( SvStream& _rStr, const OTableRow& _rRow )
92 _rStr.WriteInt32( _rRow.m_nPos );
93 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
94 if(pFieldDesc)
96 _rStr.WriteInt32( 1 );
97 _rStr.WriteUniOrByteString(pFieldDesc->GetName(), _rStr.GetStreamCharSet());
98 _rStr.WriteUniOrByteString(pFieldDesc->GetDescription(), _rStr.GetStreamCharSet());
99 _rStr.WriteUniOrByteString(pFieldDesc->GetHelpText(), _rStr.GetStreamCharSet());
100 double nValue = 0.0;
101 Any aValue = pFieldDesc->GetControlDefault();
102 if ( aValue >>= nValue )
104 _rStr.WriteInt32( 1 );
105 _rStr.WriteDouble( nValue );
107 else
109 _rStr.WriteInt32( 2 );
110 _rStr.WriteUniOrByteString(::comphelper::getString(aValue), _rStr.GetStreamCharSet());
113 _rStr.WriteInt32( pFieldDesc->GetType() );
115 _rStr.WriteInt32( pFieldDesc->GetPrecision() );
116 _rStr.WriteInt32( pFieldDesc->GetScale() );
117 _rStr.WriteInt32( pFieldDesc->GetIsNullable() );
118 _rStr.WriteInt32( pFieldDesc->GetFormatKey() );
119 _rStr.WriteInt32( static_cast<sal_Int32>(pFieldDesc->GetHorJustify()) );
120 _rStr.WriteInt32( pFieldDesc->IsAutoIncrement() ? 1 : 0 );
121 _rStr.WriteInt32( pFieldDesc->IsPrimaryKey() ? 1 : 0 );
122 _rStr.WriteInt32( pFieldDesc->IsCurrency() ? 1 : 0 );
124 else
125 _rStr.WriteInt32( 0 );
126 return _rStr;
128 SvStream& ReadOTableRow( SvStream& _rStr, OTableRow& _rRow )
130 _rStr.ReadInt32( _rRow.m_nPos );
131 sal_Int32 nValue = 0;
132 _rStr.ReadInt32( nValue );
133 if ( !nValue )
134 return _rStr;
135 OFieldDescription* pFieldDesc = new OFieldDescription();
136 _rRow.m_pActFieldDescr = pFieldDesc;
137 pFieldDesc->SetName(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
138 pFieldDesc->SetDescription(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
139 pFieldDesc->SetHelpText(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
141 _rStr.ReadInt32( nValue );
142 Any aControlDefault;
143 switch ( nValue )
145 case 1:
147 double nControlDefault;
148 _rStr.ReadDouble( nControlDefault );
149 aControlDefault <<= nControlDefault;
150 break;
152 case 2:
153 aControlDefault <<= _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
154 break;
157 pFieldDesc->SetControlDefault(aControlDefault);
159 _rStr.ReadInt32( nValue );
160 pFieldDesc->SetTypeValue(nValue);
162 _rStr.ReadInt32( nValue );
163 pFieldDesc->SetPrecision(nValue);
164 _rStr.ReadInt32( nValue );
165 pFieldDesc->SetScale(nValue);
166 _rStr.ReadInt32( nValue );
167 pFieldDesc->SetIsNullable(nValue);
168 _rStr.ReadInt32( nValue );
169 pFieldDesc->SetFormatKey(nValue);
170 _rStr.ReadInt32( nValue );
171 pFieldDesc->SetHorJustify(static_cast<SvxCellHorJustify>(nValue));
173 _rStr.ReadInt32( nValue );
174 pFieldDesc->SetAutoIncrement(nValue != 0);
175 _rStr.ReadInt32( nValue );
176 pFieldDesc->SetPrimaryKey(nValue != 0);
177 _rStr.ReadInt32( nValue );
178 pFieldDesc->SetCurrency(nValue != 0);
179 return _rStr;
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */