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 _JS_CONSOLE_H_
8#define _JS_CONSOLE_H_
9
10#include "../res/resource.h"
11
12#define WST_NONE		0x00					// No size changed
13#define WST_LEFT		0x01					// size to left
14#define WST_TOP			0x02					// size to top
15#define WST_RIGHT		0x04					// size to right
16#define WST_BOTTOM		0x08					// size to bottom
17#define WST_TOPLEFT		(WST_TOP|WST_LEFT)		// size to top & left
18#define WST_TOPRIGHT	(WST_TOP|WST_RIGHT)		// size to top & right
19#define WST_BOTTOMRIGHT	(WST_BOTTOM|WST_RIGHT)	// size to bottom & right
20#define WST_BOTTOMLEFT	(WST_BOTTOM|WST_LEFT)	// size to bottom & right
21
22#ifndef IDC_DLGSIZEBOX
23#define IDC_DLGSIZEBOX  50
24#endif	/* IDC_DLGSIZEBOX */
25
26enum { m_idSizeIcon = IDC_DLGSIZEBOX };
27enum {				// possible Control reSize Type
28	CST_NONE = 0,
29	CST_RESIZE,		// NOMOVE + SIZE, add all delta-size of dlg to control
30	CST_REPOS,		// MOVE(absolutely) + NOSIZE, move control's pos by delta-size
31	CST_RELATIVE,	// MOVE(proportional)  + NOSIZE, keep control always at a relative pos
32	CST_ZOOM,		// MOVE + SIZE (both are automatically proportional)
33	CST_DELTA_ZOOM	// MOVE(proportional, set manually) + SIZE(proportional, set manuall)
34};
35
36// contained class to hold item state
37//
38class CJS_ItemCtrl
39{
40public:
41	UINT	m_nID;
42	UINT	m_stxLeft  	   : 4;			// when left resizing ...
43	UINT	m_stxRight     : 4;			// when right resizing ...
44	UINT	m_styTop   	   : 4;			// when top resizing ...
45	UINT	m_styBottom    : 4;			// when bottom resizing ...
46	UINT	m_bFlickerFree : 1;
47	UINT	m_bInvalidate  : 1;			// Invalidate ctrl's rect(eg. no-automatical update for static when resize+move)
48	UINT	m_r0		   : 14;
49	CRect	m_wRect;
50	double	m_xRatio, m_cxRatio;
51	double	m_yRatio, m_cyRatio;
52
53protected:
54	void Assign(const CJS_ItemCtrl& src);
55
56public:
57	CJS_ItemCtrl();
58	CJS_ItemCtrl(const CJS_ItemCtrl& src);
59
60	HDWP OnSize(HDWP hdwp, int sizeType, CRect *pnCltRect, CRect *poCltRect, CRect *pR0, CWnd *pDlg);
61
62	CJS_ItemCtrl& operator=(const CJS_ItemCtrl& src);
63};
64
65class CJS_ResizeDlg : public CDialog
66{
67//	DECLARE_DYNAMIC(CJS_ResizeDlg)
68public:
69	CJS_ResizeDlg(UINT nID,CWnd *pParentWnd = NULL);
70	virtual ~CJS_ResizeDlg();
71
72
73public:
74	std::vector<CJS_ItemCtrl>	m_Items;           // array of controlled items
75	CRect					m_cltRect, m_cltR0;
76	int						m_xMin, m_yMin;
77	int						m_xSt,  m_ySt;		//step?
78	UINT					m_nDelaySide;		//drag side of window
79	CStatic					m_wndSizeIcon;     // size icon window
80
81protected:
82	void 					AddControl( UINT nID, int xl, int xr, int yt, int yb, int bFlickerFree = 0,
83									    double xRatio = -1.0, double cxRatio = -1.0,
84									    double yRatio = -1.0, double cyRatio = -1.0 );
85	void 					AllowSizing(int xst, int yst);
86	void 					HideSizeIcon(void);
87	virtual BOOL			OnInitDialog();
88
89	void					OnSizing(UINT nSide, LPRECT lpRect);
90	void					OnSize(UINT nType, int cx, int cy);
91	void					OnGetMinMaxInfo(MINMAXINFO *pmmi);
92	BOOL					OnEraseBkgnd(CDC* pDC);
93
94public:
95	int						UpdateControlRect(UINT nID, CRect *pnr);
96};
97
98
99//------------------------CIconListBox for CWndElementList-------------------------------------
100
101class CIconListBox : public CListBox
102{
103public:
104	CIconListBox();
105	virtual ~CIconListBox();
106
107public:
108	int				InsertString(int nIndex, LPCWSTR lpszItem , int nImage);
109	virtual	void	ResetContent();
110	virtual void	GetText(int nIndex, CString& rString);
111
112	virtual void	DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
113	void			MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
114	int				CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
115
116protected:
117	// Generated message map functions
118	//{{AFX_MSG(CIconListBox)
119	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
120	//}}AFX_MSG
121	DECLARE_MESSAGE_MAP()
122
123protected:
124	struct ItemDatas
125	{
126		CString	csText;
127		int		nImage;
128	};
129};
130//----------------------------------CWndElementList--------------------------------------------
131#define IDC_LIST_JS_ELEMENT 10070
132
133#define ELEMENT_LIST_WIDTH 140
134#define ELEMENT_LIST_HEIGHT 180
135#define ELEMENT_LIST_TOP_OFFSET 13
136
137#define ELEMENT_TYPE_NAME	0
138#define ELEMENT_TYPE_CONST	1
139#define ELEMENT_TYPE_FUN	2
140#define ELEMENT_TYPE_PRO	3
141
142class CWndElementList : public CWnd
143{
144public:
145	CWndElementList();
146	virtual ~CWndElementList();
147
148public:
149	virtual void	OnSize(UINT nType, int cx, int cy);
150	virtual BOOL	Create(CWnd* pParentWnd);
151	virtual BOOL	ShowWindow(int nCmdShow);
152	void			RemoveAllElement();
153	void			SetElementList(LPCWSTR* pElement, int* pType ,  int iCount);
154	void			AddElement(CFX_WideString csValue , int nType);
155	BOOL			GetElementSel(CString &csElement);
156	BOOL			SelectNext();
157	BOOL			SelectPrevious();
158	BOOL			SelectFirst();
159	BOOL			SelectLast();
160	BOOL			SelectNextPage();
161	BOOL			SelectPreviousPage();
162	int				GetListHeight();
163
164protected:
165	// Generated message map functions
166	//{{AFX_MSG(CWndElementList)
167	afx_msg void OnPaint();
168	afx_msg BOOL OnNcActivate(BOOL bActive);
169	afx_msg void OnSelJSElement();
170	afx_msg void OnDblclkJSElement();
171	afx_msg void OnDestroy();
172	//}}AFX_MSG
173	DECLARE_MESSAGE_MAP()
174protected:
175	CIconListBox	m_ListBox;
176	BOOL			m_bBlock;
177};
178
179///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180// CJS_ConsoleDlg �Ի���
181class CJS_ConsoleDlg : public CJS_ResizeDlg
182{
183	DECLARE_DYNAMIC(CJS_ConsoleDlg)
184
185public:
186	CJS_ConsoleDlg(CReader_App* pApp, CWnd* pParent);
187	virtual ~CJS_ConsoleDlg();
188
189	enum { IDD = IDD_JS_CONSOLE };
190
191	void				Create();
192
193	void				AppendConsoleText(const CFX_WideString& swText);
194	void				SetConsoleText(const CFX_WideString& swText);
195	CFX_WideString		GetConsoleText() const;
196	CFX_WideString		GetScriptText() const;
197
198	BOOL				ResetElementList(LPCWSTR lpstrRef);
199	IFXJS_Runtime*		GetJSRuntime();
200
201protected:
202	virtual void		DoDataExchange(CDataExchange* pDX);	// DDX/DDV ֧��
203
204protected:
205	virtual BOOL		OnInitDialog();
206	virtual void		OnCancel();
207
208	virtual BOOL		PreTranslateMessage(MSG* pMsg);
209
210protected:
211	// Generated message map functions
212	//{{AFX_MSG(CJS_ConsoleDlg)
213	afx_msg void OnBnClickedClear();
214	afx_msg void OnBnClickedOk();
215	afx_msg void OnBnClickTips();
216	afx_msg void OnSizing(UINT nSide, LPRECT lpRect);
217	afx_msg void OnSize(UINT nType, int cx, int cy);
218	afx_msg void OnGetMinMaxInfo(MINMAXINFO *pmmi);
219	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
220	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
221
222	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
223	afx_msg void OnChangeScriptEdit(WPARAM wParam , LPARAM lParam);
224	afx_msg void OnMove(int x , int y);
225	public:
226	virtual int	DoModal();
227	//}}AFX_MSG
228	DECLARE_MESSAGE_MAP()
229
230public:
231	CGW_LineNumberEdit			m_edtSC;
232	BOOL						m_bTips;
233	const UINT					m_uTextlimited;
234	FX_HGLOBAL					m_hGlobal;
235	CReader_App *				m_pApp;
236	CWndElementList				m_WndElementList;
237};
238
239#endif //_JS_CONSOLE_H_