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/foxitlib.h"
8 #include "xfa/src/fwl/src/core/include/fwl_targetimp.h"
9 #include "xfa/src/fwl/src/core/include/fwl_threadimp.h"
10 #include "xfa/src/fwl/src/core/include/fwl_noteimp.h"
11 #include "xfa/src/fwl/src/core/include/fwl_widgetmgrimp.h"
12 #include "xfa/src/fwl/src/core/include/fwl_appimp.h"
13 
Create(IFWL_AdapterNative * pAdapter)14 IFWL_App* IFWL_App::Create(IFWL_AdapterNative* pAdapter) {
15   IFWL_App* pApp = new IFWL_App;
16   pApp->SetImpl(new CFWL_AppImp(pApp, pAdapter));
17   return pApp;
18 }
Initialize()19 FWL_ERR IFWL_App::Initialize() {
20   return static_cast<CFWL_AppImp*>(GetImpl())->Initialize();
21 }
Finalize()22 FWL_ERR IFWL_App::Finalize() {
23   return static_cast<CFWL_AppImp*>(GetImpl())->Finalize();
24 }
GetAdapterNative()25 IFWL_AdapterNative* IFWL_App::GetAdapterNative() {
26   return static_cast<CFWL_AppImp*>(GetImpl())->GetAdapterNative();
27 }
GetWidgetMgr()28 IFWL_WidgetMgr* IFWL_App::GetWidgetMgr() {
29   return static_cast<CFWL_AppImp*>(GetImpl())->GetWidgetMgr();
30 }
GetThemeProvider()31 IFWL_ThemeProvider* IFWL_App::GetThemeProvider() {
32   return static_cast<CFWL_AppImp*>(GetImpl())->GetThemeProvider();
33 }
SetThemeProvider(IFWL_ThemeProvider * pThemeProvider)34 FWL_ERR IFWL_App::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
35   return static_cast<CFWL_AppImp*>(GetImpl())->SetThemeProvider(pThemeProvider);
36 }
Exit(int32_t iExitCode)37 FWL_ERR IFWL_App::Exit(int32_t iExitCode) {
38   return static_cast<CFWL_AppImp*>(GetImpl())->Exit(iExitCode);
39 }
40 
CFWL_AppImp(IFWL_App * pIface,IFWL_AdapterNative * pAdapter)41 CFWL_AppImp::CFWL_AppImp(IFWL_App* pIface, IFWL_AdapterNative* pAdapter)
42     : CFWL_NoteThreadImp(pIface), m_pWidgetMgr(NULL), m_pThemeProvider(NULL) {
43   if (!pAdapter) {
44     pAdapter = FWL_CreateFuelAdapterNative();
45     m_bFuelAdapter = TRUE;
46   } else {
47     m_bFuelAdapter = FALSE;
48   }
49   m_pAdapterNative = pAdapter;
50 }
~CFWL_AppImp()51 CFWL_AppImp::~CFWL_AppImp() {
52   CFWL_ToolTipContainer::DeleteInstance();
53   if (m_bFuelAdapter) {
54     FWL_ReleaseFuelAdapterNative(m_pAdapterNative);
55     m_pAdapterNative = NULL;
56   }
57   if (m_pWidgetMgr) {
58     delete m_pWidgetMgr;
59     m_pWidgetMgr = NULL;
60   }
61 }
Initialize()62 FWL_ERR CFWL_AppImp::Initialize() {
63   if (!m_pWidgetMgr) {
64     m_pWidgetMgr = new CFWL_WidgetMgr(m_pAdapterNative);
65   }
66   return FWL_ERR_Succeeded;
67 }
Finalize()68 FWL_ERR CFWL_AppImp::Finalize() {
69   delete m_pWidgetMgr;
70   m_pWidgetMgr = NULL;
71   return FWL_ERR_Succeeded;
72 }
GetAdapterNative()73 IFWL_AdapterNative* CFWL_AppImp::GetAdapterNative() {
74   return m_pAdapterNative;
75 }
FWL_GetAdapterWidgetMgr()76 IFWL_AdapterWidgetMgr* FWL_GetAdapterWidgetMgr() {
77   return static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr())
78       ->GetAdapterWidgetMgr();
79 }
GetWidgetMgr()80 IFWL_WidgetMgr* CFWL_AppImp::GetWidgetMgr() {
81   return m_pWidgetMgr;
82 }
SetThemeProvider(IFWL_ThemeProvider * pThemeProvider)83 FWL_ERR CFWL_AppImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
84   m_pThemeProvider = pThemeProvider;
85   return FWL_ERR_Succeeded;
86 }
Exit(int32_t iExitCode)87 FWL_ERR CFWL_AppImp::Exit(int32_t iExitCode) {
88   while (m_pNoteDriver->PopNoteLoop())
89     ;
90   return m_pWidgetMgr->GetAdapterWidgetMgr()->Exit(0);
91 }
GetThemeProvider()92 IFWL_ThemeProvider* CFWL_AppImp::GetThemeProvider() {
93   return m_pThemeProvider;
94 }
FWL_GetAdapterNative()95 IFWL_AdapterNative* FWL_GetAdapterNative() {
96   IFWL_App* pApp = FWL_GetApp();
97   if (!pApp)
98     return NULL;
99   return pApp->GetAdapterNative();
100 }
FWL_GetThemeProvider()101 IFWL_ThemeProvider* FWL_GetThemeProvider() {
102   return NULL;
103 }
104 static IFWL_App* _theApp = NULL;
FWL_GetApp()105 IFWL_App* FWL_GetApp() {
106   return _theApp;
107 }
FWL_SetApp(IFWL_App * pApp)108 void FWL_SetApp(IFWL_App* pApp) {
109   _theApp = pApp;
110 }
FWL_SetFullScreen(IFWL_Widget * pWidget,FX_BOOL bFullScreen)111 FWL_ERR FWL_SetFullScreen(IFWL_Widget* pWidget, FX_BOOL bFullScreen) {
112   if (!pWidget)
113     return FWL_ERR_Succeeded;
114   IFWL_NoteThread* pNoteTread = pWidget->GetOwnerThread();
115   if (!pNoteTread)
116     return FWL_ERR_Succeeded;
117   CFWL_NoteDriver* pNoteDriver =
118       static_cast<CFWL_NoteDriver*>(pNoteTread->GetNoteDriver());
119   if (!pNoteTread)
120     return FWL_ERR_Succeeded;
121   pNoteDriver->NotifyFullScreenMode(pWidget, bFullScreen);
122   return FWL_GetAdapterWidgetMgr()->SetFullScreen(pWidget, bFullScreen);
123 }
124