~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kspread/kspread_map.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
   Boston, MA 02111-1307, USA.
18
18
*/
19
19
 
20
 
#include <qprinter.h>
21
 
#include <qdom.h>
22
 
#include <qmessagebox.h>
23
20
 
 
21
#include "kspread_changes.h"
24
22
#include "kspread_map.h"
25
23
#include "kspread_doc.h"
26
 
#include "kspread_view.h"
27
24
#include "kspread_canvas.h"
28
 
#include "kspread_table.h"
29
 
#include "kspread_util.h"
30
25
 
31
26
#include "KSpreadMapIface.h"
32
27
 
 
28
#include <kmdcodec.h>
 
29
 
33
30
#include <time.h>
34
31
#include <stdlib.h>
35
32
 
36
33
KSpreadMap::KSpreadMap( KSpreadDoc *_doc, const char* name )
37
 
    : QObject( _doc, name )
 
34
  : QObject( _doc, name ),
 
35
    m_pDoc( _doc ),
 
36
    m_pChanges( 0 ),
 
37
    m_initialActiveTable( 0 ),
 
38
    m_initialMarkerColumn( 0 ),
 
39
    m_initialMarkerRow( 0 ),
 
40
    m_dcop( 0 )
38
41
{
39
 
  m_pDoc = _doc;
40
 
  m_dcop = 0;
41
 
  m_initialActiveTable = 0L;
42
 
  m_initialMarkerColumn = 0;
43
 
  m_initialMarkerRow = 0;
44
 
 
45
42
  m_lstTables.setAutoDelete( true );
46
43
}
47
44
 
50
47
    delete m_dcop;
51
48
}
52
49
 
53
 
void KSpreadMap::addTable( KSpreadTable *_table )
 
50
void KSpreadMap::setProtected( QCString const & passwd )
 
51
{
 
52
  m_strPassword = passwd;
 
53
}
 
54
 
 
55
void KSpreadMap::startRecordingChanges()
 
56
{
 
57
  delete m_pChanges;
 
58
  m_pChanges = new KSpreadChanges( this );
 
59
}
 
60
 
 
61
void KSpreadMap::stopRecordingChanges()
 
62
{
 
63
  delete m_pChanges;
 
64
  m_pChanges = 0;
 
65
}
 
66
 
 
67
void KSpreadMap::addTable( KSpreadSheet *_table )
54
68
{
55
69
  m_lstTables.append( _table );
56
70
}
57
71
 
58
 
void KSpreadMap::removeTable( KSpreadTable *_table )
59
 
{
60
 
  m_lstTables.setAutoDelete( false );
61
 
  m_lstTables.removeRef( _table );
62
 
  m_lstTables.setAutoDelete( true );
63
 
}
64
 
 
65
72
void KSpreadMap::moveTable( const QString & _from, const QString & _to, bool _before )
66
73
{
67
 
  KSpreadTable* tablefrom = findTable( _from );
68
 
  KSpreadTable* tableto = findTable( _to );
 
74
  KSpreadSheet* tablefrom = findTable( _from );
 
75
  KSpreadSheet* tableto = findTable( _to );
69
76
 
70
77
  int from = m_lstTables.find( tablefrom ) ;
71
78
  int to = m_lstTables.find( tableto ) ;
103
110
    mymap.setAttribute( "markerRow", canvas->markerRow() );
104
111
  }
105
112
 
106
 
  QListIterator<KSpreadTable> it( m_lstTables );
 
113
  if ( !m_strPassword.isNull() )
 
114
  {
 
115
    if ( m_strPassword.size() > 0 )
 
116
    {
 
117
      QCString str = KCodecs::base64Encode( m_strPassword ); 
 
118
      mymap.setAttribute( "protected", QString( str.data() ) );
 
119
    }
 
120
    else
 
121
      mymap.setAttribute( "protected", "" );      
 
122
  }
 
123
 
 
124
  if ( m_pChanges )
 
125
    m_pChanges->saveXml( doc, mymap );
 
126
 
 
127
  QPtrListIterator<KSpreadSheet> it( m_lstTables );
107
128
  for( ; it.current(); ++it )
