-
Notifications
You must be signed in to change notification settings - Fork 0
/
XHtmlTextBox.cs
482 lines (400 loc) · 15.5 KB
/
XHtmlTextBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
//___________________________________________________________________________
// Projet : XHtml
// Nom : XHtmlTextBox.xaml.cs
// Description : Objet Champ
//___________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
//using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Input;
//using System.Windows.Media;
using Divalto.Systeme.DVOutilsSysteme;
using System.Windows.Input;
using System.Drawing;
using Divalto.Systeme;
using Divalto.Systeme.XHtml;
using System.Windows;
using System.Text;
namespace Divaltohtml
{
/// <summary>
/// Classe XHtmlTextBox = Un champ
/// </summary>
public partial class XHtmlTextBox : FrameworkElement, IXHtmlEditableObject
{
#region Liste des touches valides en input
internal static List<Key> ValidKeys = new List<Key> // touches seules
{
Key.Return,
Key.Enter,
Key.Escape,
//Key.Back, // ne pas traiter : utilisé dans le texte
Key.Tab,
//Key.Space, // ne pas traiter : utilisé dans le texte
//Key.Insert, // ne pas traiter : utilisé dans le texte
//Key.Next, // ne pas traiter : utilisé dans le texte
//Key.Prior, // ne pas traiter : utilisé dans le texte
//Key.PageDown, // ne pas traiter : utilisé dans le texte
//Key.PageUp, // ne pas traiter : utilisé dans le texte
Key.Down, //TODISCUSS pas standard (= tab)
Key.Up //TODISCUSS pas standard (= tab arrière)
};
internal static List<Key> ValidModifiedKeys = new List<Key> // touches combinées à CTRL
{
//Key.A, //TODISCUSS ne devrait pas être traitée : selectionne tout le texte
Key.B,
//Key.C, // jamais traité par xrtdiva
Key.D,
Key.E,
Key.F,
//Key.G, // jamais traité par xrtdiva
//Key.H, // jamais traité par xrtdiva
//Key.I, // jamais traité par xrtdiva
//Key.J, // jamais traité par xrtdiva
//Key.K, // jamais traité par xrtdiva
//Key.L, // jamais traité par xrtdiva
//Key.M, // jamais traité par xrtdiva
Key.N,
Key.O,
Key.P,
Key.Q,
Key.R,
Key.S,
Key.T,
Key.U,
//Key.V, // jamais traité par xrtdiva
Key.W,
//Key.X, // jamais traité par xrtdiva
Key.Y,
//Key.Z // jamais traité par xrtdiva
};
#endregion Liste des touches valides en input
public uint Id { get; set; }
public ushort SeqPoint { get; set; }
public FrameworkElement FrameworkElement { get { return this; } }
public XHtmlPresentation Presentation { get; set; }
public Collection<string> ListOfValidButtons { get; private set; }
public XHtmlPage Page { get; set; }
//public static readonly DependencyProperty IsMandatoryProperty = DependencyProperty.Register("IsMandatory", typeof(bool), typeof(XHtmlTextBox));
//public bool IsMandatory
//{
// get { return (bool)GetValue(IsMandatoryProperty); }
// set { SetValue(IsMandatoryProperty, value); }
//}
public bool IsZoomCaller;
//public static readonly DependencyProperty IsZoomCallerProperty = DependencyProperty.Register("IsZoomCaller", typeof(bool), typeof(XHtmlTextBox));
//public bool IsZoomCaller
//{
// get { return (bool)GetValue(IsZoomCallerProperty); }
// set { SetValue(IsZoomCallerProperty, value); }
//}
internal int CodePage;
private bool isNumerical, isDragging;
private ushort angle;
private string _text;
private string Text
{
get
{
return _text;
}
set
{
_text = value;
textHasValue = true;
}
}
private bool textHasValue = false;
// private Point startPoint;
private bool? IsReadOnly;
public bool IsMandatory;
// public string Text;
public int MaxLengthProperty;
public TextAlignment TextAlignment;
#region Constructeur
/// <summary>
/// Initializes a new instance of the XHtmlTextBox class.
/// </summary>
public XHtmlTextBox(XHtmlPage page)
{
// InitializeComponent();
Page = page;
// PreviewKeyDown += PreviewKeyDownHandler;
// PreviewMouseDown += PreviewMouseDownHandler;
//GotFocus += (sender, e) =>
//{
// TextAlignment = TextAlignment.Left;
// SelectAll();
//};
//LostFocus += (sender, e) =>
//{
// text = Text;
// Presentation.SetCadrage();
// if (isNumerical && Presentation != null && Presentation.Cadrage == Cadrage.Defaut)
// TextAlignment = TextAlignment.Right;
//};
}
#endregion Constructeur
#region Lecture propriétés
/// <summary>
/// Reads the object's properties from the buffer
/// </summary>
/// <param name="buffer">DVBuffer where the properties are read</param>
public void ReadProperties(DVBuffer buffer)
{
ProprietesWpf property;
buffer.Get(out property);
while (property != ProprietesWpf.CHAMP_FIN)
{
switch (property)
{
case ProprietesWpf.PRESENTATION_DEBUT: // Début présentation
if (Presentation == null) Presentation = new XHtmlPresentation(this);
Presentation.ReadProperties(buffer);
Presentation.SetProperties();
break;
case ProprietesWpf.PARAM_SAISIE_SEQUENCE: // Point de séquence (ushort)
ushort pointSequence;
buffer.Get(out pointSequence);
SeqPoint = pointSequence;
break;
case ProprietesWpf.PARAM_SAISIE_TABLE_ASSOCIEE: // (Uniquement si le champ peut appeler un zoom)
IsZoomCaller = true;
break;
case ProprietesWpf.PARAM_SAISIE_TABLE_ASSOCIEE_EXT: // (Uniquement si le champ peut appeler un zoom)
byte isZoomCaller;
buffer.Get(out isZoomCaller);
IsZoomCaller = (isZoomCaller != 0);
break;
case ProprietesWpf.OBJET_EN_AFFICHAGE: // (Uniquement si le champ est en affichage seulement)
IsReadOnly = true;
break;
case ProprietesWpf.CHAMP_OBLIGATOIRE: // (Uniquement si le champ est obligatoire)
byte isMandatory;
buffer.Get(out isMandatory);
IsMandatory = (isMandatory != 0);
break;
case ProprietesWpf.CHAMP_NUMERIQUE: // (Uniquement si le champ n'accepte que des valeurs numériques)
isNumerical = true;
// PreviewTextInput += (s, e) => { e.Handled = !IsValidNumericChar(e.Text); }; // Limitations aux caractères numériques + opérateurs pour la saisie
break;
case ProprietesWpf.CODE_PAGE: // Code page
buffer.Get(out CodePage);
break;
case ProprietesWpf.CHAMP_VALEUR: // Contenu du champ (string)
string wt;
buffer.GetStringCP(out wt, CodePage);
Text = wt;
break;
case ProprietesWpf.CHAMP_LONGUEUR_SAISIE: // Longueur de saisie autorisée (ushort)
ushort maxLength;
buffer.Get(out maxLength);
MaxLengthProperty = (int)maxLength;
// SetCurrentValue(MaxLengthProperty, (int)maxLength);
break;
case ProprietesWpf.TEXTE_ANGLE: // Angle au sens trigo en ° (ushort)
buffer.Get(out angle);
// HACK inversion des hauteurs et largeur si angle multiple de 90
if ((angle + 90) % 180 == 0)
{
Presentation.Left += (Width - Height) / 2;
Presentation.Top -= (Width - Height) / 2;
var horizontalPaddingTemp = Presentation.HorizontalPadding;
Presentation.HorizontalPadding = Presentation.VerticalPadding;
Presentation.VerticalPadding = horizontalPaddingTemp;
var widthTemp = Presentation.OriginalWidth;
Presentation.OriginalWidth = Presentation.OriginalHeight;
Presentation.OriginalHeight = widthTemp;
Presentation.SetProperties();
}
// RenderTransform = new RotateTransform(-angle, Width / 2, Height / 2);
break;
case ProprietesWpf.BOUTONS_VALIDES_DEBUT: // Boutons valides dans la page en cours
ListOfValidButtons = new Collection<string>();
buffer.Get(out property);
while (property != ProprietesWpf.BOUTONS_VALIDES_FIN)
{
string buttonName;
buffer.GetString(out buttonName);
ListOfValidButtons.Add(buttonName);
buffer.Get(out property);
}
break;
default:
throw new XHtmlException(XHtmlErrorCodes.UnknownProperty, XHtmlErrorLocations.TextBox, property.ToString());
}
buffer.Get(out property);
}
// numérique aligné à droite en affichage
if (isNumerical && Presentation != null && Presentation.Cadrage == Cadrage.Defaut)
TextAlignment = TextAlignment.Right;
// gestion de l'illisibilité
//if (textHasValue && Presentation != null && Presentation.Visibilite == Visibilites.Illisible)
// Text = "xxxxxxxxxxxxxx";
}
#endregion Lecture propriétés
/// <summary>
/// Checks if the given string is a valid number (0-9 , . - +)
/// </summary>
/// <param name="str">String to check</param>
/// <returns>True if the string is a valid number</returns>
public static bool IsValidNumericChar(string str)
{
if (string.IsNullOrEmpty(str)) return true; // garde-fou
if (str == NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator |
str == NumberFormatInfo.CurrentInfo.CurrencyGroupSeparator |
str == NumberFormatInfo.CurrentInfo.CurrencySymbol |
str == NumberFormatInfo.CurrentInfo.NegativeSign |
str == NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol |
str == NumberFormatInfo.CurrentInfo.NumberDecimalSeparator |
str == NumberFormatInfo.CurrentInfo.NumberGroupSeparator |
str == NumberFormatInfo.CurrentInfo.PercentDecimalSeparator |
str == NumberFormatInfo.CurrentInfo.PercentGroupSeparator |
str == NumberFormatInfo.CurrentInfo.PercentSymbol |
str == NumberFormatInfo.CurrentInfo.PerMilleSymbol |
str == NumberFormatInfo.CurrentInfo.PositiveInfinitySymbol |
str == NumberFormatInfo.CurrentInfo.PositiveSign)
return true;
bool ret = true;
int l = str.Length;
for (int i = 0; i < l; i++)
{
char ch = str[i];
ret &= (Char.IsDigit(ch) || ch == '.');
}
return ret;
}
//#region Ecouteurs
///// <summary>
///// Gestionnaire d'évènement "PreviewKeyDown" pour la fonction XMEInput
///// </summary>
//private static void PreviewKeyDownHandler(object sender, KeyEventArgs e)
//{
// var application = ((App)Application.Current).Appli;
// if (!application.AttenteInput) // cas impossible en théorie: un contrôle ne peut pas avoir le focus sans que l'on soit en Input
// {
// e.Handled = true;
// return;
// }
// if (e.Key == Key.Apps)
// {
// // TODO simuler un clic droit sur touche windows 2
// e.Handled = true;
// }
// string key;
// // Touches de fonction (Fn)
// if (e.Key == Key.System && e.SystemKey == Key.F10) key = "F10";
// else if (XHtmlApplication.FnKeys.Contains(e.Key)) key = e.Key.ToString();
// // Autres touches
// else // pas la peine de faire les tests spécifiques si une touche générique (Fn) a déjà été détetée
// {
// if (ValidKeys.Contains(e.Key) || (
// (Keyboard.Modifiers & ModifierKeys.Control) != 0
// && (Keyboard.Modifiers & ModifierKeys.Alt) == 0
// && ValidModifiedKeys.Contains(e.Key))
// )
// key = e.Key.ToString();
// else return; // les touches restantes ne sont pas bloquées
// }
// e.Handled = true;
// application.SendInputKeyDown(key);
//}
///// <summary>
///// Gestionnaire d'évènement "PreviewMouseDown"
///// </summary>
//private void PreviewMouseDownHandler(object sender, MouseButtonEventArgs e)
//{
// if (IsReadOnly) // si IsReadOnly, on ne notifie pas l'appli
// {
// e.Handled = true;
// return;
// }
// // on laisse passer les clics gauches (simples & doubles) en input (géré par wpf)
// if (Page.Window.ActiveControl == this && e.ChangedButton == MouseButton.Left) return;
// ((App)Application.Current).Appli.SendMouseDown(this, e);
//}
///// <summary>
///// Envoi des infos à l'appli pour ouverture de zoom
///// </summary>
//private void ZoomButtonClickHandler(object sender, RoutedEventArgs e)
//{
// e.Handled = true;
// var application = ((App)Application.Current).Appli;
// var response = new DVBuffer();
// response.Put(ProprietesWpf.CLIENTLEGER_DEBUT); //début de l'acquittement ou de la réponse
// application.SetInputBuffer(response);
// response.Put(ProprietesWpf.EVENEMENT_SOURIS_DEBUT); // Début de l'envoi des évenements souris
// response.Put(ProprietesWpf.SOURIS_TYPE_EVENEMENT); // Type d'évènement souris (byte)
// if (((App)Application.Current).Client.VersionInterneServeur <= 1)
// response.Put((byte)MouseEvent.ZoomCall);
// else
// response.Put((byte)(MouseEvent.ZoomComboCall));
// response.Put(ProprietesWpf.EVENEMENT_SOURIS_FIN); // Fin de l'envoi des évenements souris
// application.Send(response);
//}
//#endregion Ecouteurs
//// D & D non implémenté pour cause d'incompatibilité avec la gestion des mouseUp et MouseDown
//#region Drag & Drop
//public void PreviewMouseLeftButtonDownHandler(object sender, MouseEventArgs e)
//{
// if (e == null) throw new ArgumentNullException("e");
// startPoint = e.GetPosition(null);
//}
//public void PreviewMouseMoveHandler(object sender, MouseEventArgs e)
//{
// if (e == null) throw new ArgumentNullException("e");
// if (isDragging) return;
// if (e.LeftButton != MouseButtonState.Pressed) return;
// // on ne déclenche le drag&drop que si la souris a été suffisament déplacée
// Vector diff = startPoint - e.GetPosition(null);
// if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
// Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
// {
// isDragging = true;
// DataObject data = new DataObject(DataFormats.UnicodeText, Text);
// DragDrop.DoDragDrop(this, data, DragDropEffects.All);
// isDragging = false;
// }
//}
//#endregion Drag & Drop
/// <summary>
/// ajouter les commandes necessaires pour le client
/// </summary>
/// <param name="envois"></param>
/// <param name="page"></param>
/// <param name="niveau"></param>
public void AjouterEnvoisUnObjet(ListeParametresEnvoyes envois, XHtmlPage page, int niveau)
{
ListeParametresEnvoyes paramsValeurs = new ListeParametresEnvoyes();
paramsValeurs.Ajouter("idObjet", HtmlGlobal.CalculerId(this.Id, page.Id, niveau), this.Page.Html.CalculerIdPage(page.Id));
if (IsReadOnly.HasValue)
paramsValeurs.Ajouter("lectureSeule", (bool)IsReadOnly ? "true" : "false");
if (Presentation != null)
this.Presentation.GenererHtml(paramsValeurs, this.Page.Html,this.CodePage,false);
if (this.textHasValue) // pour le caché etc, apres la presentation
paramsValeurs.Ajouter("texteChamp", this.Text);
paramsValeurs.Ajouter("pointSequence", this.SeqPoint.ToString(), page.NumPage.ToString());
// n'est envoyé que pourle champ en cours de saisie
if (this.MaxLengthProperty != 0)
paramsValeurs.Ajouter("tailleSaisie", this.MaxLengthProperty.ToString());
if (this.ListOfValidButtons != null && this.ListOfValidButtons.Count > 0)
{
StringBuilder vb = new StringBuilder();
vb.Append("@");
foreach (string n in ListOfValidButtons)
{
vb.Append(n);
vb.Append("@");
}
paramsValeurs.Ajouter("boutonsValides", vb.ToString());
}
UnParametreEnvoye p = new UnParametreEnvoye();
envois.Ajouter("creerObjet", "<input type='text'/>", HtmlGlobal.CalculerId(this.Id, page.Id, niveau));
envois.Ajouter("propsObjet", HtmlGlobal.ToJsonString(paramsValeurs, this.Page.Html.JsonParamsEnvoyes, false));
envois.Ajouter("ajoutObjetCourant", "");
}
}
}