AcApDocWindow.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Name: AcApDocWindow
  13. // Remarks: Defines the interface of AcApDocWindow and AcApDocWindowManager.
  14. //
  15. // AcApDocWindow is an abstraction of MDI child window inside AutoCAD,
  16. // including both DWG and non-DWG windows. It should only be used by features
  17. // that uses or interacts with non-DWG window in AutoCAD.
  18. //
  19. // The API exposed in this file serves two purpose:
  20. // 1. Allow client code to iterate, monitor and performs basic actions
  21. // on all child windows in AutoCAD.
  22. //
  23. // 2. Provide the capability for client code to define their custom
  24. // non-DWG window and show in AutoCAD.
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #include "adesk.h"
  29. #include "acdocman.h"
  30. #include "AcApWindow.h"
  31. class AcApDocWindowImp;
  32. /// <summary>Defines reactor interface for <code>AcApDocWindow</code> class. </summary>
  33. class AcApDocWindowReactor
  34. {
  35. public:
  36. /// <summary>Fired when the document window finished loading its content. Typically, the document
  37. /// instance would be available for use upon this event. </summary>
  38. /// <remarks>This event is fired one time only. </remarks>
  39. ACAD_PORT virtual void documentWindowLoaded();
  40. };
  41. /// <summary>Represents a child window inside AutoCAD main frame, either a DWG window or
  42. /// a non-DWG window.</summary>
  43. class AcApDocWindow : public AcApWindow
  44. {
  45. // Properties
  46. public:
  47. /// <summary>Gets the document associated with the window. </summary>
  48. /// <returns>Returns the document instance if available. Returns nullptr if documentWindowLoaded event
  49. /// has not been fired or the window does not use any document. </returns>
  50. /// <remarks>For DWG window, the document instance is of type AcApDocument. For other windows, the
  51. /// document could be of any type derived from <code>AcRxObject</code>.</remarks>
  52. ACAD_PORT AcRxObject* document();
  53. /// <summary>Gets the title of the window. </summary>
  54. ACAD_PORT const ACHAR* title() const;
  55. /// <summary>Sets the title of the window. </summary>
  56. /// <param name="title">New title of the window. </param>
  57. /// <remarks>This only has effect before this window is added to document window manager.</remarks>
  58. ACAD_PORT void setTitle(const ACHAR* title);
  59. /// <summary>Gets the value indicating whether the document window can be closed. </summary>
  60. ACAD_PORT bool canClose() const;
  61. /// <summary>Sets the CanClose of the window. </summary>
  62. /// <param name="bCanClose">New CanClose of the window. </param>
  63. /// <remarks>This only change private value before this window is added to document window manager.
  64. /// MFC window close button and private value change after this window is added to document window manager.</remarks>
  65. ACAD_PORT void setCanClose(bool bCanClose);
  66. // Operations
  67. public:
  68. /// <summary>Closes the window. </summary>
  69. ACAD_PORT void close();
  70. /// <summary>Activates the window. </summary>
  71. ACAD_PORT void activate();
  72. /// <summary>Enables/Disables the window </summary>
  73. /// <param name="bEnable">Specify true to enable window and false to disable it.</param>
  74. ACAD_PORT void enable(bool bEnable);
  75. /// <summary>Adds a reactor instance of type <code>AcApDocWindowReactor</code> to handle events from
  76. /// this window. </summary>
  77. /// <param name="reactor">The reactor instance to be added.</param>
  78. ACAD_PORT void addReactor(AcApDocWindowReactor* reactor);
  79. /// <summary>Removes a reactor instance of type <code>AcApDocWindowReactor</code> that has been added previously. </summary>
  80. /// <param name="reactor">The reactor instance to be removed.</param>
  81. ACAD_PORT void removeReactor(AcApDocWindowReactor* reactor);
  82. protected:
  83. /// <summary>Sets the document instance associated with the window. </summary>
  84. /// <param name="document">The document instance.</param>
  85. /// <remarks>Derived type should initialize the document instance and call this function inside
  86. /// overloaded version of <code>onLoad()</code>.</remarks>
  87. ACAD_PORT virtual void setDocument(AcRxObject* document);
  88. // Events
  89. protected:
  90. /// <summary>Called when the document window is being created.</summary>
  91. /// <param name="hWnd">The native handle of the newly created window.</param>
  92. /// <remarks>Derived types should override this function to initialize the content
  93. /// of the document window.</remarks>
  94. ACAD_PORT virtual void onCreate(HWND hWnd);
  95. /// <summary>Called when the document window is loading its content. </summary>
  96. /// <remarks>Derived types should override this function if it needs to load a document, or any other content.
  97. /// If the derived type does not override this function, the documentWindowLoaded() event is fired immediately after
  98. /// the documentWindowCreated() event on AcApDocWindowManager.</remarks>
  99. ACAD_PORT virtual void onLoad();
  100. /// <summary>Called when the document window is activated.</summary>
  101. ACAD_PORT virtual void onActivate();
  102. /// <summary>Called when the document window is destroyed.</summary>
  103. ACAD_PORT virtual void onDestroy();
  104. public:
  105. /// <summary>Initializes an instance of AcApDocWindow.</summary>
  106. /// <remarks>Non-DWG windows must be added to AcApDocWnidowManager by calling addDocumentWindow()</remarks>
  107. ACAD_PORT AcApDocWindow();
  108. /// <summary>Initializes an instance of AcApDocWindow.</summary>
  109. ACAD_PORT virtual ~AcApDocWindow();
  110. // IAdHostWindow memebers
  111. public:
  112. /// <summary>Obtains the native window handle.</summary>
  113. ACAD_PORT virtual HWND windowHandle() ADESK_OVERRIDE;
  114. private:
  115. AcApDocWindow(const AcApDocWindow&);
  116. AcApDocWindow& operator=(const AcApDocWindow&);
  117. friend class AcApDocWindowImp;
  118. };
  119. /// <summary>Derived type from AcApDocWindow which represents a DWG child window.</summary>
  120. class AcApDwgDocWindow : public AcApDocWindow
  121. {
  122. public:
  123. /// <summary>Gets the <code>AcApDocument</code> document instance associated with this DWG window.</summary>
  124. ACAD_PORT AcApDocument* document();
  125. private:
  126. AcApDwgDocWindow();
  127. friend class AcApDocWindowImp;
  128. };
  129. class AcApDocWindowManagerImp;
  130. class AcApDocWindowIteratorImp;
  131. /// <summary>Iterator of document windows.</summary>
  132. class AcApDocWindowIterator
  133. {
  134. public:
  135. /// <summary>Gets a value indicating whether the iterator has reached its end.</summary>
  136. ACAD_PORT bool done() const;
  137. /// <summary>Steps to the next item.</summary>
  138. ACAD_PORT void step();
  139. /// <summary>Gets the document window instance of the current item.</summary>
  140. ACAD_PORT AcApDocWindow* current();
  141. private:
  142. AcApDocWindowIterator();
  143. public:
  144. ACAD_PORT ~AcApDocWindowIterator();
  145. private:
  146. AcApDocWindowIteratorImp* m_pImp;
  147. friend class AcApDocWindowManagerImp;
  148. };
  149. /// <summary>Defines reactor interface for <code>AcApDocWindowManager</code> class. </summary>
  150. class AcApDocWindowManagerReactor
  151. {
  152. public:
  153. /// <summary>Fired when a document window is created, and added to the document window collection.</summary>
  154. /// <param name="docWindow">The document window just created. </param>
  155. /// <remarks>At this stage the onCreate(HWND) function on the docWindow has finished execution, and
  156. /// view elements are already initialized. </remarks>
  157. ACAD_PORT virtual void documentWindowCreated(AcApDocWindow* docWindow);
  158. /// <summary>Fired when a document window is activated.</summary>
  159. /// <param name="docWindow">The document window being activated. </param>
  160. ACAD_PORT virtual void documentWindowActivated(AcApDocWindow* docWindow);
  161. /// <summary>Fired when a document window is destroyed and removed from the document window collection.</summary>
  162. /// <param name="docWindow">The document window being destroyed. </param>
  163. /// <remarks>Upon this event the document window is already removed from document window manager, while
  164. /// <code>onDestroy()</code> logic has not been executed yet.</remarks>
  165. ACAD_PORT virtual void documentWindowDestroyed(AcApDocWindow* docWindow);
  166. /// <summary>Fired when a document window is moved.</summary>
  167. /// <param name="docWindow">The document window instance being moved. </param>
  168. /// <param name="newIndex">The new index of the document window in the list of windows. </param>
  169. /// <param name="oldIndex">The old index of the document window before it was moved. </param>
  170. ACAD_PORT virtual void documentWindowMoved(AcApDocWindow* docWindow, int newIndex, int oldIndex);
  171. /// <summary>Fired when an old document window is replaced by a new document window. </summary>
  172. /// <param name="newDocWindow">The new document window that is going to replace the old instance.</param>
  173. /// <param name="oldDocWindow">The old document window being replaced. </param>
  174. /// <remarks>Notifications documentWindowCreated/documentWindowDestroyed are not fired for either
  175. /// of these two windows.</remarks>
  176. ACAD_PORT virtual void documentWindowReplaced(AcApDocWindow* newDocWindow, AcApDocWindow* oldDocWindow);
  177. };
  178. class AcApDocWindowManagerImp;
  179. /// <summary>The manager for all child windows inside AutoCAD main frame.</summary>
  180. class AcApDocWindowManager
  181. {
  182. public:
  183. /// <summary>Gets the current active document window.</summary>
  184. /// <returns>Returns the active document window, or nullptr if no window is active.</returns>
  185. ACAD_PORT AcApDocWindow* activeDocumentWindow();
  186. /// <summary>Gets the total number of document windows.</summary>
  187. ACAD_PORT int documentWindowCount() const;
  188. /// <summary>Adds a custom non-DWG window as a child window in AutoCAD main frame.</summary>
  189. /// <param name="docWindow">The document window to be added. </param>
  190. /// <returns>Returns true if the document window is added successfully. </returns>
  191. /// <remarks>If the docWindow is added successfully, subsequent call to docWindow->windowHandle() would
  192. /// return valid handle. The docWindow instance will be deleted automatically after the window
  193. /// is closed.</remarks>
  194. ACAD_PORT bool addDocumentWindow(AcApDocWindow* docWindow);
  195. /// <summary>Moves a document window to the new index.</summary>
  196. /// <param name="docWindow">The document window to be moved. </param>
  197. /// <param name="newIndex">The new index of the document window .</param>
  198. /// <returns>Returns true if the document window is moved successfully. </returns>
  199. ACAD_PORT bool moveDocumentWindow(AcApDocWindow* docWindow, int newIndex);
  200. /// <summary>Creates a new iterator instance. The client calling this function is responsible
  201. /// for deleting the instance.</summary>
  202. /// <returns>Returns a new iterator of document windows. The iterator must be deleted by the caller
  203. /// after use. </returns>
  204. ACAD_PORT AcApDocWindowIterator* newIterator() const;
  205. /// <summary>Adds a reactor instance of type <code>AcApDocWindowManagerReactor</code> to handle changes
  206. /// of document window collection.</summary>
  207. ACAD_PORT void addReactor(AcApDocWindowManagerReactor* pReactor);
  208. /// <summary>Removes a reactor instance of type <code>AcApDocWindowManagerReactor</code> that was previously
  209. /// added.</summary>
  210. ACAD_PORT void removeReactor(AcApDocWindowManagerReactor* pReactor);
  211. private:
  212. AcApDocWindowManager();
  213. ~AcApDocWindowManager();
  214. AcApDocWindowManagerImp* m_pImp;
  215. friend class AcApDocWindowManagerImp;
  216. };
  217. /// <summary>Gets the singleton instance of <code>AcApDocWindowManager</code>. </summary>
  218. ACAD_PORT AcApDocWindowManager* acDocWindowManagerPtr();
  219. #define acDocWindowManager acDocWindowManagerPtr()