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.

435 lines
10KB

  1. /* This file is part of the KDE project
  2. Copyright 2003 Lukas Tinkl <lukas@kde.org>
  3. Copyright 2000, 2002-2003 Laurent Montel <montel@kde.org>
  4. Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
  5. Copyright 2003 Joseph Wenninger <jowenn@kde.org>
  6. Copyright 2002 Ariya Hidayat <ariya@kde.org>
  7. Copyright 2002 Harri Porten <porten@kde.org>
  8. Copyright 2002 John Dailey <dailey@vt.edu>
  9. Copyright 2001 Simon Hausmann <hausmann@kde.org>
  10. Copyright 2000 Werner Trobin <trobin@kde.org>
  11. Copyright 1999 Torben Weis <weis@kde.org>
  12. This library is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Library General Public
  14. License as published by the Free Software Foundation; either
  15. version 2 of the License, or (at your option) any later version.
  16. This library is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. Library General Public License for more details.
  20. You should have received a copy of the GNU Library General Public License
  21. along with this library; see the file COPYING.LIB. If not, write to
  22. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301, USA.
  24. */
  25. #include "kspread_sheet.h"
  26. #include "kspread_sheetprint.h"
  27. #include "kspread_util.h"
  28. #include "kspread_doc.h"
  29. #include <dcopclient.h>
  30. #include <tdeapplication.h>
  31. #include <kdebug.h>
  32. #include "KSpreadCellIface.h"
  33. #include "region.h"
  34. #include "KSpreadTableIface.h"
  35. using namespace KSpread;
  36. /*********************************************
  37. *
  38. * CellProxy
  39. *
  40. *********************************************/
  41. class KSpread::CellProxy : public DCOPObjectProxy
  42. {
  43. public:
  44. CellProxy( Sheet* sheet, const TQCString& prefix );
  45. ~CellProxy();
  46. virtual bool process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
  47. TQCString& replyType, TQByteArray &replyData );
  48. private:
  49. TQCString m_prefix;
  50. CellIface* m_cell;
  51. Sheet* m_sheet;
  52. };
  53. KSpread::CellProxy::CellProxy( Sheet* sheet, const TQCString& prefix )
  54. : DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
  55. {
  56. m_cell = new CellIface;
  57. m_sheet = sheet;
  58. }
  59. KSpread::CellProxy::~CellProxy()
  60. {
  61. delete m_cell;
  62. }
  63. bool KSpread::CellProxy::process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
  64. TQCString& replyType, TQByteArray &replyData )
  65. {
  66. kdDebug()<<"CellProxy::process: requested object:"<<obj<<endl;
  67. kdDebug()<<"CellProxy::process: prefix:"<<m_prefix<<endl;
  68. if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
  69. return false;
  70. if ( fun == "functions()" ) {
  71. replyType = "QCStringList";
  72. TQDataStream reply( replyData, IO_WriteOnly );
  73. QCStringList repList=m_cell->functions();
  74. reply<<repList;
  75. return true;
  76. }
  77. TQString cellID=TQString::fromUtf8(obj.data() + m_prefix.length());
  78. cellID=m_sheet->sheetName()+"!"+cellID;
  79. kdDebug()<<"CellProxy::process: cellID="<<cellID<<endl;
  80. Point p( cellID); //obj.data() + m_prefix.length() );
  81. if ( p.pos().x()<0 ) {
  82. kdDebug(36001)<<"CellProyxy::process: resulting Point is not valid"<<endl;
  83. return false;
  84. }
  85. kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos().x()<<endl;
  86. m_cell->setCell( m_sheet, p.pos() );
  87. return m_cell->process( fun, data, replyType, replyData );
  88. }
  89. /************************************************
  90. *
  91. * SheetIface
  92. *
  93. ************************************************/
  94. SheetIface::SheetIface( Sheet* t )
  95. : DCOPObject()
  96. {
  97. m_proxy=0;
  98. m_sheet = t;
  99. sheetNameHasChanged();
  100. }
  101. void SheetIface::sheetNameHasChanged() {
  102. ident.resize(1);
  103. TQObject *currentObj = m_sheet;
  104. while (currentObj != 0L) {
  105. ident.prepend( currentObj->name() );
  106. ident.prepend("/");
  107. currentObj = currentObj->parent();
  108. }
  109. if ( ident[0] == '/' )
  110. ident = ident.mid(1);
  111. if (qstrcmp(ident,objId())!=0) {
  112. setObjId(ident);
  113. delete m_proxy;
  114. TQCString str = objId();
  115. str += "/";
  116. kdDebug(36001)<<"SheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
  117. m_proxy = new CellProxy( m_sheet, str );
  118. }
  119. }
  120. SheetIface::~SheetIface()
  121. {
  122. delete m_proxy;
  123. }
  124. DCOPRef SheetIface::cell( int x, int y )
  125. {
  126. // if someone calls us with either x or y 0 he _most_ most likely doesn't
  127. // know that the cell counting starts with 1 (Simon)
  128. // P.S.: I did that mistake for weeks and already started looking for the
  129. // "bug" in kspread ;-)
  130. if ( x == 0 )
  131. x = 1;
  132. if ( y == 0 )
  133. y = 1;
  134. TQCString str = objId() + '/' + Cell::name( x, y ).latin1();
  135. return DCOPRef( kapp->dcopClient()->appId(), str );
  136. }
  137. DCOPRef SheetIface::cell( const TQString& name )
  138. {
  139. TQCString str = objId();
  140. str += "/";
  141. str += name.latin1();
  142. return DCOPRef( kapp->dcopClient()->appId(), str );
  143. }
  144. DCOPRef SheetIface::column( int _col )
  145. {
  146. //First col number = 1
  147. if(_col <1)
  148. return DCOPRef();
  149. return DCOPRef( kapp->dcopClient()->appId(),
  150. m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );
  151. }
  152. DCOPRef SheetIface::row( int _row )
  153. {
  154. //First row number = 1
  155. if(_row <1)
  156. return DCOPRef();
  157. return DCOPRef( kapp->dcopClient()->appId(),
  158. m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
  159. }
  160. TQString SheetIface::name() const
  161. {
  162. return m_sheet->sheetName();
  163. }
  164. int SheetIface::maxColumn() const
  165. {
  166. return m_sheet->maxColumn();
  167. }
  168. bool SheetIface::areaHasNoContent(TQRect area) const
  169. {
  170. kdDebug(36001) << "SheetIface::areaHasNoContent("<<area<<");"<<endl;
  171. return m_sheet->areaIsEmpty(area);
  172. }
  173. bool SheetIface::areaHasNoComments(TQRect area) const
  174. {
  175. return m_sheet->areaIsEmpty(area, Sheet::Comment);
  176. }
  177. int SheetIface::maxRow() const
  178. {
  179. return m_sheet->maxRow();
  180. }
  181. bool SheetIface::processDynamic( const TQCString& fun, const TQByteArray&/*data*/,
  182. TQCString& replyType, TQByteArray &replyData )
  183. {
  184. kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
  185. // Does the name follow the pattern "foobar()" ?
  186. uint len = fun.length();
  187. if ( len < 3 )
  188. return false;
  189. if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
  190. return false;
  191. // Is the function name a valid cell like "B5" ?
  192. Point p( fun.left( len - 2 ).data() );
  193. if ( !p.isValid() )
  194. return false;
  195. TQCString str = objId() + "/" + fun.left( len - 2 );
  196. replyType = "DCOPRef";
  197. TQDataStream out( replyData, IO_WriteOnly );
  198. out << DCOPRef( kapp->dcopClient()->appId(), str );
  199. return true;
  200. }
  201. bool SheetIface::setSheetName( const TQString & name)
  202. {
  203. return m_sheet->setSheetName( name);
  204. }
  205. bool SheetIface::insertColumn( int col,int nbCol )
  206. {
  207. return m_sheet->insertColumn(col,nbCol);
  208. }
  209. bool SheetIface::insertRow( int row,int nbRow)
  210. {
  211. return m_sheet->insertRow(row,nbRow);
  212. }
  213. void SheetIface::removeColumn( int col,int nbCol )
  214. {
  215. m_sheet->removeColumn( col,nbCol );
  216. }
  217. void SheetIface::removeRow( int row,int nbRow )
  218. {
  219. m_sheet->removeRow( row,nbRow );
  220. }
  221. bool SheetIface::isHidden()const
  222. {
  223. return m_sheet->isHidden();
  224. }
  225. bool SheetIface::showGrid() const
  226. {
  227. return m_sheet->getShowGrid();
  228. }
  229. bool SheetIface::showFormula() const
  230. {
  231. return m_sheet->getShowFormula();
  232. }
  233. bool SheetIface::lcMode() const
  234. {
  235. return m_sheet->getLcMode();
  236. }
  237. bool SheetIface::autoCalc() const
  238. {
  239. return m_sheet->getAutoCalc();
  240. }
  241. bool SheetIface::showColumnNumber() const
  242. {
  243. return m_sheet->getShowColumnNumber();
  244. }
  245. bool SheetIface::hideZero() const
  246. {
  247. return m_sheet->getHideZero();
  248. }
  249. bool SheetIface::firstLetterUpper() const
  250. {
  251. return m_sheet->getFirstLetterUpper();
  252. }
  253. void SheetIface::setShowPageBorders( bool b )
  254. {
  255. m_sheet->setShowPageBorders( b );
  256. m_sheet->doc()->updateBorderButton();
  257. }
  258. float SheetIface::paperHeight()const
  259. {
  260. return m_sheet->print()->paperHeight();
  261. }
  262. float SheetIface::paperWidth()const
  263. {
  264. return m_sheet->print()->paperWidth();
  265. }
  266. float SheetIface::leftBorder()const
  267. {
  268. return m_sheet->print()->leftBorder();
  269. }
  270. float SheetIface::rightBorder()const
  271. {
  272. return m_sheet->print()->rightBorder();
  273. }
  274. float SheetIface::topBorder()const
  275. {
  276. return m_sheet->print()->topBorder();
  277. }
  278. float SheetIface::bottomBorder()const
  279. {
  280. return m_sheet->print()->bottomBorder();
  281. }
  282. TQString SheetIface::paperFormatString() const
  283. {
  284. return m_sheet->print()->paperFormatString();
  285. }
  286. TQString SheetIface::headLeft()const
  287. {
  288. return m_sheet->print()->headLeft();
  289. }
  290. TQString SheetIface::headMid()const
  291. {
  292. return m_sheet->print()->headMid();
  293. }
  294. TQString SheetIface::headRight()const
  295. {
  296. return m_sheet->print()->headRight();
  297. }
  298. TQString SheetIface::footLeft()const
  299. {
  300. return m_sheet->print()->footLeft();
  301. }
  302. TQString SheetIface::footMid()const
  303. {
  304. return m_sheet->print()->footMid();
  305. }
  306. TQString SheetIface::footRight()const
  307. {
  308. return m_sheet->print()->footRight();
  309. }
  310. void SheetIface::setHeaderLeft(const TQString & text)
  311. {
  312. m_sheet->print()->setHeadFootLine( text, headMid(), headRight(),
  313. footLeft(), footMid(), footRight() );
  314. }
  315. void SheetIface::setHeaderMiddle(const TQString & text)
  316. {
  317. m_sheet->print()->setHeadFootLine( headLeft(), text, headRight(),
  318. footLeft(), footMid(), footRight() );
  319. }
  320. void SheetIface::setHeaderRight(const TQString & text)
  321. {
  322. m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
  323. footLeft(), footMid(), footRight() );
  324. }
  325. void SheetIface::setFooterLeft(const TQString & text)
  326. {
  327. m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
  328. text, footMid(), footRight() );
  329. }
  330. void SheetIface::setFooterMiddle(const TQString & text)
  331. {
  332. m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
  333. footLeft(), text, footRight() );
  334. }
  335. void SheetIface::setFooterRight(const TQString & text)
  336. {
  337. m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
  338. footLeft(), footMid(), text );
  339. }
  340. bool SheetIface::isProtected() const
  341. {
  342. return m_sheet->isProtected();
  343. }