OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/app/xfa_ffimageedit.h" | 7 #include "xfa/fxfa/app/xfa_ffimageedit.h" |
8 | 8 |
9 #include "xfa/fwl/core/cfwl_message.h" | 9 #include "xfa/fwl/core/cfwl_message.h" |
10 #include "xfa/fwl/core/ifwl_app.h" | 10 #include "xfa/fwl/core/ifwl_app.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 iAspect = imageObj.GetAspect(); | 75 iAspect = imageObj.GetAspect(); |
76 } | 76 } |
77 } | 77 } |
78 int32_t iImageXDpi = 0; | 78 int32_t iImageXDpi = 0; |
79 int32_t iImageYDpi = 0; | 79 int32_t iImageYDpi = 0; |
80 m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi); | 80 m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi); |
81 XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, | 81 XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, |
82 iImageYDpi, iHorzAlign, iVertAlign); | 82 iImageYDpi, iHorzAlign, iVertAlign); |
83 } | 83 } |
84 } | 84 } |
| 85 |
85 FX_BOOL CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, | 86 FX_BOOL CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, |
86 FX_FLOAT fx, | 87 FX_FLOAT fx, |
87 FX_FLOAT fy) { | 88 FX_FLOAT fy) { |
88 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { | 89 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) |
89 return FALSE; | 90 return FALSE; |
90 } | 91 |
91 if (!PtInActiveRect(fx, fy)) { | 92 if (!PtInActiveRect(fx, fy)) |
92 return FALSE; | 93 return FALSE; |
93 } | 94 |
94 SetButtonDown(TRUE); | 95 SetButtonDown(TRUE); |
95 CFWL_MsgMouse ms; | 96 CFWL_MsgMouse ms; |
96 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDown; | 97 ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDown; |
97 ms.m_dwFlags = dwFlags; | 98 ms.m_dwFlags = dwFlags; |
98 ms.m_fx = fx; | 99 ms.m_fx = fx; |
99 ms.m_fy = fy; | 100 ms.m_fy = fy; |
100 ms.m_pDstTarget = m_pNormalWidget->m_pIface; | 101 ms.m_pDstTarget = m_pNormalWidget->m_pIface; |
101 FWLToClient(ms.m_fx, ms.m_fy); | 102 FWLToClient(ms.m_fx, ms.m_fy); |
102 TranslateFWLMessage(&ms); | 103 TranslateFWLMessage(&ms); |
103 IXFA_AppProvider* pAppProvider = GetAppProvider(); | |
104 if (!pAppProvider) { | |
105 return TRUE; | |
106 } | |
107 CFX_WideString wsTitle; | |
108 CFX_WideString wsFilter; | |
109 pAppProvider->LoadString(XFA_IDS_ImageFilter, wsFilter); | |
110 CFX_WideStringArray wsPathArray; | |
111 pAppProvider->ShowFileDialog(wsTitle.AsStringC(), wsFilter.AsStringC(), | |
112 wsPathArray); | |
113 int32_t iSize = wsPathArray.GetSize(); | |
114 if (iSize < 1) { | |
115 return TRUE; | |
116 } | |
117 CFX_WideString wsFilePath = wsPathArray[0]; | |
118 FX_STRSIZE nLen = wsFilePath.GetLength(); | |
119 FX_STRSIZE nIndex = nLen - 1; | |
120 while (nIndex > 0 && wsFilePath[nIndex] != '.') { | |
121 nIndex--; | |
122 } | |
123 if (nIndex <= 0) { | |
124 return TRUE; | |
125 } | |
126 CFX_WideString wsContentType(L"image/"); | |
127 wsContentType += wsFilePath.Right(nLen - nIndex - 1); | |
128 wsContentType.MakeLower(); | |
129 FXCODEC_IMAGE_TYPE eImageType = XFA_GetImageType(wsContentType); | |
130 if (eImageType == FXCODEC_IMAGE_UNKNOWN) { | |
131 return TRUE; | |
132 } | |
133 CFX_WideString wsImage; | |
134 IFX_FileRead* pFileRead = FX_CreateFileRead(wsFilePath.c_str()); | |
135 if (pFileRead) { | |
136 int32_t nDataSize = pFileRead->GetSize(); | |
137 if (nDataSize > 0) { | |
138 CFX_ByteString bsBuf; | |
139 FX_CHAR* pImageBuffer = bsBuf.GetBuffer(nDataSize); | |
140 pFileRead->ReadBlock(pImageBuffer, 0, nDataSize); | |
141 bsBuf.ReleaseBuffer(); | |
142 if (!bsBuf.IsEmpty()) { | |
143 FX_CHAR* pData = XFA_Base64Encode(bsBuf.raw_str(), nDataSize); | |
144 wsImage = CFX_WideString::FromLocal(pData); | |
145 FX_Free(pData); | |
146 } | |
147 } | |
148 m_pDataAcc->SetImageEditImage(NULL); | |
149 pFileRead->Release(); | |
150 } | |
151 m_pDataAcc->SetImageEdit(wsContentType.AsStringC(), CFX_WideStringC(), | |
152 wsImage.AsStringC()); | |
153 m_pDataAcc->LoadImageEditImage(); | |
154 AddInvalidateRect(); | |
155 m_pDocView->SetChangeMark(); | |
156 return TRUE; | 104 return TRUE; |
157 } | 105 } |
| 106 |
158 void CXFA_FFImageEdit::SetFWLRect() { | 107 void CXFA_FFImageEdit::SetFWLRect() { |
159 if (!m_pNormalWidget) { | 108 if (!m_pNormalWidget) { |
160 return; | 109 return; |
161 } | 110 } |
162 CFX_RectF rtUIMargin; | 111 CFX_RectF rtUIMargin; |
163 m_pDataAcc->GetUIMargin(rtUIMargin); | 112 m_pDataAcc->GetUIMargin(rtUIMargin); |
164 CFX_RectF rtImage(m_rtUI); | 113 CFX_RectF rtImage(m_rtUI); |
165 rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, | 114 rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, |
166 rtUIMargin.height); | 115 rtUIMargin.height); |
167 m_pNormalWidget->SetWidgetRect(rtImage); | 116 m_pNormalWidget->SetWidgetRect(rtImage); |
(...skipping 10 matching lines...) Expand all Loading... |
178 return m_pOldDelegate->OnProcessMessage(pMessage); | 127 return m_pOldDelegate->OnProcessMessage(pMessage); |
179 } | 128 } |
180 FWL_ERR CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { | 129 FWL_ERR CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { |
181 CXFA_FFField::OnProcessEvent(pEvent); | 130 CXFA_FFField::OnProcessEvent(pEvent); |
182 return m_pOldDelegate->OnProcessEvent(pEvent); | 131 return m_pOldDelegate->OnProcessEvent(pEvent); |
183 } | 132 } |
184 FWL_ERR CXFA_FFImageEdit::OnDrawWidget(CFX_Graphics* pGraphics, | 133 FWL_ERR CXFA_FFImageEdit::OnDrawWidget(CFX_Graphics* pGraphics, |
185 const CFX_Matrix* pMatrix) { | 134 const CFX_Matrix* pMatrix) { |
186 return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | 135 return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); |
187 } | 136 } |
OLD | NEW |