CKEditorHMTL.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using sage.ew.functions;
10 using System.IO;
11 using System.Text.RegularExpressions;
12 using System.Globalization;
13 
14 namespace sage.ew.objetos
15 {
19  public partial class CKEditorHMTL : sage.ew.objetos.WebView
20  {
21  #region Propiedades privadas
22  private string _cHtmlTexto = string.Empty;
23  private bool _lReadOnly = false;
24  private bool _lLoading = true;
25  private bool? _lNavigatingComplete = null;
26 
31  private string Html()
32  {
33  StringBuilder loSql = new StringBuilder();
34 
35  loSql.Append($@"<!DOCTYPE html>
36  <html>
37  <head>
38  <style>
39  {_Styles}
40  </style>
41  </head>
42  <body>
43  <div class='ck-content'>
44  {_cHtmlTexto}
45  </div>
46  </body>
47  </html>");
48 
49  return loSql.ToString();
50  }
51  #endregion Propiedades privadas
52 
53  #region Propiedades públicas
54  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
60  public string _HtmlTexto
61  {
62  get
63  {
64  RefreshHtml(); //Bug 203665
65  return _cHtmlTexto;
66  }
67  set
68  {
69  _cHtmlTexto = value;
70 
71  NavigateCKEditor();
72  }
73  }
74 
78  [DefaultValue(false)]
79  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
80  public bool _ReadOnly
81  {
82  get
83  {
84  return _lReadOnly;
85  }
86  set
87  {
88  _lReadOnly = value;
89 
90  _ReadOnlyEditor(_lReadOnly);
91  }
92  }
93 
98  [DefaultValue(false)]
99  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
100  public bool _Loading
101  {
102  get
103  {
104  return _lLoading;
105  }
106  set
107  {
108  if (!value)
109  FUNCTIONS._RemoveWorkingImage(this);
110 
111  _lLoading = value;
112  }
113  }
114 
118  public string _Styles
119  {
120  get
121  {
122  return FUNCTIONS._GetStylesCKEditor();
123  }
124  }
125 
131  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
132  public string _Html
133  {
134  get
135  {
136  RefreshHtml(); //Bug 203665
137  return Html();
138  }
139  }
140  #endregion Propiedades públicas
141 
142  #region Constructor
143  public CKEditorHMTL()
147  {
148  InitializeComponent();
149 
150  if (Convert.ToBoolean(sage.ew.global.EW_GLOBAL._GetVariable("wl_designmode", true)) == false)
151  {
152  _AutoRefreshDocument = true; // Realizamos el Autorefresh del Document
153  _ResponseReceived = true; // Para que actualice automáticamente el Document al modificar el HTML
154  SuscripcionEventos();
155  }
156  }
157  #endregion Constructor
158 
159  #region Métodos privados
160  private void NavigateCKEditor()
166  {
167  string lcHtmlTexto = _cHtmlTexto.Replace(Environment.NewLine, "").Replace("'", "&apos;");
168 
169  _lNavigatingComplete = false;
170 
171  NavigateToEditor(FUNCTIONS._URLCKEditor(), lcHtmlTexto);
172  }
173 
177  private void SuscripcionEventos()
178  {
179  _EndGetHTML += CKEditorHMTL__EndGetHTML;
180  _KeyPress += CKEditorHMTL__KeyPress;
181  _MouseDown += CKEditorHMTL__MouseDown;
182  _MouseUp += CKEditorHMTL__MouseUp;
183  _MouseLeave += CKEditorHMTL__MouseLeave;
184  _NavigationCompleted += CKEditorHMTL__NavigationCompleted;
185  VisibleChanged += CKEditorHMTL_VisibleChanged;
186  }
187 
193  private void CKEditorHMTL_VisibleChanged(object sender, EventArgs e)
194  {
195  if (Visible && !IsDisposed && !Disposing && _lNavigatingComplete == null) // Solo es necesario presentar la imagen una vez
196  FUNCTIONS._SetWorkingImage(this, images.Properties.Resources.offline_process);
197  }
198 
206  private void CKEditorHMTL__NavigationCompleted(string tcUrl, bool tlIsSuccess)
207  {
208  FUNCTIONS._RemoveWorkingImage(this);
209 
210  _lNavigatingComplete = true;
211  }
212 
216  private void CancelarSuscripcionEventos()
217  {
218  _EndGetHTML -= CKEditorHMTL__EndGetHTML;
219  _KeyPress -= CKEditorHMTL__KeyPress;
220  _MouseDown -= CKEditorHMTL__MouseDown;
221  _MouseUp -= CKEditorHMTL__MouseUp;
222  _MouseLeave -= CKEditorHMTL__MouseLeave;
223  _NavigationCompleted -= CKEditorHMTL__NavigationCompleted;
224  VisibleChanged -= CKEditorHMTL_VisibleChanged;
225  }
226 
230  private void GetHtml()
231  {
232  if (!_lReadOnly)
233  _GetHtml();
234  }
235 
241  private void CKEditorHMTL_Leave(object sender, EventArgs e)
242  {
243  GetHtml();
244  }
245 
251  private void CKEditorHMTL__MouseDown(string tcTipo, string tcValue)
252  {
253  GetHtml();
254  }
255 
262  private void CKEditorHMTL__MouseUp(string tcTipo, string tcValue, string tcId)
263  {
264  if (!_lReadOnly && tcTipo == "HTML")
265  _Focus();
266 
267  GetHtml();
268  }
269 
273  private void CKEditorHMTL__MouseLeave()
274  {
275  GetHtml();
276  }
277 
282  private void CKEditorHMTL__KeyPress(KeyPressEventArgs e)
283  {
284  GetHtml();
285  }
286 
291  private void CKEditorHMTL__EndGetHTML(string tcHtml)
292  {
293 
294  _cHtmlTexto = Regex.Unescape(tcHtml);
295 
296  if (_cHtmlTexto.StartsWith("\"") && _cHtmlTexto.Length >= 2) // Eliminamos las comillas del principio y del final
297  _cHtmlTexto = _cHtmlTexto.Substring(1, _cHtmlTexto.Length - 2);
298  }
299 
305  private string ConvertUnicodeToASCII(string value)
306  {
307  return Regex.Replace(
308  value,
309  @"\\u(?<Value>[a-zA-Z0-9]{4})",
310  m => {
311  return ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString();
312  });
313  }
314 
318  private void RefreshHtml()
319  {
320  GetHtml();
321  System.Threading.Thread.Sleep(300);
322  Application.DoEvents();
323  }
324 
325  #endregion Métodos privados
326 
327  #region Métodos públicos
328  public void _Focus()
334  {
335  Focus();
336  _FocusEditor();
337  }
338 
343  public void _PutData(string tcData)
344  {
345  _PutDataEditor(tcData);
346  GetHtml();
347  }
348  #endregion Métodos públicos
349  }
350 }
void _PutData(string tcData)
Añade un texto en una posición actual del curso dentro del CkEditor
Clase EW_GLOBAL para gestionar las variables públicas de Eurowin, variables de empresa, variables de anchuras de campo, variables de mascaras, etc.
Definition: EW_GLOBAL.cs:46
Control de usuario WebView que reemplaza al WebBrowser
Definition: WebView.cs:20
Control de usuario CHKEditor
Definition: CKEditorHMTL.cs:19