John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/PWL_Signature.h" |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 8 | |
dsinclair | 48baa5f | 2016-04-06 10:00:40 -0700 | [diff] [blame] | 9 | #include "core/fxge/include/fx_ge.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 10 | #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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 15 | CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL) {} |
| 16 | |
| 17 | CPWL_Signature_Image::~CPWL_Signature_Image() {} |
| 18 | |
| 19 | void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage) { |
| 20 | m_pImage = pImage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | CFX_DIBSource* CPWL_Signature_Image::GetImage() { |
| 24 | return m_pImage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 28 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 30 | |
| 31 | if (m_pImage) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 32 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | void CPWL_Signature_Image::GetThisAppearanceStream( |
| 44 | CFX_ByteTextBuf& sAppStream) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 45 | sAppStream << CPWL_Image::GetImageAppStream().AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { |
| 49 | FX_FLOAT fImageW, fImageH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | GetImageSize(fImageW, fImageH); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 53 | CFX_FloatRect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | fHScale = rcClient.Width() / fImageW; |
| 56 | fVScale = rcClient.Height() / fImageH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | CPWL_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 | |
| 67 | CPWL_Signature::~CPWL_Signature() {} |
| 68 | |
| 69 | void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist) { |
| 70 | m_bTextExist = bTextExist; |
| 71 | |
| 72 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) { |
| 76 | m_bImageExist = bImageExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) { |
| 82 | m_bFlagExist = bFlagExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | void CPWL_Signature::SetText(const FX_WCHAR* sText) { |
| 86 | m_pText->SetText(sText); |
| 87 | |
| 88 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 91 | void CPWL_Signature::SetDescription(const FX_WCHAR* str) { |
| 92 | m_pDescription->SetText(str); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | void CPWL_Signature::SetImage(CFX_DIBSource* pImage) { |
| 98 | m_pImage->SetImage(pImage); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | void 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | void CPWL_Signature::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 112 | CFX_FloatRect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 114 | CFX_FloatRect rcText = rcClient; |
| 115 | CFX_FloatRect rcDescription = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | void 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 164 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 167 | if (m_bFlagExist) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | 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 Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 173 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 177 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | } |