Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fwl / src / lightwidget / picturebox.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 CFWL_PictureBox* CFWL_PictureBox::Create()\r
9 {\r
10     return FX_NEW CFWL_PictureBox;\r
11 }\r
12 FWL_ERR CFWL_PictureBox::Initialize(const CFWL_WidgetProperties *pProperties )\r
13 {\r
14     _FWL_RETURN_VALUE_IF_FAIL(!m_pImp, FWL_ERR_Indefinite);\r
15     if (pProperties) {\r
16         *m_pProperties = *pProperties;\r
17     }\r
18     CFWL_WidgetImpProperties prop;\r
19     prop.m_dwStyles = m_pProperties->m_dwStyles;\r
20     prop.m_dwStyleExes = m_pProperties->m_dwStyleExes;\r
21     prop.m_dwStates = m_pProperties->m_dwStates;\r
22     prop.m_ctmOnParent = m_pProperties->m_ctmOnParent;\r
23     prop.m_pDataProvider = &m_PictureBoxDP;\r
24     if (m_pProperties->m_pParent) {\r
25         prop.m_pParent = m_pProperties->m_pParent->GetWidget();\r
26     }\r
27     if (m_pProperties->m_pOwner) {\r
28         prop.m_pOwner = m_pProperties->m_pOwner->GetWidget();\r
29     }\r
30     prop.m_rtWidget = m_pProperties->m_rtWidget;\r
31     m_pImp = IFWL_PictureBox::Create();\r
32     FWL_ERR ret = ((IFWL_PictureBox*)m_pImp)->Initialize(prop);\r
33     if (ret == FWL_ERR_Succeeded) {\r
34         CFWL_Widget::Initialize();\r
35     }\r
36     return ret;\r
37 }\r
38 CFX_DIBitmap* CFWL_PictureBox::GetPicture()\r
39 {\r
40     return m_PictureBoxDP.m_pBitmap;\r
41 }\r
42 FWL_ERR CFWL_PictureBox::SetPicture(CFX_DIBitmap *pBitmap)\r
43 {\r
44     m_PictureBoxDP.m_pBitmap = pBitmap;\r
45     return FWL_ERR_Succeeded;\r
46 }\r
47 FX_FLOAT CFWL_PictureBox::GetRotation()\r
48 {\r
49     return m_PictureBoxDP.m_fRotation;\r
50 }\r
51 FWL_ERR CFWL_PictureBox::SetRotation(FX_FLOAT fRotation)\r
52 {\r
53     m_PictureBoxDP.m_fRotation = fRotation;\r
54     return FWL_ERR_Succeeded;\r
55 }\r
56 int32_t CFWL_PictureBox::GetFlipMode()\r
57 {\r
58     return m_PictureBoxDP.GetFlipMode((IFWL_Widget*)this);\r
59 }\r
60 FWL_ERR CFWL_PictureBox::SetFlipMode(int32_t iFlipMode)\r
61 {\r
62     m_PictureBoxDP.m_iFlipMode = iFlipMode;\r
63     return FWL_ERR_Succeeded;\r
64 }\r
65 int32_t CFWL_PictureBox::GetOpacity()\r
66 {\r
67     return m_PictureBoxDP.GetOpacity((IFWL_Widget*)this);\r
68 }\r
69 FWL_ERR CFWL_PictureBox::SetOpacity(int32_t iOpacity)\r
70 {\r
71     m_PictureBoxDP.m_iOpacity = iOpacity;\r
72     return FWL_ERR_Succeeded;\r
73 }\r
74 FWL_ERR CFWL_PictureBox::GetScale(FX_FLOAT &fScaleX, FX_FLOAT &fScaleY)\r
75 {\r
76     CFX_Matrix matrix;\r
77     m_PictureBoxDP.GetMatrix((IFWL_Widget*)this, matrix);\r
78     matrix.Scale(fScaleX, fScaleY);\r
79     return FWL_ERR_Succeeded;\r
80 }\r
81 FWL_ERR CFWL_PictureBox::SetScale(FX_FLOAT fScaleX, FX_FLOAT fScaleY)\r
82 {\r
83     m_PictureBoxDP.m_fScaleX = fScaleX;\r
84     m_PictureBoxDP.m_fScaleY = fScaleY;\r
85     return FWL_ERR_Succeeded;\r
86 }\r
87 FWL_ERR CFWL_PictureBox::GetOffset(FX_FLOAT &fx, FX_FLOAT &fy)\r
88 {\r
89     CFX_Matrix matrix;\r
90     m_PictureBoxDP.GetMatrix((IFWL_Widget*)this, matrix);\r
91     fx = matrix.e;\r
92     fy = matrix.f;\r
93     return FWL_ERR_Succeeded;\r
94 }\r
95 FWL_ERR CFWL_PictureBox::SetOffset(FX_FLOAT fx, FX_FLOAT fy)\r
96 {\r
97     m_PictureBoxDP.m_fOffSetX = fx;\r
98     m_PictureBoxDP.m_fOffSetY = fy;\r
99     return FWL_ERR_Succeeded;\r
100 }\r
101 CFWL_PictureBox::CFWL_PictureBox()\r
102 {\r
103 }\r
104 CFWL_PictureBox::~CFWL_PictureBox()\r
105 {\r
106 }\r
107 FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetCaption(IFWL_Widget *pWidget, CFX_WideString &wsCaption)\r
108 {\r
109     return FWL_ERR_Succeeded;\r
110 }\r
111 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetPicture(IFWL_Widget *pWidget)\r
112 {\r
113     return m_pBitmap;\r
114 }\r
115 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetErrorPicture(IFWL_Widget *pWidget)\r
116 {\r
117     return m_pBitmap;\r
118 }\r
119 CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetInitialPicture(IFWL_Widget *pWidget)\r
120 {\r
121     return m_pBitmap;\r
122 }\r
123 int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetOpacity(IFWL_Widget *pWidget)\r
124 {\r
125     return m_iOpacity;\r
126 }\r
127 FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetMatrix(IFWL_Widget *pWidget, CFX_Matrix &matrix)\r
128 {\r
129     CFX_RectF rect;\r
130     pWidget->GetClientRect(rect);\r
131     FX_FLOAT fLen = rect.width / 2;\r
132     FX_FLOAT fWid = rect.height / 2;\r
133     matrix.Reset();\r
134     matrix.Translate(-fLen, -fWid);\r
135     matrix.Rotate(m_fRotation);\r
136     matrix.Translate(fLen, fWid);\r
137     matrix.Scale(m_fScaleX, m_fScaleY);\r
138     matrix.Translate(m_fOffSetX, m_fOffSetY);\r
139     return FWL_ERR_Succeeded;\r
140 }\r
141 int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetFlipMode(IFWL_Widget *pWidget)\r
142 {\r
143     return m_iFlipMode;\r
144 }\r