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