| 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/fwl_widgetimp.h" | 14 #include "xfa/fwl/core/fwl_widgetimp.h" |
| 15 #include "xfa/fwl/core/ifwl_app.h" | 15 #include "xfa/fwl/core/ifwl_app.h" |
| 16 #include "xfa/fwl/core/ifwl_themeprovider.h" | 16 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 17 | 17 |
| 18 #define FWL_WGT_CalcHeight 2048 | 18 #define FWL_WGT_CalcHeight 2048 |
| 19 #define FWL_WGT_CalcWidth 2048 | 19 #define FWL_WGT_CalcWidth 2048 |
| 20 #define FWL_WGT_CalcMultiLineDefWidth 120.0f | 20 #define FWL_WGT_CalcMultiLineDefWidth 120.0f |
| 21 | 21 |
| 22 IFWL_Widget* CFWL_Widget::GetWidget() { | 22 IFWL_Widget* CFWL_Widget::GetWidget() { |
| 23 return m_pIface; | 23 return m_pIface.get(); |
| 24 } |
| 25 |
| 26 const IFWL_Widget* CFWL_Widget::GetWidget() const { |
| 27 return m_pIface.get(); |
| 24 } | 28 } |
| 25 | 29 |
| 26 FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { | 30 FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { |
| 27 if (!m_pIface) | 31 if (!m_pIface) |
| 28 return FWL_Error::Indefinite; | 32 return FWL_Error::Indefinite; |
| 29 return m_pIface->GetClassName(wsClass); | 33 return m_pIface->GetClassName(wsClass); |
| 30 } | 34 } |
| 31 | 35 |
| 32 FWL_Type CFWL_Widget::GetClassID() const { | 36 FWL_Type CFWL_Widget::GetClassID() const { |
| 33 if (!m_pIface) | 37 if (!m_pIface) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 205 |
| 202 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | 206 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { |
| 203 if (!m_pIface) | 207 if (!m_pIface) |
| 204 return nullptr; | 208 return nullptr; |
| 205 | 209 |
| 206 m_pDelegate = m_pIface->SetDelegate(pDelegate); | 210 m_pDelegate = m_pIface->SetDelegate(pDelegate); |
| 207 return m_pDelegate; | 211 return m_pDelegate; |
| 208 } | 212 } |
| 209 | 213 |
| 210 CFWL_Widget::CFWL_Widget() | 214 CFWL_Widget::CFWL_Widget() |
| 211 : m_pIface(nullptr), m_pDelegate(nullptr), m_pProperties(nullptr) { | 215 : m_pDelegate(nullptr), |
| 212 m_pProperties = new CFWL_WidgetProperties; | 216 m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), |
| 213 m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | 217 m_pProperties(new CFWL_WidgetProperties) { |
| 214 ASSERT(m_pWidgetMgr); | 218 ASSERT(m_pWidgetMgr); |
| 215 } | 219 } |
| 216 | 220 |
| 217 CFWL_Widget::~CFWL_Widget() { | 221 CFWL_Widget::~CFWL_Widget() { |
| 218 delete m_pProperties; | 222 if (m_pIface) |
| 219 if (m_pIface) { | |
| 220 m_pIface->Finalize(); | 223 m_pIface->Finalize(); |
| 221 delete m_pIface; | |
| 222 } | |
| 223 } | 224 } |
| 224 | 225 |
| 225 FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { | 226 FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { |
| 226 if (!m_pIface) | 227 if (!m_pIface) |
| 227 return FWL_Error::Indefinite; | 228 return FWL_Error::Indefinite; |
| 228 | 229 |
| 229 CFX_RectF rect; | 230 CFX_RectF rect; |
| 230 if (pRect) { | 231 if (pRect) { |
| 231 rect = *pRect; | 232 rect = *pRect; |
| 232 } else { | 233 } else { |
| 233 m_pIface->GetWidgetRect(rect); | 234 m_pIface->GetWidgetRect(rect); |
| 234 rect.left = rect.top = 0; | 235 rect.left = rect.top = 0; |
| 235 } | 236 } |
| 236 return m_pWidgetMgr->RepaintWidget(m_pIface, &rect); | 237 return m_pWidgetMgr->RepaintWidget(m_pIface.get(), &rect); |
| 237 } | 238 } |
| 238 | 239 |
| 239 FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { | 240 FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { |
| 240 if (!m_pIface) | 241 if (!m_pIface) |
| 241 return FWL_Error::Indefinite; | 242 return FWL_Error::Indefinite; |
| 242 | 243 |
| 243 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 244 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 244 if (!pApp) | 245 if (!pApp) |
| 245 return FWL_Error::Indefinite; | 246 return FWL_Error::Indefinite; |
| 246 | 247 |
| 247 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | 248 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); |
| 248 if (!pDriver) | 249 if (!pDriver) |
| 249 return FWL_Error::Indefinite; | 250 return FWL_Error::Indefinite; |
| 250 | 251 |
| 251 if (bFocus) { | 252 if (bFocus) { |
| 252 pDriver->SetFocus(m_pIface); | 253 pDriver->SetFocus(m_pIface.get()); |
| 253 } else { | 254 } else { |
| 254 if (pDriver->GetFocus() == m_pIface) { | 255 if (pDriver->GetFocus() == m_pIface.get()) { |
| 255 pDriver->SetFocus(nullptr); | 256 pDriver->SetFocus(nullptr); |
| 256 } | 257 } |
| 257 } | 258 } |
| 258 return FWL_Error::Succeeded; | 259 return FWL_Error::Succeeded; |
| 259 } | 260 } |
| 260 | 261 |
| 261 FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { | 262 FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { |
| 262 if (!m_pIface) | 263 if (!m_pIface) |
| 263 return FWL_Error::Indefinite; | 264 return FWL_Error::Indefinite; |
| 264 | 265 |
| 265 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 266 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 266 if (!pApp) | 267 if (!pApp) |
| 267 return FWL_Error::Indefinite; | 268 return FWL_Error::Indefinite; |
| 268 | 269 |
| 269 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | 270 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); |
| 270 if (!pDriver) | 271 if (!pDriver) |
| 271 return FWL_Error::Indefinite; | 272 return FWL_Error::Indefinite; |
| 272 | 273 |
| 273 pDriver->SetGrab(m_pIface, bSet); | 274 pDriver->SetGrab(m_pIface.get(), bSet); |
| 274 return FWL_Error::Succeeded; | 275 return FWL_Error::Succeeded; |
| 275 } | 276 } |
| 276 | 277 |
| 277 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, | 278 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, |
| 278 uint32_t dwFilter) { | 279 uint32_t dwFilter) { |
| 279 if (!m_pIface) | 280 if (!m_pIface) |
| 280 return; | 281 return; |
| 281 | 282 |
| 282 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 283 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 283 if (!pApp) | 284 if (!pApp) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 313 FX_BOOL bMultiLine, | 314 FX_BOOL bMultiLine, |
| 314 int32_t iLineWidth) { | 315 int32_t iLineWidth) { |
| 315 if (!m_pIface) | 316 if (!m_pIface) |
| 316 return CFX_SizeF(); | 317 return CFX_SizeF(); |
| 317 | 318 |
| 318 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); | 319 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); |
| 319 if (!pTheme) | 320 if (!pTheme) |
| 320 return CFX_SizeF(); | 321 return CFX_SizeF(); |
| 321 | 322 |
| 322 CFWL_ThemeText calPart; | 323 CFWL_ThemeText calPart; |
| 323 calPart.m_pWidget = m_pIface; | 324 calPart.m_pWidget = m_pIface.get(); |
| 324 calPart.m_wsText = wsText; | 325 calPart.m_wsText = wsText; |
| 325 calPart.m_dwTTOStyles = | 326 calPart.m_dwTTOStyles = |
| 326 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; | 327 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; |
| 327 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | 328 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; |
| 328 CFX_RectF rect; | 329 CFX_RectF rect; |
| 329 FX_FLOAT fWidth = bMultiLine | 330 FX_FLOAT fWidth = bMultiLine |
| 330 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth | 331 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth |
| 331 : FWL_WGT_CalcMultiLineDefWidth) | 332 : FWL_WGT_CalcMultiLineDefWidth) |
| 332 : FWL_WGT_CalcWidth; | 333 : FWL_WGT_CalcWidth; |
| 333 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); | 334 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); |
| 334 pTheme->CalcTextRect(&calPart, rect); | 335 pTheme->CalcTextRect(&calPart, rect); |
| 335 return CFX_SizeF(rect.width, rect.height); | 336 return CFX_SizeF(rect.width, rect.height); |
| 336 } | 337 } |
| OLD | NEW |