PageRenderTime 25ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/dumbhippo/branches/cluster/client/windows/HippoUI/HippoAbstractWindow.h

https://gitlab.com/manoj-makkuboy/magnetism
C Header | 254 lines | 80 code | 40 blank | 134 comment | 0 complexity | 04d950f7bf5a0ecd44757c6cc07252c8 MD5 | raw file
  1. /* HippoAbstractWindow.h: Base class for toplevel windows that embed a web browser control
  2. *
  3. * Copyright Red Hat, Inc. 2005
  4. **/
  5. #pragma once
  6. #include <HippoIE.h>
  7. #include <HippoMessageHook.h>
  8. class HippoUI;
  9. class HippoAbstractWindow : public HippoMessageHook
  10. {
  11. public:
  12. HippoAbstractWindow();
  13. virtual ~HippoAbstractWindow();
  14. /**
  15. * Provide a pointer to the main UI object for the application. Mandatory to call
  16. * before create().
  17. * @param ui the main UI object
  18. */
  19. void setUI(HippoUI *ui);
  20. /**
  21. * Provide an (optional) object that will be available as window.external.application
  22. * Must be called before create() if called at all.
  23. * @param application pointer to the COM object to make available to javascript
  24. */
  25. void setApplication(IDispatch *application);
  26. /**
  27. * Set the title of the window. Note that this currently is always used, and any title
  28. * set by the page that is loaded is ignored. Must be called before create() to have
  29. * any effect.
  30. * @param title the title to set
  31. */
  32. void setTitle(const HippoBSTR &title);
  33. /**
  34. * Actually go ahead and create the window and embed IE in it. This must be called
  35. * before any methods that manipulate the embedded IE or window.
  36. *
  37. * FIXME: We possibly should do this behind the scenes
  38. */
  39. bool create();
  40. /**
  41. * Destroy the window and shutdown the underlying Internet Explorer instance
  42. */
  43. void destroy();
  44. /**
  45. * Make the window visible onscreen.
  46. */
  47. void show(BOOL activate = true);
  48. /**
  49. * Hide the window
  50. */
  51. void hide();
  52. /**
  53. * Set the window as the "foreground window". This will either bring the window to
  54. * the front, or flash it in the user's task list if Windows doesn't want to
  55. * steal focus from the user.
  56. */
  57. void setForegroundWindow();
  58. /**
  59. * Move and resize the window to the given size and position
  60. * @param x X position. CW_DEAULT means center horizontally
  61. * @param y Y position. CW_DEAULT means center vertically
  62. * @param width the new width, including window decorations
  63. * @param height the new height, including window decorations
  64. */
  65. void moveResize(int x, int y, int width, int height);
  66. /**
  67. * Get the HippoIE object that wraps the embedded web browser control
  68. * @return the HippoIE object
  69. */
  70. HippoIE *getIE();
  71. ////////////////////////////////////////////////////////////
  72. bool hookMessage(MSG *msg);
  73. protected:
  74. /**
  75. * Whether to set the parent window of the window to ui_->window.
  76. * This is needed for transient popups, but causes problems for
  77. * more "windowy" windows. (Defaults to false
  78. * @param useParent true if we should set the parent window.
  79. **/
  80. void setUseParent(bool useParent);
  81. /**
  82. * Set whether showing and hiding of the window will be done with fade-in
  83. * and fade-out
  84. * @param animate true if animation should be done
  85. */
  86. void setAnimate(bool animate);
  87. /**
  88. * Set whether to force an update after showing the window. This is a
  89. * bug workaround for undiagnosed problems where HippoBubble can end up
  90. * shown without the embedded IE being redrawn.
  91. * @param updateOnShow true if we should force an update after showing the window.
  92. */
  93. void setUpdateOnShow(bool updateOnShow);
  94. /**
  95. * Set the class style passed to RegisterClassEx. The default value is
  96. * CS_HREDRAW | CS_VREDRAE.
  97. * @param classStyle the new class style
  98. **/
  99. void setClassStyle(UINT classStyle);
  100. /**
  101. * Set the window style flags that will be passed to CreateWindow()
  102. * @param windowStyle the window style flags. (See CreateWindow() docs)
  103. */
  104. void setWindowStyle(DWORD windowStyle);
  105. /**
  106. * Set the extended window style flags that will be passed to CreateWindowEx()
  107. * @param extendedStyle the extended window style flags. (See CreateWindowEx() docs)
  108. */
  109. void setExtendedStyle(DWORD extendedStyle);
  110. /**
  111. * Set the class name that will be used when registering the class for
  112. * this type of window. Mandatory to call before create().
  113. * @param className the class name string
  114. */
  115. void setClassName(const HippoBSTR &className);
  116. /**
  117. * Set the URL that will be loaded into the window. Mandatory to
  118. * call before create().
  119. @param URL the URL to load
  120. */
  121. void setURL(const HippoBSTR &url);
  122. /********************************************************/
  123. /**
  124. * Get the URL that will be passed to the HippoIE object. The default
  125. * implementation just returns the result of setURL(), but this
  126. * is virtual so that it can be determined dynamically, depending
  127. * on, for example, the HippoUI object passed to setUI().
  128. **/
  129. virtual HippoBSTR getURL();
  130. /**
  131. * Do any necessary post-creation initialization of our window
  132. **/
  133. virtual void initializeWindow();
  134. /**
  135. * Do any initializion of the HippoIE needed before calling ie_->create(),
  136. * for example, call ie_->setXsltTransform()
  137. **/
  138. virtual void initializeIE();
  139. /**
  140. * Do any necessary initialization of the browser control
  141. * post-creation.
  142. **/
  143. virtual void initializeBrowser();
  144. /**
  145. * Do any initialization after the UI is set
  146. */
  147. virtual void initializeUI();
  148. /**
  149. * Called on incoming messages sent to the window. If you
  150. * don't handle the event yourself, you should chain up to
  151. * to the parent class's implementation.
  152. * @param message the message type
  153. * @wParam WPARAM from the window procedure
  154. * @lParam LPARAM from the window procedure
  155. * @return true if the event was handled, otherwise false (default
  156. * handle will be done)
  157. */
  158. virtual bool processMessage(UINT message,
  159. WPARAM wParam,
  160. LPARAM lParam);
  161. /**
  162. * Callback when the document finishes loading
  163. **/
  164. virtual void onDocumentComplete();
  165. /**
  166. * Callback when the window is closed either by the user
  167. * or by a script. There is no default implementation, so
  168. * close attempts will have no effect other than anything
  169. * you do here.
  170. * @param fromScript true if a script invoked as window.close()
  171. **/
  172. virtual void onClose(bool fromScript);
  173. HippoIE *ie_;
  174. HippoPtr<IWebBrowser2> browser_;
  175. HippoUI* ui_;
  176. HWND window_;
  177. DWORD windowStyle_;
  178. DWORD extendedStyle_;
  179. private:
  180. bool useParent_;
  181. bool animate_;
  182. bool updateOnShow_;
  183. UINT classStyle_;
  184. HippoBSTR className_;
  185. HippoBSTR url_;
  186. HippoBSTR title_;
  187. HINSTANCE instance_;
  188. HippoPtr<IDispatch> application_;
  189. class HippoAbstractWindowIECallback : public HippoIECallback
  190. {
  191. public:
  192. HippoAbstractWindowIECallback(HippoAbstractWindow *chatWindow) {
  193. abstractWindow_ = chatWindow;
  194. }
  195. HippoAbstractWindow *abstractWindow_;
  196. void onDocumentComplete();
  197. void onClose();
  198. void launchBrowser(const HippoBSTR &url);
  199. bool isOurServer(const HippoBSTR &host);
  200. HRESULT getToplevelBrowser(const IID &ifaceID, void **toplevelBrowser);
  201. };
  202. HippoAbstractWindowIECallback *ieCallback_;
  203. bool embedIE(void);
  204. bool createWindow(void);
  205. bool registerClass();
  206. void onWindowDestroyed();
  207. static LRESULT CALLBACK windowProc(HWND window,
  208. UINT message,
  209. WPARAM wParam,
  210. LPARAM lParam);
  211. // private so they aren't used
  212. HippoAbstractWindow(const HippoAbstractWindow &other);
  213. HippoAbstractWindow& operator=(const HippoAbstractWindow &other);
  214. };