| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/src/fwl/core/fwl_panelimp.h" | |
| 8 | |
| 9 #include "xfa/include/fwl/core/fwl_content.h" | |
| 10 #include "xfa/include/fwl/core/fwl_grid.h" | |
| 11 #include "xfa/include/fwl/core/fwl_panel.h" | |
| 12 #include "xfa/src/fwl/core/fwl_noteimp.h" | |
| 13 #include "xfa/src/fwl/core/fwl_targetimp.h" | |
| 14 #include "xfa/src/fwl/core/fwl_widgetimp.h" | |
| 15 #include "xfa/src/fwl/core/fwl_widgetmgrimp.h" | |
| 16 | |
| 17 // static | |
| 18 IFWL_Panel* IFWL_Panel::Create(CFWL_WidgetImpProperties& properties, | |
| 19 IFWL_Widget* pOuter) { | |
| 20 IFWL_Panel* pPanel = new IFWL_Panel; | |
| 21 CFWL_PanelImp* pPanelImpl = new CFWL_PanelImp(properties, pOuter); | |
| 22 pPanel->SetImpl(pPanelImpl); | |
| 23 pPanelImpl->SetInterface(pPanel); | |
| 24 return pPanel; | |
| 25 } | |
| 26 IFWL_Panel::IFWL_Panel() {} | |
| 27 IFWL_Content* IFWL_Panel::GetContent() { | |
| 28 return static_cast<CFWL_PanelImp*>(GetImpl())->GetContent(); | |
| 29 } | |
| 30 FWL_ERR IFWL_Panel::SetContent(IFWL_Content* pContent) { | |
| 31 return static_cast<CFWL_PanelImp*>(GetImpl())->SetContent(pContent); | |
| 32 } | |
| 33 | |
| 34 CFWL_PanelImp::CFWL_PanelImp(const CFWL_WidgetImpProperties& properties, | |
| 35 IFWL_Widget* pOuter) | |
| 36 : CFWL_WidgetImp(properties, pOuter), m_pContent(nullptr) {} | |
| 37 CFWL_PanelImp::~CFWL_PanelImp() {} | |
| 38 FWL_ERR CFWL_PanelImp::GetClassName(CFX_WideString& wsClass) const { | |
| 39 wsClass = FWL_CLASS_Panel; | |
| 40 return FWL_ERR_Succeeded; | |
| 41 } | |
| 42 FX_DWORD CFWL_PanelImp::GetClassID() const { | |
| 43 return FWL_CLASSHASH_Panel; | |
| 44 } | |
| 45 FWL_ERR CFWL_PanelImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 46 if (bAutoSize) { | |
| 47 if (m_pContent) { | |
| 48 m_pContent->GetWidgetRect(rect, TRUE); | |
| 49 } | |
| 50 } else { | |
| 51 rect = m_pProperties->m_rtWidget; | |
| 52 } | |
| 53 return FWL_ERR_Succeeded; | |
| 54 } | |
| 55 FWL_ERR CFWL_PanelImp::Update() { | |
| 56 if (m_pContent) { | |
| 57 CFX_RectF rtClient; | |
| 58 GetClientRect(rtClient); | |
| 59 FWL_GRIDUNIT eWidth = FWL_GRIDUNIT_Fixed, eHeight = FWL_GRIDUNIT_Fixed; | |
| 60 IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr(); | |
| 61 if (!pWidgetMgr) | |
| 62 return FWL_ERR_Indefinite; | |
| 63 IFWL_Widget* pParent = | |
| 64 pWidgetMgr->GetWidget(GetInterface(), FWL_WGTRELATION_Parent); | |
| 65 if (pParent && pParent->GetClassID() == FWL_CLASSHASH_Grid) { | |
| 66 IFWL_Grid* pGrid = static_cast<IFWL_Grid*>(pParent); | |
| 67 pGrid->GetWidgetSize(GetInterface(), FWL_GRIDSIZE_Width, eWidth); | |
| 68 pGrid->GetWidgetSize(GetInterface(), FWL_GRIDSIZE_Height, eHeight); | |
| 69 } | |
| 70 m_pContent->SetWidgetRect(rtClient); | |
| 71 m_pContent->Update(); | |
| 72 } | |
| 73 return FWL_ERR_Succeeded; | |
| 74 } | |
| 75 IFWL_Content* CFWL_PanelImp::GetContent() { | |
| 76 return m_pContent; | |
| 77 } | |
| 78 FWL_ERR CFWL_PanelImp::SetContent(IFWL_Content* pContent) { | |
| 79 if (!pContent) | |
| 80 return FWL_ERR_Indefinite; | |
| 81 m_pContent = pContent; | |
| 82 return pContent->SetParent(m_pInterface); | |
| 83 } | |
| 84 class CFWL_CustomPanelImp : public CFWL_WidgetImp { | |
| 85 public: | |
| 86 CFWL_CustomPanelImp(const CFWL_WidgetImpProperties& properties, | |
| 87 IFWL_Widget* pOuter); | |
| 88 virtual ~CFWL_CustomPanelImp(); | |
| 89 virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); | |
| 90 virtual FWL_ERR Update(); | |
| 91 virtual IFWL_Content* GetContent(); | |
| 92 virtual FWL_ERR SetContent(IFWL_Content* pContent); | |
| 93 FWL_ERR SetProxy(IFWL_Proxy* pProxy); | |
| 94 | |
| 95 protected: | |
| 96 IFWL_Content* m_pContent; | |
| 97 IFWL_Proxy* m_pProxy; | |
| 98 }; | |
| 99 CFWL_CustomPanelImp::CFWL_CustomPanelImp( | |
| 100 const CFWL_WidgetImpProperties& properties, | |
| 101 IFWL_Widget* pOuter) | |
| 102 : CFWL_WidgetImp(properties, pOuter), | |
| 103 m_pContent(nullptr), | |
| 104 m_pProxy(nullptr) {} | |
| 105 CFWL_CustomPanelImp::~CFWL_CustomPanelImp() {} | |
| 106 FWL_ERR CFWL_CustomPanelImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 107 if (bAutoSize && m_pProxy && | |
| 108 (m_pProxy->GetWidgetRect(rect, bAutoSize) == FWL_ERR_Succeeded)) { | |
| 109 return FWL_ERR_Succeeded; | |
| 110 } | |
| 111 return CFWL_WidgetImp::GetWidgetRect(rect, bAutoSize); | |
| 112 } | |
| 113 FWL_ERR CFWL_CustomPanelImp::Update() { | |
| 114 if (m_pProxy) { | |
| 115 return m_pProxy->Update(); | |
| 116 } | |
| 117 return CFWL_WidgetImp::Update(); | |
| 118 } | |
| 119 IFWL_Content* CFWL_CustomPanelImp::GetContent() { | |
| 120 return m_pContent; | |
| 121 } | |
| 122 FWL_ERR CFWL_CustomPanelImp::SetContent(IFWL_Content* pContent) { | |
| 123 if (!pContent) | |
| 124 return FWL_ERR_Indefinite; | |
| 125 m_pContent = pContent; | |
| 126 return pContent->SetParent(m_pInterface); | |
| 127 } | |
| 128 FWL_ERR CFWL_CustomPanelImp::SetProxy(IFWL_Proxy* pProxy) { | |
| 129 m_pProxy = pProxy; | |
| 130 return FWL_ERR_Succeeded; | |
| 131 } | |
| 132 | |
| 133 // statuc | |
| 134 IFWL_CustomPanel* IFWL_CustomPanel::Create(CFWL_WidgetImpProperties& properties, | |
| 135 IFWL_Widget* pOuter) { | |
| 136 IFWL_CustomPanel* pCustomPanel = new IFWL_CustomPanel; | |
| 137 CFWL_CustomPanelImp* pCustomPanelImpl = | |
| 138 new CFWL_CustomPanelImp(properties, pOuter); | |
| 139 pCustomPanel->SetImpl(pCustomPanelImpl); | |
| 140 pCustomPanelImpl->SetInterface(pCustomPanel); | |
| 141 return pCustomPanel; | |
| 142 } | |
| 143 IFWL_CustomPanel::IFWL_CustomPanel() {} | |
| 144 IFWL_Content* IFWL_CustomPanel::GetContent() { | |
| 145 return static_cast<CFWL_CustomPanelImp*>(GetImpl())->GetContent(); | |
| 146 } | |
| 147 FWL_ERR IFWL_CustomPanel::SetContent(IFWL_Content* pContent) { | |
| 148 return static_cast<CFWL_CustomPanelImp*>(GetImpl())->SetContent(pContent); | |
| 149 } | |
| 150 FWL_ERR IFWL_CustomPanel::SetProxy(IFWL_Proxy* pProxy) { | |
| 151 return static_cast<CFWL_CustomPanelImp*>(GetImpl())->SetProxy(pProxy); | |
| 152 } | |
| OLD | NEW |