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.

256 lines
6.3KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3. Copyright (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef KSPREAD_SELECTION
  18. #define KSPREAD_SELECTION
  19. #include <tqobject.h>
  20. #include <kdebug.h>
  21. #include "region.h"
  22. namespace KSpread
  23. {
  24. class View;
  25. class Selection : public TQObject, public Region
  26. {
  27. Q_OBJECT
  28. public:
  29. Selection(View*);
  30. Selection(const Selection&);
  31. ~Selection();
  32. /**
  33. * Sets the selection to the given point
  34. */
  35. void initialize(const TQPoint&, Sheet* sheet = 0);
  36. /**
  37. * Sets the selection to the given range
  38. */
  39. void initialize(const TQRect&, Sheet* sheet = 0);
  40. /**
  41. * Sets the selection to the given region
  42. */
  43. void initialize(const Region&, Sheet* sheet = 0);
  44. /**
  45. * Emits signal changed(const Region&)
  46. */
  47. void update();
  48. /**
  49. * Uses the anchor as starting point
  50. */
  51. void update(const TQPoint&);
  52. /**
  53. * Extends the current selection with an additional point
  54. */
  55. void extend(const TQPoint&, Sheet* sheet = 0);
  56. /**
  57. * Extends the current selection with an additional range
  58. */
  59. void extend(const TQRect&, Sheet* sheet = 0);
  60. /**
  61. * Extends the current selection with an additional region
  62. */
  63. void extend(const Region&);
  64. /**
  65. * @param point the point's location
  66. * @param sheet the sheet the point belongs to
  67. */
  68. virtual Element* eor(const TQPoint& point, Sheet* sheet = 0);
  69. /**
  70. * The anchor is the starting point of a range. For points marker and anchor are the same
  71. */
  72. const TQPoint& anchor() const;
  73. /**
  74. * The cursor represents the cursor position. This needed for obscured cells
  75. */
  76. const TQPoint& cursor() const;
  77. /**
  78. * The marker is the end point of a range. For points marker and anchor are the same
  79. */
  80. const TQPoint& marker() const;
  81. /**
  82. * Checks wether the region consists only of one point
  83. */
  84. bool isSingular() const;
  85. /**
  86. * @return the area that the 'handle' of the selection is located in painting coordinates
  87. */
  88. TQRect selectionHandleArea() const;
  89. /**
  90. * @return the name of the region (e.g. "A1:A2")
  91. */
  92. TQString name(Sheet* originSheet = 0) const;
  93. /**
  94. * Sets the selection's origin sheet.
  95. * @param sheet the sheet from which the selection starts
  96. */
  97. void setSheet(Sheet* sheet);
  98. /**
  99. * @return the selection's origin sheet
  100. */
  101. Sheet* sheet() const;
  102. /**
  103. * Sets the element, which has @p point as anchor, as active
  104. */
  105. void setActiveElement(const TQPoint& point);
  106. /**
  107. * Sets the @p number 'th element as active
  108. */
  109. void setActiveElement(uint number);
  110. /**
  111. * @return the active element
  112. */
  113. Element* activeElement() const;
  114. /**
  115. * Sets the starting position and the length of a subregion in a multiple
  116. * selection
  117. */
  118. void setActiveSubRegion(uint start, uint length);
  119. /**
  120. *
  121. */
  122. TQString activeSubRegionName() const;
  123. /**
  124. * Clears the elements of the subregion
  125. */
  126. void clearSubRegion();
  127. /**
  128. * fix subregion dimensions
  129. */
  130. void fixSubRegionDimension();
  131. /**
  132. * Deletes all elements of the region. The result is an empty region.
  133. */
  134. virtual void clear();
  135. /**
  136. * Sets, wether multiple selections are allowed.
  137. */
  138. void setMultipleSelection(bool state);
  139. TQRect lastRange(bool extend = true) const;
  140. TQRect extendToMergedAreas(TQRect area) const;
  141. const TQValueList<TQColor>& colors() const;
  142. // TODO Stefan #2: replace this
  143. TQRect selection(bool extend = true) const;
  144. signals:
  145. void changed(const Region&);
  146. protected:
  147. class Point;
  148. class Range;
  149. virtual Region::Point* createPoint(const TQPoint&) const;
  150. virtual Region::Point* createPoint(const TQString&) const;
  151. virtual Region::Point* createPoint(const Point&) const;
  152. virtual Region::Range* createRange(const TQRect&) const;
  153. virtual Region::Range* createRange(const TQString&) const;
  154. virtual Region::Range* createRange(const Range&) const;
  155. private:
  156. class Private;
  157. Private *d;
  158. };
  159. /***************************************************************************
  160. class Selection::Point
  161. ****************************************************************************/
  162. class Selection::Point : public Region::Point
  163. {
  164. public:
  165. Point(const TQPoint& point);
  166. Point(const TQString& string);
  167. void setColor(const TQColor& color) { m_color = color; }
  168. virtual const TQColor& color() const { return m_color; }
  169. bool columnFixed() const { return m_columnFixed; }
  170. bool rowFixed() const { return m_rowFixed; }
  171. protected:
  172. private:
  173. TQColor m_color;
  174. bool m_columnFixed : 1;
  175. bool m_rowFixed : 1;
  176. };
  177. /***************************************************************************
  178. class Selection::Range
  179. ****************************************************************************/
  180. class Selection::Range : public Region::Range
  181. {
  182. public:
  183. Range(const TQRect& rect);
  184. Range(const TQString& string);
  185. virtual bool isColorizable() const { return true; }
  186. void setColor(const TQColor& color) { m_color = color; }
  187. const TQColor& color() const { return m_color; }
  188. protected:
  189. private:
  190. TQColor m_color;
  191. bool m_leftFixed : 1;
  192. bool m_rightFixed : 1;
  193. bool m_topFixed : 1;
  194. bool m_bottomFixed : 1;
  195. };
  196. } // namespace KSpread
  197. /***************************************************************************
  198. kdDebug support
  199. ****************************************************************************/
  200. inline kdbgstream operator<<( kdbgstream str, const KSpread::Selection& s )
  201. {
  202. str << "Selection = " << s.name();
  203. return str;
  204. }
  205. inline kndbgstream operator<<( kndbgstream str, const KSpread::Selection& )
  206. {
  207. return str;
  208. }
  209. #endif // KSPREAD_SELECTION