Initial commit.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_Signature.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 "../../include/pdfwindow/PDFWindow.h"\r
8 #include "../../include/pdfwindow/PWL_Wnd.h"\r
9 #include "../../include/pdfwindow/PWL_Icon.h"\r
10 #include "../../include/pdfwindow/PWL_Signature.h"\r
11 #include "../../include/pdfwindow/PWL_Label.h"\r
12 #include "../../include/pdfwindow/PWL_Utils.h"\r
13 \r
14 /* --------------------------------- CPWL_Signature_Image --------------------------------- */\r
15 \r
16 CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)\r
17 {\r
18 }\r
19 \r
20 CPWL_Signature_Image::~CPWL_Signature_Image()\r
21 {\r
22 }\r
23 \r
24 void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)\r
25 {\r
26         m_pImage = pImage;\r
27 }\r
28 \r
29 CFX_DIBSource* CPWL_Signature_Image::GetImage()\r
30 {\r
31         return m_pImage;\r
32 }\r
33 \r
34 void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)\r
35 {\r
36         CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);\r
37 \r
38         if (m_pImage)\r
39         {\r
40                 CPDF_Rect rcClient = GetClientRect();\r
41 \r
42                 FX_FLOAT x, y;\r
43                 pUser2Device->Transform(rcClient.left, rcClient.top, x, y);\r
44 \r
45                 pDevice->StretchDIBits(m_pImage, (FX_INT32)x, (FX_INT32)y, \r
46                         (FX_INT32)rcClient.Width(), (FX_INT32)rcClient.Height());\r
47         }\r
48 }\r
49 \r
50 void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)\r
51 {\r
52         sAppStream << CPWL_Image::GetImageAppStream();\r
53 }\r
54 \r
55 void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)\r
56 {\r
57         FX_FLOAT fImageW, fImageH;\r
58 \r
59         GetImageSize(fImageW, fImageH);\r
60 \r
61         CPDF_Rect rcClient = GetClientRect();\r
62 \r
63         fHScale = rcClient.Width() / fImageW;\r
64         fVScale = rcClient.Height() / fImageH;  \r
65 }\r
66 \r
67 /* --------------------------------- CPWL_Signature --------------------------------- */\r
68 \r
69 CPWL_Signature::CPWL_Signature() : \r
70         m_pText(NULL),\r
71         m_pDescription(NULL),\r
72         m_pImage(NULL),\r
73         m_bTextExist(TRUE),\r
74         m_bImageExist(FALSE),\r
75         m_bFlagExist(TRUE)\r
76 {\r
77 }\r
78 \r
79 CPWL_Signature::~CPWL_Signature()\r
80 {\r
81 }\r
82 \r
83 void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)\r
84 {\r
85         m_bTextExist = bTextExist;\r
86 \r
87         RePosChildWnd();\r
88 }\r
89 \r
90 void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)\r
91 {\r
92         m_bImageExist = bImageExist;\r
93 \r
94         RePosChildWnd();\r
95 }\r
96 \r
97 void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)\r
98 {\r
99         m_bFlagExist = bFlagExist;\r
100 }\r
101 \r
102 void CPWL_Signature::SetText(FX_LPCWSTR sText)\r
103 {\r
104         m_pText->SetText(sText);\r
105 \r
106         RePosChildWnd();\r
107 }\r
108 \r
109 void CPWL_Signature::SetDescription(FX_LPCWSTR string)\r
110 {\r
111         m_pDescription->SetText(string);\r
112 \r
113         RePosChildWnd();\r
114 }\r
115 \r
116 void CPWL_Signature::SetImage(CFX_DIBSource* pImage)\r
117 {\r
118         m_pImage->SetImage(pImage);\r
119 \r
120         RePosChildWnd();\r
121 }\r
122 \r
123 void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, FX_LPCSTR sImageAlias)\r
124 {\r
125         m_pImage->SetPDFStream(pStream);\r
126         m_pImage->SetImageAlias(sImageAlias);\r
127 \r
128         RePosChildWnd();\r
129 }\r
130 \r
131 void CPWL_Signature::RePosChildWnd()\r
132 {\r
133         CPDF_Rect rcClient = GetClientRect();\r
134 \r
135         CPDF_Rect rcText = rcClient;\r
136         CPDF_Rect rcDescription = rcClient;\r
137 \r
138         FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;\r
139         \r
140         if ((bTextVisible || m_bImageExist) &&\r
141                 m_pDescription->GetText().GetLength() > 0)\r
142         {\r
143                 if (rcClient.Width() >= rcClient.Height())\r
144                 {\r
145                         rcText.right = rcText.left + rcClient.Width() / 2.0f;\r
146                         rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;\r
147                 }\r
148                 else\r
149                 {\r
150                         rcText.bottom = rcText.top - rcClient.Height() / 2.0f;\r
151                         rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;\r
152                 }\r
153         }\r
154 \r
155         m_pText->SetVisible(bTextVisible);\r
156         m_pImage->SetVisible(m_bImageExist);\r
157 \r
158         m_pText->Move(rcText, TRUE, FALSE);\r
159         m_pImage->Move(rcText, TRUE, FALSE);\r
160         m_pDescription->Move(rcDescription, TRUE, FALSE);\r
161 }\r
162 \r
163 void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)\r
164 {\r
165         m_pImage = new CPWL_Signature_Image;\r
166         PWL_CREATEPARAM icp = cp;\r
167         icp.pParentWnd = this;\r
168         icp.dwFlags = PWS_CHILD | PWS_VISIBLE;\r
169         icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
170         m_pImage->Create(icp);\r
171 \r
172         m_pText = new CPWL_Label;\r
173         PWL_CREATEPARAM acp = cp;\r
174         acp.pParentWnd = this;\r
175         acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;\r
176         acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
177         m_pText->Create(acp);\r
178 \r
179         m_pDescription = new CPWL_Label;\r
180         PWL_CREATEPARAM dcp = cp;\r
181         dcp.pParentWnd = this;\r
182         dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;\r
183         dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
184         m_pDescription->Create(dcp);\r
185 }\r
186 \r
187 void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)\r
188 {\r
189         CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);\r
190 \r
191         if (m_bFlagExist)\r
192                 CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),\r
193                         CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);\r
194 \r
195         /*\r
196         CPDF_Rect rcClient = GetClientRect();\r
197 \r
198         CFX_PathData path;\r
199 \r
200         path.SetPointCount(2);\r
201         path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);\r
202         path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);\r
203 \r
204         CFX_GraphStateData gsd;\r
205         gsd.SetDashCount(2);                            \r
206         gsd.m_DashArray[0] = 6.0f;\r
207         gsd.m_DashArray[1] = 6.0f;\r
208         gsd.m_DashPhase = 0;    \r
209         \r
210         gsd.m_LineWidth = 10.0f;\r
211         pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);\r
212         */\r
213 }\r
214 \r
215 void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)\r
216 {\r
217         CPWL_Wnd::GetThisAppearanceStream(sAppStream);\r
218 }\r
219 \r
220 \r