108
129
  {
109
 
    QDomElement e = it.current()->save( doc );
 
130
    QDomElement e = it.current()->saveXML( doc );
110
131
    if ( e.isNull() )
111
132
      return e;
112
133
    mymap.appendChild( e );
120
141
  QString activeTable = mymap.attribute( "activeTable" );
121
142
  m_initialMarkerColumn = mymap.attribute( "markerColumn" ).toInt();
122
143
  m_initialMarkerRow = mymap.attribute( "markerRow" ).toInt();
 
144
 
123
145
  QDomNode n = mymap.firstChild();
 
146
  if ( n.isNull() )
 
147
  {
 
148
      // We need at least one table !
 
149
      m_pDoc->setErrorMessage( i18n("This document has no table.") );
 
150
      return false;
 
151
  }
124
152
  while( !n.isNull() )
125
153
  {
126
154
    QDomElement e = n.toElement();
127
155
    if ( !e.isNull() && e.tagName() == "table" )
128
156
    {
129
 
      KSpreadTable *t = m_pDoc->createTable();
 
157
      KSpreadSheet *t = m_pDoc->createTable();
130
158
      m_pDoc->addTable( t );
131
159
      if ( !t->loadXML( e ) )
132
160
        return false;
134
162
    n = n.nextSibling();
135
163
  }
136
164
 
 
165
  n = mymap.namedItem( "tracked-changes" );
 
166
  if ( !n.isNull() )
 
167
  {
 
168
    QDomElement ch = n.toElement();
 
169
    if ( !ch.isNull() )
 
170
    {
 
171
      m_pChanges = new KSpreadChanges( this );
 
172
      m_pChanges->loadXml( ch );
 
173
    }
 
174
  }
 
175
 
 
176
  if ( mymap.hasAttribute( "protected" ) )
 
177
  {
 
178
    QString passwd = mymap.attribute( "protected" );
 
179
    
 
180
    if ( passwd.length() > 0 )
 
181
    {
 
182
      QCString str( passwd.latin1() );
 
183
      m_strPassword = KCodecs::base64Decode( str );        
 
184
    }
 
185
    else
 
186
      m_strPassword = QCString( "" );
 
187
  }
 
188
 
137
189
  if (!activeTable.isEmpty())
138
190
  {
139
191
    // Used by KSpreadView's constructor
145
197
 
146
198
void KSpreadMap::update()
147
199
{
148
 
  QListIterator<KSpreadTable> it( m_lstTables );
 
200
  QPtrListIterator<KSpreadSheet> it( m_lstTables );
149
201
  for( ; it.current(); ++it )
150
 
    it.current()->update();
 
202
    it.current()->recalc();
151
203
}
152
204
 
153
 
KSpreadTable* KSpreadMap::findTable( const QString & _name )
 
205
KSpreadSheet* KSpreadMap::findTable( const QString & _name )
154
206
{
155
 
    KSpreadTable *t;
 
207
    KSpreadSheet * t;
156
208
 
157
209
    for ( t = m_lstTables.first(); t != 0L; t = m_lstTables.next() )
158
210
    {
163
215
    return 0L;
164
216
}
165
217
 
166
 
KSpreadTable* KSpreadMap::nextTable( KSpreadTable* currentTable )
 
218
KSpreadSheet * KSpreadMap::nextTable( KSpreadSheet * currentTable )
167
219
{
168
 
    KSpreadTable *t;
 
220
    KSpreadSheet * t;
169
221
 
170
222
    if( currentTable == m_lstTables.last())
171
223
      return currentTable;
179
231
    return 0L;
180
232
}
181
233
 
182
 
KSpreadTable* KSpreadMap::previousTable( KSpreadTable* currentTable )
 
234
KSpreadSheet * KSpreadMap::previousTable( KSpreadSheet * currentTable )
183
235
{
184
 
    KSpreadTable *t;
 
236
    KSpreadSheet * t;
185
237
 
186
238
    if( currentTable == m_lstTables.first())
187
239
      return currentTable;
195
247
    return 0L;
196
248
}
197
249
 
198
 
bool KSpreadMap::saveChildren( KoStore* _store, const QString &_path )
 
250
bool KSpreadMap::saveChildren( KoStore * _store )
199
251
{
200
 
  QListIterator<KSpreadTable> it( m_lstTables );
 
252
  QPtrListIterator<KSpreadSheet> it( m_lstTables );
201
253
  for( ; it.current(); ++it )
202
254
  {
203
255
    // set the child document's url to an internal url (ex: "tar:/0/1")
204
 
    QString path = QString( "%1/%2" ).arg( _path ).arg( it.current()->tableName() );
205
 
    if ( !it.current()->saveChildren( _store, path ) )
 
256
    if ( !it.current()->saveChildren( _store, it.current()->tableName() ) )
206
257
      return false;
207
258
  }
208
259
  return true;
209
260
}
210
261
 
211
 
bool KSpreadMap::loadChildren( KoStore* _store )
 
262
bool KSpreadMap::loadChildren( KoStore * _store )
212
263
{
213
 
  QListIterator<KSpreadTable> it( m_lstTables );
 
264
  QPtrListIterator<KSpreadSheet> it( m_lstTables );
214
265
  for( ; it.current(); ++it )
215
266
    if ( !it.current()->loadChildren( _store ) )
216
267
      return false;
218
269
  return true;
219
270
}
220
271
 
221
 
DCOPObject* KSpreadMap::dcopObject()
 
272
DCOPObject * KSpreadMap::dcopObject()
222
273
{
223
274
    if ( !m_dcop )
224
275
        m_dcop = new KSpreadMapIface( this );
226
277
    return m_dcop;
227
278
}
228
279
 
229
 
KSpreadDoc* KSpreadMap::doc()
 
280
KSpreadDoc * KSpreadMap::doc() const
230
281
{
231
282
    return m_pDoc;
232
283
}
 
284
 
 
285
void KSpreadMap::takeTable( KSpreadSheet * table )
 
286
{
 
287
    int pos = m_lstTables.findRef( table );
 
288
    m_lstTables.take( pos );
 
289
    m_lstDeletedTables.append( table );
 
290
}
 
291
 
 
292
void KSpreadMap::insertTable( KSpreadSheet * table )
 
293
{
 
294
    int pos = m_lstDeletedTables.findRef( table );
 
295
    if ( pos != -1 )
 
296
        m_lstDeletedTables.take( pos );
 
297
    m_lstTables.append(table);
 
298
}