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 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_APP_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_APP_H_
9 
10 #include "JS_Define.h"
11 
12 class CJS_Runtime;
13 
14 /* ---------------------------- TimerObj ---------------------------- */
15 
16 class CJS_Timer;
17 
18 class TimerObj : public CJS_EmbedObj
19 {
20 public:
21 	TimerObj(CJS_Object* pJSObject);
22 	virtual ~TimerObj();
23 
24 public:
25 	void			SetTimer(CJS_Timer* pTimer);
26 	CJS_Timer*		GetTimer() const;
27 
28 private:
29 	CJS_Timer*		m_pTimer;
30 };
31 
32 class CJS_TimerObj : public CJS_Object
33 {
34 public:
CJS_TimerObj(JSFXObject pObject)35 	CJS_TimerObj(JSFXObject pObject) : CJS_Object(pObject) {}
~CJS_TimerObj()36 	virtual ~CJS_TimerObj(){}
37 
38 	DECLARE_JS_CLASS(CJS_TimerObj);
39 };
40 
41 
42 // struct APP_MENUITEM_ARRAY;
43 //
44 // struct APP_MENUITEM
45 // {
46 // 	APP_MENUITEM() : oSubMenu(NULL), cName(L""), cReturn(L""), bMarked(false), bEnabled(true)
47 // 	{
48 // 	}
49 // 	CFX_WideString cName;
50 // 	CFX_WideString cReturn;
51 // 	APP_MENUITEM_ARRAY* oSubMenu;
52 // 	bool bMarked;
53 // 	bool bEnabled;
54 // };
55 
56 // struct APP_MENUITEM_ARRAY
57 // {
58 // 	APP_MENUITEM_ARRAY() : m_hMenu(NULL), pContents(NULL), nSize(0)
59 // 	{
60 //
61 // 	}
62 // 	APP_MENUITEM * pContents;
63 // 	HMENU m_hMenu;
64 // 	int	nSize;
65 // };
66 
67 // struct APP_MENU;
68 // struct APP_MENU_ARRAY
69 // {
70 // 	APP_MENU_ARRAY():
71 //     pContent(NULL)
72 // 	{
73 // 	}
74 //
75 // 	APP_MENU* pContent;
76 // };
77 
78 // struct APP_MENU
79 // {
80 // 	APP_MENU():bSubMenu(false),
81 // 	SubMenuItems(NULL),
82 // 	cwMenuItemName(L""),
83 // 	hMenu(NULL),
84 // 	iSize(0)
85 // 	{
86 //
87 // 	}
88 //
89 // 	APP_MENU(CFX_WideString &cwName):
90 // 	cwMenuItemName(cwName),
91 // 	bSubMenu(false),
92 // 	SubMenuItems(NULL),
93 // 	hMenu(NULL),
94 // 	iSize(0)
95 // 	{
96 //
97 // 	}
98 //
99 // 	CFX_WideString cwMenuItemName;
100 // 	bool bSubMenu;
101 // 	APP_MENU_ARRAY* SubMenuItems;
102 // 	int iSize;
103 // 	HMENU hMenu;
104 // };
105 
106 class app : public CJS_EmbedObj
107 {
108 public:
109 	app(CJS_Object * pJSObject);
110 	virtual ~app();
111 
112 public:
113 	FX_BOOL						activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
114 	FX_BOOL						calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
115 	FX_BOOL						formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
116 	FX_BOOL						fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
117 	FX_BOOL						fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
118 	FX_BOOL						language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
119 	FX_BOOL						media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
120 	FX_BOOL						platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
121 	FX_BOOL						runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
122 	FX_BOOL						viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
123 	FX_BOOL						viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
124 	FX_BOOL						viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError);
125 
126 
127 	FX_BOOL						alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
128 	FX_BOOL						beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
129 	FX_BOOL						browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
130 	FX_BOOL						clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
131 	FX_BOOL						clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
132 	FX_BOOL						execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
133 	FX_BOOL						execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
134 	FX_BOOL						findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
135 	FX_BOOL						goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
136 	FX_BOOL						goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
137 	FX_BOOL						launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
138 	FX_BOOL						mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
139 	FX_BOOL						newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
140 	FX_BOOL						newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
141 	FX_BOOL						openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
142 	FX_BOOL						openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
143 	FX_BOOL						popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
144 	FX_BOOL						popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
145 	FX_BOOL						response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
146 	FX_BOOL						setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
147 	FX_BOOL						setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
148 
149 private:
150 //	FX_DWORD					AppGetTickCount();
151 	void						TimerProc(CJS_Timer* pTimer);
152 	void						RunJsScript(CJS_Runtime * pRuntime,const CFX_WideString & wsScript);
153 //	void						ParsePopupMenuObj(APP_MENUITEM * ppMenuItem,JSObject * pObj);
154 //	void						DeleteMenuItems(APP_MENUITEM_ARRAY * pMenuItems);
155 // 	void						AddMenuItem(APP_MENUITEM_ARRAY * pMenuItems, HMENU hMenu, MENUITEMINFO MenuItemInfo);
156 // 	void						InitMenuItemInfo(MENUITEMINFO& MenuItemInfo);
157 // 	void						DestroyPopUpMenu();
158 
159 // 	void						ParserMenuItem(APP_MENU* pHead, const CJS_Parameters&params);
160 // 	void						AddItemToMenu(APP_MENU* pHead, HMENU hMenu, MENUITEMINFO MenuItemInfo);
161 // 	void						DestroyMenuItems(APP_MENU* pHead);
162 
163 public:
164 	static CFX_WideString		SysPathToPDFPath(const CFX_WideString& sOldPath);
165 
166 private:
167 
168 	bool						m_bCalculate;
169 	bool						m_bRuntimeHighLight;
170 
171 	CFX_ArrayTemplate<CJS_Timer*>	m_aTimer;
172 //	APP_MENU*					m_pMenuHead;
173 
174 public:
175 //	static CReader_App* s_App;
176 };
177 
178 class CJS_App : public CJS_Object
179 {
180 public:
CJS_App(JSFXObject pObject)181 	CJS_App(JSFXObject  pObject) : CJS_Object(pObject) {};
~CJS_App(void)182 	virtual ~CJS_App(void){};
183 
184 	DECLARE_JS_CLASS(CJS_App);
185 
186 	JS_STATIC_PROP(activeDocs, app);
187 	JS_STATIC_PROP(calculate, app);
188 	JS_STATIC_PROP(formsVersion, app);
189 	JS_STATIC_PROP(fs, app);
190 	JS_STATIC_PROP(fullscreen, app);
191 	JS_STATIC_PROP(language, app);
192 	JS_STATIC_PROP(media, app);
193 	JS_STATIC_PROP(platform, app);
194 	JS_STATIC_PROP(runtimeHighlight, app);
195 	JS_STATIC_PROP(viewerType, app);
196 	JS_STATIC_PROP(viewerVariation, app);
197 	JS_STATIC_PROP(viewerVersion, app);
198 
199 	JS_STATIC_METHOD(alert, app);
200 	JS_STATIC_METHOD(beep, app);
201 	JS_STATIC_METHOD(browseForDoc, app);
202 	JS_STATIC_METHOD(clearInterval, app);
203 	JS_STATIC_METHOD(clearTimeOut, app);
204 	JS_STATIC_METHOD(execDialog, app);
205 	JS_STATIC_METHOD(execMenuItem, app);
206 	JS_STATIC_METHOD(findComponent, app);
207 	JS_STATIC_METHOD(goBack, app);
208 	JS_STATIC_METHOD(goForward, app);
209 	JS_STATIC_METHOD(launchURL, app);
210 	JS_STATIC_METHOD(mailMsg, app);
211 	JS_STATIC_METHOD(newFDF, app);
212 	JS_STATIC_METHOD(newDoc, app);
213 	JS_STATIC_METHOD(openDoc, app);
214 	JS_STATIC_METHOD(openFDF, app);
215 	JS_STATIC_METHOD(popUpMenuEx, app);
216 	JS_STATIC_METHOD(popUpMenu, app);
217 	JS_STATIC_METHOD(response, app);
218 	JS_STATIC_METHOD(setInterval, app);
219 	JS_STATIC_METHOD(setTimeOut, app);
220 
221 };
222 
223 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_APP_H_
224