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 | |
| 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 14 | /* --------------------------------- CPWL_Signature_Image |
| 15 | * --------------------------------- */ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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; |
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 | CFX_DIBSource* CPWL_Signature_Image::GetImage() { |
| 26 | return m_pImage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | void CPWL_Signature_Image::GetThisAppearanceStream( |
| 46 | CFX_ByteTextBuf& sAppStream) { |
| 47 | sAppStream << CPWL_Image::GetImageAppStream(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { |
| 51 | FX_FLOAT fImageW, fImageH; |
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 | GetImageSize(fImageW, fImageH); |
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 | CPDF_Rect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | fHScale = rcClient.Width() / fImageW; |
| 58 | fVScale = rcClient.Height() / fImageH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) { |
| 81 | m_bImageExist = bImageExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) { |
| 87 | m_bFlagExist = bFlagExist; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | void CPWL_Signature::SetText(const FX_WCHAR* sText) { |
| 91 | m_pText->SetText(sText); |
| 92 | |
| 93 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | void CPWL_Signature::SetDescription(const FX_WCHAR* string) { |
| 97 | m_pDescription->SetText(string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | void CPWL_Signature::SetImage(CFX_DIBSource* pImage) { |
| 103 | m_pImage->SetImage(pImage); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | void CPWL_Signature::RePosChildWnd() { |
| 117 | CPDF_Rect rcClient = GetClientRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, |
| 169 | CPDF_Matrix* pUser2Device) { |
| 170 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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 | */ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 203 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 204 | } |