KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.4KB

  1. /* This file is part of the KDE project
  2. Copyright 2002 Ariya Hidayat <ariya@kde.org>
  3. Copyright 2001 Laurent Montel <montel@kde.org>
  4. Copyright 2001 Philipp Mueller <philipp.mueller@gmx.de>
  5. Copyright 2000 Werner Trobin <trobin@kde.org>
  6. Copyright 1999-2000 Torben Weis <weis@kde.org>
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public
  9. License as published by the Free Software Foundation; either
  10. version 2 of the License, or (at your option) any later version.
  11. This library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public License
  16. along with this library; see the file COPYING.LIB. If not, write to
  17. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include <dcopclient.h>
  21. #include <tdeapplication.h>
  22. #include <kdebug.h>
  23. #include "kspread_doc.h"
  24. #include "kspread_map.h"
  25. #include "kspread_sheet.h"
  26. #include "KSpreadMapIface.h"
  27. using namespace KSpread;
  28. MapIface::MapIface( Map* map )
  29. : DCOPObject( map )
  30. {
  31. m_map = map;
  32. }
  33. DCOPRef MapIface::sheet( const TQString& name )
  34. {
  35. Sheet* t = m_map->findSheet( name );
  36. if ( !t )
  37. return DCOPRef();
  38. return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
  39. }
  40. DCOPRef MapIface::sheetByIndex( int index )
  41. {
  42. Sheet* t = m_map->sheetList().at( index );
  43. if ( !t )
  44. {
  45. kdDebug(36001) << "+++++ No table found at index " << index << endl;
  46. return DCOPRef();
  47. }
  48. kdDebug(36001) << "+++++++ Returning table " << t->TQObject::name() << endl;
  49. return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
  50. }
  51. int MapIface::sheetCount() const
  52. {
  53. return m_map->count();
  54. }
  55. TQStringList MapIface::sheetNames() const
  56. {
  57. TQStringList names;
  58. TQPtrList<Sheet>& lst = m_map->sheetList();
  59. TQPtrListIterator<Sheet> it( lst );
  60. for( ; it.current(); ++it )
  61. names.append( it.current()->name() );
  62. return names;
  63. }
  64. TQValueList<DCOPRef> MapIface::sheets()
  65. {
  66. TQValueList<DCOPRef> t;
  67. TQPtrList<Sheet>& lst = m_map->sheetList();
  68. TQPtrListIterator<Sheet> it( lst );
  69. for( ; it.current(); ++it )
  70. t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
  71. return t;
  72. }
  73. DCOPRef MapIface::insertSheet( const TQString& name )
  74. {
  75. if ( m_map->findSheet( name ) )
  76. return sheet( name );
  77. Sheet* t = m_map->addNewSheet ();
  78. t->setSheetName( name );
  79. return sheet( name );
  80. }
  81. bool MapIface::processDynamic(const TQCString &fun, const TQByteArray &/*data*/,
  82. TQCString& replyType, TQByteArray &replyData)
  83. {
  84. // Does the name follow the pattern "foobar()" ?
  85. uint len = fun.length();
  86. if ( len < 3 )
  87. return false;
  88. if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
  89. return false;
  90. Sheet* t = m_map->findSheet( fun.left( len - 2 ).data() );
  91. if ( !t )
  92. return false;
  93. replyType = "DCOPRef";
  94. TQDataStream out( replyData, IO_WriteOnly );
  95. out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
  96. return true;
  97. }