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 | |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 7 | #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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 13 | CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL) {} |
| 14 | |
| 15 | CPWL_Signature_Image::~CPWL_Signature_Image() {} |
| 16 | |
| 17 | void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage) { |
| 18 | m_pImage = pImage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | CFX_DIBSource* CPWL_Signature_Image::GetImage() { |
| 22 | return m_pImage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 26 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 28 | |
| 29 | if (m_pImage) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame^] | 30 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | void CPWL_Signature_Image::GetThisAppearanceStream( |
| 42 | CFX_ByteTextBuf& sAppStream) { |
| 43 | sAppStream << CPWL_Image::GetImageAppStream(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { |
| 47 | FX_FLOAT fImageW, fImageH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | GetImageSize(fImageW, fImageH); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame^] | 51 | CFX_FloatRect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | fHScale = rcClient.Width() / fImageW; |
| 54 | fVScale = rcClient.Height() / fImageH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | CPWL_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 | |
| 65 | CPWL_Signature::~CPWL_Signature() {} |
| 66 | |
| 67 | void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist) { |
| 68 | m_bTextExist = bTextExist; |
| 69 | |
| 70 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) { |
| 74 | m_bImageExist = bImageExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) { |
| 80 | m_bFlagExist = bFlagExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | void CPWL_Signature::SetText(const FX_WCHAR* sText) { |
| 84 | m_pText->SetText(sText); |
| 85 | |
| 86 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | void CPWL_Signature::SetDescription(const FX_WCHAR* string) { |
| 90 | m_pDescription->SetText(string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | void CPWL_Signature::SetImage(CFX_DIBSource* pImage) { |
| 96 | m_pImage->SetImage(pImage); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | void 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 109 | void CPWL_Signature::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame^] | 110 | CFX_FloatRect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame^] | 112 | CFX_FloatRect rcText = rcClient; |
| 113 | CFX_FloatRect rcDescription = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | void 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 144 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 162 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 165 | if (m_bFlagExist) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | 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 Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 171 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 175 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | } |