| 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_ffimageedit.h" | |
| 8 | |
| 9 #include "xfa/include/fwl/core/fwl_app.h" | |
| 10 #include "xfa/include/fwl/lightwidget/picturebox.h" | |
| 11 #include "xfa/src/fxfa/app/xfa_ffdoc.h" | |
| 12 #include "xfa/src/fxfa/app/xfa_ffdocview.h" | |
| 13 #include "xfa/src/fxfa/app/xfa_fffield.h" | |
| 14 #include "xfa/src/fxfa/app/xfa_ffpageview.h" | |
| 15 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
| 16 | |
| 17 CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_FFPageView* pPageView, | |
| 18 CXFA_WidgetAcc* pDataAcc) | |
| 19 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(NULL) {} | |
| 20 CXFA_FFImageEdit::~CXFA_FFImageEdit() { | |
| 21 CXFA_FFImageEdit::UnloadWidget(); | |
| 22 } | |
| 23 FX_BOOL CXFA_FFImageEdit::LoadWidget() { | |
| 24 CFWL_PictureBox* pPictureBox = new CFWL_PictureBox; | |
| 25 if (pPictureBox) { | |
| 26 pPictureBox->Initialize(); | |
| 27 } | |
| 28 m_pNormalWidget = (CFWL_Widget*)pPictureBox; | |
| 29 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | |
| 30 m_pNormalWidget->SetPrivateData(pWidget, this, NULL); | |
| 31 IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver(); | |
| 32 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | |
| 33 m_pOldDelegate = pPictureBox->SetDelegate(this); | |
| 34 CXFA_FFField::LoadWidget(); | |
| 35 if (m_pDataAcc->GetImageEditImage()) { | |
| 36 return TRUE; | |
| 37 } | |
| 38 UpdateFWLData(); | |
| 39 return TRUE; | |
| 40 } | |
| 41 void CXFA_FFImageEdit::UnloadWidget() { | |
| 42 m_pDataAcc->SetImageEditImage(NULL); | |
| 43 CXFA_FFField::UnloadWidget(); | |
| 44 } | |
| 45 void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS, | |
| 46 CFX_Matrix* pMatrix, | |
| 47 FX_DWORD dwStatus, | |
| 48 int32_t iRotate) { | |
| 49 if (!IsMatchVisibleStatus(dwStatus)) { | |
| 50 return; | |
| 51 } | |
| 52 CFX_Matrix mtRotate; | |
| 53 GetRotateMatrix(mtRotate); | |
| 54 if (pMatrix) { | |
| 55 mtRotate.Concat(*pMatrix); | |
| 56 } | |
| 57 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); | |
| 58 CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); | |
| 59 DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); | |
| 60 RenderCaption(pGS, &mtRotate); | |
| 61 if (CFX_DIBitmap* pDIBitmap = m_pDataAcc->GetImageEditImage()) { | |
| 62 CFX_RectF rtImage; | |
| 63 m_pNormalWidget->GetWidgetRect(rtImage); | |
| 64 int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; | |
| 65 int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; | |
| 66 if (CXFA_Para para = m_pDataAcc->GetPara()) { | |
| 67 iHorzAlign = para.GetHorizontalAlign(); | |
| 68 iVertAlign = para.GetVerticalAlign(); | |
| 69 } | |
| 70 int32_t iAspect = XFA_ATTRIBUTEENUM_Fit; | |
| 71 if (CXFA_Value value = m_pDataAcc->GetFormValue()) { | |
| 72 if (CXFA_Image imageObj = value.GetImage()) { | |
| 73 iAspect = imageObj.GetAspect(); | |
| 74 } | |
| 75 } | |
| 76 int32_t iImageXDpi = 0; | |
| 77 int32_t iImageYDpi = 0; | |
| 78 m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi); | |
| 79 XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, | |
| 80 iImageYDpi, iHorzAlign, iVertAlign); | |
| 81 } | |
| 82 } | |
| 83 FX_BOOL CXFA_FFImageEdit::OnLButtonDown(FX_DWORD dwFlags, | |
| 84 FX_FLOAT fx, | |
| 85 FX_FLOAT fy) { | |
| 86 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { | |
| 87 return FALSE; | |
| 88 } | |
| 89 if (!PtInActiveRect(fx, fy)) { | |
| 90 return FALSE; | |
| 91 } | |
| 92 SetButtonDown(TRUE); | |
| 93 CFWL_MsgMouse ms; | |
| 94 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDown; | |
| 95 ms.m_dwFlags = dwFlags; | |
| 96 ms.m_fx = fx; | |
| 97 ms.m_fy = fy; | |
| 98 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | |
| 99 FWLToClient(ms.m_fx, ms.m_fy); | |
| 100 TranslateFWLMessage(&ms); | |
| 101 IXFA_AppProvider* pAppProvider = GetAppProvider(); | |
| 102 if (!pAppProvider) { | |
| 103 return TRUE; | |
| 104 } | |
| 105 CFX_WideString wsTitle; | |
| 106 CFX_WideString wsFilter; | |
| 107 pAppProvider->LoadString(XFA_IDS_ImageFilter, wsFilter); | |
| 108 CFX_WideStringArray wsPathArray; | |
| 109 pAppProvider->ShowFileDialog(wsTitle, wsFilter, wsPathArray); | |
| 110 int32_t iSize = wsPathArray.GetSize(); | |
| 111 if (iSize < 1) { | |
| 112 return TRUE; | |
| 113 } | |
| 114 CFX_WideString wsFilePath = wsPathArray[0]; | |
| 115 FX_STRSIZE nLen = wsFilePath.GetLength(); | |
| 116 FX_STRSIZE nIndex = nLen - 1; | |
| 117 while (nIndex > 0 && wsFilePath[nIndex] != '.') { | |
| 118 nIndex--; | |
| 119 } | |
| 120 if (nIndex <= 0) { | |
| 121 return TRUE; | |
| 122 } | |
| 123 CFX_WideString wsContentType(L"image/"); | |
| 124 wsContentType += wsFilePath.Right(nLen - nIndex - 1); | |
| 125 wsContentType.MakeLower(); | |
| 126 FXCODEC_IMAGE_TYPE eImageType = XFA_GetImageType(wsContentType); | |
| 127 if (eImageType == FXCODEC_IMAGE_UNKNOWN) { | |
| 128 return TRUE; | |
| 129 } | |
| 130 CFX_WideString wsImage; | |
| 131 IFX_FileRead* pFileRead = FX_CreateFileRead(wsFilePath); | |
| 132 if (pFileRead) { | |
| 133 int32_t nDataSize = pFileRead->GetSize(); | |
| 134 if (nDataSize > 0) { | |
| 135 CFX_ByteString bsBuf; | |
| 136 FX_CHAR* pImageBuffer = bsBuf.GetBuffer(nDataSize); | |
| 137 pFileRead->ReadBlock(pImageBuffer, 0, nDataSize); | |
| 138 bsBuf.ReleaseBuffer(); | |
| 139 if (!bsBuf.IsEmpty()) { | |
| 140 FX_CHAR* pData = XFA_Base64Encode(bsBuf, nDataSize); | |
| 141 wsImage = CFX_WideString::FromLocal(pData); | |
| 142 FX_Free(pData); | |
| 143 } | |
| 144 } | |
| 145 m_pDataAcc->SetImageEditImage(NULL); | |
| 146 pFileRead->Release(); | |
| 147 } | |
| 148 m_pDataAcc->SetImageEdit(wsContentType, CFX_WideStringC(), wsImage); | |
| 149 m_pDataAcc->LoadImageEditImage(); | |
| 150 AddInvalidateRect(); | |
| 151 m_pDocView->SetChangeMark(); | |
| 152 return TRUE; | |
| 153 } | |
| 154 void CXFA_FFImageEdit::SetFWLRect() { | |
| 155 if (!m_pNormalWidget) { | |
| 156 return; | |
| 157 } | |
| 158 CFX_RectF rtUIMargin; | |
| 159 m_pDataAcc->GetUIMargin(rtUIMargin); | |
| 160 CFX_RectF rtImage(m_rtUI); | |
| 161 rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, | |
| 162 rtUIMargin.height); | |
| 163 m_pNormalWidget->SetWidgetRect(rtImage); | |
| 164 } | |
| 165 FX_BOOL CXFA_FFImageEdit::CommitData() { | |
| 166 return TRUE; | |
| 167 } | |
| 168 FX_BOOL CXFA_FFImageEdit::UpdateFWLData() { | |
| 169 m_pDataAcc->SetImageEditImage(NULL); | |
| 170 m_pDataAcc->LoadImageEditImage(); | |
| 171 return TRUE; | |
| 172 } | |
| 173 int32_t CXFA_FFImageEdit::OnProcessMessage(CFWL_Message* pMessage) { | |
| 174 return m_pOldDelegate->OnProcessMessage(pMessage); | |
| 175 } | |
| 176 FWL_ERR CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { | |
| 177 CXFA_FFField::OnProcessEvent(pEvent); | |
| 178 return m_pOldDelegate->OnProcessEvent(pEvent); | |
| 179 } | |
| 180 FWL_ERR CXFA_FFImageEdit::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 181 const CFX_Matrix* pMatrix) { | |
| 182 return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | |
| 183 } | |
| OLD | NEW |