blob: c737998f26390b5f6fc1c54f1eaf4971a6cf2cbf [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dan sinclair89e904b2016-03-23 19:29:15 -04007#include "fpdfsdk/pdfwindow/PWL_Signature.h"
Dan Sinclair3ebd1212016-03-09 09:59:23 -05008
dsinclair48baa5f2016-04-06 10:00:40 -07009#include "core/fxge/include/fx_ge.h"
dan sinclair89e904b2016-03-23 19:29:15 -040010#include "fpdfsdk/pdfwindow/PWL_Icon.h"
11#include "fpdfsdk/pdfwindow/PWL_Label.h"
12#include "fpdfsdk/pdfwindow/PWL_Utils.h"
13#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL) {}
16
17CPWL_Signature_Image::~CPWL_Signature_Image() {}
18
19void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage) {
20 m_pImage = pImage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021}
22
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023CFX_DIBSource* CPWL_Signature_Image::GetImage() {
24 return m_pImage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025}
26
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -080028 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
30
31 if (m_pImage) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080032 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033
34 FX_FLOAT x, y;
35 pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
36
37 pDevice->StretchDIBits(m_pImage, (int32_t)x, (int32_t)y,
38 (int32_t)rcClient.Width(),
39 (int32_t)rcClient.Height());
40 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041}
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043void CPWL_Signature_Image::GetThisAppearanceStream(
44 CFX_ByteTextBuf& sAppStream) {
tsepez4c3debb2016-04-08 12:20:38 -070045 sAppStream << CPWL_Image::GetImageAppStream().AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) {
49 FX_FLOAT fImageW, fImageH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 GetImageSize(fImageW, fImageH);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Tom Sepez281a9ea2016-02-26 14:24:28 -080053 CFX_FloatRect rcClient = GetClientRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 fHScale = rcClient.Width() / fImageW;
56 fVScale = rcClient.Height() / fImageH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057}
58
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059CPWL_Signature::CPWL_Signature()
60 : m_pText(NULL),
61 m_pDescription(NULL),
62 m_pImage(NULL),
63 m_bTextExist(TRUE),
64 m_bImageExist(FALSE),
65 m_bFlagExist(TRUE) {}
66
67CPWL_Signature::~CPWL_Signature() {}
68
69void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist) {
70 m_bTextExist = bTextExist;
71
72 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) {
76 m_bImageExist = bImageExist;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079}
80
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) {
82 m_bFlagExist = bFlagExist;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083}
84
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085void CPWL_Signature::SetText(const FX_WCHAR* sText) {
86 m_pText->SetText(sText);
87
88 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089}
90
Dan Sinclair3ebd1212016-03-09 09:59:23 -050091void CPWL_Signature::SetDescription(const FX_WCHAR* str) {
92 m_pDescription->SetText(str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void CPWL_Signature::SetImage(CFX_DIBSource* pImage) {
98 m_pImage->SetImage(pImage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103void CPWL_Signature::SetImageStream(CPDF_Stream* pStream,
104 const FX_CHAR* sImageAlias) {
105 m_pImage->SetPDFStream(pStream);
106 m_pImage->SetImageAlias(sImageAlias);
107
108 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}
110
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111void CPWL_Signature::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800112 CFX_FloatRect rcClient = GetClientRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Tom Sepez281a9ea2016-02-26 14:24:28 -0800114 CFX_FloatRect rcText = rcClient;
115 CFX_FloatRect rcDescription = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116
117 FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
118
119 if ((bTextVisible || m_bImageExist) &&
120 m_pDescription->GetText().GetLength() > 0) {
121 if (rcClient.Width() >= rcClient.Height()) {
122 rcText.right = rcText.left + rcClient.Width() / 2.0f;
123 rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
124 } else {
125 rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
126 rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
127 }
128 }
129
130 m_pText->SetVisible(bTextVisible);
131 m_pImage->SetVisible(m_bImageExist);
132
133 m_pText->Move(rcText, TRUE, FALSE);
134 m_pImage->Move(rcText, TRUE, FALSE);
135 m_pDescription->Move(rcDescription, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM& cp) {
139 m_pImage = new CPWL_Signature_Image;
140 PWL_CREATEPARAM icp = cp;
141 icp.pParentWnd = this;
142 icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
143 icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
144 m_pImage->Create(icp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 m_pText = new CPWL_Label;
147 PWL_CREATEPARAM acp = cp;
148 acp.pParentWnd = this;
149 acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE |
150 PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
151 acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
152 m_pText->Create(acp);
153
154 m_pDescription = new CPWL_Label;
155 PWL_CREATEPARAM dcp = cp;
156 dcp.pParentWnd = this;
157 dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE |
158 PES_AUTORETURN | PES_LEFT | PES_CENTER;
159 dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
160 m_pDescription->Create(dcp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161}
162
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800164 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800167 if (m_bFlagExist) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 CPWL_Utils::DrawIconAppStream(
169 pDevice, pUser2Device, PWL_ICONTYPE_FOXIT,
170 CPWL_Utils::GetCenterSquare(GetClientRect()),
171 CPWL_Color(COLORTYPE_RGB, 0.91f, 0.855f, 0.92f),
172 CPWL_Color(COLORTYPE_TRANSPARENT), 255);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800173 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174}
175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
177 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}