| 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 "xfa/fwl/lightwidget/cfwl_widget.h" | 7 #include "xfa/fwl/lightwidget/cfwl_widget.h" |
| 8 | 8 |
| 9 #include "xfa/fde/tto/fde_textout.h" | 9 #include "xfa/fde/tto/fde_textout.h" |
| 10 #include "xfa/fwl/core/cfwl_themetext.h" | 10 #include "xfa/fwl/core/cfwl_themetext.h" |
| 11 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 11 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
| 12 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
| 13 #include "xfa/fwl/core/fwl_noteimp.h" | 13 #include "xfa/fwl/core/fwl_noteimp.h" |
| 14 #include "xfa/fwl/core/ifwl_app.h" | 14 #include "xfa/fwl/core/ifwl_app.h" |
| 15 #include "xfa/fwl/core/ifwl_themeprovider.h" | 15 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 16 | 16 |
| 17 #define FWL_WGT_CalcHeight 2048 | 17 #define FWL_WGT_CalcHeight 2048 |
| 18 #define FWL_WGT_CalcWidth 2048 | 18 #define FWL_WGT_CalcWidth 2048 |
| 19 #define FWL_WGT_CalcMultiLineDefWidth 120.0f | 19 #define FWL_WGT_CalcMultiLineDefWidth 120.0f |
| 20 | 20 |
| 21 CFWL_Widget::CFWL_Widget() |
| 22 : m_pDelegate(nullptr), |
| 23 m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), |
| 24 m_pProperties(new CFWL_WidgetProperties) { |
| 25 ASSERT(m_pWidgetMgr); |
| 26 } |
| 27 |
| 28 CFWL_Widget::~CFWL_Widget() { |
| 29 if (m_pIface) |
| 30 m_pIface->Finalize(); |
| 31 } |
| 32 |
| 21 IFWL_Widget* CFWL_Widget::GetWidget() { | 33 IFWL_Widget* CFWL_Widget::GetWidget() { |
| 22 return m_pIface.get(); | 34 return m_pIface.get(); |
| 23 } | 35 } |
| 24 | 36 |
| 25 const IFWL_Widget* CFWL_Widget::GetWidget() const { | 37 const IFWL_Widget* CFWL_Widget::GetWidget() const { |
| 26 return m_pIface.get(); | 38 return m_pIface.get(); |
| 27 } | 39 } |
| 28 | 40 |
| 29 FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { | |
| 30 if (!m_pIface) | |
| 31 return FWL_Error::Indefinite; | |
| 32 return m_pIface->GetClassName(wsClass); | |
| 33 } | |
| 34 | |
| 35 FWL_Type CFWL_Widget::GetClassID() const { | |
| 36 if (!m_pIface) | |
| 37 return FWL_Type::Unknown; | |
| 38 return m_pIface->GetClassID(); | |
| 39 } | |
| 40 | |
| 41 FX_BOOL CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { | |
| 42 if (!m_pIface) | |
| 43 return FALSE; | |
| 44 return m_pIface->IsInstance(wsClass); | |
| 45 } | |
| 46 | |
| 47 FWL_Error CFWL_Widget::Initialize(const CFWL_WidgetProperties* pProperties) { | 41 FWL_Error CFWL_Widget::Initialize(const CFWL_WidgetProperties* pProperties) { |
| 48 if (!m_pIface) | 42 if (!m_pIface) |
| 49 return FWL_Error::Indefinite; | 43 return FWL_Error::Indefinite; |
| 50 m_pIface->SetAssociateWidget(this); | 44 m_pIface->SetAssociateWidget(this); |
| 51 return FWL_Error::Succeeded; | 45 return FWL_Error::Succeeded; |
| 52 } | 46 } |
| 53 | 47 |
| 54 FWL_Error CFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 48 FWL_Error CFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { |
| 55 if (!m_pIface) | 49 if (!m_pIface) |
| 56 return FWL_Error::Indefinite; | 50 return FWL_Error::Indefinite; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 68 return FWL_Error::Indefinite; | 62 return FWL_Error::Indefinite; |
| 69 return m_pIface->SetWidgetRect(rect); | 63 return m_pIface->SetWidgetRect(rect); |
| 70 } | 64 } |
| 71 | 65 |
| 72 FWL_Error CFWL_Widget::GetClientRect(CFX_RectF& rect) { | 66 FWL_Error CFWL_Widget::GetClientRect(CFX_RectF& rect) { |
| 73 if (!m_pIface) | 67 if (!m_pIface) |
| 74 return FWL_Error::Indefinite; | 68 return FWL_Error::Indefinite; |
| 75 return m_pIface->GetClientRect(rect); | 69 return m_pIface->GetClientRect(rect); |
| 76 } | 70 } |
| 77 | 71 |
| 78 CFWL_Widget* CFWL_Widget::GetParent() { | |
| 79 if (!m_pIface) | |
| 80 return nullptr; | |
| 81 | |
| 82 IFWL_Widget* parent = m_pIface->GetParent(); | |
| 83 if (!parent) | |
| 84 return nullptr; | |
| 85 | |
| 86 return static_cast<CFWL_Widget*>(parent->GetAssociateWidget()); | |
| 87 } | |
| 88 | |
| 89 FWL_Error CFWL_Widget::SetParent(CFWL_Widget* pParent) { | |
| 90 if (!m_pIface) | |
| 91 return FWL_Error::Indefinite; | |
| 92 return m_pIface->SetParent(pParent ? pParent->GetWidget() : nullptr); | |
| 93 } | |
| 94 | |
| 95 CFWL_Widget* CFWL_Widget::GetOwner() { | |
| 96 return nullptr; | |
| 97 } | |
| 98 | |
| 99 FWL_Error CFWL_Widget::SetOwner(CFWL_Widget* pOwner) { | |
| 100 if (!m_pIface) | |
| 101 return FWL_Error::Indefinite; | |
| 102 return FWL_Error::Succeeded; | |
| 103 } | |
| 104 | |
| 105 uint32_t CFWL_Widget::GetStyles() { | |
| 106 if (!m_pIface) | |
| 107 return 0; | |
| 108 return m_pIface->GetStyles(); | |
| 109 } | |
| 110 | |
| 111 FWL_Error CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, | 72 FWL_Error CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, |
| 112 uint32_t dwStylesRemoved) { | 73 uint32_t dwStylesRemoved) { |
| 113 if (!m_pIface) | 74 if (!m_pIface) |
| 114 return FWL_Error::Indefinite; | 75 return FWL_Error::Indefinite; |
| 115 return m_pIface->ModifyStyles(dwStylesAdded, dwStylesRemoved); | 76 return m_pIface->ModifyStyles(dwStylesAdded, dwStylesRemoved); |
| 116 } | 77 } |
| 117 | 78 |
| 118 uint32_t CFWL_Widget::GetStylesEx() { | 79 uint32_t CFWL_Widget::GetStylesEx() { |
| 119 if (!m_pIface) | 80 if (!m_pIface) |
| 120 return 0; | 81 return 0; |
| 121 return m_pIface->GetStylesEx(); | 82 return m_pIface->GetStylesEx(); |
| 122 } | 83 } |
| 123 | 84 |
| 124 FWL_Error CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, | 85 FWL_Error CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, |
| 125 uint32_t dwStylesExRemoved) { | 86 uint32_t dwStylesExRemoved) { |
| 126 return m_pIface->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 87 return m_pIface->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 127 } | 88 } |
| 128 | 89 |
| 129 uint32_t CFWL_Widget::GetStates() { | 90 uint32_t CFWL_Widget::GetStates() { |
| 130 return m_pIface ? m_pIface->GetStates() : 0; | 91 return m_pIface ? m_pIface->GetStates() : 0; |
| 131 } | 92 } |
| 132 | 93 |
| 133 void CFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 94 void CFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
| 134 if (m_pIface) | 95 if (m_pIface) |
| 135 m_pIface->SetStates(dwStates, bSet); | 96 m_pIface->SetStates(dwStates, bSet); |
| 136 } | 97 } |
| 137 | 98 |
| 138 void* CFWL_Widget::GetLayoutItem() const { | |
| 139 return m_pIface ? m_pIface->GetLayoutItem() : nullptr; | |
| 140 } | |
| 141 | |
| 142 void CFWL_Widget::SetLayoutItem(void* pItem) { | 99 void CFWL_Widget::SetLayoutItem(void* pItem) { |
| 143 if (m_pIface) | 100 if (m_pIface) |
| 144 m_pIface->SetLayoutItem(pItem); | 101 m_pIface->SetLayoutItem(pItem); |
| 145 } | 102 } |
| 146 | 103 |
| 147 FWL_Error CFWL_Widget::Update() { | 104 void CFWL_Widget::Update() { |
| 148 if (!m_pIface) | 105 if (!m_pIface) |
| 149 return FWL_Error::Indefinite; | 106 return; |
| 150 return m_pIface->Update(); | 107 m_pIface->Update(); |
| 151 } | 108 } |
| 152 | 109 |
| 153 FWL_Error CFWL_Widget::LockUpdate() { | 110 void CFWL_Widget::LockUpdate() { |
| 154 if (!m_pIface) | 111 if (!m_pIface) |
| 155 return FWL_Error::Indefinite; | 112 return; |
| 156 return m_pIface->LockUpdate(); | 113 m_pIface->LockUpdate(); |
| 157 } | 114 } |
| 158 | 115 |
| 159 FWL_Error CFWL_Widget::UnlockUpdate() { | 116 void CFWL_Widget::UnlockUpdate() { |
| 160 if (!m_pIface) | 117 if (!m_pIface) |
| 161 return FWL_Error::Indefinite; | 118 return; |
| 162 return m_pIface->UnlockUpdate(); | 119 m_pIface->UnlockUpdate(); |
| 163 } | 120 } |
| 164 | 121 |
| 165 FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 122 FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 166 if (!m_pIface) | 123 if (!m_pIface) |
| 167 return FWL_WidgetHit::Unknown; | 124 return FWL_WidgetHit::Unknown; |
| 168 return m_pIface->HitTest(fx, fy); | 125 return m_pIface->HitTest(fx, fy); |
| 169 } | 126 } |
| 170 | 127 |
| 171 FWL_Error CFWL_Widget::TransformTo(CFWL_Widget* pWidget, | |
| 172 FX_FLOAT& fx, | |
| 173 FX_FLOAT& fy) { | |
| 174 if (!m_pIface) | |
| 175 return FWL_Error::Indefinite; | |
| 176 return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : nullptr, fx, | |
| 177 fy); | |
| 178 } | |
| 179 | |
| 180 FWL_Error CFWL_Widget::TransformTo(CFWL_Widget* pWidget, CFX_RectF& rt) { | |
| 181 if (!m_pIface) | |
| 182 return FWL_Error::Indefinite; | |
| 183 return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : nullptr, rt); | |
| 184 } | |
| 185 | |
| 186 FWL_Error CFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
| 187 if (!m_pIface) | |
| 188 return FWL_Error::Indefinite; | |
| 189 return m_pIface->GetMatrix(matrix, bGlobal); | |
| 190 } | |
| 191 | |
| 192 FWL_Error CFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { | |
| 193 if (!m_pIface) | |
| 194 return FWL_Error::Indefinite; | |
| 195 return m_pIface->SetMatrix(matrix); | |
| 196 } | |
| 197 | |
| 198 FWL_Error CFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, | 128 FWL_Error CFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, |
| 199 const CFX_Matrix* pMatrix) { | 129 const CFX_Matrix* pMatrix) { |
| 200 if (!m_pIface) | 130 if (!m_pIface) |
| 201 return FWL_Error::Indefinite; | 131 return FWL_Error::Indefinite; |
| 202 return m_pIface->DrawWidget(pGraphics, pMatrix); | 132 return m_pIface->DrawWidget(pGraphics, pMatrix); |
| 203 } | 133 } |
| 204 | 134 |
| 205 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | 135 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { |
| 206 if (!m_pIface) | 136 if (!m_pIface) |
| 207 return nullptr; | 137 return nullptr; |
| 208 | 138 |
| 209 m_pDelegate = m_pIface->SetDelegate(pDelegate); | 139 m_pDelegate = m_pIface->SetDelegate(pDelegate); |
| 210 return m_pDelegate; | 140 return m_pDelegate; |
| 211 } | 141 } |
| 212 | |
| 213 CFWL_Widget::CFWL_Widget() | |
| 214 : m_pDelegate(nullptr), | |
| 215 m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), | |
| 216 m_pProperties(new CFWL_WidgetProperties) { | |
| 217 ASSERT(m_pWidgetMgr); | |
| 218 } | |
| 219 | |
| 220 CFWL_Widget::~CFWL_Widget() { | |
| 221 if (m_pIface) | |
| 222 m_pIface->Finalize(); | |
| 223 } | |
| 224 | |
| 225 FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { | |
| 226 if (!m_pIface) | |
| 227 return FWL_Error::Indefinite; | |
| 228 | |
| 229 CFX_RectF rect; | |
| 230 if (pRect) { | |
| 231 rect = *pRect; | |
| 232 } else { | |
| 233 m_pIface->GetWidgetRect(rect); | |
| 234 rect.left = rect.top = 0; | |
| 235 } | |
| 236 return m_pWidgetMgr->RepaintWidget(m_pIface.get(), &rect); | |
| 237 } | |
| 238 | |
| 239 FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { | |
| 240 if (!m_pIface) | |
| 241 return FWL_Error::Indefinite; | |
| 242 | |
| 243 IFWL_App* pApp = m_pIface->GetOwnerApp(); | |
| 244 if (!pApp) | |
| 245 return FWL_Error::Indefinite; | |
| 246 | |
| 247 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | |
| 248 if (!pDriver) | |
| 249 return FWL_Error::Indefinite; | |
| 250 | |
| 251 if (bFocus) { | |
| 252 pDriver->SetFocus(m_pIface.get()); | |
| 253 } else { | |
| 254 if (pDriver->GetFocus() == m_pIface.get()) { | |
| 255 pDriver->SetFocus(nullptr); | |
| 256 } | |
| 257 } | |
| 258 return FWL_Error::Succeeded; | |
| 259 } | |
| 260 | |
| 261 FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { | |
| 262 if (!m_pIface) | |
| 263 return FWL_Error::Indefinite; | |
| 264 | |
| 265 IFWL_App* pApp = m_pIface->GetOwnerApp(); | |
| 266 if (!pApp) | |
| 267 return FWL_Error::Indefinite; | |
| 268 | |
| 269 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | |
| 270 if (!pDriver) | |
| 271 return FWL_Error::Indefinite; | |
| 272 | |
| 273 pDriver->SetGrab(m_pIface.get(), bSet); | |
| 274 return FWL_Error::Succeeded; | |
| 275 } | |
| 276 | |
| 277 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, | |
| 278 uint32_t dwFilter) { | |
| 279 if (!m_pIface) | |
| 280 return; | |
| 281 | |
| 282 IFWL_App* pApp = m_pIface->GetOwnerApp(); | |
| 283 if (!pApp) | |
| 284 return; | |
| 285 | |
| 286 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | |
| 287 if (!pNoteDriver) | |
| 288 return; | |
| 289 | |
| 290 IFWL_Widget* pEventSourceImp = | |
| 291 !pEventSource ? nullptr : pEventSource->GetWidget(); | |
| 292 pNoteDriver->RegisterEventTarget(GetWidget(), pEventSourceImp, dwFilter); | |
| 293 } | |
| 294 | |
| 295 void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { | |
| 296 if (!m_pIface) | |
| 297 return; | |
| 298 if (m_pIface->GetOuter()) | |
| 299 return; | |
| 300 | |
| 301 IFWL_App* pApp = m_pIface->GetOwnerApp(); | |
| 302 if (!pApp) | |
| 303 return; | |
| 304 | |
| 305 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | |
| 306 if (!pNoteDriver) | |
| 307 return; | |
| 308 | |
| 309 pNoteDriver->SendEvent(pEvent); | |
| 310 } | |
| 311 | |
| 312 CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, | |
| 313 FX_BOOL bMultiLine, | |
| 314 int32_t iLineWidth) { | |
| 315 if (!m_pIface) | |
| 316 return CFX_SizeF(); | |
| 317 | |
| 318 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); | |
| 319 if (!pTheme) | |
| 320 return CFX_SizeF(); | |
| 321 | |
| 322 CFWL_ThemeText calPart; | |
| 323 calPart.m_pWidget = m_pIface.get(); | |
| 324 calPart.m_wsText = wsText; | |
| 325 calPart.m_dwTTOStyles = | |
| 326 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; | |
| 327 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | |
| 328 CFX_RectF rect; | |
| 329 FX_FLOAT fWidth = bMultiLine | |
| 330 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth | |
| 331 : FWL_WGT_CalcMultiLineDefWidth) | |
| 332 : FWL_WGT_CalcWidth; | |
| 333 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); | |
| 334 pTheme->CalcTextRect(&calPart, rect); | |
| 335 return CFX_SizeF(rect.width, rect.height); | |
| 336 } | |
| OLD | NEW |