-
Notifications
You must be signed in to change notification settings - Fork 0
/
XHtmlCheckBox.cs
331 lines (268 loc) · 10.7 KB
/
XHtmlCheckBox.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
//___________________________________________________________________________
// Projet : XHtml
// Nom : XHtmlCheckBox.xaml.cs
// Description : Objet Case à cocher
//___________________________________________________________________________
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Divalto.Systeme.DVOutilsSysteme;
using Divalto.Systeme;
using Divalto.Systeme.XHtml;
using System.Text;
namespace Divaltohtml
{
public class CaseACocherVersJson
{
public bool texteAGauche; // c'est les memes noms que dans le widget !!
public bool notification;
}
/// <summary>
/// Classe XHtmlCheckBox = Une case à cocher
/// </summary>
public partial class XHtmlCheckBox : 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,
Key.Tab,
//Key.Space, // ne pas traiter : wpf gère le cochage/décochage
Key.Insert,
Key.Next,
Key.Prior,
Key.PageDown,
Key.PageUp,
Key.Down,
Key.Up
};
internal static List<Key> ValidModifiedKeys = new List<Key> // Touches combinées avec CTRL
{
Key.A,
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 IsReadOnlyProperty = TextBoxBase.IsReadOnlyProperty.AddOwner(typeof(CheckBox));
public bool? IsReadOnly;
//{
// get { return (bool)GetValue(IsReadOnlyProperty); }
// set { SetValue(IsReadOnlyProperty, value); }
//}
private int codePage;
public bool? TexteAGauche;
public bool NotificationSiModif;
public string Libelle;
public bool? IsChecked;
#region Constructeur
/// <summary>
/// Initializes a new instance of the XHtmlCheckBox class.
/// </summary>
public XHtmlCheckBox(XHtmlPage page)
{
// InitializeComponent();
Page = page;
// PreviewKeyDown += PreviewKeyDownHandler;
// PreviewMouseDown += PreviewMouseDownHandler;
}
#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.CASE_A_COCHER_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.CODE_PAGE: // Code page
buffer.Get(out codePage);
break;
case ProprietesWpf.PARAM_SAISIE_SEQUENCE: // Point de séquence (ushort)
ushort seqPoint;
buffer.Get(out seqPoint);
SeqPoint = seqPoint;
break;
case ProprietesWpf.CASE_A_COCHER_CADRAGE_TEXTE: // Position du texte par rapport à la case (byte)
byte cadrage;
buffer.Get(out cadrage);
TexteAGauche = cadrage == 1;
break;
case ProprietesWpf.OBJET_NOTIFIER_SI_MODIF: // Envoyé si la notification est demandée ==> il faudra "réveiller" Ymeg si l'utilisateur clique sur la case
//Checked += ValueChangedHandler; // traitement de la notification
//Unchecked += ValueChangedHandler; // traitement de la notification
NotificationSiModif = true;
break;
case ProprietesWpf.CASE_A_COCHER_LIBELLE: // Libellé de la case (string)
string content;
buffer.GetStringCP(out content, codePage);
Libelle = content;
break;
case ProprietesWpf.OBJET_EN_AFFICHAGE: // (Uniquement si la case est en affichage seulement)
IsReadOnly = true;
break;
case ProprietesWpf.CASE_A_COCHER_ETAT: // Etat de la case (byte : 0=non cochée ; 1=cochée)
ushort etat;
buffer.Get(out etat);
IsChecked = (etat == 1);
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.CheckBox, property.ToString());
}
buffer.Get(out property);
}
}
#endregion Lecture propriétés
//#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;
// }
// 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) && ValidModifiedKeys.Contains(e.Key)))
// key = e.Key.ToString();
// else if (e.Key != Key.Left && e.Key != Key.Right) return; // les touches restantes ne sont pas bloquées, excepté flèches droite et gauche
// }
// e.Handled = true;
// application.SendInputKeyDown(key);
//}
/// <summary>
/// Gestionnaire d'évènement "PreviewMouseDown"
/// </summary>
//private void PreviewMouseDownHandler(object sender, MouseButtonEventArgs e)
//{
// if (IsReadOnly) // refusé si IsReadOnly
// {
// 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>
/// Gestionnaire d'évènement "Checked ou Unchecked" pour la notification
/// </summary>
//private void ValueChangedHandler(object sender, RoutedEventArgs e)
//{
// var application = ((App)Application.Current).Appli;
// // on ne notifie pas si la case n'est pas le contrôle actif en input
// if (!(application.AttenteInput && Page.Window.ActiveControl == this)) return;
// var response = new DVBuffer();
// response.Put(ProprietesWpf.CLIENTLEGER_DEBUT); //début de l'acquittement ou de la réponse
// 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)
// response.Put((byte)MouseEvent.Notification);
// response.Put(ProprietesWpf.PAGE_NUMERO); // Numéro de la page contenant la donnée cliquée (byte)
// response.Put(Page.NumPage);
// response.Put(ProprietesWpf.IDENT_UNIQUE); // Id de la donnée cliquée (uint)
// response.Put(Id);
// response.Put(ProprietesWpf.PARAM_SAISIE_SEQUENCE); // Numéro du point de séquence de la donnée cliquée (ushort)
// response.Put(SeqPoint);
// response.Put(ProprietesWpf.EVENEMENT_SOURIS_FIN); // Fin de l'envoi des évenements souris
// response.Put(ProprietesWpf.CASE_A_COCHER_ETAT); // Nouvelle valeur (ushort)
// response.Put((IsChecked.HasValue && IsChecked.Value) ? (ushort)1 : (ushort)0);
// application.Send(response);
//}
//#endregion Ecouteurs
/// 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();
ListeParametresEnvoyes paramsCreation = new ListeParametresEnvoyes();
CaseACocherVersJson cc = new CaseACocherVersJson();
paramsValeurs.Ajouter("idObjet", HtmlGlobal.CalculerId(this.Id, page.Id, niveau), this.Page.Html.CalculerIdPage(page.Id));
if (this.IsChecked.HasValue)
paramsValeurs.Ajouter("caseChecked", (bool)this.IsChecked ? "true" : "false");
if (this.TexteAGauche.HasValue)
cc.texteAGauche = (bool)this.TexteAGauche;
if (string.IsNullOrEmpty(this.Libelle) == false)
paramsValeurs.Ajouter("caseLibelle", this.Libelle);
if (NotificationSiModif)
cc.notification = true;
if (IsReadOnly.HasValue)
paramsValeurs.Ajouter("lectureSeule", (bool)IsReadOnly ? "true" : "false");
if (Presentation != null)
this.Presentation.GenererHtml(paramsValeurs, this.Page.Html,0,false);
paramsValeurs.Ajouter("pointSequence", this.SeqPoint.ToString(), page.NumPage.ToString());
string parametresJson = HtmlGlobal.ToJsonString(cc, this.Page.Html.JsonParametresCaseACocher, false);
paramsCreation.Ajouter("paramsCreation", parametresJson);
//UnParametreEnvoye p = new UnParametreEnvoye();
envois.Ajouter("creerCaseACocher", HtmlGlobal.ToJsonString(paramsCreation, this.Page.Html.JsonParamsEnvoyes, false), HtmlGlobal.CalculerId(this.Id, page.Id, niveau));
// envois.Ajouter("ajoutObjetCourant", "");
envois.Ajouter("propsObjet", HtmlGlobal.ToJsonString(paramsValeurs, this.Page.Html.JsonParamsEnvoyes, false));
}
}
}