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 <memory>
8 
9 #include "xfa/src/foxitlib.h"
10 
Create()11 CFWL_PictureBox* CFWL_PictureBox::Create() {
12   return new CFWL_PictureBox;
13 }
Initialize(const CFWL_WidgetProperties * pProperties)14 FWL_ERR CFWL_PictureBox::Initialize(const CFWL_WidgetProperties* pProperties) {
15   if (m_pIface)
16     return FWL_ERR_Indefinite;
17   if (pProperties) {
18     *m_pProperties = *pProperties;
19   }
20   std::unique_ptr<IFWL_PictureBox> pPictureBox(IFWL_PictureBox::Create(
21       m_pProperties->MakeWidgetImpProperties(&m_PictureBoxDP), nullptr));
22   FWL_ERR ret = pPictureBox->Initialize();
23   if (ret != FWL_ERR_Succeeded) {
24     return ret;
25   }
26   m_pIface = pPictureBox.release();
27   CFWL_Widget::Initialize();
28   return FWL_ERR_Succeeded;
29 }
GetPicture()30 CFX_DIBitmap* CFWL_PictureBox::GetPicture() {
31   return m_PictureBoxDP.m_pBitmap;
32 }
SetPicture(CFX_DIBitmap * pBitmap)33 FWL_ERR CFWL_PictureBox::SetPicture(CFX_DIBitmap* pBitmap) {
34   m_PictureBoxDP.m_pBitmap = pBitmap;
35   return FWL_ERR_Succeeded;
36 }
GetRotation()37 FX_FLOAT CFWL_PictureBox::GetRotation() {
38   return m_PictureBoxDP.m_fRotation;
39 }
SetRotation(FX_FLOAT fRotation)40 FWL_ERR CFWL_PictureBox::SetRotation(FX_FLOAT fRotation) {
41   m_PictureBoxDP.m_fRotation = fRotation;
42   return FWL_ERR_Succeeded;
43 }
GetFlipMode()44 int32_t CFWL_PictureBox::GetFlipMode() {
45   return m_PictureBoxDP.GetFlipMode(m_pIface);
46 }
SetFlipMode(int32_t iFlipMode)47 FWL_ERR CFWL_PictureBox::SetFlipMode(int32_t iFlipMode) {
48   m_PictureBoxDP.m_iFlipMode = iFlipMode;
49   return FWL_ERR_Succeeded;
50 }
GetOpacity()51 int32_t CFWL_PictureBox::GetOpacity() {
52   return m_PictureBoxDP.GetOpacity(m_pIface);
53 }
SetOpacity(int32_t iOpacity)54 FWL_ERR CFWL_PictureBox::SetOpacity(int32_t iOpacity) {
55   m_PictureBoxDP.m_iOpacity = iOpacity;
56   return FWL_ERR_Succeeded;
57 }
GetScale(FX_FLOAT & fScaleX,FX_FLOAT & fScaleY)58 FWL_ERR CFWL_PictureBox::GetScale(FX_FLOAT& fScaleX, FX_FLOAT& fScaleY) {
59   CFX_Matrix matrix;
60   m_PictureBoxDP.GetMatrix(m_pIface, matrix);
61   matrix.Scale(fScaleX, fScaleY);
62   return FWL_ERR_Succeeded;
63 }
SetScale(FX_FLOAT fScaleX,FX_FLOAT fScaleY)64 FWL_ERR CFWL_PictureBox::SetScale(FX_FLOAT fScaleX, FX_FLOAT fScaleY) {
65   m_PictureBoxDP.m_fScaleX = fScaleX;
66   m_PictureBoxDP.m_fScaleY = fScaleY;
67   return FWL_ERR_Succeeded;
68 }
GetOffset(FX_FLOAT & fx,FX_FLOAT & fy)69 FWL_ERR CFWL_PictureBox::GetOffset(FX_FLOAT& fx, FX_FLOAT& fy) {
70   CFX_Matrix matrix;
71   m_PictureBoxDP.GetMatrix(m_pIface, matrix);
72   fx = matrix.e;
73   fy = matrix.f;
74   return FWL_ERR_Succeeded;
75 }
SetOffset(FX_FLOAT fx,FX_FLOAT fy)76 FWL_ERR CFWL_PictureBox::SetOffset(FX_FLOAT fx, FX_FLOAT fy) {
77   m_PictureBoxDP.m_fOffSetX = fx;
78   m_PictureBoxDP.m_fOffSetY = fy;
79   return FWL_ERR_Succeeded;
80 }
CFWL_PictureBox()81 CFWL_PictureBox::CFWL_PictureBox() {}
~CFWL_PictureBox()82 CFWL_PictureBox::~CFWL_PictureBox() {}
GetCaption(IFWL_Widget * pWidget,CFX_WideString & wsCaption)83 FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetCaption(
84     IFWL_Widget* pWidget,
85     CFX_WideString& wsCaption) {
86   return FWL_ERR_Succeeded;
87 }
GetPicture(IFWL_Widget * pWidget)88 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetPicture(
89     IFWL_Widget* pWidget) {
90   return m_pBitmap;
91 }
GetErrorPicture(IFWL_Widget * pWidget)92 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetErrorPicture(
93     IFWL_Widget* pWidget) {
94   return m_pBitmap;
95 }
GetInitialPicture(IFWL_Widget * pWidget)96 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetInitialPicture(
97     IFWL_Widget* pWidget) {
98   return m_pBitmap;
99 }
GetOpacity(IFWL_Widget * pWidget)100 int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetOpacity(IFWL_Widget* pWidget) {
101   return m_iOpacity;
102 }
GetMatrix(IFWL_Widget * pWidget,CFX_Matrix & matrix)103 FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetMatrix(IFWL_Widget* pWidget,
104                                                       CFX_Matrix& matrix) {
105   CFX_RectF rect;
106   pWidget->GetClientRect(rect);
107   FX_FLOAT fLen = rect.width / 2;
108   FX_FLOAT fWid = rect.height / 2;
109   matrix.SetIdentity();
110   matrix.Translate(-fLen, -fWid);
111   matrix.Rotate(m_fRotation);
112   matrix.Translate(fLen, fWid);
113   matrix.Scale(m_fScaleX, m_fScaleY);
114   matrix.Translate(m_fOffSetX, m_fOffSetY);
115   return FWL_ERR_Succeeded;
116 }
GetFlipMode(IFWL_Widget * pWidget)117 int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetFlipMode(IFWL_Widget* pWidget) {
118   return m_iFlipMode;
119 }
120