PCL
WebView.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/WebView.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_WebView_h
53 #define __PCL_WebView_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/Color.h>
63 #include <pcl/Control.h>
64 #include <pcl/Variant.h>
65 
66 #endif // !__PCL_BUILDING_PIXINSIGHT_APPLICATION
67 
68 namespace pcl
69 {
70 
71 // ----------------------------------------------------------------------------
72 
73 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
74 
75 // ----------------------------------------------------------------------------
76 
92 class PCL_CLASS WebView : public Control
93 {
94 public:
95 
102  WebView( Control& parent = Control::Null() );
103 
107  ~WebView() override
108  {
109  }
110 
140  void SetContent( const ByteArray& data, const IsoString& mimeType = IsoString() );
141 
147  void SetHTML( const IsoString& html );
148 
154  void SetHTML( const String& html );
155 
161  void SetPlainText( const IsoString& text );
162 
168  void SetPlainText( const String& text );
169 
182  void LoadContent( const String& uri );
183 
192  void RequestPlainText() const;
193 
202  void RequestHTML() const;
203 
233  void SaveAsPDF( const String& filePath, double pageWidth = 210, double pageHeight = 297,
234  double marginLeft = 10, double marginTop = 10, double marginRight = 10, double marginBottom = 10,
235  bool landscape = false );
236 
240  bool HasSelection() const;
241 
247 
252  double ZoomFactor() const;
253 
258  void SetZoomFactor( double zoom );
259 
265 
270  void SetBackgroundColor( RGBA color );
271 
276  void Reload();
277 
282  void Stop();
283 
330  void EvaluateScript( const String& sourceCode, const IsoString& language = IsoString() );
331 
347  using view_event_handler = void (Control::*)( WebView& sender );
348 
362  using progress_event_handler = void (Control::*)( WebView& sender, int loadPercent );
363 
376  using state_event_handler = void (Control::*)( WebView& sender, bool state );
377 
391  using content_event_handler = void (Control::*)( WebView& sender, const String& content );
392 
408  using result_event_handler = void (Control::*)( WebView& sender, const Variant& result );
409 
423  void OnLoadStarted( view_event_handler handler, Control& receiver );
424 
439  void OnLoadProgress( progress_event_handler handler, Control& receiver );
440 
456  void OnLoadFinished( state_event_handler handler, Control& receiver );
457 
472  void OnSelectionUpdated( view_event_handler handler, Control& receiver );
473 
489 
504  void OnHTMLAvailable( content_event_handler handler, Control& receiver );
505 
521 
522 private:
523 
524  struct EventHandlers
525  {
526  view_event_handler onLoadStarted = nullptr;
527  progress_event_handler onLoadProgress = nullptr;
528  state_event_handler onLoadFinished = nullptr;
529  view_event_handler onSelectionUpdated = nullptr;
530  content_event_handler onPlainTextAvailable = nullptr;
531  content_event_handler onHTMLAvailable = nullptr;
532  result_event_handler onScriptResultAvailable = nullptr;
533 
534  EventHandlers() = default;
535  EventHandlers( const EventHandlers& ) = default;
536  EventHandlers& operator =( const EventHandlers& ) = default;
537  };
538 
539  AutoPointer<EventHandlers> m_handlers;
540 
541  friend class WebViewEventDispatcher;
542 };
543 
544 // ----------------------------------------------------------------------------
545 
546 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
547 
548 } // pcl
549 
550 #endif // __PCL_WebView_h
551 
552 // ----------------------------------------------------------------------------
553 // EOF pcl/WebView.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
Unicode (UTF-16) string.
Definition: String.h:8113
Acts like a union to store instances of different data types.
Definition: Variant.h:332
Client-side interface to a PixInsight WebView control.
Definition: WebView.h:93
RGBA BackgroundColor() const
void RequestPlainText() const
void LoadContent(const String &uri)
void SaveAsPDF(const String &filePath, double pageWidth=210, double pageHeight=297, double marginLeft=10, double marginTop=10, double marginRight=10, double marginBottom=10, bool landscape=false)
void SetZoomFactor(double zoom)
bool HasSelection() const
double ZoomFactor() const
void SetHTML(const String &html)
void SetPlainText(const IsoString &text)
String SelectedText() const
void SetHTML(const IsoString &html)
void EvaluateScript(const String &sourceCode, const IsoString &language=IsoString())
WebView(Control &parent=Control::Null())
void SetPlainText(const String &text)
void RequestHTML() const
void SetBackgroundColor(RGBA color)
void SetContent(const ByteArray &data, const IsoString &mimeType=IsoString())
~WebView() override
Definition: WebView.h:107
uint32 RGBA
Definition: Color.h:92
void OnLoadStarted(view_event_handler handler, Control &receiver)
void OnScriptResultAvailable(result_event_handler handler, Control &receiver)
void(Control::*)(WebView &sender, bool state) state_event_handler
Definition: WebView.h:376
void OnPlainTextAvailable(content_event_handler handler, Control &receiver)
void OnHTMLAvailable(content_event_handler handler, Control &receiver)
void OnLoadProgress(progress_event_handler handler, Control &receiver)
void(Control::*)(WebView &sender) view_event_handler
Definition: WebView.h:347
void(Control::*)(WebView &sender, const String &content) content_event_handler
Definition: WebView.h:391
void OnLoadFinished(state_event_handler handler, Control &receiver)
void OnSelectionUpdated(view_event_handler handler, Control &receiver)
void(Control::*)(WebView &sender, const Variant &result) result_event_handler
Definition: WebView.h:408
void(Control::*)(WebView &sender, int loadPercent) progress_event_handler
Definition: WebView.h:362
PCL root namespace.
Definition: AbstractImage.h:77