TDE core libraries
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.

partmanager.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // -*- mode: c++; c-basic-offset: 2 -*-
  2. /* This file is part of the KDE project
  3. Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
  4. (C) 1999 David Faure <faure@kde.org>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __kpartmanager_h__
  19. #define __kpartmanager_h__
  20. #include <tqobject.h>
  21. #include <tqwidget.h>
  22. #include <tqptrlist.h>
  23. #include <tdelibs_export.h>
  24. class TDEInstance;
  25. namespace KParts
  26. {
  27. class Part;
  28. class PartManagerPrivate;
  29. /**
  30. * The part manager is an object which knows about a collection of parts
  31. * (even nested ones) and handles activation/deactivation.
  32. *
  33. * Applications that want to embed parts without merging GUIs
  34. * only use a KParts::PartManager. Those who want to merge GUIs use a
  35. * KParts::MainWindow for example, in addition to a part manager.
  36. *
  37. * Parts know about the part manager to add nested parts to it.
  38. * See also KParts::Part::manager() and KParts::Part::setManager().
  39. */
  40. class TDEPARTS_EXPORT PartManager : public TQObject
  41. {
  42. Q_OBJECT
  43. TQ_ENUMS( SelectionPolicy )
  44. TQ_PROPERTY( SelectionPolicy selectionPolicy READ selectionPolicy WRITE setSelectionPolicy )
  45. TQ_PROPERTY( bool allowNestedParts READ allowNestedParts WRITE setAllowNestedParts )
  46. TQ_PROPERTY( bool ignoreScrollBars READ ignoreScrollBars WRITE setIgnoreScrollBars )
  47. public:
  48. /// Selection policy. The default policy of a PartManager is Direct.
  49. enum SelectionPolicy { Direct, TriState };
  50. /**
  51. * This extends TQFocusEvent::Reason with the non-focus-event reasons for partmanager to activate a part.
  52. * To test for "any focusin reason", use < ReasonLeftClick.
  53. * NoReason usually means: explicit activation with @ref setActivePart.
  54. * @since 3.3
  55. */
  56. enum Reason { ReasonLeftClick = 100, ReasonMidClick, ReasonRightClick, NoReason };
  57. /**
  58. * Constructs a part manager.
  59. *
  60. * @param parent The toplevel widget (window / dialog) the
  61. * partmanager should monitor for activation/selection
  62. * events
  63. * @param name The object's name, if any.
  64. */
  65. PartManager( TQWidget * parent, const char * name = 0L );
  66. /**
  67. * Constructs a part manager.
  68. *
  69. * @param topLevel The toplevel widget (window / dialog ) the
  70. * partmanager should monitor for activation/selection
  71. * events
  72. * @param parent The parent TQObject.
  73. * @param name The object's name, if any.
  74. */
  75. PartManager( TQWidget * topLevel, TQObject *parent, const char *name = 0 );
  76. virtual ~PartManager();
  77. /**
  78. * Sets the selection policy of the partmanager.
  79. */
  80. void setSelectionPolicy( SelectionPolicy policy );
  81. /**
  82. * Returns the current selection policy.
  83. */
  84. SelectionPolicy selectionPolicy() const;
  85. /**
  86. * Specifies whether the partmanager should handle/allow nested parts
  87. * or not.
  88. *
  89. * This is a property the shell has to set/specify. Per
  90. * default we assume that the shell cannot handle nested
  91. * parts. However in case of a KOffice shell for example we allow
  92. * nested parts. A Part is nested (a child part) if its parent
  93. * object inherits KParts::Part. If a child part is activated and
  94. * nested parts are not allowed/handled, then the top parent part in
  95. * the tree is activated.
  96. */
  97. void setAllowNestedParts( bool allow );
  98. /**
  99. * @see setAllowNestedParts
  100. */
  101. bool allowNestedParts() const;
  102. /**
  103. * Specifies whether the partmanager should ignore mouse click events for
  104. * scrollbars or not. If the partmanager ignores them, then clicking on the
  105. * scrollbars of a non-active/non-selected part will not change the selection
  106. * or activation state.
  107. *
  108. * The default value is false (read: scrollbars are NOT ignored).
  109. */
  110. void setIgnoreScrollBars( bool ignore );
  111. /**
  112. * @see setIgnoreScrollBars
  113. */
  114. bool ignoreScrollBars() const;
  115. /**
  116. * Specifies which mouse buttons the partmanager should react upon.
  117. * By default it reacts on all mouse buttons (LMB/MMB/RMB).
  118. * @param buttonMask a combination of TQt::ButtonState values e.g. Qt::LeftButton | Qt::MidButton
  119. */
  120. void setActivationButtonMask( short int buttonMask );
  121. /**
  122. * @see setActivationButtonMask
  123. */
  124. short int activationButtonMask() const;
  125. /**
  126. * @internal
  127. */
  128. virtual bool eventFilter( TQObject *obj, TQEvent *ev );
  129. /**
  130. * Adds a part to the manager.
  131. *
  132. * Sets it to the active part automatically if @p setActive is true (default ).
  133. * Behavior fix in KDE3.4: the part's widget is shown only if @p setActive is true,
  134. * it used to be shown in all cases before.
  135. */
  136. virtual void addPart( Part *part, bool setActive = true );
  137. /**
  138. * Removes a part from the manager (this does not delete the object) .
  139. *
  140. * Sets the active part to 0 if @p part is the activePart() .
  141. */
  142. virtual void removePart( Part *part );
  143. /**
  144. * Replaces @p oldPart with @p newPart, and sets @p newPart as active if
  145. * @p setActive is true.
  146. * This is an optimised version of removePart + addPart
  147. */
  148. virtual void replacePart( Part * oldPart, Part * newPart, bool setActive = true );
  149. /**
  150. * Sets the active part.
  151. *
  152. * The active part receives activation events.
  153. *
  154. * @p widget can be used to specify which widget was responsible for the activation.
  155. * This is important if you have multiple views for a document/part, like in KOffice.
  156. */
  157. virtual void setActivePart( Part *part, TQWidget *widget = 0L );
  158. /**
  159. * Returns the active part.
  160. **/
  161. virtual Part *activePart() const;
  162. /**
  163. * Returns the active widget of the current active part (see activePart()).
  164. */
  165. virtual TQWidget *activeWidget() const;
  166. /**
  167. * Sets the selected part.
  168. *
  169. * The selected part receives selection events.
  170. *
  171. * @p widget can be used to specify which widget was responsible for the selection.
  172. * This is important if you have multiple views for a document/part, like in KOffice.
  173. */
  174. virtual void setSelectedPart( Part *part, TQWidget *widget = 0L );
  175. /**
  176. * Returns the current selected part.
  177. */
  178. virtual Part *selectedPart() const;
  179. /**
  180. * Returns the selected widget of the current selected part (see selectedPart()).
  181. */
  182. virtual TQWidget *selectedWidget() const;
  183. /**
  184. * Returns the list of parts being managed by the partmanager.
  185. */
  186. const TQPtrList<Part> *parts() const;
  187. /**
  188. * Adds the @p topLevel widget to the list of managed toplevel widgets.
  189. * Usually a PartManager only listens for events (for activation/selection)
  190. * for one toplevel widget (and its children), the one specified in the
  191. * constructor. Sometimes however (like for example when using the KDE dockwidget
  192. * library), it is necessary to extend this.
  193. */
  194. void addManagedTopLevelWidget( const TQWidget *topLevel );
  195. /**
  196. * Removes the @p topLevel widget from the list of managed toplevel widgets.
  197. * @see addManagedTopLevelWidget
  198. */
  199. void removeManagedTopLevelWidget( const TQWidget *topLevel );
  200. /**
  201. * @return the reason for the last activePartChanged signal emitted.
  202. * @see Reason
  203. * @since 3.3
  204. */
  205. int reason() const;
  206. signals:
  207. /**
  208. * Emitted when a new part has been added.
  209. * @see addPart()
  210. **/
  211. void partAdded( KParts::Part *part );
  212. /**
  213. * Emitted when a part has been removed.
  214. * @see removePart()
  215. **/
  216. void partRemoved( KParts::Part *part );
  217. /**
  218. * Emitted when the active part has changed.
  219. * @see setActivePart()
  220. **/
  221. void activePartChanged( KParts::Part *newPart );
  222. protected:
  223. /**
  224. * Changes the active instance when the active part changes.
  225. * The active instance is used by KBugReport and TDEAboutDialog.
  226. * Override if you really need to - usually you don't need to.
  227. */
  228. virtual void setActiveInstance( TDEInstance * instance );
  229. protected slots:
  230. /**
  231. * Removes a part when it is destroyed.
  232. **/
  233. void slotObjectDestroyed();
  234. /**
  235. * @internal
  236. */
  237. void slotWidgetDestroyed();
  238. /**
  239. * @internal
  240. */
  241. void slotManagedTopLevelWidgetDestroyed();
  242. private:
  243. Part * findPartFromWidget( TQWidget * widget, const TQPoint &pos );
  244. Part * findPartFromWidget( TQWidget * widget );
  245. protected:
  246. virtual void virtual_hook( int id, void* data );
  247. private:
  248. PartManagerPrivate *d;
  249. };
  250. }
  251. #endif