OLD | NEW |
| (Empty) |
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/src/fxfa/app/xfa_fffield.h" | |
8 | |
9 #include "xfa/include/fwl/basewidget/fwl_edit.h" | |
10 #include "xfa/include/fwl/core/fwl_widgetmgr.h" | |
11 #include "xfa/include/fwl/lightwidget/edit.h" | |
12 #include "xfa/include/fwl/lightwidget/picturebox.h" | |
13 #include "xfa/src/fxfa/app/xfa_ffapp.h" | |
14 #include "xfa/src/fxfa/app/xfa_ffdoc.h" | |
15 #include "xfa/src/fxfa/app/xfa_ffdocview.h" | |
16 #include "xfa/src/fxfa/app/xfa_ffpageview.h" | |
17 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
18 #include "xfa/src/fxfa/app/xfa_fwltheme.h" | |
19 #include "xfa/src/fxfa/app/xfa_textlayout.h" | |
20 | |
21 CXFA_FFField::CXFA_FFField(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc) | |
22 : CXFA_FFWidget(pPageView, pDataAcc), m_pNormalWidget(NULL) { | |
23 m_rtUI.Set(0, 0, 0, 0); | |
24 m_rtCaption.Set(0, 0, 0, 0); | |
25 } | |
26 CXFA_FFField::~CXFA_FFField() { | |
27 CXFA_FFField::UnloadWidget(); | |
28 } | |
29 | |
30 FX_BOOL CXFA_FFField::GetBBox(CFX_RectF& rtBox, | |
31 FX_DWORD dwStatus, | |
32 FX_BOOL bDrawFocus) { | |
33 if (!bDrawFocus) | |
34 return CXFA_FFWidget::GetBBox(rtBox, dwStatus); | |
35 | |
36 XFA_ELEMENT type = (XFA_ELEMENT)m_pDataAcc->GetUIType(); | |
37 if (type == XFA_ELEMENT_Button || type == XFA_ELEMENT_CheckButton || | |
38 type == XFA_ELEMENT_ImageEdit || type == XFA_ELEMENT_Signature || | |
39 type == XFA_ELEMENT_ChoiceList) { | |
40 rtBox = m_rtUI; | |
41 CFX_Matrix mt; | |
42 GetRotateMatrix(mt); | |
43 mt.TransformRect(rtBox); | |
44 return TRUE; | |
45 } | |
46 return FALSE; | |
47 } | |
48 | |
49 void CXFA_FFField::RenderWidget(CFX_Graphics* pGS, | |
50 CFX_Matrix* pMatrix, | |
51 FX_DWORD dwStatus, | |
52 int32_t iRotate) { | |
53 if (!IsMatchVisibleStatus(dwStatus)) { | |
54 return; | |
55 } | |
56 CFX_Matrix mtRotate; | |
57 GetRotateMatrix(mtRotate); | |
58 if (pMatrix) { | |
59 mtRotate.Concat(*pMatrix); | |
60 } | |
61 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); | |
62 CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); | |
63 DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); | |
64 RenderCaption(pGS, &mtRotate); | |
65 DrawHighlight(pGS, &mtRotate, dwStatus, FALSE); | |
66 CFX_RectF rtWidget; | |
67 m_pNormalWidget->GetWidgetRect(rtWidget); | |
68 CFX_Matrix mt; | |
69 mt.Set(1, 0, 0, 1, rtWidget.left, rtWidget.top); | |
70 mt.Concat(mtRotate); | |
71 GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget->GetWidget(), | |
72 pGS, &mt); | |
73 } | |
74 void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS, | |
75 CFX_Matrix* pMatrix, | |
76 FX_DWORD dwStatus, | |
77 FX_BOOL bEllipse) { | |
78 if (m_rtUI.IsEmpty() || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
79 return; | |
80 } | |
81 if ((dwStatus & XFA_WIDGETSTATUS_Highlight) && | |
82 m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open) { | |
83 CXFA_FFDoc* pDoc = GetDoc(); | |
84 CFX_Color crHighlight(pDoc->GetDocProvider()->GetHighlightColor(pDoc)); | |
85 pGS->SetFillColor(&crHighlight); | |
86 CFX_Path path; | |
87 path.Create(); | |
88 if (bEllipse) { | |
89 path.AddEllipse(m_rtUI); | |
90 } else { | |
91 path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); | |
92 } | |
93 pGS->FillPath(&path, FXFILL_WINDING, pMatrix); | |
94 } | |
95 } | |
96 void CXFA_FFField::DrawFocus(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { | |
97 if (m_dwStatus & XFA_WIDGETSTATUS_Focused) { | |
98 CFX_Color cr(0xFF000000); | |
99 pGS->SetStrokeColor(&cr); | |
100 FX_FLOAT DashPattern[2] = {1, 1}; | |
101 pGS->SetLineDash(0.0f, DashPattern, 2); | |
102 pGS->SetLineWidth(0, FALSE); | |
103 CFX_Path path; | |
104 path.Create(); | |
105 path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); | |
106 pGS->StrokePath(&path, pMatrix); | |
107 } | |
108 } | |
109 void CXFA_FFField::SetFWLThemeProvider() { | |
110 if (m_pNormalWidget) { | |
111 m_pNormalWidget->m_pIface->SetThemeProvider(GetApp()->GetFWLTheme()); | |
112 } | |
113 } | |
114 FX_BOOL CXFA_FFField::IsLoaded() { | |
115 return m_pNormalWidget && CXFA_FFWidget::IsLoaded(); | |
116 } | |
117 FX_BOOL CXFA_FFField::LoadWidget() { | |
118 SetFWLThemeProvider(); | |
119 m_pDataAcc->LoadCaption(); | |
120 PerformLayout(); | |
121 return TRUE; | |
122 } | |
123 void CXFA_FFField::UnloadWidget() { | |
124 delete m_pNormalWidget; | |
125 m_pNormalWidget = nullptr; | |
126 } | |
127 void CXFA_FFField::SetEditScrollOffset() { | |
128 XFA_ELEMENT eType = m_pDataAcc->GetUIType(); | |
129 if (eType == XFA_ELEMENT_TextEdit || eType == XFA_ELEMENT_NumericEdit || | |
130 eType == XFA_ELEMENT_PasswordEdit) { | |
131 FX_FLOAT fScrollOffset = 0; | |
132 CXFA_FFField* pPrev = static_cast<CXFA_FFField*>(GetPrev()); | |
133 if (pPrev) { | |
134 CFX_RectF rtMargin; | |
135 m_pDataAcc->GetUIMargin(rtMargin); | |
136 fScrollOffset = -rtMargin.top; | |
137 } | |
138 while (pPrev) { | |
139 fScrollOffset += pPrev->m_rtUI.height; | |
140 pPrev = static_cast<CXFA_FFField*>(pPrev->GetPrev()); | |
141 } | |
142 ((CFWL_Edit*)m_pNormalWidget)->SetScrollOffset(fScrollOffset); | |
143 } | |
144 } | |
145 FX_BOOL CXFA_FFField::PerformLayout() { | |
146 CXFA_FFWidget::PerformLayout(); | |
147 CapPlacement(); | |
148 LayoutCaption(); | |
149 SetFWLRect(); | |
150 SetEditScrollOffset(); | |
151 if (m_pNormalWidget) { | |
152 m_pNormalWidget->Update(); | |
153 } | |
154 return TRUE; | |
155 } | |
156 void CXFA_FFField::CapPlacement() { | |
157 CFX_RectF rtWidget; | |
158 GetRectWithoutRotate(rtWidget); | |
159 CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); | |
160 if (mgWidget) { | |
161 CXFA_LayoutItem* pItem = this; | |
162 FX_FLOAT fLeftInset = 0, fRightInset = 0, fTopInset = 0, fBottomInset = 0; | |
163 mgWidget.GetLeftInset(fLeftInset); | |
164 mgWidget.GetRightInset(fRightInset); | |
165 mgWidget.GetTopInset(fTopInset); | |
166 mgWidget.GetBottomInset(fBottomInset); | |
167 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) { | |
168 rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); | |
169 } else { | |
170 if (pItem->GetPrev() == NULL) { | |
171 rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, 0); | |
172 } else if (pItem->GetNext() == NULL) { | |
173 rtWidget.Deflate(fLeftInset, 0, fRightInset, fBottomInset); | |
174 } else { | |
175 rtWidget.Deflate(fLeftInset, 0, fRightInset, 0); | |
176 } | |
177 } | |
178 } | |
179 XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; | |
180 FX_FLOAT fCapReserve = 0; | |
181 CXFA_Caption caption = m_pDataAcc->GetCaption(); | |
182 if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { | |
183 iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); | |
184 if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && GetPrev()) { | |
185 m_rtCaption.Set(0, 0, 0, 0); | |
186 } else if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && GetNext()) { | |
187 m_rtCaption.Set(0, 0, 0, 0); | |
188 } else { | |
189 fCapReserve = caption.GetReserve(); | |
190 CXFA_LayoutItem* pItem = this; | |
191 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) { | |
192 m_rtCaption.Set(rtWidget.left, rtWidget.top, rtWidget.width, | |
193 rtWidget.height); | |
194 } else { | |
195 pItem = pItem->GetFirst(); | |
196 pItem->GetRect(m_rtCaption); | |
197 pItem = pItem->GetNext(); | |
198 while (pItem) { | |
199 CFX_RectF rtRect; | |
200 pItem->GetRect(rtRect); | |
201 m_rtCaption.height += rtRect.Height(); | |
202 pItem = pItem->GetNext(); | |
203 } | |
204 XFA_RectWidthoutMargin(m_rtCaption, mgWidget); | |
205 } | |
206 CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); | |
207 if (fCapReserve <= 0 && pCapTextLayout) { | |
208 CFX_SizeF size; | |
209 CFX_SizeF minSize; | |
210 CFX_SizeF maxSize; | |
211 pCapTextLayout->CalcSize(minSize, maxSize, size); | |
212 if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || | |
213 iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { | |
214 fCapReserve = size.y; | |
215 } else { | |
216 fCapReserve = size.x; | |
217 } | |
218 } | |
219 } | |
220 } | |
221 m_rtUI = rtWidget; | |
222 switch (iCapPlacement) { | |
223 case XFA_ATTRIBUTEENUM_Left: { | |
224 m_rtCaption.width = fCapReserve; | |
225 CapLeftRightPlacement(caption, rtWidget, iCapPlacement); | |
226 m_rtUI.width -= fCapReserve; | |
227 m_rtUI.left += fCapReserve; | |
228 } break; | |
229 case XFA_ATTRIBUTEENUM_Top: { | |
230 m_rtCaption.height = fCapReserve; | |
231 CapTopBottomPlacement(caption, rtWidget, iCapPlacement); | |
232 m_rtUI.top += fCapReserve; | |
233 m_rtUI.height -= fCapReserve; | |
234 } break; | |
235 case XFA_ATTRIBUTEENUM_Right: { | |
236 m_rtCaption.left = m_rtCaption.right() - fCapReserve; | |
237 m_rtCaption.width = fCapReserve; | |
238 CapLeftRightPlacement(caption, rtWidget, iCapPlacement); | |
239 m_rtUI.width -= fCapReserve; | |
240 } break; | |
241 case XFA_ATTRIBUTEENUM_Bottom: { | |
242 m_rtCaption.top = m_rtCaption.bottom() - fCapReserve; | |
243 m_rtCaption.height = fCapReserve; | |
244 CapTopBottomPlacement(caption, rtWidget, iCapPlacement); | |
245 m_rtUI.height -= fCapReserve; | |
246 } break; | |
247 case XFA_ATTRIBUTEENUM_Inline: | |
248 break; | |
249 default: | |
250 break; | |
251 } | |
252 CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); | |
253 if (borderUI) { | |
254 CXFA_Margin margin = borderUI.GetMargin(); | |
255 if (margin) { | |
256 XFA_RectWidthoutMargin(m_rtUI, margin); | |
257 } | |
258 } | |
259 m_rtUI.Normalize(); | |
260 } | |
261 void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, | |
262 const CFX_RectF& rtWidget, | |
263 int32_t iCapPlacement) { | |
264 CFX_RectF rtUIMargin; | |
265 m_pDataAcc->GetUIMargin(rtUIMargin); | |
266 m_rtCaption.left += rtUIMargin.left; | |
267 if (CXFA_Margin mgCap = caption.GetMargin()) { | |
268 XFA_RectWidthoutMargin(m_rtCaption, mgCap); | |
269 if (m_rtCaption.height < 0) { | |
270 m_rtCaption.top += m_rtCaption.height; | |
271 } | |
272 } | |
273 FX_FLOAT fWidth = rtUIMargin.left + rtUIMargin.width; | |
274 FX_FLOAT fHeight = m_rtCaption.height + rtUIMargin.top + rtUIMargin.height; | |
275 if (fWidth > rtWidget.width) { | |
276 m_rtUI.width += fWidth - rtWidget.width; | |
277 } | |
278 if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { | |
279 m_rtUI.height = XFA_MINUI_HEIGHT; | |
280 m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; | |
281 } else if (fHeight > rtWidget.height) { | |
282 m_rtUI.height += fHeight - rtWidget.height; | |
283 if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { | |
284 m_rtCaption.top += fHeight - rtWidget.height; | |
285 } | |
286 } | |
287 } | |
288 void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, | |
289 const CFX_RectF& rtWidget, | |
290 int32_t iCapPlacement) { | |
291 CFX_RectF rtUIMargin; | |
292 m_pDataAcc->GetUIMargin(rtUIMargin); | |
293 m_rtCaption.top += rtUIMargin.top; | |
294 m_rtCaption.height -= rtUIMargin.top; | |
295 if (CXFA_Margin mgCap = caption.GetMargin()) { | |
296 XFA_RectWidthoutMargin(m_rtCaption, mgCap); | |
297 if (m_rtCaption.height < 0) { | |
298 m_rtCaption.top += m_rtCaption.height; | |
299 } | |
300 } | |
301 FX_FLOAT fWidth = m_rtCaption.width + rtUIMargin.left + rtUIMargin.width; | |
302 FX_FLOAT fHeight = rtUIMargin.top + rtUIMargin.height; | |
303 if (fWidth > rtWidget.width) { | |
304 m_rtUI.width += fWidth - rtWidget.width; | |
305 if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) { | |
306 m_rtCaption.left += fWidth - rtWidget.width; | |
307 } | |
308 } | |
309 if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { | |
310 m_rtUI.height = XFA_MINUI_HEIGHT; | |
311 m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; | |
312 } else if (fHeight > rtWidget.height) { | |
313 m_rtUI.height += fHeight - rtWidget.height; | |
314 } | |
315 } | |
316 void CXFA_FFField::UpdateFWL() { | |
317 if (m_pNormalWidget) { | |
318 m_pNormalWidget->Update(); | |
319 } | |
320 } | |
321 FX_DWORD CXFA_FFField::UpdateUIProperty() { | |
322 CXFA_Node* pUiNode = m_pDataAcc->GetUIChild(); | |
323 FX_DWORD dwStyle = 0; | |
324 if (pUiNode && pUiNode->GetClassID() == XFA_ELEMENT_DefaultUi) { | |
325 dwStyle = FWL_STYLEEXT_EDT_ReadOnly; | |
326 } | |
327 return dwStyle; | |
328 } | |
329 void CXFA_FFField::SetFWLRect() { | |
330 if (!m_pNormalWidget) { | |
331 return; | |
332 } | |
333 CFX_RectF rtUi = m_rtUI; | |
334 if (rtUi.width < 1.0) { | |
335 FXSYS_assert(rtUi.width < 1.0); | |
336 rtUi.width = 1.0; | |
337 } | |
338 if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
339 FX_FLOAT fFontSize = m_pDataAcc->GetFontSize(); | |
340 if (rtUi.height < fFontSize) { | |
341 rtUi.height = fFontSize; | |
342 } | |
343 } | |
344 m_pNormalWidget->SetWidgetRect(rtUi); | |
345 } | |
346 FX_BOOL CXFA_FFField::OnMouseEnter() { | |
347 if (!m_pNormalWidget) { | |
348 return FALSE; | |
349 } | |
350 CFWL_MsgMouse ms; | |
351 ms.m_dwCmd = FWL_MSGMOUSECMD_MouseEnter; | |
352 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
353 ms.m_pSrcTarget = NULL; | |
354 TranslateFWLMessage(&ms); | |
355 return TRUE; | |
356 } | |
357 FX_BOOL CXFA_FFField::OnMouseExit() { | |
358 if (!m_pNormalWidget) { | |
359 return FALSE; | |
360 } | |
361 CFWL_MsgMouse ms; | |
362 ms.m_dwCmd = FWL_MSGMOUSECMD_MouseLeave; | |
363 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
364 TranslateFWLMessage(&ms); | |
365 return TRUE; | |
366 } | |
367 void CXFA_FFField::FWLToClient(FX_FLOAT& fx, FX_FLOAT& fy) { | |
368 if (!m_pNormalWidget) { | |
369 return; | |
370 } | |
371 CFX_RectF rtWidget; | |
372 m_pNormalWidget->GetWidgetRect(rtWidget); | |
373 fx -= rtWidget.left; | |
374 fy -= rtWidget.top; | |
375 } | |
376 FX_BOOL CXFA_FFField::OnLButtonDown(FX_DWORD dwFlags, | |
377 FX_FLOAT fx, | |
378 FX_FLOAT fy) { | |
379 if (!m_pNormalWidget) { | |
380 return FALSE; | |
381 } | |
382 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || | |
383 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
384 return FALSE; | |
385 } | |
386 if (!PtInActiveRect(fx, fy)) { | |
387 return FALSE; | |
388 } | |
389 SetButtonDown(TRUE); | |
390 CFWL_MsgMouse ms; | |
391 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDown; | |
392 ms.m_dwFlags = dwFlags; | |
393 ms.m_fx = fx; | |
394 ms.m_fy = fy; | |
395 FWLToClient(ms.m_fx, ms.m_fy); | |
396 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
397 TranslateFWLMessage(&ms); | |
398 return TRUE; | |
399 } | |
400 FX_BOOL CXFA_FFField::OnLButtonUp(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) { | |
401 if (!m_pNormalWidget) { | |
402 return FALSE; | |
403 } | |
404 if (!IsButtonDown()) { | |
405 return FALSE; | |
406 } | |
407 SetButtonDown(FALSE); | |
408 CFWL_MsgMouse ms; | |
409 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonUp; | |
410 ms.m_dwFlags = dwFlags; | |
411 ms.m_fx = fx; | |
412 ms.m_fy = fy; | |
413 FWLToClient(ms.m_fx, ms.m_fy); | |
414 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
415 TranslateFWLMessage(&ms); | |
416 return TRUE; | |
417 } | |
418 FX_BOOL CXFA_FFField::OnLButtonDblClk(FX_DWORD dwFlags, | |
419 FX_FLOAT fx, | |
420 FX_FLOAT fy) { | |
421 if (!m_pNormalWidget) { | |
422 return FALSE; | |
423 } | |
424 CFWL_MsgMouse ms; | |
425 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDblClk; | |
426 ms.m_dwFlags = dwFlags; | |
427 ms.m_fx = fx; | |
428 ms.m_fy = fy; | |
429 FWLToClient(ms.m_fx, ms.m_fy); | |
430 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
431 TranslateFWLMessage(&ms); | |
432 return TRUE; | |
433 } | |
434 FX_BOOL CXFA_FFField::OnMouseMove(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) { | |
435 if (!m_pNormalWidget) { | |
436 return FALSE; | |
437 } | |
438 CFWL_MsgMouse ms; | |
439 ms.m_dwCmd = FWL_MSGMOUSECMD_MouseMove; | |
440 ms.m_dwFlags = dwFlags; | |
441 ms.m_fx = fx; | |
442 ms.m_fy = fy; | |
443 FWLToClient(ms.m_fx, ms.m_fy); | |
444 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
445 TranslateFWLMessage(&ms); | |
446 return TRUE; | |
447 } | |
448 FX_BOOL CXFA_FFField::OnMouseWheel(FX_DWORD dwFlags, | |
449 int16_t zDelta, | |
450 FX_FLOAT fx, | |
451 FX_FLOAT fy) { | |
452 return FALSE; | |
453 if (!m_pNormalWidget) { | |
454 return FALSE; | |
455 } | |
456 CFWL_MsgMouseWheel ms; | |
457 ms.m_dwFlags = dwFlags; | |
458 ms.m_fx = fx; | |
459 ms.m_fy = fy; | |
460 FWLToClient(ms.m_fx, ms.m_fy); | |
461 ms.m_fDeltaX = zDelta; | |
462 ms.m_fDeltaY = 0; | |
463 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
464 TranslateFWLMessage(&ms); | |
465 return TRUE; | |
466 } | |
467 FX_BOOL CXFA_FFField::OnRButtonDown(FX_DWORD dwFlags, | |
468 FX_FLOAT fx, | |
469 FX_FLOAT fy) { | |
470 if (!m_pNormalWidget) { | |
471 return FALSE; | |
472 } | |
473 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || | |
474 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
475 return FALSE; | |
476 } | |
477 if (!PtInActiveRect(fx, fy)) { | |
478 return FALSE; | |
479 } | |
480 SetButtonDown(TRUE); | |
481 CFWL_MsgMouse ms; | |
482 ms.m_dwCmd = FWL_MSGMOUSECMD_RButtonDown; | |
483 ms.m_dwFlags = dwFlags; | |
484 ms.m_fx = fx; | |
485 ms.m_fy = fy; | |
486 FWLToClient(ms.m_fx, ms.m_fy); | |
487 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
488 TranslateFWLMessage(&ms); | |
489 return TRUE; | |
490 } | |
491 FX_BOOL CXFA_FFField::OnRButtonUp(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) { | |
492 if (!m_pNormalWidget) { | |
493 return FALSE; | |
494 } | |
495 if (!IsButtonDown()) { | |
496 return FALSE; | |
497 } | |
498 SetButtonDown(FALSE); | |
499 CFWL_MsgMouse ms; | |
500 ms.m_dwCmd = FWL_MSGMOUSECMD_RButtonUp; | |
501 ms.m_dwFlags = dwFlags; | |
502 ms.m_fx = fx; | |
503 ms.m_fy = fy; | |
504 FWLToClient(ms.m_fx, ms.m_fy); | |
505 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
506 TranslateFWLMessage(&ms); | |
507 return TRUE; | |
508 } | |
509 FX_BOOL CXFA_FFField::OnRButtonDblClk(FX_DWORD dwFlags, | |
510 FX_FLOAT fx, | |
511 FX_FLOAT fy) { | |
512 if (!m_pNormalWidget) { | |
513 return FALSE; | |
514 } | |
515 CFWL_MsgMouse ms; | |
516 ms.m_dwCmd = FWL_MSGMOUSECMD_RButtonDblClk; | |
517 ms.m_dwFlags = dwFlags; | |
518 ms.m_fx = fx; | |
519 ms.m_fy = fy; | |
520 FWLToClient(ms.m_fx, ms.m_fy); | |
521 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
522 TranslateFWLMessage(&ms); | |
523 return TRUE; | |
524 } | |
525 | |
526 FX_BOOL CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { | |
527 CXFA_FFWidget::OnSetFocus(pOldWidget); | |
528 if (!m_pNormalWidget) { | |
529 return FALSE; | |
530 } | |
531 CFWL_MsgSetFocus ms; | |
532 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
533 ms.m_pSrcTarget = NULL; | |
534 TranslateFWLMessage(&ms); | |
535 m_dwStatus |= XFA_WIDGETSTATUS_Focused; | |
536 AddInvalidateRect(); | |
537 return TRUE; | |
538 } | |
539 FX_BOOL CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { | |
540 if (!m_pNormalWidget) { | |
541 return CXFA_FFWidget::OnKillFocus(pNewWidget); | |
542 } | |
543 CFWL_MsgKillFocus ms; | |
544 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
545 ms.m_pSrcTarget = NULL; | |
546 TranslateFWLMessage(&ms); | |
547 m_dwStatus &= ~XFA_WIDGETSTATUS_Focused; | |
548 AddInvalidateRect(); | |
549 CXFA_FFWidget::OnKillFocus(pNewWidget); | |
550 return TRUE; | |
551 } | |
552 FX_BOOL CXFA_FFField::OnKeyDown(FX_DWORD dwKeyCode, FX_DWORD dwFlags) { | |
553 if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
554 return FALSE; | |
555 } | |
556 CFWL_MsgKey ms; | |
557 ms.m_dwCmd = FWL_MSGKEYCMD_KeyDown; | |
558 ms.m_dwFlags = dwFlags; | |
559 ms.m_dwKeyCode = dwKeyCode; | |
560 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
561 ms.m_pSrcTarget = NULL; | |
562 TranslateFWLMessage(&ms); | |
563 return TRUE; | |
564 } | |
565 FX_BOOL CXFA_FFField::OnKeyUp(FX_DWORD dwKeyCode, FX_DWORD dwFlags) { | |
566 if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
567 return FALSE; | |
568 } | |
569 CFWL_MsgKey ms; | |
570 ms.m_dwCmd = FWL_MSGKEYCMD_KeyUp; | |
571 ms.m_dwFlags = dwFlags; | |
572 ms.m_dwKeyCode = dwKeyCode; | |
573 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
574 ms.m_pSrcTarget = NULL; | |
575 TranslateFWLMessage(&ms); | |
576 return TRUE; | |
577 } | |
578 FX_BOOL CXFA_FFField::OnChar(FX_DWORD dwChar, FX_DWORD dwFlags) { | |
579 if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | |
580 return FALSE; | |
581 } | |
582 if (dwChar == FWL_VKEY_Tab) { | |
583 return TRUE; | |
584 } | |
585 if (!m_pNormalWidget) { | |
586 return FALSE; | |
587 } | |
588 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { | |
589 return FALSE; | |
590 } | |
591 CFWL_MsgKey ms; | |
592 ms.m_dwCmd = FWL_MSGKEYCMD_Char; | |
593 ms.m_dwFlags = dwFlags; | |
594 ms.m_dwKeyCode = dwChar; | |
595 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
596 ms.m_pSrcTarget = NULL; | |
597 TranslateFWLMessage(&ms); | |
598 return TRUE; | |
599 } | |
600 FX_DWORD CXFA_FFField::OnHitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
601 if (m_pNormalWidget) { | |
602 FX_FLOAT ffx = fx, ffy = fy; | |
603 FWLToClient(ffx, ffy); | |
604 FX_DWORD dwWidgetHit = m_pNormalWidget->HitTest(ffx, ffy); | |
605 if (dwWidgetHit != FWL_WGTHITTEST_Unknown) { | |
606 return FWL_WGTHITTEST_Client; | |
607 } | |
608 } | |
609 CFX_RectF rtBox; | |
610 GetRectWithoutRotate(rtBox); | |
611 if (!rtBox.Contains(fx, fy)) { | |
612 return FWL_WGTHITTEST_Unknown; | |
613 } | |
614 if (m_rtCaption.Contains(fx, fy)) { | |
615 return FWL_WGTHITTEST_Titlebar; | |
616 } | |
617 return FWL_WGTHITTEST_Border; | |
618 } | |
619 FX_BOOL CXFA_FFField::OnSetCursor(FX_FLOAT fx, FX_FLOAT fy) { | |
620 return TRUE; | |
621 } | |
622 FX_BOOL CXFA_FFField::PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy) { | |
623 if (!m_pNormalWidget) { | |
624 return FALSE; | |
625 } | |
626 CFX_RectF rtWidget; | |
627 m_pNormalWidget->GetWidgetRect(rtWidget); | |
628 if (rtWidget.Contains(fx, fy)) { | |
629 return TRUE; | |
630 } | |
631 return FALSE; | |
632 } | |
633 void CXFA_FFField::LayoutCaption() { | |
634 CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); | |
635 if (!pCapTextLayout) | |
636 return; | |
637 | |
638 FX_FLOAT fHeight = 0; | |
639 pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height), | |
640 &fHeight); | |
641 if (m_rtCaption.height < fHeight) | |
642 m_rtCaption.height = fHeight; | |
643 } | |
644 void CXFA_FFField::RenderCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { | |
645 CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); | |
646 if (!pCapTextLayout) { | |
647 return; | |
648 } | |
649 CXFA_Caption caption = m_pDataAcc->GetCaption(); | |
650 if (caption && caption.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { | |
651 if (!pCapTextLayout->IsLoaded()) { | |
652 pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height)); | |
653 } | |
654 CFX_RectF rtWidget; | |
655 GetRectWithoutRotate(rtWidget); | |
656 CFX_RectF rtClip = m_rtCaption; | |
657 rtClip.Intersect(rtWidget); | |
658 CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); | |
659 CFX_Matrix mt; | |
660 mt.Set(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); | |
661 if (pMatrix) { | |
662 pMatrix->TransformRect(rtClip); | |
663 mt.Concat(*pMatrix); | |
664 } | |
665 pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); | |
666 } | |
667 } | |
668 FX_BOOL CXFA_FFField::ProcessCommittedData() { | |
669 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { | |
670 return FALSE; | |
671 } | |
672 if (!IsDataChanged()) { | |
673 return FALSE; | |
674 } | |
675 if (CalculateOverride() != 1) { | |
676 return FALSE; | |
677 } | |
678 if (!CommitData()) { | |
679 return FALSE; | |
680 } | |
681 m_pDocView->SetChangeMark(); | |
682 m_pDocView->AddValidateWidget(m_pDataAcc); | |
683 return TRUE; | |
684 } | |
685 int32_t CXFA_FFField::CalculateOverride() { | |
686 CXFA_WidgetAcc* pAcc = m_pDataAcc->GetExclGroup(); | |
687 if (!pAcc) { | |
688 return CalculateWidgetAcc(m_pDataAcc); | |
689 } | |
690 if (CalculateWidgetAcc(pAcc) == 0) { | |
691 return 0; | |
692 } | |
693 CXFA_Node* pNode = pAcc->GetExclGroupFirstMember(); | |
694 if (!pNode) { | |
695 return 1; | |
696 } | |
697 CXFA_WidgetAcc* pWidgetAcc = NULL; | |
698 while (pNode) { | |
699 pWidgetAcc = (CXFA_WidgetAcc*)pNode->GetWidgetData(); | |
700 if (!pWidgetAcc) { | |
701 return 1; | |
702 } | |
703 if (CalculateWidgetAcc(pWidgetAcc) == 0) { | |
704 return 0; | |
705 } | |
706 pNode = pWidgetAcc->GetExclGroupNextMember(pNode); | |
707 } | |
708 return 1; | |
709 } | |
710 int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { | |
711 CXFA_Calculate calc = pAcc->GetCalculate(); | |
712 if (!calc) { | |
713 return 1; | |
714 } | |
715 XFA_VERSION version = pAcc->GetDoc()->GetXFADoc()->GetCurVersionMode(); | |
716 if (calc) { | |
717 int32_t iOverride = calc.GetOverride(); | |
718 switch (iOverride) { | |
719 case XFA_ATTRIBUTEENUM_Error: { | |
720 if (version <= XFA_VERSION_204) { | |
721 return 1; | |
722 } | |
723 IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); | |
724 if (pAppProvider) { | |
725 CFX_WideString wsMessage; | |
726 CFX_WideString wsWarning; | |
727 pAppProvider->LoadString(XFA_IDS_NotModifyField, wsWarning); | |
728 wsMessage += wsWarning; | |
729 CFX_WideString wsTitle; | |
730 pAppProvider->LoadString(XFA_IDS_CalcOverride, wsTitle); | |
731 pAppProvider->MsgBox(wsMessage, wsTitle, XFA_MBICON_Warning, | |
732 XFA_MB_OK); | |
733 } | |
734 } | |
735 return 0; | |
736 case XFA_ATTRIBUTEENUM_Warning: { | |
737 if (version <= XFA_VERSION_204) { | |
738 CXFA_Script script = calc.GetScript(); | |
739 if (!script) { | |
740 return 1; | |
741 } | |
742 CFX_WideString wsExpression; | |
743 script.GetExpression(wsExpression); | |
744 if (wsExpression.IsEmpty()) { | |
745 return 1; | |
746 } | |
747 } | |
748 if (pAcc->GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { | |
749 return 1; | |
750 } | |
751 IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); | |
752 if (pAppProvider) { | |
753 CFX_WideString wsMessage; | |
754 calc.GetMessageText(wsMessage); | |
755 if (!wsMessage.IsEmpty()) { | |
756 wsMessage += L"\r\n"; | |
757 } | |
758 CFX_WideString wsWarning; | |
759 pAppProvider->LoadString(XFA_IDS_ModifyField, wsWarning); | |
760 wsMessage += wsWarning; | |
761 CFX_WideString wsTitle; | |
762 pAppProvider->LoadString(XFA_IDS_CalcOverride, wsTitle); | |
763 if (pAppProvider->MsgBox(wsMessage, wsTitle, XFA_MBICON_Warning, | |
764 XFA_MB_YesNo) == XFA_IDYes) { | |
765 pAcc->GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, TRUE, FALSE); | |
766 return 1; | |
767 } | |
768 } | |
769 return 0; | |
770 } | |
771 case XFA_ATTRIBUTEENUM_Ignore: | |
772 return 0; | |
773 case XFA_ATTRIBUTEENUM_Disabled: | |
774 pAcc->GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, TRUE, FALSE); | |
775 default: | |
776 return 1; | |
777 } | |
778 } | |
779 return 1; | |
780 } | |
781 FX_BOOL CXFA_FFField::CommitData() { | |
782 return FALSE; | |
783 } | |
784 FX_BOOL CXFA_FFField::IsDataChanged() { | |
785 return FALSE; | |
786 } | |
787 void CXFA_FFField::TranslateFWLMessage(CFWL_Message* pMessage) { | |
788 GetApp()->GetWidgetMgrDelegate()->OnProcessMessageToForm(pMessage); | |
789 } | |
790 int32_t CXFA_FFField::OnProcessMessage(CFWL_Message* pMessage) { | |
791 return FWL_ERR_Succeeded; | |
792 } | |
793 FWL_ERR CXFA_FFField::OnProcessEvent(CFWL_Event* pEvent) { | |
794 FX_DWORD dwEventID = pEvent->GetClassID(); | |
795 switch (dwEventID) { | |
796 case FWL_EVTHASH_Mouse: { | |
797 CFWL_EvtMouse* event = (CFWL_EvtMouse*)pEvent; | |
798 if (event->m_dwCmd == FWL_MSGMOUSECMD_MouseEnter) { | |
799 CXFA_EventParam eParam; | |
800 eParam.m_eType = XFA_EVENT_MouseEnter; | |
801 eParam.m_pTarget = m_pDataAcc; | |
802 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseEnter, &eParam); | |
803 } else if (event->m_dwCmd == FWL_MSGMOUSECMD_MouseLeave) { | |
804 CXFA_EventParam eParam; | |
805 eParam.m_eType = XFA_EVENT_MouseExit; | |
806 eParam.m_pTarget = m_pDataAcc; | |
807 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseExit, &eParam); | |
808 } else if (event->m_dwCmd == FWL_MSGMOUSECMD_LButtonDown) { | |
809 CXFA_EventParam eParam; | |
810 eParam.m_eType = XFA_EVENT_MouseDown; | |
811 eParam.m_pTarget = m_pDataAcc; | |
812 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseDown, &eParam); | |
813 } else if (event->m_dwCmd == FWL_MSGMOUSECMD_LButtonUp) { | |
814 CXFA_EventParam eParam; | |
815 eParam.m_eType = XFA_EVENT_MouseUp; | |
816 eParam.m_pTarget = m_pDataAcc; | |
817 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseUp, &eParam); | |
818 } | |
819 break; | |
820 } | |
821 case FWL_EVTHASH_Click: { | |
822 CXFA_EventParam eParam; | |
823 eParam.m_eType = XFA_EVENT_Click; | |
824 eParam.m_pTarget = m_pDataAcc; | |
825 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); | |
826 break; | |
827 } | |
828 default: {} | |
829 } | |
830 return FWL_ERR_Succeeded; | |
831 } | |
832 FWL_ERR CXFA_FFField::OnDrawWidget(CFX_Graphics* pGraphics, | |
833 const CFX_Matrix* pMatrix) { | |
834 return FWL_ERR_Succeeded; | |
835 } | |
OLD | NEW |