Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
view-standard.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21
22#include <ui/common/component/panel.h>
23#include <wx/dcbuffer.h>
24#include <yuni/core/math/math.h>
25#include <yuni/core/bind.h>
26
27namespace Antares
28{
29namespace Window
30{
31class CalendarSelect;
32
34{
35public:
36 enum
37 {
38 nbMonthPerRow = 4,
39 spaceBetweenMonth = 10,
40 dayWidth = 18,
41 decalX = 10,
42 decalY = 10,
43 weekNumbersWidth = dayWidth * 2,
44 recommendedWindowWidth = nbMonthPerRow * (dayWidth * 7 + spaceBetweenMonth) + decalX * 2
45 + weekNumbersWidth * nbMonthPerRow /* week number*/,
46 recommendedWindowHeight
47 = (12 / nbMonthPerRow) * (dayWidth * 8 + spaceBetweenMonth) + decalY * 2 + 4 + dayWidth * 2,
48 borderWidth = 4
49 };
50
51public:
52 CalendarViewStandard(wxWindow* parent, CalendarSelect& dialog);
53 virtual ~CalendarViewStandard()
54 {
55 }
56
57 void selectWholeYear();
58 void selectNone();
59
61 void onDraw(wxPaintEvent&);
63 void onEraseBackground(wxEraseEvent&)
64 {
65 }
67 virtual void onMouseMoved(int x, int y);
68
70 virtual void onMouseDown(wxMouseEvent&);
71
73 virtual void onMouseUp(wxMouseEvent&);
74
75public:
79 Yuni::Bind<void(const YString&)> onUpdateSelectionText;
80
81private:
82 inline void updateSelectionDayRange();
83 void prepareGrid(wxDC& dc, const Date::Calendar& calendar);
84 void updateGridCells(int x, int y);
85 void updateSelectionText();
86 void updateSelectionText(YString& out, uint from, uint to);
87
88private:
90 wxPoint pMousePosition;
91
93 uint pCurrentDayYearHover;
95 uint pDayYearRangeStart;
97 uint pCurrentSelectionDayRange[2];
98
100 wxBitmap pCacheBackgroundImage;
102 bool pCacheBkgReady;
103
104 enum DayType
105 {
106 dtInvalid,
107 dtNormal,
108 dtHighlight,
109 dtHighlightRange,
110 dtHighlightRangeSimulationOut,
111 dtSelection,
112 dtWeek,
113 dtWeekNormal,
114 dtWeekHighlight,
115 dtMax
116 };
117
118 struct CellInfo
119 {
121 DayType type;
123 int x;
125 int y;
127 int textX;
129 int textY;
131 wxString text;
132 };
133
134 CellInfo pCacheDay[Date::Calendar::maxDaysInYear];
135
136 CellInfo pCacheWeek[Date::Calendar::maxWeeksInYear * 2];
137 uint pCacheWeekObjectID[Date::Calendar::maxWeeksInYear];
138
140 CalendarSelect& pDialog;
141
142 // Event table
143 DECLARE_EVENT_TABLE()
144
145}; // class CalendarViewStandard
146
147BEGIN_EVENT_TABLE(CalendarViewStandard, Panel)
149EVT_ERASE_BACKGROUND(CalendarViewStandard::onEraseBackground)
150END_EVENT_TABLE()
151
152// The font re-used for each drawing
153enum
154{
155 fontSize = 8,
156
157 textDrawOffsetY = Yuni::System::windows ? -1 : 0,
158};
159static const wxFont font(wxFontInfo(fontSize).Family(wxFONTFAMILY_SWISS).FaceName("Tahoma"));
160static const wxFont fontBold(
161 wxFontInfo(fontSize).Family(wxFONTFAMILY_SWISS).Bold().FaceName("Tahoma"));
162
163CalendarViewStandard::CalendarViewStandard(wxWindow* parent, CalendarSelect& dialog) :
164 Panel(parent), calendar(GetCurrentStudy()->calendar), pDialog(dialog)
165{
166 SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Required by both GTK and Windows
167 SetSize(recommendedWindowWidth, recommendedWindowHeight);
168 assert(parent != NULL);
169
170 pCurrentDayYearHover = (uint)-1;
171 pDayYearRangeStart = (uint)-1;
172 pCurrentSelectionDayRange[0] = pDialog.selectionDayRange[0];
173 pCurrentSelectionDayRange[1] = pDialog.selectionDayRange[1];
174 pCacheBkgReady = false;
175
176 for (uint i = 0; i != calendar.maxDaysInYear; ++i)
177 {
178 pCacheDay[i].x = 100000; // arbitrary - far far away
179 pCacheDay[i].type = dtNormal;
180 }
181 for (uint i = 0; i != calendar.maxWeeksInYear * 2; ++i)
182 {
183 pCacheWeek[i].x = 100000; // arbitrary - far far away
184 pCacheWeek[i].type = dtInvalid;
185 }
186
187 wxMemoryDC dc;
188 prepareGrid(dc, calendar);
189 updateGridCells(-1, -1);
190 Dispatcher::GUI::Post(this, &CalendarViewStandard::updateSelectionText);
191 Dispatcher::GUI::Refresh(this);
192}
193
194void CalendarViewStandard::selectWholeYear()
195{
196 pDialog.pHasBeenModified = true;
197 pDialog.selectionDayRange[0] = 0;
198 pDialog.selectionDayRange[1] = 365;
199 pCurrentDayYearHover = (uint)-1;
200 pDayYearRangeStart = (uint)-1;
201
202 updateGridCells(-1, -1);
203 updateSelectionText();
204 Refresh();
205}
206
207void CalendarViewStandard::selectNone()
208{
209 pDialog.pHasBeenModified = true;
210 pDialog.selectionDayRange[0] = (uint)-1;
211 pDialog.selectionDayRange[1] = (uint)-1;
212 pCurrentDayYearHover = (uint)-1;
213 pDayYearRangeStart = (uint)-1;
214
215 updateGridCells(-1, -1);
216 updateSelectionText();
217 Refresh();
218}
219
220void CalendarViewStandard::updateGridCells(int x, int y)
221{
222 // note : prepareGrid must be called at least once before this routine
223 // looking for the day hover
224 for (uint d = 0; d != calendar.maxDaysInYear; ++d)
225 {
226 auto& day = pCacheDay[d];
227 if (x >= day.x && y >= day.y && x < day.x + dayWidth && y < day.y + dayWidth)
228 {
229 // Do never take into consideration the last day in leap year
230 if (d < 365)
231 pCurrentDayYearHover = d;
232 break;
233 }
234 }
235 updateSelectionDayRange();
236
237 for (uint w = 0; w != calendar.maxWeeksInYear; ++w)
238 pCacheWeek[pCacheWeekObjectID[w]].type = dtWeekNormal;
239
240 // updating all cells
241 for (uint d = 0; d != calendar.maxDaysInYear; ++d)
242 {
243 auto& day = pCacheDay[d];
244
245 // hover
246 if (d == pCurrentDayYearHover)
247 {
248 for (uint i = d + 1; i < calendar.maxDaysInYear; ++i)
249 {
250 pCacheDay[i].type
251 = (pDialog.selectionDayRange[1] != (uint)-1 && i < pDialog.selectionDayRange[1]
252 && i >= pDialog.selectionDayRange[0])
253 ? dtSelection
254 : dtNormal;
255 }
256
257 // highlighting the week
258 uint week = calendar.days[d].week;
259 pCacheWeek[pCacheWeekObjectID[week]].type = dtWeekHighlight;
260 auto& range = calendar.weeks[week].daysYear;
261 if (d < pDayYearRangeStart)
262 {
263 for (uint wd = range.first; wd < range.end; ++wd)
264 pCacheDay[wd].type = dtWeek;
265 }
266 else
267 {
268 for (uint wd = d + 1; wd < range.end; ++wd)
269 pCacheDay[wd].type = dtWeek;
270 }
271
272 // hightlighting the day where the mouse is hover
273 day.type = dtHighlight;
274 break;
275 }
276
277 day.type
278 = (d >= pDayYearRangeStart)
279 ? ((d == pDayYearRangeStart) ? dtHighlight : dtHighlightRange)
280 : (d >= pDialog.selectionDayRange[0] && d < pDialog.selectionDayRange[1] ? dtSelection
281 : dtNormal);
282 }
283
284 if (pDayYearRangeStart == (uint)-1)
285 {
286 // highlight (error) partial weeks for user selection
287 if (pDialog.selectionDayRange[0] != (uint)-1 && pDialog.selectionDayRange[1] != (uint)-1)
288 {
289 uint count = pDialog.selectionDayRange[1] - pDialog.selectionDayRange[0];
290 if (count < 7)
291 {
292 for (uint i = pDialog.selectionDayRange[0]; i < pDialog.selectionDayRange[1]; ++i)
293 pCacheDay[i].type = dtHighlightRangeSimulationOut;
294 }
295 else
296 {
297 uint partial = count % 7;
298 for (uint i = pDialog.selectionDayRange[1] - partial;
299 i < pDialog.selectionDayRange[1];
300 ++i)
301 pCacheDay[i].type = dtHighlightRangeSimulationOut;
302 }
303 }
304 }
305 else
306 {
307 if (pCurrentDayYearHover != (uint)-1)
308 {
309 // highlight (error) partial weeks for the current in range selection
310 uint count = pCurrentSelectionDayRange[1] - pCurrentSelectionDayRange[0] + 1;
311 if (count < 7)
312 {
313 for (uint i = pCurrentSelectionDayRange[0]; i <= pCurrentSelectionDayRange[1]; ++i)
314 pCacheDay[i].type = dtHighlightRangeSimulationOut;
315 }
316 else
317 {
318 uint partial = count % 7;
319 for (uint i = pCurrentSelectionDayRange[1] - partial + 1;
320 i <= pCurrentSelectionDayRange[1];
321 ++i)
322 pCacheDay[i].type = dtHighlightRangeSimulationOut;
323 }
324 }
325 }
326
327 // highlight the begining of the week for the selection
328 if (pDayYearRangeStart < calendar.maxDaysInYear && pDayYearRangeStart > 0)
329 {
330 uint week = calendar.days[pDayYearRangeStart].week;
331 auto& range = calendar.weeks[week].daysYear;
332 for (uint wd = range.first; wd < pDayYearRangeStart; ++wd)
333 pCacheDay[wd].type = dtWeek;
334 }
335}
336
338{
339 // Notify other components as well
341 // Update informations about the mouse position
342 pMousePosition.x = x;
343 pMousePosition.y = y;
344 if (pDayYearRangeStart == (uint)-1)
345 pCurrentDayYearHover = (uint)-1;
346
347 updateGridCells(x, y);
348
349 if (pDayYearRangeStart != (uint)-1)
350 updateSelectionText();
351 // refresh the component itself
352 Refresh();
353}
354
356{
357 if (pDialog.allowRangeSelection)
358 pDayYearRangeStart = pCurrentDayYearHover;
359
360 pCurrentDayYearHover = (uint)-1;
361 const auto& position = evt.GetPosition();
362 updateGridCells(position.x, position.y);
363
364 Dispatcher::GUI::Refresh(this);
365}
366
368{
369 // keeping somewhere the current mouse selection
370 if (pDialog.allowRangeSelection)
371 {
372 pDialog.selectionDayRange[0] = pCurrentSelectionDayRange[0];
373 pDialog.selectionDayRange[1] = pCurrentSelectionDayRange[1] + 1;
374 }
375 else
376 {
377 pDialog.selectionDayRange[0] = pCurrentDayYearHover;
378 pDialog.selectionDayRange[1] = pCurrentDayYearHover + 1;
379 }
380 pDialog.pHasBeenModified = true;
381
382 // invalidating the current mouse selection
383 if (pDialog.allowQuickSelect && pDialog.selectionDayRange[0] != (uint)-1)
384 {
385 pDialog.pCanceled = false;
386 onUpdateSelectionText.unbind();
387 Dispatcher::GUI::Close(&pDialog, 100);
388 }
389 else
390 {
391 pCurrentDayYearHover = (uint)-1;
392 pDayYearRangeStart = (uint)-1;
393
394 updateSelectionDayRange();
395 updateGridCells(10000, 0);
396 Dispatcher::GUI::Refresh(this);
397 updateSelectionText();
398 }
399}
400
402{
403 // The DC
404 wxAutoBufferedPaintDC dc(this);
405 // Shifts the device origin so we don't have to worry
406 // about the current scroll position ourselves
407 PrepareDC(dc);
408 // Cute font
409 dc.SetFont(font);
410
411 const wxColour bkgColor(255, 255, 255);
412
413 if (not pCacheBkgReady)
414 {
415 pCacheBackgroundImage.Create(recommendedWindowWidth, recommendedWindowHeight);
416 wxMemoryDC memdc;
417 memdc.SelectObject(pCacheBackgroundImage);
418 prepareGrid(memdc, calendar);
419 pCacheBkgReady = true;
420 }
421
422 dc.DrawBitmap(pCacheBackgroundImage, 0, 0, false);
423
424 // redrawing all cells
425 struct
426 {
427 wxColour background;
428 wxColour text;
429 } colorSet[dtMax];
430
431 colorSet[dtNormal].text.Set(60, 60, 60);
432 colorSet[dtNormal].background.Set(255, 255, 255);
433
434 colorSet[dtWeekNormal].text.Set(170, 170, 170);
435 colorSet[dtWeekNormal].background.Set(255, 255, 255);
436
437 colorSet[dtWeekHighlight].text.Set(0, 0, 0);
438 colorSet[dtWeekHighlight].background.Set(235, 235, 235);
439
440 colorSet[dtHighlight].text.Set(250, 250, 250);
441 colorSet[dtHighlight].background.Set(10, 10, 10);
442
443 colorSet[dtHighlightRange].text.Set(230, 230, 230);
444 colorSet[dtHighlightRange].background.Set(80, 80, 80);
445
446 colorSet[dtHighlightRangeSimulationOut].text.Set(230, 230, 230);
447 colorSet[dtHighlightRangeSimulationOut].background.Set(200, 30, 30);
448
449 colorSet[dtWeek].text.Set(50, 40, 40);
450 colorSet[dtWeek].background.Set(210, 210, 215);
451
452 colorSet[dtSelection].text.Set(30, 30, 30);
453 colorSet[dtSelection].background.Set(157, 205, 255);
454
455 for (uint day = 0; day != calendar.maxDaysInYear; ++day)
456 {
457 auto& cache = pCacheDay[day];
458 auto& colors = colorSet[cache.type];
459
460 dc.SetBrush(wxBrush(colors.background, wxBRUSHSTYLE_SOLID));
461 dc.SetPen(wxPen(colors.background, 1, wxPENSTYLE_SOLID));
462 dc.SetTextForeground(colors.text);
463
464 dc.DrawRectangle(wxRect(cache.x, cache.y, dayWidth, dayWidth));
465 dc.DrawText(cache.text, cache.textX, cache.textY);
466 }
467
468 for (uint week = 0; week != calendar.maxWeeksInYear * 2; ++week)
469 {
470 auto& cache = pCacheWeek[week];
471 if (cache.type == dtInvalid)
472 break;
473 auto& colors = colorSet[cache.type];
474
475 dc.SetBrush(wxBrush(colors.background, wxBRUSHSTYLE_SOLID));
476 dc.SetPen(wxPen(colors.background, 1, wxPENSTYLE_SOLID));
477 dc.SetTextForeground(colors.text);
478
479 dc.DrawRectangle(wxRect(cache.x, cache.y, weekNumbersWidth, dayWidth));
480 dc.DrawText(cache.text, cache.textX, cache.textY);
481 }
482}
483
484inline void CalendarViewStandard::updateSelectionDayRange()
485{
486 pCurrentSelectionDayRange[0] = Math::Min(pDayYearRangeStart, pCurrentDayYearHover);
487 pCurrentSelectionDayRange[1] = Math::Max(pDayYearRangeStart, pCurrentDayYearHover);
488}
489
490void CalendarViewStandard::prepareGrid(wxDC& dc, const Date::Calendar& calendar)
491{
492 // Cute font
493 dc.SetFont(font);
494
495 wxRect rect = GetRect();
496 const wxColour bkgColor(255, 255, 255);
497
498 // Redraw the background
499 dc.SetPen(wxPen(bkgColor, 1, wxPENSTYLE_SOLID));
500 dc.SetBrush(wxBrush(bkgColor, wxBRUSHSTYLE_SOLID));
501 dc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight());
502
503 wxRect monthRect;
504 monthRect.x = weekNumbersWidth;
505 monthRect.y = 0;
506 monthRect.width = dayWidth * 7;
507 monthRect.height = dayWidth * 6 + dayWidth /*weekdays*/ + borderWidth * 4;
508 uint dayYear = 0;
509
510 wxColour dayTextColor(60, 60, 60);
511 wxColour dayTextColorOdd(100, 50, 50);
512 wxColour dayBkgColor(255, 255, 255);
513 wxColour dayUserSelectTextColor(20, 20, 20);
514 wxColour dayUserSelectBkgColor(255, 230, 230);
515
516 wxColour weekdaysBkgColor(250, 250, 250);
517 wxColour weekdaysTextColor(40, 40, 40);
518 // wxColour monthBkgColor(230, 230, 250);
519 wxColour monthBkgColor(89, 124, 145);
520 wxColour monthTextColor(250, 250, 250);
521
522 wxColour selectionBkgColor(175, 186, 209);
523 wxColour selectionTextColor(40, 40, 40);
524 wxColour selectionDayBkgColor(131, 139, 157);
525 wxColour selectionDayTextColor(250, 250, 250);
526
527 uint weekIndex = 0;
528
529 wxString text;
530 uint maxY = 0;
531
532 for (uint month = 0; month != 12; ++month)
533 {
534 if (month > 0)
535 {
536 if (0 == (month % nbMonthPerRow))
537 {
538 monthRect.x = weekNumbersWidth;
539 monthRect.y = maxY + dayWidth + borderWidth;
540 maxY = 0;
541 }
542 else
543 monthRect.x += weekNumbersWidth + monthRect.width + spaceBetweenMonth;
544 }
545
546 uint wx = 0;
547 uint wy = 0;
548
549 // month name
550 dc.SetFont(fontBold);
551 {
552 uint x = decalX + monthRect.x + wx;
553 uint y = decalY + monthRect.y + wy;
554 enum
555 {
556 w = dayWidth * 7,
557 };
558
559 dc.SetPen(wxPen(monthBkgColor, 1, wxPENSTYLE_SOLID));
560 dc.SetBrush(wxBrush(monthBkgColor, wxBRUSHSTYLE_SOLID));
561 dc.DrawRectangle(wxRect(x, y, w, dayWidth));
562
563 text = wxStringFromUTF8(calendar.text.months[month].name);
564 auto extend = dc.GetTextExtent(text);
565 dc.SetTextForeground(monthTextColor);
566 dc.DrawText(
567 text, x + w / 2 - extend.GetWidth() / 2, y + dayWidth / 2 - extend.GetHeight() / 2);
568 }
569 wy += dayWidth;
570
571 // days of the week
572 dc.SetFont(font);
573 dc.SetTextForeground(weekdaysTextColor);
574 dc.SetPen(wxPen(weekdaysBkgColor, 1, wxPENSTYLE_SOLID));
575 dc.SetBrush(wxBrush(weekdaysBkgColor, wxBRUSHSTYLE_SOLID));
576 for (uint wd = 0; wd != 7; ++wd)
577 {
578 uint x = decalX + monthRect.x + wx + (wd * dayWidth);
579 uint y = decalY + monthRect.y + wy;
580
581 dc.DrawRectangle(wxRect(x, y, dayWidth, dayWidth));
582
583 text = Date::WeekdayToLShortString(wd);
584 auto extend = dc.GetTextExtent(text);
585 dc.DrawText(text,
586 x + dayWidth / 2 - extend.GetWidth() / 2,
587 y + dayWidth / 2 - extend.GetHeight() / 2);
588 }
589 dc.SetPen(wxPen(monthBkgColor, 1, wxPENSTYLE_SOLID));
590 wy += dayWidth;
591 {
592 uint x = decalX + monthRect.x + wx;
593 uint y = decalY + monthRect.y + wy;
594 dc.DrawLine(x, y, x + dayWidth * 7, y);
595 }
596 wy += borderWidth;
597
598 // week numbers positions
599 uint weekNumbersX = decalX + monthRect.x + wx - weekNumbersWidth;
600 uint weekNumbersY = decalY + monthRect.y + wy;
601
602 // Current day of the week to display
603 uint graphicalWeekday = (uint)calendar.months[month].firstWeekday;
604 wx += graphicalWeekday * dayWidth;
605 // How many days in the current month
606 uint daysPerMonth = calendar.months[month].days;
607
608 // registering the first week number
609 {
610 auto& cacheweek = pCacheWeek[weekIndex];
611 cacheweek.x = weekNumbersX;
612 cacheweek.y = weekNumbersY;
613 cacheweek.type = dtWeekNormal;
614 }
615
616 for (uint day = 0; day < daysPerMonth; ++day, ++dayYear)
617 {
618 uint x = decalX + monthRect.x + wx;
619 uint y = decalY + monthRect.y + wy;
620
621 if (not graphicalWeekday)
622 {
623 if (day != 0)
624 {
625 // registering the first week number
626 ++weekIndex;
627 auto& cacheweek = pCacheWeek[weekIndex];
628 cacheweek.x = weekNumbersX;
629 cacheweek.y = weekNumbersY;
630 cacheweek.type = dtWeekNormal;
631 }
632 }
633
634 pCacheWeek[weekIndex].textX = dayYear;
635
636 auto& cacheday = pCacheDay[dayYear];
637 cacheday.x = x;
638 cacheday.y = y;
639
640 cacheday.text.clear();
641 cacheday.text << (day + 1);
642
643 auto extend = dc.GetTextExtent(cacheday.text);
644 cacheday.textX = x + dayWidth / 2 - extend.GetWidth() / 2;
645 cacheday.textY = y + dayWidth / 2 - extend.GetHeight() / 2 + textDrawOffsetY;
646
647 if (y > maxY)
648 maxY = y;
649 if (++graphicalWeekday >= 7)
650 {
651 graphicalWeekday = 0;
652 wx = 0;
653 wy += dayWidth;
654 weekNumbersY += dayWidth;
655 }
656 else
657 wx += dayWidth;
658 }
659 ++weekIndex;
660 }
661
662 // invalidating the last pseudo week
663 pCacheWeek[++weekIndex].type = dtInvalid;
664
665 // initializing textextend for all weeks
666 for (uint week = 0; week != calendar.maxWeeksInYear; ++week)
667 pCacheWeekObjectID[week] = calendar.maxWeeksInYear * 2 - 1; // invalid and never seen
668
669 for (uint pseudoweek = 0; pseudoweek != calendar.maxWeeksInYear * 2; ++pseudoweek)
670 {
671 auto& cache = pCacheWeek[pseudoweek];
672 if (cache.type == dtInvalid)
673 break;
674
675 cache.text.clear();
676 if (cache.textX < calendar.maxDaysInYear)
677 {
678 uint week = calendar.days[cache.textX].week;
679 week = calendar.weeks[week].userweek;
680 // if (pCacheWeekObjectID[week] > pseudoweek)
681 // pCacheWeekObjectID[week] = pseudoweek;
682 cache.text << week;
683 }
684
685 auto extend = dc.GetTextExtent(cache.text);
686 cache.textX = cache.x + weekNumbersWidth - extend.GetWidth() - 6;
687 cache.textY = cache.y + dayWidth / 2 - extend.GetHeight() / 2 + textDrawOffsetY;
688 }
689}
690
691void CalendarViewStandard::updateSelectionText(YString& text, uint from, uint to)
692{
693 auto& start = calendar.days[from];
694
695 text << ' ';
696 if (to != (uint)-1)
697 text << "From ";
698
699 auto realmonth = calendar.months[start.month].realmonth;
700 text << Date::WeekdayToString((int)start.weekday);
701 text << ", ";
702 text << (start.dayMonth + 1) << ' ' << Date::MonthToString((int)realmonth);
703
704 if (to != (uint)-1)
705 {
706 auto& end = calendar.days[to];
707 realmonth = calendar.months[end.month].realmonth;
708 text << " to ";
709 text << Date::WeekdayToString((int)end.weekday);
710 text << ", ";
711 text << (end.dayMonth + 1) << ' ' << Date::MonthToString((int)realmonth);
712
713 uint nbdays = to - from + 1;
714 if (nbdays > 1 && nbdays < 400)
715 {
716 text << " (" << nbdays;
717 if (nbdays >= 7)
718 {
719 text << " days, ";
720 uint nbweeks = nbdays / 7;
721 if (nbweeks == 1)
722 text << "1 week)";
723 else
724 text << nbweeks << " weeks)";
725 }
726 else
727 text << "days)";
728 }
729 }
730}
731
732void CalendarViewStandard::updateSelectionText()
733{
734 YString text;
735
736 if (pDayYearRangeStart != (uint)-1)
737 {
738 text = " Selecting ";
739 uint from = pCurrentSelectionDayRange[0];
740 uint to = pCurrentSelectionDayRange[1];
741 if (to == from)
742 to = (uint)-1;
743 updateSelectionText(text, from, to);
744 }
745 else
746 {
747 uint from = pDialog.selectionDayRange[0];
748 uint to = (pDialog.selectionDayRange[1] == (uint)-1) ? (uint)-1
749 : pDialog.selectionDayRange[1] - 1;
750 if (from != (uint)-1)
751 {
752 if (to == from)
753 to = (uint)-1;
754 updateSelectionText(text, from, to);
755 }
756 }
757
758 if (text.empty())
759 text = "(no selection)";
761}
762
763} // namespace Window
764} // namespace Antares
Panel implementation.
Definition panel.h:36
static void OnMouseMoveFromExternalComponent()
Event triggered by any other component (not derived from Panel)
Definition panel.cpp:82
Definition date.h:180
struct Antares::Date::Calendar::@17 text
Human string representations for any time interval of our calendar.
struct Antares::Date::Calendar::@14 weeks[maxWeeksInYear]
Informations about weeks according the current calendar settings.
uint userweek
User week number.
Definition date.h:254
@ maxDaysInYear
The maximum number of days in a year.
Definition date.h:194
@ maxWeeksInYear
The maximum number of weeks in a year.
Definition date.h:196
DayInterval daysYear
Days in the year.
Definition date.h:247
struct Antares::Date::Calendar::@13 days[maxDaysInYear]
Informations about days in the year according the current.
struct Antares::Date::Calendar::@15 months[12+1]
Informations about months according the current calendar settings.
uint week
Week.
Definition date.h:214
MonthName realmonth
Real month index.
Definition date.h:276
ShortString12 name
Month name (January..December)
Definition date.h:308
DayOfTheWeek firstWeekday
Very First weekday of the month.
Definition date.h:274
Dialog Window for selecting a date range.
Definition calendar.h:37
uint selectionDayRange[2]
Final Day range selection.
Definition calendar.h:56
bool allowQuickSelect
option: True to allow a quick selection (without clicking to a button)
Definition calendar.h:60
bool allowRangeSelection
option: True to allow range selection
Definition calendar.h:58
Definition view-standard.hxx:34
Date::Calendar & calendar
Current calendar.
Definition view-standard.hxx:77
void onDraw(wxPaintEvent &)
Event: draw the panel.
Definition view-standard.hxx:401
virtual void onMouseMoved(int x, int y)
wxEvent : onMouseMove
Definition view-standard.hxx:337
Yuni::Bind< void(const YString &)> onUpdateSelectionText
Event : update text.
Definition view-standard.hxx:79
virtual void onMouseUp(wxMouseEvent &)
Click up.
Definition view-standard.hxx:367
virtual void onMouseDown(wxMouseEvent &)
Click down.
Definition view-standard.hxx:355
void onEraseBackground(wxEraseEvent &)
UI: Erase background, empty to avoid flickering.
Definition view-standard.hxx:63