Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "xfa/fxfa/app/xfa_fftextedit.h" |
| 8 | |
| 9 | #include <vector> |
| 10 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 11 | #include "xfa/fwl/cfwl_datetimepicker.h" |
| 12 | #include "xfa/fwl/cfwl_edit.h" |
| 13 | #include "xfa/fwl/cfwl_eventcheckword.h" |
| 14 | #include "xfa/fwl/cfwl_eventselectchanged.h" |
| 15 | #include "xfa/fwl/cfwl_eventtextchanged.h" |
| 16 | #include "xfa/fwl/cfwl_eventvalidate.h" |
| 17 | #include "xfa/fwl/cfwl_messagekillfocus.h" |
| 18 | #include "xfa/fwl/cfwl_messagemouse.h" |
| 19 | #include "xfa/fwl/cfwl_messagesetfocus.h" |
| 20 | #include "xfa/fwl/cfwl_notedriver.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | #include "xfa/fxfa/app/xfa_fffield.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 22 | #include "xfa/fxfa/app/xfa_fwladapter.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 24 | #include "xfa/fxfa/parser/xfa_localevalue.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/xfa_ffapp.h" |
| 26 | #include "xfa/fxfa/xfa_ffdoc.h" |
| 27 | #include "xfa/fxfa/xfa_ffdocview.h" |
| 28 | #include "xfa/fxfa/xfa_ffpageview.h" |
| 29 | #include "xfa/fxfa/xfa_ffwidget.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 31 | CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) |
| 32 | : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 33 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 34 | CXFA_FFTextEdit::~CXFA_FFTextEdit() { |
| 35 | if (m_pNormalWidget) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 36 | CFWL_NoteDriver* pNoteDriver = |
| 37 | m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); |
| 38 | pNoteDriver->UnregisterEventTarget(m_pNormalWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | } |
| 40 | } |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 41 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 42 | bool CXFA_FFTextEdit::LoadWidget() { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 43 | CFWL_Edit* pFWLEdit = new CFWL_Edit( |
| 44 | GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 45 | m_pNormalWidget = pFWLEdit; |
tsepez | 54ab234 | 2016-05-26 17:35:54 -0700 | [diff] [blame] | 46 | m_pNormalWidget->SetLayoutItem(this); |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 47 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 48 | CFWL_NoteDriver* pNoteDriver = |
| 49 | m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); |
| 50 | pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 51 | |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 52 | m_pOldDelegate = m_pNormalWidget->GetDelegate(); |
| 53 | m_pNormalWidget->SetDelegate(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 54 | m_pNormalWidget->LockUpdate(); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 55 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 56 | UpdateWidgetProperty(); |
| 57 | CFX_WideString wsText; |
| 58 | m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
| 59 | pFWLEdit->SetText(wsText); |
| 60 | m_pNormalWidget->UnlockUpdate(); |
| 61 | return CXFA_FFField::LoadWidget(); |
| 62 | } |
| 63 | void CXFA_FFTextEdit::UpdateWidgetProperty() { |
| 64 | CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; |
| 65 | if (!pWidget) { |
| 66 | return; |
| 67 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 68 | uint32_t dwStyle = 0; |
| 69 | uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | FWL_STYLEEXT_EDT_OuterScrollbar | |
| 71 | FWL_STYLEEXT_EDT_LastLineHeight; |
| 72 | dwExtendedStyle |= UpdateUIProperty(); |
| 73 | if (m_pDataAcc->IsMultiLine()) { |
| 74 | dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; |
| 75 | if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { |
| 76 | dwStyle |= FWL_WGTSTYLE_VScroll; |
| 77 | dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; |
| 78 | } |
| 79 | } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { |
| 80 | dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; |
| 81 | } |
| 82 | if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || |
| 83 | !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { |
| 84 | dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; |
| 85 | dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; |
| 86 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 87 | XFA_Element eType = XFA_Element::Unknown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 89 | if (eType == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 90 | iMaxChars = 0; |
| 91 | } |
| 92 | int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); |
| 93 | if (iNumCells == 0) { |
| 94 | dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; |
| 95 | pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); |
| 96 | } else if (iNumCells > 0) { |
| 97 | dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; |
| 98 | pWidget->SetLimit(iNumCells); |
| 99 | } else { |
| 100 | pWidget->SetLimit(iMaxChars); |
| 101 | } |
| 102 | dwExtendedStyle |= GetAlignment(); |
| 103 | m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); |
| 104 | m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); |
| 105 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 106 | |
| 107 | bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { |
| 108 | if (!PtInActiveRect(point)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 109 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 110 | if (!IsFocused()) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 111 | m_dwStatus |= XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 112 | UpdateFWLData(); |
| 113 | AddInvalidateRect(); |
| 114 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 115 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 116 | SetButtonDown(true); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 117 | CFWL_MessageMouse ms(nullptr, m_pNormalWidget); |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 118 | ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 119 | ms.m_dwFlags = dwFlags; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 120 | ms.m_pos = FWLToClient(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 121 | TranslateFWLMessage(&ms); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 122 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 123 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 124 | |
| 125 | bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { |
| 126 | if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 127 | return false; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 128 | if (!PtInActiveRect(point)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 129 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 130 | if (!IsFocused()) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 131 | m_dwStatus |= XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 132 | UpdateFWLData(); |
| 133 | AddInvalidateRect(); |
| 134 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 135 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 136 | SetButtonDown(true); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 137 | CFWL_MessageMouse ms(nullptr, nullptr); |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 138 | ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 139 | ms.m_dwFlags = dwFlags; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 140 | ms.m_pos = FWLToClient(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 141 | TranslateFWLMessage(&ms); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 142 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 143 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 144 | |
| 145 | bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { |
| 146 | if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 147 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 148 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 149 | GetDoc()->GetDocEnvironment()->PopupMenu(this, point); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 150 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 151 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 152 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 153 | bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 154 | m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 155 | if (!IsFocused()) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 156 | m_dwStatus |= XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 157 | UpdateFWLData(); |
| 158 | AddInvalidateRect(); |
| 159 | } |
| 160 | CXFA_FFWidget::OnSetFocus(pOldWidget); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 161 | CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 162 | TranslateFWLMessage(&ms); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 163 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 165 | bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 166 | CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 167 | TranslateFWLMessage(&ms); |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 168 | m_dwStatus &= ~XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 169 | SetEditScrollOffset(); |
| 170 | ProcessCommittedData(); |
| 171 | UpdateFWLData(); |
| 172 | AddInvalidateRect(); |
| 173 | CXFA_FFWidget::OnKillFocus(pNewWidget); |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 174 | m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 175 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 176 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 177 | bool CXFA_FFTextEdit::CommitData() { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 178 | CFX_WideString wsText = static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 179 | if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { |
| 180 | m_pDataAcc->UpdateUIDisplay(this); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 181 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 182 | } |
| 183 | ValidateNumberField(wsText); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 184 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 185 | } |
| 186 | void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { |
| 187 | CXFA_WidgetAcc* pAcc = GetDataAcc(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 188 | if (pAcc && pAcc->GetUIType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 189 | IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); |
| 190 | if (pAppProvider) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 191 | CFX_WideString wsSomField; |
| 192 | pAcc->GetNode()->GetSOMExpression(wsSomField); |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 193 | |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 194 | CFX_WideString wsMessage; |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 195 | wsMessage.Format(L"%s can not contain %s", wsText.c_str(), |
| 196 | wsSomField.c_str()); |
| 197 | pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), |
| 198 | XFA_MBICON_Error, XFA_MB_OK); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 202 | bool CXFA_FFTextEdit::IsDataChanged() { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 203 | return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 204 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 205 | uint32_t CXFA_FFTextEdit::GetAlignment() { |
| 206 | uint32_t dwExtendedStyle = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 207 | if (CXFA_Para para = m_pDataAcc->GetPara()) { |
| 208 | int32_t iHorz = para.GetHorizontalAlign(); |
| 209 | switch (iHorz) { |
| 210 | case XFA_ATTRIBUTEENUM_Center: |
| 211 | dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; |
| 212 | break; |
| 213 | case XFA_ATTRIBUTEENUM_Justify: |
| 214 | dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; |
| 215 | break; |
| 216 | case XFA_ATTRIBUTEENUM_JustifyAll: |
| 217 | break; |
| 218 | case XFA_ATTRIBUTEENUM_Radix: |
| 219 | break; |
| 220 | case XFA_ATTRIBUTEENUM_Right: |
| 221 | dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; |
| 222 | break; |
| 223 | default: |
| 224 | dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; |
| 225 | break; |
| 226 | } |
| 227 | int32_t iVert = para.GetVerticalAlign(); |
| 228 | switch (iVert) { |
| 229 | case XFA_ATTRIBUTEENUM_Middle: |
| 230 | dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; |
| 231 | break; |
| 232 | case XFA_ATTRIBUTEENUM_Bottom: |
| 233 | dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; |
| 234 | break; |
| 235 | default: |
| 236 | dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | return dwExtendedStyle; |
| 241 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 242 | bool CXFA_FFTextEdit::UpdateFWLData() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 243 | if (!m_pNormalWidget) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 244 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 245 | } |
| 246 | XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; |
| 247 | if (IsFocused()) { |
| 248 | eType = XFA_VALUEPICTURE_Edit; |
| 249 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 250 | bool bUpdate = false; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 251 | if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 252 | m_pDataAcc->GetNumberOfCells() < 0) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 253 | XFA_Element elementType = XFA_Element::Unknown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 254 | int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 255 | if (elementType == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; |
| 257 | } |
| 258 | if (((CFWL_Edit*)m_pNormalWidget)->GetLimit() != iMaxChars) { |
| 259 | ((CFWL_Edit*)m_pNormalWidget)->SetLimit(iMaxChars); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 260 | bUpdate = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 261 | } |
| 262 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 263 | if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 264 | int32_t nDataLen = 0; |
| 265 | if (eType == XFA_VALUEPICTURE_Edit) |
| 266 | m_pDataAcc->GetBarcodeAttribute_DataLength(nDataLen); |
| 267 | static_cast<CFWL_Edit*>(m_pNormalWidget)->SetLimit(nDataLen); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 268 | bUpdate = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 269 | } |
| 270 | CFX_WideString wsText; |
| 271 | m_pDataAcc->GetValue(wsText, eType); |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 272 | CFX_WideString wsOldText = |
| 273 | static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 274 | if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { |
| 275 | ((CFWL_Edit*)m_pNormalWidget)->SetText(wsText); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 276 | bUpdate = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 277 | } |
| 278 | if (bUpdate) { |
| 279 | m_pNormalWidget->Update(); |
| 280 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 281 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 282 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 283 | void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 284 | const CFX_WideString& wsChanged, |
| 285 | const CFX_WideString& wsPrevText) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 286 | m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 287 | CXFA_EventParam eParam; |
| 288 | eParam.m_eType = XFA_EVENT_Change; |
| 289 | eParam.m_wsChange = wsChanged; |
| 290 | eParam.m_pTarget = m_pDataAcc; |
| 291 | eParam.m_wsPrevText = wsPrevText; |
| 292 | CFWL_Edit* pEdit = ((CFWL_Edit*)m_pNormalWidget); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 293 | if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 294 | CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 295 | eParam.m_wsNewText = pDateTime->GetEditText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 296 | int32_t iSels = pDateTime->CountSelRanges(); |
| 297 | if (iSels) { |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 298 | eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 299 | } |
| 300 | } else { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 301 | eParam.m_wsNewText = pEdit->GetText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 302 | int32_t iSels = pEdit->CountSelRanges(); |
| 303 | if (iSels) { |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 304 | eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); |
| 308 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 309 | void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 310 | CXFA_EventParam eParam; |
| 311 | eParam.m_eType = XFA_EVENT_Full; |
| 312 | eParam.m_pTarget = m_pDataAcc; |
| 313 | m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); |
| 314 | } |
| 315 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 316 | bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { |
dsinclair | 89f8fa8 | 2016-09-14 06:11:08 -0700 | [diff] [blame] | 317 | if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 318 | return true; |
| 319 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 320 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 321 | |
| 322 | void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { |
| 323 | m_pOldDelegate->OnProcessMessage(pMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 324 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 325 | |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 326 | void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 327 | CXFA_FFField::OnProcessEvent(pEvent); |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 328 | switch (pEvent->GetType()) { |
| 329 | case CFWL_Event::Type::TextChanged: { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 330 | CFWL_EventTextChanged* event = |
| 331 | static_cast<CFWL_EventTextChanged*>(pEvent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 332 | CFX_WideString wsChange; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 333 | OnTextChanged(m_pNormalWidget, wsChange, event->wsPrevText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 334 | break; |
| 335 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 336 | case CFWL_Event::Type::TextFull: { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 337 | OnTextFull(m_pNormalWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 338 | break; |
| 339 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 340 | case CFWL_Event::Type::CheckWord: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 341 | CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 342 | CFWL_EventCheckWord* event = static_cast<CFWL_EventCheckWord*>(pEvent); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 343 | event->bCheckWord = CheckWord(event->bsWord.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 344 | break; |
| 345 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 346 | default: |
| 347 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 348 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 349 | m_pOldDelegate->OnProcessEvent(pEvent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 350 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 351 | |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 352 | void CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics* pGraphics, |
| 353 | const CFX_Matrix* pMatrix) { |
| 354 | m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 355 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 356 | |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 357 | CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) |
| 358 | : CXFA_FFTextEdit(pDataAcc) {} |
| 359 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 360 | CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 361 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 362 | bool CXFA_FFNumericEdit::LoadWidget() { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 363 | CFWL_Edit* pWidget = new CFWL_Edit( |
| 364 | GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 365 | m_pNormalWidget = pWidget; |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 366 | |
tsepez | 54ab234 | 2016-05-26 17:35:54 -0700 | [diff] [blame] | 367 | m_pNormalWidget->SetLayoutItem(this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 368 | CFWL_NoteDriver* pNoteDriver = |
| 369 | m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); |
| 370 | pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 371 | |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 372 | m_pOldDelegate = m_pNormalWidget->GetDelegate(); |
| 373 | m_pNormalWidget->SetDelegate(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 374 | m_pNormalWidget->LockUpdate(); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 375 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 376 | CFX_WideString wsText; |
| 377 | m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
| 378 | pWidget->SetText(wsText); |
| 379 | UpdateWidgetProperty(); |
| 380 | m_pNormalWidget->UnlockUpdate(); |
| 381 | return CXFA_FFField::LoadWidget(); |
| 382 | } |
| 383 | void CXFA_FFNumericEdit::UpdateWidgetProperty() { |
| 384 | CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; |
| 385 | if (!pWidget) { |
| 386 | return; |
| 387 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 388 | uint32_t dwExtendedStyle = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 389 | FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | |
| 390 | FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | |
| 391 | FWL_STYLEEXT_EDT_LastLineHeight; |
| 392 | dwExtendedStyle |= UpdateUIProperty(); |
| 393 | if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { |
| 394 | dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; |
| 395 | } |
| 396 | int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); |
| 397 | if (iNumCells > 0) { |
| 398 | dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; |
| 399 | pWidget->SetLimit(iNumCells); |
| 400 | } |
| 401 | dwExtendedStyle |= GetAlignment(); |
| 402 | if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || |
| 403 | !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { |
| 404 | dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; |
| 405 | } |
| 406 | m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); |
| 407 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 408 | |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 409 | void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 410 | if (pEvent->GetType() == CFWL_Event::Type::Validate) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 411 | CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 412 | event->bValidate = OnValidate(m_pNormalWidget, event->wsInsert); |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 413 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 414 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 415 | CXFA_FFTextEdit::OnProcessEvent(pEvent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 416 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 417 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 418 | bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 419 | CFX_WideString& wsText) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 420 | CFX_WideString wsPattern; |
| 421 | m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); |
| 422 | if (!wsPattern.IsEmpty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 423 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 424 | } |
| 425 | int32_t iLeads = 0; |
| 426 | m_pDataAcc->GetLeadDigits(iLeads); |
| 427 | int32_t iFracs = 0; |
| 428 | m_pDataAcc->GetFracDigits(iFracs); |
| 429 | CFX_WideString wsFormat; |
| 430 | CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc); |
| 431 | widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs); |
| 432 | return widgetValue.ValidateNumericTemp(wsText, wsFormat, |
| 433 | m_pDataAcc->GetLocal()); |
| 434 | } |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 435 | |
| 436 | CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) |
| 437 | : CXFA_FFTextEdit(pDataAcc) {} |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 438 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 439 | CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 440 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 441 | bool CXFA_FFPasswordEdit::LoadWidget() { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 442 | CFWL_Edit* pWidget = new CFWL_Edit( |
| 443 | GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 444 | m_pNormalWidget = pWidget; |
tsepez | 54ab234 | 2016-05-26 17:35:54 -0700 | [diff] [blame] | 445 | m_pNormalWidget->SetLayoutItem(this); |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 446 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 447 | CFWL_NoteDriver* pNoteDriver = |
| 448 | m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); |
| 449 | pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 450 | |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 451 | m_pOldDelegate = m_pNormalWidget->GetDelegate(); |
| 452 | m_pNormalWidget->SetDelegate(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 453 | m_pNormalWidget->LockUpdate(); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 454 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 455 | CFX_WideString wsText; |
| 456 | m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
| 457 | pWidget->SetText(wsText); |
| 458 | UpdateWidgetProperty(); |
| 459 | m_pNormalWidget->UnlockUpdate(); |
| 460 | return CXFA_FFField::LoadWidget(); |
| 461 | } |
| 462 | void CXFA_FFPasswordEdit::UpdateWidgetProperty() { |
| 463 | CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; |
| 464 | if (!pWidget) { |
| 465 | return; |
| 466 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 467 | uint32_t dwExtendedStyle = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 468 | FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | |
| 469 | FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; |
| 470 | dwExtendedStyle |= UpdateUIProperty(); |
| 471 | CFX_WideString wsPassWord; |
| 472 | m_pDataAcc->GetPasswordChar(wsPassWord); |
| 473 | if (!wsPassWord.IsEmpty()) { |
| 474 | pWidget->SetAliasChar(wsPassWord.GetAt(0)); |
| 475 | } |
| 476 | if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { |
| 477 | dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; |
| 478 | } |
| 479 | if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || |
| 480 | !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { |
| 481 | dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; |
| 482 | } |
| 483 | dwExtendedStyle |= GetAlignment(); |
| 484 | m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); |
| 485 | } |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 486 | CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) |
| 487 | : CXFA_FFTextEdit(pDataAcc) {} |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 488 | |
| 489 | CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {} |
| 490 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 491 | CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | if (bDrawFocus) |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 493 | return CFX_RectF(); |
| 494 | return CXFA_FFWidget::GetBBox(dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 497 | bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { |
dsinclair | 603f57b | 2016-12-14 06:25:02 -0800 | [diff] [blame] | 498 | return m_pNormalWidget && |
| 499 | static_cast<CFWL_DateTimePicker*>(m_pNormalWidget) |
| 500 | ->GetBBox() |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame^] | 501 | .Contains(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 502 | } |
dsinclair | 603f57b | 2016-12-14 06:25:02 -0800 | [diff] [blame] | 503 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 504 | bool CXFA_FFDateTimeEdit::LoadWidget() { |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 505 | CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp()); |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 506 | m_pNormalWidget = pWidget; |
tsepez | 54ab234 | 2016-05-26 17:35:54 -0700 | [diff] [blame] | 507 | m_pNormalWidget->SetLayoutItem(this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 508 | CFWL_NoteDriver* pNoteDriver = |
| 509 | m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); |
| 510 | pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 511 | |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 512 | m_pOldDelegate = m_pNormalWidget->GetDelegate(); |
| 513 | m_pNormalWidget->SetDelegate(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 514 | m_pNormalWidget->LockUpdate(); |
dsinclair | 9ec2217 | 2016-11-01 08:33:02 -0700 | [diff] [blame] | 515 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 516 | CFX_WideString wsText; |
| 517 | m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
tsepez | 31e4463 | 2016-04-15 16:04:24 -0700 | [diff] [blame] | 518 | pWidget->SetEditText(wsText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 519 | if (CXFA_Value value = m_pDataAcc->GetFormValue()) { |
| 520 | switch (value.GetChildValueClassID()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 521 | case XFA_Element::Date: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 522 | if (!wsText.IsEmpty()) { |
| 523 | CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); |
| 524 | CFX_Unitime date = lcValue.GetDate(); |
| 525 | if ((FX_UNITIME)date != 0) { |
| 526 | pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); |
| 527 | } |
| 528 | } |
| 529 | } break; |
| 530 | default: |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | UpdateWidgetProperty(); |
| 535 | m_pNormalWidget->UnlockUpdate(); |
| 536 | return CXFA_FFField::LoadWidget(); |
| 537 | } |
| 538 | void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { |
| 539 | CFWL_DateTimePicker* pWidget = (CFWL_DateTimePicker*)m_pNormalWidget; |
| 540 | if (!pWidget) { |
| 541 | return; |
| 542 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 543 | uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 544 | dwExtendedStyle |= UpdateUIProperty(); |
| 545 | dwExtendedStyle |= GetAlignment(); |
| 546 | m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 547 | uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 548 | int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); |
| 549 | if (iNumCells > 0) { |
| 550 | dwEditStyles |= FWL_STYLEEXT_EDT_CombText; |
| 551 | pWidget->SetEditLimit(iNumCells); |
| 552 | } |
| 553 | if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || |
| 554 | !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { |
| 555 | dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; |
| 556 | } |
| 557 | if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { |
| 558 | dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; |
| 559 | } |
| 560 | pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); |
| 561 | } |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 562 | uint32_t CXFA_FFDateTimeEdit::GetAlignment() { |
| 563 | uint32_t dwExtendedStyle = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 564 | if (CXFA_Para para = m_pDataAcc->GetPara()) { |
| 565 | int32_t iHorz = para.GetHorizontalAlign(); |
| 566 | switch (iHorz) { |
| 567 | case XFA_ATTRIBUTEENUM_Center: |
| 568 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; |
| 569 | break; |
| 570 | case XFA_ATTRIBUTEENUM_Justify: |
| 571 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; |
| 572 | break; |
| 573 | case XFA_ATTRIBUTEENUM_JustifyAll: |
| 574 | break; |
| 575 | case XFA_ATTRIBUTEENUM_Radix: |
| 576 | break; |
| 577 | case XFA_ATTRIBUTEENUM_Right: |
| 578 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; |
| 579 | break; |
| 580 | default: |
| 581 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; |
| 582 | break; |
| 583 | } |
| 584 | int32_t iVert = para.GetVerticalAlign(); |
| 585 | switch (iVert) { |
| 586 | case XFA_ATTRIBUTEENUM_Middle: |
| 587 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; |
| 588 | break; |
| 589 | case XFA_ATTRIBUTEENUM_Bottom: |
| 590 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; |
| 591 | break; |
| 592 | default: |
| 593 | dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | return dwExtendedStyle; |
| 598 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 599 | bool CXFA_FFDateTimeEdit::CommitData() { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 600 | CFX_WideString wsText = |
| 601 | static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 602 | if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { |
| 603 | m_pDataAcc->UpdateUIDisplay(this); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 604 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 605 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 606 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 607 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 608 | bool CXFA_FFDateTimeEdit::UpdateFWLData() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 609 | if (!m_pNormalWidget) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 610 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 611 | } |
| 612 | XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; |
| 613 | if (IsFocused()) { |
| 614 | eType = XFA_VALUEPICTURE_Edit; |
| 615 | } |
| 616 | CFX_WideString wsText; |
| 617 | m_pDataAcc->GetValue(wsText, eType); |
tsepez | 31e4463 | 2016-04-15 16:04:24 -0700 | [diff] [blame] | 618 | ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 619 | if (IsFocused() && !wsText.IsEmpty()) { |
| 620 | CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); |
| 621 | CFX_Unitime date = lcValue.GetDate(); |
| 622 | if (lcValue.IsValid()) { |
| 623 | if ((FX_UNITIME)date != 0) { |
| 624 | ((CFWL_DateTimePicker*)m_pNormalWidget) |
| 625 | ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | m_pNormalWidget->Update(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 630 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 631 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 632 | bool CXFA_FFDateTimeEdit::IsDataChanged() { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 633 | if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 634 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 635 | } |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 636 | CFX_WideString wsText = |
| 637 | static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 638 | CFX_WideString wsOldValue; |
| 639 | m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); |
| 640 | return wsOldValue != wsText; |
| 641 | } |
dsinclair | 522c3d4 | 2016-11-10 14:01:19 -0800 | [diff] [blame] | 642 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 643 | void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 644 | int32_t iYear, |
| 645 | int32_t iMonth, |
| 646 | int32_t iDay) { |
| 647 | CFX_WideString wsPicture; |
| 648 | m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); |
| 649 | CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); |
| 650 | CFX_Unitime dt; |
| 651 | dt.Set(iYear, iMonth, iDay); |
| 652 | date.SetDate(dt); |
| 653 | CFX_WideString wsDate; |
| 654 | date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), |
| 655 | XFA_VALUEPICTURE_Edit); |
| 656 | CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget; |
tsepez | 31e4463 | 2016-04-15 16:04:24 -0700 | [diff] [blame] | 657 | pDateTime->SetEditText(wsDate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 658 | pDateTime->Update(); |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 659 | GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 660 | CXFA_EventParam eParam; |
| 661 | eParam.m_eType = XFA_EVENT_Change; |
| 662 | eParam.m_pTarget = m_pDataAcc; |
| 663 | m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); |
| 664 | m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); |
| 665 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 666 | |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 667 | void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 668 | if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 669 | CFWL_EventSelectChanged* event = |
| 670 | static_cast<CFWL_EventSelectChanged*>(pEvent); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 671 | OnSelectChanged(m_pNormalWidget, event->iYear, event->iMonth, event->iDay); |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 672 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 673 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 674 | CXFA_FFTextEdit::OnProcessEvent(pEvent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 675 | } |