Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: xfa/fwl/core/cfwl_monthcalendar.cpp

Issue 2557103002: Cleanup FWL default values part II. (Closed)
Patch Set: Unused Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/core/cfwl_monthcalendar.h" 7 #include "xfa/fwl/core/cfwl_monthcalendar.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 FWL_Type CFWL_MonthCalendar::GetClassID() const { 159 FWL_Type CFWL_MonthCalendar::GetClassID() const {
160 return FWL_Type::MonthCalendar; 160 return FWL_Type::MonthCalendar;
161 } 161 }
162 162
163 void CFWL_MonthCalendar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { 163 void CFWL_MonthCalendar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
164 if (!bAutoSize) { 164 if (!bAutoSize) {
165 rect = m_pProperties->m_rtWidget; 165 rect = m_pProperties->m_rtWidget;
166 return; 166 return;
167 } 167 }
168 168
169 CFX_SizeF fs = CalcSize(true); 169 CFX_SizeF fs = CalcSize();
170 rect.Set(0, 0, fs.x, fs.y); 170 rect.Set(0, 0, fs.x, fs.y);
171 CFWL_Widget::GetWidgetRect(rect, true); 171 CFWL_Widget::GetWidgetRect(rect, true);
172 } 172 }
173 173
174 void CFWL_MonthCalendar::Update() { 174 void CFWL_MonthCalendar::Update() {
175 if (IsLocked()) 175 if (IsLocked())
176 return; 176 return;
177 if (!m_pProperties->m_pThemeProvider) 177 if (!m_pProperties->m_pThemeProvider)
178 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 178 m_pProperties->m_pThemeProvider = GetAvailableTheme();
179 179
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 textParam.m_iPart = CFWL_Part::Caption; 290 textParam.m_iPart = CFWL_Part::Caption;
291 textParam.m_dwStates = CFWL_PartState_Normal; 291 textParam.m_dwStates = CFWL_PartState_Normal;
292 textParam.m_pGraphics = pGraphics; 292 textParam.m_pGraphics = pGraphics;
293 int32_t iYear; 293 int32_t iYear;
294 int32_t iMonth; 294 int32_t iMonth;
295 iYear = m_iCurYear; 295 iYear = m_iCurYear;
296 iMonth = m_iCurMonth; 296 iMonth = m_iCurMonth;
297 CFX_WideString wsCation; 297 CFX_WideString wsCation;
298 GetHeadText(iYear, iMonth, wsCation); 298 GetHeadText(iYear, iMonth, wsCation);
299 textParam.m_wsText = wsCation; 299 textParam.m_wsText = wsCation;
300 m_szHead = CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider); 300 m_szHead =
301 CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider, false);
301 CalcHeadSize(); 302 CalcHeadSize();
302 textParam.m_rtPart = m_rtHeadText; 303 textParam.m_rtPart = m_rtHeadText;
303 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; 304 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
304 textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; 305 textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
305 if (pMatrix) 306 if (pMatrix)
306 textParam.m_matrix.Concat(*pMatrix); 307 textParam.m_matrix.Concat(*pMatrix);
307 pTheme->DrawText(&textParam); 308 pTheme->DrawText(&textParam);
308 } 309 }
309 310
310 void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, 311 void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 params.m_pGraphics = pGraphics; 436 params.m_pGraphics = pGraphics;
436 params.m_dwStates = CFWL_PartState_Normal; 437 params.m_dwStates = CFWL_PartState_Normal;
437 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; 438 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft;
438 439
439 CFX_WideString* wsDay = static_cast<CFX_WideString*>( 440 CFX_WideString* wsDay = static_cast<CFX_WideString*>(
440 pTheme->GetCapacity(&params, CFWL_WidgetCapacity::Today)); 441 pTheme->GetCapacity(&params, CFWL_WidgetCapacity::Today));
441 CFX_WideString wsText; 442 CFX_WideString wsText;
442 GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); 443 GetTodayText(m_iYear, m_iMonth, m_iDay, wsText);
443 params.m_wsText = *wsDay + wsText; 444 params.m_wsText = *wsDay + wsText;
444 445
445 m_szToday = CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider); 446 m_szToday =
447 CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider, false);
446 CalcTodaySize(); 448 CalcTodaySize();
447 params.m_rtPart = m_rtToday; 449 params.m_rtPart = m_rtToday;
448 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; 450 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
449 if (pMatrix) 451 if (pMatrix)
450 params.m_matrix.Concat(*pMatrix); 452 params.m_matrix.Concat(*pMatrix);
451 pTheme->DrawText(&params); 453 pTheme->DrawText(&params);
452 } 454 }
453 455
454 void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, 456 void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics,
455 IFWL_ThemeProvider* pTheme, 457 IFWL_ThemeProvider* pTheme,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 params.m_pWidget = this; 510 params.m_pWidget = this;
509 params.m_iPart = CFWL_Part::DateInCircle; 511 params.m_iPart = CFWL_Part::DateInCircle;
510 params.m_pGraphics = pGraphics; 512 params.m_pGraphics = pGraphics;
511 params.m_rtPart = pDate->rect; 513 params.m_rtPart = pDate->rect;
512 params.m_dwStates = CFWL_PartState_Normal; 514 params.m_dwStates = CFWL_PartState_Normal;
513 if (pMatrix) 515 if (pMatrix)
514 params.m_matrix.Concat(*pMatrix); 516 params.m_matrix.Concat(*pMatrix);
515 pTheme->DrawBackground(&params); 517 pTheme->DrawBackground(&params);
516 } 518 }
517 519
518 CFX_SizeF CFWL_MonthCalendar::CalcSize(bool bAutoSize) { 520 CFX_SizeF CFWL_MonthCalendar::CalcSize() {
519 if (!m_pProperties->m_pThemeProvider) 521 if (!m_pProperties->m_pThemeProvider)
520 return CFX_SizeF(); 522 return CFX_SizeF();
521 if (!bAutoSize) {
522 GetClientRect(m_rtClient);
523 return CFX_SizeF(m_rtClient.width, m_rtClient.height);
524 }
525 523
526 CFX_SizeF fs; 524 CFX_SizeF fs;
527 CFWL_ThemePart params; 525 CFWL_ThemePart params;
528 params.m_pWidget = this; 526 params.m_pWidget = this;
529 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; 527 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
530 FX_FLOAT fMaxWeekW = 0.0f; 528 FX_FLOAT fMaxWeekW = 0.0f;
531 FX_FLOAT fMaxWeekH = 0.0f; 529 FX_FLOAT fMaxWeekH = 0.0f;
532 530
533 for (uint32_t i = 0; i < 7; ++i) { 531 for (uint32_t i = 0; i < 7; ++i) {
534 CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), 532 CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i),
535 m_pProperties->m_pThemeProvider); 533 m_pProperties->m_pThemeProvider, false);
536 fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; 534 fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x;
537 fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; 535 fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y;
538 } 536 }
539 537
540 FX_FLOAT fDayMaxW = 0.0f; 538 FX_FLOAT fDayMaxW = 0.0f;
541 FX_FLOAT fDayMaxH = 0.0f; 539 FX_FLOAT fDayMaxH = 0.0f;
542 for (int day = 10; day <= 31; day++) { 540 for (int day = 10; day <= 31; day++) {
543 CFX_WideString wsDay; 541 CFX_WideString wsDay;
544 wsDay.Format(L"%d", day); 542 wsDay.Format(L"%d", day);
545 CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider); 543 CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider, false);
546 fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; 544 fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x;
547 fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; 545 fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y;
548 } 546 }
549 m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) 547 m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5)
550 : (int)(fDayMaxW + 0.5)); 548 : (int)(fDayMaxW + 0.5));
551 m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; 549 m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH;
552 fs.x = m_szCell.x * MONTHCAL_COLUMNS + 550 fs.x = m_szCell.x * MONTHCAL_COLUMNS +
553 MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + 551 MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 +
554 MONTHCAL_HEADER_BTN_HMARGIN * 2; 552 MONTHCAL_HEADER_BTN_HMARGIN * 2;
555 FX_FLOAT fMonthMaxW = 0.0f; 553 FX_FLOAT fMonthMaxW = 0.0f;
556 FX_FLOAT fMonthMaxH = 0.0f; 554 FX_FLOAT fMonthMaxH = 0.0f;
557 555
558 for (uint32_t i = 0; i < 12; ++i) { 556 for (uint32_t i = 0; i < 12; ++i) {
559 CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), 557 CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i),
560 m_pProperties->m_pThemeProvider); 558 m_pProperties->m_pThemeProvider, false);
561 fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; 559 fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x;
562 fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; 560 fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y;
563 } 561 }
564 562
565 CFX_WideString wsYear; 563 CFX_WideString wsYear;
566 GetHeadText(m_iYear, m_iMonth, wsYear); 564 GetHeadText(m_iYear, m_iMonth, wsYear);
567 565
568 CFX_SizeF szYear = CalcTextSize(wsYear, m_pProperties->m_pThemeProvider); 566 CFX_SizeF szYear =
567 CalcTextSize(wsYear, m_pProperties->m_pThemeProvider, false);
569 fMonthMaxH = std::max(fMonthMaxH, szYear.y); 568 fMonthMaxH = std::max(fMonthMaxH, szYear.y);
570 m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); 569 m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH);
571 fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; 570 fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2;
572 fs.x = std::max(fs.x, fMonthMaxW); 571 fs.x = std::max(fs.x, fMonthMaxW);
573 572
574 CFX_WideString wsToday; 573 CFX_WideString wsToday;
575 GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); 574 GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday);
576 CFX_WideString* wsText = static_cast<CFX_WideString*>( 575 CFX_WideString* wsText = static_cast<CFX_WideString*>(
577 pTheme->GetCapacity(&params, CFWL_WidgetCapacity::Today)); 576 pTheme->GetCapacity(&params, CFWL_WidgetCapacity::Today));
578 m_wsToday = *wsText + wsToday; 577 m_wsToday = *wsText + wsToday;
579 m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider); 578 m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider, false);
580 m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; 579 m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y;
581 fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + 580 fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y +
582 MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; 581 MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4;
583 return fs; 582 return fs;
584 } 583 }
585 584
586 void CFWL_MonthCalendar::CalcHeadSize() { 585 void CFWL_MonthCalendar::CalcHeadSize() {
587 FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; 586 FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2;
588 FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; 587 FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2;
589 m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, 588 m_rtHeadText.Set(m_rtClient.left + fHeadHMargin,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 m_iCurYear = iYear; 803 m_iCurYear = iYear;
805 m_iCurMonth = iMonth; 804 m_iCurMonth = iMonth;
806 m_iHovered = -1; 805 m_iHovered = -1;
807 806
808 ClearDateItem(); 807 ClearDateItem();
809 ResetDateItem(); 808 ResetDateItem();
810 CalDateItem(); 809 CalDateItem();
811 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); 810 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead);
812 } 811 }
813 812
814 void CFWL_MonthCalendar::RemoveSelDay(int32_t iDay, bool bAll) { 813 void CFWL_MonthCalendar::RemoveSelDay() {
815 if (iDay == -1 && !bAll) 814 int32_t iCount = m_arrSelDays.GetSize();
816 return; 815 int32_t iDatesCount = m_arrDates.GetSize();
817 if (bAll) { 816 for (int32_t i = 0; i < iCount; i++) {
818 int32_t iCount = m_arrSelDays.GetSize(); 817 int32_t iSelDay = m_arrSelDays.GetAt(i);
819 int32_t iDatesCount = m_arrDates.GetSize(); 818 if (iSelDay <= iDatesCount) {
820 for (int32_t i = 0; i < iCount; i++) { 819 DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1);
821 int32_t iSelDay = m_arrSelDays.GetAt(i); 820 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
822 if (iSelDay <= iDatesCount) {
823 DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1);
824 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
825 }
826 } 821 }
827 m_arrSelDays.RemoveAll();
828 return;
829 } 822 }
830 823 m_arrSelDays.RemoveAll();
831 int32_t index = m_arrSelDays.Find(iDay); 824 return;
832 if (index == -1)
833 return;
834
835 int32_t iSelDay = m_arrSelDays.GetAt(iDay);
836 int32_t iDatesCount = m_arrDates.GetSize();
837 if (iSelDay <= iDatesCount) {
838 DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1);
839 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
840 }
841 m_arrSelDays.RemoveAt(index);
842 } 825 }
843 826
844 void CFWL_MonthCalendar::AddSelDay(int32_t iDay) { 827 void CFWL_MonthCalendar::AddSelDay(int32_t iDay) {
845 ASSERT(iDay > 0); 828 ASSERT(iDay > 0);
846 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) 829 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect)
847 return; 830 return;
848 831
849 if (m_arrSelDays.Find(iDay) != -1) 832 if (m_arrSelDays.Find(iDay) != -1)
850 return; 833 return;
851 834
852 RemoveSelDay(-1, true); 835 RemoveSelDay();
853 if (iDay <= m_arrDates.GetSize()) { 836 if (iDay <= m_arrDates.GetSize()) {
854 DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); 837 DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1);
855 pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; 838 pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected;
856 } 839 }
857 m_arrSelDays.Add(iDay); 840 m_arrSelDays.Add(iDay);
858 } 841 }
859 842
860 void CFWL_MonthCalendar::JumpToToday() { 843 void CFWL_MonthCalendar::JumpToToday() {
861 if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { 844 if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) {
862 m_iCurYear = m_iYear; 845 m_iCurYear = m_iYear;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 uint32_t dwSt, 1085 uint32_t dwSt,
1103 CFX_RectF rc, 1086 CFX_RectF rc,
1104 CFX_WideString& wsday) 1087 CFX_WideString& wsday)
1105 : iDay(day), 1088 : iDay(day),
1106 iDayOfWeek(dayofweek), 1089 iDayOfWeek(dayofweek),
1107 dwStates(dwSt), 1090 dwStates(dwSt),
1108 rect(rc), 1091 rect(rc),
1109 wsDay(wsday) {} 1092 wsDay(wsday) {}
1110 1093
1111 CFWL_MonthCalendar::DATEINFO::~DATEINFO() {} 1094 CFWL_MonthCalendar::DATEINFO::~DATEINFO() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698