Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / core / fwl_contentimp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "include/fwl_targetimp.h"\r
9 #include "include/fwl_threadimp.h"\r
10 #include "include/fwl_noteimp.h"\r
11 #include "include/fwl_widgetimp.h"\r
12 #include "include/fwl_contentimp.h"\r
13 #include "include/fwl_widgetmgrimp.h"\r
14 IFWL_Content* IFWL_Content::Create()\r
15 {\r
16     return new IFWL_Content;\r
17 }\r
18 FWL_ERR IFWL_Content::Initialize()\r
19 {\r
20     m_pData = FX_NEW CFWL_ContentImp;\r
21     ((CFWL_ContentImp*)m_pData)->SetInterface(this);\r
22     return ((CFWL_ContentImp*)m_pData)->Initialize();\r
23 }\r
24 FWL_ERR IFWL_Content::InsertWidget(IFWL_Widget *pChild, FX_INT32 nIndex )\r
25 {\r
26     return ((CFWL_ContentImp*)m_pData)->InsertWidget(pChild, nIndex);\r
27 }\r
28 FWL_ERR IFWL_Content::RemoveWidget(IFWL_Widget *pWidget)\r
29 {\r
30     return ((CFWL_ContentImp*)m_pData)->RemoveWidget(pWidget);\r
31 }\r
32 FWL_ERR IFWL_Content::RemoveAllWidgets()\r
33 {\r
34     return ((CFWL_ContentImp*)m_pData)->RemoveAllWidgets();\r
35 }\r
36 FWL_ERR IFWL_Content::GetMinSize(FX_FLOAT &fWidth, FX_FLOAT &fHeight)\r
37 {\r
38     return ((CFWL_ContentImp*)m_pData)->GetMinSize(fWidth, fHeight);\r
39 }\r
40 FWL_ERR IFWL_Content::SetMinSize(FX_FLOAT fWidth, FX_FLOAT fHeight)\r
41 {\r
42     return ((CFWL_ContentImp*)m_pData)->SetMinSize(fWidth, fHeight);\r
43 }\r
44 FWL_ERR IFWL_Content::GetMaxSize(FX_FLOAT &fWidth, FX_FLOAT &fHeight)\r
45 {\r
46     return ((CFWL_ContentImp*)m_pData)->GetMaxSize(fWidth, fHeight);\r
47 }\r
48 FWL_ERR IFWL_Content::SetMaxSize(FX_FLOAT fWidth, FX_FLOAT fHeight)\r
49 {\r
50     return ((CFWL_ContentImp*)m_pData)->SetMaxSize(fWidth, fHeight);\r
51 }\r
52 IFWL_Content::IFWL_Content()\r
53 {\r
54     m_pData = NULL;\r
55 }\r
56 IFWL_Content::~IFWL_Content()\r
57 {\r
58     if (m_pData) {\r
59         delete (CFWL_ContentImp*)m_pData;\r
60         m_pData = NULL;\r
61     }\r
62 }\r
63 CFWL_ContentImp::CFWL_ContentImp()\r
64 {\r
65     m_fWidthMin = 0;\r
66     m_fWidthMax = 10000;\r
67     m_fHeightMin = 0;\r
68     m_fHeightMax = 10000;\r
69 }\r
70 CFWL_ContentImp::CFWL_ContentImp(const CFWL_WidgetImpProperties &properties)\r
71     : CFWL_WidgetImp(properties)\r
72 {\r
73     m_fWidthMin = 0;\r
74     m_fWidthMax = 10000;\r
75     m_fHeightMin = 0;\r
76     m_fHeightMax = 10000;\r
77 }\r
78 CFWL_ContentImp::~CFWL_ContentImp()\r
79 {\r
80 }\r
81 FWL_ERR CFWL_ContentImp::InsertWidget(IFWL_Widget *pChild, FX_INT32 nIndex )\r
82 {\r
83     _FWL_RETURN_VALUE_IF_FAIL(pChild, FWL_ERR_Indefinite);\r
84     pChild->SetParent(m_pInterface);\r
85     if (nIndex == -1) {\r
86         return FWL_ERR_Succeeded;\r
87     }\r
88     CFWL_WidgetMgr *pMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
89     _FWL_RETURN_VALUE_IF_FAIL(pMgr, FWL_ERR_Indefinite);\r
90     pMgr->SetWidgetIndex(pChild, nIndex);\r
91     return FWL_ERR_Succeeded;\r
92 }\r
93 FWL_ERR CFWL_ContentImp::RemoveWidget(IFWL_Widget *pWidget)\r
94 {\r
95     _FWL_RETURN_VALUE_IF_FAIL(pWidget, FWL_ERR_Indefinite);\r
96     pWidget->SetParent(NULL);\r
97     return FWL_ERR_Succeeded;\r
98 }\r
99 FWL_ERR CFWL_ContentImp::RemoveAllWidgets()\r
100 {\r
101     CFWL_WidgetMgr *pMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
102     _FWL_RETURN_VALUE_IF_FAIL(pMgr, FWL_ERR_Indefinite);\r
103     while (IFWL_Widget * widget = pMgr->GetWidget(m_pInterface, FWL_WGTRELATION_FirstChild)) {\r
104         pMgr->SetParent(NULL, widget);\r
105     }\r
106     return FWL_ERR_Succeeded;\r
107 }\r
108 FWL_ERR CFWL_ContentImp::GetMinSize(FX_FLOAT &fWidth, FX_FLOAT &fHeight)\r
109 {\r
110     fWidth = m_fWidthMin;\r
111     fHeight = m_fHeightMin;\r
112     return FWL_ERR_Succeeded;\r
113 }\r
114 FWL_ERR CFWL_ContentImp::SetMinSize(FX_FLOAT fWidth, FX_FLOAT fHeight)\r
115 {\r
116     m_fWidthMin = fWidth;\r
117     m_fHeightMin = fHeight;\r
118     return FWL_ERR_Succeeded;\r
119 }\r
120 FWL_ERR CFWL_ContentImp::GetMaxSize(FX_FLOAT &fWidth, FX_FLOAT &fHeight)\r
121 {\r
122     fWidth = m_fWidthMax;\r
123     fHeight = m_fHeightMax;\r
124     return FWL_ERR_Succeeded;\r
125 }\r
126 FWL_ERR CFWL_ContentImp::SetMaxSize(FX_FLOAT fWidth, FX_FLOAT fHeight)\r
127 {\r
128     m_fWidthMax = fWidth;\r
129     m_fHeightMax = fHeight;\r
130     return FWL_ERR_Succeeded;\r
131 }\r