Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_ffimageedit.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
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/cxfa_ffimageedit.h"
8
9#include <utility>
10
11#include "core/fxge/dib/cfx_dibitmap.h"
12#include "third_party/base/check.h"
13#include "v8/include/cppgc/visitor.h"
14#include "xfa/fwl/cfwl_app.h"
15#include "xfa/fwl/cfwl_messagemouse.h"
16#include "xfa/fwl/cfwl_notedriver.h"
17#include "xfa/fwl/cfwl_picturebox.h"
18#include "xfa/fxfa/cxfa_ffdoc.h"
19#include "xfa/fxfa/cxfa_ffdocview.h"
20#include "xfa/fxfa/cxfa_fffield.h"
21#include "xfa/fxfa/cxfa_ffpageview.h"
22#include "xfa/fxfa/cxfa_ffwidget.h"
23#include "xfa/fxfa/parser/cxfa_border.h"
24#include "xfa/fxfa/parser/cxfa_image.h"
25#include "xfa/fxfa/parser/cxfa_para.h"
26#include "xfa/fxfa/parser/cxfa_value.h"
27
28CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_Node* pNode) : CXFA_FFField(pNode) {}
29
30CXFA_FFImageEdit::~CXFA_FFImageEdit() = default;
31
32void CXFA_FFImageEdit::PreFinalize() {
33 m_pNode->SetEditImage(nullptr);
34}
35
36void CXFA_FFImageEdit::Trace(cppgc::Visitor* visitor) const {
37 CXFA_FFField::Trace(visitor);
38 visitor->Trace(m_pOldDelegate);
39}
40
41bool CXFA_FFImageEdit::LoadWidget() {
42 DCHECK(!IsLoaded());
43
44 CFWL_PictureBox* pPictureBox = cppgc::MakeGarbageCollected<CFWL_PictureBox>(
45 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp());
46 SetNormalWidget(pPictureBox);
47 pPictureBox->SetAdapterIface(this);
48
49 CFWL_NoteDriver* pNoteDriver = pPictureBox->GetFWLApp()->GetNoteDriver();
50 pNoteDriver->RegisterEventTarget(pPictureBox, pPictureBox);
51 m_pOldDelegate = pPictureBox->GetDelegate();
52 pPictureBox->SetDelegate(this);
53
55 if (!m_pNode->GetEditImage())
57
58 return true;
59}
60
61void CXFA_FFImageEdit::RenderWidget(CFGAS_GEGraphics* pGS,
62 const CFX_Matrix& matrix,
63 HighlightOption highlight) {
64 if (!HasVisibleStatus())
65 return;
66
67 CFX_Matrix mtRotate = GetRotateMatrix();
68 mtRotate.Concat(matrix);
69
70 CXFA_FFWidget::RenderWidget(pGS, mtRotate, highlight);
71 DrawBorder(pGS, m_pNode->GetUIBorder(), m_UIRect, mtRotate);
72 RenderCaption(pGS, mtRotate);
73 RetainPtr<CFX_DIBitmap> pDIBitmap = m_pNode->GetEditImage();
74 if (!pDIBitmap)
75 return;
76
77 CFX_RectF rtImage = GetNormalWidget()->GetWidgetRect();
78 XFA_AttributeValue iHorzAlign = XFA_AttributeValue::Left;
79 XFA_AttributeValue iVertAlign = XFA_AttributeValue::Top;
80 CXFA_Para* para = m_pNode->GetParaIfExists();
81 if (para) {
82 iHorzAlign = para->GetHorizontalAlign();
83 iVertAlign = para->GetVerticalAlign();
84 }
85
87 CXFA_Value* value = m_pNode->GetFormValueIfExists();
88 if (value) {
89 CXFA_Image* image = value->GetImageIfExists();
90 if (image)
91 iAspect = image->GetAspect();
92 }
93
94 XFA_DrawImage(pGS, rtImage, mtRotate, std::move(pDIBitmap), iAspect,
95 m_pNode->GetEditImageDpi(), iHorzAlign, iVertAlign);
96}
97
98bool CXFA_FFImageEdit::AcceptsFocusOnButtonDown(
99 Mask<XFA_FWL_KeyFlag> dwFlags,
100 const CFX_PointF& point,
101 CFWL_MessageMouse::MouseCommand command) {
102 if (command != CFWL_MessageMouse::MouseCommand::kLeftButtonDown)
103 return CXFA_FFField::AcceptsFocusOnButtonDown(dwFlags, point, command);
104
105 if (!m_pNode->IsOpenAccess())
106 return false;
107 if (!PtInActiveRect(point))
108 return false;
109
110 return true;
111}
112
113bool CXFA_FFImageEdit::OnLButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
114 const CFX_PointF& point) {
115 SetButtonDown(true);
116 CFWL_MessageMouse msg(GetNormalWidget(),
117 CFWL_MessageMouse::MouseCommand::kLeftButtonDown,
118 dwFlags, FWLToClient(point));
120 return true;
121}
122
123void CXFA_FFImageEdit::SetFWLRect() {
124 if (!GetNormalWidget())
125 return;
126
127 CFX_RectF rtUIMargin = m_pNode->GetUIMargin();
128 CFX_RectF rtImage(m_UIRect);
129 rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width,
130 rtUIMargin.height);
131 GetNormalWidget()->SetWidgetRect(rtImage);
132}
133
134bool CXFA_FFImageEdit::CommitData() {
135 return true;
136}
137
138bool CXFA_FFImageEdit::UpdateFWLData() {
139 m_pNode->SetEditImage(nullptr);
140 m_pNode->LoadEditImage(GetDoc());
141 return true;
142}
143
144void CXFA_FFImageEdit::OnProcessMessage(CFWL_Message* pMessage) {
145 m_pOldDelegate->OnProcessMessage(pMessage);
146}
147
148void CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) {
150 m_pOldDelegate->OnProcessEvent(pEvent);
151}
152
153void CXFA_FFImageEdit::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
154 const CFX_Matrix& matrix) {
155 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
156}
157
158FormFieldType CXFA_FFImageEdit::GetFormFieldType() {
159 return FormFieldType::kXFA_ImageField;
160}
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void SetDelegate(IFWL_WidgetDelegate *delegate)
void SetAdapterIface(AdapterIface *pItem)
CFWL_App * GetFWLApp() const
void Concat(const CFX_Matrix &right)
CFX_RectF(const CFX_RectF &other)=default
void Deflate(float off_left, float off_top, float off_right, float off_bottom)
CXFA_FFField(CXFA_Node *pNode)
CFX_PointF FWLToClient(const CFX_PointF &point)
CFX_RectF m_UIRect
bool LoadWidget() override
bool AcceptsFocusOnButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point, CFWL_MessageMouse::MouseCommand command) override
void SetNormalWidget(CFWL_Widget *widget)
bool PtInActiveRect(const CFX_PointF &point) override
void OnProcessEvent(CFWL_Event *pEvent) override
void RenderCaption(CFGAS_GEGraphics *pGS, const CFX_Matrix &pMatrix)
void SendMessageToFWLWidget(CFWL_Message *pMessage)
bool CommitData() override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void OnProcessEvent(CFWL_Event *pEvent) override
bool AcceptsFocusOnButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point, CFWL_MessageMouse::MouseCommand command) override
void Trace(cppgc::Visitor *visitor) const override
~CXFA_FFImageEdit() override
bool OnLButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
bool LoadWidget() override
void RenderWidget(CFGAS_GEGraphics *pGS, const CFX_Matrix &matrix, HighlightOption highlight) override
FormFieldType GetFormFieldType() override
void SetFWLRect() override
bool UpdateFWLData() override
void OnProcessMessage(CFWL_Message *pMessage) override
CFX_Matrix GetRotateMatrix() override
virtual void RenderWidget(CFGAS_GEGraphics *pGS, const CFX_Matrix &matrix, HighlightOption highlight)
bool HasVisibleStatus() const
void SetButtonDown(bool bSet)
XFA_AttributeValue GetAspect()
XFA_AttributeValue GetHorizontalAlign()
Definition cxfa_para.cpp:57
XFA_AttributeValue GetVerticalAlign()
Definition cxfa_para.cpp:63
CXFA_Image * GetImageIfExists() const
FormFieldType
XFA_FWL_KeyFlag
XFA_AttributeValue
Definition fxfa_basic.h:60
Definition heap.h:12