• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ffimageedit.h"
8 
9 #include "xfa/fwl/cfwl_app.h"
10 #include "xfa/fwl/cfwl_messagemouse.h"
11 #include "xfa/fwl/cfwl_notedriver.h"
12 #include "xfa/fwl/cfwl_picturebox.h"
13 #include "xfa/fxfa/app/xfa_fffield.h"
14 #include "xfa/fxfa/xfa_ffdoc.h"
15 #include "xfa/fxfa/xfa_ffdocview.h"
16 #include "xfa/fxfa/xfa_ffpageview.h"
17 #include "xfa/fxfa/xfa_ffwidget.h"
18 
CXFA_FFImageEdit(CXFA_WidgetAcc * pDataAcc)19 CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc)
20     : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {}
21 
~CXFA_FFImageEdit()22 CXFA_FFImageEdit::~CXFA_FFImageEdit() {
23   CXFA_FFImageEdit::UnloadWidget();
24 }
25 
LoadWidget()26 bool CXFA_FFImageEdit::LoadWidget() {
27   CFWL_PictureBox* pPictureBox = new CFWL_PictureBox(GetFWLApp());
28   m_pNormalWidget = pPictureBox;
29   m_pNormalWidget->SetLayoutItem(this);
30 
31   CFWL_NoteDriver* pNoteDriver =
32       m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
33   pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
34 
35   m_pOldDelegate = pPictureBox->GetDelegate();
36   pPictureBox->SetDelegate(this);
37 
38   CXFA_FFField::LoadWidget();
39   if (m_pDataAcc->GetImageEditImage()) {
40     return true;
41   }
42   UpdateFWLData();
43   return true;
44 }
UnloadWidget()45 void CXFA_FFImageEdit::UnloadWidget() {
46   m_pDataAcc->SetImageEditImage(nullptr);
47   CXFA_FFField::UnloadWidget();
48 }
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,uint32_t dwStatus)49 void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS,
50                                     CFX_Matrix* pMatrix,
51                                     uint32_t dwStatus) {
52   if (!IsMatchVisibleStatus(dwStatus))
53     return;
54 
55   CFX_Matrix mtRotate = GetRotateMatrix();
56   if (pMatrix)
57     mtRotate.Concat(*pMatrix);
58 
59   CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus);
60   CXFA_Border borderUI = m_pDataAcc->GetUIBorder();
61   DrawBorder(pGS, borderUI, m_rtUI, &mtRotate);
62   RenderCaption(pGS, &mtRotate);
63   CFX_DIBitmap* pDIBitmap = m_pDataAcc->GetImageEditImage();
64   if (!pDIBitmap)
65     return;
66 
67   CFX_RectF rtImage = m_pNormalWidget->GetWidgetRect();
68   int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left;
69   int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top;
70   if (CXFA_Para para = m_pDataAcc->GetPara()) {
71     iHorzAlign = para.GetHorizontalAlign();
72     iVertAlign = para.GetVerticalAlign();
73   }
74 
75   int32_t iAspect = XFA_ATTRIBUTEENUM_Fit;
76   if (CXFA_Value value = m_pDataAcc->GetFormValue()) {
77     if (CXFA_Image imageObj = value.GetImage())
78       iAspect = imageObj.GetAspect();
79   }
80 
81   int32_t iImageXDpi = 0;
82   int32_t iImageYDpi = 0;
83   m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi);
84   XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi,
85                 iImageYDpi, iHorzAlign, iVertAlign);
86 }
87 
OnLButtonDown(uint32_t dwFlags,const CFX_PointF & point)88 bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags,
89                                      const CFX_PointF& point) {
90   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open)
91     return false;
92   if (!PtInActiveRect(point))
93     return false;
94 
95   SetButtonDown(true);
96 
97   CFWL_MessageMouse ms(nullptr, m_pNormalWidget);
98   ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown;
99   ms.m_dwFlags = dwFlags;
100   ms.m_pos = FWLToClient(point);
101   TranslateFWLMessage(&ms);
102   return true;
103 }
104 
SetFWLRect()105 void CXFA_FFImageEdit::SetFWLRect() {
106   if (!m_pNormalWidget) {
107     return;
108   }
109   CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin();
110   CFX_RectF rtImage(m_rtUI);
111   rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width,
112                   rtUIMargin.height);
113   m_pNormalWidget->SetWidgetRect(rtImage);
114 }
CommitData()115 bool CXFA_FFImageEdit::CommitData() {
116   return true;
117 }
UpdateFWLData()118 bool CXFA_FFImageEdit::UpdateFWLData() {
119   m_pDataAcc->SetImageEditImage(nullptr);
120   m_pDataAcc->LoadImageEditImage();
121   return true;
122 }
123 
OnProcessMessage(CFWL_Message * pMessage)124 void CXFA_FFImageEdit::OnProcessMessage(CFWL_Message* pMessage) {
125   m_pOldDelegate->OnProcessMessage(pMessage);
126 }
127 
OnProcessEvent(CFWL_Event * pEvent)128 void CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) {
129   CXFA_FFField::OnProcessEvent(pEvent);
130   m_pOldDelegate->OnProcessEvent(pEvent);
131 }
132 
OnDrawWidget(CFX_Graphics * pGraphics,const CFX_Matrix * pMatrix)133 void CXFA_FFImageEdit::OnDrawWidget(CFX_Graphics* pGraphics,
134                                     const CFX_Matrix* pMatrix) {
135   m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);
136 }
137