-
Notifications
You must be signed in to change notification settings - Fork 0
/
XHtmlTabControl.cs
375 lines (299 loc) · 12.3 KB
/
XHtmlTabControl.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
//___________________________________________________________________________
// Projet : XHtml
// Nom : XHtmlTabControl.xaml.cs
// Description : Objets Groupe d'onglets
//___________________________________________________________________________
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Divalto.Systeme;
using Divalto.Systeme.DVOutilsSysteme;
using Divalto.Systeme.XHtml;
namespace Divaltohtml
{
/// <summary>
/// Classe XHtmlTabControl = Un groupe d'onglets
/// </summary>
public partial class XHtmlTabControl : FrameworkElement, IXHtmlObject
{
public uint Id { get; set; }
// public FrameworkElement FrameworkElement { get { return this; } }
public XHtmlPresentation Presentation { get; set; }
public XHtmlPage Page { get; set; }
public bool IsMultiLine;
public int? ImageWidth;
public int? ImageHeight;
private ushort stopPoint;
public ushort? idPolice;
//double? VerticalPadding;
//double? HorizontalPadding;
ushort? idPadding;
byte currentTabPageNum;
public List<XHtmlTabItem>Items = new List<XHtmlTabItem>();
#region Constructeur
/// <summary>
/// Initializes a new instance of the XHtmlTabControl class.
/// </summary>
public XHtmlTabControl(XHtmlPage page)
{
//!!!!!!!!!!!!!!! mettre un zindex pour qu'on soit derriere
Page = page;
}
#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;
ushort id;
buffer.Get(out property);
while (property != ProprietesWpf.GROUPE_ONGLET_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.ONGLET_POLICE: // Police des headers d'onglets
ushort idFont;
buffer.Get(out idFont);
idPolice = idFont;
// XHtmlFont font = Application.Current.Resources["Font-" + idFont] as XHtmlFont;
//if (font == null)
//{
// Debug.WriteLine("police onglet non-chargée (ressource à null)");
// break;
//}
//if (font.Family != null) FontFamily = font.Family;
//if (font.Size != null) FontSize = font.Size.Value;
//if (font.Style != null) FontStyle = font.Style.Value;
//if (font.Weight != null) FontWeight = font.Weight.Value;
//if (font.Brush != null) Foreground = font.Brush;
break;
case ProprietesWpf.ONGLET_PADDING: // padding dans les headers d'onglets
buffer.Get(out id);
idPadding = id;
//double? verticalPadding = Application.Current.Resources["VerticalPadding-" + idPadding] as double?;
//double? horizontalPadding = Application.Current.Resources["HorizontalPadding-" + idPadding] as double?;
//Thickness padding = Padding;
//if (verticalPadding.HasValue) padding.Top = padding.Bottom = verticalPadding.Value;
//if (horizontalPadding.HasValue) padding.Left = padding.Right = horizontalPadding.Value;
//Padding = padding;
break;
case ProprietesWpf.ONGLET_TAILLE_IMAGE: // Image du bouton (ushort x ushort)
ushort imageHeight, imageWidth;
buffer.Get(out imageHeight);
buffer.Get(out imageWidth);
ImageHeight = imageHeight;
ImageWidth = imageWidth;
break;
case ProprietesWpf.ONGLET_MULTILIGNE: // (Uniquement si multiligne)
IsMultiLine = true;
break;
case ProprietesWpf.ONGLET_COURANT: // Onglet courant (byte)
buffer.Get(out currentTabPageNum);
//XHtmlTabItem currentTab = GetTabByPageNum(currentTabPageNum);
//if (currentTab != null)
//{
// currentTab.IsSelected = true;
// //UpdateLayout(); // nécessaire pour que le BringIntoView fonctionne au tout premier affichage
// //currentTab.BringIntoView();
//}
break;
case ProprietesWpf.ONGLET_ARRET: // Numéro du point d'arrêt (ushort)
buffer.Get(out stopPoint);
break;
case ProprietesWpf.ONGLET_DEBUT:
uint idTab;
buffer.Get(out idTab);
XHtmlTabItem tab = GetTabById(idTab);
if (tab == null)
{
tab = new XHtmlTabItem(this) { Id = idTab };
tab.Page = this.Page;
Items.Add(tab);
}
tab.ReadProperties(buffer);
break;
default:
throw new XHtmlException(XHtmlErrorCodes.UnknownProperty, XHtmlErrorLocations.TabControl, property.ToString());
}
buffer.Get(out property);
}
}
#endregion Lecture propriétés
#region Fonctions
/// <summary>
/// Récupération de l'onglet actif
/// </summary>
private XHtmlTabItem GetTabByPageNum(uint pageNum)
{
return Items.OfType<XHtmlTabItem>().FirstOrDefault(tab => tab.PageNumber == pageNum);
}
/// <summary>
/// Recherche d'un objet dans la liste d'objets de la page
/// </summary>
private XHtmlTabItem GetTabById(uint id)
{
return Items.OfType<XHtmlTabItem>().FirstOrDefault(tab => tab.Id == id);
}
//internal void SendCtrlN(int n)
//{
// XHtmlTabItem tabItem;
// if (n > Items.Count && n != 9) return; // garde-fou : si num > nb d'onglets dans le groupe, on ne fait rien
// if (n == 9) // CTRL + 9 active le dernier tabItem, quel qu'il soit.
// {
// n = Items.Count;
// foreach (var t in Items) // mais décompter les onglets cachés
// {
// tabItem = (XHtmlTabItem)t;
// if (tabItem.Visibility != Visibility.Visible)
// n--;
// }
// }
// if (n == 0) return; // garde-fou : si tous les onglets sont cachés
// for (int i = 0; i < n; i++) // il faut ignorer les onglets cachés
// {
// tabItem = (XHtmlTabItem)Items[i];
// if (tabItem.Visibility != Visibility.Visible)
// if (++n > Items.Count) return;
// }
// tabItem = (XHtmlTabItem)Items[n - 1];
// if (tabItem.IsEnabled == false) return; // si l'onglet demandé est grisé
// if (tabItem == SelectedItem) return; // on ne notifie pas le serveur si N correspond à l'onglet courrant
// 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)
// response.Put((byte)MouseEvent.ClickTab);
// response.Put(ProprietesWpf.SOURIS_CLIC); // 1 = simple clic; 2 = double clic (byte)
// response.Put((byte)1);
// response.Put(ProprietesWpf.SOURIS_BOUTON); // 1 = gauche; 2 = milieu; 3 = droite (byte)
// response.Put((byte)1);
// response.Put(ProprietesWpf.SOURIS_TOUCHE); // touche(s) du clavier enfoncée(s) simultanément (byte)
// response.Put((byte)0);
// // Informations sur le changement d'onglet :
// response.Put(ProprietesWpf.ONGLET_ARRET); // Numéro du point d'arrêt (ushort)
// response.Put(stopPoint);
// response.Put(ProprietesWpf.ONGLET_NOUVELLE_PAGE); // numéro de page de l'onglet à afficher (byte)
// response.Put(tabItem.PageNumber);
// response.Put(ProprietesWpf.ONGLET_ANCIENNE_PAGE); // numéro de page de l'onglet précédemment affiché (byte)
// response.Put(((XHtmlTabItem)SelectedItem).PageNumber);
// response.Put(ProprietesWpf.EVENEMENT_SOURIS_FIN); // Fin de l'envoi des évenements souris
// application.Send(response);
//}
#endregion Fonctions
#region Ecouteurs
/// <summary>
/// Gestionnaire d'évènement "MouseDown" pour la capture de souris sur l'onglet
/// </summary>
//internal void TabMouseDownHandler(object sender, MouseButtonEventArgs e)
//{
// e.Handled = true;
// if (e.ClickCount > 1 || e.ChangedButton != MouseButton.Left) return; // pas de clic autre que simple clic gauche sur un onglet
// XHtmlTabItem tabItem = (XHtmlTabItem)sender; // l'écouteur est sur le tabitem
// if (tabItem == SelectedItem) return; // on ne fait rien si le clic est sur l'onglet courant
// var application = ((App)Application.Current).Appli;
// if (!application.AttenteConsult && !application.AttenteInput) return; // garde-fou
// 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)
// response.Put((byte)MouseEvent.ClickTab);
// response.Put(ProprietesWpf.SOURIS_CLIC); // 1 = simple clic; 2 = double clic (byte)
// response.Put((byte)1);
// response.Put(ProprietesWpf.SOURIS_BOUTON); // 1 = gauche; 2 = milieu; 3 = droite (byte)
// response.Put((byte)1);
// response.Put(ProprietesWpf.SOURIS_TOUCHE); // touche(s) du clavier enfoncée(s) simultanément (byte)
// response.Put((byte)0);
// // Informations sur le changement d'onglet :
// response.Put(ProprietesWpf.ONGLET_ARRET); // Numéro du point d'arrêt (ushort)
// response.Put(stopPoint);
// response.Put(ProprietesWpf.ONGLET_NOUVELLE_PAGE); // numéro de page de l'onglet à afficher (byte)
// response.Put(tabItem.PageNumber);
// response.Put(ProprietesWpf.ONGLET_ANCIENNE_PAGE); // numéro de page de l'onglet précédemment affiché (byte)
// response.Put(((XHtmlTabItem)SelectedItem).PageNumber);
// response.Put(ProprietesWpf.EVENEMENT_SOURIS_FIN); // Fin de l'envoi des évenements souris
// application.Send(response);
//}
#endregion Ecouteurs
public void AjouterEnvoisUnObjet(ListeParametresEnvoyes envois, XHtmlPage page, int niveau)
{
ListeParametresEnvoyes paramsValeurs = new ListeParametresEnvoyes();
ListeParametresEnvoyes paramsCreation = new ListeParametresEnvoyes();
OngletVersJson cc = new OngletVersJson();
paramsValeurs.Ajouter("idObjet", HtmlGlobal.CalculerId(this.Id, page.Id, niveau), this.Page.Html.CalculerIdPage(page.Id));
if (this.idPolice.HasValue)
cc.police = XHtmlFont.PrefixeCss + idPolice.ToString();
if (this.idPadding.HasValue)
cc.padding = XHtmlPadding.PrefixeCss + idPadding.ToString();
if (this.ImageHeight.HasValue)
cc.hauteurImage = this.ImageHeight;
if (this.ImageWidth.HasValue)
cc.largeurImage = this.ImageWidth;
cc.multiLigne = this.IsMultiLine;
cc.pointArret = this.stopPoint;
cc.pageCourante = this.currentTabPageNum;
if (Presentation != null)
this.Presentation.GenererHtml(paramsValeurs, this.Page.Html, 0, false);
foreach (XHtmlTabItem item in this.Items)
{
cc.items.Add(item.AjouterEnvoisUnItem(envois,page,niveau));
}
string parametresJson = HtmlGlobal.ToJsonString(cc, this.Page.Html.JsonParametresOnglet, false);
paramsCreation.Ajouter("paramsCreation", parametresJson);
//UnParametreEnvoye p = new UnParametreEnvoye();
envois.Ajouter("creerOnglet", HtmlGlobal.ToJsonString(paramsCreation, this.Page.Html.JsonParamsEnvoyes, false), HtmlGlobal.CalculerId(this.Id, page.Id, niveau));
envois.Ajouter("propsObjet", HtmlGlobal.ToJsonString(paramsValeurs, this.Page.Html.JsonParamsEnvoyes, false));
}
}
// attention, ce sont les memes coté JavaScript
public class ItemOngletVersJson
{
public string texte;
public string bulle;
public string bitmap;
public string fond;
public byte visibilite; // 0 = visible, 1 = grisé, 2 = illisible, 3 = caché
public ushort numeroPage;
}
[DataContract]
class OngletVersJson
{
[DataMember]
public List<ItemOngletVersJson> items = new List<ItemOngletVersJson>();
[DataMember]
public string police;
[DataMember]
public string padding;
[DataMember]
public int? hauteurImage;
[DataMember]
public int? largeurImage;
[DataMember]
public bool multiLigne;
[DataMember]
public ushort pointArret;
[DataMember]
public ushort pageCourante;
}
public class ClicOnglet
{
public string idOnglet;
public ushort pageOngletClick;
public ushort anciennePage;
public ushort arretOnglet;
};
}