| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/pdfwindow/PDFWindow.h" | 7 #include "../../include/pdfwindow/PDFWindow.h" |
| 8 #include "../../include/pdfwindow/PWL_Wnd.h" | 8 #include "../../include/pdfwindow/PWL_Wnd.h" |
| 9 #include "../../include/pdfwindow/PWL_Label.h" | 9 #include "../../include/pdfwindow/PWL_Label.h" |
| 10 #include "../../include/pdfwindow/PWL_Utils.h" | 10 #include "../../include/pdfwindow/PWL_Utils.h" |
| 11 | 11 |
| 12 /* ---------------------------- CPWL_Label ------------------------------ */ | 12 /* ---------------------------- CPWL_Label ------------------------------ */ |
| 13 | 13 |
| 14 CPWL_Label::CPWL_Label() : m_pEdit(NULL) | 14 CPWL_Label::CPWL_Label() : m_pEdit(NULL) { |
| 15 { | 15 m_pEdit = IFX_Edit::NewEdit(); |
| 16 » m_pEdit = IFX_Edit::NewEdit(); | |
| 17 | 16 |
| 18 » ASSERT(m_pEdit != NULL); | 17 ASSERT(m_pEdit != NULL); |
| 19 } | 18 } |
| 20 | 19 |
| 21 CPWL_Label::~CPWL_Label() | 20 CPWL_Label::~CPWL_Label() { |
| 22 { | 21 IFX_Edit::DelEdit(m_pEdit); |
| 23 » IFX_Edit::DelEdit(m_pEdit); | |
| 24 } | 22 } |
| 25 | 23 |
| 26 CFX_ByteString CPWL_Label::GetClassName() const | 24 CFX_ByteString CPWL_Label::GetClassName() const { |
| 27 { | 25 return "CPWL_Label"; |
| 28 » return "CPWL_Label"; | |
| 29 } | 26 } |
| 30 | 27 |
| 31 void CPWL_Label::OnCreated() | 28 void CPWL_Label::OnCreated() { |
| 32 { | 29 SetParamByFlag(); |
| 33 » SetParamByFlag(); | 30 SetFontSize(this->GetCreationParam().fFontSize); |
| 34 » SetFontSize(this->GetCreationParam().fFontSize); | |
| 35 | 31 |
| 36 » m_pEdit->SetFontMap(this->GetFontMap()); | 32 m_pEdit->SetFontMap(this->GetFontMap()); |
| 37 » m_pEdit->Initialize(); | 33 m_pEdit->Initialize(); |
| 38 | 34 |
| 39 » if (HasFlag(PES_TEXTOVERFLOW)) | 35 if (HasFlag(PES_TEXTOVERFLOW)) { |
| 40 » { | 36 SetClipRect(CPDF_Rect(0.0f, 0.0f, 0.0f, 0.0f)); |
| 41 » » SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f)); | 37 m_pEdit->SetTextOverflow(TRUE); |
| 42 » » m_pEdit->SetTextOverflow(TRUE); | 38 } |
| 43 » } | |
| 44 } | 39 } |
| 45 | 40 |
| 46 void CPWL_Label::SetText(FX_LPCWSTR csText) | 41 void CPWL_Label::SetText(FX_LPCWSTR csText) { |
| 47 { | 42 m_pEdit->SetText(csText); |
| 48 » m_pEdit->SetText(csText); | |
| 49 } | 43 } |
| 50 | 44 |
| 51 void CPWL_Label::RePosChildWnd() | 45 void CPWL_Label::RePosChildWnd() { |
| 52 { | 46 m_pEdit->SetPlateRect(GetClientRect()); |
| 53 » m_pEdit->SetPlateRect(GetClientRect()); | |
| 54 } | 47 } |
| 55 | 48 |
| 56 void CPWL_Label::SetFontSize(FX_FLOAT fFontSize) | 49 void CPWL_Label::SetFontSize(FX_FLOAT fFontSize) { |
| 57 { | 50 m_pEdit->SetFontSize(fFontSize); |
| 58 » m_pEdit->SetFontSize(fFontSize); | |
| 59 } | 51 } |
| 60 | 52 |
| 61 FX_FLOAT CPWL_Label::GetFontSize() const | 53 FX_FLOAT CPWL_Label::GetFontSize() const { |
| 62 { | 54 return m_pEdit->GetFontSize(); |
| 63 » return m_pEdit->GetFontSize(); | |
| 64 } | 55 } |
| 65 | 56 |
| 66 void CPWL_Label::SetParamByFlag() | 57 void CPWL_Label::SetParamByFlag() { |
| 67 {» | 58 if (HasFlag(PES_LEFT)) { |
| 68 » if (HasFlag(PES_LEFT)) | 59 m_pEdit->SetAlignmentH(0); |
| 69 » { | 60 } else if (HasFlag(PES_MIDDLE)) { |
| 70 » » m_pEdit->SetAlignmentH(0); | 61 m_pEdit->SetAlignmentH(1); |
| 71 » } | 62 } else if (HasFlag(PES_RIGHT)) { |
| 72 » else if (HasFlag(PES_MIDDLE)) | 63 m_pEdit->SetAlignmentH(2); |
| 73 » { | 64 } else { |
| 74 » » m_pEdit->SetAlignmentH(1); | 65 m_pEdit->SetAlignmentH(0); |
| 75 » } | 66 } |
| 76 » else if (HasFlag(PES_RIGHT)) | |
| 77 » { | |
| 78 » » m_pEdit->SetAlignmentH(2); | |
| 79 » } | |
| 80 » else | |
| 81 » { | |
| 82 » » m_pEdit->SetAlignmentH(0); | |
| 83 » } | |
| 84 | 67 |
| 85 » if (HasFlag(PES_TOP)) | 68 if (HasFlag(PES_TOP)) { |
| 86 » { | 69 m_pEdit->SetAlignmentV(0); |
| 87 » » m_pEdit->SetAlignmentV(0); | 70 } else if (HasFlag(PES_CENTER)) { |
| 88 » } | 71 m_pEdit->SetAlignmentV(1); |
| 89 » else if (HasFlag(PES_CENTER)) | 72 } else if (HasFlag(PES_BOTTOM)) { |
| 90 » { | 73 m_pEdit->SetAlignmentV(2); |
| 91 » » m_pEdit->SetAlignmentV(1); | 74 } else { |
| 92 » } | 75 m_pEdit->SetAlignmentV(0); |
| 93 » else if (HasFlag(PES_BOTTOM)) | 76 } |
| 94 » { | |
| 95 » » m_pEdit->SetAlignmentV(2); | |
| 96 » } | |
| 97 » else | |
| 98 » { | |
| 99 » » m_pEdit->SetAlignmentV(0); | |
| 100 » } | |
| 101 | 77 |
| 102 » if (HasFlag(PES_PASSWORD)) | 78 if (HasFlag(PES_PASSWORD)) { |
| 103 » { | 79 m_pEdit->SetPasswordChar('*'); |
| 104 » » m_pEdit->SetPasswordChar('*'); | 80 } |
| 105 » } | |
| 106 | 81 |
| 107 » m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE)); | 82 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE)); |
| 108 » m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN)); | 83 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN)); |
| 109 » m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE)); | 84 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE)); |
| 110 » m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL)); | 85 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL)); |
| 111 } | 86 } |
| 112 | 87 |
| 113 void CPWL_Label::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUse
r2Device) | 88 void CPWL_Label::DrawThisAppearance(CFX_RenderDevice* pDevice, |
| 114 { | 89 CPDF_Matrix* pUser2Device) { |
| 115 » CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device); | 90 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 116 | 91 |
| 117 » GetClientRect(); | 92 GetClientRect(); |
| 118 | 93 |
| 119 » CPDF_Rect rcClip; | 94 CPDF_Rect rcClip; |
| 120 » CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); | 95 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); |
| 121 » CPVT_WordRange* pRange = NULL; | 96 CPVT_WordRange* pRange = NULL; |
| 122 | 97 |
| 123 » if (!HasFlag(PES_TEXTOVERFLOW)) | 98 if (!HasFlag(PES_TEXTOVERFLOW)) { |
| 124 » { | 99 rcClip = GetClientRect(); |
| 125 » » rcClip = GetClientRect(); | 100 pRange = &wrRange; |
| 126 » » pRange = &wrRange; | 101 } |
| 127 » } | 102 IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
| 128 IFX_SystemHandler* pSysHandler = GetSystemHandler(); | 103 IFX_Edit::DrawEdit( |
| 129 » IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit, | 104 pDevice, |
| 130 » » CPWL_Utils::PWLColorToFXColor(GetTextColor(), this->GetTranspare
ncy()), | 105 pUser2Device, |
| 131 » » CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), this->GetTra
nsparency()), | 106 m_pEdit, |
| 132 » » rcClip, CPDF_Point(0.0f,0.0f), pRange,pSysHandler, NULL); | 107 CPWL_Utils::PWLColorToFXColor(GetTextColor(), this->GetTransparency()), |
| 108 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), |
| 109 this->GetTransparency()), |
| 110 rcClip, |
| 111 CPDF_Point(0.0f, 0.0f), |
| 112 pRange, |
| 113 pSysHandler, |
| 114 NULL); |
| 133 } | 115 } |
| 134 | 116 |
| 135 void CPWL_Label::SetHorzScale(FX_INT32 nHorzScale) | 117 void CPWL_Label::SetHorzScale(FX_INT32 nHorzScale) { |
| 136 { | 118 m_pEdit->SetHorzScale(nHorzScale); |
| 137 » m_pEdit->SetHorzScale(nHorzScale); | |
| 138 } | 119 } |
| 139 | 120 |
| 140 void CPWL_Label::SetCharSpace(FX_FLOAT fCharSpace) | 121 void CPWL_Label::SetCharSpace(FX_FLOAT fCharSpace) { |
| 141 { | 122 m_pEdit->SetCharSpace(fCharSpace); |
| 142 » m_pEdit->SetCharSpace(fCharSpace); | |
| 143 } | 123 } |
| 144 | 124 |
| 145 CPDF_Rect CPWL_Label::GetContentRect() const | 125 CPDF_Rect CPWL_Label::GetContentRect() const { |
| 146 { | 126 return m_pEdit->GetContentRect(); |
| 147 » return m_pEdit->GetContentRect(); | |
| 148 } | 127 } |
| 149 | 128 |
| 150 void CPWL_Label::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream) | 129 void CPWL_Label::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 151 { | 130 CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 152 » CPWL_Wnd::GetThisAppearanceStream(sAppStream); | |
| 153 | 131 |
| 154 » sAppStream << GetTextAppearanceStream(CPDF_Point(0.0f, 0.0f)); | 132 sAppStream << GetTextAppearanceStream(CPDF_Point(0.0f, 0.0f)); |
| 155 } | 133 } |
| 156 | 134 |
| 157 CFX_ByteString CPWL_Label::GetTextAppearanceStream(const CPDF_Point & ptOffset)
const | 135 CFX_ByteString CPWL_Label::GetTextAppearanceStream( |
| 158 { | 136 const CPDF_Point& ptOffset) const { |
| 159 » CFX_ByteTextBuf sRet; | 137 CFX_ByteTextBuf sRet; |
| 160 » CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset); | 138 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset); |
| 161 » | |
| 162 » if (sEdit.GetLength() > 0) | |
| 163 » { | |
| 164 » » sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
<< sEdit << "ET\n"; | |
| 165 » } | |
| 166 | 139 |
| 167 » return sRet.GetByteString(); | 140 if (sEdit.GetLength() > 0) { |
| 141 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit |
| 142 << "ET\n"; |
| 143 } |
| 144 |
| 145 return sRet.GetByteString(); |
| 168 } | 146 } |
| 169 | 147 |
| 170 CFX_WideString CPWL_Label::GetText() const | 148 CFX_WideString CPWL_Label::GetText() const { |
| 171 { | 149 return m_pEdit->GetText(); |
| 172 » return m_pEdit->GetText(); | |
| 173 } | 150 } |
| 174 | 151 |
| 175 void CPWL_Label::SetLimitChar(FX_INT32 nLimitChar) | 152 void CPWL_Label::SetLimitChar(FX_INT32 nLimitChar) { |
| 176 { | 153 m_pEdit->SetLimitChar(nLimitChar); |
| 177 » m_pEdit->SetLimitChar(nLimitChar); | |
| 178 } | 154 } |
| 179 | 155 |
| 180 FX_INT32 CPWL_Label::GetTotalWords() | 156 FX_INT32 CPWL_Label::GetTotalWords() { |
| 181 { | 157 if (m_pEdit) |
| 182 » if (m_pEdit) | 158 return m_pEdit->GetTotalWords(); |
| 183 » » return m_pEdit->GetTotalWords(); | |
| 184 | 159 |
| 185 » return 0; | 160 return 0; |
| 186 } | 161 } |
| 187 | |
| OLD | NEW |