blob: 6b3940de289c9f3bcaa66248058befa9bde8dfb9 [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
Lei Zhangbde53d22015-11-12 22:21:30 -08007#include "fpdfsdk/include/pdfwindow/PWL_Icon.h"
8#include "fpdfsdk/include/pdfwindow/PWL_Label.h"
9#include "fpdfsdk/include/pdfwindow/PWL_Signature.h"
10#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
11#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Nico Weber9d8ec5a2015-08-04 13:00:21 -070013CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL) {}
14
15CPWL_Signature_Image::~CPWL_Signature_Image() {}
16
17void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage) {
18 m_pImage = pImage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019}
20
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021CFX_DIBSource* CPWL_Signature_Image::GetImage() {
22 return m_pImage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023}
24
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -080026 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
28
29 if (m_pImage) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080030 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031
32 FX_FLOAT x, y;
33 pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
34
35 pDevice->StretchDIBits(m_pImage, (int32_t)x, (int32_t)y,
36 (int32_t)rcClient.Width(),
37 (int32_t)rcClient.Height());
38 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041void CPWL_Signature_Image::GetThisAppearanceStream(
42 CFX_ByteTextBuf& sAppStream) {
43 sAppStream << CPWL_Image::GetImageAppStream();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) {
47 FX_FLOAT fImageW, fImageH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 GetImageSize(fImageW, fImageH);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Tom Sepez281a9ea2016-02-26 14:24:28 -080051 CFX_FloatRect rcClient = GetClientRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 fHScale = rcClient.Width() / fImageW;
54 fVScale = rcClient.Height() / fImageH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055}
56
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057CPWL_Signature::CPWL_Signature()
58 : m_pText(NULL),
59 m_pDescription(NULL),
60 m_pImage(NULL),
61 m_bTextExist(TRUE),
62 m_bImageExist(FALSE),
63 m_bFlagExist(TRUE) {}
64
65CPWL_Signature::~CPWL_Signature() {}
66
67void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist) {
68 m_bTextExist = bTextExist;
69
70 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) {
74 m_bImageExist = bImageExist;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) {
80 m_bFlagExist = bFlagExist;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083void CPWL_Signature::SetText(const FX_WCHAR* sText) {
84 m_pText->SetText(sText);
85
86 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087}
88
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089void CPWL_Signature::SetDescription(const FX_WCHAR* string) {
90 m_pDescription->SetText(string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093}
94
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095void CPWL_Signature::SetImage(CFX_DIBSource* pImage) {
96 m_pImage->SetImage(pImage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101void CPWL_Signature::SetImageStream(CPDF_Stream* pStream,
102 const FX_CHAR* sImageAlias) {
103 m_pImage->SetPDFStream(pStream);
104 m_pImage->SetImageAlias(sImageAlias);
105
106 RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107}
108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109void CPWL_Signature::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800110 CFX_FloatRect rcClient = GetClientRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
Tom Sepez281a9ea2016-02-26 14:24:28 -0800112 CFX_FloatRect rcText = rcClient;
113 CFX_FloatRect rcDescription = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
115 FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
116
117 if ((bTextVisible || m_bImageExist) &&
118 m_pDescription->GetText().GetLength() > 0) {
119 if (rcClient.Width() >= rcClient.Height()) {
120 rcText.right = rcText.left + rcClient.Width() / 2.0f;
121 rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
122 } else {
123 rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
124 rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
125 }
126 }
127
128 m_pText->SetVisible(bTextVisible);
129 m_pImage->SetVisible(m_bImageExist);
130
131 m_pText->Move(rcText, TRUE, FALSE);
132 m_pImage->Move(rcText, TRUE, FALSE);
133 m_pDescription->Move(rcDescription, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134}
135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM& cp) {
137 m_pImage = new CPWL_Signature_Image;
138 PWL_CREATEPARAM icp = cp;
139 icp.pParentWnd = this;
140 icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
141 icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
142 m_pImage->Create(icp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 m_pText = new CPWL_Label;
145 PWL_CREATEPARAM acp = cp;
146 acp.pParentWnd = this;
147 acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE |
148 PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
149 acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
150 m_pText->Create(acp);
151
152 m_pDescription = new CPWL_Label;
153 PWL_CREATEPARAM dcp = cp;
154 dcp.pParentWnd = this;
155 dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE |
156 PES_AUTORETURN | PES_LEFT | PES_CENTER;
157 dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
158 m_pDescription->Create(dcp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159}
160
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800162 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800165 if (m_bFlagExist) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 CPWL_Utils::DrawIconAppStream(
167 pDevice, pUser2Device, PWL_ICONTYPE_FOXIT,
168 CPWL_Utils::GetCenterSquare(GetClientRect()),
169 CPWL_Color(COLORTYPE_RGB, 0.91f, 0.855f, 0.92f),
170 CPWL_Color(COLORTYPE_TRANSPARENT), 255);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800171 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700172}
173
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
175 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176}